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