author | huffman |
Fri, 05 Mar 2010 14:05:25 -0800 | |
changeset 35596 | 49a02dab35ed |
parent 35416 | d8d7d1b785af |
child 35847 | 19f1f7066917 |
permissions | -rw-r--r-- |
14706 | 1 |
(* Title: HOL/Algebra/FiniteProduct.thy |
13936 | 2 |
Author: Clemens Ballarin, started 19 November 2002 |
3 |
||
4 |
This file is largely based on HOL/Finite_Set.thy. |
|
5 |
*) |
|
6 |
||
20318
0e0ea63fe768
Restructured algebra library, added ideals and quotient rings.
ballarin
parents:
16638
diff
changeset
|
7 |
theory FiniteProduct imports Group begin |
0e0ea63fe768
Restructured algebra library, added ideals and quotient rings.
ballarin
parents:
16638
diff
changeset
|
8 |
|
13936 | 9 |
|
27717
21bbd410ba04
Generalised polynomial lemmas from cring to ring.
ballarin
parents:
27699
diff
changeset
|
10 |
subsection {* Product Operator for Commutative Monoids *} |
20318
0e0ea63fe768
Restructured algebra library, added ideals and quotient rings.
ballarin
parents:
16638
diff
changeset
|
11 |
|
27717
21bbd410ba04
Generalised polynomial lemmas from cring to ring.
ballarin
parents:
27699
diff
changeset
|
12 |
subsubsection {* Inductive Definition of a Relation for Products over Sets *} |
13936 | 13 |
|
14750 | 14 |
text {* Instantiation of locale @{text LC} of theory @{text Finite_Set} is not |
15 |
possible, because here we have explicit typing rules like |
|
16 |
@{text "x \<in> carrier G"}. We introduce an explicit argument for the domain |
|
14651 | 17 |
@{text D}. *} |
13936 | 18 |
|
23746 | 19 |
inductive_set |
13936 | 20 |
foldSetD :: "['a set, 'b => 'a => 'a, 'a] => ('b set * 'a) set" |
23746 | 21 |
for D :: "'a set" and f :: "'b => 'a => 'a" and e :: 'a |
22 |
where |
|
14750 | 23 |
emptyI [intro]: "e \<in> D ==> ({}, e) \<in> foldSetD D f e" |
23746 | 24 |
| insertI [intro]: "[| x ~: A; f x y \<in> D; (A, y) \<in> foldSetD D f e |] ==> |
14750 | 25 |
(insert x A, f x y) \<in> foldSetD D f e" |
13936 | 26 |
|
14750 | 27 |
inductive_cases empty_foldSetDE [elim!]: "({}, x) \<in> foldSetD D f e" |
13936 | 28 |
|
35416
d8d7d1b785af
replaced a couple of constsdefs by definitions (also some old primrecs by modern ones)
haftmann
parents:
35054
diff
changeset
|
29 |
definition foldD :: "['a set, 'b => 'a => 'a, 'a, 'b set] => 'a" where |
14750 | 30 |
"foldD D f e A == THE x. (A, x) \<in> foldSetD D f e" |
13936 | 31 |
|
32 |
lemma foldSetD_closed: |
|
14750 | 33 |
"[| (A, z) \<in> foldSetD D f e ; e \<in> D; !!x y. [| x \<in> A; y \<in> D |] ==> f x y \<in> D |
34 |
|] ==> z \<in> D"; |
|
23746 | 35 |
by (erule foldSetD.cases) auto |
13936 | 36 |
|
37 |
lemma Diff1_foldSetD: |
|
14750 | 38 |
"[| (A - {x}, y) \<in> foldSetD D f e; x \<in> A; f x y \<in> D |] ==> |
39 |
(A, f x y) \<in> foldSetD D f e" |
|
13936 | 40 |
apply (erule insert_Diff [THEN subst], rule foldSetD.intros) |
41 |
apply auto |
|
42 |
done |
|
43 |
||
14750 | 44 |
lemma foldSetD_imp_finite [simp]: "(A, x) \<in> foldSetD D f e ==> finite A" |
13936 | 45 |
by (induct set: foldSetD) auto |
46 |
||
47 |
lemma finite_imp_foldSetD: |
|
14750 | 48 |
"[| finite A; e \<in> D; !!x y. [| x \<in> A; y \<in> D |] ==> f x y \<in> D |] ==> |
49 |
EX x. (A, x) \<in> foldSetD D f e" |
|
22265 | 50 |
proof (induct set: finite) |
13936 | 51 |
case empty then show ?case by auto |
52 |
next |
|
15328 | 53 |
case (insert x F) |
14750 | 54 |
then obtain y where y: "(F, y) \<in> foldSetD D f e" by auto |
55 |
with insert have "y \<in> D" by (auto dest: foldSetD_closed) |
|
56 |
with y and insert have "(insert x F, f x y) \<in> foldSetD D f e" |
|
13936 | 57 |
by (intro foldSetD.intros) auto |
58 |
then show ?case .. |
|
59 |
qed |
|
60 |
||
20318
0e0ea63fe768
Restructured algebra library, added ideals and quotient rings.
ballarin
parents:
16638
diff
changeset
|
61 |
|
27717
21bbd410ba04
Generalised polynomial lemmas from cring to ring.
ballarin
parents:
27699
diff
changeset
|
62 |
text {* Left-Commutative Operations *} |
13936 | 63 |
|
64 |
locale LCD = |
|
65 |
fixes B :: "'b set" |
|
66 |
and D :: "'a set" |
|
67 |
and f :: "'b => 'a => 'a" (infixl "\<cdot>" 70) |
|
68 |
assumes left_commute: |
|
14750 | 69 |
"[| x \<in> B; y \<in> B; z \<in> D |] ==> x \<cdot> (y \<cdot> z) = y \<cdot> (x \<cdot> z)" |
70 |
and f_closed [simp, intro!]: "!!x y. [| x \<in> B; y \<in> D |] ==> f x y \<in> D" |
|
13936 | 71 |
|
72 |
lemma (in LCD) foldSetD_closed [dest]: |
|
14750 | 73 |
"(A, z) \<in> foldSetD D f e ==> z \<in> D"; |
23746 | 74 |
by (erule foldSetD.cases) auto |
13936 | 75 |
|
76 |
lemma (in LCD) Diff1_foldSetD: |
|
14750 | 77 |
"[| (A - {x}, y) \<in> foldSetD D f e; x \<in> A; A \<subseteq> B |] ==> |
78 |
(A, f x y) \<in> foldSetD D f e" |
|
79 |
apply (subgoal_tac "x \<in> B") |
|
13936 | 80 |
prefer 2 apply fast |
81 |
apply (erule insert_Diff [THEN subst], rule foldSetD.intros) |
|
82 |
apply auto |
|
83 |
done |
|
84 |
||
85 |
lemma (in LCD) foldSetD_imp_finite [simp]: |
|
14750 | 86 |
"(A, x) \<in> foldSetD D f e ==> finite A" |
13936 | 87 |
by (induct set: foldSetD) auto |
88 |
||
89 |
lemma (in LCD) finite_imp_foldSetD: |
|
14750 | 90 |
"[| finite A; A \<subseteq> B; e \<in> D |] ==> EX x. (A, x) \<in> foldSetD D f e" |
22265 | 91 |
proof (induct set: finite) |
13936 | 92 |
case empty then show ?case by auto |
93 |
next |
|
15328 | 94 |
case (insert x F) |
14750 | 95 |
then obtain y where y: "(F, y) \<in> foldSetD D f e" by auto |
96 |
with insert have "y \<in> D" by auto |
|
97 |
with y and insert have "(insert x F, f x y) \<in> foldSetD D f e" |
|
13936 | 98 |
by (intro foldSetD.intros) auto |
99 |
then show ?case .. |
|
100 |
qed |
|
101 |
||
102 |
lemma (in LCD) foldSetD_determ_aux: |
|
14750 | 103 |
"e \<in> D ==> \<forall>A x. A \<subseteq> B & card A < n --> (A, x) \<in> foldSetD D f e --> |
104 |
(\<forall>y. (A, y) \<in> foldSetD D f e --> y = x)" |
|
13936 | 105 |
apply (induct n) |
106 |
apply (auto simp add: less_Suc_eq) (* slow *) |
|
107 |
apply (erule foldSetD.cases) |
|
108 |
apply blast |
|
109 |
apply (erule foldSetD.cases) |
|
110 |
apply blast |
|
111 |
apply clarify |
|
112 |
txt {* force simplification of @{text "card A < card (insert ...)"}. *} |
|
113 |
apply (erule rev_mp) |
|
114 |
apply (simp add: less_Suc_eq_le) |
|
115 |
apply (rule impI) |
|
23746 | 116 |
apply (rename_tac xa Aa ya xb Ab yb, case_tac "xa = xb") |
13936 | 117 |
apply (subgoal_tac "Aa = Ab") |
118 |
prefer 2 apply (blast elim!: equalityE) |
|
119 |
apply blast |
|
120 |
txt {* case @{prop "xa \<notin> xb"}. *} |
|
14750 | 121 |
apply (subgoal_tac "Aa - {xb} = Ab - {xa} & xb \<in> Aa & xa \<in> Ab") |
13936 | 122 |
prefer 2 apply (blast elim!: equalityE) |
123 |
apply clarify |
|
124 |
apply (subgoal_tac "Aa = insert xb Ab - {xa}") |
|
125 |
prefer 2 apply blast |
|
14750 | 126 |
apply (subgoal_tac "card Aa \<le> card Ab") |
13936 | 127 |
prefer 2 |
128 |
apply (rule Suc_le_mono [THEN subst]) |
|
129 |
apply (simp add: card_Suc_Diff1) |
|
130 |
apply (rule_tac A1 = "Aa - {xb}" in finite_imp_foldSetD [THEN exE]) |
|
131 |
apply (blast intro: foldSetD_imp_finite finite_Diff) |
|
132 |
apply best |
|
133 |
apply assumption |
|
134 |
apply (frule (1) Diff1_foldSetD) |
|
135 |
apply best |
|
136 |
apply (subgoal_tac "ya = f xb x") |
|
137 |
prefer 2 |
|
14750 | 138 |
apply (subgoal_tac "Aa \<subseteq> B") |
13936 | 139 |
prefer 2 apply best (* slow *) |
140 |
apply (blast del: equalityCE) |
|
14750 | 141 |
apply (subgoal_tac "(Ab - {xa}, x) \<in> foldSetD D f e") |
13936 | 142 |
prefer 2 apply simp |
143 |
apply (subgoal_tac "yb = f xa x") |
|
144 |
prefer 2 |
|
145 |
apply (blast del: equalityCE dest: Diff1_foldSetD) |
|
146 |
apply (simp (no_asm_simp)) |
|
147 |
apply (rule left_commute) |
|
148 |
apply assumption |
|
149 |
apply best (* slow *) |
|
150 |
apply best |
|
151 |
done |
|
152 |
||
153 |
lemma (in LCD) foldSetD_determ: |
|
14750 | 154 |
"[| (A, x) \<in> foldSetD D f e; (A, y) \<in> foldSetD D f e; e \<in> D; A \<subseteq> B |] |
13936 | 155 |
==> y = x" |
156 |
by (blast intro: foldSetD_determ_aux [rule_format]) |
|
157 |
||
158 |
lemma (in LCD) foldD_equality: |
|
14750 | 159 |
"[| (A, y) \<in> foldSetD D f e; e \<in> D; A \<subseteq> B |] ==> foldD D f e A = y" |
13936 | 160 |
by (unfold foldD_def) (blast intro: foldSetD_determ) |
161 |
||
162 |
lemma foldD_empty [simp]: |
|
14750 | 163 |
"e \<in> D ==> foldD D f e {} = e" |
13936 | 164 |
by (unfold foldD_def) blast |
165 |
||
166 |
lemma (in LCD) foldD_insert_aux: |
|
14750 | 167 |
"[| x ~: A; x \<in> B; e \<in> D; A \<subseteq> B |] ==> |
168 |
((insert x A, v) \<in> foldSetD D f e) = |
|
169 |
(EX y. (A, y) \<in> foldSetD D f e & v = f x y)" |
|
13936 | 170 |
apply auto |
171 |
apply (rule_tac A1 = A in finite_imp_foldSetD [THEN exE]) |
|
172 |
apply (fastsimp dest: foldSetD_imp_finite) |
|
173 |
apply assumption |
|
174 |
apply assumption |
|
175 |
apply (blast intro: foldSetD_determ) |
|
176 |
done |
|
177 |
||
178 |
lemma (in LCD) foldD_insert: |
|
14750 | 179 |
"[| finite A; x ~: A; x \<in> B; e \<in> D; A \<subseteq> B |] ==> |
13936 | 180 |
foldD D f e (insert x A) = f x (foldD D f e A)" |
181 |
apply (unfold foldD_def) |
|
182 |
apply (simp add: foldD_insert_aux) |
|
183 |
apply (rule the_equality) |
|
184 |
apply (auto intro: finite_imp_foldSetD |
|
185 |
cong add: conj_cong simp add: foldD_def [symmetric] foldD_equality) |
|
186 |
done |
|
187 |
||
188 |
lemma (in LCD) foldD_closed [simp]: |
|
14750 | 189 |
"[| finite A; e \<in> D; A \<subseteq> B |] ==> foldD D f e A \<in> D" |
22265 | 190 |
proof (induct set: finite) |
13936 | 191 |
case empty then show ?case by (simp add: foldD_empty) |
192 |
next |
|
193 |
case insert then show ?case by (simp add: foldD_insert) |
|
194 |
qed |
|
195 |
||
196 |
lemma (in LCD) foldD_commute: |
|
14750 | 197 |
"[| finite A; x \<in> B; e \<in> D; A \<subseteq> B |] ==> |
13936 | 198 |
f x (foldD D f e A) = foldD D f (f x e) A" |
22265 | 199 |
apply (induct set: finite) |
13936 | 200 |
apply simp |
201 |
apply (auto simp add: left_commute foldD_insert) |
|
202 |
done |
|
203 |
||
204 |
lemma Int_mono2: |
|
14750 | 205 |
"[| A \<subseteq> C; B \<subseteq> C |] ==> A Int B \<subseteq> C" |
13936 | 206 |
by blast |
207 |
||
208 |
lemma (in LCD) foldD_nest_Un_Int: |
|
14750 | 209 |
"[| finite A; finite C; e \<in> D; A \<subseteq> B; C \<subseteq> B |] ==> |
13936 | 210 |
foldD D f (foldD D f e C) A = foldD D f (foldD D f e (A Int C)) (A Un C)" |
22265 | 211 |
apply (induct set: finite) |
13936 | 212 |
apply simp |
213 |
apply (simp add: foldD_insert foldD_commute Int_insert_left insert_absorb |
|
32693 | 214 |
Int_mono2) |
13936 | 215 |
done |
216 |
||
217 |
lemma (in LCD) foldD_nest_Un_disjoint: |
|
14750 | 218 |
"[| finite A; finite B; A Int B = {}; e \<in> D; A \<subseteq> B; C \<subseteq> B |] |
13936 | 219 |
==> foldD D f e (A Un B) = foldD D f (foldD D f e B) A" |
220 |
by (simp add: foldD_nest_Un_Int) |
|
221 |
||
222 |
-- {* Delete rules to do with @{text foldSetD} relation. *} |
|
223 |
||
224 |
declare foldSetD_imp_finite [simp del] |
|
225 |
empty_foldSetDE [rule del] |
|
226 |
foldSetD.intros [rule del] |
|
227 |
declare (in LCD) |
|
228 |
foldSetD_closed [rule del] |
|
229 |
||
20318
0e0ea63fe768
Restructured algebra library, added ideals and quotient rings.
ballarin
parents:
16638
diff
changeset
|
230 |
|
27717
21bbd410ba04
Generalised polynomial lemmas from cring to ring.
ballarin
parents:
27699
diff
changeset
|
231 |
text {* Commutative Monoids *} |
13936 | 232 |
|
233 |
text {* |
|
234 |
We enter a more restrictive context, with @{text "f :: 'a => 'a => 'a"} |
|
235 |
instead of @{text "'b => 'a => 'a"}. |
|
236 |
*} |
|
237 |
||
238 |
locale ACeD = |
|
239 |
fixes D :: "'a set" |
|
240 |
and f :: "'a => 'a => 'a" (infixl "\<cdot>" 70) |
|
241 |
and e :: 'a |
|
14750 | 242 |
assumes ident [simp]: "x \<in> D ==> x \<cdot> e = x" |
243 |
and commute: "[| x \<in> D; y \<in> D |] ==> x \<cdot> y = y \<cdot> x" |
|
244 |
and assoc: "[| x \<in> D; y \<in> D; z \<in> D |] ==> (x \<cdot> y) \<cdot> z = x \<cdot> (y \<cdot> z)" |
|
245 |
and e_closed [simp]: "e \<in> D" |
|
246 |
and f_closed [simp]: "[| x \<in> D; y \<in> D |] ==> x \<cdot> y \<in> D" |
|
13936 | 247 |
|
248 |
lemma (in ACeD) left_commute: |
|
14750 | 249 |
"[| x \<in> D; y \<in> D; z \<in> D |] ==> x \<cdot> (y \<cdot> z) = y \<cdot> (x \<cdot> z)" |
13936 | 250 |
proof - |
14750 | 251 |
assume D: "x \<in> D" "y \<in> D" "z \<in> D" |
13936 | 252 |
then have "x \<cdot> (y \<cdot> z) = (y \<cdot> z) \<cdot> x" by (simp add: commute) |
253 |
also from D have "... = y \<cdot> (z \<cdot> x)" by (simp add: assoc) |
|
254 |
also from D have "z \<cdot> x = x \<cdot> z" by (simp add: commute) |
|
255 |
finally show ?thesis . |
|
256 |
qed |
|
257 |
||
258 |
lemmas (in ACeD) AC = assoc commute left_commute |
|
259 |
||
14750 | 260 |
lemma (in ACeD) left_ident [simp]: "x \<in> D ==> e \<cdot> x = x" |
13936 | 261 |
proof - |
23350 | 262 |
assume "x \<in> D" |
263 |
then have "x \<cdot> e = x" by (rule ident) |
|
264 |
with `x \<in> D` show ?thesis by (simp add: commute) |
|
13936 | 265 |
qed |
266 |
||
267 |
lemma (in ACeD) foldD_Un_Int: |
|
14750 | 268 |
"[| finite A; finite B; A \<subseteq> D; B \<subseteq> D |] ==> |
13936 | 269 |
foldD D f e A \<cdot> foldD D f e B = |
270 |
foldD D f e (A Un B) \<cdot> foldD D f e (A Int B)" |
|
22265 | 271 |
apply (induct set: finite) |
13936 | 272 |
apply (simp add: left_commute LCD.foldD_closed [OF LCD.intro [of D]]) |
273 |
apply (simp add: AC insert_absorb Int_insert_left |
|
274 |
LCD.foldD_insert [OF LCD.intro [of D]] |
|
275 |
LCD.foldD_closed [OF LCD.intro [of D]] |
|
32693 | 276 |
Int_mono2) |
13936 | 277 |
done |
278 |
||
279 |
lemma (in ACeD) foldD_Un_disjoint: |
|
14750 | 280 |
"[| finite A; finite B; A Int B = {}; A \<subseteq> D; B \<subseteq> D |] ==> |
13936 | 281 |
foldD D f e (A Un B) = foldD D f e A \<cdot> foldD D f e B" |
282 |
by (simp add: foldD_Un_Int |
|
32693 | 283 |
left_commute LCD.foldD_closed [OF LCD.intro [of D]]) |
13936 | 284 |
|
20318
0e0ea63fe768
Restructured algebra library, added ideals and quotient rings.
ballarin
parents:
16638
diff
changeset
|
285 |
|
27717
21bbd410ba04
Generalised polynomial lemmas from cring to ring.
ballarin
parents:
27699
diff
changeset
|
286 |
subsubsection {* Products over Finite Sets *} |
13936 | 287 |
|
14651 | 288 |
constdefs (structure G) |
15095
63f5f4c265dd
Theories now take advantage of recent syntax improvements with (structure).
ballarin
parents:
14750
diff
changeset
|
289 |
finprod :: "[('b, 'm) monoid_scheme, 'a => 'b, 'a set] => 'b" |
13936 | 290 |
"finprod G f A == if finite A |
14651 | 291 |
then foldD (carrier G) (mult G o f) \<one> A |
28524 | 292 |
else undefined" |
13936 | 293 |
|
14651 | 294 |
syntax |
295 |
"_finprod" :: "index => idt => 'a set => 'b => 'b" |
|
14666 | 296 |
("(3\<Otimes>__:_. _)" [1000, 0, 51, 10] 10) |
14651 | 297 |
syntax (xsymbols) |
298 |
"_finprod" :: "index => idt => 'a set => 'b => 'b" |
|
14666 | 299 |
("(3\<Otimes>__\<in>_. _)" [1000, 0, 51, 10] 10) |
14651 | 300 |
syntax (HTML output) |
301 |
"_finprod" :: "index => idt => 'a set => 'b => 'b" |
|
14666 | 302 |
("(3\<Otimes>__\<in>_. _)" [1000, 0, 51, 10] 10) |
14651 | 303 |
translations |
35054 | 304 |
"\<Otimes>\<index>i:A. b" == "CONST finprod \<struct>\<index> (%i. b) A" |
15095
63f5f4c265dd
Theories now take advantage of recent syntax improvements with (structure).
ballarin
parents:
14750
diff
changeset
|
305 |
-- {* Beware of argument permutation! *} |
13936 | 306 |
|
307 |
lemma (in comm_monoid) finprod_empty [simp]: |
|
308 |
"finprod G f {} = \<one>" |
|
309 |
by (simp add: finprod_def) |
|
310 |
||
311 |
declare funcsetI [intro] |
|
312 |
funcset_mem [dest] |
|
313 |
||
27933 | 314 |
context comm_monoid begin |
315 |
||
316 |
lemma finprod_insert [simp]: |
|
13936 | 317 |
"[| finite F; a \<notin> F; f \<in> F -> carrier G; f a \<in> carrier G |] ==> |
318 |
finprod G f (insert a F) = f a \<otimes> finprod G f F" |
|
319 |
apply (rule trans) |
|
320 |
apply (simp add: finprod_def) |
|
321 |
apply (rule trans) |
|
322 |
apply (rule LCD.foldD_insert [OF LCD.intro [of "insert a F"]]) |
|
323 |
apply simp |
|
324 |
apply (rule m_lcomm) |
|
325 |
apply fast |
|
326 |
apply fast |
|
327 |
apply assumption |
|
328 |
apply (fastsimp intro: m_closed) |
|
329 |
apply simp+ |
|
330 |
apply fast |
|
331 |
apply (auto simp add: finprod_def) |
|
332 |
done |
|
333 |
||
27933 | 334 |
lemma finprod_one [simp]: |
14651 | 335 |
"finite A ==> (\<Otimes>i:A. \<one>) = \<one>" |
22265 | 336 |
proof (induct set: finite) |
13936 | 337 |
case empty show ?case by simp |
338 |
next |
|
15328 | 339 |
case (insert a A) |
13936 | 340 |
have "(%i. \<one>) \<in> A -> carrier G" by auto |
341 |
with insert show ?case by simp |
|
342 |
qed |
|
343 |
||
27933 | 344 |
lemma finprod_closed [simp]: |
13936 | 345 |
fixes A |
346 |
assumes fin: "finite A" and f: "f \<in> A -> carrier G" |
|
347 |
shows "finprod G f A \<in> carrier G" |
|
348 |
using fin f |
|
349 |
proof induct |
|
350 |
case empty show ?case by simp |
|
351 |
next |
|
15328 | 352 |
case (insert a A) |
13936 | 353 |
then have a: "f a \<in> carrier G" by fast |
354 |
from insert have A: "f \<in> A -> carrier G" by fast |
|
355 |
from insert A a show ?case by simp |
|
356 |
qed |
|
357 |
||
358 |
lemma funcset_Int_left [simp, intro]: |
|
359 |
"[| f \<in> A -> C; f \<in> B -> C |] ==> f \<in> A Int B -> C" |
|
360 |
by fast |
|
361 |
||
362 |
lemma funcset_Un_left [iff]: |
|
363 |
"(f \<in> A Un B -> C) = (f \<in> A -> C & f \<in> B -> C)" |
|
364 |
by fast |
|
365 |
||
27933 | 366 |
lemma finprod_Un_Int: |
13936 | 367 |
"[| finite A; finite B; g \<in> A -> carrier G; g \<in> B -> carrier G |] ==> |
368 |
finprod G g (A Un B) \<otimes> finprod G g (A Int B) = |
|
369 |
finprod G g A \<otimes> finprod G g B" |
|
370 |
-- {* The reversed orientation looks more natural, but LOOPS as a simprule! *} |
|
22265 | 371 |
proof (induct set: finite) |
13936 | 372 |
case empty then show ?case by (simp add: finprod_closed) |
373 |
next |
|
15328 | 374 |
case (insert a A) |
13936 | 375 |
then have a: "g a \<in> carrier G" by fast |
376 |
from insert have A: "g \<in> A -> carrier G" by fast |
|
377 |
from insert A a show ?case |
|
378 |
by (simp add: m_ac Int_insert_left insert_absorb finprod_closed |
|
32693 | 379 |
Int_mono2) |
13936 | 380 |
qed |
381 |
||
27933 | 382 |
lemma finprod_Un_disjoint: |
13936 | 383 |
"[| finite A; finite B; A Int B = {}; |
384 |
g \<in> A -> carrier G; g \<in> B -> carrier G |] |
|
385 |
==> finprod G g (A Un B) = finprod G g A \<otimes> finprod G g B" |
|
386 |
apply (subst finprod_Un_Int [symmetric]) |
|
387 |
apply (auto simp add: finprod_closed) |
|
388 |
done |
|
389 |
||
27933 | 390 |
lemma finprod_multf: |
13936 | 391 |
"[| finite A; f \<in> A -> carrier G; g \<in> A -> carrier G |] ==> |
392 |
finprod G (%x. f x \<otimes> g x) A = (finprod G f A \<otimes> finprod G g A)" |
|
22265 | 393 |
proof (induct set: finite) |
13936 | 394 |
case empty show ?case by simp |
395 |
next |
|
15328 | 396 |
case (insert a A) then |
14750 | 397 |
have fA: "f \<in> A -> carrier G" by fast |
398 |
from insert have fa: "f a \<in> carrier G" by fast |
|
399 |
from insert have gA: "g \<in> A -> carrier G" by fast |
|
400 |
from insert have ga: "g a \<in> carrier G" by fast |
|
401 |
from insert have fgA: "(%x. f x \<otimes> g x) \<in> A -> carrier G" |
|
13936 | 402 |
by (simp add: Pi_def) |
15095
63f5f4c265dd
Theories now take advantage of recent syntax improvements with (structure).
ballarin
parents:
14750
diff
changeset
|
403 |
show ?case |
63f5f4c265dd
Theories now take advantage of recent syntax improvements with (structure).
ballarin
parents:
14750
diff
changeset
|
404 |
by (simp add: insert fA fa gA ga fgA m_ac) |
13936 | 405 |
qed |
406 |
||
27933 | 407 |
lemma finprod_cong': |
14750 | 408 |
"[| A = B; g \<in> B -> carrier G; |
409 |
!!i. i \<in> B ==> f i = g i |] ==> finprod G f A = finprod G g B" |
|
13936 | 410 |
proof - |
14750 | 411 |
assume prems: "A = B" "g \<in> B -> carrier G" |
412 |
"!!i. i \<in> B ==> f i = g i" |
|
13936 | 413 |
show ?thesis |
414 |
proof (cases "finite B") |
|
415 |
case True |
|
14750 | 416 |
then have "!!A. [| A = B; g \<in> B -> carrier G; |
417 |
!!i. i \<in> B ==> f i = g i |] ==> finprod G f A = finprod G g B" |
|
13936 | 418 |
proof induct |
419 |
case empty thus ?case by simp |
|
420 |
next |
|
15328 | 421 |
case (insert x B) |
13936 | 422 |
then have "finprod G f A = finprod G f (insert x B)" by simp |
423 |
also from insert have "... = f x \<otimes> finprod G f B" |
|
424 |
proof (intro finprod_insert) |
|
32960
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents:
32693
diff
changeset
|
425 |
show "finite B" by fact |
13936 | 426 |
next |
32960
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents:
32693
diff
changeset
|
427 |
show "x ~: B" by fact |
13936 | 428 |
next |
32960
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents:
32693
diff
changeset
|
429 |
assume "x ~: B" "!!i. i \<in> insert x B \<Longrightarrow> f i = g i" |
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents:
32693
diff
changeset
|
430 |
"g \<in> insert x B \<rightarrow> carrier G" |
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents:
32693
diff
changeset
|
431 |
thus "f \<in> B -> carrier G" by fastsimp |
13936 | 432 |
next |
32960
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents:
32693
diff
changeset
|
433 |
assume "x ~: B" "!!i. i \<in> insert x B \<Longrightarrow> f i = g i" |
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents:
32693
diff
changeset
|
434 |
"g \<in> insert x B \<rightarrow> carrier G" |
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents:
32693
diff
changeset
|
435 |
thus "f x \<in> carrier G" by fastsimp |
13936 | 436 |
qed |
437 |
also from insert have "... = g x \<otimes> finprod G g B" by fastsimp |
|
438 |
also from insert have "... = finprod G g (insert x B)" |
|
439 |
by (intro finprod_insert [THEN sym]) auto |
|
440 |
finally show ?case . |
|
441 |
qed |
|
442 |
with prems show ?thesis by simp |
|
443 |
next |
|
444 |
case False with prems show ?thesis by (simp add: finprod_def) |
|
445 |
qed |
|
446 |
qed |
|
447 |
||
27933 | 448 |
lemma finprod_cong: |
14750 | 449 |
"[| A = B; f \<in> B -> carrier G = True; |
450 |
!!i. i \<in> B ==> f i = g i |] ==> finprod G f A = finprod G g B" |
|
14213
7bf882b0a51e
Changed order of prems in finprod_cong. Slight speedup.
ballarin
parents:
13936
diff
changeset
|
451 |
(* This order of prems is slightly faster (3%) than the last two swapped. *) |
7bf882b0a51e
Changed order of prems in finprod_cong. Slight speedup.
ballarin
parents:
13936
diff
changeset
|
452 |
by (rule finprod_cong') force+ |
13936 | 453 |
|
454 |
text {*Usually, if this rule causes a failed congruence proof error, |
|
14750 | 455 |
the reason is that the premise @{text "g \<in> B -> carrier G"} cannot be shown. |
13936 | 456 |
Adding @{thm [source] Pi_def} to the simpset is often useful. |
457 |
For this reason, @{thm [source] comm_monoid.finprod_cong} |
|
458 |
is not added to the simpset by default. |
|
459 |
*} |
|
460 |
||
27933 | 461 |
end |
462 |
||
13936 | 463 |
declare funcsetI [rule del] |
464 |
funcset_mem [rule del] |
|
465 |
||
27933 | 466 |
context comm_monoid begin |
467 |
||
468 |
lemma finprod_0 [simp]: |
|
14750 | 469 |
"f \<in> {0::nat} -> carrier G ==> finprod G f {..0} = f 0" |
13936 | 470 |
by (simp add: Pi_def) |
471 |
||
27933 | 472 |
lemma finprod_Suc [simp]: |
14750 | 473 |
"f \<in> {..Suc n} -> carrier G ==> |
13936 | 474 |
finprod G f {..Suc n} = (f (Suc n) \<otimes> finprod G f {..n})" |
475 |
by (simp add: Pi_def atMost_Suc) |
|
476 |
||
27933 | 477 |
lemma finprod_Suc2: |
14750 | 478 |
"f \<in> {..Suc n} -> carrier G ==> |
13936 | 479 |
finprod G f {..Suc n} = (finprod G (%i. f (Suc i)) {..n} \<otimes> f 0)" |
480 |
proof (induct n) |
|
481 |
case 0 thus ?case by (simp add: Pi_def) |
|
482 |
next |
|
483 |
case Suc thus ?case by (simp add: m_assoc Pi_def) |
|
484 |
qed |
|
485 |
||
27933 | 486 |
lemma finprod_mult [simp]: |
14750 | 487 |
"[| f \<in> {..n} -> carrier G; g \<in> {..n} -> carrier G |] ==> |
13936 | 488 |
finprod G (%i. f i \<otimes> g i) {..n::nat} = |
489 |
finprod G f {..n} \<otimes> finprod G g {..n}" |
|
490 |
by (induct n) (simp_all add: m_ac Pi_def) |
|
491 |
||
27699 | 492 |
(* The following two were contributed by Jeremy Avigad. *) |
493 |
||
27933 | 494 |
lemma finprod_reindex: |
27699 | 495 |
assumes fin: "finite A" |
496 |
shows "f : (h ` A) \<rightarrow> carrier G \<Longrightarrow> |
|
497 |
inj_on h A ==> finprod G f (h ` A) = finprod G (%x. f (h x)) A" |
|
498 |
using fin apply induct |
|
499 |
apply (auto simp add: finprod_insert Pi_def) |
|
500 |
done |
|
501 |
||
27933 | 502 |
lemma finprod_const: |
27699 | 503 |
assumes fin [simp]: "finite A" |
504 |
and a [simp]: "a : carrier G" |
|
505 |
shows "finprod G (%x. a) A = a (^) card A" |
|
506 |
using fin apply induct |
|
507 |
apply force |
|
508 |
apply (subst finprod_insert) |
|
509 |
apply auto |
|
510 |
apply (subst m_comm) |
|
511 |
apply auto |
|
512 |
done |
|
513 |
||
27933 | 514 |
(* The following lemma was contributed by Jesus Aransay. *) |
515 |
||
516 |
lemma finprod_singleton: |
|
517 |
assumes i_in_A: "i \<in> A" and fin_A: "finite A" and f_Pi: "f \<in> A \<rightarrow> carrier G" |
|
518 |
shows "(\<Otimes>j\<in>A. if i = j then f j else \<one>) = f i" |
|
29237 | 519 |
using i_in_A finprod_insert [of "A - {i}" i "(\<lambda>j. if i = j then f j else \<one>)"] |
520 |
fin_A f_Pi finprod_one [of "A - {i}"] |
|
521 |
finprod_cong [of "A - {i}" "A - {i}" "(\<lambda>j. if i = j then f j else \<one>)" "(\<lambda>i. \<one>)"] |
|
27933 | 522 |
unfolding Pi_def simp_implies_def by (force simp add: insert_absorb) |
523 |
||
13936 | 524 |
end |
27933 | 525 |
|
526 |
end |