% some facts relating to the Kennedy family :- dynamic spouse/2. % bore(Father, Mother, Child) (as in the past tense of "bear", to bear a child) bore(joseph, rose, joe_jr). bore(joseph, rose, john). bore(joseph, rose, eunice). bore(joseph, rose, pat). bore(joseph, rose, bobby). bore(joseph, rose, jean). bore(joseph, rose, ted). bore(john, jackie, john_jr). bore(john, jackie, caroline). bore(sargent, eunice, robert). bore(peter, pat, chris). bore(bobby, ethyl, joe). bore(bobby, ethyl, david). bore(ted, joan, edward). male(X) :- bore(X, _, _). % males who are not parents in bore/3 male(john_jr). male(chris). male(joe). male(joe_jr). male(david). male(edward). male(robert). female(Y) :- bore(_, Y, _). % females who are not parents in bore/3 female(jean). female(caroline). person(X) :- male(X). person(X) :- female(X). full_name(joseph, 'Joseph Patrick Kennedy'). full_name(rose, 'Rose Elizabeth Fitzgerald'). full_name(joe_jr, 'Joseph Patrick Kennedy Jr.'). full_name(john, 'John Fitzgerald Kennedy'). full_name(pat, 'Pat Kennedy'). full_name(bobby, 'Robert Francis Kennedy'). full_name(jean, 'Jean Kennedy'). full_name(ted, 'Edward Moore Kennedy'). full_name(jackie, 'Jacqueline Lee Bouvier'). full_name(sargent, 'Robert Sargent Shriver Jr.'). full_name(eunice, 'Eunice Mary Kennedy'). full_name(ethyl, 'Ethyl Skakel'). full_name(joan, 'Joan ?'). full_name(peter, 'Peter Lawford'). full_name(john_jr, 'John Fitzgerald Kennedy Jr.'). full_name(chris, 'Chris Lawford'). full_name(joe, 'Joe Kennedy'). full_name(david, 'David Kennedy'). full_name(edward, 'Edward Kenendy Jr.'). full_name(robert, 'Robert Shriver'). full_name(jean, 'Jean Kennedy'). full_name(caroline, 'Caroline Kennedy'). father(X, Y) :- bore(X, _, Y). mother(X, Y) :- bore(_, X, Y). parent(X, Y) :- father(X, Y). parent(X, Y) :- mother(X, Y). grandfather(X, Y) :- father(X, Z), parent(Z, Y). grandmother(X, Y) :- mother(X, Z), parent(Z, Y). grandparent(X, Y) :- grandfather(X, Y). grandparent(X, Y) :- grandmother(X, Y). great_grandfather(X, Y) :- father(X, Z), grandparent(Z, Y). great_grandmother(X, Y) :- mother(X, Z), grandparent(Z, Y). ancestor(X, Y) :- parent(X, Y). ancestor(X, Y) :- parent(X, Z), ancestor(Z, Y). note(john, senator(massachusetts), 1953-1960). note(john, '35th U.S. President', 1961-1963). note(john, assassinated, 1963). note(john, 'established Peace Corps', 1961). note(bobby, senator(new_york), 1965-1968). note(bobby, assassinated, 1968). note(ted, senator(massachusetts), 1962-present). note(ted, 'Chappaquiddick', 1969). note(john_jr, 'founded "George" magazine', 1995). sibling(X, Y) :- parent(Z, X), parent(Z, Y), X \== Y. couple(X, Y) :- bore(X, Y, _). couple(X, Y) :- spouse(X, Y). sym_couple(X, Y) :- couple(X, Y). sym_couple(X, Y) :- couple(Y, X). % reconsult rc :- consult(kennedy). /* code for testing binary relations calling ?- test(father). for example, should produce a list of fathers: [bobby,david] [bobby,joe] [john,caroline] [john,john_jr] [joseph,bobby] [joseph,eunice] [joseph,jean] [joseph,joe_jr] [joseph,john] [joseph,pat] [joseph,ted] [peter,chris] [sargent,robert] [ted,edward] */ list([]). list([A | X]) :- write(A), nl, list(X). test(Relation) :- Term =.. [Relation, X, Y], setof([X, Y], Term, Z), list(Z).