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