/usr/share/acl2-6.3/books/leftist-trees/leftist-tree-defthms.lisp is in acl2-books-source 6.3-5.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 | #|
Leftist Trees, Version 0.1
Copyright (C) 2012 by Ben Selfridge <benself@cs.utexas.edu>
leftist-tree-defthms.lisp
This file contains the basic theory of leftist trees,
proving the basic operations correct.
This implementation follows "Purely Functional Data
Structures" by Chris Okasaki.
|#
(in-package "ACL2")
(include-book "leftist-tree-defuns")
;; We need this much arithmetic to prove theorems about the
;; rank of the tree.
(local (include-book "arithmetic-5/top" :dir :system))
(defdoc leftist-tree-thms
":doc-section leftist-trees
Useful theorems about leftist trees.~/~/
~/")
;;;;;;;;;;;;;;;;;;;
;; MISCELLANEOUS ;;
;;;;;;;;;;;;;;;;;;;
(defdoc leftist-tree-misc-thms
":doc-section leftist-tree-thms
Miscellaneous theorems~/~/
Includes proofs that the rank, length of right spine, and length of
the shortest path to an empty node are all equal. We also prove that
the rank and size of a tree are always natp, as this is helpful in
a later theorem.~/")
(defthm lrt-equals-rank-lt
(implies (proper-lt tree)
(equal (length-right-spine-lt tree)
(rank-lt tree)))
:doc ":doc-section leftist-tree-misc-thms
~/~/
(length-right-spine-lt tree) ==> (rank-lt tree)~/")
(defthm ltn-equals-rank-lt
(implies (proper-lt tree)
(equal (length-to-nil-lt tree)
(rank-lt tree)))
:doc ":doc-section leftist-tree-misc-thms
~/~/
(length-to-nil-lt tree) ==> (rank-lt tree)~/")
(defthm member-insert-lt
(implies (proper-lt tree)
(member-lt x (insert-lt x tree)))
:doc ":doc-section leftist-tree-misc-thms
~/~/
(proper-lt tree) ==> (member-lt x (insert-lt x tree))~/")
; rank and size are naturals
(defthm rank-is-natp-lt
(implies (proper-lt tree)
(natp (rank-lt tree)))
:doc ":doc-section leftist-tree-misc-thms
~/~/
(proper-lt tree) ==> (natp (rank-lt tree))~/")
(defthm size-is-natp-lt
(implies (proper-lt tree)
(natp (size-lt tree)))
:doc ":doc-section leftist-tree-misc-thms
~/~/
(proper-lt tree) ==> (natp (size-lt tree))~/")
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; BASIC OPERATIONS RESPECT STRUCTURE ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defdoc leftist-tree-structure-thms
":doc-section leftist-tree-thms
Theorems proving that the basic operations respect PROPER-LT~/~/~/")
(local
(defthmd proper-merge-lt-L1
(implies (and (consp right_tree1)
(consp tree2)
(proper-lt right_tree1)
(proper-lt tree2)
(lexorder x (root-lt right_tree1))
(lexorder x (root-lt tree2)))
(lexorder x (root-lt (merge-lt right_tree1 tree2))))
:hints (("Goal"
:induct (merge-lt right_tree1 tree2)))))
(local
(defthmd proper-merge-lt-L2
(implies (and (consp tree1)
(consp right_tree2)
(proper-lt tree1)
(proper-lt right_tree2)
(not (lexorder (root-lt tree1) x))
(lexorder x (root-lt right_tree2)))
(lexorder x (root-lt (merge-lt tree1 right_tree2))))
:hints (("Goal"
:induct (merge-lt tree1 right_tree2)))))
(local
(defthmd proper-merge-lt-L3
(implies (and (consp (cadddr tree1))
(consp tree2)
(proper-lt (cadddr tree1))
(proper-lt tree2)
(lexorder (cadr tree1)
(cadadr (cddr tree1)))
(lexorder (cadr tree1)
(cadr tree2)))
(lexorder (cadr tree1)
(cadr (merge-lt (cadddr tree1) tree2))))
:hints (("Goal"
:use ((:instance proper-merge-lt-L1
(right_tree1 (cadddr tree1))
(tree2 tree2)
(x (cadr tree1))))))))
(local
(defthmd proper-merge-lt-L4
(implies (and (consp tree1)
(consp (cadddr tree2))
(proper-lt tree1)
(proper-lt (cadddr tree2))
(not (lexorder (cadr tree1)
(cadr tree2)))
(lexorder (cadr tree2) (cadadr (cddr tree2))))
(lexorder (cadr tree2)
(cadr (merge-lt tree1 (cadddr tree2)))))
:hints (("Goal"
:use ((:instance proper-merge-lt-L2
(tree1 tree1)
(right_tree2 (cadddr tree2))
(x (cadr tree2))))))))
(defthm proper-merge-lt
(implies (and (proper-lt tree1)
(proper-lt tree2))
(proper-lt (merge-lt tree1 tree2)))
:hints (("Goal"
:in-theory (enable proper-merge-lt-L3 proper-merge-lt-L4)
:induct (merge-lt tree1 tree2)))
:doc ":doc-section leftist-tree-structure-thms
~/~/
(and (proper-lt tree1) (proper-lt tree2))
==> (proper-lt (merge-lt tree1 tree2))~/")
(defthm proper-insert-lt
(implies (proper-lt tree)
(proper-lt (insert-lt x tree)))
:doc ":doc-section leftist-tree-structure-thms
~/~/
(proper-lt tree) ==> (proper-lt (insert-lt x tree))~/")
(defthm proper-build-lt
(proper-lt (build-lt l))
:doc ":doc-section leftist-tree-structure-thms
~/~/
(proper-lt (build-lt l))~/")
(defthm proper-delete-min-lt
(implies (proper-lt tree)
(proper-lt (delete-min-lt tree)))
:doc ":doc-section leftist-tree-structure-thms
~/~/
(proper-lt tree) ==> (proper-lt (delete-min-lt tree))~/")
;;;;;;;;;;;;;;;;;;;
;; RANK THEOREMS ;;
;;;;;;;;;;;;;;;;;;;
(defdoc leftist-tree-rank-thms
":doc-section leftist-tree-thms
Theorems about the rank of leftist trees~/~/~/")
(local
(defthmd size-rank-lt-L1
(implies (and (natp b)
(natp c)
(natp p)
(natp q)
(natp r)
(equal p (+ 1 r))
(<= (expt 2 q) (+ b 1))
(<= (expt 2 r) (+ c 1))
(<= r q))
(<= (expt 2 p) (+ 2 b c)))
:hints (("Goal"
:use ((:instance (:theorem (implies (and (<= x y)
(<= y z))
(<= x z)))
(x (expt 2 p))
(y (+ (expt 2 q) (expt 2 r)))
(z (+ 2 b c))))))))
(defthm size-rank-lt
(implies (proper-lt tree)
(<= (- (expt 2 (rank-lt tree)) 1)
(size-lt tree)))
:hints (("Goal"
:induct (size-lt tree))
("Subgoal *1/2.11''"
:use ((:instance size-rank-lt-L1
(b (size-lt (caddr tree)))
(c (size-lt (cadddr tree)))
(p (car tree))
(q (caaddr tree))
(r (caaddr (cdr tree))))))
("Subgoal *1/2.6''"
:use ((:instance rank-is-natp-lt
(tree (caddr tree))))))
:doc ":doc-section leftist-tree-rank-thms
~/~/
(proper-lt tree)
==> (<= (- (expt 2 (rank-lt tree)) 1)
(size-lt tree))~/")
|