src/ZF/ex/Group.thy
author ballarin
Tue Jun 20 15:53:44 2006 +0200 (2006-06-20)
changeset 19931 fb32b43e7f80
parent 16417 9bc16273c2d4
child 21233 5a5c8ea5f66a
permissions -rw-r--r--
Restructured locales with predicates: import is now an interpretation.
New method intro_locales.
     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 constdefs
    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 constdefs (structure G)
    37   m_inv :: "i => i => i" ("inv\<index> _" [81] 80)
    38   "inv x == (THE y. y \<in> carrier(G) & y \<cdot> x = \<one> & x \<cdot> y = \<one>)"
    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 constdefs
   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 constdefs
   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 constdefs
   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 constdefs
   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 constdefs
   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 constdefs (structure G)
   555   r_coset  :: "[i,i,i] => i"    (infixl "#>\<index>" 60)
   556    "H #> a == \<Union>h\<in>H. {h \<cdot> a}"
   557 
   558   l_coset  :: "[i,i,i] => i"    (infixl "<#\<index>" 60)
   559    "a <# H == \<Union>h\<in>H. {a \<cdot> h}"
   560 
   561   RCOSETS  :: "[i,i] => i"          ("rcosets\<index> _" [81] 80)
   562    "rcosets H == \<Union>a\<in>carrier(G). {H #> a}"
   563 
   564   set_mult :: "[i,i,i] => i"    (infixl "<#>\<index>" 60)
   565    "H <#> K == \<Union>h\<in>H. \<Union>k\<in>K. {h \<cdot> k}"
   566 
   567   SET_INV  :: "[i,i] => i"  ("set'_inv\<index> _" [81] 80)
   568    "set_inv H == \<Union>h\<in>H. {inv h}"
   569 
   570 
   571 locale normal = subgroup + group +
   572   assumes coset_eq: "(\<forall>x \<in> carrier(G). H #> x = x <# H)"
   573 
   574 
   575 syntax
   576   "@normal" :: "[i,i] => i"  (infixl "\<lhd>" 60)
   577 
   578 translations
   579   "H \<lhd> G" == "normal(H,G)"
   580 
   581 
   582 subsection {*Basic Properties of Cosets*}
   583 
   584 lemma (in group) coset_mult_assoc:
   585      "\<lbrakk>M \<subseteq> carrier(G); g \<in> carrier(G); h \<in> carrier(G)\<rbrakk>
   586       \<Longrightarrow> (M #> g) #> h = M #> (g \<cdot> h)"
   587 by (force simp add: r_coset_def m_assoc)
   588 
   589 lemma (in group) coset_mult_one [simp]: "M \<subseteq> carrier(G) \<Longrightarrow> M #> \<one> = M"
   590 by (force simp add: r_coset_def)
   591 
   592 lemma (in group) solve_equation:
   593     "\<lbrakk>subgroup(H,G); x \<in> H; y \<in> H\<rbrakk> \<Longrightarrow> \<exists>h\<in>H. y = h \<cdot> x"
   594 apply (rule bexI [of _ "y \<cdot> (inv x)"])
   595 apply (auto simp add: subgroup.m_closed subgroup.m_inv_closed m_assoc
   596                       subgroup.subset [THEN subsetD])
   597 done
   598 
   599 lemma (in group) repr_independence:
   600      "\<lbrakk>y \<in> H #> x;  x \<in> carrier(G); subgroup(H,G)\<rbrakk> \<Longrightarrow> H #> x = H #> y"
   601 by (auto simp add: r_coset_def m_assoc [symmetric]
   602                    subgroup.subset [THEN subsetD]
   603                    subgroup.m_closed solve_equation)
   604 
   605 lemma (in group) coset_join2:
   606      "\<lbrakk>x \<in> carrier(G);  subgroup(H,G);  x\<in>H\<rbrakk> \<Longrightarrow> H #> x = H"
   607   --{*Alternative proof is to put @{term "x=\<one>"} in @{text repr_independence}.*}
   608 by (force simp add: subgroup.m_closed r_coset_def solve_equation)
   609 
   610 lemma (in group) r_coset_subset_G:
   611      "\<lbrakk>H \<subseteq> carrier(G); x \<in> carrier(G)\<rbrakk> \<Longrightarrow> H #> x \<subseteq> carrier(G)"
   612 by (auto simp add: r_coset_def)
   613 
   614 lemma (in group) rcosI:
   615      "\<lbrakk>h \<in> H; H \<subseteq> carrier(G); x \<in> carrier(G)\<rbrakk> \<Longrightarrow> h \<cdot> x \<in> H #> x"
   616 by (auto simp add: r_coset_def)
   617 
   618 lemma (in group) rcosetsI:
   619      "\<lbrakk>H \<subseteq> carrier(G); x \<in> carrier(G)\<rbrakk> \<Longrightarrow> H #> x \<in> rcosets H"
   620 by (auto simp add: RCOSETS_def)
   621 
   622 
   623 text{*Really needed?*}
   624 lemma (in group) transpose_inv:
   625      "\<lbrakk>x \<cdot> y = z;  x \<in> carrier(G);  y \<in> carrier(G);  z \<in> carrier(G)\<rbrakk>
   626       \<Longrightarrow> (inv x) \<cdot> z = y"
   627 by (force simp add: m_assoc [symmetric])
   628 
   629 
   630 
   631 subsection {* Normal subgroups *}
   632 
   633 lemma normal_imp_subgroup: "H \<lhd> G ==> subgroup(H,G)"
   634   by (simp add: normal_def subgroup_def)
   635 
   636 lemma (in group) normalI: 
   637   "subgroup(H,G) \<Longrightarrow> (\<forall>x \<in> carrier(G). H #> x = x <# H) \<Longrightarrow> H \<lhd> G";
   638   by (simp add: normal_def normal_axioms_def)
   639 
   640 lemma (in normal) inv_op_closed1:
   641      "\<lbrakk>x \<in> carrier(G); h \<in> H\<rbrakk> \<Longrightarrow> (inv x) \<cdot> h \<cdot> x \<in> H"
   642 apply (insert coset_eq) 
   643 apply (auto simp add: l_coset_def r_coset_def)
   644 apply (drule bspec, assumption)
   645 apply (drule equalityD1 [THEN subsetD], blast, clarify)
   646 apply (simp add: m_assoc)
   647 apply (simp add: m_assoc [symmetric])
   648 done
   649 
   650 lemma (in normal) inv_op_closed2:
   651      "\<lbrakk>x \<in> carrier(G); h \<in> H\<rbrakk> \<Longrightarrow> x \<cdot> h \<cdot> (inv x) \<in> H"
   652 apply (subgoal_tac "inv (inv x) \<cdot> h \<cdot> (inv x) \<in> H") 
   653 apply simp 
   654 apply (blast intro: inv_op_closed1) 
   655 done
   656 
   657 text{*Alternative characterization of normal subgroups*}
   658 lemma (in group) normal_inv_iff:
   659      "(N \<lhd> G) <->
   660       (subgroup(N,G) & (\<forall>x \<in> carrier(G). \<forall>h \<in> N. x \<cdot> h \<cdot> (inv x) \<in> N))"
   661       (is "_ <-> ?rhs")
   662 proof
   663   assume N: "N \<lhd> G"
   664   show ?rhs
   665     by (blast intro: N normal.inv_op_closed2 normal_imp_subgroup) 
   666 next
   667   assume ?rhs
   668   hence sg: "subgroup(N,G)" 
   669     and closed: "\<And>x. x\<in>carrier(G) \<Longrightarrow> \<forall>h\<in>N. x \<cdot> h \<cdot> inv x \<in> N" by auto
   670   hence sb: "N \<subseteq> carrier(G)" by (simp add: subgroup.subset) 
   671   show "N \<lhd> G"
   672   proof (intro normalI [OF sg], simp add: l_coset_def r_coset_def, clarify)
   673     fix x
   674     assume x: "x \<in> carrier(G)"
   675     show "(\<Union>h\<in>N. {h \<cdot> x}) = (\<Union>h\<in>N. {x \<cdot> h})"
   676     proof
   677       show "(\<Union>h\<in>N. {h \<cdot> x}) \<subseteq> (\<Union>h\<in>N. {x \<cdot> h})"
   678       proof clarify
   679         fix n
   680         assume n: "n \<in> N" 
   681         show "n \<cdot> x \<in> (\<Union>h\<in>N. {x \<cdot> h})"
   682         proof (rule UN_I) 
   683           from closed [of "inv x"]
   684           show "inv x \<cdot> n \<cdot> x \<in> N" by (simp add: x n)
   685           show "n \<cdot> x \<in> {x \<cdot> (inv x \<cdot> n \<cdot> x)}"
   686             by (simp add: x n m_assoc [symmetric] sb [THEN subsetD])
   687         qed
   688       qed
   689     next
   690       show "(\<Union>h\<in>N. {x \<cdot> h}) \<subseteq> (\<Union>h\<in>N. {h \<cdot> x})"
   691       proof clarify
   692         fix n
   693         assume n: "n \<in> N" 
   694         show "x \<cdot> n \<in> (\<Union>h\<in>N. {h \<cdot> x})"
   695         proof (rule UN_I) 
   696           show "x \<cdot> n \<cdot> inv x \<in> N" by (simp add: x n closed)
   697           show "x \<cdot> n \<in> {x \<cdot> n \<cdot> inv x \<cdot> x}"
   698             by (simp add: x n m_assoc sb [THEN subsetD])
   699         qed
   700       qed
   701     qed
   702   qed
   703 qed
   704 
   705 
   706 subsection{*More Properties of Cosets*}
   707 
   708 lemma (in group) l_coset_subset_G:
   709      "\<lbrakk>H \<subseteq> carrier(G); x \<in> carrier(G)\<rbrakk> \<Longrightarrow> x <# H \<subseteq> carrier(G)"
   710 by (auto simp add: l_coset_def subsetD)
   711 
   712 lemma (in group) l_coset_swap:
   713      "\<lbrakk>y \<in> x <# H;  x \<in> carrier(G);  subgroup(H,G)\<rbrakk> \<Longrightarrow> x \<in> y <# H"
   714 proof (simp add: l_coset_def)
   715   assume "\<exists>h\<in>H. y = x \<cdot> h"
   716     and x: "x \<in> carrier(G)"
   717     and sb: "subgroup(H,G)"
   718   then obtain h' where h': "h' \<in> H & x \<cdot> h' = y" by blast
   719   show "\<exists>h\<in>H. x = y \<cdot> h"
   720   proof
   721     show "x = y \<cdot> inv h'" using h' x sb
   722       by (auto simp add: m_assoc subgroup.subset [THEN subsetD])
   723     show "inv h' \<in> H" using h' sb
   724       by (auto simp add: subgroup.subset [THEN subsetD] subgroup.m_inv_closed)
   725   qed
   726 qed
   727 
   728 lemma (in group) l_coset_carrier:
   729      "\<lbrakk>y \<in> x <# H;  x \<in> carrier(G);  subgroup(H,G)\<rbrakk> \<Longrightarrow> y \<in> carrier(G)"
   730 by (auto simp add: l_coset_def m_assoc
   731                    subgroup.subset [THEN subsetD] subgroup.m_closed)
   732 
   733 lemma (in group) l_repr_imp_subset:
   734   assumes y: "y \<in> x <# H" and x: "x \<in> carrier(G)" and sb: "subgroup(H,G)"
   735   shows "y <# H \<subseteq> x <# H"
   736 proof -
   737   from y
   738   obtain h' where "h' \<in> H" "x \<cdot> h' = y" by (auto simp add: l_coset_def)
   739   thus ?thesis using x sb
   740     by (auto simp add: l_coset_def m_assoc
   741                        subgroup.subset [THEN subsetD] subgroup.m_closed)
   742 qed
   743 
   744 lemma (in group) l_repr_independence:
   745   assumes y: "y \<in> x <# H" and x: "x \<in> carrier(G)" and sb: "subgroup(H,G)"
   746   shows "x <# H = y <# H"
   747 proof
   748   show "x <# H \<subseteq> y <# H"
   749     by (rule l_repr_imp_subset,
   750         (blast intro: l_coset_swap l_coset_carrier y x sb)+)
   751   show "y <# H \<subseteq> x <# H" by (rule l_repr_imp_subset [OF y x sb])
   752 qed
   753 
   754 lemma (in group) setmult_subset_G:
   755      "\<lbrakk>H \<subseteq> carrier(G); K \<subseteq> carrier(G)\<rbrakk> \<Longrightarrow> H <#> K \<subseteq> carrier(G)"
   756 by (auto simp add: set_mult_def subsetD)
   757 
   758 lemma (in group) subgroup_mult_id: "subgroup(H,G) \<Longrightarrow> H <#> H = H"
   759 apply (rule equalityI) 
   760 apply (auto simp add: subgroup.m_closed set_mult_def Sigma_def image_def)
   761 apply (rule_tac x = x in bexI)
   762 apply (rule bexI [of _ "\<one>"])
   763 apply (auto simp add: subgroup.m_closed subgroup.one_closed
   764                       r_one subgroup.subset [THEN subsetD])
   765 done
   766 
   767 
   768 subsubsection {* Set of inverses of an @{text r_coset}. *}
   769 
   770 lemma (in normal) rcos_inv:
   771   assumes x:     "x \<in> carrier(G)"
   772   shows "set_inv (H #> x) = H #> (inv x)" 
   773 proof (simp add: r_coset_def SET_INV_def x inv_mult_group, safe intro!: equalityI)
   774   fix h
   775   assume "h \<in> H"
   776   show "inv x \<cdot> inv h \<in> (\<Union>j\<in>H. {j \<cdot> inv x})"
   777   proof (rule UN_I)
   778     show "inv x \<cdot> inv h \<cdot> x \<in> H"
   779       by (simp add: inv_op_closed1 prems)
   780     show "inv x \<cdot> inv h \<in> {inv x \<cdot> inv h \<cdot> x \<cdot> inv x}"
   781       by (simp add: prems m_assoc)
   782   qed
   783 next
   784   fix h
   785   assume "h \<in> H"
   786   show "h \<cdot> inv x \<in> (\<Union>j\<in>H. {inv x \<cdot> inv j})"
   787   proof (rule UN_I)
   788     show "x \<cdot> inv h \<cdot> inv x \<in> H"
   789       by (simp add: inv_op_closed2 prems)
   790     show "h \<cdot> inv x \<in> {inv x \<cdot> inv (x \<cdot> inv h \<cdot> inv x)}"
   791       by (simp add: prems m_assoc [symmetric] inv_mult_group)
   792   qed
   793 qed
   794 
   795 
   796 
   797 subsubsection {*Theorems for @{text "<#>"} with @{text "#>"} or @{text "<#"}.*}
   798 
   799 lemma (in group) setmult_rcos_assoc:
   800      "\<lbrakk>H \<subseteq> carrier(G); K \<subseteq> carrier(G); x \<in> carrier(G)\<rbrakk>
   801       \<Longrightarrow> H <#> (K #> x) = (H <#> K) #> x"
   802 by (force simp add: r_coset_def set_mult_def m_assoc)
   803 
   804 lemma (in group) rcos_assoc_lcos:
   805      "\<lbrakk>H \<subseteq> carrier(G); K \<subseteq> carrier(G); x \<in> carrier(G)\<rbrakk>
   806       \<Longrightarrow> (H #> x) <#> K = H <#> (x <# K)"
   807 by (force simp add: r_coset_def l_coset_def set_mult_def m_assoc)
   808 
   809 lemma (in normal) rcos_mult_step1:
   810      "\<lbrakk>x \<in> carrier(G); y \<in> carrier(G)\<rbrakk>
   811       \<Longrightarrow> (H #> x) <#> (H #> y) = (H <#> (x <# H)) #> y"
   812 by (simp add: setmult_rcos_assoc subset
   813               r_coset_subset_G l_coset_subset_G rcos_assoc_lcos)
   814 
   815 lemma (in normal) rcos_mult_step2:
   816      "\<lbrakk>x \<in> carrier(G); y \<in> carrier(G)\<rbrakk>
   817       \<Longrightarrow> (H <#> (x <# H)) #> y = (H <#> (H #> x)) #> y"
   818 by (insert coset_eq, simp add: normal_def)
   819 
   820 lemma (in normal) rcos_mult_step3:
   821      "\<lbrakk>x \<in> carrier(G); y \<in> carrier(G)\<rbrakk>
   822       \<Longrightarrow> (H <#> (H #> x)) #> y = H #> (x \<cdot> y)"
   823   by (simp add: setmult_rcos_assoc coset_mult_assoc
   824               subgroup_mult_id subset prems normal.axioms)
   825 
   826 lemma (in normal) rcos_sum:
   827      "\<lbrakk>x \<in> carrier(G); y \<in> carrier(G)\<rbrakk>
   828       \<Longrightarrow> (H #> x) <#> (H #> y) = H #> (x \<cdot> y)"
   829 by (simp add: rcos_mult_step1 rcos_mult_step2 rcos_mult_step3)
   830 
   831 lemma (in normal) rcosets_mult_eq: "M \<in> rcosets H \<Longrightarrow> H <#> M = M"
   832   -- {* generalizes @{text subgroup_mult_id} *}
   833   by (auto simp add: RCOSETS_def subset
   834         setmult_rcos_assoc subgroup_mult_id prems normal.axioms)
   835 
   836 
   837 subsubsection{*Two distinct right cosets are disjoint*}
   838 
   839 constdefs (structure G)
   840   r_congruent :: "[i,i] => i" ("rcong\<index> _" [60] 60)
   841    "rcong H == {<x,y> \<in> carrier(G) * carrier(G). inv x \<cdot> y \<in> H}"
   842 
   843 
   844 lemma (in subgroup) equiv_rcong:
   845    includes group G
   846    shows "equiv (carrier(G), rcong H)"
   847 proof (simp add: equiv_def, intro conjI)
   848   show "rcong H \<subseteq> carrier(G) \<times> carrier(G)"
   849     by (auto simp add: r_congruent_def) 
   850 next
   851   show "refl (carrier(G), rcong H)"
   852     by (auto simp add: r_congruent_def refl_def) 
   853 next
   854   show "sym (rcong H)"
   855   proof (simp add: r_congruent_def sym_def, clarify)
   856     fix x y
   857     assume [simp]: "x \<in> carrier(G)" "y \<in> carrier(G)" 
   858        and "inv x \<cdot> y \<in> H"
   859     hence "inv (inv x \<cdot> y) \<in> H" by (simp add: m_inv_closed) 
   860     thus "inv y \<cdot> x \<in> H" by (simp add: inv_mult_group)
   861   qed
   862 next
   863   show "trans (rcong H)"
   864   proof (simp add: r_congruent_def trans_def, clarify)
   865     fix x y z
   866     assume [simp]: "x \<in> carrier(G)" "y \<in> carrier(G)" "z \<in> carrier(G)"
   867        and "inv x \<cdot> y \<in> H" and "inv y \<cdot> z \<in> H"
   868     hence "(inv x \<cdot> y) \<cdot> (inv y \<cdot> z) \<in> H" by simp
   869     hence "inv x \<cdot> (y \<cdot> inv y) \<cdot> z \<in> H" by (simp add: m_assoc del: inv) 
   870     thus "inv x \<cdot> z \<in> H" by simp
   871   qed
   872 qed
   873 
   874 text{*Equivalence classes of @{text rcong} correspond to left cosets.
   875   Was there a mistake in the definitions? I'd have expected them to
   876   correspond to right cosets.*}
   877 lemma (in subgroup) l_coset_eq_rcong:
   878   includes group G
   879   assumes a: "a \<in> carrier(G)"
   880   shows "a <# H = (rcong H) `` {a}" 
   881 by (force simp add: r_congruent_def l_coset_def m_assoc [symmetric] a
   882                 Collect_image_eq) 
   883 
   884 
   885 lemma (in group) rcos_equation:
   886   includes subgroup H G
   887   shows
   888      "\<lbrakk>ha \<cdot> a = h \<cdot> b; a \<in> carrier(G);  b \<in> carrier(G);  
   889         h \<in> H;  ha \<in> H;  hb \<in> H\<rbrakk>
   890       \<Longrightarrow> hb \<cdot> a \<in> (\<Union>h\<in>H. {h \<cdot> b})"
   891 apply (rule UN_I [of "hb \<cdot> ((inv ha) \<cdot> h)"], simp)
   892 apply (simp add: m_assoc transpose_inv)
   893 done
   894 
   895 
   896 lemma (in group) rcos_disjoint:
   897   includes subgroup H G
   898   shows "\<lbrakk>a \<in> rcosets H; b \<in> rcosets H; a\<noteq>b\<rbrakk> \<Longrightarrow> a \<inter> b = 0"
   899 apply (simp add: RCOSETS_def r_coset_def)
   900 apply (blast intro: rcos_equation prems sym)
   901 done
   902 
   903 
   904 subsection {*Order of a Group and Lagrange's Theorem*}
   905 
   906 constdefs
   907   order :: "i => i"
   908   "order(S) == |carrier(S)|"
   909 
   910 lemma (in group) rcos_self:
   911   includes subgroup
   912   shows "x \<in> carrier(G) \<Longrightarrow> x \<in> H #> x"
   913 apply (simp add: r_coset_def)
   914 apply (rule_tac x="\<one>" in bexI, auto) 
   915 done
   916 
   917 lemma (in group) rcosets_part_G:
   918   includes subgroup
   919   shows "\<Union>(rcosets H) = carrier(G)"
   920 apply (rule equalityI)
   921  apply (force simp add: RCOSETS_def r_coset_def)
   922 apply (auto simp add: RCOSETS_def intro: rcos_self prems)
   923 done
   924 
   925 lemma (in group) cosets_finite:
   926      "\<lbrakk>c \<in> rcosets H;  H \<subseteq> carrier(G);  Finite (carrier(G))\<rbrakk> \<Longrightarrow> Finite(c)"
   927 apply (auto simp add: RCOSETS_def)
   928 apply (simp add: r_coset_subset_G [THEN subset_Finite])
   929 done
   930 
   931 text{*More general than the HOL version, which also requires @{term G} to
   932       be finite.*}
   933 lemma (in group) card_cosets_equal:
   934   assumes H:   "H \<subseteq> carrier(G)"
   935   shows "c \<in> rcosets H \<Longrightarrow> |c| = |H|"
   936 proof (simp add: RCOSETS_def, clarify)
   937   fix a
   938   assume a: "a \<in> carrier(G)"
   939   show "|H #> a| = |H|"
   940   proof (rule eqpollI [THEN cardinal_cong])
   941     show "H #> a \<lesssim> H"
   942     proof (simp add: lepoll_def, intro exI) 
   943       show "(\<lambda>y \<in> H#>a. y \<cdot> inv a) \<in> inj(H #> a, H)"
   944         by (auto intro: lam_type 
   945                  simp add: inj_def r_coset_def m_assoc subsetD [OF H] a)
   946     qed
   947     show "H \<lesssim> H #> a"
   948     proof (simp add: lepoll_def, intro exI) 
   949       show "(\<lambda>y\<in> H. y \<cdot> a) \<in> inj(H, H #> a)"
   950         by (auto intro: lam_type 
   951                  simp add: inj_def r_coset_def  subsetD [OF H] a)
   952     qed
   953   qed
   954 qed
   955 
   956 
   957 lemma (in group) rcosets_subset_PowG:
   958      "subgroup(H,G) \<Longrightarrow> rcosets H \<subseteq> Pow(carrier(G))"
   959 apply (simp add: RCOSETS_def)
   960 apply (blast dest: r_coset_subset_G subgroup.subset)
   961 done
   962 
   963 theorem (in group) lagrange:
   964      "\<lbrakk>Finite(carrier(G)); subgroup(H,G)\<rbrakk>
   965       \<Longrightarrow> |rcosets H| #* |H| = order(G)"
   966 apply (simp (no_asm_simp) add: order_def rcosets_part_G [symmetric])
   967 apply (subst mult_commute)
   968 apply (rule card_partition)
   969    apply (simp add: rcosets_subset_PowG [THEN subset_Finite])
   970   apply (simp add: rcosets_part_G)
   971  apply (simp add: card_cosets_equal [OF subgroup.subset])
   972 apply (simp add: rcos_disjoint)
   973 done
   974 
   975 
   976 subsection {*Quotient Groups: Factorization of a Group*}
   977 
   978 constdefs (structure G)
   979   FactGroup :: "[i,i] => i" (infixl "Mod" 65)
   980     --{*Actually defined for groups rather than monoids*}
   981   "G Mod H == 
   982      <rcosets\<^bsub>G\<^esub> H, \<lambda><K1,K2> \<in> (rcosets\<^bsub>G\<^esub> H) \<times> (rcosets\<^bsub>G\<^esub> H). K1 <#> K2, H, 0>"
   983 
   984 lemma (in normal) setmult_closed:
   985      "\<lbrakk>K1 \<in> rcosets H; K2 \<in> rcosets H\<rbrakk> \<Longrightarrow> K1 <#> K2 \<in> rcosets H"
   986 by (auto simp add: rcos_sum RCOSETS_def)
   987 
   988 lemma (in normal) setinv_closed:
   989      "K \<in> rcosets H \<Longrightarrow> set_inv K \<in> rcosets H"
   990 by (auto simp add: rcos_inv RCOSETS_def)
   991 
   992 lemma (in normal) rcosets_assoc:
   993      "\<lbrakk>M1 \<in> rcosets H; M2 \<in> rcosets H; M3 \<in> rcosets H\<rbrakk>
   994       \<Longrightarrow> M1 <#> M2 <#> M3 = M1 <#> (M2 <#> M3)"
   995 by (auto simp add: RCOSETS_def rcos_sum m_assoc)
   996 
   997 lemma (in subgroup) subgroup_in_rcosets:
   998   includes group G
   999   shows "H \<in> rcosets H"
  1000 proof -
  1001   have "H #> \<one> = H"
  1002     by (rule coset_join2, auto)
  1003   then show ?thesis
  1004     by (auto simp add: RCOSETS_def intro: sym)
  1005 qed
  1006 
  1007 lemma (in normal) rcosets_inv_mult_group_eq:
  1008      "M \<in> rcosets H \<Longrightarrow> set_inv M <#> M = H"
  1009 by (auto simp add: RCOSETS_def rcos_inv rcos_sum subgroup.subset prems normal.axioms)
  1010 
  1011 theorem (in normal) factorgroup_is_group:
  1012   "group (G Mod H)"
  1013 apply (simp add: FactGroup_def)
  1014 apply (rule groupI)
  1015     apply (simp add: setmult_closed)
  1016    apply (simp add: normal_imp_subgroup subgroup_in_rcosets)
  1017   apply (simp add: setmult_closed rcosets_assoc)
  1018  apply (simp add: normal_imp_subgroup
  1019                   subgroup_in_rcosets rcosets_mult_eq)
  1020 apply (auto dest: rcosets_inv_mult_group_eq simp add: setinv_closed)
  1021 done
  1022 
  1023 lemma (in normal) inv_FactGroup:
  1024      "X \<in> carrier (G Mod H) \<Longrightarrow> inv\<^bsub>G Mod H\<^esub> X = set_inv X"
  1025 apply (rule group.inv_equality [OF factorgroup_is_group]) 
  1026 apply (simp_all add: FactGroup_def setinv_closed rcosets_inv_mult_group_eq)
  1027 done
  1028 
  1029 text{*The coset map is a homomorphism from @{term G} to the quotient group
  1030   @{term "G Mod H"}*}
  1031 lemma (in normal) r_coset_hom_Mod:
  1032   "(\<lambda>a \<in> carrier(G). H #> a) \<in> hom(G, G Mod H)"
  1033 by (auto simp add: FactGroup_def RCOSETS_def hom_def rcos_sum intro: lam_type) 
  1034 
  1035 
  1036 subsection{*The First Isomorphism Theorem*}
  1037 
  1038 text{*The quotient by the kernel of a homomorphism is isomorphic to the 
  1039   range of that homomorphism.*}
  1040 
  1041 constdefs
  1042   kernel :: "[i,i,i] => i" 
  1043     --{*the kernel of a homomorphism*}
  1044   "kernel(G,H,h) == {x \<in> carrier(G). h ` x = \<one>\<^bsub>H\<^esub>}";
  1045 
  1046 lemma (in group_hom) subgroup_kernel: "subgroup (kernel(G,H,h), G)"
  1047 apply (rule subgroup.intro) 
  1048 apply (auto simp add: kernel_def group.intro prems) 
  1049 done
  1050 
  1051 text{*The kernel of a homomorphism is a normal subgroup*}
  1052 lemma (in group_hom) normal_kernel: "(kernel(G,H,h)) \<lhd> G"
  1053 apply (simp add: group.normal_inv_iff subgroup_kernel group.intro prems)
  1054 apply (simp add: kernel_def)  
  1055 done
  1056 
  1057 lemma (in group_hom) FactGroup_nonempty:
  1058   assumes X: "X \<in> carrier (G Mod kernel(G,H,h))"
  1059   shows "X \<noteq> 0"
  1060 proof -
  1061   from X
  1062   obtain g where "g \<in> carrier(G)" 
  1063              and "X = kernel(G,H,h) #> g"
  1064     by (auto simp add: FactGroup_def RCOSETS_def)
  1065   thus ?thesis 
  1066    by (auto simp add: kernel_def r_coset_def image_def intro: hom_one)
  1067 qed
  1068 
  1069 
  1070 lemma (in group_hom) FactGroup_contents_mem:
  1071   assumes X: "X \<in> carrier (G Mod (kernel(G,H,h)))"
  1072   shows "contents (h``X) \<in> carrier(H)"
  1073 proof -
  1074   from X
  1075   obtain g where g: "g \<in> carrier(G)" 
  1076              and "X = kernel(G,H,h) #> g"
  1077     by (auto simp add: FactGroup_def RCOSETS_def)
  1078   hence "h `` X = {h ` g}"
  1079     by (auto simp add: kernel_def r_coset_def image_UN 
  1080                        image_eq_UN [OF hom_is_fun] g)
  1081   thus ?thesis by (auto simp add: g)
  1082 qed
  1083 
  1084 lemma mult_FactGroup:
  1085      "[|X \<in> carrier(G Mod H); X' \<in> carrier(G Mod H)|] 
  1086       ==> X \<cdot>\<^bsub>(G Mod H)\<^esub> X' = X <#>\<^bsub>G\<^esub> X'"
  1087 by (simp add: FactGroup_def) 
  1088 
  1089 lemma (in normal) FactGroup_m_closed:
  1090      "[|X \<in> carrier(G Mod H); X' \<in> carrier(G Mod H)|] 
  1091       ==> X <#>\<^bsub>G\<^esub> X' \<in> carrier(G Mod H)"
  1092 by (simp add: FactGroup_def setmult_closed) 
  1093 
  1094 lemma (in group_hom) FactGroup_hom:
  1095      "(\<lambda>X \<in> carrier(G Mod (kernel(G,H,h))). contents (h``X))
  1096       \<in> hom (G Mod (kernel(G,H,h)), H)" 
  1097 proof (simp add: hom_def FactGroup_contents_mem lam_type mult_FactGroup normal.FactGroup_m_closed [OF normal_kernel], intro ballI)  
  1098   fix X and X'
  1099   assume X:  "X  \<in> carrier (G Mod kernel(G,H,h))"
  1100      and X': "X' \<in> carrier (G Mod kernel(G,H,h))"
  1101   then
  1102   obtain g and g'
  1103            where "g \<in> carrier(G)" and "g' \<in> carrier(G)" 
  1104              and "X = kernel(G,H,h) #> g" and "X' = kernel(G,H,h) #> g'"
  1105     by (auto simp add: FactGroup_def RCOSETS_def)
  1106   hence all: "\<forall>x\<in>X. h ` x = h ` g" "\<forall>x\<in>X'. h ` x = h ` g'" 
  1107     and Xsub: "X \<subseteq> carrier(G)" and X'sub: "X' \<subseteq> carrier(G)"
  1108     by (force simp add: kernel_def r_coset_def image_def)+
  1109   hence "h `` (X <#> X') = {h ` g \<cdot>\<^bsub>H\<^esub> h ` g'}" using X X'
  1110     by (auto dest!: FactGroup_nonempty
  1111              simp add: set_mult_def image_eq_UN [OF hom_is_fun] image_UN
  1112                        subsetD [OF Xsub] subsetD [OF X'sub]) 
  1113   thus "contents (h `` (X <#> X')) = contents (h `` X) \<cdot>\<^bsub>H\<^esub> contents (h `` X')"
  1114     by (simp add: all image_eq_UN [OF hom_is_fun] FactGroup_nonempty 
  1115                   X X' Xsub X'sub)
  1116 qed
  1117 
  1118 
  1119 text{*Lemma for the following injectivity result*}
  1120 lemma (in group_hom) FactGroup_subset:
  1121      "\<lbrakk>g \<in> carrier(G); g' \<in> carrier(G); h ` g = h ` g'\<rbrakk>
  1122       \<Longrightarrow>  kernel(G,H,h) #> g \<subseteq> kernel(G,H,h) #> g'"
  1123 apply (clarsimp simp add: kernel_def r_coset_def image_def)
  1124 apply (rename_tac y)  
  1125 apply (rule_tac x="y \<cdot> g \<cdot> inv g'" in bexI) 
  1126 apply (simp_all add: G.m_assoc) 
  1127 done
  1128 
  1129 lemma (in group_hom) FactGroup_inj:
  1130      "(\<lambda>X\<in>carrier (G Mod kernel(G,H,h)). contents (h `` X))
  1131       \<in> inj(carrier (G Mod kernel(G,H,h)), carrier(H))"
  1132 proof (simp add: inj_def FactGroup_contents_mem lam_type, clarify) 
  1133   fix X and X'
  1134   assume X:  "X  \<in> carrier (G Mod kernel(G,H,h))"
  1135      and X': "X' \<in> carrier (G Mod kernel(G,H,h))"
  1136   then
  1137   obtain g and g'
  1138            where gX: "g \<in> carrier(G)"  "g' \<in> carrier(G)" 
  1139               "X = kernel(G,H,h) #> g" "X' = kernel(G,H,h) #> g'"
  1140     by (auto simp add: FactGroup_def RCOSETS_def)
  1141   hence all: "\<forall>x\<in>X. h ` x = h ` g" "\<forall>x\<in>X'. h ` x = h ` g'"
  1142     and Xsub: "X \<subseteq> carrier(G)" and X'sub: "X' \<subseteq> carrier(G)"
  1143     by (force simp add: kernel_def r_coset_def image_def)+
  1144   assume "contents (h `` X) = contents (h `` X')"
  1145   hence h: "h ` g = h ` g'"
  1146     by (simp add: all image_eq_UN [OF hom_is_fun] FactGroup_nonempty 
  1147                   X X' Xsub X'sub)
  1148   show "X=X'" by (rule equalityI) (simp_all add: FactGroup_subset h gX) 
  1149 qed
  1150 
  1151 
  1152 lemma (in group_hom) kernel_rcoset_subset:
  1153   assumes g: "g \<in> carrier(G)"
  1154   shows "kernel(G,H,h) #> g \<subseteq> carrier (G)"
  1155     by (auto simp add: g kernel_def r_coset_def) 
  1156 
  1157 
  1158 
  1159 text{*If the homomorphism @{term h} is onto @{term H}, then so is the
  1160 homomorphism from the quotient group*}
  1161 lemma (in group_hom) FactGroup_surj:
  1162   assumes h: "h \<in> surj(carrier(G), carrier(H))"
  1163   shows "(\<lambda>X\<in>carrier (G Mod kernel(G,H,h)). contents (h `` X))
  1164          \<in> surj(carrier (G Mod kernel(G,H,h)), carrier(H))"
  1165 proof (simp add: surj_def FactGroup_contents_mem lam_type, clarify)
  1166   fix y
  1167   assume y: "y \<in> carrier(H)"
  1168   with h obtain g where g: "g \<in> carrier(G)" "h ` g = y"
  1169     by (auto simp add: surj_def) 
  1170   hence "(\<Union>x\<in>kernel(G,H,h) #> g. {h ` x}) = {y}" 
  1171     by (auto simp add: y kernel_def r_coset_def) 
  1172   with g show "\<exists>x\<in>carrier(G Mod kernel(G, H, h)). contents(h `` x) = y"
  1173         --{*The witness is @{term "kernel(G,H,h) #> g"}*}
  1174     by (force simp add: FactGroup_def RCOSETS_def 
  1175            image_eq_UN [OF hom_is_fun] kernel_rcoset_subset)
  1176 qed
  1177 
  1178 
  1179 text{*If @{term h} is a homomorphism from @{term G} onto @{term H}, then the
  1180  quotient group @{term "G Mod (kernel(G,H,h))"} is isomorphic to @{term H}.*}
  1181 theorem (in group_hom) FactGroup_iso:
  1182   "h \<in> surj(carrier(G), carrier(H))
  1183    \<Longrightarrow> (\<lambda>X\<in>carrier (G Mod kernel(G,H,h)). contents (h``X)) \<in> (G Mod (kernel(G,H,h))) \<cong> H"
  1184 by (simp add: iso_def FactGroup_hom FactGroup_inj bij_def FactGroup_surj)
  1185  
  1186 end