HAL Id: hal-00144924
https://hal.archives-ouvertes.fr/hal-00144924
Submitted on 25 Mar 2010
HAL is a multi-disciplinary open access archive for the deposit and dissemination of sci- entific research documents, whether they are pub- lished or not. The documents may come from teaching and research institutions in France or abroad, or from public or private research centers.
L’archive ouverte pluridisciplinaire HAL, est destinée au dépôt et à la diffusion de documents scientifiques de niveau recherche, publiés ou non, émanant des établissements d’enseignement et de recherche français ou étrangers, des laboratoires publics ou privés.
Expressiveness of Full First Order Constraints in the Algebra of Finite or Infinite Trees
Alain Colmerauer, Thi-Bich-Hanh Dao
To cite this version:
Alain Colmerauer, Thi-Bich-Hanh Dao. Expressiveness of Full First Order Constraints in the Algebra
of Finite or Infinite Trees. Principles and Practice of Constraint Programming - CP 2000, 2000,
Singapore, Singapore. pp.172-186. �hal-00144924�
in the algebra of nite or innite trees
AlainColmerauerandThi-Bih-HanhDao
Laboratoired'InformatiquedeMarseille,CNRS,
UniversitésdelaMéditerranéeetdeProvene
Abstrat. Weareinterestedintheexpressivenessofonstraintsrepre-
sentedbygeneralrstorderformulae,withequalityasuniquerelational
symbolandfuntionalsymbolstakenfromaninnitesetF.Thehosen
domainisthe setof treeswhosenodes,inpossiblyinnitenumber,are
labeledbyelementsofF.Theoperationlinkedto eahelementf of F
isthe mapping(a1;:::;an)7!b,where bisthetree whoseinitial node
islabeledf andwhosesequeneofdaughtersisa
1
;:::;a
n .
Werstonsideronstraintsinvolvinglongalternatedsequenesofquan-
tiers9898::: .Weshowhowtoexpresswinningpositionsoftwo-partners
gameswithsuhonstraintsandapplyourresultstotwoexamples.
Wethen onstruta familyofstrongly expressiveonstraints, inspired
byaonstrutiveproofofaomplexityresultbyPawelMielnizuk.This
familyinvolvesthehugenumber(k),obtainedbyevaluatingtopdown
apowertowerof2's,ofheight k.Withelementsofthis family,ofsizes
at most proportional to k, we dene a nite tree having (k) nodes,
and we expressthe resultof aProlog mahine exeuting atmost (k)
instrutions.
By replaing the Prolog mahine by a Turing mahine we redisover
thefollowingresultofSergeiVorobyov:theomplexityofanalgorithm,
deidingwhether aonstraint withoutfreevariables istrue, annotbe
boundedabovebyafuntionobtainedbyniteompositionofelemen-
taryfuntionsinludingexponentiation.
Finally,takingadvantageofthefatthatwehaveatourdisposalanalgo-
rithmforsolvingsuhonstraintsinalltheirgenerality,weprodueaset
ofbenhmarksforseparating feasibleexamplesfrompurelyspeulative
ones.Amongotherswesolveonstraintsinvolvingalternatedsequenes
ofmorethan160quantiers.
1 Introdution
The algebra of (possibly) innite trees plays a fundamental at in omputer
siene:itisamodelfordatastrutures,programshemesandprogramexeu-
tions.Asearlyas1976,GérardHuetproposedanalgorithmforunifyinginnite
terms,thatissolvingequationsinthatalgebra[11℄.BrunoCourellehasstudied
thepropertiesof innitetreesin thesopeofreursiveprogramshemes[8,9℄.
AlainColmerauerhasdesribedtheexeutionofPrologII,IIIandIVprograms
trees[12℄.Amongothers,hehasshownthatinthistheory,andthusinthealgebra
ofinnitetrees, anyrstorder formulaisequivalenttoaBooleanombination
ofonjuntionsofequations(partiallyortotally)existentiallyquantied.Sergei
Vorobyovhas shown that the omplexity of an algorithm, deiding whether a
formulawithoutfreevariablesistrueinthattheory,annotbeboundedabove,
byafuntionobtainedbyniteomposition ofelementaryfuntions,inluding
exponentiation[14℄.PawelMielnizukhasshown asimilar resultin thetheory
offeaturetrees,but withamoreonstrutivemethod, whihhasinspiredsome
ofourexamples[13℄.
Wehavereentlydevelopedanalgorithmforsolvinggeneralrstorder on-
straints in the algebra of innite trees [10℄. The purpose of this paper is not
thepresentationofthisalgorithm,butofexamples,rstimaginedastests,then
extended to show the expressiveness of suh general onstrains. The paper is
organizedasfollows.
(1)Weendthisrstsetionbymakinglearthenotionsoftreealgebraand
rstorderonstraintsin thatalgebra.
(2) Inthe seond setion we onsider onstraintsinvolvinglongalternated
sequenesofquantiers9898:::. Weshowhowto expresswinning positions of
two-partnersgameswithsuhonstraintsandapplyourresultstotwoexamples.
(3) In the third setion, we investigate the most expressive family of on-
straintsweknow.Itinvolvesthetrulyhugenumber(k),obtainedbyevaluating
topdown atowerofpowersof2's,ofheightk.With elementsof thisfamily, of
sizes at mostproportionalto k, we denea nitetree having(k) nodes, and
weexpresstheresultofaPrologmahine exeutingatmost(k).Byreplaing
thePrologmahinebyaTuringmahineweredisovertheomplexityresultof
SergeiVorobyovmentionedatthebeginningofthissetion.This parthasbeen
stronglyinuenedbythework ofPawelMielnizuk[13℄.
(4)We onludebydisussions andbenhmarks separatingthefeasibleex-
amplesfromthepurelyspeulativeones.
1.1 The algebra ofinnite trees
Treesare well known objets in theomputer sieneworld. Here aresome of
them:
. . . . . .
0 1
0 1
0
0 0 0
ff s
f f
f f
f f
f f s s s s s
0 1 0 s
takenfromasetF offuntionalsymbols,whihweassumeto beinnite.Note
thatthersttreeistheonlyonehavinganitesetofnodes,butthattheseond
onehasstillanitesetof(patternsof)subtrees.WedenotebyAthesetofall
trees 1
onstrutedonF.
Weintroduein Aa set ofonstrutionoperations 2
, oneforeah element
f 2F whihisthemappings(a
1
;:::;a
n
)7!b,wherenisthearityoff andbthe
treewhoseinitialnodeislabeledf andthesequeneofdaughtersis(a
1
;:::;a
n )
andwhihbeshematizedas
1 1
. . . . . .
f
a a
a an
n
Wethusobtainthealgebraof innite treesonstrutedonF,whihwedenote
by(A ;F).
1.2 Treeonstraints
We are interested in the expressiveness of onstraints represented by general
rst order formulae, with equality as unique relational symbol and funtional
symbolstakenfrom aninnitesetF.These tree onstraintsare ofoneofthe9
forms:
s=t; true; false; :(p); (p^q); (p_q); (p!q); 9xp; 8xp;
where p andq are shorter treeonstraints, x avariable taken from aninnite
set ands;tterms,that areexpressionsofoneoftheforms
x; ft
1 :::t
n
wheren0,f 2F,witharityn,andthet
i
'sareshorterterms.
ThevariablesrepresentelementsofthesetAoftreesonstrutedonF and
thefuntionalsymbolsf areinterpretedasonstrutionoperationsinthealgebra
ofinnitetrees(A ;F).Thusaonstraintwithoutfreevariablesiseithertrueor
false anda onstraint p(x
1
;:::;x
n
) with nfree variablesx
i
establishan n-ary
relationinthesetoftrees.
1
Morepreiselywedenerstanodetobeawordonstrutedonthesetofstritly
positive integers. A tree a, onstruted onF, is thena mapping of type E !F,
where E isanon-emptysetofnodes,eahonei1:::i
k
(with k0) satisfyingthe
twoonditions:(1)if k>0then i
1 :::i
k1
2E,(2)if thearity ofa(i
1 :::i
k ) is n,
thenthesetofnodesofE ofthe formi1:::ikik+
1
is obtainedbygiving toik
+1 the
values1;:::;n.
2
Infat,theonstrutionoperationlinkedtothen-arysymbolfofF isthemapping
(a1;:::;an) 7!b,where the ai's are any trees and bis the treedened as follows
fromtheai's andtheirsetofnodesEi's:thesetE ofnodesof ais f"g[fixjx2
Ei andi21::ng and,foreahx2E,ifx=",thena(x)=f andifxisoftheform
iy,withibeinganinteger,a(x)=a(y).
We rst introdue the notions of k-winning and k-losing position in any two-
partners gamesandin twoexamples.Weshowhowto express,in any domain,
thesetofk-winningpositionsbyaonstraint.Weendthesetionbyexpressing
the k-winning positions of the two examples by tree onstraints involving an
alternatedembeddingof2k quantiers.
2.1 Winning positionsin a two-partners game
Let(V;E)beadiretedgraph,withV asetofvertiesandEV V asetof
edges. Thesets V and E maybe empty andthe elements ofV are alsoalled
positions. Weonsideratwo-partnersgamewhih,given aninitialpositionx
0 ,
onsists,oneafteranother,inhoosingapositionx
1
suhthat(x
0
;x
1
)2E,then
apositionx
2
suh that(x
1
;x
2
)2E,thenapositionx
3
suhthat (x
2
;x
3 )2E
andsoon... Therstonewhoannotplayanymorehaslostandtheotherone
has won. For example thetwo following innitegraphs orrespond to the two
followinggames:
1
0 2 3 4 5 6
0,0 1,0 2,0 3,0
0,1 1,1 2,1 3,1
0,2 1,2 2,2 3,2
0,3 1,3 2,3 3,3
Game 1Anon-negativein-
tegeriisgivenand,oneafter
another, eah partner sub-
trats1or2fromi,butkeep-
ing i non-negative.Therst
person whoannot play any
morehaslost.
Game 2 An ordered pair (i;j) of non-negative
integers is given and, one after another, eah
partner hoosesoneoftheintegersi;j.Depend-
ing onthefat that thehosenintegeruisodd
oreven,hetheninreasesordereasestheother
integerv by1,but keepingv non-negative.The
rstpersonwhoannotplayanymorehaslost.
Letx2V beanyvertexofthedireted graph(V;E)andsupposethat itis
theturnofpersonAtoplay.Thepositionxissaidtobek-winningif,nomatter
thewaytheotherperson B plays,itis alwayspossiblefor Ato winin making
at mostkmoves.Thepositionx is saidtobek-losingif, nomatterthewayA
plays,B analwaysforeAtoloseand toplayatmostkmoves.
Considerthe twopreeding graphs and mark with +k the positions whih
are k-winningand with k thepositions whih are k-losing, witheah time k
being as small aspossible. Vertex 0of the rst graphand vertex (0;0) of the
ndsuessivelythesetofvertiestobemarkedby+1,then 1,then+2,then
2,then+3, then 3,andsoon.Weget
-0 +1 +1 -1 +2 +2 -2
-0 +1 -1 +2 -2 +3
+1 +2 +3
+3 +3 +3 +3 -2 +2 -1 +2
-2 -3
-3 -2
andonvineourselvesthattheset ofk-winningpositionsofgame1is
fi2Nji<3kandimod36=0g
andofgame2
f(i;j))2N 2
ji+j<2kand(i+j)mod2=1}:
whereNisthesetofnon-negativeintegers.
2.2 Expressingk-winningpositions bya onstraint
LetD beadomain, that isanon-emptysetand letG=(V;E)thegraphofa
two-partnersgame, withV D.We willexpress thek-winningpositions ofG
byaonstraintinDinvolvinganembedding989:::of2kalternatedquantiers.
Letus introdueinD thepropertiesmove,winning
k
et losing
k
,dened by
move(x;y) $(x;y)2E;
winning
k
(x)$x isak-winningpositionofG;
losing
k
(x) $x isak-losingpositionofG:
(1)
InDwethenhavetheequivalenes,forallk0:
winning
0
(x) $false;
winning
k +1
(x)$9ymove(x;y)^losing
k (y);
losing
k
(x) $8ymove(x;y)!winning
k (y):
(2)
Contrarytowhat wemaybelieve,itfollowsthatwehave:
winning
k
(x)!winning
k+1
(x); losing
k
(x)!losing
k+1 (x):
Indeed, from the rst and the last equivalene of (2) we onlude that these
impliationsholdfork=0and,ifweassumethattheyholdforaertaink0,
k
winning
k (x) $
2
6
6
6
6
6
6
6
6
6
6
6
6
6
6
4
9ymove(x;y)^:(
9xmove(y;x)^:(
9ymove(x;y)^:(
9xmove(y;x)^:(
:::
9ymove(x;y)^:(
9xmove(y;x)^:(
false ):::)
|{z}
2k 3
7
7
7
7
7
7
7
7
7
7
7
7
7
7
5
(3)
whereofourseallthequantiersapplyonelementsofD.Bymovingdownthe
negations,wethusgetanembeddingof2k alternatedquantiers.
Inequivalene (3) it is possible to use a moregeneral denition of move
than the one given in (1). We rst remark, that for any non-negative k, the
followingpropertyholds:
Property 1 Let three direted graphs be of the form G
1
= (V
1
;E
1 ), G
2
=
(V
2
;E
2
)andG=(V
1 [V
2
;E
1 [E
2
).ThegraphsG
1
andGhavethesamesetof
k-winningpositions, ifboth:
1. thesetsof vertiesV
1 andV
2
aredisjoint,
2. forallx2V
2
, thereexistsy2V
2
with(x;y)2E
2 .
Indeed,from therst onditionitfollowsthatE
1 andE
2
aredisjointandthus
that the set of k-winning positions of G is the union of the set of k-winning
positionsofG
1
withthesetofk-winningpositionsofG
2
.Thislastsetisempty
beauseoftheseondondition.
Itfollowsthat:
Property 2(Generalizedmove relation) Equivalene(3)holdsalsoforany
move relationobeyingtothe twoonditions:
1. forallx2V andy2V, move(x;y) $ (x;y)2E,
2. forallx2D V there existsy2D V suhthat move(x;y).
2.3 Formalizinggame 1in the algebraof innitetrees
Wenowreonsidergame1introduedin setion2.1.AsdomainD wetakethe
set A of trees onstruted on a set F of funtional symbolsinluding among
others thesymbols0;s, of respetivearities 0;1.We odethe vertiesi of the
gamegraphbythetrees 3
s i
(0).LetG=(V;E)bethegraphobtainedthisway.
As generalized relation move we then antake in the algebra of innite
trees:
move(x;y) def
= x=s(y)_x=s(s(y))_(:(x=0)^:(9ux=s(u))^x=y)
3 0 i+1 i
ofsolutionsinxof theonstraintwinning
k
(x) denedin(3).
Forexample,withk=1theonstraintwinning
k
(x) isequivalentto
x=s(0)_x=s(s(0))
andwithk=2to
x=s(0)_x=s(s(0))_x=s(s(s(s(0))))_x=s(s(s(s(s(0)))))
2.4 Formalizinggame 2in the algebraof innitetrees
Wealsoreonsidergame2introdued insetion2.1. AsdomainDwetakethe
set A of trees onstruted on a set F of funtional symbolsinluding among
others thesymbols0;f;g;,of respetivearities0;1;1;2.Weodethe verties
(i;j)of thegame graphby thetrees (i;j)with i= (fg) i
2
(0) ifi is even, and
i=g(i 1)ifiisodd 4
. LetG=(V;E)bethegraphobtainedthis way.
Theperspiaiousreaderwill onvinehimself that, asgeneralizedrelation
move,weantakeinthealgebraofinnitetrees:
move(x;y) def
= transition(x;y)_(:(9u9vx=(u;v))^x=y)
with
transition(x;y) def
= 2
6
6
6
6
6
6
4
9u9v9w
(x=(u;v)^y=(u;w))_
(x=(v;u)^y=(w;u))
^
(9iu=g(i)^su(v;w))_
(:(9iu=g(i))^pred(v;w))
3
7
7
7
7
7
7
5
su(v;w)
def
=
((9jv=g(j))^w=f(v))_
(:(9jv=g(j))^w=g(v))
pred(v;w) def
= 2
6
6
6
6
6
4
(9jv=f(j)^
(9kj=g(k)^w=j)_
(:(9kj=g(k))^w=v)
)_
(9jv=g(j)^
(9kj=g(k)^w=v)_
(:(9kj=g(k))^w=j)
)_
(:(9jv=f(j))^:(9jv=g(j))^:(v=0)^w=v) 3
7
7
7
7
7
5
Aordingto property2,theset of k-winningpositions ofgame 2is theset of
solutionsinx oftheonstraintwinning
k
(x)dened in(3).
Forexample,withk=1theonstraintwinning
k
(x) isequivalentto
x=(g(0);0)_x=(0;g(0)))
andwithk=2to
x=(0;g(0))_x=(g(0);0)_x=(0;g(f(g(0))))_
x=(g(0);f(g(0)))_x=(f(g(0));g(0))_x=(g(f(g(0)));0)
4
0 i+1 i
Afterallthesequantiers,wemoveto onstraints,whih aresoexpressivethat
theirsolvingbeomesquasi-undeidable.
3.1 Dening a huge nitetreeby a onstraint
Weset(k)=2 2
: :
: 2
,withk ourrenesof2.Morepreiselywetake
(0)=1; (k+1)=2 (k )
;
withk0.Thefuntioninreasesinastunningway,sine(0)=1,(1)=2,
(2) = 4, (3) = 16, (4) = 65536 and (5) = 2 65536
. Thus (5) is greater
than10 20000
,anumberprobablymuhgreaterthanthenumberofatomsofthe
universeorthenumberofnanoseondswhihelapsedsineitsreation!
Wesuppose that the set Aof trees isonstruted ona set F of funtional
symbolsinludingamong others thesymbols0;1;2;3;s;f,of respetivearities
0;0;0;0;1;4.Fork0letusintroduetheonstraint:
huge
k (x)
def
= 9z triangle
k
(3;x;z;0)
withstillfork0,
triangle
0
(t;x;z;y) def
= z=x^z=y
triangle
k +1
(t;x;z;y) def
= 2
6
6
6
6
6
6
6
6
6
6
6
6
6
6
4 [9u
1 9u
2
z=f(x;u
1
;u
2
;y)℄
^
2
6
6
6
6
6
6
6
6
6
6
4 8t
0
8y 0
8z 0
(t 0
=1_t 0
=2)^
triangle
k (t
0
;z;z 0
;y 0
)
!
2
6
6
6
6
4 (t
0
=1^form1(y 0
))_
(t 0
=2^ 2
6
6
4
9u9v form2(u;y 0
;v)^
(t=1!trans1(u;v))^
(t=2!trans2(u;v))^
(t=3!trans3(u;v)) 3
7
7
5 3
7
7
7
7
5 3
7
7
7
7
7
7
7
7
7
7
5 3
7
7
7
7
7
7
7
7
7
7
7
7
7
7
5 (4)
and
form1(x) def
= 9u
1 :::9u
4
x=f(u
1
;f(u
2
;u
2
;u
2
;u
2 );f(u
3
;u
3
;u
3
;u
3 );u
4 )
form2(x;z;y) def
= 9u
1 :::9u
6 z=f(u
1
;f(u
1
;u
2
;u
3
;x);f(y;u
4
;u
5
;u
6 );u
6 )
trans1(x;y) def
= 9u
1 :::9u
4 x=f(u
1
;u
2
;u
3
;u
4
)^(y=u
2
_y=u
3 )
trans2(x;y) def
= trans1(x;y)_x=y
def