Homework 6

Due: 26 March 2002, 11:59:59p.m. Submit a single MS Word or text document.
  1. Translate the following statements into Prolog rules (invent predicate symbols as needed):
    1. Everyone who has a child is happy.
    2. For all X, if X has a child who has a sister then X has two children.

  2. Will the following matching operations succeed or fail? If they succeed show the instantiation of each variable.
    1. point(A,B) =?= point(1,2)
    2. point(A,B) =?= point(X,Y,Z)
    3. plus(2,2) =?= 2
    4. +(2,D) =?= +(E,2)
    5. triangle(point(-1,0),P2,P3) =?= triangle(P1,point(1,0),point(0,Y))

  3. Using the following representation for line segments, write a term that represents any vertical line segment at x = 5.

  4. The monkey and banana problem is an example commonly used for illustrating simple problem solving. It can be solved by a program that searches for possible solutions like the farmer puzzle in the notes. The problem can be stated like this.

    Monkey and Banana Problem: There is a monkey at the door into a room. In the middle of the room a banana is hanging from the ceiling. The monkey is hungry and wants to get the banana, but he cannot stretch high enough from the floor to reach the banana. At the window of the room there is a box the monkey may use. The monkey can do the following things: walk on the floor, climb on the box, push the box around (if it is next to the box) and grasp the banana if standing on the box directly under the banana. How can the monkey get the banana?

    1. Define a Prolog representation of the state of the monkey's world. Use your notation to specify the initial state and the final desired state where the monkey has the banana. The state can be described with four pieces of information, so it should be sufficient to define a functor state that takes four arguments, and the constant values that can occur for each argument.
    2. Define a predicate in Prolog with rules for each of the actions of the monkey (grasp banana, climb box, move box, walk). Use the form move(State1,Action,State2), which describes the state State2 that results from applying the action Action in the state State1.
    3. Define a predicate canget(State1) that returns yes if the monkey can get the banana from State1 and no otherwise.
    4. Define a predicate canget(State1,Actions) that computes the list Actions of actions that the monkey performs to get the banana (if at all) from State1.
Ben Keller