other
(in-package "HANOI")
delfunction
(defun del (e x) (if (consp x) (if (equal e (car x)) (cdr x) (cons (car x) (del e (cdr x)))) nil))
permfunction
(defun perm (x y) (if (consp x) (and (mem (car x) y) (perm (cdr x) (del (car x) y))) (not (consp y))))
other
(defthm perm-opener (equal (perm (list a b c) '(0 1 2)) (and (integerp a) (<= 0 a) (<= a 2) (integerp b) (<= 0 b) (<= b 2) (integerp c) (<= 0 c) (<= c 2) (not (equal a b)) (not (equal a c)) (not (equal b c)))))
other
(defthm app-right-id (implies (true-listp x) (equal (app x nil) x)))
other
(defthm get-put (implies (and (natp i) (natp j)) (equal (get i (put v j x)) (if (equal i j) v (get i x)))))
other
(defthm put-get (implies (and (equal x (get n s)) (natp n) (< n (len s))) (equal (put x n s) s)))
other
(defthm put-put-1 (implies (and (natp i) (natp j) (not (equal i j))) (equal (put v i (put u j s)) (put u j (put v i s)))) :rule-classes ((:rewrite :loop-stopper ((i j)))))
other
(defthm true-listp-put (implies (and (natp n) (< n (len x))) (equal (true-listp (put v n x)) (true-listp x))))
hfunction
(defun h (i j k n) (if (zp n) nil (app (h i k j (- n 1)) (cons (list 'move i k) (h j i k (- n 1))))))
legal-syntaxpfunction
(defun legal-syntaxp (m) (and (true-listp m) (equal (car m) 'move) (equal (len m) 3) (mem (a m) '(0 1 2)) (mem (b m) '(0 1 2)) (not (equal (a m) (b m)))))
legal-movepfunction
(defun legal-movep (m s) (and (legal-syntaxp m) (consp (get (a m) s)) (if (consp (get (b m) s)) (< (car (get (a m) s)) (car (get (b m) s))) t)))
do-movefunction
(defun do-move (m s) (let ((stacka (get (a m) s)) (stackb (get (b m) s))) (put (pop stacka) (a m) (put (push (top stacka) stackb) (b m) s))))
playfunction
(defun play (moves s) (if (consp moves) (if (legal-movep (car moves) s) (play (cdr moves) (do-move (car moves) s)) nil) s))
other
(defthm examples (and (equal (play (hanoi 7) (list (tower 7) nil nil)) (list nil nil (tower 7))) (equal (play (hanoi 2) (list (tower 3) nil '(4))) '((3) nil (1 2 4))) (equal (play (hanoi 3) '((1 2 3) (0) nil)) nil)))
other
(defthm true-listp-tower (true-listp (tower n)))
big-topsfunction
(defun big-tops (a b c n s) (and (or (endp (get a s)) (< n (car (get a s)))) (or (endp (get b s)) (< n (car (get b s)))) (or (endp (get c s)) (< n (car (get c s))))))
induction-hintfunction
(defun induction-hint (a b c n s) (if (zp n) (list a b c n s) (list (induction-hint a c b (- n 1) (put (push n (get a s)) a s)) (induction-hint b a c (- n 1) (put (push n (get c s)) c s)))))
other
(defthm h-lemma (implies (and (natp n) (true-listp s) (equal (len s) 3) (perm (list a b c) '(0 1 2)) (big-tops a b c n s)) (equal (play (h a b c n) (put (app (tower n) (get a s)) a s)) (put (app (tower n) (get c s)) c s))) :rule-classes nil :hints (("Goal" :induct (induction-hint a b c n s))))