This preview shows pages 1–8. Sign up to view the full content.
This preview has intentionally blurred sections. Sign up to view the full version.
View Full DocumentThis preview has intentionally blurred sections. Sign up to view the full version.
View Full DocumentThis preview has intentionally blurred sections. Sign up to view the full version.
View Full DocumentThis preview has intentionally blurred sections. Sign up to view the full version.
View Full Document
Unformatted text preview: Principles of Programming Languages Principles of Programming Languages Lecture 3 Lecture 3 Wael Aboulsaadat Wael Aboulsaadat wael@cs.toronto.edu wael@cs.toronto.edu http://portal.utoronto.ca/ 1 Today Today Logic Programming Prolog I 2 LP: resolution in predicate calculus LP: resolution in predicate calculus We would like to infer new propositions (e.g. facts) from some existing set of propositions. An inference rule that can be applied atomically is called a resolution E.g. Given: P1 b P2 , Q1 b Q2 P1 Q2 Alternatively : T b P2 , Q1 b T New fact: Q1 b P2 New Set of Rules: P1 b P2 , Q1 b Q2 , Q1 b P2 Resolution gets more complex if variables/values are involved: To use resolution with variables, we will need to find values for variables that allow matching to proceed. E.g. Given: F(X,Y) b P2(Y,X) Q1(foo) b F(foo, bar) New fact: Q1(foo) b P2(bar, foo) New Set of Rules: F(X,Y) b P2(Y,X) , Q1(foo) b F(foo, bar) , Q1(foo) b P2(bar, foo) 3 LP: horn clause LP: horn clause Logic programming is heavily based on horn clauses: Antecedents (h's): conjunction of zero or more conditions which are atomic constructs in predicate logic. Consequent(c): an atomic construct in predicate logic Meaning of a hornclause: The consequent is true if the antecedents are all true c is true if h 1 , h 2 , h 3 ,.... are all true A horn clause can capture most, but not all, logical statements/implications, why? Additional reading: http://en.wikipedia.org/wiki/Horn_clause 4 LP: horn clause made easy! LP: horn clause made easy! Horn clause can include more complex terms: p(X) b q(X,Y) r(X,Y) s(X,Y) p(X) b K(M) i(T) q(X,Y) b r(X,Y) b s(X,Y) b k(M) b i(T) b .. We can assume the following when writing hornclauses: p is the program name q,r,s are the subprogram names X is a parameter of the program Y is a local variable 5 LP: horn LP: horn clause clause Antecedents (h's): conjunction of zero or more conditions which are atomic constructs in predicate logic. Consequent(c): an atomic construct in predicate logic Examples of horn clauses: Father (X, Y) b Child (Y, X) Male (X). Student(X) b Undergraduate(X). Example of Nonhorn clauses: Student(X) b Undergraduate(X) V Graduate(X) (Student(X) ) b Deregistered(X). 6 LP: specifying non LP: specifying nonhorn rules horn rules Many nonhorn rules can be transformed to horn form using one of two methods: logical equivalence Skolemization Logical equivalence: Uses the following logical laws: Negation A A De Morgans Law (A V B) A...
View
Full
Document
This document was uploaded on 08/02/2011.
 Spring '09
 C Programming

Click to edit the document details