src/HOL/Algebra/Group.thy
author paulson <lp15@cam.ac.uk>
Sat Jun 30 15:44:04 2018 +0100 (12 months ago)
changeset 68551 b680e74eb6f2
parent 68517 6b5f15387353
child 68555 22d51874f37d
permissions -rw-r--r--
More on Algebra by Paulo and Martin
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.
lp15@68445
     5
With additional contributions from Martin Baillon and Paulo Emílio de Vilhena.
ballarin@13813
     6
*)
ballarin@13813
     7
haftmann@28823
     8
theory Group
immler@68188
     9
imports Complete_Lattice "HOL-Library.FuncSet"
haftmann@28823
    10
begin
ballarin@13813
    11
wenzelm@61382
    12
section \<open>Monoids and Groups\<close>
ballarin@13936
    13
wenzelm@61382
    14
subsection \<open>Definitions\<close>
ballarin@20318
    15
wenzelm@61382
    16
text \<open>
wenzelm@58622
    17
  Definitions follow @{cite "Jacobson:1985"}.
wenzelm@61382
    18
\<close>
ballarin@13813
    19
paulson@14963
    20
record 'a monoid =  "'a partial_object" +
paulson@14963
    21
  mult    :: "['a, 'a] \<Rightarrow> 'a" (infixl "\<otimes>\<index>" 70)
paulson@14963
    22
  one     :: 'a ("\<one>\<index>")
ballarin@13817
    23
wenzelm@35847
    24
definition
paulson@14852
    25
  m_inv :: "('a, 'b) monoid_scheme => 'a => 'a" ("inv\<index> _" [81] 80)
wenzelm@67091
    26
  where "inv\<^bsub>G\<^esub> x = (THE y. y \<in> carrier G \<and> x \<otimes>\<^bsub>G\<^esub> y = \<one>\<^bsub>G\<^esub> \<and> y \<otimes>\<^bsub>G\<^esub> x = \<one>\<^bsub>G\<^esub>)"
ballarin@13936
    27
wenzelm@35847
    28
definition
wenzelm@14651
    29
  Units :: "_ => 'a set"
wenzelm@67443
    30
  \<comment> \<open>The set of invertible elements\<close>
wenzelm@67091
    31
  where "Units G = {y. y \<in> carrier G \<and> (\<exists>x \<in> carrier G. x \<otimes>\<^bsub>G\<^esub> y = \<one>\<^bsub>G\<^esub> \<and> y \<otimes>\<^bsub>G\<^esub> x = \<one>\<^bsub>G\<^esub>)}"
ballarin@13936
    32
ballarin@13936
    33
consts
nipkow@67341
    34
  pow :: "[('a, 'm) monoid_scheme, 'a, 'b::semiring_1] => 'a"  (infixr "[^]\<index>" 75)
wenzelm@35850
    35
wenzelm@35850
    36
overloading nat_pow == "pow :: [_, 'a, nat] => 'a"
wenzelm@35850
    37
begin
blanchet@55415
    38
  definition "nat_pow G a n = rec_nat \<one>\<^bsub>G\<^esub> (%u b. b \<otimes>\<^bsub>G\<^esub> a) n"
wenzelm@35850
    39
end
ballarin@13936
    40
wenzelm@35850
    41
overloading int_pow == "pow :: [_, 'a, int] => 'a"
wenzelm@35850
    42
begin
wenzelm@35850
    43
  definition "int_pow G a z =
blanchet@55415
    44
   (let p = rec_nat \<one>\<^bsub>G\<^esub> (%u b. b \<otimes>\<^bsub>G\<^esub> a)
huffman@46559
    45
    in if z < 0 then inv\<^bsub>G\<^esub> (p (nat (-z))) else p (nat z))"
wenzelm@35850
    46
end
ballarin@13813
    47
nipkow@67341
    48
lemma int_pow_int: "x [^]\<^bsub>G\<^esub> (int n) = x [^]\<^bsub>G\<^esub> n"
Andreas@61628
    49
by(simp add: int_pow_def nat_pow_def)
Andreas@61628
    50
ballarin@19783
    51
locale monoid =
ballarin@19783
    52
  fixes G (structure)
ballarin@13813
    53
  assumes m_closed [intro, simp]:
paulson@14963
    54
         "\<lbrakk>x \<in> carrier G; y \<in> carrier G\<rbrakk> \<Longrightarrow> x \<otimes> y \<in> carrier G"
paulson@14963
    55
      and m_assoc:
lp15@68445
    56
         "\<lbrakk>x \<in> carrier G; y \<in> carrier G; z \<in> carrier G\<rbrakk>
paulson@14963
    57
          \<Longrightarrow> (x \<otimes> y) \<otimes> z = x \<otimes> (y \<otimes> z)"
paulson@14963
    58
      and one_closed [intro, simp]: "\<one> \<in> carrier G"
paulson@14963
    59
      and l_one [simp]: "x \<in> carrier G \<Longrightarrow> \<one> \<otimes> x = x"
paulson@14963
    60
      and r_one [simp]: "x \<in> carrier G \<Longrightarrow> x \<otimes> \<one> = x"
ballarin@13817
    61
ballarin@13936
    62
lemma monoidI:
ballarin@19783
    63
  fixes G (structure)
ballarin@13936
    64
  assumes m_closed:
wenzelm@14693
    65
      "!!x y. [| x \<in> carrier G; y \<in> carrier G |] ==> x \<otimes> y \<in> carrier G"
wenzelm@14693
    66
    and one_closed: "\<one> \<in> carrier G"
ballarin@13936
    67
    and m_assoc:
ballarin@13936
    68
      "!!x y z. [| x \<in> carrier G; y \<in> carrier G; z \<in> carrier G |] ==>
wenzelm@14693
    69
      (x \<otimes> y) \<otimes> z = x \<otimes> (y \<otimes> z)"
wenzelm@14693
    70
    and l_one: "!!x. x \<in> carrier G ==> \<one> \<otimes> x = x"
wenzelm@14693
    71
    and r_one: "!!x. x \<in> carrier G ==> x \<otimes> \<one> = x"
ballarin@13936
    72
  shows "monoid G"
ballarin@27714
    73
  by (fast intro!: monoid.intro intro: assms)
ballarin@13936
    74
ballarin@13936
    75
lemma (in monoid) Units_closed [dest]:
ballarin@13936
    76
  "x \<in> Units G ==> x \<in> carrier G"
ballarin@13936
    77
  by (unfold Units_def) fast
ballarin@13936
    78
lp15@68443
    79
lemma (in monoid) one_unique:
lp15@68443
    80
  assumes "u \<in> carrier G"
lp15@68443
    81
    and "\<And>x. x \<in> carrier G \<Longrightarrow> u \<otimes> x = x"
lp15@68443
    82
  shows "u = \<one>"
lp15@68443
    83
  using assms(2)[OF one_closed] r_one[OF assms(1)] by simp
lp15@68443
    84
ballarin@13936
    85
lemma (in monoid) inv_unique:
wenzelm@14693
    86
  assumes eq: "y \<otimes> x = \<one>"  "x \<otimes> y' = \<one>"
wenzelm@14693
    87
    and G: "x \<in> carrier G"  "y \<in> carrier G"  "y' \<in> carrier G"
ballarin@13936
    88
  shows "y = y'"
ballarin@13936
    89
proof -
ballarin@13936
    90
  from G eq have "y = y \<otimes> (x \<otimes> y')" by simp
ballarin@13936
    91
  also from G have "... = (y \<otimes> x) \<otimes> y'" by (simp add: m_assoc)
ballarin@13936
    92
  also from G eq have "... = y'" by simp
ballarin@13936
    93
  finally show ?thesis .
ballarin@13936
    94
qed
ballarin@13936
    95
lp15@68443
    96
lemma (in monoid) Units_m_closed [simp, intro]:
ballarin@27698
    97
  assumes x: "x \<in> Units G" and y: "y \<in> Units G"
ballarin@27698
    98
  shows "x \<otimes> y \<in> Units G"
ballarin@27698
    99
proof -
ballarin@27698
   100
  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
   101
    unfolding Units_def by fast
ballarin@27698
   102
  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
   103
    unfolding Units_def by fast
ballarin@27698
   104
  from x y xinv yinv have "y' \<otimes> (x' \<otimes> x) \<otimes> y = \<one>" by simp
ballarin@27698
   105
  moreover from x y xinv yinv have "x \<otimes> (y \<otimes> y') \<otimes> x' = \<one>" by simp
ballarin@27698
   106
  moreover note x y
ballarin@27698
   107
  ultimately show ?thesis unfolding Units_def
lp15@68445
   108
    by simp (metis m_assoc m_closed)
ballarin@27698
   109
qed
ballarin@27698
   110
ballarin@13940
   111
lemma (in monoid) Units_one_closed [intro, simp]:
ballarin@13940
   112
  "\<one> \<in> Units G"
ballarin@13940
   113
  by (unfold Units_def) auto
ballarin@13940
   114
ballarin@13936
   115
lemma (in monoid) Units_inv_closed [intro, simp]:
ballarin@13936
   116
  "x \<in> Units G ==> inv x \<in> carrier G"
paulson@13943
   117
  apply (unfold Units_def m_inv_def, auto)
ballarin@13936
   118
  apply (rule theI2, fast)
paulson@13943
   119
   apply (fast intro: inv_unique, fast)
ballarin@13936
   120
  done
ballarin@13936
   121
ballarin@19981
   122
lemma (in monoid) Units_l_inv_ex:
ballarin@19981
   123
  "x \<in> Units G ==> \<exists>y \<in> carrier G. y \<otimes> x = \<one>"
ballarin@19981
   124
  by (unfold Units_def) auto
ballarin@19981
   125
ballarin@19981
   126
lemma (in monoid) Units_r_inv_ex:
ballarin@19981
   127
  "x \<in> Units G ==> \<exists>y \<in> carrier G. x \<otimes> y = \<one>"
ballarin@19981
   128
  by (unfold Units_def) auto
ballarin@19981
   129
ballarin@27698
   130
lemma (in monoid) Units_l_inv [simp]:
ballarin@13936
   131
  "x \<in> Units G ==> inv x \<otimes> x = \<one>"
paulson@13943
   132
  apply (unfold Units_def m_inv_def, auto)
ballarin@13936
   133
  apply (rule theI2, fast)
paulson@13943
   134
   apply (fast intro: inv_unique, fast)
ballarin@13936
   135
  done
ballarin@13936
   136
ballarin@27698
   137
lemma (in monoid) Units_r_inv [simp]:
ballarin@13936
   138
  "x \<in> Units G ==> x \<otimes> inv x = \<one>"
lp15@68458
   139
  by (metis (full_types) Units_closed Units_inv_closed Units_l_inv Units_r_inv_ex inv_unique)
ballarin@13936
   140
lp15@68445
   141
lemma (in monoid) inv_one [simp]:
lp15@68445
   142
  "inv \<one> = \<one>"
lp15@68445
   143
  by (metis Units_one_closed Units_r_inv l_one monoid.Units_inv_closed monoid_axioms)
lp15@68445
   144
ballarin@13936
   145
lemma (in monoid) Units_inv_Units [intro, simp]:
ballarin@13936
   146
  "x \<in> Units G ==> inv x \<in> Units G"
ballarin@13936
   147
proof -
ballarin@13936
   148
  assume x: "x \<in> Units G"
ballarin@13936
   149
  show "inv x \<in> Units G"
ballarin@13936
   150
    by (auto simp add: Units_def
ballarin@13936
   151
      intro: Units_l_inv Units_r_inv x Units_closed [OF x])
ballarin@13936
   152
qed
ballarin@13936
   153
ballarin@13936
   154
lemma (in monoid) Units_l_cancel [simp]:
ballarin@13936
   155
  "[| x \<in> Units G; y \<in> carrier G; z \<in> carrier G |] ==>
ballarin@13936
   156
   (x \<otimes> y = x \<otimes> z) = (y = z)"
ballarin@13936
   157
proof
ballarin@13936
   158
  assume eq: "x \<otimes> y = x \<otimes> z"
wenzelm@14693
   159
    and G: "x \<in> Units G"  "y \<in> carrier G"  "z \<in> carrier G"
ballarin@13936
   160
  then have "(inv x \<otimes> x) \<otimes> y = (inv x \<otimes> x) \<otimes> z"
ballarin@27698
   161
    by (simp add: m_assoc Units_closed del: Units_l_inv)
wenzelm@44472
   162
  with G show "y = z" by simp
ballarin@13936
   163
next
ballarin@13936
   164
  assume eq: "y = z"
wenzelm@14693
   165
    and G: "x \<in> Units G"  "y \<in> carrier G"  "z \<in> carrier G"
ballarin@13936
   166
  then show "x \<otimes> y = x \<otimes> z" by simp
ballarin@13936
   167
qed
ballarin@13936
   168
ballarin@13936
   169
lemma (in monoid) Units_inv_inv [simp]:
ballarin@13936
   170
  "x \<in> Units G ==> inv (inv x) = x"
ballarin@13936
   171
proof -
ballarin@13936
   172
  assume x: "x \<in> Units G"
ballarin@27698
   173
  then have "inv x \<otimes> inv (inv x) = inv x \<otimes> x" by simp
ballarin@27698
   174
  with x show ?thesis by (simp add: Units_closed del: Units_l_inv Units_r_inv)
ballarin@13936
   175
qed
ballarin@13936
   176
ballarin@13936
   177
lemma (in monoid) inv_inj_on_Units:
ballarin@13936
   178
  "inj_on (m_inv G) (Units G)"
ballarin@13936
   179
proof (rule inj_onI)
ballarin@13936
   180
  fix x y
wenzelm@14693
   181
  assume G: "x \<in> Units G"  "y \<in> Units G" and eq: "inv x = inv y"
ballarin@13936
   182
  then have "inv (inv x) = inv (inv y)" by simp
ballarin@13936
   183
  with G show "x = y" by simp
ballarin@13936
   184
qed
ballarin@13936
   185
ballarin@13940
   186
lemma (in monoid) Units_inv_comm:
ballarin@13940
   187
  assumes inv: "x \<otimes> y = \<one>"
wenzelm@14693
   188
    and G: "x \<in> Units G"  "y \<in> Units G"
ballarin@13940
   189
  shows "y \<otimes> x = \<one>"
ballarin@13940
   190
proof -
ballarin@13940
   191
  from G have "x \<otimes> y \<otimes> x = x \<otimes> \<one>" by (auto simp add: inv Units_closed)
ballarin@13940
   192
  with G show ?thesis by (simp del: r_one add: m_assoc Units_closed)
ballarin@13940
   193
qed
ballarin@13940
   194
Andreas@61628
   195
lemma (in monoid) carrier_not_empty: "carrier G \<noteq> {}"
Andreas@61628
   196
by auto
Andreas@61628
   197
wenzelm@61382
   198
text \<open>Power\<close>
ballarin@13936
   199
ballarin@13936
   200
lemma (in monoid) nat_pow_closed [intro, simp]:
nipkow@67341
   201
  "x \<in> carrier G ==> x [^] (n::nat) \<in> carrier G"
ballarin@13936
   202
  by (induct n) (simp_all add: nat_pow_def)
ballarin@13936
   203
ballarin@13936
   204
lemma (in monoid) nat_pow_0 [simp]:
nipkow@67341
   205
  "x [^] (0::nat) = \<one>"
ballarin@13936
   206
  by (simp add: nat_pow_def)
ballarin@13936
   207
ballarin@13936
   208
lemma (in monoid) nat_pow_Suc [simp]:
nipkow@67341
   209
  "x [^] (Suc n) = x [^] n \<otimes> x"
ballarin@13936
   210
  by (simp add: nat_pow_def)
ballarin@13936
   211
ballarin@13936
   212
lemma (in monoid) nat_pow_one [simp]:
nipkow@67341
   213
  "\<one> [^] (n::nat) = \<one>"
ballarin@13936
   214
  by (induct n) simp_all
ballarin@13936
   215
ballarin@13936
   216
lemma (in monoid) nat_pow_mult:
nipkow@67341
   217
  "x \<in> carrier G ==> x [^] (n::nat) \<otimes> x [^] m = x [^] (n + m)"
ballarin@13936
   218
  by (induct m) (simp_all add: m_assoc [THEN sym])
ballarin@13936
   219
lp15@68443
   220
lemma (in monoid) nat_pow_comm:
lp15@68443
   221
  "x \<in> carrier G \<Longrightarrow> (x [^] (n::nat)) \<otimes> (x [^] (m :: nat)) = (x [^] m) \<otimes> (x [^] n)"
lp15@68445
   222
  using nat_pow_mult[of x n m] nat_pow_mult[of x m n] by (simp add: add.commute)
lp15@68443
   223
lp15@68443
   224
lemma (in monoid) nat_pow_Suc2:
lp15@68443
   225
  "x \<in> carrier G \<Longrightarrow> x [^] (Suc n) = x \<otimes> (x [^] n)"
lp15@68443
   226
  using nat_pow_mult[of x 1 n] Suc_eq_plus1[of n]
lp15@68445
   227
  by (metis One_nat_def Suc_eq_plus1_left l_one nat.rec(1) nat_pow_Suc nat_pow_def)
lp15@68443
   228
ballarin@13936
   229
lemma (in monoid) nat_pow_pow:
nipkow@67341
   230
  "x \<in> carrier G ==> (x [^] n) [^] m = x [^] (n * m::nat)"
haftmann@57512
   231
  by (induct m) (simp, simp add: nat_pow_mult add.commute)
ballarin@13936
   232
lp15@68443
   233
lemma (in monoid) nat_pow_consistent:
lp15@68443
   234
  "x [^] (n :: nat) = x [^]\<^bsub>(G \<lparr> carrier := H \<rparr>)\<^esub> n"
lp15@68443
   235
  unfolding nat_pow_def by simp
lp15@68445
   236
ballarin@27698
   237
ballarin@27698
   238
(* Jacobson defines submonoid here. *)
ballarin@27698
   239
(* Jacobson defines the order of a monoid here. *)
ballarin@27698
   240
ballarin@27698
   241
wenzelm@61382
   242
subsection \<open>Groups\<close>
ballarin@27698
   243
wenzelm@61382
   244
text \<open>
ballarin@13936
   245
  A group is a monoid all of whose elements are invertible.
wenzelm@61382
   246
\<close>
ballarin@13936
   247
ballarin@13936
   248
locale group = monoid +
ballarin@13936
   249
  assumes Units: "carrier G <= Units G"
ballarin@13936
   250
wenzelm@26199
   251
lemma (in group) is_group: "group G" by (rule group_axioms)
paulson@14761
   252
ballarin@13936
   253
theorem groupI:
ballarin@19783
   254
  fixes G (structure)
ballarin@13936
   255
  assumes m_closed [simp]:
wenzelm@14693
   256
      "!!x y. [| x \<in> carrier G; y \<in> carrier G |] ==> x \<otimes> y \<in> carrier G"
wenzelm@14693
   257
    and one_closed [simp]: "\<one> \<in> carrier G"
ballarin@13936
   258
    and m_assoc:
ballarin@13936
   259
      "!!x y z. [| x \<in> carrier G; y \<in> carrier G; z \<in> carrier G |] ==>
wenzelm@14693
   260
      (x \<otimes> y) \<otimes> z = x \<otimes> (y \<otimes> z)"
wenzelm@14693
   261
    and l_one [simp]: "!!x. x \<in> carrier G ==> \<one> \<otimes> x = x"
paulson@14963
   262
    and l_inv_ex: "!!x. x \<in> carrier G ==> \<exists>y \<in> carrier G. y \<otimes> x = \<one>"
ballarin@13936
   263
  shows "group G"
ballarin@13936
   264
proof -
ballarin@13936
   265
  have l_cancel [simp]:
ballarin@13936
   266
    "!!x y z. [| x \<in> carrier G; y \<in> carrier G; z \<in> carrier G |] ==>
wenzelm@14693
   267
    (x \<otimes> y = x \<otimes> z) = (y = z)"
ballarin@13936
   268
  proof
ballarin@13936
   269
    fix x y z
wenzelm@14693
   270
    assume eq: "x \<otimes> y = x \<otimes> z"
wenzelm@14693
   271
      and G: "x \<in> carrier G"  "y \<in> carrier G"  "z \<in> carrier G"
ballarin@13936
   272
    with l_inv_ex obtain x_inv where xG: "x_inv \<in> carrier G"
wenzelm@14693
   273
      and l_inv: "x_inv \<otimes> x = \<one>" by fast
wenzelm@14693
   274
    from G eq xG have "(x_inv \<otimes> x) \<otimes> y = (x_inv \<otimes> x) \<otimes> z"
ballarin@13936
   275
      by (simp add: m_assoc)
ballarin@13936
   276
    with G show "y = z" by (simp add: l_inv)
ballarin@13936
   277
  next
ballarin@13936
   278
    fix x y z
ballarin@13936
   279
    assume eq: "y = z"
wenzelm@14693
   280
      and G: "x \<in> carrier G"  "y \<in> carrier G"  "z \<in> carrier G"
wenzelm@14693
   281
    then show "x \<otimes> y = x \<otimes> z" by simp
ballarin@13936
   282
  qed
ballarin@13936
   283
  have r_one:
wenzelm@14693
   284
    "!!x. x \<in> carrier G ==> x \<otimes> \<one> = x"
ballarin@13936
   285
  proof -
ballarin@13936
   286
    fix x
ballarin@13936
   287
    assume x: "x \<in> carrier G"
ballarin@13936
   288
    with l_inv_ex obtain x_inv where xG: "x_inv \<in> carrier G"
wenzelm@14693
   289
      and l_inv: "x_inv \<otimes> x = \<one>" by fast
wenzelm@14693
   290
    from x xG have "x_inv \<otimes> (x \<otimes> \<one>) = x_inv \<otimes> x"
ballarin@13936
   291
      by (simp add: m_assoc [symmetric] l_inv)
wenzelm@14693
   292
    with x xG show "x \<otimes> \<one> = x" by simp
ballarin@13936
   293
  qed
ballarin@13936
   294
  have inv_ex:
wenzelm@67091
   295
    "\<And>x. x \<in> carrier G \<Longrightarrow> \<exists>y \<in> carrier G. y \<otimes> x = \<one> \<and> x \<otimes> y = \<one>"
ballarin@13936
   296
  proof -
ballarin@13936
   297
    fix x
ballarin@13936
   298
    assume x: "x \<in> carrier G"
ballarin@13936
   299
    with l_inv_ex obtain y where y: "y \<in> carrier G"
wenzelm@14693
   300
      and l_inv: "y \<otimes> x = \<one>" by fast
wenzelm@14693
   301
    from x y have "y \<otimes> (x \<otimes> y) = y \<otimes> \<one>"
ballarin@13936
   302
      by (simp add: m_assoc [symmetric] l_inv r_one)
wenzelm@14693
   303
    with x y have r_inv: "x \<otimes> y = \<one>"
ballarin@13936
   304
      by simp
wenzelm@67091
   305
    from x y show "\<exists>y \<in> carrier G. y \<otimes> x = \<one> \<and> x \<otimes> y = \<one>"
ballarin@13936
   306
      by (fast intro: l_inv r_inv)
ballarin@13936
   307
  qed
wenzelm@67091
   308
  then have carrier_subset_Units: "carrier G \<subseteq> Units G"
ballarin@13936
   309
    by (unfold Units_def) fast
wenzelm@61169
   310
  show ?thesis
wenzelm@61169
   311
    by standard (auto simp: r_one m_assoc carrier_subset_Units)
ballarin@13936
   312
qed
ballarin@13936
   313
ballarin@27698
   314
lemma (in monoid) group_l_invI:
ballarin@13936
   315
  assumes l_inv_ex:
paulson@14963
   316
    "!!x. x \<in> carrier G ==> \<exists>y \<in> carrier G. y \<otimes> x = \<one>"
ballarin@13936
   317
  shows "group G"
ballarin@13936
   318
  by (rule groupI) (auto intro: m_assoc l_inv_ex)
ballarin@13936
   319
ballarin@13936
   320
lemma (in group) Units_eq [simp]:
ballarin@13936
   321
  "Units G = carrier G"
ballarin@13936
   322
proof
wenzelm@67091
   323
  show "Units G \<subseteq> carrier G" by fast
ballarin@13936
   324
next
wenzelm@67091
   325
  show "carrier G \<subseteq> Units G" by (rule Units)
ballarin@13936
   326
qed
ballarin@13936
   327
ballarin@13936
   328
lemma (in group) inv_closed [intro, simp]:
ballarin@13936
   329
  "x \<in> carrier G ==> inv x \<in> carrier G"
ballarin@13936
   330
  using Units_inv_closed by simp
ballarin@13936
   331
ballarin@19981
   332
lemma (in group) l_inv_ex [simp]:
ballarin@19981
   333
  "x \<in> carrier G ==> \<exists>y \<in> carrier G. y \<otimes> x = \<one>"
ballarin@19981
   334
  using Units_l_inv_ex by simp
ballarin@19981
   335
ballarin@19981
   336
lemma (in group) r_inv_ex [simp]:
ballarin@19981
   337
  "x \<in> carrier G ==> \<exists>y \<in> carrier G. x \<otimes> y = \<one>"
ballarin@19981
   338
  using Units_r_inv_ex by simp
ballarin@19981
   339
paulson@14963
   340
lemma (in group) l_inv [simp]:
ballarin@13936
   341
  "x \<in> carrier G ==> inv x \<otimes> x = \<one>"
lp15@68399
   342
  by simp
ballarin@13813
   343
ballarin@20318
   344
wenzelm@61382
   345
subsection \<open>Cancellation Laws and Basic Properties\<close>
ballarin@13813
   346
paulson@14963
   347
lemma (in group) r_inv [simp]:
ballarin@13813
   348
  "x \<in> carrier G ==> x \<otimes> inv x = \<one>"
lp15@68399
   349
  by simp
ballarin@13813
   350
lp15@68399
   351
lemma (in group) right_cancel [simp]:
ballarin@13813
   352
  "[| x \<in> carrier G; y \<in> carrier G; z \<in> carrier G |] ==>
ballarin@13813
   353
   (y \<otimes> x = z \<otimes> x) = (y = z)"
lp15@68399
   354
  by (metis inv_closed m_assoc r_inv r_one)
ballarin@13813
   355
ballarin@13813
   356
lemma (in group) inv_inv [simp]:
ballarin@13813
   357
  "x \<in> carrier G ==> inv (inv x) = x"
ballarin@13936
   358
  using Units_inv_inv by simp
ballarin@13936
   359
ballarin@13936
   360
lemma (in group) inv_inj:
ballarin@13936
   361
  "inj_on (m_inv G) (carrier G)"
ballarin@13936
   362
  using inv_inj_on_Units by simp
ballarin@13813
   363
ballarin@13854
   364
lemma (in group) inv_mult_group:
ballarin@13813
   365
  "[| x \<in> carrier G; y \<in> carrier G |] ==> inv (x \<otimes> y) = inv y \<otimes> inv x"
ballarin@13813
   366
proof -
wenzelm@14693
   367
  assume G: "x \<in> carrier G"  "y \<in> carrier G"
ballarin@13813
   368
  then have "inv (x \<otimes> y) \<otimes> (x \<otimes> y) = (inv y \<otimes> inv x) \<otimes> (x \<otimes> y)"
wenzelm@44472
   369
    by (simp add: m_assoc) (simp add: m_assoc [symmetric])
ballarin@27698
   370
  with G show ?thesis by (simp del: l_inv Units_l_inv)
ballarin@13813
   371
qed
ballarin@13813
   372
ballarin@13940
   373
lemma (in group) inv_comm:
ballarin@13940
   374
  "[| x \<otimes> y = \<one>; x \<in> carrier G; y \<in> carrier G |] ==> y \<otimes> x = \<one>"
wenzelm@14693
   375
  by (rule Units_inv_comm) auto
ballarin@13940
   376
paulson@13944
   377
lemma (in group) inv_equality:
paulson@13943
   378
     "[|y \<otimes> x = \<one>; x \<in> carrier G; y \<in> carrier G|] ==> inv x = y"
lp15@68399
   379
  using inv_unique r_inv by blast
paulson@13943
   380
ballarin@57271
   381
(* Contributed by Joachim Breitner *)
ballarin@57271
   382
lemma (in group) inv_solve_left:
ballarin@57271
   383
  "\<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
   384
  by (metis inv_equality l_inv_ex l_one m_assoc r_inv)
ballarin@57271
   385
lemma (in group) inv_solve_right:
ballarin@57271
   386
  "\<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
   387
  by (metis inv_equality l_inv_ex l_one m_assoc r_inv)
ballarin@57271
   388
wenzelm@61382
   389
text \<open>Power\<close>
ballarin@13936
   390
ballarin@13936
   391
lemma (in group) int_pow_def2:
nipkow@67341
   392
  "a [^] (z::int) = (if z < 0 then inv (a [^] (nat (-z))) else a [^] (nat z))"
ballarin@13936
   393
  by (simp add: int_pow_def nat_pow_def Let_def)
ballarin@13936
   394
ballarin@13936
   395
lemma (in group) int_pow_0 [simp]:
nipkow@67341
   396
  "x [^] (0::int) = \<one>"
ballarin@13936
   397
  by (simp add: int_pow_def2)
ballarin@13936
   398
ballarin@13936
   399
lemma (in group) int_pow_one [simp]:
nipkow@67341
   400
  "\<one> [^] (z::int) = \<one>"
ballarin@13936
   401
  by (simp add: int_pow_def2)
ballarin@13936
   402
ballarin@57271
   403
(* The following are contributed by Joachim Breitner *)
ballarin@20318
   404
ballarin@57271
   405
lemma (in group) int_pow_closed [intro, simp]:
nipkow@67341
   406
  "x \<in> carrier G ==> x [^] (i::int) \<in> carrier G"
ballarin@57271
   407
  by (simp add: int_pow_def2)
ballarin@57271
   408
ballarin@57271
   409
lemma (in group) int_pow_1 [simp]:
nipkow@67341
   410
  "x \<in> carrier G \<Longrightarrow> x [^] (1::int) = x"
ballarin@57271
   411
  by (simp add: int_pow_def2)
ballarin@57271
   412
ballarin@57271
   413
lemma (in group) int_pow_neg:
nipkow@67341
   414
  "x \<in> carrier G \<Longrightarrow> x [^] (-i::int) = inv (x [^] i)"
ballarin@57271
   415
  by (simp add: int_pow_def2)
ballarin@57271
   416
ballarin@57271
   417
lemma (in group) int_pow_mult:
nipkow@67341
   418
  "x \<in> carrier G \<Longrightarrow> x [^] (i + j::int) = x [^] i \<otimes> x [^] j"
ballarin@57271
   419
proof -
ballarin@57271
   420
  have [simp]: "-i - j = -j - i" by simp
wenzelm@67613
   421
  assume "x \<in> carrier G" then
ballarin@57271
   422
  show ?thesis
ballarin@57271
   423
    by (auto simp add: int_pow_def2 inv_solve_left inv_solve_right nat_add_distrib [symmetric] nat_pow_mult )
ballarin@57271
   424
qed
ballarin@57271
   425
lp15@68443
   426
lemma (in group) nat_pow_inv:
lp15@68443
   427
  "x \<in> carrier G \<Longrightarrow> (inv x) [^] (i :: nat) = inv (x [^] i)"
lp15@68443
   428
proof (induction i)
lp15@68443
   429
  case 0 thus ?case by simp
lp15@68443
   430
next
lp15@68443
   431
  case (Suc i)
lp15@68443
   432
  have "(inv x) [^] Suc i = ((inv x) [^] i) \<otimes> inv x"
lp15@68443
   433
    by simp
lp15@68443
   434
  also have " ... = (inv (x [^] i)) \<otimes> inv x"
lp15@68443
   435
    by (simp add: Suc.IH Suc.prems)
lp15@68443
   436
  also have " ... = inv (x \<otimes> (x [^] i))"
lp15@68443
   437
    using inv_mult_group[OF Suc.prems nat_pow_closed[OF Suc.prems, of i]] by simp
lp15@68443
   438
  also have " ... = inv (x [^] (Suc i))"
lp15@68443
   439
    using Suc.prems nat_pow_Suc2 by auto
lp15@68445
   440
  finally show ?case .
lp15@68443
   441
qed
lp15@68443
   442
lp15@68443
   443
lemma (in group) int_pow_inv:
lp15@68443
   444
  "x \<in> carrier G \<Longrightarrow> (inv x) [^] (i :: int) = inv (x [^] i)"
lp15@68443
   445
  by (simp add: nat_pow_inv int_pow_def2)
lp15@68443
   446
lp15@68443
   447
lemma (in group) int_pow_pow:
lp15@68443
   448
  assumes "x \<in> carrier G"
lp15@68443
   449
  shows "(x [^] (n :: int)) [^] (m :: int) = x [^] (n * m :: int)"
lp15@68443
   450
proof (cases)
lp15@68443
   451
  assume n_ge: "n \<ge> 0" thus ?thesis
lp15@68443
   452
  proof (cases)
lp15@68443
   453
    assume m_ge: "m \<ge> 0" thus ?thesis
lp15@68443
   454
      using n_ge nat_pow_pow[OF assms, of "nat n" "nat m"] int_pow_def2
lp15@68443
   455
      by (simp add: mult_less_0_iff nat_mult_distrib)
lp15@68443
   456
  next
lp15@68443
   457
    assume m_lt: "\<not> m \<ge> 0" thus ?thesis
lp15@68443
   458
      using n_ge int_pow_def2 nat_pow_pow[OF assms, of "nat n" "nat (- m)"]
lp15@68443
   459
      by (smt assms group.int_pow_neg is_group mult_minus_right nat_mult_distrib split_mult_neg_le)
lp15@68443
   460
  qed
lp15@68443
   461
next
lp15@68443
   462
  assume n_lt: "\<not> n \<ge> 0" thus ?thesis
lp15@68443
   463
  proof (cases)
lp15@68443
   464
    assume m_ge: "m \<ge> 0" thus ?thesis
lp15@68443
   465
      using n_lt nat_pow_pow[OF assms, of "nat (- n)" "nat m"]
lp15@68443
   466
            nat_pow_inv[of "x [^] nat (- n)" "nat m"] int_pow_def2
lp15@68443
   467
      by (smt assms group.int_pow_closed group.int_pow_neg is_group mult_minus_right
lp15@68443
   468
          mult_nonpos_nonpos nat_mult_distrib_neg)
lp15@68443
   469
  next
lp15@68443
   470
    assume m_lt: "\<not> m \<ge> 0" thus ?thesis
lp15@68443
   471
      using n_lt nat_pow_pow[OF assms, of "nat (- n)" "nat (- m)"]
lp15@68443
   472
            nat_pow_inv[of "x [^] nat (- n)" "nat (- m)"] int_pow_def2
lp15@68443
   473
      by (smt assms inv_inv mult_nonpos_nonpos nat_mult_distrib_neg nat_pow_closed)
lp15@68443
   474
  qed
lp15@68443
   475
qed
lp15@68443
   476
Andreas@61628
   477
lemma (in group) int_pow_diff:
nipkow@67341
   478
  "x \<in> carrier G \<Longrightarrow> x [^] (n - m :: int) = x [^] n \<otimes> inv (x [^] m)"
Andreas@61628
   479
by(simp only: diff_conv_add_uminus int_pow_mult int_pow_neg)
Andreas@61628
   480
Andreas@61628
   481
lemma (in group) inj_on_multc: "c \<in> carrier G \<Longrightarrow> inj_on (\<lambda>x. x \<otimes> c) (carrier G)"
Andreas@61628
   482
by(simp add: inj_on_def)
Andreas@61628
   483
Andreas@61628
   484
lemma (in group) inj_on_cmult: "c \<in> carrier G \<Longrightarrow> inj_on (\<lambda>x. c \<otimes> x) (carrier G)"
Andreas@61628
   485
by(simp add: inj_on_def)
Andreas@61628
   486
lp15@68443
   487
(*Following subsection contributed by Martin Baillon*)
lp15@68443
   488
subsection \<open>Submonoids\<close>
lp15@68443
   489
lp15@68443
   490
locale submonoid =
lp15@68443
   491
  fixes H and G (structure)
lp15@68443
   492
  assumes subset: "H \<subseteq> carrier G"
lp15@68443
   493
    and m_closed [intro, simp]: "\<lbrakk>x \<in> H; y \<in> H\<rbrakk> \<Longrightarrow> x \<otimes> y \<in> H"
lp15@68443
   494
    and one_closed [simp]: "\<one> \<in> H"
lp15@68443
   495
lp15@68443
   496
lemma (in submonoid) is_submonoid:
lp15@68443
   497
  "submonoid H G" by (rule submonoid_axioms)
lp15@68443
   498
lp15@68443
   499
lemma (in submonoid) mem_carrier [simp]:
lp15@68443
   500
  "x \<in> H \<Longrightarrow> x \<in> carrier G"
lp15@68443
   501
  using subset by blast
lp15@68443
   502
lp15@68443
   503
lemma (in submonoid) submonoid_is_monoid [intro]:
lp15@68443
   504
  assumes "monoid G"
lp15@68443
   505
  shows "monoid (G\<lparr>carrier := H\<rparr>)"
lp15@68443
   506
proof -
lp15@68443
   507
  interpret monoid G by fact
lp15@68443
   508
  show ?thesis
lp15@68443
   509
    by (simp add: monoid_def m_assoc)
lp15@68443
   510
qed
lp15@68443
   511
lp15@68443
   512
lemma submonoid_nonempty:
lp15@68443
   513
  "~ submonoid {} G"
lp15@68443
   514
  by (blast dest: submonoid.one_closed)
lp15@68443
   515
lp15@68443
   516
lemma (in submonoid) finite_monoid_imp_card_positive:
lp15@68443
   517
  "finite (carrier G) ==> 0 < card H"
lp15@68443
   518
proof (rule classical)
lp15@68443
   519
  assume "finite (carrier G)" and a: "~ 0 < card H"
lp15@68443
   520
  then have "finite H" by (blast intro: finite_subset [OF subset])
lp15@68443
   521
  with is_submonoid a have "submonoid {} G" by simp
lp15@68443
   522
  with submonoid_nonempty show ?thesis by contradiction
lp15@68443
   523
qed
lp15@68443
   524
lp15@68443
   525
lp15@68443
   526
lemma (in monoid) monoid_incl_imp_submonoid :
lp15@68443
   527
  assumes "H \<subseteq> carrier G"
lp15@68443
   528
and "monoid (G\<lparr>carrier := H\<rparr>)"
lp15@68443
   529
shows "submonoid H G"
lp15@68443
   530
proof (intro submonoid.intro[OF assms(1)])
lp15@68443
   531
  have ab_eq : "\<And> a b. a \<in> H \<Longrightarrow> b \<in> H \<Longrightarrow> a \<otimes>\<^bsub>G\<lparr>carrier := H\<rparr>\<^esub> b = a \<otimes> b" using assms by simp
lp15@68443
   532
  have "\<And>a b. a \<in> H \<Longrightarrow> b \<in> H \<Longrightarrow> a \<otimes> b \<in> carrier (G\<lparr>carrier := H\<rparr>) "
lp15@68443
   533
    using assms ab_eq unfolding group_def using monoid.m_closed by fastforce
lp15@68443
   534
  thus "\<And>a b. a \<in> H \<Longrightarrow> b \<in> H \<Longrightarrow> a \<otimes> b \<in> H" by simp
lp15@68443
   535
  show "\<one> \<in> H " using monoid.one_closed[OF assms(2)] assms by simp
lp15@68443
   536
qed
lp15@68443
   537
lp15@68517
   538
lemma (in monoid) inv_unique':
lp15@68517
   539
  assumes "x \<in> carrier G" "y \<in> carrier G"
lp15@68517
   540
  shows "\<lbrakk> x \<otimes> y = \<one>; y \<otimes> x = \<one> \<rbrakk> \<Longrightarrow> y = inv x"
lp15@68517
   541
proof -
lp15@68517
   542
  assume "x \<otimes> y = \<one>" and l_inv: "y \<otimes> x = \<one>"
lp15@68517
   543
  hence unit: "x \<in> Units G"
lp15@68517
   544
    using assms unfolding Units_def by auto
lp15@68517
   545
  show "y = inv x"
lp15@68517
   546
    using inv_unique[OF l_inv Units_r_inv[OF unit] assms Units_inv_closed[OF unit]] .
lp15@68517
   547
qed
lp15@68517
   548
lp15@68517
   549
lemma (in monoid) m_inv_monoid_consistent: (* contributed by Paulo *)
lp15@68517
   550
  assumes "x \<in> Units (G \<lparr> carrier := H \<rparr>)" and "submonoid H G"
lp15@68517
   551
  shows "inv\<^bsub>(G \<lparr> carrier := H \<rparr>)\<^esub> x = inv x"
lp15@68517
   552
proof -
lp15@68517
   553
  have monoid: "monoid (G \<lparr> carrier := H \<rparr>)"
lp15@68517
   554
    using submonoid.submonoid_is_monoid[OF assms(2) monoid_axioms] .
lp15@68517
   555
  obtain y where y: "y \<in> H" "x \<otimes> y = \<one>" "y \<otimes> x = \<one>"
lp15@68517
   556
    using assms(1) unfolding Units_def by auto
lp15@68517
   557
  have x: "x \<in> H" and in_carrier: "x \<in> carrier G" "y \<in> carrier G"
lp15@68517
   558
    using y(1) submonoid.subset[OF assms(2)] assms(1) unfolding Units_def by auto
lp15@68517
   559
  show ?thesis
lp15@68517
   560
    using monoid.inv_unique'[OF monoid, of x y] x y
lp15@68517
   561
    using inv_unique'[OF in_carrier y(2-3)] by auto
lp15@68517
   562
qed
lp15@68517
   563
wenzelm@61382
   564
subsection \<open>Subgroups\<close>
ballarin@13813
   565
ballarin@19783
   566
locale subgroup =
ballarin@19783
   567
  fixes H and G (structure)
paulson@14963
   568
  assumes subset: "H \<subseteq> carrier G"
paulson@14963
   569
    and m_closed [intro, simp]: "\<lbrakk>x \<in> H; y \<in> H\<rbrakk> \<Longrightarrow> x \<otimes> y \<in> H"
ballarin@20318
   570
    and one_closed [simp]: "\<one> \<in> H"
paulson@14963
   571
    and m_inv_closed [intro,simp]: "x \<in> H \<Longrightarrow> inv x \<in> H"
ballarin@13813
   572
ballarin@20318
   573
lemma (in subgroup) is_subgroup:
wenzelm@26199
   574
  "subgroup H G" by (rule subgroup_axioms)
ballarin@20318
   575
ballarin@13813
   576
declare (in subgroup) group.intro [intro]
ballarin@13949
   577
paulson@14963
   578
lemma (in subgroup) mem_carrier [simp]:
paulson@14963
   579
  "x \<in> H \<Longrightarrow> x \<in> carrier G"
paulson@14963
   580
  using subset by blast
ballarin@13813
   581
paulson@14963
   582
lemma (in subgroup) subgroup_is_group [intro]:
ballarin@27611
   583
  assumes "group G"
ballarin@27611
   584
  shows "group (G\<lparr>carrier := H\<rparr>)"
ballarin@27611
   585
proof -
ballarin@29237
   586
  interpret group G by fact
lp15@68458
   587
  have "Group.monoid (G\<lparr>carrier := H\<rparr>)"
lp15@68458
   588
    by (simp add: monoid_axioms submonoid.intro submonoid.submonoid_is_monoid subset)
lp15@68458
   589
  then show ?thesis
lp15@68458
   590
    by (rule monoid.group_l_invI) (auto intro: l_inv mem_carrier)
ballarin@27611
   591
qed
ballarin@13813
   592
lp15@68445
   593
lemma (in group) subgroup_inv_equality:
lp15@68443
   594
  assumes "subgroup H G" "x \<in> H"
lp15@68445
   595
  shows "m_inv (G \<lparr>carrier := H\<rparr>) x = inv x"
lp15@68443
   596
  unfolding m_inv_def apply auto
lp15@68443
   597
  using subgroup.m_inv_closed[OF assms] inv_equality
lp15@68443
   598
  by (metis (no_types, hide_lams) assms subgroup.mem_carrier)
lp15@68443
   599
lp15@68443
   600
lemma (in group) int_pow_consistent: (* by Paulo *)
lp15@68443
   601
  assumes "subgroup H G" "x \<in> H"
lp15@68443
   602
  shows "x [^] (n :: int) = x [^]\<^bsub>(G \<lparr> carrier := H \<rparr>)\<^esub> n"
lp15@68443
   603
proof (cases)
lp15@68443
   604
  assume ge: "n \<ge> 0"
lp15@68443
   605
  hence "x [^] n = x [^] (nat n)"
lp15@68443
   606
    using int_pow_def2 by auto
lp15@68443
   607
  also have " ... = x [^]\<^bsub>(G \<lparr> carrier := H \<rparr>)\<^esub> (nat n)"
lp15@68443
   608
    using nat_pow_consistent by simp
lp15@68443
   609
  also have " ... = x [^]\<^bsub>(G \<lparr> carrier := H \<rparr>)\<^esub> n"
lp15@68443
   610
    using group.int_pow_def2[OF subgroup.subgroup_is_group[OF assms(1) is_group]] ge by auto
lp15@68443
   611
  finally show ?thesis .
lp15@68445
   612
next
lp15@68443
   613
  assume "\<not> n \<ge> 0" hence lt: "n < 0" by simp
lp15@68443
   614
  hence "x [^] n = inv (x [^] (nat (- n)))"
lp15@68443
   615
    using int_pow_def2 by auto
lp15@68443
   616
  also have " ... = (inv x) [^] (nat (- n))"
lp15@68443
   617
    by (metis assms nat_pow_inv subgroup.mem_carrier)
lp15@68443
   618
  also have " ... = (inv\<^bsub>(G \<lparr> carrier := H \<rparr>)\<^esub> x) [^]\<^bsub>(G \<lparr> carrier := H \<rparr>)\<^esub> (nat (- n))"
lp15@68445
   619
    using subgroup_inv_equality[OF assms] nat_pow_consistent by auto
lp15@68443
   620
  also have " ... = inv\<^bsub>(G \<lparr> carrier := H \<rparr>)\<^esub> (x [^]\<^bsub>(G \<lparr> carrier := H \<rparr>)\<^esub> (nat (- n)))"
lp15@68443
   621
    using group.nat_pow_inv[OF subgroup.subgroup_is_group[OF assms(1) is_group]] assms(2) by auto
lp15@68443
   622
  also have " ... = x [^]\<^bsub>(G \<lparr> carrier := H \<rparr>)\<^esub> n"
lp15@68443
   623
    using group.int_pow_def2[OF subgroup.subgroup_is_group[OF assms(1) is_group]] lt by auto
lp15@68443
   624
  finally show ?thesis .
lp15@68443
   625
qed
lp15@68443
   626
wenzelm@61382
   627
text \<open>
ballarin@13813
   628
  Since @{term H} is nonempty, it contains some element @{term x}.  Since
wenzelm@63167
   629
  it is closed under inverse, it contains \<open>inv x\<close>.  Since
wenzelm@63167
   630
  it is closed under product, it contains \<open>x \<otimes> inv x = \<one>\<close>.
wenzelm@61382
   631
\<close>
ballarin@13813
   632
ballarin@13813
   633
lemma (in group) one_in_subset:
ballarin@13813
   634
  "[| 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
   635
   ==> \<one> \<in> H"
wenzelm@44472
   636
by force
ballarin@13813
   637
wenzelm@61382
   638
text \<open>A characterization of subgroups: closed, non-empty subset.\<close>
ballarin@13813
   639
ballarin@13813
   640
lemma (in group) subgroupI:
ballarin@13813
   641
  assumes subset: "H \<subseteq> carrier G" and non_empty: "H \<noteq> {}"
paulson@14963
   642
    and inv: "!!a. a \<in> H \<Longrightarrow> inv a \<in> H"
paulson@14963
   643
    and mult: "!!a b. \<lbrakk>a \<in> H; b \<in> H\<rbrakk> \<Longrightarrow> a \<otimes> b \<in> H"
ballarin@13813
   644
  shows "subgroup H G"
ballarin@27714
   645
proof (simp add: subgroup_def assms)
ballarin@27714
   646
  show "\<one> \<in> H" by (rule one_in_subset) (auto simp only: assms)
ballarin@13813
   647
qed
ballarin@13813
   648
lp15@68443
   649
lemma (in group) subgroupE:
lp15@68443
   650
  assumes "subgroup H G"
lp15@68443
   651
  shows "H \<subseteq> carrier G"
lp15@68443
   652
    and "H \<noteq> {}"
lp15@68443
   653
    and "\<And>a. a \<in> H \<Longrightarrow> inv a \<in> H"
lp15@68517
   654
    and "\<And>a b. \<lbrakk> a \<in> H; b \<in> H \<rbrakk> \<Longrightarrow> a \<otimes> b \<in> H"
lp15@68517
   655
  using assms unfolding subgroup_def[of H G] by auto
lp15@68443
   656
ballarin@13936
   657
declare monoid.one_closed [iff] group.inv_closed [simp]
ballarin@13936
   658
  monoid.l_one [simp] monoid.r_one [simp] group.inv_inv [simp]
ballarin@13813
   659
ballarin@13813
   660
lemma subgroup_nonempty:
wenzelm@67091
   661
  "\<not> subgroup {} G"
ballarin@13813
   662
  by (blast dest: subgroup.one_closed)
ballarin@13813
   663
lp15@68517
   664
lemma (in subgroup) finite_imp_card_positive: "finite (carrier G) \<Longrightarrow> 0 < card H"
lp15@68517
   665
  using subset one_closed card_gt_0_iff finite_subset by blast
ballarin@13813
   666
lp15@68443
   667
(*Following 3 lemmas contributed by Martin Baillon*)
lp15@68443
   668
lp15@68443
   669
lemma (in subgroup) subgroup_is_submonoid :
lp15@68443
   670
  "submonoid H G"
lp15@68443
   671
  by (simp add: submonoid.intro subset)
lp15@68443
   672
lp15@68443
   673
lemma (in group) submonoid_subgroupI :
lp15@68443
   674
  assumes "submonoid H G"
lp15@68443
   675
    and "\<And>a. a \<in> H \<Longrightarrow> inv a \<in> H"
lp15@68443
   676
  shows "subgroup H G"
lp15@68443
   677
  by (metis assms subgroup_def submonoid_def)
lp15@68443
   678
lp15@68443
   679
lemma (in group) group_incl_imp_subgroup:
lp15@68443
   680
  assumes "H \<subseteq> carrier G"
lp15@68445
   681
    and "group (G\<lparr>carrier := H\<rparr>)"
lp15@68445
   682
  shows "subgroup H G"
lp15@68443
   683
proof (intro submonoid_subgroupI[OF monoid_incl_imp_submonoid[OF assms(1)]])
lp15@68443
   684
  show "monoid (G\<lparr>carrier := H\<rparr>)" using group_def assms by blast
lp15@68443
   685
  have ab_eq : "\<And> a b. a \<in> H \<Longrightarrow> b \<in> H \<Longrightarrow> a \<otimes>\<^bsub>G\<lparr>carrier := H\<rparr>\<^esub> b = a \<otimes> b" using assms by simp
lp15@68445
   686
  fix a  assume aH : "a \<in> H"
lp15@68443
   687
  have " inv\<^bsub>G\<lparr>carrier := H\<rparr>\<^esub> a \<in> carrier G"
lp15@68443
   688
    using assms aH group.inv_closed[OF assms(2)] by auto
lp15@68443
   689
  moreover have "\<one>\<^bsub>G\<lparr>carrier := H\<rparr>\<^esub> = \<one>" using assms monoid.one_closed ab_eq one_def by simp
lp15@68443
   690
  hence "a \<otimes>\<^bsub>G\<lparr>carrier := H\<rparr>\<^esub> inv\<^bsub>G\<lparr>carrier := H\<rparr>\<^esub> a= \<one>"
lp15@68443
   691
    using assms ab_eq aH  group.r_inv[OF assms(2)] by simp
lp15@68443
   692
  hence "a \<otimes> inv\<^bsub>G\<lparr>carrier := H\<rparr>\<^esub> a= \<one>"
lp15@68443
   693
    using aH assms group.inv_closed[OF assms(2)] ab_eq by simp
lp15@68443
   694
  ultimately have "inv\<^bsub>G\<lparr>carrier := H\<rparr>\<^esub> a = inv a"
lp15@68443
   695
    by (smt aH assms(1) contra_subsetD group.inv_inv is_group local.inv_equality)
lp15@68443
   696
  moreover have "inv\<^bsub>G\<lparr>carrier := H\<rparr>\<^esub> a \<in> H" using aH group.inv_closed[OF assms(2)] by auto
lp15@68443
   697
  ultimately show "inv a \<in> H" by auto
lp15@68443
   698
qed
lp15@68443
   699
ballarin@13936
   700
wenzelm@61382
   701
subsection \<open>Direct Products\<close>
ballarin@13813
   702
wenzelm@35848
   703
definition
wenzelm@35848
   704
  DirProd :: "_ \<Rightarrow> _ \<Rightarrow> ('a \<times> 'b) monoid" (infixr "\<times>\<times>" 80) where
wenzelm@35848
   705
  "G \<times>\<times> H =
wenzelm@35848
   706
    \<lparr>carrier = carrier G \<times> carrier H,
wenzelm@35848
   707
     mult = (\<lambda>(g, h) (g', h'). (g \<otimes>\<^bsub>G\<^esub> g', h \<otimes>\<^bsub>H\<^esub> h')),
wenzelm@35848
   708
     one = (\<one>\<^bsub>G\<^esub>, \<one>\<^bsub>H\<^esub>)\<rparr>"
ballarin@13813
   709
paulson@14963
   710
lemma DirProd_monoid:
ballarin@27611
   711
  assumes "monoid G" and "monoid H"
paulson@14963
   712
  shows "monoid (G \<times>\<times> H)"
paulson@14963
   713
proof -
wenzelm@30729
   714
  interpret G: monoid G by fact
wenzelm@30729
   715
  interpret H: monoid H by fact
ballarin@27714
   716
  from assms
lp15@68445
   717
  show ?thesis by (unfold monoid_def DirProd_def, auto)
paulson@14963
   718
qed
ballarin@13813
   719
ballarin@13813
   720
wenzelm@61382
   721
text\<open>Does not use the previous result because it's easier just to use auto.\<close>
paulson@14963
   722
lemma DirProd_group:
ballarin@27611
   723
  assumes "group G" and "group H"
paulson@14963
   724
  shows "group (G \<times>\<times> H)"
ballarin@27611
   725
proof -
wenzelm@30729
   726
  interpret G: group G by fact
wenzelm@30729
   727
  interpret H: group H by fact
ballarin@27611
   728
  show ?thesis by (rule groupI)
paulson@14963
   729
     (auto intro: G.m_assoc H.m_assoc G.l_inv H.l_inv
paulson@14963
   730
           simp add: DirProd_def)
ballarin@27611
   731
qed
ballarin@13813
   732
paulson@14963
   733
lemma carrier_DirProd [simp]:
paulson@14963
   734
     "carrier (G \<times>\<times> H) = carrier G \<times> carrier H"
paulson@14963
   735
  by (simp add: DirProd_def)
paulson@13944
   736
paulson@14963
   737
lemma one_DirProd [simp]:
paulson@14963
   738
     "\<one>\<^bsub>G \<times>\<times> H\<^esub> = (\<one>\<^bsub>G\<^esub>, \<one>\<^bsub>H\<^esub>)"
paulson@14963
   739
  by (simp add: DirProd_def)
paulson@13944
   740
paulson@14963
   741
lemma mult_DirProd [simp]:
paulson@14963
   742
     "(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
   743
  by (simp add: DirProd_def)
paulson@13944
   744
lp15@68443
   745
lemma DirProd_assoc :
lp15@68443
   746
"(G \<times>\<times> H \<times>\<times> I) = (G \<times>\<times> (H \<times>\<times> I))"
lp15@68443
   747
  by auto
lp15@68443
   748
paulson@14963
   749
lemma inv_DirProd [simp]:
ballarin@27611
   750
  assumes "group G" and "group H"
paulson@13944
   751
  assumes g: "g \<in> carrier G"
paulson@13944
   752
      and h: "h \<in> carrier H"
paulson@14963
   753
  shows "m_inv (G \<times>\<times> H) (g, h) = (inv\<^bsub>G\<^esub> g, inv\<^bsub>H\<^esub> h)"
ballarin@27611
   754
proof -
wenzelm@30729
   755
  interpret G: group G by fact
wenzelm@30729
   756
  interpret H: group H by fact
wenzelm@30729
   757
  interpret Prod: group "G \<times>\<times> H"
ballarin@27714
   758
    by (auto intro: DirProd_group group.intro group.axioms assms)
paulson@14963
   759
  show ?thesis by (simp add: Prod.inv_equality g h)
paulson@14963
   760
qed
ballarin@27698
   761
lp15@68443
   762
lemma DirProd_subgroups :
lp15@68443
   763
  assumes "group G"
lp15@68445
   764
    and "subgroup H G"
lp15@68445
   765
    and "group K"
lp15@68445
   766
    and "subgroup I K"
lp15@68445
   767
  shows "subgroup (H \<times> I) (G \<times>\<times> K)"
lp15@68443
   768
proof (intro group.group_incl_imp_subgroup[OF DirProd_group[OF assms(1)assms(3)]])
lp15@68445
   769
  have "H \<subseteq> carrier G" "I \<subseteq> carrier K" using subgroup.subset assms apply blast+.
lp15@68443
   770
  thus "(H \<times> I) \<subseteq> carrier (G \<times>\<times> K)" unfolding DirProd_def by auto
lp15@68443
   771
  have "Group.group ((G\<lparr>carrier := H\<rparr>) \<times>\<times> (K\<lparr>carrier := I\<rparr>))"
lp15@68443
   772
    using DirProd_group[OF subgroup.subgroup_is_group[OF assms(2)assms(1)]
lp15@68445
   773
        subgroup.subgroup_is_group[OF assms(4)assms(3)]].
lp15@68443
   774
  moreover have "((G\<lparr>carrier := H\<rparr>) \<times>\<times> (K\<lparr>carrier := I\<rparr>)) = ((G \<times>\<times> K)\<lparr>carrier := H \<times> I\<rparr>)"
lp15@68443
   775
    unfolding DirProd_def using assms apply simp.
lp15@68443
   776
  ultimately show "Group.group ((G \<times>\<times> K)\<lparr>carrier := H \<times> I\<rparr>)" by simp
lp15@68443
   777
qed
paulson@14963
   778
wenzelm@61382
   779
subsection \<open>Homomorphisms and Isomorphisms\<close>
ballarin@13813
   780
wenzelm@35847
   781
definition
wenzelm@35847
   782
  hom :: "_ => _ => ('a => 'b) set" where
wenzelm@35848
   783
  "hom G H =
wenzelm@67091
   784
    {h. h \<in> carrier G \<rightarrow> carrier H \<and>
wenzelm@14693
   785
      (\<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
   786
paulson@14761
   787
lemma (in group) hom_compose:
nipkow@31754
   788
  "[|h \<in> hom G H; i \<in> hom H I|] ==> compose (carrier G) i h \<in> hom G I"
nipkow@44890
   789
by (fastforce simp add: hom_def compose_def)
paulson@13943
   790
wenzelm@35848
   791
definition
lp15@68445
   792
  iso :: "_ => _ => ('a => 'b) set"
lp15@68443
   793
  where "iso G H = {h. h \<in> hom G H \<and> bij_betw h (carrier G) (carrier H)}"
lp15@68443
   794
lp15@68443
   795
definition
lp15@68443
   796
  is_iso :: "_ \<Rightarrow> _ \<Rightarrow> bool" (infixr "\<cong>" 60)
lp15@68445
   797
  where "G \<cong> H = (iso G H  \<noteq> {})"
paulson@14761
   798
lp15@68443
   799
lemma iso_set_refl: "(\<lambda>x. x) \<in> iso G G"
lp15@68443
   800
  by (simp add: iso_def hom_def inj_on_def bij_betw_def Pi_def)
paulson@14761
   801
lp15@68443
   802
corollary iso_refl : "G \<cong> G"
lp15@68443
   803
  using iso_set_refl unfolding is_iso_def by auto
lp15@68443
   804
lp15@68443
   805
lemma (in group) iso_set_sym:
lp15@68458
   806
  assumes "h \<in> iso G H"
lp15@68458
   807
  shows "inv_into (carrier G) h \<in> iso H G"
lp15@68458
   808
proof -
lp15@68458
   809
  have h: "h \<in> hom G H" "bij_betw h (carrier G) (carrier H)"
lp15@68458
   810
    using assms by (auto simp add: iso_def bij_betw_inv_into)
lp15@68458
   811
  then have HG: "bij_betw (inv_into (carrier G) h) (carrier H) (carrier G)"
lp15@68458
   812
    by (simp add: bij_betw_inv_into)
lp15@68458
   813
  have "inv_into (carrier G) h \<in> hom H G"
lp15@68458
   814
    unfolding hom_def
lp15@68458
   815
  proof safe
lp15@68458
   816
    show *: "\<And>x. x \<in> carrier H \<Longrightarrow> inv_into (carrier G) h x \<in> carrier G"
lp15@68458
   817
      by (meson HG bij_betwE)
lp15@68458
   818
    show "inv_into (carrier G) h (x \<otimes>\<^bsub>H\<^esub> y) = inv_into (carrier G) h x \<otimes> inv_into (carrier G) h y"
lp15@68458
   819
      if "x \<in> carrier H" "y \<in> carrier H" for x y
lp15@68458
   820
    proof (rule inv_into_f_eq)
lp15@68458
   821
      show "inj_on h (carrier G)"
lp15@68458
   822
        using bij_betw_def h(2) by blast
lp15@68458
   823
      show "inv_into (carrier G) h x \<otimes> inv_into (carrier G) h y \<in> carrier G"
lp15@68458
   824
        by (simp add: * that)
lp15@68458
   825
      show "h (inv_into (carrier G) h x \<otimes> inv_into (carrier G) h y) = x \<otimes>\<^bsub>H\<^esub> y"
lp15@68458
   826
        using h bij_betw_inv_into_right [of h] unfolding hom_def by (simp add: "*" that)
lp15@68458
   827
    qed
lp15@68458
   828
  qed
lp15@68458
   829
  then show ?thesis
lp15@68458
   830
    by (simp add: Group.iso_def bij_betw_inv_into h)
lp15@68458
   831
qed
paulson@14761
   832
lp15@68458
   833
lp15@68458
   834
corollary (in group) iso_sym: "G \<cong> H \<Longrightarrow> H \<cong> G"
lp15@68443
   835
  using iso_set_sym unfolding is_iso_def by auto
lp15@68443
   836
lp15@68445
   837
lemma (in group) iso_set_trans:
lp15@68443
   838
     "[|h \<in> iso G H; i \<in> iso H I|] ==> (compose (carrier G) i h) \<in> iso G I"
paulson@14761
   839
by (auto simp add: iso_def hom_compose bij_betw_compose)
paulson@14761
   840
lp15@68458
   841
corollary (in group) iso_trans: "\<lbrakk>G \<cong> H ; H \<cong> I\<rbrakk> \<Longrightarrow> G \<cong> I"
lp15@68443
   842
  using iso_set_trans unfolding is_iso_def by blast
lp15@68443
   843
lp15@68445
   844
(* Next four lemmas contributed by Paulo. *)
lp15@68443
   845
lp15@68443
   846
lemma (in monoid) hom_imp_img_monoid:
lp15@68443
   847
  assumes "h \<in> hom G H"
lp15@68443
   848
  shows "monoid (H \<lparr> carrier := h ` (carrier G), one := h \<one>\<^bsub>G\<^esub> \<rparr>)" (is "monoid ?h_img")
lp15@68443
   849
proof (rule monoidI)
lp15@68443
   850
  show "\<one>\<^bsub>?h_img\<^esub> \<in> carrier ?h_img"
lp15@68443
   851
    by auto
lp15@68443
   852
next
lp15@68443
   853
  fix x y z assume "x \<in> carrier ?h_img" "y \<in> carrier ?h_img" "z \<in> carrier ?h_img"
lp15@68443
   854
  then obtain g1 g2 g3
lp15@68443
   855
    where g1: "g1 \<in> carrier G" "x = h g1"
lp15@68443
   856
      and g2: "g2 \<in> carrier G" "y = h g2"
lp15@68443
   857
      and g3: "g3 \<in> carrier G" "z = h g3"
lp15@68443
   858
    using image_iff[where ?f = h and ?A = "carrier G"] by auto
lp15@68443
   859
  have aux_lemma:
lp15@68443
   860
    "\<And>a b. \<lbrakk> a \<in> carrier G; b \<in> carrier G \<rbrakk> \<Longrightarrow> h a \<otimes>\<^bsub>(?h_img)\<^esub> h b = h (a \<otimes> b)"
lp15@68443
   861
    using assms unfolding hom_def by auto
lp15@68443
   862
lp15@68443
   863
  show "x \<otimes>\<^bsub>(?h_img)\<^esub> \<one>\<^bsub>(?h_img)\<^esub> = x"
lp15@68443
   864
    using aux_lemma[OF g1(1) one_closed] g1(2) r_one[OF g1(1)] by simp
lp15@68443
   865
lp15@68443
   866
  show "\<one>\<^bsub>(?h_img)\<^esub> \<otimes>\<^bsub>(?h_img)\<^esub> x = x"
lp15@68443
   867
    using aux_lemma[OF one_closed g1(1)] g1(2) l_one[OF g1(1)] by simp
lp15@68443
   868
lp15@68443
   869
  have "x \<otimes>\<^bsub>(?h_img)\<^esub> y = h (g1 \<otimes> g2)"
lp15@68443
   870
    using aux_lemma g1 g2 by auto
lp15@68443
   871
  thus "x \<otimes>\<^bsub>(?h_img)\<^esub> y \<in> carrier ?h_img"
lp15@68443
   872
    using g1(1) g2(1) by simp
lp15@68443
   873
lp15@68443
   874
  have "(x \<otimes>\<^bsub>(?h_img)\<^esub> y) \<otimes>\<^bsub>(?h_img)\<^esub> z = h ((g1 \<otimes> g2) \<otimes> g3)"
lp15@68443
   875
    using aux_lemma g1 g2 g3 by auto
lp15@68443
   876
  also have " ... = h (g1 \<otimes> (g2 \<otimes> g3))"
lp15@68443
   877
    using m_assoc[OF g1(1) g2(1) g3(1)] by simp
lp15@68443
   878
  also have " ... = x \<otimes>\<^bsub>(?h_img)\<^esub> (y \<otimes>\<^bsub>(?h_img)\<^esub> z)"
lp15@68443
   879
    using aux_lemma g1 g2 g3 by auto
lp15@68443
   880
  finally show "(x \<otimes>\<^bsub>(?h_img)\<^esub> y) \<otimes>\<^bsub>(?h_img)\<^esub> z = x \<otimes>\<^bsub>(?h_img)\<^esub> (y \<otimes>\<^bsub>(?h_img)\<^esub> z)" .
lp15@68443
   881
qed
lp15@68443
   882
lp15@68443
   883
lemma (in group) hom_imp_img_group:
lp15@68443
   884
  assumes "h \<in> hom G H"
lp15@68443
   885
  shows "group (H \<lparr> carrier := h ` (carrier G), one := h \<one>\<^bsub>G\<^esub> \<rparr>)" (is "group ?h_img")
lp15@68443
   886
proof -
lp15@68443
   887
  interpret monoid ?h_img
lp15@68443
   888
    using hom_imp_img_monoid[OF assms] .
lp15@68443
   889
lp15@68443
   890
  show ?thesis
lp15@68443
   891
  proof (unfold_locales)
lp15@68443
   892
    show "carrier ?h_img \<subseteq> Units ?h_img"
lp15@68443
   893
    proof (auto simp add: Units_def)
lp15@68443
   894
      have aux_lemma:
lp15@68443
   895
        "\<And>g1 g2. \<lbrakk> g1 \<in> carrier G; g2 \<in> carrier G \<rbrakk> \<Longrightarrow> h g1 \<otimes>\<^bsub>H\<^esub> h g2 = h (g1 \<otimes> g2)"
lp15@68443
   896
        using assms unfolding hom_def by auto
lp15@68443
   897
lp15@68443
   898
      fix g1 assume g1: "g1 \<in> carrier G"
lp15@68443
   899
      thus "\<exists>g2 \<in> carrier G. (h g2) \<otimes>\<^bsub>H\<^esub> (h g1) = h \<one> \<and> (h g1) \<otimes>\<^bsub>H\<^esub> (h g2) = h \<one>"
lp15@68443
   900
        using aux_lemma[OF g1 inv_closed[OF g1]]
lp15@68443
   901
              aux_lemma[OF inv_closed[OF g1] g1]
lp15@68443
   902
              inv_closed by auto
lp15@68443
   903
    qed
lp15@68443
   904
  qed
lp15@68443
   905
qed
lp15@68443
   906
lp15@68443
   907
lemma (in group) iso_imp_group:
lp15@68443
   908
  assumes "G \<cong> H" and "monoid H"
lp15@68443
   909
  shows "group H"
lp15@68443
   910
proof -
lp15@68443
   911
  obtain \<phi> where phi: "\<phi> \<in> iso G H" "inv_into (carrier G) \<phi> \<in> iso H G"
lp15@68443
   912
    using iso_set_sym assms unfolding is_iso_def by blast
lp15@68443
   913
  define \<psi> where psi_def: "\<psi> = inv_into (carrier G) \<phi>"
lp15@68445
   914
lp15@68443
   915
  from phi
lp15@68443
   916
  have surj: "\<phi> ` (carrier G) = (carrier H)" "\<psi> ` (carrier H) = (carrier G)"
lp15@68443
   917
   and inj: "inj_on \<phi> (carrier G)" "inj_on \<psi> (carrier H)"
lp15@68443
   918
   and phi_hom: "\<And>g1 g2. \<lbrakk> g1 \<in> carrier G; g2 \<in> carrier G \<rbrakk> \<Longrightarrow> \<phi> (g1 \<otimes> g2) = (\<phi> g1) \<otimes>\<^bsub>H\<^esub> (\<phi> g2)"
lp15@68443
   919
   and psi_hom: "\<And>h1 h2. \<lbrakk> h1 \<in> carrier H; h2 \<in> carrier H \<rbrakk> \<Longrightarrow> \<psi> (h1 \<otimes>\<^bsub>H\<^esub> h2) = (\<psi> h1) \<otimes> (\<psi> h2)"
lp15@68443
   920
   using psi_def unfolding iso_def bij_betw_def hom_def by auto
lp15@68443
   921
lp15@68443
   922
  have phi_one: "\<phi> \<one> = \<one>\<^bsub>H\<^esub>"
lp15@68443
   923
  proof -
lp15@68443
   924
    have "(\<phi> \<one>) \<otimes>\<^bsub>H\<^esub> \<one>\<^bsub>H\<^esub> = (\<phi> \<one>) \<otimes>\<^bsub>H\<^esub> (\<phi> \<one>)"
lp15@68443
   925
      by (metis assms(2) image_eqI monoid.r_one one_closed phi_hom r_one surj(1))
lp15@68443
   926
    thus ?thesis
lp15@68443
   927
      by (metis (no_types, hide_lams) Units_eq Units_one_closed assms(2) f_inv_into_f imageI
lp15@68443
   928
          monoid.l_one monoid.one_closed phi_hom psi_def r_one surj)
lp15@68443
   929
  qed
lp15@68443
   930
lp15@68443
   931
  have "carrier H \<subseteq> Units H"
lp15@68443
   932
  proof
lp15@68443
   933
    fix h assume h: "h \<in> carrier H"
lp15@68443
   934
    let ?inv_h = "\<phi> (inv (\<psi> h))"
lp15@68443
   935
    have "h \<otimes>\<^bsub>H\<^esub> ?inv_h = \<phi> (\<psi> h) \<otimes>\<^bsub>H\<^esub> ?inv_h"
lp15@68443
   936
      by (simp add: f_inv_into_f h psi_def surj(1))
lp15@68443
   937
    also have " ... = \<phi> ((\<psi> h) \<otimes> inv (\<psi> h))"
lp15@68443
   938
      by (metis h imageI inv_closed phi_hom surj(2))
lp15@68443
   939
    also have " ... = \<phi> \<one>"
lp15@68443
   940
      by (simp add: h inv_into_into psi_def surj(1))
lp15@68443
   941
    finally have 1: "h \<otimes>\<^bsub>H\<^esub> ?inv_h = \<one>\<^bsub>H\<^esub>"
lp15@68443
   942
      using phi_one by simp
lp15@68443
   943
lp15@68443
   944
    have "?inv_h \<otimes>\<^bsub>H\<^esub> h = ?inv_h \<otimes>\<^bsub>H\<^esub> \<phi> (\<psi> h)"
lp15@68443
   945
      by (simp add: f_inv_into_f h psi_def surj(1))
lp15@68443
   946
    also have " ... = \<phi> (inv (\<psi> h) \<otimes> (\<psi> h))"
lp15@68443
   947
      by (metis h imageI inv_closed phi_hom surj(2))
lp15@68443
   948
    also have " ... = \<phi> \<one>"
lp15@68443
   949
      by (simp add: h inv_into_into psi_def surj(1))
lp15@68443
   950
    finally have 2: "?inv_h \<otimes>\<^bsub>H\<^esub> h = \<one>\<^bsub>H\<^esub>"
lp15@68443
   951
      using phi_one by simp
lp15@68443
   952
lp15@68443
   953
    thus "h \<in> Units H" unfolding Units_def using 1 2 h surj by fastforce
lp15@68443
   954
  qed
lp15@68443
   955
  thus ?thesis unfolding group_def group_axioms_def using assms(2) by simp
lp15@68443
   956
qed
lp15@68443
   957
lp15@68443
   958
corollary (in group) iso_imp_img_group:
lp15@68443
   959
  assumes "h \<in> iso G H"
lp15@68443
   960
  shows "group (H \<lparr> one := h \<one> \<rparr>)"
lp15@68443
   961
proof -
lp15@68443
   962
  let ?h_img = "H \<lparr> carrier := h ` (carrier G), one := h \<one> \<rparr>"
lp15@68443
   963
  have "h \<in> iso G ?h_img"
lp15@68443
   964
    using assms unfolding iso_def hom_def bij_betw_def by auto
lp15@68443
   965
  hence "G \<cong> ?h_img"
lp15@68443
   966
    unfolding is_iso_def by auto
lp15@68443
   967
  hence "group ?h_img"
lp15@68443
   968
    using iso_imp_group[of ?h_img] hom_imp_img_monoid[of h H] assms unfolding iso_def by simp
lp15@68443
   969
  moreover have "carrier H = carrier ?h_img"
lp15@68443
   970
    using assms unfolding iso_def bij_betw_def by simp
lp15@68443
   971
  hence "H \<lparr> one := h \<one> \<rparr> = ?h_img"
lp15@68443
   972
    by simp
lp15@68443
   973
  ultimately show ?thesis by simp
lp15@68443
   974
qed
lp15@68443
   975
lp15@68443
   976
lemma DirProd_commute_iso_set:
lp15@68443
   977
  shows "(\<lambda>(x,y). (y,x)) \<in> iso (G \<times>\<times> H) (H \<times>\<times> G)"
lp15@68443
   978
  by (auto simp add: iso_def hom_def inj_on_def bij_betw_def)
lp15@68443
   979
lp15@68443
   980
corollary DirProd_commute_iso :
lp15@68443
   981
"(G \<times>\<times> H) \<cong> (H \<times>\<times> G)"
lp15@68443
   982
  using DirProd_commute_iso_set unfolding is_iso_def by blast
lp15@68443
   983
lp15@68443
   984
lemma DirProd_assoc_iso_set:
lp15@68443
   985
  shows "(\<lambda>(x,y,z). (x,(y,z))) \<in> iso (G \<times>\<times> H \<times>\<times> I) (G \<times>\<times> (H \<times>\<times> I))"
nipkow@31754
   986
by (auto simp add: iso_def hom_def inj_on_def bij_betw_def)
paulson@14761
   987
lp15@68445
   988
lemma (in group) DirProd_iso_set_trans:
lp15@68443
   989
  assumes "g \<in> iso G G2"
lp15@68443
   990
    and "h \<in> iso H I"
lp15@68443
   991
  shows "(\<lambda>(x,y). (g x, h y)) \<in> iso (G \<times>\<times> H) (G2 \<times>\<times> I)"
lp15@68443
   992
proof-
lp15@68443
   993
  have "(\<lambda>(x,y). (g x, h y)) \<in> hom (G \<times>\<times> H) (G2 \<times>\<times> I)"
lp15@68443
   994
    using assms unfolding iso_def hom_def by auto
lp15@68443
   995
  moreover have " inj_on (\<lambda>(x,y). (g x, h y)) (carrier (G \<times>\<times> H))"
lp15@68443
   996
    using assms unfolding iso_def DirProd_def bij_betw_def inj_on_def by auto
lp15@68443
   997
  moreover have "(\<lambda>(x, y). (g x, h y)) ` carrier (G \<times>\<times> H) = carrier (G2 \<times>\<times> I)"
lp15@68443
   998
    using assms unfolding iso_def bij_betw_def image_def DirProd_def by fastforce
lp15@68443
   999
  ultimately show "(\<lambda>(x,y). (g x, h y)) \<in> iso (G \<times>\<times> H) (G2 \<times>\<times> I)"
lp15@68443
  1000
    unfolding iso_def bij_betw_def by auto
lp15@68443
  1001
qed
lp15@68443
  1002
lp15@68443
  1003
corollary (in group) DirProd_iso_trans :
lp15@68443
  1004
  assumes "G \<cong> G2"
lp15@68443
  1005
    and "H \<cong> I"
lp15@68443
  1006
  shows "G \<times>\<times> H \<cong> G2 \<times>\<times> I"
lp15@68443
  1007
  using DirProd_iso_set_trans assms unfolding is_iso_def by blast
paulson@14761
  1008
paulson@14761
  1009
wenzelm@61382
  1010
text\<open>Basis for homomorphism proofs: we assume two groups @{term G} and
wenzelm@61382
  1011
  @{term H}, with a homomorphism @{term h} between them\<close>
ballarin@61565
  1012
locale group_hom = G?: group G + H?: group H for G (structure) and H (structure) +
ballarin@29237
  1013
  fixes h
ballarin@13813
  1014
  assumes homh: "h \<in> hom G H"
ballarin@29240
  1015
ballarin@29240
  1016
lemma (in group_hom) hom_mult [simp]:
ballarin@29240
  1017
  "[| 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
  1018
proof -
ballarin@29240
  1019
  assume "x \<in> carrier G" "y \<in> carrier G"
ballarin@29240
  1020
  with homh [unfolded hom_def] show ?thesis by simp
ballarin@29240
  1021
qed
ballarin@29240
  1022
ballarin@29240
  1023
lemma (in group_hom) hom_closed [simp]:
ballarin@29240
  1024
  "x \<in> carrier G ==> h x \<in> carrier H"
ballarin@29240
  1025
proof -
ballarin@29240
  1026
  assume "x \<in> carrier G"
nipkow@31754
  1027
  with homh [unfolded hom_def] show ?thesis by auto
ballarin@29240
  1028
qed
ballarin@13813
  1029
ballarin@13813
  1030
lemma (in group_hom) one_closed [simp]:
ballarin@13813
  1031
  "h \<one> \<in> carrier H"
ballarin@13813
  1032
  by simp
ballarin@13813
  1033
ballarin@13813
  1034
lemma (in group_hom) hom_one [simp]:
wenzelm@14693
  1035
  "h \<one> = \<one>\<^bsub>H\<^esub>"
ballarin@13813
  1036
proof -
ballarin@15076
  1037
  have "h \<one> \<otimes>\<^bsub>H\<^esub> \<one>\<^bsub>H\<^esub> = h \<one> \<otimes>\<^bsub>H\<^esub> h \<one>"
ballarin@13813
  1038
    by (simp add: hom_mult [symmetric] del: hom_mult)
ballarin@13813
  1039
  then show ?thesis by (simp del: r_one)
ballarin@13813
  1040
qed
ballarin@13813
  1041
ballarin@13813
  1042
lemma (in group_hom) inv_closed [simp]:
ballarin@13813
  1043
  "x \<in> carrier G ==> h (inv x) \<in> carrier H"
ballarin@13813
  1044
  by simp
ballarin@13813
  1045
ballarin@13813
  1046
lemma (in group_hom) hom_inv [simp]:
wenzelm@14693
  1047
  "x \<in> carrier G ==> h (inv x) = inv\<^bsub>H\<^esub> (h x)"
ballarin@13813
  1048
proof -
ballarin@13813
  1049
  assume x: "x \<in> carrier G"
wenzelm@14693
  1050
  then have "h x \<otimes>\<^bsub>H\<^esub> h (inv x) = \<one>\<^bsub>H\<^esub>"
paulson@14963
  1051
    by (simp add: hom_mult [symmetric] del: hom_mult)
wenzelm@14693
  1052
  also from x have "... = h x \<otimes>\<^bsub>H\<^esub> inv\<^bsub>H\<^esub> (h x)"
paulson@14963
  1053
    by (simp add: hom_mult [symmetric] del: hom_mult)
wenzelm@14693
  1054
  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
  1055
  with x show ?thesis by (simp del: H.r_inv H.Units_r_inv)
ballarin@13813
  1056
qed
ballarin@13813
  1057
ballarin@57271
  1058
(* Contributed by Joachim Breitner *)
ballarin@57271
  1059
lemma (in group) int_pow_is_hom:
nipkow@67399
  1060
  "x \<in> carrier G \<Longrightarrow> (([^]) x) \<in> hom \<lparr> carrier = UNIV, mult = (+), one = 0::int \<rparr> G "
ballarin@57271
  1061
  unfolding hom_def by (simp add: int_pow_mult)
ballarin@57271
  1062
lp15@68445
  1063
(* Next six lemmas contributed by Paulo. *)
lp15@68443
  1064
lp15@68443
  1065
lemma (in group_hom) img_is_subgroup: "subgroup (h ` (carrier G)) H"
lp15@68443
  1066
  apply (rule subgroupI)
lp15@68443
  1067
  apply (auto simp add: image_subsetI)
lp15@68443
  1068
  apply (metis (no_types, hide_lams) G.inv_closed hom_inv image_iff)
lp15@68443
  1069
  apply (smt G.monoid_axioms hom_mult image_iff monoid.m_closed)
lp15@68443
  1070
  done
lp15@68443
  1071
lp15@68443
  1072
lemma (in group_hom) subgroup_img_is_subgroup:
lp15@68443
  1073
  assumes "subgroup I G"
lp15@68443
  1074
  shows "subgroup (h ` I) H"
lp15@68443
  1075
proof -
lp15@68443
  1076
  have "h \<in> hom (G \<lparr> carrier := I \<rparr>) H"
lp15@68443
  1077
    using G.subgroupE[OF assms] subgroup.mem_carrier[OF assms] homh
lp15@68443
  1078
    unfolding hom_def by auto
lp15@68443
  1079
  hence "group_hom (G \<lparr> carrier := I \<rparr>) H h"
lp15@68443
  1080
    using subgroup.subgroup_is_group[OF assms G.is_group] is_group
lp15@68443
  1081
    unfolding group_hom_def group_hom_axioms_def by simp
lp15@68443
  1082
  thus ?thesis
lp15@68443
  1083
    using group_hom.img_is_subgroup[of "G \<lparr> carrier := I \<rparr>" H h] by simp
lp15@68443
  1084
qed
lp15@68443
  1085
lp15@68443
  1086
lemma (in group_hom) induced_group_hom:
lp15@68443
  1087
  assumes "subgroup I G"
lp15@68443
  1088
  shows "group_hom (G \<lparr> carrier := I \<rparr>) (H \<lparr> carrier := h ` I \<rparr>) h"
lp15@68443
  1089
proof -
lp15@68443
  1090
  have "h \<in> hom (G \<lparr> carrier := I \<rparr>) (H \<lparr> carrier := h ` I \<rparr>)"
lp15@68443
  1091
    using homh subgroup.mem_carrier[OF assms] unfolding hom_def by auto
lp15@68443
  1092
  thus ?thesis
lp15@68443
  1093
    unfolding group_hom_def group_hom_axioms_def
lp15@68443
  1094
    using subgroup.subgroup_is_group[OF assms G.is_group]
lp15@68443
  1095
          subgroup.subgroup_is_group[OF subgroup_img_is_subgroup[OF assms] is_group] by simp
lp15@68443
  1096
qed
lp15@68443
  1097
lp15@68443
  1098
lemma (in group) canonical_inj_is_hom:
lp15@68443
  1099
  assumes "subgroup H G"
lp15@68443
  1100
  shows "group_hom (G \<lparr> carrier := H \<rparr>) G id"
lp15@68443
  1101
  unfolding group_hom_def group_hom_axioms_def hom_def
lp15@68443
  1102
  using subgroup.subgroup_is_group[OF assms is_group]
lp15@68445
  1103
        is_group subgroup.subset[OF assms] by auto
lp15@68443
  1104
lp15@68443
  1105
lemma (in group_hom) nat_pow_hom:
lp15@68443
  1106
  "x \<in> carrier G \<Longrightarrow> h (x [^] (n :: nat)) = (h x) [^]\<^bsub>H\<^esub> n"
lp15@68443
  1107
  by (induction n) auto
lp15@68443
  1108
lp15@68443
  1109
lemma (in group_hom) int_pow_hom:
lp15@68443
  1110
  "x \<in> carrier G \<Longrightarrow> h (x [^] (n :: int)) = (h x) [^]\<^bsub>H\<^esub> n"
lp15@68443
  1111
  using int_pow_def2 nat_pow_hom by (simp add: G.int_pow_def2)
lp15@68443
  1112
ballarin@20318
  1113
wenzelm@61382
  1114
subsection \<open>Commutative Structures\<close>
ballarin@13936
  1115
wenzelm@61382
  1116
text \<open>
ballarin@13936
  1117
  Naming convention: multiplicative structures that are commutative
ballarin@13936
  1118
  are called \emph{commutative}, additive structures are called
ballarin@13936
  1119
  \emph{Abelian}.
wenzelm@61382
  1120
\<close>
ballarin@13813
  1121
paulson@14963
  1122
locale comm_monoid = monoid +
paulson@14963
  1123
  assumes m_comm: "\<lbrakk>x \<in> carrier G; y \<in> carrier G\<rbrakk> \<Longrightarrow> x \<otimes> y = y \<otimes> x"
ballarin@13813
  1124
paulson@14963
  1125
lemma (in comm_monoid) m_lcomm:
paulson@14963
  1126
  "\<lbrakk>x \<in> carrier G; y \<in> carrier G; z \<in> carrier G\<rbrakk> \<Longrightarrow>
ballarin@13813
  1127
   x \<otimes> (y \<otimes> z) = y \<otimes> (x \<otimes> z)"
ballarin@13813
  1128
proof -
wenzelm@14693
  1129
  assume xyz: "x \<in> carrier G"  "y \<in> carrier G"  "z \<in> carrier G"
ballarin@13813
  1130
  from xyz have "x \<otimes> (y \<otimes> z) = (x \<otimes> y) \<otimes> z" by (simp add: m_assoc)
ballarin@13813
  1131
  also from xyz have "... = (y \<otimes> x) \<otimes> z" by (simp add: m_comm)
ballarin@13813
  1132
  also from xyz have "... = y \<otimes> (x \<otimes> z)" by (simp add: m_assoc)
ballarin@13813
  1133
  finally show ?thesis .
ballarin@13813
  1134
qed
ballarin@13813
  1135
paulson@14963
  1136
lemmas (in comm_monoid) m_ac = m_assoc m_comm m_lcomm
ballarin@13813
  1137
ballarin@13936
  1138
lemma comm_monoidI:
ballarin@19783
  1139
  fixes G (structure)
ballarin@13936
  1140
  assumes m_closed:
wenzelm@14693
  1141
      "!!x y. [| x \<in> carrier G; y \<in> carrier G |] ==> x \<otimes> y \<in> carrier G"
wenzelm@14693
  1142
    and one_closed: "\<one> \<in> carrier G"
ballarin@13936
  1143
    and m_assoc:
ballarin@13936
  1144
      "!!x y z. [| x \<in> carrier G; y \<in> carrier G; z \<in> carrier G |] ==>
wenzelm@14693
  1145
      (x \<otimes> y) \<otimes> z = x \<otimes> (y \<otimes> z)"
wenzelm@14693
  1146
    and l_one: "!!x. x \<in> carrier G ==> \<one> \<otimes> x = x"
ballarin@13936
  1147
    and m_comm:
wenzelm@14693
  1148
      "!!x y. [| x \<in> carrier G; y \<in> carrier G |] ==> x \<otimes> y = y \<otimes> x"
ballarin@13936
  1149
  shows "comm_monoid G"
ballarin@13936
  1150
  using l_one
lp15@68445
  1151
    by (auto intro!: comm_monoid.intro comm_monoid_axioms.intro monoid.intro
ballarin@27714
  1152
             intro: assms simp: m_closed one_closed m_comm)
ballarin@13817
  1153
ballarin@13936
  1154
lemma (in monoid) monoid_comm_monoidI:
ballarin@13936
  1155
  assumes m_comm:
wenzelm@14693
  1156
      "!!x y. [| x \<in> carrier G; y \<in> carrier G |] ==> x \<otimes> y = y \<otimes> x"
ballarin@13936
  1157
  shows "comm_monoid G"
ballarin@13936
  1158
  by (rule comm_monoidI) (auto intro: m_assoc m_comm)
paulson@14963
  1159
ballarin@13936
  1160
lemma (in comm_monoid) nat_pow_distr:
ballarin@13936
  1161
  "[| x \<in> carrier G; y \<in> carrier G |] ==>
nipkow@67341
  1162
  (x \<otimes> y) [^] (n::nat) = x [^] n \<otimes> y [^] n"
ballarin@13936
  1163
  by (induct n) (simp, simp add: m_ac)
ballarin@13936
  1164
lp15@68443
  1165
lemma (in comm_monoid) submonoid_is_comm_monoid :
lp15@68443
  1166
  assumes "submonoid H G"
lp15@68443
  1167
  shows "comm_monoid (G\<lparr>carrier := H\<rparr>)"
lp15@68443
  1168
proof (intro monoid.monoid_comm_monoidI)
lp15@68443
  1169
  show "monoid (G\<lparr>carrier := H\<rparr>)"
lp15@68443
  1170
    using submonoid.submonoid_is_monoid assms comm_monoid_axioms comm_monoid_def by blast
lp15@68443
  1171
  show "\<And>x y. x \<in> carrier (G\<lparr>carrier := H\<rparr>) \<Longrightarrow> y \<in> carrier (G\<lparr>carrier := H\<rparr>)
lp15@68443
  1172
        \<Longrightarrow> x \<otimes>\<^bsub>G\<lparr>carrier := H\<rparr>\<^esub> y = y \<otimes>\<^bsub>G\<lparr>carrier := H\<rparr>\<^esub> x" apply simp
lp15@68443
  1173
    using  assms comm_monoid_axioms_def submonoid.mem_carrier
lp15@68443
  1174
    by (metis m_comm)
lp15@68443
  1175
qed
lp15@68443
  1176
ballarin@13936
  1177
locale comm_group = comm_monoid + group
ballarin@13936
  1178
ballarin@13936
  1179
lemma (in group) group_comm_groupI:
ballarin@13936
  1180
  assumes m_comm: "!!x y. [| x \<in> carrier G; y \<in> carrier G |] ==>
wenzelm@14693
  1181
      x \<otimes> y = y \<otimes> x"
ballarin@13936
  1182
  shows "comm_group G"
wenzelm@61169
  1183
  by standard (simp_all add: m_comm)
ballarin@13817
  1184
ballarin@13936
  1185
lemma comm_groupI:
ballarin@19783
  1186
  fixes G (structure)
ballarin@13936
  1187
  assumes m_closed:
wenzelm@14693
  1188
      "!!x y. [| x \<in> carrier G; y \<in> carrier G |] ==> x \<otimes> y \<in> carrier G"
wenzelm@14693
  1189
    and one_closed: "\<one> \<in> carrier G"
ballarin@13936
  1190
    and m_assoc:
ballarin@13936
  1191
      "!!x y z. [| x \<in> carrier G; y \<in> carrier G; z \<in> carrier G |] ==>
wenzelm@14693
  1192
      (x \<otimes> y) \<otimes> z = x \<otimes> (y \<otimes> z)"
ballarin@13936
  1193
    and m_comm:
wenzelm@14693
  1194
      "!!x y. [| x \<in> carrier G; y \<in> carrier G |] ==> x \<otimes> y = y \<otimes> x"
wenzelm@14693
  1195
    and l_one: "!!x. x \<in> carrier G ==> \<one> \<otimes> x = x"
paulson@14963
  1196
    and l_inv_ex: "!!x. x \<in> carrier G ==> \<exists>y \<in> carrier G. y \<otimes> x = \<one>"
ballarin@13936
  1197
  shows "comm_group G"
ballarin@27714
  1198
  by (fast intro: group.group_comm_groupI groupI assms)
ballarin@13936
  1199
lp15@68443
  1200
lemma comm_groupE:
lp15@68443
  1201
  fixes G (structure)
lp15@68443
  1202
  assumes "comm_group G"
lp15@68443
  1203
  shows "\<And>x y. \<lbrakk> x \<in> carrier G; y \<in> carrier G \<rbrakk> \<Longrightarrow> x \<otimes> y \<in> carrier G"
lp15@68443
  1204
    and "\<one> \<in> carrier G"
lp15@68443
  1205
    and "\<And>x y z. \<lbrakk> x \<in> carrier G; y \<in> carrier G; z \<in> carrier G \<rbrakk> \<Longrightarrow> (x \<otimes> y) \<otimes> z = x \<otimes> (y \<otimes> z)"
lp15@68443
  1206
    and "\<And>x y. \<lbrakk> x \<in> carrier G; y \<in> carrier G \<rbrakk> \<Longrightarrow> x \<otimes> y = y \<otimes> x"
lp15@68443
  1207
    and "\<And>x. x \<in> carrier G \<Longrightarrow> \<one> \<otimes> x = x"
lp15@68443
  1208
    and "\<And>x. x \<in> carrier G \<Longrightarrow> \<exists>y \<in> carrier G. y \<otimes> x = \<one>"
lp15@68443
  1209
  apply (simp_all add: group.axioms assms comm_group.axioms comm_monoid.m_comm comm_monoid.m_ac(1))
lp15@68443
  1210
  by (simp_all add: Group.group.axioms(1) assms comm_group.axioms(2) monoid.m_closed group.r_inv_ex)
lp15@68443
  1211
ballarin@13936
  1212
lemma (in comm_group) inv_mult:
ballarin@13854
  1213
  "[| x \<in> carrier G; y \<in> carrier G |] ==> inv (x \<otimes> y) = inv x \<otimes> inv y"
ballarin@13936
  1214
  by (simp add: m_ac inv_mult_group)
ballarin@13854
  1215
lp15@68445
  1216
(* Next three lemmas contributed by Paulo. *)
lp15@68443
  1217
lp15@68443
  1218
lemma (in comm_monoid) hom_imp_img_comm_monoid:
lp15@68443
  1219
  assumes "h \<in> hom G H"
lp15@68443
  1220
  shows "comm_monoid (H \<lparr> carrier := h ` (carrier G), one := h \<one>\<^bsub>G\<^esub> \<rparr>)" (is "comm_monoid ?h_img")
lp15@68443
  1221
proof (rule monoid.monoid_comm_monoidI)
lp15@68443
  1222
  show "monoid ?h_img"
lp15@68443
  1223
    using hom_imp_img_monoid[OF assms] .
lp15@68443
  1224
next
lp15@68443
  1225
  fix x y assume "x \<in> carrier ?h_img" "y \<in> carrier ?h_img"
lp15@68443
  1226
  then obtain g1 g2
lp15@68443
  1227
    where g1: "g1 \<in> carrier G" "x = h g1"
lp15@68443
  1228
      and g2: "g2 \<in> carrier G" "y = h g2"
lp15@68443
  1229
    by auto
lp15@68443
  1230
  have "x \<otimes>\<^bsub>(?h_img)\<^esub> y = h (g1 \<otimes> g2)"
lp15@68443
  1231
    using g1 g2 assms unfolding hom_def by auto
lp15@68443
  1232
  also have " ... = h (g2 \<otimes> g1)"
lp15@68443
  1233
    using m_comm[OF g1(1) g2(1)] by simp
lp15@68443
  1234
  also have " ... = y \<otimes>\<^bsub>(?h_img)\<^esub> x"
lp15@68443
  1235
    using g1 g2 assms unfolding hom_def by auto
lp15@68443
  1236
  finally show "x \<otimes>\<^bsub>(?h_img)\<^esub> y = y \<otimes>\<^bsub>(?h_img)\<^esub> x" .
lp15@68443
  1237
qed
lp15@68443
  1238
lp15@68517
  1239
lemma (in comm_group) hom_imp_img_comm_group:
lp15@68517
  1240
  assumes "h \<in> hom G H"
lp15@68517
  1241
  shows "comm_group (H \<lparr> carrier := h ` (carrier G), one := h \<one>\<^bsub>G\<^esub> \<rparr>)"
lp15@68517
  1242
  unfolding comm_group_def
lp15@68517
  1243
  using hom_imp_img_group[OF assms] hom_imp_img_comm_monoid[OF assms] by simp
lp15@68517
  1244
lp15@68443
  1245
lemma (in comm_group) iso_imp_img_comm_group:
lp15@68443
  1246
  assumes "h \<in> iso G H"
lp15@68443
  1247
  shows "comm_group (H \<lparr> one := h \<one>\<^bsub>G\<^esub> \<rparr>)"
lp15@68443
  1248
proof -
lp15@68443
  1249
  let ?h_img = "H \<lparr> carrier := h ` (carrier G), one := h \<one> \<rparr>"
lp15@68517
  1250
  have "comm_group ?h_img"
lp15@68517
  1251
    using hom_imp_img_comm_group[of h H] assms unfolding iso_def by auto
lp15@68443
  1252
  moreover have "carrier H = carrier ?h_img"
lp15@68443
  1253
    using assms unfolding iso_def bij_betw_def by simp
lp15@68443
  1254
  hence "H \<lparr> one := h \<one> \<rparr> = ?h_img"
lp15@68443
  1255
    by simp
lp15@68517
  1256
  ultimately show ?thesis by simp
lp15@68443
  1257
qed
lp15@68443
  1258
lp15@68443
  1259
lemma (in comm_group) iso_imp_comm_group:
lp15@68443
  1260
  assumes "G \<cong> H" "monoid H"
lp15@68443
  1261
  shows "comm_group H"
lp15@68443
  1262
proof -
lp15@68443
  1263
  obtain h where h: "h \<in> iso G H"
lp15@68443
  1264
    using assms(1) unfolding is_iso_def by auto
lp15@68443
  1265
  hence comm_gr: "comm_group (H \<lparr> one := h \<one> \<rparr>)"
lp15@68443
  1266
    using iso_imp_img_comm_group[of h H] by simp
lp15@68443
  1267
  hence "\<And>x. x \<in> carrier H \<Longrightarrow> h \<one> \<otimes>\<^bsub>H\<^esub> x = x"
lp15@68443
  1268
    using monoid.l_one[of "H \<lparr> one := h \<one> \<rparr>"] unfolding comm_group_def comm_monoid_def by simp
lp15@68443
  1269
  moreover have "h \<one> \<in> carrier H"
lp15@68443
  1270
    using h one_closed unfolding iso_def hom_def by auto
lp15@68443
  1271
  ultimately have "h \<one> = \<one>\<^bsub>H\<^esub>"
lp15@68443
  1272
    using monoid.one_unique[OF assms(2), of "h \<one>"] by simp
lp15@68443
  1273
  hence "H = H \<lparr> one := h \<one> \<rparr>"
lp15@68443
  1274
    by simp
lp15@68443
  1275
  thus ?thesis
lp15@68443
  1276
    using comm_gr by simp
lp15@68443
  1277
qed
lp15@68443
  1278
lp15@68445
  1279
(*A subgroup of a subgroup is a subgroup of the group*)
lp15@68445
  1280
lemma (in group) incl_subgroup:
lp15@68445
  1281
  assumes "subgroup J G"
lp15@68445
  1282
    and "subgroup I (G\<lparr>carrier:=J\<rparr>)"
lp15@68445
  1283
  shows "subgroup I G" unfolding subgroup_def
lp15@68445
  1284
proof
lp15@68452
  1285
  have H1: "I \<subseteq> carrier (G\<lparr>carrier:=J\<rparr>)" using assms(2) subgroup.subset by blast
lp15@68445
  1286
  also have H2: "...\<subseteq>J" by simp
lp15@68452
  1287
  also  have "...\<subseteq>(carrier G)"  by (simp add: assms(1) subgroup.subset)
lp15@68445
  1288
  finally have H: "I \<subseteq> carrier G" by simp
lp15@68445
  1289
  have "(\<And>x y. \<lbrakk>x \<in> I ; y \<in> I\<rbrakk> \<Longrightarrow> x \<otimes> y \<in> I)" using assms(2) by (auto simp add: subgroup_def)
lp15@68445
  1290
  thus  "I \<subseteq> carrier G \<and> (\<forall>x y. x \<in> I \<longrightarrow> y \<in> I \<longrightarrow> x \<otimes> y \<in> I)"  using H by blast
lp15@68445
  1291
  have K: "\<one> \<in> I" using assms(2) by (auto simp add: subgroup_def)
lp15@68445
  1292
  have "(\<And>x. x \<in> I \<Longrightarrow> inv x \<in> I)" using assms  subgroup.m_inv_closed H
lp15@68445
  1293
    by (metis H1 H2  subgroup_inv_equality subsetCE)
lp15@68445
  1294
  thus "\<one> \<in> I \<and> (\<forall>x. x \<in> I \<longrightarrow> inv x \<in> I)" using K by blast
lp15@68445
  1295
qed
lp15@68445
  1296
lp15@68445
  1297
(*A subgroup included in another subgroup is a subgroup of the subgroup*)
lp15@68445
  1298
lemma (in group) subgroup_incl:
lp15@68445
  1299
  assumes "subgroup I G"
lp15@68445
  1300
    and "subgroup J G"
lp15@68445
  1301
    and "I\<subseteq>J"
lp15@68445
  1302
  shows "subgroup I (G\<lparr>carrier:=J\<rparr>)"using assms subgroup_inv_equality
lp15@68445
  1303
  by (auto simp add: subgroup_def)
lp15@68445
  1304
lp15@68443
  1305
ballarin@20318
  1306
wenzelm@61382
  1307
subsection \<open>The Lattice of Subgroups of a Group\<close>
ballarin@14751
  1308
wenzelm@61382
  1309
text_raw \<open>\label{sec:subgroup-lattice}\<close>
ballarin@14751
  1310
ballarin@14751
  1311
theorem (in group) subgroups_partial_order:
nipkow@67399
  1312
  "partial_order \<lparr>carrier = {H. subgroup H G}, eq = (=), le = (\<subseteq>)\<rparr>"
wenzelm@61169
  1313
  by standard simp_all
ballarin@14751
  1314
ballarin@14751
  1315
lemma (in group) subgroup_self:
ballarin@14751
  1316
  "subgroup (carrier G) G"
ballarin@14751
  1317
  by (rule subgroupI) auto
ballarin@14751
  1318
ballarin@14751
  1319
lemma (in group) subgroup_imp_group:
wenzelm@55926
  1320
  "subgroup H G ==> group (G\<lparr>carrier := H\<rparr>)"
wenzelm@26199
  1321
  by (erule subgroup.subgroup_is_group) (rule group_axioms)
ballarin@14751
  1322
ballarin@14751
  1323
lemma (in group) is_monoid [intro, simp]:
ballarin@14751
  1324
  "monoid G"
lp15@68445
  1325
  by (auto intro: monoid.intro m_assoc)
ballarin@14751
  1326
lp15@68443
  1327
lemma (in group) subgroup_mult_equality:
lp15@68443
  1328
  "\<lbrakk> subgroup H G; h1 \<in> H; h2 \<in> H \<rbrakk> \<Longrightarrow>  h1 \<otimes>\<^bsub>G \<lparr> carrier := H \<rparr>\<^esub> h2 = h1 \<otimes> h2"
lp15@68443
  1329
  unfolding subgroup_def by simp
lp15@68443
  1330
ballarin@14751
  1331
theorem (in group) subgroups_Inter:
wenzelm@67091
  1332
  assumes subgr: "(\<And>H. H \<in> A \<Longrightarrow> subgroup H G)"
wenzelm@67091
  1333
    and not_empty: "A \<noteq> {}"
ballarin@14751
  1334
  shows "subgroup (\<Inter>A) G"
ballarin@14751
  1335
proof (rule subgroupI)
ballarin@14751
  1336
  from subgr [THEN subgroup.subset] and not_empty
ballarin@14751
  1337
  show "\<Inter>A \<subseteq> carrier G" by blast
ballarin@14751
  1338
next
ballarin@14751
  1339
  from subgr [THEN subgroup.one_closed]
wenzelm@67091
  1340
  show "\<Inter>A \<noteq> {}" by blast
ballarin@14751
  1341
next
ballarin@14751
  1342
  fix x assume "x \<in> \<Inter>A"
ballarin@14751
  1343
  with subgr [THEN subgroup.m_inv_closed]
ballarin@14751
  1344
  show "inv x \<in> \<Inter>A" by blast
ballarin@14751
  1345
next
ballarin@14751
  1346
  fix x y assume "x \<in> \<Inter>A" "y \<in> \<Inter>A"
ballarin@14751
  1347
  with subgr [THEN subgroup.m_closed]
ballarin@14751
  1348
  show "x \<otimes> y \<in> \<Inter>A" by blast
ballarin@14751
  1349
qed
ballarin@14751
  1350
lp15@68443
  1351
lemma (in group) subgroups_Inter_pair :
lp15@68445
  1352
  assumes  "subgroup I G"
lp15@68443
  1353
    and  "subgroup J G"
lp15@68443
  1354
  shows "subgroup (I\<inter>J) G" using subgroups_Inter[ where ?A = "{I,J}"] assms by auto
lp15@68443
  1355
ballarin@66579
  1356
theorem (in group) subgroups_complete_lattice:
nipkow@67399
  1357
  "complete_lattice \<lparr>carrier = {H. subgroup H G}, eq = (=), le = (\<subseteq>)\<rparr>"
ballarin@66579
  1358
    (is "complete_lattice ?L")
ballarin@66579
  1359
proof (rule partial_order.complete_lattice_criterion1)
ballarin@66579
  1360
  show "partial_order ?L" by (rule subgroups_partial_order)
ballarin@66579
  1361
next
ballarin@66579
  1362
  have "greatest ?L (carrier G) (carrier ?L)"
ballarin@66579
  1363
    by (unfold greatest_def) (simp add: subgroup.subset subgroup_self)
ballarin@66579
  1364
  then show "\<exists>G. greatest ?L G (carrier ?L)" ..
ballarin@66579
  1365
next
ballarin@66579
  1366
  fix A
wenzelm@67091
  1367
  assume L: "A \<subseteq> carrier ?L" and non_empty: "A \<noteq> {}"
ballarin@66579
  1368
  then have Int_subgroup: "subgroup (\<Inter>A) G"
ballarin@66579
  1369
    by (fastforce intro: subgroups_Inter)
ballarin@66579
  1370
  have "greatest ?L (\<Inter>A) (Lower ?L A)" (is "greatest _ ?Int _")
ballarin@66579
  1371
  proof (rule greatest_LowerI)
ballarin@66579
  1372
    fix H
ballarin@66579
  1373
    assume H: "H \<in> A"
ballarin@66579
  1374
    with L have subgroupH: "subgroup H G" by auto
ballarin@66579
  1375
    from subgroupH have groupH: "group (G \<lparr>carrier := H\<rparr>)" (is "group ?H")
ballarin@66579
  1376
      by (rule subgroup_imp_group)
ballarin@66579
  1377
    from groupH have monoidH: "monoid ?H"
ballarin@66579
  1378
      by (rule group.is_monoid)
ballarin@66579
  1379
    from H have Int_subset: "?Int \<subseteq> H" by fastforce
ballarin@66579
  1380
    then show "le ?L ?Int H" by simp
ballarin@66579
  1381
  next
ballarin@66579
  1382
    fix H
ballarin@66579
  1383
    assume H: "H \<in> Lower ?L A"
ballarin@66579
  1384
    with L Int_subgroup show "le ?L H ?Int"
ballarin@66579
  1385
      by (fastforce simp: Lower_def intro: Inter_greatest)
ballarin@66579
  1386
  next
ballarin@66579
  1387
    show "A \<subseteq> carrier ?L" by (rule L)
ballarin@66579
  1388
  next
ballarin@66579
  1389
    show "?Int \<in> carrier ?L" by simp (rule Int_subgroup)
ballarin@66579
  1390
  qed
ballarin@66579
  1391
  then show "\<exists>I. greatest ?L I (Lower ?L A)" ..
ballarin@66579
  1392
qed
ballarin@66579
  1393
lp15@68445
  1394
subsection\<open>Jeremy Avigad's @{text"More_Group"} material\<close>
lp15@68445
  1395
lp15@68445
  1396
text \<open>
lp15@68445
  1397
  Show that the units in any monoid give rise to a group.
lp15@68445
  1398
lp15@68445
  1399
  The file Residues.thy provides some infrastructure to use
lp15@68445
  1400
  facts about the unit group within the ring locale.
lp15@68445
  1401
\<close>
lp15@68445
  1402
lp15@68445
  1403
definition units_of :: "('a, 'b) monoid_scheme \<Rightarrow> 'a monoid"
lp15@68445
  1404
  where "units_of G =
lp15@68445
  1405
    \<lparr>carrier = Units G, Group.monoid.mult = Group.monoid.mult G, one  = one G\<rparr>"
lp15@68445
  1406
lp15@68445
  1407
lemma (in monoid) units_group: "group (units_of G)"
lp15@68458
  1408
proof -
lp15@68458
  1409
  have "\<And>x y z. \<lbrakk>x \<in> Units G; y \<in> Units G; z \<in> Units G\<rbrakk> \<Longrightarrow> x \<otimes> y \<otimes> z = x \<otimes> (y \<otimes> z)"
lp15@68458
  1410
    by (simp add: Units_closed m_assoc)
lp15@68458
  1411
  moreover have "\<And>x. x \<in> Units G \<Longrightarrow> \<exists>y\<in>Units G. y \<otimes> x = \<one>"
lp15@68458
  1412
    using Units_l_inv by blast
lp15@68458
  1413
  ultimately show ?thesis
lp15@68458
  1414
    unfolding units_of_def
lp15@68458
  1415
    by (force intro!: groupI)
lp15@68458
  1416
qed
lp15@68445
  1417
lp15@68445
  1418
lemma (in comm_monoid) units_comm_group: "comm_group (units_of G)"
lp15@68458
  1419
proof -
lp15@68458
  1420
  have "\<And>x y. \<lbrakk>x \<in> carrier (units_of G); y \<in> carrier (units_of G)\<rbrakk>
lp15@68458
  1421
              \<Longrightarrow> x \<otimes>\<^bsub>units_of G\<^esub> y = y \<otimes>\<^bsub>units_of G\<^esub> x"
lp15@68458
  1422
    by (simp add: Units_closed m_comm units_of_def)
lp15@68458
  1423
  then show ?thesis
lp15@68458
  1424
    by (rule group.group_comm_groupI [OF units_group]) auto
lp15@68458
  1425
qed
lp15@68445
  1426
lp15@68445
  1427
lemma units_of_carrier: "carrier (units_of G) = Units G"
lp15@68445
  1428
  by (auto simp: units_of_def)
lp15@68445
  1429
lp15@68445
  1430
lemma units_of_mult: "mult (units_of G) = mult G"
lp15@68445
  1431
  by (auto simp: units_of_def)
lp15@68445
  1432
lp15@68445
  1433
lemma units_of_one: "one (units_of G) = one G"
lp15@68445
  1434
  by (auto simp: units_of_def)
lp15@68445
  1435
lp15@68458
  1436
lemma (in monoid) units_of_inv: 
lp15@68458
  1437
  assumes "x \<in> Units G"
lp15@68458
  1438
  shows "m_inv (units_of G) x = m_inv G x"
lp15@68458
  1439
  by (simp add: assms group.inv_equality units_group units_of_carrier units_of_mult units_of_one)
lp15@68445
  1440
lp15@68551
  1441
lemma units_of_units [simp] : "Units (units_of G) = Units G"
lp15@68551
  1442
  unfolding units_of_def Units_def by force
lp15@68551
  1443
lp15@68445
  1444
lemma (in group) surj_const_mult: "a \<in> carrier G \<Longrightarrow> (\<lambda>x. a \<otimes> x) ` carrier G = carrier G"
lp15@68445
  1445
  apply (auto simp add: image_def)
lp15@68458
  1446
  by (metis inv_closed inv_solve_left m_closed)
lp15@68445
  1447
lp15@68445
  1448
lemma (in group) l_cancel_one [simp]: "x \<in> carrier G \<Longrightarrow> a \<in> carrier G \<Longrightarrow> x \<otimes> a = x \<longleftrightarrow> a = one G"
lp15@68445
  1449
  by (metis Units_eq Units_l_cancel monoid.r_one monoid_axioms one_closed)
lp15@68445
  1450
lp15@68445
  1451
lemma (in group) r_cancel_one [simp]: "x \<in> carrier G \<Longrightarrow> a \<in> carrier G \<Longrightarrow> a \<otimes> x = x \<longleftrightarrow> a = one G"
lp15@68445
  1452
  by (metis monoid.l_one monoid_axioms one_closed right_cancel)
lp15@68445
  1453
lp15@68445
  1454
lemma (in group) l_cancel_one' [simp]: "x \<in> carrier G \<Longrightarrow> a \<in> carrier G \<Longrightarrow> x = x \<otimes> a \<longleftrightarrow> a = one G"
lp15@68445
  1455
  using l_cancel_one by fastforce
lp15@68445
  1456
lp15@68445
  1457
lemma (in group) r_cancel_one' [simp]: "x \<in> carrier G \<Longrightarrow> a \<in> carrier G \<Longrightarrow> x = a \<otimes> x \<longleftrightarrow> a = one G"
lp15@68445
  1458
  using r_cancel_one by fastforce
lp15@68445
  1459
ballarin@13813
  1460
end