City, University of London Institutional Repository
Citation
:
Simon, A., King, A. and Howe, J. M. (2003). Two variables per linear inequality
as an abstract domain. Logic based program synthesis and transformation, 2664, pp. 71-89.
doi: 10.1007/3-540-45013-0_7
This is the unspecified version of the paper.
This version of the publication may differ from the final published
version.
Permanent repository link:
http://openaccess.city.ac.uk/1709/
Link to published version
:
http://dx.doi.org/10.1007/3-540-45013-0_7
Copyright and reuse:
City Research Online aims to make research
outputs of City, University of London available to a wider audience.
Copyright and Moral Rights remain with the author(s) and/or copyright
holders. URLs from City Research Online may be freely distributed and
linked to.
City Research Online:
http://openaccess.city.ac.uk/
[email protected]
Abstrat Domain
AxelSimon 1
AndyKing 1
JaobM.Howe 2 1
ComputingLaboratory,
2
DepartmentofComputing, UniversityofKent,Canterbury,UK. CityUniversity,London,UK.
fa.m.king, a.simonguk.a.uk jaobsoi.ity.a.uk
Abstrat. Thispaperexploresthespatialdomainofsetsofinequalities where eahinequality ontains at most two variables{ a domainthat isriher thanintervalsand moretratablethangeneralpolyhedra.We present a omplete suite of eÆient domain operations for linear sys-temswithtwovariablesperinequalitywithunrestritedoeÆients.We exploitatatiinwhihasystemofinequalitieswithatmosttwo vari-ablesperinequalityisdeomposedintoaseriesofprojetions{onefor eahtwodimensionalplane.Thedeompositionenablesalldomain oper-ationsrequiredforabstratinterpretationtobeexpressedintermsofthe twodimensionalase. TheresultingoperationsareeÆientandinlude anovelplanar onvexhull algorithm.Empirialevidenesuggests that wideninganbeappliedeetively,ensuringtratability.
1 Introdution
Thevalueof spatialdomains suh asintervals[13℄,aÆne spaes[19℄and poly-hedra [8℄ has been reognized sine the early days of program analysis. One reourringthemein programanalysisis thetrade-obetweenpreisionofthe domainandthetratabilityofthedomainoperations.Inthisregard,the polyhe-dralsub-domainthatonsistsofsetsoflinearinequalitieswhereeahinequality ontains at most two variables has reently attrated attention [26,27,33,35℄. In fat, beause of its tratability, this lass of linear inequalities hasreently beenproposedforonstraintlogiprogramming[15,18℄.Thispaperadaptsthis worktotherequirementsofprogramoptimizationandprogramdevelopmentby equipping this domain with the operationsneeded for abstrat interpretation. Twovariableinequalitydomainshavealreadyprovenusefulin areasasdiverse asprogramveriation[29,34℄,modelhekingoftimedautomata [22,28℄, par-allelization[2℄,loatingseurityvulnerabilities[36℄,detetingmemoryleaks[33℄ andverifyingprogramterminationinlogiprogramming[24℄.Thusthe applia-bilityofthedomainextendsbeyondlogiprogramming[4,17℄to otheranalysis problemsin veriationandprogramdevelopment.
Onekeyideainthisworkisthatoflosure.Closurestrengthenstheinequalities of S (representedasaDBM) to obtainanewsystemS
0
(alsorepresentedasa DBM).Forexample,ifx+y
0 2S
0 ,then
0
wheneverSimpliesx+y. Thusapplying losuremaximallytightenseahinequality,possiblyintroduing newinequalities.Projetion,entailmentandjoinapplylosureasapreproessing stepbothto preservepreisionandsimplify thedomainoperationsthemselves. Forexample,thejoinoftwoinequalitieswithidentialoeÆients,sayx y
1 and x y
2
, issimplyx ymax( 1
; 2
). Closureenablesthissimplejoin tobeliftedpoint-wisetosystemsofinequalities.Sinemostdomainoperations requireoneorbothoftheirargumentstobelosed,theseoperationsinheritthe O(d
3
) omplexity of the DBM losure operation. In this paper, we show how losureisalsothekeyoneptto taklethetwovariableperinequalitydomain withunrestrited oeÆients.Heneforth,ourlosureoperatorisreferredto as ompletionto distinguishit fromtopologiallosure.
Thispaperdrawstogetheranumberofstrandsfromtheveriation,analysis andonstraintsliteraturetomakethefollowingnovelontributions:
{ Weshowthat apolynomialompletion algorithm whih makes expliitall thetwo-dimensional projetions of a systemof (unrestrited) two variable inequalitiesenables eah domain operation to be omputed in polynomial time.Inredibly,suhaompletionoperatoralreadyexistsandisembedded intothesatisabilityalgorithmofNelson[29℄.
{ We explain how lassi O(mlogm) onvex hull algorithms for sets of m planarpoints, suh as[11℄,an be adapted to omputethejoin eÆiently. Theruialpointisthatompletionenablesjointobeomputedpoint-wise oneahtwo-dimensionalprojetionwhihneessarilydesribesaplanar ob-jet.Surprisinglylittleliteratureaddresses howtoeÆientlyompute on-vex hull of planar polyhedra (without the full omplexity of the standard d-dimensionalalgorithm[6,23℄)andasfarasweareaware,ouronvexhull algorithmisunique(see[32℄forareentsurvey).Projetionandentailment operatorsarealsodetailed.
{ Wealsoaddresssalabilityandpresentempirialevidenethat thenumber ofinequalities in eah two-dimensionalprojetionis small. Thissuggestsa naturalwidening: limit the number of inequalitiesin eah projetion by a onstant.ThistrivialwideningobtainsanO(d
2
)representation,likeDBMs, without enforing the requirement that oeÆients are 1;0 or +1. Note that in ontrast to DBMs, our representation is dense { spae is only re-quiredforthoseinequalitiesatuallyourringinthesystem.Thewidening also auses ompletion to ollapse to an O(d
3 (logd)
2
) operation whih is ompetitive with the O(d
3
) DBMapproah, taking into onsideration the extraexpressiveness.
oeÆients mustbe unitary{without ompromisingtratability. Appliations that employ the Otagon domain or related weaker domains [22,28,33℄ will thereforediretlybenetfromthiswork.
Thepaperis struturedasfollows.Setion 2presents theabstrat domain. Setion 3explains how Nelson'ssatisability algorithm [29℄an be adapted to ompleteasystem.Thenextthreesetionsexplainhowompletionprovidesthe basis for the domain operations. Setion 7 presents empirial evidene for the pratialityofthedomain.Thefutureandrelatedworksetionsonlude.
2 Abstrat domain
Tospeify thedomainalgorithms andarguetheirorretness, westartthe ex-positionbydetailingsometheoretialpropertiesofpolyhedraldomains. 2.1 Convex hull and losure
An -ballaroundy2R n
isdened asB
(y)=fx2R n j P n i=1 (x i y i ) 2 <g. AsetSR
n
isopenif,givenanyy2S,thereexists>0suhthatB
(y)S. AsetSR
n
islosediR n
nSisopen.NotethatifS i
R n
islosedforeah memberofanindexseti2I then\fS
i
ji2Igisalsolosed.The(topologial) losure of S 2 R
n
is dened l(S)=\fS 0
R n
jS S 0
^S 0
islosedg.The onvexhullofS2R
n
isdenedonv(S)=fx+(1 )yjx;y2S^01g. 2.2 Two-variablesper inequalitydomain
LetX denotethenitesetofvariablesfx 1
;:::;x n
gsothatX isordered lexio-graphiallybyx
i x
j
ii<j.LetLin X
denotethesetof(possiblyrearranged) linearinequalitiesoftheformax
i +bx
j
wherea;b;2R. LetTwo X
denote theset of allnite subsetsofLin
X
. Notethat although eahset T 2Two X
is nite, Two
X
is notnite. Syntatisugarof theform x y isused insteadof (+1)x+( 1)y02Lin
X
aswellasby+axinsteadofax+by. Denition1. The mapping [[:℄℄ : Lin
X ! R
n
is dened: [[ax i +bx j ℄℄ = fhy 1 ;:::;y
n i2R
n jay
i +by
j
gandthemapping[[:℄℄:Two X
!R n
isdened [[T℄℄=\f[[t℄℄jt2Tg.
Forbrevity, lett =
representtheboundaryofagivenhalf-spae,that is, dene t = = fax i +bx j ; ax i bx j
g when t ax i +bx j . Two X is ordered byentailment,that is, T
1 j=T
2 i[[T
1 ℄℄ [[T
2
℄℄. Equivalene onTwo X is dened T
1 T
2 i T
1 j= T
2 and T
2 j= T
1
. Moreover T j= t i T j= ftg and t 1 t 2 ift 1 gft
2
g. LetTwo X
=Two X
=.Two X
inherits entailment j= from Two
X
. In fat hTwo X
;j=;u;ti is a lattie (rather than a omplete lattie) with [T
1 ℄ u[T 2 ℄ =[T 1 [T 2 ℄ and[T 1 ℄ t[T 2 ℄ =[T℄
where [[T℄℄= l(onv([[T
1 ℄℄[[[T
2
℄℄)). Notethat in generalonv([[T 1
℄℄[[[T 2
1 T
2
=f x0;x y0;y x0gsothat[[T 1
℄℄=fh0;1igand[[T 2
℄℄=fhx;yij 0x^x=yg.Thenonv([[T
1 ℄℄[[[T
2
℄℄)inludesthepointh0;1ibutnottheray fhx;yij0x^x+1=ygandheneisnotlosed.
-6
0 1 2 3 x 0
1 2 3 y
r [[T
1 ℄℄
[[T
2 ℄℄
-6
0 1 2 3 x 0
1 2 3 y
r
ThedomainTwo X
isageneriabstratdomainthatisnotlimitedtoa spe-iappliation.Noonretizationmapisdenedinthispapersinesuhamap is spei to anappliation.However,ifanappliation usedtheonretization map(T)=[[T℄℄thennoabstrationmap :}(R
n
)!Two X
wouldexistsine there is no best abstration e.g. for the set fhx;yi j x
2 +y
2
1g. The prob-lem stemsfromthefat that Two
X
anontainanarbitrarilylargenumberof inequalities.ThisontrastswiththeOtagondomain whereeahplanarobjet willbedesribedbyatmosteightinequalities.
WewillaugmenthTwo X
;j=;u;tiwithprojetion9andwideningto aom-modate theneedsofabstratinterpretation.
Denition2. Projetionoperator9 x
i :Two
X
!Two X
isdened9 x
i ([T
1 ℄
)= [T
2 ℄
where[[T 2
℄℄=fhy 1
;:::;y i 1
;y;y i+1
;:::;y n
ijy2R^hy 1
;:::;y n
i2[[T 1
℄℄g. Projetion an be alulated using Fourier-Motzkin variable elimination and fromthis itfollowsthatT
2 2Two
X ifT
1 2Two
X .
2.3 Completeform for the two-variablesper inequality domain The omplete form for the two-variables per inequality domain is dened in termsofthosevariablesthatourinaset ofinequalities.
Denition3. Themappingvar :Lin X
!}(X)isdened:
var(ax+by)= 8 > > < > > :
; ifa=b=0 fyg ifa=0 fxg ifb =0 fx;ygotherwise
The mapping var aptures those variables with non-zerooeÆients. Observe that var(t
1
)=var(t 2
)ift 1
t 2
.Inontrast,notethat var(0u+0v1)=;= var(0x+0y 1).IfT 2Two
X
thenletvar(T)=[fvar(t)jt2Tg. Denition4. LetY X.Therestritionoperator
Y
X Two
0 X
=fT 2Two X
j8t2Lin X
:T j=t ) var(t)
(T)j=tg Proposition1. Suppose T 2Two
X
. Then there existsT 0
2Two 0 X
suh that T T
0
andT T 0
. Proof. Dene[T
x;y ℄ =9 Xnfx;yg ([T℄
)forallx;y2XandT 0
=T[ S
x;y2X T
x;y . Sine eah T
x;y
isnite, T 0
is nite, heneT 0
2Two 0 X
.Bythe denition of9, T j=T
x;y
,heneT [T x;y
T forallx;y2X,thusT T 0
.MoreoverT T 0
. Corollary 1. Two
X =Two 0 X =.
2.4 Orderingthe two-variablesper inequality domain Let Y =fx;ygX suh that x y and onsider T =ft
1 ;:::;t
n
g2 Two Y
. Eah t
i
denes ahalf-spaein theY plane andtherefore T anbeordered by theorientationofthehalf-spaesasfollows:
Denition6. The (partial) mapping : Lin Y
! [0;2) is dened suh that (ax+by)= whereos( )= b=
p a
2 +b
2
andsin( )=a= p a 2 +b 2 . The mapping atually returnsthe anti-lokwise angle whih the half-spae fhx;yijy0ghastobeturnedthroughtooinidewithfhx;yijax+by0g. 2.5 Entailmentbetween three inequalities
This setion demonstrates how entailment heks of the form ft 1
g j= t and ft
1 ;t
2
g j= t an be omputed in onstant time. The following proposition ex-plainshowthishekreduestoapplyingtheCramerruleforthethreeinequality aseandsimplesaling forthetwoinequalityase.
Proposition2. Lett i
a i
x+b i
y i
fori=1;2andtax+by.Then
ft 1
gj=t () 8 > > > > < > > > > :
false ifa 1
b ab 1
6=0 false elseifa
1
a<0_b 1
b<0 (a=a
1 )
1
elseifa 1 6=0 (b=b 1 ) 1
elseifb 1
6=0
1
<0_(0^a=0^b=0) otherwise
ft 1
;t 2
gj=t () 8 > > < > > : ft 1
gj=t_ft 2
gj=t ifd=a 1 b 2 a 2 b 1 =0 false elseif
1 =(ab
2 a
2
b)=d<0 false elseif
2 =(a
1 b ab
1 )=d<0 1 1 + 2 2 otherwise. Iftheinequalitiest
1
the onstants of the inequalities, suitably saled. The fth ase mathes the pathologialsituationoftautologousandunsatisableinequalities.
Theentailmentbetweenthreeinequalitiesreduestotheformeraseift 1
and t
2
haveequal slope (the determinant is zero). Otherwise an inequality is on-strutedwhihhasthesameslopeastandwhihpassesthroughtheintersetion point [[t
= 1
℄℄\[[t = 2
℄℄ using theCramer rule.Again, aomparison ofthe onstants determinestheentailmentrelationship.Ifeither
1 or
2
isnegative,thefeasible spaeoftheombinationoft
1 andt
2
willopposethatoft,thusft 1
;t 2
gannot entailt.
3 Completion: A variant of Nelson's satisability algorithm
Inthissetionweshowhowtoompleteasystemofinequalities.Thisoperation orrespondstothelosureoperationofMine.WefollowtheapproahthatNelson usedforhekingsatisability[29℄.Onekeyoneptinhisalgorithmisthenotion ofalterthat isformalizedbelow.
Denition7. Let Y =fx;ygX. The mappinglter Y
:Two Y
!Two Y
is dened suhthat:
1. lter Y
(T)T 2. lter
Y
(T)T 3. forallT
0
T andT 0
T,jlter Y
(T)jjT 0
j. Theroleoflter
Y
istoremoveredundantelementsfromasetofinequalitiesover thevariablesY.Iftheinequalitiesareorderedbyangle,redundanyremovalan bedonesurprisinglyeÆientlyasillustratedinFig.1.Thefuntionlter returns asingleontraditoryinequalityiftheompleted systemS isunsatisable,and otherwiseremovestautologiesbefore sortingtheinequalities.Theloop then it-eratesovertheinequalitiesoneinananti-lokwisefashion.Itterminateswhen no more redundant inequalitiesan befound, that is, when (1) the whole set of inequalitieshas been traversed one (ag f is true) and (2) theinequalities with the largest and smallest angle are both non-redundant. Sine the entail-ment hek between three inequalitiesan be performedin onstant time, the algorithmislinear.Notethatdierentsubsetsoftheinputanbeminimal.This ours,forexample,whenthesystemisunsatisable. Thenlter
Y
returnsone ofthesesubsets.
The map lter Y
lifts to arbitrary systems of two-variable inequalities as follows:
Denition8. Themappinglter :Two X
!Two X
isdened: lter(T)=
S
flter ( Y
fx;yg
X
if9s2S :s0x+0y 1thenreturnfsg; T :=fs2Sjs60x+0y1g;
letT=ft 1
;:::;t m
gsuhthat(t 1
)(t 2
):::(t m
); f:=false;
loop
letft;tn;:::;tlg=T;ifjTj>1^ftn;tlgj=tthenT :=ftn;:::;tlg;else begin if(t)(t
l
)^f thenreturnT; if(t)(tl)thenf :=true; T :=ft
l
;t;tn;::: g; end;
end; end
Fig.1.Algorithmforredundanyremoval
Theseond key ideaof Nelson is the result map that makesexpliit those inequalities that are indiretly expressed by the system. The basi step is to generate all possible ombinations of pairs of inequalities by eliminating their ommonvariable.
Denition9. Theresultantsmapresult :Two X
!Two X
isdened by:
result(T)= 8 > > < > > :
aez dbyaf d t
1 ;t
2
2T ^ t
1
ax+by ^ t
2
dx+ezf^ a>0^d<0
9 > > = > > ;
Thefollowingexampledemonstrateshowresult worksonahainof dependent variables:
Example 2. Let T 0
= fx 0
x 1
;x 1
x 2
;x 2
x 3
;x 3
x 4
g. We alulate T
1
=result(T 0
)andT 2
=result(T 0
[T 1
). result(T
0 )=fx
0 x
2 ;x
1 x
3 ;x
2 x
4 g result(T
0 [T
1 )=T
1 [fx
0 x
3 ;x
0 x
4 ;x
1 x
4 g Notethat T
3 =
S 2 i=0
T i
isaxpointin T 3
=result(T 3
).
An importantproperty ofT [result(T)is thewayit halvesthe numberof variablesrequiredtoentailagiveninequalityt.Speially,supposeT j=t.Then there existsT
0
T[result(T)suh thatT 0
j=tandT 0
ontainsnomorethan halfthevariablesofT.Lemma1formalizesthisandisbasiallyareformulation ofLemma 1bof[29℄.
Lemma1. Let T 2Two X
and t 2Lin X
[image:8.612.136.500.65.237.2]that takes(approximately) log 2
(jvar(T)j)steps.Theorem 1assertsits orret-ness.
Denition10. Themappingomplete:Two X
!Two X
isdened: omplete(T
0 )=T
dlog 2
(jvar(T 0
)j 1)e
whereT i+1
=lter(T i
[result(T i
)) Theorem1. omplete(T)T andomplete(T)2Two
0 X
forallT 2Two X
. Proof. Letf :N !N wheref(n)=bn=2+1.Thefollowingtabledetailsm2N forwhihf
m
(n)2.Observethatf dlog
2 (n 1)e
(n)2.
n 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 ... m0 1 2 2 3 3 3 3 4 4 4 4 4 4 4 4 5 ... Observethat T T [result(T)lter(T [result(T))and by indution T omplete(T).Lett2Lin
X
suh thatomplete(T)j=t.ThenT j=t.LetT 0
=T and T
i+1
= lter(T i
[result(T i
)). By indution and by Lemma 1, there ex-ists Y
i
var(T) suh that Y
i (T
i
) j= t and jY i
j f i
(jvar(T)j). Therefore jY
dlog 2
(jvar(T)j 1)e
j2,hene var(t)
(omplete(T))j=tasrequired.
Note that applying an additional ompletion step makes expliit all inequali-tiesoveronevariable. Furthermore,applying itone more reatestautologous and ontraditoryinequalities. Applyingthese twoadditionalompletion steps enableslterto detetunsatisfabilitywithoutemployinganyextramahinery. Example 3. To illustrate how unsatisability is deteted onsider the system T
0
=f x+y 1; 2x 3y 6;4x 2y 4g.Thesystemisompletebut twomoreompletionstepsareneessaryto detetunsatisability.The alula-tionT
1
=lter(T 0
[result(T 0
))=T 0
[f y 2; 5x 9;x 3gmakesall inequalitiesoveronevariableexpliit.Unsatisabilitybeomesexpliitwhen al-ulating 0 242result(T
1
).Finally lter(result(T 1
))=f0 24gollapses thesystemto asingleunsatisableonstraint.
3.1 Complexity ofthe omplete operation
Nelson shows that his satisability algorithm is polynomial in the number of input inequalities [29℄. Foromparison with the DBM approah, onsider the omplexityoflter(T
i
[result(T i
))whered=jvar(T i
)jandk=maxfj Y
(T i
)jj i 2 [0;dlog
2
(jvar(T)j 1)e℄^Y =fx;yg var(T i
)g. Sine eah T i
mayhave d(d 1)=2restritions,alinearpassoverO(kd
2
)inequalitiesissuÆientto parti-tionthesetofinequalitiesintodsets,oneforeahvariable.Eahsethasatmost O(kd)elements,soalulatingtheresultantsforeahsetisO(k
2 d
2
),hene al-ulatingalltheresultantsisO(k
2 d
3
).Theomplexityofapplyingthelinearlter isin O(kd
2 +k
2 d
3
)=O(k 2
d 3
)whihwithsortingrequiresO(k 2
d 3
log(k 2
d 3
))= O(k
2 d
3
(log (k)+log (d)))time.TheompleteoperationrunsresultO(logd)times whih leads to an overall running time of O(k
2 d
3
log(d)(log (k)+log(d))). In Setion 7 we showthat k is typially small and therefore anbe limited by a onstant with hardly any loss of expressiveness. This ollapses the bound to
Nelson [29℄ originally devised this ompletion operation in order to onstrut apolynomialtestforsatisability.Thefollowingpropositionexplainshow non-satisabilityanbeobservedafter(andevenduring)theompletionalulation. Speially,thepropositionassertsthatnon-satisabilityalwaysmanifestsitself in theexisteneofatleastoneontraditoryinequality.
Proposition3. LetT 0
2Two 0 X
.Then[[T 0
℄℄=;i[[ ;
(T 0
)℄℄=;. Proof. Let T
0
2 Two 0 X
. Suppose [[T 0
℄℄ = ;. Then T 0
j= 0x+0y 1. Sine var(0x+0y 1)=;,hene
; (T
0
)j=0x+0y 1andtherefore[[ ; (T 0 )℄℄=;. Sine ; (T 0 )T
0
theonversefollows.
4 Join: Planar onvex hull on eah projetion
Computing the join orresponds to alulating the onvex hull for polyhedra whihissurprisinglysubtle.Thestandardapproahforarbitraryd-dimensional polyhedrainvolvesapplyingthe Chernikova[6℄algorithm (oravariant[23℄) to onstrutavertiesandraysrepresentationwhihispotentiallyexponential[20℄. Bywayof ontrast, weshowthat onvexhullforsystemsof twovariables per inequalityanbeomputedbyashort polynomialalgorithm.
Theonstrutionstartsbyreformulatingtheonvexhullpiee-wiseinterms ofeahofitsplanarprojetions.Proposition4showsthatthisoperationresults in a omplete system whenever its inputs are omplete; equivalene with the fullydimensionalonvexhulloperationisstatedinProposition 5.
Denition11. The piee-wise onvex hull g : Two X 2 ! Two X is dened T 1 gT 2 =[fT x;y 2Two fx;yg
jx;y 2Xgwhere [[T x;y
℄℄=l(onv([[ fx;yg (T 1 )℄℄[ [[ fx;yg (T 2 )℄℄)). Proposition4. T
0 1 gT 0 2 2Two 0 X ifT 0 1 ;T 0 2 2Two 0 X . Proof. Let t 2 Lin
X
suh that T 0 1
gT 0 2
j= t. Let x;y 2 X and let [[T x;y
℄℄ = l(onv([[
fx;yg (T 0 1 )℄℄ [ [[ fx;yg (T 0 2
)℄℄)). Observe fx;yg
(T 0 1
) j= T x;y
, therefore T
0 1
j=T 0 1
gT 0 2
. LikewiseT 0 2
j=T 0 1
gT 0 2
,heneitfollowsthat T 0 1
j=t andT 0 2
j=t. Sine T 0 1 ;T 0 2 2Two 0 X , var(t) (T 0 1
)j=t and var(t)
(T 0 2
)j=t,thus [[ var(t)
(T 0 1
)℄℄ [[t℄℄ and [[
var(t) (T
0 2
)℄℄ [[t℄℄, hene [[ var(t) (T 0 2 )℄℄[[[ var(t) (T 0 2
)℄℄ [[t℄℄. Therefore [[ var(t) (T 0 1 gT 0 2
)℄℄=l(onv([[ var(t) (T 0 1 )℄℄[[[ var(t) (T 0 2
)℄℄))l(onv([[t℄℄))=[[t℄℄. Therefore var(t) (T 0 1 gT 0 2
)j=t asrequired. Proposition5. [[T
0 1
gT 0 2
℄℄=l(onv([[T 0 1
℄℄[[[T 0 2
℄℄))ifT 0 1 ;T 0 2 2Two 0 X . Proof. SineT
0 1
j=T 0 1 gT 0 2 andT 0 2
j=T 0 1
gT 0 2
,itfollowsthatl(onv([[T 0 1
℄℄[[[T 0 2 ℄℄)) [[T 0 1 gT 0 2
℄℄.Supposethereexists h 1
;:::; n
i2[[T 0 1
gT 0 2
℄℄ suhthat h 1 ;:::; n i62 [[T 0
℄℄where[[T 0
℄℄=l(onv([[T 0 1
℄℄[[[T 0 2
℄℄)).Thus S n i=1 fx i i ; i x i
g6j=T 0
,hene thereexistsax
j +bx
k
t2T 0 with S n fx i i ; i x i g6j=ax
j +bx
fx;yg
letT=ft0;:::;tn 1gsuhthat(t0)<(t1)<:::<(tn 1); V :=R:=;;
fori2[0;n 1℄dolettiax+byinbegin
//aretheintersetionpointsofthisinequalitydegenerated? d
pre :=((t
i ) (t
i 1modn
))mod2_n=1; dpost :=((ti+1
mod
n) (ti))mod2_n=1; ifdpre thenR:=R[fhb=
p a
2 +b
2 ; a=
p a
2 +b
2 ig; ifd
post
thenR :=R[fh b= p
a 2
+b 2
;a= p
a 2
+b 2
ig; elseV :=V [fvgwherev2[[t
= i
℄℄\[[t =
(i+1)modn ℄℄; ifdpre^dpost thenbegin
ifn=1thenR :=R[fh a= p
a 2
+b 2
; b= p
a 2
+b 2
ig; V :=V [fvgwherev2[[t
= i
℄℄ end
end
returnhV;R i end
Fig.2.Calulatingthepointsandraysofaplanarpolyhedron
But T 0 1
j= T 0
j= t and T 0 2
j= T 0
j= t. Sine T 0 1
2 Two 0 X
and T 0 2
2 Two 0 X
, it follows that
fxj;xkg (T
0 1
) j= t and fxj;xkg
(T 0 2
) j= t. Hene T 0 1
gT 0 2
j= t, thus S
n i=1
fx i
i
; i
x i
g j= T 0 1
gT 0 2
but h 1
;:::; n
i 62 [[T 0 1
gT 0 2
℄℄ whih is a ontradition.
Calulatingtheonvexhullforasetofpointsintheplanehasbeenstudied extensively [32℄.The onvex hullof polytopes anbe reduedto this problem by onverting the polytopes into their vertex representation, alulating the onvexhullofallvertiesandonvertingbakintotheinequalityrepresentation. Althoughthegeneralizationtoplanarpolyhedrafollowsthisthree-stepproess, itismuhmoresubtleandlittleliteraturehasbeenwrittenonthisfundamental problem.Givenasetofnon-redundantinequalities,orderedbytheirorientation ,theauxiliaryfuntionextreme inFigure2alulatesasetofvertiesandrays that represent the polyhedron. Rays are reated when the angle between the urrentinequality t
i
and the previousinequalityis greater orequalto (d pre is true) and similarly for the next inequality (d
post
is true). If both ags are true,wereateanarbitrarypointontheboundary ofthehalfspaeoft
i to x its representingrays in spae. A pathologial asearises when the polyhedron onsistsofasinglehalfspae(n=1).Inthisaseathirdrayisreatedtoindiate onwhihsidethefeasiblespaelies.Notethatthemaximumnumberofraysfor eahpolyhedronisfour,whihourswhenT denestwofainghalfspaes.
[image:11.612.135.481.66.278.2]1 X 2 X
if9t2T1:t0x+0y 1thenreturnT2; if9t2T
2
:t0x+0y 1thenreturnT 1
; //note:eahTiisnon-redundant
hV 1
;R 1
i:=extreme(T 1
); hV
2 ;R
2
i:=extreme(T 2
);
V :=V1[V2;R:=R1[R2;//Note:jR j8 ifV =fhx
1 ;y
1
ig^R=;then
returnfxx1; x x1;yy1; y y1g; m:=maxfjxj;jyjjhx;yi2Vg+1;
//addapointalongtheray,goesthroughx;yandisoutsidethebox forhx;y;a;bi2V1[V2RdoV :=V [fhx+2
p
2ma;y+2 p
2 mbig; fv
0 ;:::;v
n 1
g:=graham(V)suhthatv 0
;:::;v n 1
areorderedanti-lokwise andpointsontheboundaryarenotremoved T
res :=;;t
last
:=onnet(v n 1
;v 0
); fori2[0;n 1℄dobegin
lethx 1
;y 1
i=v i
,hx 2
;y 2
i=v
(i+1)modn
,t=onnet(v i
;v
(i+1)modn ) if(jx
1
j<m^jy 1
j<m)_(jx 2
j<m^jy 2
j<m)^(t)6=(t last
)thenbegin if((t) (t
last
))mod 2=^jx1j<m ^jy1j<mthen ify
1 =y
2 thenT
res :=T
res
[fsgn(x 1
x 2
)xsgn(x 1
x 2
)x 1
g else Tres:=Tres[fsgn(y1 y2)ysgn(y1 y2)y1g T
res :=T
res [ftg;t
last :=t; end
end returnTres end
funtiononnet(hx1;y1i;hx2;y2i) return(y
2 y
1 )x+(x
1 x
2 )y(y
2 y
1 )x
1 +(x
1 x
2 )y
1
Fig.3.Convexhullalgorithmforplanarpolyhedra
inV 1
[V 2
.Foreahrayr2RwetranslateeahvertexinV 1
[V 2
inthediretion of the ray r. Note that the normalization of the rays and the translation by 2
p
2mensuresthatthetranslatedvertiesareoutsidethesquare.Wenowapply theGrahamonvexhullalgorithm[11℄,modiedsothatitremovesall(stritly) interiorvertiesbut retainspointswhih lieontheboundaryofthehull.What followsisaround-triparoundthishull,translatingtwoadjaentvertiesintoan inequalitybyallingonnet ifthefollowingonditionsaremet: theinequality musthaveadierentslopethanthepreviouslygeneratedinequalityandatleast oneofthetwovertiesmustliewithinthebox.Thetwoinnermostif-statements deal with the pathologial ase of when V ontains only olinear points and additional inequalities are needed to restrit the two opposing inequalities so that an(unbounded)lineisnotinadvertentlygenerated.
[image:12.612.131.482.65.408.2]O(jTj)itfollowsthattheoverallrunningtimeisO((jT 1
j+jT 2
j)log (jT 1
j+jT 2
j)). 5 Projetion
Projetionreturnsthe most preise systemwhih does notdepend on agiven variable. Weprovideaonstrutivedenition of projetionfor (omplete) sys-tems.Proposition6statesthatthisoinides withthespatial denitionof pro-jetion.Furthermoreweprovethatthisoperationpreservesompletion. Denition12. The operator 9
x : Two
X
! Two Xnfxg
is dened 9 x
(T) = [f
Y
(T)jY =fy;zgXnfxgg. Proposition6. 9
x ([T
0 ℄
)=[9
x (T 0 )℄ and 9 x (T 0
)2Two 0 X
forallT 0
2Two 0 X
. Proof. ByFourier-Motzkin9
x ([T
0 ℄
)=[T℄
where T =ft 2T 0
[result(T 0
) j x 62var(t)g.Observe that T j= 9
x (T
0
). Now suppose r 2 T 0
[result(T 0
) suh that x62var(r).ThenT
0
j=r,hene var(r)
(T 0
)j=rand therefore9 x
(T 0
)j=r, andthus9
x (T
0
)j=T,hene9 x
(T 0
)T asrequired. Nowlet t2 Lin
X
suh that 9 x
(T 0
)j=t.MoreoverT 0
j=9 x
(T 0
) j=t,hene
var(t) (T
0
)j=t.Sinex62var(t), var(t)
(9 x
(T 0
))j=tasrequired.
Consideraompletesystemthat inludesy x0andx z 0.Projeting outxwillpreservetheinequalityy z0whihompletionhasmadeexpliit. 6 Entailment
Entailmenthekingbetweensystemsofinequalitiesanbereduedtoheking entailmentontheirtwodimensionalprojetions.Moreover,entailmentheking foraplanarpolyhedronan befurtherreduedtohekingentailmentbetween three singleinequalities. We start by detailingthe entailment relationship be-tweensystemsofinequalitiesand theirtwodimensionalprojetions.
Proposition7. Let T 0
2 Two 0 X
and T 2 Two X
. Then T 0
j=T i Y
(T 0
) j=
Y
(T)forallY =fx;ygX. Proof. SupposeT
0
j=T.Lett2 Y
(T).ThenT 0
j=T j=t.Hene var(t)
(T 0
)j=t. Sinevar(t)Y,
Y (T
0
)j=tandtherefore Y
(T 0
)j= Y (T). Now suppose Y (T 0 ) j=
Y
(T) for all Y = fx;yg X. Let t 2 T. Then t2
var(t)
(T),heneT 0
j= var(t)
(T 0
)j= var(t)
(T)j=t.
Note that the proposition does not requireboth systems of inequalities to be omplete. Due to Proposition 7 it suÆes to hek that entailment holds for allplanarprojetions.Thereforeonsiderhekingentailmentbetweentwo non-redundantplanarsystemsT
1 ;T
2 2Two
fx;yg
. Totest T 1
j=T 2
itissuÆient to showthat T
1
j=t forallt 2T 2
. This reduesto nding t i ;t i+1 2T 1 suh that (t i
)(t) <(t i+1
) (modulo 2).If any of thetests ft i
;t i+1
funtionentails(T 1
2Two X
;T 2
2Two X
)begin if9t2T1:t0x+0y 1thenreturntrue; if9t2T
2
:t0x+0y 1thenreturnfalse;
letft1;:::;tng=T1suhthat(t1)(t2):::(tn); letft
0 1
;:::;t 0 m
g=T 2
suhthat (t 0 1
)(t 0 2
):::(t 0 m
); u:=1;l:=n;
fori2[1;m℄dobegin while(t
u )<(t
0 i
)^undobegin l:=u;
u:=u+1; end
ifft l
;t (umodn)
g6j=t 0 i
thenreturnfalse; end;
returntrue; end;
Fig.4.Algorithmfor hekingentailmentofplanarpolyhedra
7 Widening
Fordomains thatdo notsatisfytheasendinghain property,widening is ne-essarytoenforeterminationofxpointalulations[7℄(forexampleinloops). Wideninganalsobeusedtoimprovespaeandtimebehavior.Inthefollowing setionsweelaborateonboth.
7.1 Widening fortermination
Anywidening [7,8℄forpolyhedraanbeapplied to planarpolyhedraand then lifted tosystemsoftwovariablesperinequality.Sinethedomainisstrutured in termsof projetions,onetati fordelayingwidening, and thereby improv-ing preision, is to only apply widening when the number of projetions has stabilizedandthe dimensionofeahofthe projetionsisalso stable. One sub-tletyisthatapplyingompletionafterwideninganompromiseterminationby reintroduinginequalitiesthatwereremovedduringwidening.
7.2 Widening fortratability
To assess the tratability of the domain, we implemented a naveompletion operation andmeasuredthe growth bothin the numberofprojetionsand in-equalities. Our test data is obtained by generating random planar polytopes overdierent pairs of variables. Eah polytope was onstrutedby omputing theonvexhullofarandomsetofpointsdistributedarossasquarein R
[image:14.612.132.482.65.259.2]0%
5%
10%
15%
20%
25%
30%
35%
40%
5
10
15
20
25
30
varying
constant
sparse
Fig.5.Thenumberofinequalitiesseemstoberestritedinpratie
thenappliedompletiontothosesystemswhihhadexatly100non-redundant inequalities.Redundaniesanourintheoriginalsystemsinetwopolytopes mayshareaommonvariableandaboundonthisvariablemaypropagatefrom one sub-system to the other, rendering inequalities superuous. The onstant senarioreates10inequalitiesforeahpairofvariables.Sinefewernon-empty projetionswereinitiallygenerated(onaverage143=10),thegrowthinthe num-berof projetionsislarger{onaverageitinreasedto 32projetions.Thelast ase,sparse,orrespondstoasystemwhereinequalitiesareweaklyoupled,that is,fewinequalitiessharevariables.Asexpetedthenumberofextraprojetions generated by ompletion is marginal.The resultsare summarized in Figure 6. Sinerandomlygenerateddataoersnopartiularadvantagetoourompletion algorithmoverrealdata,itappearstheompletionwillremaintratablein pra-tie.Inpartiular,theworstasequadratigrowthinthenumberofprojetions isunlikelytoarise.
Aninterestingobservation isthat thenumberof inequalitiesisnot propor-tional tothenumberofpointsnoverwhihtheonvexhullis alulated.This squareswithprobabilistitheory[5,31℄.Speially,theonvexhullofasetofn pointsrandomlydistributedoverasquareisexpetedtohaveO(logn)extreme points[5℄,whilearandomsetofnpointsrestritedtoairleisexpetedtohave O(n
1 3
[image:15.612.142.467.84.315.2]dimension 10 10 100 inequalitiesgenerated 147 143 139 inequalitiesperpolyhedron 3{13 10 10
afterredundanyremoval
remaininginequalities 100 100 100 avg.noofineq.perpolyhedron 5.3 7.0 7.1
afterompletion
avg.resultantinequalities 210 189 106 inreaseinnoofprojetions 56% 123% 9% projetions>30inequalities 0.22% 0.18% 0.00%
Fig.6.Theimpatofalulatingompletion
that pruning the number of inequalities down to a onstant bound will have little overall eet on preision,yet obtainsanattrativeO(d
3 (logd)
2
) perfor-maneguarantee.Onewaytosystematiallydropinequalitiesistoremovethose thatontributeleasttotheshape,thatis,removetheinequalitythatontributes theshortestedgetothepolyhedron.
8 Future Work
Usingunion-nd anarbitraryT 2Two X
anbepartitioned innear-lineartime into a system fT
1 ;:::;T
p
g suh that var(T i
)\var(T j
) = ; whenever i 6= j. This deomposition enables the omplexity of ompletion to be redued to O(d
3 (logd)
2
)whered=maxfjvar(T 1
)j;:::;jvar(T p
)jg.Thistati,whihis ap-pliabletoanypolyhedraldomain,willbeusefuliftheouplingbetweenvariables islow.
Theompletion of asystemT is urrentlyomputed iterativelyin approx-imately log
2
(jvar(T)j) steps.The ompletion operation ould benet from ap-plying astrategysuhassemi-naveiteration[3℄that would fatoroutsomeof therepeatedwork.
9 Related work
TheOtagondomain[26℄representsinequalitiesoftheformax i
+bx j
where a;b2 f1;0; 1gand x
i ;x
j
2X. Themain noveltyof [26℄ isto simultaneously workwithasetofpositivevariablesx
+ i
andnegativevariablesx i
andonsider aDBMoverfx
+ 1
;x 1
;:::;x + d
;x d
gwhered=jXj.Thenx i
x j
,x i
+x j
and x
i
an be enoded respetively as x + i
x + j
, x + i
x j
and x
+ i
x i
2.Thusan2d2dsquareDBMmatrixissuÆientforthisdomain. Note that this DBMrepresentationontainsentriesof theform x
+ i
x + j
1 wheneverx
i x
j
is notonstrained(and likewisefor x i
+x j
andx i
[image:16.612.188.416.63.192.2]thatisO(d )andehosideasintheearlyworkofPratt[30℄.Otherearlierwork on this theme onsidered the domain of inequalities of the form x
i x
j [25,33℄, though the onnetion between bounded dierenes [9℄ and abstrat interpretationdatesbak(atleast)toBagnara[1℄.Veryreently,Mine[27℄has generalized DBMsto alass of domains that representinvariantsof theform x y 2 C where C is a non-relational domain that represents, for example, aongruenelass [12℄.This work isalso formulatedin terms ofshortest-path losureandillustratesthewidespreadappliabilityofthelosureonept.
Anotherthread of work isthat of SuandWagner[35℄ whopropose a poly-nomialalgorithm foralulatingintegerrangesassolutionsto twovariable per inequality systems, despite the intratability of some of these problems [21℄. However, eÆient integer hull algorithms do exist for the planar ase [10,14℄. Combinedwith ourompletiontehnique,thissuggestsanewtratablewayof alulatingtheintegeronvexhullsfortwovariablesystemsthatpromisestobe usefulinprogramanalysis.
Itiswell-knownthatthelinearprogrammingproblem{theproblemof max-imizingalinearfuntionsubjettolinearinequalities{ispolynomialtime (Tur-ing)equivalenttotheproblemofdeidingwhetheralinearsystemissatisable. Moreover, the problem of deiding whether a linear system is satisable an be transformed into an equivalent problem where eah inequality ontains at mostthreevariables(withatmostapolynomialinreaseinthenumberof vari-ables and inequalities).Thus an eÆient algorithm for solving this problem is alsoaneÆientalgorithmforsolvingthelinearprogrammingproblem andvie versa.Thisequivalene,andnegativeresultssuhas[20℄,explainstheinterestin hekingthesatisabilityofsystemsoflinearinequalitieswhereeahinequality ontainsatmosttwovariablesthat datesbakto[29,30,34℄.Ofallthe propos-alsforhekingthesatisabilityofasystemT,thealgorithmof[16℄ ismostin tunewiththerequirementsofabstratinterpretationduetoitssuintnessand itsO(jTjjvar(T)j
2
log (jTj))runningtimewhihisguaranteedwithoutwidening. This result (and related results) provide fast entailment heking algorithms whihmaybeusefulforeÆientxpointdetetion.
We proposed a new abstrat domain of linear inequalities where eah of the inequalitieshasat mosttwovariablesand theoeÆientsareunrestrited. We haveshownhowa(polynomial)ompletion operationleadstoeÆientand sim-pledomainoperations.Empirialevidenewaspresentedthatsuggeststhatthe domainisbothtratableandwellsuitedtowidening.
Aknowledgments
We thank Roberto Bagnara, Les Hatton, Peter Linnington, Mike Norrish, Antoine Mine, Justin Pearsonand Warwik Harveyfor interesting disussions on polyhedra libraries and linear inequalities. We also thank the anonymous refereesfortheiromments.
Referenes
1. R.Bagnara.Data-FlowAnalysisforConstrantLogi-BasedLanguages.PhDthesis, DipartimentodiInformatia,UniversitadiPisa,1997.
2. V. Balasundaram and K.Kennedy. A Tehniquefor Summarizing DataAess anditsUseinParallelismEnhaningTransformations. InProgrammingLanguage DesignandImplementation,pages41{53.ACMPress, 1989.
3. F. Banilhon and R. Ramakrishnan. An Amateur's Introdution to Reursive QueryProessingStrategies.InInternationalConfereneonManagementofData, pages16{52.ACMPress, 1986.
4. F. Benoyand A.King. InferringArgumentSizeRelationshipswith CLP(R). In Logi Program Synthesis and Transformation (Seleted Papers), volume 1207 of Leture NotesinComputer Siene,pages204{223.Springer-Verlag,1997. 5. J.L.Bentley,H.T.Kung,M.Shkolnik,andC.D.Thompson. OntheAverage
NumberofMaximainaSetofVetors. JournaloftheACM,25:536{543,1978. 6. N. V. Chernikova. Algorithmfor Disovering the Set of All Solutions of a
Lin-earProgrammingProblem. USSRComputational MathematisandMathematial Physis,8(6):282{293,1968.
7. P. Cousot and R. Cousot. Comparing the Galois Connetion and Widen-ing/NarrowingApproahestoAbstratInterpretation. InProgrammingLanguage ImplementationandLogiProgramming,volume631ofLetureNotesinComputer Siene,pages269{295.Springer-Verlag,1992.
8. P. Cousot and N. Halbwahs. Automati Disovery of LinearRestraints among Variables of a Program. In Priniples of Programming Languages, pages 84{97. ACMPress,1978.
9. E. Davis. Constraint Propagation with Interval Labels. Artiial Intelligene, 32(3):281{331, 1987.
10. S.D.Feit.AFastAlgorithmfortheTwo-VariableIntegerProgrammingProblem. JournaloftheACM,31(1):99{113,1984.
of a Program. In InternationalJoint Conferene onthe Theory and Pratie of Software Development, volume493of Leture Notes in Computer Siene, pages 169{192.Springer-Verlag,1991.
13. W. H. Harrison. Compiler Analysis of the Value Ranges for Variables. IEEE TransationsonSoftwareEngineering,SE-3(3),1977.
14. W.Harvey. ComputingTwo-DimensionalIntegerHulls. SIAM Journalon Com-puting,28(6):2285{2299, 1999.
15. W. Harveyand P.J.Stukey. A UnitTwoVariableperInequalityInteger Con-straint Solver for Constraint Logi Programming. Australian Computer Siene Communiations,19(1):102{111,1997.
16. D. S.Hohbaumand J.Naor. Simpleand FastAlgorithms for Linearand Inte-ger Programs withTwoVariablesperInequality. SIAMJournal onComputing, 23(6):1179{1192, 1994.
17. J.M.HoweandA.King. SpeialisingFiniteDomainProgramsusingPolyhedra. In Logi Programming, Synthesis and Transformation (Seleted Papers), volume 1817ofLetureNotesinComputerSiene,pages118{135.Springer-Verlag,1999. 18. J.Jaar,M.J.Maher,P.J.Stukey,andR.H.C.Yap. BeyondFiniteDomains. InInternationalWorkshoponPriniplesandPratieofConstraintProgramming, volume874of Leture Notes inComputer Siene,pages 86{94.Springer-Verlag, 1994.
19. M. Karr. AÆneRelationshipsAmongVariables ofaProgram. AtaInformatia, 6:133{151, 1976.
20. V.KleeandG.J.Minty. HowGoodis theSimplexAlgorithm? InInequalities { III.AademiPress,NewYorkandLondon,1972.
21. J.C.Lagarias. TheComputationalComplexityofSimultaneousDiophantine Ap-proximationProblems. SIAMJournalonComputing, 14(1):196{209,1985. 22. K.G.Larsen,J.Pearson,C.Weise,andW.Yi.ClokDiereneDiagrams.Nordi
JournalofComputing,6(3):271{298, 1999.
23. H.LeVerge. ANoteonChernikova'sAlgorithm. TehnialReport1662,Institut deReherheenInformatique,CampusUniversitairedeBeaulieu,Frane,1992. 24. N. Lindenstrauss and Y. Sagiv. Automati Termination Analysis of Logi
Pro-grams. In International Conferene on Logi Programming, pages 63{77. MIT Press, 1997.
25. A.Mine.ANewNumerialAbstratDomainBasedonDierene-BoundMatries. InPrograms asDataObjets,volume2053 ofLeture NotesinComputer Siene, pages155{172.Springer,2001.
26. A. Mine. TheOtagonAbstratDomain. InEighthWorking Conferene on Re-verse Engineering,pages310{319.IEEEComputerSoiety,2001.
27. A.Mine. AFewGraph-BasedRelationalNumerialAbstratDomains. InNinth International Stati AnalysisSymposium, volume2477 ofLeture Notesin Com-puter Siene,pages117{132.Springer-Verlag,2002.
28. J. Mller, J. Lihtenberg, H. R. Andersen, and H. Hulgaard. Dierene Dei-sionDiagrams. InConferene of theEuropean Assoiationfor ComputerSiene Logi,volume1683ofLetureNotesinComputerSiene,pages111{125. Springer-Verlag,1999.
29. C.G.Nelson. Ann log(n)
Algorithmfor theTwo-Variable-Per-Constraint Linear ProgrammingSatisabilityProblem.TehnialReportSTAN-CS-78-689,Stanford University,DepartmentofComputerSiene,1978.
31. H.Raynaud. SurL'enveloppeConvexedesNuagesdePointsAleatoiresdansR . JournalofAppliedProbability,7(1):35{48,1970.
32. R.Seidel.ConvexHullComputations.InJ.E.GoodmanandJ.O'Rourke,editors, Handbook of Disrete and Computational Geometry, pages 361{376. CRCPress, 1997.
33. R. Shaham, H. Kolodner,and M. Sagiv. Automati Removalof Array Memory Leaks inJava. InCompilerConstrution,volume1781 ofLeture Notesin Com-puter Siene,pages50{66.Springer,2000.
34. R. Shostak. DeidingLinearInequalitiesby ComputingLoopResidues. Journal of theACM,28(4):769{779,1981.
35. Z. Suand D.Wagner. EÆient Algorithmsfor GeneralClassesof IntegerRange Constraints,July2001. http://www.s.berkeley.edu/~zhendong/.