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