ch15b - Programming Languages 2e Tucker and Noonan Chapter...

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

View Full Document Right Arrow Icon
Programming Languages 2e Tucker and Noonan Chapter 15 – part 2 Logic Programming “Q: How many legs does a dog have if you call its  tail a leg?  A: Four. Calling a tail a leg doesn’t make it one.”     Abraham Lincoln
Background image of page 1

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

View Full DocumentRight Arrow Icon
Review Prolog is a logic-based language Its syntax is based on Horn clauses, a predicate form derived from the predicate calculus. It is also a declarative language Prolog programs describe goals and provide facts and rules for the Prolog system to use in searching for a goal solution. Compare to imperative languages, which describe algorithms and specify the exact steps required to achieve a goal.
Background image of page 2
Review Propositions: statements which are either true or false; e.g., “my dog is black” Propositions can be represented by symbols, combined with logical operators, and have truth values based on the individual propositions; e.g. p Λ q is true only if both p and q are true. Predicates: Propositions with variables, and/ or quantifiers: 2200 (for all) 5 (there exists) 5 x(dog(x) Λ black(x)); 2200 (x)(dog(x) → black(x))
Background image of page 3

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

View Full DocumentRight Arrow Icon
Review: Basic Program Elements A Prolog program consists of terms: Atoms: literal strings or numbers Variables: consist of letters and underscores, must start with an upper-case letter Atoms are distinguished from variables because atoms start with a lower-case letter Prolog variables aren’t the same as variables in imperative languages; they don’t represent values. They are temporarily bound to objects/values during resolution. Structures: functor(parameters) Structures are predicates
Background image of page 4
Review: Facts and Rules Prolog facts are headless Horn clauses: student(jack, cs424). sweet(sugar). Prolog rules are headed Horn clauses: fattening(X) :- sweet(X). driversLicense(X) :- sixteen(X), passTest(X).
Background image of page 5

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

View Full DocumentRight Arrow Icon
Review: Queries Prolog programs consist of facts and rules. Users describe goal states by posing queries. Goals are described by assertions that state the characteristics of the desired goal. Using the facts and rules in the program, the Prolog system attempts to find a solution to the query.
Background image of page 6
Review Prolog uses resolution theorem proving , instantiation , and unification to find goal states. The search process is a backtracking approach : in case one goal cannot be satisfied, back up to the nearest previous goal state and try another approach.
Background image of page 7

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

View Full DocumentRight Arrow Icon
Example Suppose a program has these facts & rules: mother(sue). mother(jane). female(X) :- mother(X). To prove/disprove the goal female(jane). First find the fact mother(sue). Reject. Next find mother(jane). Matches on jane “Unify” mother(X) in the rule and mother(jane) in the fact (by instantiating X
Background image of page 8
Search Suppose a query has compound goals (several propositions must be satisfied) Depth-first searches prove the first goal before looking at the others. Breadth-first works on goals in parallel.
Background image of page 9

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

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

This note was uploaded on 04/21/2010 for the course CS 424 taught by Professor Weisskopf during the Spring '10 term at University of Alabama - Huntsville.

Page1 / 59

ch15b - Programming Languages 2e Tucker and Noonan Chapter...

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