mother(M,C):-
female(M),
parent(M,C).
father(F,C):-
parent(F,C),
male(F).
grandparent(G,X):-
parent(G,P),
parent(P,X).
sister(S1,S2):-
female(S1),
parent(P,S1),
parent(P,S2),
S1 \== S2.
brother(S1,S2):-
male(S1),
parent(P,S1),
parent(P,S2),
S1 \== S2.
aunt(A,X):-
female(A),
parent(G,A),
parent(G,P),
parent(P,X),
A \== P.
cousin(C1,C2):-
parent(P1,C1),
parent(P2,C2),
parent(G,P1),
parent(G,P2),
P1 \== P2.
ancestor(X, Y) :- parent(X, Y).
ancestor(X, Y) :- parent(X, Z), ancestor(Z, Y).
descendant(Y,X) :- parent(X,Y).
descendant(Y,X) :- parent(X, Z), descendant(Y,Z).
prolog_familiy tree program
最新推荐文章于 2023-05-06 09:30:27 发布