DCS 440 -- Homework 2: Prolog Warmup

Due by Class Time, Wednesday September 20


Contents
Objective
Details
Hand In

Objective

For this assignment you will solve three short prolog programming exercises. The first is practice for representing knowledge about the world; the second is practice for writing clauses and drawing inferences with variables; and the last is practice for describing and working with data structures symbolically. These are three of the basic skills for prolog programming.

Details

The first exercise is a version of exercise 3.1 on page 104 of Computational Intelligence.

Consider the following facts:

Dogs are animals. Feeding an animal brings it pleasure. People like the animals they own. People do things that bring pleasure to things they like. Mary is a person and Fido is her dog.
Formalize these facts as definite clauses in a Prolog program. Show how to pose the query which asks "what does Mary do?" Make sure prolog computes an answer to this query using your program.

The second exercise is a version of exercise 3.6 on page 106 of Computational Intelligence.

Write prolog clauses that directly characterize a relation shorter, where shorter relates a list L1 to a list L2 if list L1 contains the same number or fewer elements than list L2. Make sure you get the right answers to the three queries

shorter([a,g],[b,a,d,a]).
shorter([b,a,d,a],[a,g]).
shorter([a,a,a,a],[a,b]).

Now obtain all of the answers to these two queries:

shorter(L,[b,a,d,a]).
shorter([b,a,d,a],L).
Include a brief comment in your program saying what answers are computed here and what these answers mean.

The third and last exercise is a stripped-down version of exercise 3.14 on page 110 of Computational Intelligence.

Write a symbolic differentiation "program" in Prolog. The program should operate on arbitrary mathematical expressions made up of algebraic variables (represented as lower case constants) and numbers (prolog integers) using the operations of multiplication and addition. Your program should consist of definitions for a predicate diff where

diff(E, V, D)
means that the derivative of the expression given by E with respect to the variable V is the expression given by D.

In writing your predicate, you can make use of these Prolog builtin relations:

  • atom(X) which is true if X is a lower case constant
  • number(X) which is true if X is a number
  • X \== Y which - assuming that X and Y are atoms - is true if X and Y are different.

Exercise 3.14 from Computational Intelligence is a more open-ended program that allows you to include additional mathematical operations in the expressions and that invites you to write an additional relation to simplify one symbolic expression into another. You're welcome to attempt such more difficult programming for a smidge of extra credit.

Hand In

A copy of your code for the two assignments, instructively but briefly commented, on paper or by email, at the specified time.