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