5
intermediate-to-spec.lisp
6
~~~~~~~~~~~~~~~~~~~~~~~~~
8
In this file we prove that the functional qsort qsort-fn is the same as
9
isort. Basically we show that qsort-fn is an ordered permutation, and then we
10
use the main spec property, anything that produces an ordered permutation is
11
the same as qsort, to prove the result.
15
(include-book "intermediate-program")
16
(include-book "spec-properties")
19
(defthm del-last-true-listp-reduction
20
(true-listp (del-last x)))
23
(defthm snoc-del-last-reduction
24
(implies (and (true-listp x)
26
(equal (snoc (del-last x) (last-val x))
28
:rule-classes :forward-chaining)
32
(defthm lower-part-is-true-listp
33
(implies (true-listp x) (true-listp (lower-part x e))))
37
(defthm true-listp-cons-reduction
38
(implies (true-listp x)
39
(true-listp (cons e x))))
43
(defthm true-listp-snoc-reduction
44
(implies (true-listp x)
45
(true-listp (snoc x e))))
49
(defthm true-listp-append-reduction
50
(implies (and (true-listp x) (true-listp y))
51
(true-listp (append x y))))
54
(defthm upper-part-is-true-listp
55
(implies (true-listp x)
56
(true-listp (upper-part x e))))
58
(defthm qsort-fn-is-int-listp
59
(implies (true-listp x)
60
(true-listp (qsort-fn x))))
62
(defthm qsort-fn-is-a-permutation
63
(perm (qsort-fn x) x))
68
(if (<< (first x) e) (lessp e (rest x))
73
(defun not-lessp (e x)
75
(if (<<= e (first x)) (not-lessp e (rest x))
78
;; Now prove the congruences between perm, and lessp and not-lessp
81
(defcong perm equal (lessp x l) 2)
85
(defcong perm equal (not-lessp x l) 2)
88
;; End proof of congruences between perm, and lessp and not-lessp
91
(defthm ordp-lessp-not-lessp-reduction
92
(implies (and (ordp x)
96
(ordp (append x (cons e y)))))
99
;; The next two theorems establish the correspondence of lessp and
100
;; not-lessp functions with the function ordp. So if you were thinking
101
;; what was I doing with these two functions, then it is to provide
102
;; the following correspondence that I was working. I would love for
103
;; someone to give me an easier correspondence, if they can read the
107
(defthm ordp-lessp-not-lessp-reduction-1
108
(implies (and (ordp x)
113
:hints (("Subgoal *1/4"
114
:in-theory (enable <<))))
119
(defthm ordp-lessp-not-lessp-reduction-2
120
(implies (and (ordp x)
126
(defthm func-partition-x-is-lessp
128
(lower-part x splitter)))
132
(defthm func-partition-y-is-not-lessp
134
(upper-part x splitter)))
138
(defthm qsort-lower-is-lessp
140
(qsort-fn (lower-part x splitter))))
144
(defthm qsort-upper-is-not-lessp
146
(qsort-fn (upper-part x splitter))))
149
(defthm if-lower-is-endp-upper-is-the-actual-list
150
(implies (and (true-listp x)
151
(endp (lower-part x (first x))))
152
(equal (upper-part x (first x)) x))
156
(defthm not-lessp-implies-not-lessp-cdr
157
(implies (not-lessp e x)
158
(not-lessp e (rest x)))
162
;; The proofs of the following two functions are really ugly. Just
163
;; look at the number of hints I had to give it. I need to talk to Rob
164
;; about cleaning it up.
167
(defthm qsort-not-lessp-for-lower-endp
168
(implies (and (true-listp x)
169
(endp (lower-part x (first x))))
170
(not-lessp (first x) (qsort-fn (rest x))))
172
:in-theory (disable lower-part qsort-fn)
173
:use if-lower-is-endp-upper-is-the-actual-list)
175
:use ((:instance not-lessp-implies-not-lessp-cdr
177
(x (upper-part x (first x))))))))
180
;; The following theorem means that I am really done. The next theorem
181
;; should be a breeze from perm-ordp-unique.
184
(defthm qsort-fn-is-ordp
185
(implies (true-listp x)
188
:induct (qsort-fn x))
190
:use ((:instance ordp-lessp-not-lessp-reduction-1
192
(x (qsort-fn (lower-part x (car x))))
193
(y (qsort-fn (upper-part x (car x)))))))
195
:use ((:instance ordp-lessp-not-lessp-reduction-2
197
(x (qsort-fn (cdr x))))))))
200
(defthm qsort-fn-equivalent-isort
201
(implies (true-listp x)
205
:use ((:instance any-ordered-permutation-of-integers-is-isort
206
(y (qsort-fn x)))))))
208
(in-theory (enable qsort-fn))
b'\\ No newline at end of file'