Prolog Ex
Prolog Ex
?- ˆD
Halt. Program terminated normally
redstone% cat ancestors.pro
female(shelley).
female(mary).
female(lisa).
female(joan).
male(bill).
male(jake).
male(bob).
male(frank).
mother(mary, jake).
mother(mary, shelley).
mother(lisa, mary).
mother(joan, bill).
father(bill, jake).
father(bill, shelley).
father(bob, mary).
father(frank, bill).
parent(Father, Child) :- father(Father, Child).
parent(Mother, Child) :- mother(Mother, Child).
parents(Father, Mother, Child) :- father(Father, Child), mother (Mother, Child).
sibling(Child1, Child2) :-
father(Father, Child1), father(Father, Child2),
mother(Mother, Child1), mother(Mother, Child2).
true_sibling(Child1, Child2) :- sibling(Child1, Child2), not(Child1 = Child2).
ancestor(Ancestor, Descendant) :- parent(Ancestor, Descendant).
ancestor(Ancestor, Descendant) :-
parent(Descendants_Parent, Descendant),
ancestor(Ancestor, Descendants_Parent).
redstone% sbp
SB-Prolog Version 3.1
?- consult(’ancestors.pro’).
yes
?- parents(Father, Mother, jake).
Father = bill
Mother = mary
yes
?- parents(bill, mary, Child).
Child = jake;
Child = shelley;
no
?- parents(Father, Mother, Child).
Father = bill
Mother = mary
4
Child = jake;
Father = bill
Mother = mary
Child = shelley;
Father = bob
Mother = lisa
Child = mary;
Father = frank
Mother = joan
Child = bill;
no
?- sibling(Child1, Child2).
Child1 = jake
Child2 = jake;
Child1 = jake
Child2 = shelley;
Child1 = shelley
Child2 = jake;
Child1 = shelley
Child2 = shelley;
Child1 = mary
Child2 = mary;
Child1 = bill
Child2 = bill;
no
?- true_sibling(Child1, Child2).
Child1 = jake
Child2 = shelley;
Child1 = shelley
Child2 = jake;
no
?- ancestor(Ancestor, jake).
Ancestor = bill;
Ancestor = mary;
Ancestor = frank;
Ancestor = joan;
Ancestor = bob;
Ancestor = lisa;
no
?- ˆD
5