Information Technology Reference
In-Depth Information
removed or a second cousin twice removed and so on, and fill in the details
here.
7.
descendant
,
ancestor
.
x
is a descendant of
y
if
x
is either a child of
y
or (recursively) of someone who
is a descendant of
y
.
x
is an ancestor of
y
if
y
is a descendant of
x
.
8.
cousin
.
x
is a cousin of
y
if some parent of
x
and some parent of
y
are either siblings
or (recursively) cousins. (The
x
and
y
will always end up being
n
th cousins for
some
n
. For example, fourth cousins will have parents who are third cousins.)
9.
closest_common_ancestor
.
x
is a closest common ancestor of two people
y
and
z
if
x
is an ancestor of both
y
and
z
and no child of
x
is an ancestor of
y
and
z
. (A closest common ancestor
of two first cousins will be someone who is a grandparent of both.)
10.
write_descendant_chain
.
Later chapters examine the special predicates
write
and
nl
, which can be used
to produce output other than just the values of variables. For example, if there is
a clause
write_child(X,Y) :-
write(X), write(' is a child of '), write(Y), nl.
then the query
write_child(john_smith,sue_jones)
will always succeed and
will also print
john_smith is a child of sue_jones
on one line.
Include this predicate in your program,
and write the clauses
for a predicate
write_descendant_chain
(
that prints a chain from
x
to
y
when
x
is a descendant of
y
but prints nothing when
x
is not a descen-
dant of
y
. For example, if John Smith is a descendant of William Brown,
then
write_descendant_chain(john_smith,william_brown)
should
)
x
,
y
print
a
sequence of lines something like this:
john_smith is a child of sue_jones
sue_jones is a child of harvey_jones
harvey_jones is a child of davy_jones
davy_jones is a child of anna_brown
anna_brown is a child of william_brown