A language that doesn't affect the way you think about programming is not worth knowing. — A. Perlis, “Epigrams on Programming”, SIGPLAN Notices, 1982.

In this lab, we'll work with Prolog, a logic-based programming language that has been influential in artificial intelligence and in other areas. We’ll use SWI Prolog.

Programming in Prolog

Prolog supports the representation of basic facts and rules, an responds to queries on those facts and rules. Learn Prolog Now! (LPN!) provides a nice introduction to the language.

Exercise 12.1

Read LPN! Chapter 1 and do the following exercises:

  1. From LPN!
    1. Exercise 1.4 - Explain why you built the representations as you did.
    2. Exercise 1.5 - Explain how Prolog comes up with its answers.
  2. Consider the well-known modus ponens. Does Prolog implement a version of modus ponens in propositional logic form? If so, demonstrate how it’s done; if not, explain why not. If it doesn’t, can you implement one? Why or why not?

  3. Prolog supports representations in the form of Horn clauses. Compare and contrast the representational power they provide with that of propositional logic.

  4. Logical implementations generally distinguish the basic operations of TELL and ASK. Does Prolog support this distinction? If so, how; if not, why not?

Save your program in lab_1.pl.

Prolog does its inferencing using backtracking and unification. This exercise references LPN! Chapter 2.

Exercise 12.2

Read LPN! Chapter 2 and do the following exercises:

  1. From LPN!
    1. Exercise 2.1, questions 1, 2, 8, 9, 14 - Give the necessary instantiations.
    2. Exercise 2.2 - Explain how Prolog does its unification and reasoning. If you have issues getting the results you’d expect, are there things you can do to game the system?
  2. Does inference in propositional logic use unification? Why or why not?

  3. Does Prolog inferencing use resolution? Why or why not?

Save your program in lab_2.pl.

A Bewitching Exercise

The following exercise is based on the well-known “Burn the Witch” sketch from Monty Python’s The Holy Grail (see, also, the sketch’s full script).

Exercise 12.3

Create a Prolog program that implements the ridiculous inferences used by Sir Bedevere (Terry Jones) to justify the burning of the witch (Connie Booth) in Monte Python's Holy Grail. Load your rules and demonstrate that the woman is indeed a witch.

Save your program in lab_3.pl.

This serves as a warning that even logic can go tragically wrong.

Checking in

We will grade your work according to the following criteria:

See the policies page for lab due-dates and times.