src/HOL/Algebra/Ring.thy
 author haftmann Sun Jun 23 21:16:07 2013 +0200 (2013-06-23) changeset 52435 6646bb548c6b parent 48891 c0eafbd55de3 child 55926 3ef14caf5637 permissions -rw-r--r--
migration from code_(const|type|class|instance) to code_printing and from code_module to code_identifier
1 (*  Title:      HOL/Algebra/Ring.thy
2     Author:     Clemens Ballarin, started 9 December 1996
3     Copyright:  Clemens Ballarin
4 *)
6 theory Ring
7 imports FiniteProduct
8 begin
10 section {* The Algebraic Hierarchy of Rings *}
12 subsection {* Abelian Groups *}
14 record 'a ring = "'a monoid" +
15   zero :: 'a ("\<zero>\<index>")
16   add :: "['a, 'a] => 'a" (infixl "\<oplus>\<index>" 65)
18 text {* Derived operations. *}
20 definition
21   a_inv :: "[('a, 'm) ring_scheme, 'a ] => 'a" ("\<ominus>\<index> _"  80)
22   where "a_inv R = m_inv (| carrier = carrier R, mult = add R, one = zero R |)"
24 definition
25   a_minus :: "[('a, 'm) ring_scheme, 'a, 'a] => 'a" (infixl "\<ominus>\<index>" 65)
26   where "[| x \<in> carrier R; y \<in> carrier R |] ==> x \<ominus>\<^bsub>R\<^esub> y = x \<oplus>\<^bsub>R\<^esub> (\<ominus>\<^bsub>R\<^esub> y)"
28 locale abelian_monoid =
29   fixes G (structure)
30   assumes a_comm_monoid:
31      "comm_monoid (| carrier = carrier G, mult = add G, one = zero G |)"
33 definition
34   finsum :: "[('b, 'm) ring_scheme, 'a => 'b, 'a set] => 'b" where
35   "finsum G = finprod (| carrier = carrier G, mult = add G, one = zero G |)"
37 syntax
38   "_finsum" :: "index => idt => 'a set => 'b => 'b"
39       ("(3\<Oplus>__:_. _)" [1000, 0, 51, 10] 10)
40 syntax (xsymbols)
41   "_finsum" :: "index => idt => 'a set => 'b => 'b"
42       ("(3\<Oplus>__\<in>_. _)" [1000, 0, 51, 10] 10)
43 syntax (HTML output)
44   "_finsum" :: "index => idt => 'a set => 'b => 'b"
45       ("(3\<Oplus>__\<in>_. _)" [1000, 0, 51, 10] 10)
46 translations
47   "\<Oplus>\<index>i:A. b" == "CONST finsum \<struct>\<index> (%i. b) A"
48   -- {* Beware of argument permutation! *}
51 locale abelian_group = abelian_monoid +
52   assumes a_comm_group:
53      "comm_group (| carrier = carrier G, mult = add G, one = zero G |)"
56 subsection {* Basic Properties *}
58 lemma abelian_monoidI:
59   fixes R (structure)
60   assumes a_closed:
61       "!!x y. [| x \<in> carrier R; y \<in> carrier R |] ==> x \<oplus> y \<in> carrier R"
62     and zero_closed: "\<zero> \<in> carrier R"
63     and a_assoc:
64       "!!x y z. [| x \<in> carrier R; y \<in> carrier R; z \<in> carrier R |] ==>
65       (x \<oplus> y) \<oplus> z = x \<oplus> (y \<oplus> z)"
66     and l_zero: "!!x. x \<in> carrier R ==> \<zero> \<oplus> x = x"
67     and a_comm:
68       "!!x y. [| x \<in> carrier R; y \<in> carrier R |] ==> x \<oplus> y = y \<oplus> x"
69   shows "abelian_monoid R"
70   by (auto intro!: abelian_monoid.intro comm_monoidI intro: assms)
72 lemma abelian_groupI:
73   fixes R (structure)
74   assumes a_closed:
75       "!!x y. [| x \<in> carrier R; y \<in> carrier R |] ==> x \<oplus> y \<in> carrier R"
76     and zero_closed: "zero R \<in> carrier R"
77     and a_assoc:
78       "!!x y z. [| x \<in> carrier R; y \<in> carrier R; z \<in> carrier R |] ==>
79       (x \<oplus> y) \<oplus> z = x \<oplus> (y \<oplus> z)"
80     and a_comm:
81       "!!x y. [| x \<in> carrier R; y \<in> carrier R |] ==> x \<oplus> y = y \<oplus> x"
82     and l_zero: "!!x. x \<in> carrier R ==> \<zero> \<oplus> x = x"
83     and l_inv_ex: "!!x. x \<in> carrier R ==> EX y : carrier R. y \<oplus> x = \<zero>"
84   shows "abelian_group R"
85   by (auto intro!: abelian_group.intro abelian_monoidI
86       abelian_group_axioms.intro comm_monoidI comm_groupI
87     intro: assms)
89 lemma (in abelian_monoid) a_monoid:
90   "monoid (| carrier = carrier G, mult = add G, one = zero G |)"
91 by (rule comm_monoid.axioms, rule a_comm_monoid)
93 lemma (in abelian_group) a_group:
94   "group (| carrier = carrier G, mult = add G, one = zero G |)"
95   by (simp add: group_def a_monoid)
96     (simp add: comm_group.axioms group.axioms a_comm_group)
98 lemmas monoid_record_simps = partial_object.simps monoid.simps
100 text {* Transfer facts from multiplicative structures via interpretation. *}
102 sublocale abelian_monoid <
103   add!: monoid "(| carrier = carrier G, mult = add G, one = zero G |)"
104   where "carrier (| carrier = carrier G, mult = add G, one = zero G |) = carrier G"
105     and "mult (| carrier = carrier G, mult = add G, one = zero G |) = add G"
106     and "one (| carrier = carrier G, mult = add G, one = zero G |) = zero G"
107   by (rule a_monoid) auto
109 context abelian_monoid begin
111 lemmas a_closed = add.m_closed
112 lemmas zero_closed = add.one_closed
113 lemmas a_assoc = add.m_assoc
114 lemmas l_zero = add.l_one
115 lemmas r_zero = add.r_one
116 lemmas minus_unique = add.inv_unique
118 end
120 sublocale abelian_monoid <
121   add!: comm_monoid "(| carrier = carrier G, mult = add G, one = zero G |)"
122   where "carrier (| carrier = carrier G, mult = add G, one = zero G |) = carrier G"
123     and "mult (| carrier = carrier G, mult = add G, one = zero G |) = add G"
124     and "one (| carrier = carrier G, mult = add G, one = zero G |) = zero G"
125     and "finprod (| carrier = carrier G, mult = add G, one = zero G |) = finsum G"
126   by (rule a_comm_monoid) (auto simp: finsum_def)
128 context abelian_monoid begin
130 lemmas a_comm = add.m_comm
131 lemmas a_lcomm = add.m_lcomm
132 lemmas a_ac = a_assoc a_comm a_lcomm
134 lemmas finsum_empty = add.finprod_empty
135 lemmas finsum_insert = add.finprod_insert
136 lemmas finsum_zero = add.finprod_one
137 lemmas finsum_closed = add.finprod_closed
138 lemmas finsum_Un_Int = add.finprod_Un_Int
139 lemmas finsum_Un_disjoint = add.finprod_Un_disjoint
141 lemmas finsum_cong' = add.finprod_cong'
142 lemmas finsum_0 = add.finprod_0
143 lemmas finsum_Suc = add.finprod_Suc
144 lemmas finsum_Suc2 = add.finprod_Suc2
147 lemmas finsum_cong = add.finprod_cong
148 text {*Usually, if this rule causes a failed congruence proof error,
149    the reason is that the premise @{text "g \<in> B -> carrier G"} cannot be shown.
150    Adding @{thm [source] Pi_def} to the simpset is often useful. *}
152 lemmas finsum_reindex = add.finprod_reindex
154 (* The following would be wrong.  Needed is the equivalent of (^) for addition,
155   or indeed the canonical embedding from Nat into the monoid.
157 lemma finsum_const:
158   assumes fin [simp]: "finite A"
159       and a [simp]: "a : carrier G"
160     shows "finsum G (%x. a) A = a (^) card A"
161   using fin apply induct
162   apply force
163   apply (subst finsum_insert)
164   apply auto
165   apply (force simp add: Pi_def)
166   apply (subst m_comm)
167   apply auto
168 done
169 *)
171 lemmas finsum_singleton = add.finprod_singleton
173 end
175 sublocale abelian_group <
176   add!: group "(| carrier = carrier G, mult = add G, one = zero G |)"
177   where "carrier (| carrier = carrier G, mult = add G, one = zero G |) = carrier G"
178     and "mult (| carrier = carrier G, mult = add G, one = zero G |) = add G"
179     and "one (| carrier = carrier G, mult = add G, one = zero G |) = zero G"
180     and "m_inv (| carrier = carrier G, mult = add G, one = zero G |) = a_inv G"
181   by (rule a_group) (auto simp: m_inv_def a_inv_def)
183 context abelian_group begin
185 lemmas a_inv_closed = add.inv_closed
187 lemma minus_closed [intro, simp]:
188   "[| x \<in> carrier G; y \<in> carrier G |] ==> x \<ominus> y \<in> carrier G"
189   by (simp add: a_minus_def)
191 lemmas a_l_cancel = add.l_cancel
192 lemmas a_r_cancel = add.r_cancel
193 lemmas l_neg = add.l_inv [simp del]
194 lemmas r_neg = add.r_inv [simp del]
195 lemmas minus_zero = add.inv_one
196 lemmas minus_minus = add.inv_inv
197 lemmas a_inv_inj = add.inv_inj
198 lemmas minus_equality = add.inv_equality
200 end
202 sublocale abelian_group <
203   add!: comm_group "(| carrier = carrier G, mult = add G, one = zero G |)"
204   where "carrier (| carrier = carrier G, mult = add G, one = zero G |) = carrier G"
205     and "mult (| carrier = carrier G, mult = add G, one = zero G |) = add G"
206     and "one (| carrier = carrier G, mult = add G, one = zero G |) = zero G"
207     and "m_inv (| carrier = carrier G, mult = add G, one = zero G |) = a_inv G"
208     and "finprod (| carrier = carrier G, mult = add G, one = zero G |) = finsum G"
209   by (rule a_comm_group) (auto simp: m_inv_def a_inv_def finsum_def)
211 lemmas (in abelian_group) minus_add = add.inv_mult
213 text {* Derive an @{text "abelian_group"} from a @{text "comm_group"} *}
215 lemma comm_group_abelian_groupI:
216   fixes G (structure)
217   assumes cg: "comm_group \<lparr>carrier = carrier G, mult = add G, one = zero G\<rparr>"
218   shows "abelian_group G"
219 proof -
220   interpret comm_group "\<lparr>carrier = carrier G, mult = add G, one = zero G\<rparr>"
221     by (rule cg)
222   show "abelian_group G" ..
223 qed
226 subsection {* Rings: Basic Definitions *}
228 locale ring = abelian_group R + monoid R for R (structure) +
229   assumes l_distr: "[| x \<in> carrier R; y \<in> carrier R; z \<in> carrier R |]
230       ==> (x \<oplus> y) \<otimes> z = x \<otimes> z \<oplus> y \<otimes> z"
231     and r_distr: "[| x \<in> carrier R; y \<in> carrier R; z \<in> carrier R |]
232       ==> z \<otimes> (x \<oplus> y) = z \<otimes> x \<oplus> z \<otimes> y"
234 locale cring = ring + comm_monoid R
236 locale "domain" = cring +
237   assumes one_not_zero [simp]: "\<one> ~= \<zero>"
238     and integral: "[| a \<otimes> b = \<zero>; a \<in> carrier R; b \<in> carrier R |] ==>
239                   a = \<zero> | b = \<zero>"
241 locale field = "domain" +
242   assumes field_Units: "Units R = carrier R - {\<zero>}"
245 subsection {* Rings *}
247 lemma ringI:
248   fixes R (structure)
249   assumes abelian_group: "abelian_group R"
250     and monoid: "monoid R"
251     and l_distr: "!!x y z. [| x \<in> carrier R; y \<in> carrier R; z \<in> carrier R |]
252       ==> (x \<oplus> y) \<otimes> z = x \<otimes> z \<oplus> y \<otimes> z"
253     and r_distr: "!!x y z. [| x \<in> carrier R; y \<in> carrier R; z \<in> carrier R |]
254       ==> z \<otimes> (x \<oplus> y) = z \<otimes> x \<oplus> z \<otimes> y"
255   shows "ring R"
256   by (auto intro: ring.intro
257     abelian_group.axioms ring_axioms.intro assms)
259 context ring begin
261 lemma is_abelian_group: "abelian_group R" ..
263 lemma is_monoid: "monoid R"
264   by (auto intro!: monoidI m_assoc)
266 lemma is_ring: "ring R"
267   by (rule ring_axioms)
269 end
271 lemmas ring_record_simps = monoid_record_simps ring.simps
273 lemma cringI:
274   fixes R (structure)
275   assumes abelian_group: "abelian_group R"
276     and comm_monoid: "comm_monoid R"
277     and l_distr: "!!x y z. [| x \<in> carrier R; y \<in> carrier R; z \<in> carrier R |]
278       ==> (x \<oplus> y) \<otimes> z = x \<otimes> z \<oplus> y \<otimes> z"
279   shows "cring R"
280 proof (intro cring.intro ring.intro)
281   show "ring_axioms R"
282     -- {* Right-distributivity follows from left-distributivity and
283           commutativity. *}
284   proof (rule ring_axioms.intro)
285     fix x y z
286     assume R: "x \<in> carrier R" "y \<in> carrier R" "z \<in> carrier R"
287     note [simp] = comm_monoid.axioms [OF comm_monoid]
288       abelian_group.axioms [OF abelian_group]
289       abelian_monoid.a_closed
291     from R have "z \<otimes> (x \<oplus> y) = (x \<oplus> y) \<otimes> z"
292       by (simp add: comm_monoid.m_comm [OF comm_monoid.intro])
293     also from R have "... = x \<otimes> z \<oplus> y \<otimes> z" by (simp add: l_distr)
294     also from R have "... = z \<otimes> x \<oplus> z \<otimes> y"
295       by (simp add: comm_monoid.m_comm [OF comm_monoid.intro])
296     finally show "z \<otimes> (x \<oplus> y) = z \<otimes> x \<oplus> z \<otimes> y" .
297   qed (rule l_distr)
298 qed (auto intro: cring.intro
299   abelian_group.axioms comm_monoid.axioms ring_axioms.intro assms)
301 (*
302 lemma (in cring) is_comm_monoid:
303   "comm_monoid R"
304   by (auto intro!: comm_monoidI m_assoc m_comm)
305 *)
307 lemma (in cring) is_cring:
308   "cring R" by (rule cring_axioms)
311 subsubsection {* Normaliser for Rings *}
313 lemma (in abelian_group) r_neg2:
314   "[| x \<in> carrier G; y \<in> carrier G |] ==> x \<oplus> (\<ominus> x \<oplus> y) = y"
315 proof -
316   assume G: "x \<in> carrier G" "y \<in> carrier G"
317   then have "(x \<oplus> \<ominus> x) \<oplus> y = y"
318     by (simp only: r_neg l_zero)
319   with G show ?thesis
320     by (simp add: a_ac)
321 qed
323 lemma (in abelian_group) r_neg1:
324   "[| x \<in> carrier G; y \<in> carrier G |] ==> \<ominus> x \<oplus> (x \<oplus> y) = y"
325 proof -
326   assume G: "x \<in> carrier G" "y \<in> carrier G"
327   then have "(\<ominus> x \<oplus> x) \<oplus> y = y"
328     by (simp only: l_neg l_zero)
329   with G show ?thesis by (simp add: a_ac)
330 qed
332 context ring begin
334 text {*
335   The following proofs are from Jacobson, Basic Algebra I, pp.~88--89.
336 *}
338 lemma l_null [simp]:
339   "x \<in> carrier R ==> \<zero> \<otimes> x = \<zero>"
340 proof -
341   assume R: "x \<in> carrier R"
342   then have "\<zero> \<otimes> x \<oplus> \<zero> \<otimes> x = (\<zero> \<oplus> \<zero>) \<otimes> x"
343     by (simp add: l_distr del: l_zero r_zero)
344   also from R have "... = \<zero> \<otimes> x \<oplus> \<zero>" by simp
345   finally have "\<zero> \<otimes> x \<oplus> \<zero> \<otimes> x = \<zero> \<otimes> x \<oplus> \<zero>" .
346   with R show ?thesis by (simp del: r_zero)
347 qed
349 lemma r_null [simp]:
350   "x \<in> carrier R ==> x \<otimes> \<zero> = \<zero>"
351 proof -
352   assume R: "x \<in> carrier R"
353   then have "x \<otimes> \<zero> \<oplus> x \<otimes> \<zero> = x \<otimes> (\<zero> \<oplus> \<zero>)"
354     by (simp add: r_distr del: l_zero r_zero)
355   also from R have "... = x \<otimes> \<zero> \<oplus> \<zero>" by simp
356   finally have "x \<otimes> \<zero> \<oplus> x \<otimes> \<zero> = x \<otimes> \<zero> \<oplus> \<zero>" .
357   with R show ?thesis by (simp del: r_zero)
358 qed
360 lemma l_minus:
361   "[| x \<in> carrier R; y \<in> carrier R |] ==> \<ominus> x \<otimes> y = \<ominus> (x \<otimes> y)"
362 proof -
363   assume R: "x \<in> carrier R" "y \<in> carrier R"
364   then have "(\<ominus> x) \<otimes> y \<oplus> x \<otimes> y = (\<ominus> x \<oplus> x) \<otimes> y" by (simp add: l_distr)
365   also from R have "... = \<zero>" by (simp add: l_neg)
366   finally have "(\<ominus> x) \<otimes> y \<oplus> x \<otimes> y = \<zero>" .
367   with R have "(\<ominus> x) \<otimes> y \<oplus> x \<otimes> y \<oplus> \<ominus> (x \<otimes> y) = \<zero> \<oplus> \<ominus> (x \<otimes> y)" by simp
368   with R show ?thesis by (simp add: a_assoc r_neg)
369 qed
371 lemma r_minus:
372   "[| x \<in> carrier R; y \<in> carrier R |] ==> x \<otimes> \<ominus> y = \<ominus> (x \<otimes> y)"
373 proof -
374   assume R: "x \<in> carrier R" "y \<in> carrier R"
375   then have "x \<otimes> (\<ominus> y) \<oplus> x \<otimes> y = x \<otimes> (\<ominus> y \<oplus> y)" by (simp add: r_distr)
376   also from R have "... = \<zero>" by (simp add: l_neg)
377   finally have "x \<otimes> (\<ominus> y) \<oplus> x \<otimes> y = \<zero>" .
378   with R have "x \<otimes> (\<ominus> y) \<oplus> x \<otimes> y \<oplus> \<ominus> (x \<otimes> y) = \<zero> \<oplus> \<ominus> (x \<otimes> y)" by simp
379   with R show ?thesis by (simp add: a_assoc r_neg )
380 qed
382 end
384 lemma (in abelian_group) minus_eq:
385   "[| x \<in> carrier G; y \<in> carrier G |] ==> x \<ominus> y = x \<oplus> \<ominus> y"
386   by (simp only: a_minus_def)
388 text {* Setup algebra method:
389   compute distributive normal form in locale contexts *}
391 ML_file "ringsimp.ML"
393 setup Algebra.attrib_setup
395 method_setup algebra = {*
396   Scan.succeed (SIMPLE_METHOD' o Algebra.algebra_tac)
397 *} "normalisation of algebraic structure"
399 lemmas (in ring) ring_simprules
400   [algebra ring "zero R" "add R" "a_inv R" "a_minus R" "one R" "mult R"] =
401   a_closed zero_closed a_inv_closed minus_closed m_closed one_closed
402   a_assoc l_zero l_neg a_comm m_assoc l_one l_distr minus_eq
403   r_zero r_neg r_neg2 r_neg1 minus_add minus_minus minus_zero
404   a_lcomm r_distr l_null r_null l_minus r_minus
406 lemmas (in cring)
407   [algebra del: ring "zero R" "add R" "a_inv R" "a_minus R" "one R" "mult R"] =
408   _
410 lemmas (in cring) cring_simprules
411   [algebra add: cring "zero R" "add R" "a_inv R" "a_minus R" "one R" "mult R"] =
412   a_closed zero_closed a_inv_closed minus_closed m_closed one_closed
413   a_assoc l_zero l_neg a_comm m_assoc l_one l_distr m_comm minus_eq
414   r_zero r_neg r_neg2 r_neg1 minus_add minus_minus minus_zero
415   a_lcomm m_lcomm r_distr l_null r_null l_minus r_minus
417 lemma (in cring) nat_pow_zero:
418   "(n::nat) ~= 0 ==> \<zero> (^) n = \<zero>"
419   by (induct n) simp_all
421 context ring begin
423 lemma one_zeroD:
424   assumes onezero: "\<one> = \<zero>"
425   shows "carrier R = {\<zero>}"
426 proof (rule, rule)
427   fix x
428   assume xcarr: "x \<in> carrier R"
429   from xcarr have "x = x \<otimes> \<one>" by simp
430   with onezero have "x = x \<otimes> \<zero>" by simp
431   with xcarr have "x = \<zero>" by simp
432   then show "x \<in> {\<zero>}" by fast
433 qed fast
435 lemma one_zeroI:
436   assumes carrzero: "carrier R = {\<zero>}"
437   shows "\<one> = \<zero>"
438 proof -
439   from one_closed and carrzero
440       show "\<one> = \<zero>" by simp
441 qed
443 lemma carrier_one_zero: "(carrier R = {\<zero>}) = (\<one> = \<zero>)"
444   apply rule
445    apply (erule one_zeroI)
446   apply (erule one_zeroD)
447   done
449 lemma carrier_one_not_zero: "(carrier R \<noteq> {\<zero>}) = (\<one> \<noteq> \<zero>)"
450   by (simp add: carrier_one_zero)
452 end
454 text {* Two examples for use of method algebra *}
456 lemma
457   fixes R (structure) and S (structure)
458   assumes "ring R" "cring S"
459   assumes RS: "a \<in> carrier R" "b \<in> carrier R" "c \<in> carrier S" "d \<in> carrier S"
460   shows "a \<oplus> \<ominus> (a \<oplus> \<ominus> b) = b & c \<otimes>\<^bsub>S\<^esub> d = d \<otimes>\<^bsub>S\<^esub> c"
461 proof -
462   interpret ring R by fact
463   interpret cring S by fact
464   from RS show ?thesis by algebra
465 qed
467 lemma
468   fixes R (structure)
469   assumes "ring R"
470   assumes R: "a \<in> carrier R" "b \<in> carrier R"
471   shows "a \<ominus> (a \<ominus> b) = b"
472 proof -
473   interpret ring R by fact
474   from R show ?thesis by algebra
475 qed
478 subsubsection {* Sums over Finite Sets *}
480 lemma (in ring) finsum_ldistr:
481   "[| finite A; a \<in> carrier R; f \<in> A -> carrier R |] ==>
482    finsum R f A \<otimes> a = finsum R (%i. f i \<otimes> a) A"
483 proof (induct set: finite)
484   case empty then show ?case by simp
485 next
486   case (insert x F) then show ?case by (simp add: Pi_def l_distr)
487 qed
489 lemma (in ring) finsum_rdistr:
490   "[| finite A; a \<in> carrier R; f \<in> A -> carrier R |] ==>
491    a \<otimes> finsum R f A = finsum R (%i. a \<otimes> f i) A"
492 proof (induct set: finite)
493   case empty then show ?case by simp
494 next
495   case (insert x F) then show ?case by (simp add: Pi_def r_distr)
496 qed
499 subsection {* Integral Domains *}
501 context "domain" begin
503 lemma zero_not_one [simp]:
504   "\<zero> ~= \<one>"
505   by (rule not_sym) simp
507 lemma integral_iff: (* not by default a simp rule! *)
508   "[| a \<in> carrier R; b \<in> carrier R |] ==> (a \<otimes> b = \<zero>) = (a = \<zero> | b = \<zero>)"
509 proof
510   assume "a \<in> carrier R" "b \<in> carrier R" "a \<otimes> b = \<zero>"
511   then show "a = \<zero> | b = \<zero>" by (simp add: integral)
512 next
513   assume "a \<in> carrier R" "b \<in> carrier R" "a = \<zero> | b = \<zero>"
514   then show "a \<otimes> b = \<zero>" by auto
515 qed
517 lemma m_lcancel:
518   assumes prem: "a ~= \<zero>"
519     and R: "a \<in> carrier R" "b \<in> carrier R" "c \<in> carrier R"
520   shows "(a \<otimes> b = a \<otimes> c) = (b = c)"
521 proof
522   assume eq: "a \<otimes> b = a \<otimes> c"
523   with R have "a \<otimes> (b \<ominus> c) = \<zero>" by algebra
524   with R have "a = \<zero> | (b \<ominus> c) = \<zero>" by (simp add: integral_iff)
525   with prem and R have "b \<ominus> c = \<zero>" by auto
526   with R have "b = b \<ominus> (b \<ominus> c)" by algebra
527   also from R have "b \<ominus> (b \<ominus> c) = c" by algebra
528   finally show "b = c" .
529 next
530   assume "b = c" then show "a \<otimes> b = a \<otimes> c" by simp
531 qed
533 lemma m_rcancel:
534   assumes prem: "a ~= \<zero>"
535     and R: "a \<in> carrier R" "b \<in> carrier R" "c \<in> carrier R"
536   shows conc: "(b \<otimes> a = c \<otimes> a) = (b = c)"
537 proof -
538   from prem and R have "(a \<otimes> b = a \<otimes> c) = (b = c)" by (rule m_lcancel)
539   with R show ?thesis by algebra
540 qed
542 end
545 subsection {* Fields *}
547 text {* Field would not need to be derived from domain, the properties
548   for domain follow from the assumptions of field *}
549 lemma (in cring) cring_fieldI:
550   assumes field_Units: "Units R = carrier R - {\<zero>}"
551   shows "field R"
552 proof
553   from field_Units have "\<zero> \<notin> Units R" by fast
554   moreover have "\<one> \<in> Units R" by fast
555   ultimately show "\<one> \<noteq> \<zero>" by force
556 next
557   fix a b
558   assume acarr: "a \<in> carrier R"
559     and bcarr: "b \<in> carrier R"
560     and ab: "a \<otimes> b = \<zero>"
561   show "a = \<zero> \<or> b = \<zero>"
562   proof (cases "a = \<zero>", simp)
563     assume "a \<noteq> \<zero>"
564     with field_Units and acarr have aUnit: "a \<in> Units R" by fast
565     from bcarr have "b = \<one> \<otimes> b" by algebra
566     also from aUnit acarr have "... = (inv a \<otimes> a) \<otimes> b" by simp
567     also from acarr bcarr aUnit[THEN Units_inv_closed]
568     have "... = (inv a) \<otimes> (a \<otimes> b)" by algebra
569     also from ab and acarr bcarr aUnit have "... = (inv a) \<otimes> \<zero>" by simp
570     also from aUnit[THEN Units_inv_closed] have "... = \<zero>" by algebra
571     finally have "b = \<zero>" .
572     then show "a = \<zero> \<or> b = \<zero>" by simp
573   qed
574 qed (rule field_Units)
576 text {* Another variant to show that something is a field *}
577 lemma (in cring) cring_fieldI2:
578   assumes notzero: "\<zero> \<noteq> \<one>"
579   and invex: "\<And>a. \<lbrakk>a \<in> carrier R; a \<noteq> \<zero>\<rbrakk> \<Longrightarrow> \<exists>b\<in>carrier R. a \<otimes> b = \<one>"
580   shows "field R"
581   apply (rule cring_fieldI, simp add: Units_def)
582   apply (rule, clarsimp)
583   apply (simp add: notzero)
584 proof (clarsimp)
585   fix x
586   assume xcarr: "x \<in> carrier R"
587     and "x \<noteq> \<zero>"
588   then have "\<exists>y\<in>carrier R. x \<otimes> y = \<one>" by (rule invex)
589   then obtain y where ycarr: "y \<in> carrier R" and xy: "x \<otimes> y = \<one>" by fast
590   from xy xcarr ycarr have "y \<otimes> x = \<one>" by (simp add: m_comm)
591   with ycarr and xy show "\<exists>y\<in>carrier R. y \<otimes> x = \<one> \<and> x \<otimes> y = \<one>" by fast
592 qed
595 subsection {* Morphisms *}
597 definition
598   ring_hom :: "[('a, 'm) ring_scheme, ('b, 'n) ring_scheme] => ('a => 'b) set"
599   where "ring_hom R S =
600     {h. h \<in> carrier R -> carrier S &
601       (ALL x y. x \<in> carrier R & y \<in> carrier R -->
602         h (x \<otimes>\<^bsub>R\<^esub> y) = h x \<otimes>\<^bsub>S\<^esub> h y & h (x \<oplus>\<^bsub>R\<^esub> y) = h x \<oplus>\<^bsub>S\<^esub> h y) &
603       h \<one>\<^bsub>R\<^esub> = \<one>\<^bsub>S\<^esub>}"
605 lemma ring_hom_memI:
606   fixes R (structure) and S (structure)
607   assumes hom_closed: "!!x. x \<in> carrier R ==> h x \<in> carrier S"
608     and hom_mult: "!!x y. [| x \<in> carrier R; y \<in> carrier R |] ==>
609       h (x \<otimes> y) = h x \<otimes>\<^bsub>S\<^esub> h y"
610     and hom_add: "!!x y. [| x \<in> carrier R; y \<in> carrier R |] ==>
611       h (x \<oplus> y) = h x \<oplus>\<^bsub>S\<^esub> h y"
612     and hom_one: "h \<one> = \<one>\<^bsub>S\<^esub>"
613   shows "h \<in> ring_hom R S"
614   by (auto simp add: ring_hom_def assms Pi_def)
616 lemma ring_hom_closed:
617   "[| h \<in> ring_hom R S; x \<in> carrier R |] ==> h x \<in> carrier S"
618   by (auto simp add: ring_hom_def funcset_mem)
620 lemma ring_hom_mult:
621   fixes R (structure) and S (structure)
622   shows
623     "[| h \<in> ring_hom R S; x \<in> carrier R; y \<in> carrier R |] ==>
624     h (x \<otimes> y) = h x \<otimes>\<^bsub>S\<^esub> h y"
625     by (simp add: ring_hom_def)
628   fixes R (structure) and S (structure)
629   shows
630     "[| h \<in> ring_hom R S; x \<in> carrier R; y \<in> carrier R |] ==>
631     h (x \<oplus> y) = h x \<oplus>\<^bsub>S\<^esub> h y"
632     by (simp add: ring_hom_def)
634 lemma ring_hom_one:
635   fixes R (structure) and S (structure)
636   shows "h \<in> ring_hom R S ==> h \<one> = \<one>\<^bsub>S\<^esub>"
637   by (simp add: ring_hom_def)
639 locale ring_hom_cring = R: cring R + S: cring S
640     for R (structure) and S (structure) +
641   fixes h
642   assumes homh [simp, intro]: "h \<in> ring_hom R S"
643   notes hom_closed [simp, intro] = ring_hom_closed [OF homh]
644     and hom_mult [simp] = ring_hom_mult [OF homh]
645     and hom_add [simp] = ring_hom_add [OF homh]
646     and hom_one [simp] = ring_hom_one [OF homh]
648 lemma (in ring_hom_cring) hom_zero [simp]:
649   "h \<zero> = \<zero>\<^bsub>S\<^esub>"
650 proof -
651   have "h \<zero> \<oplus>\<^bsub>S\<^esub> h \<zero> = h \<zero> \<oplus>\<^bsub>S\<^esub> \<zero>\<^bsub>S\<^esub>"
653   then show ?thesis by (simp del: S.r_zero)
654 qed
656 lemma (in ring_hom_cring) hom_a_inv [simp]:
657   "x \<in> carrier R ==> h (\<ominus> x) = \<ominus>\<^bsub>S\<^esub> h x"
658 proof -
659   assume R: "x \<in> carrier R"
660   then have "h x \<oplus>\<^bsub>S\<^esub> h (\<ominus> x) = h x \<oplus>\<^bsub>S\<^esub> (\<ominus>\<^bsub>S\<^esub> h x)"
661     by (simp add: hom_add [symmetric] R.r_neg S.r_neg del: hom_add)
662   with R show ?thesis by simp
663 qed
665 lemma (in ring_hom_cring) hom_finsum [simp]:
666   "[| finite A; f \<in> A -> carrier R |] ==>
667   h (finsum R f A) = finsum S (h o f) A"
668 proof (induct set: finite)
669   case empty then show ?case by simp
670 next
671   case insert then show ?case by (simp add: Pi_def)
672 qed
674 lemma (in ring_hom_cring) hom_finprod:
675   "[| finite A; f \<in> A -> carrier R |] ==>
676   h (finprod R f A) = finprod S (h o f) A"
677 proof (induct set: finite)
678   case empty then show ?case by simp
679 next
680   case insert then show ?case by (simp add: Pi_def)
681 qed
683 declare ring_hom_cring.hom_finprod [simp]
685 lemma id_ring_hom [simp]:
686   "id \<in> ring_hom R R"
687   by (auto intro!: ring_hom_memI)
689 end