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