src/HOL/Algebra/CRing.thy
author ballarin
Tue Apr 13 09:42:40 2004 +0200 (2004-04-13)
changeset 14551 2cb6ff394bfb
parent 14399 dc677b35e54f
child 14577 dbb95b825244
permissions -rw-r--r--
Various changes to HOL-Algebra;
Locale instantiation.
ballarin@13835
     1
(*
ballarin@13835
     2
  Title:     The algebraic hierarchy of rings
ballarin@13835
     3
  Id:        $Id$
ballarin@13835
     4
  Author:    Clemens Ballarin, started 9 December 1996
ballarin@13835
     5
  Copyright: Clemens Ballarin
ballarin@13835
     6
*)
ballarin@13835
     7
ballarin@13936
     8
theory CRing = FiniteProduct
ballarin@13854
     9
files ("ringsimp.ML"):
ballarin@13835
    10
ballarin@13936
    11
section {* Abelian Groups *}
ballarin@13936
    12
ballarin@13936
    13
record 'a ring = "'a monoid" +
ballarin@13936
    14
  zero :: 'a ("\<zero>\<index>")
ballarin@13936
    15
  add :: "['a, 'a] => 'a" (infixl "\<oplus>\<index>" 65)
ballarin@13936
    16
ballarin@13936
    17
text {* Derived operations. *}
ballarin@13936
    18
ballarin@13936
    19
constdefs
ballarin@13936
    20
  a_inv :: "[('a, 'm) ring_scheme, 'a ] => 'a" ("\<ominus>\<index> _" [81] 80)
ballarin@13936
    21
  "a_inv R == m_inv (| carrier = carrier R, mult = add R, one = zero R |)"
ballarin@13936
    22
ballarin@13936
    23
  minus :: "[('a, 'm) ring_scheme, 'a, 'a] => 'a" (infixl "\<ominus>\<index>" 65)
ballarin@13936
    24
  "[| x \<in> carrier R; y \<in> carrier R |] ==> minus R x y == add R x (a_inv R y)"
ballarin@13936
    25
ballarin@13936
    26
locale abelian_monoid = struct G +
ballarin@13936
    27
  assumes a_comm_monoid: "comm_monoid (| carrier = carrier G,
ballarin@13936
    28
      mult = add G, one = zero G |)"
ballarin@13936
    29
ballarin@13936
    30
text {*
ballarin@13936
    31
  The following definition is redundant but simple to use.
ballarin@13936
    32
*}
ballarin@13936
    33
ballarin@13936
    34
locale abelian_group = abelian_monoid +
ballarin@13936
    35
  assumes a_comm_group: "comm_group (| carrier = carrier G,
ballarin@13936
    36
      mult = add G, one = zero G |)"
ballarin@13936
    37
ballarin@13936
    38
subsection {* Basic Properties *}
ballarin@13936
    39
ballarin@13936
    40
lemma abelian_monoidI:
ballarin@13936
    41
  assumes a_closed:
ballarin@13936
    42
      "!!x y. [| x \<in> carrier R; y \<in> carrier R |] ==> add R x y \<in> carrier R"
ballarin@13936
    43
    and zero_closed: "zero R \<in> carrier R"
ballarin@13936
    44
    and a_assoc:
ballarin@13936
    45
      "!!x y z. [| x \<in> carrier R; y \<in> carrier R; z \<in> carrier R |] ==>
ballarin@13936
    46
      add R (add R x y) z = add R x (add R y z)"
ballarin@13936
    47
    and l_zero: "!!x. x \<in> carrier R ==> add R (zero R) x = x"
ballarin@13936
    48
    and a_comm:
ballarin@13936
    49
      "!!x y. [| x \<in> carrier R; y \<in> carrier R |] ==> add R x y = add R y x"
ballarin@13936
    50
  shows "abelian_monoid R"
ballarin@13936
    51
  by (auto intro!: abelian_monoid.intro comm_monoidI intro: prems)
ballarin@13936
    52
ballarin@13936
    53
lemma abelian_groupI:
ballarin@13936
    54
  assumes a_closed:
ballarin@13936
    55
      "!!x y. [| x \<in> carrier R; y \<in> carrier R |] ==> add R x y \<in> carrier R"
ballarin@13936
    56
    and zero_closed: "zero R \<in> carrier R"
ballarin@13936
    57
    and a_assoc:
ballarin@13936
    58
      "!!x y z. [| x \<in> carrier R; y \<in> carrier R; z \<in> carrier R |] ==>
ballarin@13936
    59
      add R (add R x y) z = add R x (add R y z)"
ballarin@13936
    60
    and a_comm:
ballarin@13936
    61
      "!!x y. [| x \<in> carrier R; y \<in> carrier R |] ==> add R x y = add R y x"
ballarin@13936
    62
    and l_zero: "!!x. x \<in> carrier R ==> add R (zero R) x = x"
ballarin@13936
    63
    and l_inv_ex: "!!x. x \<in> carrier R ==> EX y : carrier R. add R y x = zero R"
ballarin@13936
    64
  shows "abelian_group R"
ballarin@13936
    65
  by (auto intro!: abelian_group.intro abelian_monoidI
ballarin@13936
    66
      abelian_group_axioms.intro comm_monoidI comm_groupI
ballarin@13936
    67
    intro: prems)
ballarin@13936
    68
ballarin@13936
    69
(* TODO: The following thms are probably unnecessary. *)
ballarin@13936
    70
ballarin@13936
    71
lemma (in abelian_monoid) a_magma:
ballarin@13936
    72
  "magma (| carrier = carrier G, mult = add G, one = zero G |)"
ballarin@13936
    73
  by (rule comm_monoid.axioms) (rule a_comm_monoid)
ballarin@13936
    74
ballarin@13936
    75
lemma (in abelian_monoid) a_semigroup:
ballarin@13936
    76
  "semigroup (| carrier = carrier G, mult = add G, one = zero G |)"
ballarin@13936
    77
  by (unfold semigroup_def) (fast intro: comm_monoid.axioms a_comm_monoid)
ballarin@13936
    78
ballarin@13936
    79
lemma (in abelian_monoid) a_monoid:
ballarin@13936
    80
  "monoid (| carrier = carrier G, mult = add G, one = zero G |)"
ballarin@13936
    81
  by (unfold monoid_def) (fast intro: a_comm_monoid comm_monoid.axioms)
ballarin@13936
    82
ballarin@13936
    83
lemma (in abelian_group) a_group:
ballarin@13936
    84
  "group (| carrier = carrier G, mult = add G, one = zero G |)"
ballarin@13936
    85
  by (unfold group_def semigroup_def)
ballarin@13936
    86
    (fast intro: comm_group.axioms a_comm_group)
ballarin@13936
    87
ballarin@13936
    88
lemma (in abelian_monoid) a_comm_semigroup:
ballarin@13936
    89
  "comm_semigroup (| carrier = carrier G, mult = add G, one = zero G |)"
ballarin@13936
    90
  by (unfold comm_semigroup_def semigroup_def)
ballarin@13936
    91
    (fast intro: comm_monoid.axioms a_comm_monoid)
ballarin@13936
    92
ballarin@14286
    93
lemmas monoid_record_simps = partial_object.simps semigroup.simps monoid.simps
ballarin@13936
    94
ballarin@13936
    95
lemma (in abelian_monoid) a_closed [intro, simp]:
ballarin@13936
    96
  "[| x \<in> carrier G; y \<in> carrier G |] ==> x \<oplus> y \<in> carrier G"
ballarin@13936
    97
  by (rule magma.m_closed [OF a_magma, simplified monoid_record_simps]) 
ballarin@13936
    98
ballarin@13936
    99
lemma (in abelian_monoid) zero_closed [intro, simp]:
ballarin@13936
   100
  "\<zero> \<in> carrier G"
ballarin@13936
   101
  by (rule monoid.one_closed [OF a_monoid, simplified monoid_record_simps])
ballarin@13936
   102
ballarin@13936
   103
lemma (in abelian_group) a_inv_closed [intro, simp]:
ballarin@13936
   104
  "x \<in> carrier G ==> \<ominus> x \<in> carrier G"
ballarin@13936
   105
  by (simp add: a_inv_def
ballarin@13936
   106
    group.inv_closed [OF a_group, simplified monoid_record_simps])
ballarin@13936
   107
ballarin@13936
   108
lemma (in abelian_group) minus_closed [intro, simp]:
ballarin@13936
   109
  "[| x \<in> carrier G; y \<in> carrier G |] ==> x \<ominus> y \<in> carrier G"
ballarin@13936
   110
  by (simp add: minus_def)
ballarin@13936
   111
ballarin@13936
   112
lemma (in abelian_group) a_l_cancel [simp]:
ballarin@13936
   113
  "[| x \<in> carrier G; y \<in> carrier G; z \<in> carrier G |] ==>
ballarin@13936
   114
   (x \<oplus> y = x \<oplus> z) = (y = z)"
ballarin@13936
   115
  by (rule group.l_cancel [OF a_group, simplified monoid_record_simps])
ballarin@13936
   116
ballarin@13936
   117
lemma (in abelian_group) a_r_cancel [simp]:
ballarin@13936
   118
  "[| x \<in> carrier G; y \<in> carrier G; z \<in> carrier G |] ==>
ballarin@13936
   119
   (y \<oplus> x = z \<oplus> x) = (y = z)"
ballarin@13936
   120
  by (rule group.r_cancel [OF a_group, simplified monoid_record_simps])
ballarin@13936
   121
ballarin@13936
   122
lemma (in abelian_monoid) a_assoc:
ballarin@13936
   123
  "[| x \<in> carrier G; y \<in> carrier G; z \<in> carrier G |] ==>
ballarin@13936
   124
  (x \<oplus> y) \<oplus> z = x \<oplus> (y \<oplus> z)"
ballarin@13936
   125
  by (rule semigroup.m_assoc [OF a_semigroup, simplified monoid_record_simps])
ballarin@13936
   126
ballarin@13936
   127
lemma (in abelian_monoid) l_zero [simp]:
ballarin@13936
   128
  "x \<in> carrier G ==> \<zero> \<oplus> x = x"
ballarin@13936
   129
  by (rule monoid.l_one [OF a_monoid, simplified monoid_record_simps])
ballarin@13936
   130
ballarin@13936
   131
lemma (in abelian_group) l_neg:
ballarin@13936
   132
  "x \<in> carrier G ==> \<ominus> x \<oplus> x = \<zero>"
ballarin@13936
   133
  by (simp add: a_inv_def
ballarin@13936
   134
    group.l_inv [OF a_group, simplified monoid_record_simps])
ballarin@13936
   135
ballarin@13936
   136
lemma (in abelian_monoid) a_comm:
ballarin@13936
   137
  "[| x \<in> carrier G; y \<in> carrier G |] ==> x \<oplus> y = y \<oplus> x"
ballarin@13936
   138
  by (rule comm_semigroup.m_comm [OF a_comm_semigroup,
ballarin@13936
   139
    simplified monoid_record_simps])
ballarin@13936
   140
ballarin@13936
   141
lemma (in abelian_monoid) a_lcomm:
ballarin@13936
   142
  "[| x \<in> carrier G; y \<in> carrier G; z \<in> carrier G |] ==>
ballarin@13936
   143
   x \<oplus> (y \<oplus> z) = y \<oplus> (x \<oplus> z)"
ballarin@13936
   144
  by (rule comm_semigroup.m_lcomm [OF a_comm_semigroup,
ballarin@13936
   145
    simplified monoid_record_simps])
ballarin@13936
   146
ballarin@13936
   147
lemma (in abelian_monoid) r_zero [simp]:
ballarin@13936
   148
  "x \<in> carrier G ==> x \<oplus> \<zero> = x"
ballarin@13936
   149
  using monoid.r_one [OF a_monoid]
ballarin@13936
   150
  by simp
ballarin@13936
   151
ballarin@13936
   152
lemma (in abelian_group) r_neg:
ballarin@13936
   153
  "x \<in> carrier G ==> x \<oplus> (\<ominus> x) = \<zero>"
ballarin@13936
   154
  using group.r_inv [OF a_group]
ballarin@13936
   155
  by (simp add: a_inv_def)
ballarin@13936
   156
ballarin@13936
   157
lemma (in abelian_group) minus_zero [simp]:
ballarin@13936
   158
  "\<ominus> \<zero> = \<zero>"
ballarin@13936
   159
  by (simp add: a_inv_def
ballarin@13936
   160
    group.inv_one [OF a_group, simplified monoid_record_simps])
ballarin@13936
   161
ballarin@13936
   162
lemma (in abelian_group) minus_minus [simp]:
ballarin@13936
   163
  "x \<in> carrier G ==> \<ominus> (\<ominus> x) = x"
ballarin@13936
   164
  using group.inv_inv [OF a_group, simplified monoid_record_simps]
ballarin@13936
   165
  by (simp add: a_inv_def)
ballarin@13936
   166
ballarin@13936
   167
lemma (in abelian_group) a_inv_inj:
ballarin@13936
   168
  "inj_on (a_inv G) (carrier G)"
ballarin@13936
   169
  using group.inv_inj [OF a_group, simplified monoid_record_simps]
ballarin@13936
   170
  by (simp add: a_inv_def)
ballarin@13936
   171
ballarin@13936
   172
lemma (in abelian_group) minus_add:
ballarin@13936
   173
  "[| x \<in> carrier G; y \<in> carrier G |] ==> \<ominus> (x \<oplus> y) = \<ominus> x \<oplus> \<ominus> y"
ballarin@13936
   174
  using comm_group.inv_mult [OF a_comm_group]
ballarin@13936
   175
  by (simp add: a_inv_def)
ballarin@13936
   176
ballarin@13936
   177
lemmas (in abelian_monoid) a_ac = a_assoc a_comm a_lcomm
ballarin@13936
   178
ballarin@13936
   179
subsection {* Sums over Finite Sets *}
ballarin@13936
   180
ballarin@13936
   181
text {*
ballarin@13936
   182
  This definition makes it easy to lift lemmas from @{term finprod}.
ballarin@13936
   183
*}
ballarin@13936
   184
ballarin@13936
   185
constdefs
ballarin@13936
   186
  finsum :: "[('b, 'm) ring_scheme, 'a => 'b, 'a set] => 'b"
ballarin@13936
   187
  "finsum G f A == finprod (| carrier = carrier G,
ballarin@13936
   188
     mult = add G, one = zero G |) f A"
ballarin@13936
   189
ballarin@13936
   190
(*
ballarin@13936
   191
  lemmas (in abelian_monoid) finsum_empty [simp] =
ballarin@13936
   192
    comm_monoid.finprod_empty [OF a_comm_monoid, simplified]
ballarin@13936
   193
  is dangeous, because attributes (like simplified) are applied upon opening
ballarin@13936
   194
  the locale, simplified refers to the simpset at that time!!!
ballarin@13936
   195
ballarin@13936
   196
  lemmas (in abelian_monoid) finsum_empty [simp] =
ballarin@13936
   197
    abelian_monoid.finprod_empty [OF a_abelian_monoid, folded finsum_def,
ballarin@13936
   198
      simplified monoid_record_simps]
ballarin@13936
   199
makes the locale slow, because proofs are repeated for every
ballarin@13936
   200
"lemma (in abelian_monoid)" command.
ballarin@13936
   201
When lemma is used time in UnivPoly.thy from beginning to UP_cring goes down
ballarin@13936
   202
from 110 secs to 60 secs.
ballarin@13936
   203
*)
ballarin@13936
   204
ballarin@13936
   205
lemma (in abelian_monoid) finsum_empty [simp]:
ballarin@13936
   206
  "finsum G f {} = \<zero>"
ballarin@13936
   207
  by (rule comm_monoid.finprod_empty [OF a_comm_monoid,
ballarin@13936
   208
    folded finsum_def, simplified monoid_record_simps])
ballarin@13936
   209
ballarin@13936
   210
lemma (in abelian_monoid) finsum_insert [simp]:
ballarin@13936
   211
  "[| finite F; a \<notin> F; f \<in> F -> carrier G; f a \<in> carrier G |]
ballarin@13936
   212
  ==> finsum G f (insert a F) = f a \<oplus> finsum G f F"
ballarin@13936
   213
  by (rule comm_monoid.finprod_insert [OF a_comm_monoid,
ballarin@13936
   214
    folded finsum_def, simplified monoid_record_simps])
ballarin@13936
   215
ballarin@13936
   216
lemma (in abelian_monoid) finsum_zero [simp]:
ballarin@13936
   217
  "finite A ==> finsum G (%i. \<zero>) A = \<zero>"
ballarin@13936
   218
  by (rule comm_monoid.finprod_one [OF a_comm_monoid, folded finsum_def,
ballarin@13936
   219
    simplified monoid_record_simps])
ballarin@13936
   220
ballarin@13936
   221
lemma (in abelian_monoid) finsum_closed [simp]:
ballarin@13936
   222
  fixes A
ballarin@13936
   223
  assumes fin: "finite A" and f: "f \<in> A -> carrier G" 
ballarin@13936
   224
  shows "finsum G f A \<in> carrier G"
ballarin@13936
   225
  by (rule comm_monoid.finprod_closed [OF a_comm_monoid,
ballarin@13936
   226
    folded finsum_def, simplified monoid_record_simps])
ballarin@13936
   227
ballarin@13936
   228
lemma (in abelian_monoid) finsum_Un_Int:
ballarin@13936
   229
  "[| finite A; finite B; g \<in> A -> carrier G; g \<in> B -> carrier G |] ==>
ballarin@13936
   230
     finsum G g (A Un B) \<oplus> finsum G g (A Int B) =
ballarin@13936
   231
     finsum G g A \<oplus> finsum G g B"
ballarin@13936
   232
  by (rule comm_monoid.finprod_Un_Int [OF a_comm_monoid,
ballarin@13936
   233
    folded finsum_def, simplified monoid_record_simps])
ballarin@13936
   234
ballarin@13936
   235
lemma (in abelian_monoid) finsum_Un_disjoint:
ballarin@13936
   236
  "[| finite A; finite B; A Int B = {};
ballarin@13936
   237
      g \<in> A -> carrier G; g \<in> B -> carrier G |]
ballarin@13936
   238
   ==> finsum G g (A Un B) = finsum G g A \<oplus> finsum G g B"
ballarin@13936
   239
  by (rule comm_monoid.finprod_Un_disjoint [OF a_comm_monoid,
ballarin@13936
   240
    folded finsum_def, simplified monoid_record_simps])
ballarin@13936
   241
ballarin@13936
   242
lemma (in abelian_monoid) finsum_addf:
ballarin@13936
   243
  "[| finite A; f \<in> A -> carrier G; g \<in> A -> carrier G |] ==>
ballarin@13936
   244
   finsum G (%x. f x \<oplus> g x) A = (finsum G f A \<oplus> finsum G g A)"
ballarin@13936
   245
  by (rule comm_monoid.finprod_multf [OF a_comm_monoid,
ballarin@13936
   246
    folded finsum_def, simplified monoid_record_simps])
ballarin@13936
   247
ballarin@13936
   248
lemma (in abelian_monoid) finsum_cong':
ballarin@13936
   249
  "[| A = B; g : B -> carrier G;
ballarin@13936
   250
      !!i. i : B ==> f i = g i |] ==> finsum G f A = finsum G g B"
ballarin@13936
   251
  by (rule comm_monoid.finprod_cong' [OF a_comm_monoid,
ballarin@13936
   252
    folded finsum_def, simplified monoid_record_simps]) auto
ballarin@13936
   253
ballarin@13936
   254
lemma (in abelian_monoid) finsum_0 [simp]:
ballarin@13936
   255
  "f : {0::nat} -> carrier G ==> finsum G f {..0} = f 0"
ballarin@13936
   256
  by (rule comm_monoid.finprod_0 [OF a_comm_monoid, folded finsum_def,
ballarin@13936
   257
    simplified monoid_record_simps])
ballarin@13936
   258
ballarin@13936
   259
lemma (in abelian_monoid) finsum_Suc [simp]:
ballarin@13936
   260
  "f : {..Suc n} -> carrier G ==>
ballarin@13936
   261
   finsum G f {..Suc n} = (f (Suc n) \<oplus> finsum G f {..n})"
ballarin@13936
   262
  by (rule comm_monoid.finprod_Suc [OF a_comm_monoid, folded finsum_def,
ballarin@13936
   263
    simplified monoid_record_simps])
ballarin@13936
   264
ballarin@13936
   265
lemma (in abelian_monoid) finsum_Suc2:
ballarin@13936
   266
  "f : {..Suc n} -> carrier G ==>
ballarin@13936
   267
   finsum G f {..Suc n} = (finsum G (%i. f (Suc i)) {..n} \<oplus> f 0)"
ballarin@13936
   268
  by (rule comm_monoid.finprod_Suc2 [OF a_comm_monoid, folded finsum_def,
ballarin@13936
   269
    simplified monoid_record_simps])
ballarin@13936
   270
ballarin@13936
   271
lemma (in abelian_monoid) finsum_add [simp]:
ballarin@13936
   272
  "[| f : {..n} -> carrier G; g : {..n} -> carrier G |] ==>
ballarin@13936
   273
     finsum G (%i. f i \<oplus> g i) {..n::nat} =
ballarin@13936
   274
     finsum G f {..n} \<oplus> finsum G g {..n}"
ballarin@13936
   275
  by (rule comm_monoid.finprod_mult [OF a_comm_monoid, folded finsum_def,
ballarin@13936
   276
    simplified monoid_record_simps])
ballarin@13936
   277
ballarin@13936
   278
lemma (in abelian_monoid) finsum_cong:
ballarin@14399
   279
  "[| A = B; f : B -> carrier G = True;
ballarin@14399
   280
      !!i. i : B ==> f i = g i |] ==> finsum G f A = finsum G g B"
ballarin@13936
   281
  by (rule comm_monoid.finprod_cong [OF a_comm_monoid, folded finsum_def,
ballarin@13936
   282
    simplified monoid_record_simps]) auto
ballarin@13936
   283
ballarin@13936
   284
text {*Usually, if this rule causes a failed congruence proof error,
ballarin@13936
   285
   the reason is that the premise @{text "g \<in> B -> carrier G"} cannot be shown.
ballarin@13936
   286
   Adding @{thm [source] Pi_def} to the simpset is often useful. *}
ballarin@13936
   287
ballarin@13835
   288
section {* The Algebraic Hierarchy of Rings *}
ballarin@13835
   289
ballarin@13835
   290
subsection {* Basic Definitions *}
ballarin@13835
   291
ballarin@14399
   292
locale ring = abelian_group R + monoid R +
ballarin@13936
   293
  assumes l_distr: "[| x \<in> carrier R; y \<in> carrier R; z \<in> carrier R |]
ballarin@13835
   294
      ==> (x \<oplus> y) \<otimes> z = x \<otimes> z \<oplus> y \<otimes> z"
ballarin@14399
   295
    and r_distr: "[| x \<in> carrier R; y \<in> carrier R; z \<in> carrier R |]
ballarin@14399
   296
      ==> z \<otimes> (x \<oplus> y) = z \<otimes> x \<oplus> z \<otimes> y"
ballarin@14399
   297
ballarin@14399
   298
locale cring = ring + comm_monoid R
ballarin@13835
   299
ballarin@13864
   300
locale "domain" = cring +
ballarin@13864
   301
  assumes one_not_zero [simp]: "\<one> ~= \<zero>"
ballarin@13864
   302
    and integral: "[| a \<otimes> b = \<zero>; a \<in> carrier R; b \<in> carrier R |] ==>
ballarin@13864
   303
                  a = \<zero> | b = \<zero>"
ballarin@13864
   304
ballarin@14551
   305
locale field = "domain" +
ballarin@14551
   306
  assumes field_Units: "Units R = carrier R - {\<zero>}"
ballarin@14551
   307
ballarin@13864
   308
subsection {* Basic Facts of Rings *}
ballarin@13835
   309
ballarin@14399
   310
lemma ringI:
ballarin@14399
   311
  includes struct R
ballarin@14399
   312
  assumes abelian_group: "abelian_group R"
ballarin@14399
   313
    and monoid: "monoid R"
ballarin@14399
   314
    and l_distr: "!!x y z. [| x \<in> carrier R; y \<in> carrier R; z \<in> carrier R |]
ballarin@14399
   315
      ==> mult R (add R x y) z = add R (mult R x z) (mult R y z)"
ballarin@14399
   316
    and r_distr: "!!x y z. [| x \<in> carrier R; y \<in> carrier R; z \<in> carrier R |]
ballarin@14399
   317
      ==> z \<otimes> (x \<oplus> y) = z \<otimes> x \<oplus> z \<otimes> y"
ballarin@14399
   318
  shows "ring R"
ballarin@14399
   319
  by (auto intro: ring.intro
ballarin@14399
   320
    abelian_group.axioms monoid.axioms ring_axioms.intro prems)
ballarin@14399
   321
ballarin@14399
   322
lemma (in ring) is_abelian_group:
ballarin@14399
   323
  "abelian_group R"
ballarin@14399
   324
  by (auto intro!: abelian_groupI a_assoc a_comm l_neg)
ballarin@14399
   325
ballarin@14399
   326
lemma (in ring) is_monoid:
ballarin@14399
   327
  "monoid R"
ballarin@14399
   328
  by (auto intro!: monoidI m_assoc)
ballarin@14399
   329
ballarin@13936
   330
lemma cringI:
ballarin@14399
   331
  includes struct R
ballarin@13936
   332
  assumes abelian_group: "abelian_group R"
ballarin@13936
   333
    and comm_monoid: "comm_monoid R"
ballarin@13936
   334
    and l_distr: "!!x y z. [| x \<in> carrier R; y \<in> carrier R; z \<in> carrier R |]
ballarin@13936
   335
      ==> mult R (add R x y) z = add R (mult R x z) (mult R y z)"
ballarin@13936
   336
  shows "cring R"
ballarin@14399
   337
  proof (rule cring.intro)
ballarin@14399
   338
    show "ring_axioms R"
ballarin@14399
   339
    -- {* Right-distributivity follows from left-distributivity and
ballarin@14399
   340
          commutativity. *}
ballarin@14399
   341
    proof (rule ring_axioms.intro)
ballarin@14399
   342
      fix x y z
ballarin@14399
   343
      assume R: "x \<in> carrier R" "y \<in> carrier R" "z \<in> carrier R"
ballarin@14399
   344
      note [simp]= comm_monoid.axioms [OF comm_monoid]
ballarin@14399
   345
        abelian_group.axioms [OF abelian_group]
ballarin@14399
   346
        abelian_monoid.a_closed
ballarin@14399
   347
        magma.m_closed
ballarin@14399
   348
        
ballarin@14399
   349
      from R have "z \<otimes> (x \<oplus> y) = (x \<oplus> y) \<otimes> z"
ballarin@14399
   350
        by (simp add: comm_semigroup.m_comm [OF comm_semigroup.intro])
ballarin@14399
   351
      also from R have "... = x \<otimes> z \<oplus> y \<otimes> z" by (simp add: l_distr)
ballarin@14399
   352
      also from R have "... = z \<otimes> x \<oplus> z \<otimes> y"
ballarin@14399
   353
        by (simp add: comm_semigroup.m_comm [OF comm_semigroup.intro])
ballarin@14399
   354
      finally show "z \<otimes> (x \<oplus> y) = z \<otimes> x \<oplus> z \<otimes> y" .
ballarin@14399
   355
    qed
ballarin@14399
   356
  qed (auto intro: cring.intro
ballarin@14399
   357
      abelian_group.axioms comm_monoid.axioms ring_axioms.intro prems)
ballarin@13854
   358
ballarin@13936
   359
lemma (in cring) is_comm_monoid:
ballarin@13936
   360
  "comm_monoid R"
ballarin@13936
   361
  by (auto intro!: comm_monoidI m_assoc m_comm)
ballarin@13835
   362
ballarin@14551
   363
subsection {* Normaliser for Rings *}
ballarin@13835
   364
ballarin@13936
   365
lemma (in abelian_group) r_neg2:
ballarin@13936
   366
  "[| x \<in> carrier G; y \<in> carrier G |] ==> x \<oplus> (\<ominus> x \<oplus> y) = y"
ballarin@13854
   367
proof -
ballarin@13936
   368
  assume G: "x \<in> carrier G" "y \<in> carrier G"
ballarin@13936
   369
  then have "(x \<oplus> \<ominus> x) \<oplus> y = y"
ballarin@13936
   370
    by (simp only: r_neg l_zero)
ballarin@13936
   371
  with G show ?thesis 
ballarin@13936
   372
    by (simp add: a_ac)
ballarin@13835
   373
qed
ballarin@13835
   374
ballarin@13936
   375
lemma (in abelian_group) r_neg1:
ballarin@13936
   376
  "[| x \<in> carrier G; y \<in> carrier G |] ==> \<ominus> x \<oplus> (x \<oplus> y) = y"
ballarin@13854
   377
proof -
ballarin@13936
   378
  assume G: "x \<in> carrier G" "y \<in> carrier G"
ballarin@13936
   379
  then have "(\<ominus> x \<oplus> x) \<oplus> y = y" 
ballarin@13936
   380
    by (simp only: l_neg l_zero)
ballarin@13854
   381
  with G show ?thesis by (simp add: a_ac)
ballarin@13835
   382
qed
ballarin@13835
   383
ballarin@13854
   384
text {* 
ballarin@13854
   385
  The following proofs are from Jacobson, Basic Algebra I, pp.~88--89
ballarin@13835
   386
*}
ballarin@13835
   387
ballarin@14399
   388
lemma (in ring) l_null [simp]:
ballarin@13854
   389
  "x \<in> carrier R ==> \<zero> \<otimes> x = \<zero>"
ballarin@13854
   390
proof -
ballarin@13854
   391
  assume R: "x \<in> carrier R"
ballarin@13854
   392
  then have "\<zero> \<otimes> x \<oplus> \<zero> \<otimes> x = (\<zero> \<oplus> \<zero>) \<otimes> x"
ballarin@13854
   393
    by (simp add: l_distr del: l_zero r_zero)
ballarin@13854
   394
  also from R have "... = \<zero> \<otimes> x \<oplus> \<zero>" by simp
ballarin@13854
   395
  finally have "\<zero> \<otimes> x \<oplus> \<zero> \<otimes> x = \<zero> \<otimes> x \<oplus> \<zero>" .
ballarin@13854
   396
  with R show ?thesis by (simp del: r_zero)
ballarin@13854
   397
qed
ballarin@13835
   398
ballarin@14399
   399
lemma (in ring) r_null [simp]:
ballarin@13854
   400
  "x \<in> carrier R ==> x \<otimes> \<zero> = \<zero>"
ballarin@13854
   401
proof -
ballarin@13854
   402
  assume R: "x \<in> carrier R"
ballarin@14399
   403
  then have "x \<otimes> \<zero> \<oplus> x \<otimes> \<zero> = x \<otimes> (\<zero> \<oplus> \<zero>)"
ballarin@14399
   404
    by (simp add: r_distr del: l_zero r_zero)
ballarin@14399
   405
  also from R have "... = x \<otimes> \<zero> \<oplus> \<zero>" by simp
ballarin@14399
   406
  finally have "x \<otimes> \<zero> \<oplus> x \<otimes> \<zero> = x \<otimes> \<zero> \<oplus> \<zero>" .
ballarin@14399
   407
  with R show ?thesis by (simp del: r_zero)
ballarin@13854
   408
qed
ballarin@13835
   409
ballarin@14399
   410
lemma (in ring) l_minus:
ballarin@13854
   411
  "[| x \<in> carrier R; y \<in> carrier R |] ==> \<ominus> x \<otimes> y = \<ominus> (x \<otimes> y)"
ballarin@13854
   412
proof -
ballarin@13854
   413
  assume R: "x \<in> carrier R" "y \<in> carrier R"
ballarin@13854
   414
  then have "(\<ominus> x) \<otimes> y \<oplus> x \<otimes> y = (\<ominus> x \<oplus> x) \<otimes> y" by (simp add: l_distr)
ballarin@13854
   415
  also from R have "... = \<zero>" by (simp add: l_neg l_null)
ballarin@13854
   416
  finally have "(\<ominus> x) \<otimes> y \<oplus> x \<otimes> y = \<zero>" .
ballarin@13854
   417
  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@13854
   418
  with R show ?thesis by (simp add: a_assoc r_neg )
ballarin@13835
   419
qed
ballarin@13835
   420
ballarin@14399
   421
lemma (in ring) r_minus:
ballarin@13854
   422
  "[| x \<in> carrier R; y \<in> carrier R |] ==> x \<otimes> \<ominus> y = \<ominus> (x \<otimes> y)"
ballarin@13854
   423
proof -
ballarin@13854
   424
  assume R: "x \<in> carrier R" "y \<in> carrier R"
ballarin@14399
   425
  then have "x \<otimes> (\<ominus> y) \<oplus> x \<otimes> y = x \<otimes> (\<ominus> y \<oplus> y)" by (simp add: r_distr)
ballarin@14399
   426
  also from R have "... = \<zero>" by (simp add: l_neg r_null)
ballarin@14399
   427
  finally have "x \<otimes> (\<ominus> y) \<oplus> x \<otimes> y = \<zero>" .
ballarin@14399
   428
  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@14399
   429
  with R show ?thesis by (simp add: a_assoc r_neg )
ballarin@13835
   430
qed
ballarin@13835
   431
ballarin@14399
   432
lemma (in ring) minus_eq:
ballarin@13936
   433
  "[| x \<in> carrier R; y \<in> carrier R |] ==> x \<ominus> y = x \<oplus> \<ominus> y"
ballarin@13936
   434
  by (simp only: minus_def)
ballarin@13936
   435
ballarin@14399
   436
lemmas (in ring) ring_simprules =
ballarin@14399
   437
  a_closed zero_closed a_inv_closed minus_closed m_closed one_closed
ballarin@14399
   438
  a_assoc l_zero l_neg a_comm m_assoc l_one l_distr minus_eq
ballarin@14399
   439
  r_zero r_neg r_neg2 r_neg1 minus_add minus_minus minus_zero
ballarin@14399
   440
  a_lcomm r_distr l_null r_null l_minus r_minus
ballarin@14399
   441
ballarin@13854
   442
lemmas (in cring) cring_simprules =
ballarin@13854
   443
  a_closed zero_closed a_inv_closed minus_closed m_closed one_closed
ballarin@13936
   444
  a_assoc l_zero l_neg a_comm m_assoc l_one l_distr m_comm minus_eq
ballarin@13854
   445
  r_zero r_neg r_neg2 r_neg1 minus_add minus_minus minus_zero
ballarin@13854
   446
  a_lcomm m_lcomm r_distr l_null r_null l_minus r_minus
ballarin@13854
   447
ballarin@13854
   448
use "ringsimp.ML"
ballarin@13854
   449
ballarin@13854
   450
method_setup algebra =
ballarin@13854
   451
  {* Method.ctxt_args cring_normalise *}
ballarin@13936
   452
  {* computes distributive normal form in locale context cring *}
ballarin@13936
   453
ballarin@13936
   454
lemma (in cring) nat_pow_zero:
ballarin@13936
   455
  "(n::nat) ~= 0 ==> \<zero> (^) n = \<zero>"
ballarin@13936
   456
  by (induct n) simp_all
ballarin@13854
   457
ballarin@13864
   458
text {* Two examples for use of method algebra *}
ballarin@13864
   459
ballarin@13854
   460
lemma
ballarin@14399
   461
  includes ring R + cring S
ballarin@13854
   462
  shows "[| a \<in> carrier R; b \<in> carrier R; c \<in> carrier S; d \<in> carrier S |] ==> 
ballarin@13854
   463
  a \<oplus> \<ominus> (a \<oplus> \<ominus> b) = b & c \<otimes>\<^sub>2 d = d \<otimes>\<^sub>2 c"
ballarin@13854
   464
  by algebra
ballarin@13854
   465
ballarin@13854
   466
lemma
ballarin@13854
   467
  includes cring
ballarin@13854
   468
  shows "[| a \<in> carrier R; b \<in> carrier R |] ==> a \<ominus> (a \<ominus> b) = b"
ballarin@13854
   469
  by algebra
ballarin@13835
   470
ballarin@13864
   471
subsection {* Sums over Finite Sets *}
ballarin@13864
   472
ballarin@13864
   473
lemma (in cring) finsum_ldistr:
ballarin@13864
   474
  "[| finite A; a \<in> carrier R; f \<in> A -> carrier R |] ==>
ballarin@13864
   475
   finsum R f A \<otimes> a = finsum R (%i. f i \<otimes> a) A"
ballarin@13864
   476
proof (induct set: Finites)
ballarin@13864
   477
  case empty then show ?case by simp
ballarin@13864
   478
next
ballarin@13864
   479
  case (insert F x) then show ?case by (simp add: Pi_def l_distr)
ballarin@13864
   480
qed
ballarin@13864
   481
ballarin@13864
   482
lemma (in cring) finsum_rdistr:
ballarin@13864
   483
  "[| finite A; a \<in> carrier R; f \<in> A -> carrier R |] ==>
ballarin@13864
   484
   a \<otimes> finsum R f A = finsum R (%i. a \<otimes> f i) A"
ballarin@13864
   485
proof (induct set: Finites)
ballarin@13864
   486
  case empty then show ?case by simp
ballarin@13864
   487
next
ballarin@13864
   488
  case (insert F x) then show ?case by (simp add: Pi_def r_distr)
ballarin@13864
   489
qed
ballarin@13864
   490
ballarin@13864
   491
subsection {* Facts of Integral Domains *}
ballarin@13864
   492
ballarin@13864
   493
lemma (in "domain") zero_not_one [simp]:
ballarin@13864
   494
  "\<zero> ~= \<one>"
ballarin@13864
   495
  by (rule not_sym) simp
ballarin@13864
   496
ballarin@13864
   497
lemma (in "domain") integral_iff: (* not by default a simp rule! *)
ballarin@13864
   498
  "[| a \<in> carrier R; b \<in> carrier R |] ==> (a \<otimes> b = \<zero>) = (a = \<zero> | b = \<zero>)"
ballarin@13864
   499
proof
ballarin@13864
   500
  assume "a \<in> carrier R" "b \<in> carrier R" "a \<otimes> b = \<zero>"
ballarin@13864
   501
  then show "a = \<zero> | b = \<zero>" by (simp add: integral)
ballarin@13864
   502
next
ballarin@13864
   503
  assume "a \<in> carrier R" "b \<in> carrier R" "a = \<zero> | b = \<zero>"
ballarin@13864
   504
  then show "a \<otimes> b = \<zero>" by auto
ballarin@13864
   505
qed
ballarin@13864
   506
ballarin@13864
   507
lemma (in "domain") m_lcancel:
ballarin@13864
   508
  assumes prem: "a ~= \<zero>"
ballarin@13864
   509
    and R: "a \<in> carrier R" "b \<in> carrier R" "c \<in> carrier R"
ballarin@13864
   510
  shows "(a \<otimes> b = a \<otimes> c) = (b = c)"
ballarin@13864
   511
proof
ballarin@13864
   512
  assume eq: "a \<otimes> b = a \<otimes> c"
ballarin@13864
   513
  with R have "a \<otimes> (b \<ominus> c) = \<zero>" by algebra
ballarin@13864
   514
  with R have "a = \<zero> | (b \<ominus> c) = \<zero>" by (simp add: integral_iff)
ballarin@13864
   515
  with prem and R have "b \<ominus> c = \<zero>" by auto 
ballarin@13864
   516
  with R have "b = b \<ominus> (b \<ominus> c)" by algebra 
ballarin@13864
   517
  also from R have "b \<ominus> (b \<ominus> c) = c" by algebra
ballarin@13864
   518
  finally show "b = c" .
ballarin@13864
   519
next
ballarin@13864
   520
  assume "b = c" then show "a \<otimes> b = a \<otimes> c" by simp
ballarin@13864
   521
qed
ballarin@13864
   522
ballarin@13864
   523
lemma (in "domain") m_rcancel:
ballarin@13864
   524
  assumes prem: "a ~= \<zero>"
ballarin@13864
   525
    and R: "a \<in> carrier R" "b \<in> carrier R" "c \<in> carrier R"
ballarin@13864
   526
  shows conc: "(b \<otimes> a = c \<otimes> a) = (b = c)"
ballarin@13864
   527
proof -
ballarin@13864
   528
  from prem and R have "(a \<otimes> b = a \<otimes> c) = (b = c)" by (rule m_lcancel)
ballarin@13864
   529
  with R show ?thesis by algebra
ballarin@13864
   530
qed
ballarin@13864
   531
ballarin@13936
   532
subsection {* Morphisms *}
ballarin@13936
   533
ballarin@13936
   534
constdefs
ballarin@13936
   535
  ring_hom :: "[('a, 'm) ring_scheme, ('b, 'n) ring_scheme] => ('a => 'b) set"
ballarin@13936
   536
  "ring_hom R S == {h. h \<in> carrier R -> carrier S &
ballarin@13936
   537
      (ALL x y. x \<in> carrier R & y \<in> carrier R -->
ballarin@13936
   538
        h (mult R x y) = mult S (h x) (h y) &
ballarin@13936
   539
        h (add R x y) = add S (h x) (h y)) &
ballarin@13936
   540
      h (one R) = one S}"
ballarin@13936
   541
ballarin@13936
   542
lemma ring_hom_memI:
ballarin@13936
   543
  assumes hom_closed: "!!x. x \<in> carrier R ==> h x \<in> carrier S"
ballarin@13936
   544
    and hom_mult: "!!x y. [| x \<in> carrier R; y \<in> carrier R |] ==>
ballarin@13936
   545
      h (mult R x y) = mult S (h x) (h y)"
ballarin@13936
   546
    and hom_add: "!!x y. [| x \<in> carrier R; y \<in> carrier R |] ==>
ballarin@13936
   547
      h (add R x y) = add S (h x) (h y)"
ballarin@13936
   548
    and hom_one: "h (one R) = one S"
ballarin@13936
   549
  shows "h \<in> ring_hom R S"
ballarin@13936
   550
  by (auto simp add: ring_hom_def prems Pi_def)
ballarin@13936
   551
ballarin@13936
   552
lemma ring_hom_closed:
ballarin@13936
   553
  "[| h \<in> ring_hom R S; x \<in> carrier R |] ==> h x \<in> carrier S"
ballarin@13936
   554
  by (auto simp add: ring_hom_def funcset_mem)
ballarin@13936
   555
ballarin@13936
   556
lemma ring_hom_mult:
ballarin@13936
   557
  "[| h \<in> ring_hom R S; x \<in> carrier R; y \<in> carrier R |] ==>
ballarin@13936
   558
  h (mult R x y) = mult S (h x) (h y)"
ballarin@13936
   559
  by (simp add: ring_hom_def)
ballarin@13936
   560
ballarin@13936
   561
lemma ring_hom_add:
ballarin@13936
   562
  "[| h \<in> ring_hom R S; x \<in> carrier R; y \<in> carrier R |] ==>
ballarin@13936
   563
  h (add R x y) = add S (h x) (h y)"
ballarin@13936
   564
  by (simp add: ring_hom_def)
ballarin@13936
   565
ballarin@13936
   566
lemma ring_hom_one:
ballarin@13936
   567
  "h \<in> ring_hom R S ==> h (one R) = one S"
ballarin@13936
   568
  by (simp add: ring_hom_def)
ballarin@13936
   569
ballarin@13936
   570
locale ring_hom_cring = cring R + cring S + var h +
ballarin@13936
   571
  assumes homh [simp, intro]: "h \<in> ring_hom R S"
ballarin@13936
   572
  notes hom_closed [simp, intro] = ring_hom_closed [OF homh]
ballarin@13936
   573
    and hom_mult [simp] = ring_hom_mult [OF homh]
ballarin@13936
   574
    and hom_add [simp] = ring_hom_add [OF homh]
ballarin@13936
   575
    and hom_one [simp] = ring_hom_one [OF homh]
ballarin@13936
   576
ballarin@13936
   577
lemma (in ring_hom_cring) hom_zero [simp]:
ballarin@13936
   578
  "h \<zero> = \<zero>\<^sub>2"
ballarin@13936
   579
proof -
ballarin@13936
   580
  have "h \<zero> \<oplus>\<^sub>2 h \<zero> = h \<zero> \<oplus>\<^sub>2 \<zero>\<^sub>2"
ballarin@13936
   581
    by (simp add: hom_add [symmetric] del: hom_add)
ballarin@13936
   582
  then show ?thesis by (simp del: S.r_zero)
ballarin@13936
   583
qed
ballarin@13936
   584
ballarin@13936
   585
lemma (in ring_hom_cring) hom_a_inv [simp]:
ballarin@13936
   586
  "x \<in> carrier R ==> h (\<ominus> x) = \<ominus>\<^sub>2 h x"
ballarin@13936
   587
proof -
ballarin@13936
   588
  assume R: "x \<in> carrier R"
ballarin@13936
   589
  then have "h x \<oplus>\<^sub>2 h (\<ominus> x) = h x \<oplus>\<^sub>2 (\<ominus>\<^sub>2 h x)"
ballarin@13936
   590
    by (simp add: hom_add [symmetric] R.r_neg S.r_neg del: hom_add)
ballarin@13936
   591
  with R show ?thesis by simp
ballarin@13936
   592
qed
ballarin@13936
   593
ballarin@13936
   594
lemma (in ring_hom_cring) hom_finsum [simp]:
ballarin@13936
   595
  "[| finite A; f \<in> A -> carrier R |] ==>
ballarin@13936
   596
  h (finsum R f A) = finsum S (h o f) A"
ballarin@13936
   597
proof (induct set: Finites)
ballarin@13936
   598
  case empty then show ?case by simp
ballarin@13936
   599
next
ballarin@13936
   600
  case insert then show ?case by (simp add: Pi_def)
ballarin@13936
   601
qed
ballarin@13936
   602
ballarin@13936
   603
lemma (in ring_hom_cring) hom_finprod:
ballarin@13936
   604
  "[| finite A; f \<in> A -> carrier R |] ==>
ballarin@13936
   605
  h (finprod R f A) = finprod S (h o f) A"
ballarin@13936
   606
proof (induct set: Finites)
ballarin@13936
   607
  case empty then show ?case by simp
ballarin@13936
   608
next
ballarin@13936
   609
  case insert then show ?case by (simp add: Pi_def)
ballarin@13936
   610
qed
ballarin@13936
   611
ballarin@13936
   612
declare ring_hom_cring.hom_finprod [simp]
ballarin@13936
   613
ballarin@13936
   614
lemma id_ring_hom [simp]:
ballarin@13936
   615
  "id \<in> ring_hom R R"
ballarin@13936
   616
  by (auto intro!: ring_hom_memI)
ballarin@13936
   617
ballarin@13835
   618
end