title: Query the relation between two people in a Prolog Family Tree
body: <p>Suppose I have the below code in my familyTree.pl file:</p>
  
  <pre><code>male(tom).
  male(bob).
  
  female(lisa).
  female(emily).
  
  parent(tom, bob).
  parent(lisa, bob).
  
  morethanfriends(emily, bob).
  
  father(X,Y) :- male(X), parent(X,Y).
  mother(X,Y) :- female(X), parent(X,Y).
  girlfriend(X,Y) :- female(X), (morethanfriends(X,Y); morethanfriends(Y,X)).
  boyfriend(X,Y) :- male(X), (morethanfriends(X,Y); morethanfriends(Y,X)).
  </code></pre>
  
  <p>Now, I want to get the answer to the questions like:</p>
  
  <pre><code>What is the relationship between Tom and Bob ?
  
  What is the relationship between Lisa and Emily ?
  </code></pre>
  
  <p><strong>How can I ask the above questions to prolog?</strong></p>
  
  <p>The only solution I could come up with was to iterate over the known relation types giving (Tom, Bob) or (Lisa, Emily) as paremeter and check which one returns true. But; this solution seems to be a waste of time, when the number of known relation types are more than a few and/or there is a chain relation between the given two people (i.e.: Lisa and Emily: Lisa is Emily's boyfriend's mother).</p>