Homework #4

Due Monday, 12 Feb @ 5:00 pm

Your task is to represent binary search trees of numbers as we discussed in class and write a function insert : Number BST → BST. Your BSTs should permit duplicate values (imagine you're representing a multiset). This can be accommodated by using a BST invariant that says that all numbers in the left subtree are less or equal to the root, and numbers in the right subtree are strictly larger than the root. You must prove that insert holds up its end of the contract; that is, prove that insert delivers a BST under the assumptions that it is given a Number and a BST.

You must also prove that insert works properly. In particular, if you insert a number n into a tree tree, then the new tree has one more occurrence of n than does tree.

Hints

You will need several lemmas (= helper-theorems). A key to successful theorem proving is to know how to recognize when the proof you're doing requires a lemma. Three are necessary for this assignment.

If ACL2 does not stop on a proof attempt, use Dracula's Stop Prover button. Unfortunately, this closes the proof window and causes you to lose the checkpoints that you'll need to look at. To get around this, use with-prover-time-limit:

;; Attempt to prove my-theorem, but automatically fail after 10 seconds

(with-prover-time-limit 10
  (defthm my-theorem
    (implies foo bar)))

Then you can examine the checkpoints as usual. Note that 10 seconds should be plenty for the theorems on this assignment.