Logic Languages Source: Scott, Michael Programming Language Pragmatics 3rd Ed.

Slides:



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

Some Prolog Prolog is a logic programming language
Resolution Proof System for First Order Logic
Chapter 11 :: Logic Languages
Resolution.
Automated Reasoning Systems For first order Predicate Logic.
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.
We have seen that we can use Generalized Modus Ponens (GMP) combined with search to see if a fact is entailed from a Knowledge Base. Unfortunately, there.
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.
Formal Logic Mathematical Structures for Computer Science Chapter 1 Copyright © 2006 W.H. Freeman & Co.MSCS SlidesFormal Logic.
CS 330 Programming Languages 12 / 02 / 2008 Instructor: Michael Eckmann.
Chapter 12 - Logic Programming
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.
1 COMP 144 Programming Language Concepts Felix Hernandez-Campos Lecture 26: Introduction to Logic Programming with Prolog COMP 144 Programming Language.
Inference and Resolution for Problem Solving
Chapter 3 Propositional Logic
ISBN Chapter 16 Logic Programming Languages.
Logic Programming Languages
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.
1 Lecture 15: Introduction to Logic Programming with Prolog (Section 11.3) A modification of slides developed by Felix Hernandez-Campos at UNC Chapel Hill.
1 Knowledge Based Systems (CM0377) Lecture 4 (Last modified 5th February 2001)
1 Chapter 8 Inference and Resolution for Problem Solving.
Introduction to Logic Programming with Prolog (Section 11.3)
Chapter 16 Logic Programming Languages. Copyright © 2012 Addison-Wesley. All rights reserved.1-2 Chapter 16 Topics Introduction A Brief Introduction to.
Declarative vs Procedural Programming  Procedural programming requires that – the programmer tell the computer what to do. That is, how to get the output.
CSE S. Tanimoto Horn Clauses and Unification 1 Horn Clauses and Unification Propositional Logic Clauses Resolution Predicate Logic Horn Clauses.
CHAPTER 15 & 16 Functional & Logic Programming Languages.
CS Introduction to AI Tutorial 8 Resolution Tutorial 8 Resolution.
Prolog Kyle Marcotte. Outline What is Prolog? Origins of Prolog (History) Basic Tutorial TEST!!! (sort of…actually not really at all) My example Why Prolog?
By: Cory Canter CSC 415 Programming Languages. History  Created by Alain Colmerauer, Phillipe Roussel and Robert Kowalski in 1971  Started as a natural.
Dr. Muhammed Al-Mulhem ICS An Introduction to Logical Programming.
Logic Programming Languages Session 13 Course : T Programming Language Concept Year : February 2011.
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.
Automated Reasoning Early AI explored how to automate several reasoning tasks – these were solved by what we might call weak problem solving methods as.
Prolog Harry R. Erwin, PhD COMM2M University of Sunderland.
CS 337 Programming Languages Logic Programming I (Logic, Intro to Prolog)
C. Varela1 Logic Programming (PLP 11) Predicate Calculus, Horn Clauses, Clocksin-Mellish Procedure Carlos Varela Rennselaer Polytechnic Institute November.
© Kenneth C. Louden, Chapter 12 - Logic Programming Programming Languages: Principles and Practice, 2nd Ed. Kenneth C. Louden.
Programming Languages Third Edition Chapter 4 Logic Programming.
CSE 3302 Programming Languages Chengkai Li Spring 2008 Logic Programming: Prolog Lecture 21 – Prolog, Spring CSE3302 Programming Languages, UT-Arlington.
1 Knowledge Based Systems (CM0377) Lecture 6 (last modified 20th February 2002)
ISBN Chapter 16 Logic Programming Languages.
C. Varela1 Logic Programming (PLP 11, CTM 9.1) Terms, Resolution, Unification, Search, Backtracking (Prolog) Relational Computation Model (Oz) Carlos Varela.
Knowledge Based Information System
1-1 An Introduction to Logical Programming Sept
Introduction to Prolog Asst. Prof. Dr. Senem Kumova Metin Revised lecture notes of “Concepts of Programmig Languages, Robert W. Sebesta, Ch. 16”
Copyright 1999Paul F. Reynolds, Jr. Foundations of Logic Programming.
6/11/2016 Linear Resolution and Introduction to First Order Logic Michael Leuschel Softwaretechnik und Programmiersprachen Lecture 5.
By P. S. Suryateja Asst. Professor, CSE Vishnu Institute of Technology
Introduction to Logic for Artificial Intelligence Lecture 2
Carlos Varela Rennselaer Polytechnic Institute November 11, 2016
CS 3304 Comparative Languages
Horn Clauses and Unification
Carlos Varela Rensselaer Polytechnic Institute November 14, 2017
Prolog fundamentals Module 14.2 COP4020 – Programming Language Concepts Dr. Manuel E. Bermudez.
Logic Programming Languages
Chapter 11 :: Logic Languages
Carlos Varela Rensselaer Polytechnic Institute November 10, 2017
Horn Clauses and Unification
Horn Clauses and Unification
Logic Programming Language
Chapter 12 :: Logic Languages
CS2136: Paradigms of Computation
RESOLUTION.
Chapter 12 :: Logic Languages
Carlos Varela Rennselaer Polytechnic Institute August 30, 2007
Presentation transcript:

Logic Languages Source: Scott, Michael Programming Language Pragmatics 3rd Ed.

Overview Predicate Calculus – Some History and Background – Operators & Quantifiers – Predicates Horn Clause – Resolution and Unification ProLog – Basics – Examples Limitations, Execution and Wrap up

History and Background 1970’s – Alain Clomeraurer & Philippe Roussel of the Univ. of Aix-Marseille (France) with associates at the Univ. of Edinburgh (Scotland), due to their work, the process of logical deduction began to be used as a general- purpose model of computing. Logic Languages are based on first-order predicate calculus. Predicate Calculus is composed of predicates, operators and quantifiers for statements (propositions). Logic languages however cannot capture the full power of predicate calculus, therefore we have limitations as we will see later.

Operators & Quantifiers Operators: – And ( ∧ ) – Or ( ∨ ) – Not (¬) – Implication (→) – Equivalence (↔) Quantifiers: – For all ( ∀ ) (Universal-indicates true for all values) – There Exists ( ∃ ) (Existential-indicates true for at least one value)

Predicates Definition from section 11.3 (On CD section): – A Predicate is a function that maps constants (atoms) or variables to the values true and false.

Examples from Text: ∀ C [rainy(C) ∧ cold(C) → snowy(C)] (For all cities C, if C is rainy and C is cold, then C is snowy.) ∀ A, ∀ B [( ∃ C [takes(A, C) ∧ takes(B, C)]) → classmates(A, B)] (For all students A and B, if there exists a class C such that A takes C and B takes C, then A and B are classmates.) In Predicate calculus the same thing can be said in different ways. ( P  Q) can be written as (¬P ∨ Q) (P implies Q) — (Not P or Q)

Clausal Form: 5 Step procedure referred to in 11.3 on cd to translate first order into clausal form. – Step 1: Rewrite the expression to eliminate implication (→) and equivalence (↔) operators. – Step 2: Move any negations (¬) outside parenthesis as far inside as you can. – Step 3: Technique called Skolemization (after logician Thoralf Skolem). Uses Math theorem: Axiom of choice to replace X with x in the following to remove ∃ : ∃ X[takes(X, cs254) ∧ class year(X, 2)] then becomes: takes(x, cs254), class year(x, 2)

Clausal Form Continued: – Step 4: Move all universal quantifiers ( ∀ ) to the outside then drop it. – Step 5: Use Boolean algebra to form a conjunctive normal form. - And ( ∧ ) & Or ( ∨ ) operators can’t be nested any more than 2 levels deep with ∧ on the outside and ∨ on the outside.

Example from text: ∀ A [¬student(A) → (¬dorm resident(A) ∧ ¬ ∃ B[takes(A, B) ∧ class(B)])] (For all students A, if A is not Student, then A is not Dorm Resident and there doesn’t exist Class B such that A takes B and B is a class) –My interpretation of the above logical equation. Step 1: ∀ A[student(A) ∨ (¬dorm resident(A) ∧ ¬ ∃ B[takes(A, B) ∧ class(B)])] (For all students A, A is student or (not a dorm resident and there doesn’t exist a class B such that student A takes class B and B is a class.)) Step 2: ∀ A[student(A) ∨ (¬dorm resident(A) ∧ ∀ B[¬(takes(A, B) ∧ class(B))])] ∀ A[student(A) ∨ (¬dorm resident(A) ∧ ∀ B[¬takes(A, B) ∨ ¬class(B)])] (For all students A, A is a student or ( A is not a dorm resident and for all classes B student A doesn’t take class B and B is a class./ 2 nd one or B is not a class.)) Step 3: -NO CHANGE in this Example- Step 4: ∀ (student(A) ∨ (¬dorm resident(A) ∧ (¬takes(A, B) ∨ ¬class(B)))) student(A) ∨ (¬dorm resident(A) ∧ (¬takes(A, B) ∨ ¬class(B))) (For all A is a student or (A is not a dorm resident and A doesn’t take class B or B isn’t a class) Step 5: (student(A) ∨ ¬dorm resident(A)) ∧ (student(A) ∨ ¬takes(A, B) ∨ ¬class(B)) (A is a student or A is not a dorm resident) and (A is a student or A doesn’t take class B or B isn’t a class) Completed, it is now in clause form.

Horn Clause Almost all logic languages follow the standard form called the Horn clause. Every clause consists of a head and a body – H  B1, B2, …, Bn. (read: H if B1,…, and Bn) As we noted earlier, Horn clauses cannot capture all logical statements, but most. We will revisit in limitations later.

Resolution and Unification Resolution: – The process in which we derive a new statement by combining existing statements. – Example: If A, B  C and C  D We can use resolution to obtain A, B  D Unification – During Resolution, free variables may acquire values. – Example: flowery(X)  rainy(X) and we have rainy(Rochester) We can use Resolution to get flowery(Rochester)

ProLog After translating the expression into the Clausal form, we will need to translate into ProLog. The Clausal form of Predicate Calculus is very close to ProLog language. A minor drawback we will see in limitations is as ProLog cannot capture all of Predicate Calculus, Predicate Calculus does not encompass all that ProLog can do. For running ProLog, I found a java embedded version called tuProlog ide. Google search: tuProLog and it is located in the Google code online.

Translate to Prolog: The next step is to now translate what we have into Prolog. Simply enough, we convert each logical clause to a Prolog fact or rule. 1. (student(A) ∨ ¬dorm resident(A)) ∧ (student(A) ∨ ¬takes(A, B) ∨ ¬class(B)) 2. (student(A) ← ¬(¬dorm resident(A))) ∧ (student(A) ← ¬(¬takes(A, B) ∨ ¬class(B))) 3. (student(A) ← dorm resident(A)) ∧ (student(A) ← (takes(A, B) ∧ class(B))) In step three, we now have 2 Horn Clauses, and the translation into ProLog rules becomes: student(A) :- dorm_resident(A). student(A) :- takes(A, B), class(B).

Syntax and Notations ProLog runs off of a database of clauses. A Clause is composed of terms. A term can be composed of constants, variables, or structures. Constants are either an atom or a number. A number which of course is a number. An atom starts with a lowercase letter followed by any type of punctuation or can be a quoted string. Example: – foo – my_Const+ – ‘Hi,Everyone’ A Variable starts with an uppercase letter : – Foo – My_var – X Structures consist of an atom called the functor and it’s arguments which can be constants, variables or nested structures. – bin_tree(foo, bin_tree(bar,glarch))

More about ProLog ProLog like Scheme is homoiconic, it can represent itself and modify itself. – Keywords assert and retract add and remove clauses to the database respectively. ProLog can only return true or false. (Or Yes or No)

Advanced ProLog Facts are like Horn Clauses without the Head – We also use these as a Query to give the ProLog interpreter. A rule has a right-hand side. Variable only become instantiated when unified and given a value. Unification rules of ProLog: – Constants unifies only with itself. – Two structures unify iff the functer name and arity are the same, and the arguments unify recursively. – A variable unifies with anything. If it’s a value, great its instantiated. If it’s another non-instantiated variable, then if either get a value later, they both will be instantiated.

Execution ProLog is defined as Backward Chaining Backward Chaining is defined as starting with the goal and working backward, attempting to “un-resolve” it into a set of preexisting clauses.

Limitations So what is missing and what can go wrong? Consequence could result in a disjunction on the left-hand-side or a headless clause. Example of disjunctive head: Every living thing is an animal or a plant animal(X) ∨ plant(X) ∨ ¬living(X) animal(X) ∨ plant(X) ← living(X)(two left hand side) The Prolog then would be: (as close as can) animal(X) :- living(X), \+(plant(X))(\+ is a form of negation used to solve plant(X) :- living(X), \+(animal(X))some of the issues that arise with negations as seen here)

Limitations continued Example of empty head: ∀ N[big(N)→ ¬( ∃ A, ∃ B, ∃ C[works(A, B, C,N)])] (For all N, if N is Big, then not(there exists A, B, C such that A, B, C and N works) Clausal form is: ¬big(N) ∨ ¬works(A, B, C,N) (N isn’t big or A, B, C and N don’t work) Prolog: big(N), works(A, B, C, N). But this will never terminate and is only a query, it can’t be stated as a fact or a rule.

Wrap up Tic Tac Toe example Other Examples