src/HOL/Algebra/Group.thy
author wenzelm
Sun Mar 21 15:57:40 2010 +0100 (2010-03-21)
changeset 35847 19f1f7066917
parent 35416 d8d7d1b785af
child 35848 5443079512ea
permissions -rw-r--r--
eliminated old constdefs;
     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 definition
    26   m_inv :: "('a, 'b) monoid_scheme => 'a => 'a" ("inv\<index> _" [81] 80)
    27   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>)"
    28 
    29 definition
    30   Units :: "_ => 'a set"
    31   --{*The set of invertible elements*}
    32   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>)}"
    33 
    34 consts
    35   pow :: "[('a, 'm) monoid_scheme, 'a, 'b::number] => 'a" (infixr "'(^')\<index>" 75)
    36 
    37 defs (overloaded)
    38   nat_pow_def: "pow G a n == nat_rec \<one>\<^bsub>G\<^esub> (%u b. b \<otimes>\<^bsub>G\<^esub> a) n"
    39   int_pow_def: "pow G a z ==
    40     let p = nat_rec \<one>\<^bsub>G\<^esub> (%u b. b \<otimes>\<^bsub>G\<^esub> a)
    41     in if neg z then inv\<^bsub>G\<^esub> (p (nat (-z))) else p (nat z)"
    42 
    43 locale monoid =
    44   fixes G (structure)
    45   assumes m_closed [intro, simp]:
    46          "\<lbrakk>x \<in> carrier G; y \<in> carrier G\<rbrakk> \<Longrightarrow> x \<otimes> y \<in> carrier G"
    47       and m_assoc:
    48          "\<lbrakk>x \<in> carrier G; y \<in> carrier G; z \<in> carrier G\<rbrakk> 
    49           \<Longrightarrow> (x \<otimes> y) \<otimes> z = x \<otimes> (y \<otimes> z)"
    50       and one_closed [intro, simp]: "\<one> \<in> carrier G"
    51       and l_one [simp]: "x \<in> carrier G \<Longrightarrow> \<one> \<otimes> x = x"
    52       and r_one [simp]: "x \<in> carrier G \<Longrightarrow> x \<otimes> \<one> = x"
    53 
    54 lemma monoidI:
    55   fixes G (structure)
    56   assumes m_closed:
    57       "!!x y. [| x \<in> carrier G; y \<in> carrier G |] ==> x \<otimes> y \<in> carrier G"
    58     and one_closed: "\<one> \<in> carrier G"
    59     and m_assoc:
    60       "!!x y z. [| x \<in> carrier G; y \<in> carrier G; z \<in> carrier G |] ==>
    61       (x \<otimes> y) \<otimes> z = x \<otimes> (y \<otimes> z)"
    62     and l_one: "!!x. x \<in> carrier G ==> \<one> \<otimes> x = x"
    63     and r_one: "!!x. x \<in> carrier G ==> x \<otimes> \<one> = x"
    64   shows "monoid G"
    65   by (fast intro!: monoid.intro intro: assms)
    66 
    67 lemma (in monoid) Units_closed [dest]:
    68   "x \<in> Units G ==> x \<in> carrier G"
    69   by (unfold Units_def) fast
    70 
    71 lemma (in monoid) inv_unique:
    72   assumes eq: "y \<otimes> x = \<one>"  "x \<otimes> y' = \<one>"
    73     and G: "x \<in> carrier G"  "y \<in> carrier G"  "y' \<in> carrier G"
    74   shows "y = y'"
    75 proof -
    76   from G eq have "y = y \<otimes> (x \<otimes> y')" by simp
    77   also from G have "... = (y \<otimes> x) \<otimes> y'" by (simp add: m_assoc)
    78   also from G eq have "... = y'" by simp
    79   finally show ?thesis .
    80 qed
    81 
    82 lemma (in monoid) Units_m_closed [intro, simp]:
    83   assumes x: "x \<in> Units G" and y: "y \<in> Units G"
    84   shows "x \<otimes> y \<in> Units G"
    85 proof -
    86   from x obtain x' where x: "x \<in> carrier G" "x' \<in> carrier G" and xinv: "x \<otimes> x' = \<one>" "x' \<otimes> x = \<one>"
    87     unfolding Units_def by fast
    88   from y obtain y' where y: "y \<in> carrier G" "y' \<in> carrier G" and yinv: "y \<otimes> y' = \<one>" "y' \<otimes> y = \<one>"
    89     unfolding Units_def by fast
    90   from x y xinv yinv have "y' \<otimes> (x' \<otimes> x) \<otimes> y = \<one>" by simp
    91   moreover from x y xinv yinv have "x \<otimes> (y \<otimes> y') \<otimes> x' = \<one>" by simp
    92   moreover note x y
    93   ultimately show ?thesis unfolding Units_def
    94     -- "Must avoid premature use of @{text hyp_subst_tac}."
    95     apply (rule_tac CollectI)
    96     apply (rule)
    97     apply (fast)
    98     apply (rule bexI [where x = "y' \<otimes> x'"])
    99     apply (auto simp: m_assoc)
   100     done
   101 qed
   102 
   103 lemma (in monoid) Units_one_closed [intro, simp]:
   104   "\<one> \<in> Units G"
   105   by (unfold Units_def) auto
   106 
   107 lemma (in monoid) Units_inv_closed [intro, simp]:
   108   "x \<in> Units G ==> inv x \<in> carrier G"
   109   apply (unfold Units_def m_inv_def, auto)
   110   apply (rule theI2, fast)
   111    apply (fast intro: inv_unique, fast)
   112   done
   113 
   114 lemma (in monoid) Units_l_inv_ex:
   115   "x \<in> Units G ==> \<exists>y \<in> carrier G. y \<otimes> x = \<one>"
   116   by (unfold Units_def) auto
   117 
   118 lemma (in monoid) Units_r_inv_ex:
   119   "x \<in> Units G ==> \<exists>y \<in> carrier G. x \<otimes> y = \<one>"
   120   by (unfold Units_def) auto
   121 
   122 lemma (in monoid) Units_l_inv [simp]:
   123   "x \<in> Units G ==> inv x \<otimes> x = \<one>"
   124   apply (unfold Units_def m_inv_def, auto)
   125   apply (rule theI2, fast)
   126    apply (fast intro: inv_unique, fast)
   127   done
   128 
   129 lemma (in monoid) Units_r_inv [simp]:
   130   "x \<in> Units G ==> x \<otimes> inv x = \<one>"
   131   apply (unfold Units_def m_inv_def, auto)
   132   apply (rule theI2, fast)
   133    apply (fast intro: inv_unique, fast)
   134   done
   135 
   136 lemma (in monoid) Units_inv_Units [intro, simp]:
   137   "x \<in> Units G ==> inv x \<in> Units G"
   138 proof -
   139   assume x: "x \<in> Units G"
   140   show "inv x \<in> Units G"
   141     by (auto simp add: Units_def
   142       intro: Units_l_inv Units_r_inv x Units_closed [OF x])
   143 qed
   144 
   145 lemma (in monoid) Units_l_cancel [simp]:
   146   "[| x \<in> Units G; y \<in> carrier G; z \<in> carrier G |] ==>
   147    (x \<otimes> y = x \<otimes> z) = (y = z)"
   148 proof
   149   assume eq: "x \<otimes> y = x \<otimes> z"
   150     and G: "x \<in> Units G"  "y \<in> carrier G"  "z \<in> carrier G"
   151   then have "(inv x \<otimes> x) \<otimes> y = (inv x \<otimes> x) \<otimes> z"
   152     by (simp add: m_assoc Units_closed del: Units_l_inv)
   153   with G show "y = z" by (simp add: Units_l_inv)
   154 next
   155   assume eq: "y = z"
   156     and G: "x \<in> Units G"  "y \<in> carrier G"  "z \<in> carrier G"
   157   then show "x \<otimes> y = x \<otimes> z" by simp
   158 qed
   159 
   160 lemma (in monoid) Units_inv_inv [simp]:
   161   "x \<in> Units G ==> inv (inv x) = x"
   162 proof -
   163   assume x: "x \<in> Units G"
   164   then have "inv x \<otimes> inv (inv x) = inv x \<otimes> x" by simp
   165   with x show ?thesis by (simp add: Units_closed del: Units_l_inv Units_r_inv)
   166 qed
   167 
   168 lemma (in monoid) inv_inj_on_Units:
   169   "inj_on (m_inv G) (Units G)"
   170 proof (rule inj_onI)
   171   fix x y
   172   assume G: "x \<in> Units G"  "y \<in> Units G" and eq: "inv x = inv y"
   173   then have "inv (inv x) = inv (inv y)" by simp
   174   with G show "x = y" by simp
   175 qed
   176 
   177 lemma (in monoid) Units_inv_comm:
   178   assumes inv: "x \<otimes> y = \<one>"
   179     and G: "x \<in> Units G"  "y \<in> Units G"
   180   shows "y \<otimes> x = \<one>"
   181 proof -
   182   from G have "x \<otimes> y \<otimes> x = x \<otimes> \<one>" by (auto simp add: inv Units_closed)
   183   with G show ?thesis by (simp del: r_one add: m_assoc Units_closed)
   184 qed
   185 
   186 text {* Power *}
   187 
   188 lemma (in monoid) nat_pow_closed [intro, simp]:
   189   "x \<in> carrier G ==> x (^) (n::nat) \<in> carrier G"
   190   by (induct n) (simp_all add: nat_pow_def)
   191 
   192 lemma (in monoid) nat_pow_0 [simp]:
   193   "x (^) (0::nat) = \<one>"
   194   by (simp add: nat_pow_def)
   195 
   196 lemma (in monoid) nat_pow_Suc [simp]:
   197   "x (^) (Suc n) = x (^) n \<otimes> x"
   198   by (simp add: nat_pow_def)
   199 
   200 lemma (in monoid) nat_pow_one [simp]:
   201   "\<one> (^) (n::nat) = \<one>"
   202   by (induct n) simp_all
   203 
   204 lemma (in monoid) nat_pow_mult:
   205   "x \<in> carrier G ==> x (^) (n::nat) \<otimes> x (^) m = x (^) (n + m)"
   206   by (induct m) (simp_all add: m_assoc [THEN sym])
   207 
   208 lemma (in monoid) nat_pow_pow:
   209   "x \<in> carrier G ==> (x (^) n) (^) m = x (^) (n * m::nat)"
   210   by (induct m) (simp, simp add: nat_pow_mult add_commute)
   211 
   212 
   213 (* Jacobson defines submonoid here. *)
   214 (* Jacobson defines the order of a monoid here. *)
   215 
   216 
   217 subsection {* Groups *}
   218 
   219 text {*
   220   A group is a monoid all of whose elements are invertible.
   221 *}
   222 
   223 locale group = monoid +
   224   assumes Units: "carrier G <= Units G"
   225 
   226 lemma (in group) is_group: "group G" by (rule group_axioms)
   227 
   228 theorem groupI:
   229   fixes G (structure)
   230   assumes m_closed [simp]:
   231       "!!x y. [| x \<in> carrier G; y \<in> carrier G |] ==> x \<otimes> y \<in> carrier G"
   232     and one_closed [simp]: "\<one> \<in> carrier G"
   233     and m_assoc:
   234       "!!x y z. [| x \<in> carrier G; y \<in> carrier G; z \<in> carrier G |] ==>
   235       (x \<otimes> y) \<otimes> z = x \<otimes> (y \<otimes> z)"
   236     and l_one [simp]: "!!x. x \<in> carrier G ==> \<one> \<otimes> x = x"
   237     and l_inv_ex: "!!x. x \<in> carrier G ==> \<exists>y \<in> carrier G. y \<otimes> x = \<one>"
   238   shows "group G"
   239 proof -
   240   have l_cancel [simp]:
   241     "!!x y z. [| x \<in> carrier G; y \<in> carrier G; z \<in> carrier G |] ==>
   242     (x \<otimes> y = x \<otimes> z) = (y = z)"
   243   proof
   244     fix x y z
   245     assume eq: "x \<otimes> y = x \<otimes> z"
   246       and G: "x \<in> carrier G"  "y \<in> carrier G"  "z \<in> carrier G"
   247     with l_inv_ex obtain x_inv where xG: "x_inv \<in> carrier G"
   248       and l_inv: "x_inv \<otimes> x = \<one>" by fast
   249     from G eq xG have "(x_inv \<otimes> x) \<otimes> y = (x_inv \<otimes> x) \<otimes> z"
   250       by (simp add: m_assoc)
   251     with G show "y = z" by (simp add: l_inv)
   252   next
   253     fix x y z
   254     assume eq: "y = z"
   255       and G: "x \<in> carrier G"  "y \<in> carrier G"  "z \<in> carrier G"
   256     then show "x \<otimes> y = x \<otimes> z" by simp
   257   qed
   258   have r_one:
   259     "!!x. x \<in> carrier G ==> x \<otimes> \<one> = x"
   260   proof -
   261     fix x
   262     assume x: "x \<in> carrier G"
   263     with l_inv_ex obtain x_inv where xG: "x_inv \<in> carrier G"
   264       and l_inv: "x_inv \<otimes> x = \<one>" by fast
   265     from x xG have "x_inv \<otimes> (x \<otimes> \<one>) = x_inv \<otimes> x"
   266       by (simp add: m_assoc [symmetric] l_inv)
   267     with x xG show "x \<otimes> \<one> = x" by simp
   268   qed
   269   have inv_ex:
   270     "!!x. x \<in> carrier G ==> \<exists>y \<in> carrier G. y \<otimes> x = \<one> & x \<otimes> y = \<one>"
   271   proof -
   272     fix x
   273     assume x: "x \<in> carrier G"
   274     with l_inv_ex obtain y where y: "y \<in> carrier G"
   275       and l_inv: "y \<otimes> x = \<one>" by fast
   276     from x y have "y \<otimes> (x \<otimes> y) = y \<otimes> \<one>"
   277       by (simp add: m_assoc [symmetric] l_inv r_one)
   278     with x y have r_inv: "x \<otimes> y = \<one>"
   279       by simp
   280     from x y show "\<exists>y \<in> carrier G. y \<otimes> x = \<one> & x \<otimes> y = \<one>"
   281       by (fast intro: l_inv r_inv)
   282   qed
   283   then have carrier_subset_Units: "carrier G <= Units G"
   284     by (unfold Units_def) fast
   285   show ?thesis proof qed (auto simp: r_one m_assoc carrier_subset_Units)
   286 qed
   287 
   288 lemma (in monoid) group_l_invI:
   289   assumes l_inv_ex:
   290     "!!x. x \<in> carrier G ==> \<exists>y \<in> carrier G. y \<otimes> x = \<one>"
   291   shows "group G"
   292   by (rule groupI) (auto intro: m_assoc l_inv_ex)
   293 
   294 lemma (in group) Units_eq [simp]:
   295   "Units G = carrier G"
   296 proof
   297   show "Units G <= carrier G" by fast
   298 next
   299   show "carrier G <= Units G" by (rule Units)
   300 qed
   301 
   302 lemma (in group) inv_closed [intro, simp]:
   303   "x \<in> carrier G ==> inv x \<in> carrier G"
   304   using Units_inv_closed by simp
   305 
   306 lemma (in group) l_inv_ex [simp]:
   307   "x \<in> carrier G ==> \<exists>y \<in> carrier G. y \<otimes> x = \<one>"
   308   using Units_l_inv_ex by simp
   309 
   310 lemma (in group) r_inv_ex [simp]:
   311   "x \<in> carrier G ==> \<exists>y \<in> carrier G. x \<otimes> y = \<one>"
   312   using Units_r_inv_ex by simp
   313 
   314 lemma (in group) l_inv [simp]:
   315   "x \<in> carrier G ==> inv x \<otimes> x = \<one>"
   316   using Units_l_inv by simp
   317 
   318 
   319 subsection {* Cancellation Laws and Basic Properties *}
   320 
   321 lemma (in group) l_cancel [simp]:
   322   "[| x \<in> carrier G; y \<in> carrier G; z \<in> carrier G |] ==>
   323    (x \<otimes> y = x \<otimes> z) = (y = z)"
   324   using Units_l_inv by simp
   325 
   326 lemma (in group) r_inv [simp]:
   327   "x \<in> carrier G ==> x \<otimes> inv x = \<one>"
   328 proof -
   329   assume x: "x \<in> carrier G"
   330   then have "inv x \<otimes> (x \<otimes> inv x) = inv x \<otimes> \<one>"
   331     by (simp add: m_assoc [symmetric] l_inv)
   332   with x show ?thesis by (simp del: r_one)
   333 qed
   334 
   335 lemma (in group) r_cancel [simp]:
   336   "[| x \<in> carrier G; y \<in> carrier G; z \<in> carrier G |] ==>
   337    (y \<otimes> x = z \<otimes> x) = (y = z)"
   338 proof
   339   assume eq: "y \<otimes> x = z \<otimes> x"
   340     and G: "x \<in> carrier G"  "y \<in> carrier G"  "z \<in> carrier G"
   341   then have "y \<otimes> (x \<otimes> inv x) = z \<otimes> (x \<otimes> inv x)"
   342     by (simp add: m_assoc [symmetric] del: r_inv Units_r_inv)
   343   with G show "y = z" by simp
   344 next
   345   assume eq: "y = z"
   346     and G: "x \<in> carrier G"  "y \<in> carrier G"  "z \<in> carrier G"
   347   then show "y \<otimes> x = z \<otimes> x" by simp
   348 qed
   349 
   350 lemma (in group) inv_one [simp]:
   351   "inv \<one> = \<one>"
   352 proof -
   353   have "inv \<one> = \<one> \<otimes> (inv \<one>)" by (simp del: r_inv Units_r_inv)
   354   moreover have "... = \<one>" by simp
   355   finally show ?thesis .
   356 qed
   357 
   358 lemma (in group) inv_inv [simp]:
   359   "x \<in> carrier G ==> inv (inv x) = x"
   360   using Units_inv_inv by simp
   361 
   362 lemma (in group) inv_inj:
   363   "inj_on (m_inv G) (carrier G)"
   364   using inv_inj_on_Units by simp
   365 
   366 lemma (in group) inv_mult_group:
   367   "[| x \<in> carrier G; y \<in> carrier G |] ==> inv (x \<otimes> y) = inv y \<otimes> inv x"
   368 proof -
   369   assume G: "x \<in> carrier G"  "y \<in> carrier G"
   370   then have "inv (x \<otimes> y) \<otimes> (x \<otimes> y) = (inv y \<otimes> inv x) \<otimes> (x \<otimes> y)"
   371     by (simp add: m_assoc l_inv) (simp add: m_assoc [symmetric])
   372   with G show ?thesis by (simp del: l_inv Units_l_inv)
   373 qed
   374 
   375 lemma (in group) inv_comm:
   376   "[| x \<otimes> y = \<one>; x \<in> carrier G; y \<in> carrier G |] ==> y \<otimes> x = \<one>"
   377   by (rule Units_inv_comm) auto
   378 
   379 lemma (in group) inv_equality:
   380      "[|y \<otimes> x = \<one>; x \<in> carrier G; y \<in> carrier G|] ==> inv x = y"
   381 apply (simp add: m_inv_def)
   382 apply (rule the_equality)
   383  apply (simp add: inv_comm [of y x])
   384 apply (rule r_cancel [THEN iffD1], auto)
   385 done
   386 
   387 text {* Power *}
   388 
   389 lemma (in group) int_pow_def2:
   390   "a (^) (z::int) = (if neg z then inv (a (^) (nat (-z))) else a (^) (nat z))"
   391   by (simp add: int_pow_def nat_pow_def Let_def)
   392 
   393 lemma (in group) int_pow_0 [simp]:
   394   "x (^) (0::int) = \<one>"
   395   by (simp add: int_pow_def2)
   396 
   397 lemma (in group) int_pow_one [simp]:
   398   "\<one> (^) (z::int) = \<one>"
   399   by (simp add: int_pow_def2)
   400 
   401 
   402 subsection {* Subgroups *}
   403 
   404 locale subgroup =
   405   fixes H and G (structure)
   406   assumes subset: "H \<subseteq> carrier G"
   407     and m_closed [intro, simp]: "\<lbrakk>x \<in> H; y \<in> H\<rbrakk> \<Longrightarrow> x \<otimes> y \<in> H"
   408     and one_closed [simp]: "\<one> \<in> H"
   409     and m_inv_closed [intro,simp]: "x \<in> H \<Longrightarrow> inv x \<in> H"
   410 
   411 lemma (in subgroup) is_subgroup:
   412   "subgroup H G" by (rule subgroup_axioms)
   413 
   414 declare (in subgroup) group.intro [intro]
   415 
   416 lemma (in subgroup) mem_carrier [simp]:
   417   "x \<in> H \<Longrightarrow> x \<in> carrier G"
   418   using subset by blast
   419 
   420 lemma subgroup_imp_subset:
   421   "subgroup H G \<Longrightarrow> H \<subseteq> carrier G"
   422   by (rule subgroup.subset)
   423 
   424 lemma (in subgroup) subgroup_is_group [intro]:
   425   assumes "group G"
   426   shows "group (G\<lparr>carrier := H\<rparr>)"
   427 proof -
   428   interpret group G by fact
   429   show ?thesis
   430     apply (rule monoid.group_l_invI)
   431     apply (unfold_locales) [1]
   432     apply (auto intro: m_assoc l_inv mem_carrier)
   433     done
   434 qed
   435 
   436 text {*
   437   Since @{term H} is nonempty, it contains some element @{term x}.  Since
   438   it is closed under inverse, it contains @{text "inv x"}.  Since
   439   it is closed under product, it contains @{text "x \<otimes> inv x = \<one>"}.
   440 *}
   441 
   442 lemma (in group) one_in_subset:
   443   "[| 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 |]
   444    ==> \<one> \<in> H"
   445 by (force simp add: l_inv)
   446 
   447 text {* A characterization of subgroups: closed, non-empty subset. *}
   448 
   449 lemma (in group) subgroupI:
   450   assumes subset: "H \<subseteq> carrier G" and non_empty: "H \<noteq> {}"
   451     and inv: "!!a. a \<in> H \<Longrightarrow> inv a \<in> H"
   452     and mult: "!!a b. \<lbrakk>a \<in> H; b \<in> H\<rbrakk> \<Longrightarrow> a \<otimes> b \<in> H"
   453   shows "subgroup H G"
   454 proof (simp add: subgroup_def assms)
   455   show "\<one> \<in> H" by (rule one_in_subset) (auto simp only: assms)
   456 qed
   457 
   458 declare monoid.one_closed [iff] group.inv_closed [simp]
   459   monoid.l_one [simp] monoid.r_one [simp] group.inv_inv [simp]
   460 
   461 lemma subgroup_nonempty:
   462   "~ subgroup {} G"
   463   by (blast dest: subgroup.one_closed)
   464 
   465 lemma (in subgroup) finite_imp_card_positive:
   466   "finite (carrier G) ==> 0 < card H"
   467 proof (rule classical)
   468   assume "finite (carrier G)" "~ 0 < card H"
   469   then have "finite H" by (blast intro: finite_subset [OF subset])
   470   with prems have "subgroup {} G" by simp
   471   with subgroup_nonempty show ?thesis by contradiction
   472 qed
   473 
   474 (*
   475 lemma (in monoid) Units_subgroup:
   476   "subgroup (Units G) G"
   477 *)
   478 
   479 
   480 subsection {* Direct Products *}
   481 
   482 definition DirProd :: "_ \<Rightarrow> _ \<Rightarrow> ('a \<times> 'b) monoid" (infixr "\<times>\<times>" 80) where
   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 definition
   539   hom :: "_ => _ => ('a => 'b) set" where
   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 (in group) hom_compose:
   545   "[|h \<in> hom G H; i \<in> hom H I|] ==> compose (carrier G) i h \<in> hom G I"
   546 by (fastsimp simp add: hom_def compose_def)
   547 
   548 definition iso :: "_ => _ => ('a => 'b) set" (infixr "\<cong>" 60) where
   549   "G \<cong> H == {h. h \<in> hom G H & bij_betw h (carrier G) (carrier H)}"
   550 
   551 lemma iso_refl: "(%x. x) \<in> G \<cong> G"
   552 by (simp add: iso_def hom_def inj_on_def bij_betw_def Pi_def)
   553 
   554 lemma (in group) iso_sym:
   555      "h \<in> G \<cong> H \<Longrightarrow> inv_into (carrier G) h \<in> H \<cong> G"
   556 apply (simp add: iso_def bij_betw_inv_into) 
   557 apply (subgoal_tac "inv_into (carrier G) h \<in> carrier H \<rightarrow> carrier G") 
   558  prefer 2 apply (simp add: bij_betw_imp_funcset [OF bij_betw_inv_into]) 
   559 apply (simp add: hom_def bij_betw_def inv_into_f_eq f_inv_into_f Pi_def)
   560 done
   561 
   562 lemma (in group) iso_trans: 
   563      "[|h \<in> G \<cong> H; i \<in> H \<cong> I|] ==> (compose (carrier G) i h) \<in> G \<cong> I"
   564 by (auto simp add: iso_def hom_compose bij_betw_compose)
   565 
   566 lemma DirProd_commute_iso:
   567   shows "(\<lambda>(x,y). (y,x)) \<in> (G \<times>\<times> H) \<cong> (H \<times>\<times> G)"
   568 by (auto simp add: iso_def hom_def inj_on_def bij_betw_def)
   569 
   570 lemma DirProd_assoc_iso:
   571   shows "(\<lambda>(x,y,z). (x,(y,z))) \<in> (G \<times>\<times> H \<times>\<times> I) \<cong> (G \<times>\<times> (H \<times>\<times> I))"
   572 by (auto simp add: iso_def hom_def inj_on_def bij_betw_def)
   573 
   574 
   575 text{*Basis for homomorphism proofs: we assume two groups @{term G} and
   576   @{term H}, with a homomorphism @{term h} between them*}
   577 locale group_hom = G: group G + H: group H for G (structure) and H (structure) +
   578   fixes h
   579   assumes homh: "h \<in> hom G H"
   580 
   581 lemma (in group_hom) hom_mult [simp]:
   582   "[| x \<in> carrier G; y \<in> carrier G |] ==> h (x \<otimes>\<^bsub>G\<^esub> y) = h x \<otimes>\<^bsub>H\<^esub> h y"
   583 proof -
   584   assume "x \<in> carrier G" "y \<in> carrier G"
   585   with homh [unfolded hom_def] show ?thesis by simp
   586 qed
   587 
   588 lemma (in group_hom) hom_closed [simp]:
   589   "x \<in> carrier G ==> h x \<in> carrier H"
   590 proof -
   591   assume "x \<in> carrier G"
   592   with homh [unfolded hom_def] show ?thesis by auto
   593 qed
   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