11 november 2005 foundations of logic and constraint programming 1 negation: declarative...
Post on 20-Dec-2015
217 views
TRANSCRIPT
11 November 2005 Foundations of Logic and Constraint Programming 1
Negation: Declarative Interpretation
Anoverview
• FirstOrderFormulasandLogicalTruth
• CompletionofPrograms
• SLDNF-resolution:Soundnessandrestrictedcompleteness
• ExtendedConsequenceOperator
• StandardModels
[Lloy87] J.W. Lloyd, Foundations of Logic Programming, Second Extended Edition,Springer,1987.
[ApBo94]KrzysztofAptandRolandBol,LogicProgrammingandNegation:ASurvey,JournalofLogicProgramming,19/20:9-71,1994.
11 November 2005 Foundations of Logic and Constraint Programming 2
First-Order Formulas
Given ranked alphabets F and for functiona and predicate symbols,respectively,andasetVofvariables,thesetof
(first-order) formulas(over,FandV)isinductivelydefinedasfollows:
IfatomATB ,F,V,thenAisaformula
If G1andG2areformulas,thenG1 , G1 G2(written G1,G2),G1 G2,G1
G2andG1 G2areformulas
IfGisaformulaandx V, then x Gand x G areformulas
11 November 2005 Foundations of Logic and Constraint Programming 3
Extended Notion of Logical Truth (1)
GivenaformulaG,andinterpretationIwithdomainD,andastate : V → D:
G is true in I under , written I |= G :
I |= p(t1, ..., tn) :(t1), ... , (t1) pI
I |= G :I | G
I |= G1 G2 : I |= G1 and I |= G2
I |= G1 G2 : I |= G1 or I |= G2
I |= G1 G2 : if I |= G2 then I |= G1
I |= G1 G2 : I |= G2 iff I |= G1
I |= xG : forevery d D: I |=’ G
I |= xG : forsome d D: I |=’ G
where ’ : V → Dwith’(x) = d and ’(y) = (y) forevery y V – {x}
11 November 2005 Foundations of Logic and Constraint Programming 4
Extended Notion of Logical Truth (2)
GivenaformulaG,setsofFormulasSandT,andinterpretationI,
andwherex1, ..., xkarethevariablesoccurringin G
x1, ..., xkG istheuniversal closureofG(abbreviatedto G)
I |= G : I |= G foreverystate
G is true in I (or I isa model ofG),written I |= G : I |= G
I isa model ofS,written I |= S : I |=G forevery G S
• T isa semantic (or logical) consequence ofS written S |= T :
everymodelof S isamodelof T ( I: I |= S implies I |= T)
11 November 2005 Foundations of Logic and Constraint Programming 5
No Negative Consequences of (Extended) Programs (1)
ConsiderprogramPmem:
member(x,[x|y]) member(x,[y|z]) member(x, z)
Then,e.gPmem|=member(a,[a,b])andPmem|member(a,[]).
Butalso,Pmem|member(a,[])since
HB {member},{|, [], a}|= Pmem andHB {member},{|, [], a}|member(a,[]).
Nevertheless,theSLDNFtreeofPmem {member(a, [ ])}issuccessful
member(a,[])
member(a,[])
failure
□ success
11 November 2005 Foundations of Logic and Constraint Programming 6
No Negative Consequences of (Extended) Programs (2)
Problem:
ForeveryextendedprogramP,thecorrespondingHerbrandBaseisamodel.
Hence,thereisnonegativegroundliteralAasalogicalconsequenceofP.
ButSLDNFtreeofPmem {A}, may be successful ! (?)
Hence, is SLDNF-resolutionsound?Whatdoessoundnessmeans?
Solution:
Strengthen P by completion (“replace implication by “equivalences”) to
comp(P)andcompare SLDNF-resolutionandcomp(P),insteadofP!
11 November 2005 Foundations of Logic and Constraint Programming 7
Completed Definitions (Example 1)
WhereasP |= precipitation, cold, snow %theleastHerbrandModel
comp(P) |= precipitation, cold, snow, holidays, sun, happy
P: happy snow, holidays happy sun
snow cold, precipitationcold precipitation
comp(P): happy ( snow, holidays ) sun snow cold, precipitation
cold true
precipitation true
holidays false
sun false
11 November 2005 Foundations of Logic and Constraint Programming 8
Completed Definitions (Example 2)
Then,e.g.comp(p) |= member(a,[a,b]), member(a,[ ]), member(a,[b,c])
P: member(x,[x|y]) member(x,[y|z]) member(x,z)
disjoint([],x) disjoint([x|y],z) member(x,z), disjoint(y,z)
comp(P): x1 x2 member(x1,x2)
x,y (x1 = x, x2 = [x|y]) x,y,z (x1 = x, x2 = [y|z]), member(x,z)x1 x2 disjoint(x1,x2)
x (x1 = [], x = x) x,y,z (x1 = [x|y], x2 = z,
member(x,z), disjoint(y,z)) (plusthestandardaxiomsforequalityandinequality)
11 November 2005 Foundations of Logic and Constraint Programming 9
Completion (1)
Thecompletionofextended programP (denotedby comp(P)), isthesetof
formulasconstructedfromPbythefollowing6steps:
1. Associatewitheveryn-arypredicatesymbolpasequenceofpairwisedistinct
variablesx1, ... , xnwhichdonotoccurinP.
2. Transformeachclausec = p(t1, ... , tn) B into
p(x1, ... , xn) x1, = t1, ... , xn, = tn, B
3. Transformeachresultingformulap(x1, ... , xn) G into
p(x1, ... , xn) z G
wherezisasequenceoftheelementsofVars(c).
11 November 2005 Foundations of Logic and Constraint Programming 10
Completion (2)
4. Foreveryn-arypredicatesymbolp,let
p(x1, ... , xn) z1 G1 , . . . , p(x1, ... , xn) zm Gm
beallimplicationsobtainedinstep3(m0).
4.a) Ifm>0,thenreplacethesebytheformula
x1, ... , xn p(x1, ... , xn) z1 G1 . . . zm Gm
(ifsomeGiisempty,replaceitbytrue.)
4.b) Ifm = 0, i.e predicate p had no defining clause, then add theformula
x1, ... , xn p(x1, ... , xn) false.
11 November 2005 Foundations of Logic and Constraint Programming 11
Completion (3)
5. Addthestandard axioms of equality
5.1 [ x = x] %reflexivity
5.2 [ x = y → y = x ] %simetry
5.3 [ x = y , y = z → x = z ] %transitivity
5.4 [ xi = y → f(x1, ..., xi, ... , xn) = f(x1, ..., y, ... , xn) ] %substitutivity
5.5 [ xi = y → p(x1, ..., xi, ... , xn) p(x1, ..., y, ... , xn) ] %substitutivity
6. Addthestandard axioms of inequality
6.1 [ x1 y1 ... xm ym →f(x1, ..., xi, ... , xn) f(y1, ..., yi, ... , yn) ]
6.2 [ f(x1, ..., xi, ... , xn) g(y1, ..., yi, ... , yn) ] (whenf g )
6.3 [ x t ] (whenx isapropersubtermof t)
– Noticethataxioms6.1to6.3arearestrictionofFOequalitytotheUNA(Unique Names Assumptiom)–“differentnamesdenotedifferententities”
11 November 2005 Foundations of Logic and Constraint Programming 12
Soundness of SLDNF-Resolution
GivenextendedprogramP,extendedqueryQandsubstitution:
| var(Q)isacorrect answer substitutionofQ: comp(P) |= Q
Qisacorrect instance ofQ: comp(P) |= Q
Theorem (Lloyd, 1987)
IfthereexistsasuccessfulSLDNF-derivationofP {Q}withCAS then
comp(P) |= Q
Corollary (Lloyd, 1987)
IfthereexistsasuccessfulSLDNF-derivationofP {Q},then
comp(P) |= Q
11 November 2005 Foundations of Logic and Constraint Programming 13
Incompleteness of SLDNF (Inconsistency)
Thus,comp(P) { p p } “=“ { false }
Hence, comp(p) |= p and comp(p) |= p
In this case comp(P) is inconsistent, as it has no model, since forevery I, I | comp(P)
In this case of inconsistency, SLDNF-resolution is incomplete, since there is
neitherasuccessfulSLDNF-derivationforP {p},norforP { p},
P: p p
11 November 2005 Foundations of Logic and Constraint Programming 14
Incompleteness of SLDNF (Non Strictness)
Thus,comp(P) { p q q, q q } “=“ { p true }
Hence, comp(p) |= p.
Inthiscase,ofnon-strictness(seelater),SLDNF-resolutionisincomplete,since
thereisnosuccessfulSLDNF-derivationforP {p}.
Notice that in the absence of one of the first two clauses, there would be no
incompleteness,sincep true wouldnotbein comp(P).
P: p q
p q
q q
11 November 2005 Foundations of Logic and Constraint Programming 15
Incompleteness of SLDNF (Floundering)
Thus,comp(P) { x1 p(x1) x (x1 = x, q(x)) , x1 q(x1) false } “=“
{ x1 p(x1) true , x1 q(x1) false }
Hence, comp(p) |= x1 p(x1) .
In this case, of floundering, SLDNF-resolution is incomplete, since there is no
successfulSLDNF-derivationforP {p(x1)}
Note:SLDNFblocksquery q(x),contrarytowhatPrologdoes!
P: p(x) q(x)
11 November 2005 Foundations of Logic and Constraint Programming 16
Incompleteness of SLDNF (Unfairness)
Thus,comp(P) { r p, q , p p, q false } “=“ {r false , q false }
Hence, comp(P) |= r .
Inthiscase,SLDNF-resolutionmightbeincomplete,sincethereisnosuccessful
SLDNF-derivationforP {r}whentheleftmostselectionrule(asinProlog)is
adopted (unfairness of the selection rule).
P: r p, q
p p
11 November 2005 Foundations of Logic and Constraint Programming 17
Dependency Graphs
Adependency graphDpofanextendedprogramP
:
directedgraphwithlabellededges,where
ThenodesarethepredicatesymbolsofP
Theedgesareeitherpositive(labelled+)ornegative(labelled-);
p →+ q edgein Dp :
P containsaclause p(s1, ..., sm) L, q( t1, .., tn), R
p →- q edgein Dp :
P containsaclause p(s1, ..., sm) L, q( t1, .., tn), R
11 November 2005 Foundations of Logic and Constraint Programming 18
Strict, Hierarchical and Stratified Programs
Given an extended program P, with dependency graph Dp, with predicatesymbolsp, q,andanextendedqueryQ:
pdepends evenly / oddlyonq:
There is a path in Dp from p to q with an even (including 0) / oddnumberofnegativeedges.
Pisstrict wrt. Q :
NopredicatesymboloccurringinQdependsbothevenlyandoddlyonapredicatesymbolintheheadofaclauseinP.
Pishierarchical :
NocycleexistsinDp
P isstratified :
Nocyclewith a negative edgeexistsinDp
11 November 2005 Foundations of Logic and Constraint Programming 19
Strict, Hierarchical and Stratified Examples (1)
P1: p p
• pdependsonitself (oddly)
• P1isstrict(noevenandodddependencyofponanypredicate)
• P1 isnot hierarchical(thereisacycleinP1)
• P1isnot stratified(thereisacyclewithanegativeedgeinP1)
• pdependsevenly(0)andoddly(1)onq,whichdependsonitself(evenly)
• P2isnot strict(thereisanevenandanodddependencyofponq
• P2 isnot hierarchical(thereisacycleinP2,, asqdependsonitself)
• P2isstratified(thereisnocyclewithanegativeedgeinP2)
P2: p qp qq q
p
+
-
q +
p -
11 November 2005 Foundations of Logic and Constraint Programming 20
Strict, Hierarchical and Stratified Examples (1)
• pdependsoddlyonq
• P3isstrict(noevenandodddependencyofpredicatep/1onanypredicate)
• P1 ishierarchical(thereisnocycleinP3)
• P1isstratified(thereisnocyclewithanegativeedgeinP3)
• rdependsevenlyonqandp,thatdependsevenlyonitself
• P4isstrict(nopredicatedependsevenlyandoddlyonanotherpredicate)
• P2 isnot hierarchical(thereisacycleinP4,theselfdependencyofp)
• P2isstratified(thereisnocyclewithanegativeedgeinP1)
p/1
-
P3: p(x) q(x) q/1
P4: r p, q
p pr
+
+p +
q
11 November 2005 Foundations of Logic and Constraint Programming 21
Restricted Completeness of SLDNF-resolution (1)
Theorem(Lloyd,1987)
LetPbeahierarchicalandallowedprogramandQanallowedquery.
If comp(P) |= Q for some such that Q is ground, then there is a successfulSLDNF-derivationofP {Q}withCAS
Note: Theoremdoesnotholdifanarbitraryselectionruleisfixed.
Theselectionrulemustbesafe (doesnotselectnegativeliteralsthatarenotground).
11 November 2005 Foundations of Logic and Constraint Programming 22
Restricted Completeness of SLDNF-resolution (2)
Theorem(Lloyd,1987)
LetPbeastratifiedandallowedprogramandQanallowedquery,suchthatPisstrictwrt.Q
If comp(P) |= Q for some such that Q is ground, then there is a successfulSLDNF-derivationofP {Q}.WithCAS
Note: Theoremdoesnotholdifanarbitraryselectionruleisfixed.
Theselectionrulemustbesafeandfair.
11 November 2005 Foundations of Logic and Constraint Programming 23
Fair Selection Rule
AnextendedselectionruleRisfair:
foreverySLDNF-treeFviaRandforeverybranchinF:
Either isfailed;or
For every literal L occurring in a query of , (some further instantiatedversionof)Lisselectedwithinafinitenumberofderivationsteps
Examples:
Selectionrule“select leftmost literal”isunfair(depth-firstsearch)
Selectionrule“select leftmost literal to the right of the literals introduced in the previous derivation step, if it exists, otherwise select leftmost literal”isfair(breadth-firstsearch)
11 November 2005 Foundations of Logic and Constraint Programming 24
Extended Consequence Operator
LetPbeanextendedprogramandIaHerbrandinterpretation.Then
TP(I) : { H | H B ground(P), I |= B}
WhenPisadefiniteprogram,then
TP ismonotonic
TPIscontinuous
TPhastheleastfixpointM(P)
M(P)=TP
In case of extended programs all these properties are lost, since TP is not
monotonic.
11 November 2005 Foundations of Logic and Constraint Programming 25
Extended Consequence Operator is Not Continuous
LetI = {q }
ThenTP(I) = { },
Hence,itisnotthecasethat I TP(I).
Therefore,TPisnotmonotonic(norcontinuous)forPa(duetonegation).
Pa: p q
Pb: p p
LetI1 = { } and I2 = {p }
ThenTP(I1) = I1 = { },and TP(I2) = I2 = {p},
Therefore,TPismonotonic(andcontinuous)forPb.(andallwithnonegation)
11 November 2005 Foundations of Logic and Constraint Programming 26
Extended TP-Characterization (1)
Lemma 4.3([ApBo94]):
LetPbeanextendedprogramandI aHerbrandinterpretation.Then
I |= P iff TP (I) I
Proof.
I |= P
iffforeveryH B ground(P) : I |= B implies I |= H
iffforeveryH B ground(P) : I |= B implies H I
iffforeveryground atom H : H TP (I) implies H I
iff TP (I) I
11 November 2005 Foundations of Logic and Constraint Programming 27
Extended TP-Characterization (2)
Definition
Let F and be ranked alphabets of function and predicate symbols,
respectively,let = beabinarypredicatesymbol(for“equality”),andletI
beaHerbrandinterpretationforF and .
Then I= :I { t = t | t HUFis called a standardized Herbrand
interpretationforF and {=}
Lemma 4.4([ApBo94]):
LetPbeanextendedprogramandI aHerbrandinterpretation.Then
I |= comp(P) iff TP (I) I
11 November 2005 Foundations of Logic and Constraint Programming 28
Extended TP-Characterization (3)
Proof sketch of Lemma 4.4:
I= |= comp(P)
iffforeverygroundatomH:
I |= H (H B ground(P)) B )
(since I= isamodelforstandardaxiomsofequalityandinequality)
iffforeverygroundatomH:
H I I |= B forsomeH B ground(P)
iffforeveryground atom H :
H I implies H TP (I)
iff TP (I) I
11 November 2005 Foundations of Logic and Constraint Programming 29
Extended TP-Characterization: Example (1)
Let I0 = { }, I1 = {p }, I2 = {q }, I3 = {p, q },
Then TP(I0) = { p }, TP(I1) = { p }, TP(I2) = { }, TP(I3) = { }.
TP (I1 ) = I1 . Hence, I1 |= comp(Pa) and I1 |= Pa
TP (I2 ) I2. but TP (I2 ) I2. Hence, I2 |= Pa,butI2 | comp(Pa)
TP (I3 ) I3. but TP (I3 ) I3. Hence, I3 |= Pa,butI3 | comp(Pa)
TP (I0) I0 . Hence,I0 | Pa
Pa: p q comp(Pa) = {p, q}
11 November 2005 Foundations of Logic and Constraint Programming 30
Extended TP-Characterization: Example (2)
Pb: p q
q qcomp(Pb) = {p q}
Let I0 = { }, I1 = {p }, I2 = {q }, I3 = {p, q },
Then TP(I0) = { p }, TP(I1) = { p }, TP(I2) = { q }, TP(I3) = { q }.
TP (I1 ) = I1 . Hence, I1 |= comp(Pb) and I1 |= Pb
TP (I2 ) = I2 . Hence, I2 |= comp(Pb) and I1 |= Pb
TP (I3 ) I3. but TP (I3 ) I3. Hence, I3 |= Pb,butI3 | comp(Pb)
TP (I0) I0 . Hence,I0 | Pa
11 November 2005 Foundations of Logic and Constraint Programming 31
Completion may be Inadequate
Thus,comp(P) { ill ill, infection , infection true } “=“
{ill ill, infection true }
isinconsistent(ithasnomodels).
Hence, comp(P) |= healthy
But,I ={ ill, infection } istheonlyHerbrandmodelofP.
Hence, P | healthy
ill ill, infection
infection
11 November 2005 Foundations of Logic and Constraint Programming 32
Non-Intended Herbrand Models
P1hasthreeHerbrandmodels
M1 = {p}, M2 = {q},andM3 = {p, q}
P1hasnoleast,buttwominimalmodels:M1andM2.
However: M1andnotM2 , isthe“intended“modelofP1
P1: p q
BecauseTpisnotmonotonicnorcontinuous,itisnotpossible,ingeneraltogeta
fixpoint,noraleastmodelfromanextendedprogram.Nevertheless,thereare
minimalmodels,althoughnotnecessarilyunique.
11 November 2005 Foundations of Logic and Constraint Programming 33
Supported Herbrand Interpretations
AHerbrandinterpretation I is supported
:
Forevery H I thereexistssome H B ground(P) suchthat I |= B
(intuitively: B isan explanation forH )
Example:
M1 = {p, q },M2 = {p ,q},andM3 = {p, q}
M1isasupportedmodelofP1 (q istheexplanationfor p)
M2isnosupportedmodelofP1 (thereisnoexplanationfor q)
Notethat TP(M2) = M1 andthat TP(M1) = M1.
P1: p q
11 November 2005 Foundations of Logic and Constraint Programming 34
Extended TP-Characterization (4)
Lemma 6.2([ApBo94]):
LetPbeanextendedprogramandI aHerbrandinterpretation.Then
I |= P and I supported iff TP (I) I
Proof (sketch):
I |= P and I supported
iffforeveryH B ground(P) : I |= B implies I |= H and
foreveryH I: I |= (H B ground(P)) B
iffforeverygroundatom H : I |= ( H (H B ground(P)) B )
and I |= (H → (H B ground(P)) B )
iffforeveryground atom H : I |= ( H (H B ground(P)) B )
iff I= isamodelof comp(P)
iff TP (I) I (cf. Lemma 4.4)
11 November 2005 Foundations of Logic and Constraint Programming 35
Non-Intended Supported Models
P2hasthreeHerbrandmodels
M1 = {p}, M2 = {q},andM3 = {p, q}
P2hastwosupportedHerbrandmodels:M1andM2.
Infact,both M1 andM2 areminimalmodelsfor comp(P2) = {p q}
However: M1andnotM2 , isthe“intended“modelofP2.
M1iscalledthestandardmodelofP2 (cf.laterslide)
Ingeneral,itisnotpossibletodefinestandardmodels,unless the programs are stratified!
P2: p q
q q
11 November 2005 Foundations of Logic and Constraint Programming 36
Stratifications
LetPbeanextendedprogramandDp itsdependencygraph,
PredicatesymbolpisdefinedinP :P containsaclausep(t1, ..., tm) B
P1 ... Pn = PisastratificationofP:
Pi foreveryi 1.. n
Pi Pj foreveryi,j 1.. n,withi j
foreverypdefinedinPiandedgep →+ q in Dp :
qisnotdefinedinnj=i+1Pj
foreverypdefinedinPiandedgep →- q in Dp :
qisnotdefinedinnj=iPj
Lemma 6.5([ApBo94]):
An extended program is stratified iff it admits a (not necessarily unique)stratification.
11 November 2005 Foundations of Logic and Constraint Programming 37
Stratifications Example (1)
P1 P2 P3 isastratificationofP, where
P1 = { num(0) , num(s(x)) num(x) }
P2 = { zero(0) }
P3 = { positive(x) num(x) , zero(x) }
zero(0)
positive(x) num(x), zero(x)
num(0)
num(s(x)) num(x)
11 November 2005 Foundations of Logic and Constraint Programming 38
Stratifications Example (2)
P admitsnostratification
since
strat(even) > oddbutstrat(odd) strat(even)
even(0)
even(x) odd(x), num(x)
odd(s(x)) even(x)
num(0)
num(s(x)) num(x)
11 November 2005 Foundations of Logic and Constraint Programming 39
Standard Models (Stratified Programs)
Let
IbeanHerbrandinterpretationandasetofpredicatesymbols:
I | : I p(t1, ..., tm) | p P, t1, ..., tm groundterms)
P1 ... Pn beastratificationofastratificationofextendedprogramP,
Then
M1 : leastHerbrandmodelofP1suchthat
M1 | { p | p notdefinedin P } =
M2 : leastHerbrandmodelofP2suchthat
M2 | { p | p definednowhereorin P1 } = M1
...
Mn : leastHerbrandmodelofPnsuchthat
Mn | { p | p definednowhereorin P1 ... Pn-1 } = Mn-1
WecallMP = Mnthestandard modelof P
11 November 2005 Foundations of Logic and Constraint Programming 40
Standard Models: Example
Let P1 P2 P3 with
P1 = { num(0) , num(s(x)) num(x) }
P2 = { zero(0) }
P3 = { positive(x) num(x) , zero(x) }
beastratificationofP. Then
M1 = { num(t) | t HU{s,0} }
M2 = { num(t) | t HU{s,0} } {zero(0)}
M3 = { num(t) | t HU{s,0} } {zero(0)} {positive(t) | t HU{s,0} – {0} }
HenceMP = M3isthestandardmodelof P
zero(0)
positive(x) num(x), zero(x)
num(0)
num(s(x)) num(x)
11 November 2005 Foundations of Logic and Constraint Programming 41
Properties of Standard Models
Theorem 6.7([ApBo94]):
ConsiderastratifiedprogramP.Then
MP doesnotdependonthechosenstratificationof P,
MP isaminimalmodelof P,
MP isasupportedmodelof P,
Corollary:
ForastratifiedprogramP, comp(P)admitsaHerbrandModel.