src/HOL/Algebra/CRing.thy
author ballarin
Mon Aug 02 09:44:46 2004 +0200 (2004-08-02)
changeset 15095 63f5f4c265dd
parent 14963 d584e32f7d46
child 15328 35951e6a7855
permissions -rw-r--r--
Theories now take advantage of recent syntax improvements with (structure).
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
wenzelm@14577
     8
header {* Abelian Groups *}
wenzelm@14577
     9
ballarin@13936
    10
theory CRing = FiniteProduct
ballarin@13854
    11
files ("ringsimp.ML"):
ballarin@13835
    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
wenzelm@14651
    19
constdefs (structure R)
ballarin@15095
    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)
wenzelm@14651
    24
  "[| x \<in> carrier R; y \<in> carrier R |] ==> x \<ominus> y == x \<oplus> (\<ominus> y)"
ballarin@13936
    25
ballarin@13936
    26
locale abelian_monoid = struct G +
paulson@14963
    27
  assumes a_comm_monoid:
paulson@14963
    28
     "comm_monoid (| carrier = carrier G, mult = add G, one = zero G |)"
paulson@14963
    29
ballarin@13936
    30
ballarin@13936
    31
text {*
ballarin@13936
    32
  The following definition is redundant but simple to use.
ballarin@13936
    33
*}
ballarin@13936
    34
ballarin@13936
    35
locale abelian_group = abelian_monoid +
paulson@14963
    36
  assumes a_comm_group:
paulson@14963
    37
     "comm_group (| carrier = carrier G, mult = add G, one = zero G |)"
paulson@14963
    38
ballarin@13936
    39
ballarin@13936
    40
subsection {* Basic Properties *}
ballarin@13936
    41
ballarin@13936
    42
lemma abelian_monoidI:
ballarin@15095
    43
  includes struct R
ballarin@13936
    44
  assumes a_closed:
ballarin@15095
    45
      "!!x y. [| x \<in> carrier R; y \<in> carrier R |] ==> x \<oplus> y \<in> carrier R"
ballarin@15095
    46
    and zero_closed: "\<zero> \<in> carrier R"
ballarin@13936
    47
    and a_assoc:
ballarin@13936
    48
      "!!x y z. [| x \<in> carrier R; y \<in> carrier R; z \<in> carrier R |] ==>
ballarin@15095
    49
      (x \<oplus> y) \<oplus> z = x \<oplus> (y \<oplus> z)"
ballarin@15095
    50
    and l_zero: "!!x. x \<in> carrier R ==> \<zero> \<oplus> x = x"
ballarin@13936
    51
    and a_comm:
ballarin@15095
    52
      "!!x y. [| x \<in> carrier R; y \<in> carrier R |] ==> x \<oplus> y = y \<oplus> x"
ballarin@13936
    53
  shows "abelian_monoid R"
ballarin@13936
    54
  by (auto intro!: abelian_monoid.intro comm_monoidI intro: prems)
ballarin@13936
    55
ballarin@13936
    56
lemma abelian_groupI:
ballarin@15095
    57
  includes struct R
ballarin@13936
    58
  assumes a_closed:
ballarin@15095
    59
      "!!x y. [| x \<in> carrier R; y \<in> carrier R |] ==> x \<oplus> y \<in> carrier R"
ballarin@13936
    60
    and zero_closed: "zero R \<in> carrier R"
ballarin@13936
    61
    and a_assoc:
ballarin@13936
    62
      "!!x y z. [| x \<in> carrier R; y \<in> carrier R; z \<in> carrier R |] ==>
ballarin@15095
    63
      (x \<oplus> y) \<oplus> z = x \<oplus> (y \<oplus> z)"
ballarin@13936
    64
    and a_comm:
ballarin@15095
    65
      "!!x y. [| x \<in> carrier R; y \<in> carrier R |] ==> x \<oplus> y = y \<oplus> x"
ballarin@15095
    66
    and l_zero: "!!x. x \<in> carrier R ==> \<zero> \<oplus> x = x"
ballarin@15095
    67
    and l_inv_ex: "!!x. x \<in> carrier R ==> EX y : carrier R. y \<oplus> x = \<zero>"
ballarin@13936
    68
  shows "abelian_group R"
ballarin@13936
    69
  by (auto intro!: abelian_group.intro abelian_monoidI
ballarin@13936
    70
      abelian_group_axioms.intro comm_monoidI comm_groupI
ballarin@13936
    71
    intro: prems)
ballarin@13936
    72
ballarin@13936
    73
lemma (in abelian_monoid) a_monoid:
ballarin@13936
    74
  "monoid (| carrier = carrier G, mult = add G, one = zero G |)"
paulson@14963
    75
by (rule comm_monoid.axioms, rule a_comm_monoid) 
ballarin@13936
    76
ballarin@13936
    77
lemma (in abelian_group) a_group:
ballarin@13936
    78
  "group (| carrier = carrier G, mult = add G, one = zero G |)"
paulson@14963
    79
by (simp add: group_def a_monoid comm_group.axioms a_comm_group) 
ballarin@13936
    80
paulson@14963
    81
lemmas monoid_record_simps = partial_object.simps monoid.simps
ballarin@13936
    82
ballarin@13936
    83
lemma (in abelian_monoid) a_closed [intro, simp]:
paulson@14963
    84
  "\<lbrakk> x \<in> carrier G; y \<in> carrier G \<rbrakk> \<Longrightarrow> x \<oplus> y \<in> carrier G"
paulson@14963
    85
  by (rule monoid.m_closed [OF a_monoid, simplified monoid_record_simps]) 
ballarin@13936
    86
ballarin@13936
    87
lemma (in abelian_monoid) zero_closed [intro, simp]:
ballarin@13936
    88
  "\<zero> \<in> carrier G"
ballarin@13936
    89
  by (rule monoid.one_closed [OF a_monoid, simplified monoid_record_simps])
ballarin@13936
    90
ballarin@13936
    91
lemma (in abelian_group) a_inv_closed [intro, simp]:
ballarin@13936
    92
  "x \<in> carrier G ==> \<ominus> x \<in> carrier G"
ballarin@13936
    93
  by (simp add: a_inv_def
ballarin@13936
    94
    group.inv_closed [OF a_group, simplified monoid_record_simps])
ballarin@13936
    95
ballarin@13936
    96
lemma (in abelian_group) minus_closed [intro, simp]:
ballarin@13936
    97
  "[| x \<in> carrier G; y \<in> carrier G |] ==> x \<ominus> y \<in> carrier G"
ballarin@13936
    98
  by (simp add: minus_def)
ballarin@13936
    99
ballarin@13936
   100
lemma (in abelian_group) a_l_cancel [simp]:
ballarin@13936
   101
  "[| x \<in> carrier G; y \<in> carrier G; z \<in> carrier G |] ==>
ballarin@13936
   102
   (x \<oplus> y = x \<oplus> z) = (y = z)"
ballarin@13936
   103
  by (rule group.l_cancel [OF a_group, simplified monoid_record_simps])
ballarin@13936
   104
ballarin@13936
   105
lemma (in abelian_group) a_r_cancel [simp]:
ballarin@13936
   106
  "[| x \<in> carrier G; y \<in> carrier G; z \<in> carrier G |] ==>
ballarin@13936
   107
   (y \<oplus> x = z \<oplus> x) = (y = z)"
ballarin@13936
   108
  by (rule group.r_cancel [OF a_group, simplified monoid_record_simps])
ballarin@13936
   109
ballarin@13936
   110
lemma (in abelian_monoid) a_assoc:
paulson@14963
   111
  "\<lbrakk>x \<in> carrier G; y \<in> carrier G; z \<in> carrier G\<rbrakk> \<Longrightarrow>
ballarin@13936
   112
  (x \<oplus> y) \<oplus> z = x \<oplus> (y \<oplus> z)"
paulson@14963
   113
  by (rule monoid.m_assoc [OF a_monoid, simplified monoid_record_simps])
ballarin@13936
   114
ballarin@13936
   115
lemma (in abelian_monoid) l_zero [simp]:
ballarin@13936
   116
  "x \<in> carrier G ==> \<zero> \<oplus> x = x"
ballarin@13936
   117
  by (rule monoid.l_one [OF a_monoid, simplified monoid_record_simps])
ballarin@13936
   118
ballarin@13936
   119
lemma (in abelian_group) l_neg:
ballarin@13936
   120
  "x \<in> carrier G ==> \<ominus> x \<oplus> x = \<zero>"
ballarin@13936
   121
  by (simp add: a_inv_def
ballarin@13936
   122
    group.l_inv [OF a_group, simplified monoid_record_simps])
ballarin@13936
   123
ballarin@13936
   124
lemma (in abelian_monoid) a_comm:
paulson@14963
   125
  "\<lbrakk>x \<in> carrier G; y \<in> carrier G\<rbrakk> \<Longrightarrow> x \<oplus> y = y \<oplus> x"
paulson@14963
   126
  by (rule comm_monoid.m_comm [OF a_comm_monoid,
ballarin@13936
   127
    simplified monoid_record_simps])
ballarin@13936
   128
ballarin@13936
   129
lemma (in abelian_monoid) a_lcomm:
paulson@14963
   130
  "\<lbrakk>x \<in> carrier G; y \<in> carrier G; z \<in> carrier G\<rbrakk> \<Longrightarrow>
ballarin@13936
   131
   x \<oplus> (y \<oplus> z) = y \<oplus> (x \<oplus> z)"
paulson@14963
   132
  by (rule comm_monoid.m_lcomm [OF a_comm_monoid,
paulson@14963
   133
                                simplified monoid_record_simps])
ballarin@13936
   134
ballarin@13936
   135
lemma (in abelian_monoid) r_zero [simp]:
ballarin@13936
   136
  "x \<in> carrier G ==> x \<oplus> \<zero> = x"
ballarin@13936
   137
  using monoid.r_one [OF a_monoid]
ballarin@13936
   138
  by simp
ballarin@13936
   139
ballarin@13936
   140
lemma (in abelian_group) r_neg:
ballarin@13936
   141
  "x \<in> carrier G ==> x \<oplus> (\<ominus> x) = \<zero>"
ballarin@13936
   142
  using group.r_inv [OF a_group]
ballarin@13936
   143
  by (simp add: a_inv_def)
ballarin@13936
   144
ballarin@13936
   145
lemma (in abelian_group) minus_zero [simp]:
ballarin@13936
   146
  "\<ominus> \<zero> = \<zero>"
ballarin@13936
   147
  by (simp add: a_inv_def
ballarin@13936
   148
    group.inv_one [OF a_group, simplified monoid_record_simps])
ballarin@13936
   149
ballarin@13936
   150
lemma (in abelian_group) minus_minus [simp]:
ballarin@13936
   151
  "x \<in> carrier G ==> \<ominus> (\<ominus> x) = x"
ballarin@13936
   152
  using group.inv_inv [OF a_group, simplified monoid_record_simps]
ballarin@13936
   153
  by (simp add: a_inv_def)
ballarin@13936
   154
ballarin@13936
   155
lemma (in abelian_group) a_inv_inj:
ballarin@13936
   156
  "inj_on (a_inv G) (carrier G)"
ballarin@13936
   157
  using group.inv_inj [OF a_group, simplified monoid_record_simps]
ballarin@13936
   158
  by (simp add: a_inv_def)
ballarin@13936
   159
ballarin@13936
   160
lemma (in abelian_group) minus_add:
ballarin@13936
   161
  "[| x \<in> carrier G; y \<in> carrier G |] ==> \<ominus> (x \<oplus> y) = \<ominus> x \<oplus> \<ominus> y"
ballarin@13936
   162
  using comm_group.inv_mult [OF a_comm_group]
ballarin@13936
   163
  by (simp add: a_inv_def)
ballarin@13936
   164
ballarin@13936
   165
lemmas (in abelian_monoid) a_ac = a_assoc a_comm a_lcomm
ballarin@13936
   166
ballarin@13936
   167
subsection {* Sums over Finite Sets *}
ballarin@13936
   168
ballarin@13936
   169
text {*
ballarin@13936
   170
  This definition makes it easy to lift lemmas from @{term finprod}.
ballarin@13936
   171
*}
ballarin@13936
   172
ballarin@13936
   173
constdefs
ballarin@15095
   174
  finsum :: "[('b, 'm) ring_scheme, 'a => 'b, 'a set] => 'b"
ballarin@13936
   175
  "finsum G f A == finprod (| carrier = carrier G,
ballarin@13936
   176
     mult = add G, one = zero G |) f A"
ballarin@13936
   177
wenzelm@14651
   178
syntax
wenzelm@14651
   179
  "_finsum" :: "index => idt => 'a set => 'b => 'b"
wenzelm@14666
   180
      ("(3\<Oplus>__:_. _)" [1000, 0, 51, 10] 10)
wenzelm@14651
   181
syntax (xsymbols)
wenzelm@14651
   182
  "_finsum" :: "index => idt => 'a set => 'b => 'b"
wenzelm@14666
   183
      ("(3\<Oplus>__\<in>_. _)" [1000, 0, 51, 10] 10)
wenzelm@14651
   184
syntax (HTML output)
wenzelm@14651
   185
  "_finsum" :: "index => idt => 'a set => 'b => 'b"
wenzelm@14666
   186
      ("(3\<Oplus>__\<in>_. _)" [1000, 0, 51, 10] 10)
wenzelm@14651
   187
translations
ballarin@15095
   188
  "\<Oplus>\<index>i:A. b" == "finsum \<struct>\<index> (%i. b) A"
ballarin@15095
   189
  -- {* Beware of argument permutation! *}
wenzelm@14651
   190
ballarin@13936
   191
(*
ballarin@13936
   192
  lemmas (in abelian_monoid) finsum_empty [simp] =
ballarin@13936
   193
    comm_monoid.finprod_empty [OF a_comm_monoid, simplified]
ballarin@13936
   194
  is dangeous, because attributes (like simplified) are applied upon opening
ballarin@13936
   195
  the locale, simplified refers to the simpset at that time!!!
ballarin@13936
   196
ballarin@13936
   197
  lemmas (in abelian_monoid) finsum_empty [simp] =
ballarin@13936
   198
    abelian_monoid.finprod_empty [OF a_abelian_monoid, folded finsum_def,
ballarin@13936
   199
      simplified monoid_record_simps]
ballarin@15095
   200
  makes the locale slow, because proofs are repeated for every
ballarin@15095
   201
  "lemma (in abelian_monoid)" command.
ballarin@15095
   202
  When lemma is used time in UnivPoly.thy from beginning to UP_cring goes down
ballarin@15095
   203
  from 110 secs to 60 secs.
ballarin@13936
   204
*)
ballarin@13936
   205
ballarin@13936
   206
lemma (in abelian_monoid) finsum_empty [simp]:
ballarin@13936
   207
  "finsum G f {} = \<zero>"
ballarin@13936
   208
  by (rule comm_monoid.finprod_empty [OF a_comm_monoid,
ballarin@13936
   209
    folded finsum_def, simplified monoid_record_simps])
ballarin@13936
   210
ballarin@13936
   211
lemma (in abelian_monoid) finsum_insert [simp]:
ballarin@13936
   212
  "[| finite F; a \<notin> F; f \<in> F -> carrier G; f a \<in> carrier G |]
ballarin@13936
   213
  ==> finsum G f (insert a F) = f a \<oplus> finsum G f F"
ballarin@13936
   214
  by (rule comm_monoid.finprod_insert [OF a_comm_monoid,
ballarin@13936
   215
    folded finsum_def, simplified monoid_record_simps])
ballarin@13936
   216
ballarin@13936
   217
lemma (in abelian_monoid) finsum_zero [simp]:
ballarin@15095
   218
  "finite A ==> (\<Oplus>i\<in>A. \<zero>) = \<zero>"
ballarin@13936
   219
  by (rule comm_monoid.finprod_one [OF a_comm_monoid, folded finsum_def,
ballarin@13936
   220
    simplified monoid_record_simps])
ballarin@13936
   221
ballarin@13936
   222
lemma (in abelian_monoid) finsum_closed [simp]:
ballarin@13936
   223
  fixes A
ballarin@13936
   224
  assumes fin: "finite A" and f: "f \<in> A -> carrier G" 
ballarin@13936
   225
  shows "finsum G f A \<in> carrier G"
ballarin@13936
   226
  by (rule comm_monoid.finprod_closed [OF a_comm_monoid,
ballarin@13936
   227
    folded finsum_def, simplified monoid_record_simps])
ballarin@13936
   228
ballarin@13936
   229
lemma (in abelian_monoid) finsum_Un_Int:
ballarin@13936
   230
  "[| finite A; finite B; g \<in> A -> carrier G; g \<in> B -> carrier G |] ==>
ballarin@13936
   231
     finsum G g (A Un B) \<oplus> finsum G g (A Int B) =
ballarin@13936
   232
     finsum G g A \<oplus> finsum G g B"
ballarin@13936
   233
  by (rule comm_monoid.finprod_Un_Int [OF a_comm_monoid,
ballarin@13936
   234
    folded finsum_def, simplified monoid_record_simps])
ballarin@13936
   235
ballarin@13936
   236
lemma (in abelian_monoid) finsum_Un_disjoint:
ballarin@13936
   237
  "[| finite A; finite B; A Int B = {};
ballarin@13936
   238
      g \<in> A -> carrier G; g \<in> B -> carrier G |]
ballarin@13936
   239
   ==> finsum G g (A Un B) = finsum G g A \<oplus> finsum G g B"
ballarin@13936
   240
  by (rule comm_monoid.finprod_Un_disjoint [OF a_comm_monoid,
ballarin@13936
   241
    folded finsum_def, simplified monoid_record_simps])
ballarin@13936
   242
ballarin@13936
   243
lemma (in abelian_monoid) finsum_addf:
ballarin@13936
   244
  "[| finite A; f \<in> A -> carrier G; g \<in> A -> carrier G |] ==>
ballarin@13936
   245
   finsum G (%x. f x \<oplus> g x) A = (finsum G f A \<oplus> finsum G g A)"
ballarin@13936
   246
  by (rule comm_monoid.finprod_multf [OF a_comm_monoid,
ballarin@13936
   247
    folded finsum_def, simplified monoid_record_simps])
ballarin@13936
   248
ballarin@13936
   249
lemma (in abelian_monoid) finsum_cong':
ballarin@13936
   250
  "[| A = B; g : B -> carrier G;
ballarin@13936
   251
      !!i. i : B ==> f i = g i |] ==> finsum G f A = finsum G g B"
ballarin@13936
   252
  by (rule comm_monoid.finprod_cong' [OF a_comm_monoid,
ballarin@13936
   253
    folded finsum_def, simplified monoid_record_simps]) auto
ballarin@13936
   254
ballarin@13936
   255
lemma (in abelian_monoid) finsum_0 [simp]:
ballarin@13936
   256
  "f : {0::nat} -> carrier G ==> finsum G f {..0} = f 0"
ballarin@13936
   257
  by (rule comm_monoid.finprod_0 [OF a_comm_monoid, folded finsum_def,
ballarin@13936
   258
    simplified monoid_record_simps])
ballarin@13936
   259
ballarin@13936
   260
lemma (in abelian_monoid) finsum_Suc [simp]:
ballarin@13936
   261
  "f : {..Suc n} -> carrier G ==>
ballarin@13936
   262
   finsum G f {..Suc n} = (f (Suc n) \<oplus> finsum G f {..n})"
ballarin@13936
   263
  by (rule comm_monoid.finprod_Suc [OF a_comm_monoid, folded finsum_def,
ballarin@13936
   264
    simplified monoid_record_simps])
ballarin@13936
   265
ballarin@13936
   266
lemma (in abelian_monoid) finsum_Suc2:
ballarin@13936
   267
  "f : {..Suc n} -> carrier G ==>
ballarin@13936
   268
   finsum G f {..Suc n} = (finsum G (%i. f (Suc i)) {..n} \<oplus> f 0)"
ballarin@13936
   269
  by (rule comm_monoid.finprod_Suc2 [OF a_comm_monoid, folded finsum_def,
ballarin@13936
   270
    simplified monoid_record_simps])
ballarin@13936
   271
ballarin@13936
   272
lemma (in abelian_monoid) finsum_add [simp]:
ballarin@13936
   273
  "[| f : {..n} -> carrier G; g : {..n} -> carrier G |] ==>
ballarin@13936
   274
     finsum G (%i. f i \<oplus> g i) {..n::nat} =
ballarin@13936
   275
     finsum G f {..n} \<oplus> finsum G g {..n}"
ballarin@13936
   276
  by (rule comm_monoid.finprod_mult [OF a_comm_monoid, folded finsum_def,
ballarin@13936
   277
    simplified monoid_record_simps])
ballarin@13936
   278
ballarin@13936
   279
lemma (in abelian_monoid) finsum_cong:
ballarin@14399
   280
  "[| A = B; f : B -> carrier G = True;
ballarin@14399
   281
      !!i. i : B ==> f i = g i |] ==> finsum G f A = finsum G g B"
ballarin@13936
   282
  by (rule comm_monoid.finprod_cong [OF a_comm_monoid, folded finsum_def,
ballarin@13936
   283
    simplified monoid_record_simps]) auto
ballarin@13936
   284
ballarin@13936
   285
text {*Usually, if this rule causes a failed congruence proof error,
ballarin@13936
   286
   the reason is that the premise @{text "g \<in> B -> carrier G"} cannot be shown.
ballarin@13936
   287
   Adding @{thm [source] Pi_def} to the simpset is often useful. *}
ballarin@13936
   288
ballarin@13835
   289
section {* The Algebraic Hierarchy of Rings *}
ballarin@13835
   290
ballarin@13835
   291
subsection {* Basic Definitions *}
ballarin@13835
   292
ballarin@14399
   293
locale ring = abelian_group R + monoid R +
ballarin@13936
   294
  assumes l_distr: "[| x \<in> carrier R; y \<in> carrier R; z \<in> carrier R |]
ballarin@13835
   295
      ==> (x \<oplus> y) \<otimes> z = x \<otimes> z \<oplus> y \<otimes> z"
ballarin@14399
   296
    and r_distr: "[| x \<in> carrier R; y \<in> carrier R; z \<in> carrier R |]
ballarin@14399
   297
      ==> z \<otimes> (x \<oplus> y) = z \<otimes> x \<oplus> z \<otimes> y"
ballarin@14399
   298
ballarin@14399
   299
locale cring = ring + comm_monoid R
ballarin@13835
   300
ballarin@13864
   301
locale "domain" = cring +
ballarin@13864
   302
  assumes one_not_zero [simp]: "\<one> ~= \<zero>"
ballarin@13864
   303
    and integral: "[| a \<otimes> b = \<zero>; a \<in> carrier R; b \<in> carrier R |] ==>
ballarin@13864
   304
                  a = \<zero> | b = \<zero>"
ballarin@13864
   305
ballarin@14551
   306
locale field = "domain" +
ballarin@14551
   307
  assumes field_Units: "Units R = carrier R - {\<zero>}"
ballarin@14551
   308
ballarin@13864
   309
subsection {* Basic Facts of Rings *}
ballarin@13835
   310
ballarin@14399
   311
lemma ringI:
ballarin@14399
   312
  includes struct R
ballarin@14399
   313
  assumes abelian_group: "abelian_group R"
ballarin@14399
   314
    and monoid: "monoid R"
ballarin@14399
   315
    and l_distr: "!!x y z. [| x \<in> carrier R; y \<in> carrier R; z \<in> carrier R |]
ballarin@15095
   316
      ==> (x \<oplus> y) \<otimes> z = x \<otimes> z \<oplus> y \<otimes> z"
ballarin@14399
   317
    and r_distr: "!!x y z. [| x \<in> carrier R; y \<in> carrier R; z \<in> carrier R |]
ballarin@14399
   318
      ==> z \<otimes> (x \<oplus> y) = z \<otimes> x \<oplus> z \<otimes> y"
ballarin@14399
   319
  shows "ring R"
ballarin@14399
   320
  by (auto intro: ring.intro
paulson@14963
   321
    abelian_group.axioms ring_axioms.intro prems)
ballarin@14399
   322
ballarin@14399
   323
lemma (in ring) is_abelian_group:
ballarin@14399
   324
  "abelian_group R"
ballarin@14399
   325
  by (auto intro!: abelian_groupI a_assoc a_comm l_neg)
ballarin@14399
   326
ballarin@14399
   327
lemma (in ring) is_monoid:
ballarin@14399
   328
  "monoid R"
ballarin@14399
   329
  by (auto intro!: monoidI m_assoc)
ballarin@14399
   330
ballarin@13936
   331
lemma cringI:
ballarin@14399
   332
  includes struct R
ballarin@13936
   333
  assumes abelian_group: "abelian_group R"
ballarin@13936
   334
    and comm_monoid: "comm_monoid R"
ballarin@13936
   335
    and l_distr: "!!x y z. [| x \<in> carrier R; y \<in> carrier R; z \<in> carrier R |]
ballarin@15095
   336
      ==> (x \<oplus> y) \<otimes> z = x \<otimes> z \<oplus> y \<otimes> z"
ballarin@13936
   337
  shows "cring R"
ballarin@14399
   338
  proof (rule cring.intro)
ballarin@14399
   339
    show "ring_axioms R"
ballarin@14399
   340
    -- {* Right-distributivity follows from left-distributivity and
ballarin@14399
   341
          commutativity. *}
ballarin@14399
   342
    proof (rule ring_axioms.intro)
ballarin@14399
   343
      fix x y z
ballarin@14399
   344
      assume R: "x \<in> carrier R" "y \<in> carrier R" "z \<in> carrier R"
ballarin@14399
   345
      note [simp]= comm_monoid.axioms [OF comm_monoid]
ballarin@14399
   346
        abelian_group.axioms [OF abelian_group]
ballarin@14399
   347
        abelian_monoid.a_closed
ballarin@14399
   348
        
ballarin@14399
   349
      from R have "z \<otimes> (x \<oplus> y) = (x \<oplus> y) \<otimes> z"
paulson@14963
   350
        by (simp add: comm_monoid.m_comm [OF comm_monoid.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"
paulson@14963
   353
        by (simp add: comm_monoid.m_comm [OF comm_monoid.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@15095
   463
  a \<oplus> \<ominus> (a \<oplus> \<ominus> b) = b & c \<otimes>\<^bsub>S\<^esub> d = d \<otimes>\<^bsub>S\<^esub> 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@15095
   534
constdefs (structure R S)
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@15095
   538
        h (x \<otimes> y) = h x \<otimes>\<^bsub>S\<^esub> h y & h (x \<oplus> y) = h x \<oplus>\<^bsub>S\<^esub> h y) &
ballarin@15095
   539
      h \<one> = \<one>\<^bsub>S\<^esub>}"
ballarin@13936
   540
ballarin@13936
   541
lemma ring_hom_memI:
ballarin@15095
   542
  includes struct R + struct S
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@15095
   545
      h (x \<otimes> y) = h x \<otimes>\<^bsub>S\<^esub> h y"
ballarin@13936
   546
    and hom_add: "!!x y. [| x \<in> carrier R; y \<in> carrier R |] ==>
ballarin@15095
   547
      h (x \<oplus> y) = h x \<oplus>\<^bsub>S\<^esub> h y"
ballarin@15095
   548
    and hom_one: "h \<one> = \<one>\<^bsub>S\<^esub>"
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@15095
   557
  includes struct R + struct S
ballarin@15095
   558
  shows
ballarin@15095
   559
    "[| h \<in> ring_hom R S; x \<in> carrier R; y \<in> carrier R |] ==>
ballarin@15095
   560
    h (x \<otimes> y) = h x \<otimes>\<^bsub>S\<^esub> h y"
ballarin@15095
   561
    by (simp add: ring_hom_def)
ballarin@13936
   562
ballarin@13936
   563
lemma ring_hom_add:
ballarin@15095
   564
  includes struct R + struct S
ballarin@15095
   565
  shows
ballarin@15095
   566
    "[| h \<in> ring_hom R S; x \<in> carrier R; y \<in> carrier R |] ==>
ballarin@15095
   567
    h (x \<oplus> y) = h x \<oplus>\<^bsub>S\<^esub> h y"
ballarin@15095
   568
    by (simp add: ring_hom_def)
ballarin@13936
   569
ballarin@13936
   570
lemma ring_hom_one:
ballarin@15095
   571
  includes struct R + struct S
ballarin@15095
   572
  shows "h \<in> ring_hom R S ==> h \<one> = \<one>\<^bsub>S\<^esub>"
ballarin@13936
   573
  by (simp add: ring_hom_def)
ballarin@13936
   574
ballarin@13936
   575
locale ring_hom_cring = cring R + cring S + var h +
ballarin@13936
   576
  assumes homh [simp, intro]: "h \<in> ring_hom R S"
ballarin@13936
   577
  notes hom_closed [simp, intro] = ring_hom_closed [OF homh]
ballarin@13936
   578
    and hom_mult [simp] = ring_hom_mult [OF homh]
ballarin@13936
   579
    and hom_add [simp] = ring_hom_add [OF homh]
ballarin@13936
   580
    and hom_one [simp] = ring_hom_one [OF homh]
ballarin@13936
   581
ballarin@13936
   582
lemma (in ring_hom_cring) hom_zero [simp]:
ballarin@15095
   583
  "h \<zero> = \<zero>\<^bsub>S\<^esub>"
ballarin@13936
   584
proof -
ballarin@15095
   585
  have "h \<zero> \<oplus>\<^bsub>S\<^esub> h \<zero> = h \<zero> \<oplus>\<^bsub>S\<^esub> \<zero>\<^bsub>S\<^esub>"
ballarin@13936
   586
    by (simp add: hom_add [symmetric] del: hom_add)
ballarin@13936
   587
  then show ?thesis by (simp del: S.r_zero)
ballarin@13936
   588
qed
ballarin@13936
   589
ballarin@13936
   590
lemma (in ring_hom_cring) hom_a_inv [simp]:
ballarin@15095
   591
  "x \<in> carrier R ==> h (\<ominus> x) = \<ominus>\<^bsub>S\<^esub> h x"
ballarin@13936
   592
proof -
ballarin@13936
   593
  assume R: "x \<in> carrier R"
ballarin@15095
   594
  then have "h x \<oplus>\<^bsub>S\<^esub> h (\<ominus> x) = h x \<oplus>\<^bsub>S\<^esub> (\<ominus>\<^bsub>S\<^esub> h x)"
ballarin@13936
   595
    by (simp add: hom_add [symmetric] R.r_neg S.r_neg del: hom_add)
ballarin@13936
   596
  with R show ?thesis by simp
ballarin@13936
   597
qed
ballarin@13936
   598
ballarin@13936
   599
lemma (in ring_hom_cring) hom_finsum [simp]:
ballarin@13936
   600
  "[| finite A; f \<in> A -> carrier R |] ==>
ballarin@13936
   601
  h (finsum R f A) = finsum S (h o f) A"
ballarin@13936
   602
proof (induct set: Finites)
ballarin@13936
   603
  case empty then show ?case by simp
ballarin@13936
   604
next
ballarin@13936
   605
  case insert then show ?case by (simp add: Pi_def)
ballarin@13936
   606
qed
ballarin@13936
   607
ballarin@13936
   608
lemma (in ring_hom_cring) hom_finprod:
ballarin@13936
   609
  "[| finite A; f \<in> A -> carrier R |] ==>
ballarin@13936
   610
  h (finprod R f A) = finprod S (h o f) A"
ballarin@13936
   611
proof (induct set: Finites)
ballarin@13936
   612
  case empty then show ?case by simp
ballarin@13936
   613
next
ballarin@13936
   614
  case insert then show ?case by (simp add: Pi_def)
ballarin@13936
   615
qed
ballarin@13936
   616
ballarin@13936
   617
declare ring_hom_cring.hom_finprod [simp]
ballarin@13936
   618
ballarin@13936
   619
lemma id_ring_hom [simp]:
ballarin@13936
   620
  "id \<in> ring_hom R R"
ballarin@13936
   621
  by (auto intro!: ring_hom_memI)
ballarin@13936
   622
ballarin@13835
   623
end