17 October 2006 Foundations of Logic and Constraint Programming 1 Declarative Semantics An overview...
-
date post
22-Dec-2015 -
Category
Documents
-
view
224 -
download
1
Transcript of 17 October 2006 Foundations of Logic and Constraint Programming 1 Declarative Semantics An overview...
17 October 2006 Foundations of Logic and Constraint Programming 1
Declarative Semantics
Anoverview
• Algebras(semanticsforterms)
• Interpretations(semanticsforprograms)
• SoundnessofSLD-Resolution
• CompletenessofSLD-Resolution
• LeastHerbrandModels
• ComputingleastHerbrandModels
17 October 2006 Foundations of Logic and Constraint Programming 2
Algebras
Informally,analgebraassignsvaluesofconstantsandfunctionstoelementsofa
certaindomain(forexample,theusualalgebraforthenaturalnumbersN,assigns
tofunction+(3,1))thevalue4).Moreformally
- GivenasetofVariablesV,andarankedalphabetFoffunctionsymbols,
AnalgebraJforF(orF-algebraorpre-interpretationforF)consistsof:
1. domain:non-emptysetD
2. Assignmentofamapping
fJ : Dn D
toeveryf F (n)(withn0)
- StateσoverD:mappingσ : V D
- Extensionofσ toTUF,V:
σ: TUF,V D suchthatforevery f F (n)
σ(f(t1, ... , tn)) = fJ (σ(t1), ... , σ(tn))
17 October 2006 Foundations of Logic and Constraint Programming 3
Interpretations
Informally,aninterpretationassignstrueorfalsetopredicatesoveritsarguments,
which are elements of a domain (or terms pre-interpreted by an algebra). For
example,(+(3,1),2)istrueintheusualinterpretationof/2).Moreformally
- GivenarankedalphabetFoffunctionsymbols,andarankedalphabetofpredicatesymbols
- AninterpretationIforFandconsistsof:
1. AlgebraJforF(withdomainD)
2. AssignmentofarelationpI D D ... D toeveryp (n)(withn0)
- Note:GivenapredicatepwithnargumentsinD,thisdefinitionisequivalent
tomappingthepredicateinto
• trueifthen-tupleisamemberofintherelationpI
• falseifthen-tupleisnotamemberoftherelationpI
n
17 October 2006 Foundations of Logic and Constraint Programming 4
Interpretations
LetPaddbethe”add-program”
add(0,M,M). add(s(M),N,s(K)):- add(M,N,K).
I1, I2, I3, I4, I5and I6areall legitimate (ifnotall “conventional”) interpretations forthesetsF={0,s/1}and={add/3}
- I1 : DI1 = N, 0I1 = 0, sI1(n) = n+1 f.e. n N
addI1 = {(m,n,m+n) | m, n N }
Note:Thisistheusualinterpretationwheretermsareinterpretedtonumbersandaddis“addition”
- I2 : DI2 = N, 0I2 = 0, sI2(n) = n+1 f.e. n N
addI2 = {(m,n,m*n) | m, n N }
Note:Inthisinterpretation,“additionisinfactmultiplication”.
- I3 : DI3 = HU{s,0}, 0I3 = 0, sI3(t) = s(t) f.e. t HU{s,0},
addI3 = {(sm(0), sn(0), sm+n(0),) | m, n N }
Note:ThisistheinterpretationofadditioninthePeanoalgebraforintegers.
17 October 2006 Foundations of Logic and Constraint Programming 5
Interpretations
LetPaddbethe”add-program”
add(0,M,M).add(s(M),N,s(K)):- add(M,N,K).
- I4 : DI4 = HU{s,0}, 0I4 = 0, sI4(t) = s(t) f.e. t HU{s,0},
addI4 = { }
Note:Inthisinterpretation,“Peanonumberscannotbeadded”.
- I5 : DI5 = HU{s,0}, 0I5 = 0, sI5(t) = s(t) f.e. t HU{s,0},
addI5 = (HU{s,0} )3
Note:Inthisinterpretation,“anythinggoes”,sinceanytripleoftermsisinthemodel.
- I6 : DI6 = {0,1} 0I6 = 0, sI6(n) = n f.e. n { 0,1}
addI6 = {(m,n,n) | m, n { 0,1}
Note: in this interpretation forabooleandomain,s is the identity function,andadd“selectsofthesecondargument”.
17 October 2006 Foundations of Logic and Constraint Programming 6
Logical Truth (1)
ExpressionE:Eisanatom,query,clauseorresultant
GivenanexpressionE,aninterpretationIandastateσ
E truein I under σ,written I |= σ E
:
BycaseanalysisonE:
I |= σ p(t1, ... , tn) :(σ(t1), ... , σ(tn)) pI (atom)
I |= σ A1, ... , An :I |= σ A1, ... , I |= σ An (query)
I |= σ A ← B :ifI |= σ B then I |= σ A (clause)
I |= σ A ← B :ifI |= σ B then I |= σ A (resultant)
17 October 2006 Foundations of Logic and Constraint Programming 7
Logical Truth (2)
GivenanexpressionE,andaninterpretationI:
Letx1,...,xkbethevariablesoccurringinE
x1, xkE:UniversalclosureofE(abreviatedE
x1, xkE:ExistentialclosureofE(abreviated E
I |= E :ifI |= σ E foreverystateσ
I |= E :ifI |= σ E forsomestateσ
WhenI |= Ewesaythat
• I isamodelof E;or
• E istruein I.
17 October 2006 Foundations of Logic and Constraint Programming 8
Logical Truth (3)
GivensetsofexpressionsSandT,andaninterpretationI:
I isamodelof S (written I |= S )
:I |= E foreveryE S
T is a semantic (orlogical)consequenceof S, (written S |= T )
:everymodelofSisamodelofT
GivenaprogramP,aqueryQ0andasubstitution
| var(Q0) isacorrect answer substitution ofQ0
:P |= Q0
Q0 is acorrect instanceofQ0
:P |= Q0
17 October 2006 Foundations of Logic and Constraint Programming 9
Models (Example)
LetPaddbethe”add-program”
add(0,M,M).add(s(M),N,s(K)):- add(M,N,K).
- I1 : DI1 = N, 0I1 = 0, sI1(n) = n+1 ;addI1 = {(m,n,m+n) | m, n N }
- I1 |= PaddasI1 |= c foreveryclause c of Paddandstateσ : V N.Infact
(i)(σ(0), σ(x), σ(x)) add I1;and
(ii)if(σ(M), σ(N), σ(K)) add I1 then(σ(M)+1, σ(N), σ(K)+1) add I1
- I2 : DI2 = N, 0I2 = 0, sI2(n) = n+1 ; addI2 = {(m,n,m*n) | m, n N }
- I2 | Padd.Tocheckthisletσ(M) = 1.ThenI2 |σ add(0,M,M)since(σ(0), σ(M), σ(M))=(0,1,1)addI2 (inotherwords,0*11)
- I3 : DI3 = HU{s,0}, 0I3 = 0, sI3(t)=s(t) ; addI3={(sm(0),sn(0),sm+n(0),)|m,n N }
- I3 |= Padd like for I1. SincethedomainD is theHerbrandUniverseof terms,
thisinterpretationisa(least)HerbrandModel.
17 October 2006 Foundations of Logic and Constraint Programming 10
Models (Example)
add(0,M,M).add(s(M),N,s(K)):- add(M,N,K).
- I4 : DI4 = HU{s,0}, 0I4 = 0, sI4(t) = s(t) f.e. t HU{s,0}, addI4 = { }
- I4 | Padd.Tocheckthisletσ(M) = 1.ThenI4 |σ add(0,M,M)since(σ(0),
σ(M), σ(M))=(0,1,1)addI4 = { }.
- I5 : DI5 = HU{s,0}, 0I5 = 0, sI5(t) = s(t) f.e. t HU{s,0}, addI5 = (HU{s,0} )3
- I5 | Padd as any triple, (σ(0), ỤỴ(M), σ(M)) or (s(σ(M)), σ(N)), s(σ(K)),
belongs to addI5. SinceDI5 is the Herbrand Universe, I5 is a Herbrand
Model.However,itisnotaleastmodel,sinceaddI5includesmoretriples
thanstrictlynecessary(addI2 addI5)
- I6 : DI6 = {0,1} 0I6 = 0, sI6(n) = n;addI6 = {(m,n,n) | m, n { 0,1}
- I6 |= Padd.LikeforI1.
(i)(σ(0), σ(x), σ(x)) add I6;and
(ii)if(σ(M), σ(N), σ(K)) add I6 then(σ(M), σ(N), σ(K)) add I6
17 October 2006 Foundations of Logic and Constraint Programming 11
Semantic Consequences (Example)
add(0,M,M).add(s(M),N,s(K)):- add(M,N,K).
- Padd |= add(0,x,x)
- ForeveryinterpretationI,ifI |= PaddthenI |= Paddsinceadd(0,x,x)Padd.
- Padd |= add(s(0),x,s(x))
- ForeveryinterpretationI,ifI |= Paddthen
(i)I |= add(0,x,x) ;and
(ii) I |= add(s(0),x,s(x)) ← add(0,x,x).
- Hence, I |= add(s(0),x,s(x)) .
- Padd | add(x,0,x)
- ConsiderinterpretationI6,(thatselectsthesecondelement).Although
I6 |= Paddasseenbefore,itis
I6 | add(x,0,x) forstate σ(x) = 1,as(σ(x),σ(0),σ(x)) = (1,0,1) addI6
17 October 2006 Foundations of Logic and Constraint Programming 12
Towards Soundness of SLD-Resolution (1)
- Lemma 4.3 (i)
- LetQ c Q’beanSLD-derivationstepandQ← Q’theresultantassociated
withit.Then
c |= Q← Q’
Proof.
- LetQ = A, B, C withselectedatom B. Let H ← B betheinputclause c , andQ’ = (A,B,C) .Then
c |= H ← B (variantofc)
implies c |= H ← B (instance)
implies c |= B ← B (unifiesBandH)
implies c |= (A,B,C) ← (A,B,C) (unchanged“context”:A,C)
17 October 2006 Foundations of Logic and Constraint Programming 13
Towards Soundness of SLD-Resolution (2)
Lemma 4.3 (ii)
LetbeanSLD-derivationofP {Q0}.ForiletRi betheresultantofleveliof.Then
P |= Ri
Proof. Let=Q0 1 Q1 ... Qn n+1Qn+1. Theproofisbyinductiononn.
- i=0: R0 =Q0 ← Q0 =“true”. Hence,P |= R0.
- i=1: R1 =Q01← Q1 . ByLemma4.3(i)itisP |= R1.
- i~>i+1:AssumethatP |= Ri andQii+1← Qi+1
- LetQi i+1← Qi+1 andRi = Q0 12i← Qi;Then
- Ri+1 = Ri i+1= Q0 12i+1 ← Qi+1
- Hence,byLemma4.3(i) andtheinductionhipothesis,itis P |= Ri+1.
17 October 2006 Foundations of Logic and Constraint Programming 14
Soundness of SLD-Resolution
Theorem 4.4
If there exists a successful SLD-derivation ofP {Q0 } with CAS (computed answer substitution) ,then
P |= Q0
Proof.
Let=Q0 1 Q1 ... Qn-1 n□ beasuccessfulSLD-derivation. Lemma4.3(ii)
appliedtotheresultantoflevelnofimplies
P |= Q01n
andQ01n = Q01n | Var(Q0)) = Q0
- This theorem thus guarantees that the answers computed by a successful derivation are logical consequences of the program.
- Theconverseresult,istheobjectofthecompletenesstheorem.
17 October 2006 Foundations of Logic and Constraint Programming 15
Intuitive Meaning of Queries
- To prepare the addressing of completeness, the next corollary simply states
thatifanSLD-derivationexists,thentheprogramimpliestheexistentialclosure
ofthequery(someinstanceofthequery).
Corollary 4.5
IfthereexistsasuccessfulSLD-derivationofP {Q0} thenP |= Q0.
Proof.
Theorem4.4.impliesP |= Q0 forsomeCAS.Now,
P |= Q0 .
- impliesforeveryinterpretationI: I |= P,thenI |= Q0
- impliesforeveryinterpretationI: I |= P,thenI |=(Q0 )
- impliesforeveryinterpretationI: I |= P,thenI |=Q0
- impliesP |= Q0
17 October 2006 Foundations of Logic and Constraint Programming 16
Towards Completeness of SLD-Resolution
- ToassesscompletenessofSLD-Resolutionitisconvenienttocharacterisethe
set of sintactically derivable queries. For this purpose the concepts of term
modelsandimplication treesaredefined.
- Themain idea is to interpret the set of functional symbols into “themselves”,
rather,avoindingtheirmappingintoadifferentdomain.Forexample,insteadof
amappingsuchas
- “0”0,”s(0)”1,“s(s(0))”2,...aterminterpretation/modelwilladopt- “0”0,“s(0)”s(0),“s(s(0))”s(s(0)),...
- Formally,foranexpressionE,andasetofexpressionsS
- inst(E) :setofallinstancesofE
- inst(S) :setofallinstancesofallelementsE S
- ground(E) :setofallgroundinstancesofE
- ground(S) :setofallgroundinstancesofallelementsE S
17 October 2006 Foundations of Logic and Constraint Programming 17
Term Models
ForasetofvariablesV,functionsymbolsFandpredicatesymbols
- Theterm algebraJforFisdefinedasfollows:
1. DomainD = TUF,V
2. Mapping fJ: (TUF,V)n TUF,V assignedtoevery f F(n) with
fJ(t1, ... , tn) : f(t1, ... , tn)
Aterm interpretationIforFand consistsof:
1. AtermalgebraforF
2. I TB,F,V (set of atoms that are true; equivalently it can be seen as an
assignmentofarelation pI (TUF,V)ntoeveryp(n)).
Aterm modelIofasetSofexpressions
: aterminterpretationIthatisamodelof S
17 October 2006 Foundations of Logic and Constraint Programming 18
Herbrand Models
TheHerbrand algebraJforFisdefinedforgroundtermsasfollows:
1. DomainD = HUF
2. Mapping fJ: (HUF)n HUF assignedtoevery f F(n) with
fJ(t1, ... , tn) : f(t1, ... , tn)
AHerbrand interpretationIforFand consistsof:
1. HerbrandalgebraforF
2. I HB,F (setofgroundatomsthataretrue;equivalentlyitcanbeseenasan
assignmentofarelation pI (HUF)ntoeveryp(n)).
AHerbrand modelIofasetSofexpressions
: aHerbrandinterpretationIthatisamodelof S
Aleast Herbrand modelIofasetSofexpressions
: I isaHerbrandmodelof S and I I’ forallHerbrandModels I’ ofS
17 October 2006 Foundations of Logic and Constraint Programming 19
Implication Trees
Animplication treeT withrespecttoprogramP
:
- Tisafinitetree
- ThenodesofTareatoms
- IfAisanodewithdirectdescendantsB1, ... , BnthentheremustbesomeA ← B1, ... , Bn inst(P).
- IfAisaleaf,thenA ← inst(P).
- Bisaground implication treewrt.ProgramP
:
BisanimplicationtreewrtPandallnodesaregroundatoms.
17 October 2006 Foundations of Logic and Constraint Programming 20
Implication Trees (Example)
LetPaddbethe”add-program”,
add(0,M,M).add(s(M),N,s(K)):- add(M,N,K).
and n N,Vbeasetofvariablesandt TU{s,0},V.
LetT =
Then
- Tisanimplicationtreewrt.Padd.
- Ifadditionallyt HU{s,0}, then T isagroundimplicationtree.
add(sn(0), t, sn(t))
add(sn-1(0), t, sn-1(t))
add(s(0), t, s(t))
add(0, t, t)
17 October 2006 Foundations of Logic and Constraint Programming 21
Implication Trees (Example)
LetPmultbethe”multiply-program”,
mult(0,X,0).mult(s(M),N, K):- mult(M,N,Z), add(Z,N,K).
and n N,Vbeasetofvariablesandt TU{s,0},V. . LetT =
Then
- Tisanimplicationtreewrt.Padd.
- T isalsoagroundimplicationtree.
mult(s(s(0)),s(0),s(s(0)))
mult(s(0),s(0),s(0)) add(s(0),s(0),s(s(0)))
mult(0,s(0),0) add(0,s(0),s(0)) add(0,s(0),s(0))
17 October 2006 Foundations of Logic and Constraint Programming 22
Implication Trees and Term Models
Lemma 4.7
ConsiderterminterpretationI,atomAandprogramP
• I |= Aiffinst (A) I
• I |= AiffforeveryA ← B1, ... , Bn inst(P), {B1, ... , Bn} I impliesA I.
Lemma 4.12
Theterminterpretation
C (P) : {A | A istherootofsomeimplicationtree wrt.P}
isamodelofP.
17 October 2006 Foundations of Logic and Constraint Programming 23
Ground Implication Trees and Herbrand Models
Lemma 4.26
ConsiderHerbrandinterpretationI,atomAandprogramP
• I |= Aiffground (A) I
• I |= AiffforeveryA ← B1, ... , Bn ground(P), {B1, ... , Bn} I impliesA I.
Lemma 4.28
TheHerbrandinterpretation
M(P) : {A | A istherootofsomegroundimplicationtree wrt.P}
isamodelofP.
17 October 2006 Foundations of Logic and Constraint Programming 24
Implication Trees (Example)
LetPaddbethe”add-program”belowandVasetofvariables.
add(0,M,M).add(s(M),N,s(K)):- add(M,N,K).
Theterminterpretation
C (P) = {add(sn(0), t, sn(t)) | n N, t TU{s,0},V }
= {add(sn(0), sm(v), sm+n(v)) | n,m N, v V {0} }
isamodelof Padd.
TheHerbrandinterpretation
M(P) = {add(sn(0), t, sn(t)) | n N, t HU{s,0} }
= {add(sn(0), sm(0), sm+n(0)) | n,m N}
isamodelof Padd.
17 October 2006 Foundations of Logic and Constraint Programming 25
Answer Substitutions
LetPaddbethe”add-program”belowandthequeryQ=add(s(0), u, s(u)) add(0,M1,M1).
add(s(M2),N,s(K)):- add(M2,N,K).
•{u / s(s(v))}isacorrectanswersubstitutionofQ,since
Padd |=Qadd(s(0), s(s(V)), s(s(s(V)))) .
- However, there isnoSLD-derivation leading toQ. In fact,queryQ leads tothefollowingSLD-derivationofPadd {Q}
add(s(0), u, s(u)) 1 add(0, u, u ) 2 □
where1{M2/0, N/u, K/u} and2{u/M1}. Hence,
=12| {u} ={u/M1}istheComputedAnswerSubstitution(CAS)ofQ.
- Hence,QismoregeneralthanQsince ={M1/s(s(v) ),andCASaremore general than specific correct answer substitutions. Nevertheless, are
therealwaysCAS,possiblymoregeneral,foreverycorrectanswer?
- Thecompleteness result for SLD-resolutionensuresthis.
17 October 2006 Foundations of Logic and Constraint Programming 26
Completeness of SLD-Resolution (Implication Trees)
First, a convenient lemma is obtained that relates SLD-resolution withimplication trees.
QueryQisn-deep
:everyatominQistherootofanimplicationtree,andnisthetotalnumberofnodesinthesetrees.
Lemma 4.15
SupposeQ isn-deepforsomen 0.ThenforeveryselectionruleR thereexistsasuccessfulSLD-derivationofP {Q} withCASsuchthatQismoregeneralthan Q.
Proof. Byinductiononn(see[Apt97],pg84)
17 October 2006 Foundations of Logic and Constraint Programming 27
Completeness of SLD-Resolution (1)
Theorem 4.13
SupposeisacorrectanswersubstitutionofQ.ThenforeveryselectionruleR thereexistsasuccessfulSLD-derivationofP {Q} withCASsuchthatQ ismoregeneralthan Q.
Proof. LetQ = A1, ... , Am.Then
correctanswersubstitutionofA1, ... , Am
P |= A1, ... , Am
foreveryinterpretation I: if I |= P then I |= A1, ... , Am
C(P) |= A1, ... , Am(sinceC(P) |= P, byLemma4.12)
inst(AiC(P) foreveryi 1, ..., m
AiC(P) foreveryi 1, ..., m
A1, ... , Amis n-deep forsome n0(bydefinitionofC(P) ).
claim (byLemma4.15)
17 October 2006 Foundations of Logic and Constraint Programming 28
Completeness of SLD-Resolution (2)
The completeness of SLD-resolution is often regarded as the guarantee of
obtainingasuccessfulSLD-derivationforanyquerywhoseexistentialclosure
isimpliedbytheprogram.
Corollary 4.16
SupposeP |= Q. ThenthereexistsasuccessfulSLD-derivationof P {Q}.
Proof. P |= Q
P |= Q forsomesubstitution
isacorrectanswersubstitutionof Q
Claim (byTheorem4.13)
- However,itisinterestingtocharacterise,beforehand,thesetofquerieswhose
existentialclosureisimpliedbytheprogram.Thisisthegoalofthedeclarative
semanticsforlogicprograms.
17 October 2006 Foundations of Logic and Constraint Programming 29
Least Herbrand Models
Thissetofqueriesisinfacttheleast Herbrand modelofP. Firstwedefineit.
Theorem 4.29
M(P)†istheleastHerbrandmodelofP.
Proof. LetIHbesomeHerbrandmodelofPandlet A M(P).WeproveA IH byinductiononthenumberiofnodesinthegroundimplicationtreewrt. PwithrootA.ThenM(P) IH.
i = 1: A isaleaf A ← ground(P) IH |= A (sinceIH |= P)
A IH
i ~> i+1: A hasdirectdescendants B1, ... , Bn (rootsofsubtrees)
A ← B1, ... , Bn ground(P) and B1, ... , Bn I (HerbrandInterpretation)
A ← B1, ... , Bn ground(P) and IH |= B1, ... , Bn
IH |= A (since IH |= P)
A IH
†(M(P)asdefinedinslide 23)
17 October 2006 Foundations of Logic and Constraint Programming 30
Ground Equivalence
Nowwecharacterisethesetofgroundatomsimpliedbyaprogram.
Theorem 4.30
ForeverygroundatomA:P |= AiffM(P)|= A
Proof.
:P |= Aand,fromLemma4.28,M(P)|= P. ThenitmustbeM(P) |= A.
: ShowthatforallA M(P),everyinterpretationI: I |= PimpliesI |= A.LetusconsiderHerbrandinterpretationIH = {A | AgroundatomandI |= A}. Then,
I |= P
I |= A ← B1, ... , Bn forall A ← B1, ... , Bn ground(P)
if I |= B1, ... , Bn then I |= A forall A ← B1, ... , Bn ground(P)
if B1 IH, ... , Bn IH, then A IH, forall A ← B1, ... , Bn ground(P)
IH |= P (byLemma4.26;thusIH isaHerbrandmodel)
Forall AM(P),itisA IH , (IH |= A) as M(P) istheleastHerbrandModel.
Hence,I |= A (bydefinitionof IH, A IH implies A IH).
17 October 2006 Foundations of Logic and Constraint Programming 31
Complete Partial Orderings
Once proven that the least Herbrand models are the set of ground atomsimplied by logic programs, it is interesting to specify alternative forms ofcharacterisingtheseleastHerbrandmodels.
Let(A, )beapartialordering(i.e.reflexive,antisimmetricandtransitive)
• aistheleast elementofX A:
a X, a x forall x X
• aistheleast upper boundofX A (notation a = X ):
a A , x a forall x X and a istheleast suchelementof A
• (A, )isacomplete partial ordering(cpo)containsaleastelement:• Acontainsaleastelement
• Forevery increasingsequenceao a1 a2 ... ofelementsof A, thesetX = { a0, a1, a2, ...}hasaleastupperbound.
17 October 2006 Foundations of Logic and Constraint Programming 32
Some Properties of Operators
Let(A, )beacompletepartialordering
• Operator T: A A is monotonic:
I J implies T(I) T(J)
• Operator T: A A is finitary:
foreveryinfinitesequenceI0 I1 ...
∞n=0 T (In) exists and T (∞
n=0 In) ∞n=0 T(In)
• Operator T: A A is continuous:
Tismonotonicandfinitary
• I isa pre-fixpoint of T :T(I) I
• I isa fixpoint of T :T(I) = I
17 October 2006 Foundations of Logic and Constraint Programming 33
Iterating of Operators
Let(A, )beaCPO,T: A A and I A
• T↑0(I) :I
• T↑(n+1)(I) :T(T↑n(I) )
• T↑(I) :∞n=0 (T↑n(I) )
T↑ :T↑() (for = 0, 1, 2, ... ,
Bythedefinitionofa CPO:
• Ifthesequence T↑0(I) , T↑1(I) , T↑2(I) , ... isincreasing,then T↑(I) exists
Theorem 4.22
IfTisacontinuousoperatoronaCPO,thenT↑existsandistheleastpre-fixpointofTandtheleastfixpointofT.
17 October 2006 Foundations of Logic and Constraint Programming 34
Consequence Operator TP
ConsiderCPO({I | I Herbrand Interpretation},
Let PbeaprogramandIaHerbrandinterpretation.Then
• TP(I) :{A | A ← B1, ... , Bn ground(P) , B1, ... , Bn I}
Lemma 4.33
(i) TP is finitary
(i) TP is monotonic
• In“practice”,theTpoperatorisusefultoobtain(least)HerbrandModelswithabottom-upprocedure.
17 October 2006 Foundations of Logic and Constraint Programming 35
Consequence Operator TP: Example (1)
TP↑0 =
TP↑1 = {sunny, summer}
TP↑2 = {sunny, summer, warm}
TP↑3 = {sunny, summer, warm, happy}
...
TP↑ = {sunny, summer, warm, happy} isthefixpoint
happy ← summer, warm
warm ← sunny
sunny ←
summer ←
17 October 2006 Foundations of Logic and Constraint Programming 36
Consequence Operator TP: Example (2)
Notice that if I is some “incomplete model” of P, then the consequenceoperatoraddsnewatomstoI.Forexample,let
I = {summer, sunny}
then
J = TP(I) = {summer, sunny, warm}
and
TP(I)
happy ← summer, warm
warm ← sunny
sunny ←
summer ←
17 October 2006 Foundations of Logic and Constraint Programming 37
Consequence Operator TP: Example (3)
TP↑0 =
TP↑1 = {num(0)} %0isthe1stnumber
TP↑2 = {num(sk(0))} 0k<2 %0,1arethefirst2numbers
... wheres0(0)=0
TP↑i = {num(sk(0))} 0k<i %0,...,i-1arethefirstinumbers
...
TP↑ (I)= {num(sk(0))} 0k %fixpoint
num(0) ← num(s(x)) ← num(x).
17 October 2006 Foundations of Logic and Constraint Programming 38
Consequence Operator TP: Example (4)
TP↑0=
TP↑1={num(0}
TP↑2={num(0}, num(s(0)),sum(0,0,0)}
TP↑3={num(sk(0)),sum(si(0),sj(0),si+j(0))} 0k<2,0i<1,0j<i
...
TP↑i={num(sk(0)),sum(si(0),sj(0),si+j(0))} 0k<i,0i<i-1,0j<i
...
TP↑w={num(sk(0)),sum(si(0),sj(0),si+j(0))} 0k,0i,0jfixpoint
num(0) ←
num(s(x)) ← num(x).
sum(0,z,z) ← num(z)
sum(s(x),y,s(z)) ← sum(x,y,z).
17 October 2006 Foundations of Logic and Constraint Programming 39
TP characterization
Lemma 4.32
AHerbrandInterpretationIisamodelofPiff
TP (I) I
Proof.
I |= P
iffforevery A ← B1, ... , Bn ground(P) :
{B1, ... , Bn} I implies A I (by Lemma 4.26)
iff foreverygroundatom A :
A TP (I) implies A I
iff
TP (I) I
17 October 2006 Foundations of Logic and Constraint Programming 40
Characterization Theorem
Theorem 4.31
Thefollowingsetsareequal
• M(P) (i)
• = least Herbrand model of P (ii)
• = least pre-fixpoint of P (iii)
• = least fixpoint of P (iv)
• = TP↑(v)
• = {A | A is a ground atom, P |= A} (vi)
17 October 2006 Foundations of Logic and Constraint Programming 41
Success Sets
Thesuccess setofaprogram P
:
{A | A isagroundatom, sucessfulSLD-derivationof P {A}}
Theorem 4.37
Foragroundatom A,thefollowingareequivalent
M(P) |= A (i)
• P |= A (ii)
EverySLD-treeforP {A}issuccessful (iii)
A isinthesuccesssetof P (iv)