prolog - CSC 24C: Principles of Programming Languages Logic...

Info iconThis preview shows pages 1–10. Sign up to view the full content.

View Full Document Right Arrow Icon

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

View Full DocumentRight Arrow Icon

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

View Full DocumentRight Arrow Icon

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

View Full DocumentRight Arrow Icon

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

View Full DocumentRight Arrow Icon

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

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: CSC 24C: Principles of Programming Languages Logic Programming c circlecopyrt Suzanne Stevenson 2001, with revisions by Cathy Jansen 1 Part V: Logic Programming and Prolog Logic programming languages are not procedural or functional. Specify relations between objects larger(3,2) father(tom,jane) Separate logic from control: Programmer declares what facts and relations are true. System determines how to use facts to solve problems. System instantiates variables in order to make relations true! Computation engine: theorem-proving and recursion (Unification, Resolution, Backward Chaining, Backtracking) Higher-level than imperative languages 2 Basic Facts and Relations Start with the basic facts... > cat family.P male(albert). <------------------------- a fact female(alice). Facts are put in a file. male(edward). female(victoria). parent(albert,edward). parent(victoria,edward). parent(albert,alice). parent(victoria,alice). > xsb | ?- [family]. <--------- loads file family.P yes | ?- male(albert). <--------------------- a query yes | ?- male(alice). no | ?- parent(albert,edward). yes | ?- parent(bullwinkle,edward). no Limited use: need variables and deductive rules. 3 Variables and Unification | ?- female(X). X = alice yes | ?- female(X). X = alice ; <------------ ; means look further X = victoria ; no X is unified to all possible values that make the query female(X) true. | ?- parent(P,edward). P = albert ; P = victoria ; no P is unified to all possible values that make the query parent(P,edward) true. search with pattern matching 4 In Prolog: All variables are capitalized All constants are in lower case All predicates are in lower case 5 Prolog Queries A query is a proposed fact that is to be proven. If the query has no variables, returns yes/no. If the query has variables, returns appropriate values of variables (called a substitution). 6 Horn Clauses (Rules) A Horn Clause is: c h 1 h 2 h 3 . . . h n Antecedents: conjunction of zero or more conditions which are atomic formulae in predicate logic Consequent: an atomic formula 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 , . . . , and h n are all true 7 Horn Clause Terminology Horn Clause = Clause Consequent = Goal = Head Antecedents = Subgoals = Tail Horn Clause with No Tail = Fact Horn Clause with Tail = Rule In Prolog, a Horn clause c h 1 . . . h n is written c :- h 1 , , h n . Syntax elements: :- , . 8 Prolog Horn Clause Examples A Horn clause with no tail: male(albert)....
View Full Document

This note was uploaded on 02/05/2011 for the course CS 24 taught by Professor Cathy during the Summer '10 term at University of Toronto- Toronto.

Page1 / 58

prolog - CSC 24C: Principles of Programming Languages Logic...

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

View Full Document Right Arrow Icon
Ask a homework question - tutors are online