<div class="notebook"> <div class="nb-cell markdown" name="md1"> # Family relations Below we include the basic facts about the Greek gods and define one derived relation as an example. Note that you can inspec the content of the file [greek_gods](greek_gods.pl) by long-clicking the link in the program at the bottom. First we provide a query that produces a graph of our data. </div> <div class="nb-cell query" name="q5"> graph(G). </div> <div class="nb-cell markdown" name="md4"> Our first new relation defines the concept of _daughter_: </div> <div class="nb-cell program" name="p2"> daughter(Daugther, Parent) :- parent(Parent, Daugther), female(Daugther). </div> <div class="nb-cell query" data-tabled="true" name="q1"> daughter(Daugther, Parent). </div> <div class="nb-cell markdown" name="md3"> ## Examining the search The trace/0 command allows you to inspect the steps Prolog takes to find a solution. In this case we trace a query that has no solutions because _poseidon_ is male. You can trace below, but this will jump around rather inconveniently. It is easier to copy-and-paste this to the query window at the right. If this is not visible, first use the top-right hamburger to exit _full-screen_ mode. </div> <div class="nb-cell query" data-tabled="true" name="q4"> trace, daughter(poseidon, Parent). </div> <div class="nb-cell markdown" name="md2"> ## Exercises Define the following relations: - sister(Sister, Of) Sister is the sister of Of - ancestor(Ancestor, God) Ancestor is a (possibly indirect) ancestor of God. Add your rules into the program box just above the query. </div> <div class="nb-cell program" name="p3"> </div> <div class="nb-cell query" data-tabled="true" name="q2"> sister(Sister, Of). </div> <div class="nb-cell program" name="p4"> </div> <div class="nb-cell query" data-tabled="true" name="q3"> ancestor(Ancestor, Descendant). </div> <div class="nb-cell program" data-background="true" name="p1"> :- include(greek_gods). :- use_rendering(graphviz). graph(digraph([rankdir='BT'|Nodes])) :- findall((Child->Parent), parent(Parent, Child), Nodes, Shapes), findall(node(Male, [shape(pentagon)]), male(Male), Shapes). </div> </div>