I need to model the family tree in the prologue. And I have a problem with character predicates.
Data:
parent(x,y).
male(x).
female(y).
age(x, number).
Rules:
blood_relationgives me a headache. this is what i did:
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).
and I get that I consider satisfactory results (I have double prints - I can fix it), the problem is that I want this ratio to be symmetrical. This is not right now.
blood_relation(johns_father, joh):yes
blood_relation(john,johns_father): no
So, is there a way to fix this. And I need a request: all pairs that are not in blood_relation ..
Update:
What relationship is the first statement that should satisfy? blood_relation (X, Y): - blood_relation (X, Y).
sorry .. this is a bad copy / paste..it
blood_relation(X,Y):-ancestor(X,Y).
Now fixed above.
there are other rules here:
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).
- . . , , , . .
, blood_relation ? not_blood_relation - . . . , .
. . .
query.. not(blood_relation(X,Y)) , , .
:
age(X,Y), Y>18,
not(parent(X,Z)),write(X),nl,fail.