{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

324-lecture3

# 324-lecture3 - Principles Principles of Programming...

This preview shows pages 1–8. Sign up to view the full content.

Principles of Programming Languages Lecture 3 Wael Aboulsaadat [email protected] http://portal.utoronto.ca/ 1

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
Today Logic Programming Prolog I 2
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 barb4left P2 , Q1 barb4left Q2 P1 Q2 Alternatively : T barb4left P2 , Q1 barb4left T New fact: Q1 barb4left P2 New Set of Rules: P1 barb4left P2 , Q1 barb4left Q2 , Q1 barb4left 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) barb4left P2(Y,X) Q1(foo) barb4left F(foo, bar) New fact: Q1(foo) barb4left P2(bar, foo) New Set of Rules: F(X,Y) barb4left P2(Y,X) , Q1(foo) barb4left F(foo, bar) , Q1(foo) barb4left P2(bar, foo) 3

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
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 horn-clause: 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! Horn clause can include more complex terms: p(X) barb2left q(X,Y) Λ r(X,Y) Λ s(X,Y) p(X) barb2left K(M) Λ i(T) q(X,Y) barb2left …… r(X,Y) barb2left …… s(X,Y) barb2left …… k(M) barb2left …… i(T) barb2left …… ….. We can assume the following when writing horn-clauses: 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

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
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) barb4left Child (Y, X) Λ Male (X). Student(X) barb4left Undergraduate(X). Example of Non-horn clauses: Student(X) barb4left Undergraduate(X) V Graduate(X) ¬ (Student(X) ) barb4left Deregistered(X). 6
LP: specifying non -horn rules horn rules Many non-horn 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 Morgan’s Law ¬(A V B) ¬A Λ ¬B ¬(A Λ B) ¬A V ¬B Distributive Property A V (B Λ C) (A V B) Λ (A V C) A Λ (B V C)

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### Page1 / 24

324-lecture3 - Principles Principles of Programming...

This preview shows document pages 1 - 8. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online