name = 'descendant/2' slug = 'the descendant relation' description = '''\
descendant(X, Y)
: X
is a descendant (child, grandchild, great-grandchild, ...)
of Y
.
?- descendant(patricia, X). X = william ; X = tina ; X = thomas.
Family trees are
described with predicates parent/2
, male/1
, and
female/1
.
I believe recursion is needed... how can we reduce the problem into a smaller one (a single step smaller that is)?
''', '''\If Z
is a parent of some X
and at the same time
Z
is a descendant of Y
,
then X
is also a descendant of Y
.
Is gender really important?
''', 'gender_is_irrelevant_markup': '''\Is this necessary?
''', 'grandparent_used': '''\The solution using the grandparent relation will not be general enough, try using recursion instead. Try to reduce the problem into a "smaller" one, e.g. a descendant in one step less (a closer descendant).
''', 'grandparent_used_markup': '''\Can you solve without using this?
''', 'base_case': '''\Did you think of a base case? The recursion has to stop at some point. What is the most obvious pair (descendand, ancestor)?
''', # TODO: morda ta hint naredim z "more": najprej tekst, ob kliku pa še slika... (sicer je preveč očitno) 'descendant_of_oneself': '''\How can anyone be a descendant of him- or herself? This can be inferred from the current version of the program. It might also help to graphically sketch your current solution.
''', 'descendant_of_oneself_with_or': '''\How can anyone be a descendant of him- or herself? This can be inferred from the current version of the program. It might help to graphically sketch your current solution.
Perhaps you should also check your use of the semicolon. The semicolon basically creates two separate clauses or branches (one or the other can hold, or even both). However, be careful, as this two branches are independent of one another -- assigned values to variables in one branch do not transfer to the other branch.
''', 'descendant_need_not_be_parent': '''\The descendant X
doesn't actually need to have any children...
It seems your predicate is always "false". Did you give it the correct name, or is it perhaps misspelled?
If the name is correct, check whether something else is misspelled, perhaps there is a full stop instead of a comma or vice versa, or maybe you typed a variable name in lowercase?
It is, of course, also possible that your conditions are too restrictive, or even impossible to satisfy
(as would be, for example, the condition that X
is both a parent and a sister of Y
, or
something similarly impossible).
Is there an infinite recursion at work here? How will it ever stop?
Or perhaps is there a missing, faulty, or simply incompatible (with the general recursive case) base case?
''', 'wrong_direction': '''\Did you perhaps program exactly the reverse relation, ancestor instead of descendant?
X
should be a descendant of Y
and not the other way around!
Interesting tidbit. This exercise could also be solved using the solution to the ancestor/2
relation. Simply reverse the variables X
and Y
;
if X
is a descendant of Y
, then Y
is an ancestor of X
.