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

Slides:



Advertisements
Similar presentations
Applications Computational LogicLecture 11 Michael Genesereth Spring 2004.
Advertisements

1 Knowledge Representation Introduction KR and Logic.
Artificial Intelligence: Natural Language and Prolog
Introductory Mathematics & Statistics for Business
By D. Fisher Geometric Transformations. Reflection, Rotation, or Translation 1.
DIVIDING INTEGERS 1. IF THE SIGNS ARE THE SAME THE ANSWER IS POSITIVE 2. IF THE SIGNS ARE DIFFERENT THE ANSWER IS NEGATIVE.
MULT. INTEGERS 1. IF THE SIGNS ARE THE SAME THE ANSWER IS POSITIVE 2. IF THE SIGNS ARE DIFFERENT THE ANSWER IS NEGATIVE.
Addition Facts
Artificial Intelligence 8. The Resolution Method
Formal Models of Computation Part II The Logic Model
CS4026 Formal Models of Computation Part II The Logic Model Lecture 6 – Arithmetic, fail and the cut.
Simply Logical – Chapter 2© Peter Flach, 2000 Clausal logic Propositional clausal logic Propositional clausal logic expressions that can be true or false.
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: ?-
Chapter 2 Section 3.
1 Declarative Programming Motivation Warm Fuzzies What is Logic?... Logic Programming? Mechanics of Prolog Terms, Substitution, Unification, Horn Clauses,
1 Knowledge Based Systems (CM0377) Lecture 11 (Last modified 26th March 2001)
Query Answering for OWL-DL with Rules Boris Motik Ulrike Sattler Rudi Studer.
Addition 1’s to 20.
25 seconds left…...
Copyright © Cengage Learning. All rights reserved.
Complexity ©D.Moshkovits 1 Where Can We Draw The Line? On the Hardness of Satisfiability Problems.
Introduction to Computability Theory
Week 1.
9.2 Absolute Value Equations and Inequalities
Biointelligence Lab School of Computer Sci. & Eng.
Inference Rules Universal Instantiation Existential Generalization
1 Programming Languages (CS 550) Mini Language Interpreter Jeremy R. Johnson.
SLD-resolution Introduction Most general unifiers SLD-resolution
1 A formula in predicate logic An atom is a formula. If F is a formula then (~F) is a formula. If F and G are Formulae then (F /\ G), (F \/ G), (F → G),
Knowledge & Reasoning Logical Reasoning: to have a computer automatically perform deduction or prove theorems Knowledge Representations: modern ways of.
Standard Logical Equivalences
First Order Logic Resolution
Inference and Reasoning. Basic Idea Given a set of statements, does a new statement logically follow from this. For example If an animal has wings and.
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.
Logic Use mathematical deduction to derive new knowledge.
F22H1 Logic and Proof Week 7 Clausal Form and Resolution.
1 Applied Computer Science II Resolution in FOL Luc De Raedt.
Outline Recap Knowledge Representation I Textbook: Chapters 6, 7, 9 and 10.
Constraint Logic Programming Ryan Kinworthy. Overview Introduction Logic Programming LP as a constraint programming language Constraint Logic Programming.
Logic Programming Languages. Objective To introduce the concepts of logic programming and logic programming languages To introduce a brief description.
AI - Week 16 Logic and Reasoning in AI: Resolution Refutation Lee McCluskey, room 2/07
Inference and Resolution for Problem Solving
Knoweldge Representation & Reasoning
CS1502 Formal Methods in Computer Science Lecture Notes 10 Resolution and Horn Sentences.
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.
1 Knowledge Based Systems (CM0377) Lecture 4 (Last modified 5th February 2001)
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.
CSE S. Tanimoto Horn Clauses and Unification 1 Horn Clauses and Unification Propositional Logic Clauses Resolution Predicate Logic Horn Clauses.
CS Introduction to AI Tutorial 8 Resolution Tutorial 8 Resolution.
CS4026 Formal Models of Computation Part II The Logic Model Lecture 2 – Prolog: History and Introduction.
Dr. Muhammed Al-Mulhem ICS An Introduction to Logical Programming.
Logic Programming Languages Session 13 Course : T Programming Language Concept Year : February 2011.
Automated Reasoning Early AI explored how to automated several reasoning tasks – these were solved by what we might call weak problem solving methods as.
Automated Reasoning Early AI explored how to automate several reasoning tasks – these were solved by what we might call weak problem solving methods as.
Ch. 13 Ch. 131 jcmt CSE 3302 Programming Languages CSE3302 Programming Languages (notes?) Dr. Carter Tiernan.
603 Database Systems Senior Lecturer: Laurie Webster II, M.S.S.E.,M.S.E.E., M.S.BME, Ph.D., P.E. Lecture 25 A First Course in Database Systems.
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
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.
Knowledge Representation and Reasoning
CSE 341, S. Tanimoto Logic Programming -
ARTIFICIAL INTELLIGENCE
Logic Use mathematical deduction to derive new knowledge.
Logic: Top-down proof procedure and Datalog
Horn Clauses and Unification
Horn Clauses and Unification
Horn Clauses and Unification
CS2136: Paradigms of Computation
Presentation transcript:

CS4026 Formal Models of Computation Part II The Logic Model Lecture 1 – Programming in Logic

formal models of computation 2 Logic Programming: the vision A computational problem can be expressed as a set of statements in logic: Describing the domain and its constraints Describing what the solution must be like Example: devising a timetable Might use concepts such as: bestT(x) – x is the best timetable h(event,room,time) – event happens in room at time …

formal models of computation 3 Formally The problem/requirements: A logical statement A, e.g. ( 8 x bestT(x) ´ …) Æ ( 8 r 8 t 8 e 8 e1. h(e,r,t) Æ h(e1,r,t) ¾ e=e1) Æ … The solution: A logical statement B, e.g. bestT(…) We want to know: A ² B ??

formal models of computation 4 Satisfiability and Consequence in Logic A formula A is satisfiable, ² A, if there is an interpretation of the formula that is true in the world. Finding such an interpretation involves: –Deciding what each predicate symbol means –Deciding what each function symbol means –Deciding what each constant symbol means –Checking the complex claim of the formula A ² B ( B is a logical consequence of A ) means that B is true in any interpretation that makes A true

formal models of computation 5 Inference Procedures An inference procedure is a mechanical way of determining logical consequences. A ` B : the procedure derives B from A Two desirable properties: –Completeness: If A ² B then A ` B –Soundness: If A ` B then A ² B Given a complete and sound inference procedure, we can use this to calculate logical consequences

formal models of computation 6 Refutation To test, A ² B, we could (using ` ) try deriving logical consequences from A and look to see if B is there. But: –Not guided by the nature of B –There are infinitely many logical consequences… A ² B can be replaced by A Æ : B ², where is the formula that is never true (false) Saying this differently: A Æ : B is not satisfiable So now only need refutation soundness/ completeness (where the consequence is )

formal models of computation 7 Computational approaches to deduction Resolution (Robinson 1965) Assumes that statements are expressed in a simpler, more uniform, notation: clauses Practical approaches mostly use some kind of Resolution. Resolution and the translation from logic into clauses is sound and refutation complete.

formal models of computation 8 Equivalences in Predicate Calculus ¾ and ´ can be replaced, e.g. by (a ¾ b) ) : a Ç b : can be moved inwards to only modify a predicate directly, e.g. by : (a Ç b) ) : a Æ : b 9 can be replaced by using new constant/ function symbols, e.g. by 8 x 9 y p(y) ) 8 x p(f(x)) 8 can be moved to the outside of formulae, e.g. by a Æ 8 x p(x) ) 8 x (a Æ p(x)) Æ can be distributed over Ç (CNF) e.g. by a Ç (b Æ c) ) (a Ç b) Æ (a Ç c)

formal models of computation 9 Clauses Once the above translations have taken place: –We can miss out explicit 8 signs (because all variables are universally quantified at the outside) –The logical formula is now of the form: (l 11 Ç l 12 Ç l 1k ) Æ (l 21 Ç l 2m ) Æ Where each literal l ij is either positive - a predicate applied to arguments, e.g. n(x,f(y)), or negative - the negation of a predicate, e.g. : n(x,f(y)) A formula (l 11 Ç l 12 Ç l 1k ) is called a clause. It can also be written: (l 11 ; l 12 ; ) :- l 13, l 14,. where l 11, l 12 are the positive literals and l 13, l 14 are the (unnegated!) negative ones

formal models of computation 10 Example: Translating Logic to Clauses 8 x. n(x) ´ ( x=lowest Ç n(min(x,1)) ) ) 8 x. ( : n(x) Ç x=lowest Ç n(min(x,1))) Æ ( : (x=lowest Ç n(min(x,1))) Ç n(x)) ) 8 x. ( : n(x) Ç x=lowest Ç n(min(x,1))) Æ (( : x=lowest Æ : n(min(x,1))) Ç n(x)) ) 8 x. ( : n(x) Ç x=lowest Ç n(min(x,1))) Æ (( : x=lowest Ç n(x)) Æ ( : n(min(x,1)) Ç n(x)) )

formal models of computation 11 8 x. ( : n(x) Ç x=lowest Ç n(min(x,1))) Æ (( : x=lowest Ç n(x)) Æ ( : n(min(x,1)) Ç n(x)) ) Remove 8. Clauses are: ( : n(x) Ç x=lowest Ç n(min(x,1))) ( : x=lowest Ç n(x)) ( : n(min(x,1)) Ç n(x)) Write these as: x=lowest; n(min(x,1)) :- n(x). n(x) :- x=lowest. n(x) :- n(min(x,1)).

formal models of computation 12 Skolemisation In producing clauses, removing 9 is the most tricky operation. 9 x. centre(x,universe) ) centre(k23,universe) 8 x. man(x) ¾ 9 y. mother(x,y) ) 8 x. man(x) ¾ mother(x,k24(x)) This affects the true interpretations of a formula. But does not affect whether a formula is satisfiable, so is harmless if we are doing refutation.

formal models of computation 13 Horn Clauses A clause with at most one positive literal is called a Horn clause (at most one thing left of the :-) It can be shown (using the methods of Part III of this course) that Horn clauses are all we need in order to do computation. A Horn clause is headed if it has something to the left of the :-, otherwise it is headless. In our example: x=lowest; n(min(x,1)) :- n(x). n(x) :- x=lowest. n(x) :- n(min(x,1)). The last two clauses are headed Horn clauses

formal models of computation 14 Computational interpretation of HCs The set of headed clauses with a given predicate on the left can be thought of as defining a procedure to establish whether it holds: n(x) :- x=lowest. ( 8 x. n(x) ½ x=lowest) n(x) :- n(min(x,1)). ( 8 x. n(x) ½ n(min(x,1))) uncle(x,y) :- parent(x,z), brother(z,y). ( 8 x. 8 y. uncle(x,y) ½ 9 z. parent(x,z) Æ brother(z,y)) A headless clause can be thought of as defining a goal : :- uncle(mary,x). :- n(x), n(min(1,x)). A procedure allows goals to be reduced to simpler subgoals. This is the basis of languages like Prolog.

formal models of computation 15 How to do Logic Programming (version 1) Encode the problem in logic: A (the program) Encode the solution in logic: B (the goal) Translate A into clausal form – gives a set of headed Horn clauses Translate :B into clausal form – gives a headless Horn clause Attempt to refute A Æ :B using resolution Read off the answer (to be described)

formal models of computation 16 SLD resolution SLD resolution is a refutation complete version of resolution for Horn Clauses A current goal (headless clause) is repeatedly reduced to a (hopefully simpler) new goal, using a headed clause from the program: :- g 1, g 2, g n. (selected literal) g 2 :- g 21, g 22, g 2m. (selected clause) gives rise to the new goal: :- g 1, g 21, g 22, g 2m, g n. SLD resolution does not tell you which literal to choose or which clause to choose

formal models of computation 17 Example Program: a :- b, c. b :- d. c :-. d :-. Goal: :- a. SLD refutation: :- a. :- b, c. :- d, c. :- c. :-. (empty clause – false)

formal models of computation 18 Substitutions and Answers An SLD refutation is allowed to associate values with variables in clauses (because a 8 variable can be anything): uncle(x,y) :- parent(x,z), brother(z,y). parent(mary,jean). brother(jean,tom). :- uncle(mary,w). x=mary, y=w :- parent(mary,z), brother(z,w). z=jean :- brother(jean,w). w=tom :-. The assumed values for variables are kept in an increasing substitution, which can be used to read off the answer.

formal models of computation 19 Unification To deal with variable values, the matching criterion for SLD resolution needs to be more general than identity. A selected literal is required to unify with the head of a clause, and this produces a new substitution. Unification – computes the minimal assignments to variables that will make two terms identical, e.g. uncle(mary,john) uncle(mary,x) YES, x=john uncle(x,john)uncle(motherof(z),john) YES, x=motherof(z) uncle(motherof(z),john) uncle(motherof(mary),john) YES, z=mary uncle(mary,john)uncle(john,mary) NO

formal models of computation 20 Control SLD resolution does not specify: –Which literal in the goal to resolve away next –Which clause whose head unifies with the literal should be used Various selection functions can be defined, but there is no perfect approach Bad choices can lead to inefficiency/ infinite loops. Finding the best solution path is a search problem. In practice, a programmer has some idea about how the search should be controlled: Algorithm = logic + control Logic programming languages provide extra control mechanisms separate from the logic.

formal models of computation 21 How to do Logic Programming (version 2) Encode the problem in logic: A (the program) Encode the solution in logic: B (the goal) Translate A into clausal form – gives a set of headed Horn clauses Translate :B into clausal form – gives a headless Horn clause Use SLD resolution (with your favourite control/ selection functions) to reduce A Æ : B to Read off the answer from the substitution built In practice, most people write the clauses for A and B directly.