Cs774 (Prasad)L7Negation1 Negation by Failure [email protected]
-
Upload
laurel-stokes -
Category
Documents
-
view
217 -
download
1
Transcript of Cs774 (Prasad)L7Negation1 Negation by Failure [email protected]
Motivationp(X) :- q(X).
q(a).
?-q(a). true
?-p(a). true
?-q(b). false
?-p(b). false• ‘false’ really corresponds to ‘cannot prove’. That is,
‘true’ and ‘false’ are responses to the question : “Is it a theorem/logical consequence?”
cs774 (Prasad) L7Negation 2
Closed World Assumption
• The database is complete with respect to positive information.
• That is, all positive atomic consequences are provable.
• Failure to prove goal G can be interpreted as evidence that G is false, or that negation of G (that is, ~G) is true .
cs774 (Prasad) L7Negation 3
‘Negation as failure’ operator (in the query)
p(X) :- q(X).
q(a).
?- q(a). true
?- p(a). true
?- q(b). false
?- \+ q(b). true
?- \+ p(b). true
cs774 (Prasad) L7Negation 4
Nonmonotonic Reasoning p(X) :- q(X).
q(a).
q(b).
?-q(b). true
?-p(b). true• Previous conclusions (e.g., \+ q(b), \+ p(b), etc )
overturned/overridden when new facts are added. • This is in stark contrast with classical logics, where the
set of theorems grows monotonically with the axioms.
cs774 (Prasad) L7Negation 5
Monotonic vs non-monotonic entailment
cs774 (Prasad) L7Negation 6
wv
w
,
wv
w
,
}){()(
:icityNonmonoton
TheoremsTheorems
‘Negation as failure’ in a rule p(X) :- q(X), \+ r(X).
q(a).
r(a).
q(b).
?-p(a). false
?-p(b). true
?-q(c). false
?-p(c). false
?- \+ p(c). true
cs774 (Prasad) L7Negation 7
Negation : Theory vs Practice
p :- \+ p.
?-p.
Computation: infinite loop
Translation into logic: {p}
• Recursion through negation results in a computation that does not fail finitely.
cs774 (Prasad) L7Negation 8
Negation : Theory vs Practice
p(X) :- p(s(X)).
?-p(a).
Computation: infinite loop
?- \+ p(a).
Computation: infinite loop• Ideally, the latter should succeed because p(a) is
not provable from the input, but the Prolog query \+ p(a) loops, as p(a) does not fail finitely.
cs774 (Prasad) L7Negation 9
Negation Meta-predicate: Simulation using Cut
not(p) :- p, !, fail.
not(p).
Informally, if p succeeds, then not(p) fails.
Else, not(p) succeeds.
p :- \+ q(X).
Informally, p succeeds if there is no x such that q(x) succeeds.
p fails if there is some x such that q(x) succeeds.
cs774 (Prasad) L7Negation 10
Negation : Meaning
Example: Correct use of \+
• Hotel is full if there are no vacant rooms.• Room 13 is vacant.• Room 113 is vacant.
hotelFull :- \+ vacantRoom(X).
vacantRoom(13).
vacantRoom(113).
?- hotelFull.• No, because there are vacant rooms.
– Note that some implementations will complain about variables inside negated goals, as explained later.
cs774 (Prasad) L7Negation 11
Example: Incorrect use of \+• X is at home if X is not out.• Sue is out.• John is Sue’s husband.
home(X):- \+ out(X).
out(sue).
husband(john,sue).
?- home(john). True.
?- home(X). False.– Even though John is at home, it is not extracted.
– I.e., the query is equivalent to “Is everyone out?” cs774 (Prasad) L7Negation 12
Example: Characteristics of \+student(bill).
married(joe).
unmarriedStudent(X):-
\+ married(X), student(X).
?- unmarriedStudent(X). False.
bachelor(X):-
student(X), \+ married(X).
?- bachelor(X). X = bill
• Negated goals do not generate bindings.
cs774 (Prasad) L7Negation 13
Recursion through Negation Revisited
p :- \+ q.q :- \+ p.
Logically equivalent to: p v q
• Ambiguity • Minimal models {p} and {q}.
cs774 (Prasad) L7Negation 14
Stratified Negation
cs774 (Prasad) L7Negation 15
p1 :- p2, \+ q.
…
p2 :- p1, \+ r2.
q1 :- q2, q3, \+ r1.
…
q4.
r1 :- r2.
r2.
Stratified Negation• Syntactic restriction for characterizing
“good programs”– What is the purpose?
• Associate unique meaning
– How is it obtained?• Mutual recursion among same level predicates
• Negated predicates / atoms must contain lower level predicates
• No recursion through negation
cs774 (Prasad) L7Negation 16
Example: Common-sense Reasoning
fly(X) :- bird(X).
bird(X) :- eagle(X).
bird(tweety).
eagle(toto).
?- fly(tweety). True.
?- fly(toto). True.
• Monotonic reasoning?Birds fly.
cs774 (Prasad) L7Negation 17
Example: Common-sense Reasoning(Exceptions)
fly(X) :- bird(X), \+ abnormal(X).
abnormal(X) :- penguin(X).
bird(X) :- penguin(X).
penguin(tweety).
?- fly(tweety). False.• Non-monotonic reasoning
Typically, birds fly.– Infer abnormality only if it is provable.
– Otherwise, assume normal.
cs774 (Prasad) L7Negation 18