26 October 2006 Foundations of Logic and Constraint Programming 1 Negation: Procedural Interpretation ­An overview Why negation Extended programs and queries.

Slides:



Advertisements
Similar presentations
CS4026 Formal Models of Computation Part II The Logic Model Lecture 1 – Programming in Logic.
Advertisements

Next Key Stone Problem… Set 7 Part 2 © 2007 Herbert I. Gross.
The Model Evolution Calculus with Built-in Theories Peter Baumgartner MPI Informatik, Saarbrücken
Biointelligence Lab School of Computer Sci. & Eng.
Inference Rules Universal Instantiation Existential Generalization
SLD-resolution Introduction Most general unifiers SLD-resolution
10 October 2006 Foundations of Logic and Constraint Programming 1 Unification ­An overview Need for Unification Ranked alfabeths and terms. Substitutions.
Vered Gafni – Formal Development of Real Time Systems 1 Statecharts Semantics.
Justification-based TMSs (JTMS) JTMS utilizes 3 types of nodes, where each node is associated with an assertion: 1.Premises. Their justifications (provided.
Automated Reasoning Systems For first order Predicate Logic.
First Order Logic Resolution
Answer Set Programming Overview Dr. Rogelio Dávila Pérez Profesor-Investigador División de Posgrado Universidad Autónoma de Guadalajara
Logic CPSC 386 Artificial Intelligence Ellen Walker Hiram College.
1 Knowledge Based Systems (CM0377) Lecture 8 (Last modified 5th March 2001)
Abstract Answer Set Solver. Todolist Print the rules of Fig 1.
Artificial Intelligence Chapter 14. Resolution in the Propositional Calculus Artificial Intelligence Chapter 14. Resolution in the Propositional Calculus.
1 Conditional XPath, the first order complete XPath dialect Maarten Marx Presented by: Einav Bar-Ner.
1 Applied Computer Science II Resolution in FOL Luc De Raedt.
Formal Logic Proof Methods Direct Proof / Natural Deduction Conditional Proof (Implication Introduction) Reductio ad Absurdum Resolution Refutation.
Introduction to Computability Theory
Constraint Logic Programming Ryan Kinworthy. Overview Introduction Logic Programming LP as a constraint programming language Constraint Logic Programming.
11 November 2005 Foundations of Logic and Constraint Programming 1 Negation: Declarative Interpretation ­An overview First Order Formulas and Logical Truth.
Inference and Resolution for Problem Solving
Catriel Beeri Pls/Winter 2004/5 type reconstruction 1 Type Reconstruction & Parametric Polymorphism  Introduction  Unification and type reconstruction.
Programming Language Semantics Mooly SagivEran Yahav Schrirber 317Open space html://
Semantics with Applications Mooly Sagiv Schrirber html:// Textbooks:Winskel The.
1 CILOG User Manual Bayesian Networks Seminar Sep 7th, 2006.
12 October 2006 Foundations of Logic and Constraint Programming 1 Operational Semantics ­An overview The language of programs The computation mechanism.
Lesson 6. Refinement of the Operator Model This page describes formally how we refine Figure 2.5 into a more detailed model so that we can connect it.
ASP vs. Prolog like programming ASP is adequate for: –NP-complete problems –situation where the whole program is relevant for the problem at hands èIf.
17 October 2006 Foundations of Logic and Constraint Programming 1 Declarative Semantics ­An overview Algebras (semantics for terms) Interpretations (semantics.
Belief Revision Lecture 1: AGM April 1, 2004 Gregory Wheeler
Linear Systems The definition of a linear equation given in Chapter 1 can be extended to more variables; any equation of the form for real numbers.
CS1502 Formal Methods in Computer Science Lecture Notes 10 Resolution and Horn Sentences.
Equational Reasoning Math Foundations of Computer Science.
Regular Model Checking Ahmed Bouajjani,Benget Jonsson, Marcus Nillson and Tayssir Touili Moran Ben Tulila
Notes for Chapter 12 Logic Programming The AI War Basic Concepts of Logic Programming Prolog Review questions.
Proof Systems KB |- Q iff there is a sequence of wffs D1,..., Dn such that Dn is Q and for each Di in the sequence: a) either Di is in KB or b) Di can.
Logic Programming Two possible work modes: 1.At the lab: Use SICstus Prolog. To load a prolog file (*.pl or *.pro extension) to the interpreter, use: ?-
Multiway Trees. Trees with possibly more than two branches at each node are know as Multiway trees. 1. Orchards, Trees, and Binary Trees 2. Lexicographic.
14/10/04 AIPP Lecture 7: The Cut1 Controlling Backtracking: The Cut Artificial Intelligence Programming in Prolog Lecturer: Tim Smith Lecture 7 14/10/04.
Steffen Staab Advanced Data Modeling 1 of 32 WeST Häufungspunkte Bifurkation: x n+1 = r x n (1-x n ) Startwert x 0 = 0,25.
Advanced Topics in Propositional Logic Chapter 17 Language, Proof and Logic.
Slide 1 Propositional Definite Clause Logic: Syntax, Semantics and Bottom-up Proofs Jim Little UBC CS 322 – CSP October 20, 2014.
Type Inference II David Walker COS 441. Type Inference Goal: Given unannotated program, find its type or report it does not type check Overview: generate.
CS344: Introduction to Artificial Intelligence Lecture: Herbrand’s Theorem Proving satisfiability of logic formulae using semantic trees (from Symbolic.
CS621: Artificial Intelligence Pushpak Bhattacharyya CSE Dept., IIT Bombay Lecture 28– Interpretation; Herbrand Interpertation 30 th Sept, 2010.
Unification Algorithm Input: a finite set Σ of simple expressions Output: a mgu for Σ (if Σ is unifiable) 1. Set k = 0 and  0 = . 2. If Σ  k is a singleton,
O A procedure: a set of axioms (rules and facts) with identical signature (predicate symbol and arity). o A logic program: a set of procedures defining.
Copyright © Cengage Learning. All rights reserved.
Ch. 13 Ch. 131 jcmt CSE 3302 Programming Languages CSE3302 Programming Languages (notes?) Dr. Carter Tiernan.
Web Science & Technologies University of Koblenz ▪ Landau, Germany Procedural Semantics Soundness of SLD-Resolution.
Automated Reasoning Systems For first order Predicate Logic.
第 1 6 章 谓词演算中的归结. 2 Outline Unification Predicate-Calculus Resolution Completeness and Soundness Converting Arbitrary wffs to Clause Form Using Resolution.
© Copyright 2008 STI INNSBRUCK Intelligent Systems Propositional Logic.
1 Knowledge Based Systems (CM0377) Lecture 6 (last modified 20th February 2002)
1 Reasoning with Infinite stable models Piero A. Bonatti presented by Axel Polleres (IJCAI 2001,
Answer Extraction To use resolution to answer questions, for example a query of the form  X C(X), we must keep track of the substitutions made during.
Operational Semantics Mooly Sagiv Tel Aviv University Sunday Scrieber 8 Monday Schrieber.
Assumption-based Truth Maintenance Systems: Motivation n Problem solvers need to explore multiple contexts at the same time, instead of a single one (the.
Logics for Data and Knowledge Representation ClassL (part 1): syntax and semantics.
O A procedure: a set of axioms (rules and facts) with identical signature (predicate symbol and arity). o A logic program: a set of procedures (predicates),
COMP 412, FALL Type Systems C OMP 412 Rice University Houston, Texas Fall 2000 Copyright 2000, Robert Cartwright, all rights reserved. Students.
Resolution in the Propositional Calculus
Computability and Complexity
Structural testing, Path Testing
Complexity 6-1 The Class P Complexity Andrei Bulatov.
Logics for Data and Knowledge Representation
Logic: Top-down proof procedure and Datalog
Switching Lemmas and Proof Complexity
Presentation transcript:

26 October 2006 Foundations of Logic and Constraint Programming 1 Negation: Procedural Interpretation ­An overview Why negation Extended programs and queries The computation mechanism: SLDNF-derivations Allowed programs and queries [ApBo94] Krzysztof Apt and Roland Bol, Logic Programming and Negation: A Survey, Journal of Logic Programming, 19/20: 9-71, 1994.

26 October 2006 Foundations of Logic and Constraint Programming 2 Example (1) ­In many cases, it is important to find solutions that do not satisfy some property. The introduction of negation in Logic Programming aims at enabling a declarative style for specifying such situations. ­Example: Given program P below for which airports do I have a direct flight from Lisbon, but not from Porto? ­In this case, a declarative specification of the intended query is direct(lisbon,X),  direct(porto,X). where  stands for negation. direct(lisbon, london). direct(lisbon,paris). direct(lisbon, madrid).kfurt) direct(lisbon,frankfurt). direct(porto,madrid). direct(porto,paris). direct(porto,london).

26 October 2006 Foundations of Logic and Constraint Programming 3 Example (2) ­When sets are represented by lists, some operations on sets are also conveniently expressed by means of negation. ­Example1 : Set Difference % diff(S,T,R) : R = S \ T diff([],_,[]) ← diff([H|T], L, R) ← member(H,L), diff(T,L,R]. diff([H|T], L, [H|R])←  member(H,L), diff(T,L,R]. ­Example2 : Set Disjointness (S  T =  ) % disjoint(S,T) : S  T =  disjoint([], _) ← disjoint([H|T], L) ←  member(H,L), disjoint(T,L).

26 October 2006 Foundations of Logic and Constraint Programming 4 Extended Logic Programs and Queries First, some definitions regarding negation “  ” denotes the negation sign A,  A are literals :  A is an atom A,  A are ground literals :  A is a ground atom Q is an extended query :  Q is a finite sequence of literals H ← B is an extended clause :  H is an atom, B is an extended query. P is an extended programs :  P is a finite set of extended clauses. Now, to “compute” negation, a particular semantics for negation has been widely adopted in logic programming, namely negation as failure. Intuitively, “if you cannot prove that P is true, then P must be false (?)”.

26 October 2006 Foundations of Logic and Constraint Programming 5 Negation as Failure To compute negation, it has been adopted a particular semantics for negation, namely negation as failure. Intuitively, if you cannot prove that P is true, then P must be false (?). Negation as Failure (NF) :  1.Assume  A is selected in the query Q = L,  A, N. 2.If P  {A} succeeds then the derivation of P  {Q} fails at this point. 3.If all derivations of P  {A} fail then Q resolves to Q’ = L, N. Hence  A succeeds iff A finitely fails  A finitely fails iff A succeeds

26 October 2006 Foundations of Logic and Constraint Programming 6 SLDNF resolvents 1.Let Q = L, A, N be a query, A the selected, positive, literal. Let H ← M be a variant of a clause c, which is variable disjoint with Q,  is a mgu of A and H; then Q’ = ( L, M, N )  is the SLDNF-resolvent of Q (wrt A with  ); the SLDNF-derivation step is denoted by Q   c Q’ 2.Let Q = L,  A, N be a query, A the selected, negative and ground, literal. Then Q’ = ( L, N ) is the SLDNF-resolvent of Q (wrt A with  ); the SLDNF-derivation step is denoted by Q   Q’ Note: No substitution is performed due to the negative literal. This literal, that should be ground, is only checked for not true.

26 October 2006 Foundations of Logic and Constraint Programming 7 Pseudo Derivations 1.A maximal sequence of SLDNF-derivation steps Q 0   1 c 1 Q 1... Q n-1   n c n Q n... is a pseudo-derivation of P  {Q} :  Q 0,..., Q n,... are queries, each empty or with one literal selected in it;  1  n  are substitutions; c 1,..., c n,... are clauses of program P (in case a positive literal is selected in the preceeding query); For every SLDNF-derivation step with input clause, the standardisation apart (“fresh variables”) condition holds.

26 October 2006 Foundations of Logic and Constraint Programming 8 Forests Since for each negated ground literal a “distinct” derivation is started, the whole procedure is better modeled as a set of trees (forest). F = ( T, T, subs) is a forest :  T is a set of trees where -Nodes are queries -A literal is selected in each non empty query -Leaves are marked as “success”, “failure” or “floundered” T  T is the main tree subs assigns to some nodes of trees in T with selected negative ground literal  A a subsidiary tree of T, with root A. Tree T  T is successful :  it contains a leaf marked as “success” Tree T  T is finitely failed :  it is finite and all leaves are marked as “failure”

26 October 2006 Foundations of Logic and Constraint Programming 9 Pre-SLDNF Trees The class of pre-SLDNF trees for a program P is the smallest class C of forests such that for every query Q: -The initial pre-SLDNF tree ({T Q }, T Q, subs) is in C, where T Q contains the single node Q and subs(Q) are undefined. for every F  C : -The extension of F is in C.

26 October 2006 Foundations of Logic and Constraint Programming 10 Extension of Pre-SLDNF Trees (1) Extension of forest F = ( T, T, subs) :  a.Every occurrence of the empty query is marked as “success” b.For every non-empty query Q, which is an unmarked leaf in some tree in T, perform the following action: Let L be the selected literal of Q 1.L is positive If Q has no SLDNF-resolvents then Q is marked as “failure” else for every program clause c which is applicable to L, exactly one direct descendant of Q is added. This resolvent is the SLDNF- resolvent of Q with c wrt. L.

26 October 2006 Foundations of Logic and Constraint Programming 11 Extension of Pre-SLDNF Trees (2) Extension of forest F = ( T, T, subs) :  (cont.) 2.L =  A is negative If A non-ground then Q is marked as “floundered” else (A is ground) subs(Q) undefined new tree T’ with single root A is added to T and subs(Q) is set to T’ subs(Q) defined and successful Q is marked as failure subs(Q) defined and finitely failed SLDNF-resolvent of Q is added as the only direct descendent of Q subs(Q) defined and neither successful nor finitely failed no action

26 October 2006 Foundations of Logic and Constraint Programming 12 SLDNF-Trees An SLDNF-tree :  limit of a sequence F 0, F 1, F 2,..., where F 0 is the initial pre-SLDNF tree F i+1 is an extension of F i, for every i  N An SLDNF-tree for P  {Q} :  SLDNF-tree in which Q is the root of the main tree

26 October 2006 Foundations of Logic and Constraint Programming 13 Successful, Failed and Finite SLDNF-Trees A (pre-)SLDNF-tree is successful :  its main tree is successful A (pre-)SLDNF-tree is finitely failed :  its main tree is finitely failed A SLDNF-tree is finite :  no infinite path exists in it, where a path is a sequence of nodes N 0, N 1, N 2,... such that for every i (  N), N i+1 is either a direct descendant of N i ; or the root of subs(N i )

26 October 2006 Foundations of Logic and Constraint Programming 14 Example (1) Program P: q ← q  qqqqq qqqqq The SLDNF-tree for P  {  q} is infinite

26 October 2006 Foundations of Logic and Constraint Programming 15 Example (2) The SLDNF-tree for P  {  q} is successful Program P: q ←  r r ← r ← r  q q q  r failure r □ success □ success r □ success r □ success a 4b

26 October 2006 Foundations of Logic and Constraint Programming 16 SLDNF- derivation A SLDNF-derivation of P  {Q} :  branch in the main tree of a SLDNF-tree F for P  {Q} together with the set of all trees of F whose roots can be reached from the nodes in this branch. A SLDNF-derivation is successful :  it ends with success ( □ ). A computed answer substitution (CAS) of Q 0 (wrt  ) :  (  1   2   n ) | var(Q 0 ) where the main tree of an SLDNF-tree for P  {Q 0 } contains the branch  = Q 0   1 Q 1... Q n-1   n  Q n = □

26 October 2006 Foundations of Logic and Constraint Programming 17 A Theorem on Limits The following theorem justifies that the determination of whether a SLDNF- tree is successful or finitely failed is a search problem in a finite search space. Theorem 1.Every SLDNF-tree is the limit of a unique sequence of pre-SLDNF-trees. 2.If the SLDNF-tree F is the the limit of the sequence F 0, F 1, F 2,..., then: i. F is successful and yields CAS  iff some F i is successful and yields CAS  ii. F is finitely failed iff some F i is finitely failed.

26 October 2006 Foundations of Logic and Constraint Programming 18 Why Select Ground Literals Only Ideally, when a  A is selected in a query, we would like SLDNF-resolution to answer the question: “Is there a substitution  that makes atom A false?” Unfortunately, SLDNF-resolution answers adiffrent question: “Are there no substitutions that make atom A true?” Indeed SLDNF does not check the existencial closure of  A, i.e. P |=  A, but rather the negation (failure) of the existencial closure of A, i.e. P |=   A, which is in fact equivalent to P |=  A. It is easy to see that the only situation where (  A)  (  A), i.e.  x 1,  x k  A   x 1,  x k  A occurs when there are no variables in atom A, thus justifying the need for ground literals.

26 October 2006 Foundations of Logic and Constraint Programming 19 Why Select Ground Literals Only (Example 1) The difference between (  A)  (  A) can be observed in program zero(0) ← positive(x) ←  zero(x) for query Q = positive(y). Indeed, rather than finding whether there are positive numbers, i.e. “are there non-zero numbers”, SLDNF answers the quite different question of “are all numbers non-zero”, which is of course false (0 is zero!). positive(y)  zero(y) failure zero(y) □ success {x/y} {y/0}

26 October 2006 Foundations of Logic and Constraint Programming 20 Why Select Ground Literals Only (Example 2) The “unintended” behaviour od SLDNF does not occur when the query is ground; neither with Q0 = positive(0), nor Q1 = positive(s(0)). zero(0) ← positive(x) ←  zero(x) In both cases, the “correct” answers are given: 0 is not positive s(0) is positive positive(0)  zero(0) failure zero(0) □ success {x/0} {} positive(s(0))  zero(s(0)) sucess zero(s(0))  failure {x/s(0)}

26 October 2006 Foundations of Logic and Constraint Programming 21 Extended Selection Rule (Extended) selection rule :  Function which, given a pre-SLDNF-tree F = ( T, T, subs) selects a literal in every non-empty unmarked leaf in every tree in T. SLDNF-tree F is via a selection rule R :  F is the limit of a sequence of pre-SLDNF-trees, in which literals are selected according to R. Selection rule R is safe :  R never selects a non-ground negative literal.

26 October 2006 Foundations of Logic and Constraint Programming 22 Blocked Queries Query Q is blocked :  Q is non-empty and contains exclusively non-ground negative literals P  {Q} flounders :  some SLDNF-tree for P  {Q} contains a blocked node. Notice that floundering causes a the program to behave in the “unintended way”, discussed before.

26 October 2006 Foundations of Logic and Constraint Programming 23 Allowed Programs and Queries do not Flounder Query Q is allowed :  every x  var(Q) occurs in a positive literal of Q Clause H ← B is allowed :   H, B is allowed (Unit) clause H ← is allowed :  H is a ground atom Program P is allowed :  all clauses of P are allowed Theorem 3.13 (Apt and Bol, 1994) Assume that P and Q are allowed. Then i. P  {Q} does not flounder; ii.If  is a CAS of Q, then Q  is ground.

26 October 2006 Foundations of Logic and Constraint Programming 24 SLDNF implementation in Prolog Operationally, Prolog systems use the cut (“!”) mechanism to implement negation as failure literally, by means of the built-in meta-predicate “\+”, defined as follows % \+ is the negation operator % (1)  A finitely fails iff A succeeds \+A :- call(A), !, fail. % (2)  A succeeds iff A finitely fails \+A. The negation of an atom (or goal) is treated separately, starting a new tree. a)If the goal succeeds with some substitution the meta-predicate is forceed to fail, with no alternative (due to the !). b)If the goal fails the cut is not invoked and the catch all clause makes the meta-predicate \+ to succeed, with no substitution.

26 October 2006 Foundations of Logic and Constraint Programming 25 Specifics of Prolog In Prolog, SLDNF-resolution (Selection rule driven Linear Resolution for Definite clauses augmented by Negation as Failure) is instantiated by adopting Leftmost selection rule% leftmost literals from resolvents A program is a sequence of clauses% top clauses first Non-ground negative literals selected!% floundering! Unification without occurs check% incorrect unification Depth-first search, backtracking% trapped in infinite branches The notions of SLDNF-resolution, -resolvents, -trees, etc. are “replaced” by LNDF- correspondents.

26 October 2006 Foundations of Logic and Constraint Programming 26 Extended Prolog Trees Let P be an extended program and Q 0 an extended query. Then The Extended Prolog Tree for P  {Q 0 } is the forest of finitely branching, ordered trees of queries possibly marked with “success” or “failure”, produced as follows: Start with forest ({T Q 0 }, T Q 0, subs), where T Q 0 contains the single node Q 0 and subs(Q 0 ) is undefined Repeatedly apply operation expand ( F,Q). to the current forest F = ( T, T, subs) where T 1  T is leftmost, bottommost (i.e. most nested subsidiary) tree with an unmarked leaf. Q is the leftmost unmarked leaf in T 1,

26 October 2006 Foundations of Logic and Constraint Programming 27 Operation Expand (1) Let F = ( T,T,subs) be the current forest, where T 1  T is leftmost, bottommost tree with an unmarked leaf, and Q is the leftmost unmarked leaf in T 1. Operation expand ( F,Q). is defined as follows: If Q = □ then 1.Mark Q with “sucess” 2.If T 1  T, then remove from T 1 all edges to the right of the branch that ends with Q (i.e. do not repeat success in a subsidiary tree). If Q has no LDNF-resolvents, then mark Q with “failure” else let L be the leftmost literal in Q

26 October 2006 Foundations of Logic and Constraint Programming 28 Operation Expand (2) –L is positive Add for each clause that is applicable to L, an LDNF-resolvent as a descendant of Q (such that the order of the clauses is preserved) –L =  A is negative (not necessarily ground!) If subs(Q) is undefined then add a new tree T’ = A and set subs(Q) to T’ If subs(Q) is defined and successful then mark Q with “failure” If subs(Q) is defined and finitely failed then add in T 1 the LNDF-resolvent of Q as the only descendant of Q

26 October 2006 Foundations of Logic and Constraint Programming 29 Prolog Negation does not Check Floundering From the specification, Prolog does not check whether a negated goal is ground or not. Hence, computation is never blocked, but the price to pay is floundering. This can be shown in the following interaction. | ?- positive(0). no | ?- positive(s(s(0))). yes | ?- positive(X). no % ???? The reason for floundering is, of course, the call of the nonground negative goal \+zero(X). zero(0). positive(X):- \+ zero(X)

26 October 2006 Foundations of Logic and Constraint Programming 30 Prolog Users Must Avoid Floundering To avoid floundering, an user must take care to write programs which are allowed. This can in general be achieved by specifying what the variables “might be”, before specifying what they “are not”. Example: Instead of program use program | ?- positive(X).| ?- positive(X). no% ???? X = s(0) ? ; X = s(s(0)) ? ; X = s(s(s(0))) ? ;... zero(0). positive(X):- \+ zero(X) zero(0). positive(X):- num(X), \+ zero(X) num(0). num(s(X)):- num(X).