~/ learn/ comp-456/ cards/ Facts, rules, queries, and the closed-world assumption
1 of 5

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.

space flip · ← → navigate · esc to exit
NORMAL ~/memra/library/c8dd5aa7-e75b-4340-94ab-fa9d3e6eb4e1/flashcard utf-8 LF