| author | popescua | 
| Tue, 28 May 2013 13:22:06 +0200 | |
| changeset 52200 | 6324f30e23b6 | 
| parent 46953 | 2b6e55924af3 | 
| child 57492 | 74bf65a1910a | 
| permissions | -rw-r--r-- | 
| 12610 | 1 | (* Title: ZF/Induct/Multiset.thy | 
| 12089 
34e7693271a9
Sidi Ehmety's port of the fold_set operator and multisets to ZF.
 paulson parents: diff
changeset | 2 | Author: Sidi O Ehmety, Cambridge University Computer Laboratory | 
| 
34e7693271a9
Sidi Ehmety's port of the fold_set operator and multisets to ZF.
 paulson parents: diff
changeset | 3 | |
| 
34e7693271a9
Sidi Ehmety's port of the fold_set operator and multisets to ZF.
 paulson parents: diff
changeset | 4 | A definitional theory of multisets, | 
| 
34e7693271a9
Sidi Ehmety's port of the fold_set operator and multisets to ZF.
 paulson parents: diff
changeset | 5 | including a wellfoundedness proof for the multiset order. | 
| 
34e7693271a9
Sidi Ehmety's port of the fold_set operator and multisets to ZF.
 paulson parents: diff
changeset | 6 | |
| 
34e7693271a9
Sidi Ehmety's port of the fold_set operator and multisets to ZF.
 paulson parents: diff
changeset | 7 | The theory features ordinal multisets and the usual ordering. | 
| 
34e7693271a9
Sidi Ehmety's port of the fold_set operator and multisets to ZF.
 paulson parents: diff
changeset | 8 | *) | 
| 
34e7693271a9
Sidi Ehmety's port of the fold_set operator and multisets to ZF.
 paulson parents: diff
changeset | 9 | |
| 15201 | 10 | theory Multiset | 
| 11 | imports FoldSet Acc | |
| 12 | begin | |
| 13 | ||
| 24892 | 14 | abbreviation (input) | 
| 15 |   -- {* Short cut for multiset space *}
 | |
| 16 | Mult :: "i=>i" where | |
| 17 |   "Mult(A) == A -||> nat-{0}"
 | |
| 15201 | 18 | |
| 24893 | 19 | definition | 
| 12891 | 20 | (* This is the original "restrict" from ZF.thy. | 
| 15201 | 21 | Restricts the function f to the domain A | 
| 12891 | 22 | FIXME: adapt Multiset to the new "restrict". *) | 
| 24893 | 23 | funrestrict :: "[i,i] => i" where | 
| 15201 | 24 | "funrestrict(f,A) == \<lambda>x \<in> A. f`x" | 
| 12891 | 25 | |
| 24893 | 26 | definition | 
| 12089 
34e7693271a9
Sidi Ehmety's port of the fold_set operator and multisets to ZF.
 paulson parents: diff
changeset | 27 | (* M is a multiset *) | 
| 24893 | 28 | multiset :: "i => o" where | 
| 15201 | 29 |   "multiset(M) == \<exists>A. M \<in> A -> nat-{0} & Finite(A)"
 | 
| 12089 
34e7693271a9
Sidi Ehmety's port of the fold_set operator and multisets to ZF.
 paulson parents: diff
changeset | 30 | |
| 24893 | 31 | definition | 
| 32 | mset_of :: "i=>i" where | |
| 12089 
34e7693271a9
Sidi Ehmety's port of the fold_set operator and multisets to ZF.
 paulson parents: diff
changeset | 33 | "mset_of(M) == domain(M)" | 
| 
34e7693271a9
Sidi Ehmety's port of the fold_set operator and multisets to ZF.
 paulson parents: diff
changeset | 34 | |
| 24893 | 35 | definition | 
| 36 | munion :: "[i, i] => i" (infixl "+#" 65) where | |
| 46822 
95f1e700b712
 mathematical symbols for Isabelle/ZF example theories
 paulson parents: 
45602diff
changeset | 37 | "M +# N == \<lambda>x \<in> mset_of(M) \<union> mset_of(N). | 
| 
95f1e700b712
 mathematical symbols for Isabelle/ZF example theories
 paulson parents: 
45602diff
changeset | 38 | if x \<in> mset_of(M) \<inter> mset_of(N) then (M`x) #+ (N`x) | 
| 15201 | 39 | else (if x \<in> mset_of(M) then M`x else N`x)" | 
| 12089 
34e7693271a9
Sidi Ehmety's port of the fold_set operator and multisets to ZF.
 paulson parents: diff
changeset | 40 | |
| 24893 | 41 | definition | 
| 14046 | 42 | (*convert a function to a multiset by eliminating 0*) | 
| 24893 | 43 | normalize :: "i => i" where | 
| 14046 | 44 | "normalize(f) == | 
| 15201 | 45 | if (\<exists>A. f \<in> A -> nat & Finite(A)) then | 
| 46 |             funrestrict(f, {x \<in> mset_of(f). 0 < f`x})
 | |
| 14046 | 47 | else 0" | 
| 12089 
34e7693271a9
Sidi Ehmety's port of the fold_set operator and multisets to ZF.
 paulson parents: diff
changeset | 48 | |
| 24893 | 49 | definition | 
| 50 | mdiff :: "[i, i] => i" (infixl "-#" 65) where | |
| 15201 | 51 | "M -# N == normalize(\<lambda>x \<in> mset_of(M). | 
| 32960 
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
 wenzelm parents: 
26417diff
changeset | 52 | if x \<in> mset_of(N) then M`x #- N`x else M`x)" | 
| 12089 
34e7693271a9
Sidi Ehmety's port of the fold_set operator and multisets to ZF.
 paulson parents: diff
changeset | 53 | |
| 24893 | 54 | definition | 
| 12089 
34e7693271a9
Sidi Ehmety's port of the fold_set operator and multisets to ZF.
 paulson parents: diff
changeset | 55 | (* set of elements of a multiset *) | 
| 24893 | 56 |   msingle :: "i => i"    ("{#_#}")  where
 | 
| 12089 
34e7693271a9
Sidi Ehmety's port of the fold_set operator and multisets to ZF.
 paulson parents: diff
changeset | 57 |   "{#a#} == {<a, 1>}"
 | 
| 15201 | 58 | |
| 24893 | 59 | definition | 
| 60 | MCollect :: "[i, i=>o] => i" (*comprehension*) where | |
| 15201 | 61 |   "MCollect(M, P) == funrestrict(M, {x \<in> mset_of(M). P(x)})"
 | 
| 12089 
34e7693271a9
Sidi Ehmety's port of the fold_set operator and multisets to ZF.
 paulson parents: diff
changeset | 62 | |
| 24893 | 63 | definition | 
| 12089 
34e7693271a9
Sidi Ehmety's port of the fold_set operator and multisets to ZF.
 paulson parents: diff
changeset | 64 | (* Counts the number of occurences of an element in a multiset *) | 
| 24893 | 65 | mcount :: "[i, i] => i" where | 
| 15201 | 66 | "mcount(M, a) == if a \<in> mset_of(M) then M`a else 0" | 
| 67 | ||
| 24893 | 68 | definition | 
| 69 | msize :: "i => i" where | |
| 15201 | 70 | "msize(M) == setsum(%a. $# mcount(M,a), mset_of(M))" | 
| 12089 
34e7693271a9
Sidi Ehmety's port of the fold_set operator and multisets to ZF.
 paulson parents: diff
changeset | 71 | |
| 24892 | 72 | abbreviation | 
| 73 |   melem :: "[i,i] => o"    ("(_/ :# _)" [50, 51] 50)  where
 | |
| 74 | "a :# M == a \<in> mset_of(M)" | |
| 75 | ||
| 12089 
34e7693271a9
Sidi Ehmety's port of the fold_set operator and multisets to ZF.
 paulson parents: diff
changeset | 76 | syntax | 
| 46822 
95f1e700b712
 mathematical symbols for Isabelle/ZF example theories
 paulson parents: 
45602diff
changeset | 77 |   "_MColl" :: "[pttrn, i, o] => i" ("(1{# _ \<in> _./ _#})")
 | 
| 15201 | 78 | syntax (xsymbols) | 
| 35112 
ff6f60e6ab85
numeral syntax: clarify parse trees vs. actual terms;
 wenzelm parents: 
32960diff
changeset | 79 |   "_MColl" :: "[pttrn, i, o] => i" ("(1{# _ \<in> _./ _#})")
 | 
| 12089 
34e7693271a9
Sidi Ehmety's port of the fold_set operator and multisets to ZF.
 paulson parents: diff
changeset | 80 | translations | 
| 24893 | 81 |   "{#x \<in> M. P#}" == "CONST MCollect(M, %x. P)"
 | 
| 12089 
34e7693271a9
Sidi Ehmety's port of the fold_set operator and multisets to ZF.
 paulson parents: diff
changeset | 82 | |
| 
34e7693271a9
Sidi Ehmety's port of the fold_set operator and multisets to ZF.
 paulson parents: diff
changeset | 83 | (* multiset orderings *) | 
| 15201 | 84 | |
| 24893 | 85 | definition | 
| 12089 
34e7693271a9
Sidi Ehmety's port of the fold_set operator and multisets to ZF.
 paulson parents: diff
changeset | 86 | (* multirel1 has to be a set (not a predicate) so that we can form | 
| 
34e7693271a9
Sidi Ehmety's port of the fold_set operator and multisets to ZF.
 paulson parents: diff
changeset | 87 | its transitive closure and reason about wf(.) and acc(.) *) | 
| 24893 | 88 | multirel1 :: "[i,i]=>i" where | 
| 12089 
34e7693271a9
Sidi Ehmety's port of the fold_set operator and multisets to ZF.
 paulson parents: diff
changeset | 89 | "multirel1(A, r) == | 
| 15201 | 90 |      {<M, N> \<in> Mult(A)*Mult(A).
 | 
| 91 | \<exists>a \<in> A. \<exists>M0 \<in> Mult(A). \<exists>K \<in> Mult(A). | |
| 92 |       N=M0 +# {#a#} & M=M0 +# K & (\<forall>b \<in> mset_of(K). <b,a> \<in> r)}"
 | |
| 93 | ||
| 24893 | 94 | definition | 
| 95 | multirel :: "[i, i] => i" where | |
| 46953 | 96 | "multirel(A, r) == multirel1(A, r)^+" | 
| 12089 
34e7693271a9
Sidi Ehmety's port of the fold_set operator and multisets to ZF.
 paulson parents: diff
changeset | 97 | |
| 12860 
7fc3fbfed8ef
  Multiset:  added the translation Mult(A) => A-||>nat-{0}
 paulson parents: 
12610diff
changeset | 98 | (* ordinal multiset orderings *) | 
| 15201 | 99 | |
| 24893 | 100 | definition | 
| 101 | omultiset :: "i => o" where | |
| 15201 | 102 | "omultiset(M) == \<exists>i. Ord(i) & M \<in> Mult(field(Memrel(i)))" | 
| 103 | ||
| 24893 | 104 | definition | 
| 105 | mless :: "[i, i] => o" (infixl "<#" 50) where | |
| 15201 | 106 | "M <# N == \<exists>i. Ord(i) & <M, N> \<in> multirel(field(Memrel(i)), Memrel(i))" | 
| 107 | ||
| 24893 | 108 | definition | 
| 109 | mle :: "[i, i] => o" (infixl "<#=" 50) where | |
| 15201 | 110 | "M <#= N == (omultiset(M) & M = N) | M <# N" | 
| 111 | ||
| 112 | ||
| 113 | subsection{*Properties of the original "restrict" from ZF.thy*}
 | |
| 114 | ||
| 115 | lemma funrestrict_subset: "[| f \<in> Pi(C,B); A\<subseteq>C |] ==> funrestrict(f,A) \<subseteq> f" | |
| 116 | by (auto simp add: funrestrict_def lam_def intro: apply_Pair) | |
| 117 | ||
| 118 | lemma funrestrict_type: | |
| 119 | "[| !!x. x \<in> A ==> f`x \<in> B(x) |] ==> funrestrict(f,A) \<in> Pi(A,B)" | |
| 120 | by (simp add: funrestrict_def lam_type) | |
| 121 | ||
| 122 | lemma funrestrict_type2: "[| f \<in> Pi(C,B); A\<subseteq>C |] ==> funrestrict(f,A) \<in> Pi(A,B)" | |
| 123 | by (blast intro: apply_type funrestrict_type) | |
| 124 | ||
| 125 | lemma funrestrict [simp]: "a \<in> A ==> funrestrict(f,A) ` a = f`a" | |
| 126 | by (simp add: funrestrict_def) | |
| 127 | ||
| 128 | lemma funrestrict_empty [simp]: "funrestrict(f,0) = 0" | |
| 129 | by (simp add: funrestrict_def) | |
| 130 | ||
| 131 | lemma domain_funrestrict [simp]: "domain(funrestrict(f,C)) = C" | |
| 132 | by (auto simp add: funrestrict_def lam_def) | |
| 133 | ||
| 134 | lemma fun_cons_funrestrict_eq: | |
| 135 | "f \<in> cons(a, b) -> B ==> f = cons(<a, f ` a>, funrestrict(f, b))" | |
| 136 | apply (rule equalityI) | |
| 137 | prefer 2 apply (blast intro: apply_Pair funrestrict_subset [THEN subsetD]) | |
| 138 | apply (auto dest!: Pi_memberD simp add: funrestrict_def lam_def) | |
| 139 | done | |
| 140 | ||
| 141 | declare domain_of_fun [simp] | |
| 142 | declare domainE [rule del] | |
| 143 | ||
| 144 | ||
| 145 | text{* A useful simplification rule *}
 | |
| 146 | lemma multiset_fun_iff: | |
| 46822 
95f1e700b712
 mathematical symbols for Isabelle/ZF example theories
 paulson parents: 
45602diff
changeset | 147 |      "(f \<in> A -> nat-{0}) \<longleftrightarrow> f \<in> A->nat&(\<forall>a \<in> A. f`a \<in> nat & 0 < f`a)"
 | 
| 15201 | 148 | apply safe | 
| 149 | apply (rule_tac [4] B1 = "range (f) " in Pi_mono [THEN subsetD]) | |
| 150 | apply (auto intro!: Ord_0_lt | |
| 151 | dest: apply_type Diff_subset [THEN Pi_mono, THEN subsetD] | |
| 152 | simp add: range_of_fun apply_iff) | |
| 153 | done | |
| 154 | ||
| 155 | (** The multiset space **) | |
| 156 | lemma multiset_into_Mult: "[| multiset(M); mset_of(M)\<subseteq>A |] ==> M \<in> Mult(A)" | |
| 157 | apply (simp add: multiset_def) | |
| 158 | apply (auto simp add: multiset_fun_iff mset_of_def) | |
| 159 | apply (rule_tac B1 = "nat-{0}" in FiniteFun_mono [THEN subsetD], simp_all)
 | |
| 160 | apply (rule Finite_into_Fin [THEN [2] Fin_mono [THEN subsetD], THEN fun_FiniteFunI]) | |
| 161 | apply (simp_all (no_asm_simp) add: multiset_fun_iff) | |
| 162 | done | |
| 163 | ||
| 164 | lemma Mult_into_multiset: "M \<in> Mult(A) ==> multiset(M) & mset_of(M)\<subseteq>A" | |
| 165 | apply (simp add: multiset_def mset_of_def) | |
| 166 | apply (frule FiniteFun_is_fun) | |
| 167 | apply (drule FiniteFun_domain_Fin) | |
| 168 | apply (frule FinD, clarify) | |
| 169 | apply (rule_tac x = "domain (M) " in exI) | |
| 170 | apply (blast intro: Fin_into_Finite) | |
| 171 | done | |
| 172 | ||
| 46822 
95f1e700b712
 mathematical symbols for Isabelle/ZF example theories
 paulson parents: 
45602diff
changeset | 173 | lemma Mult_iff_multiset: "M \<in> Mult(A) \<longleftrightarrow> multiset(M) & mset_of(M)\<subseteq>A" | 
| 15201 | 174 | by (blast dest: Mult_into_multiset intro: multiset_into_Mult) | 
| 175 | ||
| 46822 
95f1e700b712
 mathematical symbols for Isabelle/ZF example theories
 paulson parents: 
45602diff
changeset | 176 | lemma multiset_iff_Mult_mset_of: "multiset(M) \<longleftrightarrow> M \<in> Mult(mset_of(M))" | 
| 15201 | 177 | by (auto simp add: Mult_iff_multiset) | 
| 178 | ||
| 179 | ||
| 180 | text{*The @{term multiset} operator*}
 | |
| 181 | ||
| 182 | (* the empty multiset is 0 *) | |
| 183 | ||
| 184 | lemma multiset_0 [simp]: "multiset(0)" | |
| 185 | by (auto intro: FiniteFun.intros simp add: multiset_iff_Mult_mset_of) | |
| 186 | ||
| 187 | ||
| 188 | text{*The @{term mset_of} operator*}
 | |
| 189 | ||
| 190 | lemma multiset_set_of_Finite [simp]: "multiset(M) ==> Finite(mset_of(M))" | |
| 191 | by (simp add: multiset_def mset_of_def, auto) | |
| 192 | ||
| 193 | lemma mset_of_0 [iff]: "mset_of(0) = 0" | |
| 194 | by (simp add: mset_of_def) | |
| 195 | ||
| 46822 
95f1e700b712
 mathematical symbols for Isabelle/ZF example theories
 paulson parents: 
45602diff
changeset | 196 | lemma mset_is_0_iff: "multiset(M) ==> mset_of(M)=0 \<longleftrightarrow> M=0" | 
| 15201 | 197 | by (auto simp add: multiset_def mset_of_def) | 
| 198 | ||
| 199 | lemma mset_of_single [iff]: "mset_of({#a#}) = {a}"
 | |
| 200 | by (simp add: msingle_def mset_of_def) | |
| 201 | ||
| 46822 
95f1e700b712
 mathematical symbols for Isabelle/ZF example theories
 paulson parents: 
45602diff
changeset | 202 | lemma mset_of_union [iff]: "mset_of(M +# N) = mset_of(M) \<union> mset_of(N)" | 
| 15201 | 203 | by (simp add: mset_of_def munion_def) | 
| 204 | ||
| 205 | lemma mset_of_diff [simp]: "mset_of(M)\<subseteq>A ==> mset_of(M -# N) \<subseteq> A" | |
| 206 | by (auto simp add: mdiff_def multiset_def normalize_def mset_of_def) | |
| 207 | ||
| 208 | (* msingle *) | |
| 209 | ||
| 210 | lemma msingle_not_0 [iff]: "{#a#} \<noteq> 0 & 0 \<noteq> {#a#}"
 | |
| 211 | by (simp add: msingle_def) | |
| 212 | ||
| 46822 
95f1e700b712
 mathematical symbols for Isabelle/ZF example theories
 paulson parents: 
45602diff
changeset | 213 | lemma msingle_eq_iff [iff]: "({#a#} = {#b#}) \<longleftrightarrow>  (a = b)"
 | 
| 15201 | 214 | by (simp add: msingle_def) | 
| 215 | ||
| 216 | lemma msingle_multiset [iff,TC]: "multiset({#a#})"
 | |
| 217 | apply (simp add: multiset_def msingle_def) | |
| 218 | apply (rule_tac x = "{a}" in exI)
 | |
| 219 | apply (auto intro: Finite_cons Finite_0 fun_extend3) | |
| 220 | done | |
| 221 | ||
| 222 | (** normalize **) | |
| 223 | ||
| 45602 | 224 | lemmas Collect_Finite = Collect_subset [THEN subset_Finite] | 
| 15201 | 225 | |
| 226 | lemma normalize_idem [simp]: "normalize(normalize(f)) = normalize(f)" | |
| 227 | apply (simp add: normalize_def funrestrict_def mset_of_def) | |
| 228 | apply (case_tac "\<exists>A. f \<in> A -> nat & Finite (A) ") | |
| 229 | apply clarify | |
| 230 | apply (drule_tac x = "{x \<in> domain (f) . 0 < f ` x}" in spec)
 | |
| 231 | apply auto | |
| 232 | apply (auto intro!: lam_type simp add: Collect_Finite) | |
| 233 | done | |
| 234 | ||
| 235 | lemma normalize_multiset [simp]: "multiset(M) ==> normalize(M) = M" | |
| 236 | by (auto simp add: multiset_def normalize_def mset_of_def funrestrict_def multiset_fun_iff) | |
| 237 | ||
| 238 | lemma multiset_normalize [simp]: "multiset(normalize(f))" | |
| 239 | apply (simp add: normalize_def) | |
| 240 | apply (simp add: normalize_def mset_of_def multiset_def, auto) | |
| 241 | apply (rule_tac x = "{x \<in> A . 0<f`x}" in exI)
 | |
| 242 | apply (auto intro: Collect_subset [THEN subset_Finite] funrestrict_type) | |
| 243 | done | |
| 244 | ||
| 245 | (** Typechecking rules for union and difference of multisets **) | |
| 246 | ||
| 247 | (* union *) | |
| 248 | ||
| 249 | lemma munion_multiset [simp]: "[| multiset(M); multiset(N) |] ==> multiset(M +# N)" | |
| 250 | apply (unfold multiset_def munion_def mset_of_def, auto) | |
| 46822 
95f1e700b712
 mathematical symbols for Isabelle/ZF example theories
 paulson parents: 
45602diff
changeset | 251 | apply (rule_tac x = "A \<union> Aa" in exI) | 
| 15201 | 252 | apply (auto intro!: lam_type intro: Finite_Un simp add: multiset_fun_iff zero_less_add) | 
| 253 | done | |
| 254 | ||
| 255 | (* difference *) | |
| 256 | ||
| 257 | lemma mdiff_multiset [simp]: "multiset(M -# N)" | |
| 258 | by (simp add: mdiff_def) | |
| 259 | ||
| 260 | (** Algebraic properties of multisets **) | |
| 261 | ||
| 262 | (* Union *) | |
| 263 | ||
| 264 | lemma munion_0 [simp]: "multiset(M) ==> M +# 0 = M & 0 +# M = M" | |
| 265 | apply (simp add: multiset_def) | |
| 266 | apply (auto simp add: munion_def mset_of_def) | |
| 267 | done | |
| 268 | ||
| 269 | lemma munion_commute: "M +# N = N +# M" | |
| 270 | by (auto intro!: lam_cong simp add: munion_def) | |
| 271 | ||
| 272 | lemma munion_assoc: "(M +# N) +# K = M +# (N +# K)" | |
| 273 | apply (unfold munion_def mset_of_def) | |
| 274 | apply (rule lam_cong, auto) | |
| 275 | done | |
| 276 | ||
| 277 | lemma munion_lcommute: "M +# (N +# K) = N +# (M +# K)" | |
| 278 | apply (unfold munion_def mset_of_def) | |
| 279 | apply (rule lam_cong, auto) | |
| 280 | done | |
| 281 | ||
| 282 | lemmas munion_ac = munion_commute munion_assoc munion_lcommute | |
| 283 | ||
| 284 | (* Difference *) | |
| 285 | ||
| 286 | lemma mdiff_self_eq_0 [simp]: "M -# M = 0" | |
| 287 | by (simp add: mdiff_def normalize_def mset_of_def) | |
| 288 | ||
| 289 | lemma mdiff_0 [simp]: "0 -# M = 0" | |
| 290 | by (simp add: mdiff_def normalize_def) | |
| 291 | ||
| 292 | lemma mdiff_0_right [simp]: "multiset(M) ==> M -# 0 = M" | |
| 293 | by (auto simp add: multiset_def mdiff_def normalize_def multiset_fun_iff mset_of_def funrestrict_def) | |
| 294 | ||
| 295 | lemma mdiff_union_inverse2 [simp]: "multiset(M) ==> M +# {#a#} -# {#a#} = M"
 | |
| 296 | apply (unfold multiset_def munion_def mdiff_def msingle_def normalize_def mset_of_def) | |
| 297 | apply (auto cong add: if_cong simp add: ltD multiset_fun_iff funrestrict_def subset_Un_iff2 [THEN iffD1]) | |
| 298 | prefer 2 apply (force intro!: lam_type) | |
| 299 | apply (subgoal_tac [2] "{x \<in> A \<union> {a} . x \<noteq> a \<and> x \<in> A} = A")
 | |
| 300 | apply (rule fun_extension, auto) | |
| 46822 
95f1e700b712
 mathematical symbols for Isabelle/ZF example theories
 paulson parents: 
45602diff
changeset | 301 | apply (drule_tac x = "A \<union> {a}" in spec)
 | 
| 15201 | 302 | apply (simp add: Finite_Un) | 
| 303 | apply (force intro!: lam_type) | |
| 304 | done | |
| 305 | ||
| 306 | (** Count of elements **) | |
| 307 | ||
| 308 | lemma mcount_type [simp,TC]: "multiset(M) ==> mcount(M, a) \<in> nat" | |
| 309 | by (auto simp add: multiset_def mcount_def mset_of_def multiset_fun_iff) | |
| 310 | ||
| 311 | lemma mcount_0 [simp]: "mcount(0, a) = 0" | |
| 312 | by (simp add: mcount_def) | |
| 313 | ||
| 314 | lemma mcount_single [simp]: "mcount({#b#}, a) = (if a=b then 1 else 0)"
 | |
| 315 | by (simp add: mcount_def mset_of_def msingle_def) | |
| 316 | ||
| 317 | lemma mcount_union [simp]: "[| multiset(M); multiset(N) |] | |
| 318 | ==> mcount(M +# N, a) = mcount(M, a) #+ mcount (N, a)" | |
| 319 | apply (auto simp add: multiset_def multiset_fun_iff mcount_def munion_def mset_of_def) | |
| 320 | done | |
| 321 | ||
| 322 | lemma mcount_diff [simp]: | |
| 323 | "multiset(M) ==> mcount(M -# N, a) = mcount(M, a) #- mcount(N, a)" | |
| 324 | apply (simp add: multiset_def) | |
| 325 | apply (auto dest!: not_lt_imp_le | |
| 326 | simp add: mdiff_def multiset_fun_iff mcount_def normalize_def mset_of_def) | |
| 327 | apply (force intro!: lam_type) | |
| 328 | apply (force intro!: lam_type) | |
| 329 | done | |
| 330 | ||
| 331 | lemma mcount_elem: "[| multiset(M); a \<in> mset_of(M) |] ==> 0 < mcount(M, a)" | |
| 332 | apply (simp add: multiset_def, clarify) | |
| 333 | apply (simp add: mcount_def mset_of_def) | |
| 334 | apply (simp add: multiset_fun_iff) | |
| 335 | done | |
| 336 | ||
| 337 | (** msize **) | |
| 338 | ||
| 339 | lemma msize_0 [simp]: "msize(0) = #0" | |
| 340 | by (simp add: msize_def) | |
| 341 | ||
| 342 | lemma msize_single [simp]: "msize({#a#}) = #1"
 | |
| 343 | by (simp add: msize_def) | |
| 344 | ||
| 345 | lemma msize_type [simp,TC]: "msize(M) \<in> int" | |
| 346 | by (simp add: msize_def) | |
| 347 | ||
| 348 | lemma msize_zpositive: "multiset(M)==> #0 $\<le> msize(M)" | |
| 349 | by (auto simp add: msize_def intro: g_zpos_imp_setsum_zpos) | |
| 350 | ||
| 351 | lemma msize_int_of_nat: "multiset(M) ==> \<exists>n \<in> nat. msize(M)= $# n" | |
| 352 | apply (rule not_zneg_int_of) | |
| 353 | apply (simp_all (no_asm_simp) add: msize_type [THEN znegative_iff_zless_0] not_zless_iff_zle msize_zpositive) | |
| 354 | done | |
| 355 | ||
| 356 | lemma not_empty_multiset_imp_exist: | |
| 357 | "[| M\<noteq>0; multiset(M) |] ==> \<exists>a \<in> mset_of(M). 0 < mcount(M, a)" | |
| 358 | apply (simp add: multiset_def) | |
| 359 | apply (erule not_emptyE) | |
| 360 | apply (auto simp add: mset_of_def mcount_def multiset_fun_iff) | |
| 361 | apply (blast dest!: fun_is_rel) | |
| 362 | done | |
| 363 | ||
| 46822 
95f1e700b712
 mathematical symbols for Isabelle/ZF example theories
 paulson parents: 
45602diff
changeset | 364 | lemma msize_eq_0_iff: "multiset(M) ==> msize(M)=#0 \<longleftrightarrow> M=0" | 
| 15201 | 365 | apply (simp add: msize_def, auto) | 
| 26417 | 366 | apply (rule_tac P = "setsum (?u,?v) \<noteq> #0" in swap) | 
| 15201 | 367 | apply blast | 
| 368 | apply (drule not_empty_multiset_imp_exist, assumption, clarify) | |
| 369 | apply (subgoal_tac "Finite (mset_of (M) - {a}) ")
 | |
| 370 | prefer 2 apply (simp add: Finite_Diff) | |
| 371 | apply (subgoal_tac "setsum (%x. $# mcount (M, x), cons (a, mset_of (M) -{a}))=#0")
 | |
| 372 | prefer 2 apply (simp add: cons_Diff, simp) | |
| 373 | apply (subgoal_tac "#0 $\<le> setsum (%x. $# mcount (M, x), mset_of (M) - {a}) ")
 | |
| 374 | apply (rule_tac [2] g_zpos_imp_setsum_zpos) | |
| 375 | apply (auto simp add: Finite_Diff not_zless_iff_zle [THEN iff_sym] znegative_iff_zless_0 [THEN iff_sym]) | |
| 376 | apply (rule not_zneg_int_of [THEN bexE]) | |
| 377 | apply (auto simp del: int_of_0 simp add: int_of_add [symmetric] int_of_0 [symmetric]) | |
| 378 | done | |
| 379 | ||
| 380 | lemma setsum_mcount_Int: | |
| 46822 
95f1e700b712
 mathematical symbols for Isabelle/ZF example theories
 paulson parents: 
45602diff
changeset | 381 | "Finite(A) ==> setsum(%a. $# mcount(N, a), A \<inter> mset_of(N)) | 
| 32960 
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
 wenzelm parents: 
26417diff
changeset | 382 | = setsum(%a. $# mcount(N, a), A)" | 
| 18415 | 383 | apply (induct rule: Finite_induct) | 
| 384 | apply auto | |
| 46822 
95f1e700b712
 mathematical symbols for Isabelle/ZF example theories
 paulson parents: 
45602diff
changeset | 385 | apply (subgoal_tac "Finite (B \<inter> mset_of (N))") | 
| 15201 | 386 | prefer 2 apply (blast intro: subset_Finite) | 
| 387 | apply (auto simp add: mcount_def Int_cons_left) | |
| 388 | done | |
| 389 | ||
| 390 | lemma msize_union [simp]: | |
| 391 | "[| multiset(M); multiset(N) |] ==> msize(M +# N) = msize(M) $+ msize(N)" | |
| 392 | apply (simp add: msize_def setsum_Un setsum_addf int_of_add setsum_mcount_Int) | |
| 393 | apply (subst Int_commute) | |
| 394 | apply (simp add: setsum_mcount_Int) | |
| 395 | done | |
| 396 | ||
| 397 | lemma msize_eq_succ_imp_elem: "[|msize(M)= $# succ(n); n \<in> nat|] ==> \<exists>a. a \<in> mset_of(M)" | |
| 398 | apply (unfold msize_def) | |
| 399 | apply (blast dest: setsum_succD) | |
| 400 | done | |
| 401 | ||
| 402 | (** Equality of multisets **) | |
| 403 | ||
| 404 | lemma equality_lemma: | |
| 405 | "[| multiset(M); multiset(N); \<forall>a. mcount(M, a)=mcount(N, a) |] | |
| 406 | ==> mset_of(M)=mset_of(N)" | |
| 407 | apply (simp add: multiset_def) | |
| 408 | apply (rule sym, rule equalityI) | |
| 409 | apply (auto simp add: multiset_fun_iff mcount_def mset_of_def) | |
| 410 | apply (drule_tac [!] x=x in spec) | |
| 411 | apply (case_tac [2] "x \<in> Aa", case_tac "x \<in> A", auto) | |
| 412 | done | |
| 413 | ||
| 414 | lemma multiset_equality: | |
| 46822 
95f1e700b712
 mathematical symbols for Isabelle/ZF example theories
 paulson parents: 
45602diff
changeset | 415 | "[| multiset(M); multiset(N) |]==> M=N\<longleftrightarrow>(\<forall>a. mcount(M, a)=mcount(N, a))" | 
| 15201 | 416 | apply auto | 
| 417 | apply (subgoal_tac "mset_of (M) = mset_of (N) ") | |
| 418 | prefer 2 apply (blast intro: equality_lemma) | |
| 419 | apply (simp add: multiset_def mset_of_def) | |
| 420 | apply (auto simp add: multiset_fun_iff) | |
| 421 | apply (rule fun_extension) | |
| 422 | apply (blast, blast) | |
| 423 | apply (drule_tac x = x in spec) | |
| 424 | apply (auto simp add: mcount_def mset_of_def) | |
| 425 | done | |
| 426 | ||
| 427 | (** More algebraic properties of multisets **) | |
| 428 | ||
| 46822 
95f1e700b712
 mathematical symbols for Isabelle/ZF example theories
 paulson parents: 
45602diff
changeset | 429 | lemma munion_eq_0_iff [simp]: "[|multiset(M); multiset(N)|]==>(M +# N =0) \<longleftrightarrow> (M=0 & N=0)" | 
| 15201 | 430 | by (auto simp add: multiset_equality) | 
| 431 | ||
| 46822 
95f1e700b712
 mathematical symbols for Isabelle/ZF example theories
 paulson parents: 
45602diff
changeset | 432 | lemma empty_eq_munion_iff [simp]: "[|multiset(M); multiset(N)|]==>(0=M +# N) \<longleftrightarrow> (M=0 & N=0)" | 
| 15201 | 433 | apply (rule iffI, drule sym) | 
| 434 | apply (simp_all add: multiset_equality) | |
| 435 | done | |
| 436 | ||
| 437 | lemma munion_right_cancel [simp]: | |
| 46822 
95f1e700b712
 mathematical symbols for Isabelle/ZF example theories
 paulson parents: 
45602diff
changeset | 438 | "[| multiset(M); multiset(N); multiset(K) |]==>(M +# K = N +# K)\<longleftrightarrow>(M=N)" | 
| 15201 | 439 | by (auto simp add: multiset_equality) | 
| 440 | ||
| 441 | lemma munion_left_cancel [simp]: | |
| 46822 
95f1e700b712
 mathematical symbols for Isabelle/ZF example theories
 paulson parents: 
45602diff
changeset | 442 | "[|multiset(K); multiset(M); multiset(N)|] ==>(K +# M = K +# N) \<longleftrightarrow> (M = N)" | 
| 15201 | 443 | by (auto simp add: multiset_equality) | 
| 444 | ||
| 46822 
95f1e700b712
 mathematical symbols for Isabelle/ZF example theories
 paulson parents: 
45602diff
changeset | 445 | lemma nat_add_eq_1_cases: "[| m \<in> nat; n \<in> nat |] ==> (m #+ n = 1) \<longleftrightarrow> (m=1 & n=0) | (m=0 & n=1)" | 
| 18415 | 446 | by (induct_tac n) auto | 
| 15201 | 447 | |
| 448 | lemma munion_is_single: | |
| 46953 | 449 | "[|multiset(M); multiset(N)|] | 
| 46822 
95f1e700b712
 mathematical symbols for Isabelle/ZF example theories
 paulson parents: 
45602diff
changeset | 450 |       ==> (M +# N = {#a#}) \<longleftrightarrow>  (M={#a#} & N=0) | (M = 0 & N = {#a#})"
 | 
| 15201 | 451 | apply (simp (no_asm_simp) add: multiset_equality) | 
| 452 | apply safe | |
| 453 | apply simp_all | |
| 454 | apply (case_tac "aa=a") | |
| 455 | apply (drule_tac [2] x = aa in spec) | |
| 456 | apply (drule_tac x = a in spec) | |
| 457 | apply (simp add: nat_add_eq_1_cases, simp) | |
| 458 | apply (case_tac "aaa=aa", simp) | |
| 459 | apply (drule_tac x = aa in spec) | |
| 460 | apply (simp add: nat_add_eq_1_cases) | |
| 461 | apply (case_tac "aaa=a") | |
| 462 | apply (drule_tac [4] x = aa in spec) | |
| 463 | apply (drule_tac [3] x = a in spec) | |
| 464 | apply (drule_tac [2] x = aaa in spec) | |
| 465 | apply (drule_tac x = aa in spec) | |
| 466 | apply (simp_all add: nat_add_eq_1_cases) | |
| 467 | done | |
| 468 | ||
| 469 | lemma msingle_is_union: "[| multiset(M); multiset(N) |] | |
| 46822 
95f1e700b712
 mathematical symbols for Isabelle/ZF example theories
 paulson parents: 
45602diff
changeset | 470 |   ==> ({#a#} = M +# N) \<longleftrightarrow> ({#a#} = M  & N=0 | M = 0 & {#a#} = N)"
 | 
| 
95f1e700b712
 mathematical symbols for Isabelle/ZF example theories
 paulson parents: 
45602diff
changeset | 471 | apply (subgoal_tac " ({#a#} = M +# N) \<longleftrightarrow> (M +# N = {#a#}) ")
 | 
| 15201 | 472 | apply (simp (no_asm_simp) add: munion_is_single) | 
| 473 | apply blast | |
| 474 | apply (blast dest: sym) | |
| 475 | done | |
| 476 | ||
| 477 | (** Towards induction over multisets **) | |
| 478 | ||
| 479 | lemma setsum_decr: | |
| 480 | "Finite(A) | |
| 46822 
95f1e700b712
 mathematical symbols for Isabelle/ZF example theories
 paulson parents: 
45602diff
changeset | 481 | ==> (\<forall>M. multiset(M) \<longrightarrow> | 
| 15201 | 482 | (\<forall>a \<in> mset_of(M). setsum(%z. $# mcount(M(a:=M`a #- 1), z), A) = | 
| 483 | (if a \<in> A then setsum(%z. $# mcount(M, z), A) $- #1 | |
| 484 | else setsum(%z. $# mcount(M, z), A))))" | |
| 485 | apply (unfold multiset_def) | |
| 486 | apply (erule Finite_induct) | |
| 487 | apply (auto simp add: multiset_fun_iff) | |
| 488 | apply (unfold mset_of_def mcount_def) | |
| 489 | apply (case_tac "x \<in> A", auto) | |
| 490 | apply (subgoal_tac "$# M ` x $+ #-1 = $# M ` x $- $# 1") | |
| 491 | apply (erule ssubst) | |
| 492 | apply (rule int_of_diff, auto) | |
| 493 | done | |
| 494 | ||
| 495 | lemma setsum_decr2: | |
| 496 | "Finite(A) | |
| 46822 
95f1e700b712
 mathematical symbols for Isabelle/ZF example theories
 paulson parents: 
45602diff
changeset | 497 | ==> \<forall>M. multiset(M) \<longrightarrow> (\<forall>a \<in> mset_of(M). | 
| 16973 | 498 |            setsum(%x. $# mcount(funrestrict(M, mset_of(M)-{a}), x), A) =
 | 
| 499 | (if a \<in> A then setsum(%x. $# mcount(M, x), A) $- $# M`a | |
| 500 | else setsum(%x. $# mcount(M, x), A)))" | |
| 15201 | 501 | apply (simp add: multiset_def) | 
| 502 | apply (erule Finite_induct) | |
| 503 | apply (auto simp add: multiset_fun_iff mcount_def mset_of_def) | |
| 504 | done | |
| 505 | ||
| 506 | lemma setsum_decr3: "[| Finite(A); multiset(M); a \<in> mset_of(M) |] | |
| 507 |       ==> setsum(%x. $# mcount(funrestrict(M, mset_of(M)-{a}), x), A - {a}) =
 | |
| 508 | (if a \<in> A then setsum(%x. $# mcount(M, x), A) $- $# M`a | |
| 509 | else setsum(%x. $# mcount(M, x), A))" | |
| 510 | apply (subgoal_tac "setsum (%x. $# mcount (funrestrict (M, mset_of (M) -{a}),x),A-{a}) = setsum (%x. $# mcount (funrestrict (M, mset_of (M) -{a}),x),A) ")
 | |
| 511 | apply (rule_tac [2] setsum_Diff [symmetric]) | |
| 512 | apply (rule sym, rule ssubst, blast) | |
| 513 | apply (rule sym, drule setsum_decr2, auto) | |
| 514 | apply (simp add: mcount_def mset_of_def) | |
| 515 | done | |
| 516 | ||
| 46822 
95f1e700b712
 mathematical symbols for Isabelle/ZF example theories
 paulson parents: 
45602diff
changeset | 517 | lemma nat_le_1_cases: "n \<in> nat ==> n \<le> 1 \<longleftrightarrow> (n=0 | n=1)" | 
| 15201 | 518 | by (auto elim: natE) | 
| 519 | ||
| 520 | lemma succ_pred_eq_self: "[| 0<n; n \<in> nat |] ==> succ(n #- 1) = n" | |
| 46822 
95f1e700b712
 mathematical symbols for Isabelle/ZF example theories
 paulson parents: 
45602diff
changeset | 521 | apply (subgoal_tac "1 \<le> n") | 
| 15201 | 522 | apply (drule add_diff_inverse2, auto) | 
| 523 | done | |
| 524 | ||
| 525 | text{*Specialized for use in the proof below.*}
 | |
| 526 | lemma multiset_funrestict: | |
| 527 | "\<lbrakk>\<forall>a\<in>A. M ` a \<in> nat \<and> 0 < M ` a; Finite(A)\<rbrakk> | |
| 528 |       \<Longrightarrow> multiset(funrestrict(M, A - {a}))"
 | |
| 529 | apply (simp add: multiset_def multiset_fun_iff) | |
| 530 | apply (rule_tac x="A-{a}" in exI)
 | |
| 531 | apply (auto intro: Finite_Diff funrestrict_type) | |
| 532 | done | |
| 533 | ||
| 534 | lemma multiset_induct_aux: | |
| 535 | assumes prem1: "!!M a. [| multiset(M); a\<notin>mset_of(M); P(M) |] ==> P(cons(<a, 1>, M))" | |
| 536 | and prem2: "!!M b. [| multiset(M); b \<in> mset_of(M); P(M) |] ==> P(M(b:= M`b #+ 1))" | |
| 537 | shows | |
| 538 | "[| n \<in> nat; P(0) |] | |
| 46822 
95f1e700b712
 mathematical symbols for Isabelle/ZF example theories
 paulson parents: 
45602diff
changeset | 539 | ==> (\<forall>M. multiset(M)\<longrightarrow> | 
| 
95f1e700b712
 mathematical symbols for Isabelle/ZF example theories
 paulson parents: 
45602diff
changeset | 540 |   (setsum(%x. $# mcount(M, x), {x \<in> mset_of(M). 0 < M`x}) = $# n) \<longrightarrow> P(M))"
 | 
| 15201 | 541 | apply (erule nat_induct, clarify) | 
| 542 | apply (frule msize_eq_0_iff) | |
| 543 | apply (auto simp add: mset_of_def multiset_def multiset_fun_iff msize_def) | |
| 544 | apply (subgoal_tac "setsum (%x. $# mcount (M, x), A) =$# succ (x) ") | |
| 545 | apply (drule setsum_succD, auto) | |
| 546 | apply (case_tac "1 <M`a") | |
| 547 | apply (drule_tac [2] not_lt_imp_le) | |
| 548 | apply (simp_all add: nat_le_1_cases) | |
| 549 | apply (subgoal_tac "M= (M (a:=M`a #- 1)) (a:= (M (a:=M`a #- 1))`a #+ 1) ") | |
| 550 | apply (rule_tac [2] A = A and B = "%x. nat" and D = "%x. nat" in fun_extension) | |
| 551 | apply (rule_tac [3] update_type)+ | |
| 552 | apply (simp_all (no_asm_simp)) | |
| 553 | apply (rule_tac [2] impI) | |
| 554 | apply (rule_tac [2] succ_pred_eq_self [symmetric]) | |
| 555 | apply (simp_all (no_asm_simp)) | |
| 556 | apply (rule subst, rule sym, blast, rule prem2) | |
| 557 | apply (simp (no_asm) add: multiset_def multiset_fun_iff) | |
| 558 | apply (rule_tac x = A in exI) | |
| 559 | apply (force intro: update_type) | |
| 560 | apply (simp (no_asm_simp) add: mset_of_def mcount_def) | |
| 561 | apply (drule_tac x = "M (a := M ` a #- 1) " in spec) | |
| 562 | apply (drule mp, drule_tac [2] mp, simp_all) | |
| 563 | apply (rule_tac x = A in exI) | |
| 564 | apply (auto intro: update_type) | |
| 46822 
95f1e700b712
 mathematical symbols for Isabelle/ZF example theories
 paulson parents: 
45602diff
changeset | 565 | apply (subgoal_tac "Finite ({x \<in> cons (a, A) . x\<noteq>a\<longrightarrow>0<M`x}) ")
 | 
| 15201 | 566 | prefer 2 apply (blast intro: Collect_subset [THEN subset_Finite] Finite_cons) | 
| 46822 
95f1e700b712
 mathematical symbols for Isabelle/ZF example theories
 paulson parents: 
45602diff
changeset | 567 | apply (drule_tac A = "{x \<in> cons (a, A) . x\<noteq>a\<longrightarrow>0<M`x}" in setsum_decr)
 | 
| 15201 | 568 | apply (drule_tac x = M in spec) | 
| 569 | apply (subgoal_tac "multiset (M) ") | |
| 570 | prefer 2 | |
| 571 | apply (simp add: multiset_def multiset_fun_iff) | |
| 572 | apply (rule_tac x = A in exI, force) | |
| 573 | apply (simp_all add: mset_of_def) | |
| 574 | apply (drule_tac psi = "\<forall>x \<in> A. ?u (x) " in asm_rl) | |
| 575 | apply (drule_tac x = a in bspec) | |
| 576 | apply (simp (no_asm_simp)) | |
| 577 | apply (subgoal_tac "cons (a, A) = A") | |
| 578 | prefer 2 apply blast | |
| 579 | apply simp | |
| 580 | apply (subgoal_tac "M=cons (<a, M`a>, funrestrict (M, A-{a}))")
 | |
| 581 | prefer 2 | |
| 582 | apply (rule fun_cons_funrestrict_eq) | |
| 583 |  apply (subgoal_tac "cons (a, A-{a}) = A")
 | |
| 584 | apply force | |
| 585 | apply force | |
| 586 | apply (rule_tac a = "cons (<a, 1>, funrestrict (M, A - {a}))" in ssubst)
 | |
| 587 | apply simp | |
| 588 | apply (frule multiset_funrestict, assumption) | |
| 589 | apply (rule prem1, assumption) | |
| 590 | apply (simp add: mset_of_def) | |
| 591 | apply (drule_tac x = "funrestrict (M, A-{a}) " in spec)
 | |
| 592 | apply (drule mp) | |
| 593 | apply (rule_tac x = "A-{a}" in exI)
 | |
| 594 | apply (auto intro: Finite_Diff funrestrict_type simp add: funrestrict) | |
| 595 | apply (frule_tac A = A and M = M and a = a in setsum_decr3) | |
| 596 | apply (simp (no_asm_simp) add: multiset_def multiset_fun_iff) | |
| 597 | apply blast | |
| 598 | apply (simp (no_asm_simp) add: mset_of_def) | |
| 599 | apply (drule_tac b = "if ?u then ?v else ?w" in sym, simp_all) | |
| 600 | apply (subgoal_tac "{x \<in> A - {a} . 0 < funrestrict (M, A - {x}) ` x} = A - {a}")
 | |
| 601 | apply (auto intro!: setsum_cong simp add: zdiff_eq_iff zadd_commute multiset_def multiset_fun_iff mset_of_def) | |
| 602 | done | |
| 603 | ||
| 604 | lemma multiset_induct2: | |
| 605 | "[| multiset(M); P(0); | |
| 606 | (!!M a. [| multiset(M); a\<notin>mset_of(M); P(M) |] ==> P(cons(<a, 1>, M))); | |
| 607 | (!!M b. [| multiset(M); b \<in> mset_of(M); P(M) |] ==> P(M(b:= M`b #+ 1))) |] | |
| 608 | ==> P(M)" | |
| 609 | apply (subgoal_tac "\<exists>n \<in> nat. setsum (\<lambda>x. $# mcount (M, x), {x \<in> mset_of (M) . 0 < M ` x}) = $# n")
 | |
| 610 | apply (rule_tac [2] not_zneg_int_of) | |
| 611 | apply (simp_all (no_asm_simp) add: znegative_iff_zless_0 not_zless_iff_zle) | |
| 612 | apply (rule_tac [2] g_zpos_imp_setsum_zpos) | |
| 613 | prefer 2 apply (blast intro: multiset_set_of_Finite Collect_subset [THEN subset_Finite]) | |
| 614 | prefer 2 apply (simp add: multiset_def multiset_fun_iff, clarify) | |
| 615 | apply (rule multiset_induct_aux [rule_format], auto) | |
| 616 | done | |
| 617 | ||
| 618 | lemma munion_single_case1: | |
| 619 |      "[| multiset(M); a \<notin>mset_of(M) |] ==> M +# {#a#} = cons(<a, 1>, M)"
 | |
| 620 | apply (simp add: multiset_def msingle_def) | |
| 621 | apply (auto simp add: munion_def) | |
| 622 | apply (unfold mset_of_def, simp) | |
| 623 | apply (rule fun_extension, rule lam_type, simp_all) | |
| 624 | apply (auto simp add: multiset_fun_iff fun_extend_apply) | |
| 625 | apply (drule_tac c = a and b = 1 in fun_extend3) | |
| 626 | apply (auto simp add: cons_eq Un_commute [of _ "{a}"])
 | |
| 627 | done | |
| 628 | ||
| 629 | lemma munion_single_case2: | |
| 630 |      "[| multiset(M); a \<in> mset_of(M) |] ==> M +# {#a#} = M(a:=M`a #+ 1)"
 | |
| 631 | apply (simp add: multiset_def) | |
| 632 | apply (auto simp add: munion_def multiset_fun_iff msingle_def) | |
| 633 | apply (unfold mset_of_def, simp) | |
| 46822 
95f1e700b712
 mathematical symbols for Isabelle/ZF example theories
 paulson parents: 
45602diff
changeset | 634 | apply (subgoal_tac "A \<union> {a} = A")
 | 
| 15201 | 635 | apply (rule fun_extension) | 
| 636 | apply (auto dest: domain_type intro: lam_type update_type) | |
| 637 | done | |
| 638 | ||
| 639 | (* Induction principle for multisets *) | |
| 640 | ||
| 641 | lemma multiset_induct: | |
| 642 | assumes M: "multiset(M)" | |
| 643 | and P0: "P(0)" | |
| 644 |       and step: "!!M a. [| multiset(M); P(M) |] ==> P(M +# {#a#})"
 | |
| 645 | shows "P(M)" | |
| 646 | apply (rule multiset_induct2 [OF M]) | |
| 647 | apply (simp_all add: P0) | |
| 20898 | 648 | apply (frule_tac [2] a = b in munion_single_case2 [symmetric]) | 
| 649 | apply (frule_tac a = a in munion_single_case1 [symmetric]) | |
| 15201 | 650 | apply (auto intro: step) | 
| 651 | done | |
| 652 | ||
| 653 | (** MCollect **) | |
| 654 | ||
| 655 | lemma MCollect_multiset [simp]: | |
| 656 |      "multiset(M) ==> multiset({# x \<in> M. P(x)#})"
 | |
| 657 | apply (simp add: MCollect_def multiset_def mset_of_def, clarify) | |
| 658 | apply (rule_tac x = "{x \<in> A. P (x) }" in exI)
 | |
| 659 | apply (auto dest: CollectD1 [THEN [2] apply_type] | |
| 660 | intro: Collect_subset [THEN subset_Finite] funrestrict_type) | |
| 661 | done | |
| 662 | ||
| 663 | lemma mset_of_MCollect [simp]: | |
| 664 |      "multiset(M) ==> mset_of({# x \<in> M. P(x) #}) \<subseteq> mset_of(M)"
 | |
| 665 | by (auto simp add: mset_of_def MCollect_def multiset_def funrestrict_def) | |
| 666 | ||
| 667 | lemma MCollect_mem_iff [iff]: | |
| 46822 
95f1e700b712
 mathematical symbols for Isabelle/ZF example theories
 paulson parents: 
45602diff
changeset | 668 |      "x \<in> mset_of({#x \<in> M. P(x)#}) \<longleftrightarrow>  x \<in> mset_of(M) & P(x)"
 | 
| 15201 | 669 | by (simp add: MCollect_def mset_of_def) | 
| 670 | ||
| 671 | lemma mcount_MCollect [simp]: | |
| 672 |      "mcount({# x \<in> M. P(x) #}, a) = (if P(a) then mcount(M,a) else 0)"
 | |
| 673 | by (simp add: mcount_def MCollect_def mset_of_def) | |
| 674 | ||
| 675 | lemma multiset_partition: "multiset(M) ==> M = {# x \<in> M. P(x) #} +# {# x \<in> M. ~ P(x) #}"
 | |
| 676 | by (simp add: multiset_equality) | |
| 677 | ||
| 678 | lemma natify_elem_is_self [simp]: | |
| 679 | "[| multiset(M); a \<in> mset_of(M) |] ==> natify(M`a) = M`a" | |
| 680 | by (auto simp add: multiset_def mset_of_def multiset_fun_iff) | |
| 681 | ||
| 682 | (* and more algebraic laws on multisets *) | |
| 683 | ||
| 684 | lemma munion_eq_conv_diff: "[| multiset(M); multiset(N) |] | |
| 46822 
95f1e700b712
 mathematical symbols for Isabelle/ZF example theories
 paulson parents: 
45602diff
changeset | 685 |   ==>  (M +# {#a#} = N +# {#b#}) \<longleftrightarrow>  (M = N & a = b |
 | 
| 15201 | 686 |        M = N -# {#a#} +# {#b#} & N = M -# {#b#} +# {#a#})"
 | 
| 687 | apply (simp del: mcount_single add: multiset_equality) | |
| 688 | apply (rule iffI, erule_tac [2] disjE, erule_tac [3] conjE) | |
| 689 | apply (case_tac "a=b", auto) | |
| 690 | apply (drule_tac x = a in spec) | |
| 691 | apply (drule_tac [2] x = b in spec) | |
| 692 | apply (drule_tac [3] x = aa in spec) | |
| 693 | apply (drule_tac [4] x = a in spec, auto) | |
| 694 | apply (subgoal_tac [!] "mcount (N,a) :nat") | |
| 695 | apply (erule_tac [3] natE, erule natE, auto) | |
| 696 | done | |
| 697 | ||
| 698 | lemma melem_diff_single: | |
| 699 | "multiset(M) ==> | |
| 46822 
95f1e700b712
 mathematical symbols for Isabelle/ZF example theories
 paulson parents: 
45602diff
changeset | 700 |   k \<in> mset_of(M -# {#a#}) \<longleftrightarrow> (k=a & 1 < mcount(M,a)) | (k\<noteq> a & k \<in> mset_of(M))"
 | 
| 15201 | 701 | apply (simp add: multiset_def) | 
| 702 | apply (simp add: normalize_def mset_of_def msingle_def mdiff_def mcount_def) | |
| 703 | apply (auto dest: domain_type intro: zero_less_diff [THEN iffD1] | |
| 704 | simp add: multiset_fun_iff apply_iff) | |
| 705 | apply (force intro!: lam_type) | |
| 706 | apply (force intro!: lam_type) | |
| 707 | apply (force intro!: lam_type) | |
| 708 | done | |
| 709 | ||
| 710 | lemma munion_eq_conv_exist: | |
| 711 | "[| M \<in> Mult(A); N \<in> Mult(A) |] | |
| 46822 
95f1e700b712
 mathematical symbols for Isabelle/ZF example theories
 paulson parents: 
45602diff
changeset | 712 |   ==> (M +# {#a#} = N +# {#b#}) \<longleftrightarrow>
 | 
| 15201 | 713 |       (M=N & a=b | (\<exists>K \<in> Mult(A). M= K +# {#b#} & N=K +# {#a#}))"
 | 
| 714 | by (auto simp add: Mult_iff_multiset melem_diff_single munion_eq_conv_diff) | |
| 715 | ||
| 716 | ||
| 717 | subsection{*Multiset Orderings*}
 | |
| 718 | ||
| 719 | (* multiset on a domain A are finite functions from A to nat-{0} *)
 | |
| 720 | ||
| 721 | ||
| 722 | (* multirel1 type *) | |
| 723 | ||
| 724 | lemma multirel1_type: "multirel1(A, r) \<subseteq> Mult(A)*Mult(A)" | |
| 725 | by (auto simp add: multirel1_def) | |
| 726 | ||
| 727 | lemma multirel1_0 [simp]: "multirel1(0, r) =0" | |
| 728 | by (auto simp add: multirel1_def) | |
| 729 | ||
| 730 | lemma multirel1_iff: | |
| 46822 
95f1e700b712
 mathematical symbols for Isabelle/ZF example theories
 paulson parents: 
45602diff
changeset | 731 | " <N, M> \<in> multirel1(A, r) \<longleftrightarrow> | 
| 15201 | 732 | (\<exists>a. a \<in> A & | 
| 733 | (\<exists>M0. M0 \<in> Mult(A) & (\<exists>K. K \<in> Mult(A) & | |
| 734 |    M=M0 +# {#a#} & N=M0 +# K & (\<forall>b \<in> mset_of(K). <b,a> \<in> r))))"
 | |
| 735 | by (auto simp add: multirel1_def Mult_iff_multiset Bex_def) | |
| 736 | ||
| 737 | ||
| 738 | text{*Monotonicity of @{term multirel1}*}
 | |
| 739 | ||
| 740 | lemma multirel1_mono1: "A\<subseteq>B ==> multirel1(A, r)\<subseteq>multirel1(B, r)" | |
| 741 | apply (auto simp add: multirel1_def) | |
| 742 | apply (auto simp add: Un_subset_iff Mult_iff_multiset) | |
| 743 | apply (rule_tac x = a in bexI) | |
| 744 | apply (rule_tac x = M0 in bexI, simp) | |
| 745 | apply (rule_tac x = K in bexI) | |
| 746 | apply (auto simp add: Mult_iff_multiset) | |
| 747 | done | |
| 748 | ||
| 749 | lemma multirel1_mono2: "r\<subseteq>s ==> multirel1(A,r)\<subseteq>multirel1(A, s)" | |
| 46953 | 750 | apply (simp add: multirel1_def, auto) | 
| 15201 | 751 | apply (rule_tac x = a in bexI) | 
| 752 | apply (rule_tac x = M0 in bexI) | |
| 753 | apply (simp_all add: Mult_iff_multiset) | |
| 754 | apply (rule_tac x = K in bexI) | |
| 755 | apply (simp_all add: Mult_iff_multiset, auto) | |
| 756 | done | |
| 757 | ||
| 758 | lemma multirel1_mono: | |
| 759 | "[| A\<subseteq>B; r\<subseteq>s |] ==> multirel1(A, r) \<subseteq> multirel1(B, s)" | |
| 760 | apply (rule subset_trans) | |
| 761 | apply (rule multirel1_mono1) | |
| 762 | apply (rule_tac [2] multirel1_mono2, auto) | |
| 763 | done | |
| 764 | ||
| 765 | subsection{* Toward the proof of well-foundedness of multirel1 *}
 | |
| 766 | ||
| 767 | lemma not_less_0 [iff]: "<M,0> \<notin> multirel1(A, r)" | |
| 768 | by (auto simp add: multirel1_def Mult_iff_multiset) | |
| 12089 
34e7693271a9
Sidi Ehmety's port of the fold_set operator and multisets to ZF.
 paulson parents: diff
changeset | 769 | |
| 15201 | 770 | lemma less_munion: "[| <N, M0 +# {#a#}> \<in> multirel1(A, r); M0 \<in> Mult(A) |] ==>
 | 
| 771 |   (\<exists>M. <M, M0> \<in> multirel1(A, r) & N = M +# {#a#}) |
 | |
| 772 | (\<exists>K. K \<in> Mult(A) & (\<forall>b \<in> mset_of(K). <b, a> \<in> r) & N = M0 +# K)" | |
| 773 | apply (frule multirel1_type [THEN subsetD]) | |
| 774 | apply (simp add: multirel1_iff) | |
| 775 | apply (auto simp add: munion_eq_conv_exist) | |
| 776 | apply (rule_tac x="Ka +# K" in exI, auto, simp add: Mult_iff_multiset) | |
| 777 | apply (simp (no_asm_simp) add: munion_left_cancel munion_assoc) | |
| 778 | apply (auto simp add: munion_commute) | |
| 779 | done | |
| 780 | ||
| 781 | lemma multirel1_base: "[| M \<in> Mult(A); a \<in> A |] ==> <M, M +# {#a#}> \<in> multirel1(A, r)"
 | |
| 782 | apply (auto simp add: multirel1_iff) | |
| 783 | apply (simp add: Mult_iff_multiset) | |
| 784 | apply (rule_tac x = a in exI, clarify) | |
| 785 | apply (rule_tac x = M in exI, simp) | |
| 786 | apply (rule_tac x = 0 in exI, auto) | |
| 787 | done | |
| 788 | ||
| 789 | lemma acc_0: "acc(0)=0" | |
| 790 | by (auto intro!: equalityI dest: acc.dom_subset [THEN subsetD]) | |
| 791 | ||
| 46822 
95f1e700b712
 mathematical symbols for Isabelle/ZF example theories
 paulson parents: 
45602diff
changeset | 792 | lemma lemma1: "[| \<forall>b \<in> A. <b,a> \<in> r \<longrightarrow> | 
| 15201 | 793 |     (\<forall>M \<in> acc(multirel1(A, r)). M +# {#b#}:acc(multirel1(A, r)));
 | 
| 794 | M0 \<in> acc(multirel1(A, r)); a \<in> A; | |
| 46822 
95f1e700b712
 mathematical symbols for Isabelle/ZF example theories
 paulson parents: 
45602diff
changeset | 795 |     \<forall>M. <M,M0> \<in> multirel1(A, r) \<longrightarrow> M +# {#a#} \<in> acc(multirel1(A, r)) |]
 | 
| 15201 | 796 |   ==> M0 +# {#a#} \<in> acc(multirel1(A, r))"
 | 
| 15481 | 797 | apply (subgoal_tac "M0 \<in> Mult(A) ") | 
| 15201 | 798 | prefer 2 | 
| 799 | apply (erule acc.cases) | |
| 800 | apply (erule fieldE) | |
| 801 | apply (auto dest: multirel1_type [THEN subsetD]) | |
| 802 | apply (rule accI) | |
| 803 | apply (rename_tac "N") | |
| 804 | apply (drule less_munion, blast) | |
| 805 | apply (auto simp add: Mult_iff_multiset) | |
| 806 | apply (erule_tac P = "\<forall>x \<in> mset_of (K) . <x, a> \<in> r" in rev_mp) | |
| 807 | apply (erule_tac P = "mset_of (K) \<subseteq>A" in rev_mp) | |
| 808 | apply (erule_tac M = K in multiset_induct) | |
| 809 | (* three subgoals *) | |
| 46953 | 810 | (* subgoal 1 \<in> the induction base case *) | 
| 15201 | 811 | apply (simp (no_asm_simp)) | 
| 46953 | 812 | (* subgoal 2 \<in> the induction general case *) | 
| 15201 | 813 | apply (simp add: Ball_def Un_subset_iff, clarify) | 
| 814 | apply (drule_tac x = aa in spec, simp) | |
| 815 | apply (subgoal_tac "aa \<in> A") | |
| 816 | prefer 2 apply blast | |
| 817 | apply (drule_tac x = "M0 +# M" and P = | |
| 818 | "%x. x \<in> acc(multirel1(A, r)) \<longrightarrow> ?Q(x)" in spec) | |
| 819 | apply (simp add: munion_assoc [symmetric]) | |
| 46953 | 820 | (* subgoal 3 \<in> additional conditions *) | 
| 15201 | 821 | apply (auto intro!: multirel1_base [THEN fieldI2] simp add: Mult_iff_multiset) | 
| 822 | done | |
| 823 | ||
| 824 | lemma lemma2: "[| \<forall>b \<in> A. <b,a> \<in> r | |
| 46822 
95f1e700b712
 mathematical symbols for Isabelle/ZF example theories
 paulson parents: 
45602diff
changeset | 825 |    \<longrightarrow> (\<forall>M \<in> acc(multirel1(A, r)). M +# {#b#} :acc(multirel1(A, r)));
 | 
| 15201 | 826 |         M \<in> acc(multirel1(A, r)); a \<in> A|] ==> M +# {#a#} \<in> acc(multirel1(A, r))"
 | 
| 827 | apply (erule acc_induct) | |
| 828 | apply (blast intro: lemma1) | |
| 829 | done | |
| 830 | ||
| 831 | lemma lemma3: "[| wf[A](r); a \<in> A |] | |
| 832 |       ==> \<forall>M \<in> acc(multirel1(A, r)). M +# {#a#} \<in> acc(multirel1(A, r))"
 | |
| 833 | apply (erule_tac a = a in wf_on_induct, blast) | |
| 834 | apply (blast intro: lemma2) | |
| 835 | done | |
| 836 | ||
| 46822 
95f1e700b712
 mathematical symbols for Isabelle/ZF example theories
 paulson parents: 
45602diff
changeset | 837 | lemma lemma4: "multiset(M) ==> mset_of(M)\<subseteq>A \<longrightarrow> | 
| 
95f1e700b712
 mathematical symbols for Isabelle/ZF example theories
 paulson parents: 
45602diff
changeset | 838 | wf[A](r) \<longrightarrow> M \<in> field(multirel1(A, r)) \<longrightarrow> M \<in> acc(multirel1(A, r))" | 
| 15201 | 839 | apply (erule multiset_induct) | 
| 840 | (* proving the base case *) | |
| 841 | apply clarify | |
| 842 | apply (rule accI, force) | |
| 843 | apply (simp add: multirel1_def) | |
| 844 | (* Proving the general case *) | |
| 845 | apply clarify | |
| 846 | apply simp | |
| 847 | apply (subgoal_tac "mset_of (M) \<subseteq>A") | |
| 848 | prefer 2 apply blast | |
| 849 | apply clarify | |
| 850 | apply (drule_tac a = a in lemma3, blast) | |
| 851 | apply (subgoal_tac "M \<in> field (multirel1 (A,r))") | |
| 852 | apply blast | |
| 853 | apply (rule multirel1_base [THEN fieldI1]) | |
| 854 | apply (auto simp add: Mult_iff_multiset) | |
| 855 | done | |
| 856 | ||
| 857 | lemma all_accessible: "[| wf[A](r); M \<in> Mult(A); A \<noteq> 0|] ==> M \<in> acc(multirel1(A, r))" | |
| 858 | apply (erule not_emptyE) | |
| 859 | apply (rule lemma4 [THEN mp, THEN mp, THEN mp]) | |
| 860 | apply (rule_tac [4] multirel1_base [THEN fieldI1]) | |
| 861 | apply (auto simp add: Mult_iff_multiset) | |
| 862 | done | |
| 863 | ||
| 864 | lemma wf_on_multirel1: "wf[A](r) ==> wf[A-||>nat-{0}](multirel1(A, r))"
 | |
| 865 | apply (case_tac "A=0") | |
| 866 | apply (simp (no_asm_simp)) | |
| 867 | apply (rule wf_imp_wf_on) | |
| 868 | apply (rule wf_on_field_imp_wf) | |
| 869 | apply (simp (no_asm_simp) add: wf_on_0) | |
| 870 | apply (rule_tac A = "acc (multirel1 (A,r))" in wf_on_subset_A) | |
| 871 | apply (rule wf_on_acc) | |
| 872 | apply (blast intro: all_accessible) | |
| 873 | done | |
| 874 | ||
| 875 | lemma wf_multirel1: "wf(r) ==>wf(multirel1(field(r), r))" | |
| 876 | apply (simp (no_asm_use) add: wf_iff_wf_on_field) | |
| 877 | apply (drule wf_on_multirel1) | |
| 878 | apply (rule_tac A = "field (r) -||> nat - {0}" in wf_on_subset_A)
 | |
| 879 | apply (simp (no_asm_simp)) | |
| 880 | apply (rule field_rel_subset) | |
| 881 | apply (rule multirel1_type) | |
| 882 | done | |
| 883 | ||
| 884 | (** multirel **) | |
| 885 | ||
| 886 | lemma multirel_type: "multirel(A, r) \<subseteq> Mult(A)*Mult(A)" | |
| 887 | apply (simp add: multirel_def) | |
| 888 | apply (rule trancl_type [THEN subset_trans]) | |
| 889 | apply (auto dest: multirel1_type [THEN subsetD]) | |
| 890 | done | |
| 891 | ||
| 892 | (* Monotonicity of multirel *) | |
| 893 | lemma multirel_mono: | |
| 894 | "[| A\<subseteq>B; r\<subseteq>s |] ==> multirel(A, r)\<subseteq>multirel(B,s)" | |
| 895 | apply (simp add: multirel_def) | |
| 896 | apply (rule trancl_mono) | |
| 897 | apply (rule multirel1_mono, auto) | |
| 898 | done | |
| 899 | ||
| 900 | (* Equivalence of multirel with the usual (closure-free) def *) | |
| 901 | ||
| 46822 
95f1e700b712
 mathematical symbols for Isabelle/ZF example theories
 paulson parents: 
45602diff
changeset | 902 | lemma add_diff_eq: "k \<in> nat ==> 0 < k \<longrightarrow> n #+ k #- 1 = n #+ (k #- 1)" | 
| 15201 | 903 | by (erule nat_induct, auto) | 
| 904 | ||
| 905 | lemma mdiff_union_single_conv: "[|a \<in> mset_of(J); multiset(I); multiset(J) |] | |
| 906 |    ==> I +# J -# {#a#} = I +# (J-# {#a#})"
 | |
| 907 | apply (simp (no_asm_simp) add: multiset_equality) | |
| 908 | apply (case_tac "a \<notin> mset_of (I) ") | |
| 909 | apply (auto simp add: mcount_def mset_of_def multiset_def multiset_fun_iff) | |
| 910 | apply (auto dest: domain_type simp add: add_diff_eq) | |
| 911 | done | |
| 912 | ||
| 46822 
95f1e700b712
 mathematical symbols for Isabelle/ZF example theories
 paulson parents: 
45602diff
changeset | 913 | lemma diff_add_commute: "[| n \<le> m; m \<in> nat; n \<in> nat; k \<in> nat |] ==> m #- n #+ k = m #+ k #- n" | 
| 15201 | 914 | by (auto simp add: le_iff less_iff_succ_add) | 
| 915 | ||
| 916 | (* One direction *) | |
| 917 | ||
| 918 | lemma multirel_implies_one_step: | |
| 919 | "<M,N> \<in> multirel(A, r) ==> | |
| 46822 
95f1e700b712
 mathematical symbols for Isabelle/ZF example theories
 paulson parents: 
45602diff
changeset | 920 | trans[A](r) \<longrightarrow> | 
| 15201 | 921 | (\<exists>I J K. | 
| 922 | I \<in> Mult(A) & J \<in> Mult(A) & K \<in> Mult(A) & | |
| 923 | N = I +# J & M = I +# K & J \<noteq> 0 & | |
| 924 | (\<forall>k \<in> mset_of(K). \<exists>j \<in> mset_of(J). <k,j> \<in> r))" | |
| 925 | apply (simp add: multirel_def Ball_def Bex_def) | |
| 926 | apply (erule converse_trancl_induct) | |
| 927 | apply (simp_all add: multirel1_iff Mult_iff_multiset) | |
| 928 | (* Two subgoals remain *) | |
| 929 | (* Subgoal 1 *) | |
| 930 | apply clarify | |
| 931 | apply (rule_tac x = M0 in exI, force) | |
| 932 | (* Subgoal 2 *) | |
| 933 | apply clarify | |
| 934 | apply (case_tac "a \<in> mset_of (Ka) ") | |
| 935 | apply (rule_tac x = I in exI, simp (no_asm_simp)) | |
| 936 | apply (rule_tac x = J in exI, simp (no_asm_simp)) | |
| 937 | apply (rule_tac x = " (Ka -# {#a#}) +# K" in exI, simp (no_asm_simp))
 | |
| 938 | apply (simp_all add: Un_subset_iff) | |
| 939 | apply (simp (no_asm_simp) add: munion_assoc [symmetric]) | |
| 940 | apply (drule_tac t = "%M. M-#{#a#}" in subst_context)
 | |
| 941 | apply (simp add: mdiff_union_single_conv melem_diff_single, clarify) | |
| 942 | apply (erule disjE, simp) | |
| 943 | apply (erule disjE, simp) | |
| 944 | apply (drule_tac x = a and P = "%x. x :# Ka \<longrightarrow> ?Q(x)" in spec) | |
| 945 | apply clarify | |
| 946 | apply (rule_tac x = xa in exI) | |
| 947 | apply (simp (no_asm_simp)) | |
| 948 | apply (blast dest: trans_onD) | |
| 949 | (* new we know that a\<notin>mset_of(Ka) *) | |
| 950 | apply (subgoal_tac "a :# I") | |
| 951 | apply (rule_tac x = "I-#{#a#}" in exI, simp (no_asm_simp))
 | |
| 952 | apply (rule_tac x = "J+#{#a#}" in exI)
 | |
| 953 | apply (simp (no_asm_simp) add: Un_subset_iff) | |
| 954 | apply (rule_tac x = "Ka +# K" in exI) | |
| 955 | apply (simp (no_asm_simp) add: Un_subset_iff) | |
| 956 | apply (rule conjI) | |
| 957 | apply (simp (no_asm_simp) add: multiset_equality mcount_elem [THEN succ_pred_eq_self]) | |
| 958 | apply (rule conjI) | |
| 959 | apply (drule_tac t = "%M. M-#{#a#}" in subst_context)
 | |
| 960 | apply (simp add: mdiff_union_inverse2) | |
| 961 | apply (simp_all (no_asm_simp) add: multiset_equality) | |
| 962 | apply (rule diff_add_commute [symmetric]) | |
| 963 | apply (auto intro: mcount_elem) | |
| 964 | apply (subgoal_tac "a \<in> mset_of (I +# Ka) ") | |
| 965 | apply (drule_tac [2] sym, auto) | |
| 966 | done | |
| 967 | ||
| 968 | lemma melem_imp_eq_diff_union [simp]: "[| a \<in> mset_of(M); multiset(M) |] ==> M -# {#a#} +# {#a#} = M"
 | |
| 969 | by (simp add: multiset_equality mcount_elem [THEN succ_pred_eq_self]) | |
| 970 | ||
| 971 | lemma msize_eq_succ_imp_eq_union: | |
| 972 | "[| msize(M)=$# succ(n); M \<in> Mult(A); n \<in> nat |] | |
| 973 |       ==> \<exists>a N. M = N +# {#a#} & N \<in> Mult(A) & a \<in> A"
 | |
| 974 | apply (drule msize_eq_succ_imp_elem, auto) | |
| 975 | apply (rule_tac x = a in exI) | |
| 976 | apply (rule_tac x = "M -# {#a#}" in exI)
 | |
| 977 | apply (frule Mult_into_multiset) | |
| 978 | apply (simp (no_asm_simp)) | |
| 979 | apply (auto simp add: Mult_iff_multiset) | |
| 980 | done | |
| 981 | ||
| 982 | (* The second direction *) | |
| 983 | ||
| 984 | lemma one_step_implies_multirel_lemma [rule_format (no_asm)]: | |
| 985 | "n \<in> nat ==> | |
| 986 | (\<forall>I J K. | |
| 987 | I \<in> Mult(A) & J \<in> Mult(A) & K \<in> Mult(A) & | |
| 988 | (msize(J) = $# n & J \<noteq>0 & (\<forall>k \<in> mset_of(K). \<exists>j \<in> mset_of(J). <k, j> \<in> r)) | |
| 46822 
95f1e700b712
 mathematical symbols for Isabelle/ZF example theories
 paulson parents: 
45602diff
changeset | 989 | \<longrightarrow> <I +# K, I +# J> \<in> multirel(A, r))" | 
| 15201 | 990 | apply (simp add: Mult_iff_multiset) | 
| 991 | apply (erule nat_induct, clarify) | |
| 992 | apply (drule_tac M = J in msize_eq_0_iff, auto) | |
| 993 | (* one subgoal remains *) | |
| 994 | apply (subgoal_tac "msize (J) =$# succ (x) ") | |
| 995 | prefer 2 apply simp | |
| 996 | apply (frule_tac A = A in msize_eq_succ_imp_eq_union) | |
| 997 | apply (simp_all add: Mult_iff_multiset, clarify) | |
| 998 | apply (rename_tac "J'", simp) | |
| 999 | apply (case_tac "J' = 0") | |
| 1000 | apply (simp add: multirel_def) | |
| 1001 | apply (rule r_into_trancl, clarify) | |
| 1002 | apply (simp add: multirel1_iff Mult_iff_multiset, force) | |
| 1003 | (*Now we know J' \<noteq> 0*) | |
| 1004 | apply (drule sym, rotate_tac -1, simp) | |
| 1005 | apply (erule_tac V = "$# x = msize (J') " in thin_rl) | |
| 1006 | apply (frule_tac M = K and P = "%x. <x,a> \<in> r" in multiset_partition) | |
| 1007 | apply (erule_tac P = "\<forall>k \<in> mset_of (K) . ?P (k) " in rev_mp) | |
| 1008 | apply (erule ssubst) | |
| 1009 | apply (simp add: Ball_def, auto) | |
| 15481 | 1010 | apply (subgoal_tac "< (I +# {# x \<in> K. <x, a> \<in> r#}) +# {# x \<in> K. <x, a> \<notin> r#}, (I +# {# x \<in> K. <x, a> \<in> r#}) +# J'> \<in> multirel(A, r) ")
 | 
| 15201 | 1011 | prefer 2 | 
| 1012 |  apply (drule_tac x = "I +# {# x \<in> K. <x, a> \<in> r#}" in spec)
 | |
| 1013 | apply (rotate_tac -1) | |
| 1014 | apply (drule_tac x = "J'" in spec) | |
| 1015 | apply (rotate_tac -1) | |
| 1016 |  apply (drule_tac x = "{# x \<in> K. <x, a> \<notin> r#}" in spec, simp) apply blast
 | |
| 1017 | apply (simp add: munion_assoc [symmetric] multirel_def) | |
| 1018 | apply (rule_tac b = "I +# {# x \<in> K. <x, a> \<in> r#} +# J'" in trancl_trans, blast)
 | |
| 1019 | apply (rule r_into_trancl) | |
| 1020 | apply (simp add: multirel1_iff Mult_iff_multiset) | |
| 1021 | apply (rule_tac x = a in exI) | |
| 1022 | apply (simp (no_asm_simp)) | |
| 1023 | apply (rule_tac x = "I +# J'" in exI) | |
| 1024 | apply (auto simp add: munion_ac Un_subset_iff) | |
| 1025 | done | |
| 1026 | ||
| 1027 | lemma one_step_implies_multirel: | |
| 1028 | "[| J \<noteq> 0; \<forall>k \<in> mset_of(K). \<exists>j \<in> mset_of(J). <k,j> \<in> r; | |
| 1029 | I \<in> Mult(A); J \<in> Mult(A); K \<in> Mult(A) |] | |
| 1030 | ==> <I+#K, I+#J> \<in> multirel(A, r)" | |
| 1031 | apply (subgoal_tac "multiset (J) ") | |
| 1032 | prefer 2 apply (simp add: Mult_iff_multiset) | |
| 1033 | apply (frule_tac M = J in msize_int_of_nat) | |
| 1034 | apply (auto intro: one_step_implies_multirel_lemma) | |
| 1035 | done | |
| 1036 | ||
| 1037 | (** Proving that multisets are partially ordered **) | |
| 1038 | ||
| 1039 | (*irreflexivity*) | |
| 1040 | ||
| 1041 | lemma multirel_irrefl_lemma: | |
| 46822 
95f1e700b712
 mathematical symbols for Isabelle/ZF example theories
 paulson parents: 
45602diff
changeset | 1042 | "Finite(A) ==> part_ord(A, r) \<longrightarrow> (\<forall>x \<in> A. \<exists>y \<in> A. <x,y> \<in> r) \<longrightarrow>A=0" | 
| 15201 | 1043 | apply (erule Finite_induct) | 
| 1044 | apply (auto dest: subset_consI [THEN [2] part_ord_subset]) | |
| 1045 | apply (auto simp add: part_ord_def irrefl_def) | |
| 1046 | apply (drule_tac x = xa in bspec) | |
| 1047 | apply (drule_tac [2] a = xa and b = x in trans_onD, auto) | |
| 1048 | done | |
| 1049 | ||
| 1050 | lemma irrefl_on_multirel: | |
| 1051 | "part_ord(A, r) ==> irrefl(Mult(A), multirel(A, r))" | |
| 1052 | apply (simp add: irrefl_def) | |
| 1053 | apply (subgoal_tac "trans[A](r) ") | |
| 1054 | prefer 2 apply (simp add: part_ord_def, clarify) | |
| 1055 | apply (drule multirel_implies_one_step, clarify) | |
| 1056 | apply (simp add: Mult_iff_multiset, clarify) | |
| 1057 | apply (subgoal_tac "Finite (mset_of (K))") | |
| 1058 | apply (frule_tac r = r in multirel_irrefl_lemma) | |
| 1059 | apply (frule_tac B = "mset_of (K) " in part_ord_subset) | |
| 1060 | apply simp_all | |
| 1061 | apply (auto simp add: multiset_def mset_of_def) | |
| 1062 | done | |
| 1063 | ||
| 1064 | lemma trans_on_multirel: "trans[Mult(A)](multirel(A, r))" | |
| 1065 | apply (simp add: multirel_def trans_on_def) | |
| 1066 | apply (blast intro: trancl_trans) | |
| 1067 | done | |
| 1068 | ||
| 1069 | lemma multirel_trans: | |
| 1070 | "[| <M, N> \<in> multirel(A, r); <N, K> \<in> multirel(A, r) |] ==> <M, K> \<in> multirel(A,r)" | |
| 1071 | apply (simp add: multirel_def) | |
| 1072 | apply (blast intro: trancl_trans) | |
| 1073 | done | |
| 1074 | ||
| 1075 | lemma trans_multirel: "trans(multirel(A,r))" | |
| 1076 | apply (simp add: multirel_def) | |
| 1077 | apply (rule trans_trancl) | |
| 1078 | done | |
| 1079 | ||
| 1080 | lemma part_ord_multirel: "part_ord(A,r) ==> part_ord(Mult(A), multirel(A, r))" | |
| 1081 | apply (simp (no_asm) add: part_ord_def) | |
| 1082 | apply (blast intro: irrefl_on_multirel trans_on_multirel) | |
| 1083 | done | |
| 1084 | ||
| 1085 | (** Monotonicity of multiset union **) | |
| 1086 | ||
| 1087 | lemma munion_multirel1_mono: | |
| 1088 | "[|<M,N> \<in> multirel1(A, r); K \<in> Mult(A) |] ==> <K +# M, K +# N> \<in> multirel1(A, r)" | |
| 1089 | apply (frule multirel1_type [THEN subsetD]) | |
| 1090 | apply (auto simp add: multirel1_iff Mult_iff_multiset) | |
| 1091 | apply (rule_tac x = a in exI) | |
| 1092 | apply (simp (no_asm_simp)) | |
| 1093 | apply (rule_tac x = "K+#M0" in exI) | |
| 1094 | apply (simp (no_asm_simp) add: Un_subset_iff) | |
| 1095 | apply (rule_tac x = Ka in exI) | |
| 1096 | apply (simp (no_asm_simp) add: munion_assoc) | |
| 1097 | done | |
| 1098 | ||
| 1099 | lemma munion_multirel_mono2: | |
| 1100 | "[| <M, N> \<in> multirel(A, r); K \<in> Mult(A) |]==><K +# M, K +# N> \<in> multirel(A, r)" | |
| 1101 | apply (frule multirel_type [THEN subsetD]) | |
| 1102 | apply (simp (no_asm_use) add: multirel_def) | |
| 1103 | apply clarify | |
| 1104 | apply (drule_tac psi = "<M,N> \<in> multirel1 (A, r) ^+" in asm_rl) | |
| 1105 | apply (erule rev_mp) | |
| 1106 | apply (erule rev_mp) | |
| 1107 | apply (erule rev_mp) | |
| 1108 | apply (erule trancl_induct, clarify) | |
| 1109 | apply (blast intro: munion_multirel1_mono r_into_trancl, clarify) | |
| 15481 | 1110 | apply (subgoal_tac "y \<in> Mult(A) ") | 
| 15201 | 1111 | prefer 2 | 
| 1112 | apply (blast dest: multirel_type [unfolded multirel_def, THEN subsetD]) | |
| 1113 | apply (subgoal_tac "<K +# y, K +# z> \<in> multirel1 (A, r) ") | |
| 1114 | prefer 2 apply (blast intro: munion_multirel1_mono) | |
| 1115 | apply (blast intro: r_into_trancl trancl_trans) | |
| 1116 | done | |
| 1117 | ||
| 1118 | lemma munion_multirel_mono1: | |
| 1119 | "[|<M, N> \<in> multirel(A, r); K \<in> Mult(A)|] ==> <M +# K, N +# K> \<in> multirel(A, r)" | |
| 1120 | apply (frule multirel_type [THEN subsetD]) | |
| 15481 | 1121 | apply (rule_tac P = "%x. <x,?u> \<in> multirel(A, r) " in munion_commute [THEN subst]) | 
| 1122 | apply (subst munion_commute [of N]) | |
| 15201 | 1123 | apply (rule munion_multirel_mono2) | 
| 1124 | apply (auto simp add: Mult_iff_multiset) | |
| 1125 | done | |
| 1126 | ||
| 1127 | lemma munion_multirel_mono: | |
| 1128 | "[|<M,K> \<in> multirel(A, r); <N,L> \<in> multirel(A, r)|] | |
| 1129 | ==> <M +# N, K +# L> \<in> multirel(A, r)" | |
| 15481 | 1130 | apply (subgoal_tac "M \<in> Mult(A) & N \<in> Mult(A) & K \<in> Mult(A) & L \<in> Mult(A) ") | 
| 15201 | 1131 | prefer 2 apply (blast dest: multirel_type [THEN subsetD]) | 
| 1132 | apply (blast intro: munion_multirel_mono1 multirel_trans munion_multirel_mono2) | |
| 1133 | done | |
| 1134 | ||
| 1135 | ||
| 1136 | subsection{*Ordinal Multisets*}
 | |
| 1137 | ||
| 1138 | (* A \<subseteq> B ==> field(Memrel(A)) \<subseteq> field(Memrel(B)) *) | |
| 45602 | 1139 | lemmas field_Memrel_mono = Memrel_mono [THEN field_mono] | 
| 15201 | 1140 | |
| 1141 | (* | |
| 1142 | [| Aa \<subseteq> Ba; A \<subseteq> B |] ==> | |
| 1143 | multirel(field(Memrel(Aa)), Memrel(A))\<subseteq> multirel(field(Memrel(Ba)), Memrel(B)) | |
| 1144 | *) | |
| 1145 | ||
| 1146 | lemmas multirel_Memrel_mono = multirel_mono [OF field_Memrel_mono Memrel_mono] | |
| 1147 | ||
| 1148 | lemma omultiset_is_multiset [simp]: "omultiset(M) ==> multiset(M)" | |
| 1149 | apply (simp add: omultiset_def) | |
| 1150 | apply (auto simp add: Mult_iff_multiset) | |
| 1151 | done | |
| 1152 | ||
| 1153 | lemma munion_omultiset [simp]: "[| omultiset(M); omultiset(N) |] ==> omultiset(M +# N)" | |
| 1154 | apply (simp add: omultiset_def, clarify) | |
| 46822 
95f1e700b712
 mathematical symbols for Isabelle/ZF example theories
 paulson parents: 
45602diff
changeset | 1155 | apply (rule_tac x = "i \<union> ia" in exI) | 
| 15201 | 1156 | apply (simp add: Mult_iff_multiset Ord_Un Un_subset_iff) | 
| 1157 | apply (blast intro: field_Memrel_mono) | |
| 1158 | done | |
| 1159 | ||
| 1160 | lemma mdiff_omultiset [simp]: "omultiset(M) ==> omultiset(M -# N)" | |
| 1161 | apply (simp add: omultiset_def, clarify) | |
| 1162 | apply (simp add: Mult_iff_multiset) | |
| 1163 | apply (rule_tac x = i in exI) | |
| 1164 | apply (simp (no_asm_simp)) | |
| 1165 | done | |
| 1166 | ||
| 1167 | (** Proving that Memrel is a partial order **) | |
| 1168 | ||
| 1169 | lemma irrefl_Memrel: "Ord(i) ==> irrefl(field(Memrel(i)), Memrel(i))" | |
| 1170 | apply (rule irreflI, clarify) | |
| 1171 | apply (subgoal_tac "Ord (x) ") | |
| 1172 | prefer 2 apply (blast intro: Ord_in_Ord) | |
| 1173 | apply (drule_tac i = x in ltI [THEN lt_irrefl], auto) | |
| 1174 | done | |
| 1175 | ||
| 46822 
95f1e700b712
 mathematical symbols for Isabelle/ZF example theories
 paulson parents: 
45602diff
changeset | 1176 | lemma trans_iff_trans_on: "trans(r) \<longleftrightarrow> trans[field(r)](r)" | 
| 15201 | 1177 | by (simp add: trans_on_def trans_def, auto) | 
| 1178 | ||
| 1179 | lemma part_ord_Memrel: "Ord(i) ==>part_ord(field(Memrel(i)), Memrel(i))" | |
| 1180 | apply (simp add: part_ord_def) | |
| 1181 | apply (simp (no_asm) add: trans_iff_trans_on [THEN iff_sym]) | |
| 1182 | apply (blast intro: trans_Memrel irrefl_Memrel) | |
| 1183 | done | |
| 1184 | ||
| 1185 | (* | |
| 1186 | Ord(i) ==> | |
| 1187 |   part_ord(field(Memrel(i))-||>nat-{0}, multirel(field(Memrel(i)), Memrel(i)))
 | |
| 1188 | *) | |
| 1189 | ||
| 45602 | 1190 | lemmas part_ord_mless = part_ord_Memrel [THEN part_ord_multirel] | 
| 15201 | 1191 | |
| 1192 | (*irreflexivity*) | |
| 1193 | ||
| 1194 | lemma mless_not_refl: "~(M <# M)" | |
| 1195 | apply (simp add: mless_def, clarify) | |
| 1196 | apply (frule multirel_type [THEN subsetD]) | |
| 1197 | apply (drule part_ord_mless) | |
| 1198 | apply (simp add: part_ord_def irrefl_def) | |
| 1199 | done | |
| 1200 | ||
| 1201 | (* N<N ==> R *) | |
| 45602 | 1202 | lemmas mless_irrefl = mless_not_refl [THEN notE, elim!] | 
| 15201 | 1203 | |
| 1204 | (*transitivity*) | |
| 1205 | lemma mless_trans: "[| K <# M; M <# N |] ==> K <# N" | |
| 1206 | apply (simp add: mless_def, clarify) | |
| 46822 
95f1e700b712
 mathematical symbols for Isabelle/ZF example theories
 paulson parents: 
45602diff
changeset | 1207 | apply (rule_tac x = "i \<union> ia" in exI) | 
| 15201 | 1208 | apply (blast dest: multirel_Memrel_mono [OF Un_upper1 Un_upper1, THEN subsetD] | 
| 1209 | multirel_Memrel_mono [OF Un_upper2 Un_upper2, THEN subsetD] | |
| 1210 | intro: multirel_trans Ord_Un) | |
| 1211 | done | |
| 1212 | ||
| 1213 | (*asymmetry*) | |
| 1214 | lemma mless_not_sym: "M <# N ==> ~ N <# M" | |
| 1215 | apply clarify | |
| 1216 | apply (rule mless_not_refl [THEN notE]) | |
| 1217 | apply (erule mless_trans, assumption) | |
| 1218 | done | |
| 1219 | ||
| 1220 | lemma mless_asym: "[| M <# N; ~P ==> N <# M |] ==> P" | |
| 1221 | by (blast dest: mless_not_sym) | |
| 1222 | ||
| 1223 | lemma mle_refl [simp]: "omultiset(M) ==> M <#= M" | |
| 1224 | by (simp add: mle_def) | |
| 1225 | ||
| 1226 | (*anti-symmetry*) | |
| 1227 | lemma mle_antisym: | |
| 1228 | "[| M <#= N; N <#= M |] ==> M = N" | |
| 1229 | apply (simp add: mle_def) | |
| 1230 | apply (blast dest: mless_not_sym) | |
| 1231 | done | |
| 1232 | ||
| 1233 | (*transitivity*) | |
| 1234 | lemma mle_trans: "[| K <#= M; M <#= N |] ==> K <#= N" | |
| 1235 | apply (simp add: mle_def) | |
| 1236 | apply (blast intro: mless_trans) | |
| 1237 | done | |
| 1238 | ||
| 46822 
95f1e700b712
 mathematical symbols for Isabelle/ZF example theories
 paulson parents: 
45602diff
changeset | 1239 | lemma mless_le_iff: "M <# N \<longleftrightarrow> (M <#= N & M \<noteq> N)" | 
| 15201 | 1240 | by (simp add: mle_def, auto) | 
| 1241 | ||
| 1242 | (** Monotonicity of mless **) | |
| 1243 | ||
| 1244 | lemma munion_less_mono2: "[| M <# N; omultiset(K) |] ==> K +# M <# K +# N" | |
| 1245 | apply (simp add: mless_def omultiset_def, clarify) | |
| 46822 
95f1e700b712
 mathematical symbols for Isabelle/ZF example theories
 paulson parents: 
45602diff
changeset | 1246 | apply (rule_tac x = "i \<union> ia" in exI) | 
| 15201 | 1247 | apply (simp add: Mult_iff_multiset Ord_Un Un_subset_iff) | 
| 1248 | apply (rule munion_multirel_mono2) | |
| 1249 | apply (blast intro: multirel_Memrel_mono [THEN subsetD]) | |
| 1250 | apply (simp add: Mult_iff_multiset) | |
| 1251 | apply (blast intro: field_Memrel_mono [THEN subsetD]) | |
| 1252 | done | |
| 1253 | ||
| 1254 | lemma munion_less_mono1: "[| M <# N; omultiset(K) |] ==> M +# K <# N +# K" | |
| 1255 | by (force dest: munion_less_mono2 simp add: munion_commute) | |
| 1256 | ||
| 1257 | lemma mless_imp_omultiset: "M <# N ==> omultiset(M) & omultiset(N)" | |
| 1258 | by (auto simp add: mless_def omultiset_def dest: multirel_type [THEN subsetD]) | |
| 1259 | ||
| 1260 | lemma munion_less_mono: "[| M <# K; N <# L |] ==> M +# N <# K +# L" | |
| 1261 | apply (frule_tac M = M in mless_imp_omultiset) | |
| 1262 | apply (frule_tac M = N in mless_imp_omultiset) | |
| 1263 | apply (blast intro: munion_less_mono1 munion_less_mono2 mless_trans) | |
| 1264 | done | |
| 1265 | ||
| 1266 | (* <#= *) | |
| 1267 | ||
| 1268 | lemma mle_imp_omultiset: "M <#= N ==> omultiset(M) & omultiset(N)" | |
| 1269 | by (auto simp add: mle_def mless_imp_omultiset) | |
| 1270 | ||
| 1271 | lemma mle_mono: "[| M <#= K; N <#= L |] ==> M +# N <#= K +# L" | |
| 1272 | apply (frule_tac M = M in mle_imp_omultiset) | |
| 1273 | apply (frule_tac M = N in mle_imp_omultiset) | |
| 1274 | apply (auto simp add: mle_def intro: munion_less_mono1 munion_less_mono2 munion_less_mono) | |
| 1275 | done | |
| 1276 | ||
| 1277 | lemma omultiset_0 [iff]: "omultiset(0)" | |
| 1278 | by (auto simp add: omultiset_def Mult_iff_multiset) | |
| 1279 | ||
| 1280 | lemma empty_leI [simp]: "omultiset(M) ==> 0 <#= M" | |
| 1281 | apply (simp add: mle_def mless_def) | |
| 15481 | 1282 | apply (subgoal_tac "\<exists>i. Ord (i) & M \<in> Mult(field(Memrel(i))) ") | 
| 15201 | 1283 | prefer 2 apply (simp add: omultiset_def) | 
| 1284 | apply (case_tac "M=0", simp_all, clarify) | |
| 15481 | 1285 | apply (subgoal_tac "<0 +# 0, 0 +# M> \<in> multirel(field (Memrel(i)), Memrel(i))") | 
| 15201 | 1286 | apply (rule_tac [2] one_step_implies_multirel) | 
| 1287 | apply (auto simp add: Mult_iff_multiset) | |
| 1288 | done | |
| 1289 | ||
| 1290 | lemma munion_upper1: "[| omultiset(M); omultiset(N) |] ==> M <#= M +# N" | |
| 1291 | apply (subgoal_tac "M +# 0 <#= M +# N") | |
| 1292 | apply (rule_tac [2] mle_mono, auto) | |
| 1293 | done | |
| 1294 | ||
| 12089 
34e7693271a9
Sidi Ehmety's port of the fold_set operator and multisets to ZF.
 paulson parents: diff
changeset | 1295 | end |