src/HOL/Algebra/QuotRing.thy
author paulson <lp15@cam.ac.uk>
Tue Jul 03 10:07:24 2018 +0100 (14 months ago)
changeset 68583 654e73d05495
parent 68551 b680e74eb6f2
child 68584 ec4fe1032b6e
permissions -rw-r--r--
even more from Paulo
     1 (*  Title:      HOL/Algebra/QuotRing.thy
     2     Author:     Stephan Hohe
     3     Author:     Paulo Emílio de Vilhena
     4 
     5 *)
     6 
     7 theory QuotRing
     8 imports RingHom
     9 begin
    10 
    11 section \<open>Quotient Rings\<close>
    12 
    13 subsection \<open>Multiplication on Cosets\<close>
    14 
    15 definition rcoset_mult :: "[('a, _) ring_scheme, 'a set, 'a set, 'a set] \<Rightarrow> 'a set"
    16     ("[mod _:] _ \<Otimes>\<index> _" [81,81,81] 80)
    17   where "rcoset_mult R I A B = (\<Union>a\<in>A. \<Union>b\<in>B. I +>\<^bsub>R\<^esub> (a \<otimes>\<^bsub>R\<^esub> b))"
    18 
    19 
    20 text \<open>@{const "rcoset_mult"} fulfils the properties required by
    21   congruences\<close>
    22 lemma (in ideal) rcoset_mult_add:
    23     "x \<in> carrier R \<Longrightarrow> y \<in> carrier R \<Longrightarrow> [mod I:] (I +> x) \<Otimes> (I +> y) = I +> (x \<otimes> y)"
    24   apply rule
    25   apply (rule, simp add: rcoset_mult_def, clarsimp)
    26   defer 1
    27   apply (rule, simp add: rcoset_mult_def)
    28   defer 1
    29 proof -
    30   fix z x' y'
    31   assume carr: "x \<in> carrier R" "y \<in> carrier R"
    32     and x'rcos: "x' \<in> I +> x"
    33     and y'rcos: "y' \<in> I +> y"
    34     and zrcos: "z \<in> I +> x' \<otimes> y'"
    35 
    36   from x'rcos have "\<exists>h\<in>I. x' = h \<oplus> x"
    37     by (simp add: a_r_coset_def r_coset_def)
    38   then obtain hx where hxI: "hx \<in> I" and x': "x' = hx \<oplus> x"
    39     by fast+
    40 
    41   from y'rcos have "\<exists>h\<in>I. y' = h \<oplus> y"
    42     by (simp add: a_r_coset_def r_coset_def)
    43   then obtain hy where hyI: "hy \<in> I" and y': "y' = hy \<oplus> y"
    44     by fast+
    45 
    46   from zrcos have "\<exists>h\<in>I. z = h \<oplus> (x' \<otimes> y')"
    47     by (simp add: a_r_coset_def r_coset_def)
    48   then obtain hz where hzI: "hz \<in> I" and z: "z = hz \<oplus> (x' \<otimes> y')"
    49     by fast+
    50 
    51   note carr = carr hxI[THEN a_Hcarr] hyI[THEN a_Hcarr] hzI[THEN a_Hcarr]
    52 
    53   from z have "z = hz \<oplus> (x' \<otimes> y')" .
    54   also from x' y' have "\<dots> = hz \<oplus> ((hx \<oplus> x) \<otimes> (hy \<oplus> y))" by simp
    55   also from carr have "\<dots> = (hz \<oplus> (hx \<otimes> (hy \<oplus> y)) \<oplus> x \<otimes> hy) \<oplus> x \<otimes> y" by algebra
    56   finally have z2: "z = (hz \<oplus> (hx \<otimes> (hy \<oplus> y)) \<oplus> x \<otimes> hy) \<oplus> x \<otimes> y" .
    57 
    58   from hxI hyI hzI carr have "hz \<oplus> (hx \<otimes> (hy \<oplus> y)) \<oplus> x \<otimes> hy \<in> I"
    59     by (simp add: I_l_closed I_r_closed)
    60 
    61   with z2 have "\<exists>h\<in>I. z = h \<oplus> x \<otimes> y" by fast
    62   then show "z \<in> I +> x \<otimes> y" by (simp add: a_r_coset_def r_coset_def)
    63 next
    64   fix z
    65   assume xcarr: "x \<in> carrier R"
    66     and ycarr: "y \<in> carrier R"
    67     and zrcos: "z \<in> I +> x \<otimes> y"
    68   from xcarr have xself: "x \<in> I +> x" by (intro a_rcos_self)
    69   from ycarr have yself: "y \<in> I +> y" by (intro a_rcos_self)
    70   show "\<exists>a\<in>I +> x. \<exists>b\<in>I +> y. z \<in> I +> a \<otimes> b"
    71     using xself and yself and zrcos by fast
    72 qed
    73 
    74 
    75 subsection \<open>Quotient Ring Definition\<close>
    76 
    77 definition FactRing :: "[('a,'b) ring_scheme, 'a set] \<Rightarrow> ('a set) ring"
    78     (infixl "Quot" 65)
    79   where "FactRing R I =
    80     \<lparr>carrier = a_rcosets\<^bsub>R\<^esub> I, mult = rcoset_mult R I,
    81       one = (I +>\<^bsub>R\<^esub> \<one>\<^bsub>R\<^esub>), zero = I, add = set_add R\<rparr>"
    82 
    83 
    84 subsection \<open>Factorization over General Ideals\<close>
    85 
    86 text \<open>The quotient is a ring\<close>
    87 lemma (in ideal) quotient_is_ring: "ring (R Quot I)"
    88 apply (rule ringI)
    89    \<comment> \<open>abelian group\<close>
    90    apply (rule comm_group_abelian_groupI)
    91    apply (simp add: FactRing_def)
    92    apply (rule a_factorgroup_is_comm_group[unfolded A_FactGroup_def'])
    93   \<comment> \<open>mult monoid\<close>
    94   apply (rule monoidI)
    95       apply (simp_all add: FactRing_def A_RCOSETS_def RCOSETS_def
    96              a_r_coset_def[symmetric])
    97       \<comment> \<open>mult closed\<close>
    98       apply (clarify)
    99       apply (simp add: rcoset_mult_add, fast)
   100      \<comment> \<open>mult \<open>one_closed\<close>\<close>
   101      apply force
   102     \<comment> \<open>mult assoc\<close>
   103     apply clarify
   104     apply (simp add: rcoset_mult_add m_assoc)
   105    \<comment> \<open>mult one\<close>
   106    apply clarify
   107    apply (simp add: rcoset_mult_add)
   108   apply clarify
   109   apply (simp add: rcoset_mult_add)
   110  \<comment> \<open>distr\<close>
   111  apply clarify
   112  apply (simp add: rcoset_mult_add a_rcos_sum l_distr)
   113 apply clarify
   114 apply (simp add: rcoset_mult_add a_rcos_sum r_distr)
   115 done
   116 
   117 
   118 text \<open>This is a ring homomorphism\<close>
   119 
   120 lemma (in ideal) rcos_ring_hom: "((+>) I) \<in> ring_hom R (R Quot I)"
   121 apply (rule ring_hom_memI)
   122    apply (simp add: FactRing_def a_rcosetsI[OF a_subset])
   123   apply (simp add: FactRing_def rcoset_mult_add)
   124  apply (simp add: FactRing_def a_rcos_sum)
   125 apply (simp add: FactRing_def)
   126 done
   127 
   128 lemma (in ideal) rcos_ring_hom_ring: "ring_hom_ring R (R Quot I) ((+>) I)"
   129 apply (rule ring_hom_ringI)
   130      apply (rule is_ring, rule quotient_is_ring)
   131    apply (simp add: FactRing_def a_rcosetsI[OF a_subset])
   132   apply (simp add: FactRing_def rcoset_mult_add)
   133  apply (simp add: FactRing_def a_rcos_sum)
   134 apply (simp add: FactRing_def)
   135 done
   136 
   137 text \<open>The quotient of a cring is also commutative\<close>
   138 lemma (in ideal) quotient_is_cring:
   139   assumes "cring R"
   140   shows "cring (R Quot I)"
   141 proof -
   142   interpret cring R by fact
   143   show ?thesis
   144     apply (intro cring.intro comm_monoid.intro comm_monoid_axioms.intro)
   145       apply (rule quotient_is_ring)
   146      apply (rule ring.axioms[OF quotient_is_ring])
   147     apply (simp add: FactRing_def A_RCOSETS_defs a_r_coset_def[symmetric])
   148     apply clarify
   149     apply (simp add: rcoset_mult_add m_comm)
   150     done
   151 qed
   152 
   153 text \<open>Cosets as a ring homomorphism on crings\<close>
   154 lemma (in ideal) rcos_ring_hom_cring:
   155   assumes "cring R"
   156   shows "ring_hom_cring R (R Quot I) ((+>) I)"
   157 proof -
   158   interpret cring R by fact
   159   show ?thesis
   160     apply (rule ring_hom_cringI)
   161       apply (rule rcos_ring_hom_ring)
   162      apply (rule is_cring)
   163     apply (rule quotient_is_cring)
   164    apply (rule is_cring)
   165    done
   166 qed
   167 
   168 
   169 subsection \<open>Factorization over Prime Ideals\<close>
   170 
   171 text \<open>The quotient ring generated by a prime ideal is a domain\<close>
   172 lemma (in primeideal) quotient_is_domain: "domain (R Quot I)"
   173   apply (rule domain.intro)
   174    apply (rule quotient_is_cring, rule is_cring)
   175   apply (rule domain_axioms.intro)
   176    apply (simp add: FactRing_def) defer 1
   177     apply (simp add: FactRing_def A_RCOSETS_defs a_r_coset_def[symmetric], clarify)
   178     apply (simp add: rcoset_mult_add) defer 1
   179 proof (rule ccontr, clarsimp)
   180   assume "I +> \<one> = I"
   181   then have "\<one> \<in> I" by (simp only: a_coset_join1 one_closed a_subgroup)
   182   then have "carrier R \<subseteq> I" by (subst one_imp_carrier, simp, fast)
   183   with a_subset have "I = carrier R" by fast
   184   with I_notcarr show False by fast
   185 next
   186   fix x y
   187   assume carr: "x \<in> carrier R" "y \<in> carrier R"
   188     and a: "I +> x \<otimes> y = I"
   189     and b: "I +> y \<noteq> I"
   190 
   191   have ynI: "y \<notin> I"
   192   proof (rule ccontr, simp)
   193     assume "y \<in> I"
   194     then have "I +> y = I" by (rule a_rcos_const)
   195     with b show False by simp
   196   qed
   197 
   198   from carr have "x \<otimes> y \<in> I +> x \<otimes> y" by (simp add: a_rcos_self)
   199   then have xyI: "x \<otimes> y \<in> I" by (simp add: a)
   200 
   201   from xyI and carr have xI: "x \<in> I \<or> y \<in> I" by (simp add: I_prime)
   202   with ynI have "x \<in> I" by fast
   203   then show "I +> x = I" by (rule a_rcos_const)
   204 qed
   205 
   206 text \<open>Generating right cosets of a prime ideal is a homomorphism
   207         on commutative rings\<close>
   208 lemma (in primeideal) rcos_ring_hom_cring: "ring_hom_cring R (R Quot I) ((+>) I)"
   209   by (rule rcos_ring_hom_cring) (rule is_cring)
   210 
   211 
   212 subsection \<open>Factorization over Maximal Ideals\<close>
   213 
   214 text \<open>In a commutative ring, the quotient ring over a maximal ideal
   215         is a field.
   216         The proof follows ``W. Adkins, S. Weintraub: Algebra --
   217         An Approach via Module Theory''\<close>
   218 lemma (in maximalideal) quotient_is_field:
   219   assumes "cring R"
   220   shows "field (R Quot I)"
   221 proof -
   222   interpret cring R by fact
   223   show ?thesis
   224     apply (intro cring.cring_fieldI2)
   225       apply (rule quotient_is_cring, rule is_cring)
   226      defer 1
   227      apply (simp add: FactRing_def A_RCOSETS_defs a_r_coset_def[symmetric], clarsimp)
   228      apply (simp add: rcoset_mult_add) defer 1
   229   proof (rule ccontr, simp)
   230     \<comment> \<open>Quotient is not empty\<close>
   231     assume "\<zero>\<^bsub>R Quot I\<^esub> = \<one>\<^bsub>R Quot I\<^esub>"
   232     then have II1: "I = I +> \<one>" by (simp add: FactRing_def)
   233     from a_rcos_self[OF one_closed] have "\<one> \<in> I"
   234       by (simp add: II1[symmetric])
   235     then have "I = carrier R" by (rule one_imp_carrier)
   236     with I_notcarr show False by simp
   237   next
   238     \<comment> \<open>Existence of Inverse\<close>
   239     fix a
   240     assume IanI: "I +> a \<noteq> I" and acarr: "a \<in> carrier R"
   241 
   242     \<comment> \<open>Helper ideal \<open>J\<close>\<close>
   243     define J :: "'a set" where "J = (carrier R #> a) <+> I"
   244     have idealJ: "ideal J R"
   245       apply (unfold J_def, rule add_ideals)
   246        apply (simp only: cgenideal_eq_rcos[symmetric], rule cgenideal_ideal, rule acarr)
   247       apply (rule is_ideal)
   248       done
   249 
   250     \<comment> \<open>Showing @{term "J"} not smaller than @{term "I"}\<close>
   251     have IinJ: "I \<subseteq> J"
   252     proof (rule, simp add: J_def r_coset_def set_add_defs)
   253       fix x
   254       assume xI: "x \<in> I"
   255       have Zcarr: "\<zero> \<in> carrier R" by fast
   256       from xI[THEN a_Hcarr] acarr
   257       have "x = \<zero> \<otimes> a \<oplus> x" by algebra
   258       with Zcarr and xI show "\<exists>xa\<in>carrier R. \<exists>k\<in>I. x = xa \<otimes> a \<oplus> k" by fast
   259     qed
   260 
   261     \<comment> \<open>Showing @{term "J \<noteq> I"}\<close>
   262     have anI: "a \<notin> I"
   263     proof (rule ccontr, simp)
   264       assume "a \<in> I"
   265       then have "I +> a = I" by (rule a_rcos_const)
   266       with IanI show False by simp
   267     qed
   268 
   269     have aJ: "a \<in> J"
   270     proof (simp add: J_def r_coset_def set_add_defs)
   271       from acarr
   272       have "a = \<one> \<otimes> a \<oplus> \<zero>" by algebra
   273       with one_closed and additive_subgroup.zero_closed[OF is_additive_subgroup]
   274       show "\<exists>x\<in>carrier R. \<exists>k\<in>I. a = x \<otimes> a \<oplus> k" by fast
   275     qed
   276 
   277     from aJ and anI have JnI: "J \<noteq> I" by fast
   278 
   279     \<comment> \<open>Deducing @{term "J = carrier R"} because @{term "I"} is maximal\<close>
   280     from idealJ and IinJ have "J = I \<or> J = carrier R"
   281     proof (rule I_maximal, unfold J_def)
   282       have "carrier R #> a \<subseteq> carrier R"
   283         using subset_refl acarr by (rule r_coset_subset_G)
   284       then show "carrier R #> a <+> I \<subseteq> carrier R"
   285         using a_subset by (rule set_add_closed)
   286     qed
   287 
   288     with JnI have Jcarr: "J = carrier R" by simp
   289 
   290     \<comment> \<open>Calculating an inverse for @{term "a"}\<close>
   291     from one_closed[folded Jcarr]
   292     have "\<exists>r\<in>carrier R. \<exists>i\<in>I. \<one> = r \<otimes> a \<oplus> i"
   293       by (simp add: J_def r_coset_def set_add_defs)
   294     then obtain r i where rcarr: "r \<in> carrier R"
   295       and iI: "i \<in> I" and one: "\<one> = r \<otimes> a \<oplus> i" by fast
   296     from one and rcarr and acarr and iI[THEN a_Hcarr]
   297     have rai1: "a \<otimes> r = \<ominus>i \<oplus> \<one>" by algebra
   298 
   299     \<comment> \<open>Lifting to cosets\<close>
   300     from iI have "\<ominus>i \<oplus> \<one> \<in> I +> \<one>"
   301       by (intro a_rcosI, simp, intro a_subset, simp)
   302     with rai1 have "a \<otimes> r \<in> I +> \<one>" by simp
   303     then have "I +> \<one> = I +> a \<otimes> r"
   304       by (rule a_repr_independence, simp) (rule a_subgroup)
   305 
   306     from rcarr and this[symmetric]
   307     show "\<exists>r\<in>carrier R. I +> a \<otimes> r = I +> \<one>" by fast
   308   qed
   309 qed
   310 
   311 
   312 lemma (in ring_hom_ring) trivial_hom_iff:
   313   "(h ` (carrier R) = { \<zero>\<^bsub>S\<^esub> }) = (a_kernel R S h = carrier R)"
   314   using group_hom.trivial_hom_iff[OF a_group_hom] by (simp add: a_kernel_def)
   315 
   316 lemma (in ring_hom_ring) trivial_ker_imp_inj:
   317   assumes "a_kernel R S h = { \<zero> }"
   318   shows "inj_on h (carrier R)"
   319   using group_hom.trivial_ker_imp_inj[OF a_group_hom] assms a_kernel_def[of R S h] by simp 
   320 
   321 lemma (in ring_hom_ring) non_trivial_field_hom_imp_inj:
   322   assumes "field R"
   323   shows "h ` (carrier R) \<noteq> { \<zero>\<^bsub>S\<^esub> } \<Longrightarrow> inj_on h (carrier R)"
   324 proof -
   325   assume "h ` (carrier R) \<noteq> { \<zero>\<^bsub>S\<^esub> }"
   326   hence "a_kernel R S h \<noteq> carrier R"
   327     using trivial_hom_iff by linarith
   328   hence "a_kernel R S h = { \<zero> }"
   329     using field.all_ideals[OF assms] kernel_is_ideal by blast
   330   thus "inj_on h (carrier R)"
   331     using trivial_ker_imp_inj by blast
   332 qed
   333 
   334 lemma (in ring_hom_ring) img_is_add_subgroup:
   335   assumes "subgroup H (add_monoid R)"
   336   shows "subgroup (h ` H) (add_monoid S)"
   337 proof -
   338   have "group ((add_monoid R) \<lparr> carrier := H \<rparr>)"
   339     using assms R.add.subgroup_imp_group by blast
   340   moreover have "H \<subseteq> carrier R" by (simp add: R.add.subgroupE(1) assms)
   341   hence "h \<in> hom ((add_monoid R) \<lparr> carrier := H \<rparr>) (add_monoid S)"
   342     unfolding hom_def by (auto simp add: subsetD)
   343   ultimately have "subgroup (h ` carrier ((add_monoid R) \<lparr> carrier := H \<rparr>)) (add_monoid S)"
   344     using group_hom.img_is_subgroup[of "(add_monoid R) \<lparr> carrier := H \<rparr>" "add_monoid S" h]
   345     using a_group_hom group_hom_axioms.intro group_hom_def by blast
   346   thus "subgroup (h ` H) (add_monoid S)" by simp
   347 qed
   348 
   349 lemma (in ring) ring_ideal_imp_quot_ideal:
   350   assumes "ideal I R"
   351   shows "ideal J R \<Longrightarrow> ideal ((+>) I ` J) (R Quot I)"
   352 proof -
   353   assume A: "ideal J R" show "ideal (((+>) I) ` J) (R Quot I)"
   354   proof (rule idealI)
   355     show "ring (R Quot I)"
   356       by (simp add: assms(1) ideal.quotient_is_ring) 
   357   next
   358     have "subgroup J (add_monoid R)"
   359       by (simp add: additive_subgroup.a_subgroup A ideal.axioms(1))
   360     moreover have "((+>) I) \<in> ring_hom R (R Quot I)"
   361       by (simp add: assms(1) ideal.rcos_ring_hom)
   362     ultimately show "subgroup ((+>) I ` J) (add_monoid (R Quot I))"
   363       using assms(1) ideal.rcos_ring_hom_ring ring_hom_ring.img_is_add_subgroup by blast
   364   next
   365     fix a x assume "a \<in> (+>) I ` J" "x \<in> carrier (R Quot I)"
   366     then obtain i j where i: "i \<in> carrier R" "x = I +> i"
   367                       and j: "j \<in> J" "a = I +> j"
   368       unfolding FactRing_def using A_RCOSETS_def'[of R I] by auto
   369     hence "a \<otimes>\<^bsub>R Quot I\<^esub> x = [mod I:] (I +> j) \<Otimes> (I +> i)"
   370       unfolding FactRing_def by simp
   371     hence "a \<otimes>\<^bsub>R Quot I\<^esub> x = I +> (j \<otimes> i)"
   372       using ideal.rcoset_mult_add[OF assms(1), of j i] i(1) j(1) A ideal.Icarr by force
   373     thus "a \<otimes>\<^bsub>R Quot I\<^esub> x \<in> (+>) I ` J"
   374       using A i(1) j(1) by (simp add: ideal.I_r_closed)
   375   
   376     have "x \<otimes>\<^bsub>R Quot I\<^esub> a = [mod I:] (I +> i) \<Otimes> (I +> j)"
   377       unfolding FactRing_def i j by simp
   378     hence "x \<otimes>\<^bsub>R Quot I\<^esub> a = I +> (i \<otimes> j)"
   379       using ideal.rcoset_mult_add[OF assms(1), of i j] i(1) j(1) A ideal.Icarr by force
   380     thus "x \<otimes>\<^bsub>R Quot I\<^esub> a \<in> (+>) I ` J"
   381       using A i(1) j(1) by (simp add: ideal.I_l_closed)
   382   qed
   383 qed
   384 
   385 lemma (in ring_hom_ring) ideal_vimage:
   386   assumes "ideal I S"
   387   shows "ideal { r \<in> carrier R. h r \<in> I } R" (* or (carrier R) \<inter> (h -` I) *)
   388 proof
   389   show "{ r \<in> carrier R. h r \<in> I } \<subseteq> carrier (add_monoid R)" by auto
   390 next
   391   show "\<one>\<^bsub>add_monoid R\<^esub> \<in> { r \<in> carrier R. h r \<in> I }"
   392     by (simp add: additive_subgroup.zero_closed assms ideal.axioms(1))
   393 next
   394   fix a b
   395   assume "a \<in> { r \<in> carrier R. h r \<in> I }"
   396      and "b \<in> { r \<in> carrier R. h r \<in> I }"
   397   hence a: "a \<in> carrier R" "h a \<in> I"
   398     and b: "b \<in> carrier R" "h b \<in> I" by auto
   399   hence "h (a \<oplus> b) = (h a) \<oplus>\<^bsub>S\<^esub> (h b)" using hom_add by blast
   400   moreover have "(h a) \<oplus>\<^bsub>S\<^esub> (h b) \<in> I" using a b assms
   401     by (simp add: additive_subgroup.a_closed ideal.axioms(1))
   402   ultimately show "a \<otimes>\<^bsub>add_monoid R\<^esub> b \<in> { r \<in> carrier R. h r \<in> I }"
   403     using a(1) b (1) by auto
   404 
   405   have "h (\<ominus> a) = \<ominus>\<^bsub>S\<^esub> (h a)" by (simp add: a)
   406   moreover have "\<ominus>\<^bsub>S\<^esub> (h a) \<in> I"
   407     by (simp add: a(2) additive_subgroup.a_inv_closed assms ideal.axioms(1))
   408   ultimately show "inv\<^bsub>add_monoid R\<^esub> a \<in> { r \<in> carrier R. h r \<in> I }"
   409     using a by (simp add: a_inv_def)
   410 next
   411   fix a r
   412   assume "a \<in> { r \<in> carrier R. h r \<in> I }" and r: "r \<in> carrier R"
   413   hence a: "a \<in> carrier R" "h a \<in> I" by auto
   414 
   415   have "h a \<otimes>\<^bsub>S\<^esub> h r \<in> I"
   416     using assms a r by (simp add: ideal.I_r_closed)
   417   thus "a \<otimes> r \<in> { r \<in> carrier R. h r \<in> I }" by (simp add: a(1) r)
   418 
   419   have "h r \<otimes>\<^bsub>S\<^esub> h a \<in> I"
   420     using assms a r by (simp add: ideal.I_l_closed)
   421   thus "r \<otimes> a \<in> { r \<in> carrier R. h r \<in> I }" by (simp add: a(1) r)
   422 qed
   423 
   424 lemma (in ring) canonical_proj_vimage_in_carrier:
   425   assumes "ideal I R"
   426   shows "J \<subseteq> carrier (R Quot I) \<Longrightarrow> \<Union> J \<subseteq> carrier R"
   427 proof -
   428   assume A: "J \<subseteq> carrier (R Quot I)" show "\<Union> J \<subseteq> carrier R"
   429   proof
   430     fix j assume j: "j \<in> \<Union> J"
   431     then obtain j' where j': "j' \<in> J" "j \<in> j'" by blast
   432     then obtain r where r: "r \<in> carrier R" "j' = I +> r"
   433       using A j' unfolding FactRing_def using A_RCOSETS_def'[of R I] by auto
   434     thus "j \<in> carrier R" using j' assms
   435       by (meson a_r_coset_subset_G additive_subgroup.a_subset contra_subsetD ideal.axioms(1)) 
   436   qed
   437 qed
   438 
   439 lemma (in ring) canonical_proj_vimage_mem_iff:
   440   assumes "ideal I R" "J \<subseteq> carrier (R Quot I)"
   441   shows "\<And>a. a \<in> carrier R \<Longrightarrow> (a \<in> (\<Union> J)) = (I +> a \<in> J)"
   442 proof -
   443   fix a assume a: "a \<in> carrier R" show "(a \<in> (\<Union> J)) = (I +> a \<in> J)"
   444   proof
   445     assume "a \<in> \<Union> J"
   446     then obtain j where j: "j \<in> J" "a \<in> j" by blast
   447     then obtain r where r: "r \<in> carrier R" "j = I +> r"
   448       using assms j unfolding FactRing_def using A_RCOSETS_def'[of R I] by auto
   449     hence "I +> r = I +> a"
   450       using add.repr_independence[of a I r] j r
   451       by (metis a_r_coset_def additive_subgroup.a_subgroup assms(1) ideal.axioms(1))
   452     thus "I +> a \<in> J" using r j by simp
   453   next
   454     assume "I +> a \<in> J"
   455     hence "\<zero> \<oplus> a \<in> I +> a"
   456       using additive_subgroup.zero_closed[OF ideal.axioms(1)[OF assms(1)]]
   457             a_r_coset_def'[of R I a] by blast
   458     thus "a \<in> \<Union> J" using a \<open>I +> a \<in> J\<close> by auto 
   459   qed
   460 qed
   461 
   462 corollary (in ring) quot_ideal_imp_ring_ideal:
   463   assumes "ideal I R"
   464   shows "ideal J (R Quot I) \<Longrightarrow> ideal (\<Union> J) R"
   465 proof -
   466   assume A: "ideal J (R Quot I)"
   467   have "\<Union> J = { r \<in> carrier R. I +> r \<in> J }"
   468     using canonical_proj_vimage_in_carrier[OF assms, of J]
   469           canonical_proj_vimage_mem_iff[OF assms, of J]
   470           additive_subgroup.a_subset[OF ideal.axioms(1)[OF A]] by blast
   471   thus "ideal (\<Union> J) R"
   472     using ring_hom_ring.ideal_vimage[OF ideal.rcos_ring_hom_ring[OF assms] A] by simp
   473 qed
   474 
   475 lemma (in ring) ideal_incl_iff:
   476   assumes "ideal I R" "ideal J R"
   477   shows "(I \<subseteq> J) = (J = (\<Union> j \<in> J. I +> j))"
   478 proof
   479   assume A: "J = (\<Union> j \<in> J. I +> j)" hence "I +> \<zero> \<subseteq> J"
   480     using additive_subgroup.zero_closed[OF ideal.axioms(1)[OF assms(2)]] by blast
   481   thus "I \<subseteq> J" using additive_subgroup.a_subset[OF ideal.axioms(1)[OF assms(1)]] by simp 
   482 next
   483   assume A: "I \<subseteq> J" show "J = (\<Union>j\<in>J. I +> j)"
   484   proof
   485     show "J \<subseteq> (\<Union> j \<in> J. I +> j)"
   486     proof
   487       fix j assume j: "j \<in> J"
   488       have "\<zero> \<in> I" by (simp add: additive_subgroup.zero_closed assms(1) ideal.axioms(1))
   489       hence "\<zero> \<oplus> j \<in> I +> j"
   490         using a_r_coset_def'[of R I j] by blast
   491       thus "j \<in> (\<Union>j\<in>J. I +> j)"
   492         using assms(2) j additive_subgroup.a_Hcarr ideal.axioms(1) by fastforce 
   493     qed
   494   next
   495     show "(\<Union> j \<in> J. I +> j) \<subseteq> J"
   496     proof
   497       fix x assume "x \<in> (\<Union> j \<in> J. I +> j)"
   498       then obtain j where j: "j \<in> J" "x \<in> I +> j" by blast
   499       then obtain i where i: "i \<in> I" "x = i \<oplus> j"
   500         using a_r_coset_def'[of R I j] by blast
   501       thus "x \<in> J"
   502         using assms(2) j A additive_subgroup.a_closed[OF ideal.axioms(1)[OF assms(2)]] by blast
   503     qed
   504   qed
   505 qed
   506 
   507 theorem (in ring) quot_ideal_correspondence:
   508   assumes "ideal I R"
   509   shows "bij_betw (\<lambda>J. (+>) I ` J) { J. ideal J R \<and> I \<subseteq> J } { J . ideal J (R Quot I) }"
   510 proof (rule bij_betw_byWitness[where ?f' = "\<lambda>X. \<Union> X"])
   511   show "\<forall>J \<in> { J. ideal J R \<and> I \<subseteq> J }. (\<lambda>X. \<Union> X) ((+>) I ` J) = J"
   512     using assms ideal_incl_iff by blast
   513 next
   514   show "(\<lambda>J. (+>) I ` J) ` { J. ideal J R \<and> I \<subseteq> J } \<subseteq> { J. ideal J (R Quot I) }"
   515     using assms ring_ideal_imp_quot_ideal by auto
   516 next
   517   show "(\<lambda>X. \<Union> X) ` { J. ideal J (R Quot I) } \<subseteq> { J. ideal J R \<and> I \<subseteq> J }"
   518   proof
   519     fix J assume "J \<in> ((\<lambda>X. \<Union> X) ` { J. ideal J (R Quot I) })"
   520     then obtain J' where J': "ideal J' (R Quot I)" "J = \<Union> J'" by blast
   521     hence "ideal J R"
   522       using assms quot_ideal_imp_ring_ideal by auto
   523     moreover have "I \<in> J'"
   524       using additive_subgroup.zero_closed[OF ideal.axioms(1)[OF J'(1)]] unfolding FactRing_def by simp
   525     ultimately show "J \<in> { J. ideal J R \<and> I \<subseteq> J }" using J'(2) by auto
   526   qed
   527 next
   528   show "\<forall>J' \<in> { J. ideal J (R Quot I) }. ((+>) I ` (\<Union> J')) = J'"
   529   proof
   530     fix J' assume "J' \<in> { J. ideal J (R Quot I) }"
   531     hence subset: "J' \<subseteq> carrier (R Quot I) \<and> ideal J' (R Quot I)"
   532       using additive_subgroup.a_subset ideal_def by blast
   533     hence "((+>) I ` (\<Union> J')) \<subseteq> J'"
   534       using canonical_proj_vimage_in_carrier canonical_proj_vimage_mem_iff
   535       by (meson assms contra_subsetD image_subsetI)
   536     moreover have "J' \<subseteq> ((+>) I ` (\<Union> J'))"
   537     proof
   538       fix x assume "x \<in> J'"
   539       then obtain r where r: "r \<in> carrier R" "x = I +> r"
   540         using subset unfolding FactRing_def A_RCOSETS_def'[of R I] by auto
   541       hence "r \<in> (\<Union> J')"
   542         using \<open>x \<in> J'\<close> assms canonical_proj_vimage_mem_iff subset by blast
   543       thus "x \<in> ((+>) I ` (\<Union> J'))" using r(2) by blast
   544     qed
   545     ultimately show "((+>) I ` (\<Union> J')) = J'" by blast
   546   qed
   547 qed
   548 
   549 lemma (in cring) quot_domain_imp_primeideal:
   550   assumes "ideal P R"
   551   shows "domain (R Quot P) \<Longrightarrow> primeideal P R"
   552 proof -
   553   assume A: "domain (R Quot P)" show "primeideal P R"
   554   proof (rule primeidealI)
   555     show "ideal P R" using assms .
   556     show "cring R" using is_cring .
   557   next
   558     show "carrier R \<noteq> P"
   559     proof (rule ccontr)
   560       assume "\<not> carrier R \<noteq> P" hence "carrier R = P" by simp
   561       hence "\<And>I. I \<in> carrier (R Quot P) \<Longrightarrow> I = P"
   562         unfolding FactRing_def A_RCOSETS_def' apply simp
   563         using a_coset_join2 additive_subgroup.a_subgroup assms ideal.axioms(1) by blast
   564       hence "\<one>\<^bsub>(R Quot P)\<^esub> = \<zero>\<^bsub>(R Quot P)\<^esub>"
   565         by (metis assms ideal.quotient_is_ring ring.ring_simprules(2) ring.ring_simprules(6))
   566       thus False using domain.one_not_zero[OF A] by simp
   567     qed
   568   next
   569     fix a b assume a: "a \<in> carrier R" and b: "b \<in> carrier R" and ab: "a \<otimes> b \<in> P"
   570     hence "P +> (a \<otimes> b) = \<zero>\<^bsub>(R Quot P)\<^esub>" unfolding FactRing_def
   571       by (simp add: a_coset_join2 additive_subgroup.a_subgroup assms ideal.axioms(1))
   572     moreover have "(P +> a) \<otimes>\<^bsub>(R Quot P)\<^esub> (P +> b) = P +> (a \<otimes> b)" unfolding FactRing_def
   573       using a b by (simp add: assms ideal.rcoset_mult_add)
   574     moreover have "P +> a \<in> carrier (R Quot P) \<and> P +> b \<in> carrier (R Quot P)"
   575       by (simp add: a b FactRing_def a_rcosetsI additive_subgroup.a_subset assms ideal.axioms(1))
   576     ultimately have "P +> a = \<zero>\<^bsub>(R Quot P)\<^esub> \<or> P +> b = \<zero>\<^bsub>(R Quot P)\<^esub>"
   577       using domain.integral[OF A, of "P +> a" "P +> b"] by auto
   578     thus "a \<in> P \<or> b \<in> P" unfolding FactRing_def apply simp
   579       using a b assms a_coset_join1 additive_subgroup.a_subgroup ideal.axioms(1) by blast
   580   qed
   581 qed
   582 
   583 lemma (in cring) quot_domain_iff_primeideal:
   584   assumes "ideal P R"
   585   shows "domain (R Quot P) = primeideal P R"
   586   using quot_domain_imp_primeideal[OF assms] primeideal.quotient_is_domain[of P R] by auto
   587 
   588 
   589 subsection \<open>Isomorphism\<close>
   590 
   591 definition
   592   ring_iso :: "_ \<Rightarrow> _ \<Rightarrow> ('a \<Rightarrow> 'b) set"
   593   where "ring_iso R S = { h. h \<in> ring_hom R S \<and> bij_betw h (carrier R) (carrier S) }"
   594 
   595 definition
   596   is_ring_iso :: "_ \<Rightarrow> _ \<Rightarrow> bool" (infixr "\<simeq>" 60)
   597   where "R \<simeq> S = (ring_iso R S \<noteq> {})"
   598 
   599 definition
   600   morphic_prop :: "_ \<Rightarrow> ('a \<Rightarrow> bool) \<Rightarrow> bool"
   601   where "morphic_prop R P =
   602            ((P \<one>\<^bsub>R\<^esub>) \<and>
   603             (\<forall>r \<in> carrier R. P r) \<and>
   604             (\<forall>r1 \<in> carrier R. \<forall>r2 \<in> carrier R. P (r1 \<otimes>\<^bsub>R\<^esub> r2)) \<and>
   605             (\<forall>r1 \<in> carrier R. \<forall>r2 \<in> carrier R. P (r1 \<oplus>\<^bsub>R\<^esub> r2)))"
   606 
   607 lemma ring_iso_memI:
   608   fixes R (structure) and S (structure)
   609   assumes "\<And>x. x \<in> carrier R \<Longrightarrow> h x \<in> carrier S"
   610       and "\<And>x y. \<lbrakk> x \<in> carrier R; y \<in> carrier R \<rbrakk> \<Longrightarrow> h (x \<otimes> y) = h x \<otimes>\<^bsub>S\<^esub> h y"
   611       and "\<And>x y. \<lbrakk> x \<in> carrier R; y \<in> carrier R \<rbrakk> \<Longrightarrow> h (x \<oplus> y) = h x \<oplus>\<^bsub>S\<^esub> h y"
   612       and "h \<one> = \<one>\<^bsub>S\<^esub>"
   613       and "bij_betw h (carrier R) (carrier S)"
   614   shows "h \<in> ring_iso R S"
   615   by (auto simp add: ring_hom_memI assms ring_iso_def)
   616 
   617 lemma ring_iso_memE:
   618   fixes R (structure) and S (structure)
   619   assumes "h \<in> ring_iso R S"
   620   shows "\<And>x. x \<in> carrier R \<Longrightarrow> h x \<in> carrier S"
   621    and "\<And>x y. \<lbrakk> x \<in> carrier R; y \<in> carrier R \<rbrakk> \<Longrightarrow> h (x \<otimes> y) = h x \<otimes>\<^bsub>S\<^esub> h y"
   622    and "\<And>x y. \<lbrakk> x \<in> carrier R; y \<in> carrier R \<rbrakk> \<Longrightarrow> h (x \<oplus> y) = h x \<oplus>\<^bsub>S\<^esub> h y"
   623    and "h \<one> = \<one>\<^bsub>S\<^esub>"
   624    and "bij_betw h (carrier R) (carrier S)"
   625   using assms unfolding ring_iso_def ring_hom_def by auto
   626 
   627 lemma morphic_propI:
   628   fixes R (structure)
   629   assumes "P \<one>"
   630     and "\<And>r. r \<in> carrier R \<Longrightarrow> P r"
   631     and "\<And>r1 r2. \<lbrakk> r1 \<in> carrier R; r2 \<in> carrier R \<rbrakk> \<Longrightarrow> P (r1 \<otimes> r2)"
   632     and "\<And>r1 r2. \<lbrakk> r1 \<in> carrier R; r2 \<in> carrier R \<rbrakk> \<Longrightarrow> P (r1 \<oplus> r2)"
   633   shows "morphic_prop R P"
   634   unfolding morphic_prop_def using assms by auto
   635 
   636 lemma morphic_propE:
   637   fixes R (structure)
   638   assumes "morphic_prop R P"
   639   shows "P \<one>"
   640     and "\<And>r. r \<in> carrier R \<Longrightarrow> P r"
   641     and "\<And>r1 r2. \<lbrakk> r1 \<in> carrier R; r2 \<in> carrier R \<rbrakk> \<Longrightarrow> P (r1 \<otimes> r2)"
   642     and "\<And>r1 r2. \<lbrakk> r1 \<in> carrier R; r2 \<in> carrier R \<rbrakk> \<Longrightarrow> P (r1 \<oplus> r2)"
   643   using assms unfolding morphic_prop_def by auto
   644 
   645 lemma ring_iso_restrict:
   646   assumes "f \<in> ring_iso R S"
   647     and "\<And>r. r \<in> carrier R \<Longrightarrow> f r = g r"
   648     and "ring R"
   649   shows "g \<in> ring_iso R S"
   650 proof (rule ring_iso_memI)
   651   show "bij_betw g (carrier R) (carrier S)"
   652     using assms(1-2) bij_betw_cong ring_iso_memE(5) by blast
   653   show "g \<one>\<^bsub>R\<^esub> = \<one>\<^bsub>S\<^esub>"
   654     using assms ring.ring_simprules(6) ring_iso_memE(4) by force
   655 next
   656   fix x y assume x: "x \<in> carrier R" and y: "y \<in> carrier R"
   657   show "g x \<in> carrier S"
   658     using assms(1-2) ring_iso_memE(1) x by fastforce
   659   show "g (x \<otimes>\<^bsub>R\<^esub> y) = g x \<otimes>\<^bsub>S\<^esub> g y"
   660     by (metis assms ring.ring_simprules(5) ring_iso_memE(2) x y)
   661   show "g (x \<oplus>\<^bsub>R\<^esub> y) = g x \<oplus>\<^bsub>S\<^esub> g y"
   662     by (metis assms ring.ring_simprules(1) ring_iso_memE(3) x y)
   663 qed
   664 
   665 lemma ring_iso_morphic_prop:
   666   assumes "f \<in> ring_iso R S"
   667     and "morphic_prop R P"
   668     and "\<And>r. P r \<Longrightarrow> f r = g r"
   669   shows "g \<in> ring_iso R S"
   670 proof -
   671   have eq0: "\<And>r. r \<in> carrier R \<Longrightarrow> f r = g r"
   672    and eq1: "f \<one>\<^bsub>R\<^esub> = g \<one>\<^bsub>R\<^esub>"
   673    and eq2: "\<And>r1 r2. \<lbrakk> r1 \<in> carrier R; r2 \<in> carrier R \<rbrakk> \<Longrightarrow> f (r1 \<otimes>\<^bsub>R\<^esub> r2) = g (r1 \<otimes>\<^bsub>R\<^esub> r2)"
   674    and eq3: "\<And>r1 r2. \<lbrakk> r1 \<in> carrier R; r2 \<in> carrier R \<rbrakk> \<Longrightarrow> f (r1 \<oplus>\<^bsub>R\<^esub> r2) = g (r1 \<oplus>\<^bsub>R\<^esub> r2)"
   675     using assms(2-3) unfolding morphic_prop_def by auto
   676   show ?thesis
   677     apply (rule ring_iso_memI)
   678     using assms(1) eq0 ring_iso_memE(1) apply fastforce
   679     apply (metis assms(1) eq0 eq2 ring_iso_memE(2))
   680     apply (metis assms(1) eq0 eq3 ring_iso_memE(3))
   681     using assms(1) eq1 ring_iso_memE(4) apply fastforce
   682     using assms(1) bij_betw_cong eq0 ring_iso_memE(5) by blast
   683 qed
   684 
   685 lemma (in ring) ring_hom_imp_img_ring:
   686   assumes "h \<in> ring_hom R S"
   687   shows "ring (S \<lparr> carrier := h ` (carrier R), one := h \<one>, zero := h \<zero> \<rparr>)" (is "ring ?h_img")
   688 proof -
   689   have "h \<in> hom (add_monoid R) (add_monoid S)"
   690     using assms unfolding hom_def ring_hom_def by auto
   691   hence "comm_group ((add_monoid S) \<lparr>  carrier := h ` (carrier R), one := h \<zero> \<rparr>)"
   692     using add.hom_imp_img_comm_group[of h "add_monoid S"] by simp
   693   hence comm_group: "comm_group (add_monoid ?h_img)"
   694     by (auto intro: comm_monoidI simp add: monoid.defs)
   695 
   696   moreover have "h \<in> hom R S"
   697     using assms unfolding ring_hom_def hom_def by auto
   698   hence "monoid (S \<lparr>  carrier := h ` (carrier R), one := h \<one> \<rparr>)"
   699     using hom_imp_img_monoid[of h S] by simp
   700   hence monoid: "monoid ?h_img"
   701     unfolding monoid_def by (simp add: monoid.defs)
   702 
   703   show ?thesis
   704   proof (rule ringI, simp_all add: comm_group_abelian_groupI[OF comm_group] monoid)
   705     fix x y z assume "x \<in> h ` carrier R" "y \<in> h ` carrier R" "z \<in> h ` carrier R"
   706     then obtain r1 r2 r3
   707       where r1: "r1 \<in> carrier R" "x = h r1"
   708         and r2: "r2 \<in> carrier R" "y = h r2"
   709         and r3: "r3 \<in> carrier R" "z = h r3" by blast
   710     hence "(x \<oplus>\<^bsub>S\<^esub> y) \<otimes>\<^bsub>S\<^esub> z = h ((r1 \<oplus> r2) \<otimes> r3)"
   711       using ring_hom_memE[OF assms] by auto
   712     also have " ... = h ((r1 \<otimes> r3) \<oplus> (r2 \<otimes> r3))"
   713       using l_distr[OF r1(1) r2(1) r3(1)] by simp
   714     also have " ... = (x \<otimes>\<^bsub>S\<^esub> z) \<oplus>\<^bsub>S\<^esub> (y \<otimes>\<^bsub>S\<^esub> z)"
   715       using ring_hom_memE[OF assms] r1 r2 r3 by auto
   716     finally show "(x \<oplus>\<^bsub>S\<^esub> y) \<otimes>\<^bsub>S\<^esub> z = (x \<otimes>\<^bsub>S\<^esub> z) \<oplus>\<^bsub>S\<^esub> (y \<otimes>\<^bsub>S\<^esub> z)" .
   717 
   718     have "z \<otimes>\<^bsub>S\<^esub> (x \<oplus>\<^bsub>S\<^esub> y) = h (r3 \<otimes> (r1 \<oplus> r2))"
   719       using ring_hom_memE[OF assms] r1 r2 r3 by auto
   720     also have " ... =  h ((r3 \<otimes> r1) \<oplus> (r3 \<otimes> r2))"
   721       using r_distr[OF r1(1) r2(1) r3(1)] by simp
   722     also have " ... = (z \<otimes>\<^bsub>S\<^esub> x) \<oplus>\<^bsub>S\<^esub> (z \<otimes>\<^bsub>S\<^esub> y)"
   723       using ring_hom_memE[OF assms] r1 r2 r3 by auto
   724     finally show "z \<otimes>\<^bsub>S\<^esub> (x \<oplus>\<^bsub>S\<^esub> y) = (z \<otimes>\<^bsub>S\<^esub> x) \<oplus>\<^bsub>S\<^esub> (z \<otimes>\<^bsub>S\<^esub> y)" .
   725   qed
   726 qed
   727 
   728 lemma (in ring) ring_iso_imp_img_ring:
   729   assumes "h \<in> ring_iso R S"
   730   shows "ring (S \<lparr> one := h \<one>, zero := h \<zero> \<rparr>)"
   731 proof -
   732   have "ring (S \<lparr> carrier := h ` (carrier R), one := h \<one>, zero := h \<zero> \<rparr>)"
   733     using ring_hom_imp_img_ring[of h S] assms unfolding ring_iso_def by auto
   734   moreover have "h ` (carrier R) = carrier S"
   735     using assms unfolding ring_iso_def bij_betw_def by auto
   736   ultimately show ?thesis by simp
   737 qed
   738 
   739 lemma (in cring) ring_iso_imp_img_cring:
   740   assumes "h \<in> ring_iso R S"
   741   shows "cring (S \<lparr> one := h \<one>, zero := h \<zero> \<rparr>)" (is "cring ?h_img")
   742 proof -
   743   note m_comm
   744   interpret h_img?: ring ?h_img
   745     using ring_iso_imp_img_ring[OF assms] .
   746   show ?thesis 
   747   proof (unfold_locales)
   748     fix x y assume "x \<in> carrier ?h_img" "y \<in> carrier ?h_img"
   749     then obtain r1 r2
   750       where r1: "r1 \<in> carrier R" "x = h r1"
   751         and r2: "r2 \<in> carrier R" "y = h r2"
   752       using assms image_iff[where ?f = h and ?A = "carrier R"]
   753       unfolding ring_iso_def bij_betw_def by auto
   754     have "x \<otimes>\<^bsub>(?h_img)\<^esub> y = h (r1 \<otimes> r2)"
   755       using assms r1 r2 unfolding ring_iso_def ring_hom_def by auto
   756     also have " ... = h (r2 \<otimes> r1)"
   757       using m_comm[OF r1(1) r2(1)] by simp
   758     also have " ... = y \<otimes>\<^bsub>(?h_img)\<^esub> x"
   759       using assms r1 r2 unfolding ring_iso_def ring_hom_def by auto
   760     finally show "x \<otimes>\<^bsub>(?h_img)\<^esub> y = y \<otimes>\<^bsub>(?h_img)\<^esub> x" .
   761   qed
   762 qed
   763 
   764 lemma (in domain) ring_iso_imp_img_domain:
   765   assumes "h \<in> ring_iso R S"
   766   shows "domain (S \<lparr> one := h \<one>, zero := h \<zero> \<rparr>)" (is "domain ?h_img")
   767 proof -
   768   note aux = m_closed integral one_not_zero one_closed zero_closed
   769   interpret h_img?: cring ?h_img
   770     using ring_iso_imp_img_cring[OF assms] .
   771   show ?thesis 
   772   proof (unfold_locales)
   773     show "\<one>\<^bsub>?h_img\<^esub> \<noteq> \<zero>\<^bsub>?h_img\<^esub>"
   774       using ring_iso_memE(5)[OF assms] aux(3-4)
   775       unfolding bij_betw_def inj_on_def by force
   776   next
   777     fix a b
   778     assume A: "a \<otimes>\<^bsub>?h_img\<^esub> b = \<zero>\<^bsub>?h_img\<^esub>" "a \<in> carrier ?h_img" "b \<in> carrier ?h_img"
   779     then obtain r1 r2
   780       where r1: "r1 \<in> carrier R" "a = h r1"
   781         and r2: "r2 \<in> carrier R" "b = h r2"
   782       using assms image_iff[where ?f = h and ?A = "carrier R"]
   783       unfolding ring_iso_def bij_betw_def by auto
   784     hence "a \<otimes>\<^bsub>?h_img\<^esub> b = h (r1 \<otimes> r2)"
   785       using assms r1 r2 unfolding ring_iso_def ring_hom_def by auto
   786     hence "h (r1 \<otimes> r2) = h \<zero>"
   787       using A(1) by simp
   788     hence "r1 \<otimes> r2 = \<zero>"
   789       using ring_iso_memE(5)[OF assms] aux(1)[OF r1(1) r2(1)] aux(5)
   790       unfolding bij_betw_def inj_on_def by force
   791     hence "r1 = \<zero> \<or> r2 = \<zero>"
   792       using aux(2)[OF _ r1(1) r2(1)] by simp
   793     thus "a = \<zero>\<^bsub>?h_img\<^esub> \<or> b = \<zero>\<^bsub>?h_img\<^esub>"
   794       unfolding r1 r2 by auto
   795   qed
   796 qed
   797 
   798 lemma (in field) ring_iso_imp_img_field:
   799   assumes "h \<in> ring_iso R S"
   800   shows "field (S \<lparr> one := h \<one>, zero := h \<zero> \<rparr>)" (is "field ?h_img")
   801 proof -
   802   interpret h_img?: domain ?h_img
   803     using ring_iso_imp_img_domain[OF assms] .
   804   show ?thesis
   805   proof (unfold_locales, auto simp add: Units_def)
   806     interpret field R using field_axioms .
   807     fix a assume a: "a \<in> carrier S" "a \<otimes>\<^bsub>S\<^esub> h \<zero> = h \<one>"
   808     then obtain r where r: "r \<in> carrier R" "a = h r"
   809       using assms image_iff[where ?f = h and ?A = "carrier R"]
   810       unfolding ring_iso_def bij_betw_def by auto
   811     have "a \<otimes>\<^bsub>S\<^esub> h \<zero> = h (r \<otimes> \<zero>)" unfolding r(2)
   812       using ring_iso_memE(2)[OF assms r(1)] by simp
   813     hence "h \<one> = h \<zero>"
   814       using r(1) a(2) by simp
   815     thus False
   816       using ring_iso_memE(5)[OF assms]
   817       unfolding bij_betw_def inj_on_def by force
   818   next
   819     interpret field R using field_axioms .
   820     fix s assume s: "s \<in> carrier S" "s \<noteq> h \<zero>"
   821     then obtain r where r: "r \<in> carrier R" "s = h r"
   822       using assms image_iff[where ?f = h and ?A = "carrier R"]
   823       unfolding ring_iso_def bij_betw_def by auto
   824     hence "r \<noteq> \<zero>" using s(2) by auto 
   825     hence inv_r: "inv r \<in> carrier R" "inv r \<noteq> \<zero>" "r \<otimes> inv r = \<one>" "inv r \<otimes> r = \<one>"
   826       using field_Units r(1) by auto
   827     have "h (inv r) \<otimes>\<^bsub>S\<^esub> h r = h \<one>" and "h r \<otimes>\<^bsub>S\<^esub> h (inv r) = h \<one>"
   828       using ring_iso_memE(2)[OF assms inv_r(1) r(1)] inv_r(3-4)
   829             ring_iso_memE(2)[OF assms r(1) inv_r(1)] by auto
   830     thus "\<exists>s' \<in> carrier S. s' \<otimes>\<^bsub>S\<^esub> s = h \<one> \<and> s \<otimes>\<^bsub>S\<^esub> s' = h \<one>"
   831       using ring_iso_memE(1)[OF assms inv_r(1)] r(2) by auto
   832   qed
   833 qed
   834 
   835 lemma ring_iso_same_card: "R \<simeq> S \<Longrightarrow> card (carrier R) = card (carrier S)"
   836 proof -
   837   assume "R \<simeq> S"
   838   then obtain h where "bij_betw h (carrier R) (carrier S)"
   839     unfolding is_ring_iso_def ring_iso_def by auto
   840   thus "card (carrier R) = card (carrier S)"
   841     using bij_betw_same_card[of h "carrier R" "carrier S"] by simp
   842 qed
   843 
   844 lemma ring_iso_set_refl: "id \<in> ring_iso R R"
   845   by (rule ring_iso_memI) (auto)
   846 
   847 corollary ring_iso_refl: "R \<simeq> R"
   848   using is_ring_iso_def ring_iso_set_refl by auto 
   849 
   850 lemma ring_iso_set_trans:
   851   "\<lbrakk> f \<in> ring_iso R S; g \<in> ring_iso S Q \<rbrakk> \<Longrightarrow> (g \<circ> f) \<in> ring_iso R Q"
   852   unfolding ring_iso_def using bij_betw_trans ring_hom_trans by fastforce 
   853 
   854 corollary ring_iso_trans: "\<lbrakk> R \<simeq> S; S \<simeq> Q \<rbrakk> \<Longrightarrow> R \<simeq> Q"
   855   using ring_iso_set_trans unfolding is_ring_iso_def by blast 
   856 
   857 lemma ring_iso_set_sym:
   858   assumes "ring R"
   859   shows "h \<in> ring_iso R S \<Longrightarrow> (inv_into (carrier R) h) \<in> ring_iso S R"
   860 proof -
   861   assume h: "h \<in> ring_iso R S"
   862   hence h_hom:  "h \<in> ring_hom R S"
   863     and h_surj: "h ` (carrier R) = (carrier S)"
   864     and h_inj:  "\<And> x1 x2. \<lbrakk> x1 \<in> carrier R; x2 \<in> carrier R \<rbrakk> \<Longrightarrow>  h x1 = h x2 \<Longrightarrow> x1 = x2"
   865     unfolding ring_iso_def bij_betw_def inj_on_def by auto
   866 
   867   have h_inv_bij: "bij_betw (inv_into (carrier R) h) (carrier S) (carrier R)"
   868       using bij_betw_inv_into h ring_iso_def by fastforce
   869 
   870   show "inv_into (carrier R) h \<in> ring_iso S R"
   871     apply (rule ring_iso_memI)
   872     apply (simp add: h_surj inv_into_into)
   873     apply (auto simp add: h_inv_bij)
   874     apply (smt assms f_inv_into_f h_hom h_inj h_surj inv_into_into
   875            ring.ring_simprules(5) ring_hom_closed ring_hom_mult)
   876     apply (smt assms f_inv_into_f h_hom h_inj h_surj inv_into_into
   877            ring.ring_simprules(1) ring_hom_add ring_hom_closed)
   878     by (metis (no_types, hide_lams) assms f_inv_into_f h_hom h_inj
   879         imageI inv_into_into ring.ring_simprules(6) ring_hom_one)
   880 qed
   881 
   882 corollary ring_iso_sym:
   883   assumes "ring R"
   884   shows "R \<simeq> S \<Longrightarrow> S \<simeq> R"
   885   using assms ring_iso_set_sym unfolding is_ring_iso_def by auto 
   886 
   887 lemma (in ring_hom_ring) the_elem_simp [simp]:
   888   "\<And>x. x \<in> carrier R \<Longrightarrow> the_elem (h ` ((a_kernel R S h) +> x)) = h x"
   889 proof -
   890   fix x assume x: "x \<in> carrier R"
   891   hence "h x \<in> h ` ((a_kernel R S h) +> x)"
   892     using homeq_imp_rcos by blast
   893   thus "the_elem (h ` ((a_kernel R S h) +> x)) = h x"
   894     by (metis (no_types, lifting) x empty_iff homeq_imp_rcos rcos_imp_homeq the_elem_image_unique)
   895 qed
   896 
   897 lemma (in ring_hom_ring) the_elem_inj:
   898   "\<And>X Y. \<lbrakk> X \<in> carrier (R Quot (a_kernel R S h)); Y \<in> carrier (R Quot (a_kernel R S h)) \<rbrakk> \<Longrightarrow>
   899            the_elem (h ` X) = the_elem (h ` Y) \<Longrightarrow> X = Y"
   900 proof -
   901   fix X Y
   902   assume "X \<in> carrier (R Quot (a_kernel R S h))"
   903      and "Y \<in> carrier (R Quot (a_kernel R S h))"
   904      and Eq: "the_elem (h ` X) = the_elem (h ` Y)"
   905   then obtain x y where x: "x \<in> carrier R" "X = (a_kernel R S h) +> x"
   906                     and y: "y \<in> carrier R" "Y = (a_kernel R S h) +> y"
   907     unfolding FactRing_def A_RCOSETS_def' by auto
   908   hence "h x = h y" using Eq by simp
   909   hence "x \<ominus> y \<in> (a_kernel R S h)"
   910     by (simp add: a_minus_def abelian_subgroup.a_rcos_module_imp
   911                   abelian_subgroup_a_kernel homeq_imp_rcos x(1) y(1))
   912   thus "X = Y"
   913     by (metis R.a_coset_add_inv1 R.minus_eq abelian_subgroup.a_rcos_const
   914         abelian_subgroup_a_kernel additive_subgroup.a_subset additive_subgroup_a_kernel x y)
   915 qed
   916 
   917 lemma (in ring_hom_ring) quot_mem:
   918   "\<And>X. X \<in> carrier (R Quot (a_kernel R S h)) \<Longrightarrow> \<exists>x \<in> carrier R. X = (a_kernel R S h) +> x"
   919 proof -
   920   fix X assume "X \<in> carrier (R Quot (a_kernel R S h))"
   921   thus "\<exists>x \<in> carrier R. X = (a_kernel R S h) +> x"
   922     unfolding FactRing_def RCOSETS_def A_RCOSETS_def by (simp add: a_r_coset_def)
   923 qed
   924 
   925 lemma (in ring_hom_ring) the_elem_wf:
   926   "\<And>X. X \<in> carrier (R Quot (a_kernel R S h)) \<Longrightarrow> \<exists>y \<in> carrier S. (h ` X) = { y }"
   927 proof -
   928   fix X assume "X \<in> carrier (R Quot (a_kernel R S h))"
   929   then obtain x where x: "x \<in> carrier R" and X: "X = (a_kernel R S h) +> x"
   930     using quot_mem by blast
   931   hence "\<And>x'. x' \<in> X \<Longrightarrow> h x' = h x"
   932   proof -
   933     fix x' assume "x' \<in> X" hence "x' \<in> (a_kernel R S h) +> x" using X by simp
   934     then obtain k where k: "k \<in> a_kernel R S h" "x' = k \<oplus> x"
   935       by (metis R.add.inv_closed R.add.m_assoc R.l_neg R.r_zero
   936           abelian_subgroup.a_elemrcos_carrier
   937           abelian_subgroup.a_rcos_module_imp abelian_subgroup_a_kernel x)
   938     hence "h x' = h k \<oplus>\<^bsub>S\<^esub> h x"
   939       by (meson additive_subgroup.a_Hcarr additive_subgroup_a_kernel hom_add x)
   940     also have " ... =  h x"
   941       using k by (auto simp add: x)
   942     finally show "h x' = h x" .
   943   qed
   944   moreover have "h x \<in> h ` X"
   945     by (simp add: X homeq_imp_rcos x)
   946   ultimately have "(h ` X) = { h x }"
   947     by blast
   948   thus "\<exists>y \<in> carrier S. (h ` X) = { y }" using x by simp
   949 qed
   950 
   951 corollary (in ring_hom_ring) the_elem_wf':
   952   "\<And>X. X \<in> carrier (R Quot (a_kernel R S h)) \<Longrightarrow> \<exists>r \<in> carrier R. (h ` X) = { h r }"
   953   using the_elem_wf by (metis quot_mem the_elem_eq the_elem_simp) 
   954 
   955 lemma (in ring_hom_ring) the_elem_hom:
   956   "(\<lambda>X. the_elem (h ` X)) \<in> ring_hom (R Quot (a_kernel R S h)) S"
   957 proof (rule ring_hom_memI)
   958   show "\<And>x. x \<in> carrier (R Quot a_kernel R S h) \<Longrightarrow> the_elem (h ` x) \<in> carrier S"
   959     using the_elem_wf by fastforce
   960   
   961   show "the_elem (h ` \<one>\<^bsub>R Quot a_kernel R S h\<^esub>) = \<one>\<^bsub>S\<^esub>"
   962     unfolding FactRing_def  using the_elem_simp[of "\<one>\<^bsub>R\<^esub>"] by simp
   963 
   964   fix X Y
   965   assume "X \<in> carrier (R Quot a_kernel R S h)"
   966      and "Y \<in> carrier (R Quot a_kernel R S h)"
   967   then obtain x y where x: "x \<in> carrier R" "X = (a_kernel R S h) +> x"
   968                     and y: "y \<in> carrier R" "Y = (a_kernel R S h) +> y"
   969     using quot_mem by blast
   970 
   971   have "X \<otimes>\<^bsub>R Quot a_kernel R S h\<^esub> Y = (a_kernel R S h) +> (x \<otimes> y)"
   972     by (simp add: FactRing_def ideal.rcoset_mult_add kernel_is_ideal x y)
   973   thus "the_elem (h ` (X \<otimes>\<^bsub>R Quot a_kernel R S h\<^esub> Y)) = the_elem (h ` X) \<otimes>\<^bsub>S\<^esub> the_elem (h ` Y)"
   974     by (simp add: x y)
   975 
   976   have "X \<oplus>\<^bsub>R Quot a_kernel R S h\<^esub> Y = (a_kernel R S h) +> (x \<oplus> y)"
   977     using ideal.rcos_ring_hom kernel_is_ideal ring_hom_add x y by fastforce
   978   thus "the_elem (h ` (X \<oplus>\<^bsub>R Quot a_kernel R S h\<^esub> Y)) = the_elem (h ` X) \<oplus>\<^bsub>S\<^esub> the_elem (h ` Y)"
   979     by (simp add: x y)
   980 qed
   981 
   982 lemma (in ring_hom_ring) the_elem_surj:
   983     "(\<lambda>X. (the_elem (h ` X))) ` carrier (R Quot (a_kernel R S h)) = (h ` (carrier R))"
   984 proof
   985   show "(\<lambda>X. the_elem (h ` X)) ` carrier (R Quot a_kernel R S h) \<subseteq> h ` carrier R"
   986     using the_elem_wf' by fastforce
   987 next
   988   show "h ` carrier R \<subseteq> (\<lambda>X. the_elem (h ` X)) ` carrier (R Quot a_kernel R S h)"
   989   proof
   990     fix y assume "y \<in> h ` carrier R"
   991     then obtain x where x: "x \<in> carrier R" "h x = y"
   992       by (metis image_iff)
   993     hence "the_elem (h ` ((a_kernel R S h) +> x)) = y" by simp
   994     moreover have "(a_kernel R S h) +> x \<in> carrier (R Quot (a_kernel R S h))"
   995      unfolding FactRing_def RCOSETS_def A_RCOSETS_def by (auto simp add: x a_r_coset_def)
   996     ultimately show "y \<in> (\<lambda>X. (the_elem (h ` X))) ` carrier (R Quot (a_kernel R S h))" by blast
   997   qed
   998 qed
   999 
  1000 proposition (in ring_hom_ring) FactRing_iso_set_aux:
  1001   "(\<lambda>X. the_elem (h ` X)) \<in> ring_iso (R Quot (a_kernel R S h)) (S \<lparr> carrier := h ` (carrier R) \<rparr>)"
  1002 proof -
  1003   have "bij_betw (\<lambda>X. the_elem (h ` X)) (carrier (R Quot a_kernel R S h)) (h ` (carrier R))"
  1004     unfolding bij_betw_def inj_on_def using the_elem_surj the_elem_inj by simp
  1005 
  1006   moreover
  1007   have "(\<lambda>X. the_elem (h ` X)): carrier (R Quot (a_kernel R S h)) \<rightarrow> h ` (carrier R)"
  1008     using the_elem_wf' by fastforce
  1009   hence "(\<lambda>X. the_elem (h ` X)) \<in> ring_hom (R Quot (a_kernel R S h)) (S \<lparr> carrier := h ` (carrier R) \<rparr>)"
  1010     using the_elem_hom the_elem_wf' unfolding ring_hom_def by simp
  1011 
  1012   ultimately show ?thesis unfolding ring_iso_def using the_elem_hom by simp
  1013 qed
  1014 
  1015 theorem (in ring_hom_ring) FactRing_iso_set:
  1016   assumes "h ` carrier R = carrier S"
  1017   shows "(\<lambda>X. the_elem (h ` X)) \<in> ring_iso (R Quot (a_kernel R S h)) S"
  1018   using FactRing_iso_set_aux assms by auto
  1019 
  1020 corollary (in ring_hom_ring) FactRing_iso:
  1021   assumes "h ` carrier R = carrier S"
  1022   shows "R Quot (a_kernel R S h) \<simeq> S"
  1023   using FactRing_iso_set assms is_ring_iso_def by auto
  1024 
  1025 corollary (in ring) FactRing_zeroideal:
  1026   shows "R Quot { \<zero> } \<simeq> R" and "R \<simeq> R Quot { \<zero> }"
  1027 proof -
  1028   have "ring_hom_ring R R id"
  1029     using ring_axioms by (auto intro: ring_hom_ringI)
  1030   moreover have "a_kernel R R id = { \<zero> }"
  1031     unfolding a_kernel_def' by auto
  1032   ultimately show "R Quot { \<zero> } \<simeq> R" and "R \<simeq> R Quot { \<zero> }"
  1033     using ring_hom_ring.FactRing_iso[of R R id]
  1034           ring_iso_sym[OF ideal.quotient_is_ring[OF zeroideal], of R] by auto
  1035 qed
  1036 
  1037 lemma (in ring_hom_ring) img_is_ring: "ring (S \<lparr> carrier := h ` (carrier R) \<rparr>)"
  1038 proof -
  1039   let ?the_elem = "\<lambda>X. the_elem (h ` X)"
  1040   have FactRing_is_ring: "ring (R Quot (a_kernel R S h))"
  1041     by (simp add: ideal.quotient_is_ring kernel_is_ideal)
  1042   have "ring ((S \<lparr> carrier := ?the_elem ` (carrier (R Quot (a_kernel R S h))) \<rparr>)
  1043                  \<lparr>     one := ?the_elem \<one>\<^bsub>(R Quot (a_kernel R S h))\<^esub>,
  1044                       zero := ?the_elem \<zero>\<^bsub>(R Quot (a_kernel R S h))\<^esub> \<rparr>)"
  1045     using ring.ring_iso_imp_img_ring[OF FactRing_is_ring, of ?the_elem
  1046           "S \<lparr> carrier := ?the_elem ` (carrier (R Quot (a_kernel R S h))) \<rparr>"]
  1047           FactRing_iso_set_aux the_elem_surj by auto
  1048 
  1049   moreover
  1050   have "\<zero> \<in> (a_kernel R S h)"
  1051     using a_kernel_def'[of R S h] by auto
  1052   hence "\<one> \<in> (a_kernel R S h) +> \<one>"
  1053     using a_r_coset_def'[of R "a_kernel R S h" \<one>] by force
  1054   hence "\<one>\<^bsub>S\<^esub> \<in> (h ` ((a_kernel R S h) +> \<one>))"
  1055     using hom_one by force
  1056   hence "?the_elem \<one>\<^bsub>(R Quot (a_kernel R S h))\<^esub> = \<one>\<^bsub>S\<^esub>"
  1057     using the_elem_wf[of "(a_kernel R S h) +> \<one>"] by (simp add: FactRing_def)
  1058   
  1059   moreover
  1060   have "\<zero>\<^bsub>S\<^esub> \<in> (h ` (a_kernel R S h))"
  1061     using a_kernel_def'[of R S h] hom_zero by force
  1062   hence "\<zero>\<^bsub>S\<^esub> \<in> (h ` \<zero>\<^bsub>(R Quot (a_kernel R S h))\<^esub>)"
  1063     by (simp add: FactRing_def)
  1064   hence "?the_elem \<zero>\<^bsub>(R Quot (a_kernel R S h))\<^esub> = \<zero>\<^bsub>S\<^esub>"
  1065     using the_elem_wf[OF ring.ring_simprules(2)[OF FactRing_is_ring]]
  1066     by (metis singletonD the_elem_eq) 
  1067 
  1068   ultimately
  1069   have "ring ((S \<lparr> carrier := h ` (carrier R) \<rparr>) \<lparr> one := \<one>\<^bsub>S\<^esub>, zero := \<zero>\<^bsub>S\<^esub> \<rparr>)"
  1070     using the_elem_surj by simp
  1071   thus ?thesis
  1072     by auto
  1073 qed
  1074 
  1075 lemma (in ring_hom_ring) img_is_cring:
  1076   assumes "cring S"
  1077   shows "cring (S \<lparr> carrier := h ` (carrier R) \<rparr>)"
  1078 proof -
  1079   interpret ring "S \<lparr> carrier := h ` (carrier R) \<rparr>"
  1080     using img_is_ring .
  1081   show ?thesis
  1082     apply unfold_locales
  1083     using assms unfolding cring_def comm_monoid_def comm_monoid_axioms_def by auto
  1084 qed
  1085 
  1086 lemma (in ring_hom_ring) img_is_domain:
  1087   assumes "domain S"
  1088   shows "domain (S \<lparr> carrier := h ` (carrier R) \<rparr>)"
  1089 proof -
  1090   interpret cring "S \<lparr> carrier := h ` (carrier R) \<rparr>"
  1091     using img_is_cring assms unfolding domain_def by simp
  1092   show ?thesis
  1093     apply unfold_locales
  1094     using assms unfolding domain_def domain_axioms_def apply auto
  1095     using hom_closed by blast 
  1096 qed
  1097 
  1098 proposition (in ring_hom_ring) primeideal_vimage:
  1099   assumes "cring R"
  1100   shows "primeideal P S \<Longrightarrow> primeideal { r \<in> carrier R. h r \<in> P } R"
  1101 proof -
  1102   assume A: "primeideal P S"
  1103   hence is_ideal: "ideal P S" unfolding primeideal_def by simp
  1104   have "ring_hom_ring R (S Quot P) (((+>\<^bsub>S\<^esub>) P) \<circ> h)" (is "ring_hom_ring ?A ?B ?h")
  1105     using ring_hom_trans[OF homh, of "(+>\<^bsub>S\<^esub>) P" "S Quot P"]
  1106           ideal.rcos_ring_hom_ring[OF is_ideal] assms
  1107     unfolding ring_hom_ring_def ring_hom_ring_axioms_def cring_def by simp
  1108   then interpret hom: ring_hom_ring R "S Quot P" "((+>\<^bsub>S\<^esub>) P) \<circ> h" by simp
  1109   
  1110   have "inj_on (\<lambda>X. the_elem (?h ` X)) (carrier (R Quot (a_kernel R (S Quot P) ?h)))"
  1111     using hom.the_elem_inj unfolding inj_on_def by simp
  1112   moreover
  1113   have "ideal (a_kernel R (S Quot P) ?h) R"
  1114     using hom.kernel_is_ideal by auto
  1115   have hom': "ring_hom_ring (R Quot (a_kernel R (S Quot P) ?h)) (S Quot P) (\<lambda>X. the_elem (?h ` X))"
  1116     using hom.the_elem_hom hom.kernel_is_ideal
  1117     by (meson hom.ring_hom_ring_axioms ideal.rcos_ring_hom_ring ring_hom_ring_axioms_def ring_hom_ring_def)
  1118   
  1119   ultimately
  1120   have "primeideal (a_kernel R (S Quot P) ?h) R"
  1121     using ring_hom_ring.inj_on_domain[OF hom'] primeideal.quotient_is_domain[OF A]
  1122           cring.quot_domain_imp_primeideal[OF assms hom.kernel_is_ideal] by simp
  1123   
  1124   moreover have "a_kernel R (S Quot P) ?h = { r \<in> carrier R. h r \<in> P }"
  1125   proof
  1126     show "a_kernel R (S Quot P) ?h \<subseteq> { r \<in> carrier R. h r \<in> P }"
  1127     proof 
  1128       fix r assume "r \<in> a_kernel R (S Quot P) ?h"
  1129       hence r: "r \<in> carrier R" "P +>\<^bsub>S\<^esub> (h r) = P"
  1130         unfolding a_kernel_def kernel_def FactRing_def by auto
  1131       hence "h r \<in> P"
  1132         using S.a_rcosI R.l_zero S.l_zero additive_subgroup.a_subset[OF ideal.axioms(1)[OF is_ideal]]
  1133               additive_subgroup.zero_closed[OF ideal.axioms(1)[OF is_ideal]] hom_closed by metis
  1134       thus "r \<in> { r \<in> carrier R. h r \<in> P }" using r by simp
  1135     qed
  1136   next
  1137     show "{ r \<in> carrier R. h r \<in> P } \<subseteq> a_kernel R (S Quot P) ?h"
  1138     proof
  1139       fix r assume "r \<in> { r \<in> carrier R. h r \<in> P }"
  1140       hence r: "r \<in> carrier R" "h r \<in> P" by simp_all
  1141       hence "?h r = P"
  1142         by (simp add: S.a_coset_join2 additive_subgroup.a_subgroup ideal.axioms(1) is_ideal)
  1143       thus "r \<in> a_kernel R (S Quot P) ?h"
  1144         unfolding a_kernel_def kernel_def FactRing_def using r(1) by auto
  1145     qed
  1146   qed
  1147   ultimately show "primeideal { r \<in> carrier R. h r \<in> P } R" by simp
  1148 qed
  1149 
  1150 end