Toggle navigation
?
users online
Logout
Open hangout
Open chat for current file
male(terah). male(abraham). male(nahor). male(haran). male(isaac). male(ismael). male(jacob). female(sarah). female(hagar). father(terah, sarah). father(terah, abraham). father(abraham, isaac). father(isaac, jacob). father(abraham, ismael). mother(sarah,isaac). mother(hagar,ismael). parent(Parent,Child) :- father(Parent,Child). parent(Parent,Child) :- mother(Parent,Child). son_of(Child,Parent) :- male(Child), parent(Parent,Child). daughter_of(Child,Parent) :- female(Child), parent(Parent,Child). grandparent_of(GrandChild,GrandParent) :- distinct( (GrandParent,GrandChild), parent(GrandParent,Someone),parent(Someone,GrandChild) ). ancestor_of(Descendant,Ancestor) :- parent(Ancestor,Descendant). ancestor_of(Descendant,Ancestor) :- parent(Ancestor,X), ancestor_of(Descendant,X). % we can use the higher-order predicate distinct/2 to % get rid of duplicate results ancestor_of2(Descendant,Ancestor) :- distinct( (Ancestor,Descendant) , parent(Ancestor,Descendant)). ancestor_of2(Descendant,Ancestor) :- distinct( (Ancestor,Descendant) , (parent(Ancestor,X), ancestor_of2(Descendant,X))).