I am new to prolog and I don't know how to solve this. I have to write a siblings rule. All the way at the bottom of the code I have my siblings rule. The problem with the rule is that it returns the siblings twice. For example, if I want to get julia's siblings, I get "rosa" twice. I suppose that what is happening is that the program evaluates for each parent (alex and lina). So how could I fix my rule so I only get julia's (or anyone's) siblings just once?
parent(alex,julia).
parent(alex,rosa).
parent(lina,julia).
parent(lina,rosa).
parent(romeo,peter).
parent(julia,peter).
parent(rosa,silvia).
parent(oscar,ida).
parent(eva,ida).
parent(eva,bruno).
parent(peter,bruno).
parent(peter,georg).
parent(peter,irma).
parent(ruth,georg).
parent(ruth,irma).
parent(silvia,otto).
parent(silvia,pascal).
parent(irma,olga).
parent(irma,jean).
parent(otto,olga).
parent(otto,jean).
parent(jean,tina).
parent(marie,tina).
male(alex).
male(romeo).
male(oscar).
male(peter).
male(bruno).
male(georg).
male(otto).
male(pascal).
male(jean).
husband(alex,lina).
husband(romeo,julia).
husband(oscar,eva).
husband(peter,ruth).
husband(otto,irma).
husband(jean,marie).
% father(X,Y) :- X is the father of Y.
father(X,Y) :- parent(X,Y), male(X).
% grandfather(X,Y) :- X is the grandfather of Y.
grandfather(X,Y) :- father(X,P), parent(P,Y).
% brother(X,Y) :- X is the brother of Y.
brother(X,Y) :- parent(P,X), parent(P,Y), male(X), X \= Y.
% uncle(X,Y) :- X is the uncle of Y.
uncle(X,Y) :- brother(X,P), parent(P,Y).
% female(X) :- X is a female person.
female(X) :- \+ male(X).
% sister(X,Y) :- X is the sister of Y.
sister(X,Y) :- parent(P,X), parent(P,Y), female(X), X \= Y.
% has_son(X) :- the person X has a son.
has_son(X) :- parent(X,Y), male(Y).
% married(X,Y) :- X and Y are married to each other.
married(X,Y) :- husband(X,Y).
married(X,Y) :- husband(Y,X).
% brother_in_law(X,Y) :- X is the brother-in-law of Y.
brother_in_law(X,Y) :- brother(X,P), married(P,Y).
brother_in_law(X,Y) :- husband(X,W), sister(W,Y).
% ancestor(X,Y) :- X is an ancestor of Y.
ancestor(X,Y) :- parent(X,Y).
ancestor(X,Y) :- parent(X,P), ancestor(P,Y).
% relatives(X,Y) :- X and Y are relatives (related by blood to each other).
relatives(X,X).
relatives(X,Y) :- ancestor(X,Y).
relatives(X,Y) :- ancestor(Y,X).
relatives(X,Y) :- ancestor(A,X), ancestor(A,Y).
% ancestors(As,X) :- As is the set of all (known) ancestors of X.
ancestors(As,X) :- setof(A,ancestor(A,X),As).
% descendants(Ds,X) :- Ds is the set of all (known) descendants of X.
descendants(Ds,X) :-setof(D,ancestor(X,D),Ds).
% ancestor(X,Y,L) :- X is an ancestor of Y, and L is the list of names
% leading from X to Y.
ancestor(X,Y,[X,Y]) :- parent(X,Y).
ancestor(X,Y,[X|L]) :- parent(X,P), ancestor(P,Y,L).
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Exercise 1
% Write a rule that determines if mother (M) is mother of (C) child.
% mother(M, C) :-
mother(M,C) :- female(M), parent(M,C).
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Exercise 2
% Write a rule that infers the siblings of certain (X) person
% siblings. Ss is the siblings list.
% siblings(Ss, X) :-
sibling(X,Y) :- dif(X,Y),parent(Z,X),parent(Z,Y).
mother/2and/orfather/2to make the predicate "assymetrical" (given of course same-sex marriages are not allowed). - Willem Van Onsem