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