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