CSE583: Programming Languages

2/15/00


Click here to start


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 scoped within 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 be homogeneous

Unification of terms

Unification of terms S and T

More unification examples

Unification is implicit in 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 only works 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 bottom rule 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 not always what we want

delete_all example

A query for delete_all

delete_all can succeed in any of three ways...

delete_all has multiple matching rules

Third rule contained implicit assumption

Use a “cut” — !

The query again

Cut divides problem into 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