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