More Prolog - Planning




CS156

Chris Pollett

Nov 9, 2022

Outline

Introduction

Prolog Example

Prolog uses unification. Consider the Prolog program:

num(0).
num(s(X)) :- num(X).

Prolog is case sensitive. Variables must begin with a capital letter, otherwise, Prolog assumes one is referring to a constant or function symbol.

Notice in the above, the clauses now involve first-order, atomic formulas, this is the setting in which most people write their Prolog programs.

From the Prolog prompt we can then do a query like:

|?- num(Y).

It will unify Y with 0 initially and say

Y = 0

To indicate that num(Y) can be made true if we set Y = 0. If we type `n`, we are indicating we don't want that solution and it will try to resatisfying the statement with a different substitution. i.e., it is as if we did the query num(Y), not(Y = 0). To this Prolog, will now make use of the second rule and return:

Y = s(0)

If Prolog did occurs checks then the following kind of query would fail:

|?- num(s (s (X))) 

Example of Unify's Execution

Let's return to the unification algorithm from the end of last day. As an example of unify in action, consider:

x' = g(h(x, y), z)
y' = g(w, t(v))

Initially, S, the substitution list is (). Since x' and y' are both terms, we return

Unify((h(x, y), z), (w, t(v)), Unify(g(a, b), g(a, b), ())) 

Notice that a, b are new variable names. The second Unify will return S = (), since both g(a, b) are the same thing.

So now we try to unify two lists (h(x, y), z), (w, t(v)).

So we will do Unify( (z), (t(v)), Unify (h(x, y), w, S)). S is still ().

Now we call Unify-var (w, h(x,y), S).

This statement will return (w |-> h(x, y)). We now need to unify (z) and (t(v)) with respect to the substitution (w |-> h(x,y)). When we get the final recursive answer, we will have ( (z |-> t(v)), (w |-> h(x,y)) )

Example of Theorem Proving Process

The example images below show going from an English riddle to first-order logic formulas expressing that riddle then Skolemizing and converting to clauses for `KB ^^ neg alpha`, then giving a resolution refutation:

Initial riddle
Riddle in Logic
Riddle as clauses
Refutation

In-Class Exercise

Equality