Computer Science 60
Principles of Computer Science
Fall 2007


Assignment 8: Programming with Logic [100 Points]
Due Monday, November 5 by 11:59 PM

Please use the standard commenting convention of your name, file name, and date in each file. In addition, please have at least a one-line comment for each function that you implement. Finally, please BE SURE TO NAME YOUR FILES AND FUNCTIONS EXACTLY AS WE'VE SPECIFIED. The grading procedure for this assignment is partially automated and files and functions whose spellings differ from those below will cause our scripts to "barf".

Part 1: Movies and Prolog (30 Points)

Download the file movies.pl from the assignments page, which is a database containing facts that you will use in this part of the assignment.  Also download the file part1.pl which contains starter code for this part of the assignment.  

Your task is to write several rules for reasoning about the information in the movie database.  The database already defines the following predicates:

  movie([Title, Year], Director, [... categories])
 
  actress(Name, [Birth City, Birth State], Birthyear)
 
  actor(Name, [Birth City, Birth State], Birthyear)
 
  plays(Player, Role, [Title, Year])
 

Your job is to define the following predicates:
  1. directedBandits(Director) iff Director is the director of the movie  ['Bandits', 2001].
  2. directedByBay(Movie) iff Movie is directed by 'Michael Bay'.
  3. actressAfter1970(Actress) iff Actress was born after 1970.
  4. player(Name, BirthPlace, Birthyear) iff either actor(Name, BirthPlace, Birthyear) or actress(Name, BirthPlace, Birthyear).
  5. bornInLondon(Player) iff Player was born in ['London', 'England'].
  6. playerAndDirector(Player) iff Player is a player that directed some movie.
  7. playedAndDirected(Player) iff Player is a player that directed a movie in which he or she played.
  8. playedMultiple(Player) iff Player played in more than one movie.
  9. playedInComedy(Player) iff Player played in a comedy.
  10. playedNotDirected(Director) iff Director directed some movies, but played in at least one movie he/she did not direct.
Note that skeleton definitions for these predicates are given in the file part1.pl.  Your predicate names must be exactly those given above, or your solutions will not be able to pass the tests that will be applied in grading.

For this problem, we are providing you with test cases.  Just type "test." at the prompt to test your answers.  But be sure you also understand how to invoke each predicate at the prompt (i.e., how to answer queries).

In defining your predicates, remove the _ from the variables.  These are present for now so the compiler doesn't complain about singleton variables, which are often the sign of an error, such as a spelling error.

Recall that "," is the symbol for AND, ";" is the SYMBOL for OR, and "\+" is the symbol for NOT. Please look at the class notes for other Prolog syntax. Your file should be called part1.pl.


Part 2: Lists in Prolog (40 Points)


Here, you will write four Prolog rules for lists. Please write these rules in one file called part2.pl. You may use any helper rules that you like. In particular, some of the rules that we saw in class may be useful to you here. You may implement and use any of them.