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