Type the family-tree facts and the grandparent rule
Type the family-tree facts and the grandparent rule
Answer
parent(tom, bob). parent(bob, ann). parent(bob, pat). grandparent(X, Y) :- parent(X, Z), parent(Z, Y).
The rule body is a conjunction: X is a grandparent of Y if X is a parent of some Z AND Z is a parent of Y. The shared variable Z must unify to the SAME object in both goals — that is how the two parent steps chain together.