1 (* |
|
2 Title: The algebraic hierarchy of rings |
|
3 Id: $Id$ |
|
4 Author: Clemens Ballarin, started 9 December 1996 |
|
5 Copyright: Clemens Ballarin |
|
6 *) |
|
7 |
|
8 header {* Abelian Groups *} |
|
9 |
|
10 theory CRing imports FiniteProduct |
|
11 uses ("ringsimp.ML") begin |
|
12 |
|
13 record 'a ring = "'a monoid" + |
|
14 zero :: 'a ("\<zero>\<index>") |
|
15 add :: "['a, 'a] => 'a" (infixl "\<oplus>\<index>" 65) |
|
16 |
|
17 text {* Derived operations. *} |
|
18 |
|
19 constdefs (structure R) |
|
20 a_inv :: "[('a, 'm) ring_scheme, 'a ] => 'a" ("\<ominus>\<index> _" [81] 80) |
|
21 "a_inv R == m_inv (| carrier = carrier R, mult = add R, one = zero R |)" |
|
22 |
|
23 a_minus :: "[('a, 'm) ring_scheme, 'a, 'a] => 'a" (infixl "\<ominus>\<index>" 65) |
|
24 "[| x \<in> carrier R; y \<in> carrier R |] ==> x \<ominus> y == x \<oplus> (\<ominus> y)" |
|
25 |
|
26 locale abelian_monoid = |
|
27 fixes G (structure) |
|
28 assumes a_comm_monoid: |
|
29 "comm_monoid (| carrier = carrier G, mult = add G, one = zero G |)" |
|
30 |
|
31 |
|
32 text {* |
|
33 The following definition is redundant but simple to use. |
|
34 *} |
|
35 |
|
36 locale abelian_group = abelian_monoid + |
|
37 assumes a_comm_group: |
|
38 "comm_group (| carrier = carrier G, mult = add G, one = zero G |)" |
|
39 |
|
40 |
|
41 subsection {* Basic Properties *} |
|
42 |
|
43 lemma abelian_monoidI: |
|
44 fixes R (structure) |
|
45 assumes a_closed: |
|
46 "!!x y. [| x \<in> carrier R; y \<in> carrier R |] ==> x \<oplus> y \<in> carrier R" |
|
47 and zero_closed: "\<zero> \<in> carrier R" |
|
48 and a_assoc: |
|
49 "!!x y z. [| x \<in> carrier R; y \<in> carrier R; z \<in> carrier R |] ==> |
|
50 (x \<oplus> y) \<oplus> z = x \<oplus> (y \<oplus> z)" |
|
51 and l_zero: "!!x. x \<in> carrier R ==> \<zero> \<oplus> x = x" |
|
52 and a_comm: |
|
53 "!!x y. [| x \<in> carrier R; y \<in> carrier R |] ==> x \<oplus> y = y \<oplus> x" |
|
54 shows "abelian_monoid R" |
|
55 by (auto intro!: abelian_monoid.intro comm_monoidI intro: prems) |
|
56 |
|
57 lemma abelian_groupI: |
|
58 fixes R (structure) |
|
59 assumes a_closed: |
|
60 "!!x y. [| x \<in> carrier R; y \<in> carrier R |] ==> x \<oplus> y \<in> carrier R" |
|
61 and zero_closed: "zero R \<in> carrier R" |
|
62 and a_assoc: |
|
63 "!!x y z. [| x \<in> carrier R; y \<in> carrier R; z \<in> carrier R |] ==> |
|
64 (x \<oplus> y) \<oplus> z = x \<oplus> (y \<oplus> z)" |
|
65 and a_comm: |
|
66 "!!x y. [| x \<in> carrier R; y \<in> carrier R |] ==> x \<oplus> y = y \<oplus> x" |
|
67 and l_zero: "!!x. x \<in> carrier R ==> \<zero> \<oplus> x = x" |
|
68 and l_inv_ex: "!!x. x \<in> carrier R ==> EX y : carrier R. y \<oplus> x = \<zero>" |
|
69 shows "abelian_group R" |
|
70 by (auto intro!: abelian_group.intro abelian_monoidI |
|
71 abelian_group_axioms.intro comm_monoidI comm_groupI |
|
72 intro: prems) |
|
73 |
|
74 lemma (in abelian_monoid) a_monoid: |
|
75 "monoid (| carrier = carrier G, mult = add G, one = zero G |)" |
|
76 by (rule comm_monoid.axioms, rule a_comm_monoid) |
|
77 |
|
78 lemma (in abelian_group) a_group: |
|
79 "group (| carrier = carrier G, mult = add G, one = zero G |)" |
|
80 by (simp add: group_def a_monoid) |
|
81 (simp add: comm_group.axioms group.axioms a_comm_group) |
|
82 |
|
83 lemmas monoid_record_simps = partial_object.simps monoid.simps |
|
84 |
|
85 lemma (in abelian_monoid) a_closed [intro, simp]: |
|
86 "\<lbrakk> x \<in> carrier G; y \<in> carrier G \<rbrakk> \<Longrightarrow> x \<oplus> y \<in> carrier G" |
|
87 by (rule monoid.m_closed [OF a_monoid, simplified monoid_record_simps]) |
|
88 |
|
89 lemma (in abelian_monoid) zero_closed [intro, simp]: |
|
90 "\<zero> \<in> carrier G" |
|
91 by (rule monoid.one_closed [OF a_monoid, simplified monoid_record_simps]) |
|
92 |
|
93 lemma (in abelian_group) a_inv_closed [intro, simp]: |
|
94 "x \<in> carrier G ==> \<ominus> x \<in> carrier G" |
|
95 by (simp add: a_inv_def |
|
96 group.inv_closed [OF a_group, simplified monoid_record_simps]) |
|
97 |
|
98 lemma (in abelian_group) minus_closed [intro, simp]: |
|
99 "[| x \<in> carrier G; y \<in> carrier G |] ==> x \<ominus> y \<in> carrier G" |
|
100 by (simp add: a_minus_def) |
|
101 |
|
102 lemma (in abelian_group) a_l_cancel [simp]: |
|
103 "[| x \<in> carrier G; y \<in> carrier G; z \<in> carrier G |] ==> |
|
104 (x \<oplus> y = x \<oplus> z) = (y = z)" |
|
105 by (rule group.l_cancel [OF a_group, simplified monoid_record_simps]) |
|
106 |
|
107 lemma (in abelian_group) a_r_cancel [simp]: |
|
108 "[| x \<in> carrier G; y \<in> carrier G; z \<in> carrier G |] ==> |
|
109 (y \<oplus> x = z \<oplus> x) = (y = z)" |
|
110 by (rule group.r_cancel [OF a_group, simplified monoid_record_simps]) |
|
111 |
|
112 lemma (in abelian_monoid) a_assoc: |
|
113 "\<lbrakk>x \<in> carrier G; y \<in> carrier G; z \<in> carrier G\<rbrakk> \<Longrightarrow> |
|
114 (x \<oplus> y) \<oplus> z = x \<oplus> (y \<oplus> z)" |
|
115 by (rule monoid.m_assoc [OF a_monoid, simplified monoid_record_simps]) |
|
116 |
|
117 lemma (in abelian_monoid) l_zero [simp]: |
|
118 "x \<in> carrier G ==> \<zero> \<oplus> x = x" |
|
119 by (rule monoid.l_one [OF a_monoid, simplified monoid_record_simps]) |
|
120 |
|
121 lemma (in abelian_group) l_neg: |
|
122 "x \<in> carrier G ==> \<ominus> x \<oplus> x = \<zero>" |
|
123 by (simp add: a_inv_def |
|
124 group.l_inv [OF a_group, simplified monoid_record_simps]) |
|
125 |
|
126 lemma (in abelian_monoid) a_comm: |
|
127 "\<lbrakk>x \<in> carrier G; y \<in> carrier G\<rbrakk> \<Longrightarrow> x \<oplus> y = y \<oplus> x" |
|
128 by (rule comm_monoid.m_comm [OF a_comm_monoid, |
|
129 simplified monoid_record_simps]) |
|
130 |
|
131 lemma (in abelian_monoid) a_lcomm: |
|
132 "\<lbrakk>x \<in> carrier G; y \<in> carrier G; z \<in> carrier G\<rbrakk> \<Longrightarrow> |
|
133 x \<oplus> (y \<oplus> z) = y \<oplus> (x \<oplus> z)" |
|
134 by (rule comm_monoid.m_lcomm [OF a_comm_monoid, |
|
135 simplified monoid_record_simps]) |
|
136 |
|
137 lemma (in abelian_monoid) r_zero [simp]: |
|
138 "x \<in> carrier G ==> x \<oplus> \<zero> = x" |
|
139 using monoid.r_one [OF a_monoid] |
|
140 by simp |
|
141 |
|
142 lemma (in abelian_group) r_neg: |
|
143 "x \<in> carrier G ==> x \<oplus> (\<ominus> x) = \<zero>" |
|
144 using group.r_inv [OF a_group] |
|
145 by (simp add: a_inv_def) |
|
146 |
|
147 lemma (in abelian_group) minus_zero [simp]: |
|
148 "\<ominus> \<zero> = \<zero>" |
|
149 by (simp add: a_inv_def |
|
150 group.inv_one [OF a_group, simplified monoid_record_simps]) |
|
151 |
|
152 lemma (in abelian_group) minus_minus [simp]: |
|
153 "x \<in> carrier G ==> \<ominus> (\<ominus> x) = x" |
|
154 using group.inv_inv [OF a_group, simplified monoid_record_simps] |
|
155 by (simp add: a_inv_def) |
|
156 |
|
157 lemma (in abelian_group) a_inv_inj: |
|
158 "inj_on (a_inv G) (carrier G)" |
|
159 using group.inv_inj [OF a_group, simplified monoid_record_simps] |
|
160 by (simp add: a_inv_def) |
|
161 |
|
162 lemma (in abelian_group) minus_add: |
|
163 "[| x \<in> carrier G; y \<in> carrier G |] ==> \<ominus> (x \<oplus> y) = \<ominus> x \<oplus> \<ominus> y" |
|
164 using comm_group.inv_mult [OF a_comm_group] |
|
165 by (simp add: a_inv_def) |
|
166 |
|
167 lemma (in abelian_group) minus_equality: |
|
168 "[| x \<in> carrier G; y \<in> carrier G; y \<oplus> x = \<zero> |] ==> \<ominus> x = y" |
|
169 using group.inv_equality [OF a_group] |
|
170 by (auto simp add: a_inv_def) |
|
171 |
|
172 lemma (in abelian_monoid) minus_unique: |
|
173 "[| x \<in> carrier G; y \<in> carrier G; y' \<in> carrier G; |
|
174 y \<oplus> x = \<zero>; x \<oplus> y' = \<zero> |] ==> y = y'" |
|
175 using monoid.inv_unique [OF a_monoid] |
|
176 by (simp add: a_inv_def) |
|
177 |
|
178 lemmas (in abelian_monoid) a_ac = a_assoc a_comm a_lcomm |
|
179 |
|
180 subsection {* Sums over Finite Sets *} |
|
181 |
|
182 text {* |
|
183 This definition makes it easy to lift lemmas from @{term finprod}. |
|
184 *} |
|
185 |
|
186 constdefs |
|
187 finsum :: "[('b, 'm) ring_scheme, 'a => 'b, 'a set] => 'b" |
|
188 "finsum G f A == finprod (| carrier = carrier G, |
|
189 mult = add G, one = zero G |) f A" |
|
190 |
|
191 syntax |
|
192 "_finsum" :: "index => idt => 'a set => 'b => 'b" |
|
193 ("(3\<Oplus>__:_. _)" [1000, 0, 51, 10] 10) |
|
194 syntax (xsymbols) |
|
195 "_finsum" :: "index => idt => 'a set => 'b => 'b" |
|
196 ("(3\<Oplus>__\<in>_. _)" [1000, 0, 51, 10] 10) |
|
197 syntax (HTML output) |
|
198 "_finsum" :: "index => idt => 'a set => 'b => 'b" |
|
199 ("(3\<Oplus>__\<in>_. _)" [1000, 0, 51, 10] 10) |
|
200 translations |
|
201 "\<Oplus>\<index>i:A. b" == "finsum \<struct>\<index> (%i. b) A" |
|
202 -- {* Beware of argument permutation! *} |
|
203 |
|
204 (* |
|
205 lemmas (in abelian_monoid) finsum_empty [simp] = |
|
206 comm_monoid.finprod_empty [OF a_comm_monoid, simplified] |
|
207 is dangeous, because attributes (like simplified) are applied upon opening |
|
208 the locale, simplified refers to the simpset at that time!!! |
|
209 |
|
210 lemmas (in abelian_monoid) finsum_empty [simp] = |
|
211 abelian_monoid.finprod_empty [OF a_abelian_monoid, folded finsum_def, |
|
212 simplified monoid_record_simps] |
|
213 makes the locale slow, because proofs are repeated for every |
|
214 "lemma (in abelian_monoid)" command. |
|
215 When lemma is used time in UnivPoly.thy from beginning to UP_cring goes down |
|
216 from 110 secs to 60 secs. |
|
217 *) |
|
218 |
|
219 lemma (in abelian_monoid) finsum_empty [simp]: |
|
220 "finsum G f {} = \<zero>" |
|
221 by (rule comm_monoid.finprod_empty [OF a_comm_monoid, |
|
222 folded finsum_def, simplified monoid_record_simps]) |
|
223 |
|
224 lemma (in abelian_monoid) finsum_insert [simp]: |
|
225 "[| finite F; a \<notin> F; f \<in> F -> carrier G; f a \<in> carrier G |] |
|
226 ==> finsum G f (insert a F) = f a \<oplus> finsum G f F" |
|
227 by (rule comm_monoid.finprod_insert [OF a_comm_monoid, |
|
228 folded finsum_def, simplified monoid_record_simps]) |
|
229 |
|
230 lemma (in abelian_monoid) finsum_zero [simp]: |
|
231 "finite A ==> (\<Oplus>i\<in>A. \<zero>) = \<zero>" |
|
232 by (rule comm_monoid.finprod_one [OF a_comm_monoid, folded finsum_def, |
|
233 simplified monoid_record_simps]) |
|
234 |
|
235 lemma (in abelian_monoid) finsum_closed [simp]: |
|
236 fixes A |
|
237 assumes fin: "finite A" and f: "f \<in> A -> carrier G" |
|
238 shows "finsum G f A \<in> carrier G" |
|
239 by (rule comm_monoid.finprod_closed [OF a_comm_monoid, |
|
240 folded finsum_def, simplified monoid_record_simps]) |
|
241 |
|
242 lemma (in abelian_monoid) finsum_Un_Int: |
|
243 "[| finite A; finite B; g \<in> A -> carrier G; g \<in> B -> carrier G |] ==> |
|
244 finsum G g (A Un B) \<oplus> finsum G g (A Int B) = |
|
245 finsum G g A \<oplus> finsum G g B" |
|
246 by (rule comm_monoid.finprod_Un_Int [OF a_comm_monoid, |
|
247 folded finsum_def, simplified monoid_record_simps]) |
|
248 |
|
249 lemma (in abelian_monoid) finsum_Un_disjoint: |
|
250 "[| finite A; finite B; A Int B = {}; |
|
251 g \<in> A -> carrier G; g \<in> B -> carrier G |] |
|
252 ==> finsum G g (A Un B) = finsum G g A \<oplus> finsum G g B" |
|
253 by (rule comm_monoid.finprod_Un_disjoint [OF a_comm_monoid, |
|
254 folded finsum_def, simplified monoid_record_simps]) |
|
255 |
|
256 lemma (in abelian_monoid) finsum_addf: |
|
257 "[| finite A; f \<in> A -> carrier G; g \<in> A -> carrier G |] ==> |
|
258 finsum G (%x. f x \<oplus> g x) A = (finsum G f A \<oplus> finsum G g A)" |
|
259 by (rule comm_monoid.finprod_multf [OF a_comm_monoid, |
|
260 folded finsum_def, simplified monoid_record_simps]) |
|
261 |
|
262 lemma (in abelian_monoid) finsum_cong': |
|
263 "[| A = B; g : B -> carrier G; |
|
264 !!i. i : B ==> f i = g i |] ==> finsum G f A = finsum G g B" |
|
265 by (rule comm_monoid.finprod_cong' [OF a_comm_monoid, |
|
266 folded finsum_def, simplified monoid_record_simps]) auto |
|
267 |
|
268 lemma (in abelian_monoid) finsum_0 [simp]: |
|
269 "f : {0::nat} -> carrier G ==> finsum G f {..0} = f 0" |
|
270 by (rule comm_monoid.finprod_0 [OF a_comm_monoid, folded finsum_def, |
|
271 simplified monoid_record_simps]) |
|
272 |
|
273 lemma (in abelian_monoid) finsum_Suc [simp]: |
|
274 "f : {..Suc n} -> carrier G ==> |
|
275 finsum G f {..Suc n} = (f (Suc n) \<oplus> finsum G f {..n})" |
|
276 by (rule comm_monoid.finprod_Suc [OF a_comm_monoid, folded finsum_def, |
|
277 simplified monoid_record_simps]) |
|
278 |
|
279 lemma (in abelian_monoid) finsum_Suc2: |
|
280 "f : {..Suc n} -> carrier G ==> |
|
281 finsum G f {..Suc n} = (finsum G (%i. f (Suc i)) {..n} \<oplus> f 0)" |
|
282 by (rule comm_monoid.finprod_Suc2 [OF a_comm_monoid, folded finsum_def, |
|
283 simplified monoid_record_simps]) |
|
284 |
|
285 lemma (in abelian_monoid) finsum_add [simp]: |
|
286 "[| f : {..n} -> carrier G; g : {..n} -> carrier G |] ==> |
|
287 finsum G (%i. f i \<oplus> g i) {..n::nat} = |
|
288 finsum G f {..n} \<oplus> finsum G g {..n}" |
|
289 by (rule comm_monoid.finprod_mult [OF a_comm_monoid, folded finsum_def, |
|
290 simplified monoid_record_simps]) |
|
291 |
|
292 lemma (in abelian_monoid) finsum_cong: |
|
293 "[| A = B; f : B -> carrier G; |
|
294 !!i. i : B =simp=> f i = g i |] ==> finsum G f A = finsum G g B" |
|
295 by (rule comm_monoid.finprod_cong [OF a_comm_monoid, folded finsum_def, |
|
296 simplified monoid_record_simps]) (auto simp add: simp_implies_def) |
|
297 |
|
298 text {*Usually, if this rule causes a failed congruence proof error, |
|
299 the reason is that the premise @{text "g \<in> B -> carrier G"} cannot be shown. |
|
300 Adding @{thm [source] Pi_def} to the simpset is often useful. *} |
|
301 |
|
302 section {* The Algebraic Hierarchy of Rings *} |
|
303 |
|
304 subsection {* Basic Definitions *} |
|
305 |
|
306 locale ring = abelian_group R + monoid R + |
|
307 assumes l_distr: "[| x \<in> carrier R; y \<in> carrier R; z \<in> carrier R |] |
|
308 ==> (x \<oplus> y) \<otimes> z = x \<otimes> z \<oplus> y \<otimes> z" |
|
309 and r_distr: "[| x \<in> carrier R; y \<in> carrier R; z \<in> carrier R |] |
|
310 ==> z \<otimes> (x \<oplus> y) = z \<otimes> x \<oplus> z \<otimes> y" |
|
311 |
|
312 locale cring = ring + comm_monoid R |
|
313 |
|
314 locale "domain" = cring + |
|
315 assumes one_not_zero [simp]: "\<one> ~= \<zero>" |
|
316 and integral: "[| a \<otimes> b = \<zero>; a \<in> carrier R; b \<in> carrier R |] ==> |
|
317 a = \<zero> | b = \<zero>" |
|
318 |
|
319 locale field = "domain" + |
|
320 assumes field_Units: "Units R = carrier R - {\<zero>}" |
|
321 |
|
322 subsection {* Basic Facts of Rings *} |
|
323 |
|
324 lemma ringI: |
|
325 fixes R (structure) |
|
326 assumes abelian_group: "abelian_group R" |
|
327 and monoid: "monoid R" |
|
328 and l_distr: "!!x y z. [| x \<in> carrier R; y \<in> carrier R; z \<in> carrier R |] |
|
329 ==> (x \<oplus> y) \<otimes> z = x \<otimes> z \<oplus> y \<otimes> z" |
|
330 and r_distr: "!!x y z. [| x \<in> carrier R; y \<in> carrier R; z \<in> carrier R |] |
|
331 ==> z \<otimes> (x \<oplus> y) = z \<otimes> x \<oplus> z \<otimes> y" |
|
332 shows "ring R" |
|
333 by (auto intro: ring.intro |
|
334 abelian_group.axioms ring_axioms.intro prems) |
|
335 |
|
336 lemma (in ring) is_abelian_group: |
|
337 "abelian_group R" |
|
338 by (auto intro!: abelian_groupI a_assoc a_comm l_neg) |
|
339 |
|
340 lemma (in ring) is_monoid: |
|
341 "monoid R" |
|
342 by (auto intro!: monoidI m_assoc) |
|
343 |
|
344 lemma cringI: |
|
345 fixes R (structure) |
|
346 assumes abelian_group: "abelian_group R" |
|
347 and comm_monoid: "comm_monoid R" |
|
348 and l_distr: "!!x y z. [| x \<in> carrier R; y \<in> carrier R; z \<in> carrier R |] |
|
349 ==> (x \<oplus> y) \<otimes> z = x \<otimes> z \<oplus> y \<otimes> z" |
|
350 shows "cring R" |
|
351 proof (intro cring.intro ring.intro) |
|
352 show "ring_axioms R" |
|
353 -- {* Right-distributivity follows from left-distributivity and |
|
354 commutativity. *} |
|
355 proof (rule ring_axioms.intro) |
|
356 fix x y z |
|
357 assume R: "x \<in> carrier R" "y \<in> carrier R" "z \<in> carrier R" |
|
358 note [simp]= comm_monoid.axioms [OF comm_monoid] |
|
359 abelian_group.axioms [OF abelian_group] |
|
360 abelian_monoid.a_closed |
|
361 |
|
362 from R have "z \<otimes> (x \<oplus> y) = (x \<oplus> y) \<otimes> z" |
|
363 by (simp add: comm_monoid.m_comm [OF comm_monoid.intro]) |
|
364 also from R have "... = x \<otimes> z \<oplus> y \<otimes> z" by (simp add: l_distr) |
|
365 also from R have "... = z \<otimes> x \<oplus> z \<otimes> y" |
|
366 by (simp add: comm_monoid.m_comm [OF comm_monoid.intro]) |
|
367 finally show "z \<otimes> (x \<oplus> y) = z \<otimes> x \<oplus> z \<otimes> y" . |
|
368 qed |
|
369 qed (auto intro: cring.intro |
|
370 abelian_group.axioms comm_monoid.axioms ring_axioms.intro prems) |
|
371 |
|
372 lemma (in cring) is_comm_monoid: |
|
373 "comm_monoid R" |
|
374 by (auto intro!: comm_monoidI m_assoc m_comm) |
|
375 |
|
376 subsection {* Normaliser for Rings *} |
|
377 |
|
378 lemma (in abelian_group) r_neg2: |
|
379 "[| x \<in> carrier G; y \<in> carrier G |] ==> x \<oplus> (\<ominus> x \<oplus> y) = y" |
|
380 proof - |
|
381 assume G: "x \<in> carrier G" "y \<in> carrier G" |
|
382 then have "(x \<oplus> \<ominus> x) \<oplus> y = y" |
|
383 by (simp only: r_neg l_zero) |
|
384 with G show ?thesis |
|
385 by (simp add: a_ac) |
|
386 qed |
|
387 |
|
388 lemma (in abelian_group) r_neg1: |
|
389 "[| x \<in> carrier G; y \<in> carrier G |] ==> \<ominus> x \<oplus> (x \<oplus> y) = y" |
|
390 proof - |
|
391 assume G: "x \<in> carrier G" "y \<in> carrier G" |
|
392 then have "(\<ominus> x \<oplus> x) \<oplus> y = y" |
|
393 by (simp only: l_neg l_zero) |
|
394 with G show ?thesis by (simp add: a_ac) |
|
395 qed |
|
396 |
|
397 text {* |
|
398 The following proofs are from Jacobson, Basic Algebra I, pp.~88--89 |
|
399 *} |
|
400 |
|
401 lemma (in ring) l_null [simp]: |
|
402 "x \<in> carrier R ==> \<zero> \<otimes> x = \<zero>" |
|
403 proof - |
|
404 assume R: "x \<in> carrier R" |
|
405 then have "\<zero> \<otimes> x \<oplus> \<zero> \<otimes> x = (\<zero> \<oplus> \<zero>) \<otimes> x" |
|
406 by (simp add: l_distr del: l_zero r_zero) |
|
407 also from R have "... = \<zero> \<otimes> x \<oplus> \<zero>" by simp |
|
408 finally have "\<zero> \<otimes> x \<oplus> \<zero> \<otimes> x = \<zero> \<otimes> x \<oplus> \<zero>" . |
|
409 with R show ?thesis by (simp del: r_zero) |
|
410 qed |
|
411 |
|
412 lemma (in ring) r_null [simp]: |
|
413 "x \<in> carrier R ==> x \<otimes> \<zero> = \<zero>" |
|
414 proof - |
|
415 assume R: "x \<in> carrier R" |
|
416 then have "x \<otimes> \<zero> \<oplus> x \<otimes> \<zero> = x \<otimes> (\<zero> \<oplus> \<zero>)" |
|
417 by (simp add: r_distr del: l_zero r_zero) |
|
418 also from R have "... = x \<otimes> \<zero> \<oplus> \<zero>" by simp |
|
419 finally have "x \<otimes> \<zero> \<oplus> x \<otimes> \<zero> = x \<otimes> \<zero> \<oplus> \<zero>" . |
|
420 with R show ?thesis by (simp del: r_zero) |
|
421 qed |
|
422 |
|
423 lemma (in ring) l_minus: |
|
424 "[| x \<in> carrier R; y \<in> carrier R |] ==> \<ominus> x \<otimes> y = \<ominus> (x \<otimes> y)" |
|
425 proof - |
|
426 assume R: "x \<in> carrier R" "y \<in> carrier R" |
|
427 then have "(\<ominus> x) \<otimes> y \<oplus> x \<otimes> y = (\<ominus> x \<oplus> x) \<otimes> y" by (simp add: l_distr) |
|
428 also from R have "... = \<zero>" by (simp add: l_neg l_null) |
|
429 finally have "(\<ominus> x) \<otimes> y \<oplus> x \<otimes> y = \<zero>" . |
|
430 with R have "(\<ominus> x) \<otimes> y \<oplus> x \<otimes> y \<oplus> \<ominus> (x \<otimes> y) = \<zero> \<oplus> \<ominus> (x \<otimes> y)" by simp |
|
431 with R show ?thesis by (simp add: a_assoc r_neg ) |
|
432 qed |
|
433 |
|
434 lemma (in ring) r_minus: |
|
435 "[| x \<in> carrier R; y \<in> carrier R |] ==> x \<otimes> \<ominus> y = \<ominus> (x \<otimes> y)" |
|
436 proof - |
|
437 assume R: "x \<in> carrier R" "y \<in> carrier R" |
|
438 then have "x \<otimes> (\<ominus> y) \<oplus> x \<otimes> y = x \<otimes> (\<ominus> y \<oplus> y)" by (simp add: r_distr) |
|
439 also from R have "... = \<zero>" by (simp add: l_neg r_null) |
|
440 finally have "x \<otimes> (\<ominus> y) \<oplus> x \<otimes> y = \<zero>" . |
|
441 with R have "x \<otimes> (\<ominus> y) \<oplus> x \<otimes> y \<oplus> \<ominus> (x \<otimes> y) = \<zero> \<oplus> \<ominus> (x \<otimes> y)" by simp |
|
442 with R show ?thesis by (simp add: a_assoc r_neg ) |
|
443 qed |
|
444 |
|
445 lemma (in ring) minus_eq: |
|
446 "[| x \<in> carrier R; y \<in> carrier R |] ==> x \<ominus> y = x \<oplus> \<ominus> y" |
|
447 by (simp only: a_minus_def) |
|
448 |
|
449 text {* Setup algebra method: |
|
450 compute distributive normal form in locale contexts *} |
|
451 |
|
452 use "ringsimp.ML" |
|
453 |
|
454 setup Algebra.setup |
|
455 |
|
456 lemmas (in ring) ring_simprules |
|
457 [algebra ring "zero R" "add R" "a_inv R" "a_minus R" "one R" "mult R"] = |
|
458 a_closed zero_closed a_inv_closed minus_closed m_closed one_closed |
|
459 a_assoc l_zero l_neg a_comm m_assoc l_one l_distr minus_eq |
|
460 r_zero r_neg r_neg2 r_neg1 minus_add minus_minus minus_zero |
|
461 a_lcomm r_distr l_null r_null l_minus r_minus |
|
462 |
|
463 lemmas (in cring) |
|
464 [algebra del: ring "zero R" "add R" "a_inv R" "a_minus R" "one R" "mult R"] = |
|
465 _ |
|
466 |
|
467 lemmas (in cring) cring_simprules |
|
468 [algebra add: cring "zero R" "add R" "a_inv R" "a_minus R" "one R" "mult R"] = |
|
469 a_closed zero_closed a_inv_closed minus_closed m_closed one_closed |
|
470 a_assoc l_zero l_neg a_comm m_assoc l_one l_distr m_comm minus_eq |
|
471 r_zero r_neg r_neg2 r_neg1 minus_add minus_minus minus_zero |
|
472 a_lcomm m_lcomm r_distr l_null r_null l_minus r_minus |
|
473 |
|
474 |
|
475 lemma (in cring) nat_pow_zero: |
|
476 "(n::nat) ~= 0 ==> \<zero> (^) n = \<zero>" |
|
477 by (induct n) simp_all |
|
478 |
|
479 text {* Two examples for use of method algebra *} |
|
480 |
|
481 lemma |
|
482 includes ring R + cring S |
|
483 shows "[| a \<in> carrier R; b \<in> carrier R; c \<in> carrier S; d \<in> carrier S |] ==> |
|
484 a \<oplus> \<ominus> (a \<oplus> \<ominus> b) = b & c \<otimes>\<^bsub>S\<^esub> d = d \<otimes>\<^bsub>S\<^esub> c" |
|
485 by algebra |
|
486 |
|
487 lemma |
|
488 includes cring |
|
489 shows "[| a \<in> carrier R; b \<in> carrier R |] ==> a \<ominus> (a \<ominus> b) = b" |
|
490 by algebra |
|
491 |
|
492 subsection {* Sums over Finite Sets *} |
|
493 |
|
494 lemma (in cring) finsum_ldistr: |
|
495 "[| finite A; a \<in> carrier R; f \<in> A -> carrier R |] ==> |
|
496 finsum R f A \<otimes> a = finsum R (%i. f i \<otimes> a) A" |
|
497 proof (induct set: Finites) |
|
498 case empty then show ?case by simp |
|
499 next |
|
500 case (insert x F) then show ?case by (simp add: Pi_def l_distr) |
|
501 qed |
|
502 |
|
503 lemma (in cring) finsum_rdistr: |
|
504 "[| finite A; a \<in> carrier R; f \<in> A -> carrier R |] ==> |
|
505 a \<otimes> finsum R f A = finsum R (%i. a \<otimes> f i) A" |
|
506 proof (induct set: Finites) |
|
507 case empty then show ?case by simp |
|
508 next |
|
509 case (insert x F) then show ?case by (simp add: Pi_def r_distr) |
|
510 qed |
|
511 |
|
512 subsection {* Facts of Integral Domains *} |
|
513 |
|
514 lemma (in "domain") zero_not_one [simp]: |
|
515 "\<zero> ~= \<one>" |
|
516 by (rule not_sym) simp |
|
517 |
|
518 lemma (in "domain") integral_iff: (* not by default a simp rule! *) |
|
519 "[| a \<in> carrier R; b \<in> carrier R |] ==> (a \<otimes> b = \<zero>) = (a = \<zero> | b = \<zero>)" |
|
520 proof |
|
521 assume "a \<in> carrier R" "b \<in> carrier R" "a \<otimes> b = \<zero>" |
|
522 then show "a = \<zero> | b = \<zero>" by (simp add: integral) |
|
523 next |
|
524 assume "a \<in> carrier R" "b \<in> carrier R" "a = \<zero> | b = \<zero>" |
|
525 then show "a \<otimes> b = \<zero>" by auto |
|
526 qed |
|
527 |
|
528 lemma (in "domain") m_lcancel: |
|
529 assumes prem: "a ~= \<zero>" |
|
530 and R: "a \<in> carrier R" "b \<in> carrier R" "c \<in> carrier R" |
|
531 shows "(a \<otimes> b = a \<otimes> c) = (b = c)" |
|
532 proof |
|
533 assume eq: "a \<otimes> b = a \<otimes> c" |
|
534 with R have "a \<otimes> (b \<ominus> c) = \<zero>" by algebra |
|
535 with R have "a = \<zero> | (b \<ominus> c) = \<zero>" by (simp add: integral_iff) |
|
536 with prem and R have "b \<ominus> c = \<zero>" by auto |
|
537 with R have "b = b \<ominus> (b \<ominus> c)" by algebra |
|
538 also from R have "b \<ominus> (b \<ominus> c) = c" by algebra |
|
539 finally show "b = c" . |
|
540 next |
|
541 assume "b = c" then show "a \<otimes> b = a \<otimes> c" by simp |
|
542 qed |
|
543 |
|
544 lemma (in "domain") m_rcancel: |
|
545 assumes prem: "a ~= \<zero>" |
|
546 and R: "a \<in> carrier R" "b \<in> carrier R" "c \<in> carrier R" |
|
547 shows conc: "(b \<otimes> a = c \<otimes> a) = (b = c)" |
|
548 proof - |
|
549 from prem and R have "(a \<otimes> b = a \<otimes> c) = (b = c)" by (rule m_lcancel) |
|
550 with R show ?thesis by algebra |
|
551 qed |
|
552 |
|
553 subsection {* Morphisms *} |
|
554 |
|
555 constdefs (structure R S) |
|
556 ring_hom :: "[('a, 'm) ring_scheme, ('b, 'n) ring_scheme] => ('a => 'b) set" |
|
557 "ring_hom R S == {h. h \<in> carrier R -> carrier S & |
|
558 (ALL x y. x \<in> carrier R & y \<in> carrier R --> |
|
559 h (x \<otimes> y) = h x \<otimes>\<^bsub>S\<^esub> h y & h (x \<oplus> y) = h x \<oplus>\<^bsub>S\<^esub> h y) & |
|
560 h \<one> = \<one>\<^bsub>S\<^esub>}" |
|
561 |
|
562 lemma ring_hom_memI: |
|
563 fixes R (structure) and S (structure) |
|
564 assumes hom_closed: "!!x. x \<in> carrier R ==> h x \<in> carrier S" |
|
565 and hom_mult: "!!x y. [| x \<in> carrier R; y \<in> carrier R |] ==> |
|
566 h (x \<otimes> y) = h x \<otimes>\<^bsub>S\<^esub> h y" |
|
567 and hom_add: "!!x y. [| x \<in> carrier R; y \<in> carrier R |] ==> |
|
568 h (x \<oplus> y) = h x \<oplus>\<^bsub>S\<^esub> h y" |
|
569 and hom_one: "h \<one> = \<one>\<^bsub>S\<^esub>" |
|
570 shows "h \<in> ring_hom R S" |
|
571 by (auto simp add: ring_hom_def prems Pi_def) |
|
572 |
|
573 lemma ring_hom_closed: |
|
574 "[| h \<in> ring_hom R S; x \<in> carrier R |] ==> h x \<in> carrier S" |
|
575 by (auto simp add: ring_hom_def funcset_mem) |
|
576 |
|
577 lemma ring_hom_mult: |
|
578 fixes R (structure) and S (structure) |
|
579 shows |
|
580 "[| h \<in> ring_hom R S; x \<in> carrier R; y \<in> carrier R |] ==> |
|
581 h (x \<otimes> y) = h x \<otimes>\<^bsub>S\<^esub> h y" |
|
582 by (simp add: ring_hom_def) |
|
583 |
|
584 lemma ring_hom_add: |
|
585 fixes R (structure) and S (structure) |
|
586 shows |
|
587 "[| h \<in> ring_hom R S; x \<in> carrier R; y \<in> carrier R |] ==> |
|
588 h (x \<oplus> y) = h x \<oplus>\<^bsub>S\<^esub> h y" |
|
589 by (simp add: ring_hom_def) |
|
590 |
|
591 lemma ring_hom_one: |
|
592 fixes R (structure) and S (structure) |
|
593 shows "h \<in> ring_hom R S ==> h \<one> = \<one>\<^bsub>S\<^esub>" |
|
594 by (simp add: ring_hom_def) |
|
595 |
|
596 locale ring_hom_cring = cring R + cring S + |
|
597 fixes h |
|
598 assumes homh [simp, intro]: "h \<in> ring_hom R S" |
|
599 notes hom_closed [simp, intro] = ring_hom_closed [OF homh] |
|
600 and hom_mult [simp] = ring_hom_mult [OF homh] |
|
601 and hom_add [simp] = ring_hom_add [OF homh] |
|
602 and hom_one [simp] = ring_hom_one [OF homh] |
|
603 |
|
604 lemma (in ring_hom_cring) hom_zero [simp]: |
|
605 "h \<zero> = \<zero>\<^bsub>S\<^esub>" |
|
606 proof - |
|
607 have "h \<zero> \<oplus>\<^bsub>S\<^esub> h \<zero> = h \<zero> \<oplus>\<^bsub>S\<^esub> \<zero>\<^bsub>S\<^esub>" |
|
608 by (simp add: hom_add [symmetric] del: hom_add) |
|
609 then show ?thesis by (simp del: S.r_zero) |
|
610 qed |
|
611 |
|
612 lemma (in ring_hom_cring) hom_a_inv [simp]: |
|
613 "x \<in> carrier R ==> h (\<ominus> x) = \<ominus>\<^bsub>S\<^esub> h x" |
|
614 proof - |
|
615 assume R: "x \<in> carrier R" |
|
616 then have "h x \<oplus>\<^bsub>S\<^esub> h (\<ominus> x) = h x \<oplus>\<^bsub>S\<^esub> (\<ominus>\<^bsub>S\<^esub> h x)" |
|
617 by (simp add: hom_add [symmetric] R.r_neg S.r_neg del: hom_add) |
|
618 with R show ?thesis by simp |
|
619 qed |
|
620 |
|
621 lemma (in ring_hom_cring) hom_finsum [simp]: |
|
622 "[| finite A; f \<in> A -> carrier R |] ==> |
|
623 h (finsum R f A) = finsum S (h o f) A" |
|
624 proof (induct set: Finites) |
|
625 case empty then show ?case by simp |
|
626 next |
|
627 case insert then show ?case by (simp add: Pi_def) |
|
628 qed |
|
629 |
|
630 lemma (in ring_hom_cring) hom_finprod: |
|
631 "[| finite A; f \<in> A -> carrier R |] ==> |
|
632 h (finprod R f A) = finprod S (h o f) A" |
|
633 proof (induct set: Finites) |
|
634 case empty then show ?case by simp |
|
635 next |
|
636 case insert then show ?case by (simp add: Pi_def) |
|
637 qed |
|
638 |
|
639 declare ring_hom_cring.hom_finprod [simp] |
|
640 |
|
641 lemma id_ring_hom [simp]: |
|
642 "id \<in> ring_hom R R" |
|
643 by (auto intro!: ring_hom_memI) |
|
644 |
|
645 end |
|