Files
rose-ash/lib/prolog/tests/programs/family.pl
giles 09683b8a18
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Has been cancelled
prolog: family.pl + family.sx, 10 tests; 5/5 classic programs done
2026-04-25 05:52:28 +00:00

25 lines
532 B
Prolog

%% family — facts + transitive ancestor + derived relations.
%% Five-generation tree: tom -> bob -> {ann, pat} -> jim, plus tom's
%% other child liz.
parent(tom, bob).
parent(tom, liz).
parent(bob, ann).
parent(bob, pat).
parent(pat, jim).
male(tom).
male(bob).
male(jim).
male(pat).
female(liz).
female(ann).
father(F, C) :- parent(F, C), male(F).
mother(M, C) :- parent(M, C), female(M).
ancestor(X, Y) :- parent(X, Y).
ancestor(X, Y) :- parent(X, Z), ancestor(Z, Y).
sibling(X, Y) :- parent(P, X), parent(P, Y), \=(X, Y).