Prolog谓词half_sister_of(X,Y)的规则?

时间:2016-12-17 12:17:48

标签: prolog

kb是

parent_of(john,ann).
parent_of(mary,ann).
parent_of(mary,sylvia).
parent_of(brian,sylvia).

female(sylvia).
female(ann).


?-Half_sister_of(X,Y).
X=ann
X=sylvia ;

X=sylvia
X=ann 

1 个答案:

答案 0 :(得分:0)

half_sister_of(X,Y) :-
    parent_of(A,X),
    parent_of(A,Y),
    parent_of(B,X),
    parent_of(C,Y),
    not(A = B),
    not(A = C),
    not(B = C),
    female(Y).

为了使Y成为X的同父异母,他们必须分享一个父母(A),而不与其他父母分享(B和C),Y必须是女性。