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