% A sample database. % Percent-sign ('%') marks comments to end-of-line. % FACTS male(abe). male(homer). male(bart). parent(jackie,marge). parent(abe,homer). parent(mona,homer). parent(homer,bart). parent(marge,bart). parent(homer,lisa). parent(marge,lisa). parent(bart,bartJr). parent(bart,cowabunga). parent(bartJr,bartJrII). % RULES father(Dad, Child) :- parent(Dad, Child), male(Dad). % Dad is the father of Child % if Dad is the parent of Child and Dad is male % Use meaningful variable names. Cf. % father(X, Y) :- parent(X, Y), male(X). % (You can use generic var names when representing a generic input.) % ":-" read as "if" % "," read as "and" %%%% Define grandparent: %%%% (What is the def'n in English, for "Old is a grandparent of Yng"?) %%%% %%%% Define grandfather: %%%% Define "ancestor": anc(P,P). anc(P1,P2) :- parent(P1,Middle), anc(Middle,P2). cousin(X,Y) :- parent(P,X), parent(P,Y). % siblings are 0th-cousins. cousin(X,Y) :- parent(PX,X), parent(PY,Y), cousin(PX,PY). %%%% Cousin: %%%% Digress, in English: %%%% cousin, 2nd cousin, 3rd cousin; %%%% nth cousin m times removed. %%%% nthCousin: