grandparent_of/2 could be defined as
grandparent_of(X,Y) :- parent_of(X,Z), parent_of(Z,Y).The predicate
greatgrandparent_of/2could be defined as follows:
greatgrandparent_of(X,Y) :- parent_of(X,Z), parent_of(Z,A), parent_of(A,Y).And the predicate
greatgreatgrandparent_of/2could be defined analogously by simply adding one more
parent_ofstep to the definition of
ancestor_of/2cannot be defined in this way, as we don't know how many 'parents we have to go back' to find an ancestor. Anybody who is an arbitrary number of parent relations back is an ancestor.
So, how can we express what
Well, obviously if I am the parent of somebody, I also belong to
his ancestors. Furthermore, if I am the parent of somebody and
that somebody is an ancestor of a third person, I am also an
ancestor of this third person.