So for my class I'm asked to write an entire search tree for the query below. I have been given an example sheet however to be honest my eyes glaze over looking at it. Can someone walk me through the process step by step and explain it to me as best you can much appreciated.
This is what I'm given:
p([], _).
p([H|T], [H|T2]) :- p(T, T2).
q(X, X).
q(X, [_|T]) :- q(X, T).
And the query
p(X, [a,b,c]), q(X, [a,b,c])
To create a search tree you start with your query and step through your clauses pretending to be the Prolog interpreter. The blocks in the tree represent the next clause to execute, and the "legs" of the tree are what variable instantiations are occurring. If this case is complex, start with a very simple case to get the idea. There are several examples online.
Here's just one path through the tree and I'll leave it as an exercise to fill in the rest:
{ Result from the first matched clause:
p([], _).}{ Results from matching second
qclause,q(X, [_|T]). Firstqclause did not match }{ Results from matching second
qclause }{ Results from matching second
qclause }{ Matches first
qclauseq(X, X).}There's another branch off of the first clause to be followed, which corresponds to matching the second
pclause instead of the first: