8
We prove the final theorem about qsort here. After all that I had to do, this
9
should go like a breeze, except (maybe) for the hiccup when (length x) is equal
10
to 0. But this is not a big deal.
12
We mark the final theorem by a capital DEFTHM for easy look-up.
16
(include-book "sort-qs-properties")
19
(include-book "load-extract")
23
(in-theory (disable alloc-qs load-qs))
27
(in-theory (enable in-situ-equal-intermediate
28
intermediate-in-situ-qsort-equal-qsort))
33
(implies (and (not (natp (1- l)))
36
:rule-classes :forward-chaining)
40
(defthm len-0-implies-not-consp
41
(implies (equal (len x) 0)
44
:in-theory (enable len)))
45
:rule-classes :forward-chaining)
48
(DEFTHM qsort-is-correct
49
(implies (true-listp x)
53
:in-theory (disable natp-posp--1) ; needed for v2-8
54
:cases ((not (natp (1- (len x))))))))
56
;; Finally, we add an mbe version of sort which is isort in the logic and is
57
;; qsort in under-the-hood execution. This work is new, i.e., not included
58
;; in the 2002 ACL2 workshop supporting materials.
61
(declare (xargs :guard (true-listp x)))
62
(mbe :logic (isort x) :exec (qsort x)))
64
(defthm sort-list-is-correct
65
(and (ordp (sort-list x))
66
(perm (sort-list x) x)))
68
;; We now prove that sort-list is idempotent by proving the property about
71
(defthm <<=-implies-equal
72
(implies (and (<<= x y) (not (<< x y)))
74
:rule-classes :forward-chaining)
79
(in-theory (enable isort insert))
81
(in-theory (disable qsort-fn-equivalent-isort))
83
(defthm true-listp-isort
84
(true-listp (isort x)))
86
(defthm insert-equals-cons
87
(implies (and (ordp x) (<<= e (car x)) (true-listp x))
88
(equal (insert e x) (cons e x))))
90
(defthm isort-idempotent-1
91
(implies (and (ordp x) (true-listp x))
94
(defthm isort-idempotent
95
(equal (isort (isort x)) (isort x)))
97
(defthm sort-list-idempotent
98
(equal (sort-list (sort-list x)) (sort-list x)))