INFO I308 Lab 2: Prolog

40 points

Turn in through Oncourse Assignments.

Technical Matters

To start and stop SWI Prolog on merlin:

$ pl
Welcome to SWI-Prolog (Multi-threaded, 32 bits, Version 5.7.11)
Copyright (c) 1990-2009 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).

?- halt.

(On some other systems, the command to start SWI Prolog is swipl)

To start and stop GNU Prolog on merlin:

$ gprolog
GNU Prolog 1.3.1
By Daniel Diaz
Copyright (C) 1999-2009 Daniel Diaz
| ?- halt.

To capture your session in a file:

  1. Select and Edit/Copy the text from GNOME Terminal.
  2. Paste the text into a text editor of your choice.
  3. Use the editor to save the file.

Problems

1 Create a Knowledge Base

Using a text editor, create a Prolog knowledge base that represents the following information:

Barry is a brown mouse. Greta is a gray mouse. Mabel is a mouse, too.

Carl, Cathy, Hector, and Juana are cats. Carl sees everything that's brown or gray. Cathy sees everything that's brown. Hector and Juana see all mice. Hector is gray, and Juana is brown. Juana is lame.

Mutt is a brown dog.

Any cat that sees a mouse will chase the mouse, unless the cat is lame.

Hints

The first three sentences (about the mice) express five facts.

Use two rules for what Carl sees.

All statements (facts or rules) defining a predicate should be grouped together.

Save and turn in your Prolog source file.

2 Query the Knowledge Base

Use Prolog to query your knowledge base. Capture the session as a plain text file and turn it in. Find all solutions (use ; if needed) for each question.

  1. Who sees Barry?
  2. Who sees Mutt?
  3. Who chases Greta?
  4. Who chases Barry?
  5. Who chases Mutt?

Hint

Use common sense to check the answers given by Prolog, and adjust your queries and/or knowledge base if needed.

Turning It In

Turn in your source code file(s) and saved testing session(s) (plain text files(s) with extension .txt) as attachments in Oncourse Assignments.

Grading

Total: 40 points