Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Given that you've got <code>female/1</code> &amp; <code>male/1</code> predicates the predicate becomes quite simple.</p> <pre><code>marriedcouple(X,Y) :- parent( (X,Z), bornin(_) ), parent( (Y,Z), bornin(_) ), female(X), male(Y). </code></pre> <p>However, if you want to see if X and Y are not the same use the <code>(\==)/2</code> operator for "not identical" or <code>(\=)/2</code> for "not unifiable".</p> <hr/> <blockquote> <p>Pradeep, based on your comment below, here is a more complete solution.</p> </blockquote> <p>In order to prevent the same answer coming back twice there's a number of choices. We can build a list of solutions and only add a newly found solution if it isn't already in the list. Or use an approach that incorporates state using the <code>assert/1</code> predicate.</p> <p>I've chosen the latter.</p> <pre><code>?- solve. solve :- marriedcouple(Dad, Mum), not( found( marriedcouple(Dad, Mum) ) ), assert( found( marriedcouple(Dad, Mum) ) ), write( [Dad, Mum] ), nl, fail. marriedcouple(Dad, Mum) :- parent(Dad, Child), parent(Mum, Child), male(Dad), female(Mum). male(aaron). male(adam). female(betty). female(eve). parent(aaron, callum). parent(aaron, david). parent(adam, abel). parent(adam, cain). parent(betty, callum). parent(betty, david). parent(eve, abel). parent(eve, cain). </code></pre> <p>When I run this I get the following:</p> <pre><code>[aaron,betty]; [adam,eve]; No. </code></pre> <p>Be careful using <code>assert/1</code> predicates as you may introduce unwanted side-effects into your programs. You may need to do appropriate <code>retract/1</code> calls too.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload