author | paulson |
Thu, 22 Jul 2004 10:33:26 +0200 | |
changeset 15072 | 4861bf6af0b4 |
parent 14981 | e73f8140af78 |
child 15131 | c69542757a4d |
permissions | -rw-r--r-- |
10249 | 1 |
(* Title: HOL/Library/Multiset.thy |
2 |
ID: $Id$ |
|
15072 | 3 |
Author: Tobias Nipkow, Markus Wenzel, Lawrence C Paulson, Norbert Voelker |
10249 | 4 |
*) |
5 |
||
14706 | 6 |
header {* Multisets *} |
10249 | 7 |
|
8 |
theory Multiset = Accessible_Part: |
|
9 |
||
10 |
subsection {* The type of multisets *} |
|
11 |
||
12 |
typedef 'a multiset = "{f::'a => nat. finite {x . 0 < f x}}" |
|
13 |
proof |
|
11464 | 14 |
show "(\<lambda>x. 0::nat) \<in> ?multiset" by simp |
10249 | 15 |
qed |
16 |
||
17 |
lemmas multiset_typedef [simp] = |
|
10277 | 18 |
Abs_multiset_inverse Rep_multiset_inverse Rep_multiset |
19 |
and [simp] = Rep_multiset_inject [symmetric] |
|
10249 | 20 |
|
21 |
constdefs |
|
22 |
Mempty :: "'a multiset" ("{#}") |
|
11464 | 23 |
"{#} == Abs_multiset (\<lambda>a. 0)" |
10249 | 24 |
|
25 |
single :: "'a => 'a multiset" ("{#_#}") |
|
11701
3d51fbf81c17
sane numerals (stage 1): added generic 1, removed 1' and 2 on nat,
wenzelm
parents:
11655
diff
changeset
|
26 |
"{#a#} == Abs_multiset (\<lambda>b. if b = a then 1 else 0)" |
10249 | 27 |
|
28 |
count :: "'a multiset => 'a => nat" |
|
29 |
"count == Rep_multiset" |
|
30 |
||
31 |
MCollect :: "'a multiset => ('a => bool) => 'a multiset" |
|
11464 | 32 |
"MCollect M P == Abs_multiset (\<lambda>x. if P x then Rep_multiset M x else 0)" |
10249 | 33 |
|
34 |
syntax |
|
35 |
"_Melem" :: "'a => 'a multiset => bool" ("(_/ :# _)" [50, 51] 50) |
|
36 |
"_MCollect" :: "pttrn => 'a multiset => bool => 'a multiset" ("(1{# _ : _./ _#})") |
|
37 |
translations |
|
38 |
"a :# M" == "0 < count M a" |
|
11464 | 39 |
"{#x:M. P#}" == "MCollect M (\<lambda>x. P)" |
10249 | 40 |
|
41 |
constdefs |
|
42 |
set_of :: "'a multiset => 'a set" |
|
43 |
"set_of M == {x. x :# M}" |
|
44 |
||
14691 | 45 |
instance multiset :: (type) "{plus, minus, zero}" .. |
10249 | 46 |
|
47 |
defs (overloaded) |
|
11464 | 48 |
union_def: "M + N == Abs_multiset (\<lambda>a. Rep_multiset M a + Rep_multiset N a)" |
49 |
diff_def: "M - N == Abs_multiset (\<lambda>a. Rep_multiset M a - Rep_multiset N a)" |
|
11701
3d51fbf81c17
sane numerals (stage 1): added generic 1, removed 1' and 2 on nat,
wenzelm
parents:
11655
diff
changeset
|
50 |
Zero_multiset_def [simp]: "0 == {#}" |
10249 | 51 |
size_def: "size M == setsum (count M) (set_of M)" |
52 |
||
53 |
||
54 |
text {* |
|
55 |
\medskip Preservation of the representing set @{term multiset}. |
|
56 |
*} |
|
57 |
||
11464 | 58 |
lemma const0_in_multiset [simp]: "(\<lambda>a. 0) \<in> multiset" |
15072 | 59 |
by (simp add: multiset_def) |
10249 | 60 |
|
11701
3d51fbf81c17
sane numerals (stage 1): added generic 1, removed 1' and 2 on nat,
wenzelm
parents:
11655
diff
changeset
|
61 |
lemma only1_in_multiset [simp]: "(\<lambda>b. if b = a then 1 else 0) \<in> multiset" |
15072 | 62 |
by (simp add: multiset_def) |
10249 | 63 |
|
64 |
lemma union_preserves_multiset [simp]: |
|
11464 | 65 |
"M \<in> multiset ==> N \<in> multiset ==> (\<lambda>a. M a + N a) \<in> multiset" |
15072 | 66 |
apply (unfold multiset_def, simp) |
67 |
apply (drule finite_UnI, assumption) |
|
10249 | 68 |
apply (simp del: finite_Un add: Un_def) |
69 |
done |
|
70 |
||
71 |
lemma diff_preserves_multiset [simp]: |
|
11464 | 72 |
"M \<in> multiset ==> (\<lambda>a. M a - N a) \<in> multiset" |
15072 | 73 |
apply (unfold multiset_def, simp) |
10249 | 74 |
apply (rule finite_subset) |
75 |
prefer 2 |
|
76 |
apply assumption |
|
77 |
apply auto |
|
78 |
done |
|
79 |
||
80 |
||
81 |
subsection {* Algebraic properties of multisets *} |
|
82 |
||
83 |
subsubsection {* Union *} |
|
84 |
||
11464 | 85 |
theorem union_empty [simp]: "M + {#} = M \<and> {#} + M = M" |
15072 | 86 |
by (simp add: union_def Mempty_def) |
10249 | 87 |
|
88 |
theorem union_commute: "M + N = N + (M::'a multiset)" |
|
15072 | 89 |
by (simp add: union_def add_ac) |
10249 | 90 |
|
91 |
theorem union_assoc: "(M + N) + K = M + (N + (K::'a multiset))" |
|
15072 | 92 |
by (simp add: union_def add_ac) |
10249 | 93 |
|
94 |
theorem union_lcomm: "M + (N + K) = N + (M + (K::'a multiset))" |
|
95 |
apply (rule union_commute [THEN trans]) |
|
96 |
apply (rule union_assoc [THEN trans]) |
|
97 |
apply (rule union_commute [THEN arg_cong]) |
|
98 |
done |
|
99 |
||
100 |
theorems union_ac = union_assoc union_commute union_lcomm |
|
101 |
||
14738 | 102 |
instance multiset :: (type) comm_monoid_add |
14722
8e739a6eaf11
replaced apply-style proof for instance Multiset :: plus_ac0 by recommended Isar proof style
obua
parents:
14706
diff
changeset
|
103 |
proof |
8e739a6eaf11
replaced apply-style proof for instance Multiset :: plus_ac0 by recommended Isar proof style
obua
parents:
14706
diff
changeset
|
104 |
fix a b c :: "'a multiset" |
8e739a6eaf11
replaced apply-style proof for instance Multiset :: plus_ac0 by recommended Isar proof style
obua
parents:
14706
diff
changeset
|
105 |
show "(a + b) + c = a + (b + c)" by (rule union_assoc) |
8e739a6eaf11
replaced apply-style proof for instance Multiset :: plus_ac0 by recommended Isar proof style
obua
parents:
14706
diff
changeset
|
106 |
show "a + b = b + a" by (rule union_commute) |
8e739a6eaf11
replaced apply-style proof for instance Multiset :: plus_ac0 by recommended Isar proof style
obua
parents:
14706
diff
changeset
|
107 |
show "0 + a = a" by simp |
8e739a6eaf11
replaced apply-style proof for instance Multiset :: plus_ac0 by recommended Isar proof style
obua
parents:
14706
diff
changeset
|
108 |
qed |
10277 | 109 |
|
10249 | 110 |
|
111 |
subsubsection {* Difference *} |
|
112 |
||
11464 | 113 |
theorem diff_empty [simp]: "M - {#} = M \<and> {#} - M = {#}" |
15072 | 114 |
by (simp add: Mempty_def diff_def) |
10249 | 115 |
|
116 |
theorem diff_union_inverse2 [simp]: "M + {#a#} - {#a#} = M" |
|
15072 | 117 |
by (simp add: union_def diff_def) |
10249 | 118 |
|
119 |
||
120 |
subsubsection {* Count of elements *} |
|
121 |
||
122 |
theorem count_empty [simp]: "count {#} a = 0" |
|
15072 | 123 |
by (simp add: count_def Mempty_def) |
10249 | 124 |
|
11701
3d51fbf81c17
sane numerals (stage 1): added generic 1, removed 1' and 2 on nat,
wenzelm
parents:
11655
diff
changeset
|
125 |
theorem count_single [simp]: "count {#b#} a = (if b = a then 1 else 0)" |
15072 | 126 |
by (simp add: count_def single_def) |
10249 | 127 |
|
128 |
theorem count_union [simp]: "count (M + N) a = count M a + count N a" |
|
15072 | 129 |
by (simp add: count_def union_def) |
10249 | 130 |
|
131 |
theorem count_diff [simp]: "count (M - N) a = count M a - count N a" |
|
15072 | 132 |
by (simp add: count_def diff_def) |
10249 | 133 |
|
134 |
||
135 |
subsubsection {* Set of elements *} |
|
136 |
||
137 |
theorem set_of_empty [simp]: "set_of {#} = {}" |
|
15072 | 138 |
by (simp add: set_of_def) |
10249 | 139 |
|
140 |
theorem set_of_single [simp]: "set_of {#b#} = {b}" |
|
15072 | 141 |
by (simp add: set_of_def) |
10249 | 142 |
|
11464 | 143 |
theorem set_of_union [simp]: "set_of (M + N) = set_of M \<union> set_of N" |
15072 | 144 |
by (auto simp add: set_of_def) |
10249 | 145 |
|
146 |
theorem set_of_eq_empty_iff [simp]: "(set_of M = {}) = (M = {#})" |
|
15072 | 147 |
by (auto simp add: set_of_def Mempty_def count_def expand_fun_eq) |
10249 | 148 |
|
11464 | 149 |
theorem mem_set_of_iff [simp]: "(x \<in> set_of M) = (x :# M)" |
15072 | 150 |
by (auto simp add: set_of_def) |
10249 | 151 |
|
152 |
||
153 |
subsubsection {* Size *} |
|
154 |
||
155 |
theorem size_empty [simp]: "size {#} = 0" |
|
15072 | 156 |
by (simp add: size_def) |
10249 | 157 |
|
158 |
theorem size_single [simp]: "size {#b#} = 1" |
|
15072 | 159 |
by (simp add: size_def) |
10249 | 160 |
|
161 |
theorem finite_set_of [iff]: "finite (set_of M)" |
|
162 |
apply (cut_tac x = M in Rep_multiset) |
|
163 |
apply (simp add: multiset_def set_of_def count_def) |
|
164 |
done |
|
165 |
||
166 |
theorem setsum_count_Int: |
|
11464 | 167 |
"finite A ==> setsum (count N) (A \<inter> set_of N) = setsum (count N) A" |
15072 | 168 |
apply (erule finite_induct, simp) |
10249 | 169 |
apply (simp add: Int_insert_left set_of_def) |
170 |
done |
|
171 |
||
172 |
theorem size_union [simp]: "size (M + N::'a multiset) = size M + size N" |
|
173 |
apply (unfold size_def) |
|
11464 | 174 |
apply (subgoal_tac "count (M + N) = (\<lambda>a. count M a + count N a)") |
10249 | 175 |
prefer 2 |
15072 | 176 |
apply (rule ext, simp) |
10249 | 177 |
apply (simp (no_asm_simp) add: setsum_Un setsum_addf setsum_count_Int) |
178 |
apply (subst Int_commute) |
|
179 |
apply (simp (no_asm_simp) add: setsum_count_Int) |
|
180 |
done |
|
181 |
||
182 |
theorem size_eq_0_iff_empty [iff]: "(size M = 0) = (M = {#})" |
|
15072 | 183 |
apply (unfold size_def Mempty_def count_def, auto) |
10249 | 184 |
apply (simp add: set_of_def count_def expand_fun_eq) |
185 |
done |
|
186 |
||
11464 | 187 |
theorem size_eq_Suc_imp_elem: "size M = Suc n ==> \<exists>a. a :# M" |
10249 | 188 |
apply (unfold size_def) |
15072 | 189 |
apply (drule setsum_SucD, auto) |
10249 | 190 |
done |
191 |
||
192 |
||
193 |
subsubsection {* Equality of multisets *} |
|
194 |
||
11464 | 195 |
theorem multiset_eq_conv_count_eq: "(M = N) = (\<forall>a. count M a = count N a)" |
15072 | 196 |
by (simp add: count_def expand_fun_eq) |
10249 | 197 |
|
11464 | 198 |
theorem single_not_empty [simp]: "{#a#} \<noteq> {#} \<and> {#} \<noteq> {#a#}" |
15072 | 199 |
by (simp add: single_def Mempty_def expand_fun_eq) |
10249 | 200 |
|
201 |
theorem single_eq_single [simp]: "({#a#} = {#b#}) = (a = b)" |
|
15072 | 202 |
by (auto simp add: single_def expand_fun_eq) |
10249 | 203 |
|
11464 | 204 |
theorem union_eq_empty [iff]: "(M + N = {#}) = (M = {#} \<and> N = {#})" |
15072 | 205 |
by (auto simp add: union_def Mempty_def expand_fun_eq) |
10249 | 206 |
|
11464 | 207 |
theorem empty_eq_union [iff]: "({#} = M + N) = (M = {#} \<and> N = {#})" |
15072 | 208 |
by (auto simp add: union_def Mempty_def expand_fun_eq) |
10249 | 209 |
|
210 |
theorem union_right_cancel [simp]: "(M + K = N + K) = (M = (N::'a multiset))" |
|
15072 | 211 |
by (simp add: union_def expand_fun_eq) |
10249 | 212 |
|
213 |
theorem union_left_cancel [simp]: "(K + M = K + N) = (M = (N::'a multiset))" |
|
15072 | 214 |
by (simp add: union_def expand_fun_eq) |
10249 | 215 |
|
216 |
theorem union_is_single: |
|
11464 | 217 |
"(M + N = {#a#}) = (M = {#a#} \<and> N={#} \<or> M = {#} \<and> N = {#a#})" |
15072 | 218 |
apply (simp add: Mempty_def single_def union_def add_is_1 expand_fun_eq) |
10249 | 219 |
apply blast |
220 |
done |
|
221 |
||
222 |
theorem single_is_union: |
|
15072 | 223 |
"({#a#} = M + N) = ({#a#} = M \<and> N = {#} \<or> M = {#} \<and> {#a#} = N)" |
10249 | 224 |
apply (unfold Mempty_def single_def union_def) |
11464 | 225 |
apply (simp add: add_is_1 one_is_add expand_fun_eq) |
10249 | 226 |
apply (blast dest: sym) |
227 |
done |
|
228 |
||
229 |
theorem add_eq_conv_diff: |
|
230 |
"(M + {#a#} = N + {#b#}) = |
|
15072 | 231 |
(M = N \<and> a = b \<or> M = N - {#a#} + {#b#} \<and> N = M - {#b#} + {#a#})" |
10249 | 232 |
apply (unfold single_def union_def diff_def) |
233 |
apply (simp (no_asm) add: expand_fun_eq) |
|
15072 | 234 |
apply (rule conjI, force, safe, simp_all) |
13601 | 235 |
apply (simp add: eq_sym_conv) |
10249 | 236 |
done |
237 |
||
238 |
(* |
|
239 |
val prems = Goal |
|
240 |
"[| !!F. [| finite F; !G. G < F --> P G |] ==> P F |] ==> finite F --> P F"; |
|
11464 | 241 |
by (res_inst_tac [("a","F"),("f","\<lambda>A. if finite A then card A else 0")] |
10249 | 242 |
measure_induct 1); |
15072 | 243 |
by (Clarify_tac 1) |
244 |
by (resolve_tac prems 1) |
|
245 |
by (assume_tac 1) |
|
246 |
by (Clarify_tac 1) |
|
247 |
by (subgoal_tac "finite G" 1) |
|
10249 | 248 |
by (fast_tac (claset() addDs [finite_subset,order_less_le RS iffD1]) 2); |
15072 | 249 |
by (etac allE 1) |
250 |
by (etac impE 1) |
|
251 |
by (Blast_tac 2) |
|
10249 | 252 |
by (asm_simp_tac (simpset() addsimps [psubset_card]) 1); |
253 |
no_qed(); |
|
254 |
val lemma = result(); |
|
255 |
||
256 |
val prems = Goal |
|
257 |
"[| finite F; !!F. [| finite F; !G. G < F --> P G |] ==> P F |] ==> P F"; |
|
258 |
by (rtac (lemma RS mp) 1); |
|
259 |
by (REPEAT(ares_tac prems 1)); |
|
260 |
qed "finite_psubset_induct"; |
|
261 |
||
262 |
Better: use wf_finite_psubset in WF_Rel |
|
263 |
*) |
|
264 |
||
265 |
||
266 |
subsection {* Induction over multisets *} |
|
267 |
||
268 |
lemma setsum_decr: |
|
11701
3d51fbf81c17
sane numerals (stage 1): added generic 1, removed 1' and 2 on nat,
wenzelm
parents:
11655
diff
changeset
|
269 |
"finite F ==> (0::nat) < f a ==> |
15072 | 270 |
setsum (f (a := f a - 1)) F = (if a\<in>F then setsum f F - 1 else setsum f F)" |
271 |
apply (erule finite_induct, auto) |
|
272 |
apply (drule_tac a = a in mk_disjoint_insert, auto) |
|
10249 | 273 |
done |
274 |
||
10313 | 275 |
lemma rep_multiset_induct_aux: |
11701
3d51fbf81c17
sane numerals (stage 1): added generic 1, removed 1' and 2 on nat,
wenzelm
parents:
11655
diff
changeset
|
276 |
"P (\<lambda>a. (0::nat)) ==> (!!f b. f \<in> multiset ==> P f ==> P (f (b := f b + 1))) |
11464 | 277 |
==> \<forall>f. f \<in> multiset --> setsum f {x. 0 < f x} = n --> P f" |
10249 | 278 |
proof - |
11549 | 279 |
case rule_context |
280 |
note premises = this [unfolded multiset_def] |
|
10249 | 281 |
show ?thesis |
282 |
apply (unfold multiset_def) |
|
15072 | 283 |
apply (induct_tac n, simp, clarify) |
11464 | 284 |
apply (subgoal_tac "f = (\<lambda>a.0)") |
10249 | 285 |
apply simp |
11549 | 286 |
apply (rule premises) |
15072 | 287 |
apply (rule ext, force, clarify) |
288 |
apply (frule setsum_SucD, clarify) |
|
10249 | 289 |
apply (rename_tac a) |
11701
3d51fbf81c17
sane numerals (stage 1): added generic 1, removed 1' and 2 on nat,
wenzelm
parents:
11655
diff
changeset
|
290 |
apply (subgoal_tac "finite {x. 0 < (f (a := f a - 1)) x}") |
10249 | 291 |
prefer 2 |
292 |
apply (rule finite_subset) |
|
293 |
prefer 2 |
|
294 |
apply assumption |
|
295 |
apply simp |
|
296 |
apply blast |
|
11701
3d51fbf81c17
sane numerals (stage 1): added generic 1, removed 1' and 2 on nat,
wenzelm
parents:
11655
diff
changeset
|
297 |
apply (subgoal_tac "f = (f (a := f a - 1))(a := (f (a := f a - 1)) a + 1)") |
10249 | 298 |
prefer 2 |
299 |
apply (rule ext) |
|
300 |
apply (simp (no_asm_simp)) |
|
15072 | 301 |
apply (erule ssubst, rule premises, blast) |
302 |
apply (erule allE, erule impE, erule_tac [2] mp, blast) |
|
11701
3d51fbf81c17
sane numerals (stage 1): added generic 1, removed 1' and 2 on nat,
wenzelm
parents:
11655
diff
changeset
|
303 |
apply (simp (no_asm_simp) add: setsum_decr del: fun_upd_apply One_nat_def) |
11464 | 304 |
apply (subgoal_tac "{x. x \<noteq> a --> 0 < f x} = {x. 0 < f x}") |
10249 | 305 |
prefer 2 |
306 |
apply blast |
|
11464 | 307 |
apply (subgoal_tac "{x. x \<noteq> a \<and> 0 < f x} = {x. 0 < f x} - {a}") |
10249 | 308 |
prefer 2 |
309 |
apply blast |
|
310 |
apply (simp add: le_imp_diff_is_add setsum_diff1 cong: conj_cong) |
|
311 |
done |
|
312 |
qed |
|
313 |
||
10313 | 314 |
theorem rep_multiset_induct: |
11464 | 315 |
"f \<in> multiset ==> P (\<lambda>a. 0) ==> |
11701
3d51fbf81c17
sane numerals (stage 1): added generic 1, removed 1' and 2 on nat,
wenzelm
parents:
11655
diff
changeset
|
316 |
(!!f b. f \<in> multiset ==> P f ==> P (f (b := f b + 1))) ==> P f" |
15072 | 317 |
by (insert rep_multiset_induct_aux, blast) |
10249 | 318 |
|
319 |
theorem multiset_induct [induct type: multiset]: |
|
320 |
"P {#} ==> (!!M x. P M ==> P (M + {#x#})) ==> P M" |
|
321 |
proof - |
|
322 |
note defns = union_def single_def Mempty_def |
|
323 |
assume prem1 [unfolded defns]: "P {#}" |
|
324 |
assume prem2 [unfolded defns]: "!!M x. P M ==> P (M + {#x#})" |
|
325 |
show ?thesis |
|
326 |
apply (rule Rep_multiset_inverse [THEN subst]) |
|
10313 | 327 |
apply (rule Rep_multiset [THEN rep_multiset_induct]) |
10249 | 328 |
apply (rule prem1) |
15072 | 329 |
apply (subgoal_tac "f(b := f b + 1) = (\<lambda>a. f a + (if a=b then 1 else 0))") |
10249 | 330 |
prefer 2 |
331 |
apply (simp add: expand_fun_eq) |
|
332 |
apply (erule ssubst) |
|
333 |
apply (erule Abs_multiset_inverse [THEN subst]) |
|
334 |
apply (erule prem2 [simplified]) |
|
335 |
done |
|
336 |
qed |
|
337 |
||
338 |
||
339 |
lemma MCollect_preserves_multiset: |
|
11464 | 340 |
"M \<in> multiset ==> (\<lambda>x. if P x then M x else 0) \<in> multiset" |
10249 | 341 |
apply (simp add: multiset_def) |
15072 | 342 |
apply (rule finite_subset, auto) |
10249 | 343 |
done |
344 |
||
345 |
theorem count_MCollect [simp]: |
|
346 |
"count {# x:M. P x #} a = (if P a then count M a else 0)" |
|
15072 | 347 |
by (simp add: count_def MCollect_def MCollect_preserves_multiset) |
10249 | 348 |
|
11464 | 349 |
theorem set_of_MCollect [simp]: "set_of {# x:M. P x #} = set_of M \<inter> {x. P x}" |
15072 | 350 |
by (auto simp add: set_of_def) |
10249 | 351 |
|
11464 | 352 |
theorem multiset_partition: "M = {# x:M. P x #} + {# x:M. \<not> P x #}" |
15072 | 353 |
by (subst multiset_eq_conv_count_eq, auto) |
10249 | 354 |
|
10277 | 355 |
declare Rep_multiset_inject [symmetric, simp del] |
10249 | 356 |
declare multiset_typedef [simp del] |
357 |
||
358 |
theorem add_eq_conv_ex: |
|
15072 | 359 |
"(M + {#a#} = N + {#b#}) = |
360 |
(M = N \<and> a = b \<or> (\<exists>K. M = K + {#b#} \<and> N = K + {#a#}))" |
|
361 |
by (auto simp add: add_eq_conv_diff) |
|
10249 | 362 |
|
363 |
||
364 |
subsection {* Multiset orderings *} |
|
365 |
||
366 |
subsubsection {* Well-foundedness *} |
|
367 |
||
368 |
constdefs |
|
11464 | 369 |
mult1 :: "('a \<times> 'a) set => ('a multiset \<times> 'a multiset) set" |
10249 | 370 |
"mult1 r == |
11464 | 371 |
{(N, M). \<exists>a M0 K. M = M0 + {#a#} \<and> N = M0 + K \<and> |
372 |
(\<forall>b. b :# K --> (b, a) \<in> r)}" |
|
10249 | 373 |
|
11464 | 374 |
mult :: "('a \<times> 'a) set => ('a multiset \<times> 'a multiset) set" |
10392 | 375 |
"mult r == (mult1 r)\<^sup>+" |
10249 | 376 |
|
11464 | 377 |
lemma not_less_empty [iff]: "(M, {#}) \<notin> mult1 r" |
10277 | 378 |
by (simp add: mult1_def) |
10249 | 379 |
|
11464 | 380 |
lemma less_add: "(N, M0 + {#a#}) \<in> mult1 r ==> |
381 |
(\<exists>M. (M, M0) \<in> mult1 r \<and> N = M + {#a#}) \<or> |
|
382 |
(\<exists>K. (\<forall>b. b :# K --> (b, a) \<in> r) \<and> N = M0 + K)" |
|
383 |
(concl is "?case1 (mult1 r) \<or> ?case2") |
|
10249 | 384 |
proof (unfold mult1_def) |
11464 | 385 |
let ?r = "\<lambda>K a. \<forall>b. b :# K --> (b, a) \<in> r" |
386 |
let ?R = "\<lambda>N M. \<exists>a M0 K. M = M0 + {#a#} \<and> N = M0 + K \<and> ?r K a" |
|
10249 | 387 |
let ?case1 = "?case1 {(N, M). ?R N M}" |
388 |
||
11464 | 389 |
assume "(N, M0 + {#a#}) \<in> {(N, M). ?R N M}" |
390 |
hence "\<exists>a' M0' K. |
|
391 |
M0 + {#a#} = M0' + {#a'#} \<and> N = M0' + K \<and> ?r K a'" by simp |
|
392 |
thus "?case1 \<or> ?case2" |
|
10249 | 393 |
proof (elim exE conjE) |
394 |
fix a' M0' K |
|
395 |
assume N: "N = M0' + K" and r: "?r K a'" |
|
396 |
assume "M0 + {#a#} = M0' + {#a'#}" |
|
11464 | 397 |
hence "M0 = M0' \<and> a = a' \<or> |
398 |
(\<exists>K'. M0 = K' + {#a'#} \<and> M0' = K' + {#a#})" |
|
10249 | 399 |
by (simp only: add_eq_conv_ex) |
400 |
thus ?thesis |
|
401 |
proof (elim disjE conjE exE) |
|
402 |
assume "M0 = M0'" "a = a'" |
|
11464 | 403 |
with N r have "?r K a \<and> N = M0 + K" by simp |
10249 | 404 |
hence ?case2 .. thus ?thesis .. |
405 |
next |
|
406 |
fix K' |
|
407 |
assume "M0' = K' + {#a#}" |
|
408 |
with N have n: "N = K' + K + {#a#}" by (simp add: union_ac) |
|
409 |
||
410 |
assume "M0 = K' + {#a'#}" |
|
411 |
with r have "?R (K' + K) M0" by blast |
|
412 |
with n have ?case1 by simp thus ?thesis .. |
|
413 |
qed |
|
414 |
qed |
|
415 |
qed |
|
416 |
||
11464 | 417 |
lemma all_accessible: "wf r ==> \<forall>M. M \<in> acc (mult1 r)" |
10249 | 418 |
proof |
419 |
let ?R = "mult1 r" |
|
420 |
let ?W = "acc ?R" |
|
421 |
{ |
|
422 |
fix M M0 a |
|
11464 | 423 |
assume M0: "M0 \<in> ?W" |
12399 | 424 |
and wf_hyp: "!!b. (b, a) \<in> r ==> (\<forall>M \<in> ?W. M + {#b#} \<in> ?W)" |
11464 | 425 |
and acc_hyp: "\<forall>M. (M, M0) \<in> ?R --> M + {#a#} \<in> ?W" |
426 |
have "M0 + {#a#} \<in> ?W" |
|
10249 | 427 |
proof (rule accI [of "M0 + {#a#}"]) |
428 |
fix N |
|
11464 | 429 |
assume "(N, M0 + {#a#}) \<in> ?R" |
430 |
hence "((\<exists>M. (M, M0) \<in> ?R \<and> N = M + {#a#}) \<or> |
|
431 |
(\<exists>K. (\<forall>b. b :# K --> (b, a) \<in> r) \<and> N = M0 + K))" |
|
10249 | 432 |
by (rule less_add) |
11464 | 433 |
thus "N \<in> ?W" |
10249 | 434 |
proof (elim exE disjE conjE) |
11464 | 435 |
fix M assume "(M, M0) \<in> ?R" and N: "N = M + {#a#}" |
436 |
from acc_hyp have "(M, M0) \<in> ?R --> M + {#a#} \<in> ?W" .. |
|
437 |
hence "M + {#a#} \<in> ?W" .. |
|
438 |
thus "N \<in> ?W" by (simp only: N) |
|
10249 | 439 |
next |
440 |
fix K |
|
441 |
assume N: "N = M0 + K" |
|
11464 | 442 |
assume "\<forall>b. b :# K --> (b, a) \<in> r" |
443 |
have "?this --> M0 + K \<in> ?W" (is "?P K") |
|
10249 | 444 |
proof (induct K) |
11464 | 445 |
from M0 have "M0 + {#} \<in> ?W" by simp |
10249 | 446 |
thus "?P {#}" .. |
447 |
||
448 |
fix K x assume hyp: "?P K" |
|
449 |
show "?P (K + {#x#})" |
|
450 |
proof |
|
11464 | 451 |
assume a: "\<forall>b. b :# (K + {#x#}) --> (b, a) \<in> r" |
452 |
hence "(x, a) \<in> r" by simp |
|
453 |
with wf_hyp have b: "\<forall>M \<in> ?W. M + {#x#} \<in> ?W" by blast |
|
10249 | 454 |
|
11464 | 455 |
from a hyp have "M0 + K \<in> ?W" by simp |
456 |
with b have "(M0 + K) + {#x#} \<in> ?W" .. |
|
457 |
thus "M0 + (K + {#x#}) \<in> ?W" by (simp only: union_assoc) |
|
10249 | 458 |
qed |
459 |
qed |
|
11464 | 460 |
hence "M0 + K \<in> ?W" .. |
461 |
thus "N \<in> ?W" by (simp only: N) |
|
10249 | 462 |
qed |
463 |
qed |
|
464 |
} note tedious_reasoning = this |
|
465 |
||
466 |
assume wf: "wf r" |
|
467 |
fix M |
|
11464 | 468 |
show "M \<in> ?W" |
10249 | 469 |
proof (induct M) |
11464 | 470 |
show "{#} \<in> ?W" |
10249 | 471 |
proof (rule accI) |
11464 | 472 |
fix b assume "(b, {#}) \<in> ?R" |
473 |
with not_less_empty show "b \<in> ?W" by contradiction |
|
10249 | 474 |
qed |
475 |
||
11464 | 476 |
fix M a assume "M \<in> ?W" |
477 |
from wf have "\<forall>M \<in> ?W. M + {#a#} \<in> ?W" |
|
10249 | 478 |
proof induct |
479 |
fix a |
|
12399 | 480 |
assume "!!b. (b, a) \<in> r ==> (\<forall>M \<in> ?W. M + {#b#} \<in> ?W)" |
11464 | 481 |
show "\<forall>M \<in> ?W. M + {#a#} \<in> ?W" |
10249 | 482 |
proof |
11464 | 483 |
fix M assume "M \<in> ?W" |
484 |
thus "M + {#a#} \<in> ?W" |
|
10249 | 485 |
by (rule acc_induct) (rule tedious_reasoning) |
486 |
qed |
|
487 |
qed |
|
11464 | 488 |
thus "M + {#a#} \<in> ?W" .. |
10249 | 489 |
qed |
490 |
qed |
|
491 |
||
492 |
theorem wf_mult1: "wf r ==> wf (mult1 r)" |
|
493 |
by (rule acc_wfI, rule all_accessible) |
|
494 |
||
495 |
theorem wf_mult: "wf r ==> wf (mult r)" |
|
496 |
by (unfold mult_def, rule wf_trancl, rule wf_mult1) |
|
497 |
||
498 |
||
499 |
subsubsection {* Closure-free presentation *} |
|
500 |
||
501 |
(*Badly needed: a linear arithmetic procedure for multisets*) |
|
502 |
||
503 |
lemma diff_union_single_conv: "a :# J ==> I + J - {#a#} = I + (J - {#a#})" |
|
15072 | 504 |
by (simp add: multiset_eq_conv_count_eq) |
10249 | 505 |
|
506 |
text {* One direction. *} |
|
507 |
||
508 |
lemma mult_implies_one_step: |
|
11464 | 509 |
"trans r ==> (M, N) \<in> mult r ==> |
510 |
\<exists>I J K. N = I + J \<and> M = I + K \<and> J \<noteq> {#} \<and> |
|
511 |
(\<forall>k \<in> set_of K. \<exists>j \<in> set_of J. (k, j) \<in> r)" |
|
10249 | 512 |
apply (unfold mult_def mult1_def set_of_def) |
15072 | 513 |
apply (erule converse_trancl_induct, clarify) |
514 |
apply (rule_tac x = M0 in exI, simp, clarify) |
|
10249 | 515 |
apply (case_tac "a :# K") |
516 |
apply (rule_tac x = I in exI) |
|
517 |
apply (simp (no_asm)) |
|
518 |
apply (rule_tac x = "(K - {#a#}) + Ka" in exI) |
|
519 |
apply (simp (no_asm_simp) add: union_assoc [symmetric]) |
|
11464 | 520 |
apply (drule_tac f = "\<lambda>M. M - {#a#}" in arg_cong) |
10249 | 521 |
apply (simp add: diff_union_single_conv) |
522 |
apply (simp (no_asm_use) add: trans_def) |
|
523 |
apply blast |
|
524 |
apply (subgoal_tac "a :# I") |
|
525 |
apply (rule_tac x = "I - {#a#}" in exI) |
|
526 |
apply (rule_tac x = "J + {#a#}" in exI) |
|
527 |
apply (rule_tac x = "K + Ka" in exI) |
|
528 |
apply (rule conjI) |
|
529 |
apply (simp add: multiset_eq_conv_count_eq split: nat_diff_split) |
|
530 |
apply (rule conjI) |
|
15072 | 531 |
apply (drule_tac f = "\<lambda>M. M - {#a#}" in arg_cong, simp) |
10249 | 532 |
apply (simp add: multiset_eq_conv_count_eq split: nat_diff_split) |
533 |
apply (simp (no_asm_use) add: trans_def) |
|
534 |
apply blast |
|
10277 | 535 |
apply (subgoal_tac "a :# (M0 + {#a#})") |
10249 | 536 |
apply simp |
537 |
apply (simp (no_asm)) |
|
538 |
done |
|
539 |
||
540 |
lemma elem_imp_eq_diff_union: "a :# M ==> M = M - {#a#} + {#a#}" |
|
15072 | 541 |
by (simp add: multiset_eq_conv_count_eq) |
10249 | 542 |
|
11464 | 543 |
lemma size_eq_Suc_imp_eq_union: "size M = Suc n ==> \<exists>a N. M = N + {#a#}" |
10249 | 544 |
apply (erule size_eq_Suc_imp_elem [THEN exE]) |
15072 | 545 |
apply (drule elem_imp_eq_diff_union, auto) |
10249 | 546 |
done |
547 |
||
548 |
lemma one_step_implies_mult_aux: |
|
549 |
"trans r ==> |
|
11464 | 550 |
\<forall>I J K. (size J = n \<and> J \<noteq> {#} \<and> (\<forall>k \<in> set_of K. \<exists>j \<in> set_of J. (k, j) \<in> r)) |
551 |
--> (I + K, I + J) \<in> mult r" |
|
15072 | 552 |
apply (induct_tac n, auto) |
553 |
apply (frule size_eq_Suc_imp_eq_union, clarify) |
|
554 |
apply (rename_tac "J'", simp) |
|
555 |
apply (erule notE, auto) |
|
10249 | 556 |
apply (case_tac "J' = {#}") |
557 |
apply (simp add: mult_def) |
|
558 |
apply (rule r_into_trancl) |
|
15072 | 559 |
apply (simp add: mult1_def set_of_def, blast) |
11464 | 560 |
txt {* Now we know @{term "J' \<noteq> {#}"}. *} |
561 |
apply (cut_tac M = K and P = "\<lambda>x. (x, a) \<in> r" in multiset_partition) |
|
562 |
apply (erule_tac P = "\<forall>k \<in> set_of K. ?P k" in rev_mp) |
|
10249 | 563 |
apply (erule ssubst) |
15072 | 564 |
apply (simp add: Ball_def, auto) |
10249 | 565 |
apply (subgoal_tac |
11464 | 566 |
"((I + {# x : K. (x, a) \<in> r #}) + {# x : K. (x, a) \<notin> r #}, |
567 |
(I + {# x : K. (x, a) \<in> r #}) + J') \<in> mult r") |
|
10249 | 568 |
prefer 2 |
569 |
apply force |
|
570 |
apply (simp (no_asm_use) add: union_assoc [symmetric] mult_def) |
|
571 |
apply (erule trancl_trans) |
|
572 |
apply (rule r_into_trancl) |
|
573 |
apply (simp add: mult1_def set_of_def) |
|
574 |
apply (rule_tac x = a in exI) |
|
575 |
apply (rule_tac x = "I + J'" in exI) |
|
576 |
apply (simp add: union_ac) |
|
577 |
done |
|
578 |
||
579 |
theorem one_step_implies_mult: |
|
11464 | 580 |
"trans r ==> J \<noteq> {#} ==> \<forall>k \<in> set_of K. \<exists>j \<in> set_of J. (k, j) \<in> r |
581 |
==> (I + K, I + J) \<in> mult r" |
|
15072 | 582 |
apply (insert one_step_implies_mult_aux, blast) |
10249 | 583 |
done |
584 |
||
585 |
||
586 |
subsubsection {* Partial-order properties *} |
|
587 |
||
12338
de0f4a63baa5
renamed class "term" to "type" (actually "HOL.type");
wenzelm
parents:
11868
diff
changeset
|
588 |
instance multiset :: (type) ord .. |
10249 | 589 |
|
590 |
defs (overloaded) |
|
11464 | 591 |
less_multiset_def: "M' < M == (M', M) \<in> mult {(x', x). x' < x}" |
592 |
le_multiset_def: "M' <= M == M' = M \<or> M' < (M::'a multiset)" |
|
10249 | 593 |
|
594 |
lemma trans_base_order: "trans {(x', x). x' < (x::'a::order)}" |
|
595 |
apply (unfold trans_def) |
|
596 |
apply (blast intro: order_less_trans) |
|
597 |
done |
|
598 |
||
599 |
text {* |
|
600 |
\medskip Irreflexivity. |
|
601 |
*} |
|
602 |
||
603 |
lemma mult_irrefl_aux: |
|
11464 | 604 |
"finite A ==> (\<forall>x \<in> A. \<exists>y \<in> A. x < (y::'a::order)) --> A = {}" |
10249 | 605 |
apply (erule finite_induct) |
606 |
apply (auto intro: order_less_trans) |
|
607 |
done |
|
608 |
||
11464 | 609 |
theorem mult_less_not_refl: "\<not> M < (M::'a::order multiset)" |
15072 | 610 |
apply (unfold less_multiset_def, auto) |
611 |
apply (drule trans_base_order [THEN mult_implies_one_step], auto) |
|
10249 | 612 |
apply (drule finite_set_of [THEN mult_irrefl_aux [rule_format (no_asm)]]) |
613 |
apply (simp add: set_of_eq_empty_iff) |
|
614 |
done |
|
615 |
||
616 |
lemma mult_less_irrefl [elim!]: "M < (M::'a::order multiset) ==> R" |
|
15072 | 617 |
by (insert mult_less_not_refl, fast) |
10249 | 618 |
|
619 |
||
620 |
text {* Transitivity. *} |
|
621 |
||
622 |
theorem mult_less_trans: "K < M ==> M < N ==> K < (N::'a::order multiset)" |
|
623 |
apply (unfold less_multiset_def mult_def) |
|
624 |
apply (blast intro: trancl_trans) |
|
625 |
done |
|
626 |
||
627 |
text {* Asymmetry. *} |
|
628 |
||
11464 | 629 |
theorem mult_less_not_sym: "M < N ==> \<not> N < (M::'a::order multiset)" |
10249 | 630 |
apply auto |
631 |
apply (rule mult_less_not_refl [THEN notE]) |
|
15072 | 632 |
apply (erule mult_less_trans, assumption) |
10249 | 633 |
done |
634 |
||
635 |
theorem mult_less_asym: |
|
11464 | 636 |
"M < N ==> (\<not> P ==> N < (M::'a::order multiset)) ==> P" |
15072 | 637 |
by (insert mult_less_not_sym, blast) |
10249 | 638 |
|
639 |
theorem mult_le_refl [iff]: "M <= (M::'a::order multiset)" |
|
15072 | 640 |
by (unfold le_multiset_def, auto) |
10249 | 641 |
|
642 |
text {* Anti-symmetry. *} |
|
643 |
||
644 |
theorem mult_le_antisym: |
|
645 |
"M <= N ==> N <= M ==> M = (N::'a::order multiset)" |
|
646 |
apply (unfold le_multiset_def) |
|
647 |
apply (blast dest: mult_less_not_sym) |
|
648 |
done |
|
649 |
||
650 |
text {* Transitivity. *} |
|
651 |
||
652 |
theorem mult_le_trans: |
|
653 |
"K <= M ==> M <= N ==> K <= (N::'a::order multiset)" |
|
654 |
apply (unfold le_multiset_def) |
|
655 |
apply (blast intro: mult_less_trans) |
|
656 |
done |
|
657 |
||
11655 | 658 |
theorem mult_less_le: "(M < N) = (M <= N \<and> M \<noteq> (N::'a::order multiset))" |
15072 | 659 |
by (unfold le_multiset_def, auto) |
10249 | 660 |
|
10277 | 661 |
text {* Partial order. *} |
662 |
||
663 |
instance multiset :: (order) order |
|
664 |
apply intro_classes |
|
665 |
apply (rule mult_le_refl) |
|
15072 | 666 |
apply (erule mult_le_trans, assumption) |
667 |
apply (erule mult_le_antisym, assumption) |
|
10277 | 668 |
apply (rule mult_less_le) |
669 |
done |
|
670 |
||
10249 | 671 |
|
672 |
subsubsection {* Monotonicity of multiset union *} |
|
673 |
||
674 |
theorem mult1_union: |
|
11464 | 675 |
"(B, D) \<in> mult1 r ==> trans r ==> (C + B, C + D) \<in> mult1 r" |
15072 | 676 |
apply (unfold mult1_def, auto) |
10249 | 677 |
apply (rule_tac x = a in exI) |
678 |
apply (rule_tac x = "C + M0" in exI) |
|
679 |
apply (simp add: union_assoc) |
|
680 |
done |
|
681 |
||
682 |
lemma union_less_mono2: "B < D ==> C + B < C + (D::'a::order multiset)" |
|
683 |
apply (unfold less_multiset_def mult_def) |
|
684 |
apply (erule trancl_induct) |
|
685 |
apply (blast intro: mult1_union transI order_less_trans r_into_trancl) |
|
686 |
apply (blast intro: mult1_union transI order_less_trans r_into_trancl trancl_trans) |
|
687 |
done |
|
688 |
||
689 |
lemma union_less_mono1: "B < D ==> B + C < D + (C::'a::order multiset)" |
|
690 |
apply (subst union_commute [of B C]) |
|
691 |
apply (subst union_commute [of D C]) |
|
692 |
apply (erule union_less_mono2) |
|
693 |
done |
|
694 |
||
695 |
theorem union_less_mono: |
|
696 |
"A < C ==> B < D ==> A + B < C + (D::'a::order multiset)" |
|
697 |
apply (blast intro!: union_less_mono1 union_less_mono2 mult_less_trans) |
|
698 |
done |
|
699 |
||
700 |
theorem union_le_mono: |
|
701 |
"A <= C ==> B <= D ==> A + B <= C + (D::'a::order multiset)" |
|
702 |
apply (unfold le_multiset_def) |
|
703 |
apply (blast intro: union_less_mono union_less_mono1 union_less_mono2) |
|
704 |
done |
|
705 |
||
706 |
theorem empty_leI [iff]: "{#} <= (M::'a::order multiset)" |
|
707 |
apply (unfold le_multiset_def less_multiset_def) |
|
708 |
apply (case_tac "M = {#}") |
|
709 |
prefer 2 |
|
11464 | 710 |
apply (subgoal_tac "({#} + {#}, {#} + M) \<in> mult (Collect (split op <))") |
10249 | 711 |
prefer 2 |
712 |
apply (rule one_step_implies_mult) |
|
15072 | 713 |
apply (simp only: trans_def, auto) |
10249 | 714 |
done |
715 |
||
716 |
theorem union_upper1: "A <= A + (B::'a::order multiset)" |
|
15072 | 717 |
proof - |
718 |
have "A + {#} <= A + B" by (blast intro: union_le_mono) |
|
719 |
thus ?thesis by simp |
|
720 |
qed |
|
721 |
||
722 |
theorem union_upper2: "B <= A + (B::'a::order multiset)" |
|
723 |
by (subst union_commute, rule union_upper1) |
|
724 |
||
725 |
||
726 |
subsection {* Link with lists *} |
|
727 |
||
728 |
consts |
|
729 |
multiset_of :: "'a list \<Rightarrow> 'a multiset" |
|
730 |
primrec |
|
731 |
"multiset_of [] = {#}" |
|
732 |
"multiset_of (a # x) = multiset_of x + {# a #}" |
|
733 |
||
734 |
lemma multiset_of_zero_iff[simp]: "(multiset_of x = {#}) = (x = [])" |
|
735 |
by (induct_tac x, auto) |
|
736 |
||
737 |
lemma multiset_of_zero_iff_right[simp]: "({#} = multiset_of x) = (x = [])" |
|
738 |
by (induct_tac x, auto) |
|
739 |
||
740 |
lemma set_of_multiset_of[simp]: "set_of(multiset_of x) = set x" |
|
741 |
by (induct_tac x, auto) |
|
742 |
||
743 |
lemma multset_of_append[simp]: |
|
744 |
"multiset_of (xs @ ys) = multiset_of xs + multiset_of ys" |
|
745 |
by (rule_tac x=ys in spec, induct_tac xs, auto simp: union_ac) |
|
746 |
||
747 |
lemma surj_multiset_of: "surj multiset_of" |
|
748 |
apply (unfold surj_def, rule allI) |
|
749 |
apply (rule_tac M=y in multiset_induct, auto) |
|
750 |
apply (rule_tac x = "x # xa" in exI, auto) |
|
10249 | 751 |
done |
752 |
||
15072 | 753 |
lemma set_count_greater_0: "set x = {a. 0 < count (multiset_of x) a}" |
754 |
by (induct_tac x, auto) |
|
755 |
||
756 |
lemma distinct_count_atmost_1: |
|
757 |
"distinct x = (! a. count (multiset_of x) a = (if a \<in> set x then 1 else 0))" |
|
758 |
apply ( induct_tac x, simp, rule iffI, simp_all) |
|
759 |
apply (rule conjI) |
|
760 |
apply (simp_all add: set_of_multiset_of [THEN sym] del: set_of_multiset_of) |
|
761 |
apply (erule_tac x=a in allE, simp, clarify) |
|
762 |
apply (erule_tac x=aa in allE, simp) |
|
763 |
done |
|
764 |
||
765 |
lemma set_eq_iff_multiset_of_eq_distinct: |
|
766 |
"\<lbrakk>distinct x; distinct y\<rbrakk> |
|
767 |
\<Longrightarrow> (set x = set y) = (multiset_of x = multiset_of y)" |
|
768 |
by (auto simp: multiset_eq_conv_count_eq distinct_count_atmost_1) |
|
769 |
||
770 |
lemma set_eq_iff_multiset_of_remdups_eq: |
|
771 |
"(set x = set y) = (multiset_of (remdups x) = multiset_of (remdups y))" |
|
772 |
apply (rule iffI) |
|
773 |
apply (simp add: set_eq_iff_multiset_of_eq_distinct[THEN iffD1]) |
|
774 |
apply (drule distinct_remdups[THEN distinct_remdups |
|
775 |
[THEN set_eq_iff_multiset_of_eq_distinct[THEN iffD2]]]) |
|
776 |
apply simp |
|
10249 | 777 |
done |
778 |
||
15072 | 779 |
|
780 |
subsection {* Pointwise ordering induced by count *} |
|
781 |
||
782 |
consts |
|
783 |
mset_le :: "['a multiset, 'a multiset] \<Rightarrow> bool" |
|
784 |
||
785 |
syntax |
|
786 |
"_mset_le" :: "'a multiset \<Rightarrow> 'a multiset \<Rightarrow> bool" ("_ \<le># _" [50,51] 50) |
|
787 |
translations |
|
788 |
"x \<le># y" == "mset_le x y" |
|
789 |
||
790 |
defs |
|
791 |
mset_le_def: "xs \<le># ys == (! a. count xs a \<le> count ys a)" |
|
792 |
||
793 |
lemma mset_le_refl[simp]: "xs \<le># xs" |
|
794 |
by (unfold mset_le_def, auto) |
|
795 |
||
796 |
lemma mset_le_trans: "\<lbrakk> xs \<le># ys; ys \<le># zs \<rbrakk> \<Longrightarrow> xs \<le># zs" |
|
797 |
by (unfold mset_le_def, fast intro: order_trans) |
|
798 |
||
799 |
lemma mset_le_antisym: "\<lbrakk> xs\<le># ys; ys \<le># xs\<rbrakk> \<Longrightarrow> xs = ys" |
|
800 |
apply (unfold mset_le_def) |
|
801 |
apply (rule multiset_eq_conv_count_eq[THEN iffD2]) |
|
802 |
apply (blast intro: order_antisym) |
|
803 |
done |
|
804 |
||
805 |
lemma mset_le_exists_conv: |
|
806 |
"(xs \<le># ys) = (? zs. ys = xs + zs)" |
|
807 |
apply (unfold mset_le_def, rule iffI, rule_tac x = "ys - xs" in exI) |
|
808 |
apply (auto intro: multiset_eq_conv_count_eq [THEN iffD2]) |
|
809 |
done |
|
810 |
||
811 |
lemma mset_le_mono_add_right_cancel[simp]: "(xs + zs \<le># ys + zs) = (xs \<le># ys)" |
|
812 |
by (unfold mset_le_def, auto) |
|
813 |
||
814 |
lemma mset_le_mono_add_left_cancel[simp]: "(zs + xs \<le># zs + ys) = (xs \<le># ys)" |
|
815 |
by (unfold mset_le_def, auto) |
|
816 |
||
817 |
lemma mset_le_mono_add: "\<lbrakk> xs \<le># ys; vs \<le># ws \<rbrakk> \<Longrightarrow> xs + vs \<le># ys + ws" |
|
818 |
apply (unfold mset_le_def, auto) |
|
819 |
apply (erule_tac x=a in allE)+ |
|
820 |
apply auto |
|
821 |
done |
|
822 |
||
823 |
lemma mset_le_add_left[simp]: "xs \<le># xs + ys" |
|
824 |
by (unfold mset_le_def, auto) |
|
825 |
||
826 |
lemma mset_le_add_right[simp]: "ys \<le># xs + ys" |
|
827 |
by (unfold mset_le_def, auto) |
|
828 |
||
829 |
lemma multiset_of_remdups_le: "multiset_of (remdups x) \<le># multiset_of x" |
|
830 |
by (induct_tac x, auto, rule mset_le_trans, auto) |
|
831 |
||
10249 | 832 |
end |