1 Section 9.2 Logic Programming A logic program is a set of clauses with the restriction that there is exactly one positive literal in each clause. Such.

Slides:



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

SLD-resolution Introduction Most general unifiers SLD-resolution
Logic Programming Automated Reasoning in practice.
Knowledge & Reasoning Logical Reasoning: to have a computer automatically perform deduction or prove theorems Knowledge Representations: modern ways of.
Standard Logical Equivalences
1 Knowledge Based Systems (CM0377) Lecture 8 (Last modified 5th March 2001)
Inferences The Reasoning Power of Expert Systems.
Equivalence, Order, and Inductive Proof
Logic Concepts Lecture Module 11.
Formal Logic Proof Methods Direct Proof / Natural Deduction Conditional Proof (Implication Introduction) Reductio ad Absurdum Resolution Refutation.
AI - Week 16 Logic and Reasoning in AI: Resolution Refutation Lee McCluskey, room 2/07
Inference and Resolution for Problem Solving
EE1J2 - Slide 1 EE1J2 – Discrete Maths Lecture 12 Number theory Mathematical induction Proof by induction Examples.
CSE (c) S. Tanimoto, 2007 Unification 1 Unification Predicate calculus rules are sometimes so general that we need to create specializations of.
Restricted Satisfiability (SAT) Problem
CS1502 Formal Methods in Computer Science Lecture Notes 10 Resolution and Horn Sentences.
First Order Logic. This Lecture Last time we talked about propositional logic, a logic on simple statements. This time we will talk about first order.
CS2013 Maths for Computing Science Proof (part b) Adam Wyner University of Aberdeen Computing Science.
Formal Models of Computation Part II The Logic Model
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.
MATH 224 – Discrete Mathematics
DECIDABILITY OF PRESBURGER ARITHMETIC USING FINITE AUTOMATA Presented by : Shubha Jain Reference : Paper by Alexandre Boudet and Hubert Comon.
Conjunctive normal form: any formula of the predicate calculus can be transformed into a conjunctive normal form. Def. A formula is said to be in conjunctive.
1 Chapter 8 Inference and Resolution for Problem Solving.
1 Sections 1.5 & 3.1 Methods of Proof / Proof Strategy.
1 COSC3306: Programming Paradigms Lecture 8: Declarative Programming Specifications Haibin Zhu, Ph.D. Computer Science Nipissing University (C) 2003.
1 Section 7.2 Equivalent Formulas Two wffs A and B are equivalent, written A  B, if they have the same truth value for every interpretation. Property:
First Order Predicate Logic
Week 10Complexity of Algorithms1 Hard Computational Problems Some computational problems are hard Despite a numerous attempts we do not know any efficient.
First Order Logic Lecture 2: Sep 9. This Lecture Last time we talked about propositional logic, a logic on simple statements. This time we will talk about.
ARTIFICIAL INTELLIGENCE [INTELLIGENT AGENTS PARADIGM] Professor Janis Grundspenkis Riga Technical University Faculty of Computer Science and Information.
CSE S. Tanimoto Horn Clauses and Unification 1 Horn Clauses and Unification Propositional Logic Clauses Resolution Predicate Logic Horn Clauses.
Chapter 1, Part II: Predicate Logic With Question/Answer Animations.
Induction Proof. Well-ordering A set S is well ordered if every subset has a least element. [0, 1] is not well ordered since (0,1] has no least element.
CS Introduction to AI Tutorial 8 Resolution Tutorial 8 Resolution.
1 Section 13.2 The Church-Turing Thesis The Church-Turing Thesis: Anything that is intuitively computable can be be computed by a Turing machine. It is.
Kansas State University Department of Computing and Information Sciences CIS 730: Introduction to Artificial Intelligence Lecture 17 Wednesday, 01 October.
The AI War LISP and Prolog Basic Concepts of Logic Programming
Dr. Muhammed Al-Mulhem ICS An Introduction to Logical Programming.
Automated Reasoning Early AI explored how to automated several reasoning tasks – these were solved by what we might call weak problem solving methods as.
Web Science & Technologies University of Koblenz ▪ Landau, Germany Procedural Semantics Soundness of SLD-Resolution.
1 Introduction to Abstract Mathematics Chapter 2: The Logic of Quantified Statements. Predicate Calculus Instructor: Hayk Melikya 2.3.
Chapter 2 Logic 2.1 Statements 2.2 The Negation of a Statement 2.3 The Disjunction and Conjunction of Statements 2.4 The Implication 2.5 More on Implications.
Kansas State University Department of Computing and Information Sciences CIS 730: Introduction to Artificial Intelligence Lecture 18 of 41 Friday, 01 October.
Reasoning using First-Order Logic
The Law of Resolution Formal Aspects of Computer Science - Week 7 The Law of Resolution Lee McCluskey, room 2/07
1 Section 9.1 Automatic Reasoning Recall that a wff W is valid iff ¬ W is unsatisfiable. Resolution is an inference rule used to prove unsatisfiability.
1 Section 4.3 Order Relations A binary relation is an partial order if it transitive and antisymmetric. If R is a partial order over the set S, we also.
CSE (c) S. Tanimoto, 2008 Predicate Calculus II 1 Predicate Calculus 2 Outline: Unification: definitions, algorithm Formal interpretations and satisfiability.
1 Knowledge Based Systems (CM0377) Lecture 6 (last modified 20th February 2002)
1-1 An Introduction to Logical Programming Sept
1 Section 8.3 Higher-Order Logic A logic is higher-order if it allows predicate names or function names to be quantified or to be arguments of a predicate.
CS104:Discrete Structures Chapter 2: Proof Techniques.
1 Section 6.2 Propositional Calculus Propositional calculus is the language of propositions (statements that are true or false). We represent propositions.
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.
1 Chapter Construction Techniques. 2 Section 3.1 Inductively Defined Sets To define a set S inductively is to do three things: Basis: Specify one.
Lecture 041 Predicate Calculus Learning outcomes Students are able to: 1. Evaluate predicate 2. Translate predicate into human language and vice versa.
1 Section 7.3 Formal Proofs in Predicate Calculus All proof rules for propositional calculus extend to predicate calculus. Example. … k.  x p(x) P k+1.
1 Hojjat Ghaderi, University of Toronto, Fall 2006 CSC384: Intro to Artificial Intelligence Knowledge Representation III ● Required Readings: 9.1, 9.2,
1 Section 7.1 First-Order Predicate Calculus Predicate calculus studies the internal structure of sentences where subjects are applied to predicates existentially.
6/11/2016 Linear Resolution and Introduction to First Order Logic Michael Leuschel Softwaretechnik und Programmiersprachen Lecture 5.
CSE 341, S. Tanimoto Logic Programming -
Horn Clauses and Unification
Horn Clauses and Unification
Horn Clauses and Unification
Horn Clauses and Unification
Horn Clauses and Unification
Logical Inference 4 wrap up
Inference Rules for Quantified Propositions
Presentation transcript:

1 Section 9.2 Logic Programming A logic program is a set of clauses with the restriction that there is exactly one positive literal in each clause. Such clauses are often called definite clauses. Example. Let p(x, y) mean x is a parent of y and let g(x, y) mean x is a grandparent of y. Here are some ways to represent a definition of the grandparent relation. First-order logic:  x  y  z (p(x, z)  p(z, y)  g(x, y)). First-order clause:g(x, y)  ¬ p(x, z)  ¬ p(z, y). Logic programming:g(x, y)  p(x, z), p(z, y). Prolog:g(X, Y) :- p(X, Z), p(Z, Y). A query or goal is a question that asks whether the program infers something. The something is a sequence of one or more atoms and the question is whether there is a substitution that can be applied to the atoms so that the resulting atoms are inferred by the program. Example. Suppose we have the following little logic program. p(a, b). p(b, d). g(x, y)  p(x, z), p(z, y). Let g(a, w) be a query. It asks whether a has a grandchild. If we let  = {w/d}, then g(a, w)  = g(a, d), which says a has a grandchild d. This follows from the two program facts p(a, b) and p(b, d) and the definition of g. So g(a, d) is inferred by the program.

2 Formal Representation of a Query From a formal viewpoint (i.e., first-order predicate calculus) a query is the existential closure of a conjunction of one or more atoms. Example. The query g(a, w) is formally represented by  w g(a, w). We saw that the example program infers g(a, w)  = g(a, d) for  = {w/d}. But EG can be applied to g(a, d) to infer  w g(a, w). Therefore the program infers  w g(a, w). Example. The query g(a, w), p(u, w) is formally represented by  w  u (g(a, w)  p(u, w)). If we let  = {w/d, u/b}, then (g(a, w)  p(u, w))  = g(a, d)  p(b, d), which follows from the two example program facts p(a, b) and p(b, d) and the definition of g. So g(a, d)  p(b, d) is inferred by the program. Now apply EG twice to infer  w  u (g(a, w)  p(u, w)). Therefore the program infers  w  u (g(a, w)  p(u, w)). Logic Programming Representation of a Query To see whether a query can be inferred from a program, a resolution proof is attempted. The premises are the program clauses together with the negation of the query, which can be written as a clause with only negative literals. Example. Given the query g(a, w), p(u, w). Its formal meaning is  w  u (g(a, w)  p(u, w)). So we negate it and convert it to a clause. Here are some ways to represent the negation of the query. First-order logic:¬  w  u (g(a, w)  p(u, w))   w  u ¬ (g(a, w)  p(u, w)). First-order clause:¬ g(a, w)  ¬ p(u, w). Logic programming:  g(a, w), p(u, w). Prolog: |?- g(a, W), p(U, W).

3 SLD-resolution is a form of resolution used to execute logic programs. SLD means selective linear resolution of definite clauses. Select the leftmost atom of goal; Linear (each resolvant depends of the previous resolvant); and Definite clauses are the clauses of a logic program. Example. Given the following little logic program and query, where the clauses are also listed in first-order form. Logic Programming SyntaxFirst-Order Clauses p(a, b).p(a, b). p(b, d).p(b, d). g(x, y)  p(x, z), p(z, y).g(x, y)  ¬ p(x, z)  ¬ p(z, y). The query:  g(a, w), p(u, w). ¬ g(a, w)  ¬ p(u, w). The resolution proof: 1.p(a, b)p(a, b)P 2.p(b, d)p(b, d)P 3.g(x, y)  p(x, z), p(z, y)g(x, y)  ¬ p(x, z)  ¬ p(z, y)P 4.  g(a, w), p(u, w)¬ g(a, w)  ¬ p(u, w)P 5.  p(a, z), p(z, y), p(u, y) ¬ p(a, z)  ¬ p(z, y)  ¬ p(u, y) 3, 4, R, {x/a, w/y} 6.  p(b, y), p(u, y)¬ p(b, y)  ¬ p(u, y) 1, 5, R, {z/b} 7.  p(u, d)¬ p(u, d) 2, 6, R, {y/d} 8.[] [] 2, 7, R, {u/b} QED.

4 Computation Trees A computation tree for a query represents all possible ways to satisfy the query. i.e., it represents all possible refutations by resolution. The root is the query and a child of a node is a resolvant of the node with a program clause. The mgus are listed along each branch of the tree. Computed answers are listed below the leaf of each successful refutation. Example. Given the following logic program and query: p(a, b) p(c, b) p(b, d) g(x, y)  p(x, z), p(z, y) Query:  g(w, d) The computation tree for the query is pictured.  g(w, d)  p(w, z), p(z, d) {x/w, y/d}  p(b, d)  p(d, d) failure {w/a, z/b} {w/c, z/b} {w/b, z/d} [] success w = a { } [] success w = c

5 Example/Quiz. Given the following logic program and query. p(a)p(a) p(x)  p(ƒ(x)) p(ƒ(b)). The query:  p(y). Draw several levels of the computation tree for the query.  p(y) p(y)  p(ƒ(x 1 )) {y/a} {y/x 1 } {y/ƒ(b)} [] success y = a {x 3 /ƒ(ƒ(x 1 ))} [] success y = ƒ(b) {x 2 /ƒ(x 1 )}{x 1 /b}  p(ƒ(ƒ(x 1 ))) [] success y = b  p(ƒ 3 (x 1 )) infinite branch Solution:

6 Logic Programming Examples Example. Let ex(n, m) mean the execution of p(n), p(n + 1), …, p(m). Write a program for the predicate ex. Solution: ex(n, n)  p(n). ex(n, m)  n < m, p(n), k is n + 1, ex(k, m). Example. Suppose we need to construct the set L = {n | (1 ≤ n ≤ 50) and p(n) is true}. With Prolog’s setof predicate, we could find the answer with the query |?- setof(N, (1 =< N, N =< 50, p(N)), L). Without the setof predicate we need to define a predicate to do the job. Solution: Assume that the the following query will construct the set L. |?- set(1, 50, [ ], L). The third argument, initilized to [ ], will accumulate the set of n for which p(n) is true. Then we can define the predicate set as follows. set(Lower, Upper, L, L) :- Lower > Upper. set(Lower, Upper, L, X) :- p(Lower), N is Lower + 1, set(N, Upper, [Lower | L], X). set(Lower, Upper, L, X) :- N is Lower + 1, set(N, Upper, L, X).