; Practice Midterm ; Implicitly below I am operating in the following environment: ; (include-book "m1-lemmas") (in-package "M1") ; Problem 1 ; Define the function execute-DUP to extend M1 with the following ; new instruction ; Format: (DUP) ; Stack: ..., v => ..., v, v ; Description: ; Duplicates the topmost item on the stack. ; Note: To actually extend M1 we would have to change do-inst ; also, but that is not necessary here. ; Problem 2 ; Given (defun sum (n) (if (zp n) 0 (+ n (sum (- n 1))))) ; Prove the following theorem: (defthm problem-2 (implies (natp n) (equal (sum n) (/ (+ (* n n) n) 2)))) ; Note: I want to see a conventional proof, not an ACL2s ; abbreviated proof. You may use conventional arithmetic ; notation, e.g., prove ; natp(n) -> sum(n) = (n^2 + n)/2 ; Problem 3 ; Suppose n is a natural number (a nonnegative integer). Write ; an M1 program that sums the naturals from n down to 0 and halts ; with the result on top of the stack. Let *prog* be the ACL2 ; constant that contains your list of instructions. Note: you ; know that the result of running *prog* will be (n^2 + n)/2, but ; the program should compute it by iterated additions. ; Problem 4 ; Write the schedule function, sched, to drive your program to ; its HALT statement for an arbitrary given natural number n. ; Problem 5 ; Write the additional definitions and theorems required to give ; the abbreviated proof of ; (implies (natp n) ; (equal (top ; (stack ; (run (sched n) ; (make-state 0 (list n a) stack *prog*)))) ; (/ (+ (* n n) n) 2)))