name = 'ancestor/2' slug = 'the ancestor relation' description = '''\
ancestor(X, Y)
: X
is an ancestor (parent, grandparent, great-grandparent, ...)
of Y
.
?- ancestor(patricia, X). X = john ; X = michael ; X = michelle.
Family trees are
described with predicates parent/2
, male/1
, and
female/1
.
It's time to use recursion for the first time... how can we reduce the problem into a smaller one (a single step smaller that is)?
''', '''\If X
is a parent of some Z
and that Z
is an ancestor of Y
,
then X
is also an ancestor 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. an ancestor in one step less (a closer ancestor).
''', '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 (ancestor, descendand)?
''', # TODO: morda ta hint naredim z "more": najprej tekst, ob kliku pa še slika... (sicer je preveč očitno) 'ancestor_to_oneself': '''\How can anyone be an ancestor to him- or herself? This can be inferred from the current version of the program. It might also help to graphically sketch your current solution.
''', 'ancestor_to_oneself_with_or': '''\How can anyone be an ancestor to 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.
''', 'only_two_levels_deep': '''\Your solution is not general enough. An ancestor can also be someone "more steps away" than grandparents, e.g. great-grandparents or great-great-grandparents are also ancestors.
''', 'descendant_need_not_be_parent': '''\The descendant Y
doesn't actually need to have any children...
Did you perhaps program exactly the reverse relation, descendant instead of ancestor?
X
should be an ancestor of Y
and not the other way around!
It seems your predicate is
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?
''', }