Homework 6
Prolog Introduction

powered by FreeFind

Modified: 

Assignment

The purpose of the assignment is to provide an introduction to the Prolog language.

  1. Give your personal family tree back to your great-grandparents for some reasonable subset.
    1. Define appropriate predicates and implications for:
      1. great-grandparent
      2. uncle
      3. second-cousin
    2. 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).
  2. 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

  1. Download SWI-Prolog
  2. Save the above Prolog in a file named: Family.pl
  3. 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 ?-

  4. File | Consult | Family.pl
  5. ?- father(daddieWumpus,X).

    X = wumpusJr ;

    ; attempts additional unifications.
  6. ?- cousin(X, Y).

    X = wumpusJrJr
    Y = girliegirlieWumpus ;

    X = girliegirlieWumpus
    Y = wumpusJrJr ;

    Backtracking produced duplicate results, though different bindings. OK for this assignment.
     

Turn in

  1. Cover page - Your name, date, and Homework 6 should be on the first page. Staple all pages together.
  2. Printouts - Print the final Prolog programs for Assignment 1-2 and Prolog executions.