src/HOL/Algebra/Ring.thy
 author wenzelm Wed Mar 05 21:33:59 2008 +0100 (2008-03-05) changeset 26202 51f8a696cd8d parent 23957 54fab60ddc97 child 27611 2c01c0bdb385 permissions -rw-r--r--
explicit referencing of background facts;
```     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> _"  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   apply (rule comm_monoid.finprod_closed [OF a_comm_monoid,
```
```   253     folded finsum_def, simplified monoid_record_simps])
```
```   254    apply (rule fin)
```
```   255   apply (rule f)
```
```   256   done
```
```   257
```
```   258 lemma (in abelian_monoid) finsum_Un_Int:
```
```   259   "[| finite A; finite B; g \<in> A -> carrier G; g \<in> B -> carrier G |] ==>
```
```   260      finsum G g (A Un B) \<oplus> finsum G g (A Int B) =
```
```   261      finsum G g A \<oplus> finsum G g B"
```
```   262   by (rule comm_monoid.finprod_Un_Int [OF a_comm_monoid,
```
```   263     folded finsum_def, simplified monoid_record_simps])
```
```   264
```
```   265 lemma (in abelian_monoid) finsum_Un_disjoint:
```
```   266   "[| finite A; finite B; A Int B = {};
```
```   267       g \<in> A -> carrier G; g \<in> B -> carrier G |]
```
```   268    ==> finsum G g (A Un B) = finsum G g A \<oplus> finsum G g B"
```
```   269   by (rule comm_monoid.finprod_Un_disjoint [OF a_comm_monoid,
```
```   270     folded finsum_def, simplified monoid_record_simps])
```
```   271
```
```   272 lemma (in abelian_monoid) finsum_addf:
```
```   273   "[| finite A; f \<in> A -> carrier G; g \<in> A -> carrier G |] ==>
```
```   274    finsum G (%x. f x \<oplus> g x) A = (finsum G f A \<oplus> finsum G g A)"
```
```   275   by (rule comm_monoid.finprod_multf [OF a_comm_monoid,
```
```   276     folded finsum_def, simplified monoid_record_simps])
```
```   277
```
```   278 lemma (in abelian_monoid) finsum_cong':
```
```   279   "[| A = B; g : B -> carrier G;
```
```   280       !!i. i : B ==> f i = g i |] ==> finsum G f A = finsum G g B"
```
```   281   by (rule comm_monoid.finprod_cong' [OF a_comm_monoid,
```
```   282     folded finsum_def, simplified monoid_record_simps]) auto
```
```   283
```
```   284 lemma (in abelian_monoid) finsum_0 [simp]:
```
```   285   "f : {0::nat} -> carrier G ==> finsum G f {..0} = f 0"
```
```   286   by (rule comm_monoid.finprod_0 [OF a_comm_monoid, folded finsum_def,
```
```   287     simplified monoid_record_simps])
```
```   288
```
```   289 lemma (in abelian_monoid) finsum_Suc [simp]:
```
```   290   "f : {..Suc n} -> carrier G ==>
```
```   291    finsum G f {..Suc n} = (f (Suc n) \<oplus> finsum G f {..n})"
```
```   292   by (rule comm_monoid.finprod_Suc [OF a_comm_monoid, folded finsum_def,
```
```   293     simplified monoid_record_simps])
```
```   294
```
```   295 lemma (in abelian_monoid) finsum_Suc2:
```
```   296   "f : {..Suc n} -> carrier G ==>
```
```   297    finsum G f {..Suc n} = (finsum G (%i. f (Suc i)) {..n} \<oplus> f 0)"
```
```   298   by (rule comm_monoid.finprod_Suc2 [OF a_comm_monoid, folded finsum_def,
```
```   299     simplified monoid_record_simps])
```
```   300
```
```   301 lemma (in abelian_monoid) finsum_add [simp]:
```
```   302   "[| f : {..n} -> carrier G; g : {..n} -> carrier G |] ==>
```
```   303      finsum G (%i. f i \<oplus> g i) {..n::nat} =
```
```   304      finsum G f {..n} \<oplus> finsum G g {..n}"
```
```   305   by (rule comm_monoid.finprod_mult [OF a_comm_monoid, folded finsum_def,
```
```   306     simplified monoid_record_simps])
```
```   307
```
```   308 lemma (in abelian_monoid) finsum_cong:
```
```   309   "[| A = B; f : B -> carrier G;
```
```   310       !!i. i : B =simp=> f i = g i |] ==> finsum G f A = finsum G g B"
```
```   311   by (rule comm_monoid.finprod_cong [OF a_comm_monoid, folded finsum_def,
```
```   312     simplified monoid_record_simps]) (auto simp add: simp_implies_def)
```
```   313
```
```   314 text {*Usually, if this rule causes a failed congruence proof error,
```
```   315    the reason is that the premise @{text "g \<in> B -> carrier G"} cannot be shown.
```
```   316    Adding @{thm [source] Pi_def} to the simpset is often useful. *}
```
```   317
```
```   318
```
```   319 section {* The Algebraic Hierarchy of Rings *}
```
```   320
```
```   321
```
```   322 subsection {* Basic Definitions *}
```
```   323
```
```   324 locale ring = abelian_group R + monoid R +
```
```   325   assumes l_distr: "[| x \<in> carrier R; y \<in> carrier R; z \<in> carrier R |]
```
```   326       ==> (x \<oplus> y) \<otimes> z = x \<otimes> z \<oplus> y \<otimes> z"
```
```   327     and r_distr: "[| x \<in> carrier R; y \<in> carrier R; z \<in> carrier R |]
```
```   328       ==> z \<otimes> (x \<oplus> y) = z \<otimes> x \<oplus> z \<otimes> y"
```
```   329
```
```   330 locale cring = ring + comm_monoid R
```
```   331
```
```   332 locale "domain" = cring +
```
```   333   assumes one_not_zero [simp]: "\<one> ~= \<zero>"
```
```   334     and integral: "[| a \<otimes> b = \<zero>; a \<in> carrier R; b \<in> carrier R |] ==>
```
```   335                   a = \<zero> | b = \<zero>"
```
```   336
```
```   337 locale field = "domain" +
```
```   338   assumes field_Units: "Units R = carrier R - {\<zero>}"
```
```   339
```
```   340
```
```   341 subsection {* Rings *}
```
```   342
```
```   343 lemma ringI:
```
```   344   fixes R (structure)
```
```   345   assumes abelian_group: "abelian_group R"
```
```   346     and monoid: "monoid R"
```
```   347     and l_distr: "!!x y z. [| x \<in> carrier R; y \<in> carrier R; z \<in> carrier R |]
```
```   348       ==> (x \<oplus> y) \<otimes> z = x \<otimes> z \<oplus> y \<otimes> z"
```
```   349     and r_distr: "!!x y z. [| x \<in> carrier R; y \<in> carrier R; z \<in> carrier R |]
```
```   350       ==> z \<otimes> (x \<oplus> y) = z \<otimes> x \<oplus> z \<otimes> y"
```
```   351   shows "ring R"
```
```   352   by (auto intro: ring.intro
```
```   353     abelian_group.axioms ring_axioms.intro prems)
```
```   354
```
```   355 lemma (in ring) is_abelian_group:
```
```   356   "abelian_group R"
```
```   357   by (auto intro!: abelian_groupI a_assoc a_comm l_neg)
```
```   358
```
```   359 lemma (in ring) is_monoid:
```
```   360   "monoid R"
```
```   361   by (auto intro!: monoidI m_assoc)
```
```   362
```
```   363 lemma (in ring) is_ring:
```
```   364   "ring R"
```
```   365   by (rule ring_axioms)
```
```   366
```
```   367 lemmas ring_record_simps = monoid_record_simps ring.simps
```
```   368
```
```   369 lemma cringI:
```
```   370   fixes R (structure)
```
```   371   assumes abelian_group: "abelian_group R"
```
```   372     and comm_monoid: "comm_monoid R"
```
```   373     and l_distr: "!!x y z. [| x \<in> carrier R; y \<in> carrier R; z \<in> carrier R |]
```
```   374       ==> (x \<oplus> y) \<otimes> z = x \<otimes> z \<oplus> y \<otimes> z"
```
```   375   shows "cring R"
```
```   376 proof (intro cring.intro ring.intro)
```
```   377   show "ring_axioms R"
```
```   378     -- {* Right-distributivity follows from left-distributivity and
```
```   379           commutativity. *}
```
```   380   proof (rule ring_axioms.intro)
```
```   381     fix x y z
```
```   382     assume R: "x \<in> carrier R" "y \<in> carrier R" "z \<in> carrier R"
```
```   383     note [simp] = comm_monoid.axioms [OF comm_monoid]
```
```   384       abelian_group.axioms [OF abelian_group]
```
```   385       abelian_monoid.a_closed
```
```   386
```
```   387     from R have "z \<otimes> (x \<oplus> y) = (x \<oplus> y) \<otimes> z"
```
```   388       by (simp add: comm_monoid.m_comm [OF comm_monoid.intro])
```
```   389     also from R have "... = x \<otimes> z \<oplus> y \<otimes> z" by (simp add: l_distr)
```
```   390     also from R have "... = z \<otimes> x \<oplus> z \<otimes> y"
```
```   391       by (simp add: comm_monoid.m_comm [OF comm_monoid.intro])
```
```   392     finally show "z \<otimes> (x \<oplus> y) = z \<otimes> x \<oplus> z \<otimes> y" .
```
```   393   qed (rule l_distr)
```
```   394 qed (auto intro: cring.intro
```
```   395   abelian_group.axioms comm_monoid.axioms ring_axioms.intro prems)
```
```   396
```
```   397 lemma (in cring) is_comm_monoid:
```
```   398   "comm_monoid R"
```
```   399   by (auto intro!: comm_monoidI m_assoc m_comm)
```
```   400
```
```   401 lemma (in cring) is_cring:
```
```   402   "cring R" by (rule cring_axioms)
```
```   403
```
```   404
```
```   405 subsubsection {* Normaliser for Rings *}
```
```   406
```
```   407 lemma (in abelian_group) r_neg2:
```
```   408   "[| x \<in> carrier G; y \<in> carrier G |] ==> x \<oplus> (\<ominus> x \<oplus> y) = y"
```
```   409 proof -
```
```   410   assume G: "x \<in> carrier G" "y \<in> carrier G"
```
```   411   then have "(x \<oplus> \<ominus> x) \<oplus> y = y"
```
```   412     by (simp only: r_neg l_zero)
```
```   413   with G show ?thesis
```
```   414     by (simp add: a_ac)
```
```   415 qed
```
```   416
```
```   417 lemma (in abelian_group) r_neg1:
```
```   418   "[| x \<in> carrier G; y \<in> carrier G |] ==> \<ominus> x \<oplus> (x \<oplus> y) = y"
```
```   419 proof -
```
```   420   assume G: "x \<in> carrier G" "y \<in> carrier G"
```
```   421   then have "(\<ominus> x \<oplus> x) \<oplus> y = y"
```
```   422     by (simp only: l_neg l_zero)
```
```   423   with G show ?thesis by (simp add: a_ac)
```
```   424 qed
```
```   425
```
```   426 text {*
```
```   427   The following proofs are from Jacobson, Basic Algebra I, pp.~88--89
```
```   428 *}
```
```   429
```
```   430 lemma (in ring) l_null [simp]:
```
```   431   "x \<in> carrier R ==> \<zero> \<otimes> x = \<zero>"
```
```   432 proof -
```
```   433   assume R: "x \<in> carrier R"
```
```   434   then have "\<zero> \<otimes> x \<oplus> \<zero> \<otimes> x = (\<zero> \<oplus> \<zero>) \<otimes> x"
```
```   435     by (simp add: l_distr del: l_zero r_zero)
```
```   436   also from R have "... = \<zero> \<otimes> x \<oplus> \<zero>" by simp
```
```   437   finally have "\<zero> \<otimes> x \<oplus> \<zero> \<otimes> x = \<zero> \<otimes> x \<oplus> \<zero>" .
```
```   438   with R show ?thesis by (simp del: r_zero)
```
```   439 qed
```
```   440
```
```   441 lemma (in ring) r_null [simp]:
```
```   442   "x \<in> carrier R ==> x \<otimes> \<zero> = \<zero>"
```
```   443 proof -
```
```   444   assume R: "x \<in> carrier R"
```
```   445   then have "x \<otimes> \<zero> \<oplus> x \<otimes> \<zero> = x \<otimes> (\<zero> \<oplus> \<zero>)"
```
```   446     by (simp add: r_distr del: l_zero r_zero)
```
```   447   also from R have "... = x \<otimes> \<zero> \<oplus> \<zero>" by simp
```
```   448   finally have "x \<otimes> \<zero> \<oplus> x \<otimes> \<zero> = x \<otimes> \<zero> \<oplus> \<zero>" .
```
```   449   with R show ?thesis by (simp del: r_zero)
```
```   450 qed
```
```   451
```
```   452 lemma (in ring) l_minus:
```
```   453   "[| x \<in> carrier R; y \<in> carrier R |] ==> \<ominus> x \<otimes> y = \<ominus> (x \<otimes> y)"
```
```   454 proof -
```
```   455   assume R: "x \<in> carrier R" "y \<in> carrier R"
```
```   456   then have "(\<ominus> x) \<otimes> y \<oplus> x \<otimes> y = (\<ominus> x \<oplus> x) \<otimes> y" by (simp add: l_distr)
```
```   457   also from R have "... = \<zero>" by (simp add: l_neg l_null)
```
```   458   finally have "(\<ominus> x) \<otimes> y \<oplus> x \<otimes> y = \<zero>" .
```
```   459   with R have "(\<ominus> x) \<otimes> y \<oplus> x \<otimes> y \<oplus> \<ominus> (x \<otimes> y) = \<zero> \<oplus> \<ominus> (x \<otimes> y)" by simp
```
```   460   with R show ?thesis by (simp add: a_assoc r_neg)
```
```   461 qed
```
```   462
```
```   463 lemma (in ring) r_minus:
```
```   464   "[| x \<in> carrier R; y \<in> carrier R |] ==> x \<otimes> \<ominus> y = \<ominus> (x \<otimes> y)"
```
```   465 proof -
```
```   466   assume R: "x \<in> carrier R" "y \<in> carrier R"
```
```   467   then have "x \<otimes> (\<ominus> y) \<oplus> x \<otimes> y = x \<otimes> (\<ominus> y \<oplus> y)" by (simp add: r_distr)
```
```   468   also from R have "... = \<zero>" by (simp add: l_neg r_null)
```
```   469   finally have "x \<otimes> (\<ominus> y) \<oplus> x \<otimes> y = \<zero>" .
```
```   470   with R have "x \<otimes> (\<ominus> y) \<oplus> x \<otimes> y \<oplus> \<ominus> (x \<otimes> y) = \<zero> \<oplus> \<ominus> (x \<otimes> y)" by simp
```
```   471   with R show ?thesis by (simp add: a_assoc r_neg )
```
```   472 qed
```
```   473
```
```   474 lemma (in abelian_group) minus_eq:
```
```   475   "[| x \<in> carrier G; y \<in> carrier G |] ==> x \<ominus> y = x \<oplus> \<ominus> y"
```
```   476   by (simp only: a_minus_def)
```
```   477
```
```   478 text {* Setup algebra method:
```
```   479   compute distributive normal form in locale contexts *}
```
```   480
```
```   481 use "ringsimp.ML"
```
```   482
```
```   483 setup Algebra.setup
```
```   484
```
```   485 lemmas (in ring) ring_simprules
```
```   486   [algebra ring "zero R" "add R" "a_inv R" "a_minus R" "one R" "mult R"] =
```
```   487   a_closed zero_closed a_inv_closed minus_closed m_closed one_closed
```
```   488   a_assoc l_zero l_neg a_comm m_assoc l_one l_distr minus_eq
```
```   489   r_zero r_neg r_neg2 r_neg1 minus_add minus_minus minus_zero
```
```   490   a_lcomm r_distr l_null r_null l_minus r_minus
```
```   491
```
```   492 lemmas (in cring)
```
```   493   [algebra del: ring "zero R" "add R" "a_inv R" "a_minus R" "one R" "mult R"] =
```
```   494   _
```
```   495
```
```   496 lemmas (in cring) cring_simprules
```
```   497   [algebra add: cring "zero R" "add R" "a_inv R" "a_minus R" "one R" "mult R"] =
```
```   498   a_closed zero_closed a_inv_closed minus_closed m_closed one_closed
```
```   499   a_assoc l_zero l_neg a_comm m_assoc l_one l_distr m_comm minus_eq
```
```   500   r_zero r_neg r_neg2 r_neg1 minus_add minus_minus minus_zero
```
```   501   a_lcomm m_lcomm r_distr l_null r_null l_minus r_minus
```
```   502
```
```   503
```
```   504 lemma (in cring) nat_pow_zero:
```
```   505   "(n::nat) ~= 0 ==> \<zero> (^) n = \<zero>"
```
```   506   by (induct n) simp_all
```
```   507
```
```   508 lemma (in ring) one_zeroD:
```
```   509   assumes onezero: "\<one> = \<zero>"
```
```   510   shows "carrier R = {\<zero>}"
```
```   511 proof (rule, rule)
```
```   512   fix x
```
```   513   assume xcarr: "x \<in> carrier R"
```
```   514   from xcarr
```
```   515       have "x = x \<otimes> \<one>" by simp
```
```   516   from this and onezero
```
```   517       have "x = x \<otimes> \<zero>" by simp
```
```   518   from this and xcarr
```
```   519       have "x = \<zero>" by simp
```
```   520   thus "x \<in> {\<zero>}" by fast
```
```   521 qed fast
```
```   522
```
```   523 lemma (in ring) one_zeroI:
```
```   524   assumes carrzero: "carrier R = {\<zero>}"
```
```   525   shows "\<one> = \<zero>"
```
```   526 proof -
```
```   527   from one_closed and carrzero
```
```   528       show "\<one> = \<zero>" by simp
```
```   529 qed
```
```   530
```
```   531 lemma (in ring) one_zero:
```
```   532   shows "(carrier R = {\<zero>}) = (\<one> = \<zero>)"
```
```   533   by (rule, erule one_zeroI, erule one_zeroD)
```
```   534
```
```   535 lemma (in ring) one_not_zero:
```
```   536   shows "(carrier R \<noteq> {\<zero>}) = (\<one> \<noteq> \<zero>)"
```
```   537   by (simp add: one_zero)
```
```   538
```
```   539 text {* Two examples for use of method algebra *}
```
```   540
```
```   541 lemma
```
```   542   includes ring R + cring S
```
```   543   shows "[| a \<in> carrier R; b \<in> carrier R; c \<in> carrier S; d \<in> carrier S |] ==>
```
```   544   a \<oplus> \<ominus> (a \<oplus> \<ominus> b) = b & c \<otimes>\<^bsub>S\<^esub> d = d \<otimes>\<^bsub>S\<^esub> c"
```
```   545   by algebra
```
```   546
```
```   547 lemma
```
```   548   includes cring
```
```   549   shows "[| a \<in> carrier R; b \<in> carrier R |] ==> a \<ominus> (a \<ominus> b) = b"
```
```   550   by algebra
```
```   551
```
```   552
```
```   553 subsubsection {* Sums over Finite Sets *}
```
```   554
```
```   555 lemma (in cring) finsum_ldistr:
```
```   556   "[| finite A; a \<in> carrier R; f \<in> A -> carrier R |] ==>
```
```   557    finsum R f A \<otimes> a = finsum R (%i. f i \<otimes> a) A"
```
```   558 proof (induct set: finite)
```
```   559   case empty then show ?case by simp
```
```   560 next
```
```   561   case (insert x F) then show ?case by (simp add: Pi_def l_distr)
```
```   562 qed
```
```   563
```
```   564 lemma (in cring) finsum_rdistr:
```
```   565   "[| finite A; a \<in> carrier R; f \<in> A -> carrier R |] ==>
```
```   566    a \<otimes> finsum R f A = finsum R (%i. a \<otimes> f i) A"
```
```   567 proof (induct set: finite)
```
```   568   case empty then show ?case by simp
```
```   569 next
```
```   570   case (insert x F) then show ?case by (simp add: Pi_def r_distr)
```
```   571 qed
```
```   572
```
```   573
```
```   574 subsection {* Integral Domains *}
```
```   575
```
```   576 lemma (in "domain") zero_not_one [simp]:
```
```   577   "\<zero> ~= \<one>"
```
```   578   by (rule not_sym) simp
```
```   579
```
```   580 lemma (in "domain") integral_iff: (* not by default a simp rule! *)
```
```   581   "[| a \<in> carrier R; b \<in> carrier R |] ==> (a \<otimes> b = \<zero>) = (a = \<zero> | b = \<zero>)"
```
```   582 proof
```
```   583   assume "a \<in> carrier R" "b \<in> carrier R" "a \<otimes> b = \<zero>"
```
```   584   then show "a = \<zero> | b = \<zero>" by (simp add: integral)
```
```   585 next
```
```   586   assume "a \<in> carrier R" "b \<in> carrier R" "a = \<zero> | b = \<zero>"
```
```   587   then show "a \<otimes> b = \<zero>" by auto
```
```   588 qed
```
```   589
```
```   590 lemma (in "domain") m_lcancel:
```
```   591   assumes prem: "a ~= \<zero>"
```
```   592     and R: "a \<in> carrier R" "b \<in> carrier R" "c \<in> carrier R"
```
```   593   shows "(a \<otimes> b = a \<otimes> c) = (b = c)"
```
```   594 proof
```
```   595   assume eq: "a \<otimes> b = a \<otimes> c"
```
```   596   with R have "a \<otimes> (b \<ominus> c) = \<zero>" by algebra
```
```   597   with R have "a = \<zero> | (b \<ominus> c) = \<zero>" by (simp add: integral_iff)
```
```   598   with prem and R have "b \<ominus> c = \<zero>" by auto
```
```   599   with R have "b = b \<ominus> (b \<ominus> c)" by algebra
```
```   600   also from R have "b \<ominus> (b \<ominus> c) = c" by algebra
```
```   601   finally show "b = c" .
```
```   602 next
```
```   603   assume "b = c" then show "a \<otimes> b = a \<otimes> c" by simp
```
```   604 qed
```
```   605
```
```   606 lemma (in "domain") m_rcancel:
```
```   607   assumes prem: "a ~= \<zero>"
```
```   608     and R: "a \<in> carrier R" "b \<in> carrier R" "c \<in> carrier R"
```
```   609   shows conc: "(b \<otimes> a = c \<otimes> a) = (b = c)"
```
```   610 proof -
```
```   611   from prem and R have "(a \<otimes> b = a \<otimes> c) = (b = c)" by (rule m_lcancel)
```
```   612   with R show ?thesis by algebra
```
```   613 qed
```
```   614
```
```   615
```
```   616 subsection {* Fields *}
```
```   617
```
```   618 text {* Field would not need to be derived from domain, the properties
```
```   619   for domain follow from the assumptions of field *}
```
```   620 lemma (in cring) cring_fieldI:
```
```   621   assumes field_Units: "Units R = carrier R - {\<zero>}"
```
```   622   shows "field R"
```
```   623 proof unfold_locales
```
```   624   from field_Units
```
```   625   have a: "\<zero> \<notin> Units R" by fast
```
```   626   have "\<one> \<in> Units R" by fast
```
```   627   from this and a
```
```   628   show "\<one> \<noteq> \<zero>" by force
```
```   629 next
```
```   630   fix a b
```
```   631   assume acarr: "a \<in> carrier R"
```
```   632     and bcarr: "b \<in> carrier R"
```
```   633     and ab: "a \<otimes> b = \<zero>"
```
```   634   show "a = \<zero> \<or> b = \<zero>"
```
```   635   proof (cases "a = \<zero>", simp)
```
```   636     assume "a \<noteq> \<zero>"
```
```   637     from this and field_Units and acarr
```
```   638     have aUnit: "a \<in> Units R" by fast
```
```   639     from bcarr
```
```   640     have "b = \<one> \<otimes> b" by algebra
```
```   641     also from aUnit acarr
```
```   642     have "... = (inv a \<otimes> a) \<otimes> b" by (simp add: Units_l_inv)
```
```   643     also from acarr bcarr aUnit[THEN Units_inv_closed]
```
```   644     have "... = (inv a) \<otimes> (a \<otimes> b)" by algebra
```
```   645     also from ab and acarr bcarr aUnit
```
```   646     have "... = (inv a) \<otimes> \<zero>" by simp
```
```   647     also from aUnit[THEN Units_inv_closed]
```
```   648     have "... = \<zero>" by algebra
```
```   649     finally
```
```   650     have "b = \<zero>" .
```
```   651     thus "a = \<zero> \<or> b = \<zero>" by simp
```
```   652   qed
```
```   653 qed (rule field_Units)
```
```   654
```
```   655 text {* Another variant to show that something is a field *}
```
```   656 lemma (in cring) cring_fieldI2:
```
```   657   assumes notzero: "\<zero> \<noteq> \<one>"
```
```   658   and invex: "\<And>a. \<lbrakk>a \<in> carrier R; a \<noteq> \<zero>\<rbrakk> \<Longrightarrow> \<exists>b\<in>carrier R. a \<otimes> b = \<one>"
```
```   659   shows "field R"
```
```   660   apply (rule cring_fieldI, simp add: Units_def)
```
```   661   apply (rule, clarsimp)
```
```   662   apply (simp add: notzero)
```
```   663 proof (clarsimp)
```
```   664   fix x
```
```   665   assume xcarr: "x \<in> carrier R"
```
```   666     and "x \<noteq> \<zero>"
```
```   667   from this
```
```   668   have "\<exists>y\<in>carrier R. x \<otimes> y = \<one>" by (rule invex)
```
```   669   from this
```
```   670   obtain y
```
```   671     where ycarr: "y \<in> carrier R"
```
```   672     and xy: "x \<otimes> y = \<one>"
```
```   673     by fast
```
```   674   from xy xcarr ycarr have "y \<otimes> x = \<one>" by (simp add: m_comm)
```
```   675   from ycarr and this and xy
```
```   676   show "\<exists>y\<in>carrier R. y \<otimes> x = \<one> \<and> x \<otimes> y = \<one>" by fast
```
```   677 qed
```
```   678
```
```   679
```
```   680 subsection {* Morphisms *}
```
```   681
```
```   682 constdefs (structure R S)
```
```   683   ring_hom :: "[('a, 'm) ring_scheme, ('b, 'n) ring_scheme] => ('a => 'b) set"
```
```   684   "ring_hom R S == {h. h \<in> carrier R -> carrier S &
```
```   685       (ALL x y. x \<in> carrier R & y \<in> carrier R -->
```
```   686         h (x \<otimes> y) = h x \<otimes>\<^bsub>S\<^esub> h y & h (x \<oplus> y) = h x \<oplus>\<^bsub>S\<^esub> h y) &
```
```   687       h \<one> = \<one>\<^bsub>S\<^esub>}"
```
```   688
```
```   689 lemma ring_hom_memI:
```
```   690   fixes R (structure) and S (structure)
```
```   691   assumes hom_closed: "!!x. x \<in> carrier R ==> h x \<in> carrier S"
```
```   692     and hom_mult: "!!x y. [| x \<in> carrier R; y \<in> carrier R |] ==>
```
```   693       h (x \<otimes> y) = h x \<otimes>\<^bsub>S\<^esub> h y"
```
```   694     and hom_add: "!!x y. [| x \<in> carrier R; y \<in> carrier R |] ==>
```
```   695       h (x \<oplus> y) = h x \<oplus>\<^bsub>S\<^esub> h y"
```
```   696     and hom_one: "h \<one> = \<one>\<^bsub>S\<^esub>"
```
```   697   shows "h \<in> ring_hom R S"
```
```   698   by (auto simp add: ring_hom_def prems Pi_def)
```
```   699
```
```   700 lemma ring_hom_closed:
```
```   701   "[| h \<in> ring_hom R S; x \<in> carrier R |] ==> h x \<in> carrier S"
```
```   702   by (auto simp add: ring_hom_def funcset_mem)
```
```   703
```
```   704 lemma ring_hom_mult:
```
```   705   fixes R (structure) and S (structure)
```
```   706   shows
```
```   707     "[| h \<in> ring_hom R S; x \<in> carrier R; y \<in> carrier R |] ==>
```
```   708     h (x \<otimes> y) = h x \<otimes>\<^bsub>S\<^esub> h y"
```
```   709     by (simp add: ring_hom_def)
```
```   710
```
```   711 lemma ring_hom_add:
```
```   712   fixes R (structure) and S (structure)
```
```   713   shows
```
```   714     "[| h \<in> ring_hom R S; x \<in> carrier R; y \<in> carrier R |] ==>
```
```   715     h (x \<oplus> y) = h x \<oplus>\<^bsub>S\<^esub> h y"
```
```   716     by (simp add: ring_hom_def)
```
```   717
```
```   718 lemma ring_hom_one:
```
```   719   fixes R (structure) and S (structure)
```
```   720   shows "h \<in> ring_hom R S ==> h \<one> = \<one>\<^bsub>S\<^esub>"
```
```   721   by (simp add: ring_hom_def)
```
```   722
```
```   723 locale ring_hom_cring = cring R + cring S +
```
```   724   fixes h
```
```   725   assumes homh [simp, intro]: "h \<in> ring_hom R S"
```
```   726   notes hom_closed [simp, intro] = ring_hom_closed [OF homh]
```
```   727     and hom_mult [simp] = ring_hom_mult [OF homh]
```
```   728     and hom_add [simp] = ring_hom_add [OF homh]
```
```   729     and hom_one [simp] = ring_hom_one [OF homh]
```
```   730
```
```   731 lemma (in ring_hom_cring) hom_zero [simp]:
```
```   732   "h \<zero> = \<zero>\<^bsub>S\<^esub>"
```
```   733 proof -
```
```   734   have "h \<zero> \<oplus>\<^bsub>S\<^esub> h \<zero> = h \<zero> \<oplus>\<^bsub>S\<^esub> \<zero>\<^bsub>S\<^esub>"
```
```   735     by (simp add: hom_add [symmetric] del: hom_add)
```
```   736   then show ?thesis by (simp del: S.r_zero)
```
```   737 qed
```
```   738
```
```   739 lemma (in ring_hom_cring) hom_a_inv [simp]:
```
```   740   "x \<in> carrier R ==> h (\<ominus> x) = \<ominus>\<^bsub>S\<^esub> h x"
```
```   741 proof -
```
```   742   assume R: "x \<in> carrier R"
```
```   743   then have "h x \<oplus>\<^bsub>S\<^esub> h (\<ominus> x) = h x \<oplus>\<^bsub>S\<^esub> (\<ominus>\<^bsub>S\<^esub> h x)"
```
```   744     by (simp add: hom_add [symmetric] R.r_neg S.r_neg del: hom_add)
```
```   745   with R show ?thesis by simp
```
```   746 qed
```
```   747
```
```   748 lemma (in ring_hom_cring) hom_finsum [simp]:
```
```   749   "[| finite A; f \<in> A -> carrier R |] ==>
```
```   750   h (finsum R f A) = finsum S (h o f) A"
```
```   751 proof (induct set: finite)
```
```   752   case empty then show ?case by simp
```
```   753 next
```
```   754   case insert then show ?case by (simp add: Pi_def)
```
```   755 qed
```
```   756
```
```   757 lemma (in ring_hom_cring) hom_finprod:
```
```   758   "[| finite A; f \<in> A -> carrier R |] ==>
```
```   759   h (finprod R f A) = finprod S (h o f) A"
```
```   760 proof (induct set: finite)
```
```   761   case empty then show ?case by simp
```
```   762 next
```
```   763   case insert then show ?case by (simp add: Pi_def)
```
```   764 qed
```
```   765
```
```   766 declare ring_hom_cring.hom_finprod [simp]
```
```   767
```
```   768 lemma id_ring_hom [simp]:
```
```   769   "id \<in> ring_hom R R"
```
```   770   by (auto intro!: ring_hom_memI)
```
```   771
```
```   772 end
```