Prolog: family relations

The first set of tasks is an introduction to Prolog. At the same time we will refresh our knowledge of family relations – that’s right, we will deal with aunts, uncles, grandparents, ancestors and descendants.

Knowledge base

Everything Prolog knows is written in its knowledge base, which is simply a Prolog program. This is usually loaded from one or more files, which are loaded automatically in CodeQ. The figure below shows a graphical representation of the knowledge base for this set.

The graph (forest) of family relations

The knowledge base itself is of course not represented in graphical form; it actually looks like this:

parent(tina, william).
parent(thomas, william).
parent(thomas, sally).
parent(thomas, jeffrey).
parent(william, vanessa).
…
female(tina).
female(sally).
female(vanessa).
…
male(william).
male(thomas).
male(jeffrey).
…