src/HOL/Algebra/Group.thy
author ballarin
Wed Apr 30 18:32:06 2003 +0200 (2003-04-30)
changeset 13940 c67798653056
parent 13936 d3671b878828
child 13943 83d842ccd4aa
permissions -rw-r--r--
HOL-Algebra: New polynomial development added.
     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 header {* Algebraic Structures up to Commutative Groups *}
    10 
    11 theory Group = FuncSet:
    12 
    13 axclass number < type
    14 
    15 instance nat :: number ..
    16 instance int :: number ..
    17 
    18 section {* From Magmas to Groups *}
    19 
    20 text {*
    21   Definitions follow Jacobson, Basic Algebra I, Freeman, 1985; with
    22   the exception of \emph{magma} which, following Bourbaki, is a set
    23   together with a binary, closed operation.
    24 *}
    25 
    26 subsection {* Definitions *}
    27 
    28 record 'a semigroup =
    29   carrier :: "'a set"
    30   mult :: "['a, 'a] => 'a" (infixl "\<otimes>\<index>" 70)
    31 
    32 record 'a monoid = "'a semigroup" +
    33   one :: 'a ("\<one>\<index>")
    34 
    35 constdefs
    36   m_inv :: "[('a, 'm) monoid_scheme, 'a] => 'a" ("inv\<index> _" [81] 80)
    37   "m_inv G x == (THE y. y \<in> carrier G &
    38                   mult G x y = one G & mult G y x = one G)"
    39 
    40   Units :: "('a, 'm) monoid_scheme => 'a set"
    41   "Units G == {y. y \<in> carrier G &
    42                   (EX x : carrier G. mult G x y = one G & mult G y x = one G)}"
    43 
    44 consts
    45   pow :: "[('a, 'm) monoid_scheme, 'a, 'b::number] => 'a" (infixr "'(^')\<index>" 75)
    46 
    47 defs (overloaded)
    48   nat_pow_def: "pow G a n == nat_rec (one G) (%u b. mult G b a) n"
    49   int_pow_def: "pow G a z ==
    50     let p = nat_rec (one G) (%u b. mult G b a)
    51     in if neg z then m_inv G (p (nat (-z))) else p (nat z)"
    52 
    53 locale magma = struct G +
    54   assumes m_closed [intro, simp]:
    55     "[| x \<in> carrier G; y \<in> carrier G |] ==> x \<otimes> y \<in> carrier G"
    56 
    57 locale semigroup = magma +
    58   assumes m_assoc:
    59     "[| x \<in> carrier G; y \<in> carrier G; z \<in> carrier G |] ==>
    60     (x \<otimes> y) \<otimes> z = x \<otimes> (y \<otimes> z)"
    61 
    62 locale monoid = semigroup +
    63   assumes one_closed [intro, simp]: "\<one> \<in> carrier G"
    64     and l_one [simp]: "x \<in> carrier G ==> \<one> \<otimes> x = x"
    65     and r_one [simp]: "x \<in> carrier G ==> x \<otimes> \<one> = x"
    66 
    67 lemma monoidI:
    68   assumes m_closed:
    69       "!!x y. [| x \<in> carrier G; y \<in> carrier G |] ==> mult G x y \<in> carrier G"
    70     and one_closed: "one G \<in> carrier G"
    71     and m_assoc:
    72       "!!x y z. [| x \<in> carrier G; y \<in> carrier G; z \<in> carrier G |] ==>
    73       mult G (mult G x y) z = mult G x (mult G y z)"
    74     and l_one: "!!x. x \<in> carrier G ==> mult G (one G) x = x"
    75     and r_one: "!!x. x \<in> carrier G ==> mult G x (one G) = x"
    76   shows "monoid G"
    77   by (fast intro!: monoid.intro magma.intro semigroup_axioms.intro
    78     semigroup.intro monoid_axioms.intro
    79     intro: prems)
    80 
    81 lemma (in monoid) Units_closed [dest]:
    82   "x \<in> Units G ==> x \<in> carrier G"
    83   by (unfold Units_def) fast
    84 
    85 lemma (in monoid) inv_unique:
    86   assumes eq: "y \<otimes> x = \<one>" "x \<otimes> y' = \<one>"
    87     and G: "x \<in> carrier G" "y \<in> carrier G" "y' \<in> carrier G"
    88   shows "y = y'"
    89 proof -
    90   from G eq have "y = y \<otimes> (x \<otimes> y')" by simp
    91   also from G have "... = (y \<otimes> x) \<otimes> y'" by (simp add: m_assoc)
    92   also from G eq have "... = y'" by simp
    93   finally show ?thesis .
    94 qed
    95 
    96 lemma (in monoid) Units_one_closed [intro, simp]:
    97   "\<one> \<in> Units G"
    98   by (unfold Units_def) auto
    99 
   100 lemma (in monoid) Units_inv_closed [intro, simp]:
   101   "x \<in> Units G ==> inv x \<in> carrier G"
   102   apply (unfold Units_def m_inv_def)
   103   apply auto
   104   apply (rule theI2, fast)
   105    apply (fast intro: inv_unique)
   106   apply fast
   107   done
   108 
   109 lemma (in monoid) Units_l_inv:
   110   "x \<in> Units G ==> inv x \<otimes> x = \<one>"
   111   apply (unfold Units_def m_inv_def)
   112   apply auto
   113   apply (rule theI2, fast)
   114    apply (fast intro: inv_unique)
   115   apply fast
   116   done
   117 
   118 lemma (in monoid) Units_r_inv:
   119   "x \<in> Units G ==> x \<otimes> inv x = \<one>"
   120   apply (unfold Units_def m_inv_def)
   121   apply auto
   122   apply (rule theI2, fast)
   123    apply (fast intro: inv_unique)
   124   apply fast
   125   done
   126 
   127 lemma (in monoid) Units_inv_Units [intro, simp]:
   128   "x \<in> Units G ==> inv x \<in> Units G"
   129 proof -
   130   assume x: "x \<in> Units G"
   131   show "inv x \<in> Units G"
   132     by (auto simp add: Units_def
   133       intro: Units_l_inv Units_r_inv x Units_closed [OF x])
   134 qed
   135 
   136 lemma (in monoid) Units_l_cancel [simp]:
   137   "[| x \<in> Units G; y \<in> carrier G; z \<in> carrier G |] ==>
   138    (x \<otimes> y = x \<otimes> z) = (y = z)"
   139 proof
   140   assume eq: "x \<otimes> y = x \<otimes> z"
   141     and G: "x \<in> Units G" "y \<in> carrier G" "z \<in> carrier G"
   142   then have "(inv x \<otimes> x) \<otimes> y = (inv x \<otimes> x) \<otimes> z"
   143     by (simp add: m_assoc Units_closed)
   144   with G show "y = z" by (simp add: Units_l_inv)
   145 next
   146   assume eq: "y = z"
   147     and G: "x \<in> Units G" "y \<in> carrier G" "z \<in> carrier G"
   148   then show "x \<otimes> y = x \<otimes> z" by simp
   149 qed
   150 
   151 lemma (in monoid) Units_inv_inv [simp]:
   152   "x \<in> Units G ==> inv (inv x) = x"
   153 proof -
   154   assume x: "x \<in> Units G"
   155   then have "inv x \<otimes> inv (inv x) = inv x \<otimes> x"
   156     by (simp add: Units_l_inv Units_r_inv)
   157   with x show ?thesis by (simp add: Units_closed)
   158 qed
   159 
   160 lemma (in monoid) inv_inj_on_Units:
   161   "inj_on (m_inv G) (Units G)"
   162 proof (rule inj_onI)
   163   fix x y
   164   assume G: "x \<in> Units G" "y \<in> Units G" and eq: "inv x = inv y"
   165   then have "inv (inv x) = inv (inv y)" by simp
   166   with G show "x = y" by simp
   167 qed
   168 
   169 lemma (in monoid) Units_inv_comm:
   170   assumes inv: "x \<otimes> y = \<one>"
   171     and G: "x \<in> Units G" "y \<in> Units G"
   172   shows "y \<otimes> x = \<one>"
   173 proof -
   174   from G have "x \<otimes> y \<otimes> x = x \<otimes> \<one>" by (auto simp add: inv Units_closed)
   175   with G show ?thesis by (simp del: r_one add: m_assoc Units_closed)
   176 qed
   177 
   178 text {* Power *}
   179 
   180 lemma (in monoid) nat_pow_closed [intro, simp]:
   181   "x \<in> carrier G ==> x (^) (n::nat) \<in> carrier G"
   182   by (induct n) (simp_all add: nat_pow_def)
   183 
   184 lemma (in monoid) nat_pow_0 [simp]:
   185   "x (^) (0::nat) = \<one>"
   186   by (simp add: nat_pow_def)
   187 
   188 lemma (in monoid) nat_pow_Suc [simp]:
   189   "x (^) (Suc n) = x (^) n \<otimes> x"
   190   by (simp add: nat_pow_def)
   191 
   192 lemma (in monoid) nat_pow_one [simp]:
   193   "\<one> (^) (n::nat) = \<one>"
   194   by (induct n) simp_all
   195 
   196 lemma (in monoid) nat_pow_mult:
   197   "x \<in> carrier G ==> x (^) (n::nat) \<otimes> x (^) m = x (^) (n + m)"
   198   by (induct m) (simp_all add: m_assoc [THEN sym])
   199 
   200 lemma (in monoid) nat_pow_pow:
   201   "x \<in> carrier G ==> (x (^) n) (^) m = x (^) (n * m::nat)"
   202   by (induct m) (simp, simp add: nat_pow_mult add_commute)
   203 
   204 text {*
   205   A group is a monoid all of whose elements are invertible.
   206 *}
   207 
   208 locale group = monoid +
   209   assumes Units: "carrier G <= Units G"
   210 
   211 theorem groupI:
   212   assumes m_closed [simp]:
   213       "!!x y. [| x \<in> carrier G; y \<in> carrier G |] ==> mult G x y \<in> carrier G"
   214     and one_closed [simp]: "one G \<in> carrier G"
   215     and m_assoc:
   216       "!!x y z. [| x \<in> carrier G; y \<in> carrier G; z \<in> carrier G |] ==>
   217       mult G (mult G x y) z = mult G x (mult G y z)"
   218     and l_one [simp]: "!!x. x \<in> carrier G ==> mult G (one G) x = x"
   219     and l_inv_ex: "!!x. x \<in> carrier G ==> EX y : carrier G. mult G y x = one G"
   220   shows "group G"
   221 proof -
   222   have l_cancel [simp]:
   223     "!!x y z. [| x \<in> carrier G; y \<in> carrier G; z \<in> carrier G |] ==>
   224     (mult G x y = mult G x z) = (y = z)"
   225   proof
   226     fix x y z
   227     assume eq: "mult G x y = mult G x z"
   228       and G: "x \<in> carrier G" "y \<in> carrier G" "z \<in> carrier G"
   229     with l_inv_ex obtain x_inv where xG: "x_inv \<in> carrier G"
   230       and l_inv: "mult G x_inv x = one G" by fast
   231     from G eq xG have "mult G (mult G x_inv x) y = mult G (mult G x_inv x) z"
   232       by (simp add: m_assoc)
   233     with G show "y = z" by (simp add: l_inv)
   234   next
   235     fix x y z
   236     assume eq: "y = z"
   237       and G: "x \<in> carrier G" "y \<in> carrier G" "z \<in> carrier G"
   238     then show "mult G x y = mult G x z" by simp
   239   qed
   240   have r_one:
   241     "!!x. x \<in> carrier G ==> mult G x (one G) = x"
   242   proof -
   243     fix x
   244     assume x: "x \<in> carrier G"
   245     with l_inv_ex obtain x_inv where xG: "x_inv \<in> carrier G"
   246       and l_inv: "mult G x_inv x = one G" by fast
   247     from x xG have "mult G x_inv (mult G x (one G)) = mult G x_inv x"
   248       by (simp add: m_assoc [symmetric] l_inv)
   249     with x xG show "mult G x (one G) = x" by simp 
   250   qed
   251   have inv_ex:
   252     "!!x. x \<in> carrier G ==> EX y : carrier G. mult G y x = one G &
   253       mult G x y = one G"
   254   proof -
   255     fix x
   256     assume x: "x \<in> carrier G"
   257     with l_inv_ex obtain y where y: "y \<in> carrier G"
   258       and l_inv: "mult G y x = one G" by fast
   259     from x y have "mult G y (mult G x y) = mult G y (one G)"
   260       by (simp add: m_assoc [symmetric] l_inv r_one)
   261     with x y have r_inv: "mult G x y = one G"
   262       by simp
   263     from x y show "EX y : carrier G. mult G y x = one G &
   264       mult G x y = one G"
   265       by (fast intro: l_inv r_inv)
   266   qed
   267   then have carrier_subset_Units: "carrier G <= Units G"
   268     by (unfold Units_def) fast
   269   show ?thesis
   270     by (fast intro!: group.intro magma.intro semigroup_axioms.intro
   271       semigroup.intro monoid_axioms.intro group_axioms.intro
   272       carrier_subset_Units intro: prems r_one)
   273 qed
   274 
   275 lemma (in monoid) monoid_groupI:
   276   assumes l_inv_ex:
   277     "!!x. x \<in> carrier G ==> EX y : carrier G. mult G y x = one G"
   278   shows "group G"
   279   by (rule groupI) (auto intro: m_assoc l_inv_ex)
   280 
   281 lemma (in group) Units_eq [simp]:
   282   "Units G = carrier G"
   283 proof
   284   show "Units G <= carrier G" by fast
   285 next
   286   show "carrier G <= Units G" by (rule Units)
   287 qed
   288 
   289 lemma (in group) inv_closed [intro, simp]:
   290   "x \<in> carrier G ==> inv x \<in> carrier G"
   291   using Units_inv_closed by simp
   292 
   293 lemma (in group) l_inv:
   294   "x \<in> carrier G ==> inv x \<otimes> x = \<one>"
   295   using Units_l_inv by simp
   296 
   297 subsection {* Cancellation Laws and Basic Properties *}
   298 
   299 lemma (in group) l_cancel [simp]:
   300   "[| x \<in> carrier G; y \<in> carrier G; z \<in> carrier G |] ==>
   301    (x \<otimes> y = x \<otimes> z) = (y = z)"
   302   using Units_l_inv by simp
   303 
   304 lemma (in group) r_inv:
   305   "x \<in> carrier G ==> x \<otimes> inv x = \<one>"
   306 proof -
   307   assume x: "x \<in> carrier G"
   308   then have "inv x \<otimes> (x \<otimes> inv x) = inv x \<otimes> \<one>"
   309     by (simp add: m_assoc [symmetric] l_inv)
   310   with x show ?thesis by (simp del: r_one)
   311 qed
   312 
   313 lemma (in group) r_cancel [simp]:
   314   "[| x \<in> carrier G; y \<in> carrier G; z \<in> carrier G |] ==>
   315    (y \<otimes> x = z \<otimes> x) = (y = z)"
   316 proof
   317   assume eq: "y \<otimes> x = z \<otimes> x"
   318     and G: "x \<in> carrier G" "y \<in> carrier G" "z \<in> carrier G"
   319   then have "y \<otimes> (x \<otimes> inv x) = z \<otimes> (x \<otimes> inv x)"
   320     by (simp add: m_assoc [symmetric])
   321   with G show "y = z" by (simp add: r_inv)
   322 next
   323   assume eq: "y = z"
   324     and G: "x \<in> carrier G" "y \<in> carrier G" "z \<in> carrier G"
   325   then show "y \<otimes> x = z \<otimes> x" by simp
   326 qed
   327 
   328 lemma (in group) inv_one [simp]:
   329   "inv \<one> = \<one>"
   330 proof -
   331   have "inv \<one> = \<one> \<otimes> (inv \<one>)" by simp
   332   moreover have "... = \<one>" by (simp add: r_inv)
   333   finally show ?thesis .
   334 qed
   335 
   336 lemma (in group) inv_inv [simp]:
   337   "x \<in> carrier G ==> inv (inv x) = x"
   338   using Units_inv_inv by simp
   339 
   340 lemma (in group) inv_inj:
   341   "inj_on (m_inv G) (carrier G)"
   342   using inv_inj_on_Units by simp
   343 
   344 lemma (in group) inv_mult_group:
   345   "[| x \<in> carrier G; y \<in> carrier G |] ==> inv (x \<otimes> y) = inv y \<otimes> inv x"
   346 proof -
   347   assume G: "x \<in> carrier G" "y \<in> carrier G"
   348   then have "inv (x \<otimes> y) \<otimes> (x \<otimes> y) = (inv y \<otimes> inv x) \<otimes> (x \<otimes> y)"
   349     by (simp add: m_assoc l_inv) (simp add: m_assoc [symmetric] l_inv)
   350   with G show ?thesis by simp
   351 qed
   352 
   353 lemma (in group) inv_comm:
   354   "[| x \<otimes> y = \<one>; x \<in> carrier G; y \<in> carrier G |] ==> y \<otimes> x = \<one>"
   355   by (rule Units_inv_comm) auto                          
   356 
   357 text {* Power *}
   358 
   359 lemma (in group) int_pow_def2:
   360   "a (^) (z::int) = (if neg z then inv (a (^) (nat (-z))) else a (^) (nat z))"
   361   by (simp add: int_pow_def nat_pow_def Let_def)
   362 
   363 lemma (in group) int_pow_0 [simp]:
   364   "x (^) (0::int) = \<one>"
   365   by (simp add: int_pow_def2)
   366 
   367 lemma (in group) int_pow_one [simp]:
   368   "\<one> (^) (z::int) = \<one>"
   369   by (simp add: int_pow_def2)
   370 
   371 subsection {* Substructures *}
   372 
   373 locale submagma = var H + struct G +
   374   assumes subset [intro, simp]: "H \<subseteq> carrier G"
   375     and m_closed [intro, simp]: "[| x \<in> H; y \<in> H |] ==> x \<otimes> y \<in> H"
   376 
   377 declare (in submagma) magma.intro [intro] semigroup.intro [intro]
   378   semigroup_axioms.intro [intro]
   379 (*
   380 alternative definition of submagma
   381 
   382 locale submagma = var H + struct G +
   383   assumes subset [intro, simp]: "carrier H \<subseteq> carrier G"
   384     and m_equal [simp]: "mult H = mult G"
   385     and m_closed [intro, simp]:
   386       "[| x \<in> carrier H; y \<in> carrier H |] ==> x \<otimes> y \<in> carrier H"
   387 *)
   388 
   389 lemma submagma_imp_subset:
   390   "submagma H G ==> H \<subseteq> carrier G"
   391   by (rule submagma.subset)
   392 
   393 lemma (in submagma) subsetD [dest, simp]:
   394   "x \<in> H ==> x \<in> carrier G"
   395   using subset by blast
   396 
   397 lemma (in submagma) magmaI [intro]:
   398   includes magma G
   399   shows "magma (G(| carrier := H |))"
   400   by rule simp
   401 
   402 lemma (in submagma) semigroup_axiomsI [intro]:
   403   includes semigroup G
   404   shows "semigroup_axioms (G(| carrier := H |))"
   405     by rule (simp add: m_assoc)
   406 
   407 lemma (in submagma) semigroupI [intro]:
   408   includes semigroup G
   409   shows "semigroup (G(| carrier := H |))"
   410   using prems by fast
   411 
   412 locale subgroup = submagma H G +
   413   assumes one_closed [intro, simp]: "\<one> \<in> H"
   414     and m_inv_closed [intro, simp]: "x \<in> H ==> inv x \<in> H"
   415 
   416 declare (in subgroup) group.intro [intro]
   417 (*
   418 lemma (in subgroup) l_oneI [intro]:
   419   includes l_one G
   420   shows "l_one (G(| carrier := H |))"
   421   by rule simp_all
   422 *)
   423 lemma (in subgroup) group_axiomsI [intro]:
   424   includes group G
   425   shows "group_axioms (G(| carrier := H |))"
   426   by rule (auto intro: l_inv r_inv simp add: Units_def)
   427 
   428 lemma (in subgroup) groupI [intro]:
   429   includes group G
   430   shows "group (G(| carrier := H |))"
   431   by (rule groupI) (auto intro: m_assoc l_inv)
   432 
   433 text {*
   434   Since @{term H} is nonempty, it contains some element @{term x}.  Since
   435   it is closed under inverse, it contains @{text "inv x"}.  Since
   436   it is closed under product, it contains @{text "x \<otimes> inv x = \<one>"}.
   437 *}
   438 
   439 lemma (in group) one_in_subset:
   440   "[| 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 |]
   441    ==> \<one> \<in> H"
   442 by (force simp add: l_inv)
   443 
   444 text {* A characterization of subgroups: closed, non-empty subset. *}
   445 
   446 lemma (in group) subgroupI:
   447   assumes subset: "H \<subseteq> carrier G" and non_empty: "H \<noteq> {}"
   448     and inv: "!!a. a \<in> H ==> inv a \<in> H"
   449     and mult: "!!a b. [|a \<in> H; b \<in> H|] ==> a \<otimes> b \<in> H"
   450   shows "subgroup H G"
   451 proof
   452   from subset and mult show "submagma H G" ..
   453 next
   454   have "\<one> \<in> H" by (rule one_in_subset) (auto simp only: prems)
   455   with inv show "subgroup_axioms H G"
   456     by (intro subgroup_axioms.intro) simp_all
   457 qed
   458 
   459 text {*
   460   Repeat facts of submagmas for subgroups.  Necessary???
   461 *}
   462 
   463 lemma (in subgroup) subset:
   464   "H \<subseteq> carrier G"
   465   ..
   466 
   467 lemma (in subgroup) m_closed:
   468   "[| x \<in> H; y \<in> H |] ==> x \<otimes> y \<in> H"
   469   ..
   470 
   471 declare magma.m_closed [simp]
   472 
   473 declare monoid.one_closed [iff] group.inv_closed [simp]
   474   monoid.l_one [simp] monoid.r_one [simp] group.inv_inv [simp]
   475 
   476 lemma subgroup_nonempty:
   477   "~ subgroup {} G"
   478   by (blast dest: subgroup.one_closed)
   479 
   480 lemma (in subgroup) finite_imp_card_positive:
   481   "finite (carrier G) ==> 0 < card H"
   482 proof (rule classical)
   483   have sub: "subgroup H G" using prems ..
   484   assume fin: "finite (carrier G)"
   485     and zero: "~ 0 < card H"
   486   then have "finite H" by (blast intro: finite_subset dest: subset)
   487   with zero sub have "subgroup {} G" by simp
   488   with subgroup_nonempty show ?thesis by contradiction
   489 qed
   490 
   491 (*
   492 lemma (in monoid) Units_subgroup:
   493   "subgroup (Units G) G"
   494 *)
   495 
   496 subsection {* Direct Products *}
   497 
   498 constdefs
   499   DirProdSemigroup ::
   500     "[('a, 'm) semigroup_scheme, ('b, 'n) semigroup_scheme]
   501     => ('a \<times> 'b) semigroup"
   502     (infixr "\<times>\<^sub>s" 80)
   503   "G \<times>\<^sub>s H == (| carrier = carrier G \<times> carrier H,
   504     mult = (%(xg, xh) (yg, yh). (mult G xg yg, mult H xh yh)) |)"
   505 
   506   DirProdGroup ::
   507     "[('a, 'm) monoid_scheme, ('b, 'n) monoid_scheme] => ('a \<times> 'b) monoid"
   508     (infixr "\<times>\<^sub>g" 80)
   509   "G \<times>\<^sub>g H == (| carrier = carrier (G \<times>\<^sub>s H),
   510     mult = mult (G \<times>\<^sub>s H),
   511     one = (one G, one H) |)"
   512 (*
   513   DirProdGroup ::
   514     "[('a, 'm) group_scheme, ('b, 'n) group_scheme] => ('a \<times> 'b) group"
   515     (infixr "\<times>\<^sub>g" 80)
   516   "G \<times>\<^sub>g H == (| carrier = carrier (G \<times>\<^sub>m H),
   517     mult = mult (G \<times>\<^sub>m H),
   518     one = one (G \<times>\<^sub>m H),
   519     m_inv = (%(g, h). (m_inv G g, m_inv H h)) |)"
   520 *)
   521 
   522 lemma DirProdSemigroup_magma:
   523   includes magma G + magma H
   524   shows "magma (G \<times>\<^sub>s H)"
   525   by rule (auto simp add: DirProdSemigroup_def)
   526 
   527 lemma DirProdSemigroup_semigroup_axioms:
   528   includes semigroup G + semigroup H
   529   shows "semigroup_axioms (G \<times>\<^sub>s H)"
   530   by rule (auto simp add: DirProdSemigroup_def G.m_assoc H.m_assoc)
   531 
   532 lemma DirProdSemigroup_semigroup:
   533   includes semigroup G + semigroup H
   534   shows "semigroup (G \<times>\<^sub>s H)"
   535   using prems
   536   by (fast intro: semigroup.intro
   537     DirProdSemigroup_magma DirProdSemigroup_semigroup_axioms)
   538 
   539 lemma DirProdGroup_magma:
   540   includes magma G + magma H
   541   shows "magma (G \<times>\<^sub>g H)"
   542   by rule
   543     (auto simp add: DirProdGroup_def DirProdSemigroup_def)
   544 
   545 lemma DirProdGroup_semigroup_axioms:
   546   includes semigroup G + semigroup H
   547   shows "semigroup_axioms (G \<times>\<^sub>g H)"
   548   by rule
   549     (auto simp add: DirProdGroup_def DirProdSemigroup_def
   550       G.m_assoc H.m_assoc)
   551 
   552 lemma DirProdGroup_semigroup:
   553   includes semigroup G + semigroup H
   554   shows "semigroup (G \<times>\<^sub>g H)"
   555   using prems
   556   by (fast intro: semigroup.intro
   557     DirProdGroup_magma DirProdGroup_semigroup_axioms)
   558 
   559 (* ... and further lemmas for group ... *)
   560 
   561 lemma DirProdGroup_group:
   562   includes group G + group H
   563   shows "group (G \<times>\<^sub>g H)"
   564   by (rule groupI)
   565     (auto intro: G.m_assoc H.m_assoc G.l_inv H.l_inv
   566       simp add: DirProdGroup_def DirProdSemigroup_def)
   567 
   568 subsection {* Homomorphisms *}
   569 
   570 constdefs
   571   hom :: "[('a, 'c) semigroup_scheme, ('b, 'd) semigroup_scheme]
   572     => ('a => 'b)set"
   573   "hom G H ==
   574     {h. h \<in> carrier G -> carrier H &
   575       (\<forall>x \<in> carrier G. \<forall>y \<in> carrier G. h (mult G x y) = mult H (h x) (h y))}"
   576 
   577 lemma (in semigroup) hom:
   578   includes semigroup G
   579   shows "semigroup (| carrier = hom G G, mult = op o |)"
   580 proof
   581   show "magma (| carrier = hom G G, mult = op o |)"
   582     by rule (simp add: Pi_def hom_def)
   583 next
   584   show "semigroup_axioms (| carrier = hom G G, mult = op o |)"
   585     by rule (simp add: o_assoc)
   586 qed
   587 
   588 lemma hom_mult:
   589   "[| h \<in> hom G H; x \<in> carrier G; y \<in> carrier G |] 
   590    ==> h (mult G x y) = mult H (h x) (h y)"
   591   by (simp add: hom_def) 
   592 
   593 lemma hom_closed:
   594   "[| h \<in> hom G H; x \<in> carrier G |] ==> h x \<in> carrier H"
   595   by (auto simp add: hom_def funcset_mem)
   596 
   597 locale group_hom = group G + group H + var h +
   598   assumes homh: "h \<in> hom G H"
   599   notes hom_mult [simp] = hom_mult [OF homh]
   600     and hom_closed [simp] = hom_closed [OF homh]
   601 
   602 lemma (in group_hom) one_closed [simp]:
   603   "h \<one> \<in> carrier H"
   604   by simp
   605 
   606 lemma (in group_hom) hom_one [simp]:
   607   "h \<one> = \<one>\<^sub>2"
   608 proof -
   609   have "h \<one> \<otimes>\<^sub>2 \<one>\<^sub>2 = h \<one> \<otimes>\<^sub>2 h \<one>"
   610     by (simp add: hom_mult [symmetric] del: hom_mult)
   611   then show ?thesis by (simp del: r_one)
   612 qed
   613 
   614 lemma (in group_hom) inv_closed [simp]:
   615   "x \<in> carrier G ==> h (inv x) \<in> carrier H"
   616   by simp
   617 
   618 lemma (in group_hom) hom_inv [simp]:
   619   "x \<in> carrier G ==> h (inv x) = inv\<^sub>2 (h x)"
   620 proof -
   621   assume x: "x \<in> carrier G"
   622   then have "h x \<otimes>\<^sub>2 h (inv x) = \<one>\<^sub>2"
   623     by (simp add: hom_mult [symmetric] G.r_inv del: hom_mult)
   624   also from x have "... = h x \<otimes>\<^sub>2 inv\<^sub>2 (h x)"
   625     by (simp add: hom_mult [symmetric] H.r_inv del: hom_mult)
   626   finally have "h x \<otimes>\<^sub>2 h (inv x) = h x \<otimes>\<^sub>2 inv\<^sub>2 (h x)" .
   627   with x show ?thesis by simp
   628 qed
   629 
   630 section {* Commutative Structures *}
   631 
   632 text {*
   633   Naming convention: multiplicative structures that are commutative
   634   are called \emph{commutative}, additive structures are called
   635   \emph{Abelian}.
   636 *}
   637 
   638 subsection {* Definition *}
   639 
   640 locale comm_semigroup = semigroup +
   641   assumes m_comm: "[| x \<in> carrier G; y \<in> carrier G |] ==> x \<otimes> y = y \<otimes> x"
   642 
   643 lemma (in comm_semigroup) m_lcomm:
   644   "[| x \<in> carrier G; y \<in> carrier G; z \<in> carrier G |] ==>
   645    x \<otimes> (y \<otimes> z) = y \<otimes> (x \<otimes> z)"
   646 proof -
   647   assume xyz: "x \<in> carrier G" "y \<in> carrier G" "z \<in> carrier G"
   648   from xyz have "x \<otimes> (y \<otimes> z) = (x \<otimes> y) \<otimes> z" by (simp add: m_assoc)
   649   also from xyz have "... = (y \<otimes> x) \<otimes> z" by (simp add: m_comm)
   650   also from xyz have "... = y \<otimes> (x \<otimes> z)" by (simp add: m_assoc)
   651   finally show ?thesis .
   652 qed
   653 
   654 lemmas (in comm_semigroup) m_ac = m_assoc m_comm m_lcomm
   655 
   656 locale comm_monoid = comm_semigroup + monoid
   657 
   658 lemma comm_monoidI:
   659   assumes m_closed:
   660       "!!x y. [| x \<in> carrier G; y \<in> carrier G |] ==> mult G x y \<in> carrier G"
   661     and one_closed: "one G \<in> carrier G"
   662     and m_assoc:
   663       "!!x y z. [| x \<in> carrier G; y \<in> carrier G; z \<in> carrier G |] ==>
   664       mult G (mult G x y) z = mult G x (mult G y z)"
   665     and l_one: "!!x. x \<in> carrier G ==> mult G (one G) x = x"
   666     and m_comm:
   667       "!!x y. [| x \<in> carrier G; y \<in> carrier G |] ==> mult G x y = mult G y x"
   668   shows "comm_monoid G"
   669   using l_one
   670   by (auto intro!: comm_monoid.intro magma.intro semigroup_axioms.intro
   671     comm_semigroup_axioms.intro monoid_axioms.intro
   672     intro: prems simp: m_closed one_closed m_comm)
   673 
   674 lemma (in monoid) monoid_comm_monoidI:
   675   assumes m_comm:
   676       "!!x y. [| x \<in> carrier G; y \<in> carrier G |] ==> mult G x y = mult G y x"
   677   shows "comm_monoid G"
   678   by (rule comm_monoidI) (auto intro: m_assoc m_comm)
   679 (*
   680 lemma (in comm_monoid) r_one [simp]:
   681   "x \<in> carrier G ==> x \<otimes> \<one> = x"
   682 proof -
   683   assume G: "x \<in> carrier G"
   684   then have "x \<otimes> \<one> = \<one> \<otimes> x" by (simp add: m_comm)
   685   also from G have "... = x" by simp
   686   finally show ?thesis .
   687 qed
   688 *)
   689 
   690 lemma (in comm_monoid) nat_pow_distr:
   691   "[| x \<in> carrier G; y \<in> carrier G |] ==>
   692   (x \<otimes> y) (^) (n::nat) = x (^) n \<otimes> y (^) n"
   693   by (induct n) (simp, simp add: m_ac)
   694 
   695 locale comm_group = comm_monoid + group
   696 
   697 lemma (in group) group_comm_groupI:
   698   assumes m_comm: "!!x y. [| x \<in> carrier G; y \<in> carrier G |] ==>
   699       mult G x y = mult G y x"
   700   shows "comm_group G"
   701   by (fast intro: comm_group.intro comm_semigroup_axioms.intro
   702     group.axioms prems)
   703 
   704 lemma comm_groupI:
   705   assumes m_closed:
   706       "!!x y. [| x \<in> carrier G; y \<in> carrier G |] ==> mult G x y \<in> carrier G"
   707     and one_closed: "one G \<in> carrier G"
   708     and m_assoc:
   709       "!!x y z. [| x \<in> carrier G; y \<in> carrier G; z \<in> carrier G |] ==>
   710       mult G (mult G x y) z = mult G x (mult G y z)"
   711     and m_comm:
   712       "!!x y. [| x \<in> carrier G; y \<in> carrier G |] ==> mult G x y = mult G y x"
   713     and l_one: "!!x. x \<in> carrier G ==> mult G (one G) x = x"
   714     and l_inv_ex: "!!x. x \<in> carrier G ==> EX y : carrier G. mult G y x = one G"
   715   shows "comm_group G"
   716   by (fast intro: group.group_comm_groupI groupI prems)
   717 
   718 lemma (in comm_group) inv_mult:
   719   "[| x \<in> carrier G; y \<in> carrier G |] ==> inv (x \<otimes> y) = inv x \<otimes> inv y"
   720   by (simp add: m_ac inv_mult_group)
   721 
   722 end