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