Table Of ContentTetris
∗
Implementation of as a Model Counter
JimmyDobler AtriRudra
UniversityatBuffalo,SUNY UniversityatBuffalo,SUNY
[email protected] [email protected]
7
1
0 Abstract
2
Solving #SAT problems isanimportant areaof work. Inthis paper, wediscuss implementing
n
a Tetris,analgorithmoriginallydesignedforhandlingnaturaljoins,asanexactmodelcounterforthe
J #SAT problem. Tetris uses a simple geometric framework, yetmanages to achieve the fractional
5 hypertree-widthbound. Itsdesignallowsittohandlecomplexproblemsinvolving extremelylarge
2 numbersofclausesonwhichotherstate-of-the-artmodelcountersdonotperformwell,yetstillper-
formsstronglyonstandardSATbenchmarks.
]
S Wehave achieved the following objectives. First, wehave found a natural set of model count-
D ingbenchmarksonwhichTetrisoutperformsothermodelcounters. Second,wehaveconstructed
. adatastructurecapableofefficientlyhandlingandcachingallofthedataTetrisneedstoworkon
s
overthecourseofthealgorithm.Third,wehavemodifiedTetrisinordertomovefromatheoretical,
c
[ asymptotic-time-focused environmenttoonethatperformswellinpractice. Inparticular,wehave
managed to produce results keeping us within a single order of magnitude as compared to other
1
solversonmostbenchmarks,andoutperformthosesolversbymultipleordersofmagnitudeonoth-
v
3 ers.
7
4
7
0
.
1
0
7
1
:
v
i
X
r
a
∗Thisresearchwassupportedinpartbygrant#NSFCCF-1319402.
1
1 Introduction
#SATistheprototypical#P-completeproblem.#SAT(aswellasitsNP-completecousinSAT)arenot
onlyofgreatinterestincomputationalcomplexitybutbytheircompletenessturnouttobeagreattool
tomodelawidehostofpracticalproblems. ThishasledtoanexplosionofSATsolversthattrytosolve
practical instances of #SAT or SAT by exploiting structure in these instances. For this paper, we will
assumetheimportanceofdesigning#SATandSATsolversasagiven. Wereferthereadertothebook
chaptersbyGomes, SabharwalandSelmanon#SATsolvers(alsoknownasmodelcounters)[15]and
byGomesetal.onSATsolvers[14]formoredetails.
A common technique is the DPLL procedure, a depth-first search procedure where the algorithm
makesguessesontheassignmentsonevariableatatime,determinesateachstagewhetherornotthis
producesaconflict,andusesthatinformationtolearnnewclausesandgetclosertofindingthesatisfying
assignment[17].
Recentlyinthedatabaseliterature,theworkofAboKhamisetal.[6]connectedtheDPLLprocedure
tocomputingnaturaljoins.Inparticular,theypresentedtheTetrisalgorithm,whichcomputesthenatu-
raljoinwithbeyondworst-casetheoreticalguarantees.Asaspecialcase,Tetrisalsorecoverssomeofthe
recentworst-caseoptimaljoinresults[24,30,25]. AboKhamisetal. thenshowedthatTetrisisanDPLL
procedureandpointedouthowoneofthemainstepintheiralgorithmisexactlytheresolutionstepthat
isubiquitousinDPLL-basedSATsolvers.GiventheclosetiesofSATsolverstoDPLL,theyleftopenthe
followingintriguingpossibility:
CanTetrisbeimplementedasaSATsolverormodelcounterthatcancompetewithstate-of-
the-artsolvers?
Ourcontributions OurmainresultinthispaperistoshowthatTetriscanindeedbeimplementedasa
modelcounterthatiscompetitivewithstate-of-the-artmodelcountersonactualdatasets.
While[6]presentedanicegeometricframeworktoreasonaboutalgorithmstocomputethenatural
join query, some of its simplicity arose from inefficiencies that matter when implementing Tetris as a
modelcounter. Before we presenttheissues we tackle, we give aquick overviewofTetris. Thefunda-
mentalideaisthat,ratherthanworkingtocreatetheoutputofajoindirectly,itinsteadattemptstorule
outlargesectionsofthecrossproductofthejoinedtables[6]. Initially,Tetrisisgivenasetofsetswhose
unionisthesetofallincorrectsolutionstotheproblemTetrisissolving. Inotherwords,anysolutionto
theproblemmustnotbeamemberofthisunion.Byefficientlyqueryingthissetofsets,andbyaddingto
itintelligentlyatvarioustimes(suchasbyaddinganewexclusionwheneveranoutputpointisfound),
Tetrisisabletoruleoutincreasinglylargesetsofpotentialsolutions. Onceithasruledoutallpossible
solutions,itterminatesandoutputsthelistofsolutions.
WetacklethefollowingthreeissueswiththetheoreticalpresentationofTetrisin[6]:
1. Atanypoint,Tetrisneedstokeeptrackoftheunionofallthepotentialsolutionsithasruledout.
Todothis,[6]usedasimpletriedatastructuretokeeptrackoftheunion.However,thislosessome
poly-logarithmic factors andproves detrimentalto practical performance. To deal with this, we
design anewdatastructurethatessentially compresses consecutive layers inthetraditionaltrie
into one ‘mega layer.’ Inspired by the used of SIMD instructions by EmptyHeaded [5] (to speed
upimplementationsofworst-case optimaljoin algorithms[25]), weset upthecompression ina
mannerthatlendsitselftospeedupviaSIMDinstructions.
2
2. TheanalysisofTetrisin[6]wasfordatacomplexity.Thisimpliestheycouldaffordtouseexponen-
tial(inthesizeofthejoinquery)timealgorithmtofindanappropriateorderinginwhichtoexplore
differentvariables. In#SATinstances,wecannolongerassumethatthenumberofvariablesisa
constant,andhencewecannotobtainanoptimalorderingusingabruteforcealgorithm.Wedeal
withthisbydesigningheuristicsthattakethestructureofTetrisintoaccount.
3. Asmentionedearlier,Tetris(likeaDPLLprocedure)performsasequenceofresolutionsandthe-
oretically, itcanstoretheoutcomesofalltheresolutionsitperforms. However,forpracticaleffi-
ciency,weuseaheuristictodecidewhichresolutionresultstocacheandwhichonestodiscard.
Our experimental results are promising. On some natural #SAT benchmarks based on counting
numberofoccurrencesofsmallsubgraphsinalargegraph(whichwecreated),ourimplementationof
Tetrisisatleasttwoordersofmagnitude(andinmostcasesmorethanthreeordersofmagnitude)faster
thanthestandardmodelcounters(sharpSAT[28],Cachet[26]anddSharp[22]).WealsocomparedTetris
withthesemodelcountersonstandardSATbenchmarks,whereTetriswaseithercomparableoratmost
25xslower.
TheoreticalImplications Whilethispaperdealswithanexperimentalvalidationofthetheoreticalre-
sultfrom[6],webelievethatithighlightscertaintheoreticalquestionsthatareworthinvestigatingbythe
databasecommunity. Wehighlightsomeofourfavoriteonesthatcorrespondtoeachofourthreemain
contributions:
1. ExtendingTetrisbeyondjoinqueries. Asourworkhasshown,Tetriscanbeusedtosolveproblem
beyond the original naturaljoin computation. Recently, the worst-case optimal join algorithms
wereshowntobepowerfulenoughtosolveproblemsinhostofotherareassuchasCSPs(ofwhich
MaxSATisaprominentexample),probabilisticgraphicalmodelsandlogic[7]. (Alsoseethefol-
lowup work[18].) Thebeyondworst-case resultsin[6]havesofarseemedmore of atheoretical
novelty. However, giventhatthispaperdemonstratestheviabilityofTetrisinpractice, thiswork
opensupthetantalizingpossibilityofextendingthetheoreticalresultsofTetristoproblemscap-
turedby[7,18].SucharesultevenforMaxSATwouldbeofinterestinpractice.
2. Computing orderings efficiently. As mentioned earlier, the theoretical results for Tetris assumes
that therequired orderingamong variables can be computedin exponentialtime. However, for
applications inSAT (aswellasotherareassuch asprobabilistic graphicalmodels, assuming the
question in the item above can be answered), we need to compute orderings that are approxi-
matelygoodinpolynomialtime. Thus,afurtheravenueoftheoreticalinvestigationistocomeup
withapolynomialtimealgorithmtocomputetheordering,andtoprovesomeguaranteesonthe
lossofperformancefromthecasewhereTetrishasaccesstothe‘optimal’ordering. Someofthe
heuristicsdevelopedinourpapermightprovetobegoodstartingpointsforthisinvestigation.We
wouldliketopointthatthattheimportanceofefficientlycomputingvariableorderingshasbeen
studiedalotinAIanddatabaseliterature.SomeoftheveryrecentworkonGeneralizedHypertree
Decompositions(whicharewellknowntobeequivalenttovariableeliminationorderings)could
potentiallybeusefultowardsthisgoal[13].
3. Time-spacetradeoff.Recentresultsonworst-caseoptimalalgorithmstocomputenaturaljoins[24,
30,25]andtocomputejoinswithfunctionaldependencies[8]allfocusexclusivelyontimecom-
plexity.However,ashighlightedbyourwork,beingmoreprudentwithspaceusageinfactbenefits
3
actualperformance.Thispointwasalsoindirectlyhighlightedin[6],whereitwasshownthatres-
olutionschemesthatdidnotcachetheirintermediateresultsarestrictlylesspowerfulthanthose
thatdo(inthecontextofcomputingthenaturaljoin). However,webelievethatasystematicthe-
oretical study of the tradeoff between time and space needed to compute the naturaljoin is an
attractiveroutetopursue.
Wewill begininSection 2byintroducingthefundamentalconceptsnecessarytounderstandboth
SATproblemsanddetailsonTetrisitself,allwhilegivingahands-onexampleofhowTetriswouldhandle
atoyexample.Fromthere,wewillmoveintoSection3,anin-depthanalysisofourmajorcontributions.
Afterwards, we will continue with our experimental results in Section 4. Then we will discuss related
workinthefieldinSection5.
2 Background
Inthissection,wewillintroducetheconceptsnecessarytounderstandhowTetrisfunctions,introduce
theconceptofresolutions,andwalkthroughhowTetriswouldhandleasimpleinput.
SAT
2.1 andBoxes
We begin by defining several key terms and ideas. Recall that a SAT problem consists of a series of
Booleanvariables,x ,x ,...,x ,joinedtogetherinaseriesofANDandORclauses.Problemsaregenerally
1 2 n
presentedintheconjunctivenormalform(CNF),asimplificationwhereintheentireformulaiswritten
as a series of ANDs over a set of disjunctive clauses. Onesuch example would be (x ∨x )∧(x ∨x¯ ).
1 2 1 2
Asolution, or satisfying assignment, toa SAT problem is an assignment of trueor falseto each of the
variablessuchthattheBooleanformulaissatisfied;thatis,thatallclausesaresatisfied.
Next, we will consider the idea of boxes, which is how our algorithm will interpret SAT problems.
Eachboxisann-dimensionalstructurein{0,1}n,wherenisthenumberofvariablesintheoriginalSAT
problem. Wewilldefinethissetastheoutputspace;thatis,allpotentialoutputswillbeelementsofthis
set.Eachofourboxesexistswithinthishypercube,andalongeachdimensionhasthevalue0,thevalue
1,orextendsalongthefulllengthoftheedge. Thereasonforthisissimple: 0correspondstofalse,1to
true,andthelengthoftheedgetoboth.Henceforth,wewilluseλtorefertoedgeswithlength1.Wethus
formthefollowingdefinition:
Definition1(BoxNotation). Aboxtakestheform〈b ,b ,...,b 〉,whereeachb ∈{T,F,λ}.
1 2 n i
Observethat,fromthesedefinitions,wecanconsidereveryassignmenttobea0-dimensionalbox;
thiswillbeimportantlater.
Then, ourgoal will be tofindtheset of pointswithin theoutputspace thatarenot contained(see
Definition2)byanyboxes. Anysuchpointwillbetermedanoutputpoint,andthegoalofanalgorithm
workingontheseboxesistofindallsuchoutputpoints.
Definition2(Containment). Aboxbissaidtocontainanotherboxc if,forallpointsp∈{0,1}n suchthat
p ∈c, itistruethat p ∈b. Equivalently,thebox〈b ,b ,...,b 〉containsthebox〈c ,c ,...,c 〉if, for alli,
1 2 n 1 2 n
b =c orb =λ.
i i i
However, thereisonekeydifferencebetweenthesetworepresentations. EachclauseinaCNFfor-
mulaisessentiallyasubproblemwhereinatleastonevariable’sassignmentmustmatchitsvalueinthe
4
clausefortheassignmenttopossibly besatisfying. Butwithboxes, theexactoppositeistrue: ifanas-
signmentmatchesthevaluefortheboxesonallnon-λdimensions,werejecttheassignment. Inother
words,ifweconsiderageometricvisualizationoftheseboxes,anyandallassignmentsthatfallwithina
boxarerejected.
Hence,ournextstepistodeviseameansbywhichtoconvertanygivenSATprobleminCNFformto
theboxesformatthatTetriscanunderstand.Asfollowsfromouraboveobservation,themostimportant
stepissimplythenegationoftheCNFformula;therestisallbookkeeping. Fortheexactalgorithm,see
Algorithm1.
Algorithm1ConversionfromCNFtoboxes
1: foreachCNFclausedo
2: Negatetheclause
3: Setallx¯i toF,andallxj toT
4: Setallvariablesnotpresentintheclausetoλ.
5: Insertintothedatabase{See Definition 3}
LetusconsiderthefollowingtoyexampleCNFproblem:
Example1. (x ∨x )∧(x ∨x¯ )∧(x ∨x ).
1 2 1 2 2 3
Ourfirststepistonegateeachclause,whichwillgiveusadisjunctivenormalform(DNF)co-problem:
(x¯ ∧x¯ )∨(x¯ ∧x )∨(x¯ ∧x¯ ).
1 2 1 2 2 3
Next, we will converttoboxes (by replacing a variable with T andits negation with F)andaddall
missingvariables(asλ).Afterconversion,ourthreeclausesbecome〈F,F,λ〉,〈F,T,λ〉,and〈λ,F,F〉.
x x x
2 2 2
1 1 1
0 x 0 x 0 x
1 1 1
1 1 1
1 1 1
x x x
3 3 3
(x ∨x ),〈F,F,λ〉 (x ∨x¯ ),〈F,T,λ〉 (x ∨x ),〈λ,F,F〉
1 2 1 2 2 3
Figure1: Ourstartingboxes,andthecorrespondingSATclauses. Whileboxesare,technicallyspeaking,
strictlythecornersofwhatwedepictastheboxes,wedepictthemwiththeedgesandsurfacesdrawnfor
thepurposeofvisualclarity.
Atthispoint,itistimetoinserttheboxesintoourdatastructure. Letuslistthefundamentalopera-
tionsthedatastructuremustbeabletoperform:
Definition3(Tetrisdatastructure). TheTetrisdatastructureshallbeabletoperformthefollowingoper-
ations:
1)Insert,inputistheboxtobeinserted,nooutput
2)Contains,inputistheboxweareseeingifthestructurecontains,outputisthecontainingbox(seeDefi-
nition2)
5
3)GetAllContainingBoxes, inputistheboxweareseeingifthestructurecontains,outputisthesetofall
containingboxes
WewillreturntothedetailsofthedatastructureimplementationinSection3.1.
2.2 Resolution
Wethencometotheconceptofresolution,akeyaspectofTetrisandmoststate-of-the-artSATsolvers.
ResolutioncanbedefinedoverbothCNFclausesandboxes;letusbeginwiththeformer.Letusconsider
twoclausesinourCNFExample1onceagain:specifically,(x ∨x )and(x ∨x¯ ).Weseethatthesearetwo
1 2 1 2
verysimilarclauses;theydifferonlyinthatthex termisnegatedinoneandnottheother.Therefore,we
2
canresolvethesetwoclausesbyremovingthex termandthentakingtheORofallremainingvariables.
2
Inthiscase,thisgivesus(x ).WethenremovetheoriginaltwoclausesfromtheCNFproblemandinsert
1
thisnewclauseinitsplace.Thisisasignificantsimplification.
Similarly,wecanresolveanytwoclausessuchthatthereisexactlyonepivotpoint,bywhichwemean
avariablethatappearsinbothclauses,butisnegatedinoneandnottheother.Forinstance,lookingback
atourexample, we canalsoresolve (x ∨x¯ )with (x ∨x )toform(x ∨x )In thiscase, we wouldnot
1 2 2 3 1 3
beabletoremovetheoriginaltwoclauses,butwewouldhavegainedinformation. Letusnowformally
definethisprocess:
Definition4(ResolutiononClauses). Twoclauses(x ∨x ∨...∨x ∨v)and(y ∨y ∨...∨y ∨v¯),i ∈I,
i1 i2 im j1 j2 jl
j ∈J,I,J ⊂[n],canberesolvedifandonlyifthereexistsexactlyonevariablev,thepivotpoint,suchthat
v∈xandv¯∈y.
Theresolutionofthetwoclausesis(x ∨x ∨...∨x ∨y ∨y ∨...∨y ).
i1 i2 im j1 j2 jm
Sinceboxesaresimplyanotherrepresentationofthesameproblem,itfollowsthatresolutioncanbe
performedonboxesaswell.First,wewillrequirethattheremustexistexactlyonevariableonwhichone
boxistrueandtheotherboxisfalse.1 Callthisthepivotvariable. Intheoutput,setthisvariabletoλ.
Then,foreachothervariable,ifitisT inoneorbothboxes,setittoT intheoutputbox;ifitisF inone
orbothboxes,setittoF intheoutputbox;andifbothvariablesareλ,thentheresolutionofthetwois
alsoλ.
We see two possible resolutions in our Example 1. The resolution of 〈F,F,λ〉 and 〈F,T,λ〉, two co-
planarandparalleledges,isthesquare〈F,λ,λ〉,asdepictedinFigure2,andtheresolutionoftheaskew
edges 〈F,T,λ〉 and 〈λ,F,F〉 is the edge 〈F,λ,F〉, as depicted in Figure 3. For a formal definition of the
resolutionoperator,henceforth⊕,seeDefinition5.
x x x
2 2 2
1 1 1
0 x + 0 x = 0 x
1 1 1
1 1 1
1 1 1
x x x
3 3 3
Figure2: Theresolutionof〈F,F,λ〉and〈F,T,λ〉onthevertexx isthesquare〈F,λ,λ〉. Thisisequivalent
2
to(x ∨x )resolvedwith(x ∨x¯ )beingtheclause(x ).
1 2 1 2 1
1Thisisexactlyanalogoustotherequirementthatweresolveonapivotpointintheclauseversion.
6
x x x
2 2 2
1 1 1
0 x + 0 x = 0 x
1 1 1
1 1 1
1 1 1
x x x
3 3 3
Figure3: Theresolutionof〈F,T,λ〉and〈λ,F,F〉onthevertexx istheedge〈F,λ,F〉Thisisequivalentto
2
(x ∨x¯ )resolvedwith(x ∨x )beingtheclause(x ∨x ).
1 2 2 3 1 3
Definition5(ResolutiononBoxes). Twoboxes〈b ,b ,...,b 〉and〈c ,c ,...,c 〉canberesolvedifandonly
1 2 n 1 2 n
ifthereexistsexactlyonei suchthatb istrueandc isfalse,orvice-versa.
i i
Intheresolvedboxa,a =λ.Eacha ,j 6=i isequaltob ⊕c ,where⊕isdefinedasfollows:
i j j j
T⊕T =T
F⊕F =F
λ⊕T =T
λ⊕F =F
T⊕λ=T
F⊕λ=F
λ⊕λ=λ
T⊕F isundefined.
Observethatresolutiononboxesandresolutiononclausesareidentical:
Lemma1. Resolutiononboxes,withtheadditionalrestrictionthatexactlyonevariablemustbetruein
oneboxandfalseintheother,isexactlyequivalenttoresolutiononSATclauses.
Proof. Let(x ∨...∨x )and(y ∨...∨y ),i ∈I,j ∈J,whereIandJ⊂[n],betheclausesweareresolving.
i1 im j1 jl
AssumeWLOGthati =j isthepivotpoint.Thentheresolvedclauseis(x ∨...∨x ∨y ∨...∨y ).
1 1 i2 im j2 jl
Theboxesequivalenttoourstartingtoclausesare〈b ,...,b 〉and〈c ,...,c 〉,whereb =F ifx ∈x,b =T
1 n 1 n k k k
ifx¯ ∈x,andλotherwise,andc isdefinedsimilarlywithrespecttoy.Theresolutionoftheseboxesais
k k
thendefinedas〈a ,...,a 〉,wherea =λifk=i =j ,anda =b ⊕c otherwise.
1 n k 1 1 k k k
Now,letuscalculatetheboxequivalentoftheoutputoftheclause-basedresolution,t. Itcanbeshown
thatt =λifk =i = j , t =x =y ifk ∈I,k ∈ J andk 6=i , t =x ifk ∈I andk ∉ J, t =y ifk ∈J
k 1 1 k k k 1 k k k k
andk∉I,andt =λifk∉I andk∉J. Inspectionwiththeabovedefinitionof⊕revealsthatt isexactly
k
equivalenttoa.Sincethesameproblemwitharbitrary,equivalentinputsproducedequivalentoutputs,
thetwooperationsmustbeequivalent.
Tetrisintroducesoneadditionalrestrictiononresolution.
Definition 6 (Resolution on Boxes in Tetris). Two boxes b and c can be resolved if and only if there is
exactlyonespoti suchthatb =Tandc =F,orvice-versa,andforall j >i,b =c =λ.
i i j j
In otherwords, we will demandthatthatthepivotvariable bethefinalnon-λvariable. Therefore,
whileTetriswillperformtheresolutionof〈F,F,λ〉and〈F,T,λ〉(Figure2),itwillnotperformtheresolution
of〈F,T,λ〉and〈λ,F,F〉(Figure3).Wesee,then,thattheorderingofthevariablesdetermineswhetheror
7
notaresolutionisevenpossible.Thismakesdeterminingtheglobalorderingofthevariablesakeyissue,
asmentionedearlierasTheoreticalImplication2,whichwewilladdresslaterinSection3.2.
Ingeneral,Tetrisperformsresolutiononpairsofrecentlyfoundboxes. Letk bethelocationofthe
lastnon-λvariableinaboxb. Thenb mustbeeithertrueorfalse. Ifitisfalse,wewillstoretheboxfor
k
futureuse.Ifitistrue,thenwewilltakethisboxbandresolveitwiththestoredboxwiththesamevalue
fork whoselastnon-λvariablewasfalse. Bydoingso,wewillguaranteetheproductionofaboxwhere
thelastn−k+1variableshavethevalueλ.Formoredetailsonhowthisworks,alongwiththereasoning
forwhysuchpairscanalwaysbefound,seeSection2.3.
Tetris
2.3
Fornow, letusreturntoourExample1. Whenwe last leftoff,we were just insertingthethreeclauses
intoourdatastructure,whichwaslooselydefinedinDefinition3.Foraformaldefinitionofthedatabase
anddetailsforhowitallowsthesetofboxesTetrisknowsabouttobequicklyandefficientlyqueried,see
Section3.1;fornow,onecansimplyassumeittobeatrie-basedstructure. Additionally,wecanresolve
thefirsttwoboxeswhileleavingthethirduntouched,asinFigure2;therefore,thedatabasewillcontain
exactly the boxes 〈F,λ,λ〉 and 〈λ,F,F〉 (see Figure 4). Furthermore, we will prepare an empty array of
boxesLofsizen,whichwillbeusedlater.Thepurposeofthisarrayistostoreandretrieveboxesthatwe
wishtoresolvewithotherboxes.
Nowthatwehaveourdatabaseestablished,itistimetoperformTetrisproper. Thebasicideahere
is very simple. We will pick a point P in the output space, which we will call the probe point; recall
thatthispointisitselfa0-dimensionalbox. Wethendeterminewhetherornotanyboxinthedatabase
containsthispoint. Ifonedoes,wewillstorethisboxinanadditionaldatastructurereferredtoasthe
cache,whichfunctionsidentically tothemaindatabase,andprobeanewpoint. IfnoboxcontainsP,
wewilllistthepointasasolutionandfurthermoreaddthispointintothecache. Alongtheway,wewill
performresolutioninordertocreatenewandlargerboxes. Thisprocesscontinuesuntiltheentiretyof
theoutputspaceiscoveredbyasinglebox,atwhichpointwemusthavefoundeveryoutputpointand
are done. Algorithm 3 hasthe details. It should be notedthat thisalgorithm was originally presented
recursivelyin[6]; here,wepresentititerativelybothforthepurposesofspeedandbecausethisallows
fornon-chronologicalbacktracking;inotherwords,wecanbacktrackmorethanonelayeratatime.
Algorithm2Advance(boxb,probepoint&p) (note: p is a global variable)
1: whilebContainsp do
2: ifthelastnon-λvariableofpisF then
3: SetthatvariabletoT {Return to the previous branching point and take the right,
or true, branch}
4: else
5: whilethelastnon-λvariableofp isT do
6: Setthatvariabletoλ{Return to the most recent level where we branched left}
7: Setthelastnon-λvariableofptoT {Branch right here}
8: ReplaceallλsafterthisvariablewithF {Repeatedly branch left}
Now,letusconsiderhowthisalgorithmbehaveswithregardstoourearlierExample1.Wepickasour
firstprobepoint〈F,F,F〉,givingusthesituationillustratedinFigure4.Wefirstscanourlocalcache,C,for
anyboxesthatcontainthispoint;however,sincethisisthefirstprobepoint,thecacheistriviallyempty.
Next,wescanthedatabaseD. D containsalltheboxescorrespondingtotheclausesintheoriginalSAT
8
Algorithm3GeneralTetrisforSAT
1: Establishvariableordering
2: BuildthedatabaseD usingAlgorithm1
3: C ←;
4: L←Anemptyarrayofsizen{This array is implicit in [6]}
5: p←〈F,F,...,F〉
6: while〈λ,λ,...,λ〉∉C do
7: if(b←C.Contains(p))isnonemptythen
8: Advance(b,p){Advance (see Algorithm 2) the probe point past b}
9: elseif(A←D.GetAllContainingBoxes(p))isnonemptythen
10: forallboxesb∈Ado
11: C.Insert(b)
12: Advance(b,p){Advance the probe point past b}
13: else
14: Addptotheoutput{There is no containing box, so p is an output point}
15: C.Insert(p)
16: Advance(p,p){Advance the probe point past itself}
17: k←thelocationofthelastnon-λvariableinbw.r.t.thevariableordering
18: ifbk=F then
19: L[k]=b{Store the most recent left-branching box for a given depth}
20: else
21: r ← b ⊕ L[k] {Resolve this right-branching box with the corresponding
left-branching box}
22: C.Insert(r)
problem. Thedatabasejustsohappenstocontaintwocontainingboxes; forreasonsthatwillbecome
clearshortly,theoperationwillchoosetooutput〈F,λ,λ〉.Weinsertthebox〈F,λ,λ〉intoC.
Our next task is to advance the probe point until it lies beyond our box. To do this, we proceed
accordingtoAlgorithm2. Theideaistothinkofthesetofallpossibleprobepointsasatreethatweare
performingadepth-firstsearchon,withF representingleft-branchingpathsandT representingright-
branchingpaths. Wewillcontinuealongthisdepth-firstsearchuntilwefindapointnotcoveredbythe
mostrecentlydiscoveredbox.Thistakesusto〈T,F,F〉.Notethatifthedatabasehadfetched〈F,F,λ〉,we
wouldnothavebeenabletoadvancetheprobepointasfar.
Finally,weinsertourcontainingboxintothearrayLatlocation1,sinceonlythefirstvariableisnon-
λ, for futureuse. We know to doinsertion here, ratherthan tryingtoresolve with a non-existentbox,
becausethevalueofthatfirstnon-λvariableisfalse.ThistakesustothesituationdepictedinFigure5.
Again we scanC, thistime forthe probe point 〈T,F,F〉,andagain we findnocontaining box inC.
So we scan D once again andfind the containing box 〈λ,F,F〉. We then insert this box into the cache
andadvancetheprobepointto〈T,F,T〉. Thistime,althoughourcontainingboxfeaturesaλatthefirst
location,wedeterminethelocationinLintowhichwewillinsertbasedonthelocationofthelastnon-λ
variable,soweinsertitintoL[3].
Thistime,wefindnocontainingboxesineitherthecacheorthedatabase.Therefore,wehavefound
an output point (see Figure 6 for an illustration). We add〈T,F,T〉 toour output set, then addthe box
〈T,F,T〉toourcache,whichmarksthepointasfound.
Atthisjuncture,wefindthatthelastnon-λvariableisatlocation3,butthistime,itistrue.Therefore,
9
DatabaseD CacheC ProbePointp ProbePointMap
x x x
2 2 2
1 1 1
0 x 0 x 0 x
1 1 1
1 1 1
1 1 1
x x x
3 3 3
Figure4: TheinitialstateofthedatabaseD,cacheC,andthelocationofthefirstprobepointp,which
willsearch theoutputspaceinadepth-firstmannerthatcanbetrackedusingthemaponitsright. D
issimplytheunionofalltheboxeswecreatedfromtheinitialSATproblem,while p issettoaninitial
valueof〈F,F,F〉.Liscurrentlyempty.
DatabaseD CacheC ProbePointp ProbePointMap
x x x
2 2 2
1 1 1
0 x 0 x 0 x
1 1 1
1 1 1
1 1 1
x x x
3 3 3
Figure 5: The stateof thedatabase, cache, andprobe point afterthe firstroundof thealgorithm. Our
probepoint foundthebox 〈F,λ,λ〉,soit addedthisbox toC. Then, p wasadvanceduntilitreacheda
pointnotcontainedbythisbox,whichturnedouttobe〈T,F,F〉.L(1)isthebox〈F,λ,λ〉,whichisthebox
correspondingtotheorangevertexinthemap;thearrayisemptyelsewhere.
we will extractthesame-length boxwe storedpreviously atL[3]andresolve itwiththisbox. Weknow
thatthiswillbealegalresolutionbecausewearescanningtheoutputspaceinatree-likefashion. This
meansthat,whenretreatingfromarightbranch,theboxcontainingthecorrespondingleftbranchmust
beabletocontaintherightbranchifthefinalnon-λvariableweresettoλinstead. Itfollows thatthis
finalnon-λvariablemustbetheoneandonlypivotpointbetweenthetwo.
Therefore,wecananddoperformthisresolution;inthisexample,itis〈T,F,T〉resolvedwith〈λ,F,F〉.
Thisoutputsthebox〈T,F,λ〉. WefurthermorestorethisboxinL atlocation2,sincethisboxendswith
falseatthatindex.
Wecontinueforthwithprobepoints〈T,T,F〉and〈T,T,T〉.NeitherwillbefoundineitherDorC,and
arethereforeoutputpoints. Bothagainhavetheirfinalnon-λvariablesatindex3, with〈T,T,F〉being
insertedintoL atthatindex andthen〈T,T,T〉recoveringthatbox so it canresolve with it toformthe
box〈T,T,λ〉. Thistime,theoutputofourresolutionendswithtrue,sowerecovertheboxatindex2in
L,〈T,F,λ〉,andtaketheresolution ofthesetwoboxes, givingus〈T,λ,λ〉. OnceagainthisendsinT,so
wecanresolveitwiththeboxwefoundbackatthebeginningthathasbeenwaitinginslot1,〈F,λ,λ〉,to
formthebox〈λ,λ,λ〉. Thisboxcompletelycoverstheoutputspace;therefore,thealgorithmknowsthat
ithasfoundallpossibleoutputpointsandterminates(seeFigure7foranillustration).
10