src/HOL/Algebra/Group.thy
author paulson
Tue Jun 01 11:25:01 2004 +0200 (2004-06-01)
changeset 14852 fffab59e0050
parent 14803 f7557773cc87
child 14963 d584e32f7d46
permissions -rw-r--r--
tidied
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@13949
     9
header {* Groups *}
ballarin@13813
    10
ballarin@14751
    11
theory Group = FuncSet + Lattice:
ballarin@13813
    12
paulson@14761
    13
ballarin@13936
    14
section {* From Magmas to Groups *}
ballarin@13936
    15
ballarin@13813
    16
text {*
wenzelm@14706
    17
  Definitions follow \cite{Jacobson:1985}; with the exception of
wenzelm@14706
    18
  \emph{magma} which, following Bourbaki, is a set together with a
wenzelm@14706
    19
  binary, closed operation.
ballarin@13813
    20
*}
ballarin@13813
    21
ballarin@13813
    22
subsection {* Definitions *}
ballarin@13813
    23
ballarin@14286
    24
record 'a semigroup = "'a partial_object" +
ballarin@13813
    25
  mult :: "['a, 'a] => 'a" (infixl "\<otimes>\<index>" 70)
ballarin@13813
    26
ballarin@13817
    27
record 'a monoid = "'a semigroup" +
ballarin@13813
    28
  one :: 'a ("\<one>\<index>")
ballarin@13817
    29
wenzelm@14651
    30
constdefs (structure G)
paulson@14852
    31
  m_inv :: "('a, 'b) monoid_scheme => 'a => 'a" ("inv\<index> _" [81] 80)
wenzelm@14651
    32
  "inv x == (THE y. y \<in> carrier G & x \<otimes> y = \<one> & y \<otimes> x = \<one>)"
ballarin@13936
    33
wenzelm@14651
    34
  Units :: "_ => 'a set"
paulson@14852
    35
  --{*The set of invertible elements*}
wenzelm@14651
    36
  "Units G == {y. y \<in> carrier G & (EX x : carrier G. x \<otimes> y = \<one> & y \<otimes> x = \<one>)}"
ballarin@13936
    37
ballarin@13936
    38
consts
ballarin@13936
    39
  pow :: "[('a, 'm) monoid_scheme, 'a, 'b::number] => 'a" (infixr "'(^')\<index>" 75)
ballarin@13936
    40
ballarin@13936
    41
defs (overloaded)
wenzelm@14693
    42
  nat_pow_def: "pow G a n == nat_rec \<one>\<^bsub>G\<^esub> (%u b. b \<otimes>\<^bsub>G\<^esub> a) n"
ballarin@13936
    43
  int_pow_def: "pow G a z ==
wenzelm@14693
    44
    let p = nat_rec \<one>\<^bsub>G\<^esub> (%u b. b \<otimes>\<^bsub>G\<^esub> a)
wenzelm@14693
    45
    in if neg z then inv\<^bsub>G\<^esub> (p (nat (-z))) else p (nat z)"
ballarin@13813
    46
ballarin@13813
    47
locale magma = struct G +
ballarin@13813
    48
  assumes m_closed [intro, simp]:
ballarin@13813
    49
    "[| x \<in> carrier G; y \<in> carrier G |] ==> x \<otimes> y \<in> carrier G"
ballarin@13813
    50
ballarin@13813
    51
locale semigroup = magma +
ballarin@13813
    52
  assumes m_assoc:
ballarin@13813
    53
    "[| x \<in> carrier G; y \<in> carrier G; z \<in> carrier G |] ==>
ballarin@13936
    54
    (x \<otimes> y) \<otimes> z = x \<otimes> (y \<otimes> z)"
ballarin@13813
    55
ballarin@13936
    56
locale monoid = semigroup +
ballarin@13813
    57
  assumes one_closed [intro, simp]: "\<one> \<in> carrier G"
ballarin@13813
    58
    and l_one [simp]: "x \<in> carrier G ==> \<one> \<otimes> x = x"
ballarin@13936
    59
    and r_one [simp]: "x \<in> carrier G ==> x \<otimes> \<one> = x"
ballarin@13817
    60
ballarin@13936
    61
lemma monoidI:
wenzelm@14693
    62
  includes struct G
ballarin@13936
    63
  assumes m_closed:
wenzelm@14693
    64
      "!!x y. [| x \<in> carrier G; y \<in> carrier G |] ==> x \<otimes> y \<in> carrier G"
wenzelm@14693
    65
    and one_closed: "\<one> \<in> carrier G"
ballarin@13936
    66
    and m_assoc:
ballarin@13936
    67
      "!!x y z. [| x \<in> carrier G; y \<in> carrier G; z \<in> carrier G |] ==>
wenzelm@14693
    68
      (x \<otimes> y) \<otimes> z = x \<otimes> (y \<otimes> z)"
wenzelm@14693
    69
    and l_one: "!!x. x \<in> carrier G ==> \<one> \<otimes> x = x"
wenzelm@14693
    70
    and r_one: "!!x. x \<in> carrier G ==> x \<otimes> \<one> = x"
ballarin@13936
    71
  shows "monoid G"
ballarin@13936
    72
  by (fast intro!: monoid.intro magma.intro semigroup_axioms.intro
ballarin@13936
    73
    semigroup.intro monoid_axioms.intro
ballarin@13936
    74
    intro: prems)
ballarin@13936
    75
ballarin@13936
    76
lemma (in monoid) Units_closed [dest]:
ballarin@13936
    77
  "x \<in> Units G ==> x \<in> carrier G"
ballarin@13936
    78
  by (unfold Units_def) fast
ballarin@13936
    79
ballarin@13936
    80
lemma (in monoid) inv_unique:
wenzelm@14693
    81
  assumes eq: "y \<otimes> x = \<one>"  "x \<otimes> y' = \<one>"
wenzelm@14693
    82
    and G: "x \<in> carrier G"  "y \<in> carrier G"  "y' \<in> carrier G"
ballarin@13936
    83
  shows "y = y'"
ballarin@13936
    84
proof -
ballarin@13936
    85
  from G eq have "y = y \<otimes> (x \<otimes> y')" by simp
ballarin@13936
    86
  also from G have "... = (y \<otimes> x) \<otimes> y'" by (simp add: m_assoc)
ballarin@13936
    87
  also from G eq have "... = y'" by simp
ballarin@13936
    88
  finally show ?thesis .
ballarin@13936
    89
qed
ballarin@13936
    90
ballarin@13940
    91
lemma (in monoid) Units_one_closed [intro, simp]:
ballarin@13940
    92
  "\<one> \<in> Units G"
ballarin@13940
    93
  by (unfold Units_def) auto
ballarin@13940
    94
ballarin@13936
    95
lemma (in monoid) Units_inv_closed [intro, simp]:
ballarin@13936
    96
  "x \<in> Units G ==> inv x \<in> carrier G"
paulson@13943
    97
  apply (unfold Units_def m_inv_def, auto)
ballarin@13936
    98
  apply (rule theI2, fast)
paulson@13943
    99
   apply (fast intro: inv_unique, fast)
ballarin@13936
   100
  done
ballarin@13936
   101
ballarin@13936
   102
lemma (in monoid) Units_l_inv:
ballarin@13936
   103
  "x \<in> Units G ==> inv x \<otimes> x = \<one>"
paulson@13943
   104
  apply (unfold Units_def m_inv_def, auto)
ballarin@13936
   105
  apply (rule theI2, fast)
paulson@13943
   106
   apply (fast intro: inv_unique, fast)
ballarin@13936
   107
  done
ballarin@13936
   108
ballarin@13936
   109
lemma (in monoid) Units_r_inv:
ballarin@13936
   110
  "x \<in> Units G ==> x \<otimes> inv x = \<one>"
paulson@13943
   111
  apply (unfold Units_def m_inv_def, auto)
ballarin@13936
   112
  apply (rule theI2, fast)
paulson@13943
   113
   apply (fast intro: inv_unique, fast)
ballarin@13936
   114
  done
ballarin@13936
   115
ballarin@13936
   116
lemma (in monoid) Units_inv_Units [intro, simp]:
ballarin@13936
   117
  "x \<in> Units G ==> inv x \<in> Units G"
ballarin@13936
   118
proof -
ballarin@13936
   119
  assume x: "x \<in> Units G"
ballarin@13936
   120
  show "inv x \<in> Units G"
ballarin@13936
   121
    by (auto simp add: Units_def
ballarin@13936
   122
      intro: Units_l_inv Units_r_inv x Units_closed [OF x])
ballarin@13936
   123
qed
ballarin@13936
   124
ballarin@13936
   125
lemma (in monoid) Units_l_cancel [simp]:
ballarin@13936
   126
  "[| x \<in> Units G; y \<in> carrier G; z \<in> carrier G |] ==>
ballarin@13936
   127
   (x \<otimes> y = x \<otimes> z) = (y = z)"
ballarin@13936
   128
proof
ballarin@13936
   129
  assume eq: "x \<otimes> y = x \<otimes> z"
wenzelm@14693
   130
    and G: "x \<in> Units G"  "y \<in> carrier G"  "z \<in> carrier G"
ballarin@13936
   131
  then have "(inv x \<otimes> x) \<otimes> y = (inv x \<otimes> x) \<otimes> z"
ballarin@13936
   132
    by (simp add: m_assoc Units_closed)
ballarin@13936
   133
  with G show "y = z" by (simp add: Units_l_inv)
ballarin@13936
   134
next
ballarin@13936
   135
  assume eq: "y = z"
wenzelm@14693
   136
    and G: "x \<in> Units G"  "y \<in> carrier G"  "z \<in> carrier G"
ballarin@13936
   137
  then show "x \<otimes> y = x \<otimes> z" by simp
ballarin@13936
   138
qed
ballarin@13936
   139
ballarin@13936
   140
lemma (in monoid) Units_inv_inv [simp]:
ballarin@13936
   141
  "x \<in> Units G ==> inv (inv x) = x"
ballarin@13936
   142
proof -
ballarin@13936
   143
  assume x: "x \<in> Units G"
ballarin@13936
   144
  then have "inv x \<otimes> inv (inv x) = inv x \<otimes> x"
ballarin@13936
   145
    by (simp add: Units_l_inv Units_r_inv)
ballarin@13936
   146
  with x show ?thesis by (simp add: Units_closed)
ballarin@13936
   147
qed
ballarin@13936
   148
ballarin@13936
   149
lemma (in monoid) inv_inj_on_Units:
ballarin@13936
   150
  "inj_on (m_inv G) (Units G)"
ballarin@13936
   151
proof (rule inj_onI)
ballarin@13936
   152
  fix x y
wenzelm@14693
   153
  assume G: "x \<in> Units G"  "y \<in> Units G" and eq: "inv x = inv y"
ballarin@13936
   154
  then have "inv (inv x) = inv (inv y)" by simp
ballarin@13936
   155
  with G show "x = y" by simp
ballarin@13936
   156
qed
ballarin@13936
   157
ballarin@13940
   158
lemma (in monoid) Units_inv_comm:
ballarin@13940
   159
  assumes inv: "x \<otimes> y = \<one>"
wenzelm@14693
   160
    and G: "x \<in> Units G"  "y \<in> Units G"
ballarin@13940
   161
  shows "y \<otimes> x = \<one>"
ballarin@13940
   162
proof -
ballarin@13940
   163
  from G have "x \<otimes> y \<otimes> x = x \<otimes> \<one>" by (auto simp add: inv Units_closed)
ballarin@13940
   164
  with G show ?thesis by (simp del: r_one add: m_assoc Units_closed)
ballarin@13940
   165
qed
ballarin@13940
   166
ballarin@13936
   167
text {* Power *}
ballarin@13936
   168
ballarin@13936
   169
lemma (in monoid) nat_pow_closed [intro, simp]:
ballarin@13936
   170
  "x \<in> carrier G ==> x (^) (n::nat) \<in> carrier G"
ballarin@13936
   171
  by (induct n) (simp_all add: nat_pow_def)
ballarin@13936
   172
ballarin@13936
   173
lemma (in monoid) nat_pow_0 [simp]:
ballarin@13936
   174
  "x (^) (0::nat) = \<one>"
ballarin@13936
   175
  by (simp add: nat_pow_def)
ballarin@13936
   176
ballarin@13936
   177
lemma (in monoid) nat_pow_Suc [simp]:
ballarin@13936
   178
  "x (^) (Suc n) = x (^) n \<otimes> x"
ballarin@13936
   179
  by (simp add: nat_pow_def)
ballarin@13936
   180
ballarin@13936
   181
lemma (in monoid) nat_pow_one [simp]:
ballarin@13936
   182
  "\<one> (^) (n::nat) = \<one>"
ballarin@13936
   183
  by (induct n) simp_all
ballarin@13936
   184
ballarin@13936
   185
lemma (in monoid) nat_pow_mult:
ballarin@13936
   186
  "x \<in> carrier G ==> x (^) (n::nat) \<otimes> x (^) m = x (^) (n + m)"
ballarin@13936
   187
  by (induct m) (simp_all add: m_assoc [THEN sym])
ballarin@13936
   188
ballarin@13936
   189
lemma (in monoid) nat_pow_pow:
ballarin@13936
   190
  "x \<in> carrier G ==> (x (^) n) (^) m = x (^) (n * m::nat)"
ballarin@13936
   191
  by (induct m) (simp, simp add: nat_pow_mult add_commute)
ballarin@13936
   192
ballarin@13936
   193
text {*
ballarin@13936
   194
  A group is a monoid all of whose elements are invertible.
ballarin@13936
   195
*}
ballarin@13936
   196
ballarin@13936
   197
locale group = monoid +
ballarin@13936
   198
  assumes Units: "carrier G <= Units G"
ballarin@13936
   199
paulson@14761
   200
paulson@14761
   201
lemma (in group) is_group: "group G"
paulson@14761
   202
  by (rule group.intro [OF prems]) 
paulson@14761
   203
ballarin@13936
   204
theorem groupI:
wenzelm@14693
   205
  includes struct G
ballarin@13936
   206
  assumes m_closed [simp]:
wenzelm@14693
   207
      "!!x y. [| x \<in> carrier G; y \<in> carrier G |] ==> x \<otimes> y \<in> carrier G"
wenzelm@14693
   208
    and one_closed [simp]: "\<one> \<in> carrier G"
ballarin@13936
   209
    and m_assoc:
ballarin@13936
   210
      "!!x y z. [| x \<in> carrier G; y \<in> carrier G; z \<in> carrier G |] ==>
wenzelm@14693
   211
      (x \<otimes> y) \<otimes> z = x \<otimes> (y \<otimes> z)"
wenzelm@14693
   212
    and l_one [simp]: "!!x. x \<in> carrier G ==> \<one> \<otimes> x = x"
wenzelm@14693
   213
    and l_inv_ex: "!!x. x \<in> carrier G ==> EX y : carrier G. y \<otimes> x = \<one>"
ballarin@13936
   214
  shows "group G"
ballarin@13936
   215
proof -
ballarin@13936
   216
  have l_cancel [simp]:
ballarin@13936
   217
    "!!x y z. [| x \<in> carrier G; y \<in> carrier G; z \<in> carrier G |] ==>
wenzelm@14693
   218
    (x \<otimes> y = x \<otimes> z) = (y = z)"
ballarin@13936
   219
  proof
ballarin@13936
   220
    fix x y z
wenzelm@14693
   221
    assume eq: "x \<otimes> y = x \<otimes> z"
wenzelm@14693
   222
      and G: "x \<in> carrier G"  "y \<in> carrier G"  "z \<in> carrier G"
ballarin@13936
   223
    with l_inv_ex obtain x_inv where xG: "x_inv \<in> carrier G"
wenzelm@14693
   224
      and l_inv: "x_inv \<otimes> x = \<one>" by fast
wenzelm@14693
   225
    from G eq xG have "(x_inv \<otimes> x) \<otimes> y = (x_inv \<otimes> x) \<otimes> z"
ballarin@13936
   226
      by (simp add: m_assoc)
ballarin@13936
   227
    with G show "y = z" by (simp add: l_inv)
ballarin@13936
   228
  next
ballarin@13936
   229
    fix x y z
ballarin@13936
   230
    assume eq: "y = z"
wenzelm@14693
   231
      and G: "x \<in> carrier G"  "y \<in> carrier G"  "z \<in> carrier G"
wenzelm@14693
   232
    then show "x \<otimes> y = x \<otimes> z" by simp
ballarin@13936
   233
  qed
ballarin@13936
   234
  have r_one:
wenzelm@14693
   235
    "!!x. x \<in> carrier G ==> x \<otimes> \<one> = x"
ballarin@13936
   236
  proof -
ballarin@13936
   237
    fix x
ballarin@13936
   238
    assume x: "x \<in> carrier G"
ballarin@13936
   239
    with l_inv_ex obtain x_inv where xG: "x_inv \<in> carrier G"
wenzelm@14693
   240
      and l_inv: "x_inv \<otimes> x = \<one>" by fast
wenzelm@14693
   241
    from x xG have "x_inv \<otimes> (x \<otimes> \<one>) = x_inv \<otimes> x"
ballarin@13936
   242
      by (simp add: m_assoc [symmetric] l_inv)
wenzelm@14693
   243
    with x xG show "x \<otimes> \<one> = x" by simp
ballarin@13936
   244
  qed
ballarin@13936
   245
  have inv_ex:
wenzelm@14693
   246
    "!!x. x \<in> carrier G ==> EX y : carrier G. y \<otimes> x = \<one> & x \<otimes> y = \<one>"
ballarin@13936
   247
  proof -
ballarin@13936
   248
    fix x
ballarin@13936
   249
    assume x: "x \<in> carrier G"
ballarin@13936
   250
    with l_inv_ex obtain y where y: "y \<in> carrier G"
wenzelm@14693
   251
      and l_inv: "y \<otimes> x = \<one>" by fast
wenzelm@14693
   252
    from x y have "y \<otimes> (x \<otimes> y) = y \<otimes> \<one>"
ballarin@13936
   253
      by (simp add: m_assoc [symmetric] l_inv r_one)
wenzelm@14693
   254
    with x y have r_inv: "x \<otimes> y = \<one>"
ballarin@13936
   255
      by simp
wenzelm@14693
   256
    from x y show "EX y : carrier G. y \<otimes> x = \<one> & x \<otimes> y = \<one>"
ballarin@13936
   257
      by (fast intro: l_inv r_inv)
ballarin@13936
   258
  qed
ballarin@13936
   259
  then have carrier_subset_Units: "carrier G <= Units G"
ballarin@13936
   260
    by (unfold Units_def) fast
ballarin@13936
   261
  show ?thesis
ballarin@13936
   262
    by (fast intro!: group.intro magma.intro semigroup_axioms.intro
ballarin@13936
   263
      semigroup.intro monoid_axioms.intro group_axioms.intro
ballarin@13936
   264
      carrier_subset_Units intro: prems r_one)
ballarin@13936
   265
qed
ballarin@13936
   266
ballarin@13936
   267
lemma (in monoid) monoid_groupI:
ballarin@13936
   268
  assumes l_inv_ex:
wenzelm@14693
   269
    "!!x. x \<in> carrier G ==> EX y : carrier G. y \<otimes> x = \<one>"
ballarin@13936
   270
  shows "group G"
ballarin@13936
   271
  by (rule groupI) (auto intro: m_assoc l_inv_ex)
ballarin@13936
   272
ballarin@13936
   273
lemma (in group) Units_eq [simp]:
ballarin@13936
   274
  "Units G = carrier G"
ballarin@13936
   275
proof
ballarin@13936
   276
  show "Units G <= carrier G" by fast
ballarin@13936
   277
next
ballarin@13936
   278
  show "carrier G <= Units G" by (rule Units)
ballarin@13936
   279
qed
ballarin@13936
   280
ballarin@13936
   281
lemma (in group) inv_closed [intro, simp]:
ballarin@13936
   282
  "x \<in> carrier G ==> inv x \<in> carrier G"
ballarin@13936
   283
  using Units_inv_closed by simp
ballarin@13936
   284
ballarin@13936
   285
lemma (in group) l_inv:
ballarin@13936
   286
  "x \<in> carrier G ==> inv x \<otimes> x = \<one>"
ballarin@13936
   287
  using Units_l_inv by simp
ballarin@13813
   288
ballarin@13813
   289
subsection {* Cancellation Laws and Basic Properties *}
ballarin@13813
   290
ballarin@13813
   291
lemma (in group) l_cancel [simp]:
ballarin@13813
   292
  "[| x \<in> carrier G; y \<in> carrier G; z \<in> carrier G |] ==>
ballarin@13813
   293
   (x \<otimes> y = x \<otimes> z) = (y = z)"
ballarin@13936
   294
  using Units_l_inv by simp
ballarin@13940
   295
ballarin@13813
   296
lemma (in group) r_inv:
ballarin@13813
   297
  "x \<in> carrier G ==> x \<otimes> inv x = \<one>"
ballarin@13813
   298
proof -
ballarin@13813
   299
  assume x: "x \<in> carrier G"
ballarin@13813
   300
  then have "inv x \<otimes> (x \<otimes> inv x) = inv x \<otimes> \<one>"
ballarin@13813
   301
    by (simp add: m_assoc [symmetric] l_inv)
ballarin@13813
   302
  with x show ?thesis by (simp del: r_one)
ballarin@13813
   303
qed
ballarin@13813
   304
ballarin@13813
   305
lemma (in group) r_cancel [simp]:
ballarin@13813
   306
  "[| x \<in> carrier G; y \<in> carrier G; z \<in> carrier G |] ==>
ballarin@13813
   307
   (y \<otimes> x = z \<otimes> x) = (y = z)"
ballarin@13813
   308
proof
ballarin@13813
   309
  assume eq: "y \<otimes> x = z \<otimes> x"
wenzelm@14693
   310
    and G: "x \<in> carrier G"  "y \<in> carrier G"  "z \<in> carrier G"
ballarin@13813
   311
  then have "y \<otimes> (x \<otimes> inv x) = z \<otimes> (x \<otimes> inv x)"
ballarin@13813
   312
    by (simp add: m_assoc [symmetric])
ballarin@13813
   313
  with G show "y = z" by (simp add: r_inv)
ballarin@13813
   314
next
ballarin@13813
   315
  assume eq: "y = z"
wenzelm@14693
   316
    and G: "x \<in> carrier G"  "y \<in> carrier G"  "z \<in> carrier G"
ballarin@13813
   317
  then show "y \<otimes> x = z \<otimes> x" by simp
ballarin@13813
   318
qed
ballarin@13813
   319
ballarin@13854
   320
lemma (in group) inv_one [simp]:
ballarin@13854
   321
  "inv \<one> = \<one>"
ballarin@13854
   322
proof -
ballarin@13854
   323
  have "inv \<one> = \<one> \<otimes> (inv \<one>)" by simp
ballarin@13854
   324
  moreover have "... = \<one>" by (simp add: r_inv)
ballarin@13854
   325
  finally show ?thesis .
ballarin@13854
   326
qed
ballarin@13854
   327
ballarin@13813
   328
lemma (in group) inv_inv [simp]:
ballarin@13813
   329
  "x \<in> carrier G ==> inv (inv x) = x"
ballarin@13936
   330
  using Units_inv_inv by simp
ballarin@13936
   331
ballarin@13936
   332
lemma (in group) inv_inj:
ballarin@13936
   333
  "inj_on (m_inv G) (carrier G)"
ballarin@13936
   334
  using inv_inj_on_Units by simp
ballarin@13813
   335
ballarin@13854
   336
lemma (in group) inv_mult_group:
ballarin@13813
   337
  "[| x \<in> carrier G; y \<in> carrier G |] ==> inv (x \<otimes> y) = inv y \<otimes> inv x"
ballarin@13813
   338
proof -
wenzelm@14693
   339
  assume G: "x \<in> carrier G"  "y \<in> carrier G"
ballarin@13813
   340
  then have "inv (x \<otimes> y) \<otimes> (x \<otimes> y) = (inv y \<otimes> inv x) \<otimes> (x \<otimes> y)"
ballarin@13813
   341
    by (simp add: m_assoc l_inv) (simp add: m_assoc [symmetric] l_inv)
ballarin@13813
   342
  with G show ?thesis by simp
ballarin@13813
   343
qed
ballarin@13813
   344
ballarin@13940
   345
lemma (in group) inv_comm:
ballarin@13940
   346
  "[| x \<otimes> y = \<one>; x \<in> carrier G; y \<in> carrier G |] ==> y \<otimes> x = \<one>"
wenzelm@14693
   347
  by (rule Units_inv_comm) auto
ballarin@13940
   348
paulson@13944
   349
lemma (in group) inv_equality:
paulson@13943
   350
     "[|y \<otimes> x = \<one>; x \<in> carrier G; y \<in> carrier G|] ==> inv x = y"
paulson@13943
   351
apply (simp add: m_inv_def)
paulson@13943
   352
apply (rule the_equality)
wenzelm@14693
   353
 apply (simp add: inv_comm [of y x])
wenzelm@14693
   354
apply (rule r_cancel [THEN iffD1], auto)
paulson@13943
   355
done
paulson@13943
   356
ballarin@13936
   357
text {* Power *}
ballarin@13936
   358
ballarin@13936
   359
lemma (in group) int_pow_def2:
ballarin@13936
   360
  "a (^) (z::int) = (if neg z then inv (a (^) (nat (-z))) else a (^) (nat z))"
ballarin@13936
   361
  by (simp add: int_pow_def nat_pow_def Let_def)
ballarin@13936
   362
ballarin@13936
   363
lemma (in group) int_pow_0 [simp]:
ballarin@13936
   364
  "x (^) (0::int) = \<one>"
ballarin@13936
   365
  by (simp add: int_pow_def2)
ballarin@13936
   366
ballarin@13936
   367
lemma (in group) int_pow_one [simp]:
ballarin@13936
   368
  "\<one> (^) (z::int) = \<one>"
ballarin@13936
   369
  by (simp add: int_pow_def2)
ballarin@13936
   370
ballarin@13813
   371
subsection {* Substructures *}
ballarin@13813
   372
ballarin@13813
   373
locale submagma = var H + struct G +
ballarin@13813
   374
  assumes subset [intro, simp]: "H \<subseteq> carrier G"
ballarin@13813
   375
    and m_closed [intro, simp]: "[| x \<in> H; y \<in> H |] ==> x \<otimes> y \<in> H"
ballarin@13813
   376
ballarin@13813
   377
declare (in submagma) magma.intro [intro] semigroup.intro [intro]
ballarin@13936
   378
  semigroup_axioms.intro [intro]
ballarin@13813
   379
ballarin@13813
   380
lemma submagma_imp_subset:
ballarin@13813
   381
  "submagma H G ==> H \<subseteq> carrier G"
ballarin@13813
   382
  by (rule submagma.subset)
ballarin@13813
   383
ballarin@13813
   384
lemma (in submagma) subsetD [dest, simp]:
ballarin@13813
   385
  "x \<in> H ==> x \<in> carrier G"
ballarin@13813
   386
  using subset by blast
ballarin@13813
   387
ballarin@13813
   388
lemma (in submagma) magmaI [intro]:
ballarin@13813
   389
  includes magma G
ballarin@13813
   390
  shows "magma (G(| carrier := H |))"
ballarin@13813
   391
  by rule simp
ballarin@13813
   392
ballarin@13813
   393
lemma (in submagma) semigroup_axiomsI [intro]:
ballarin@13813
   394
  includes semigroup G
ballarin@13813
   395
  shows "semigroup_axioms (G(| carrier := H |))"
ballarin@13813
   396
    by rule (simp add: m_assoc)
ballarin@13813
   397
ballarin@13813
   398
lemma (in submagma) semigroupI [intro]:
ballarin@13813
   399
  includes semigroup G
ballarin@13813
   400
  shows "semigroup (G(| carrier := H |))"
ballarin@13813
   401
  using prems by fast
ballarin@13813
   402
ballarin@14551
   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@13949
   409
ballarin@13813
   410
lemma (in subgroup) group_axiomsI [intro]:
ballarin@13813
   411
  includes group G
ballarin@13813
   412
  shows "group_axioms (G(| carrier := H |))"
ballarin@14254
   413
  by (rule group_axioms.intro) (auto intro: l_inv r_inv simp add: Units_def)
ballarin@13813
   414
ballarin@13813
   415
lemma (in subgroup) groupI [intro]:
ballarin@13813
   416
  includes group G
ballarin@13813
   417
  shows "group (G(| carrier := H |))"
ballarin@13936
   418
  by (rule groupI) (auto intro: m_assoc l_inv)
ballarin@13813
   419
ballarin@13813
   420
text {*
ballarin@13813
   421
  Since @{term H} is nonempty, it contains some element @{term x}.  Since
ballarin@13813
   422
  it is closed under inverse, it contains @{text "inv x"}.  Since
ballarin@13813
   423
  it is closed under product, it contains @{text "x \<otimes> inv x = \<one>"}.
ballarin@13813
   424
*}
ballarin@13813
   425
ballarin@13813
   426
lemma (in group) one_in_subset:
ballarin@13813
   427
  "[| 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
   428
   ==> \<one> \<in> H"
ballarin@13813
   429
by (force simp add: l_inv)
ballarin@13813
   430
ballarin@13813
   431
text {* A characterization of subgroups: closed, non-empty subset. *}
ballarin@13813
   432
ballarin@13813
   433
lemma (in group) subgroupI:
ballarin@13813
   434
  assumes subset: "H \<subseteq> carrier G" and non_empty: "H \<noteq> {}"
ballarin@13813
   435
    and inv: "!!a. a \<in> H ==> inv a \<in> H"
ballarin@13813
   436
    and mult: "!!a b. [|a \<in> H; b \<in> H|] ==> a \<otimes> b \<in> H"
ballarin@13813
   437
  shows "subgroup H G"
ballarin@14254
   438
proof (rule subgroup.intro)
ballarin@14254
   439
  from subset and mult show "submagma H G" by (rule submagma.intro)
ballarin@13813
   440
next
ballarin@13813
   441
  have "\<one> \<in> H" by (rule one_in_subset) (auto simp only: prems)
ballarin@13813
   442
  with inv show "subgroup_axioms H G"
ballarin@13813
   443
    by (intro subgroup_axioms.intro) simp_all
ballarin@13813
   444
qed
ballarin@13813
   445
ballarin@13813
   446
text {*
ballarin@13813
   447
  Repeat facts of submagmas for subgroups.  Necessary???
ballarin@13813
   448
*}
ballarin@13813
   449
ballarin@13813
   450
lemma (in subgroup) subset:
ballarin@13813
   451
  "H \<subseteq> carrier G"
ballarin@13813
   452
  ..
ballarin@13813
   453
ballarin@13813
   454
lemma (in subgroup) m_closed:
ballarin@13813
   455
  "[| x \<in> H; y \<in> H |] ==> x \<otimes> y \<in> H"
ballarin@13813
   456
  ..
ballarin@13813
   457
ballarin@13813
   458
declare magma.m_closed [simp]
ballarin@13813
   459
ballarin@13936
   460
declare monoid.one_closed [iff] group.inv_closed [simp]
ballarin@13936
   461
  monoid.l_one [simp] monoid.r_one [simp] group.inv_inv [simp]
ballarin@13813
   462
ballarin@13813
   463
lemma subgroup_nonempty:
ballarin@13813
   464
  "~ subgroup {} G"
ballarin@13813
   465
  by (blast dest: subgroup.one_closed)
ballarin@13813
   466
ballarin@13813
   467
lemma (in subgroup) finite_imp_card_positive:
ballarin@13813
   468
  "finite (carrier G) ==> 0 < card H"
ballarin@13813
   469
proof (rule classical)
ballarin@14254
   470
  have sub: "subgroup H G" using prems by (rule subgroup.intro)
ballarin@13813
   471
  assume fin: "finite (carrier G)"
ballarin@13813
   472
    and zero: "~ 0 < card H"
ballarin@13813
   473
  then have "finite H" by (blast intro: finite_subset dest: subset)
ballarin@13813
   474
  with zero sub have "subgroup {} G" by simp
ballarin@13813
   475
  with subgroup_nonempty show ?thesis by contradiction
ballarin@13813
   476
qed
ballarin@13813
   477
ballarin@13936
   478
(*
ballarin@13936
   479
lemma (in monoid) Units_subgroup:
ballarin@13936
   480
  "subgroup (Units G) G"
ballarin@13936
   481
*)
ballarin@13936
   482
ballarin@13813
   483
subsection {* Direct Products *}
ballarin@13813
   484
wenzelm@14651
   485
constdefs (structure G and H)
wenzelm@14651
   486
  DirProdSemigroup :: "_ => _ => ('a \<times> 'b) semigroup"  (infixr "\<times>\<^sub>s" 80)
ballarin@13817
   487
  "G \<times>\<^sub>s H == (| carrier = carrier G \<times> carrier H,
wenzelm@14693
   488
    mult = (%(g, h) (g', h'). (g \<otimes>\<^bsub>G\<^esub> g', h \<otimes>\<^bsub>H\<^esub> h')) |)"
ballarin@13817
   489
wenzelm@14651
   490
  DirProdGroup :: "_ => _ => ('a \<times> 'b) monoid"  (infixr "\<times>\<^sub>g" 80)
wenzelm@14693
   491
  "G \<times>\<^sub>g H == semigroup.extend (G \<times>\<^sub>s H) (| one = (\<one>\<^bsub>G\<^esub>, \<one>\<^bsub>H\<^esub>) |)"
ballarin@13813
   492
ballarin@13817
   493
lemma DirProdSemigroup_magma:
ballarin@13813
   494
  includes magma G + magma H
ballarin@13817
   495
  shows "magma (G \<times>\<^sub>s H)"
ballarin@14254
   496
  by (rule magma.intro) (auto simp add: DirProdSemigroup_def)
ballarin@13813
   497
ballarin@13817
   498
lemma DirProdSemigroup_semigroup_axioms:
ballarin@13813
   499
  includes semigroup G + semigroup H
ballarin@13817
   500
  shows "semigroup_axioms (G \<times>\<^sub>s H)"
ballarin@14254
   501
  by (rule semigroup_axioms.intro)
ballarin@14254
   502
    (auto simp add: DirProdSemigroup_def G.m_assoc H.m_assoc)
ballarin@13813
   503
ballarin@13817
   504
lemma DirProdSemigroup_semigroup:
ballarin@13813
   505
  includes semigroup G + semigroup H
ballarin@13817
   506
  shows "semigroup (G \<times>\<^sub>s H)"
ballarin@13813
   507
  using prems
ballarin@13813
   508
  by (fast intro: semigroup.intro
ballarin@13817
   509
    DirProdSemigroup_magma DirProdSemigroup_semigroup_axioms)
ballarin@13813
   510
ballarin@13813
   511
lemma DirProdGroup_magma:
ballarin@13813
   512
  includes magma G + magma H
ballarin@13813
   513
  shows "magma (G \<times>\<^sub>g H)"
ballarin@14254
   514
  by (rule magma.intro)
wenzelm@14651
   515
    (auto simp add: DirProdGroup_def DirProdSemigroup_def semigroup.defs)
ballarin@13813
   516
ballarin@13813
   517
lemma DirProdGroup_semigroup_axioms:
ballarin@13813
   518
  includes semigroup G + semigroup H
ballarin@13813
   519
  shows "semigroup_axioms (G \<times>\<^sub>g H)"
ballarin@14254
   520
  by (rule semigroup_axioms.intro)
wenzelm@14651
   521
    (auto simp add: DirProdGroup_def DirProdSemigroup_def semigroup.defs
ballarin@13817
   522
      G.m_assoc H.m_assoc)
ballarin@13813
   523
ballarin@13813
   524
lemma DirProdGroup_semigroup:
ballarin@13813
   525
  includes semigroup G + semigroup H
ballarin@13813
   526
  shows "semigroup (G \<times>\<^sub>g H)"
ballarin@13813
   527
  using prems
ballarin@13813
   528
  by (fast intro: semigroup.intro
ballarin@13813
   529
    DirProdGroup_magma DirProdGroup_semigroup_axioms)
ballarin@13813
   530
wenzelm@14651
   531
text {* \dots\ and further lemmas for group \dots *}
ballarin@13813
   532
ballarin@13817
   533
lemma DirProdGroup_group:
ballarin@13813
   534
  includes group G + group H
ballarin@13813
   535
  shows "group (G \<times>\<^sub>g H)"
ballarin@13936
   536
  by (rule groupI)
ballarin@13936
   537
    (auto intro: G.m_assoc H.m_assoc G.l_inv H.l_inv
wenzelm@14651
   538
      simp add: DirProdGroup_def DirProdSemigroup_def semigroup.defs)
ballarin@13813
   539
paulson@13944
   540
lemma carrier_DirProdGroup [simp]:
paulson@13944
   541
     "carrier (G \<times>\<^sub>g H) = carrier G \<times> carrier H"
wenzelm@14651
   542
  by (simp add: DirProdGroup_def DirProdSemigroup_def semigroup.defs)
paulson@13944
   543
paulson@13944
   544
lemma one_DirProdGroup [simp]:
wenzelm@14693
   545
     "\<one>\<^bsub>(G \<times>\<^sub>g H)\<^esub> = (\<one>\<^bsub>G\<^esub>, \<one>\<^bsub>H\<^esub>)"
wenzelm@14651
   546
  by (simp add: DirProdGroup_def DirProdSemigroup_def semigroup.defs)
paulson@13944
   547
paulson@13944
   548
lemma mult_DirProdGroup [simp]:
wenzelm@14693
   549
     "(g, h) \<otimes>\<^bsub>(G \<times>\<^sub>g H)\<^esub> (g', h') = (g \<otimes>\<^bsub>G\<^esub> g', h \<otimes>\<^bsub>H\<^esub> h')"
wenzelm@14651
   550
  by (simp add: DirProdGroup_def DirProdSemigroup_def semigroup.defs)
paulson@13944
   551
paulson@13944
   552
lemma inv_DirProdGroup [simp]:
paulson@13944
   553
  includes group G + group H
paulson@13944
   554
  assumes g: "g \<in> carrier G"
paulson@13944
   555
      and h: "h \<in> carrier H"
wenzelm@14693
   556
  shows "m_inv (G \<times>\<^sub>g H) (g, h) = (inv\<^bsub>G\<^esub> g, inv\<^bsub>H\<^esub> h)"
paulson@13944
   557
  apply (rule group.inv_equality [OF DirProdGroup_group])
paulson@13944
   558
  apply (simp_all add: prems group_def group.l_inv)
paulson@13944
   559
  done
paulson@13944
   560
paulson@14761
   561
subsection {* Isomorphisms *}
ballarin@13813
   562
wenzelm@14651
   563
constdefs (structure G and H)
wenzelm@14651
   564
  hom :: "_ => _ => ('a => 'b) set"
ballarin@13813
   565
  "hom G H ==
ballarin@13813
   566
    {h. h \<in> carrier G -> carrier H &
wenzelm@14693
   567
      (\<forall>x \<in> carrier G. \<forall>y \<in> carrier G. h (x \<otimes>\<^bsub>G\<^esub> y) = h x \<otimes>\<^bsub>H\<^esub> h y)}"
ballarin@13813
   568
ballarin@13813
   569
lemma (in semigroup) hom:
paulson@14761
   570
     "semigroup (| carrier = hom G G, mult = op o |)"
ballarin@14254
   571
proof (rule semigroup.intro)
ballarin@13813
   572
  show "magma (| carrier = hom G G, mult = op o |)"
ballarin@14254
   573
    by (rule magma.intro) (simp add: Pi_def hom_def)
ballarin@13813
   574
next
ballarin@13813
   575
  show "semigroup_axioms (| carrier = hom G G, mult = op o |)"
ballarin@14254
   576
    by (rule semigroup_axioms.intro) (simp add: o_assoc)
ballarin@13813
   577
qed
ballarin@13813
   578
ballarin@13813
   579
lemma hom_mult:
wenzelm@14693
   580
  "[| h \<in> hom G H; x \<in> carrier G; y \<in> carrier G |]
wenzelm@14693
   581
   ==> h (x \<otimes>\<^bsub>G\<^esub> y) = h x \<otimes>\<^bsub>H\<^esub> h y"
wenzelm@14693
   582
  by (simp add: hom_def)
ballarin@13813
   583
ballarin@13813
   584
lemma hom_closed:
ballarin@13813
   585
  "[| h \<in> hom G H; x \<in> carrier G |] ==> h x \<in> carrier H"
ballarin@13813
   586
  by (auto simp add: hom_def funcset_mem)
ballarin@13813
   587
paulson@14761
   588
lemma (in group) hom_compose:
paulson@14761
   589
     "[|h \<in> hom G H; i \<in> hom H I|] ==> compose (carrier G) i h \<in> hom G I"
paulson@14761
   590
apply (auto simp add: hom_def funcset_compose) 
paulson@14761
   591
apply (simp add: compose_def funcset_mem)
paulson@13943
   592
done
paulson@13943
   593
paulson@14761
   594
paulson@14761
   595
subsection {* Isomorphisms *}
paulson@14761
   596
paulson@14803
   597
constdefs
paulson@14803
   598
  iso :: "_ => _ => ('a => 'b) set"  (infixr "\<cong>" 60)
paulson@14803
   599
  "G \<cong> H == {h. h \<in> hom G H & bij_betw h (carrier G) (carrier H)}"
paulson@14761
   600
paulson@14803
   601
lemma iso_refl: "(%x. x) \<in> G \<cong> G"
paulson@14761
   602
by (simp add: iso_def hom_def inj_on_def bij_betw_def Pi_def) 
paulson@14761
   603
paulson@14761
   604
lemma (in group) iso_sym:
paulson@14803
   605
     "h \<in> G \<cong> H \<Longrightarrow> Inv (carrier G) h \<in> H \<cong> G"
paulson@14761
   606
apply (simp add: iso_def bij_betw_Inv) 
paulson@14761
   607
apply (subgoal_tac "Inv (carrier G) h \<in> carrier H \<rightarrow> carrier G") 
paulson@14761
   608
 prefer 2 apply (simp add: bij_betw_imp_funcset [OF bij_betw_Inv]) 
paulson@14761
   609
apply (simp add: hom_def bij_betw_def Inv_f_eq funcset_mem f_Inv_f) 
paulson@14761
   610
done
paulson@14761
   611
paulson@14761
   612
lemma (in group) iso_trans: 
paulson@14803
   613
     "[|h \<in> G \<cong> H; i \<in> H \<cong> I|] ==> (compose (carrier G) i h) \<in> G \<cong> I"
paulson@14761
   614
by (auto simp add: iso_def hom_compose bij_betw_compose)
paulson@14761
   615
paulson@14761
   616
lemma DirProdGroup_commute_iso:
paulson@14803
   617
  shows "(%(x,y). (y,x)) \<in> (G \<times>\<^sub>g H) \<cong> (H \<times>\<^sub>g G)"
paulson@14761
   618
by (auto simp add: iso_def hom_def inj_on_def bij_betw_def Pi_def) 
paulson@14761
   619
paulson@14761
   620
lemma DirProdGroup_assoc_iso:
paulson@14803
   621
  shows "(%(x,y,z). (x,(y,z))) \<in> (G \<times>\<^sub>g H \<times>\<^sub>g I) \<cong> (G \<times>\<^sub>g (H \<times>\<^sub>g I))"
paulson@14761
   622
by (auto simp add: iso_def hom_def inj_on_def bij_betw_def Pi_def) 
paulson@14761
   623
paulson@14761
   624
ballarin@13813
   625
locale group_hom = group G + group H + var h +
ballarin@13813
   626
  assumes homh: "h \<in> hom G H"
ballarin@13813
   627
  notes hom_mult [simp] = hom_mult [OF homh]
ballarin@13813
   628
    and hom_closed [simp] = hom_closed [OF homh]
ballarin@13813
   629
ballarin@13813
   630
lemma (in group_hom) one_closed [simp]:
ballarin@13813
   631
  "h \<one> \<in> carrier H"
ballarin@13813
   632
  by simp
ballarin@13813
   633
ballarin@13813
   634
lemma (in group_hom) hom_one [simp]:
wenzelm@14693
   635
  "h \<one> = \<one>\<^bsub>H\<^esub>"
ballarin@13813
   636
proof -
wenzelm@14693
   637
  have "h \<one> \<otimes>\<^bsub>H\<^esub> \<one>\<^bsub>H\<^esub> = h \<one> \<otimes>\<^sub>2 h \<one>"
ballarin@13813
   638
    by (simp add: hom_mult [symmetric] del: hom_mult)
ballarin@13813
   639
  then show ?thesis by (simp del: r_one)
ballarin@13813
   640
qed
ballarin@13813
   641
ballarin@13813
   642
lemma (in group_hom) inv_closed [simp]:
ballarin@13813
   643
  "x \<in> carrier G ==> h (inv x) \<in> carrier H"
ballarin@13813
   644
  by simp
ballarin@13813
   645
ballarin@13813
   646
lemma (in group_hom) hom_inv [simp]:
wenzelm@14693
   647
  "x \<in> carrier G ==> h (inv x) = inv\<^bsub>H\<^esub> (h x)"
ballarin@13813
   648
proof -
ballarin@13813
   649
  assume x: "x \<in> carrier G"
wenzelm@14693
   650
  then have "h x \<otimes>\<^bsub>H\<^esub> h (inv x) = \<one>\<^bsub>H\<^esub>"
ballarin@13813
   651
    by (simp add: hom_mult [symmetric] G.r_inv del: hom_mult)
wenzelm@14693
   652
  also from x have "... = h x \<otimes>\<^bsub>H\<^esub> inv\<^bsub>H\<^esub> (h x)"
ballarin@13813
   653
    by (simp add: hom_mult [symmetric] H.r_inv del: hom_mult)
wenzelm@14693
   654
  finally have "h x \<otimes>\<^bsub>H\<^esub> h (inv x) = h x \<otimes>\<^bsub>H\<^esub> inv\<^bsub>H\<^esub> (h x)" .
ballarin@13813
   655
  with x show ?thesis by simp
ballarin@13813
   656
qed
ballarin@13813
   657
ballarin@13949
   658
subsection {* Commutative Structures *}
ballarin@13936
   659
ballarin@13936
   660
text {*
ballarin@13936
   661
  Naming convention: multiplicative structures that are commutative
ballarin@13936
   662
  are called \emph{commutative}, additive structures are called
ballarin@13936
   663
  \emph{Abelian}.
ballarin@13936
   664
*}
ballarin@13813
   665
ballarin@13813
   666
subsection {* Definition *}
ballarin@13813
   667
ballarin@13936
   668
locale comm_semigroup = semigroup +
ballarin@13813
   669
  assumes m_comm: "[| x \<in> carrier G; y \<in> carrier G |] ==> x \<otimes> y = y \<otimes> x"
ballarin@13813
   670
ballarin@13936
   671
lemma (in comm_semigroup) m_lcomm:
ballarin@13813
   672
  "[| x \<in> carrier G; y \<in> carrier G; z \<in> carrier G |] ==>
ballarin@13813
   673
   x \<otimes> (y \<otimes> z) = y \<otimes> (x \<otimes> z)"
ballarin@13813
   674
proof -
wenzelm@14693
   675
  assume xyz: "x \<in> carrier G"  "y \<in> carrier G"  "z \<in> carrier G"
ballarin@13813
   676
  from xyz have "x \<otimes> (y \<otimes> z) = (x \<otimes> y) \<otimes> z" by (simp add: m_assoc)
ballarin@13813
   677
  also from xyz have "... = (y \<otimes> x) \<otimes> z" by (simp add: m_comm)
ballarin@13813
   678
  also from xyz have "... = y \<otimes> (x \<otimes> z)" by (simp add: m_assoc)
ballarin@13813
   679
  finally show ?thesis .
ballarin@13813
   680
qed
ballarin@13813
   681
ballarin@13936
   682
lemmas (in comm_semigroup) m_ac = m_assoc m_comm m_lcomm
ballarin@13936
   683
ballarin@13936
   684
locale comm_monoid = comm_semigroup + monoid
ballarin@13813
   685
ballarin@13936
   686
lemma comm_monoidI:
wenzelm@14693
   687
  includes struct G
ballarin@13936
   688
  assumes m_closed:
wenzelm@14693
   689
      "!!x y. [| x \<in> carrier G; y \<in> carrier G |] ==> x \<otimes> y \<in> carrier G"
wenzelm@14693
   690
    and one_closed: "\<one> \<in> carrier G"
ballarin@13936
   691
    and m_assoc:
ballarin@13936
   692
      "!!x y z. [| x \<in> carrier G; y \<in> carrier G; z \<in> carrier G |] ==>
wenzelm@14693
   693
      (x \<otimes> y) \<otimes> z = x \<otimes> (y \<otimes> z)"
wenzelm@14693
   694
    and l_one: "!!x. x \<in> carrier G ==> \<one> \<otimes> x = x"
ballarin@13936
   695
    and m_comm:
wenzelm@14693
   696
      "!!x y. [| x \<in> carrier G; y \<in> carrier G |] ==> x \<otimes> y = y \<otimes> x"
ballarin@13936
   697
  shows "comm_monoid G"
ballarin@13936
   698
  using l_one
ballarin@13936
   699
  by (auto intro!: comm_monoid.intro magma.intro semigroup_axioms.intro
ballarin@13936
   700
    comm_semigroup_axioms.intro monoid_axioms.intro
ballarin@13936
   701
    intro: prems simp: m_closed one_closed m_comm)
ballarin@13817
   702
ballarin@13936
   703
lemma (in monoid) monoid_comm_monoidI:
ballarin@13936
   704
  assumes m_comm:
wenzelm@14693
   705
      "!!x y. [| x \<in> carrier G; y \<in> carrier G |] ==> x \<otimes> y = y \<otimes> x"
ballarin@13936
   706
  shows "comm_monoid G"
ballarin@13936
   707
  by (rule comm_monoidI) (auto intro: m_assoc m_comm)
wenzelm@14693
   708
(*lemma (in comm_monoid) r_one [simp]:
ballarin@13817
   709
  "x \<in> carrier G ==> x \<otimes> \<one> = x"
ballarin@13817
   710
proof -
ballarin@13817
   711
  assume G: "x \<in> carrier G"
ballarin@13817
   712
  then have "x \<otimes> \<one> = \<one> \<otimes> x" by (simp add: m_comm)
ballarin@13817
   713
  also from G have "... = x" by simp
ballarin@13817
   714
  finally show ?thesis .
wenzelm@14693
   715
qed*)
ballarin@13936
   716
lemma (in comm_monoid) nat_pow_distr:
ballarin@13936
   717
  "[| x \<in> carrier G; y \<in> carrier G |] ==>
ballarin@13936
   718
  (x \<otimes> y) (^) (n::nat) = x (^) n \<otimes> y (^) n"
ballarin@13936
   719
  by (induct n) (simp, simp add: m_ac)
ballarin@13936
   720
ballarin@13936
   721
locale comm_group = comm_monoid + group
ballarin@13936
   722
ballarin@13936
   723
lemma (in group) group_comm_groupI:
ballarin@13936
   724
  assumes m_comm: "!!x y. [| x \<in> carrier G; y \<in> carrier G |] ==>
wenzelm@14693
   725
      x \<otimes> y = y \<otimes> x"
ballarin@13936
   726
  shows "comm_group G"
ballarin@13936
   727
  by (fast intro: comm_group.intro comm_semigroup_axioms.intro
paulson@14761
   728
                  is_group prems)
ballarin@13817
   729
ballarin@13936
   730
lemma comm_groupI:
wenzelm@14693
   731
  includes struct G
ballarin@13936
   732
  assumes m_closed:
wenzelm@14693
   733
      "!!x y. [| x \<in> carrier G; y \<in> carrier G |] ==> x \<otimes> y \<in> carrier G"
wenzelm@14693
   734
    and one_closed: "\<one> \<in> carrier G"
ballarin@13936
   735
    and m_assoc:
ballarin@13936
   736
      "!!x y z. [| x \<in> carrier G; y \<in> carrier G; z \<in> carrier G |] ==>
wenzelm@14693
   737
      (x \<otimes> y) \<otimes> z = x \<otimes> (y \<otimes> z)"
ballarin@13936
   738
    and m_comm:
wenzelm@14693
   739
      "!!x y. [| x \<in> carrier G; y \<in> carrier G |] ==> x \<otimes> y = y \<otimes> x"
wenzelm@14693
   740
    and l_one: "!!x. x \<in> carrier G ==> \<one> \<otimes> x = x"
wenzelm@14693
   741
    and l_inv_ex: "!!x. x \<in> carrier G ==> EX y : carrier G. y \<otimes> x = \<one>"
ballarin@13936
   742
  shows "comm_group G"
ballarin@13936
   743
  by (fast intro: group.group_comm_groupI groupI prems)
ballarin@13936
   744
ballarin@13936
   745
lemma (in comm_group) inv_mult:
ballarin@13854
   746
  "[| x \<in> carrier G; y \<in> carrier G |] ==> inv (x \<otimes> y) = inv x \<otimes> inv y"
ballarin@13936
   747
  by (simp add: m_ac inv_mult_group)
ballarin@13854
   748
ballarin@14751
   749
subsection {* Lattice of subgroups of a group *}
ballarin@14751
   750
ballarin@14751
   751
text_raw {* \label{sec:subgroup-lattice} *}
ballarin@14751
   752
ballarin@14751
   753
theorem (in group) subgroups_partial_order:
ballarin@14751
   754
  "partial_order (| carrier = {H. subgroup H G}, le = op \<subseteq> |)"
ballarin@14751
   755
  by (rule partial_order.intro) simp_all
ballarin@14751
   756
ballarin@14751
   757
lemma (in group) subgroup_self:
ballarin@14751
   758
  "subgroup (carrier G) G"
ballarin@14751
   759
  by (rule subgroupI) auto
ballarin@14751
   760
ballarin@14751
   761
lemma (in group) subgroup_imp_group:
ballarin@14751
   762
  "subgroup H G ==> group (G(| carrier := H |))"
ballarin@14751
   763
  using subgroup.groupI [OF _ group.intro] .
ballarin@14751
   764
ballarin@14751
   765
lemma (in group) is_monoid [intro, simp]:
ballarin@14751
   766
  "monoid G"
ballarin@14751
   767
  by (rule monoid.intro)
ballarin@14751
   768
ballarin@14751
   769
lemma (in group) subgroup_inv_equality:
ballarin@14751
   770
  "[| subgroup H G; x \<in> H |] ==> m_inv (G (| carrier := H |)) x = inv x"
ballarin@14751
   771
apply (rule_tac inv_equality [THEN sym])
paulson@14761
   772
  apply (rule group.l_inv [OF subgroup_imp_group, simplified], assumption+)
paulson@14761
   773
 apply (rule subsetD [OF subgroup.subset], assumption+)
paulson@14761
   774
apply (rule subsetD [OF subgroup.subset], assumption)
paulson@14761
   775
apply (rule_tac group.inv_closed [OF subgroup_imp_group, simplified], assumption+)
ballarin@14751
   776
done
ballarin@14751
   777
ballarin@14751
   778
theorem (in group) subgroups_Inter:
ballarin@14751
   779
  assumes subgr: "(!!H. H \<in> A ==> subgroup H G)"
ballarin@14751
   780
    and not_empty: "A ~= {}"
ballarin@14751
   781
  shows "subgroup (\<Inter>A) G"
ballarin@14751
   782
proof (rule subgroupI)
ballarin@14751
   783
  from subgr [THEN subgroup.subset] and not_empty
ballarin@14751
   784
  show "\<Inter>A \<subseteq> carrier G" by blast
ballarin@14751
   785
next
ballarin@14751
   786
  from subgr [THEN subgroup.one_closed]
ballarin@14751
   787
  show "\<Inter>A ~= {}" by blast
ballarin@14751
   788
next
ballarin@14751
   789
  fix x assume "x \<in> \<Inter>A"
ballarin@14751
   790
  with subgr [THEN subgroup.m_inv_closed]
ballarin@14751
   791
  show "inv x \<in> \<Inter>A" by blast
ballarin@14751
   792
next
ballarin@14751
   793
  fix x y assume "x \<in> \<Inter>A" "y \<in> \<Inter>A"
ballarin@14751
   794
  with subgr [THEN subgroup.m_closed]
ballarin@14751
   795
  show "x \<otimes> y \<in> \<Inter>A" by blast
ballarin@14751
   796
qed
ballarin@14751
   797
ballarin@14751
   798
theorem (in group) subgroups_complete_lattice:
ballarin@14751
   799
  "complete_lattice (| carrier = {H. subgroup H G}, le = op \<subseteq> |)"
ballarin@14751
   800
    (is "complete_lattice ?L")
ballarin@14751
   801
proof (rule partial_order.complete_lattice_criterion1)
ballarin@14751
   802
  show "partial_order ?L" by (rule subgroups_partial_order)
ballarin@14751
   803
next
ballarin@14751
   804
  have "greatest ?L (carrier G) (carrier ?L)"
ballarin@14751
   805
    by (unfold greatest_def) (simp add: subgroup.subset subgroup_self)
ballarin@14751
   806
  then show "EX G. greatest ?L G (carrier ?L)" ..
ballarin@14751
   807
next
ballarin@14751
   808
  fix A
ballarin@14751
   809
  assume L: "A \<subseteq> carrier ?L" and non_empty: "A ~= {}"
ballarin@14751
   810
  then have Int_subgroup: "subgroup (\<Inter>A) G"
ballarin@14751
   811
    by (fastsimp intro: subgroups_Inter)
ballarin@14751
   812
  have "greatest ?L (\<Inter>A) (Lower ?L A)"
ballarin@14751
   813
    (is "greatest ?L ?Int _")
ballarin@14751
   814
  proof (rule greatest_LowerI)
ballarin@14751
   815
    fix H
ballarin@14751
   816
    assume H: "H \<in> A"
ballarin@14751
   817
    with L have subgroupH: "subgroup H G" by auto
ballarin@14751
   818
    from subgroupH have submagmaH: "submagma H G" by (rule subgroup.axioms)
ballarin@14751
   819
    from subgroupH have groupH: "group (G (| carrier := H |))" (is "group ?H")
ballarin@14751
   820
      by (rule subgroup_imp_group)
ballarin@14751
   821
    from groupH have monoidH: "monoid ?H"
ballarin@14751
   822
      by (rule group.is_monoid)
ballarin@14751
   823
    from H have Int_subset: "?Int \<subseteq> H" by fastsimp
ballarin@14751
   824
    then show "le ?L ?Int H" by simp
ballarin@14751
   825
  next
ballarin@14751
   826
    fix H
ballarin@14751
   827
    assume H: "H \<in> Lower ?L A"
ballarin@14751
   828
    with L Int_subgroup show "le ?L H ?Int" by (fastsimp intro: Inter_greatest)
ballarin@14751
   829
  next
ballarin@14751
   830
    show "A \<subseteq> carrier ?L" by (rule L)
ballarin@14751
   831
  next
ballarin@14751
   832
    show "?Int \<in> carrier ?L" by simp (rule Int_subgroup)
ballarin@14751
   833
  qed
ballarin@14751
   834
  then show "EX I. greatest ?L I (Lower ?L A)" ..
ballarin@14751
   835
qed
ballarin@14751
   836
ballarin@13813
   837
end