Carlos Varela Rensselaer Polytechnic Institute November 14, 2017

Slides:



Advertisements
Similar presentations
Chapter 11 :: Logic Languages
Advertisements

Prolog The language of logic. History Kowalski: late 60’s Logician who showed logical proof can support computation. Colmerauer: early 70’s Developed.
1 Introduction to Prolog References: – – Bratko, I., Prolog Programming.
1 Logic Programming with Prolog: Resolution, Unification, Backtracking COMP 144 Programming Language Concepts Spring 2003 Stotts, Hernandez-Campos Modified.
C. Varela; Adapted w/permission from S. Haridi and P. Van Roy1 Declarative Computation Model From kernel to practical language (CTM 2.6) Exceptions (CTM.
Logic Languages Source: Scott, Michael Programming Language Pragmatics 3rd Ed.
COP4020 Programming Languages Logic programming and Prolog Prof. Xin Yuan.
1 COMP 144 Programming Language Concepts Felix Hernandez-Campos Lecture 27: Prolog’s Resolution and Programming Techniques COMP 144 Programming Language.
C. Varela; Adapted w/permission from S. Haridi and P. Van Roy1 Declarative Computation Model Defining practical programming languages Carlos Varela RPI.
Comp 205: Comparative Programming Languages Declarative Programming Languages Unification Backtracking Lecture notes, exercises, etc., can be found at:
C. Varela; Adapted w/permission from S. Haridi and P. Van Roy1 Declarative Computation Model Single assignment store Kernel language syntax Carlos Varela.
C. Varela; Adapted w/permission from S. Haridi and P. Van Roy1 Declarative Computation Model Kernel language semantics Carlos Varela RPI Adapted with permission.
C. Varela1 Programming Languages (CSCI 4430/6969) History, Syntax, Semantics, Essentials, Paradigms Carlos Varela Rennselaer Polytechnic Institute August.
C. Varela1 Logic Programming (PLP 11.3) Prolog Imperative Control Flow: Backtracking Cut, Fail, Not Carlos Varela Rennselaer Polytechnic Institute September.
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.
Introduction to Logic Programming with Prolog (Section 11.3)
1 Lecture 6 Logic Programming introduction to Prolog, facts, rules Ras Bodik Shaon Barman Thibaud Hottelier Hack Your Language! CS164: Introduction to.
30/09/04 AIPP Lecture 3: Recursion, Structures, and Lists1 Recursion, Structures, and Lists Artificial Intelligence Programming in Prolog Lecturer: Tim.
Logic Programming CSC 358/ Outline Pattern matching Unification Logic programming.
The AI War LISP and Prolog Basic Concepts of Logic 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.
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.
Propositional Logic Predicate Logic
Programming Languages Third Edition Chapter 4 Logic Programming.
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
In The Name Of Allah Lab 03 1Tahani Aldweesh. objectives Searching for the solution’s. Declaration. Query. Comments. Prolog Concepts. Unification. Disjunction.
Introduction to Prolog Asst. Prof. Dr. Senem Kumova Metin Revised lecture notes of “Concepts of Programmig Languages, Robert W. Sebesta, Ch. 16”
C. Varela1 Logic Programming (CTM ) Constraint Programming: Constraints and Computation Spaces Carlos Varela Rennselaer Polytechnic Institute.
1 Announcements HW2 due Thursday, 2/18 in class and in Homework Server Note on Problem 3: Show means prove Note on 4&7: Will cover material today Download.
1 Announcements We are almost done grading HW1 HW2 due today Download SWI Prolog! HW3 (Prolog) will be posted today, due on February 29 th Spring 16 CSCI.
Announcements Rainbow grades up HW1, Quiz 1-2 in HW Server Deadline for HW3 (Prolog) is extended to Monday, March 7 th. Submit in HW Server A few notes.
C. Varela1 Logic Programming (PLP 11, CTM 9.3) Prolog Imperative Control Flow: Backtracking, Cut, Fail, Not Lists, Append Carlos Varela Rennselaer Polytechnic.
Prolog Fundamentals. 2 Review Last Lecture A Prolog program consists of a database of facts and rules, and queries (questions). –Fact:.... –Rule:... :-....
Logic Programming Lecture 2: Unification and proof search.
Copyright © 2009 Elsevier Chapter 11 :: Logic Languages And other online sources (see links on schedule page) Michael L. Scott Based on Programming Language.
More on Prolog syntax Already seen program statement types: Already seen program statement types: rules: p(X) :- q(X,Y), r(Y,z). rules: p(X) :- q(X,Y),
By P. S. Suryateja Asst. Professor, CSE Vishnu Institute of Technology
Functional Programming: Lists, Pattern Matching, Recursive Programming (CTM Sections , 3.2, , 4.7.2) Carlos Varela RPI September 12,
Prolog a declarative language
Carlos Varela Rennselaer Polytechnic Institute November 11, 2016
CS 3304 Comparative Languages
For Friday No reading Prolog handout 3 Chapter 9, exercises 9-11.
Carlos Varela Rensselaer Polytechnic Institute November 17, 2017
Carlos Varela Rensselaer Polytechnic Institute December 5, 2017
Logic Programming with Prolog: Resolution, Unification, Backtracking
Carlos Varela Rennselaer Polytechnic Institute December 6, 2016
Carlos Varela Rensselaer Polytechnic Institute December 8, 2017
Declarative Computation Model Kernel language semantics (Non-)Suspendable statements (VRH ) Carlos Varela RPI October 11, 2007 Adapted with.
Prolog fundamentals Module 14.2 COP4020 – Programming Language Concepts Dr. Manuel E. Bermudez.
Logic Programming Languages
Chapter 11 :: Logic Languages
Prolog a declarative language
Prolog a declarative language
Prolog a declarative language
Chapter 11 :: Logic Languages
Carlos Varela Rensselaer Polytechnic Institute November 10, 2017
Chapter 12 :: Logic Languages
Chapter 12 :: Logic Languages
Logic Programming Language
Chapter 12 :: Logic Languages
Declarative Computation Model Single assignment store (VRH 2
Chapter 2: Prolog (Introduction and Basic Concepts)
Carlos Varela Rennselaer Polytechnic Institute November 15, 2016
Chapter 12 :: Logic Languages
Chapter 12 :: Logic Languages
Presentation transcript:

Carlos Varela Rensselaer Polytechnic Institute November 14, 2017 Logic Programming (PLP 11, CTM 9.1) Terms, Resolution, Unification, Search, Backtracking (Prolog) Relational Computation Model (Oz) Carlos Varela Rensselaer Polytechnic Institute November 14, 2017 C. Varela

Prolog Terms Constants Variables Predicates rpi troy University City located_at(rpi,troy) pair(a, pair(b,c)) Can be nested. C. Varela

Resolution To derive new statements, Robinson’s resolution principle says that if two Horn clauses: H1  B11 , B12 , …, B1m H2  B21 , B22 , …, B2n are such that H1 matches B2i, then we can replace B2i with B11 , B12 , …, B1m : H2  B21 , B22 , …, B2(i-1), B11 , B12 , …, B1m , B2(i+1) …, B2n For example: C  A,B E  C,D E  A,B,D C. Varela

Resolution Example father(X,Y) :- parent(X,Y), male(X). grandfather(X,Y) :- father(X,Z), parent(Z,Y). grandfather(X,Y) :- parent(X,Z), male(X), parent(Z,Y). :- is Prolog’s notation (syntax) for . C. Varela

Unification During resolution, free variables acquire values through unification with expressions in matching terms. For example: male(carlos). parent(carlos, tatiana). parent(carlos, catalina). father(X,Y) :- parent(X,Y), male(X). father(carlos, tatiana). father(carlos, catalina). C. Varela

Unification Process A constant unifies only with itself. Two predicates unify if and only if they have the same functor, the same number of arguments, and the corresponding arguments unify. A variable unifies with anything. If the other thing has a value, then the variable is instantiated. If it is an uninstantiated variable, then the two variables are associated. C. Varela

Backtracking Forward chaining goes from axioms forward into goals. Backward chaining starts from goals and works backwards to prove them with existing axioms. C. Varela

Backtracking example rainy(seattle). rainy(rochester). cold(rochester). snowy(X) :- rainy(X), cold(X). C. Varela

Backtracking example AND OR snowy(C) snowy(X) rainy(X) cold(X) rainy(seattle). rainy(rochester). cold(rochester). snowy(X) :- rainy(X), cold(X). snowy(C) snowy(X) AND rainy(X) cold(X) OR cold(rochester) rainy(seattle) rainy(rochester) C. Varela

Backtracking example AND OR snowy(C) _C = _X snowy(X) rainy(seattle). rainy(rochester). cold(rochester). snowy(X) :- rainy(X), cold(X). snowy(C) _C = _X snowy(X) cold(seattle) fails; backtrack. AND rainy(X) cold(X) X = seattle OR cold(rochester) rainy(seattle) rainy(rochester) C. Varela

Backtracking example AND OR snowy(C) _C = _X success snowy(X) rainy(seattle). rainy(rochester). cold(rochester). snowy(X) :- rainy(X), cold(X). snowy(C) _C = _X success snowy(X) cold(seattle) fails; backtrack. AND rainy(X) cold(X) X = seattle X = rochester OR cold(rochester) rainy(seattle) rainy(rochester) C. Varela

Relational computation model (Oz) The following defines the syntax of a statement, s denotes a statement s ::= skip empty statement | x = y variable-variable binding | x = v variable-value binding | s1 s2 sequential composition | local x in s1 end declaration | proc {x y1 … yn } s1 end procedure introduction | if x then s1 else s2 end conditional | { x y1 … yn } procedure application | case x of pattern then s1 else s2 end pattern matching | choice s1 [] … [] sn end choice | fail failure C. Varela

Relational Computation Model Declarative model (purely functional) is extended with relations. The choice statement groups a set of alternatives. Execution of choice statement chooses one alternative. Semantics is to rollback and try other alternatives if a failure is subsequently encountered. The fail statement indicates that the current alternative is wrong. A fail is implicit upon trying to bind incompatible values, e.g., 3=4. This is in contrast to raising an exception (as in the declarative model). C. Varela

Search tree and procedure The search tree is produced by creating a new branch at each choice point. When fail is executed, execution « backs up » or backtracks to the most recent choice statement, which picks the next alternative (left to right). Each path in the tree can correspond to no solution (« fail »), or to a solution (« succeed »). A search procedure returns a lazy list of all solutions, ordered according to a depth-first search strategy. C. Varela

C. Varela; Adapted with permission from S. Haridi and P. Van Roy Rainy/Snowy Example fun {Rainy} choice seattle [] rochester end fun {Cold} rochester proc {Snowy X} {Rainy X} {Cold X} {Browse {Search.base.all proc {$ C} {Rainy C} end}} {Browse {Search.base.all Snowy}} C. Varela; Adapted with permission from S. Haridi and P. Van Roy

Exercises Download SWI Prolog and Mozart 1.4.0 and install them in your laptop. Execute the “snowy(City)” example. In Prolog, use “tracing” to follow backtracking step by step. Create a knowledge base with facts about your family members using predicates and constants. Create rules using variables to define the following relationships: brother, sister, uncle, aunt, nephew, niece, grandfather, grandmother,etc. Query your Prolog/Oz program for family relationships. C. Varela