- Review predicate calculus (see Lecture 9 from CS 270).
- Chapters 13 and 14 of Alfred V. Aho and Jeffrey D. Ullman, Foundations of Computer Science - C Edition, W. H. Freeman and Company, 1995.

- Chapter 11 of the text.

- gcd(U,0,U).
- gcd(U,V,W) :- V=\=0, R is U mod V, gcd(V,R,W).
- append([],Y,Y).
- append([X|XS],Y,[X|ZS]) :- append(XS,Y,ZS).
- sort(X,Y) :- permutation(X,Y), sorted(Y).

- Horn clauses and queries.
A Horn claus is a statement of the form a_1 and a_2 and ... and a_n &rarr b. In prolog is is written b :- a1,a2,...,an. b is called the

**head**, and a_1,a_2,...,a_n the**body**. A clause without a body is always true and is called an axiom or fact. A Horn clause without a head is considered a query or goal.- ancestor(X,Y) :- parent(X,Z), ancestor(Z,Y).
- ancestor(X,X).
- parent(amy,bob).

- ?- parent(amy,bob).
- yes
- ?- ancestor(amy,bob).
- true ?
- yes
- ?- ancestor(bob,amy).
- no
- ?- ancestor(X,bob).
- X = amy ? ;
- X = bob
- yes

- Arithmetic.
- is predicate.
- X is 3+4*5.
- is(X,3+4*5).

- Resolution and unification.
If we have Horn clauses a &larr a_1,...,a_n. and b &larr b_1,...,b_m. and b_i matches a, then we can infer the clause b &larr b_1,...,b_{i-1},a_1,...,a_n,b_{i+1},...,b_m. In the case when there is only a single statement in the body: b &larr a. and c &larr b, then we infer c &larr a.

In order to match statements it may be necessary to instantiate variables. This process is called

**unification**.- legs(x,2) &larr mammal(x), arms(x,2).
- legs(x,4) &larr mammal(x), armx(x,0).
- mammal(horse).
- arms(horse,0).

- legs(horse,4).
- legs(horse,Y).

- Backtracking.
- Lists.

- None for this lecture - see required reading and sample programs.

- Alfred V. Aho and Jeffrey D. Ullman, Foundations of Computer Science - C Edition, W. H. Freeman and Company, 1995.
- GNU Prolog
- Prolog page on wikipedia.

- Trace resolution and unification using the query gcd(15,10,X).
- Install GNU Prolog and try some simple examples.