1 / 22

Introduction to Prolog

Introduction to Prolog. CS321. Brief History. The first, official version of Prolog was developed at the University of Marseilles, France by Alain Colmerauer in the early 1970s as a tool for PROgramming in LOGic. . Application Areas. Prolog has been a very important tool in

woody
Download Presentation

Introduction to 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. Introduction to Prolog CS321

  2. Brief History • The first, official version of Prolog was developed • at the University of Marseilles, France • by Alain Colmerauer • in the early 1970s • as a tool for PROgramming in LOGic.

  3. Application Areas • Prolog has been a very important tool in • artificial intelligence applications • expert systems • Updated versions of Prolog are now being used for • natural language interfaces • smart information management systems

  4. Declarative Language • This means that • The programmer • declares facts • defines rules for reasoning with the facts • Prolog uses deductive reasoning to • determine new facts from old • decide whether a proposed fact (goal) can be logically derived from known facts (such a decision is called a conclusion)

  5. Predicate • In classic logic, a declarative statement (fact) is called a predicate. • The next few slides review relevant classic logic, as related to logic programming

  6. Predicates • A predicate is • decidable (true or false) • A sentence that can be put in the place of “…” in the sentence Is it true that “…”? • Examples: The sky is red. I am honest.

  7. Primitive, Compound • A predicate is a primitive statement • it cannot be broken down into simpler form • can be represented by a single symbol p: I am a computer science major. q: My printer is not working today. • Predicates can be combined into compound statements with logical connectors

  8. Logical Connectors • Negation ! q • Conjunction • p and q • Disjunction (inclusive, one or both) • p or q • Disjunction (exclusive, one or the other) • p or q , but not both

  9. Implication (rule) • An if…then “relationship” between predicates p :- q can mean any of • “ if p is true, then q is also true” • “q is necessary for p” • “ p only if q’ Note: this is not necessarily a “cause and effect” type of relationship • p is the hypothesis (premise) and q is the conclusion

  10. Arguments • Central to the notion of logic is an argument: … a set of predicates used as hypotheses to justify a conclusion • Example: If Socrates is a man then Socrates is mortal. Socrates is a man. Therefore, Socrates is mortal.

  11. Argument Structure • A (modus ponens) argument structure can be represented as: If Ssss is an xxxxx then Ssss is a yyyyy. Ssss is an xxxxx. Therefore, Ssss is a yyyyy. • We can judge the validity of the argument by its structure (form), rather than by its meaning.

  12. Formalizing Arguments • Abstracting with symbols for predicates, we get an argument form that looks like this: if p then q p therefore q • Thus, the formal representation ((p :- q)  p)  q

  13. Predicate Logic • When we look at predicates abstractly, we see that the correctness of an argument is not governed by its content (meaning), but by its logical form. • There are rules (procedures) to decide whether or not a given argument is acceptable. (Rules of Inference)

  14. Rules of Inference • Modus Ponens • If p then q, p, therefore q • Law of Syllogism • p, then q, q then rp, therefore r • Modus Tollens (mode that denies) • If P, then Q. Q is false. therefore P is false. • Rule of Conjunction • If p and q, therefore p or q

  15. Logic Programming Language • Prolog is a language where the language implementation is a collection of procedures (functions) based on the rules of inference in classical logic Modus Ponens Law of Syllogism Modus Tollens Rule of Conjunction

  16. Inference Engine • The procedures for reasoning logically about facts are combined with a pattern matcher to create the inference engine • A pattern matcher • retrieves stored facts by matching answers to questions. • infers that a hypothesis is true by questioning the set of facts already known to be true

  17. Prolog program • Prolog's known world is the finite set of facts (and rules) that are given in a program. • Typically, a Prolog program isn't a sequence of actions--it's a list of facts together with inference rules. • The Prolog system arrives at conclusions by logically inferring new facts from known facts.

  18. Writing Predicates in Prolog • First eliminate all unnecessary words from your sentences. • Then transform the sentence, placing the relationship first and grouping the objects after the relationship. • The objects then become arguments that the relationship acts upon. • See examples, next slide

  19. Examples Natural Language: Predicate Logic: A car is fun. fun(car). A rose is red. red(rose). Bill likes a car likes(bill,Car)if fun(Car). if the car is fun.

  20. Facts • A Fact declares a relation between objects likes(bill, cindy). likes(cindy, bill). likes(bill, dogs). • Facts can also express properties of objects green(kermit). girl(caitlin).

  21. Rules • Rules enable you to infer facts from other facts. • Another way to say this is: a rule states a way to conclude a new fact -- if one or more other facts can be shown to be true. Cindy likes everything that Bill likes. Caitlin likes everything that is green.

  22. FACTS: likes(bill, cindy). likes(cindy, bill). likes(bill, dogs). green(kermit). girl(caitlin). RULES: Cindy likes everything that Bill likes. Caitlin likes everything that is green. What new facts can we infer from the known facts and rules? Cindy likes Cindy. Caitlin likes Kermit. Inference

More Related