Homework 6
|
The purpose of the assignment is to provide an introduction to the Prolog language.
- Give your personal family tree back to your great-grandparents for some reasonable subset.
- Define appropriate predicates and implications for:
- great-grandparent
- uncle
- second-cousin
- Verify each (e.g. uncle(X,Y).)
Below is an example of the wumpus family.
father(daddieWumpus,wumpusJr).
father(wumpusJr,wumpusJrJr).
mother(mommieWumpus,wumpusJr).
mother(mommieWumpus,girlieWumpus).
mother(girlieWumpus,girliegirlieWumpus).
parent(P,C) :- father(P,C); mother(P,C).
siblings(S1,S2) :- parent(P,S1), parent(P,S2), S1\=S2.
cousin(X,Y) :- parent(P1,X),parent(P2,Y),siblings(P1,P2).
grandparent(P,C) :- parent(P,X), parent(X,C).- Convert the FOL below into Prolog.
- ØOn(u, v) Ú Above(u, v)
- ØAbove(x, y) Ú ØAbove(y, z) Ú Above(x, z)
- On(B, A)
- On(A, Table)
Prove using resolution (i.e. Prolog): Above(B, Table)Show using Prolog: Above(X,Y).
Starting
- Download SWI-Prolog
- Save the above Prolog in a file named: Family.pl
- Install and execute. You'll see the following:
Welcome to SWI-Prolog (Multi-threaded, Version 5.4.2)
Copyright (c) 1990-2003 University of Amsterdam.
SWI-Prolog comes with ABSOLUTELY NO WARRANTY. This is free software,
and you are welcome to redistribute it under certain conditions.
Please visit http://www.swi-prolog.org for details.
For help, use ?- help(Topic). or ?- apropos(Word).
1 ?-- File | Consult | Family.pl
- ?- father(daddieWumpus,X).
X = wumpusJr ;
; attempts additional unifications.- ?- cousin(X, Y).
X = wumpusJrJr
Y = girliegirlieWumpus ;
X = girliegirlieWumpus
Y = wumpusJrJr ;Backtracking produced duplicate results, though different bindings. OK for this assignment.