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