1 / 14

Prolog

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. Where is declarative programming useful?. Data-driven programming tasks

brygid
Download Presentation

Prolog

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

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 AND: Conjunction OR: Disjunction NOT: Inversion

  4. Logical Operators Implication Equivalence A->B is equivalent to !AvB 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.”

More Related