HAL Id: hal-00459195
https://hal.archives-ouvertes.fr/hal-00459195
Submitted on 23 Feb 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.
Programming Environments
Willy Lesaint
To cite this version:
Willy Lesaint. Value Withdrawal Explanations: a Theoretical Tool for Programming Environments.
12th Workshop on Logic Programming Environments, 2002, Denmark. pp.17-33. �hal-00459195�
WillyLesaint
Laboratoired'InformatiqueFondamentaled'Orleans
rueLeonarddeVini{BP6759 {F-45067OrleansCedex2{Frane
Willy.Lesaintlifo.univ-orlea ns.f r
Abstrat. Constraintlogiprogrammingombinesdelarativityandef-
ienythanks to onstraint solvers implementedfor spei domains.
ValuewithdrawalexplanationshavebeeneÆientlyusedinseveralon-
straintsprogrammingenvironmentsbuttheredoesnotexistanyformal-
izationofthem.Thispaperisanattempttollthis lak.Furthermore,
wehopethatthistheoretialtoolouldhelptovalidatesomeprogram-
mingenvironments.Avaluewithdrawalexplanationisatreedesribing
thewithdrawalofavalueduringadomainredutionbyloalonsisteny
notionsandlabeling.Domainredutionisformalizedbyasearhtreeus-
ingtwokindsofoperators:forloalonsistenynotionsandforlabeling.
Theseoperators are dened by setsof rules.Proof trees are builtwith
respettotheserules.Foreahremovedvalue,thereexistssuhaproof
treewhihisthewithdrawalexplanationofthisvalue.
1 Introdution
Constraintlogiprogrammingisoneofthemostimportantomputingparadigms
of the last years. It ombines delarativity and eÆieny thanks to onstraint
solvers implemented for spei domains. The needs in programming environ-
ments is growing. But logi programming environments are not always suÆ-
ient to deal with the onstraint side of onstraint logi programming. Value
withdrawal explanations have been eÆiently used in several onstraints pro-
gramming environments but there does not exist any formalization of them.
This paperisanattemptto llthislak.This workis supportedbythefrenh
RNTL 1
projetOADymPPaC 2
whoseaimistoprovideonstraintprogramming
environments.
Avaluewithdrawalexplanationisatreedesribingthewithdrawalofavalue
duringadomainredution.Thisdesriptionisdoneintheframeworkofdomain
redutionofnite domainsbynotionsofloalonsistenyandlabeling. Arst
work[7℄dealtwithexplanationsin theframeworkofdomainredutionbyloal
onsisteny notions only. A value withdrawal explanation ontains the whole
1
ReseauNationaldesTehnologiesLogiielles
2
Outils pour l'Analyse Dynamique et la mise auPoint de Programmes ave Con-
informationaboutaremovalandmaythereforebeausefultoolforprogramming
environments.Indeeditallowsperforming:
{ failureanalysis:afailureexplanationbeingasetofvaluewithdrawalexpla-
nations;
{ onstraintretration:explanationsprovidethevalueswhihhavebeenwith-
drawndiretlyorindiretlybytheonstraintandthenallowtoeasilyrepair
thedomains;
{ debugging:anexplanationbeingakindofdelarativetraeofavaluewith-
drawal,itanbeusedtondanerrorfromasymptom.
Therstandseond itemhavebeenimplementedinthePaLMsystem[8℄. PaLM
is basedon the onstraint solver hoo [9℄ where labeling is replaed by the
use ofexplanations. Note that theonstraintretration algorithmof PaLMhas
beenproved orret thanksto ourdenition of explanations, and moregener-
allya largefamily ofonstraintretration algorithms arealso inluded in this
framework.
Themainmotivationofthisworkisnotonlytoprovideaommonmodelfor
the partners of theOADymPPaC projet but also to use explanationsfor the
debuggingofonstraintsprograms.Nevertheless,theaimofthispaperisnotto
desribetheappliationsofvaluewithdrawalexplanationsbuttoformallydene
thisnotionofexplanation.
ThedenitionofaConstraintSatisfationProblemisgiveninthepreliminary
setion.Inthirdandfourthsetionsatheoretialframeworkfortheomputation
ofsolutionsisdesribedinsetions3and4.Aomputationisviewedasasearh
tree where eah branh is an iteration of operators. Finally, explanations are
presentedinthelastsetionthankstothedenitionofrulesassoiatedtothese
operators.
2 Preliminaries
Following[10℄,aConstraintSatisfation Problem (CSP)is made oftwoparts:
a syntati part and a semanti part. The syntati part is a nite set V of
variables, a nite set C of onstraints and afuntion var: C ! P(V), whih
assoiatesasetofrelatedvariablestoeahonstraint.Indeed,aonstraintmay
involveonlyasubsetof V.
Forthesemantipart,weneedtointroduesomepreliminaryonepts.We
onsidervariousfamiliesf =(f
i )
i2I
.Suhafamilyisreferredtobythefuntion
i7!f
i
orbytheset f(i;f
i
)ji2Ig.
Eahvariableis assoiatedwith aset ofpossiblevalues.Therefore,weon-
siderafamily(D
x )
x2V
whereeahD
x
isanite nonempty set.
Wedene the domain by D = S
x2V
(fxgD
x
). This domain allowssim-
pleand uniformdenitionsof (loalonsisteny)operatorsonapower-set.For
domain redution,weonsider subsetsdof D. Suh asubset isalled an envi-
ronment.Wedenote by dj
W
therestritionof asetdD to asetof variables
W V, that is, dj = f(x;e)2 dj x 2 Wg.Any d D is atually afamily
(d
x )
x2V
with d
x D
x
:forx2V, wedened
x
=fe2D
x
j(x;e)2dgandall
ittheenvironmentof x.
Constraintsare dened bytheirset of allowed tuples.A tuple t onW V
is a partiular environment suh that eah variable of W appears only one:
t Dj
W
and 8x2 W;9e2 D
x
;tj
fxg
=f(x;e)g. Foreah 2 C, T
is aset of
tuplesonvar(), alledthesolutionsof.
Wean nowformallydeneaCSP.
Denition1. A ConstraintSatisfationProblem (CSP)isdenedby:
{ anite setV ofvariables;
{ anite setC of onstraints;
{ afuntion var:C!P(V);
{ thefamily (D
x )
x2V
(thedomains);
{ afamily (T
)
2C
(theonstraintssemantis).
Notethatatuplet2T
isequivalenttothefamily(e
x )
x2var()
andthattis
identiedwithf(x;e
x
)jx2var()g.
A user is interested in partiular tuples (onV) whih assoiatea value to
eahvariable,suh thatalltheonstraintsaresatised.
Denition2. A tuplet onV isa solutionofthe CSP if82C ;tj
var() 2T
.
Example 1. Confereneproblem
Mike, Peter and Alan want to give a talk about their work to eah other
during threehalf-days.PeterknowsAlan'sworkandvie versa.There arefour
talks(andsofourvariables):MiketoPeter(MP),PetertoMike(PM),Miketo
Alan(MA)andAlantoMike(AM). Notethat MikeannotlistentoAlanand
Petersimultaneously(AM6=PM).Mikewantsto knowtheworksofPeterand
Alanbeforetalking(MA>AM,MA>PM,MP>AM,MP>PM).
Thisanbewritten inGNU-Prolog[4℄(withalabelingonPM)by:
onf(AM,MP,PM,MA):-
fd_domain([MP,PM,MA,AM℄,1,3),
MA #> AM,
MA #> PM,
MP #> AM,
MP #> PM,
AM #\= PM,
fd_labeling(PM).
Thevalues1;2;3orrespondstotherst,seondandthirdhalf-days.Notethat
thelabelingonPM issuÆientto obtainthesolutions.Withoutthis labeling,
thesolverprovidesredueddomainsonly(nosolution).
Thisexamplewillbeontinuedthroughoutthepaper.
Theaimofasolveristoprovideone(ormore)solutions.Inordertoobtain
notionsandlabeling.Therstoneisorretwithrespettothesolutions,thatis
itonlyremovesvalueswhihannotbelongtoanysolution,whereastheseond
oneis usedto restritthesearhspae. Notethat to doalabelingamounts to
utting aproblemin severalsub-problems.
Inthenextsetion,wedonotonsiderthewholelabeling(thatisthepassage
from aproblem toaset ofsub-problems)but onlythepassagefrom aproblem
tooneofitssub-problems.Thewholelabelingwillbeonsiderinsetion4with
thewell-knownnotionofsearhtree.
3 Domain redution mehanism
Inpratie, operatorsare assoiatedwith theonstraintsandare applied with
respettoapropagationqueue.Thismethodisinterleavedwithsomerestrition
(dueto labeling).Inthis setion,thisomputationof areduedenvironmentis
formalized thanksto ahaoti iterationof operators. Theredution operators
anbeoftwotypes:operatorsassoiatedwithaonstraintandanotionofloal
onsisteny,andoperatorsassoiatedwith arestrition.Theresultingenviron-
mentisdesribedin termsoflosureensuringonuene.
Domainredutionwithrespettonotionsofonsistenyanbeexpressedin
termsof operators.Suh an operatoromputes aset of onsistent valuesfora
set ofvariables W
out
aordingtothe environmentsofanother setof variables
W
in .
Denition3. Aloalonsistenyoperatoroftype(W
in
;W
out
),withW
in
;W
out
V isamonotoni funtion f :P(D)!P(D) suhthat:8dD,
{ f(d)j
VnW
out
=Dj
VnW
out ,
{ f(d)=f(dj
Win )
Notethat therst itemensures that theoperator isonlyonerned bythe
variables W
out
. The seond one ensures that this result only depends on the
variableW
in .
TheseoperatorsareassoiatedwithonstraintsoftheCSP.Soeahoperator
mustnotremovesolutionsofitsassoiatedonstraint(andofourseoftheCSP).
Thesenotionsoforretionaredetailedin[6℄.
Example 2. In GNU-Prolog, two loal onsisteny operators are assoiated
with the onstraint MA #> PM: the operator whih redues the domain of MA
withrespettoPMand theonewhihredues thedomainofPMwith respet
to MA.
Fromnowon,wedenotebyLasetofloalonsistenyoperators(thesetof
loalonsistenyoperatorsassoiatedwiththeonstraintsoftheCSP).
Domain redution by notions of onsisteny alone is not always suÆient.
Theresultingenvironmentisanapproximationof thesolutions(thatis allthe
(forexample,bythehoie ofavalueforavariable).Ofourse,suharestri-
tion(formalizedbytheappliationof arestritionoperator) doesnothavethe
propertiesoforretnessofaloalonsistenyoperator:theappliationofsuh
anoperatormayremovesolutions.But,inthenextsetion,theseoperatorswill
beonsidered asaset (orresponding to thewhole labeling onavariable). In-
tuitively, if weonsider alabelingsearh tree, this setiondealswith onlyone
branh ofthistree.
Inthe same way loal onsisteny operators have beendened, restrition
operatorsarenowintrodued.
Denition4. A restrition operator on x 2 V is a onstant funtion f :
P(D)!P(D) suhthat:8dD;f(d)j
Vnfxg
=Dj
Vnfxg .
Example 3. The funtion f suhthat 8d 2D;f(d) =Dj
VnfPMg
[f(PM;1)gis
arestritionoperator.
FromnowonwedenotebyRasetofrestritionoperators.
Thesetwokindofoperatorsaresuessivelyappliedtotheenvironment.The
environmentis replaedbyitsintersetion withtheresultoftheappliation of
theoperator.WedenotebyF theset ofoperatorsL[R .
Denition5. The redutionoperatorassoiatedwiththeoperator f 2F isthe
monotoni andontratingfuntion d7!d\f(d).
A ommon x-point of theredution operators assoiated with F starting
from an environmentd is an environmentd 0
dsuh that 8f 2 F;d 0
= d 0
\
f(d 0
),thatis8f 2F;d 0
f(d 0
). Thegreatestommonx-pointisthisgreatest
environmentd.Tobemorepreise:
Denition6. The downwardlosureof dby F ismaxfd 0
D jd 0
d^8f 2
F;d 0
f(d 0
)g andisdenotedbyCL#(d;F).
NotethatCL#(d;;)=dandCL#(d;F)CL#(d;F 0
)ifF 0
F.
Inpratie, the order of appliation of these operators is determined by a
propagation queue. It is implemented to ensuresto never forget any operator
and to alwaysreah thelosure CL #(d;F). From atheoretialpoint ofview,
thislosure analsobeomputedbyhaoti iterations introduedforthis aim
in [5℄.Thefollowingdenition istakenfrom Apt[2℄.
Denition7. A run is an innite sequene of operators of F, that is, a run
assoiates with eah i 2 IN (i 1) an element of F denoted by f i
. A run is
fair if eah f 2F appears init innitely often, that is, 8f 2F;fijf =f i
gis
innite.
The iteration of the set of operators F from the environment d D with
respettoaninnitesequeneofoperatorsofF:f 1
;f 2
;:::istheinnitesequene
d 0
;d 1
;d 2
;:::indutively denedby:
0
2. foreahi2IN,d i+1
=d i
\f i+1
(d i
).
Its limitis\
i2IN d
i
.
Ahaotiiteration isaniteration with respet toasequene ofoperators of
F (with respettoF,inshort)where eahf 2F appearsinnitely often.
Note that an iteration may start from a domain d whih an be dierent
from D. Thisis moregeneralandonvenientforalotof appliations(dynami
aspetsofonstraintprogramming,forexample).
Thenextwell-knownresultofonuene[3,5℄ensuresthatanyhaotiiter-
ation reahes thelosure. Notethat, sineis awell-foundedordering(i.e. D
is anite set), everyiterationfrom d D is stationary, that is, 9i 2 IN ;8j
i;d j
=d i
.
Lemma1. Thelimitd F
ofeveryhaoti iteration ofasetof operatorsF from
dD isthe downwardlosureof dby F.
Proof. Let d 0
;d 1
;d 2
;::: be a haoti iteration of F from d with respet to
f 1
;f 2
;:::
[CL#(d;F)d F
℄Foreahi,CL#(d;F)d i
,byindution:CL#(d;F)
d 0
=d.Assume CL#(d;F)d i
,CL#(d;F)f i+1
(CL#(d;F))f i+1
(d i
)
bymonotoniity.Thus,CL#(d;F)d i
\f i+1
(d i
)=d i+1
.
[d F
CL #(d;F)℄ There exists k 2 IN suh that d F
= d k
beause isa
well-foundedordering.Theiterationishaoti, hened k
isaommonx-point
of theset of operators assoiated withF, thusd k
CL #(d;F)(the greatest
ommonx-point).
Inorder toobtain alosure,it isnot neessaryto haveahaotiiteration.
Indeed,sinerestritionoperatorsareonstantfuntions,theyanbeapplyonly
one.
Lemma2. d L[R
=CL#(CL#(d;R );L)
Proof. d L[R
=CL#(d;L[R )bylemma1andCL#(d;L[R )=CL#(CL#
(d;R );L)beauseoperatorsofRareonstantfuntions.
Assaidabove,wehaveonsidered in thissetionaomputation inasingle
branh of a labeling searh tree. This formalization is extended in the next
setioninorder totakethewholesearhtreeintoaount.
4 Searh tree
A labelingonavariable anbe viewedasthepassagefromaproblem to aset
ofproblems.Theprevioussetionhastreatedthepassagefromthisproblem to
oneofitssub-problemsthankstoarestritionoperator.Inordertoonsiderthe
whole set ofpossiblevaluesfor thelabelingonavariable, restritionoperators
on asame variable must be grouped together. The unionof the environments
of the variable (the variable onerned by the labeling) of eah sub-problem
obtainedbytheappliationofeahoftheseoperatorsmustbeapartitionofthe
Denition8. A setfd
i
j1ingisa partitionofdonx if:
{ 8i;1in; dj
Vnfxg d
i j
Vnfxg ,
{ dj
fxg [
1in d
i j
fxg ,
{ 8i;j;1in;1jn;i6=j;d
i j
fxg
\d
j j
fxg
=;.
Inpratie,environmentredutionsbyloalonsistenyoperatorsandlabel-
ingareinterleavedtobethemosteÆient.
A labeling onx 2 V an bea omplete enumeration (eah environment of
the partition isredued to asingleton)ora splitting.Note that the partitions
alwaysverify:8i;1in;d
i j
fxg 6=;.
Example 4. fDj
VnfPMg
[f(PM;1)g;Dj
VnfPMg
[f(PM;2)g;Dj
VnfPMg
[f(PM;3)g
isapartitionofD.
Next lemma ensures that no solution is lost during a labeling step (eah
solutionwillremaininexatlyonebranh ofthesearhtreedenedlater).
Lemma3. If tdisasolutionof the CSPandfd
i
j1ingisapartition
of dthent[
1in
CL#(d
i
;L).
Proof. straightforward.
Eahnodeofasearhtreeanbeharaterizedbyaquadrupleontainingthe
environmentd(whihhavebeenomputeduptonow),thedepthpinthetree,
the operator f (loal onsisteny operator or restrition operator) onneting
itwith itsfatherandtherestritedenvironmente.Therestritedenvironment
isobtainedfromtheinitial environmentwhenonlytherestritedoperatorsare
applied.
Denition9. A searh node is a quadruple (d;e;f;p) with d;e 2 P(D) , f 2
F[f?gandp2IN.
Thedepth andthe restritedenvironmentallowto loalizethenodein the
searhtree.
Thereexiststwokindsoftransition inasearhtree:thoseaused byaloal
onsisteny operatorwhih ensurethe passageto oneonly sonand thetransi-
tionsaused by alabelingwhih ensurethepassage to somesons(as many as
environmentsinthepartition).
Denition10. A searh tree is a tree for whih eah node is a searh step
indutivelydenedby:
{ (D;D;?;0) isthe rootof the tree,
{ if(d;e;op;p) isanon leavenode thenithas:
oneson:(d\f(d);e;f;p+1)with f 2L;
nsons:(d\f
i
(d);e\f
i (d);f
i
;p+1)with ff
i
(d)j1ingapartition
of dandf
i 2R .
Denition11. A searh tree is said omplete if eah leaf (d;e;f;p) is suh
that:d=CL#(e;L).
This setion hasformally desribedthe omputation of solversin terms of