I did it but its not showing answers When i ask about the brothers,sisters,uncles,aunts This is what I wrote, what's wrong? /*uncle(X, Y):– male(X), sibling(X, Z), parent(Z, Y).*/ /*uncle(X, Y):– male(X), spouse(X, W), sibling(W, Z), parent(Z, Y).*/ uncle(X,Y):- parent(Z,Y), brother(X,Z).
Aunt(X,Y):- parent(Z,Y), sister(X,Z). Sibling(X, Y):- parent(Z, X), parent(Z, Y), X = Y. Sister(X, Y):- sibling(X, Y), female(X). Brother(X, Y):- sibling(X, Y), male(X). Parent(Z,Y):- father(Z,Y). Parent(Z,Y):- mother(Z,Y).
Prolog Family Tree query issues. Prolog family tree. Error in Family Tree using Prolog. Infinite recursion in SWI-Prolog. Basic prolog issue with.
Grandparent(C,D):- parent(C,E), parent(E,D). Aunt(X, Y):– female(X), sibling(X, Z), parent(Z, Y). Aunt(X, Y):– female(X), spouse(X, W), sibling(W, Z), parent(Z, Y).
Mother(mary, sue). Mother(mary, bill).
Mother(sue, nancy). Mother(sue, jeff). Hoover Steamvac Pet Complete Carpet Cleaner With Clean Surge Manual.
Mother(jane, ron). Father(john, sue). Father(john, bill).
Father(bob, nancy). Father(bob, jeff). Father(bill, ron). And one more thing, how do I optimize the rule of the brother so that X is not brother to itself. Your rule of brother already verifies that brother(bob, bob) will fail because it calls sibling(X, Y), which does the check to make sure X = Y already. Also, it looks as though everything is working on my machine, but I had to change the dashes on these lines: aunt(X, Y):– female(X), sibling(X, Z), parent(Z, Y).
Aunt(X, Y):– female(X), spouse(X, W), sibling(W, Z), parent(Z, Y). To: aunt(X, Y):- female(X), sibling(X, Z), parent(Z, Y). Aunt(X, Y):- female(X), spouse(X, W), sibling(W, Z), parent(Z, Y). Yeah, they look identical, but the dashes in the top version are slightly longer. And seemed to cause problems when I 'consulted' the file. I only caught that because I created a Prolog color scheme for Notepad++, if anyone is interested I can post it online.
You have a strong database of facts and a very important predicate called parent(X,Y). Think logically about the approach.
• Who is a brother/sister: a) A male/female, thus male(X) or female(X) must be inside the predicate b) X and Y have the same, but be careful to use either mother or father function, because otherwise the result will be shown twice. PS: make sure X/=Y.
=) Ex.: brother(X,Y):- X/=Y, male(X), father(Father,X), father(Father,Y). • Who is uncle/aunt(a bit tricky, but not a lot): a) Is a male/female. B) Aunt/uncle is sister/brother of the sibling's mom or dad. Ex.: aunt(X,Y):- female(X), parent(Parent,Y),sister(X,Parent). PS: Aunt may also be considered the wife of the brother of sibling's mom or dad(Uncle's wife). But in this case you need to introduce a new fact that expresses a married_couple.
Aunt(X,Y):- female(X), parent(Parent,Y), (sister(X,Parent); (brother(Parent,Uncle),married_couple(Uncle,X))). Hope this works;).
Your aunt/2 predicates are not placed together, therefore Prolog assumes grandparent/2 is aunt/2. Place them together like below or use:- discontiguous(aunt/2). You use spouse/2, but do not define it.
Furthermore, Prolog assumes there should be a sibling/2 predicate somewhere and uses father/2. It does this because you define list of siblings on the bottom of your KB. Again, place them together like below. Like stated in other answers, you can use not(X = Y). Parent(Z,Y):- father(Z,Y); mother(Z,Y). Sibling(X,Y):- parent(A,X), parent(A,Y), not(X = Y). Sister(X, Y):- sibling(X, Y), female(X), not(X = Y).
Brother(X, Y):- sibling(X, Y), male(X), not(X = Y). Grandparent(C,D):- parent(C,E), parent(E,D). Aunt(X,Y):- parent(Z,Y), sister(X,Z). Aunt(X, Y):- female(X), sibling(X, Z), parent(Z, Y).% aunt(X, Y):- female(X), spouse(X, W), sibling(W, Z), parent(Z, Y). Uncle(X,Y):- parent(Z,Y), brother(X,Z). Mother(mary, sue).