Prolog Programming Assignment


Assigned: 10/24/96
Due: 10/29/96 (Tuesday by midnight)
Submission procedure: via email to echris@cs

Write the code for this assignment as succinctly and readably as possible. Each question requires 1 to 3 lines of code. All questions are of equal weight, except for the extra credit, which is worth more because it is tricky.

See the Getting Started with Prolog page to get up to speed with our Prolog systems.


  1. Let the on relation mean that one thing is resting directly on another. For example, the fact on(block1,block2) means that block1 is on top of block2. Write a rule above(X,Y) that is true when X is somewhere above Y.

  2. The following facts represent some "likes" among the Mariners.
        likes(junior, jay).
        likes(junior, alex).
        likes(lou, junior).
        likes(lou, alex).
    
    (a) Write a universal fact that says, "Everyone likes junior."

    (b) Write a rule important(X) that says, "X is important if junior likes X."

    (c) Write a rule very_important(X) that says, "X is very important if X is important and lou likes X."

  3. Define the rule(s) for the predicate sumlist(L,S) so that S is the sum of the list of numbers L. Here it is in action.

        | ?- sumlist([1,2,3,4],10).
        
        yes
        | ?- sumlist([1,2,3,4],12).
        
        no
        | ?- sumlist([1,2,3,4],X).
        
        X = 10 
    
  4. THIS PROBLEM IS EXTRA CREDIT. I WOULD HIGHLY RECOMMEND DOING IT. Define the rule(s) for the predicate delete(L,E,NoEs), where the list NoEs is the result of removing all occurrences of element E from list L. Here are some uses of delete in action.

        | ?- delete([1,2,3,4],3,[1,2,4]).
        
        yes
        | ?- delete([1,2,3,4],3,X).
        
        X = [1,2,4] 
        
        | ?- delete([1,2,3,4],X,[1,2,4]).
        
        X = 3 
    

echris@cs.washington.edu (10/23/96)