src/ZF/ex/Group.thy
author wenzelm
Tue Nov 07 19:40:13 2006 +0100 (2006-11-07)
changeset 21233 5a5c8ea5f66a
parent 19931 fb32b43e7f80
child 21404 eb85850d3eb7
permissions -rw-r--r--
tuned specifications;
     1 (* Title:  ZF/ex/Group.thy
     2   Id:     $Id$
     3 
     4 *)
     5 
     6 header {* Groups *}
     7 
     8 theory Group imports Main begin
     9 
    10 text{*Based on work by Clemens Ballarin, Florian Kammueller, L C Paulson and
    11 Markus Wenzel.*}
    12 
    13 
    14 subsection {* Monoids *}
    15 
    16 (*First, we must simulate a record declaration:
    17 record monoid = 
    18   carrier :: i
    19   mult :: "[i,i] => i" (infixl "\<cdot>\<index>" 70)
    20   one :: i ("\<one>\<index>")
    21 *)
    22 
    23 definition
    24   carrier :: "i => i"
    25   "carrier(M) == fst(M)"
    26 
    27   mmult :: "[i, i, i] => i" (infixl "\<cdot>\<index>" 70)
    28   "mmult(M,x,y) == fst(snd(M)) ` <x,y>"
    29 
    30   one :: "i => i" ("\<one>\<index>")
    31   "one(M) == fst(snd(snd(M)))"
    32 
    33   update_carrier :: "[i,i] => i"
    34   "update_carrier(M,A) == <A,snd(M)>"
    35 
    36 definition
    37   m_inv :: "i => i => i" ("inv\<index> _" [81] 80)
    38   "inv\<^bsub>G\<^esub> x == (THE y. y \<in> carrier(G) & y \<cdot>\<^bsub>G\<^esub> x = \<one>\<^bsub>G\<^esub> & x \<cdot>\<^bsub>G\<^esub> y = \<one>\<^bsub>G\<^esub>)"
    39 
    40 locale monoid = struct G +
    41   assumes m_closed [intro, simp]:
    42          "\<lbrakk>x \<in> carrier(G); y \<in> carrier(G)\<rbrakk> \<Longrightarrow> x \<cdot> y \<in> carrier(G)"
    43       and m_assoc:
    44          "\<lbrakk>x \<in> carrier(G); y \<in> carrier(G); z \<in> carrier(G)\<rbrakk> 
    45           \<Longrightarrow> (x \<cdot> y) \<cdot> z = x \<cdot> (y \<cdot> z)"
    46       and one_closed [intro, simp]: "\<one> \<in> carrier(G)"
    47       and l_one [simp]: "x \<in> carrier(G) \<Longrightarrow> \<one> \<cdot> x = x"
    48       and r_one [simp]: "x \<in> carrier(G) \<Longrightarrow> x \<cdot> \<one> = x"
    49 
    50 text{*Simulating the record*}
    51 lemma carrier_eq [simp]: "carrier(<A,Z>) = A"
    52   by (simp add: carrier_def)
    53 
    54 lemma mult_eq [simp]: "mmult(<A,M,Z>, x, y) = M ` <x,y>"
    55   by (simp add: mmult_def)
    56 
    57 lemma one_eq [simp]: "one(<A,M,I,Z>) = I"
    58   by (simp add: one_def)
    59 
    60 lemma update_carrier_eq [simp]: "update_carrier(<A,Z>,B) = <B,Z>"
    61   by (simp add: update_carrier_def)
    62 
    63 lemma carrier_update_carrier [simp]: "carrier(update_carrier(M,B)) = B"
    64 by (simp add: update_carrier_def) 
    65 
    66 lemma mult_update_carrier [simp]: "mmult(update_carrier(M,B),x,y) = mmult(M,x,y)"
    67 by (simp add: update_carrier_def mmult_def) 
    68 
    69 lemma one_update_carrier [simp]: "one(update_carrier(M,B)) = one(M)"
    70 by (simp add: update_carrier_def one_def) 
    71 
    72 
    73 lemma (in monoid) inv_unique:
    74   assumes eq: "y \<cdot> x = \<one>"  "x \<cdot> y' = \<one>"
    75     and G: "x \<in> carrier(G)"  "y \<in> carrier(G)"  "y' \<in> carrier(G)"
    76   shows "y = y'"
    77 proof -
    78   from G eq have "y = y \<cdot> (x \<cdot> y')" by simp
    79   also from G have "... = (y \<cdot> x) \<cdot> y'" by (simp add: m_assoc)
    80   also from G eq have "... = y'" by simp
    81   finally show ?thesis .
    82 qed
    83 
    84 text {*
    85   A group is a monoid all of whose elements are invertible.
    86 *}
    87 
    88 locale group = monoid +
    89   assumes inv_ex:
    90      "\<And>x. x \<in> carrier(G) \<Longrightarrow> \<exists>y \<in> carrier(G). y \<cdot> x = \<one> & x \<cdot> y = \<one>"
    91 
    92 lemma (in group) is_group [simp]: "group(G)" .
    93 
    94 theorem groupI:
    95   includes struct G
    96   assumes m_closed [simp]:
    97       "\<And>x y. \<lbrakk>x \<in> carrier(G); y \<in> carrier(G)\<rbrakk> \<Longrightarrow> x \<cdot> y \<in> carrier(G)"
    98     and one_closed [simp]: "\<one> \<in> carrier(G)"
    99     and m_assoc:
   100       "\<And>x y z. \<lbrakk>x \<in> carrier(G); y \<in> carrier(G); z \<in> carrier(G)\<rbrakk> \<Longrightarrow>
   101       (x \<cdot> y) \<cdot> z = x \<cdot> (y \<cdot> z)"
   102     and l_one [simp]: "\<And>x. x \<in> carrier(G) \<Longrightarrow> \<one> \<cdot> x = x"
   103     and l_inv_ex: "\<And>x. x \<in> carrier(G) \<Longrightarrow> \<exists>y \<in> carrier(G). y \<cdot> x = \<one>"
   104   shows "group(G)"
   105 proof -
   106   have l_cancel [simp]:
   107     "\<And>x y z. \<lbrakk>x \<in> carrier(G); y \<in> carrier(G); z \<in> carrier(G)\<rbrakk> \<Longrightarrow>
   108     (x \<cdot> y = x \<cdot> z) <-> (y = z)"
   109   proof
   110     fix x y z
   111     assume G: "x \<in> carrier(G)"  "y \<in> carrier(G)"  "z \<in> carrier(G)"
   112     { 
   113       assume eq: "x \<cdot> y = x \<cdot> z"
   114       with G l_inv_ex obtain x_inv where xG: "x_inv \<in> carrier(G)"
   115 	and l_inv: "x_inv \<cdot> x = \<one>" by fast
   116       from G eq xG have "(x_inv \<cdot> x) \<cdot> y = (x_inv \<cdot> x) \<cdot> z"
   117 	by (simp add: m_assoc)
   118       with G show "y = z" by (simp add: l_inv)
   119     next
   120       assume eq: "y = z"
   121       with G show "x \<cdot> y = x \<cdot> z" by simp
   122     }
   123   qed
   124   have r_one:
   125     "\<And>x. x \<in> carrier(G) \<Longrightarrow> x \<cdot> \<one> = x"
   126   proof -
   127     fix x
   128     assume x: "x \<in> carrier(G)"
   129     with l_inv_ex obtain x_inv where xG: "x_inv \<in> carrier(G)"
   130       and l_inv: "x_inv \<cdot> x = \<one>" by fast
   131     from x xG have "x_inv \<cdot> (x \<cdot> \<one>) = x_inv \<cdot> x"
   132       by (simp add: m_assoc [symmetric] l_inv)
   133     with x xG show "x \<cdot> \<one> = x" by simp
   134   qed
   135   have inv_ex:
   136     "!!x. x \<in> carrier(G) ==> \<exists>y \<in> carrier(G). y \<cdot> x = \<one> & x \<cdot> y = \<one>"
   137   proof -
   138     fix x
   139     assume x: "x \<in> carrier(G)"
   140     with l_inv_ex obtain y where y: "y \<in> carrier(G)"
   141       and l_inv: "y \<cdot> x = \<one>" by fast
   142     from x y have "y \<cdot> (x \<cdot> y) = y \<cdot> \<one>"
   143       by (simp add: m_assoc [symmetric] l_inv r_one)
   144     with x y have r_inv: "x \<cdot> y = \<one>"
   145       by simp
   146     from x y show "\<exists>y \<in> carrier(G). y \<cdot> x = \<one> & x \<cdot> y = \<one>"
   147       by (fast intro: l_inv r_inv)
   148   qed
   149   show ?thesis
   150     by (blast intro: group.intro monoid.intro group_axioms.intro 
   151                      prems r_one inv_ex)
   152 qed
   153 
   154 lemma (in group) inv [simp]:
   155   "x \<in> carrier(G) \<Longrightarrow> inv x \<in> carrier(G) & inv x \<cdot> x = \<one> & x \<cdot> inv x = \<one>"
   156   apply (frule inv_ex) 
   157   apply (unfold Bex_def m_inv_def)
   158   apply (erule exE) 
   159   apply (rule theI)
   160   apply (rule ex1I, assumption)
   161    apply (blast intro: inv_unique)
   162   done
   163 
   164 lemma (in group) inv_closed [intro!]:
   165   "x \<in> carrier(G) \<Longrightarrow> inv x \<in> carrier(G)"
   166   by simp
   167 
   168 lemma (in group) l_inv:
   169   "x \<in> carrier(G) \<Longrightarrow> inv x \<cdot> x = \<one>"
   170   by simp
   171 
   172 lemma (in group) r_inv:
   173   "x \<in> carrier(G) \<Longrightarrow> x \<cdot> inv x = \<one>"
   174   by simp
   175 
   176 
   177 subsection {* Cancellation Laws and Basic Properties *}
   178 
   179 lemma (in group) l_cancel [simp]:
   180   assumes [simp]: "x \<in> carrier(G)" "y \<in> carrier(G)" "z \<in> carrier(G)"
   181   shows "(x \<cdot> y = x \<cdot> z) <-> (y = z)"
   182 proof
   183   assume eq: "x \<cdot> y = x \<cdot> z"
   184   hence  "(inv x \<cdot> x) \<cdot> y = (inv x \<cdot> x) \<cdot> z"
   185     by (simp only: m_assoc inv_closed prems)
   186   thus "y = z" by simp
   187 next
   188   assume eq: "y = z"
   189   then show "x \<cdot> y = x \<cdot> z" by simp
   190 qed
   191 
   192 lemma (in group) r_cancel [simp]:
   193   assumes [simp]: "x \<in> carrier(G)" "y \<in> carrier(G)" "z \<in> carrier(G)"
   194   shows "(y \<cdot> x = z \<cdot> x) <-> (y = z)"
   195 proof
   196   assume eq: "y \<cdot> x = z \<cdot> x"
   197   then have "y \<cdot> (x \<cdot> inv x) = z \<cdot> (x \<cdot> inv x)"
   198     by (simp only: m_assoc [symmetric] inv_closed prems)
   199   thus "y = z" by simp
   200 next
   201   assume eq: "y = z"
   202   thus  "y \<cdot> x = z \<cdot> x" by simp
   203 qed
   204 
   205 lemma (in group) inv_comm:
   206   assumes inv: "x \<cdot> y = \<one>"
   207       and G: "x \<in> carrier(G)"  "y \<in> carrier(G)"
   208   shows "y \<cdot> x = \<one>"
   209 proof -
   210   from G have "x \<cdot> y \<cdot> x = x \<cdot> \<one>" by (auto simp add: inv)
   211   with G show ?thesis by (simp del: r_one add: m_assoc)
   212 qed
   213 
   214 lemma (in group) inv_equality:
   215      "\<lbrakk>y \<cdot> x = \<one>; x \<in> carrier(G); y \<in> carrier(G)\<rbrakk> \<Longrightarrow> inv x = y"
   216 apply (simp add: m_inv_def)
   217 apply (rule the_equality)
   218  apply (simp add: inv_comm [of y x])
   219 apply (rule r_cancel [THEN iffD1], auto)
   220 done
   221 
   222 lemma (in group) inv_one [simp]:
   223   "inv \<one> = \<one>"
   224   by (auto intro: inv_equality) 
   225 
   226 lemma (in group) inv_inv [simp]: "x \<in> carrier(G) \<Longrightarrow> inv (inv x) = x"
   227   by (auto intro: inv_equality) 
   228 
   229 text{*This proof is by cancellation*}
   230 lemma (in group) inv_mult_group:
   231   "\<lbrakk>x \<in> carrier(G); y \<in> carrier(G)\<rbrakk> \<Longrightarrow> inv (x \<cdot> y) = inv y \<cdot> inv x"
   232 proof -
   233   assume G: "x \<in> carrier(G)"  "y \<in> carrier(G)"
   234   then have "inv (x \<cdot> y) \<cdot> (x \<cdot> y) = (inv y \<cdot> inv x) \<cdot> (x \<cdot> y)"
   235     by (simp add: m_assoc l_inv) (simp add: m_assoc [symmetric] l_inv)
   236   with G show ?thesis by (simp_all del: inv add: inv_closed)
   237 qed
   238 
   239 
   240 subsection {* Substructures *}
   241 
   242 locale subgroup = var H + struct G + 
   243   assumes subset: "H \<subseteq> carrier(G)"
   244     and m_closed [intro, simp]: "\<lbrakk>x \<in> H; y \<in> H\<rbrakk> \<Longrightarrow> x \<cdot> y \<in> H"
   245     and  one_closed [simp]: "\<one> \<in> H"
   246     and m_inv_closed [intro,simp]: "x \<in> H \<Longrightarrow> inv x \<in> H"
   247 
   248 
   249 lemma (in subgroup) mem_carrier [simp]:
   250   "x \<in> H \<Longrightarrow> x \<in> carrier(G)"
   251   using subset by blast
   252 
   253 
   254 lemma subgroup_imp_subset:
   255   "subgroup(H,G) \<Longrightarrow> H \<subseteq> carrier(G)"
   256   by (rule subgroup.subset)
   257 
   258 lemma (in subgroup) group_axiomsI [intro]:
   259   includes group G
   260   shows "group_axioms (update_carrier(G,H))"
   261 by (force intro: group_axioms.intro l_inv r_inv) 
   262 
   263 lemma (in subgroup) is_group [intro]:
   264   includes group G
   265   shows "group (update_carrier(G,H))"
   266   by (rule groupI) (auto intro: m_assoc l_inv mem_carrier)
   267 
   268 text {*
   269   Since @{term H} is nonempty, it contains some element @{term x}.  Since
   270   it is closed under inverse, it contains @{text "inv x"}.  Since
   271   it is closed under product, it contains @{text "x \<cdot> inv x = \<one>"}.
   272 *}
   273 
   274 text {*
   275   Since @{term H} is nonempty, it contains some element @{term x}.  Since
   276   it is closed under inverse, it contains @{text "inv x"}.  Since
   277   it is closed under product, it contains @{text "x \<cdot> inv x = \<one>"}.
   278 *}
   279 
   280 lemma (in group) one_in_subset:
   281   "\<lbrakk>H \<subseteq> carrier(G); H \<noteq> 0; \<forall>a \<in> H. inv a \<in> H; \<forall>a\<in>H. \<forall>b\<in>H. a \<cdot> b \<in> H\<rbrakk>
   282    \<Longrightarrow> \<one> \<in> H"
   283 by (force simp add: l_inv)
   284 
   285 text {* A characterization of subgroups: closed, non-empty subset. *}
   286 
   287 declare monoid.one_closed [simp] group.inv_closed [simp]
   288   monoid.l_one [simp] monoid.r_one [simp] group.inv_inv [simp]
   289 
   290 lemma subgroup_nonempty:
   291   "~ subgroup(0,G)"
   292   by (blast dest: subgroup.one_closed)
   293 
   294 
   295 subsection {* Direct Products *}
   296 
   297 definition
   298   DirProdGroup :: "[i,i] => i"  (infixr "\<Otimes>" 80)
   299   "G \<Otimes> H == <carrier(G) \<times> carrier(H),
   300               (\<lambda><<g,h>, <g', h'>>
   301                    \<in> (carrier(G) \<times> carrier(H)) \<times> (carrier(G) \<times> carrier(H)).
   302                 <g \<cdot>\<^bsub>G\<^esub> g', h \<cdot>\<^bsub>H\<^esub> h'>),
   303               <\<one>\<^bsub>G\<^esub>, \<one>\<^bsub>H\<^esub>>, 0>"
   304 
   305 lemma DirProdGroup_group:
   306   includes group G + group H
   307   shows "group (G \<Otimes> H)"
   308 by (force intro!: groupI G.m_assoc H.m_assoc G.l_inv H.l_inv
   309           simp add: DirProdGroup_def)
   310 
   311 lemma carrier_DirProdGroup [simp]:
   312      "carrier (G \<Otimes> H) = carrier(G) \<times> carrier(H)"
   313   by (simp add: DirProdGroup_def)
   314 
   315 lemma one_DirProdGroup [simp]:
   316      "\<one>\<^bsub>G \<Otimes> H\<^esub> = <\<one>\<^bsub>G\<^esub>, \<one>\<^bsub>H\<^esub>>"
   317   by (simp add: DirProdGroup_def)
   318 
   319 lemma mult_DirProdGroup [simp]:
   320      "[|g \<in> carrier(G); h \<in> carrier(H); g' \<in> carrier(G); h' \<in> carrier(H)|]
   321       ==> <g, h> \<cdot>\<^bsub>G \<Otimes> H\<^esub> <g', h'> = <g \<cdot>\<^bsub>G\<^esub> g', h \<cdot>\<^bsub>H\<^esub> h'>"
   322 by (simp add: DirProdGroup_def)
   323 
   324 lemma inv_DirProdGroup [simp]:
   325   includes group G + group H
   326   assumes g: "g \<in> carrier(G)"
   327       and h: "h \<in> carrier(H)"
   328   shows "inv \<^bsub>G \<Otimes> H\<^esub> <g, h> = <inv\<^bsub>G\<^esub> g, inv\<^bsub>H\<^esub> h>"
   329   apply (rule group.inv_equality [OF DirProdGroup_group])
   330   apply (simp_all add: prems group.l_inv)
   331   done
   332 
   333 subsection {* Isomorphisms *}
   334 
   335 definition
   336   hom :: "[i,i] => i"
   337   "hom(G,H) ==
   338     {h \<in> carrier(G) -> carrier(H).
   339       (\<forall>x \<in> carrier(G). \<forall>y \<in> carrier(G). h ` (x \<cdot>\<^bsub>G\<^esub> y) = (h ` x) \<cdot>\<^bsub>H\<^esub> (h ` y))}"
   340 
   341 lemma hom_mult:
   342   "\<lbrakk>h \<in> hom(G,H); x \<in> carrier(G); y \<in> carrier(G)\<rbrakk>
   343    \<Longrightarrow> h ` (x \<cdot>\<^bsub>G\<^esub> y) = h ` x \<cdot>\<^bsub>H\<^esub> h ` y"
   344   by (simp add: hom_def)
   345 
   346 lemma hom_closed:
   347   "\<lbrakk>h \<in> hom(G,H); x \<in> carrier(G)\<rbrakk> \<Longrightarrow> h ` x \<in> carrier(H)"
   348   by (auto simp add: hom_def)
   349 
   350 lemma (in group) hom_compose:
   351      "\<lbrakk>h \<in> hom(G,H); i \<in> hom(H,I)\<rbrakk> \<Longrightarrow> i O h \<in> hom(G,I)"
   352 by (force simp add: hom_def comp_fun) 
   353 
   354 lemma hom_is_fun:
   355   "h \<in> hom(G,H) \<Longrightarrow> h \<in> carrier(G) -> carrier(H)"
   356   by (simp add: hom_def)
   357 
   358 
   359 subsection {* Isomorphisms *}
   360 
   361 definition
   362   iso :: "[i,i] => i"  (infixr "\<cong>" 60)
   363   "G \<cong> H == hom(G,H) \<inter> bij(carrier(G), carrier(H))"
   364 
   365 lemma (in group) iso_refl: "id(carrier(G)) \<in> G \<cong> G"
   366 by (simp add: iso_def hom_def id_type id_bij) 
   367 
   368 
   369 lemma (in group) iso_sym:
   370      "h \<in> G \<cong> H \<Longrightarrow> converse(h) \<in> H \<cong> G"
   371 apply (simp add: iso_def bij_converse_bij, clarify) 
   372 apply (subgoal_tac "converse(h) \<in> carrier(H) \<rightarrow> carrier(G)") 
   373  prefer 2 apply (simp add: bij_converse_bij bij_is_fun) 
   374 apply (auto intro: left_inverse_eq [of _ "carrier(G)" "carrier(H)"] 
   375             simp add: hom_def bij_is_inj right_inverse_bij); 
   376 done
   377 
   378 lemma (in group) iso_trans: 
   379      "\<lbrakk>h \<in> G \<cong> H; i \<in> H \<cong> I\<rbrakk> \<Longrightarrow> i O h \<in> G \<cong> I"
   380 by (auto simp add: iso_def hom_compose comp_bij)
   381 
   382 lemma DirProdGroup_commute_iso:
   383   includes group G + group H
   384   shows "(\<lambda><x,y> \<in> carrier(G \<Otimes> H). <y,x>) \<in> (G \<Otimes> H) \<cong> (H \<Otimes> G)"
   385 by (auto simp add: iso_def hom_def inj_def surj_def bij_def) 
   386 
   387 lemma DirProdGroup_assoc_iso:
   388   includes group G + group H + group I
   389   shows "(\<lambda><<x,y>,z> \<in> carrier((G \<Otimes> H) \<Otimes> I). <x,<y,z>>)
   390           \<in> ((G \<Otimes> H) \<Otimes> I) \<cong> (G \<Otimes> (H \<Otimes> I))"
   391 by (auto intro: lam_type simp add: iso_def hom_def inj_def surj_def bij_def) 
   392 
   393 text{*Basis for homomorphism proofs: we assume two groups @{term G} and
   394   @term{H}, with a homomorphism @{term h} between them*}
   395 locale group_hom = group G + group H + var h +
   396   assumes homh: "h \<in> hom(G,H)"
   397   notes hom_mult [simp] = hom_mult [OF homh]
   398     and hom_closed [simp] = hom_closed [OF homh]
   399     and hom_is_fun [simp] = hom_is_fun [OF homh]
   400 
   401 lemma (in group_hom) one_closed [simp]:
   402   "h ` \<one> \<in> carrier(H)"
   403   by simp
   404 
   405 lemma (in group_hom) hom_one [simp]:
   406   "h ` \<one> = \<one>\<^bsub>H\<^esub>"
   407 proof -
   408   have "h ` \<one> \<cdot>\<^bsub>H\<^esub> \<one>\<^bsub>H\<^esub> = (h ` \<one>) \<cdot>\<^bsub>H\<^esub> (h ` \<one>)"
   409     by (simp add: hom_mult [symmetric] del: hom_mult)
   410   then show ?thesis by (simp del: r_one)
   411 qed
   412 
   413 lemma (in group_hom) inv_closed [simp]:
   414   "x \<in> carrier(G) \<Longrightarrow> h ` (inv x) \<in> carrier(H)"
   415   by simp
   416 
   417 lemma (in group_hom) hom_inv [simp]:
   418   "x \<in> carrier(G) \<Longrightarrow> h ` (inv x) = inv\<^bsub>H\<^esub> (h ` x)"
   419 proof -
   420   assume x: "x \<in> carrier(G)"
   421   then have "h ` x \<cdot>\<^bsub>H\<^esub> h ` (inv x) = \<one>\<^bsub>H\<^esub>"
   422     by (simp add: hom_mult [symmetric] G.r_inv del: hom_mult)
   423   also from x have "... = h ` x \<cdot>\<^bsub>H\<^esub> inv\<^bsub>H\<^esub> (h ` x)"
   424     by (simp add: hom_mult [symmetric] H.r_inv del: hom_mult)
   425   finally have "h ` x \<cdot>\<^bsub>H\<^esub> h ` (inv x) = h ` x \<cdot>\<^bsub>H\<^esub> inv\<^bsub>H\<^esub> (h ` x)" .
   426   with x show ?thesis by (simp del: inv add: is_group)
   427 qed
   428 
   429 subsection {* Commutative Structures *}
   430 
   431 text {*
   432   Naming convention: multiplicative structures that are commutative
   433   are called \emph{commutative}, additive structures are called
   434   \emph{Abelian}.
   435 *}
   436 
   437 subsection {* Definition *}
   438 
   439 locale comm_monoid = monoid +
   440   assumes m_comm: "\<lbrakk>x \<in> carrier(G); y \<in> carrier(G)\<rbrakk> \<Longrightarrow> x \<cdot> y = y \<cdot> x"
   441 
   442 lemma (in comm_monoid) m_lcomm:
   443   "\<lbrakk>x \<in> carrier(G); y \<in> carrier(G); z \<in> carrier(G)\<rbrakk> \<Longrightarrow>
   444    x \<cdot> (y \<cdot> z) = y \<cdot> (x \<cdot> z)"
   445 proof -
   446   assume xyz: "x \<in> carrier(G)"  "y \<in> carrier(G)"  "z \<in> carrier(G)"
   447   from xyz have "x \<cdot> (y \<cdot> z) = (x \<cdot> y) \<cdot> z" by (simp add: m_assoc)
   448   also from xyz have "... = (y \<cdot> x) \<cdot> z" by (simp add: m_comm)
   449   also from xyz have "... = y \<cdot> (x \<cdot> z)" by (simp add: m_assoc)
   450   finally show ?thesis .
   451 qed
   452 
   453 lemmas (in comm_monoid) m_ac = m_assoc m_comm m_lcomm
   454 
   455 locale comm_group = comm_monoid + group
   456 
   457 lemma (in comm_group) inv_mult:
   458   "\<lbrakk>x \<in> carrier(G); y \<in> carrier(G)\<rbrakk> \<Longrightarrow> inv (x \<cdot> y) = inv x \<cdot> inv y"
   459   by (simp add: m_ac inv_mult_group)
   460 
   461 
   462 lemma (in group) subgroup_self: "subgroup (carrier(G),G)"
   463 by (simp add: subgroup_def prems) 
   464 
   465 lemma (in group) subgroup_imp_group:
   466   "subgroup(H,G) \<Longrightarrow> group (update_carrier(G,H))"
   467 by (simp add: subgroup.is_group)
   468 
   469 lemma (in group) subgroupI:
   470   assumes subset: "H \<subseteq> carrier(G)" and non_empty: "H \<noteq> 0"
   471     and inv: "!!a. a \<in> H ==> inv a \<in> H"
   472     and mult: "!!a b. [|a \<in> H; b \<in> H|] ==> a \<cdot> b \<in> H"
   473   shows "subgroup(H,G)"
   474 proof (simp add: subgroup_def prems)
   475   show "\<one> \<in> H" by (rule one_in_subset) (auto simp only: prems)
   476 qed
   477 
   478 
   479 subsection {* Bijections of a Set, Permutation Groups, Automorphism Groups *}
   480 
   481 definition
   482   BijGroup :: "i=>i"
   483   "BijGroup(S) ==
   484     <bij(S,S),
   485      \<lambda><g,f> \<in> bij(S,S) \<times> bij(S,S). g O f,
   486      id(S), 0>"
   487 
   488 
   489 subsection {*Bijections Form a Group *}
   490 
   491 theorem group_BijGroup: "group(BijGroup(S))"
   492 apply (simp add: BijGroup_def)
   493 apply (rule groupI) 
   494     apply (simp_all add: id_bij comp_bij comp_assoc) 
   495  apply (simp add: id_bij bij_is_fun left_comp_id [of _ S S] fun_is_rel)
   496 apply (blast intro: left_comp_inverse bij_is_inj bij_converse_bij)
   497 done
   498 
   499 
   500 subsection{*Automorphisms Form a Group*}
   501 
   502 lemma Bij_Inv_mem: "\<lbrakk>f \<in> bij(S,S);  x \<in> S\<rbrakk> \<Longrightarrow> converse(f) ` x \<in> S" 
   503 by (blast intro: apply_funtype bij_is_fun bij_converse_bij)
   504 
   505 lemma inv_BijGroup: "f \<in> bij(S,S) \<Longrightarrow> m_inv (BijGroup(S), f) = converse(f)"
   506 apply (rule group.inv_equality)
   507 apply (rule group_BijGroup)
   508 apply (simp_all add: BijGroup_def bij_converse_bij 
   509           left_comp_inverse [OF bij_is_inj]) 
   510 done
   511 
   512 lemma iso_is_bij: "h \<in> G \<cong> H ==> h \<in> bij(carrier(G), carrier(H))"
   513 by (simp add: iso_def)
   514 
   515 
   516 definition
   517   auto :: "i=>i"
   518   "auto(G) == iso(G,G)"
   519 
   520   AutoGroup :: "i=>i"
   521   "AutoGroup(G) == update_carrier(BijGroup(carrier(G)), auto(G))"
   522 
   523 
   524 lemma (in group) id_in_auto: "id(carrier(G)) \<in> auto(G)"
   525   by (simp add: iso_refl auto_def)
   526 
   527 lemma (in group) subgroup_auto:
   528       "subgroup (auto(G)) (BijGroup (carrier(G)))"
   529 proof (rule subgroup.intro)
   530   show "auto(G) \<subseteq> carrier (BijGroup (carrier(G)))"
   531     by (auto simp add: auto_def BijGroup_def iso_def)
   532 next
   533   fix x y
   534   assume "x \<in> auto(G)" "y \<in> auto(G)" 
   535   thus "x \<cdot>\<^bsub>BijGroup (carrier(G))\<^esub> y \<in> auto(G)"
   536     by (auto simp add: BijGroup_def auto_def iso_def bij_is_fun 
   537                        group.hom_compose comp_bij)
   538 next
   539   show "\<one>\<^bsub>BijGroup (carrier(G))\<^esub> \<in> auto(G)" by (simp add:  BijGroup_def id_in_auto)
   540 next
   541   fix x 
   542   assume "x \<in> auto(G)" 
   543   thus "inv\<^bsub>BijGroup (carrier(G))\<^esub> x \<in> auto(G)"
   544     by (simp add: auto_def inv_BijGroup iso_is_bij iso_sym) 
   545 qed
   546 
   547 theorem (in group) AutoGroup: "group (AutoGroup(G))"
   548 by (simp add: AutoGroup_def subgroup.is_group subgroup_auto group_BijGroup)
   549 
   550 
   551 
   552 subsection{*Cosets and Quotient Groups*}
   553 
   554 definition
   555   r_coset  :: "[i,i,i] => i"    (infixl "#>\<index>" 60)
   556   "H #>\<^bsub>G\<^esub> a == \<Union>h\<in>H. {h \<cdot>\<^bsub>G\<^esub> a}"
   557 
   558   l_coset  :: "[i,i,i] => i"    (infixl "<#\<index>" 60)
   559   "a <#\<^bsub>G\<^esub> H == \<Union>h\<in>H. {a \<cdot>\<^bsub>G\<^esub> h}"
   560 
   561   RCOSETS  :: "[i,i] => i"          ("rcosets\<index> _" [81] 80)
   562   "rcosets\<^bsub>G\<^esub> H == \<Union>a\<in>carrier(G). {H #>\<^bsub>G\<^esub> a}"
   563 
   564   set_mult :: "[i,i,i] => i"    (infixl "<#>\<index>" 60)
   565   "H <#>\<^bsub>G\<^esub> K == \<Union>h\<in>H. \<Union>k\<in>K. {h \<cdot>\<^bsub>G\<^esub> k}"
   566 
   567   SET_INV  :: "[i,i] => i"  ("set'_inv\<index> _" [81] 80)
   568   "set_inv\<^bsub>G\<^esub> H == \<Union>h\<in>H. {inv\<^bsub>G\<^esub> h}"
   569 
   570 
   571 locale normal = subgroup + group +
   572   assumes coset_eq: "(\<forall>x \<in> carrier(G). H #> x = x <# H)"
   573 
   574 notation
   575   normal  (infixl "\<lhd>" 60)
   576 
   577 
   578 subsection {*Basic Properties of Cosets*}
   579 
   580 lemma (in group) coset_mult_assoc:
   581      "\<lbrakk>M \<subseteq> carrier(G); g \<in> carrier(G); h \<in> carrier(G)\<rbrakk>
   582       \<Longrightarrow> (M #> g) #> h = M #> (g \<cdot> h)"
   583 by (force simp add: r_coset_def m_assoc)
   584 
   585 lemma (in group) coset_mult_one [simp]: "M \<subseteq> carrier(G) \<Longrightarrow> M #> \<one> = M"
   586 by (force simp add: r_coset_def)
   587 
   588 lemma (in group) solve_equation:
   589     "\<lbrakk>subgroup(H,G); x \<in> H; y \<in> H\<rbrakk> \<Longrightarrow> \<exists>h\<in>H. y = h \<cdot> x"
   590 apply (rule bexI [of _ "y \<cdot> (inv x)"])
   591 apply (auto simp add: subgroup.m_closed subgroup.m_inv_closed m_assoc
   592                       subgroup.subset [THEN subsetD])
   593 done
   594 
   595 lemma (in group) repr_independence:
   596      "\<lbrakk>y \<in> H #> x;  x \<in> carrier(G); subgroup(H,G)\<rbrakk> \<Longrightarrow> H #> x = H #> y"
   597 by (auto simp add: r_coset_def m_assoc [symmetric]
   598                    subgroup.subset [THEN subsetD]
   599                    subgroup.m_closed solve_equation)
   600 
   601 lemma (in group) coset_join2:
   602      "\<lbrakk>x \<in> carrier(G);  subgroup(H,G);  x\<in>H\<rbrakk> \<Longrightarrow> H #> x = H"
   603   --{*Alternative proof is to put @{term "x=\<one>"} in @{text repr_independence}.*}
   604 by (force simp add: subgroup.m_closed r_coset_def solve_equation)
   605 
   606 lemma (in group) r_coset_subset_G:
   607      "\<lbrakk>H \<subseteq> carrier(G); x \<in> carrier(G)\<rbrakk> \<Longrightarrow> H #> x \<subseteq> carrier(G)"
   608 by (auto simp add: r_coset_def)
   609 
   610 lemma (in group) rcosI:
   611      "\<lbrakk>h \<in> H; H \<subseteq> carrier(G); x \<in> carrier(G)\<rbrakk> \<Longrightarrow> h \<cdot> x \<in> H #> x"
   612 by (auto simp add: r_coset_def)
   613 
   614 lemma (in group) rcosetsI:
   615      "\<lbrakk>H \<subseteq> carrier(G); x \<in> carrier(G)\<rbrakk> \<Longrightarrow> H #> x \<in> rcosets H"
   616 by (auto simp add: RCOSETS_def)
   617 
   618 
   619 text{*Really needed?*}
   620 lemma (in group) transpose_inv:
   621      "\<lbrakk>x \<cdot> y = z;  x \<in> carrier(G);  y \<in> carrier(G);  z \<in> carrier(G)\<rbrakk>
   622       \<Longrightarrow> (inv x) \<cdot> z = y"
   623 by (force simp add: m_assoc [symmetric])
   624 
   625 
   626 
   627 subsection {* Normal subgroups *}
   628 
   629 lemma normal_imp_subgroup: "H \<lhd> G ==> subgroup(H,G)"
   630   by (simp add: normal_def subgroup_def)
   631 
   632 lemma (in group) normalI: 
   633   "subgroup(H,G) \<Longrightarrow> (\<forall>x \<in> carrier(G). H #> x = x <# H) \<Longrightarrow> H \<lhd> G";
   634   by (simp add: normal_def normal_axioms_def)
   635 
   636 lemma (in normal) inv_op_closed1:
   637      "\<lbrakk>x \<in> carrier(G); h \<in> H\<rbrakk> \<Longrightarrow> (inv x) \<cdot> h \<cdot> x \<in> H"
   638 apply (insert coset_eq) 
   639 apply (auto simp add: l_coset_def r_coset_def)
   640 apply (drule bspec, assumption)
   641 apply (drule equalityD1 [THEN subsetD], blast, clarify)
   642 apply (simp add: m_assoc)
   643 apply (simp add: m_assoc [symmetric])
   644 done
   645 
   646 lemma (in normal) inv_op_closed2:
   647      "\<lbrakk>x \<in> carrier(G); h \<in> H\<rbrakk> \<Longrightarrow> x \<cdot> h \<cdot> (inv x) \<in> H"
   648 apply (subgoal_tac "inv (inv x) \<cdot> h \<cdot> (inv x) \<in> H") 
   649 apply simp 
   650 apply (blast intro: inv_op_closed1) 
   651 done
   652 
   653 text{*Alternative characterization of normal subgroups*}
   654 lemma (in group) normal_inv_iff:
   655      "(N \<lhd> G) <->
   656       (subgroup(N,G) & (\<forall>x \<in> carrier(G). \<forall>h \<in> N. x \<cdot> h \<cdot> (inv x) \<in> N))"
   657       (is "_ <-> ?rhs")
   658 proof
   659   assume N: "N \<lhd> G"
   660   show ?rhs
   661     by (blast intro: N normal.inv_op_closed2 normal_imp_subgroup) 
   662 next
   663   assume ?rhs
   664   hence sg: "subgroup(N,G)" 
   665     and closed: "\<And>x. x\<in>carrier(G) \<Longrightarrow> \<forall>h\<in>N. x \<cdot> h \<cdot> inv x \<in> N" by auto
   666   hence sb: "N \<subseteq> carrier(G)" by (simp add: subgroup.subset) 
   667   show "N \<lhd> G"
   668   proof (intro normalI [OF sg], simp add: l_coset_def r_coset_def, clarify)
   669     fix x
   670     assume x: "x \<in> carrier(G)"
   671     show "(\<Union>h\<in>N. {h \<cdot> x}) = (\<Union>h\<in>N. {x \<cdot> h})"
   672     proof
   673       show "(\<Union>h\<in>N. {h \<cdot> x}) \<subseteq> (\<Union>h\<in>N. {x \<cdot> h})"
   674       proof clarify
   675         fix n
   676         assume n: "n \<in> N" 
   677         show "n \<cdot> x \<in> (\<Union>h\<in>N. {x \<cdot> h})"
   678         proof (rule UN_I) 
   679           from closed [of "inv x"]
   680           show "inv x \<cdot> n \<cdot> x \<in> N" by (simp add: x n)
   681           show "n \<cdot> x \<in> {x \<cdot> (inv x \<cdot> n \<cdot> x)}"
   682             by (simp add: x n m_assoc [symmetric] sb [THEN subsetD])
   683         qed
   684       qed
   685     next
   686       show "(\<Union>h\<in>N. {x \<cdot> h}) \<subseteq> (\<Union>h\<in>N. {h \<cdot> x})"
   687       proof clarify
   688         fix n
   689         assume n: "n \<in> N" 
   690         show "x \<cdot> n \<in> (\<Union>h\<in>N. {h \<cdot> x})"
   691         proof (rule UN_I) 
   692           show "x \<cdot> n \<cdot> inv x \<in> N" by (simp add: x n closed)
   693           show "x \<cdot> n \<in> {x \<cdot> n \<cdot> inv x \<cdot> x}"
   694             by (simp add: x n m_assoc sb [THEN subsetD])
   695         qed
   696       qed
   697     qed
   698   qed
   699 qed
   700 
   701 
   702 subsection{*More Properties of Cosets*}
   703 
   704 lemma (in group) l_coset_subset_G:
   705      "\<lbrakk>H \<subseteq> carrier(G); x \<in> carrier(G)\<rbrakk> \<Longrightarrow> x <# H \<subseteq> carrier(G)"
   706 by (auto simp add: l_coset_def subsetD)
   707 
   708 lemma (in group) l_coset_swap:
   709      "\<lbrakk>y \<in> x <# H;  x \<in> carrier(G);  subgroup(H,G)\<rbrakk> \<Longrightarrow> x \<in> y <# H"
   710 proof (simp add: l_coset_def)
   711   assume "\<exists>h\<in>H. y = x \<cdot> h"
   712     and x: "x \<in> carrier(G)"
   713     and sb: "subgroup(H,G)"
   714   then obtain h' where h': "h' \<in> H & x \<cdot> h' = y" by blast
   715   show "\<exists>h\<in>H. x = y \<cdot> h"
   716   proof
   717     show "x = y \<cdot> inv h'" using h' x sb
   718       by (auto simp add: m_assoc subgroup.subset [THEN subsetD])
   719     show "inv h' \<in> H" using h' sb
   720       by (auto simp add: subgroup.subset [THEN subsetD] subgroup.m_inv_closed)
   721   qed
   722 qed
   723 
   724 lemma (in group) l_coset_carrier:
   725      "\<lbrakk>y \<in> x <# H;  x \<in> carrier(G);  subgroup(H,G)\<rbrakk> \<Longrightarrow> y \<in> carrier(G)"
   726 by (auto simp add: l_coset_def m_assoc
   727                    subgroup.subset [THEN subsetD] subgroup.m_closed)
   728 
   729 lemma (in group) l_repr_imp_subset:
   730   assumes y: "y \<in> x <# H" and x: "x \<in> carrier(G)" and sb: "subgroup(H,G)"
   731   shows "y <# H \<subseteq> x <# H"
   732 proof -
   733   from y
   734   obtain h' where "h' \<in> H" "x \<cdot> h' = y" by (auto simp add: l_coset_def)
   735   thus ?thesis using x sb
   736     by (auto simp add: l_coset_def m_assoc
   737                        subgroup.subset [THEN subsetD] subgroup.m_closed)
   738 qed
   739 
   740 lemma (in group) l_repr_independence:
   741   assumes y: "y \<in> x <# H" and x: "x \<in> carrier(G)" and sb: "subgroup(H,G)"
   742   shows "x <# H = y <# H"
   743 proof
   744   show "x <# H \<subseteq> y <# H"
   745     by (rule l_repr_imp_subset,
   746         (blast intro: l_coset_swap l_coset_carrier y x sb)+)
   747   show "y <# H \<subseteq> x <# H" by (rule l_repr_imp_subset [OF y x sb])
   748 qed
   749 
   750 lemma (in group) setmult_subset_G:
   751      "\<lbrakk>H \<subseteq> carrier(G); K \<subseteq> carrier(G)\<rbrakk> \<Longrightarrow> H <#> K \<subseteq> carrier(G)"
   752 by (auto simp add: set_mult_def subsetD)
   753 
   754 lemma (in group) subgroup_mult_id: "subgroup(H,G) \<Longrightarrow> H <#> H = H"
   755 apply (rule equalityI) 
   756 apply (auto simp add: subgroup.m_closed set_mult_def Sigma_def image_def)
   757 apply (rule_tac x = x in bexI)
   758 apply (rule bexI [of _ "\<one>"])
   759 apply (auto simp add: subgroup.m_closed subgroup.one_closed
   760                       r_one subgroup.subset [THEN subsetD])
   761 done
   762 
   763 
   764 subsubsection {* Set of inverses of an @{text r_coset}. *}
   765 
   766 lemma (in normal) rcos_inv:
   767   assumes x:     "x \<in> carrier(G)"
   768   shows "set_inv (H #> x) = H #> (inv x)" 
   769 proof (simp add: r_coset_def SET_INV_def x inv_mult_group, safe intro!: equalityI)
   770   fix h
   771   assume "h \<in> H"
   772   show "inv x \<cdot> inv h \<in> (\<Union>j\<in>H. {j \<cdot> inv x})"
   773   proof (rule UN_I)
   774     show "inv x \<cdot> inv h \<cdot> x \<in> H"
   775       by (simp add: inv_op_closed1 prems)
   776     show "inv x \<cdot> inv h \<in> {inv x \<cdot> inv h \<cdot> x \<cdot> inv x}"
   777       by (simp add: prems m_assoc)
   778   qed
   779 next
   780   fix h
   781   assume "h \<in> H"
   782   show "h \<cdot> inv x \<in> (\<Union>j\<in>H. {inv x \<cdot> inv j})"
   783   proof (rule UN_I)
   784     show "x \<cdot> inv h \<cdot> inv x \<in> H"
   785       by (simp add: inv_op_closed2 prems)
   786     show "h \<cdot> inv x \<in> {inv x \<cdot> inv (x \<cdot> inv h \<cdot> inv x)}"
   787       by (simp add: prems m_assoc [symmetric] inv_mult_group)
   788   qed
   789 qed
   790 
   791 
   792 
   793 subsubsection {*Theorems for @{text "<#>"} with @{text "#>"} or @{text "<#"}.*}
   794 
   795 lemma (in group) setmult_rcos_assoc:
   796      "\<lbrakk>H \<subseteq> carrier(G); K \<subseteq> carrier(G); x \<in> carrier(G)\<rbrakk>
   797       \<Longrightarrow> H <#> (K #> x) = (H <#> K) #> x"
   798 by (force simp add: r_coset_def set_mult_def m_assoc)
   799 
   800 lemma (in group) rcos_assoc_lcos:
   801      "\<lbrakk>H \<subseteq> carrier(G); K \<subseteq> carrier(G); x \<in> carrier(G)\<rbrakk>
   802       \<Longrightarrow> (H #> x) <#> K = H <#> (x <# K)"
   803 by (force simp add: r_coset_def l_coset_def set_mult_def m_assoc)
   804 
   805 lemma (in normal) rcos_mult_step1:
   806      "\<lbrakk>x \<in> carrier(G); y \<in> carrier(G)\<rbrakk>
   807       \<Longrightarrow> (H #> x) <#> (H #> y) = (H <#> (x <# H)) #> y"
   808 by (simp add: setmult_rcos_assoc subset
   809               r_coset_subset_G l_coset_subset_G rcos_assoc_lcos)
   810 
   811 lemma (in normal) rcos_mult_step2:
   812      "\<lbrakk>x \<in> carrier(G); y \<in> carrier(G)\<rbrakk>
   813       \<Longrightarrow> (H <#> (x <# H)) #> y = (H <#> (H #> x)) #> y"
   814 by (insert coset_eq, simp add: normal_def)
   815 
   816 lemma (in normal) rcos_mult_step3:
   817      "\<lbrakk>x \<in> carrier(G); y \<in> carrier(G)\<rbrakk>
   818       \<Longrightarrow> (H <#> (H #> x)) #> y = H #> (x \<cdot> y)"
   819   by (simp add: setmult_rcos_assoc coset_mult_assoc
   820               subgroup_mult_id subset prems normal.axioms)
   821 
   822 lemma (in normal) rcos_sum:
   823      "\<lbrakk>x \<in> carrier(G); y \<in> carrier(G)\<rbrakk>
   824       \<Longrightarrow> (H #> x) <#> (H #> y) = H #> (x \<cdot> y)"
   825 by (simp add: rcos_mult_step1 rcos_mult_step2 rcos_mult_step3)
   826 
   827 lemma (in normal) rcosets_mult_eq: "M \<in> rcosets H \<Longrightarrow> H <#> M = M"
   828   -- {* generalizes @{text subgroup_mult_id} *}
   829   by (auto simp add: RCOSETS_def subset
   830         setmult_rcos_assoc subgroup_mult_id prems normal.axioms)
   831 
   832 
   833 subsubsection{*Two distinct right cosets are disjoint*}
   834 
   835 definition
   836   r_congruent :: "[i,i] => i" ("rcong\<index> _" [60] 60)
   837   "rcong\<^bsub>G\<^esub> H == {<x,y> \<in> carrier(G) * carrier(G). inv\<^bsub>G\<^esub> x \<cdot>\<^bsub>G\<^esub> y \<in> H}"
   838 
   839 
   840 lemma (in subgroup) equiv_rcong:
   841    includes group G
   842    shows "equiv (carrier(G), rcong H)"
   843 proof (simp add: equiv_def, intro conjI)
   844   show "rcong H \<subseteq> carrier(G) \<times> carrier(G)"
   845     by (auto simp add: r_congruent_def) 
   846 next
   847   show "refl (carrier(G), rcong H)"
   848     by (auto simp add: r_congruent_def refl_def) 
   849 next
   850   show "sym (rcong H)"
   851   proof (simp add: r_congruent_def sym_def, clarify)
   852     fix x y
   853     assume [simp]: "x \<in> carrier(G)" "y \<in> carrier(G)" 
   854        and "inv x \<cdot> y \<in> H"
   855     hence "inv (inv x \<cdot> y) \<in> H" by (simp add: m_inv_closed) 
   856     thus "inv y \<cdot> x \<in> H" by (simp add: inv_mult_group)
   857   qed
   858 next
   859   show "trans (rcong H)"
   860   proof (simp add: r_congruent_def trans_def, clarify)
   861     fix x y z
   862     assume [simp]: "x \<in> carrier(G)" "y \<in> carrier(G)" "z \<in> carrier(G)"
   863        and "inv x \<cdot> y \<in> H" and "inv y \<cdot> z \<in> H"
   864     hence "(inv x \<cdot> y) \<cdot> (inv y \<cdot> z) \<in> H" by simp
   865     hence "inv x \<cdot> (y \<cdot> inv y) \<cdot> z \<in> H" by (simp add: m_assoc del: inv) 
   866     thus "inv x \<cdot> z \<in> H" by simp
   867   qed
   868 qed
   869 
   870 text{*Equivalence classes of @{text rcong} correspond to left cosets.
   871   Was there a mistake in the definitions? I'd have expected them to
   872   correspond to right cosets.*}
   873 lemma (in subgroup) l_coset_eq_rcong:
   874   includes group G
   875   assumes a: "a \<in> carrier(G)"
   876   shows "a <# H = (rcong H) `` {a}" 
   877 by (force simp add: r_congruent_def l_coset_def m_assoc [symmetric] a
   878                 Collect_image_eq) 
   879 
   880 
   881 lemma (in group) rcos_equation:
   882   includes subgroup H G
   883   shows
   884      "\<lbrakk>ha \<cdot> a = h \<cdot> b; a \<in> carrier(G);  b \<in> carrier(G);  
   885         h \<in> H;  ha \<in> H;  hb \<in> H\<rbrakk>
   886       \<Longrightarrow> hb \<cdot> a \<in> (\<Union>h\<in>H. {h \<cdot> b})"
   887 apply (rule UN_I [of "hb \<cdot> ((inv ha) \<cdot> h)"], simp)
   888 apply (simp add: m_assoc transpose_inv)
   889 done
   890 
   891 
   892 lemma (in group) rcos_disjoint:
   893   includes subgroup H G
   894   shows "\<lbrakk>a \<in> rcosets H; b \<in> rcosets H; a\<noteq>b\<rbrakk> \<Longrightarrow> a \<inter> b = 0"
   895 apply (simp add: RCOSETS_def r_coset_def)
   896 apply (blast intro: rcos_equation prems sym)
   897 done
   898 
   899 
   900 subsection {*Order of a Group and Lagrange's Theorem*}
   901 
   902 definition
   903   order :: "i => i"
   904   "order(S) == |carrier(S)|"
   905 
   906 lemma (in group) rcos_self:
   907   includes subgroup
   908   shows "x \<in> carrier(G) \<Longrightarrow> x \<in> H #> x"
   909 apply (simp add: r_coset_def)
   910 apply (rule_tac x="\<one>" in bexI, auto) 
   911 done
   912 
   913 lemma (in group) rcosets_part_G:
   914   includes subgroup
   915   shows "\<Union>(rcosets H) = carrier(G)"
   916 apply (rule equalityI)
   917  apply (force simp add: RCOSETS_def r_coset_def)
   918 apply (auto simp add: RCOSETS_def intro: rcos_self prems)
   919 done
   920 
   921 lemma (in group) cosets_finite:
   922      "\<lbrakk>c \<in> rcosets H;  H \<subseteq> carrier(G);  Finite (carrier(G))\<rbrakk> \<Longrightarrow> Finite(c)"
   923 apply (auto simp add: RCOSETS_def)
   924 apply (simp add: r_coset_subset_G [THEN subset_Finite])
   925 done
   926 
   927 text{*More general than the HOL version, which also requires @{term G} to
   928       be finite.*}
   929 lemma (in group) card_cosets_equal:
   930   assumes H:   "H \<subseteq> carrier(G)"
   931   shows "c \<in> rcosets H \<Longrightarrow> |c| = |H|"
   932 proof (simp add: RCOSETS_def, clarify)
   933   fix a
   934   assume a: "a \<in> carrier(G)"
   935   show "|H #> a| = |H|"
   936   proof (rule eqpollI [THEN cardinal_cong])
   937     show "H #> a \<lesssim> H"
   938     proof (simp add: lepoll_def, intro exI) 
   939       show "(\<lambda>y \<in> H#>a. y \<cdot> inv a) \<in> inj(H #> a, H)"
   940         by (auto intro: lam_type 
   941                  simp add: inj_def r_coset_def m_assoc subsetD [OF H] a)
   942     qed
   943     show "H \<lesssim> H #> a"
   944     proof (simp add: lepoll_def, intro exI) 
   945       show "(\<lambda>y\<in> H. y \<cdot> a) \<in> inj(H, H #> a)"
   946         by (auto intro: lam_type 
   947                  simp add: inj_def r_coset_def  subsetD [OF H] a)
   948     qed
   949   qed
   950 qed
   951 
   952 
   953 lemma (in group) rcosets_subset_PowG:
   954      "subgroup(H,G) \<Longrightarrow> rcosets H \<subseteq> Pow(carrier(G))"
   955 apply (simp add: RCOSETS_def)
   956 apply (blast dest: r_coset_subset_G subgroup.subset)
   957 done
   958 
   959 theorem (in group) lagrange:
   960      "\<lbrakk>Finite(carrier(G)); subgroup(H,G)\<rbrakk>
   961       \<Longrightarrow> |rcosets H| #* |H| = order(G)"
   962 apply (simp (no_asm_simp) add: order_def rcosets_part_G [symmetric])
   963 apply (subst mult_commute)
   964 apply (rule card_partition)
   965    apply (simp add: rcosets_subset_PowG [THEN subset_Finite])
   966   apply (simp add: rcosets_part_G)
   967  apply (simp add: card_cosets_equal [OF subgroup.subset])
   968 apply (simp add: rcos_disjoint)
   969 done
   970 
   971 
   972 subsection {*Quotient Groups: Factorization of a Group*}
   973 
   974 definition
   975   FactGroup :: "[i,i] => i" (infixl "Mod" 65)
   976     --{*Actually defined for groups rather than monoids*}
   977   "G Mod H == 
   978      <rcosets\<^bsub>G\<^esub> H, \<lambda><K1,K2> \<in> (rcosets\<^bsub>G\<^esub> H) \<times> (rcosets\<^bsub>G\<^esub> H). K1 <#>\<^bsub>G\<^esub> K2, H, 0>"
   979 
   980 lemma (in normal) setmult_closed:
   981      "\<lbrakk>K1 \<in> rcosets H; K2 \<in> rcosets H\<rbrakk> \<Longrightarrow> K1 <#> K2 \<in> rcosets H"
   982 by (auto simp add: rcos_sum RCOSETS_def)
   983 
   984 lemma (in normal) setinv_closed:
   985      "K \<in> rcosets H \<Longrightarrow> set_inv K \<in> rcosets H"
   986 by (auto simp add: rcos_inv RCOSETS_def)
   987 
   988 lemma (in normal) rcosets_assoc:
   989      "\<lbrakk>M1 \<in> rcosets H; M2 \<in> rcosets H; M3 \<in> rcosets H\<rbrakk>
   990       \<Longrightarrow> M1 <#> M2 <#> M3 = M1 <#> (M2 <#> M3)"
   991 by (auto simp add: RCOSETS_def rcos_sum m_assoc)
   992 
   993 lemma (in subgroup) subgroup_in_rcosets:
   994   includes group G
   995   shows "H \<in> rcosets H"
   996 proof -
   997   have "H #> \<one> = H"
   998     by (rule coset_join2, auto)
   999   then show ?thesis
  1000     by (auto simp add: RCOSETS_def intro: sym)
  1001 qed
  1002 
  1003 lemma (in normal) rcosets_inv_mult_group_eq:
  1004      "M \<in> rcosets H \<Longrightarrow> set_inv M <#> M = H"
  1005 by (auto simp add: RCOSETS_def rcos_inv rcos_sum subgroup.subset prems normal.axioms)
  1006 
  1007 theorem (in normal) factorgroup_is_group:
  1008   "group (G Mod H)"
  1009 apply (simp add: FactGroup_def)
  1010 apply (rule groupI)
  1011     apply (simp add: setmult_closed)
  1012    apply (simp add: normal_imp_subgroup subgroup_in_rcosets)
  1013   apply (simp add: setmult_closed rcosets_assoc)
  1014  apply (simp add: normal_imp_subgroup
  1015                   subgroup_in_rcosets rcosets_mult_eq)
  1016 apply (auto dest: rcosets_inv_mult_group_eq simp add: setinv_closed)
  1017 done
  1018 
  1019 lemma (in normal) inv_FactGroup:
  1020      "X \<in> carrier (G Mod H) \<Longrightarrow> inv\<^bsub>G Mod H\<^esub> X = set_inv X"
  1021 apply (rule group.inv_equality [OF factorgroup_is_group]) 
  1022 apply (simp_all add: FactGroup_def setinv_closed rcosets_inv_mult_group_eq)
  1023 done
  1024 
  1025 text{*The coset map is a homomorphism from @{term G} to the quotient group
  1026   @{term "G Mod H"}*}
  1027 lemma (in normal) r_coset_hom_Mod:
  1028   "(\<lambda>a \<in> carrier(G). H #> a) \<in> hom(G, G Mod H)"
  1029 by (auto simp add: FactGroup_def RCOSETS_def hom_def rcos_sum intro: lam_type) 
  1030 
  1031 
  1032 subsection{*The First Isomorphism Theorem*}
  1033 
  1034 text{*The quotient by the kernel of a homomorphism is isomorphic to the 
  1035   range of that homomorphism.*}
  1036 
  1037 definition
  1038   kernel :: "[i,i,i] => i" 
  1039     --{*the kernel of a homomorphism*}
  1040   "kernel(G,H,h) == {x \<in> carrier(G). h ` x = \<one>\<^bsub>H\<^esub>}";
  1041 
  1042 lemma (in group_hom) subgroup_kernel: "subgroup (kernel(G,H,h), G)"
  1043 apply (rule subgroup.intro) 
  1044 apply (auto simp add: kernel_def group.intro prems) 
  1045 done
  1046 
  1047 text{*The kernel of a homomorphism is a normal subgroup*}
  1048 lemma (in group_hom) normal_kernel: "(kernel(G,H,h)) \<lhd> G"
  1049 apply (simp add: group.normal_inv_iff subgroup_kernel group.intro prems)
  1050 apply (simp add: kernel_def)  
  1051 done
  1052 
  1053 lemma (in group_hom) FactGroup_nonempty:
  1054   assumes X: "X \<in> carrier (G Mod kernel(G,H,h))"
  1055   shows "X \<noteq> 0"
  1056 proof -
  1057   from X
  1058   obtain g where "g \<in> carrier(G)" 
  1059              and "X = kernel(G,H,h) #> g"
  1060     by (auto simp add: FactGroup_def RCOSETS_def)
  1061   thus ?thesis 
  1062    by (auto simp add: kernel_def r_coset_def image_def intro: hom_one)
  1063 qed
  1064 
  1065 
  1066 lemma (in group_hom) FactGroup_contents_mem:
  1067   assumes X: "X \<in> carrier (G Mod (kernel(G,H,h)))"
  1068   shows "contents (h``X) \<in> carrier(H)"
  1069 proof -
  1070   from X
  1071   obtain g where g: "g \<in> carrier(G)" 
  1072              and "X = kernel(G,H,h) #> g"
  1073     by (auto simp add: FactGroup_def RCOSETS_def)
  1074   hence "h `` X = {h ` g}"
  1075     by (auto simp add: kernel_def r_coset_def image_UN 
  1076                        image_eq_UN [OF hom_is_fun] g)
  1077   thus ?thesis by (auto simp add: g)
  1078 qed
  1079 
  1080 lemma mult_FactGroup:
  1081      "[|X \<in> carrier(G Mod H); X' \<in> carrier(G Mod H)|] 
  1082       ==> X \<cdot>\<^bsub>(G Mod H)\<^esub> X' = X <#>\<^bsub>G\<^esub> X'"
  1083 by (simp add: FactGroup_def) 
  1084 
  1085 lemma (in normal) FactGroup_m_closed:
  1086      "[|X \<in> carrier(G Mod H); X' \<in> carrier(G Mod H)|] 
  1087       ==> X <#>\<^bsub>G\<^esub> X' \<in> carrier(G Mod H)"
  1088 by (simp add: FactGroup_def setmult_closed) 
  1089 
  1090 lemma (in group_hom) FactGroup_hom:
  1091      "(\<lambda>X \<in> carrier(G Mod (kernel(G,H,h))). contents (h``X))
  1092       \<in> hom (G Mod (kernel(G,H,h)), H)" 
  1093 proof (simp add: hom_def FactGroup_contents_mem lam_type mult_FactGroup normal.FactGroup_m_closed [OF normal_kernel], intro ballI)  
  1094   fix X and X'
  1095   assume X:  "X  \<in> carrier (G Mod kernel(G,H,h))"
  1096      and X': "X' \<in> carrier (G Mod kernel(G,H,h))"
  1097   then
  1098   obtain g and g'
  1099            where "g \<in> carrier(G)" and "g' \<in> carrier(G)" 
  1100              and "X = kernel(G,H,h) #> g" and "X' = kernel(G,H,h) #> g'"
  1101     by (auto simp add: FactGroup_def RCOSETS_def)
  1102   hence all: "\<forall>x\<in>X. h ` x = h ` g" "\<forall>x\<in>X'. h ` x = h ` g'" 
  1103     and Xsub: "X \<subseteq> carrier(G)" and X'sub: "X' \<subseteq> carrier(G)"
  1104     by (force simp add: kernel_def r_coset_def image_def)+
  1105   hence "h `` (X <#> X') = {h ` g \<cdot>\<^bsub>H\<^esub> h ` g'}" using X X'
  1106     by (auto dest!: FactGroup_nonempty
  1107              simp add: set_mult_def image_eq_UN [OF hom_is_fun] image_UN
  1108                        subsetD [OF Xsub] subsetD [OF X'sub]) 
  1109   thus "contents (h `` (X <#> X')) = contents (h `` X) \<cdot>\<^bsub>H\<^esub> contents (h `` X')"
  1110     by (simp add: all image_eq_UN [OF hom_is_fun] FactGroup_nonempty 
  1111                   X X' Xsub X'sub)
  1112 qed
  1113 
  1114 
  1115 text{*Lemma for the following injectivity result*}
  1116 lemma (in group_hom) FactGroup_subset:
  1117      "\<lbrakk>g \<in> carrier(G); g' \<in> carrier(G); h ` g = h ` g'\<rbrakk>
  1118       \<Longrightarrow>  kernel(G,H,h) #> g \<subseteq> kernel(G,H,h) #> g'"
  1119 apply (clarsimp simp add: kernel_def r_coset_def image_def)
  1120 apply (rename_tac y)  
  1121 apply (rule_tac x="y \<cdot> g \<cdot> inv g'" in bexI) 
  1122 apply (simp_all add: G.m_assoc) 
  1123 done
  1124 
  1125 lemma (in group_hom) FactGroup_inj:
  1126      "(\<lambda>X\<in>carrier (G Mod kernel(G,H,h)). contents (h `` X))
  1127       \<in> inj(carrier (G Mod kernel(G,H,h)), carrier(H))"
  1128 proof (simp add: inj_def FactGroup_contents_mem lam_type, clarify) 
  1129   fix X and X'
  1130   assume X:  "X  \<in> carrier (G Mod kernel(G,H,h))"
  1131      and X': "X' \<in> carrier (G Mod kernel(G,H,h))"
  1132   then
  1133   obtain g and g'
  1134            where gX: "g \<in> carrier(G)"  "g' \<in> carrier(G)" 
  1135               "X = kernel(G,H,h) #> g" "X' = kernel(G,H,h) #> g'"
  1136     by (auto simp add: FactGroup_def RCOSETS_def)
  1137   hence all: "\<forall>x\<in>X. h ` x = h ` g" "\<forall>x\<in>X'. h ` x = h ` g'"
  1138     and Xsub: "X \<subseteq> carrier(G)" and X'sub: "X' \<subseteq> carrier(G)"
  1139     by (force simp add: kernel_def r_coset_def image_def)+
  1140   assume "contents (h `` X) = contents (h `` X')"
  1141   hence h: "h ` g = h ` g'"
  1142     by (simp add: all image_eq_UN [OF hom_is_fun] FactGroup_nonempty 
  1143                   X X' Xsub X'sub)
  1144   show "X=X'" by (rule equalityI) (simp_all add: FactGroup_subset h gX) 
  1145 qed
  1146 
  1147 
  1148 lemma (in group_hom) kernel_rcoset_subset:
  1149   assumes g: "g \<in> carrier(G)"
  1150   shows "kernel(G,H,h) #> g \<subseteq> carrier (G)"
  1151     by (auto simp add: g kernel_def r_coset_def) 
  1152 
  1153 
  1154 
  1155 text{*If the homomorphism @{term h} is onto @{term H}, then so is the
  1156 homomorphism from the quotient group*}
  1157 lemma (in group_hom) FactGroup_surj:
  1158   assumes h: "h \<in> surj(carrier(G), carrier(H))"
  1159   shows "(\<lambda>X\<in>carrier (G Mod kernel(G,H,h)). contents (h `` X))
  1160          \<in> surj(carrier (G Mod kernel(G,H,h)), carrier(H))"
  1161 proof (simp add: surj_def FactGroup_contents_mem lam_type, clarify)
  1162   fix y
  1163   assume y: "y \<in> carrier(H)"
  1164   with h obtain g where g: "g \<in> carrier(G)" "h ` g = y"
  1165     by (auto simp add: surj_def) 
  1166   hence "(\<Union>x\<in>kernel(G,H,h) #> g. {h ` x}) = {y}" 
  1167     by (auto simp add: y kernel_def r_coset_def) 
  1168   with g show "\<exists>x\<in>carrier(G Mod kernel(G, H, h)). contents(h `` x) = y"
  1169         --{*The witness is @{term "kernel(G,H,h) #> g"}*}
  1170     by (force simp add: FactGroup_def RCOSETS_def 
  1171            image_eq_UN [OF hom_is_fun] kernel_rcoset_subset)
  1172 qed
  1173 
  1174 
  1175 text{*If @{term h} is a homomorphism from @{term G} onto @{term H}, then the
  1176  quotient group @{term "G Mod (kernel(G,H,h))"} is isomorphic to @{term H}.*}
  1177 theorem (in group_hom) FactGroup_iso:
  1178   "h \<in> surj(carrier(G), carrier(H))
  1179    \<Longrightarrow> (\<lambda>X\<in>carrier (G Mod kernel(G,H,h)). contents (h``X)) \<in> (G Mod (kernel(G,H,h))) \<cong> H"
  1180 by (simp add: iso_def FactGroup_hom FactGroup_inj bij_def FactGroup_surj)
  1181  
  1182 end