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