C. Varela1 Logic Programming (PLP 11, CTM 9.1) Terms, Resolution, Unification, Search, Backtracking (Prolog) Relational Computation Model (Oz) Carlos Varela.

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.
Chapter 12 - Logic Programming
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.
ISBN Chapter 16 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.
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.
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.
Ch. 13 Ch. 131 jcmt CSE 3302 Programming Languages CSE3302 Programming Languages (notes?) Dr. Carter Tiernan.
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.
Programming Language Concepts Lecture 17 Prepared by Manuel E. Bermúdez, Ph.D. Associate Professor University of Florida Logic Programming.
Knowledge Based Information System
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.
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),
Prolog a declarative language
Carlos Varela Rennselaer Polytechnic Institute November 11, 2016
CS 3304 Comparative Languages
Carlos Varela Rensselaer Polytechnic Institute November 17, 2017
Carlos Varela Rensselaer Polytechnic Institute December 5, 2017
Carlos Varela Rensselaer Polytechnic Institute November 14, 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.
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
Chapter 12 :: Logic Languages
Declarative Computation Model Single assignment store (VRH 2
Carlos Varela Rennselaer Polytechnic Institute November 15, 2016
Chapter 12 :: Logic Languages
Chapter 12 :: Logic Languages
Presentation transcript:

C. Varela1 Logic Programming (PLP 11, CTM 9.1) Terms, Resolution, Unification, Search, Backtracking (Prolog) Relational Computation Model (Oz) Carlos Varela Rennselaer Polytechnic Institute November 13, 2015

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

C. Varela3 Resolution To derive new statements, Robinson’s resolution principle says that if two Horn clauses: H 1  B 11, B 12, …, B 1m H 2  B 21, B 22, …, B 2n are such that H 1 matches B 2i, then we can replace B 2i with B 11, B 12, …, B 1m : H 2  B 21, B 22, …, B 2(i-1), B 11, B 12, …, B 1m, B 2(i+1) …, B 2n For example: C  A,B E  C,D E  A,B,D

C. Varela4 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. Varela5 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. Varela6 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. Varela7 Backtracking Forward chaining goes from axioms forward into goals. Backward chaining starts from goals and works backwards to prove them with existing axioms.

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

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

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

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

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

C. Varela13 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. Varela14 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; Adapted with permission from S. Haridi and P. Van Roy15 Rainy/Snowy Example fun {Rainy} choice seattle [] rochester end fun {Cold} rochester end proc {Snowy X} {Rainy X} {Cold X} end {Browse {Search.base.all proc {$ C} {Rainy C} end}} {Browse {Search.base.all Snowy}}

C. Varela16 Exercises 76.Download SWI Prolog and Mozart and install them in your laptop. 77.Execute the “snowy(City)” example. In Prolog, use “tracing” to follow backtracking step by step. 78.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.