Table of Contents
CSE583: Programming Languages
Two weeks: logic and constraint logic programming paradigms
Note
(Symbolic) Logic
Logic basics
Connectives
Quantifiers
Formulae
?
Predicate logic and English
Theorems
Tautologies and contradictions
But...
Prolog
Prolog deals with relations
History of Prolog
Not for general purpose programming
Why restrict applicability of a language?
Example applications
A Prolog Program
Example facts and simple queries
Syntax for facts
Variables
Variables are scopedwithin a query
More facts
A simple rule
Example
Proving
Two interpretations of rule
Eight Queens:A typical search problem
A Solution to Eight Queens
Eight Queens in Prolog
Query for solution
Our friend the list
Declaration of append rule
“Return value”is an argument of the rule
Terminology
Lists
Lists need not behomogeneous
Unification of terms
Unification of terms S and T
More unification examples
Unification is implicitin rule application
Unification in append rule
Trace of app([1,2,3],A,[1,2,3,4])
Trace of app([1,2,3],[4],Z)
Horn clauses
Why this limitation?
Example
Resolution
Arithmetic in Prolog
Change for a dollar: J.R. Fisher
Arithmetic onlyworks forward in Prolog
member rule
Definition of member
The declarative interpretation falls short…
More uses of member
Reminder: How Prolog tries to prove
Evidence of top to bottomrule order
Order of rules matters!
Trace of mem1(2,[1,2,3])
Trace of mem2(2,[1,2,3])
mem1 was faster
PPT Slide
PPT Slide
PPT Slide
PPT Slide
Prolog is not an oracle!
PPT Slide
PPT Slide
PPT Slide
PPT Slide
PPT Slide
PPT Slide
PPT Slide
PPT Slide
PPT Slide
PPT Slide
PPT Slide
PPT Slide
PPT Slide
PPT Slide
PPT Slide
PPT Slide
Search algorithm
Multiple sub-goals
Another search tree…
Tracing through the tree
PPT Slide
PPT Slide
PPT Slide
PPT Slide
PPT Slide
PPT Slide
PPT Slide
PPT Slide
PPT Slide
PPT Slide
PPT Slide
PPT Slide
PPT Slide
PPT Slide
Backtracking is notalways what we want
delete_all example
A query for delete_all
delete_all can succeedin any of three ways...
delete_all has multiple matching rules
Third rule contained implicit assumption
Use a “cut” — !
The query again
Cut divides probleminto backtracking regions
Controversy over cut
cut and not
!, fail combination
Tree view of a cut
Tree view of a cut
Icon
Expression evaluation
Generators
Examples
Writing generators
In some sense, that’s it
Other cool things
More
Next week: CLP(R)
|
Author: David Notkin
Email: notkin@cs.washington.edu
Home Page: http://www.cs.washington.edu/education/courses/583
Download presentation source
|