CSE 341, S. Tanimoto Logic Programming -

Slides:



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

Chapter 11 :: Logic Languages
Prolog The language of logic. History Kowalski: late 60’s Logician who showed logical proof can support computation. Colmerauer: early 70’s Developed.
Introduction to Prolog, cont’d Lecturer: Xinming (Simon) Ou CIS 505: Programming Languages Fall 2010 Kansas State University 1.
Standard Logical Equivalences
Prolog The language of logic. History Kowalski: late 60’s Logician who showed logical proof can support computation. Colmerauer: early 70’s Developed.
For Friday No reading Homework: –Chapter 9, exercise 4 (This is VERY short – do it while you’re running your tests) Make sure you keep variables and constants.
Outline Recap Knowledge Representation I Textbook: Chapters 6, 7, 9 and 10.
Computability and Complexity 9-1 Computability and Complexity Andrei Bulatov Logic Reminder (Cnt’d)
Constraint Logic Programming Ryan Kinworthy. Overview Introduction Logic Programming LP as a constraint programming language Constraint Logic Programming.
Inference and Resolution for Problem Solving
CSE (c) S. Tanimoto, 2007 Unification 1 Unification Predicate calculus rules are sometimes so general that we need to create specializations of.
CSE (c) S. Tanimoto, 2005 Logic Programming 1 Logic Programming Outline: Motivation Examples: The Grandmother relation Formulation in Prolog Logic,
Introduction to Logic for Artificial Intelligence Lecture 2 Erik Sandewall 2010.
© Patrick Blackburn, Johan Bos & Kristina Striegnitz Horn clauses A literal is an atomic formula or its negation A clause is a disjunction of literals.
Propositional Logic Reasoning correctly computationally Chapter 7 or 8.
INFERENCE IN FIRST-ORDER LOGIC IES 503 ARTIFICIAL INTELLIGENCE İPEK SÜĞÜT.
Notes for Chapter 12 Logic Programming The AI War Basic Concepts of Logic Programming Prolog Review questions.
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.
Cs7120 (Prasad)L16-Meaning1 Procedural and Declarative Meaning of Prolog
First Order Predicate Logic
CSE S. Tanimoto Horn Clauses and Unification 1 Horn Clauses and Unification Propositional Logic Clauses Resolution Predicate Logic Horn Clauses.
Logic Logic can be traced back to Aristotle, and more recently to Frege who introduced predicate logic as a language for representing and reasoning about.
1CS3754 Class Notes 14B, John Shieh, Figure 2.5: Further steps in the unification of (parents X (father X) (mother bill)) and (parents bill.
CS Introduction to AI Tutorial 8 Resolution Tutorial 8 Resolution.
Programming Languages Tucker and Noonan – 2e Chapter 15 – Part 1 Logic Programming “Q: How many legs does a dog have if you call its tail a leg? A: Four.
Resolution Strategies One common strategy for applying resolution is called level saturation. Here you try to resolve every pair of clauses from the original.
Dr. Muhammed Al-Mulhem ICS An Introduction to Logical Programming.
Logic Programming and Prolog Goal: use formalism of first-order logic Output described by logical formula (theorem) Input described by set of formulae.
Automated Reasoning Early AI explored how to automated several reasoning tasks – these were solved by what we might call weak problem solving methods as.
Introduction to Prolog. Outline What is Prolog? Prolog basics Prolog Demo Syntax: –Atoms and Variables –Complex Terms –Facts & Queries –Rules Examples.
© Kenneth C. Louden, Chapter 12 - Logic Programming Programming Languages: Principles and Practice, 2nd Ed. Kenneth C. Louden.
CSE (c) S. Tanimoto, 2008 Predicate Calculus II 1 Predicate Calculus 2 Outline: Unification: definitions, algorithm Formal interpretations and satisfiability.
CSE 341, S. Tanimoto Logic Programming Intro - 1 Logic Programming Introduction Motivation. Sample logic programs.
1-1 An Introduction to Logical Programming Sept
In The Name Of Allah Lab 03 1Tahani Aldweesh. objectives Searching for the solution’s. Declaration. Query. Comments. Prolog Concepts. Unification. Disjunction.
Artificial Intelligence CIS 342 The College of Saint Rose David Goldschmidt, Ph.D.
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.
Copyright 1999Paul F. Reynolds, Jr. Foundations of Logic Programming.
CSE (c) S. Tanimoto, 2001 Logic Programming
CS 3304 Comparative Languages
The function of knowledge representation scheme is
Proposition & Predicates
Horn Clauses and Unification
Logic Programming Languages
Introduction to Logic Programming and Prolog
Prolog a declarative language
Chapter 11 :: Logic Languages
Horn Clauses and Unification
Horn Clauses and Unification
Introduction to Logic Programming and Prolog
CSE (c) S. Tanimoto, 2004 Unification
CSE S. Tanimoto Unification
Horn Clauses and Unification
Introduction to Prolog
CSE (c) S. Tanimoto, 2002 Unification
CSE (c) S. Tanimoto, 2004 Logic Programming
Introduction to Prolog
CSE (c) S. Tanimoto, 2002 Logic Programming
Horn Clauses and Unification
CS2136: Paradigms of Computation
Encoding Knowledge with First Order Predicate Logic
Encoding Knowledge with First Order Predicate Logic
RESOLUTION.
Introduction to Logic Programming and Prolog
Substituting into formulae
Encoding Knowledge with First Order Predicate Logic
Introduction to Logic Programming and Prolog
Prolog Concepts.
Presentation transcript:

CSE 341, S. Tanimoto Logic Programming - Motivation. Predicate Logic Clause Form. Horn Clauses. A backtracking Horn-clause resolver. Sample logic programs. CSE 341, S. Tanimoto Logic Programming -

CSE 341, S. Tanimoto Logic Programming - Motivation 1. Reduce the programming burden: it would be nice to have a system that could simply accept the necessary information and the objective (goal), and then figure out its own solution. 2. Have a program that looks more like its own specification. 3. Take advantage of logical inference to automatically get many of the consequences of the given information. CSE 341, S. Tanimoto Logic Programming -

CSE 341, S. Tanimoto Logic Programming - Predicate Logic Every Macintosh computer uses electricity. (all x) (Macintosh(x) implies UsesElectricity(x)) variables: x, y, z, etc. constants: a, b, c, etc. function symbols: f, g, etc. Predicate symbols: P, Q, Macintosh, UsesElectricity quantifiers: all, exists Logical connectives: not, implies, and, or. ~, ->, &, V. CSE 341, S. Tanimoto Logic Programming -

CSE 341, S. Tanimoto Logic Programming - Clause Form (all x) (Macintosh(x) -> UsesElectricity(x) UsesElectricy(x) V Not Macintosh(x). Any boolean formula can be put into conjunctive normal form (CNF). If not Y then X and not Z. Y or (X & not Z) (Y or X & (Y or not Z) (X V Y) & (Y V ~Z) clauses: (X V Y), (Y V ~Z) X, Y, and ~Z are called literals. CSE 341, S. Tanimoto Logic Programming -

CSE 341, S. Tanimoto Logic Programming - Horn Clauses Horn clause: at most one unnegated literal (X V Y) is not a Horn clause. (Y V ~Z) is a Horn clause. “If X is the mother of Y and Y is a parent of Z, then X is a grandmother of Z.” (m(X,Y) & p(Y, Z)) -> g(X,Z). grandmother(X, Z) provided mother(X, Y) and parent (Y, Z) g(X,Z) :- m(X,Y), p(Y,Z). ; Edinburgh Prolog syntax ((grandmother x z) ; head (not (mother x y)) ; subgoal 1 (not (parent y z))) ; subgoal 2 CSE 341, S. Tanimoto Logic Programming -

Unification of Literals A substitution is a set of term/variable pairs. { f(a)/x, b/y, z/w } A unifier for a pair of literals is a substitution that when applied to both literals, makes them identical. P(x, a), P(f(a), y) have the unifier { f(a)/x, a/y } P(x), P(y) have the unifier { a/x, a/y }, but they also have the unifier { x/y }. The latter is more general because after unifying with { x/y} we get P(x) whereas with the other it is P(a), yet we can obtain the latter from the former with an additional substitution { a/x }. CSE 341, S. Tanimoto Logic Programming -

Horn-Clause Resolution Example of resolution with the grandmother rules: g(X, Z) :- m(X, Y), p(Y, Z). m(X, Y) :- p(X, Y), f(X). g(X, Z) :- p(X, Y), f(X), p(Y, Z). more generally, from: P :- Q1, Q2. Q1 :- R1, R2. we obtain the resolvent: P :- R1, R2, Q2 CSE 341, S. Tanimoto Logic Programming -

A Backtracking Horn-Clause Resolver Maintain the rules in a database of rules. Accept a query (goal) as a positive unit clause, e.g., P(a, b). Put this goal on the subgoal list. Repeatedly try to satisfy the next clause on the subgoal list as follows: Find a rule in the database whose head unifies with the subgoal. Apply the same unifier to the literals in the body of that rule and replace the subgoal by these new literals. If the subgoal list is empty, stop. The combined set of unifiers includes the solution. CSE 341, S. Tanimoto Logic Programming -

CSE 341, S. Tanimoto Logic Programming - Example Logic Program (SETF DATABASE3 '( ; Rules: ((GRANDMOTHER X Z) (MOTHER X Y) (PARENT Y Z)) ((PARENT X Y) (MOTHER X Y)) ((PARENT X Y) (FATHER X Y)) ; Facts: ((MOTHER MARY JOHN)) ((FATHER JOHN BILL)) ((FATHER PETER JAMES)) )) (QUERY '((GRANDMOTHER X BILL))) CSE 341, S. Tanimoto Logic Programming -

Invertible List Manipulation (SETF DATABASE4 '( ;;; (APPEND L1 L2 L3) is true provided L3 is the ;;; result of appending L1 and L2. ((APPEND NILL L L)) ((APPEND L NILL L)) ((APPEND (CONS X L1) L2 (CONS X L3)) (APPEND L1 L2 L3)) )) (QUERY '((APPEND (CONS X (CONS Y NILL)) (CONS Z (CONS W NILL)) L)) ) SOLUTION: L=(CONS X (CONS Y (CONS Z (CONS W NILL)))) CSE 341, S. Tanimoto Logic Programming -

Invertible List Manipulation (Cont.) (QUERY '((APPEND L (CONS Z (CONS W NILL)) (CONS X (CONS Y (CONS Z (CONS W NILL)))))) ) SOLUTION: L=(CONS X (CONS Y NILL)) Functional programming: evaluation is one-way. Logic programming: evaluation can be two-way. CSE 341, S. Tanimoto Logic Programming -