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