% Here we introduce a bunch of predicates representing many family % relationships. The comma indicates logical and, so mother is implied by % being a parent AND being female. mother(X, Y) :- parent(X, Y), female(X). father(X, Y) :- parent(X, Y), male(X). child(X, Y) :- parent(Y, X). daughter(X, Y) :- child(X, Y), female(X). son(X, Y) :- child(X, Y), male(X). % Here we use a not-equal comparison, as well as a a throwawy variable, Z, % which represents the person who is parent to both X and Y. Prolog will % find a correct binding for Z if one is possible. % If there isn't a correct way to bind Z, the program will fail sibling(X, Y) :- X \== Y, child(X, Z), child(Y, Z). sister(X, Y) :- sibling(X, Y), female(X). brother(X, Y) :- sibling(X, Y), male(X). uncle(X, Y) :- parent(Z, Y), brother(X, Z). aunt(X, Y) :- parent(Z, Y), sister(X, Z). cousin(X, Y) :- parent(Z, Y), parent(W, X), sibling(Z, W). % Here we see a logical or (symbolized by semicolon) relative(X, Y) :- parent(X, Y); child(X, Y); sibling(X, Y). % You see we've now declared the same relative(X, Y) predicate twice. The % two definitions are logically or'd together in the Prolog system. relative(X, Y) :- child(X, Z), relative(Y, Z). relative(X, Y) :- child(Y, Z), relative(X, Z). female(mary). female(jane). female(joan). female(beth). female(sally). female(francis). male(mark). male(mel). male(john). male(bob). male(salvador). parent(mary, jane). parent(mary, john). parent(mary, joan). parent(mark, jane). parent(mark, john). parent(mel, joan). parent(jane, beth). parent(jane, bob). parent(john, salvador). parent(john, sally). parent(joan, francis).