author | wenzelm |
Fri, 16 Apr 2010 21:28:09 +0200 | |
changeset 36176 | 3fe7e97ccca8 |
parent 35712 | 77aa29bf14ee |
child 36635 | 080b755377c0 |
permissions | -rw-r--r-- |
10249 | 1 |
(* Title: HOL/Library/Multiset.thy |
15072 | 2 |
Author: Tobias Nipkow, Markus Wenzel, Lawrence C Paulson, Norbert Voelker |
10249 | 3 |
*) |
4 |
||
34943
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
5 |
header {* (Finite) multisets *} |
10249 | 6 |
|
15131 | 7 |
theory Multiset |
34943
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
8 |
imports Main |
15131 | 9 |
begin |
10249 | 10 |
|
11 |
subsection {* The type of multisets *} |
|
12 |
||
34943
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
13 |
typedef 'a multiset = "{f :: 'a => nat. finite {x. f x > 0}}" |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
14 |
morphisms count Abs_multiset |
10249 | 15 |
proof |
11464 | 16 |
show "(\<lambda>x. 0::nat) \<in> ?multiset" by simp |
10249 | 17 |
qed |
18 |
||
34943
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
19 |
lemmas multiset_typedef = Abs_multiset_inverse count_inverse count |
19086 | 20 |
|
28708
a1a436f09ec6
explicit check for pattern discipline before code translation
haftmann
parents:
28562
diff
changeset
|
21 |
abbreviation Melem :: "'a => 'a multiset => bool" ("(_/ :# _)" [50, 51] 50) where |
25610 | 22 |
"a :# M == 0 < count M a" |
23 |
||
26145 | 24 |
notation (xsymbols) |
25 |
Melem (infix "\<in>#" 50) |
|
10249 | 26 |
|
34943
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
27 |
lemma multiset_eq_conv_count_eq: |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
28 |
"M = N \<longleftrightarrow> (\<forall>a. count M a = count N a)" |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
29 |
by (simp only: count_inject [symmetric] expand_fun_eq) |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
30 |
|
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
31 |
lemma multi_count_ext: |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
32 |
"(\<And>x. count A x = count B x) \<Longrightarrow> A = B" |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
33 |
using multiset_eq_conv_count_eq by auto |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
34 |
|
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
35 |
text {* |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
36 |
\medskip Preservation of the representing set @{term multiset}. |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
37 |
*} |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
38 |
|
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
39 |
lemma const0_in_multiset: |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
40 |
"(\<lambda>a. 0) \<in> multiset" |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
41 |
by (simp add: multiset_def) |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
42 |
|
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
43 |
lemma only1_in_multiset: |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
44 |
"(\<lambda>b. if b = a then n else 0) \<in> multiset" |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
45 |
by (simp add: multiset_def) |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
46 |
|
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
47 |
lemma union_preserves_multiset: |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
48 |
"M \<in> multiset \<Longrightarrow> N \<in> multiset \<Longrightarrow> (\<lambda>a. M a + N a) \<in> multiset" |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
49 |
by (simp add: multiset_def) |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
50 |
|
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
51 |
lemma diff_preserves_multiset: |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
52 |
assumes "M \<in> multiset" |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
53 |
shows "(\<lambda>a. M a - N a) \<in> multiset" |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
54 |
proof - |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
55 |
have "{x. N x < M x} \<subseteq> {x. 0 < M x}" |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
56 |
by auto |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
57 |
with assms show ?thesis |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
58 |
by (auto simp add: multiset_def intro: finite_subset) |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
59 |
qed |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
60 |
|
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
61 |
lemma MCollect_preserves_multiset: |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
62 |
assumes "M \<in> multiset" |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
63 |
shows "(\<lambda>x. if P x then M x else 0) \<in> multiset" |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
64 |
proof - |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
65 |
have "{x. (P x \<longrightarrow> 0 < M x) \<and> P x} \<subseteq> {x. 0 < M x}" |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
66 |
by auto |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
67 |
with assms show ?thesis |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
68 |
by (auto simp add: multiset_def intro: finite_subset) |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
69 |
qed |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
70 |
|
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
71 |
lemmas in_multiset = const0_in_multiset only1_in_multiset |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
72 |
union_preserves_multiset diff_preserves_multiset MCollect_preserves_multiset |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
73 |
|
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
74 |
|
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
75 |
subsection {* Representing multisets *} |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
76 |
|
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
77 |
text {* Multiset comprehension *} |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
78 |
|
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
79 |
definition MCollect :: "'a multiset => ('a => bool) => 'a multiset" where |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
80 |
"MCollect M P = Abs_multiset (\<lambda>x. if P x then count M x else 0)" |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
81 |
|
10249 | 82 |
syntax |
26033 | 83 |
"_MCollect" :: "pttrn => 'a multiset => bool => 'a multiset" ("(1{# _ :# _./ _#})") |
10249 | 84 |
translations |
26033 | 85 |
"{#x :# M. P#}" == "CONST MCollect M (\<lambda>x. P)" |
10249 | 86 |
|
87 |
||
34943
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
88 |
text {* Multiset enumeration *} |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
89 |
|
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
90 |
instantiation multiset :: (type) "{zero, plus}" |
25571
c9e39eafc7a0
instantiation target rather than legacy instance
haftmann
parents:
25507
diff
changeset
|
91 |
begin |
c9e39eafc7a0
instantiation target rather than legacy instance
haftmann
parents:
25507
diff
changeset
|
92 |
|
34943
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
93 |
definition Mempty_def: |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
94 |
"0 = Abs_multiset (\<lambda>a. 0)" |
25571
c9e39eafc7a0
instantiation target rather than legacy instance
haftmann
parents:
25507
diff
changeset
|
95 |
|
34943
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
96 |
abbreviation Mempty :: "'a multiset" ("{#}") where |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
97 |
"Mempty \<equiv> 0" |
25571
c9e39eafc7a0
instantiation target rather than legacy instance
haftmann
parents:
25507
diff
changeset
|
98 |
|
34943
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
99 |
definition union_def: |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
100 |
"M + N = Abs_multiset (\<lambda>a. count M a + count N a)" |
25571
c9e39eafc7a0
instantiation target rather than legacy instance
haftmann
parents:
25507
diff
changeset
|
101 |
|
c9e39eafc7a0
instantiation target rather than legacy instance
haftmann
parents:
25507
diff
changeset
|
102 |
instance .. |
c9e39eafc7a0
instantiation target rather than legacy instance
haftmann
parents:
25507
diff
changeset
|
103 |
|
c9e39eafc7a0
instantiation target rather than legacy instance
haftmann
parents:
25507
diff
changeset
|
104 |
end |
10249 | 105 |
|
34943
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
106 |
definition single :: "'a => 'a multiset" where |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
107 |
"single a = Abs_multiset (\<lambda>b. if b = a then 1 else 0)" |
15869 | 108 |
|
26145 | 109 |
syntax |
26176 | 110 |
"_multiset" :: "args => 'a multiset" ("{#(_)#}") |
25507 | 111 |
translations |
112 |
"{#x, xs#}" == "{#x#} + {#xs#}" |
|
113 |
"{#x#}" == "CONST single x" |
|
114 |
||
34943
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
115 |
lemma count_empty [simp]: "count {#} a = 0" |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
116 |
by (simp add: Mempty_def in_multiset multiset_typedef) |
10249 | 117 |
|
34943
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
118 |
lemma count_single [simp]: "count {#b#} a = (if b = a then 1 else 0)" |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
119 |
by (simp add: single_def in_multiset multiset_typedef) |
29901 | 120 |
|
10249 | 121 |
|
34943
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
122 |
subsection {* Basic operations *} |
10249 | 123 |
|
124 |
subsubsection {* Union *} |
|
125 |
||
34943
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
126 |
lemma count_union [simp]: "count (M + N) a = count M a + count N a" |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
127 |
by (simp add: union_def in_multiset multiset_typedef) |
10249 | 128 |
|
34943
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
129 |
instance multiset :: (type) cancel_comm_monoid_add proof |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
130 |
qed (simp_all add: multiset_eq_conv_count_eq) |
10277 | 131 |
|
10249 | 132 |
|
133 |
subsubsection {* Difference *} |
|
134 |
||
34943
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
135 |
instantiation multiset :: (type) minus |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
136 |
begin |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
137 |
|
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
138 |
definition diff_def: |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
139 |
"M - N = Abs_multiset (\<lambda>a. count M a - count N a)" |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
140 |
|
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
141 |
instance .. |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
142 |
|
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
143 |
end |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
144 |
|
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
145 |
lemma count_diff [simp]: "count (M - N) a = count M a - count N a" |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
146 |
by (simp add: diff_def in_multiset multiset_typedef) |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
147 |
|
17161 | 148 |
lemma diff_empty [simp]: "M - {#} = M \<and> {#} - M = {#}" |
34943
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
149 |
by (simp add: Mempty_def diff_def in_multiset multiset_typedef) |
10249 | 150 |
|
17161 | 151 |
lemma diff_union_inverse2 [simp]: "M + {#a#} - {#a#} = M" |
34943
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
152 |
by (rule multi_count_ext) |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
153 |
(auto simp del: count_single simp add: union_def diff_def in_multiset multiset_typedef) |
10249 | 154 |
|
26143
314c0bcb7df7
Added useful general lemmas from the work with the HeapMonad
bulwahn
parents:
26033
diff
changeset
|
155 |
lemma diff_cancel: "A - A = {#}" |
34943
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
156 |
by (rule multi_count_ext) simp |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
157 |
|
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
158 |
lemma insert_DiffM: |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
159 |
"x \<in># M \<Longrightarrow> {#x#} + (M - {#x#}) = M" |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
160 |
by (clarsimp simp: multiset_eq_conv_count_eq) |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
161 |
|
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
162 |
lemma insert_DiffM2 [simp]: |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
163 |
"x \<in># M \<Longrightarrow> M - {#x#} + {#x#} = M" |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
164 |
by (clarsimp simp: multiset_eq_conv_count_eq) |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
165 |
|
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
166 |
lemma diff_right_commute: |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
167 |
"(M::'a multiset) - N - Q = M - Q - N" |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
168 |
by (auto simp add: multiset_eq_conv_count_eq) |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
169 |
|
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
170 |
lemma diff_union_swap: |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
171 |
"a \<noteq> b \<Longrightarrow> M - {#a#} + {#b#} = M + {#b#} - {#a#}" |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
172 |
by (auto simp add: multiset_eq_conv_count_eq) |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
173 |
|
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
174 |
lemma diff_union_single_conv: |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
175 |
"a \<in># J \<Longrightarrow> I + J - {#a#} = I + (J - {#a#})" |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
176 |
by (simp add: multiset_eq_conv_count_eq) |
26143
314c0bcb7df7
Added useful general lemmas from the work with the HeapMonad
bulwahn
parents:
26033
diff
changeset
|
177 |
|
10249 | 178 |
|
34943
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
179 |
subsubsection {* Equality of multisets *} |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
180 |
|
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
181 |
lemma single_not_empty [simp]: "{#a#} \<noteq> {#} \<and> {#} \<noteq> {#a#}" |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
182 |
by (simp add: multiset_eq_conv_count_eq) |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
183 |
|
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
184 |
lemma single_eq_single [simp]: "{#a#} = {#b#} \<longleftrightarrow> a = b" |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
185 |
by (auto simp add: multiset_eq_conv_count_eq) |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
186 |
|
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
187 |
lemma union_eq_empty [iff]: "M + N = {#} \<longleftrightarrow> M = {#} \<and> N = {#}" |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
188 |
by (auto simp add: multiset_eq_conv_count_eq) |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
189 |
|
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
190 |
lemma empty_eq_union [iff]: "{#} = M + N \<longleftrightarrow> M = {#} \<and> N = {#}" |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
191 |
by (auto simp add: multiset_eq_conv_count_eq) |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
192 |
|
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
193 |
lemma multi_self_add_other_not_self [simp]: "M = M + {#x#} \<longleftrightarrow> False" |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
194 |
by (auto simp add: multiset_eq_conv_count_eq) |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
195 |
|
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
196 |
lemma diff_single_trivial: |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
197 |
"\<not> x \<in># M \<Longrightarrow> M - {#x#} = M" |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
198 |
by (auto simp add: multiset_eq_conv_count_eq) |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
199 |
|
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
200 |
lemma diff_single_eq_union: |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
201 |
"x \<in># M \<Longrightarrow> M - {#x#} = N \<longleftrightarrow> M = N + {#x#}" |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
202 |
by auto |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
203 |
|
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
204 |
lemma union_single_eq_diff: |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
205 |
"M + {#x#} = N \<Longrightarrow> M = N - {#x#}" |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
206 |
by (auto dest: sym) |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
207 |
|
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
208 |
lemma union_single_eq_member: |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
209 |
"M + {#x#} = N \<Longrightarrow> x \<in># N" |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
210 |
by auto |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
211 |
|
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
212 |
lemma union_is_single: |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
213 |
"M + N = {#a#} \<longleftrightarrow> M = {#a#} \<and> N={#} \<or> M = {#} \<and> N = {#a#}" (is "?lhs = ?rhs") |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
214 |
proof |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
215 |
assume ?rhs then show ?lhs by auto |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
216 |
next |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
217 |
assume ?lhs |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
218 |
then have "\<And>b. count (M + N) b = (if b = a then 1 else 0)" by auto |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
219 |
then have *: "\<And>b. count M b + count N b = (if b = a then 1 else 0)" by auto |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
220 |
then have "count M a + count N a = 1" by auto |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
221 |
then have **: "count M a = 1 \<and> count N a = 0 \<or> count M a = 0 \<and> count N a = 1" |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
222 |
by auto |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
223 |
from * have "\<And>b. b \<noteq> a \<Longrightarrow> count M b + count N b = 0" by auto |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
224 |
then have ***: "\<And>b. b \<noteq> a \<Longrightarrow> count M b = 0 \<and> count N b = 0" by auto |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
225 |
from ** and *** have |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
226 |
"(\<forall>b. count M b = (if b = a then 1 else 0) \<and> count N b = 0) \<or> |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
227 |
(\<forall>b. count M b = 0 \<and> count N b = (if b = a then 1 else 0))" |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
228 |
by auto |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
229 |
then have |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
230 |
"(\<forall>b. count M b = (if b = a then 1 else 0)) \<and> (\<forall>b. count N b = 0) \<or> |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
231 |
(\<forall>b. count M b = 0) \<and> (\<forall>b. count N b = (if b = a then 1 else 0))" |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
232 |
by auto |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
233 |
then show ?rhs by (auto simp add: multiset_eq_conv_count_eq) |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
234 |
qed |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
235 |
|
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
236 |
lemma single_is_union: |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
237 |
"{#a#} = M + N \<longleftrightarrow> {#a#} = M \<and> N = {#} \<or> M = {#} \<and> {#a#} = N" |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
238 |
by (auto simp add: eq_commute [of "{#a#}" "M + N"] union_is_single) |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
239 |
|
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
240 |
lemma add_eq_conv_diff: |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
241 |
"M + {#a#} = N + {#b#} \<longleftrightarrow> M = N \<and> a = b \<or> M = N - {#a#} + {#b#} \<and> N = M - {#b#} + {#a#}" (is "?lhs = ?rhs") |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
242 |
proof |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
243 |
assume ?rhs then show ?lhs |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
244 |
by (auto simp add: add_assoc add_commute [of "{#b#}"]) |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
245 |
(drule sym, simp add: add_assoc [symmetric]) |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
246 |
next |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
247 |
assume ?lhs |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
248 |
show ?rhs |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
249 |
proof (cases "a = b") |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
250 |
case True with `?lhs` show ?thesis by simp |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
251 |
next |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
252 |
case False |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
253 |
from `?lhs` have "a \<in># N + {#b#}" by (rule union_single_eq_member) |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
254 |
with False have "a \<in># N" by auto |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
255 |
moreover from `?lhs` have "M = N + {#b#} - {#a#}" by (rule union_single_eq_diff) |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
256 |
moreover note False |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
257 |
ultimately show ?thesis by (auto simp add: diff_right_commute [of _ "{#a#}"] diff_union_swap) |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
258 |
qed |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
259 |
qed |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
260 |
|
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
261 |
lemma insert_noteq_member: |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
262 |
assumes BC: "B + {#b#} = C + {#c#}" |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
263 |
and bnotc: "b \<noteq> c" |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
264 |
shows "c \<in># B" |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
265 |
proof - |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
266 |
have "c \<in># C + {#c#}" by simp |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
267 |
have nc: "\<not> c \<in># {#b#}" using bnotc by simp |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
268 |
then have "c \<in># B + {#b#}" using BC by simp |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
269 |
then show "c \<in># B" using nc by simp |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
270 |
qed |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
271 |
|
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
272 |
lemma add_eq_conv_ex: |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
273 |
"(M + {#a#} = N + {#b#}) = |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
274 |
(M = N \<and> a = b \<or> (\<exists>K. M = K + {#b#} \<and> N = K + {#a#}))" |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
275 |
by (auto simp add: add_eq_conv_diff) |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
276 |
|
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
277 |
|
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
278 |
subsubsection {* Pointwise ordering induced by count *} |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
279 |
|
35268
04673275441a
switched notations for pointwise and multiset order
haftmann
parents:
35028
diff
changeset
|
280 |
instantiation multiset :: (type) ordered_ab_semigroup_add_imp_le |
04673275441a
switched notations for pointwise and multiset order
haftmann
parents:
35028
diff
changeset
|
281 |
begin |
04673275441a
switched notations for pointwise and multiset order
haftmann
parents:
35028
diff
changeset
|
282 |
|
04673275441a
switched notations for pointwise and multiset order
haftmann
parents:
35028
diff
changeset
|
283 |
definition less_eq_multiset :: "'a multiset \<Rightarrow> 'a multiset \<Rightarrow> bool" where |
04673275441a
switched notations for pointwise and multiset order
haftmann
parents:
35028
diff
changeset
|
284 |
mset_le_def: "A \<le> B \<longleftrightarrow> (\<forall>a. count A a \<le> count B a)" |
34943
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
285 |
|
35268
04673275441a
switched notations for pointwise and multiset order
haftmann
parents:
35028
diff
changeset
|
286 |
definition less_multiset :: "'a multiset \<Rightarrow> 'a multiset \<Rightarrow> bool" where |
04673275441a
switched notations for pointwise and multiset order
haftmann
parents:
35028
diff
changeset
|
287 |
mset_less_def: "(A::'a multiset) < B \<longleftrightarrow> A \<le> B \<and> A \<noteq> B" |
34943
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
288 |
|
35268
04673275441a
switched notations for pointwise and multiset order
haftmann
parents:
35028
diff
changeset
|
289 |
instance proof |
04673275441a
switched notations for pointwise and multiset order
haftmann
parents:
35028
diff
changeset
|
290 |
qed (auto simp add: mset_le_def mset_less_def multiset_eq_conv_count_eq intro: order_trans antisym) |
04673275441a
switched notations for pointwise and multiset order
haftmann
parents:
35028
diff
changeset
|
291 |
|
04673275441a
switched notations for pointwise and multiset order
haftmann
parents:
35028
diff
changeset
|
292 |
end |
34943
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
293 |
|
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
294 |
lemma mset_less_eqI: |
35268
04673275441a
switched notations for pointwise and multiset order
haftmann
parents:
35028
diff
changeset
|
295 |
"(\<And>x. count A x \<le> count B x) \<Longrightarrow> A \<le> B" |
34943
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
296 |
by (simp add: mset_le_def) |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
297 |
|
35268
04673275441a
switched notations for pointwise and multiset order
haftmann
parents:
35028
diff
changeset
|
298 |
lemma mset_le_exists_conv: |
04673275441a
switched notations for pointwise and multiset order
haftmann
parents:
35028
diff
changeset
|
299 |
"(A::'a multiset) \<le> B \<longleftrightarrow> (\<exists>C. B = A + C)" |
34943
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
300 |
apply (unfold mset_le_def, rule iffI, rule_tac x = "B - A" in exI) |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
301 |
apply (auto intro: multiset_eq_conv_count_eq [THEN iffD2]) |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
302 |
done |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
303 |
|
35268
04673275441a
switched notations for pointwise and multiset order
haftmann
parents:
35028
diff
changeset
|
304 |
lemma mset_le_mono_add_right_cancel [simp]: |
04673275441a
switched notations for pointwise and multiset order
haftmann
parents:
35028
diff
changeset
|
305 |
"(A::'a multiset) + C \<le> B + C \<longleftrightarrow> A \<le> B" |
04673275441a
switched notations for pointwise and multiset order
haftmann
parents:
35028
diff
changeset
|
306 |
by (fact add_le_cancel_right) |
34943
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
307 |
|
35268
04673275441a
switched notations for pointwise and multiset order
haftmann
parents:
35028
diff
changeset
|
308 |
lemma mset_le_mono_add_left_cancel [simp]: |
04673275441a
switched notations for pointwise and multiset order
haftmann
parents:
35028
diff
changeset
|
309 |
"C + (A::'a multiset) \<le> C + B \<longleftrightarrow> A \<le> B" |
04673275441a
switched notations for pointwise and multiset order
haftmann
parents:
35028
diff
changeset
|
310 |
by (fact add_le_cancel_left) |
04673275441a
switched notations for pointwise and multiset order
haftmann
parents:
35028
diff
changeset
|
311 |
|
04673275441a
switched notations for pointwise and multiset order
haftmann
parents:
35028
diff
changeset
|
312 |
lemma mset_le_mono_add: |
04673275441a
switched notations for pointwise and multiset order
haftmann
parents:
35028
diff
changeset
|
313 |
"(A::'a multiset) \<le> B \<Longrightarrow> C \<le> D \<Longrightarrow> A + C \<le> B + D" |
04673275441a
switched notations for pointwise and multiset order
haftmann
parents:
35028
diff
changeset
|
314 |
by (fact add_mono) |
34943
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
315 |
|
35268
04673275441a
switched notations for pointwise and multiset order
haftmann
parents:
35028
diff
changeset
|
316 |
lemma mset_le_add_left [simp]: |
04673275441a
switched notations for pointwise and multiset order
haftmann
parents:
35028
diff
changeset
|
317 |
"(A::'a multiset) \<le> A + B" |
04673275441a
switched notations for pointwise and multiset order
haftmann
parents:
35028
diff
changeset
|
318 |
unfolding mset_le_def by auto |
04673275441a
switched notations for pointwise and multiset order
haftmann
parents:
35028
diff
changeset
|
319 |
|
04673275441a
switched notations for pointwise and multiset order
haftmann
parents:
35028
diff
changeset
|
320 |
lemma mset_le_add_right [simp]: |
04673275441a
switched notations for pointwise and multiset order
haftmann
parents:
35028
diff
changeset
|
321 |
"B \<le> (A::'a multiset) + B" |
04673275441a
switched notations for pointwise and multiset order
haftmann
parents:
35028
diff
changeset
|
322 |
unfolding mset_le_def by auto |
34943
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
323 |
|
35268
04673275441a
switched notations for pointwise and multiset order
haftmann
parents:
35028
diff
changeset
|
324 |
lemma mset_le_single: |
04673275441a
switched notations for pointwise and multiset order
haftmann
parents:
35028
diff
changeset
|
325 |
"a :# B \<Longrightarrow> {#a#} \<le> B" |
04673275441a
switched notations for pointwise and multiset order
haftmann
parents:
35028
diff
changeset
|
326 |
by (simp add: mset_le_def) |
34943
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
327 |
|
35268
04673275441a
switched notations for pointwise and multiset order
haftmann
parents:
35028
diff
changeset
|
328 |
lemma multiset_diff_union_assoc: |
04673275441a
switched notations for pointwise and multiset order
haftmann
parents:
35028
diff
changeset
|
329 |
"C \<le> B \<Longrightarrow> (A::'a multiset) + B - C = A + (B - C)" |
04673275441a
switched notations for pointwise and multiset order
haftmann
parents:
35028
diff
changeset
|
330 |
by (simp add: multiset_eq_conv_count_eq mset_le_def) |
34943
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
331 |
|
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
332 |
lemma mset_le_multiset_union_diff_commute: |
35268
04673275441a
switched notations for pointwise and multiset order
haftmann
parents:
35028
diff
changeset
|
333 |
assumes "B \<le> A" |
04673275441a
switched notations for pointwise and multiset order
haftmann
parents:
35028
diff
changeset
|
334 |
shows "(A::'a multiset) - B + C = A + C - B" |
34943
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
335 |
proof - |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
336 |
from mset_le_exists_conv [of "B" "A"] assms have "\<exists>D. A = B + D" .. |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
337 |
from this obtain D where "A = B + D" .. |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
338 |
then show ?thesis |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
339 |
apply simp |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
340 |
apply (subst add_commute) |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
341 |
apply (subst multiset_diff_union_assoc) |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
342 |
apply simp |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
343 |
apply (simp add: diff_cancel) |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
344 |
apply (subst add_assoc) |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
345 |
apply (subst add_commute [of "B" _]) |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
346 |
apply (subst multiset_diff_union_assoc) |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
347 |
apply simp |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
348 |
apply (simp add: diff_cancel) |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
349 |
done |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
350 |
qed |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
351 |
|
35268
04673275441a
switched notations for pointwise and multiset order
haftmann
parents:
35028
diff
changeset
|
352 |
lemma mset_lessD: "A < B \<Longrightarrow> x \<in># A \<Longrightarrow> x \<in># B" |
34943
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
353 |
apply (clarsimp simp: mset_le_def mset_less_def) |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
354 |
apply (erule_tac x=x in allE) |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
355 |
apply auto |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
356 |
done |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
357 |
|
35268
04673275441a
switched notations for pointwise and multiset order
haftmann
parents:
35028
diff
changeset
|
358 |
lemma mset_leD: "A \<le> B \<Longrightarrow> x \<in># A \<Longrightarrow> x \<in># B" |
34943
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
359 |
apply (clarsimp simp: mset_le_def mset_less_def) |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
360 |
apply (erule_tac x = x in allE) |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
361 |
apply auto |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
362 |
done |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
363 |
|
35268
04673275441a
switched notations for pointwise and multiset order
haftmann
parents:
35028
diff
changeset
|
364 |
lemma mset_less_insertD: "(A + {#x#} < B) \<Longrightarrow> (x \<in># B \<and> A < B)" |
34943
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
365 |
apply (rule conjI) |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
366 |
apply (simp add: mset_lessD) |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
367 |
apply (clarsimp simp: mset_le_def mset_less_def) |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
368 |
apply safe |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
369 |
apply (erule_tac x = a in allE) |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
370 |
apply (auto split: split_if_asm) |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
371 |
done |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
372 |
|
35268
04673275441a
switched notations for pointwise and multiset order
haftmann
parents:
35028
diff
changeset
|
373 |
lemma mset_le_insertD: "(A + {#x#} \<le> B) \<Longrightarrow> (x \<in># B \<and> A \<le> B)" |
34943
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
374 |
apply (rule conjI) |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
375 |
apply (simp add: mset_leD) |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
376 |
apply (force simp: mset_le_def mset_less_def split: split_if_asm) |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
377 |
done |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
378 |
|
35268
04673275441a
switched notations for pointwise and multiset order
haftmann
parents:
35028
diff
changeset
|
379 |
lemma mset_less_of_empty[simp]: "A < {#} \<longleftrightarrow> False" |
34943
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
380 |
by (auto simp add: mset_less_def mset_le_def multiset_eq_conv_count_eq) |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
381 |
|
35268
04673275441a
switched notations for pointwise and multiset order
haftmann
parents:
35028
diff
changeset
|
382 |
lemma multi_psub_of_add_self[simp]: "A < A + {#x#}" |
04673275441a
switched notations for pointwise and multiset order
haftmann
parents:
35028
diff
changeset
|
383 |
by (auto simp: mset_le_def mset_less_def) |
34943
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
384 |
|
35268
04673275441a
switched notations for pointwise and multiset order
haftmann
parents:
35028
diff
changeset
|
385 |
lemma multi_psub_self[simp]: "(A::'a multiset) < A = False" |
04673275441a
switched notations for pointwise and multiset order
haftmann
parents:
35028
diff
changeset
|
386 |
by simp |
34943
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
387 |
|
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
388 |
lemma mset_less_add_bothsides: |
35268
04673275441a
switched notations for pointwise and multiset order
haftmann
parents:
35028
diff
changeset
|
389 |
"T + {#x#} < S + {#x#} \<Longrightarrow> T < S" |
04673275441a
switched notations for pointwise and multiset order
haftmann
parents:
35028
diff
changeset
|
390 |
by (fact add_less_imp_less_right) |
04673275441a
switched notations for pointwise and multiset order
haftmann
parents:
35028
diff
changeset
|
391 |
|
04673275441a
switched notations for pointwise and multiset order
haftmann
parents:
35028
diff
changeset
|
392 |
lemma mset_less_empty_nonempty: |
04673275441a
switched notations for pointwise and multiset order
haftmann
parents:
35028
diff
changeset
|
393 |
"{#} < S \<longleftrightarrow> S \<noteq> {#}" |
04673275441a
switched notations for pointwise and multiset order
haftmann
parents:
35028
diff
changeset
|
394 |
by (auto simp: mset_le_def mset_less_def) |
04673275441a
switched notations for pointwise and multiset order
haftmann
parents:
35028
diff
changeset
|
395 |
|
04673275441a
switched notations for pointwise and multiset order
haftmann
parents:
35028
diff
changeset
|
396 |
lemma mset_less_diff_self: |
04673275441a
switched notations for pointwise and multiset order
haftmann
parents:
35028
diff
changeset
|
397 |
"c \<in># B \<Longrightarrow> B - {#c#} < B" |
04673275441a
switched notations for pointwise and multiset order
haftmann
parents:
35028
diff
changeset
|
398 |
by (auto simp: mset_le_def mset_less_def multiset_eq_conv_count_eq) |
04673275441a
switched notations for pointwise and multiset order
haftmann
parents:
35028
diff
changeset
|
399 |
|
04673275441a
switched notations for pointwise and multiset order
haftmann
parents:
35028
diff
changeset
|
400 |
|
04673275441a
switched notations for pointwise and multiset order
haftmann
parents:
35028
diff
changeset
|
401 |
subsubsection {* Intersection *} |
04673275441a
switched notations for pointwise and multiset order
haftmann
parents:
35028
diff
changeset
|
402 |
|
04673275441a
switched notations for pointwise and multiset order
haftmann
parents:
35028
diff
changeset
|
403 |
instantiation multiset :: (type) semilattice_inf |
04673275441a
switched notations for pointwise and multiset order
haftmann
parents:
35028
diff
changeset
|
404 |
begin |
04673275441a
switched notations for pointwise and multiset order
haftmann
parents:
35028
diff
changeset
|
405 |
|
04673275441a
switched notations for pointwise and multiset order
haftmann
parents:
35028
diff
changeset
|
406 |
definition inf_multiset :: "'a multiset \<Rightarrow> 'a multiset \<Rightarrow> 'a multiset" where |
04673275441a
switched notations for pointwise and multiset order
haftmann
parents:
35028
diff
changeset
|
407 |
multiset_inter_def: "inf_multiset A B = A - (A - B)" |
04673275441a
switched notations for pointwise and multiset order
haftmann
parents:
35028
diff
changeset
|
408 |
|
04673275441a
switched notations for pointwise and multiset order
haftmann
parents:
35028
diff
changeset
|
409 |
instance proof - |
04673275441a
switched notations for pointwise and multiset order
haftmann
parents:
35028
diff
changeset
|
410 |
have aux: "\<And>m n q :: nat. m \<le> n \<Longrightarrow> m \<le> q \<Longrightarrow> m \<le> n - (n - q)" by arith |
04673275441a
switched notations for pointwise and multiset order
haftmann
parents:
35028
diff
changeset
|
411 |
show "OFCLASS('a multiset, semilattice_inf_class)" proof |
04673275441a
switched notations for pointwise and multiset order
haftmann
parents:
35028
diff
changeset
|
412 |
qed (auto simp add: multiset_inter_def mset_le_def aux) |
04673275441a
switched notations for pointwise and multiset order
haftmann
parents:
35028
diff
changeset
|
413 |
qed |
04673275441a
switched notations for pointwise and multiset order
haftmann
parents:
35028
diff
changeset
|
414 |
|
04673275441a
switched notations for pointwise and multiset order
haftmann
parents:
35028
diff
changeset
|
415 |
end |
04673275441a
switched notations for pointwise and multiset order
haftmann
parents:
35028
diff
changeset
|
416 |
|
04673275441a
switched notations for pointwise and multiset order
haftmann
parents:
35028
diff
changeset
|
417 |
abbreviation multiset_inter :: "'a multiset \<Rightarrow> 'a multiset \<Rightarrow> 'a multiset" (infixl "#\<inter>" 70) where |
04673275441a
switched notations for pointwise and multiset order
haftmann
parents:
35028
diff
changeset
|
418 |
"multiset_inter \<equiv> inf" |
34943
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
419 |
|
35268
04673275441a
switched notations for pointwise and multiset order
haftmann
parents:
35028
diff
changeset
|
420 |
lemma multiset_inter_count: |
04673275441a
switched notations for pointwise and multiset order
haftmann
parents:
35028
diff
changeset
|
421 |
"count (A #\<inter> B) x = min (count A x) (count B x)" |
04673275441a
switched notations for pointwise and multiset order
haftmann
parents:
35028
diff
changeset
|
422 |
by (simp add: multiset_inter_def multiset_typedef) |
04673275441a
switched notations for pointwise and multiset order
haftmann
parents:
35028
diff
changeset
|
423 |
|
04673275441a
switched notations for pointwise and multiset order
haftmann
parents:
35028
diff
changeset
|
424 |
lemma multiset_inter_single: "a \<noteq> b \<Longrightarrow> {#a#} #\<inter> {#b#} = {#}" |
04673275441a
switched notations for pointwise and multiset order
haftmann
parents:
35028
diff
changeset
|
425 |
by (rule multi_count_ext) (auto simp add: multiset_inter_count) |
34943
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
426 |
|
35268
04673275441a
switched notations for pointwise and multiset order
haftmann
parents:
35028
diff
changeset
|
427 |
lemma multiset_union_diff_commute: |
04673275441a
switched notations for pointwise and multiset order
haftmann
parents:
35028
diff
changeset
|
428 |
assumes "B #\<inter> C = {#}" |
04673275441a
switched notations for pointwise and multiset order
haftmann
parents:
35028
diff
changeset
|
429 |
shows "A + B - C = A - C + B" |
04673275441a
switched notations for pointwise and multiset order
haftmann
parents:
35028
diff
changeset
|
430 |
proof (rule multi_count_ext) |
04673275441a
switched notations for pointwise and multiset order
haftmann
parents:
35028
diff
changeset
|
431 |
fix x |
04673275441a
switched notations for pointwise and multiset order
haftmann
parents:
35028
diff
changeset
|
432 |
from assms have "min (count B x) (count C x) = 0" |
04673275441a
switched notations for pointwise and multiset order
haftmann
parents:
35028
diff
changeset
|
433 |
by (auto simp add: multiset_inter_count multiset_eq_conv_count_eq) |
04673275441a
switched notations for pointwise and multiset order
haftmann
parents:
35028
diff
changeset
|
434 |
then have "count B x = 0 \<or> count C x = 0" |
04673275441a
switched notations for pointwise and multiset order
haftmann
parents:
35028
diff
changeset
|
435 |
by auto |
04673275441a
switched notations for pointwise and multiset order
haftmann
parents:
35028
diff
changeset
|
436 |
then show "count (A + B - C) x = count (A - C + B) x" |
04673275441a
switched notations for pointwise and multiset order
haftmann
parents:
35028
diff
changeset
|
437 |
by auto |
04673275441a
switched notations for pointwise and multiset order
haftmann
parents:
35028
diff
changeset
|
438 |
qed |
04673275441a
switched notations for pointwise and multiset order
haftmann
parents:
35028
diff
changeset
|
439 |
|
04673275441a
switched notations for pointwise and multiset order
haftmann
parents:
35028
diff
changeset
|
440 |
|
04673275441a
switched notations for pointwise and multiset order
haftmann
parents:
35028
diff
changeset
|
441 |
subsubsection {* Comprehension (filter) *} |
04673275441a
switched notations for pointwise and multiset order
haftmann
parents:
35028
diff
changeset
|
442 |
|
04673275441a
switched notations for pointwise and multiset order
haftmann
parents:
35028
diff
changeset
|
443 |
lemma count_MCollect [simp]: |
04673275441a
switched notations for pointwise and multiset order
haftmann
parents:
35028
diff
changeset
|
444 |
"count {# x:#M. P x #} a = (if P a then count M a else 0)" |
04673275441a
switched notations for pointwise and multiset order
haftmann
parents:
35028
diff
changeset
|
445 |
by (simp add: MCollect_def in_multiset multiset_typedef) |
04673275441a
switched notations for pointwise and multiset order
haftmann
parents:
35028
diff
changeset
|
446 |
|
04673275441a
switched notations for pointwise and multiset order
haftmann
parents:
35028
diff
changeset
|
447 |
lemma MCollect_empty [simp]: "MCollect {#} P = {#}" |
04673275441a
switched notations for pointwise and multiset order
haftmann
parents:
35028
diff
changeset
|
448 |
by (rule multi_count_ext) simp |
04673275441a
switched notations for pointwise and multiset order
haftmann
parents:
35028
diff
changeset
|
449 |
|
04673275441a
switched notations for pointwise and multiset order
haftmann
parents:
35028
diff
changeset
|
450 |
lemma MCollect_single [simp]: |
04673275441a
switched notations for pointwise and multiset order
haftmann
parents:
35028
diff
changeset
|
451 |
"MCollect {#x#} P = (if P x then {#x#} else {#})" |
04673275441a
switched notations for pointwise and multiset order
haftmann
parents:
35028
diff
changeset
|
452 |
by (rule multi_count_ext) simp |
04673275441a
switched notations for pointwise and multiset order
haftmann
parents:
35028
diff
changeset
|
453 |
|
04673275441a
switched notations for pointwise and multiset order
haftmann
parents:
35028
diff
changeset
|
454 |
lemma MCollect_union [simp]: |
04673275441a
switched notations for pointwise and multiset order
haftmann
parents:
35028
diff
changeset
|
455 |
"MCollect (M + N) f = MCollect M f + MCollect N f" |
04673275441a
switched notations for pointwise and multiset order
haftmann
parents:
35028
diff
changeset
|
456 |
by (rule multi_count_ext) simp |
10249 | 457 |
|
458 |
||
459 |
subsubsection {* Set of elements *} |
|
460 |
||
34943
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
461 |
definition set_of :: "'a multiset => 'a set" where |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
462 |
"set_of M = {x. x :# M}" |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
463 |
|
17161 | 464 |
lemma set_of_empty [simp]: "set_of {#} = {}" |
26178 | 465 |
by (simp add: set_of_def) |
10249 | 466 |
|
17161 | 467 |
lemma set_of_single [simp]: "set_of {#b#} = {b}" |
26178 | 468 |
by (simp add: set_of_def) |
10249 | 469 |
|
17161 | 470 |
lemma set_of_union [simp]: "set_of (M + N) = set_of M \<union> set_of N" |
26178 | 471 |
by (auto simp add: set_of_def) |
10249 | 472 |
|
17161 | 473 |
lemma set_of_eq_empty_iff [simp]: "(set_of M = {}) = (M = {#})" |
34943
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
474 |
by (auto simp add: set_of_def multiset_eq_conv_count_eq) |
10249 | 475 |
|
17161 | 476 |
lemma mem_set_of_iff [simp]: "(x \<in> set_of M) = (x :# M)" |
26178 | 477 |
by (auto simp add: set_of_def) |
26016 | 478 |
|
26033 | 479 |
lemma set_of_MCollect [simp]: "set_of {# x:#M. P x #} = set_of M \<inter> {x. P x}" |
26178 | 480 |
by (auto simp add: set_of_def) |
10249 | 481 |
|
34943
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
482 |
lemma finite_set_of [iff]: "finite (set_of M)" |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
483 |
using count [of M] by (simp add: multiset_def set_of_def) |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
484 |
|
10249 | 485 |
|
486 |
subsubsection {* Size *} |
|
487 |
||
34943
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
488 |
instantiation multiset :: (type) size |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
489 |
begin |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
490 |
|
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
491 |
definition size_def: |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
492 |
"size M = setsum (count M) (set_of M)" |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
493 |
|
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
494 |
instance .. |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
495 |
|
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
496 |
end |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
497 |
|
28708
a1a436f09ec6
explicit check for pattern discipline before code translation
haftmann
parents:
28562
diff
changeset
|
498 |
lemma size_empty [simp]: "size {#} = 0" |
26178 | 499 |
by (simp add: size_def) |
10249 | 500 |
|
28708
a1a436f09ec6
explicit check for pattern discipline before code translation
haftmann
parents:
28562
diff
changeset
|
501 |
lemma size_single [simp]: "size {#b#} = 1" |
26178 | 502 |
by (simp add: size_def) |
10249 | 503 |
|
17161 | 504 |
lemma setsum_count_Int: |
26178 | 505 |
"finite A ==> setsum (count N) (A \<inter> set_of N) = setsum (count N) A" |
506 |
apply (induct rule: finite_induct) |
|
507 |
apply simp |
|
508 |
apply (simp add: Int_insert_left set_of_def) |
|
509 |
done |
|
10249 | 510 |
|
28708
a1a436f09ec6
explicit check for pattern discipline before code translation
haftmann
parents:
28562
diff
changeset
|
511 |
lemma size_union [simp]: "size (M + N::'a multiset) = size M + size N" |
26178 | 512 |
apply (unfold size_def) |
513 |
apply (subgoal_tac "count (M + N) = (\<lambda>a. count M a + count N a)") |
|
514 |
prefer 2 |
|
515 |
apply (rule ext, simp) |
|
516 |
apply (simp (no_asm_simp) add: setsum_Un_nat setsum_addf setsum_count_Int) |
|
517 |
apply (subst Int_commute) |
|
518 |
apply (simp (no_asm_simp) add: setsum_count_Int) |
|
519 |
done |
|
10249 | 520 |
|
17161 | 521 |
lemma size_eq_0_iff_empty [iff]: "(size M = 0) = (M = {#})" |
34943
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
522 |
by (auto simp add: size_def multiset_eq_conv_count_eq) |
26016 | 523 |
|
524 |
lemma nonempty_has_size: "(S \<noteq> {#}) = (0 < size S)" |
|
26178 | 525 |
by (metis gr0I gr_implies_not0 size_empty size_eq_0_iff_empty) |
10249 | 526 |
|
17161 | 527 |
lemma size_eq_Suc_imp_elem: "size M = Suc n ==> \<exists>a. a :# M" |
26178 | 528 |
apply (unfold size_def) |
529 |
apply (drule setsum_SucD) |
|
530 |
apply auto |
|
531 |
done |
|
10249 | 532 |
|
34943
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
533 |
lemma size_eq_Suc_imp_eq_union: |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
534 |
assumes "size M = Suc n" |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
535 |
shows "\<exists>a N. M = N + {#a#}" |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
536 |
proof - |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
537 |
from assms obtain a where "a \<in># M" |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
538 |
by (erule size_eq_Suc_imp_elem [THEN exE]) |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
539 |
then have "M = M - {#a#} + {#a#}" by simp |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
540 |
then show ?thesis by blast |
23611 | 541 |
qed |
15869 | 542 |
|
26016 | 543 |
|
544 |
subsection {* Induction and case splits *} |
|
10249 | 545 |
|
546 |
lemma setsum_decr: |
|
11701
3d51fbf81c17
sane numerals (stage 1): added generic 1, removed 1' and 2 on nat,
wenzelm
parents:
11655
diff
changeset
|
547 |
"finite F ==> (0::nat) < f a ==> |
15072 | 548 |
setsum (f (a := f a - 1)) F = (if a\<in>F then setsum f F - 1 else setsum f F)" |
26178 | 549 |
apply (induct rule: finite_induct) |
550 |
apply auto |
|
551 |
apply (drule_tac a = a in mk_disjoint_insert, auto) |
|
552 |
done |
|
10249 | 553 |
|
10313 | 554 |
lemma rep_multiset_induct_aux: |
26178 | 555 |
assumes 1: "P (\<lambda>a. (0::nat))" |
556 |
and 2: "!!f b. f \<in> multiset ==> P f ==> P (f (b := f b + 1))" |
|
557 |
shows "\<forall>f. f \<in> multiset --> setsum f {x. f x \<noteq> 0} = n --> P f" |
|
558 |
apply (unfold multiset_def) |
|
559 |
apply (induct_tac n, simp, clarify) |
|
560 |
apply (subgoal_tac "f = (\<lambda>a.0)") |
|
561 |
apply simp |
|
562 |
apply (rule 1) |
|
563 |
apply (rule ext, force, clarify) |
|
564 |
apply (frule setsum_SucD, clarify) |
|
565 |
apply (rename_tac a) |
|
566 |
apply (subgoal_tac "finite {x. (f (a := f a - 1)) x > 0}") |
|
567 |
prefer 2 |
|
568 |
apply (rule finite_subset) |
|
569 |
prefer 2 |
|
570 |
apply assumption |
|
571 |
apply simp |
|
572 |
apply blast |
|
573 |
apply (subgoal_tac "f = (f (a := f a - 1))(a := (f (a := f a - 1)) a + 1)") |
|
574 |
prefer 2 |
|
575 |
apply (rule ext) |
|
576 |
apply (simp (no_asm_simp)) |
|
577 |
apply (erule ssubst, rule 2 [unfolded multiset_def], blast) |
|
578 |
apply (erule allE, erule impE, erule_tac [2] mp, blast) |
|
579 |
apply (simp (no_asm_simp) add: setsum_decr del: fun_upd_apply One_nat_def) |
|
580 |
apply (subgoal_tac "{x. x \<noteq> a --> f x \<noteq> 0} = {x. f x \<noteq> 0}") |
|
581 |
prefer 2 |
|
582 |
apply blast |
|
583 |
apply (subgoal_tac "{x. x \<noteq> a \<and> f x \<noteq> 0} = {x. f x \<noteq> 0} - {a}") |
|
584 |
prefer 2 |
|
585 |
apply blast |
|
586 |
apply (simp add: le_imp_diff_is_add setsum_diff1_nat cong: conj_cong) |
|
587 |
done |
|
10249 | 588 |
|
10313 | 589 |
theorem rep_multiset_induct: |
11464 | 590 |
"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
|
591 |
(!!f b. f \<in> multiset ==> P f ==> P (f (b := f b + 1))) ==> P f" |
26178 | 592 |
using rep_multiset_induct_aux by blast |
10249 | 593 |
|
18258 | 594 |
theorem multiset_induct [case_names empty add, induct type: multiset]: |
26178 | 595 |
assumes empty: "P {#}" |
596 |
and add: "!!M x. P M ==> P (M + {#x#})" |
|
597 |
shows "P M" |
|
10249 | 598 |
proof - |
599 |
note defns = union_def single_def Mempty_def |
|
34943
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
600 |
note add' = add [unfolded defns, simplified] |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
601 |
have aux: "\<And>a::'a. count (Abs_multiset (\<lambda>b. if b = a then 1 else 0)) = |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
602 |
(\<lambda>b. if b = a then 1 else 0)" by (simp add: Abs_multiset_inverse in_multiset) |
10249 | 603 |
show ?thesis |
34943
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
604 |
apply (rule count_inverse [THEN subst]) |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
605 |
apply (rule count [THEN rep_multiset_induct]) |
18258 | 606 |
apply (rule empty [unfolded defns]) |
15072 | 607 |
apply (subgoal_tac "f(b := f b + 1) = (\<lambda>a. f a + (if a=b then 1 else 0))") |
10249 | 608 |
prefer 2 |
609 |
apply (simp add: expand_fun_eq) |
|
610 |
apply (erule ssubst) |
|
17200 | 611 |
apply (erule Abs_multiset_inverse [THEN subst]) |
34943
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
612 |
apply (drule add') |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
613 |
apply (simp add: aux) |
10249 | 614 |
done |
615 |
qed |
|
616 |
||
25610 | 617 |
lemma multi_nonempty_split: "M \<noteq> {#} \<Longrightarrow> \<exists>A a. M = A + {#a#}" |
26178 | 618 |
by (induct M) auto |
25610 | 619 |
|
620 |
lemma multiset_cases [cases type, case_names empty add]: |
|
26178 | 621 |
assumes em: "M = {#} \<Longrightarrow> P" |
622 |
assumes add: "\<And>N x. M = N + {#x#} \<Longrightarrow> P" |
|
623 |
shows "P" |
|
25610 | 624 |
proof (cases "M = {#}") |
26145 | 625 |
assume "M = {#}" then show ?thesis using em by simp |
25610 | 626 |
next |
627 |
assume "M \<noteq> {#}" |
|
628 |
then obtain M' m where "M = M' + {#m#}" |
|
629 |
by (blast dest: multi_nonempty_split) |
|
26145 | 630 |
then show ?thesis using add by simp |
25610 | 631 |
qed |
632 |
||
633 |
lemma multi_member_split: "x \<in># M \<Longrightarrow> \<exists>A. M = A + {#x#}" |
|
26178 | 634 |
apply (cases M) |
635 |
apply simp |
|
636 |
apply (rule_tac x="M - {#x#}" in exI, simp) |
|
637 |
done |
|
25610 | 638 |
|
34943
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
639 |
lemma multi_drop_mem_not_eq: "c \<in># B \<Longrightarrow> B - {#c#} \<noteq> B" |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
640 |
by (cases "B = {#}") (auto dest: multi_member_split) |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
641 |
|
26033 | 642 |
lemma multiset_partition: "M = {# x:#M. P x #} + {# x:#M. \<not> P x #}" |
26178 | 643 |
apply (subst multiset_eq_conv_count_eq) |
644 |
apply auto |
|
645 |
done |
|
10249 | 646 |
|
35268
04673275441a
switched notations for pointwise and multiset order
haftmann
parents:
35028
diff
changeset
|
647 |
lemma mset_less_size: "(A::'a multiset) < B \<Longrightarrow> size A < size B" |
34943
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
648 |
proof (induct A arbitrary: B) |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
649 |
case (empty M) |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
650 |
then have "M \<noteq> {#}" by (simp add: mset_less_empty_nonempty) |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
651 |
then obtain M' x where "M = M' + {#x#}" |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
652 |
by (blast dest: multi_nonempty_split) |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
653 |
then show ?case by simp |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
654 |
next |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
655 |
case (add S x T) |
35268
04673275441a
switched notations for pointwise and multiset order
haftmann
parents:
35028
diff
changeset
|
656 |
have IH: "\<And>B. S < B \<Longrightarrow> size S < size B" by fact |
04673275441a
switched notations for pointwise and multiset order
haftmann
parents:
35028
diff
changeset
|
657 |
have SxsubT: "S + {#x#} < T" by fact |
04673275441a
switched notations for pointwise and multiset order
haftmann
parents:
35028
diff
changeset
|
658 |
then have "x \<in># T" and "S < T" by (auto dest: mset_less_insertD) |
34943
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
659 |
then obtain T' where T: "T = T' + {#x#}" |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
660 |
by (blast dest: multi_member_split) |
35268
04673275441a
switched notations for pointwise and multiset order
haftmann
parents:
35028
diff
changeset
|
661 |
then have "S < T'" using SxsubT |
34943
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
662 |
by (blast intro: mset_less_add_bothsides) |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
663 |
then have "size S < size T'" using IH by simp |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
664 |
then show ?case using T by simp |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
665 |
qed |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
666 |
|
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
667 |
|
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
668 |
subsubsection {* Strong induction and subset induction for multisets *} |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
669 |
|
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
670 |
text {* Well-foundedness of proper subset operator: *} |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
671 |
|
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
672 |
text {* proper multiset subset *} |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
673 |
|
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
674 |
definition |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
675 |
mset_less_rel :: "('a multiset * 'a multiset) set" where |
35268
04673275441a
switched notations for pointwise and multiset order
haftmann
parents:
35028
diff
changeset
|
676 |
"mset_less_rel = {(A,B). A < B}" |
10249 | 677 |
|
34943
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
678 |
lemma multiset_add_sub_el_shuffle: |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
679 |
assumes "c \<in># B" and "b \<noteq> c" |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
680 |
shows "B - {#c#} + {#b#} = B + {#b#} - {#c#}" |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
681 |
proof - |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
682 |
from `c \<in># B` obtain A where B: "B = A + {#c#}" |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
683 |
by (blast dest: multi_member_split) |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
684 |
have "A + {#b#} = A + {#b#} + {#c#} - {#c#}" by simp |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
685 |
then have "A + {#b#} = A + {#c#} + {#b#} - {#c#}" |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
686 |
by (simp add: add_ac) |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
687 |
then show ?thesis using B by simp |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
688 |
qed |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
689 |
|
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
690 |
lemma wf_mset_less_rel: "wf mset_less_rel" |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
691 |
apply (unfold mset_less_rel_def) |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
692 |
apply (rule wf_measure [THEN wf_subset, where f1=size]) |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
693 |
apply (clarsimp simp: measure_def inv_image_def mset_less_size) |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
694 |
done |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
695 |
|
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
696 |
text {* The induction rules: *} |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
697 |
|
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
698 |
lemma full_multiset_induct [case_names less]: |
35268
04673275441a
switched notations for pointwise and multiset order
haftmann
parents:
35028
diff
changeset
|
699 |
assumes ih: "\<And>B. \<forall>(A::'a multiset). A < B \<longrightarrow> P A \<Longrightarrow> P B" |
34943
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
700 |
shows "P B" |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
701 |
apply (rule wf_mset_less_rel [THEN wf_induct]) |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
702 |
apply (rule ih, auto simp: mset_less_rel_def) |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
703 |
done |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
704 |
|
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
705 |
lemma multi_subset_induct [consumes 2, case_names empty add]: |
35268
04673275441a
switched notations for pointwise and multiset order
haftmann
parents:
35028
diff
changeset
|
706 |
assumes "F \<le> A" |
34943
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
707 |
and empty: "P {#}" |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
708 |
and insert: "\<And>a F. a \<in># A \<Longrightarrow> P F \<Longrightarrow> P (F + {#a#})" |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
709 |
shows "P F" |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
710 |
proof - |
35268
04673275441a
switched notations for pointwise and multiset order
haftmann
parents:
35028
diff
changeset
|
711 |
from `F \<le> A` |
34943
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
712 |
show ?thesis |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
713 |
proof (induct F) |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
714 |
show "P {#}" by fact |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
715 |
next |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
716 |
fix x F |
35268
04673275441a
switched notations for pointwise and multiset order
haftmann
parents:
35028
diff
changeset
|
717 |
assume P: "F \<le> A \<Longrightarrow> P F" and i: "F + {#x#} \<le> A" |
34943
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
718 |
show "P (F + {#x#})" |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
719 |
proof (rule insert) |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
720 |
from i show "x \<in># A" by (auto dest: mset_le_insertD) |
35268
04673275441a
switched notations for pointwise and multiset order
haftmann
parents:
35028
diff
changeset
|
721 |
from i have "F \<le> A" by (auto dest: mset_le_insertD) |
34943
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
722 |
with P show "P F" . |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
723 |
qed |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
724 |
qed |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
725 |
qed |
26145 | 726 |
|
17161 | 727 |
|
34943
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
728 |
subsection {* Alternative representations *} |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
729 |
|
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
730 |
subsubsection {* Lists *} |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
731 |
|
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
732 |
primrec multiset_of :: "'a list \<Rightarrow> 'a multiset" where |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
733 |
"multiset_of [] = {#}" | |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
734 |
"multiset_of (a # x) = multiset_of x + {# a #}" |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
735 |
|
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
736 |
lemma multiset_of_zero_iff[simp]: "(multiset_of x = {#}) = (x = [])" |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
737 |
by (induct x) auto |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
738 |
|
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
739 |
lemma multiset_of_zero_iff_right[simp]: "({#} = multiset_of x) = (x = [])" |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
740 |
by (induct x) auto |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
741 |
|
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
742 |
lemma set_of_multiset_of[simp]: "set_of(multiset_of x) = set x" |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
743 |
by (induct x) auto |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
744 |
|
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
745 |
lemma mem_set_multiset_eq: "x \<in> set xs = (x :# multiset_of xs)" |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
746 |
by (induct xs) auto |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
747 |
|
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
748 |
lemma multiset_of_append [simp]: |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
749 |
"multiset_of (xs @ ys) = multiset_of xs + multiset_of ys" |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
750 |
by (induct xs arbitrary: ys) (auto simp: add_ac) |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
751 |
|
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
752 |
lemma surj_multiset_of: "surj multiset_of" |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
753 |
apply (unfold surj_def) |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
754 |
apply (rule allI) |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
755 |
apply (rule_tac M = y in multiset_induct) |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
756 |
apply auto |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
757 |
apply (rule_tac x = "x # xa" in exI) |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
758 |
apply auto |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
759 |
done |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
760 |
|
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
761 |
lemma set_count_greater_0: "set x = {a. count (multiset_of x) a > 0}" |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
762 |
by (induct x) auto |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
763 |
|
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
764 |
lemma distinct_count_atmost_1: |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
765 |
"distinct x = (! a. count (multiset_of x) a = (if a \<in> set x then 1 else 0))" |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
766 |
apply (induct x, simp, rule iffI, simp_all) |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
767 |
apply (rule conjI) |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
768 |
apply (simp_all add: set_of_multiset_of [THEN sym] del: set_of_multiset_of) |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
769 |
apply (erule_tac x = a in allE, simp, clarify) |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
770 |
apply (erule_tac x = aa in allE, simp) |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
771 |
done |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
772 |
|
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
773 |
lemma multiset_of_eq_setD: |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
774 |
"multiset_of xs = multiset_of ys \<Longrightarrow> set xs = set ys" |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
775 |
by (rule) (auto simp add:multiset_eq_conv_count_eq set_count_greater_0) |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
776 |
|
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
777 |
lemma set_eq_iff_multiset_of_eq_distinct: |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
778 |
"distinct x \<Longrightarrow> distinct y \<Longrightarrow> |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
779 |
(set x = set y) = (multiset_of x = multiset_of y)" |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
780 |
by (auto simp: multiset_eq_conv_count_eq distinct_count_atmost_1) |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
781 |
|
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
782 |
lemma set_eq_iff_multiset_of_remdups_eq: |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
783 |
"(set x = set y) = (multiset_of (remdups x) = multiset_of (remdups y))" |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
784 |
apply (rule iffI) |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
785 |
apply (simp add: set_eq_iff_multiset_of_eq_distinct[THEN iffD1]) |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
786 |
apply (drule distinct_remdups [THEN distinct_remdups |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
787 |
[THEN set_eq_iff_multiset_of_eq_distinct [THEN iffD2]]]) |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
788 |
apply simp |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
789 |
done |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
790 |
|
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
791 |
lemma multiset_of_compl_union [simp]: |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
792 |
"multiset_of [x\<leftarrow>xs. P x] + multiset_of [x\<leftarrow>xs. \<not>P x] = multiset_of xs" |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
793 |
by (induct xs) (auto simp: add_ac) |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
794 |
|
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
795 |
lemma count_filter: |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
796 |
"count (multiset_of xs) x = length [y \<leftarrow> xs. y = x]" |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
797 |
by (induct xs) auto |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
798 |
|
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
799 |
lemma nth_mem_multiset_of: "i < length ls \<Longrightarrow> (ls ! i) :# multiset_of ls" |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
800 |
apply (induct ls arbitrary: i) |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
801 |
apply simp |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
802 |
apply (case_tac i) |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
803 |
apply auto |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
804 |
done |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
805 |
|
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
806 |
lemma multiset_of_remove1: "multiset_of (remove1 a xs) = multiset_of xs - {#a#}" |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
807 |
by (induct xs) (auto simp add: multiset_eq_conv_count_eq) |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
808 |
|
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
809 |
lemma multiset_of_eq_length: |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
810 |
assumes "multiset_of xs = multiset_of ys" |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
811 |
shows "length xs = length ys" |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
812 |
using assms |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
813 |
proof (induct arbitrary: ys rule: length_induct) |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
814 |
case (1 xs ys) |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
815 |
show ?case |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
816 |
proof (cases xs) |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
817 |
case Nil with "1.prems" show ?thesis by simp |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
818 |
next |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
819 |
case (Cons x xs') |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
820 |
note xCons = Cons |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
821 |
show ?thesis |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
822 |
proof (cases ys) |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
823 |
case Nil |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
824 |
with "1.prems" Cons show ?thesis by simp |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
825 |
next |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
826 |
case (Cons y ys') |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
827 |
have x_in_ys: "x = y \<or> x \<in> set ys'" |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
828 |
proof (cases "x = y") |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
829 |
case True then show ?thesis .. |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
830 |
next |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
831 |
case False |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
832 |
from "1.prems" [symmetric] xCons Cons have "x :# multiset_of ys' + {#y#}" by simp |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
833 |
with False show ?thesis by (simp add: mem_set_multiset_eq) |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
834 |
qed |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
835 |
from "1.hyps" have IH: "length xs' < length xs \<longrightarrow> |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
836 |
(\<forall>x. multiset_of xs' = multiset_of x \<longrightarrow> length xs' = length x)" by blast |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
837 |
from "1.prems" x_in_ys Cons xCons have "multiset_of xs' = multiset_of (remove1 x (y#ys'))" |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
838 |
apply - |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
839 |
apply (simp add: multiset_of_remove1, simp only: add_eq_conv_diff) |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
840 |
apply fastsimp |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
841 |
done |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
842 |
with IH xCons have IH': "length xs' = length (remove1 x (y#ys'))" by fastsimp |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
843 |
from x_in_ys have "x \<noteq> y \<Longrightarrow> length ys' > 0" by auto |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
844 |
with Cons xCons x_in_ys IH' show ?thesis by (auto simp add: length_remove1) |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
845 |
qed |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
846 |
qed |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
847 |
qed |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
848 |
|
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
849 |
text {* |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
850 |
This lemma shows which properties suffice to show that a function |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
851 |
@{text "f"} with @{text "f xs = ys"} behaves like sort. |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
852 |
*} |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
853 |
lemma properties_for_sort: |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
854 |
"multiset_of ys = multiset_of xs \<Longrightarrow> sorted ys \<Longrightarrow> sort xs = ys" |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
855 |
proof (induct xs arbitrary: ys) |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
856 |
case Nil then show ?case by simp |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
857 |
next |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
858 |
case (Cons x xs) |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
859 |
then have "x \<in> set ys" |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
860 |
by (auto simp add: mem_set_multiset_eq intro!: ccontr) |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
861 |
with Cons.prems Cons.hyps [of "remove1 x ys"] show ?case |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
862 |
by (simp add: sorted_remove1 multiset_of_remove1 insort_remove1) |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
863 |
qed |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
864 |
|
35268
04673275441a
switched notations for pointwise and multiset order
haftmann
parents:
35028
diff
changeset
|
865 |
lemma multiset_of_remdups_le: "multiset_of (remdups xs) \<le> multiset_of xs" |
04673275441a
switched notations for pointwise and multiset order
haftmann
parents:
35028
diff
changeset
|
866 |
by (induct xs) (auto intro: order_trans) |
34943
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
867 |
|
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
868 |
lemma multiset_of_update: |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
869 |
"i < length ls \<Longrightarrow> multiset_of (ls[i := v]) = multiset_of ls - {#ls ! i#} + {#v#}" |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
870 |
proof (induct ls arbitrary: i) |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
871 |
case Nil then show ?case by simp |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
872 |
next |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
873 |
case (Cons x xs) |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
874 |
show ?case |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
875 |
proof (cases i) |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
876 |
case 0 then show ?thesis by simp |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
877 |
next |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
878 |
case (Suc i') |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
879 |
with Cons show ?thesis |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
880 |
apply simp |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
881 |
apply (subst add_assoc) |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
882 |
apply (subst add_commute [of "{#v#}" "{#x#}"]) |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
883 |
apply (subst add_assoc [symmetric]) |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
884 |
apply simp |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
885 |
apply (rule mset_le_multiset_union_diff_commute) |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
886 |
apply (simp add: mset_le_single nth_mem_multiset_of) |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
887 |
done |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
888 |
qed |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
889 |
qed |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
890 |
|
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
891 |
lemma multiset_of_swap: |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
892 |
"i < length ls \<Longrightarrow> j < length ls \<Longrightarrow> |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
893 |
multiset_of (ls[j := ls ! i, i := ls ! j]) = multiset_of ls" |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
894 |
by (cases "i = j") (simp_all add: multiset_of_update nth_mem_multiset_of) |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
895 |
|
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
896 |
|
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
897 |
subsubsection {* Association lists -- including rudimentary code generation *} |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
898 |
|
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
899 |
definition count_of :: "('a \<times> nat) list \<Rightarrow> 'a \<Rightarrow> nat" where |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
900 |
"count_of xs x = (case map_of xs x of None \<Rightarrow> 0 | Some n \<Rightarrow> n)" |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
901 |
|
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
902 |
lemma count_of_multiset: |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
903 |
"count_of xs \<in> multiset" |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
904 |
proof - |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
905 |
let ?A = "{x::'a. 0 < (case map_of xs x of None \<Rightarrow> 0\<Colon>nat | Some (n\<Colon>nat) \<Rightarrow> n)}" |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
906 |
have "?A \<subseteq> dom (map_of xs)" |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
907 |
proof |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
908 |
fix x |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
909 |
assume "x \<in> ?A" |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
910 |
then have "0 < (case map_of xs x of None \<Rightarrow> 0\<Colon>nat | Some (n\<Colon>nat) \<Rightarrow> n)" by simp |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
911 |
then have "map_of xs x \<noteq> None" by (cases "map_of xs x") auto |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
912 |
then show "x \<in> dom (map_of xs)" by auto |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
913 |
qed |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
914 |
with finite_dom_map_of [of xs] have "finite ?A" |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
915 |
by (auto intro: finite_subset) |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
916 |
then show ?thesis |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
917 |
by (simp add: count_of_def expand_fun_eq multiset_def) |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
918 |
qed |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
919 |
|
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
920 |
lemma count_simps [simp]: |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
921 |
"count_of [] = (\<lambda>_. 0)" |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
922 |
"count_of ((x, n) # xs) = (\<lambda>y. if x = y then n else count_of xs y)" |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
923 |
by (simp_all add: count_of_def expand_fun_eq) |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
924 |
|
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
925 |
lemma count_of_empty: |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
926 |
"x \<notin> fst ` set xs \<Longrightarrow> count_of xs x = 0" |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
927 |
by (induct xs) (simp_all add: count_of_def) |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
928 |
|
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
929 |
lemma count_of_filter: |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
930 |
"count_of (filter (P \<circ> fst) xs) x = (if P x then count_of xs x else 0)" |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
931 |
by (induct xs) auto |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
932 |
|
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
933 |
definition Bag :: "('a \<times> nat) list \<Rightarrow> 'a multiset" where |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
934 |
"Bag xs = Abs_multiset (count_of xs)" |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
935 |
|
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
936 |
code_datatype Bag |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
937 |
|
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
938 |
lemma count_Bag [simp, code]: |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
939 |
"count (Bag xs) = count_of xs" |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
940 |
by (simp add: Bag_def count_of_multiset Abs_multiset_inverse) |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
941 |
|
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
942 |
lemma Mempty_Bag [code]: |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
943 |
"{#} = Bag []" |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
944 |
by (simp add: multiset_eq_conv_count_eq) |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
945 |
|
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
946 |
lemma single_Bag [code]: |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
947 |
"{#x#} = Bag [(x, 1)]" |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
948 |
by (simp add: multiset_eq_conv_count_eq) |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
949 |
|
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
950 |
lemma MCollect_Bag [code]: |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
951 |
"MCollect (Bag xs) P = Bag (filter (P \<circ> fst) xs)" |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
952 |
by (simp add: multiset_eq_conv_count_eq count_of_filter) |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
953 |
|
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
954 |
lemma mset_less_eq_Bag [code]: |
35268
04673275441a
switched notations for pointwise and multiset order
haftmann
parents:
35028
diff
changeset
|
955 |
"Bag xs \<le> A \<longleftrightarrow> (\<forall>(x, n) \<in> set xs. count_of xs x \<le> count A x)" |
34943
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
956 |
(is "?lhs \<longleftrightarrow> ?rhs") |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
957 |
proof |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
958 |
assume ?lhs then show ?rhs |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
959 |
by (auto simp add: mset_le_def count_Bag) |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
960 |
next |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
961 |
assume ?rhs |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
962 |
show ?lhs |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
963 |
proof (rule mset_less_eqI) |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
964 |
fix x |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
965 |
from `?rhs` have "count_of xs x \<le> count A x" |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
966 |
by (cases "x \<in> fst ` set xs") (auto simp add: count_of_empty) |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
967 |
then show "count (Bag xs) x \<le> count A x" |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
968 |
by (simp add: mset_le_def count_Bag) |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
969 |
qed |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
970 |
qed |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
971 |
|
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
972 |
instantiation multiset :: (eq) eq |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
973 |
begin |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
974 |
|
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
975 |
definition |
35268
04673275441a
switched notations for pointwise and multiset order
haftmann
parents:
35028
diff
changeset
|
976 |
"HOL.eq A B \<longleftrightarrow> (A::'a multiset) \<le> B \<and> B \<le> A" |
34943
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
977 |
|
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
978 |
instance proof |
35268
04673275441a
switched notations for pointwise and multiset order
haftmann
parents:
35028
diff
changeset
|
979 |
qed (simp add: eq_multiset_def eq_iff) |
34943
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
980 |
|
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
981 |
end |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
982 |
|
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
983 |
definition (in term_syntax) |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
984 |
bagify :: "('a\<Colon>typerep \<times> nat) list \<times> (unit \<Rightarrow> Code_Evaluation.term) |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
985 |
\<Rightarrow> 'a multiset \<times> (unit \<Rightarrow> Code_Evaluation.term)" where |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
986 |
[code_unfold]: "bagify xs = Code_Evaluation.valtermify Bag {\<cdot>} xs" |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
987 |
|
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
988 |
notation fcomp (infixl "o>" 60) |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
989 |
notation scomp (infixl "o\<rightarrow>" 60) |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
990 |
|
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
991 |
instantiation multiset :: (random) random |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
992 |
begin |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
993 |
|
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
994 |
definition |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
995 |
"Quickcheck.random i = Quickcheck.random i o\<rightarrow> (\<lambda>xs. Pair (bagify xs))" |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
996 |
|
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
997 |
instance .. |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
998 |
|
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
999 |
end |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
1000 |
|
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
1001 |
no_notation fcomp (infixl "o>" 60) |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
1002 |
no_notation scomp (infixl "o\<rightarrow>" 60) |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
1003 |
|
36176
3fe7e97ccca8
replaced generic 'hide' command by more conventional 'hide_class', 'hide_type', 'hide_const', 'hide_fact' -- frees some popular keywords;
wenzelm
parents:
35712
diff
changeset
|
1004 |
hide_const (open) bagify |
34943
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
1005 |
|
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
1006 |
|
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
1007 |
subsection {* The multiset order *} |
10249 | 1008 |
|
1009 |
subsubsection {* Well-foundedness *} |
|
1010 |
||
28708
a1a436f09ec6
explicit check for pattern discipline before code translation
haftmann
parents:
28562
diff
changeset
|
1011 |
definition mult1 :: "('a \<times> 'a) set => ('a multiset \<times> 'a multiset) set" where |
a1a436f09ec6
explicit check for pattern discipline before code translation
haftmann
parents:
28562
diff
changeset
|
1012 |
[code del]: "mult1 r = {(N, M). \<exists>a M0 K. M = M0 + {#a#} \<and> N = M0 + K \<and> |
23751 | 1013 |
(\<forall>b. b :# K --> (b, a) \<in> r)}" |
10249 | 1014 |
|
28708
a1a436f09ec6
explicit check for pattern discipline before code translation
haftmann
parents:
28562
diff
changeset
|
1015 |
definition mult :: "('a \<times> 'a) set => ('a multiset \<times> 'a multiset) set" where |
34943
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
1016 |
[code del]: "mult r = (mult1 r)\<^sup>+" |
10249 | 1017 |
|
23751 | 1018 |
lemma not_less_empty [iff]: "(M, {#}) \<notin> mult1 r" |
26178 | 1019 |
by (simp add: mult1_def) |
10249 | 1020 |
|
23751 | 1021 |
lemma less_add: "(N, M0 + {#a#}) \<in> mult1 r ==> |
1022 |
(\<exists>M. (M, M0) \<in> mult1 r \<and> N = M + {#a#}) \<or> |
|
1023 |
(\<exists>K. (\<forall>b. b :# K --> (b, a) \<in> r) \<and> N = M0 + K)" |
|
19582 | 1024 |
(is "_ \<Longrightarrow> ?case1 (mult1 r) \<or> ?case2") |
10249 | 1025 |
proof (unfold mult1_def) |
23751 | 1026 |
let ?r = "\<lambda>K a. \<forall>b. b :# K --> (b, a) \<in> r" |
11464 | 1027 |
let ?R = "\<lambda>N M. \<exists>a M0 K. M = M0 + {#a#} \<and> N = M0 + K \<and> ?r K a" |
23751 | 1028 |
let ?case1 = "?case1 {(N, M). ?R N M}" |
10249 | 1029 |
|
23751 | 1030 |
assume "(N, M0 + {#a#}) \<in> {(N, M). ?R N M}" |
18258 | 1031 |
then have "\<exists>a' M0' K. |
11464 | 1032 |
M0 + {#a#} = M0' + {#a'#} \<and> N = M0' + K \<and> ?r K a'" by simp |
18258 | 1033 |
then show "?case1 \<or> ?case2" |
10249 | 1034 |
proof (elim exE conjE) |
1035 |
fix a' M0' K |
|
1036 |
assume N: "N = M0' + K" and r: "?r K a'" |
|
1037 |
assume "M0 + {#a#} = M0' + {#a'#}" |
|
18258 | 1038 |
then have "M0 = M0' \<and> a = a' \<or> |
11464 | 1039 |
(\<exists>K'. M0 = K' + {#a'#} \<and> M0' = K' + {#a#})" |
10249 | 1040 |
by (simp only: add_eq_conv_ex) |
18258 | 1041 |
then show ?thesis |
10249 | 1042 |
proof (elim disjE conjE exE) |
1043 |
assume "M0 = M0'" "a = a'" |
|
11464 | 1044 |
with N r have "?r K a \<and> N = M0 + K" by simp |
18258 | 1045 |
then have ?case2 .. then show ?thesis .. |
10249 | 1046 |
next |
1047 |
fix K' |
|
1048 |
assume "M0' = K' + {#a#}" |
|
34943
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
1049 |
with N have n: "N = K' + K + {#a#}" by (simp add: add_ac) |
10249 | 1050 |
|
1051 |
assume "M0 = K' + {#a'#}" |
|
1052 |
with r have "?R (K' + K) M0" by blast |
|
18258 | 1053 |
with n have ?case1 by simp then show ?thesis .. |
10249 | 1054 |
qed |
1055 |
qed |
|
1056 |
qed |
|
1057 |
||
23751 | 1058 |
lemma all_accessible: "wf r ==> \<forall>M. M \<in> acc (mult1 r)" |
10249 | 1059 |
proof |
1060 |
let ?R = "mult1 r" |
|
1061 |
let ?W = "acc ?R" |
|
1062 |
{ |
|
1063 |
fix M M0 a |
|
23751 | 1064 |
assume M0: "M0 \<in> ?W" |
1065 |
and wf_hyp: "!!b. (b, a) \<in> r ==> (\<forall>M \<in> ?W. M + {#b#} \<in> ?W)" |
|
1066 |
and acc_hyp: "\<forall>M. (M, M0) \<in> ?R --> M + {#a#} \<in> ?W" |
|
1067 |
have "M0 + {#a#} \<in> ?W" |
|
1068 |
proof (rule accI [of "M0 + {#a#}"]) |
|
10249 | 1069 |
fix N |
23751 | 1070 |
assume "(N, M0 + {#a#}) \<in> ?R" |
1071 |
then have "((\<exists>M. (M, M0) \<in> ?R \<and> N = M + {#a#}) \<or> |
|
1072 |
(\<exists>K. (\<forall>b. b :# K --> (b, a) \<in> r) \<and> N = M0 + K))" |
|
10249 | 1073 |
by (rule less_add) |
23751 | 1074 |
then show "N \<in> ?W" |
10249 | 1075 |
proof (elim exE disjE conjE) |
23751 | 1076 |
fix M assume "(M, M0) \<in> ?R" and N: "N = M + {#a#}" |
1077 |
from acc_hyp have "(M, M0) \<in> ?R --> M + {#a#} \<in> ?W" .. |
|
1078 |
from this and `(M, M0) \<in> ?R` have "M + {#a#} \<in> ?W" .. |
|
1079 |
then show "N \<in> ?W" by (simp only: N) |
|
10249 | 1080 |
next |
1081 |
fix K |
|
1082 |
assume N: "N = M0 + K" |
|
23751 | 1083 |
assume "\<forall>b. b :# K --> (b, a) \<in> r" |
1084 |
then have "M0 + K \<in> ?W" |
|
10249 | 1085 |
proof (induct K) |
18730 | 1086 |
case empty |
23751 | 1087 |
from M0 show "M0 + {#} \<in> ?W" by simp |
18730 | 1088 |
next |
1089 |
case (add K x) |
|
23751 | 1090 |
from add.prems have "(x, a) \<in> r" by simp |
1091 |
with wf_hyp have "\<forall>M \<in> ?W. M + {#x#} \<in> ?W" by blast |
|
1092 |
moreover from add have "M0 + K \<in> ?W" by simp |
|
1093 |
ultimately have "(M0 + K) + {#x#} \<in> ?W" .. |
|
34943
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
1094 |
then show "M0 + (K + {#x#}) \<in> ?W" by (simp only: add_assoc) |
10249 | 1095 |
qed |
23751 | 1096 |
then show "N \<in> ?W" by (simp only: N) |
10249 | 1097 |
qed |
1098 |
qed |
|
1099 |
} note tedious_reasoning = this |
|
1100 |
||
23751 | 1101 |
assume wf: "wf r" |
10249 | 1102 |
fix M |
23751 | 1103 |
show "M \<in> ?W" |
10249 | 1104 |
proof (induct M) |
23751 | 1105 |
show "{#} \<in> ?W" |
10249 | 1106 |
proof (rule accI) |
23751 | 1107 |
fix b assume "(b, {#}) \<in> ?R" |
1108 |
with not_less_empty show "b \<in> ?W" by contradiction |
|
10249 | 1109 |
qed |
1110 |
||
23751 | 1111 |
fix M a assume "M \<in> ?W" |
1112 |
from wf have "\<forall>M \<in> ?W. M + {#a#} \<in> ?W" |
|
10249 | 1113 |
proof induct |
1114 |
fix a |
|
23751 | 1115 |
assume r: "!!b. (b, a) \<in> r ==> (\<forall>M \<in> ?W. M + {#b#} \<in> ?W)" |
1116 |
show "\<forall>M \<in> ?W. M + {#a#} \<in> ?W" |
|
10249 | 1117 |
proof |
23751 | 1118 |
fix M assume "M \<in> ?W" |
1119 |
then show "M + {#a#} \<in> ?W" |
|
23373 | 1120 |
by (rule acc_induct) (rule tedious_reasoning [OF _ r]) |
10249 | 1121 |
qed |
1122 |
qed |
|
23751 | 1123 |
from this and `M \<in> ?W` show "M + {#a#} \<in> ?W" .. |
10249 | 1124 |
qed |
1125 |
qed |
|
1126 |
||
23751 | 1127 |
theorem wf_mult1: "wf r ==> wf (mult1 r)" |
26178 | 1128 |
by (rule acc_wfI) (rule all_accessible) |
10249 | 1129 |
|
23751 | 1130 |
theorem wf_mult: "wf r ==> wf (mult r)" |
26178 | 1131 |
unfolding mult_def by (rule wf_trancl) (rule wf_mult1) |
10249 | 1132 |
|
1133 |
||
1134 |
subsubsection {* Closure-free presentation *} |
|
1135 |
||
1136 |
text {* One direction. *} |
|
1137 |
||
1138 |
lemma mult_implies_one_step: |
|
23751 | 1139 |
"trans r ==> (M, N) \<in> mult r ==> |
11464 | 1140 |
\<exists>I J K. N = I + J \<and> M = I + K \<and> J \<noteq> {#} \<and> |
23751 | 1141 |
(\<forall>k \<in> set_of K. \<exists>j \<in> set_of J. (k, j) \<in> r)" |
26178 | 1142 |
apply (unfold mult_def mult1_def set_of_def) |
1143 |
apply (erule converse_trancl_induct, clarify) |
|
1144 |
apply (rule_tac x = M0 in exI, simp, clarify) |
|
1145 |
apply (case_tac "a :# K") |
|
1146 |
apply (rule_tac x = I in exI) |
|
1147 |
apply (simp (no_asm)) |
|
1148 |
apply (rule_tac x = "(K - {#a#}) + Ka" in exI) |
|
34943
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
1149 |
apply (simp (no_asm_simp) add: add_assoc [symmetric]) |
26178 | 1150 |
apply (drule_tac f = "\<lambda>M. M - {#a#}" in arg_cong) |
1151 |
apply (simp add: diff_union_single_conv) |
|
1152 |
apply (simp (no_asm_use) add: trans_def) |
|
1153 |
apply blast |
|
1154 |
apply (subgoal_tac "a :# I") |
|
1155 |
apply (rule_tac x = "I - {#a#}" in exI) |
|
1156 |
apply (rule_tac x = "J + {#a#}" in exI) |
|
1157 |
apply (rule_tac x = "K + Ka" in exI) |
|
1158 |
apply (rule conjI) |
|
1159 |
apply (simp add: multiset_eq_conv_count_eq split: nat_diff_split) |
|
1160 |
apply (rule conjI) |
|
1161 |
apply (drule_tac f = "\<lambda>M. M - {#a#}" in arg_cong, simp) |
|
1162 |
apply (simp add: multiset_eq_conv_count_eq split: nat_diff_split) |
|
1163 |
apply (simp (no_asm_use) add: trans_def) |
|
1164 |
apply blast |
|
1165 |
apply (subgoal_tac "a :# (M0 + {#a#})") |
|
1166 |
apply simp |
|
1167 |
apply (simp (no_asm)) |
|
1168 |
done |
|
10249 | 1169 |
|
1170 |
lemma one_step_implies_mult_aux: |
|
23751 | 1171 |
"trans r ==> |
1172 |
\<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)) |
|
1173 |
--> (I + K, I + J) \<in> mult r" |
|
26178 | 1174 |
apply (induct_tac n, auto) |
1175 |
apply (frule size_eq_Suc_imp_eq_union, clarify) |
|
1176 |
apply (rename_tac "J'", simp) |
|
1177 |
apply (erule notE, auto) |
|
1178 |
apply (case_tac "J' = {#}") |
|
1179 |
apply (simp add: mult_def) |
|
1180 |
apply (rule r_into_trancl) |
|
1181 |
apply (simp add: mult1_def set_of_def, blast) |
|
1182 |
txt {* Now we know @{term "J' \<noteq> {#}"}. *} |
|
1183 |
apply (cut_tac M = K and P = "\<lambda>x. (x, a) \<in> r" in multiset_partition) |
|
1184 |
apply (erule_tac P = "\<forall>k \<in> set_of K. ?P k" in rev_mp) |
|
1185 |
apply (erule ssubst) |
|
1186 |
apply (simp add: Ball_def, auto) |
|
1187 |
apply (subgoal_tac |
|
1188 |
"((I + {# x :# K. (x, a) \<in> r #}) + {# x :# K. (x, a) \<notin> r #}, |
|
1189 |
(I + {# x :# K. (x, a) \<in> r #}) + J') \<in> mult r") |
|
1190 |
prefer 2 |
|
1191 |
apply force |
|
34943
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
1192 |
apply (simp (no_asm_use) add: add_assoc [symmetric] mult_def) |
26178 | 1193 |
apply (erule trancl_trans) |
1194 |
apply (rule r_into_trancl) |
|
1195 |
apply (simp add: mult1_def set_of_def) |
|
1196 |
apply (rule_tac x = a in exI) |
|
1197 |
apply (rule_tac x = "I + J'" in exI) |
|
34943
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
1198 |
apply (simp add: add_ac) |
26178 | 1199 |
done |
10249 | 1200 |
|
17161 | 1201 |
lemma one_step_implies_mult: |
23751 | 1202 |
"trans r ==> J \<noteq> {#} ==> \<forall>k \<in> set_of K. \<exists>j \<in> set_of J. (k, j) \<in> r |
1203 |
==> (I + K, I + J) \<in> mult r" |
|
26178 | 1204 |
using one_step_implies_mult_aux by blast |
10249 | 1205 |
|
1206 |
||
1207 |
subsubsection {* Partial-order properties *} |
|
1208 |
||
35273 | 1209 |
definition less_multiset :: "'a\<Colon>order multiset \<Rightarrow> 'a multiset \<Rightarrow> bool" (infix "<#" 50) where |
1210 |
"M' <# M \<longleftrightarrow> (M', M) \<in> mult {(x', x). x' < x}" |
|
10249 | 1211 |
|
35273 | 1212 |
definition le_multiset :: "'a\<Colon>order multiset \<Rightarrow> 'a multiset \<Rightarrow> bool" (infix "<=#" 50) where |
1213 |
"M' <=# M \<longleftrightarrow> M' <# M \<or> M' = M" |
|
1214 |
||
35308 | 1215 |
notation (xsymbols) less_multiset (infix "\<subset>#" 50) |
1216 |
notation (xsymbols) le_multiset (infix "\<subseteq>#" 50) |
|
10249 | 1217 |
|
35268
04673275441a
switched notations for pointwise and multiset order
haftmann
parents:
35028
diff
changeset
|
1218 |
interpretation multiset_order: order le_multiset less_multiset |
04673275441a
switched notations for pointwise and multiset order
haftmann
parents:
35028
diff
changeset
|
1219 |
proof - |
04673275441a
switched notations for pointwise and multiset order
haftmann
parents:
35028
diff
changeset
|
1220 |
have irrefl: "\<And>M :: 'a multiset. \<not> M \<subset># M" |
04673275441a
switched notations for pointwise and multiset order
haftmann
parents:
35028
diff
changeset
|
1221 |
proof |
04673275441a
switched notations for pointwise and multiset order
haftmann
parents:
35028
diff
changeset
|
1222 |
fix M :: "'a multiset" |
04673275441a
switched notations for pointwise and multiset order
haftmann
parents:
35028
diff
changeset
|
1223 |
assume "M \<subset># M" |
04673275441a
switched notations for pointwise and multiset order
haftmann
parents:
35028
diff
changeset
|
1224 |
then have MM: "(M, M) \<in> mult {(x, y). x < y}" by (simp add: less_multiset_def) |
04673275441a
switched notations for pointwise and multiset order
haftmann
parents:
35028
diff
changeset
|
1225 |
have "trans {(x'::'a, x). x' < x}" |
04673275441a
switched notations for pointwise and multiset order
haftmann
parents:
35028
diff
changeset
|
1226 |
by (rule transI) simp |
04673275441a
switched notations for pointwise and multiset order
haftmann
parents:
35028
diff
changeset
|
1227 |
moreover note MM |
04673275441a
switched notations for pointwise and multiset order
haftmann
parents:
35028
diff
changeset
|
1228 |
ultimately have "\<exists>I J K. M = I + J \<and> M = I + K |
04673275441a
switched notations for pointwise and multiset order
haftmann
parents:
35028
diff
changeset
|
1229 |
\<and> J \<noteq> {#} \<and> (\<forall>k\<in>set_of K. \<exists>j\<in>set_of J. (k, j) \<in> {(x, y). x < y})" |
04673275441a
switched notations for pointwise and multiset order
haftmann
parents:
35028
diff
changeset
|
1230 |
by (rule mult_implies_one_step) |
04673275441a
switched notations for pointwise and multiset order
haftmann
parents:
35028
diff
changeset
|
1231 |
then obtain I J K where "M = I + J" and "M = I + K" |
04673275441a
switched notations for pointwise and multiset order
haftmann
parents:
35028
diff
changeset
|
1232 |
and "J \<noteq> {#}" and "(\<forall>k\<in>set_of K. \<exists>j\<in>set_of J. (k, j) \<in> {(x, y). x < y})" by blast |
04673275441a
switched notations for pointwise and multiset order
haftmann
parents:
35028
diff
changeset
|
1233 |
then have aux1: "K \<noteq> {#}" and aux2: "\<forall>k\<in>set_of K. \<exists>j\<in>set_of K. k < j" by auto |
04673275441a
switched notations for pointwise and multiset order
haftmann
parents:
35028
diff
changeset
|
1234 |
have "finite (set_of K)" by simp |
04673275441a
switched notations for pointwise and multiset order
haftmann
parents:
35028
diff
changeset
|
1235 |
moreover note aux2 |
04673275441a
switched notations for pointwise and multiset order
haftmann
parents:
35028
diff
changeset
|
1236 |
ultimately have "set_of K = {}" |
04673275441a
switched notations for pointwise and multiset order
haftmann
parents:
35028
diff
changeset
|
1237 |
by (induct rule: finite_induct) (auto intro: order_less_trans) |
04673275441a
switched notations for pointwise and multiset order
haftmann
parents:
35028
diff
changeset
|
1238 |
with aux1 show False by simp |
04673275441a
switched notations for pointwise and multiset order
haftmann
parents:
35028
diff
changeset
|
1239 |
qed |
04673275441a
switched notations for pointwise and multiset order
haftmann
parents:
35028
diff
changeset
|
1240 |
have trans: "\<And>K M N :: 'a multiset. K \<subset># M \<Longrightarrow> M \<subset># N \<Longrightarrow> K \<subset># N" |
04673275441a
switched notations for pointwise and multiset order
haftmann
parents:
35028
diff
changeset
|
1241 |
unfolding less_multiset_def mult_def by (blast intro: trancl_trans) |
04673275441a
switched notations for pointwise and multiset order
haftmann
parents:
35028
diff
changeset
|
1242 |
show "order (le_multiset :: 'a multiset \<Rightarrow> _) less_multiset" proof |
04673275441a
switched notations for pointwise and multiset order
haftmann
parents:
35028
diff
changeset
|
1243 |
qed (auto simp add: le_multiset_def irrefl dest: trans) |
04673275441a
switched notations for pointwise and multiset order
haftmann
parents:
35028
diff
changeset
|
1244 |
qed |
10249 | 1245 |
|
35268
04673275441a
switched notations for pointwise and multiset order
haftmann
parents:
35028
diff
changeset
|
1246 |
lemma mult_less_irrefl [elim!]: |
04673275441a
switched notations for pointwise and multiset order
haftmann
parents:
35028
diff
changeset
|
1247 |
"M \<subset># (M::'a::order multiset) ==> R" |
04673275441a
switched notations for pointwise and multiset order
haftmann
parents:
35028
diff
changeset
|
1248 |
by (simp add: multiset_order.less_irrefl) |
26567
7bcebb8c2d33
instantiation replacing primitive instance plus overloaded defs; more conservative type arities
haftmann
parents:
26178
diff
changeset
|
1249 |
|
10249 | 1250 |
|
1251 |
subsubsection {* Monotonicity of multiset union *} |
|
1252 |
||
17161 | 1253 |
lemma mult1_union: |
26178 | 1254 |
"(B, D) \<in> mult1 r ==> trans r ==> (C + B, C + D) \<in> mult1 r" |
1255 |
apply (unfold mult1_def) |
|
1256 |
apply auto |
|
1257 |
apply (rule_tac x = a in exI) |
|
1258 |
apply (rule_tac x = "C + M0" in exI) |
|
34943
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
1259 |
apply (simp add: add_assoc) |
26178 | 1260 |
done |
10249 | 1261 |
|
35268
04673275441a
switched notations for pointwise and multiset order
haftmann
parents:
35028
diff
changeset
|
1262 |
lemma union_less_mono2: "B \<subset># D ==> C + B \<subset># C + (D::'a::order multiset)" |
26178 | 1263 |
apply (unfold less_multiset_def mult_def) |
1264 |
apply (erule trancl_induct) |
|
1265 |
apply (blast intro: mult1_union transI order_less_trans r_into_trancl) |
|
1266 |
apply (blast intro: mult1_union transI order_less_trans r_into_trancl trancl_trans) |
|
1267 |
done |
|
10249 | 1268 |
|
35268
04673275441a
switched notations for pointwise and multiset order
haftmann
parents:
35028
diff
changeset
|
1269 |
lemma union_less_mono1: "B \<subset># D ==> B + C \<subset># D + (C::'a::order multiset)" |
34943
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
1270 |
apply (subst add_commute [of B C]) |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
1271 |
apply (subst add_commute [of D C]) |
26178 | 1272 |
apply (erule union_less_mono2) |
1273 |
done |
|
10249 | 1274 |
|
17161 | 1275 |
lemma union_less_mono: |
35268
04673275441a
switched notations for pointwise and multiset order
haftmann
parents:
35028
diff
changeset
|
1276 |
"A \<subset># C ==> B \<subset># D ==> A + B \<subset># C + (D::'a::order multiset)" |
04673275441a
switched notations for pointwise and multiset order
haftmann
parents:
35028
diff
changeset
|
1277 |
by (blast intro!: union_less_mono1 union_less_mono2 multiset_order.less_trans) |
10249 | 1278 |
|
35268
04673275441a
switched notations for pointwise and multiset order
haftmann
parents:
35028
diff
changeset
|
1279 |
interpretation multiset_order: ordered_ab_semigroup_add plus le_multiset less_multiset |
04673275441a
switched notations for pointwise and multiset order
haftmann
parents:
35028
diff
changeset
|
1280 |
proof |
04673275441a
switched notations for pointwise and multiset order
haftmann
parents:
35028
diff
changeset
|
1281 |
qed (auto simp add: le_multiset_def intro: union_less_mono2) |
26145 | 1282 |
|
15072 | 1283 |
|
25610 | 1284 |
subsection {* The fold combinator *} |
1285 |
||
26145 | 1286 |
text {* |
1287 |
The intended behaviour is |
|
1288 |
@{text "fold_mset f z {#x\<^isub>1, ..., x\<^isub>n#} = f x\<^isub>1 (\<dots> (f x\<^isub>n z)\<dots>)"} |
|
1289 |
if @{text f} is associative-commutative. |
|
25610 | 1290 |
*} |
1291 |
||
26145 | 1292 |
text {* |
1293 |
The graph of @{text "fold_mset"}, @{text "z"}: the start element, |
|
1294 |
@{text "f"}: folding function, @{text "A"}: the multiset, @{text |
|
1295 |
"y"}: the result. |
|
1296 |
*} |
|
25610 | 1297 |
inductive |
25759 | 1298 |
fold_msetG :: "('a \<Rightarrow> 'b \<Rightarrow> 'b) \<Rightarrow> 'b \<Rightarrow> 'a multiset \<Rightarrow> 'b \<Rightarrow> bool" |
25610 | 1299 |
for f :: "'a \<Rightarrow> 'b \<Rightarrow> 'b" |
1300 |
and z :: 'b |
|
1301 |
where |
|
25759 | 1302 |
emptyI [intro]: "fold_msetG f z {#} z" |
1303 |
| insertI [intro]: "fold_msetG f z A y \<Longrightarrow> fold_msetG f z (A + {#x#}) (f x y)" |
|
25610 | 1304 |
|
25759 | 1305 |
inductive_cases empty_fold_msetGE [elim!]: "fold_msetG f z {#} x" |
1306 |
inductive_cases insert_fold_msetGE: "fold_msetG f z (A + {#}) y" |
|
25610 | 1307 |
|
1308 |
definition |
|
26145 | 1309 |
fold_mset :: "('a \<Rightarrow> 'b \<Rightarrow> 'b) \<Rightarrow> 'b \<Rightarrow> 'a multiset \<Rightarrow> 'b" where |
1310 |
"fold_mset f z A = (THE x. fold_msetG f z A x)" |
|
25610 | 1311 |
|
25759 | 1312 |
lemma Diff1_fold_msetG: |
26145 | 1313 |
"fold_msetG f z (A - {#x#}) y \<Longrightarrow> x \<in># A \<Longrightarrow> fold_msetG f z A (f x y)" |
26178 | 1314 |
apply (frule_tac x = x in fold_msetG.insertI) |
1315 |
apply auto |
|
1316 |
done |
|
25610 | 1317 |
|
25759 | 1318 |
lemma fold_msetG_nonempty: "\<exists>x. fold_msetG f z A x" |
26178 | 1319 |
apply (induct A) |
1320 |
apply blast |
|
1321 |
apply clarsimp |
|
1322 |
apply (drule_tac x = x in fold_msetG.insertI) |
|
1323 |
apply auto |
|
1324 |
done |
|
25610 | 1325 |
|
25759 | 1326 |
lemma fold_mset_empty[simp]: "fold_mset f z {#} = z" |
26178 | 1327 |
unfolding fold_mset_def by blast |
25610 | 1328 |
|
34943
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
1329 |
context fun_left_comm |
26145 | 1330 |
begin |
25610 | 1331 |
|
26145 | 1332 |
lemma fold_msetG_determ: |
1333 |
"fold_msetG f z A x \<Longrightarrow> fold_msetG f z A y \<Longrightarrow> y = x" |
|
25610 | 1334 |
proof (induct arbitrary: x y z rule: full_multiset_induct) |
1335 |
case (less M x\<^isub>1 x\<^isub>2 Z) |
|
35268
04673275441a
switched notations for pointwise and multiset order
haftmann
parents:
35028
diff
changeset
|
1336 |
have IH: "\<forall>A. A < M \<longrightarrow> |
25759 | 1337 |
(\<forall>x x' x''. fold_msetG f x'' A x \<longrightarrow> fold_msetG f x'' A x' |
25610 | 1338 |
\<longrightarrow> x' = x)" by fact |
25759 | 1339 |
have Mfoldx\<^isub>1: "fold_msetG f Z M x\<^isub>1" and Mfoldx\<^isub>2: "fold_msetG f Z M x\<^isub>2" by fact+ |
25610 | 1340 |
show ?case |
25759 | 1341 |
proof (rule fold_msetG.cases [OF Mfoldx\<^isub>1]) |
25610 | 1342 |
assume "M = {#}" and "x\<^isub>1 = Z" |
26145 | 1343 |
then show ?case using Mfoldx\<^isub>2 by auto |
25610 | 1344 |
next |
1345 |
fix B b u |
|
25759 | 1346 |
assume "M = B + {#b#}" and "x\<^isub>1 = f b u" and Bu: "fold_msetG f Z B u" |
26145 | 1347 |
then have MBb: "M = B + {#b#}" and x\<^isub>1: "x\<^isub>1 = f b u" by auto |
25610 | 1348 |
show ?case |
25759 | 1349 |
proof (rule fold_msetG.cases [OF Mfoldx\<^isub>2]) |
25610 | 1350 |
assume "M = {#}" "x\<^isub>2 = Z" |
26145 | 1351 |
then show ?case using Mfoldx\<^isub>1 by auto |
25610 | 1352 |
next |
1353 |
fix C c v |
|
25759 | 1354 |
assume "M = C + {#c#}" and "x\<^isub>2 = f c v" and Cv: "fold_msetG f Z C v" |
26145 | 1355 |
then have MCc: "M = C + {#c#}" and x\<^isub>2: "x\<^isub>2 = f c v" by auto |
35268
04673275441a
switched notations for pointwise and multiset order
haftmann
parents:
35028
diff
changeset
|
1356 |
then have CsubM: "C < M" by simp |
04673275441a
switched notations for pointwise and multiset order
haftmann
parents:
35028
diff
changeset
|
1357 |
from MBb have BsubM: "B < M" by simp |
25610 | 1358 |
show ?case |
1359 |
proof cases |
|
1360 |
assume "b=c" |
|
1361 |
then moreover have "B = C" using MBb MCc by auto |
|
1362 |
ultimately show ?thesis using Bu Cv x\<^isub>1 x\<^isub>2 CsubM IH by auto |
|
1363 |
next |
|
1364 |
assume diff: "b \<noteq> c" |
|
1365 |
let ?D = "B - {#c#}" |
|
1366 |
have cinB: "c \<in># B" and binC: "b \<in># C" using MBb MCc diff |
|
1367 |
by (auto intro: insert_noteq_member dest: sym) |
|
35268
04673275441a
switched notations for pointwise and multiset order
haftmann
parents:
35028
diff
changeset
|
1368 |
have "B - {#c#} < B" using cinB by (rule mset_less_diff_self) |
04673275441a
switched notations for pointwise and multiset order
haftmann
parents:
35028
diff
changeset
|
1369 |
then have DsubM: "?D < M" using BsubM by (blast intro: order_less_trans) |
25610 | 1370 |
from MBb MCc have "B + {#b#} = C + {#c#}" by blast |
26145 | 1371 |
then have [simp]: "B + {#b#} - {#c#} = C" |
25610 | 1372 |
using MBb MCc binC cinB by auto |
1373 |
have B: "B = ?D + {#c#}" and C: "C = ?D + {#b#}" |
|
1374 |
using MBb MCc diff binC cinB |
|
1375 |
by (auto simp: multiset_add_sub_el_shuffle) |
|
25759 | 1376 |
then obtain d where Dfoldd: "fold_msetG f Z ?D d" |
1377 |
using fold_msetG_nonempty by iprover |
|
26145 | 1378 |
then have "fold_msetG f Z B (f c d)" using cinB |
25759 | 1379 |
by (rule Diff1_fold_msetG) |
26145 | 1380 |
then have "f c d = u" using IH BsubM Bu by blast |
25610 | 1381 |
moreover |
25759 | 1382 |
have "fold_msetG f Z C (f b d)" using binC cinB diff Dfoldd |
25610 | 1383 |
by (auto simp: multiset_add_sub_el_shuffle |
25759 | 1384 |
dest: fold_msetG.insertI [where x=b]) |
26145 | 1385 |
then have "f b d = v" using IH CsubM Cv by blast |
25610 | 1386 |
ultimately show ?thesis using x\<^isub>1 x\<^isub>2 |
34943
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
1387 |
by (auto simp: fun_left_comm) |
25610 | 1388 |
qed |
1389 |
qed |
|
1390 |
qed |
|
1391 |
qed |
|
1392 |
||
26145 | 1393 |
lemma fold_mset_insert_aux: |
1394 |
"(fold_msetG f z (A + {#x#}) v) = |
|
25759 | 1395 |
(\<exists>y. fold_msetG f z A y \<and> v = f x y)" |
26178 | 1396 |
apply (rule iffI) |
1397 |
prefer 2 |
|
1398 |
apply blast |
|
1399 |
apply (rule_tac A=A and f=f in fold_msetG_nonempty [THEN exE, standard]) |
|
1400 |
apply (blast intro: fold_msetG_determ) |
|
1401 |
done |
|
25610 | 1402 |
|
26145 | 1403 |
lemma fold_mset_equality: "fold_msetG f z A y \<Longrightarrow> fold_mset f z A = y" |
26178 | 1404 |
unfolding fold_mset_def by (blast intro: fold_msetG_determ) |
25610 | 1405 |
|
26145 | 1406 |
lemma fold_mset_insert: |
26178 | 1407 |
"fold_mset f z (A + {#x#}) = f x (fold_mset f z A)" |
34943
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
1408 |
apply (simp add: fold_mset_def fold_mset_insert_aux add_commute) |
26178 | 1409 |
apply (rule the_equality) |
1410 |
apply (auto cong add: conj_cong |
|
26145 | 1411 |
simp add: fold_mset_def [symmetric] fold_mset_equality fold_msetG_nonempty) |
26178 | 1412 |
done |
25759 | 1413 |
|
26145 | 1414 |
lemma fold_mset_insert_idem: |
26178 | 1415 |
"fold_mset f z (A + {#a#}) = f a (fold_mset f z A)" |
1416 |
apply (simp add: fold_mset_def fold_mset_insert_aux) |
|
1417 |
apply (rule the_equality) |
|
1418 |
apply (auto cong add: conj_cong |
|
26145 | 1419 |
simp add: fold_mset_def [symmetric] fold_mset_equality fold_msetG_nonempty) |
26178 | 1420 |
done |
25610 | 1421 |
|
26145 | 1422 |
lemma fold_mset_commute: "f x (fold_mset f z A) = fold_mset f (f x z) A" |
34943
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
1423 |
by (induct A) (auto simp: fold_mset_insert fun_left_comm [of x]) |
26178 | 1424 |
|
26145 | 1425 |
lemma fold_mset_single [simp]: "fold_mset f z {#x#} = f x z" |
26178 | 1426 |
using fold_mset_insert [of z "{#}"] by simp |
25610 | 1427 |
|
26145 | 1428 |
lemma fold_mset_union [simp]: |
1429 |
"fold_mset f z (A+B) = fold_mset f (fold_mset f z A) B" |
|
25759 | 1430 |
proof (induct A) |
26145 | 1431 |
case empty then show ?case by simp |
25759 | 1432 |
next |
26145 | 1433 |
case (add A x) |
34943
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
1434 |
have "A + {#x#} + B = (A+B) + {#x#}" by (simp add: add_ac) |
26145 | 1435 |
then have "fold_mset f z (A + {#x#} + B) = f x (fold_mset f z (A + B))" |
1436 |
by (simp add: fold_mset_insert) |
|
1437 |
also have "\<dots> = fold_mset f (fold_mset f z (A + {#x#})) B" |
|
1438 |
by (simp add: fold_mset_commute[of x,symmetric] add fold_mset_insert) |
|
1439 |
finally show ?case . |
|
25759 | 1440 |
qed |
1441 |
||
26145 | 1442 |
lemma fold_mset_fusion: |
34943
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
1443 |
assumes "fun_left_comm g" |
27611 | 1444 |
shows "(\<And>x y. h (g x y) = f x (h y)) \<Longrightarrow> h (fold_mset g w A) = fold_mset f (h w) A" (is "PROP ?P") |
1445 |
proof - |
|
34943
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
1446 |
interpret fun_left_comm g by (fact assms) |
27611 | 1447 |
show "PROP ?P" by (induct A) auto |
1448 |
qed |
|
25610 | 1449 |
|
26145 | 1450 |
lemma fold_mset_rec: |
1451 |
assumes "a \<in># A" |
|
25759 | 1452 |
shows "fold_mset f z A = f a (fold_mset f z (A - {#a#}))" |
25610 | 1453 |
proof - |
26145 | 1454 |
from assms obtain A' where "A = A' + {#a#}" |
1455 |
by (blast dest: multi_member_split) |
|
1456 |
then show ?thesis by simp |
|
25610 | 1457 |
qed |
1458 |
||
26145 | 1459 |
end |
1460 |
||
1461 |
text {* |
|
1462 |
A note on code generation: When defining some function containing a |
|
1463 |
subterm @{term"fold_mset F"}, code generation is not automatic. When |
|
1464 |
interpreting locale @{text left_commutative} with @{text F}, the |
|
1465 |
would be code thms for @{const fold_mset} become thms like |
|
1466 |
@{term"fold_mset F z {#} = z"} where @{text F} is not a pattern but |
|
1467 |
contains defined symbols, i.e.\ is not a code thm. Hence a separate |
|
1468 |
constant with its own code thms needs to be introduced for @{text |
|
1469 |
F}. See the image operator below. |
|
1470 |
*} |
|
1471 |
||
26016 | 1472 |
|
1473 |
subsection {* Image *} |
|
1474 |
||
34943
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
1475 |
definition image_mset :: "('a \<Rightarrow> 'b) \<Rightarrow> 'a multiset \<Rightarrow> 'b multiset" where |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
1476 |
"image_mset f = fold_mset (op + o single o f) {#}" |
26016 | 1477 |
|
34943
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
1478 |
interpretation image_left_comm: fun_left_comm "op + o single o f" |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
1479 |
proof qed (simp add: add_ac) |
26016 | 1480 |
|
28708
a1a436f09ec6
explicit check for pattern discipline before code translation
haftmann
parents:
28562
diff
changeset
|
1481 |
lemma image_mset_empty [simp]: "image_mset f {#} = {#}" |
26178 | 1482 |
by (simp add: image_mset_def) |
26016 | 1483 |
|
28708
a1a436f09ec6
explicit check for pattern discipline before code translation
haftmann
parents:
28562
diff
changeset
|
1484 |
lemma image_mset_single [simp]: "image_mset f {#x#} = {#f x#}" |
26178 | 1485 |
by (simp add: image_mset_def) |
26016 | 1486 |
|
1487 |
lemma image_mset_insert: |
|
1488 |
"image_mset f (M + {#a#}) = image_mset f M + {#f a#}" |
|
26178 | 1489 |
by (simp add: image_mset_def add_ac) |
26016 | 1490 |
|
28708
a1a436f09ec6
explicit check for pattern discipline before code translation
haftmann
parents:
28562
diff
changeset
|
1491 |
lemma image_mset_union [simp]: |
26016 | 1492 |
"image_mset f (M+N) = image_mset f M + image_mset f N" |
26178 | 1493 |
apply (induct N) |
1494 |
apply simp |
|
34943
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
1495 |
apply (simp add: add_assoc [symmetric] image_mset_insert) |
26178 | 1496 |
done |
26016 | 1497 |
|
26145 | 1498 |
lemma size_image_mset [simp]: "size (image_mset f M) = size M" |
26178 | 1499 |
by (induct M) simp_all |
26016 | 1500 |
|
26145 | 1501 |
lemma image_mset_is_empty_iff [simp]: "image_mset f M = {#} \<longleftrightarrow> M = {#}" |
26178 | 1502 |
by (cases M) auto |
26016 | 1503 |
|
26145 | 1504 |
syntax |
35352 | 1505 |
"_comprehension1_mset" :: "'a \<Rightarrow> 'b \<Rightarrow> 'b multiset \<Rightarrow> 'a multiset" |
26145 | 1506 |
("({#_/. _ :# _#})") |
1507 |
translations |
|
1508 |
"{#e. x:#M#}" == "CONST image_mset (%x. e) M" |
|
26016 | 1509 |
|
26145 | 1510 |
syntax |
35352 | 1511 |
"_comprehension2_mset" :: "'a \<Rightarrow> 'b \<Rightarrow> 'b multiset \<Rightarrow> bool \<Rightarrow> 'a multiset" |
26145 | 1512 |
("({#_/ | _ :# _./ _#})") |
26016 | 1513 |
translations |
26033 | 1514 |
"{#e | x:#M. P#}" => "{#e. x :# {# x:#M. P#}#}" |
26016 | 1515 |
|
26145 | 1516 |
text {* |
1517 |
This allows to write not just filters like @{term "{#x:#M. x<c#}"} |
|
1518 |
but also images like @{term "{#x+x. x:#M #}"} and @{term [source] |
|
1519 |
"{#x+x|x:#M. x<c#}"}, where the latter is currently displayed as |
|
1520 |
@{term "{#x+x|x:#M. x<c#}"}. |
|
1521 |
*} |
|
26016 | 1522 |
|
29125
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
krauss
parents:
28823
diff
changeset
|
1523 |
|
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
krauss
parents:
28823
diff
changeset
|
1524 |
subsection {* Termination proofs with multiset orders *} |
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
krauss
parents:
28823
diff
changeset
|
1525 |
|
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
krauss
parents:
28823
diff
changeset
|
1526 |
lemma multi_member_skip: "x \<in># XS \<Longrightarrow> x \<in># {# y #} + XS" |
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
krauss
parents:
28823
diff
changeset
|
1527 |
and multi_member_this: "x \<in># {# x #} + XS" |
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
krauss
parents:
28823
diff
changeset
|
1528 |
and multi_member_last: "x \<in># {# x #}" |
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
krauss
parents:
28823
diff
changeset
|
1529 |
by auto |
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
krauss
parents:
28823
diff
changeset
|
1530 |
|
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
krauss
parents:
28823
diff
changeset
|
1531 |
definition "ms_strict = mult pair_less" |
30428 | 1532 |
definition [code del]: "ms_weak = ms_strict \<union> Id" |
29125
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
krauss
parents:
28823
diff
changeset
|
1533 |
|
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
krauss
parents:
28823
diff
changeset
|
1534 |
lemma ms_reduction_pair: "reduction_pair (ms_strict, ms_weak)" |
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
krauss
parents:
28823
diff
changeset
|
1535 |
unfolding reduction_pair_def ms_strict_def ms_weak_def pair_less_def |
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
krauss
parents:
28823
diff
changeset
|
1536 |
by (auto intro: wf_mult1 wf_trancl simp: mult_def) |
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
krauss
parents:
28823
diff
changeset
|
1537 |
|
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
krauss
parents:
28823
diff
changeset
|
1538 |
lemma smsI: |
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
krauss
parents:
28823
diff
changeset
|
1539 |
"(set_of A, set_of B) \<in> max_strict \<Longrightarrow> (Z + A, Z + B) \<in> ms_strict" |
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
krauss
parents:
28823
diff
changeset
|
1540 |
unfolding ms_strict_def |
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
krauss
parents:
28823
diff
changeset
|
1541 |
by (rule one_step_implies_mult) (auto simp add: max_strict_def pair_less_def elim!:max_ext.cases) |
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
krauss
parents:
28823
diff
changeset
|
1542 |
|
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
krauss
parents:
28823
diff
changeset
|
1543 |
lemma wmsI: |
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
krauss
parents:
28823
diff
changeset
|
1544 |
"(set_of A, set_of B) \<in> max_strict \<or> A = {#} \<and> B = {#} |
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
krauss
parents:
28823
diff
changeset
|
1545 |
\<Longrightarrow> (Z + A, Z + B) \<in> ms_weak" |
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
krauss
parents:
28823
diff
changeset
|
1546 |
unfolding ms_weak_def ms_strict_def |
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
krauss
parents:
28823
diff
changeset
|
1547 |
by (auto simp add: pair_less_def max_strict_def elim!:max_ext.cases intro: one_step_implies_mult) |
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
krauss
parents:
28823
diff
changeset
|
1548 |
|
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
krauss
parents:
28823
diff
changeset
|
1549 |
inductive pw_leq |
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
krauss
parents:
28823
diff
changeset
|
1550 |
where |
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
krauss
parents:
28823
diff
changeset
|
1551 |
pw_leq_empty: "pw_leq {#} {#}" |
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
krauss
parents:
28823
diff
changeset
|
1552 |
| pw_leq_step: "\<lbrakk>(x,y) \<in> pair_leq; pw_leq X Y \<rbrakk> \<Longrightarrow> pw_leq ({#x#} + X) ({#y#} + Y)" |
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
krauss
parents:
28823
diff
changeset
|
1553 |
|
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
krauss
parents:
28823
diff
changeset
|
1554 |
lemma pw_leq_lstep: |
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
krauss
parents:
28823
diff
changeset
|
1555 |
"(x, y) \<in> pair_leq \<Longrightarrow> pw_leq {#x#} {#y#}" |
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
krauss
parents:
28823
diff
changeset
|
1556 |
by (drule pw_leq_step) (rule pw_leq_empty, simp) |
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
krauss
parents:
28823
diff
changeset
|
1557 |
|
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
krauss
parents:
28823
diff
changeset
|
1558 |
lemma pw_leq_split: |
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
krauss
parents:
28823
diff
changeset
|
1559 |
assumes "pw_leq X Y" |
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
krauss
parents:
28823
diff
changeset
|
1560 |
shows "\<exists>A B Z. X = A + Z \<and> Y = B + Z \<and> ((set_of A, set_of B) \<in> max_strict \<or> (B = {#} \<and> A = {#}))" |
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
krauss
parents:
28823
diff
changeset
|
1561 |
using assms |
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
krauss
parents:
28823
diff
changeset
|
1562 |
proof (induct) |
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
krauss
parents:
28823
diff
changeset
|
1563 |
case pw_leq_empty thus ?case by auto |
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
krauss
parents:
28823
diff
changeset
|
1564 |
next |
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
krauss
parents:
28823
diff
changeset
|
1565 |
case (pw_leq_step x y X Y) |
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
krauss
parents:
28823
diff
changeset
|
1566 |
then obtain A B Z where |
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
krauss
parents:
28823
diff
changeset
|
1567 |
[simp]: "X = A + Z" "Y = B + Z" |
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
krauss
parents:
28823
diff
changeset
|
1568 |
and 1[simp]: "(set_of A, set_of B) \<in> max_strict \<or> (B = {#} \<and> A = {#})" |
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
krauss
parents:
28823
diff
changeset
|
1569 |
by auto |
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
krauss
parents:
28823
diff
changeset
|
1570 |
from pw_leq_step have "x = y \<or> (x, y) \<in> pair_less" |
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
krauss
parents:
28823
diff
changeset
|
1571 |
unfolding pair_leq_def by auto |
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
krauss
parents:
28823
diff
changeset
|
1572 |
thus ?case |
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
krauss
parents:
28823
diff
changeset
|
1573 |
proof |
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
krauss
parents:
28823
diff
changeset
|
1574 |
assume [simp]: "x = y" |
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
krauss
parents:
28823
diff
changeset
|
1575 |
have |
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
krauss
parents:
28823
diff
changeset
|
1576 |
"{#x#} + X = A + ({#y#}+Z) |
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
krauss
parents:
28823
diff
changeset
|
1577 |
\<and> {#y#} + Y = B + ({#y#}+Z) |
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
krauss
parents:
28823
diff
changeset
|
1578 |
\<and> ((set_of A, set_of B) \<in> max_strict \<or> (B = {#} \<and> A = {#}))" |
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
krauss
parents:
28823
diff
changeset
|
1579 |
by (auto simp: add_ac) |
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
krauss
parents:
28823
diff
changeset
|
1580 |
thus ?case by (intro exI) |
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
krauss
parents:
28823
diff
changeset
|
1581 |
next |
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
krauss
parents:
28823
diff
changeset
|
1582 |
assume A: "(x, y) \<in> pair_less" |
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
krauss
parents:
28823
diff
changeset
|
1583 |
let ?A' = "{#x#} + A" and ?B' = "{#y#} + B" |
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
krauss
parents:
28823
diff
changeset
|
1584 |
have "{#x#} + X = ?A' + Z" |
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
krauss
parents:
28823
diff
changeset
|
1585 |
"{#y#} + Y = ?B' + Z" |
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
krauss
parents:
28823
diff
changeset
|
1586 |
by (auto simp add: add_ac) |
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
krauss
parents:
28823
diff
changeset
|
1587 |
moreover have |
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
krauss
parents:
28823
diff
changeset
|
1588 |
"(set_of ?A', set_of ?B') \<in> max_strict" |
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
krauss
parents:
28823
diff
changeset
|
1589 |
using 1 A unfolding max_strict_def |
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
krauss
parents:
28823
diff
changeset
|
1590 |
by (auto elim!: max_ext.cases) |
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
krauss
parents:
28823
diff
changeset
|
1591 |
ultimately show ?thesis by blast |
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
krauss
parents:
28823
diff
changeset
|
1592 |
qed |
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
krauss
parents:
28823
diff
changeset
|
1593 |
qed |
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
krauss
parents:
28823
diff
changeset
|
1594 |
|
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
krauss
parents:
28823
diff
changeset
|
1595 |
lemma |
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
krauss
parents:
28823
diff
changeset
|
1596 |
assumes pwleq: "pw_leq Z Z'" |
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
krauss
parents:
28823
diff
changeset
|
1597 |
shows ms_strictI: "(set_of A, set_of B) \<in> max_strict \<Longrightarrow> (Z + A, Z' + B) \<in> ms_strict" |
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
krauss
parents:
28823
diff
changeset
|
1598 |
and ms_weakI1: "(set_of A, set_of B) \<in> max_strict \<Longrightarrow> (Z + A, Z' + B) \<in> ms_weak" |
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
krauss
parents:
28823
diff
changeset
|
1599 |
and ms_weakI2: "(Z + {#}, Z' + {#}) \<in> ms_weak" |
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
krauss
parents:
28823
diff
changeset
|
1600 |
proof - |
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
krauss
parents:
28823
diff
changeset
|
1601 |
from pw_leq_split[OF pwleq] |
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
krauss
parents:
28823
diff
changeset
|
1602 |
obtain A' B' Z'' |
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
krauss
parents:
28823
diff
changeset
|
1603 |
where [simp]: "Z = A' + Z''" "Z' = B' + Z''" |
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
krauss
parents:
28823
diff
changeset
|
1604 |
and mx_or_empty: "(set_of A', set_of B') \<in> max_strict \<or> (A' = {#} \<and> B' = {#})" |
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
krauss
parents:
28823
diff
changeset
|
1605 |
by blast |
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
krauss
parents:
28823
diff
changeset
|
1606 |
{ |
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
krauss
parents:
28823
diff
changeset
|
1607 |
assume max: "(set_of A, set_of B) \<in> max_strict" |
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
krauss
parents:
28823
diff
changeset
|
1608 |
from mx_or_empty |
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
krauss
parents:
28823
diff
changeset
|
1609 |
have "(Z'' + (A + A'), Z'' + (B + B')) \<in> ms_strict" |
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
krauss
parents:
28823
diff
changeset
|
1610 |
proof |
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
krauss
parents:
28823
diff
changeset
|
1611 |
assume max': "(set_of A', set_of B') \<in> max_strict" |
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
krauss
parents:
28823
diff
changeset
|
1612 |
with max have "(set_of (A + A'), set_of (B + B')) \<in> max_strict" |
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
krauss
parents:
28823
diff
changeset
|
1613 |
by (auto simp: max_strict_def intro: max_ext_additive) |
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
krauss
parents:
28823
diff
changeset
|
1614 |
thus ?thesis by (rule smsI) |
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
krauss
parents:
28823
diff
changeset
|
1615 |
next |
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
krauss
parents:
28823
diff
changeset
|
1616 |
assume [simp]: "A' = {#} \<and> B' = {#}" |
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
krauss
parents:
28823
diff
changeset
|
1617 |
show ?thesis by (rule smsI) (auto intro: max) |
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
krauss
parents:
28823
diff
changeset
|
1618 |
qed |
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
krauss
parents:
28823
diff
changeset
|
1619 |
thus "(Z + A, Z' + B) \<in> ms_strict" by (simp add:add_ac) |
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
krauss
parents:
28823
diff
changeset
|
1620 |
thus "(Z + A, Z' + B) \<in> ms_weak" by (simp add: ms_weak_def) |
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
krauss
parents:
28823
diff
changeset
|
1621 |
} |
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
krauss
parents:
28823
diff
changeset
|
1622 |
from mx_or_empty |
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
krauss
parents:
28823
diff
changeset
|
1623 |
have "(Z'' + A', Z'' + B') \<in> ms_weak" by (rule wmsI) |
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
krauss
parents:
28823
diff
changeset
|
1624 |
thus "(Z + {#}, Z' + {#}) \<in> ms_weak" by (simp add:add_ac) |
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
krauss
parents:
28823
diff
changeset
|
1625 |
qed |
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
krauss
parents:
28823
diff
changeset
|
1626 |
|
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
krauss
parents:
28823
diff
changeset
|
1627 |
lemma empty_idemp: "{#} + x = x" "x + {#} = x" |
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
krauss
parents:
28823
diff
changeset
|
1628 |
and nonempty_plus: "{# x #} + rs \<noteq> {#}" |
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
krauss
parents:
28823
diff
changeset
|
1629 |
and nonempty_single: "{# x #} \<noteq> {#}" |
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
krauss
parents:
28823
diff
changeset
|
1630 |
by auto |
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
krauss
parents:
28823
diff
changeset
|
1631 |
|
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
krauss
parents:
28823
diff
changeset
|
1632 |
setup {* |
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
krauss
parents:
28823
diff
changeset
|
1633 |
let |
35402 | 1634 |
fun msetT T = Type (@{type_name multiset}, [T]); |
29125
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
krauss
parents:
28823
diff
changeset
|
1635 |
|
35402 | 1636 |
fun mk_mset T [] = Const (@{const_abbrev Mempty}, msetT T) |
29125
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
krauss
parents:
28823
diff
changeset
|
1637 |
| mk_mset T [x] = Const (@{const_name single}, T --> msetT T) $ x |
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
krauss
parents:
28823
diff
changeset
|
1638 |
| mk_mset T (x :: xs) = |
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
krauss
parents:
28823
diff
changeset
|
1639 |
Const (@{const_name plus}, msetT T --> msetT T --> msetT T) $ |
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
krauss
parents:
28823
diff
changeset
|
1640 |
mk_mset T [x] $ mk_mset T xs |
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
krauss
parents:
28823
diff
changeset
|
1641 |
|
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
krauss
parents:
28823
diff
changeset
|
1642 |
fun mset_member_tac m i = |
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
krauss
parents:
28823
diff
changeset
|
1643 |
(if m <= 0 then |
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
krauss
parents:
28823
diff
changeset
|
1644 |
rtac @{thm multi_member_this} i ORELSE rtac @{thm multi_member_last} i |
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
krauss
parents:
28823
diff
changeset
|
1645 |
else |
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
krauss
parents:
28823
diff
changeset
|
1646 |
rtac @{thm multi_member_skip} i THEN mset_member_tac (m - 1) i) |
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
krauss
parents:
28823
diff
changeset
|
1647 |
|
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
krauss
parents:
28823
diff
changeset
|
1648 |
val mset_nonempty_tac = |
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
krauss
parents:
28823
diff
changeset
|
1649 |
rtac @{thm nonempty_plus} ORELSE' rtac @{thm nonempty_single} |
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
krauss
parents:
28823
diff
changeset
|
1650 |
|
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
krauss
parents:
28823
diff
changeset
|
1651 |
val regroup_munion_conv = |
35402 | 1652 |
Function_Lib.regroup_conv @{const_abbrev Mempty} @{const_name plus} |
34943
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
1653 |
(map (fn t => t RS eq_reflection) (@{thms add_ac} @ @{thms empty_idemp})) |
29125
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
krauss
parents:
28823
diff
changeset
|
1654 |
|
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
krauss
parents:
28823
diff
changeset
|
1655 |
fun unfold_pwleq_tac i = |
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
krauss
parents:
28823
diff
changeset
|
1656 |
(rtac @{thm pw_leq_step} i THEN (fn st => unfold_pwleq_tac (i + 1) st)) |
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
krauss
parents:
28823
diff
changeset
|
1657 |
ORELSE (rtac @{thm pw_leq_lstep} i) |
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
krauss
parents:
28823
diff
changeset
|
1658 |
ORELSE (rtac @{thm pw_leq_empty} i) |
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
krauss
parents:
28823
diff
changeset
|
1659 |
|
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
krauss
parents:
28823
diff
changeset
|
1660 |
val set_of_simps = [@{thm set_of_empty}, @{thm set_of_single}, @{thm set_of_union}, |
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
krauss
parents:
28823
diff
changeset
|
1661 |
@{thm Un_insert_left}, @{thm Un_empty_left}] |
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
krauss
parents:
28823
diff
changeset
|
1662 |
in |
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
krauss
parents:
28823
diff
changeset
|
1663 |
ScnpReconstruct.multiset_setup (ScnpReconstruct.Multiset |
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
krauss
parents:
28823
diff
changeset
|
1664 |
{ |
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
krauss
parents:
28823
diff
changeset
|
1665 |
msetT=msetT, mk_mset=mk_mset, mset_regroup_conv=regroup_munion_conv, |
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
krauss
parents:
28823
diff
changeset
|
1666 |
mset_member_tac=mset_member_tac, mset_nonempty_tac=mset_nonempty_tac, |
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
krauss
parents:
28823
diff
changeset
|
1667 |
mset_pwleq_tac=unfold_pwleq_tac, set_of_simps=set_of_simps, |
30595
c87a3350f5a9
proper spacing before ML antiquotations -- note that @ may be part of symbolic ML identifiers;
wenzelm
parents:
30428
diff
changeset
|
1668 |
smsI'= @{thm ms_strictI}, wmsI2''= @{thm ms_weakI2}, wmsI1= @{thm ms_weakI1}, |
c87a3350f5a9
proper spacing before ML antiquotations -- note that @ may be part of symbolic ML identifiers;
wenzelm
parents:
30428
diff
changeset
|
1669 |
reduction_pair= @{thm ms_reduction_pair} |
29125
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
krauss
parents:
28823
diff
changeset
|
1670 |
}) |
10249 | 1671 |
end |
29125
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
krauss
parents:
28823
diff
changeset
|
1672 |
*} |
d41182a8135c
method "sizechange" proves termination of functions; added more infrastructure for termination proofs
krauss
parents:
28823
diff
changeset
|
1673 |
|
34943
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
1674 |
|
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
1675 |
subsection {* Legacy theorem bindings *} |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
1676 |
|
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
1677 |
lemmas multi_count_eq = multiset_eq_conv_count_eq [symmetric] |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
1678 |
|
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
1679 |
lemma union_commute: "M + N = N + (M::'a multiset)" |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
1680 |
by (fact add_commute) |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
1681 |
|
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
1682 |
lemma union_assoc: "(M + N) + K = M + (N + (K::'a multiset))" |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
1683 |
by (fact add_assoc) |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
1684 |
|
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
1685 |
lemma union_lcomm: "M + (N + K) = N + (M + (K::'a multiset))" |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
1686 |
by (fact add_left_commute) |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
1687 |
|
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
1688 |
lemmas union_ac = union_assoc union_commute union_lcomm |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
1689 |
|
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
1690 |
lemma union_right_cancel: "M + K = N + K \<longleftrightarrow> M = (N::'a multiset)" |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
1691 |
by (fact add_right_cancel) |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
1692 |
|
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
1693 |
lemma union_left_cancel: "K + M = K + N \<longleftrightarrow> M = (N::'a multiset)" |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
1694 |
by (fact add_left_cancel) |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
1695 |
|
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
1696 |
lemma multi_union_self_other_eq: "(A::'a multiset) + X = A + Y \<Longrightarrow> X = Y" |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
1697 |
by (fact add_imp_eq) |
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
1698 |
|
35268
04673275441a
switched notations for pointwise and multiset order
haftmann
parents:
35028
diff
changeset
|
1699 |
lemma mset_less_trans: "(M::'a multiset) < K \<Longrightarrow> K < N \<Longrightarrow> M < N" |
04673275441a
switched notations for pointwise and multiset order
haftmann
parents:
35028
diff
changeset
|
1700 |
by (fact order_less_trans) |
04673275441a
switched notations for pointwise and multiset order
haftmann
parents:
35028
diff
changeset
|
1701 |
|
04673275441a
switched notations for pointwise and multiset order
haftmann
parents:
35028
diff
changeset
|
1702 |
lemma multiset_inter_commute: "A #\<inter> B = B #\<inter> A" |
04673275441a
switched notations for pointwise and multiset order
haftmann
parents:
35028
diff
changeset
|
1703 |
by (fact inf.commute) |
04673275441a
switched notations for pointwise and multiset order
haftmann
parents:
35028
diff
changeset
|
1704 |
|
04673275441a
switched notations for pointwise and multiset order
haftmann
parents:
35028
diff
changeset
|
1705 |
lemma multiset_inter_assoc: "A #\<inter> (B #\<inter> C) = A #\<inter> B #\<inter> C" |
04673275441a
switched notations for pointwise and multiset order
haftmann
parents:
35028
diff
changeset
|
1706 |
by (fact inf.assoc [symmetric]) |
04673275441a
switched notations for pointwise and multiset order
haftmann
parents:
35028
diff
changeset
|
1707 |
|
04673275441a
switched notations for pointwise and multiset order
haftmann
parents:
35028
diff
changeset
|
1708 |
lemma multiset_inter_left_commute: "A #\<inter> (B #\<inter> C) = B #\<inter> (A #\<inter> C)" |
04673275441a
switched notations for pointwise and multiset order
haftmann
parents:
35028
diff
changeset
|
1709 |
by (fact inf.left_commute) |
04673275441a
switched notations for pointwise and multiset order
haftmann
parents:
35028
diff
changeset
|
1710 |
|
04673275441a
switched notations for pointwise and multiset order
haftmann
parents:
35028
diff
changeset
|
1711 |
lemmas multiset_inter_ac = |
04673275441a
switched notations for pointwise and multiset order
haftmann
parents:
35028
diff
changeset
|
1712 |
multiset_inter_commute |
04673275441a
switched notations for pointwise and multiset order
haftmann
parents:
35028
diff
changeset
|
1713 |
multiset_inter_assoc |
04673275441a
switched notations for pointwise and multiset order
haftmann
parents:
35028
diff
changeset
|
1714 |
multiset_inter_left_commute |
04673275441a
switched notations for pointwise and multiset order
haftmann
parents:
35028
diff
changeset
|
1715 |
|
04673275441a
switched notations for pointwise and multiset order
haftmann
parents:
35028
diff
changeset
|
1716 |
lemma mult_less_not_refl: |
04673275441a
switched notations for pointwise and multiset order
haftmann
parents:
35028
diff
changeset
|
1717 |
"\<not> M \<subset># (M::'a::order multiset)" |
04673275441a
switched notations for pointwise and multiset order
haftmann
parents:
35028
diff
changeset
|
1718 |
by (fact multiset_order.less_irrefl) |
04673275441a
switched notations for pointwise and multiset order
haftmann
parents:
35028
diff
changeset
|
1719 |
|
04673275441a
switched notations for pointwise and multiset order
haftmann
parents:
35028
diff
changeset
|
1720 |
lemma mult_less_trans: |
04673275441a
switched notations for pointwise and multiset order
haftmann
parents:
35028
diff
changeset
|
1721 |
"K \<subset># M ==> M \<subset># N ==> K \<subset># (N::'a::order multiset)" |
04673275441a
switched notations for pointwise and multiset order
haftmann
parents:
35028
diff
changeset
|
1722 |
by (fact multiset_order.less_trans) |
04673275441a
switched notations for pointwise and multiset order
haftmann
parents:
35028
diff
changeset
|
1723 |
|
04673275441a
switched notations for pointwise and multiset order
haftmann
parents:
35028
diff
changeset
|
1724 |
lemma mult_less_not_sym: |
04673275441a
switched notations for pointwise and multiset order
haftmann
parents:
35028
diff
changeset
|
1725 |
"M \<subset># N ==> \<not> N \<subset># (M::'a::order multiset)" |
04673275441a
switched notations for pointwise and multiset order
haftmann
parents:
35028
diff
changeset
|
1726 |
by (fact multiset_order.less_not_sym) |
04673275441a
switched notations for pointwise and multiset order
haftmann
parents:
35028
diff
changeset
|
1727 |
|
04673275441a
switched notations for pointwise and multiset order
haftmann
parents:
35028
diff
changeset
|
1728 |
lemma mult_less_asym: |
04673275441a
switched notations for pointwise and multiset order
haftmann
parents:
35028
diff
changeset
|
1729 |
"M \<subset># N ==> (\<not> P ==> N \<subset># (M::'a::order multiset)) ==> P" |
04673275441a
switched notations for pointwise and multiset order
haftmann
parents:
35028
diff
changeset
|
1730 |
by (fact multiset_order.less_asym) |
34943
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
1731 |
|
35712
77aa29bf14ee
added a mechanism to Nitpick to support custom rendering of terms, and used it for multisets
blanchet
parents:
35402
diff
changeset
|
1732 |
ML {* |
77aa29bf14ee
added a mechanism to Nitpick to support custom rendering of terms, and used it for multisets
blanchet
parents:
35402
diff
changeset
|
1733 |
(* Proof.context -> string -> (typ -> term list) -> typ -> term -> term *) |
77aa29bf14ee
added a mechanism to Nitpick to support custom rendering of terms, and used it for multisets
blanchet
parents:
35402
diff
changeset
|
1734 |
fun multiset_postproc _ maybe_name all_values (T as Type (_, [elem_T])) |
77aa29bf14ee
added a mechanism to Nitpick to support custom rendering of terms, and used it for multisets
blanchet
parents:
35402
diff
changeset
|
1735 |
(Const _ $ t') = |
77aa29bf14ee
added a mechanism to Nitpick to support custom rendering of terms, and used it for multisets
blanchet
parents:
35402
diff
changeset
|
1736 |
let |
77aa29bf14ee
added a mechanism to Nitpick to support custom rendering of terms, and used it for multisets
blanchet
parents:
35402
diff
changeset
|
1737 |
val (maybe_opt, ps) = |
77aa29bf14ee
added a mechanism to Nitpick to support custom rendering of terms, and used it for multisets
blanchet
parents:
35402
diff
changeset
|
1738 |
Nitpick_Model.dest_plain_fun t' ||> op ~~ |
77aa29bf14ee
added a mechanism to Nitpick to support custom rendering of terms, and used it for multisets
blanchet
parents:
35402
diff
changeset
|
1739 |
||> map (apsnd (snd o HOLogic.dest_number)) |
77aa29bf14ee
added a mechanism to Nitpick to support custom rendering of terms, and used it for multisets
blanchet
parents:
35402
diff
changeset
|
1740 |
fun elems_for t = |
77aa29bf14ee
added a mechanism to Nitpick to support custom rendering of terms, and used it for multisets
blanchet
parents:
35402
diff
changeset
|
1741 |
case AList.lookup (op =) ps t of |
77aa29bf14ee
added a mechanism to Nitpick to support custom rendering of terms, and used it for multisets
blanchet
parents:
35402
diff
changeset
|
1742 |
SOME n => replicate n t |
77aa29bf14ee
added a mechanism to Nitpick to support custom rendering of terms, and used it for multisets
blanchet
parents:
35402
diff
changeset
|
1743 |
| NONE => [Const (maybe_name, elem_T --> elem_T) $ t] |
77aa29bf14ee
added a mechanism to Nitpick to support custom rendering of terms, and used it for multisets
blanchet
parents:
35402
diff
changeset
|
1744 |
in |
77aa29bf14ee
added a mechanism to Nitpick to support custom rendering of terms, and used it for multisets
blanchet
parents:
35402
diff
changeset
|
1745 |
case maps elems_for (all_values elem_T) @ |
77aa29bf14ee
added a mechanism to Nitpick to support custom rendering of terms, and used it for multisets
blanchet
parents:
35402
diff
changeset
|
1746 |
(if maybe_opt then [Const (Nitpick_Model.unrep, elem_T)] else []) of |
77aa29bf14ee
added a mechanism to Nitpick to support custom rendering of terms, and used it for multisets
blanchet
parents:
35402
diff
changeset
|
1747 |
[] => Const (@{const_name zero_class.zero}, T) |
77aa29bf14ee
added a mechanism to Nitpick to support custom rendering of terms, and used it for multisets
blanchet
parents:
35402
diff
changeset
|
1748 |
| ts => foldl1 (fn (t1, t2) => |
77aa29bf14ee
added a mechanism to Nitpick to support custom rendering of terms, and used it for multisets
blanchet
parents:
35402
diff
changeset
|
1749 |
Const (@{const_name plus_class.plus}, T --> T --> T) |
77aa29bf14ee
added a mechanism to Nitpick to support custom rendering of terms, and used it for multisets
blanchet
parents:
35402
diff
changeset
|
1750 |
$ t1 $ t2) |
77aa29bf14ee
added a mechanism to Nitpick to support custom rendering of terms, and used it for multisets
blanchet
parents:
35402
diff
changeset
|
1751 |
(map (curry (op $) (Const (@{const_name single}, |
77aa29bf14ee
added a mechanism to Nitpick to support custom rendering of terms, and used it for multisets
blanchet
parents:
35402
diff
changeset
|
1752 |
elem_T --> T))) ts) |
77aa29bf14ee
added a mechanism to Nitpick to support custom rendering of terms, and used it for multisets
blanchet
parents:
35402
diff
changeset
|
1753 |
end |
77aa29bf14ee
added a mechanism to Nitpick to support custom rendering of terms, and used it for multisets
blanchet
parents:
35402
diff
changeset
|
1754 |
| multiset_postproc _ _ _ _ t = t |
77aa29bf14ee
added a mechanism to Nitpick to support custom rendering of terms, and used it for multisets
blanchet
parents:
35402
diff
changeset
|
1755 |
*} |
77aa29bf14ee
added a mechanism to Nitpick to support custom rendering of terms, and used it for multisets
blanchet
parents:
35402
diff
changeset
|
1756 |
|
77aa29bf14ee
added a mechanism to Nitpick to support custom rendering of terms, and used it for multisets
blanchet
parents:
35402
diff
changeset
|
1757 |
setup {* |
77aa29bf14ee
added a mechanism to Nitpick to support custom rendering of terms, and used it for multisets
blanchet
parents:
35402
diff
changeset
|
1758 |
Nitpick.register_term_postprocessor @{typ "'a multiset"} multiset_postproc |
77aa29bf14ee
added a mechanism to Nitpick to support custom rendering of terms, and used it for multisets
blanchet
parents:
35402
diff
changeset
|
1759 |
*} |
77aa29bf14ee
added a mechanism to Nitpick to support custom rendering of terms, and used it for multisets
blanchet
parents:
35402
diff
changeset
|
1760 |
|
34943
e97b22500a5c
cleanup of Multiset.thy: less duplication, tuned and simplified a couple of proofs, less historical organization of sections, conversion from associations lists to multisets, rudimentary code generation
haftmann
parents:
33102
diff
changeset
|
1761 |
end |