13936
|
1 |
(* Title: Product Operator for Commutative Monoids
|
|
2 |
ID: $Id$
|
|
3 |
Author: Clemens Ballarin, started 19 November 2002
|
|
4 |
|
|
5 |
This file is largely based on HOL/Finite_Set.thy.
|
|
6 |
*)
|
|
7 |
|
|
8 |
header {* Product Operator *}
|
|
9 |
|
|
10 |
theory FiniteProduct = Group:
|
|
11 |
|
|
12 |
(* Instantiation of LC from Finite_Set.thy is not possible,
|
|
13 |
because here we have explicit typing rules like x : carrier G.
|
|
14 |
We introduce an explicit argument for the domain D *)
|
|
15 |
|
|
16 |
consts
|
|
17 |
foldSetD :: "['a set, 'b => 'a => 'a, 'a] => ('b set * 'a) set"
|
|
18 |
|
|
19 |
inductive "foldSetD D f e"
|
|
20 |
intros
|
|
21 |
emptyI [intro]: "e : D ==> ({}, e) : foldSetD D f e"
|
|
22 |
insertI [intro]: "[| x ~: A; f x y : D; (A, y) : foldSetD D f e |] ==>
|
|
23 |
(insert x A, f x y) : foldSetD D f e"
|
|
24 |
|
|
25 |
inductive_cases empty_foldSetDE [elim!]: "({}, x) : foldSetD D f e"
|
|
26 |
|
|
27 |
constdefs
|
|
28 |
foldD :: "['a set, 'b => 'a => 'a, 'a, 'b set] => 'a"
|
|
29 |
"foldD D f e A == THE x. (A, x) : foldSetD D f e"
|
|
30 |
|
|
31 |
lemma foldSetD_closed:
|
|
32 |
"[| (A, z) : foldSetD D f e ; e : D; !!x y. [| x : A; y : D |] ==> f x y : D
|
|
33 |
|] ==> z : D";
|
|
34 |
by (erule foldSetD.elims) auto
|
|
35 |
|
|
36 |
lemma Diff1_foldSetD:
|
|
37 |
"[| (A - {x}, y) : foldSetD D f e; x : A; f x y : D |] ==>
|
|
38 |
(A, f x y) : foldSetD D f e"
|
|
39 |
apply (erule insert_Diff [THEN subst], rule foldSetD.intros)
|
|
40 |
apply auto
|
|
41 |
done
|
|
42 |
|
|
43 |
lemma foldSetD_imp_finite [simp]: "(A, x) : foldSetD D f e ==> finite A"
|
|
44 |
by (induct set: foldSetD) auto
|
|
45 |
|
|
46 |
lemma finite_imp_foldSetD:
|
|
47 |
"[| finite A; e : D; !!x y. [| x : A; y : D |] ==> f x y : D |] ==>
|
|
48 |
EX x. (A, x) : foldSetD D f e"
|
|
49 |
proof (induct set: Finites)
|
|
50 |
case empty then show ?case by auto
|
|
51 |
next
|
|
52 |
case (insert F x)
|
|
53 |
then obtain y where y: "(F, y) : foldSetD D f e" by auto
|
|
54 |
with insert have "y : D" by (auto dest: foldSetD_closed)
|
|
55 |
with y and insert have "(insert x F, f x y) : foldSetD D f e"
|
|
56 |
by (intro foldSetD.intros) auto
|
|
57 |
then show ?case ..
|
|
58 |
qed
|
|
59 |
|
|
60 |
subsection {* Left-commutative operations *}
|
|
61 |
|
|
62 |
locale LCD =
|
|
63 |
fixes B :: "'b set"
|
|
64 |
and D :: "'a set"
|
|
65 |
and f :: "'b => 'a => 'a" (infixl "\<cdot>" 70)
|
|
66 |
assumes left_commute:
|
|
67 |
"[| x : B; y : B; z : D |] ==> x \<cdot> (y \<cdot> z) = y \<cdot> (x \<cdot> z)"
|
|
68 |
and f_closed [simp, intro!]: "!!x y. [| x : B; y : D |] ==> f x y : D"
|
|
69 |
|
|
70 |
lemma (in LCD) foldSetD_closed [dest]:
|
|
71 |
"(A, z) : foldSetD D f e ==> z : D";
|
|
72 |
by (erule foldSetD.elims) auto
|
|
73 |
|
|
74 |
lemma (in LCD) Diff1_foldSetD:
|
|
75 |
"[| (A - {x}, y) : foldSetD D f e; x : A; A <= B |] ==>
|
|
76 |
(A, f x y) : foldSetD D f e"
|
|
77 |
apply (subgoal_tac "x : B")
|
|
78 |
prefer 2 apply fast
|
|
79 |
apply (erule insert_Diff [THEN subst], rule foldSetD.intros)
|
|
80 |
apply auto
|
|
81 |
done
|
|
82 |
|
|
83 |
lemma (in LCD) foldSetD_imp_finite [simp]:
|
|
84 |
"(A, x) : foldSetD D f e ==> finite A"
|
|
85 |
by (induct set: foldSetD) auto
|
|
86 |
|
|
87 |
lemma (in LCD) finite_imp_foldSetD:
|
|
88 |
"[| finite A; A <= B; e : D |] ==> EX x. (A, x) : foldSetD D f e"
|
|
89 |
proof (induct set: Finites)
|
|
90 |
case empty then show ?case by auto
|
|
91 |
next
|
|
92 |
case (insert F x)
|
|
93 |
then obtain y where y: "(F, y) : foldSetD D f e" by auto
|
|
94 |
with insert have "y : D" by auto
|
|
95 |
with y and insert have "(insert x F, f x y) : foldSetD D f e"
|
|
96 |
by (intro foldSetD.intros) auto
|
|
97 |
then show ?case ..
|
|
98 |
qed
|
|
99 |
|
|
100 |
lemma (in LCD) foldSetD_determ_aux:
|
|
101 |
"e : D ==> ALL A x. A <= B & card A < n --> (A, x) : foldSetD D f e -->
|
|
102 |
(ALL y. (A, y) : foldSetD D f e --> y = x)"
|
|
103 |
apply (induct n)
|
|
104 |
apply (auto simp add: less_Suc_eq) (* slow *)
|
|
105 |
apply (erule foldSetD.cases)
|
|
106 |
apply blast
|
|
107 |
apply (erule foldSetD.cases)
|
|
108 |
apply blast
|
|
109 |
apply clarify
|
|
110 |
txt {* force simplification of @{text "card A < card (insert ...)"}. *}
|
|
111 |
apply (erule rev_mp)
|
|
112 |
apply (simp add: less_Suc_eq_le)
|
|
113 |
apply (rule impI)
|
|
114 |
apply (rename_tac Aa xa ya Ab xb yb, case_tac "xa = xb")
|
|
115 |
apply (subgoal_tac "Aa = Ab")
|
|
116 |
prefer 2 apply (blast elim!: equalityE)
|
|
117 |
apply blast
|
|
118 |
txt {* case @{prop "xa \<notin> xb"}. *}
|
|
119 |
apply (subgoal_tac "Aa - {xb} = Ab - {xa} & xb : Aa & xa : Ab")
|
|
120 |
prefer 2 apply (blast elim!: equalityE)
|
|
121 |
apply clarify
|
|
122 |
apply (subgoal_tac "Aa = insert xb Ab - {xa}")
|
|
123 |
prefer 2 apply blast
|
|
124 |
apply (subgoal_tac "card Aa <= card Ab")
|
|
125 |
prefer 2
|
|
126 |
apply (rule Suc_le_mono [THEN subst])
|
|
127 |
apply (simp add: card_Suc_Diff1)
|
|
128 |
apply (rule_tac A1 = "Aa - {xb}" in finite_imp_foldSetD [THEN exE])
|
|
129 |
apply (blast intro: foldSetD_imp_finite finite_Diff)
|
|
130 |
apply best
|
|
131 |
apply assumption
|
|
132 |
apply (frule (1) Diff1_foldSetD)
|
|
133 |
apply best
|
|
134 |
apply (subgoal_tac "ya = f xb x")
|
|
135 |
prefer 2
|
|
136 |
apply (subgoal_tac "Aa <= B")
|
|
137 |
prefer 2 apply best (* slow *)
|
|
138 |
apply (blast del: equalityCE)
|
|
139 |
apply (subgoal_tac "(Ab - {xa}, x) : foldSetD D f e")
|
|
140 |
prefer 2 apply simp
|
|
141 |
apply (subgoal_tac "yb = f xa x")
|
|
142 |
prefer 2
|
|
143 |
apply (blast del: equalityCE dest: Diff1_foldSetD)
|
|
144 |
apply (simp (no_asm_simp))
|
|
145 |
apply (rule left_commute)
|
|
146 |
apply assumption
|
|
147 |
apply best (* slow *)
|
|
148 |
apply best
|
|
149 |
done
|
|
150 |
|
|
151 |
lemma (in LCD) foldSetD_determ:
|
|
152 |
"[| (A, x) : foldSetD D f e; (A, y) : foldSetD D f e; e : D; A <= B |]
|
|
153 |
==> y = x"
|
|
154 |
by (blast intro: foldSetD_determ_aux [rule_format])
|
|
155 |
|
|
156 |
lemma (in LCD) foldD_equality:
|
|
157 |
"[| (A, y) : foldSetD D f e; e : D; A <= B |] ==> foldD D f e A = y"
|
|
158 |
by (unfold foldD_def) (blast intro: foldSetD_determ)
|
|
159 |
|
|
160 |
lemma foldD_empty [simp]:
|
|
161 |
"e : D ==> foldD D f e {} = e"
|
|
162 |
by (unfold foldD_def) blast
|
|
163 |
|
|
164 |
lemma (in LCD) foldD_insert_aux:
|
|
165 |
"[| x ~: A; x : B; e : D; A <= B |] ==>
|
|
166 |
((insert x A, v) : foldSetD D f e) =
|
|
167 |
(EX y. (A, y) : foldSetD D f e & v = f x y)"
|
|
168 |
apply auto
|
|
169 |
apply (rule_tac A1 = A in finite_imp_foldSetD [THEN exE])
|
|
170 |
apply (fastsimp dest: foldSetD_imp_finite)
|
|
171 |
apply assumption
|
|
172 |
apply assumption
|
|
173 |
apply (blast intro: foldSetD_determ)
|
|
174 |
done
|
|
175 |
|
|
176 |
lemma (in LCD) foldD_insert:
|
|
177 |
"[| finite A; x ~: A; x : B; e : D; A <= B |] ==>
|
|
178 |
foldD D f e (insert x A) = f x (foldD D f e A)"
|
|
179 |
apply (unfold foldD_def)
|
|
180 |
apply (simp add: foldD_insert_aux)
|
|
181 |
apply (rule the_equality)
|
|
182 |
apply (auto intro: finite_imp_foldSetD
|
|
183 |
cong add: conj_cong simp add: foldD_def [symmetric] foldD_equality)
|
|
184 |
done
|
|
185 |
|
|
186 |
lemma (in LCD) foldD_closed [simp]:
|
|
187 |
"[| finite A; e : D; A <= B |] ==> foldD D f e A : D"
|
|
188 |
proof (induct set: Finites)
|
|
189 |
case empty then show ?case by (simp add: foldD_empty)
|
|
190 |
next
|
|
191 |
case insert then show ?case by (simp add: foldD_insert)
|
|
192 |
qed
|
|
193 |
|
|
194 |
lemma (in LCD) foldD_commute:
|
|
195 |
"[| finite A; x : B; e : D; A <= B |] ==>
|
|
196 |
f x (foldD D f e A) = foldD D f (f x e) A"
|
|
197 |
apply (induct set: Finites)
|
|
198 |
apply simp
|
|
199 |
apply (auto simp add: left_commute foldD_insert)
|
|
200 |
done
|
|
201 |
|
|
202 |
lemma Int_mono2:
|
|
203 |
"[| A <= C; B <= C |] ==> A Int B <= C"
|
|
204 |
by blast
|
|
205 |
|
|
206 |
lemma (in LCD) foldD_nest_Un_Int:
|
|
207 |
"[| finite A; finite C; e : D; A <= B; C <= B |] ==>
|
|
208 |
foldD D f (foldD D f e C) A = foldD D f (foldD D f e (A Int C)) (A Un C)"
|
|
209 |
apply (induct set: Finites)
|
|
210 |
apply simp
|
|
211 |
apply (simp add: foldD_insert foldD_commute Int_insert_left insert_absorb
|
|
212 |
Int_mono2 Un_subset_iff)
|
|
213 |
done
|
|
214 |
|
|
215 |
lemma (in LCD) foldD_nest_Un_disjoint:
|
|
216 |
"[| finite A; finite B; A Int B = {}; e : D; A <= B; C <= B |]
|
|
217 |
==> foldD D f e (A Un B) = foldD D f (foldD D f e B) A"
|
|
218 |
by (simp add: foldD_nest_Un_Int)
|
|
219 |
|
|
220 |
-- {* Delete rules to do with @{text foldSetD} relation. *}
|
|
221 |
|
|
222 |
declare foldSetD_imp_finite [simp del]
|
|
223 |
empty_foldSetDE [rule del]
|
|
224 |
foldSetD.intros [rule del]
|
|
225 |
declare (in LCD)
|
|
226 |
foldSetD_closed [rule del]
|
|
227 |
|
|
228 |
subsection {* Commutative monoids *}
|
|
229 |
|
|
230 |
text {*
|
|
231 |
We enter a more restrictive context, with @{text "f :: 'a => 'a => 'a"}
|
|
232 |
instead of @{text "'b => 'a => 'a"}.
|
|
233 |
*}
|
|
234 |
|
|
235 |
locale ACeD =
|
|
236 |
fixes D :: "'a set"
|
|
237 |
and f :: "'a => 'a => 'a" (infixl "\<cdot>" 70)
|
|
238 |
and e :: 'a
|
|
239 |
assumes ident [simp]: "x : D ==> x \<cdot> e = x"
|
|
240 |
and commute: "[| x : D; y : D |] ==> x \<cdot> y = y \<cdot> x"
|
|
241 |
and assoc: "[| x : D; y : D; z : D |] ==> (x \<cdot> y) \<cdot> z = x \<cdot> (y \<cdot> z)"
|
|
242 |
and e_closed [simp]: "e : D"
|
|
243 |
and f_closed [simp]: "[| x : D; y : D |] ==> x \<cdot> y : D"
|
|
244 |
|
|
245 |
lemma (in ACeD) left_commute:
|
|
246 |
"[| x : D; y : D; z : D |] ==> x \<cdot> (y \<cdot> z) = y \<cdot> (x \<cdot> z)"
|
|
247 |
proof -
|
|
248 |
assume D: "x : D" "y : D" "z : D"
|
|
249 |
then have "x \<cdot> (y \<cdot> z) = (y \<cdot> z) \<cdot> x" by (simp add: commute)
|
|
250 |
also from D have "... = y \<cdot> (z \<cdot> x)" by (simp add: assoc)
|
|
251 |
also from D have "z \<cdot> x = x \<cdot> z" by (simp add: commute)
|
|
252 |
finally show ?thesis .
|
|
253 |
qed
|
|
254 |
|
|
255 |
lemmas (in ACeD) AC = assoc commute left_commute
|
|
256 |
|
|
257 |
lemma (in ACeD) left_ident [simp]: "x : D ==> e \<cdot> x = x"
|
|
258 |
proof -
|
|
259 |
assume D: "x : D"
|
|
260 |
have "x \<cdot> e = x" by (rule ident)
|
|
261 |
with D show ?thesis by (simp add: commute)
|
|
262 |
qed
|
|
263 |
|
|
264 |
lemma (in ACeD) foldD_Un_Int:
|
|
265 |
"[| finite A; finite B; A <= D; B <= D |] ==>
|
|
266 |
foldD D f e A \<cdot> foldD D f e B =
|
|
267 |
foldD D f e (A Un B) \<cdot> foldD D f e (A Int B)"
|
|
268 |
apply (induct set: Finites)
|
|
269 |
apply (simp add: left_commute LCD.foldD_closed [OF LCD.intro [of D]])
|
|
270 |
apply (simp add: AC insert_absorb Int_insert_left
|
|
271 |
LCD.foldD_insert [OF LCD.intro [of D]]
|
|
272 |
LCD.foldD_closed [OF LCD.intro [of D]]
|
|
273 |
Int_mono2 Un_subset_iff)
|
|
274 |
done
|
|
275 |
|
|
276 |
lemma (in ACeD) foldD_Un_disjoint:
|
|
277 |
"[| finite A; finite B; A Int B = {}; A <= D; B <= D |] ==>
|
|
278 |
foldD D f e (A Un B) = foldD D f e A \<cdot> foldD D f e B"
|
|
279 |
by (simp add: foldD_Un_Int
|
|
280 |
left_commute LCD.foldD_closed [OF LCD.intro [of D]] Un_subset_iff)
|
|
281 |
|
|
282 |
subsection {* Products over Finite Sets *}
|
|
283 |
|
|
284 |
constdefs
|
|
285 |
finprod :: "[('b, 'm) monoid_scheme, 'a => 'b, 'a set] => 'b"
|
|
286 |
"finprod G f A == if finite A
|
|
287 |
then foldD (carrier G) (mult G o f) (one G) A
|
|
288 |
else arbitrary"
|
|
289 |
|
|
290 |
(* TODO: nice syntax for the summation operator inside the locale
|
|
291 |
like \<Otimes>\<index> i\<in>A. f i, probably needs hand-coded translation *)
|
|
292 |
|
|
293 |
ML_setup {*
|
|
294 |
Context.>> (fn thy => (simpset_ref_of thy :=
|
|
295 |
simpset_of thy setsubgoaler asm_full_simp_tac; thy))
|
|
296 |
*}
|
|
297 |
|
|
298 |
lemma (in comm_monoid) finprod_empty [simp]:
|
|
299 |
"finprod G f {} = \<one>"
|
|
300 |
by (simp add: finprod_def)
|
|
301 |
|
|
302 |
ML_setup {*
|
|
303 |
Context.>> (fn thy => (simpset_ref_of thy :=
|
|
304 |
simpset_of thy setsubgoaler asm_simp_tac; thy))
|
|
305 |
*}
|
|
306 |
|
|
307 |
declare funcsetI [intro]
|
|
308 |
funcset_mem [dest]
|
|
309 |
|
|
310 |
lemma (in comm_monoid) finprod_insert [simp]:
|
|
311 |
"[| finite F; a \<notin> F; f \<in> F -> carrier G; f a \<in> carrier G |] ==>
|
|
312 |
finprod G f (insert a F) = f a \<otimes> finprod G f F"
|
|
313 |
apply (rule trans)
|
|
314 |
apply (simp add: finprod_def)
|
|
315 |
apply (rule trans)
|
|
316 |
apply (rule LCD.foldD_insert [OF LCD.intro [of "insert a F"]])
|
|
317 |
apply simp
|
|
318 |
apply (rule m_lcomm)
|
|
319 |
apply fast
|
|
320 |
apply fast
|
|
321 |
apply assumption
|
|
322 |
apply (fastsimp intro: m_closed)
|
|
323 |
apply simp+
|
|
324 |
apply fast
|
|
325 |
apply (auto simp add: finprod_def)
|
|
326 |
done
|
|
327 |
|
|
328 |
lemma (in comm_monoid) finprod_one [simp]:
|
|
329 |
"finite A ==> finprod G (%i. \<one>) A = \<one>"
|
|
330 |
proof (induct set: Finites)
|
|
331 |
case empty show ?case by simp
|
|
332 |
next
|
|
333 |
case (insert A a)
|
|
334 |
have "(%i. \<one>) \<in> A -> carrier G" by auto
|
|
335 |
with insert show ?case by simp
|
|
336 |
qed
|
|
337 |
|
|
338 |
lemma (in comm_monoid) finprod_closed [simp]:
|
|
339 |
fixes A
|
|
340 |
assumes fin: "finite A" and f: "f \<in> A -> carrier G"
|
|
341 |
shows "finprod G f A \<in> carrier G"
|
|
342 |
using fin f
|
|
343 |
proof induct
|
|
344 |
case empty show ?case by simp
|
|
345 |
next
|
|
346 |
case (insert A a)
|
|
347 |
then have a: "f a \<in> carrier G" by fast
|
|
348 |
from insert have A: "f \<in> A -> carrier G" by fast
|
|
349 |
from insert A a show ?case by simp
|
|
350 |
qed
|
|
351 |
|
|
352 |
lemma funcset_Int_left [simp, intro]:
|
|
353 |
"[| f \<in> A -> C; f \<in> B -> C |] ==> f \<in> A Int B -> C"
|
|
354 |
by fast
|
|
355 |
|
|
356 |
lemma funcset_Un_left [iff]:
|
|
357 |
"(f \<in> A Un B -> C) = (f \<in> A -> C & f \<in> B -> C)"
|
|
358 |
by fast
|
|
359 |
|
|
360 |
lemma (in comm_monoid) finprod_Un_Int:
|
|
361 |
"[| finite A; finite B; g \<in> A -> carrier G; g \<in> B -> carrier G |] ==>
|
|
362 |
finprod G g (A Un B) \<otimes> finprod G g (A Int B) =
|
|
363 |
finprod G g A \<otimes> finprod G g B"
|
|
364 |
-- {* The reversed orientation looks more natural, but LOOPS as a simprule! *}
|
|
365 |
proof (induct set: Finites)
|
|
366 |
case empty then show ?case by (simp add: finprod_closed)
|
|
367 |
next
|
|
368 |
case (insert A a)
|
|
369 |
then have a: "g a \<in> carrier G" by fast
|
|
370 |
from insert have A: "g \<in> A -> carrier G" by fast
|
|
371 |
from insert A a show ?case
|
|
372 |
by (simp add: m_ac Int_insert_left insert_absorb finprod_closed
|
|
373 |
Int_mono2 Un_subset_iff)
|
|
374 |
qed
|
|
375 |
|
|
376 |
lemma (in comm_monoid) finprod_Un_disjoint:
|
|
377 |
"[| finite A; finite B; A Int B = {};
|
|
378 |
g \<in> A -> carrier G; g \<in> B -> carrier G |]
|
|
379 |
==> finprod G g (A Un B) = finprod G g A \<otimes> finprod G g B"
|
|
380 |
apply (subst finprod_Un_Int [symmetric])
|
|
381 |
apply (auto simp add: finprod_closed)
|
|
382 |
done
|
|
383 |
|
|
384 |
lemma (in comm_monoid) finprod_multf:
|
|
385 |
"[| finite A; f \<in> A -> carrier G; g \<in> A -> carrier G |] ==>
|
|
386 |
finprod G (%x. f x \<otimes> g x) A = (finprod G f A \<otimes> finprod G g A)"
|
|
387 |
proof (induct set: Finites)
|
|
388 |
case empty show ?case by simp
|
|
389 |
next
|
|
390 |
case (insert A a) then
|
|
391 |
have fA: "f : A -> carrier G" by fast
|
|
392 |
from insert have fa: "f a : carrier G" by fast
|
|
393 |
from insert have gA: "g : A -> carrier G" by fast
|
|
394 |
from insert have ga: "g a : carrier G" by fast
|
|
395 |
from insert have fgA: "(%x. f x \<otimes> g x) : A -> carrier G"
|
|
396 |
by (simp add: Pi_def)
|
|
397 |
show ?case (* check if all simps are really necessary *)
|
|
398 |
by (simp add: insert fA fa gA ga fgA m_ac Int_insert_left insert_absorb
|
|
399 |
Int_mono2 Un_subset_iff)
|
|
400 |
qed
|
|
401 |
|
|
402 |
lemma (in comm_monoid) finprod_cong':
|
|
403 |
"[| A = B; g : B -> carrier G;
|
|
404 |
!!i. i : B ==> f i = g i |] ==> finprod G f A = finprod G g B"
|
|
405 |
proof -
|
|
406 |
assume prems: "A = B" "g : B -> carrier G"
|
|
407 |
"!!i. i : B ==> f i = g i"
|
|
408 |
show ?thesis
|
|
409 |
proof (cases "finite B")
|
|
410 |
case True
|
|
411 |
then have "!!A. [| A = B; g : B -> carrier G;
|
|
412 |
!!i. i : B ==> f i = g i |] ==> finprod G f A = finprod G g B"
|
|
413 |
proof induct
|
|
414 |
case empty thus ?case by simp
|
|
415 |
next
|
|
416 |
case (insert B x)
|
|
417 |
then have "finprod G f A = finprod G f (insert x B)" by simp
|
|
418 |
also from insert have "... = f x \<otimes> finprod G f B"
|
|
419 |
proof (intro finprod_insert)
|
|
420 |
show "finite B" .
|
|
421 |
next
|
|
422 |
show "x ~: B" .
|
|
423 |
next
|
|
424 |
assume "x ~: B" "!!i. i \<in> insert x B \<Longrightarrow> f i = g i"
|
|
425 |
"g \<in> insert x B \<rightarrow> carrier G"
|
|
426 |
thus "f : B -> carrier G" by fastsimp
|
|
427 |
next
|
|
428 |
assume "x ~: B" "!!i. i \<in> insert x B \<Longrightarrow> f i = g i"
|
|
429 |
"g \<in> insert x B \<rightarrow> carrier G"
|
|
430 |
thus "f x \<in> carrier G" by fastsimp
|
|
431 |
qed
|
|
432 |
also from insert have "... = g x \<otimes> finprod G g B" by fastsimp
|
|
433 |
also from insert have "... = finprod G g (insert x B)"
|
|
434 |
by (intro finprod_insert [THEN sym]) auto
|
|
435 |
finally show ?case .
|
|
436 |
qed
|
|
437 |
with prems show ?thesis by simp
|
|
438 |
next
|
|
439 |
case False with prems show ?thesis by (simp add: finprod_def)
|
|
440 |
qed
|
|
441 |
qed
|
|
442 |
|
|
443 |
lemma (in comm_monoid) finprod_cong:
|
|
444 |
"[| A = B; !!i. i : B ==> f i = g i;
|
|
445 |
g : B -> carrier G = True |] ==> finprod G f A = finprod G g B"
|
|
446 |
by (rule finprod_cong') fast+
|
|
447 |
|
|
448 |
text {*Usually, if this rule causes a failed congruence proof error,
|
|
449 |
the reason is that the premise @{text "g : B -> carrier G"} cannot be shown.
|
|
450 |
Adding @{thm [source] Pi_def} to the simpset is often useful.
|
|
451 |
For this reason, @{thm [source] comm_monoid.finprod_cong}
|
|
452 |
is not added to the simpset by default.
|
|
453 |
*}
|
|
454 |
|
|
455 |
declare funcsetI [rule del]
|
|
456 |
funcset_mem [rule del]
|
|
457 |
|
|
458 |
lemma (in comm_monoid) finprod_0 [simp]:
|
|
459 |
"f : {0::nat} -> carrier G ==> finprod G f {..0} = f 0"
|
|
460 |
by (simp add: Pi_def)
|
|
461 |
|
|
462 |
lemma (in comm_monoid) finprod_Suc [simp]:
|
|
463 |
"f : {..Suc n} -> carrier G ==>
|
|
464 |
finprod G f {..Suc n} = (f (Suc n) \<otimes> finprod G f {..n})"
|
|
465 |
by (simp add: Pi_def atMost_Suc)
|
|
466 |
|
|
467 |
lemma (in comm_monoid) finprod_Suc2:
|
|
468 |
"f : {..Suc n} -> carrier G ==>
|
|
469 |
finprod G f {..Suc n} = (finprod G (%i. f (Suc i)) {..n} \<otimes> f 0)"
|
|
470 |
proof (induct n)
|
|
471 |
case 0 thus ?case by (simp add: Pi_def)
|
|
472 |
next
|
|
473 |
case Suc thus ?case by (simp add: m_assoc Pi_def)
|
|
474 |
qed
|
|
475 |
|
|
476 |
lemma (in comm_monoid) finprod_mult [simp]:
|
|
477 |
"[| f : {..n} -> carrier G; g : {..n} -> carrier G |] ==>
|
|
478 |
finprod G (%i. f i \<otimes> g i) {..n::nat} =
|
|
479 |
finprod G f {..n} \<otimes> finprod G g {..n}"
|
|
480 |
by (induct n) (simp_all add: m_ac Pi_def)
|
|
481 |
|
|
482 |
end
|
|
483 |
|