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