200 likes | 312 Views
Negation by Failure. t.k.prasad@wright.edu http://www.knoesis.org/tkprasad/. Motivation. p(X) :- q(X). q(a). ?-q(a). true ?-p(a). true ?-q(b). false ?-p(b). false
E N D
Negation by Failure t.k.prasad@wright.edu http://www.knoesis.org/tkprasad/ L7Negation
Motivation p(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?” L7Negation
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 . L7Negation
‘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 L7Negation
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. L7Negation
Monotonic vs non-monotonic entailment L7Negation
‘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 L7Negation
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. L7Negation
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. L7Negation
Negation Meta-predicate: Simulation using Cut Negation : Meaning 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. L7Negation
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. L7Negation
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?” L7Negation
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. L7Negation
Recursion through Negation Revisited p :- \+q. q :- \+p. Logically equivalent to:p v q • Ambiguity • Minimal models {p} and {q}. L7Negation
Stratified Negation p1 :- p2, \+q. … p2 :- p1, \+ r2. q1 :- q2, q3, \+r1. … q4. r1 :- r2. r2. L7Negation
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 L7Negation
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. L7Negation
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. L7Negation