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