Prolog 在这种情况下如何避免重复

Prolog 在这种情况下如何避免重复,prolog,Prolog,我现在有了我想要的: male(roelof). male(mans). male(ronald). male(jan). female(chantal). female(marie). female(gerda). female(dagmar). female(denise). female(kimberly). parent(mans,gerda). parent(mans,roelof). parent(marie,gerda). parent(marie,roelof). pare

我现在有了我想要的:

male(roelof).
male(mans). 
male(ronald).
male(jan).

female(chantal).
female(marie).
female(gerda).
female(dagmar).
female(denise).
female(kimberly).

parent(mans,gerda).
parent(mans,roelof).
parent(marie,gerda).
parent(marie,roelof).
parent(dagmar,denise).
parent(dagmar,kimberly).
parent(ronald,denise).
parent(ronald,kimberly).
parent(chantal,tamara).
parent(roelof,tamara).
parent(jan,chantal).
parent(jan,dagmar).

% Looks for the father of a child. Gives the name if found. 
% if no father is  found then it gives false
father_child(Child) :-
parent(Father, Child),
 male(Father).

% Looks for the mother of a child. Gives the name if found. 
% if no mother is  found then it gives false
mother_child(Child) :-
parent(Mother, Child),
female(Mother).

% Looks if two person has the same father. 
% Gives true if a person is a father of both persons 
% Gives false if no person is a father of both persons.
same_father(Child, Sibling) :-
  parent(Father,Child),
  parent(Father,Sibling),
  male(Father).

% Looks if two person has the same mother. 
% Gives true if a person is a mother of both persons 
% Gives false if no person is a mother of both persons.
same_mother(Child, Sibling) :-
  parent(Mother,Child),
  parent(Mother,Sibling),
  female(Mother).

% Looks if there are siblings of a person. 
% Persons are siblings if they have the same father or
% if they have the same mother and not the same father.
siblings(X,Y) :-
       (   same_father(X, Y),
            X \= Y
        ;   same_mother(X, Y),
        \+ same_father(X, Y)
    ).

% Displays the output of siblings(X,Y) and takes care that 
% there are no duplicates.
display_siblings(Person) :-
      findall(Person - Y, (siblings(Person,Y), Y @< Person), Sibs),
      display_the_siblings(Sibs).

% Display a message if there are no siblings found. 
display_the_siblings([]) :-
       write('Er zijn geen zussen/broers bekend').

display_many([]).
display_many([H|T]):-
        writeln('Many elements '-H), display_many(T).

display_the-siblings([X]):- better_display([X]),!.
display_the_siblings([H|T]):- better_display([H|T]).

better_display([X]):-
    writeln('Single Element '-X).
better_display([X,Y|T]):-
    writeln('Many elements '-X), display_many([Y|T]).
男性(roelof)。
男性(男性)。
男(罗纳德)。
男(1月)。
女性(尚塔尔)。
女(玛丽)。
女(格尔达)。
女(达格玛)。
女(丹尼斯)。
女(金伯利)。
父母(男,格尔达)。
父母(男,罗洛夫)。
父母(玛丽,格尔达)。
父母(玛丽,罗洛夫)。
父母(达格玛,丹尼斯)。
母公司(达格玛,金伯利)。
父母(罗纳德,丹尼斯)。
父母(罗纳德,金伯利)。
父母(尚塔尔、塔马拉)。
父母(罗洛夫,塔马拉)。
父母(简,尚塔尔)。
家长(一月,达格玛)。
%寻找孩子的父亲。如果找到,则提供名称。
%如果找不到父亲,那就给假消息
父子(子女):-
父母(父亲、孩子),
男(父亲)。
%寻找一个孩子的母亲。如果找到,则提供名称。
%如果没有找到母亲,那么它会给出错误的答案
母子(子女):-
父母(母亲、孩子),
女性(母亲)。
%看两个人是否有相同的父亲。
%如果一个人是两个人的父亲,则为真
%如果没有人是两个人的父亲,则给出false。
同父亲(子女、兄弟姐妹):-
父母(父亲、孩子),
父母(父亲、兄弟姐妹),
男(父亲)。
%看两个人是否有相同的母亲。
%如果一个人是两个人的母亲,则为真
%如果没有人是两个人的母亲,则给出false。
同一母亲(子女、兄弟姐妹):-
父母(母亲、孩子),
父母(母亲、兄弟姐妹),
女性(母亲)。
%查看是否有一个人的兄弟姐妹。
%如果他们有相同的父亲或母亲,那么他们就是兄弟姐妹
%如果他们有相同的母亲而不是相同的父亲。
兄弟姐妹(X,Y):-
(同一个父亲(X,Y),
X\=Y
;同一个母亲(X,Y),
\+同一个父亲(X,Y)
).
%显示同级(X,Y)的输出并注意
%没有重复的。
显示兄弟姐妹(人):-
findall(Person-Y)(兄弟姐妹(Person,Y),Y@<人),兄弟姐妹,
显示兄弟姐妹(SIB)。
%如果未找到同级,则显示消息。
显示兄弟姐妹([]):-
写('Er zijn geen zussen/broers bekend')。
显示多个([])。
显示多个([H | T]):-
writeln('Many element'-H),display_Many(T)。
显示兄弟姐妹([X]):-更好的显示([X]),!。
显示兄弟姐妹([H | T]):-更好的显示([H | T])。
更好的显示([X]):-
writeln('单个元素'-X)。
更好的显示([X,Y | T]):-
writeln('Many element'-X),display|u Many([Y | T])。
但在本例中,display_同胞(Kimberly)为false,因为
Kimberly@
失败。 我是否将规则设置为
Y@
然后
display\u同胞(kimberly)
工作,但
display(gerda)
失败

有人想办法摆脱这混乱局面吗

罗洛夫

看看

apropos(setof).
apropos(findall).
apropos(member).

这两种方法的结合可以消除消音。

你可以试试这样的方法

display_siblings(Person) :-
    setof(Pair, (siblings(Person,Y), sib_pair(Person, Y, Pair)), Sibs),
    display_the_siblings(Sibs).

sib_pair(Person, Sib, Person-Sib) :-
    Person @< Sib.
sib_pair(Person, Sib, Sib-Person) :-
    Person @> Sib.
显示兄弟姐妹(个人):-
集合(对,(兄弟姐妹(人,Y),兄弟姐妹(人,Y,对)),兄弟姐妹,
显示兄弟姐妹(SIB)。
同胞对(人、同胞、同胞):-
人@<同胞。
兄弟姐妹对(人、兄弟姐妹、兄弟姐妹人):-
人@>同胞。

它位于代码部分。我想你必须滚动一点