0% found this document useful (0 votes)
97 views

Prolog: Tutorial 5: Barbara Morawska

This document discusses SLD resolution in Prolog, which is a restricted form of resolution that applies inference rules to goal atoms and clauses whose heads unify with the goal. It provides an example SLD refutation and exercises for drawing refutation trees and using cut to prevent backtracking.

Uploaded by

prayag527
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
97 views

Prolog: Tutorial 5: Barbara Morawska

This document discusses SLD resolution in Prolog, which is a restricted form of resolution that applies inference rules to goal atoms and clauses whose heads unify with the goal. It provides an example SLD refutation and exercises for drawing refutation trees and using cut to prevent backtracking.

Uploaded by

prayag527
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

Prolog: tutorial 5

Barbara Morawska

March 22, 2019


SLD resolution (Selective Linear Definite clause resolution)
In Prolog the resulotion inference is used with the following restriction:

I The rule is always applied to a goal atom (literal) and a clause


whose head unifies with the goal atom.

I Literal is an atomic formula or its negation: p, a(X ), ¬p.


I Clause is a disjunction of literals.
I Horne clause is a disjunction of literals with at most one positive
literal.

I The sequence of SLD-resolutions is called SLD-derivation and if it


ends with the empty clause, it is called SLD-refutation.
SLD resolution example
Let assume our program P is the following:
p(a, b).
p(a, c).
p(b, d).
p(c, e).
g(X, Y) :- p(X, Z), p(Z, Y).
And the goal G is: ?- g(a, W).
The following is the SLD-refutation of P ∪ {G }

1. p(a, b) assumption
2. p(a, c) assumption
3. p(b, d) assumption
4. p(c, e) assumption
5 g (X , Y ) : −p(X , Z ), p(Z , Y ). assumption
6. ?- g(a, W). goal
7. ?- p(a, Z), p(Z,W). 5, 6, θ1 : X /a, Y /W
8. ?- p(b,W). 1, 7, θ2 : Z /b
9. [] 3, 8, θ3 : W /d
The answer is: θ3 θ2 θ1 = X /a, W /d
SLD-refutation - exercises
I Draw a tree of all possible refutations of P ∪ {G }. Mark each
answer in the leaf.
I Check this tree using tracing and backtracking.
I Let natural numbers be constructed only from 0 and s-a successor
predicate: 0, s(0), s(s(0)), . . . .
I Define predicate add(X , Y , Z ) which is true if Z is the sum of X , Y .
I For example add(0, s(0), s(0)) should be true.
I Example of a goal ?- add(s(s(0)), s(0), A)
I Construct an SLD-refutation of this goal.
I Define predicate mult(X , Y , Z )
Cut predicate
Cut predicate: !
It is a nullary predicate that stops backtracking.
It has similar function as negation. Compare the following programs:
I With negation:
p(a).
p(b).
q(a).
r(b).
s(X) :- p(X), q(X).
s(X) :- \+p(X), r(X).
I With cut:
p(a).
p(b).
q(a).
r(b).
s(X) :- p(X),!, q(X).
s(X) :- r(X).
Cut predicate

s(X) :- p(X),!, q(X).


s(X) :- r(X).

I If p(X ) succeeds for some X (substitution for X ), e.g. X = b.


I then the program checks if q(b) succeeds.
I If it does not, then it backtracks and meets !.
I ! tells the program to skip backtracking (checking the next clause for
s(X ) with the same substitution for X )
I Hence s(X ) fails for this substitution for X , i.e. s(b) fails.
Exercise with cut
Load the following program:

a :- b, c.
a :- d, f.
b :- d, !, e.
b :- f.
c.
d :- g, h.
d.
e :- i, j.
e :- k.
f.

I Draw the inference tree for SLD-refutations for ?-a.


I Draw this tree without cut and then mark which part is skiped, due
to cut.
I Try the goals ?-a, ?-b, ?-c
I What happens?

You might also like