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

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

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

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

View Full Document
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.
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))

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

View Full Document
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
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).

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

View Full Document
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.
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.

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

View Full Document
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
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.

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

View Full Document
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
Ask a homework question - tutors are online