Cs7120 (Prasad)L16-Meaning1 Procedural and Declarative Meaning of Prolog

Slides:



Advertisements
Similar presentations
Computer Science CPSC 322 Lecture 25 Top Down Proof Procedure (Ch 5.2.2)
Advertisements

Cs7120 (Prasad)L22-MetaPgm1 Meta-Programming
LING 388: Language and Computers Sandiway Fong Lecture 5: 9/5.
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. 2 A little bit of Prolog Objects and relations between objects Facts and rules. Upper case are variables. parent(pam, bob).parent(tom,bob).
Lecture 10 Logic programming, PROLOG (PROgramming in LOGic)
Answer Set Programming Overview Dr. Rogelio Dávila Pérez Profesor-Investigador División de Posgrado Universidad Autónoma de Guadalajara
1Lecture 12 Introduction to Prolog SWI-Prolog. 2Lecture 12 Introduction to Prolog Welcome to SWI-Prolog (Version 4.0.9) Copyright (c) University.
Logic.
© by Kenneth H. Rosen, Discrete Mathematics & its Applications, Sixth Edition, Mc Graw-Hill, 2007 Chapter 1: (Part 2): The Foundations: Logic and Proofs.
Copyright © 2006 Addison-Wesley. All rights reserved.1-1 ICS 410: Programming Languages Chapter 3 : Describing Syntax and Semantics Axiomatic Semantics.
ISBN Chapter 3 Describing Syntax and Semantics.
MB: 2 March 2001CS360 Lecture 31 Programming in Logic: Prolog Prolog’s Declarative & Procedural Semantics Readings: Sections
CS128 – Discrete Mathematics for Computer Science
UNIVERSITY OF SOUTH CAROLINA Department of Computer Science and Engineering Controlling Backtracking Notes for Ch.5 of Bratko For CSCE 580 Sp03 Marco Valtorta.
Constraint Logic Programming Ryan Kinworthy. Overview Introduction Logic Programming LP as a constraint programming language Constraint Logic Programming.
CSE 311 Foundations of Computing I Lecture 6 Predicate Logic Autumn 2011 CSE 3111.
1 Discrete Structures CS 280 Example application of probability: MAX 3-SAT.
CSE (c) S. Tanimoto, 2005 Logic Programming 1 Logic Programming Outline: Motivation Examples: The Grandmother relation Formulation in Prolog Logic,
Describing Syntax and Semantics
Copyright © Cengage Learning. All rights reserved.
Propositional Calculus Math Foundations of Computer Science.
SAT Solver Math Foundations of Computer Science. 2 Boolean Expressions  A Boolean expression is a Boolean function  Any Boolean function can be written.
CSE 311 Foundations of Computing I Lecture 6 Predicate Logic, Logical Inference Spring
FATIH UNIVERSITY Department of Computer Engineering Controlling Backtracking Notes for Ch.5 of Bratko For CENG 421 Fall03.
Systems Architecture I1 Propositional Calculus Objective: To provide students with the concepts and techniques from propositional calculus so that they.
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 Inference Rules and Proofs (Z); Program Specification and Verification Inference Rules and Proofs (Z); Program Specification and Verification.
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.
14/10/04 AIPP Lecture 7: The Cut1 Controlling Backtracking: The Cut Artificial Intelligence Programming in Prolog Lecturer: Tim Smith Lecture 7 14/10/04.
Slide 1 Propositional Definite Clause Logic: Syntax, Semantics and Bottom-up Proofs Jim Little UBC CS 322 – CSP October 20, 2014.
2.3Logical Implication: Rules of Inference From the notion of a valid argument, we begin a formal study of what we shall mean by an argument and when such.
CSE S. Tanimoto Horn Clauses and Unification 1 Horn Clauses and Unification Propositional Logic Clauses Resolution Predicate Logic Horn Clauses.
1Lecture 12 Introduction to Prolog Logic Programming Prolog.
PROLOG SYNTAX AND MEANING Ivan Bratko University of Ljubljana Faculty of Computer and Info. Sc. Ljubljana, Slovenia.
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.
CSE 311 Foundations of Computing I Lecture 7 Logical Inference Autumn 2012 CSE
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.
1 Georgia Tech, IIC, GVU, 2006 MAGIC Lab Rossignac Lecture 02: QUANTIFIERS Sections 1.3 and 1.4 Jarek Rossignac CS1050:
C. Varela1 Logic Programming (PLP 11) Predicate Calculus, Horn Clauses, Clocksin-Mellish Procedure Carlos Varela Rennselaer Polytechnic Institute November.
Cs774 (Prasad)L6Backtracking1 Controlling Backtracking : Cuts
Lecture course: Heuristics & Prolog for Artificial Intelligence Applications Notes on Prolog from Professor Bruce Batchelor, DSc.
Knowledge Based Information System
1-1 An Introduction to Logical Programming Sept
Instructor: Eyal Amir Grad TAs: Wen Pu, Yonatan Bisk Undergrad TAs: Sam Johnson, Nikhil Johri CS 440 / ECE 448 Introduction to Artificial Intelligence.
07/10/04 AIPP Lecture 5: List Processing1 List Processing Artificial Intelligence Programming in Prolog Lecturer: Tim Smith Lecture 5 07/10/04.
PREDICATES AND QUANTIFIERS COSC-1321 Discrete Structures 1.
Copyright 1999Paul F. Reynolds, Jr. Foundations of Logic Programming.
CSE (c) S. Tanimoto, 2001 Logic Programming
Propositional Equivalence
Recursive stack-based version of Back-chaining using Propositional Logic
CSE 341, S. Tanimoto Logic Programming -
Horn Clauses and Unification
Propositional Calculus: Boolean Algebra and Simplification
Discrete Mathematics CS 2610
CSE 311 Foundations of Computing I
Prolog syntax + Unification
Carlos Varela Rensselaer Polytechnic Institute November 10, 2017
Horn Clauses and Unification
Horn Clauses and Unification
Horn Clauses and Unification
CSE (c) S. Tanimoto, 2004 Logic Programming
CSE (c) S. Tanimoto, 2002 Logic Programming
Horn Clauses and Unification
Controlling Backtracking : Cuts
Carlos Varela Rennselaer Polytechnic Institute August 30, 2007
Presentation transcript:

cs7120 (Prasad)L16-Meaning1 Procedural and Declarative Meaning of Prolog

p :- q, r. q. Declarative –Machine independent. Formalized through propositional and predicate logic. p is true if q is true and r is true. q is true. Procedural To solve p: first solve q, and then solve r. q is solved. cs7120 (Prasad)L16-Meaning2

Consequences : Equivalence Declarative Reading p :- q, r. q. equivalent to p :- r, q. q. since “OR”and “AND” are commutative. p :- p. p. equivalent to p. p :- p. since “AND” is commutative. cs7120 (Prasad)L16-Meaning3

(cont’d) Procedural Reading p :- p. p. is not equivalent to p. p :- p. The former program loops on the query ?-p, while the latter program succeeds. Prolog strategy is computationally efficient but incomplete. cs7120 (Prasad)L16-Meaning4

Declarative Meaning Specifies whether or not a given goal G is true, and if so, for what values of the variables is it true. Instance of a clause C is obtained by substituting terms for each of its variables. Variant of a clause C is obtained by renam- ing the variables of C. cs7120 (Prasad)L16-Meaning5

Example Clause: p(X) :- q(X,Y), r(Y). Instance: p(a) :- q(a,Y), r(Y). p(b) :- q(b,b), r(b). Variant: p(A) :- q(A,B), r(B). cs7120 (Prasad)L16-Meaning6

Declarative Meaning Given a program P and a goal G, G is true ( i.e., logically follows from P) if and only if: (1) There is a clause C in P such that (2) there is a clause instance I of C such that (a) the head of I is identical to G, and (b) all the goals in the body of I are true. (Recursive definition of satisfaction) cs7120 (Prasad)L16-Meaning7

An instance of a clause C is obtained by renaming each variable in C and possibly substituting the variable by some term. E.g. an instance of p(X,Y) :- q(Y,Z). is p(U,a) :- q(a,V). Recall that scope of a variable is the clause (locality of reference) and same variable name implies equality constraint. cs7120 (Prasad)L16-Meaning8

Specifies how Prolog answers questions. Procedural meaning is an algorithm to execute a list of goals given a Prolog program: program success/failure indication goal list execute instantiation of variables Procedural Meaning 

procedure execute( Program, GoalList, Success) execute = declarative meaning + procedural elements G is true ( i.e. logically follows from P) if and only if: (1) there is a clause C in P such that (2) there is a clause instance I of C such that (a) the head of I is identical to G, and (b) all the goals in the body of I are true Search program from top to bottom to find such clause Match G and head of C Execute goals in order as they appear in program

procedure execute( Program, GoalList, Success) begin if empty(GoalList) then Success := true else begin Goal := head(GoalList); OtherGoals := tail(GoalList); Satisfied := false; while not Satisfied and “more clauses in Program” do begin (* NEXT GoalList GENERATION *)(* NEXT GoalList GENERATION *) end; Success := Satisfied end end; cs7120 (Prasad)L16-Meaning11

Let next clause in Program be H :- B1, B2, …, Bn. Construct a variant of this clause (variables disjoint from GoalList) H’ :- B1’, B2’, …, Bn’. match(Goal, H’, MatchOK, substitution); if MatchOK then begin NewGoals := apply(substitution, append( [B1’,B2’,…,Bn’], OtherGoals) ); execute(Program, NewGoals, Satisfied); end cs7120 (Prasad)L16-Meaning12

Debugging Prolog Welcome to SWI-Prolog (Multi-threaded, 32 bits, Version ) Copyright (c) University of Amsterdam. … For help, use ?- help(Topic). or ?- apropos(Word). 1 ?- consult(user). | likes(mary,food). likes(mary,wine). likes(john,wine). likes(john,mary). | % user://2 compiled 0.00 sec, 632 bytes cs7120 (Prasad)L16-Meaning13

2 ?- trace, likes(X,Y). Call: (9) likes(_G597, _G598) ? creep Exit: (9) likes(mary, food) ? creep X = mary, Y = food ; Redo: (9) likes(_G597, _G598) ? creep Exit: (9) likes(mary, wine) ? creep X = mary, Y = wine ; Redo: (9) likes(_G597, _G598) ? creep Exit: (9) likes(john, wine) ? creep … [debug] 4 ?- likes(tom,john). false. cs7120 (Prasad)L16-Meaning14 Debugging trace. spy(…). ; …?creep …?leap …?abort

Propositional Prolog p.  p :- true. p :- q. p if q cs7120 (Prasad)L16-Meaning15 p => qtruefalse true false true Facts Rules Boolean Logic

De Morgan’s Laws cs7120 (Prasad)L16-Meaning16 p :- q,r.

cs7120 (Prasad)L16-Meaning17 p :- q. p :- r. p :- q ; r. cf. Normal Form / Clausal form Sum of product form disjunctive normal form product of sum forms conjunctive normal form