CSC 261 Grinnell College Fall, 2007
Artificial Intelligence

Programming and Projects

The accompanying table indicates programming assignments, projects, and due dates for Computer Science 261 and are subject to the following notes.

Due Date Collaboration
Fri., Sept. 7 Yes Programming Problem 1
Mon., Sept. 10 No Programming Problem 2
Fri., Sept. 21 Yes Project 1
Mon., Oct. 8 Yes Programming Problem 3
Wed., Oct. 10 No Programming Problem 4
Mon., Oct. 15 Yes Project 2
Wed., Nov. 7 Yes Expert Systems Lab
Mon., Nov. 19 Yes Project 3
Wed., Dec. 5 Yes Neural Network Lab
Mon., Dec. 10 Yes Project 4

Some Grading Notes:

Programming Exercises

  1. Given a multiplicative expression in list form, write a LISP procedure simplify-1 to reformat and simplify the expression, as follows:

    Note: You need not evaluate nested lists in this procedure.


    (simplify-1 '(* 3 a b (- x y) 0 5 r 8 z))         ; product 0
    ==> 0
    (simplify-1 '(* 3 a b (- x y) 1/120 5 r 8 z))     ; product 1
    ==> (* a b (- x y) r z)
    (simplify-1 '(* 3 a b (- x y)  5 r 8 z))          ; product of 3 5 8 is 120
    ==> (* 120 a b (- x y) r z)
    (simplify-1 '(* 3 a b (- x y)  -5 r 8 z))         ; product is -120
    ==> (* -120 a b (- x y) r z)
    (simplify-1 '(* 3 a b (- x y) (- 3 3) 5 r 8 z))   ; (- 3 3) not evaluated
    ==>  (* 120 a b (- x y) (- 3 3) r z)
  2. Write a LISP procedure same-term that takes two multiplicative LISP expressions as parameters, and returns true (T) if they are the same (except for leading numeric coefficient), and returns false (NIL) otherwise.


    (same-term '(* 3 x y) (* -2 x y)) ==> T
    (same-term '(* 3 x y) (* -2 y x)) ==> T
    (same-term '(* 3 x y) (* -2 x z)) ==> NIL
    (same-term '(* 3 x y) (* -2 x)) ==> NIL
  3. Write Prolog predicates to solve the following three problems

    1. double has two list parameters and returns true if the second parameter is obtained from the first by repeating each element in succession, as each appears. Examples:

      double([a, b, c], [a, a, b, b, c, c]). yields yes
      double([a, b, c], [a, b, c, a, b, c]). yields no
      double([1, 2, 3, 4]), Y). yields Y = [1, 1, 2, 2, 3, 3, 4, 4]
      double([], Y). yields Y = []

    2. insert has three parameters, an item and two lists, and returns true in the second list may be obtained by inserting the item at some position of the first. Examples:

      • insert(1, [a, b], [1, a, b]). insert(1, [a, b], [a, 1, b]). and insert(1, [a, b], [a, b, 1]). return yes.

      • insert(1, [a, b], [b, 1, a]). returns no, because a comes before b in the first list but after in the second.

    3. ordered has a single list (of numbers) as parameter and returns true if the numbers are in ascending order. Examples:

      ordered([]). yields yes (no numbers out of order)
      ordered([1]). yields yes
      ordered([1, 2, 3]). yields yes
      ordered([1, 3, 2, 4]). yields no

      Note: You may not use the built-in sort predicate for this problem.

  4. More Practice with Prolog:

    1. Write a Prolog predicate nextItem that has three parameters: a list, and two items. The predicate is true if the second item follows immediately after the first on the given list. Examples:

      nextItem([1,2,3,4], 1, 2), nextItem([1,2,3,4], 2, 3), and nextItem([1,2,3,4], 3, 4) all yield yes.
      nextItem([1,2,3,4], 1, 3) yields no because 3 does not follow immediately after 1 on the list — there is a 2 between them. nextItem([1,2,3,4], 1, 5) yields no because 5 is not on the list at all.

    2. Consider these rules that determine whether one ordered list (L3) of integers is obtained as the merge of two other ordered lists (L1 and L2).
      merge([H|T1], [H|T2], [H,H|T3]) :- merge(T1, T2, T3).
      merge([H1|T1], [H2|T2], [H1|T3]) :- merge(T1, [H2|T2], T3), H1<H2 .
      merge([H1|T1], [H2|T2], [H2|T3]) :- merge([H1|T1], T2, T3), H1>H2 .

      Draw a full search tree to show the processing involved for the query merge(X,Y,[1,2,3]).


Initial planning for the course anticipates four programming-based projects.

  1. Symbolic differentiation and expression simplification (using LISP)
  2. A simplified version of the Eliza program, initially developed by Joseph Weizenbaum (using Prolog)
  3. An expert system to aid in the placement of incoming students in statistics (using the TMYCIN, a LISP-based inference engine by Gordon Novak at the University of Texas at Austin)
  4. A neural network to address the same statistics-placement problem (using the NevProp system by Phil Goodman at the University of Nevada at Reno)

Students may collaborate in pairs on each project. (Groups of more than 2 may be considered only with prior approval of the instructor.)

Project 1: Symbolic Differential and Expression Simplification>

Consider valid algebraic LISP expressions defined recursively as follows:

Basic Problem: Write a LISP function diff-basic that takes two parameters, a valid algebraic LISP expression VALP and a symbol X, and that returns the (unsimplified) derivative of VALP with respect to X. The result of VALP must again be a valid algebraic LISP expression. To emphasize the note in the first sentence, diff-basic need not perform any simplifications of any kind. Thus, (diff-basic '(* 2 X) 'X) might return (+ (* 2 1) (* X 0)) and (diff-basic '(* 2 X Y) 'X) might return (+ (* 2 (+ (* X 0) (* Y 1))) (* (* X Y) 0))).

Refined Problem: Write a LISP function diff-better that takes the same two parameters as diff-basic, differentiates the given expression, and performs at least three of the following simplifications:

Additional simplifications may be considered, but check with the instructor first (e-mail:

Extra Credit is possible on this project if more than 3 types of simplifications are performed within diff-better.

Project 2: A Simplified Eliza Program

One of the early, well-known programs within the field of artificial intelligence was called Eliza, a program by Joseph Weizenbaum. The idea was to simulate conversation between a patient and psycho-therapist, based on a series of patterns and corresponding responses. Although the original program had an extensive sequence of patterns, this assignment focuses on the following five rules:

Pattern     Response Template
---1 my singleWord ---2 me ---3 tell me about your singleWord
---1 i am ---2 i am sorry to hear you are ---2
---1 am i ---2 do you believe you are ---2
---1 you ---2 me --- 3 why do you think i ---2 you
---1 in what way

In this table, the blank spaces in a pattern, denoted by subscripted dashes, can be filled in with any sequence of words. Similarly, singleWord represents exactly one word in a sentence. For example, these patterns might generate the following "conversation," where the responses are indented and in italics:

Sample Dialogue:

well my friend made me come here
    tell me about your friend
he says i am depressed
    i am sorry to hear you are depressed
i think i need help
    in what way
i wonder if you would help me learning to program Scheme
    why do you think i would help you
when i registered for the course i wondered am i crazy
    do you believe you are crazy

Each of these statements and responses follows the template/response patterns given. For example, in the first statement:

well my friend made me come here

the presence of the word my near the start of the sentence with the word me later on corresponds to the first pattern, with the following matches:

Pattern Element     Words from this Sentence
---1 well
my my
singleWord friend
---2 made
me me
---3 come here

After identifying these pattern elements for the first pattern, the Eliza program uses the corresponding response template. In this case, the program prints "Tell me about your friend". The first four of these words come directly from the template. For the final word, singleWord in the template was matched with the word "friend" in the above analysis.

Historical Note

Although this approach may seem simple today, Joseph Weizenbaum used this approach as the basis for his widely heralded Eliza in 1966. In 1976, Weizenbaum noted he "was startled to see how quickly and how deeply people conversing with [ Eliza] became emotionally involved" in the conversation. People shared their hopes and secrets, and they became annoyed if other people looked over their shoulders or otherwise interrupted. Even when they knew Eliza was a program, they often talked as if it were a close personal friend.

Project 2 Assignment — Due: Monday, October 15

Write a PROLOG program to solve this Eliza-based pattern-matching problem. In the interests of time, we will largely ignore niceties of I/O for this project. Thus, you are not allowed to use such I/O predicates as get, put, read, or write. Rather, you should enter a sentence directly as a list, within the context of Prolog query. For example,

eliza ([well, my, friend, made, me, come, here], Response).

Project 3: A Expert System for the Statistics Placement Problem

The current rule-base to place incoming students in computer science and mathematics courses may be found at ~walker/261/tmycin/newstudents.lsp. After copying this program to your account, expand it to include statistics placements, following the Placement Cases for Statistics as outlined in supplemental problem 2 fof this course.


Project 4: A Neural Network for the Statistics Placement Problem

Develop a neural network to solve the statistics placement problem.

Several scripts may help with data sets for setting up this problem:

This document is available on the World Wide Web as

created 29 August 2007
last revised 30 November 2007
Valid HTML 4.01! Valid CSS!
For more information, please contact Henry M. Walker at (