% 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(sargent, eunice, maria). bore(peter, pat, chris). bore(bobby, ethyl, joe). bore(bobby, ethyl, david). bore(ted, joan, edward). bore(arnold, maria, katherine). bore(arnold, maria, christina). bore(arnold, maria, patrick). bore(arnold, maria, christopher). 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). % females who are not parents in bore/3 female(Y) :- bore(_, Y, _). 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. %% X is an uncle of Y if X is male and has a sibling Z who is a parent of Y %% X is an uncle of Y if X is coupled to a female W %% who is a sibling of a parent Z of Y uncle(X, Y) :- male(X), sibling(X, Z), parent(Z, Y). uncle(X, Y) :- couple(X, W), sibling(W, Z), parent(Z, 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). %% X is a sister-in-law of Y if X is a female with a sibling Z %% who is coupled to Y %% X is a sister-in-law of Y if X is a female coupled with Z who has sibling Y %% X is a sister-in-law of Y if X is a female coupled with Z who is a sibling %% of some W who is coupled to Y. sister_in_law(X, Y) :- female(X), sibling(X, Z), sym_couple(Z, Y). sister_in_law(X, Y) :- female(X), couple(Z, X), sibling(Z, Y). sister_in_law(X, Y) :- female(X), couple(Z, X), sibling(Z, W), sym_couple(W, Y). % reconsult rc :- consult(kennedy). list([]). list([A | X]) :- write(A), nl, list(X). table(Relation) :- Term =.. [Relation, X, Y], setof([X, Y], Term, Z), list(Z).