The following predicate is a helper predicate for flattening a tree into a list:
flattenH(leaf(X),L,[X|L]). flattenH(branch(V,W),L,N) :- flattenH(W,L,M), flattenH(V,M,N).In this question, you are going to trace the solution of
flattenH(T,[],[1,2,3]).
You need to carefully go through every step of the algorithm on page
428, with the changes for variable renaming described on pages
433-435. We will do this in pieces.
Solve the following unification problems. Either give a/the MGU, or indicate that the unification failed.
Solve the following resolution problems.
As part of resolution, you may do unification.
If the unification is one you solved in the previous section, you
can use the results directly by referring to one of unify
,
unify
, unify
and unify
. Otherwise, indicate a new
unification problem and solve it.
resolution([flattenH(branch(V2,W2),L2,N2),
flattenH(W2,L2,M2),
flattenH(V2,M2,N2)],
[flattenH(T,[],[1,2,3])])
resolution([flattenH(leaf(X3),L3,[X3|L3])],
[flattenH(W2,[],M2), flattenH(V2,M2,[1,2,3])])
Using the previous steps to give the whole proof tree trace
up to the first success for
the following call. Please trace every call to solve,
resolution and unify, even ones that fail.
solve([flattenH(T,[],[1,2,3])])Assume that the entire rule database consist of those two rules for
flattenH.
After this first success, the proof tree goes on forever without any more success. (Try it in Prolog!) Why?
Do the following exercises from Chapter 21 on paper: Exercises 21.1-3.