Note that there are some explanatory texts on larger screens.

plurals
  1. POProlog -- symetrical predicates
    primarykey
    data
    text
    <p>I have to simulate family tree in prolog. And i have problem of symetrical predicates. <strong>Facts:</strong></p> <pre><code>parent(x,y). male(x). female(y). age(x, number). </code></pre> <p><strong>Rules:</strong> </p> <p><code>blood_relation</code> is giving me headache. this is what i have done:</p> <pre><code>blood_relation(X,Y):-ancestor(X,Y). blood_relation(X,Y):-uncle(X,Y);brother(X,Y);sister(X,Y);(mother(Z,Y),sister(X,Z));(father(Z,Y),sister(X,Z));(father(Z,Y),brother(X,Z)). blood_relation(X,Y):-uncle(X,Z),blood_relation(Z,Y). </code></pre> <p>and I am getting i think satisfactory results(i have double prints - can i fix this), problem is that i want that this relation be symmetrical. It is not now. </p> <pre><code>blood_relation(johns_father, joh):yes blood_relation(john,johns_father): no </code></pre> <p>so..is there a way to fix this. And i need query: All pairs that are not in blood_relation..</p> <h2>Update:</h2> <blockquote> <p>What kinds of relationships is the first statement supposed to satisfy? blood_relation(X,Y):-blood_relation(X,Y).</p> </blockquote> <p>sorry..it is a bad copy/paste..it </p> <pre><code>blood_relation(X,Y):-ancestor(X,Y). </code></pre> <p>Now fixed above.</p> <p>here are other rules:</p> <pre><code>father(X,Y):-parent(X,Y),male(X). mother(X,Y):-parent(X,Y),female(X). brother(X,Y):-parent(Z,X),parent(Z,Y),male(X). sister(X,Y):-parent(Z,X),parent(Z,Y),female(X). grandFather(X,Y):-parent(Z,Y),parent(X,Z),male(X). grandMother(X,Y):-parent(Z,Y),parent(X,Z),female(X). uncle(X,Y):-mother(Z,Y),brother(X,Z). ancestor(X,Y):-ancestor(X,Y). ancestor(X,Y):-parent(X,Z),ancestor(Z,Y). </code></pre> <p>Mother's brother is in uncle definition. It's kind of strange. I've got rules that I need to implement, and I don't know how I can implement rules besides that. I'm just confused. </p> <p>Any idea how to make <code>blood_relation</code> symmetric? And <code>not_blood_relation</code> is a new rule. And I need query. This one is really giving me headache. Maybe because relation is written like crap.</p> <p>And there are no more facts. That's all. All rules, and all facts.</p> <p>query.. <code>not(blood_relation(X,Y))</code> doesn't work, and I really don't know why. For example query: </p> <pre><code>age(X,Y), Y&gt;18, not(parent(X,Z)),write(X),nl,fail. </code></pre> <p>works just fine</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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