title: Don't repeat solutions in Prolog
body: <p>Suppose you have a database with the following content:</p>
  
  <pre><code>son(a, d).
  son(b, d).
  son(a, c).
  son(b, c).
  </code></pre>
  
  <p>So a and b are sons of d and c. Now you want to know, given a bigger database, who is brother to who. A solution would be:</p>
  
  <pre><code>brother(X, Y) :-
      son(X, P),
      son(Y, P),
      X \= Y.
  </code></pre>
  
  <p>The problem with this is that if you ask "brother(X, Y)." and start pressing ";" you'll get redundant results like:</p>
  
  <ul>
  <li>X = a, Y = b;</li>
  <li>X = b, Y = a;</li>
  <li>X = a, Y = b;</li>
  <li>X = b, Y = a;</li>
  </ul>
  
  <p>I can understand why I get these results but I am looking for a way to fix this. What can I do?</p>