Permalink
Join GitHub today
A genealogy database seems to be a good introductory to Prolog. In this lesson, we present a simple Prolog program that captures basic family relations. The program demonstrates features of Prolog like using facts, rules, variables or recursion. Tip: Use Copy&Paste function of the browser to move the code directly into the PROLOG environment. Prolog programs. – explain how Prolog evaluates queries. To represent the above family tree in Prolog we use facts.
GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.
Sign up Find file Copy path
Anniepoochanged order of males to make it easier to step thru with students57e087aFeb 3, 2014
1 contributor
:- discontiguousmale/1, female/1, parent/2. |
male(dicky). |
male(randy). |
male(mike). |
male(don). |
male(elmer). |
female(anne). |
female(rosie). |
female(esther). |
female(mildred). |
female(greatgramma). |
male(blair). |
male(god). |
female(god). |
parent(don,randy). |
parent(don,mike). |
parent(don,anne). |
parent(rosie,randy). |
parent(rosie,mike). |
parent(rosie,anne). |
parent(elmer,don). |
parent(mildred,don). |
parent(esther,rosie). |
parent(esther,dicky). |
parent(greatgramma,esther). |
parent(randy,blair). |
male(mel). |
male(teo). |
parent(melsr,mel). |
parent(melsr,teo). |
american(anne). |
american(X) :- ancestor(X,anne). |
american(X) :- ancestor(anne,X). |
relation(X,Y) :- ancestor(A,X), ancestor(A,Y). |
father(X,Y) :- male(X),parent(X,Y). |
father(god, _) :- male(god). |
mother(X,Y) :- female(X),parent(X,Y). |
son(X,Y) :- male(X),parent(Y,X). |
daughter(X,Y) :- female(X),parent(Y,X). |
grandfather(X,Y) :- male(X),parent(X,Somebody),parent(Somebody,Y). |
aunt(X,Y) :- female(X),sister(X,Mom),mother(Mom,Y). |
aunt(X,Y) :- female(X),sister(X,Dad),father(Dad,Y). |
sister(X,Y) :- female(X),parent(Par,X),parent(Par,Y), X=Y. |
uncle(X,Y) :- brother(X,Par),parent(Par,Y). |
cousin(X,Y) :- uncle(Unc , X),father(Unc,Y). |
ancestor(X,Y) :- parent(X,Y). |
ancestor(X,Y) :- parent(X,Somebody),ancestor(Somebody,Y). |
brother(X,Y) :- male(X),parent(Somebody,X),parent(Somebody,Y), X=Y. |
Copy lines Copy permalink