Presentation is loading. Please wait.

Presentation is loading. Please wait.

Prolog Prolog: Programming in Logic Prolog programs consist of clauses and rules. Declarative programming –Emphasis is on data and relations between objects.

Similar presentations


Presentation on theme: "Prolog Prolog: Programming in Logic Prolog programs consist of clauses and rules. Declarative programming –Emphasis is on data and relations between objects."— Presentation transcript:

1 Prolog Prolog: Programming in Logic Prolog programs consist of clauses and rules. Declarative programming –Emphasis is on data and relations between objects. –No familiar procedural controls. –Built-in inference engine.

2 Where is declarative programming useful? Data-driven programming tasks –Verification –Natural Language –Expert Systems –Relational Databases –Diagnostic Systems

3 Logical Operators ABA^B 000 010 100 111 AND: Conjunction ABAvB 000 011 101 111 OR: Disjunction NOT: Inversion A!A 01 10

4 Logical Operators ABA->B 001 011 100 111 Implication A->B is equivalent to !AvB ABA B 001 010 100 111 Equivalence A B is equivalent to: A->B ^ B->A (A ^ B) v (!A ^ !B)

5 Propositional Calculus Represent facts as symbols. –Homer_likes_beer. –Lisa_likes_tofu. –!(Bart_likes_school) –Bart_likes_school -> Bart_does_homework. –Lisa_likes_school ^ Lisa_likes_music Easy, but overly verbose. No reuse.

6 Predicate Calculus A predicate is a function that maps from zero or more objects to {T,F}. –Likes(Homer, beer) –!Likes(Bart, school) –Likes(Bart, school) -> Does(Bart, homework). –Happy(Lisa). –Gives(Moe, Homer, beer) -> Happy(Homer). Predicates provides a syntactic shorthand for propositions. No extra representational power.

7 Inference Rules AND-elimination: –If A^B is true, then A is true. –likes(Homer,beer) ^ likes(Homer, food)->likes(Homer,beer) OR-introduction: –If A is true, then AvB is true. –likes(Homer,food)->likes(Homer,food)v likes(Homer,work). Modus Ponens: –If A->B is true, and A is true, then B is true. –likes(Lisa,school)->does(Lisa,homework) ^ likes(Lisa,school) -> Does(Lisa,homework)

8 Quantification We would like to be able to express facts such as: –“Everyone who likes school does their homework.” –“No one who likes beef also likes tofu.” –“Someone likes beef.” This requires us to be able to quantify over variables in the domain.

9 First-Order Logic First order logic allows quantification over objects. Universal quantification: “For all x”  x likes(x,school) -> does(x, homework). “Everyone who likes school does their homework.” Existential quantification: “There exists an x”  x likes(x,tofu). “There exists someone who likes tofu.”

10 Computational Issues Full FOL is too computationally difficult to work with. –Nested quantifiers are semi-decidable.  x  y  z likes(x,y) ^ likes(y,z). “Everyone likes a person who likes everyone.” –Implications with an AND in the consequent are exponentially hard.  x likes(x, school) -> does(x,homework) ^ attends(x,class) “Everyone who likes school does their homework and attends class.”

11 Horn clauses Horn clauses are implications of the form: x ^ y ^ z -> a Only a single term in the consequent. Horn clause inference is computationally tractable. Prolog uses Horn clauses.

12 Knowledge Representation in Prolog Facts (unit clauses): –likes(homer, beer). Constants are lower case. Names of relations are lower case. Conjunctions: –likes(homer,beer). –likes(homer,food). Statement is represented as separate Prolog clauses. <- ends with a period

13 Knowledge Representation in Prolog Rules –does(lisa,homework) :- likes(lisa,school). –Equivalent to: likes(lisa,school) ->does(lisa,homework) –Read as: “Lisa does homework if she likes school.” or … –“To prove that Lisa does homework, prove that she likes school.”

14 Variables Variables are all upper-case. Universal quantification is achieved by using variables in rules. –does(X,homework) :- likes(X,school). “Everyone who likes school does their homework.” “To prove that someone does their homework, prove that they like school.”


Download ppt "Prolog Prolog: Programming in Logic Prolog programs consist of clauses and rules. Declarative programming –Emphasis is on data and relations between objects."

Similar presentations


Ads by Google