src/HOL/Algebra/Group.thy
author ballarin
Wed Apr 30 10:01:35 2003 +0200 (2003-04-30)
changeset 13936 d3671b878828
parent 13854 91c9ab25fece
child 13940 c67798653056
permissions -rw-r--r--
Greatly extended CRing. Added Module.
ballarin@13813
     1
(*
ballarin@13813
     2
  Title:  HOL/Algebra/Group.thy
ballarin@13813
     3
  Id:     $Id$
ballarin@13813
     4
  Author: Clemens Ballarin, started 4 February 2003
ballarin@13813
     5
ballarin@13813
     6
Based on work by Florian Kammueller, L C Paulson and Markus Wenzel.
ballarin@13813
     7
*)
ballarin@13813
     8
ballarin@13936
     9
header {* Algebraic Structures up to Commutative Groups *}
ballarin@13813
    10
ballarin@13835
    11
theory Group = FuncSet:
ballarin@13813
    12
ballarin@13936
    13
axclass number < type
ballarin@13936
    14
ballarin@13936
    15
instance nat :: number ..
ballarin@13936
    16
instance int :: number ..
ballarin@13936
    17
ballarin@13936
    18
section {* From Magmas to Groups *}
ballarin@13936
    19
ballarin@13813
    20
text {*
ballarin@13813
    21
  Definitions follow Jacobson, Basic Algebra I, Freeman, 1985; with
ballarin@13813
    22
  the exception of \emph{magma} which, following Bourbaki, is a set
ballarin@13813
    23
  together with a binary, closed operation.
ballarin@13813
    24
*}
ballarin@13813
    25
ballarin@13813
    26
subsection {* Definitions *}
ballarin@13813
    27
ballarin@13817
    28
record 'a semigroup =
ballarin@13813
    29
  carrier :: "'a set"
ballarin@13813
    30
  mult :: "['a, 'a] => 'a" (infixl "\<otimes>\<index>" 70)
ballarin@13813
    31
ballarin@13817
    32
record 'a monoid = "'a semigroup" +
ballarin@13813
    33
  one :: 'a ("\<one>\<index>")
ballarin@13817
    34
ballarin@13936
    35
constdefs
ballarin@13936
    36
  m_inv :: "[('a, 'm) monoid_scheme, 'a] => 'a" ("inv\<index> _" [81] 80)
ballarin@13936
    37
  "m_inv G x == (THE y. y \<in> carrier G &
ballarin@13936
    38
                  mult G x y = one G & mult G y x = one G)"
ballarin@13936
    39
ballarin@13936
    40
  Units :: "('a, 'm) monoid_scheme => 'a set"
ballarin@13936
    41
  "Units G == {y. y \<in> carrier G &
ballarin@13936
    42
                  (EX x : carrier G. mult G x y = one G & mult G y x = one G)}"
ballarin@13936
    43
ballarin@13936
    44
consts
ballarin@13936
    45
  pow :: "[('a, 'm) monoid_scheme, 'a, 'b::number] => 'a" (infixr "'(^')\<index>" 75)
ballarin@13936
    46
ballarin@13936
    47
defs (overloaded)
ballarin@13936
    48
  nat_pow_def: "pow G a n == nat_rec (one G) (%u b. mult G b a) n"
ballarin@13936
    49
  int_pow_def: "pow G a z ==
ballarin@13936
    50
    let p = nat_rec (one G) (%u b. mult G b a)
ballarin@13936
    51
    in if neg z then m_inv G (p (nat (-z))) else p (nat z)"
ballarin@13813
    52
ballarin@13813
    53
locale magma = struct G +
ballarin@13813
    54
  assumes m_closed [intro, simp]:
ballarin@13813
    55
    "[| x \<in> carrier G; y \<in> carrier G |] ==> x \<otimes> y \<in> carrier G"
ballarin@13813
    56
ballarin@13813
    57
locale semigroup = magma +
ballarin@13813
    58
  assumes m_assoc:
ballarin@13813
    59
    "[| x \<in> carrier G; y \<in> carrier G; z \<in> carrier G |] ==>
ballarin@13936
    60
    (x \<otimes> y) \<otimes> z = x \<otimes> (y \<otimes> z)"
ballarin@13813
    61
ballarin@13936
    62
locale monoid = semigroup +
ballarin@13813
    63
  assumes one_closed [intro, simp]: "\<one> \<in> carrier G"
ballarin@13813
    64
    and l_one [simp]: "x \<in> carrier G ==> \<one> \<otimes> x = x"
ballarin@13936
    65
    and r_one [simp]: "x \<in> carrier G ==> x \<otimes> \<one> = x"
ballarin@13817
    66
ballarin@13936
    67
lemma monoidI:
ballarin@13936
    68
  assumes m_closed:
ballarin@13936
    69
      "!!x y. [| x \<in> carrier G; y \<in> carrier G |] ==> mult G x y \<in> carrier G"
ballarin@13936
    70
    and one_closed: "one G \<in> carrier G"
ballarin@13936
    71
    and m_assoc:
ballarin@13936
    72
      "!!x y z. [| x \<in> carrier G; y \<in> carrier G; z \<in> carrier G |] ==>
ballarin@13936
    73
      mult G (mult G x y) z = mult G x (mult G y z)"
ballarin@13936
    74
    and l_one: "!!x. x \<in> carrier G ==> mult G (one G) x = x"
ballarin@13936
    75
    and r_one: "!!x. x \<in> carrier G ==> mult G x (one G) = x"
ballarin@13936
    76
  shows "monoid G"
ballarin@13936
    77
  by (fast intro!: monoid.intro magma.intro semigroup_axioms.intro
ballarin@13936
    78
    semigroup.intro monoid_axioms.intro
ballarin@13936
    79
    intro: prems)
ballarin@13936
    80
ballarin@13936
    81
lemma (in monoid) Units_closed [dest]:
ballarin@13936
    82
  "x \<in> Units G ==> x \<in> carrier G"
ballarin@13936
    83
  by (unfold Units_def) fast
ballarin@13936
    84
ballarin@13936
    85
lemma (in monoid) inv_unique:
ballarin@13936
    86
  assumes eq: "y \<otimes> x = \<one>" "x \<otimes> y' = \<one>"
ballarin@13936
    87
    and G: "x \<in> carrier G" "y \<in> carrier G" "y' \<in> carrier G"
ballarin@13936
    88
  shows "y = y'"
ballarin@13936
    89
proof -
ballarin@13936
    90
  from G eq have "y = y \<otimes> (x \<otimes> y')" by simp
ballarin@13936
    91
  also from G have "... = (y \<otimes> x) \<otimes> y'" by (simp add: m_assoc)
ballarin@13936
    92
  also from G eq have "... = y'" by simp
ballarin@13936
    93
  finally show ?thesis .
ballarin@13936
    94
qed
ballarin@13936
    95
ballarin@13936
    96
lemma (in monoid) Units_inv_closed [intro, simp]:
ballarin@13936
    97
  "x \<in> Units G ==> inv x \<in> carrier G"
ballarin@13936
    98
  apply (unfold Units_def m_inv_def)
ballarin@13936
    99
  apply auto
ballarin@13936
   100
  apply (rule theI2, fast)
ballarin@13936
   101
   apply (fast intro: inv_unique)
ballarin@13936
   102
  apply fast
ballarin@13936
   103
  done
ballarin@13936
   104
ballarin@13936
   105
lemma (in monoid) Units_l_inv:
ballarin@13936
   106
  "x \<in> Units G ==> inv x \<otimes> x = \<one>"
ballarin@13936
   107
  apply (unfold Units_def m_inv_def)
ballarin@13936
   108
  apply auto
ballarin@13936
   109
  apply (rule theI2, fast)
ballarin@13936
   110
   apply (fast intro: inv_unique)
ballarin@13936
   111
  apply fast
ballarin@13936
   112
  done
ballarin@13936
   113
ballarin@13936
   114
lemma (in monoid) Units_r_inv:
ballarin@13936
   115
  "x \<in> Units G ==> x \<otimes> inv x = \<one>"
ballarin@13936
   116
  apply (unfold Units_def m_inv_def)
ballarin@13936
   117
  apply auto
ballarin@13936
   118
  apply (rule theI2, fast)
ballarin@13936
   119
   apply (fast intro: inv_unique)
ballarin@13936
   120
  apply fast
ballarin@13936
   121
  done
ballarin@13936
   122
ballarin@13936
   123
lemma (in monoid) Units_inv_Units [intro, simp]:
ballarin@13936
   124
  "x \<in> Units G ==> inv x \<in> Units G"
ballarin@13936
   125
proof -
ballarin@13936
   126
  assume x: "x \<in> Units G"
ballarin@13936
   127
  show "inv x \<in> Units G"
ballarin@13936
   128
    by (auto simp add: Units_def
ballarin@13936
   129
      intro: Units_l_inv Units_r_inv x Units_closed [OF x])
ballarin@13936
   130
qed
ballarin@13936
   131
ballarin@13936
   132
lemma (in monoid) Units_l_cancel [simp]:
ballarin@13936
   133
  "[| x \<in> Units G; y \<in> carrier G; z \<in> carrier G |] ==>
ballarin@13936
   134
   (x \<otimes> y = x \<otimes> z) = (y = z)"
ballarin@13936
   135
proof
ballarin@13936
   136
  assume eq: "x \<otimes> y = x \<otimes> z"
ballarin@13936
   137
    and G: "x \<in> Units G" "y \<in> carrier G" "z \<in> carrier G"
ballarin@13936
   138
  then have "(inv x \<otimes> x) \<otimes> y = (inv x \<otimes> x) \<otimes> z"
ballarin@13936
   139
    by (simp add: m_assoc Units_closed)
ballarin@13936
   140
  with G show "y = z" by (simp add: Units_l_inv)
ballarin@13936
   141
next
ballarin@13936
   142
  assume eq: "y = z"
ballarin@13936
   143
    and G: "x \<in> Units G" "y \<in> carrier G" "z \<in> carrier G"
ballarin@13936
   144
  then show "x \<otimes> y = x \<otimes> z" by simp
ballarin@13936
   145
qed
ballarin@13936
   146
ballarin@13936
   147
lemma (in monoid) Units_inv_inv [simp]:
ballarin@13936
   148
  "x \<in> Units G ==> inv (inv x) = x"
ballarin@13936
   149
proof -
ballarin@13936
   150
  assume x: "x \<in> Units G"
ballarin@13936
   151
  then have "inv x \<otimes> inv (inv x) = inv x \<otimes> x"
ballarin@13936
   152
    by (simp add: Units_l_inv Units_r_inv)
ballarin@13936
   153
  with x show ?thesis by (simp add: Units_closed)
ballarin@13936
   154
qed
ballarin@13936
   155
ballarin@13936
   156
lemma (in monoid) inv_inj_on_Units:
ballarin@13936
   157
  "inj_on (m_inv G) (Units G)"
ballarin@13936
   158
proof (rule inj_onI)
ballarin@13936
   159
  fix x y
ballarin@13936
   160
  assume G: "x \<in> Units G" "y \<in> Units G" and eq: "inv x = inv y"
ballarin@13936
   161
  then have "inv (inv x) = inv (inv y)" by simp
ballarin@13936
   162
  with G show "x = y" by simp
ballarin@13936
   163
qed
ballarin@13936
   164
ballarin@13936
   165
text {* Power *}
ballarin@13936
   166
ballarin@13936
   167
lemma (in monoid) nat_pow_closed [intro, simp]:
ballarin@13936
   168
  "x \<in> carrier G ==> x (^) (n::nat) \<in> carrier G"
ballarin@13936
   169
  by (induct n) (simp_all add: nat_pow_def)
ballarin@13936
   170
ballarin@13936
   171
lemma (in monoid) nat_pow_0 [simp]:
ballarin@13936
   172
  "x (^) (0::nat) = \<one>"
ballarin@13936
   173
  by (simp add: nat_pow_def)
ballarin@13936
   174
ballarin@13936
   175
lemma (in monoid) nat_pow_Suc [simp]:
ballarin@13936
   176
  "x (^) (Suc n) = x (^) n \<otimes> x"
ballarin@13936
   177
  by (simp add: nat_pow_def)
ballarin@13936
   178
ballarin@13936
   179
lemma (in monoid) nat_pow_one [simp]:
ballarin@13936
   180
  "\<one> (^) (n::nat) = \<one>"
ballarin@13936
   181
  by (induct n) simp_all
ballarin@13936
   182
ballarin@13936
   183
lemma (in monoid) nat_pow_mult:
ballarin@13936
   184
  "x \<in> carrier G ==> x (^) (n::nat) \<otimes> x (^) m = x (^) (n + m)"
ballarin@13936
   185
  by (induct m) (simp_all add: m_assoc [THEN sym])
ballarin@13936
   186
ballarin@13936
   187
lemma (in monoid) nat_pow_pow:
ballarin@13936
   188
  "x \<in> carrier G ==> (x (^) n) (^) m = x (^) (n * m::nat)"
ballarin@13936
   189
  by (induct m) (simp, simp add: nat_pow_mult add_commute)
ballarin@13936
   190
ballarin@13936
   191
text {*
ballarin@13936
   192
  A group is a monoid all of whose elements are invertible.
ballarin@13936
   193
*}
ballarin@13936
   194
ballarin@13936
   195
locale group = monoid +
ballarin@13936
   196
  assumes Units: "carrier G <= Units G"
ballarin@13936
   197
ballarin@13936
   198
theorem groupI:
ballarin@13936
   199
  assumes m_closed [simp]:
ballarin@13936
   200
      "!!x y. [| x \<in> carrier G; y \<in> carrier G |] ==> mult G x y \<in> carrier G"
ballarin@13936
   201
    and one_closed [simp]: "one G \<in> carrier G"
ballarin@13936
   202
    and m_assoc:
ballarin@13936
   203
      "!!x y z. [| x \<in> carrier G; y \<in> carrier G; z \<in> carrier G |] ==>
ballarin@13936
   204
      mult G (mult G x y) z = mult G x (mult G y z)"
ballarin@13936
   205
    and l_one [simp]: "!!x. x \<in> carrier G ==> mult G (one G) x = x"
ballarin@13936
   206
    and l_inv_ex: "!!x. x \<in> carrier G ==> EX y : carrier G. mult G y x = one G"
ballarin@13936
   207
  shows "group G"
ballarin@13936
   208
proof -
ballarin@13936
   209
  have l_cancel [simp]:
ballarin@13936
   210
    "!!x y z. [| x \<in> carrier G; y \<in> carrier G; z \<in> carrier G |] ==>
ballarin@13936
   211
    (mult G x y = mult G x z) = (y = z)"
ballarin@13936
   212
  proof
ballarin@13936
   213
    fix x y z
ballarin@13936
   214
    assume eq: "mult G x y = mult G x z"
ballarin@13936
   215
      and G: "x \<in> carrier G" "y \<in> carrier G" "z \<in> carrier G"
ballarin@13936
   216
    with l_inv_ex obtain x_inv where xG: "x_inv \<in> carrier G"
ballarin@13936
   217
      and l_inv: "mult G x_inv x = one G" by fast
ballarin@13936
   218
    from G eq xG have "mult G (mult G x_inv x) y = mult G (mult G x_inv x) z"
ballarin@13936
   219
      by (simp add: m_assoc)
ballarin@13936
   220
    with G show "y = z" by (simp add: l_inv)
ballarin@13936
   221
  next
ballarin@13936
   222
    fix x y z
ballarin@13936
   223
    assume eq: "y = z"
ballarin@13936
   224
      and G: "x \<in> carrier G" "y \<in> carrier G" "z \<in> carrier G"
ballarin@13936
   225
    then show "mult G x y = mult G x z" by simp
ballarin@13936
   226
  qed
ballarin@13936
   227
  have r_one:
ballarin@13936
   228
    "!!x. x \<in> carrier G ==> mult G x (one G) = x"
ballarin@13936
   229
  proof -
ballarin@13936
   230
    fix x
ballarin@13936
   231
    assume x: "x \<in> carrier G"
ballarin@13936
   232
    with l_inv_ex obtain x_inv where xG: "x_inv \<in> carrier G"
ballarin@13936
   233
      and l_inv: "mult G x_inv x = one G" by fast
ballarin@13936
   234
    from x xG have "mult G x_inv (mult G x (one G)) = mult G x_inv x"
ballarin@13936
   235
      by (simp add: m_assoc [symmetric] l_inv)
ballarin@13936
   236
    with x xG show "mult G x (one G) = x" by simp 
ballarin@13936
   237
  qed
ballarin@13936
   238
  have inv_ex:
ballarin@13936
   239
    "!!x. x \<in> carrier G ==> EX y : carrier G. mult G y x = one G &
ballarin@13936
   240
      mult G x y = one G"
ballarin@13936
   241
  proof -
ballarin@13936
   242
    fix x
ballarin@13936
   243
    assume x: "x \<in> carrier G"
ballarin@13936
   244
    with l_inv_ex obtain y where y: "y \<in> carrier G"
ballarin@13936
   245
      and l_inv: "mult G y x = one G" by fast
ballarin@13936
   246
    from x y have "mult G y (mult G x y) = mult G y (one G)"
ballarin@13936
   247
      by (simp add: m_assoc [symmetric] l_inv r_one)
ballarin@13936
   248
    with x y have r_inv: "mult G x y = one G"
ballarin@13936
   249
      by simp
ballarin@13936
   250
    from x y show "EX y : carrier G. mult G y x = one G &
ballarin@13936
   251
      mult G x y = one G"
ballarin@13936
   252
      by (fast intro: l_inv r_inv)
ballarin@13936
   253
  qed
ballarin@13936
   254
  then have carrier_subset_Units: "carrier G <= Units G"
ballarin@13936
   255
    by (unfold Units_def) fast
ballarin@13936
   256
  show ?thesis
ballarin@13936
   257
    by (fast intro!: group.intro magma.intro semigroup_axioms.intro
ballarin@13936
   258
      semigroup.intro monoid_axioms.intro group_axioms.intro
ballarin@13936
   259
      carrier_subset_Units intro: prems r_one)
ballarin@13936
   260
qed
ballarin@13936
   261
ballarin@13936
   262
lemma (in monoid) monoid_groupI:
ballarin@13936
   263
  assumes l_inv_ex:
ballarin@13936
   264
    "!!x. x \<in> carrier G ==> EX y : carrier G. mult G y x = one G"
ballarin@13936
   265
  shows "group G"
ballarin@13936
   266
  by (rule groupI) (auto intro: m_assoc l_inv_ex)
ballarin@13936
   267
ballarin@13936
   268
lemma (in group) Units_eq [simp]:
ballarin@13936
   269
  "Units G = carrier G"
ballarin@13936
   270
proof
ballarin@13936
   271
  show "Units G <= carrier G" by fast
ballarin@13936
   272
next
ballarin@13936
   273
  show "carrier G <= Units G" by (rule Units)
ballarin@13936
   274
qed
ballarin@13936
   275
ballarin@13936
   276
lemma (in group) inv_closed [intro, simp]:
ballarin@13936
   277
  "x \<in> carrier G ==> inv x \<in> carrier G"
ballarin@13936
   278
  using Units_inv_closed by simp
ballarin@13936
   279
ballarin@13936
   280
lemma (in group) l_inv:
ballarin@13936
   281
  "x \<in> carrier G ==> inv x \<otimes> x = \<one>"
ballarin@13936
   282
  using Units_l_inv by simp
ballarin@13813
   283
ballarin@13813
   284
subsection {* Cancellation Laws and Basic Properties *}
ballarin@13813
   285
ballarin@13813
   286
lemma (in group) l_cancel [simp]:
ballarin@13813
   287
  "[| x \<in> carrier G; y \<in> carrier G; z \<in> carrier G |] ==>
ballarin@13813
   288
   (x \<otimes> y = x \<otimes> z) = (y = z)"
ballarin@13936
   289
  using Units_l_inv by simp
ballarin@13936
   290
(*
ballarin@13813
   291
lemma (in group) r_one [simp]:  
ballarin@13813
   292
  "x \<in> carrier G ==> x \<otimes> \<one> = x"
ballarin@13813
   293
proof -
ballarin@13813
   294
  assume x: "x \<in> carrier G"
ballarin@13813
   295
  then have "inv x \<otimes> (x \<otimes> \<one>) = inv x \<otimes> x"
ballarin@13813
   296
    by (simp add: m_assoc [symmetric] l_inv)
ballarin@13813
   297
  with x show ?thesis by simp 
ballarin@13813
   298
qed
ballarin@13936
   299
*)
ballarin@13813
   300
lemma (in group) r_inv:
ballarin@13813
   301
  "x \<in> carrier G ==> x \<otimes> inv x = \<one>"
ballarin@13813
   302
proof -
ballarin@13813
   303
  assume x: "x \<in> carrier G"
ballarin@13813
   304
  then have "inv x \<otimes> (x \<otimes> inv x) = inv x \<otimes> \<one>"
ballarin@13813
   305
    by (simp add: m_assoc [symmetric] l_inv)
ballarin@13813
   306
  with x show ?thesis by (simp del: r_one)
ballarin@13813
   307
qed
ballarin@13813
   308
ballarin@13813
   309
lemma (in group) r_cancel [simp]:
ballarin@13813
   310
  "[| x \<in> carrier G; y \<in> carrier G; z \<in> carrier G |] ==>
ballarin@13813
   311
   (y \<otimes> x = z \<otimes> x) = (y = z)"
ballarin@13813
   312
proof
ballarin@13813
   313
  assume eq: "y \<otimes> x = z \<otimes> x"
ballarin@13813
   314
    and G: "x \<in> carrier G" "y \<in> carrier G" "z \<in> carrier G"
ballarin@13813
   315
  then have "y \<otimes> (x \<otimes> inv x) = z \<otimes> (x \<otimes> inv x)"
ballarin@13813
   316
    by (simp add: m_assoc [symmetric])
ballarin@13813
   317
  with G show "y = z" by (simp add: r_inv)
ballarin@13813
   318
next
ballarin@13813
   319
  assume eq: "y = z"
ballarin@13813
   320
    and G: "x \<in> carrier G" "y \<in> carrier G" "z \<in> carrier G"
ballarin@13813
   321
  then show "y \<otimes> x = z \<otimes> x" by simp
ballarin@13813
   322
qed
ballarin@13813
   323
ballarin@13854
   324
lemma (in group) inv_one [simp]:
ballarin@13854
   325
  "inv \<one> = \<one>"
ballarin@13854
   326
proof -
ballarin@13854
   327
  have "inv \<one> = \<one> \<otimes> (inv \<one>)" by simp
ballarin@13854
   328
  moreover have "... = \<one>" by (simp add: r_inv)
ballarin@13854
   329
  finally show ?thesis .
ballarin@13854
   330
qed
ballarin@13854
   331
ballarin@13813
   332
lemma (in group) inv_inv [simp]:
ballarin@13813
   333
  "x \<in> carrier G ==> inv (inv x) = x"
ballarin@13936
   334
  using Units_inv_inv by simp
ballarin@13936
   335
ballarin@13936
   336
lemma (in group) inv_inj:
ballarin@13936
   337
  "inj_on (m_inv G) (carrier G)"
ballarin@13936
   338
  using inv_inj_on_Units by simp
ballarin@13813
   339
ballarin@13854
   340
lemma (in group) inv_mult_group:
ballarin@13813
   341
  "[| x \<in> carrier G; y \<in> carrier G |] ==> inv (x \<otimes> y) = inv y \<otimes> inv x"
ballarin@13813
   342
proof -
ballarin@13813
   343
  assume G: "x \<in> carrier G" "y \<in> carrier G"
ballarin@13813
   344
  then have "inv (x \<otimes> y) \<otimes> (x \<otimes> y) = (inv y \<otimes> inv x) \<otimes> (x \<otimes> y)"
ballarin@13813
   345
    by (simp add: m_assoc l_inv) (simp add: m_assoc [symmetric] l_inv)
ballarin@13813
   346
  with G show ?thesis by simp
ballarin@13813
   347
qed
ballarin@13813
   348
ballarin@13936
   349
text {* Power *}
ballarin@13936
   350
ballarin@13936
   351
lemma (in group) int_pow_def2:
ballarin@13936
   352
  "a (^) (z::int) = (if neg z then inv (a (^) (nat (-z))) else a (^) (nat z))"
ballarin@13936
   353
  by (simp add: int_pow_def nat_pow_def Let_def)
ballarin@13936
   354
ballarin@13936
   355
lemma (in group) int_pow_0 [simp]:
ballarin@13936
   356
  "x (^) (0::int) = \<one>"
ballarin@13936
   357
  by (simp add: int_pow_def2)
ballarin@13936
   358
ballarin@13936
   359
lemma (in group) int_pow_one [simp]:
ballarin@13936
   360
  "\<one> (^) (z::int) = \<one>"
ballarin@13936
   361
  by (simp add: int_pow_def2)
ballarin@13936
   362
ballarin@13813
   363
subsection {* Substructures *}
ballarin@13813
   364
ballarin@13813
   365
locale submagma = var H + struct G +
ballarin@13813
   366
  assumes subset [intro, simp]: "H \<subseteq> carrier G"
ballarin@13813
   367
    and m_closed [intro, simp]: "[| x \<in> H; y \<in> H |] ==> x \<otimes> y \<in> H"
ballarin@13813
   368
ballarin@13813
   369
declare (in submagma) magma.intro [intro] semigroup.intro [intro]
ballarin@13936
   370
  semigroup_axioms.intro [intro]
ballarin@13813
   371
(*
ballarin@13813
   372
alternative definition of submagma
ballarin@13813
   373
ballarin@13813
   374
locale submagma = var H + struct G +
ballarin@13813
   375
  assumes subset [intro, simp]: "carrier H \<subseteq> carrier G"
ballarin@13813
   376
    and m_equal [simp]: "mult H = mult G"
ballarin@13813
   377
    and m_closed [intro, simp]:
ballarin@13813
   378
      "[| x \<in> carrier H; y \<in> carrier H |] ==> x \<otimes> y \<in> carrier H"
ballarin@13813
   379
*)
ballarin@13813
   380
ballarin@13813
   381
lemma submagma_imp_subset:
ballarin@13813
   382
  "submagma H G ==> H \<subseteq> carrier G"
ballarin@13813
   383
  by (rule submagma.subset)
ballarin@13813
   384
ballarin@13813
   385
lemma (in submagma) subsetD [dest, simp]:
ballarin@13813
   386
  "x \<in> H ==> x \<in> carrier G"
ballarin@13813
   387
  using subset by blast
ballarin@13813
   388
ballarin@13813
   389
lemma (in submagma) magmaI [intro]:
ballarin@13813
   390
  includes magma G
ballarin@13813
   391
  shows "magma (G(| carrier := H |))"
ballarin@13813
   392
  by rule simp
ballarin@13813
   393
ballarin@13813
   394
lemma (in submagma) semigroup_axiomsI [intro]:
ballarin@13813
   395
  includes semigroup G
ballarin@13813
   396
  shows "semigroup_axioms (G(| carrier := H |))"
ballarin@13813
   397
    by rule (simp add: m_assoc)
ballarin@13813
   398
ballarin@13813
   399
lemma (in submagma) semigroupI [intro]:
ballarin@13813
   400
  includes semigroup G
ballarin@13813
   401
  shows "semigroup (G(| carrier := H |))"
ballarin@13813
   402
  using prems by fast
ballarin@13813
   403
ballarin@13813
   404
locale subgroup = submagma H G +
ballarin@13813
   405
  assumes one_closed [intro, simp]: "\<one> \<in> H"
ballarin@13813
   406
    and m_inv_closed [intro, simp]: "x \<in> H ==> inv x \<in> H"
ballarin@13813
   407
ballarin@13813
   408
declare (in subgroup) group.intro [intro]
ballarin@13936
   409
(*
ballarin@13817
   410
lemma (in subgroup) l_oneI [intro]:
ballarin@13817
   411
  includes l_one G
ballarin@13817
   412
  shows "l_one (G(| carrier := H |))"
ballarin@13817
   413
  by rule simp_all
ballarin@13936
   414
*)
ballarin@13813
   415
lemma (in subgroup) group_axiomsI [intro]:
ballarin@13813
   416
  includes group G
ballarin@13813
   417
  shows "group_axioms (G(| carrier := H |))"
ballarin@13936
   418
  by rule (auto intro: l_inv r_inv simp add: Units_def)
ballarin@13813
   419
ballarin@13813
   420
lemma (in subgroup) groupI [intro]:
ballarin@13813
   421
  includes group G
ballarin@13813
   422
  shows "group (G(| carrier := H |))"
ballarin@13936
   423
  by (rule groupI) (auto intro: m_assoc l_inv)
ballarin@13813
   424
ballarin@13813
   425
text {*
ballarin@13813
   426
  Since @{term H} is nonempty, it contains some element @{term x}.  Since
ballarin@13813
   427
  it is closed under inverse, it contains @{text "inv x"}.  Since
ballarin@13813
   428
  it is closed under product, it contains @{text "x \<otimes> inv x = \<one>"}.
ballarin@13813
   429
*}
ballarin@13813
   430
ballarin@13813
   431
lemma (in group) one_in_subset:
ballarin@13813
   432
  "[| H \<subseteq> carrier G; H \<noteq> {}; \<forall>a \<in> H. inv a \<in> H; \<forall>a\<in>H. \<forall>b\<in>H. a \<otimes> b \<in> H |]
ballarin@13813
   433
   ==> \<one> \<in> H"
ballarin@13813
   434
by (force simp add: l_inv)
ballarin@13813
   435
ballarin@13813
   436
text {* A characterization of subgroups: closed, non-empty subset. *}
ballarin@13813
   437
ballarin@13813
   438
lemma (in group) subgroupI:
ballarin@13813
   439
  assumes subset: "H \<subseteq> carrier G" and non_empty: "H \<noteq> {}"
ballarin@13813
   440
    and inv: "!!a. a \<in> H ==> inv a \<in> H"
ballarin@13813
   441
    and mult: "!!a b. [|a \<in> H; b \<in> H|] ==> a \<otimes> b \<in> H"
ballarin@13813
   442
  shows "subgroup H G"
ballarin@13813
   443
proof
ballarin@13813
   444
  from subset and mult show "submagma H G" ..
ballarin@13813
   445
next
ballarin@13813
   446
  have "\<one> \<in> H" by (rule one_in_subset) (auto simp only: prems)
ballarin@13813
   447
  with inv show "subgroup_axioms H G"
ballarin@13813
   448
    by (intro subgroup_axioms.intro) simp_all
ballarin@13813
   449
qed
ballarin@13813
   450
ballarin@13813
   451
text {*
ballarin@13813
   452
  Repeat facts of submagmas for subgroups.  Necessary???
ballarin@13813
   453
*}
ballarin@13813
   454
ballarin@13813
   455
lemma (in subgroup) subset:
ballarin@13813
   456
  "H \<subseteq> carrier G"
ballarin@13813
   457
  ..
ballarin@13813
   458
ballarin@13813
   459
lemma (in subgroup) m_closed:
ballarin@13813
   460
  "[| x \<in> H; y \<in> H |] ==> x \<otimes> y \<in> H"
ballarin@13813
   461
  ..
ballarin@13813
   462
ballarin@13813
   463
declare magma.m_closed [simp]
ballarin@13813
   464
ballarin@13936
   465
declare monoid.one_closed [iff] group.inv_closed [simp]
ballarin@13936
   466
  monoid.l_one [simp] monoid.r_one [simp] group.inv_inv [simp]
ballarin@13813
   467
ballarin@13813
   468
lemma subgroup_nonempty:
ballarin@13813
   469
  "~ subgroup {} G"
ballarin@13813
   470
  by (blast dest: subgroup.one_closed)
ballarin@13813
   471
ballarin@13813
   472
lemma (in subgroup) finite_imp_card_positive:
ballarin@13813
   473
  "finite (carrier G) ==> 0 < card H"
ballarin@13813
   474
proof (rule classical)
ballarin@13813
   475
  have sub: "subgroup H G" using prems ..
ballarin@13813
   476
  assume fin: "finite (carrier G)"
ballarin@13813
   477
    and zero: "~ 0 < card H"
ballarin@13813
   478
  then have "finite H" by (blast intro: finite_subset dest: subset)
ballarin@13813
   479
  with zero sub have "subgroup {} G" by simp
ballarin@13813
   480
  with subgroup_nonempty show ?thesis by contradiction
ballarin@13813
   481
qed
ballarin@13813
   482
ballarin@13936
   483
(*
ballarin@13936
   484
lemma (in monoid) Units_subgroup:
ballarin@13936
   485
  "subgroup (Units G) G"
ballarin@13936
   486
*)
ballarin@13936
   487
ballarin@13813
   488
subsection {* Direct Products *}
ballarin@13813
   489
ballarin@13813
   490
constdefs
ballarin@13817
   491
  DirProdSemigroup ::
ballarin@13854
   492
    "[('a, 'm) semigroup_scheme, ('b, 'n) semigroup_scheme]
ballarin@13817
   493
    => ('a \<times> 'b) semigroup"
ballarin@13817
   494
    (infixr "\<times>\<^sub>s" 80)
ballarin@13817
   495
  "G \<times>\<^sub>s H == (| carrier = carrier G \<times> carrier H,
ballarin@13817
   496
    mult = (%(xg, xh) (yg, yh). (mult G xg yg, mult H xh yh)) |)"
ballarin@13817
   497
ballarin@13936
   498
  DirProdGroup ::
ballarin@13854
   499
    "[('a, 'm) monoid_scheme, ('b, 'n) monoid_scheme] => ('a \<times> 'b) monoid"
ballarin@13936
   500
    (infixr "\<times>\<^sub>g" 80)
ballarin@13936
   501
  "G \<times>\<^sub>g H == (| carrier = carrier (G \<times>\<^sub>s H),
ballarin@13817
   502
    mult = mult (G \<times>\<^sub>s H),
ballarin@13817
   503
    one = (one G, one H) |)"
ballarin@13936
   504
(*
ballarin@13813
   505
  DirProdGroup ::
ballarin@13854
   506
    "[('a, 'm) group_scheme, ('b, 'n) group_scheme] => ('a \<times> 'b) group"
ballarin@13813
   507
    (infixr "\<times>\<^sub>g" 80)
ballarin@13813
   508
  "G \<times>\<^sub>g H == (| carrier = carrier (G \<times>\<^sub>m H),
ballarin@13813
   509
    mult = mult (G \<times>\<^sub>m H),
ballarin@13817
   510
    one = one (G \<times>\<^sub>m H),
ballarin@13813
   511
    m_inv = (%(g, h). (m_inv G g, m_inv H h)) |)"
ballarin@13936
   512
*)
ballarin@13813
   513
ballarin@13817
   514
lemma DirProdSemigroup_magma:
ballarin@13813
   515
  includes magma G + magma H
ballarin@13817
   516
  shows "magma (G \<times>\<^sub>s H)"
ballarin@13817
   517
  by rule (auto simp add: DirProdSemigroup_def)
ballarin@13813
   518
ballarin@13817
   519
lemma DirProdSemigroup_semigroup_axioms:
ballarin@13813
   520
  includes semigroup G + semigroup H
ballarin@13817
   521
  shows "semigroup_axioms (G \<times>\<^sub>s H)"
ballarin@13817
   522
  by rule (auto simp add: DirProdSemigroup_def G.m_assoc H.m_assoc)
ballarin@13813
   523
ballarin@13817
   524
lemma DirProdSemigroup_semigroup:
ballarin@13813
   525
  includes semigroup G + semigroup H
ballarin@13817
   526
  shows "semigroup (G \<times>\<^sub>s H)"
ballarin@13813
   527
  using prems
ballarin@13813
   528
  by (fast intro: semigroup.intro
ballarin@13817
   529
    DirProdSemigroup_magma DirProdSemigroup_semigroup_axioms)
ballarin@13813
   530
ballarin@13813
   531
lemma DirProdGroup_magma:
ballarin@13813
   532
  includes magma G + magma H
ballarin@13813
   533
  shows "magma (G \<times>\<^sub>g H)"
ballarin@13817
   534
  by rule
ballarin@13936
   535
    (auto simp add: DirProdGroup_def DirProdSemigroup_def)
ballarin@13813
   536
ballarin@13813
   537
lemma DirProdGroup_semigroup_axioms:
ballarin@13813
   538
  includes semigroup G + semigroup H
ballarin@13813
   539
  shows "semigroup_axioms (G \<times>\<^sub>g H)"
ballarin@13813
   540
  by rule
ballarin@13936
   541
    (auto simp add: DirProdGroup_def DirProdSemigroup_def
ballarin@13817
   542
      G.m_assoc H.m_assoc)
ballarin@13813
   543
ballarin@13813
   544
lemma DirProdGroup_semigroup:
ballarin@13813
   545
  includes semigroup G + semigroup H
ballarin@13813
   546
  shows "semigroup (G \<times>\<^sub>g H)"
ballarin@13813
   547
  using prems
ballarin@13813
   548
  by (fast intro: semigroup.intro
ballarin@13813
   549
    DirProdGroup_magma DirProdGroup_semigroup_axioms)
ballarin@13813
   550
ballarin@13813
   551
(* ... and further lemmas for group ... *)
ballarin@13813
   552
ballarin@13817
   553
lemma DirProdGroup_group:
ballarin@13813
   554
  includes group G + group H
ballarin@13813
   555
  shows "group (G \<times>\<^sub>g H)"
ballarin@13936
   556
  by (rule groupI)
ballarin@13936
   557
    (auto intro: G.m_assoc H.m_assoc G.l_inv H.l_inv
ballarin@13936
   558
      simp add: DirProdGroup_def DirProdSemigroup_def)
ballarin@13813
   559
ballarin@13813
   560
subsection {* Homomorphisms *}
ballarin@13813
   561
ballarin@13813
   562
constdefs
ballarin@13817
   563
  hom :: "[('a, 'c) semigroup_scheme, ('b, 'd) semigroup_scheme]
ballarin@13817
   564
    => ('a => 'b)set"
ballarin@13813
   565
  "hom G H ==
ballarin@13813
   566
    {h. h \<in> carrier G -> carrier H &
ballarin@13813
   567
      (\<forall>x \<in> carrier G. \<forall>y \<in> carrier G. h (mult G x y) = mult H (h x) (h y))}"
ballarin@13813
   568
ballarin@13813
   569
lemma (in semigroup) hom:
ballarin@13813
   570
  includes semigroup G
ballarin@13813
   571
  shows "semigroup (| carrier = hom G G, mult = op o |)"
ballarin@13813
   572
proof
ballarin@13813
   573
  show "magma (| carrier = hom G G, mult = op o |)"
ballarin@13813
   574
    by rule (simp add: Pi_def hom_def)
ballarin@13813
   575
next
ballarin@13813
   576
  show "semigroup_axioms (| carrier = hom G G, mult = op o |)"
ballarin@13813
   577
    by rule (simp add: o_assoc)
ballarin@13813
   578
qed
ballarin@13813
   579
ballarin@13813
   580
lemma hom_mult:
ballarin@13813
   581
  "[| h \<in> hom G H; x \<in> carrier G; y \<in> carrier G |] 
ballarin@13813
   582
   ==> h (mult G x y) = mult H (h x) (h y)"
ballarin@13813
   583
  by (simp add: hom_def) 
ballarin@13813
   584
ballarin@13813
   585
lemma hom_closed:
ballarin@13813
   586
  "[| h \<in> hom G H; x \<in> carrier G |] ==> h x \<in> carrier H"
ballarin@13813
   587
  by (auto simp add: hom_def funcset_mem)
ballarin@13813
   588
ballarin@13813
   589
locale group_hom = group G + group H + var h +
ballarin@13813
   590
  assumes homh: "h \<in> hom G H"
ballarin@13813
   591
  notes hom_mult [simp] = hom_mult [OF homh]
ballarin@13813
   592
    and hom_closed [simp] = hom_closed [OF homh]
ballarin@13813
   593
ballarin@13813
   594
lemma (in group_hom) one_closed [simp]:
ballarin@13813
   595
  "h \<one> \<in> carrier H"
ballarin@13813
   596
  by simp
ballarin@13813
   597
ballarin@13813
   598
lemma (in group_hom) hom_one [simp]:
ballarin@13813
   599
  "h \<one> = \<one>\<^sub>2"
ballarin@13813
   600
proof -
ballarin@13813
   601
  have "h \<one> \<otimes>\<^sub>2 \<one>\<^sub>2 = h \<one> \<otimes>\<^sub>2 h \<one>"
ballarin@13813
   602
    by (simp add: hom_mult [symmetric] del: hom_mult)
ballarin@13813
   603
  then show ?thesis by (simp del: r_one)
ballarin@13813
   604
qed
ballarin@13813
   605
ballarin@13813
   606
lemma (in group_hom) inv_closed [simp]:
ballarin@13813
   607
  "x \<in> carrier G ==> h (inv x) \<in> carrier H"
ballarin@13813
   608
  by simp
ballarin@13813
   609
ballarin@13813
   610
lemma (in group_hom) hom_inv [simp]:
ballarin@13813
   611
  "x \<in> carrier G ==> h (inv x) = inv\<^sub>2 (h x)"
ballarin@13813
   612
proof -
ballarin@13813
   613
  assume x: "x \<in> carrier G"
ballarin@13813
   614
  then have "h x \<otimes>\<^sub>2 h (inv x) = \<one>\<^sub>2"
ballarin@13813
   615
    by (simp add: hom_mult [symmetric] G.r_inv del: hom_mult)
ballarin@13813
   616
  also from x have "... = h x \<otimes>\<^sub>2 inv\<^sub>2 (h x)"
ballarin@13813
   617
    by (simp add: hom_mult [symmetric] H.r_inv del: hom_mult)
ballarin@13813
   618
  finally have "h x \<otimes>\<^sub>2 h (inv x) = h x \<otimes>\<^sub>2 inv\<^sub>2 (h x)" .
ballarin@13813
   619
  with x show ?thesis by simp
ballarin@13813
   620
qed
ballarin@13813
   621
ballarin@13936
   622
section {* Commutative Structures *}
ballarin@13936
   623
ballarin@13936
   624
text {*
ballarin@13936
   625
  Naming convention: multiplicative structures that are commutative
ballarin@13936
   626
  are called \emph{commutative}, additive structures are called
ballarin@13936
   627
  \emph{Abelian}.
ballarin@13936
   628
*}
ballarin@13813
   629
ballarin@13813
   630
subsection {* Definition *}
ballarin@13813
   631
ballarin@13936
   632
locale comm_semigroup = semigroup +
ballarin@13813
   633
  assumes m_comm: "[| x \<in> carrier G; y \<in> carrier G |] ==> x \<otimes> y = y \<otimes> x"
ballarin@13813
   634
ballarin@13936
   635
lemma (in comm_semigroup) m_lcomm:
ballarin@13813
   636
  "[| x \<in> carrier G; y \<in> carrier G; z \<in> carrier G |] ==>
ballarin@13813
   637
   x \<otimes> (y \<otimes> z) = y \<otimes> (x \<otimes> z)"
ballarin@13813
   638
proof -
ballarin@13813
   639
  assume xyz: "x \<in> carrier G" "y \<in> carrier G" "z \<in> carrier G"
ballarin@13813
   640
  from xyz have "x \<otimes> (y \<otimes> z) = (x \<otimes> y) \<otimes> z" by (simp add: m_assoc)
ballarin@13813
   641
  also from xyz have "... = (y \<otimes> x) \<otimes> z" by (simp add: m_comm)
ballarin@13813
   642
  also from xyz have "... = y \<otimes> (x \<otimes> z)" by (simp add: m_assoc)
ballarin@13813
   643
  finally show ?thesis .
ballarin@13813
   644
qed
ballarin@13813
   645
ballarin@13936
   646
lemmas (in comm_semigroup) m_ac = m_assoc m_comm m_lcomm
ballarin@13936
   647
ballarin@13936
   648
locale comm_monoid = comm_semigroup + monoid
ballarin@13813
   649
ballarin@13936
   650
lemma comm_monoidI:
ballarin@13936
   651
  assumes m_closed:
ballarin@13936
   652
      "!!x y. [| x \<in> carrier G; y \<in> carrier G |] ==> mult G x y \<in> carrier G"
ballarin@13936
   653
    and one_closed: "one G \<in> carrier G"
ballarin@13936
   654
    and m_assoc:
ballarin@13936
   655
      "!!x y z. [| x \<in> carrier G; y \<in> carrier G; z \<in> carrier G |] ==>
ballarin@13936
   656
      mult G (mult G x y) z = mult G x (mult G y z)"
ballarin@13936
   657
    and l_one: "!!x. x \<in> carrier G ==> mult G (one G) x = x"
ballarin@13936
   658
    and m_comm:
ballarin@13936
   659
      "!!x y. [| x \<in> carrier G; y \<in> carrier G |] ==> mult G x y = mult G y x"
ballarin@13936
   660
  shows "comm_monoid G"
ballarin@13936
   661
  using l_one
ballarin@13936
   662
  by (auto intro!: comm_monoid.intro magma.intro semigroup_axioms.intro
ballarin@13936
   663
    comm_semigroup_axioms.intro monoid_axioms.intro
ballarin@13936
   664
    intro: prems simp: m_closed one_closed m_comm)
ballarin@13817
   665
ballarin@13936
   666
lemma (in monoid) monoid_comm_monoidI:
ballarin@13936
   667
  assumes m_comm:
ballarin@13936
   668
      "!!x y. [| x \<in> carrier G; y \<in> carrier G |] ==> mult G x y = mult G y x"
ballarin@13936
   669
  shows "comm_monoid G"
ballarin@13936
   670
  by (rule comm_monoidI) (auto intro: m_assoc m_comm)
ballarin@13936
   671
(*
ballarin@13936
   672
lemma (in comm_monoid) r_one [simp]:
ballarin@13817
   673
  "x \<in> carrier G ==> x \<otimes> \<one> = x"
ballarin@13817
   674
proof -
ballarin@13817
   675
  assume G: "x \<in> carrier G"
ballarin@13817
   676
  then have "x \<otimes> \<one> = \<one> \<otimes> x" by (simp add: m_comm)
ballarin@13817
   677
  also from G have "... = x" by simp
ballarin@13817
   678
  finally show ?thesis .
ballarin@13817
   679
qed
ballarin@13936
   680
*)
ballarin@13817
   681
ballarin@13936
   682
lemma (in comm_monoid) nat_pow_distr:
ballarin@13936
   683
  "[| x \<in> carrier G; y \<in> carrier G |] ==>
ballarin@13936
   684
  (x \<otimes> y) (^) (n::nat) = x (^) n \<otimes> y (^) n"
ballarin@13936
   685
  by (induct n) (simp, simp add: m_ac)
ballarin@13936
   686
ballarin@13936
   687
locale comm_group = comm_monoid + group
ballarin@13936
   688
ballarin@13936
   689
lemma (in group) group_comm_groupI:
ballarin@13936
   690
  assumes m_comm: "!!x y. [| x \<in> carrier G; y \<in> carrier G |] ==>
ballarin@13936
   691
      mult G x y = mult G y x"
ballarin@13936
   692
  shows "comm_group G"
ballarin@13936
   693
  by (fast intro: comm_group.intro comm_semigroup_axioms.intro
ballarin@13936
   694
    group.axioms prems)
ballarin@13817
   695
ballarin@13936
   696
lemma comm_groupI:
ballarin@13936
   697
  assumes m_closed:
ballarin@13936
   698
      "!!x y. [| x \<in> carrier G; y \<in> carrier G |] ==> mult G x y \<in> carrier G"
ballarin@13936
   699
    and one_closed: "one G \<in> carrier G"
ballarin@13936
   700
    and m_assoc:
ballarin@13936
   701
      "!!x y z. [| x \<in> carrier G; y \<in> carrier G; z \<in> carrier G |] ==>
ballarin@13936
   702
      mult G (mult G x y) z = mult G x (mult G y z)"
ballarin@13936
   703
    and m_comm:
ballarin@13936
   704
      "!!x y. [| x \<in> carrier G; y \<in> carrier G |] ==> mult G x y = mult G y x"
ballarin@13936
   705
    and l_one: "!!x. x \<in> carrier G ==> mult G (one G) x = x"
ballarin@13936
   706
    and l_inv_ex: "!!x. x \<in> carrier G ==> EX y : carrier G. mult G y x = one G"
ballarin@13936
   707
  shows "comm_group G"
ballarin@13936
   708
  by (fast intro: group.group_comm_groupI groupI prems)
ballarin@13936
   709
ballarin@13936
   710
lemma (in comm_group) inv_mult:
ballarin@13854
   711
  "[| x \<in> carrier G; y \<in> carrier G |] ==> inv (x \<otimes> y) = inv x \<otimes> inv y"
ballarin@13936
   712
  by (simp add: m_ac inv_mult_group)
ballarin@13854
   713
ballarin@13813
   714
end