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
|
; Fully Ordered Finite Sets
; Copyright (C) 2003-2012 Kookamara LLC
;
; Contact:
;
; Kookamara LLC
; 11410 Windermere Meadows
; Austin, TX 78759, USA
; http://www.kookamara.com/
;
; License: (An MIT/X11-style license)
;
; Permission is hereby granted, free of charge, to any person obtaining a
; copy of this software and associated documentation files (the "Software"),
; to deal in the Software without restriction, including without limitation
; the rights to use, copy, modify, merge, publish, distribute, sublicense,
; and/or sell copies of the Software, and to permit persons to whom the
; Software is furnished to do so, subject to the following conditions:
;
; The above copyright notice and this permission notice shall be included in
; all copies or substantial portions of the Software.
;
; THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
; IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
; FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
; AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
; LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
; FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
; DEALINGS IN THE SOFTWARE.
;
; Original author: Jared Davis <jared@kookamara.com>
; outer.lisp
;
; Theorems relating the more complicated set operations (union, intersect,
; etc.) to one another.
(in-package "SET")
(include-book "delete")
(include-book "union")
(include-book "intersect")
(include-book "difference")
(include-book "cardinality")
(set-verify-guards-eagerness 2)
#||
Q. Why do we need SUBSET enabled?
I think I understand what's going on here. For a reproducible example, you can
just open up std/osets/outer.lisp and try to prove the first theorem with
subset disabled. This leads to the goal below, which is perfectly fine, just
before the pick-a-point strategy kicks in:
Subgoal 2.2
(IMPLIES (IN A Y)
(SUBSET (UNION Y (DELETE A X))
(UNION X Y))).
But after the hint applies, it produces a really weird goal, which ultimately
fails to prove and seems to be the real culprit:
Subgoal 2.2.1
(EQUAL (SUBSET SET-FOR-ALL-REDUCTION (UNION X Y))
(COND ((EMPTY SET-FOR-ALL-REDUCTION) T)
((IN (HEAD SET-FOR-ALL-REDUCTION)
(UNION X Y))
(SUBSET (TAIL SET-FOR-ALL-REDUCTION)
(UNION X Y)))
(T NIL))).
I don't like this goal at all. It appears to be due to needing to prove that
(SUBSET X Y) is equivalent to (ALL X) when (PREDICATE A) == (IN A Y). The goal
above basically corresponds to the recursive definition of ALL:
(defun all (set-for-all-reduction)
(declare (xargs :guard (setp set-for-all-reduction)))
(if (empty set-for-all-reduction)
t
(and (predicate (head set-for-all-reduction))
(all (tail set-for-all-reduction)))))
After tinkering around with several solutions, I think I found one that will
work well. I'm doing a full regression with it now. I'm not planning to
disable subset by default (which would be a bigger change), but with this rule
in place it does seem like the pick-a-point proofs in the osets library are
going through OK even with subset disabled, so I'm optimistic that the new
rule will work:
(defthm pick-a-point-subset-constraint-helper
;; When we do a pick-a-point proof of subset, we need to show that (SUBSET X
;; Y) is just the same as (ALL X) with (PREDICATE A) = (IN A Y). Since ALL
;; is defined recursively, the proof goals we get end up mentioning
;; HEAD/TAIL. This doesn't always work well if the user's theory doesn't
;; have the right rules enabled. This rule is intended to open up SUBSET in
;; only this very special case to solve such goals.
(implies (syntaxp (equal set-for-all-reduction 'set-for-all-reduction))
(equal (subset set-for-all-reduction rhs)
(cond ((empty set-for-all-reduction) t)
((in (head set-for-all-reduction) rhs)
(subset (tail set-for-all-reduction) rhs))
(t nil)))))
Once the regressions pass I'll push it...
Cheers,
Jared
||#
(defthm union-delete-X
(equal (union (delete a X) Y)
(if (in a Y)
(union X Y)
(delete a (union X Y)))))
(defthm union-delete-Y
(equal (union X (delete a Y))
(if (in a X)
(union X Y)
(delete a (union X Y)))))
(defthm intersect-delete-X
(equal (intersect (delete a X) Y)
(delete a (intersect X Y))))
(defthm intersect-delete-Y
(equal (intersect X (delete a Y))
(delete a (intersect X Y))))
(defthm union-over-intersect
(equal (union X (intersect Y Z))
(intersect (union X Y) (union X Z))))
(defthm intersect-over-union
(equal (intersect X (union Y Z))
(union (intersect X Y) (intersect X Z))))
(defthm difference-over-union
(equal (difference X (union Y Z))
(intersect (difference X Y) (difference X Z))))
(defthm difference-over-intersect
(equal (difference X (intersect Y Z))
(union (difference X Y) (difference X Z))))
(defthm difference-delete-X
(equal (difference (delete a X) Y)
(delete a (difference X Y))))
(defthm difference-delete-Y
(equal (difference X (delete a Y))
(if (in a X)
(insert a (difference X Y))
(difference X Y))))
(defthm difference-insert-Y
(equal (difference X (insert a Y))
(delete a (difference X Y))))
(defthm intersect-cardinality-X
(<= (cardinality (intersect X Y))
(cardinality X))
:rule-classes (:rewrite :linear))
(defthm intersect-cardinality-Y
(<= (cardinality (intersect X Y))
(cardinality Y))
:rule-classes (:rewrite :linear))
; There are also some interesting properties about cardinality which are more
; precise.
(defthm expand-cardinality-of-union
;; This is pretty questionable -- it used to also be a :linear rule, but that was
;; really expensive.
(equal (cardinality (union X Y))
(- (+ (cardinality X) (cardinality Y))
(cardinality (intersect X Y)))))
(defthm expand-cardinality-of-difference
;; Also questionable, also used to be :linear
(equal (cardinality (difference X Y))
(- (cardinality X)
(cardinality (intersect X Y)))))
;; We used to have this rule, but it was silly -- (intersect X Y) can just rewrite to
;; (SFIX X) when X is a subset of Y.
;; (defthm intersect-cardinality-subset
;; (implies (subset X Y)
;; (equal (cardinality (intersect X Y))
;; (cardinality X))))
(defthmd intersect-cardinality-non-subset
(implies (not (subset x y))
(< (cardinality (intersect x y))
(cardinality x)))
:rule-classes (:rewrite :linear)
:hints(("Goal" :in-theory (enable subset))))
(defthmd intersect-cardinality-subset-2
(equal (equal (cardinality (intersect X Y))
(cardinality X))
(subset X Y)))
(defthmd intersect-cardinality-non-subset-2
(equal (< (cardinality (intersect x y))
(cardinality x))
(not (subset x y))))
|