Prolog -- symetrical predicates -
I want to emulate the family tree and I have a problem of similar future Fact:
Parent (X, Y) Male (X). Female (y). Age (x, number) Rule:
blood relation is giving me headache Done:
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'm getting satisfactory results (my double print - I can fix it), the problem is that I want this connection to be symmetrical. It is no longer
blood_relation (jones_father, joh): yes blood linkage (John, Johnsfather): no like this .. The way. And I need a query: All pairs that are not in blood-related.
Update:
What is the first statement to complete the relationship? Blood-related (x, y): - blood-related (x, y).
Sorry .. this is a bad copy / paste..aite
is blood_relation (x, y): - ancestor (x, y). Now fixed above.
Here are other rules:
Father (X, Y): - Guardian (X, Y), Male (X). Mother (X, Y): - Parents (X, Y), Women (X). Brother (X, Y): - Parents (Z, X), Parents (Jade, Y), Men (X). Sister (X, Y): - Parents (Z, X), Parents (Z, Y), Women (X). Dada (X, Y): - Parents (Jade, Y), Parents (X, Z), Men (X). Grandmother (X, Y): - Parents (Z, Y), Parents (X, Z), Women (X). Uncle (X, Y): - Mom (Z, Y), Brother (X, Z) Ancestor (X, Y): - Ancestor (X, Y). Ancestor (X, Y): - Parents (X, Z), Ancestor (Z, Y). Mother's brother is in Chacha's definition. It is strange that I have a rule that I need to implement, and I do not know how I can apply the rules besides . I'm just confused.
Any idea how to make blood_relation symmetrical? And not_blood_relation is a new rule and I need a query. It is actually giving me a headache because the relationship is written like crap.
There is no other fact that just so much. All the rules, and all the facts, and all the facts.
query .. no (blood linkage (x, y)) does not work, and I do not really know why the question for example:
Age (X, Y), Y & gt; 18, not (parent (x, z)), write (x), nl, fail Just works fine
Looks like a little homework It is not ...
A trick that does not think of Prol's earliest ideas is a pattern matching. As the tree [a1, [[a2], [b2, [[e3]] [f3]]] [c2]]] as & lt; Tree1 >, & lt; Tree2 >, ...]]:
% Are the immediate children of Y X? Children (X, Y, [X | S]): - Select a tree in the member ([or | _], S) and check the child (X, Y, [x | S]): - Member ([ Jade | SS], S), Children (Z, Y, [Z | SS]). % X and y end with the same root? Sib (X, Y, [R | T]): - Children (R, X, [R | T]), Children (R, Y, [R | T]). I think that you can improve this kind of situation, use joints as a root, adding gender, giving names of specific relationships of members of the trees Are ...
Comments
Post a Comment