More on Algebra by Paulo and Martin
authorpaulson <lp15@cam.ac.uk>
Sat Jun 30 15:44:04 2018 +0100 (9 months ago)
changeset 68551b680e74eb6f2
parent 68550 516e81f75957
child 68552 391e89e03eef
More on Algebra by Paulo and Martin
src/HOL/Algebra/Divisibility.thy
src/HOL/Algebra/Group.thy
src/HOL/Algebra/Module.thy
src/HOL/Algebra/Multiplicative_Group.thy
src/HOL/Algebra/QuotRing.thy
src/HOL/Algebra/Ring.thy
src/HOL/Algebra/RingHom.thy
     1.1 --- a/src/HOL/Algebra/Divisibility.thy	Fri Jun 29 23:04:36 2018 +0200
     1.2 +++ b/src/HOL/Algebra/Divisibility.thy	Sat Jun 30 15:44:04 2018 +0100
     1.3 @@ -763,6 +763,27 @@
     1.4    apply (metis pp' associated_sym divides_cong_l)
     1.5    done
     1.6  
     1.7 +(*by Paulo Emílio de Vilhena*)
     1.8 +lemma (in comm_monoid_cancel) prime_irreducible:
     1.9 +  assumes "prime G p"
    1.10 +  shows "irreducible G p"
    1.11 +proof (rule irreducibleI)
    1.12 +  show "p \<notin> Units G"
    1.13 +    using assms unfolding prime_def by simp
    1.14 +next
    1.15 +  fix b assume A: "b \<in> carrier G" "properfactor G b p"
    1.16 +  then obtain c where c: "c \<in> carrier G" "p = b \<otimes> c"
    1.17 +    unfolding properfactor_def factor_def by auto
    1.18 +  hence "p divides c"
    1.19 +    using A assms unfolding prime_def properfactor_def by auto
    1.20 +  then obtain b' where b': "b' \<in> carrier G" "c = p \<otimes> b'"
    1.21 +    unfolding factor_def by auto
    1.22 +  hence "\<one> = b \<otimes> b'"
    1.23 +    by (metis A(1) l_cancel m_closed m_lcomm one_closed r_one c)
    1.24 +  thus "b \<in> Units G"
    1.25 +    using A(1) Units_one_closed b'(1) unit_factor by presburger
    1.26 +qed
    1.27 +
    1.28  
    1.29  subsection \<open>Factorization and Factorial Monoids\<close>
    1.30  
     2.1 --- a/src/HOL/Algebra/Group.thy	Fri Jun 29 23:04:36 2018 +0200
     2.2 +++ b/src/HOL/Algebra/Group.thy	Sat Jun 30 15:44:04 2018 +0100
     2.3 @@ -1438,6 +1438,9 @@
     2.4    shows "m_inv (units_of G) x = m_inv G x"
     2.5    by (simp add: assms group.inv_equality units_group units_of_carrier units_of_mult units_of_one)
     2.6  
     2.7 +lemma units_of_units [simp] : "Units (units_of G) = Units G"
     2.8 +  unfolding units_of_def Units_def by force
     2.9 +
    2.10  lemma (in group) surj_const_mult: "a \<in> carrier G \<Longrightarrow> (\<lambda>x. a \<otimes> x) ` carrier G = carrier G"
    2.11    apply (auto simp add: image_def)
    2.12    by (metis inv_closed inv_solve_left m_closed)
     3.1 --- a/src/HOL/Algebra/Module.thy	Fri Jun 29 23:04:36 2018 +0200
     3.2 +++ b/src/HOL/Algebra/Module.thy	Sat Jun 30 15:44:04 2018 +0100
     3.3 @@ -76,87 +76,95 @@
     3.4        "!!a x y. [| a \<in> carrier R; x \<in> carrier M; y \<in> carrier M |] ==>
     3.5        (a \<odot>\<^bsub>M\<^esub> x) \<otimes>\<^bsub>M\<^esub> y = a \<odot>\<^bsub>M\<^esub> (x \<otimes>\<^bsub>M\<^esub> y)"
     3.6    shows "algebra R M"
     3.7 -apply intro_locales
     3.8 -apply (rule cring.axioms ring.axioms abelian_group.axioms comm_monoid.axioms assms)+
     3.9 -apply (rule module_axioms.intro)
    3.10 - apply (simp add: smult_closed)
    3.11 - apply (simp add: smult_l_distr)
    3.12 - apply (simp add: smult_r_distr)
    3.13 - apply (simp add: smult_assoc1)
    3.14 - apply (simp add: smult_one)
    3.15 -apply (rule cring.axioms ring.axioms abelian_group.axioms comm_monoid.axioms assms)+
    3.16 -apply (rule algebra_axioms.intro)
    3.17 - apply (simp add: smult_assoc2)
    3.18 -done
    3.19 +  apply intro_locales
    3.20 +             apply (rule cring.axioms ring.axioms abelian_group.axioms comm_monoid.axioms assms)+
    3.21 +      apply (rule module_axioms.intro)
    3.22 +          apply (simp add: smult_closed)
    3.23 +         apply (simp add: smult_l_distr)
    3.24 +        apply (simp add: smult_r_distr)
    3.25 +       apply (simp add: smult_assoc1)
    3.26 +      apply (simp add: smult_one)
    3.27 +     apply (rule cring.axioms ring.axioms abelian_group.axioms comm_monoid.axioms assms)+
    3.28 +  apply (rule algebra_axioms.intro)
    3.29 +  apply (simp add: smult_assoc2)
    3.30 +  done
    3.31  
    3.32 -lemma (in algebra) R_cring:
    3.33 -  "cring R"
    3.34 -  ..
    3.35 +lemma (in algebra) R_cring: "cring R" ..
    3.36  
    3.37 -lemma (in algebra) M_cring:
    3.38 -  "cring M"
    3.39 -  ..
    3.40 +lemma (in algebra) M_cring: "cring M" ..
    3.41  
    3.42 -lemma (in algebra) module:
    3.43 -  "module R M"
    3.44 -  by (auto intro: moduleI R_cring is_abelian_group
    3.45 -    smult_l_distr smult_r_distr smult_assoc1)
    3.46 +lemma (in algebra) module: "module R M"
    3.47 +  by (auto intro: moduleI R_cring is_abelian_group smult_l_distr smult_r_distr smult_assoc1)
    3.48  
    3.49  
    3.50 -subsection \<open>Basic Properties of Algebras\<close>
    3.51 +subsection \<open>Basic Properties of Modules\<close>
    3.52  
    3.53 -lemma (in algebra) smult_l_null [simp]:
    3.54 -  "x \<in> carrier M ==> \<zero> \<odot>\<^bsub>M\<^esub> x = \<zero>\<^bsub>M\<^esub>"
    3.55 -proof -
    3.56 -  assume M: "x \<in> carrier M"
    3.57 +lemma (in module) smult_l_null [simp]:
    3.58 + "x \<in> carrier M ==> \<zero> \<odot>\<^bsub>M\<^esub> x = \<zero>\<^bsub>M\<^esub>"
    3.59 +proof-
    3.60 +  assume M : "x \<in> carrier M"
    3.61    note facts = M smult_closed [OF R.zero_closed]
    3.62 -  from facts have "\<zero> \<odot>\<^bsub>M\<^esub> x = (\<zero> \<odot>\<^bsub>M\<^esub> x \<oplus>\<^bsub>M\<^esub> \<zero> \<odot>\<^bsub>M\<^esub> x) \<oplus>\<^bsub>M\<^esub> \<ominus>\<^bsub>M\<^esub> (\<zero> \<odot>\<^bsub>M\<^esub> x)" by algebra
    3.63 -  also from M have "... = (\<zero> \<oplus> \<zero>) \<odot>\<^bsub>M\<^esub> x \<oplus>\<^bsub>M\<^esub> \<ominus>\<^bsub>M\<^esub> (\<zero> \<odot>\<^bsub>M\<^esub> x)"
    3.64 -    by (simp add: smult_l_distr del: R.l_zero R.r_zero)
    3.65 -  also from facts have "... = \<zero>\<^bsub>M\<^esub>" apply algebra apply algebra done
    3.66 -  finally show ?thesis .
    3.67 +  from facts have "\<zero> \<odot>\<^bsub>M\<^esub> x = (\<zero> \<oplus> \<zero>) \<odot>\<^bsub>M\<^esub> x "
    3.68 +    using smult_l_distr by auto
    3.69 +  also have "... = \<zero> \<odot>\<^bsub>M\<^esub> x \<oplus>\<^bsub>M\<^esub> \<zero> \<odot>\<^bsub>M\<^esub> x"
    3.70 +    using smult_l_distr[of \<zero> \<zero> x] facts by auto
    3.71 +  finally show "\<zero> \<odot>\<^bsub>M\<^esub> x = \<zero>\<^bsub>M\<^esub>" using facts
    3.72 +    by (metis M.add.r_cancel_one')
    3.73  qed
    3.74  
    3.75 -lemma (in algebra) smult_r_null [simp]:
    3.76 +lemma (in module) smult_r_null [simp]:
    3.77    "a \<in> carrier R ==> a \<odot>\<^bsub>M\<^esub> \<zero>\<^bsub>M\<^esub> = \<zero>\<^bsub>M\<^esub>"
    3.78  proof -
    3.79    assume R: "a \<in> carrier R"
    3.80    note facts = R smult_closed
    3.81    from facts have "a \<odot>\<^bsub>M\<^esub> \<zero>\<^bsub>M\<^esub> = (a \<odot>\<^bsub>M\<^esub> \<zero>\<^bsub>M\<^esub> \<oplus>\<^bsub>M\<^esub> a \<odot>\<^bsub>M\<^esub> \<zero>\<^bsub>M\<^esub>) \<oplus>\<^bsub>M\<^esub> \<ominus>\<^bsub>M\<^esub> (a \<odot>\<^bsub>M\<^esub> \<zero>\<^bsub>M\<^esub>)"
    3.82 -    by algebra
    3.83 +    by (simp add: M.add.inv_solve_right)
    3.84    also from R have "... = a \<odot>\<^bsub>M\<^esub> (\<zero>\<^bsub>M\<^esub> \<oplus>\<^bsub>M\<^esub> \<zero>\<^bsub>M\<^esub>) \<oplus>\<^bsub>M\<^esub> \<ominus>\<^bsub>M\<^esub> (a \<odot>\<^bsub>M\<^esub> \<zero>\<^bsub>M\<^esub>)"
    3.85      by (simp add: smult_r_distr del: M.l_zero M.r_zero)
    3.86 -  also from facts have "... = \<zero>\<^bsub>M\<^esub>" by algebra
    3.87 +  also from facts have "... = \<zero>\<^bsub>M\<^esub>"
    3.88 +    by (simp add: M.r_neg)
    3.89    finally show ?thesis .
    3.90  qed
    3.91  
    3.92 -lemma (in algebra) smult_l_minus:
    3.93 -  "[| a \<in> carrier R; x \<in> carrier M |] ==> (\<ominus>a) \<odot>\<^bsub>M\<^esub> x = \<ominus>\<^bsub>M\<^esub> (a \<odot>\<^bsub>M\<^esub> x)"
    3.94 -proof -
    3.95 +lemma (in module) smult_l_minus:
    3.96 +"\<lbrakk> a \<in> carrier R; x \<in> carrier M \<rbrakk> \<Longrightarrow> (\<ominus>a) \<odot>\<^bsub>M\<^esub> x = \<ominus>\<^bsub>M\<^esub> (a \<odot>\<^bsub>M\<^esub> x)"
    3.97 +proof-
    3.98    assume RM: "a \<in> carrier R" "x \<in> carrier M"
    3.99    from RM have a_smult: "a \<odot>\<^bsub>M\<^esub> x \<in> carrier M" by simp
   3.100    from RM have ma_smult: "\<ominus>a \<odot>\<^bsub>M\<^esub> x \<in> carrier M" by simp
   3.101    note facts = RM a_smult ma_smult
   3.102    from facts have "(\<ominus>a) \<odot>\<^bsub>M\<^esub> x = (\<ominus>a \<odot>\<^bsub>M\<^esub> x \<oplus>\<^bsub>M\<^esub> a \<odot>\<^bsub>M\<^esub> x) \<oplus>\<^bsub>M\<^esub> \<ominus>\<^bsub>M\<^esub>(a \<odot>\<^bsub>M\<^esub> x)"
   3.103 -    by algebra
   3.104 +    by (simp add: M.add.inv_solve_right)
   3.105    also from RM have "... = (\<ominus>a \<oplus> a) \<odot>\<^bsub>M\<^esub> x \<oplus>\<^bsub>M\<^esub> \<ominus>\<^bsub>M\<^esub>(a \<odot>\<^bsub>M\<^esub> x)"
   3.106      by (simp add: smult_l_distr)
   3.107    also from facts smult_l_null have "... = \<ominus>\<^bsub>M\<^esub>(a \<odot>\<^bsub>M\<^esub> x)"
   3.108 -    apply algebra apply algebra done
   3.109 +    by (simp add: R.l_neg)
   3.110    finally show ?thesis .
   3.111  qed
   3.112  
   3.113 -lemma (in algebra) smult_r_minus:
   3.114 +lemma (in module) smult_r_minus:
   3.115    "[| a \<in> carrier R; x \<in> carrier M |] ==> a \<odot>\<^bsub>M\<^esub> (\<ominus>\<^bsub>M\<^esub>x) = \<ominus>\<^bsub>M\<^esub> (a \<odot>\<^bsub>M\<^esub> x)"
   3.116  proof -
   3.117    assume RM: "a \<in> carrier R" "x \<in> carrier M"
   3.118    note facts = RM smult_closed
   3.119    from facts have "a \<odot>\<^bsub>M\<^esub> (\<ominus>\<^bsub>M\<^esub>x) = (a \<odot>\<^bsub>M\<^esub> \<ominus>\<^bsub>M\<^esub>x \<oplus>\<^bsub>M\<^esub> a \<odot>\<^bsub>M\<^esub> x) \<oplus>\<^bsub>M\<^esub> \<ominus>\<^bsub>M\<^esub>(a \<odot>\<^bsub>M\<^esub> x)"
   3.120 -    by algebra
   3.121 +    by (simp add: M.add.inv_solve_right)
   3.122    also from RM have "... = a \<odot>\<^bsub>M\<^esub> (\<ominus>\<^bsub>M\<^esub>x \<oplus>\<^bsub>M\<^esub> x) \<oplus>\<^bsub>M\<^esub> \<ominus>\<^bsub>M\<^esub>(a \<odot>\<^bsub>M\<^esub> x)"
   3.123      by (simp add: smult_r_distr)
   3.124 -  also from facts smult_r_null have "... = \<ominus>\<^bsub>M\<^esub>(a \<odot>\<^bsub>M\<^esub> x)" by algebra
   3.125 +  also from facts smult_l_null have "... = \<ominus>\<^bsub>M\<^esub>(a \<odot>\<^bsub>M\<^esub> x)"
   3.126 +    by (metis M.add.inv_closed M.add.inv_solve_right M.l_neg R.zero_closed r_null smult_assoc1)
   3.127    finally show ?thesis .
   3.128  qed
   3.129  
   3.130 +lemma (in module) finsum_smult_ldistr:
   3.131 +  "\<lbrakk> finite A; a \<in> carrier R; f: A \<rightarrow> carrier M \<rbrakk> \<Longrightarrow>
   3.132 +     a \<odot>\<^bsub>M\<^esub> (\<Oplus>\<^bsub>M\<^esub> i \<in> A. (f i)) = (\<Oplus>\<^bsub>M\<^esub> i \<in> A. ( a \<odot>\<^bsub>M\<^esub> (f i)))"
   3.133 +proof (induct set: finite)
   3.134 +  case empty then show ?case
   3.135 +    by (metis M.finsum_empty M.zero_closed R.zero_closed r_null smult_assoc1 smult_l_null)
   3.136 +next
   3.137 +  case (insert x F) then show ?case
   3.138 +    by (simp add: Pi_def smult_r_distr)
   3.139 +qed
   3.140 +
   3.141  end
     4.1 --- a/src/HOL/Algebra/Multiplicative_Group.thy	Fri Jun 29 23:04:36 2018 +0200
     4.2 +++ b/src/HOL/Algebra/Multiplicative_Group.thy	Sat Jun 30 15:44:04 2018 +0100
     4.3 @@ -590,7 +590,11 @@
     4.4  
     4.5  lemmas mult_of_simps = carrier_mult_of mult_mult_of nat_pow_mult_of one_mult_of
     4.6  
     4.7 -context field begin
     4.8 +context field 
     4.9 +begin
    4.10 +
    4.11 +lemma mult_of_is_Units: "mult_of R = units_of R" 
    4.12 +  unfolding mult_of_def units_of_def using field_Units by auto
    4.13  
    4.14  lemma field_mult_group :
    4.15    shows "group (mult_of R)"
     5.1 --- a/src/HOL/Algebra/QuotRing.thy	Fri Jun 29 23:04:36 2018 +0200
     5.2 +++ b/src/HOL/Algebra/QuotRing.thy	Sat Jun 30 15:44:04 2018 +0100
     5.3 @@ -1,5 +1,7 @@
     5.4  (*  Title:      HOL/Algebra/QuotRing.thy
     5.5      Author:     Stephan Hohe
     5.6 +    Author:     Paulo Emílio de Vilhena
     5.7 +
     5.8  *)
     5.9  
    5.10  theory QuotRing
    5.11 @@ -306,4 +308,831 @@
    5.12    qed
    5.13  qed
    5.14  
    5.15 +
    5.16 +lemma (in ring_hom_ring) trivial_hom_iff:
    5.17 +  "(h ` (carrier R) = { \<zero>\<^bsub>S\<^esub> }) = (a_kernel R S h = carrier R)"
    5.18 +  using group_hom.trivial_hom_iff[OF a_group_hom] by (simp add: a_kernel_def)
    5.19 +
    5.20 +lemma (in ring_hom_ring) trivial_ker_imp_inj:
    5.21 +  assumes "a_kernel R S h = { \<zero> }"
    5.22 +  shows "inj_on h (carrier R)"
    5.23 +  using group_hom.trivial_ker_imp_inj[OF a_group_hom] assms a_kernel_def[of R S h] by simp 
    5.24 +
    5.25 +lemma (in ring_hom_ring) non_trivial_field_hom_imp_inj:
    5.26 +  assumes "field R"
    5.27 +  shows "h ` (carrier R) \<noteq> { \<zero>\<^bsub>S\<^esub> } \<Longrightarrow> inj_on h (carrier R)"
    5.28 +proof -
    5.29 +  assume "h ` (carrier R) \<noteq> { \<zero>\<^bsub>S\<^esub> }"
    5.30 +  hence "a_kernel R S h \<noteq> carrier R"
    5.31 +    using trivial_hom_iff by linarith
    5.32 +  hence "a_kernel R S h = { \<zero> }"
    5.33 +    using field.all_ideals[OF assms] kernel_is_ideal by blast
    5.34 +  thus "inj_on h (carrier R)"
    5.35 +    using trivial_ker_imp_inj by blast
    5.36 +qed
    5.37 +
    5.38 +lemma (in ring_hom_ring) img_is_add_subgroup:
    5.39 +  assumes "subgroup H (add_monoid R)"
    5.40 +  shows "subgroup (h ` H) (add_monoid S)"
    5.41 +proof -
    5.42 +  have "group ((add_monoid R) \<lparr> carrier := H \<rparr>)"
    5.43 +    using assms R.add.subgroup_imp_group by blast
    5.44 +  moreover have "H \<subseteq> carrier R" by (simp add: R.add.subgroupE(1) assms)
    5.45 +  hence "h \<in> hom ((add_monoid R) \<lparr> carrier := H \<rparr>) (add_monoid S)"
    5.46 +    unfolding hom_def by (auto simp add: subsetD)
    5.47 +  ultimately have "subgroup (h ` carrier ((add_monoid R) \<lparr> carrier := H \<rparr>)) (add_monoid S)"
    5.48 +    using group_hom.img_is_subgroup[of "(add_monoid R) \<lparr> carrier := H \<rparr>" "add_monoid S" h]
    5.49 +    using a_group_hom group_hom_axioms.intro group_hom_def by blast
    5.50 +  thus "subgroup (h ` H) (add_monoid S)" by simp
    5.51 +qed
    5.52 +
    5.53 +lemma (in ring) ring_ideal_imp_quot_ideal:
    5.54 +  assumes "ideal I R"
    5.55 +  shows "ideal J R \<Longrightarrow> ideal ((+>) I ` J) (R Quot I)"
    5.56 +proof -
    5.57 +  assume A: "ideal J R" show "ideal (((+>) I) ` J) (R Quot I)"
    5.58 +  proof (rule idealI)
    5.59 +    show "ring (R Quot I)"
    5.60 +      by (simp add: assms(1) ideal.quotient_is_ring) 
    5.61 +  next
    5.62 +    have "subgroup J (add_monoid R)"
    5.63 +      by (simp add: additive_subgroup.a_subgroup A ideal.axioms(1))
    5.64 +    moreover have "((+>) I) \<in> ring_hom R (R Quot I)"
    5.65 +      by (simp add: assms(1) ideal.rcos_ring_hom)
    5.66 +    ultimately show "subgroup ((+>) I ` J) (add_monoid (R Quot I))"
    5.67 +      using assms(1) ideal.rcos_ring_hom_ring ring_hom_ring.img_is_add_subgroup by blast
    5.68 +  next
    5.69 +    fix a x assume "a \<in> (+>) I ` J" "x \<in> carrier (R Quot I)"
    5.70 +    then obtain i j where i: "i \<in> carrier R" "x = I +> i"
    5.71 +                      and j: "j \<in> J" "a = I +> j"
    5.72 +      unfolding FactRing_def using A_RCOSETS_def'[of R I] by auto
    5.73 +    hence "a \<otimes>\<^bsub>R Quot I\<^esub> x = [mod I:] (I +> j) \<Otimes> (I +> i)"
    5.74 +      unfolding FactRing_def by simp
    5.75 +    hence "a \<otimes>\<^bsub>R Quot I\<^esub> x = I +> (j \<otimes> i)"
    5.76 +      using ideal.rcoset_mult_add[OF assms(1), of j i] i(1) j(1) A ideal.Icarr by force
    5.77 +    thus "a \<otimes>\<^bsub>R Quot I\<^esub> x \<in> (+>) I ` J"
    5.78 +      using A i(1) j(1) by (simp add: ideal.I_r_closed)
    5.79 +  
    5.80 +    have "x \<otimes>\<^bsub>R Quot I\<^esub> a = [mod I:] (I +> i) \<Otimes> (I +> j)"
    5.81 +      unfolding FactRing_def i j by simp
    5.82 +    hence "x \<otimes>\<^bsub>R Quot I\<^esub> a = I +> (i \<otimes> j)"
    5.83 +      using ideal.rcoset_mult_add[OF assms(1), of i j] i(1) j(1) A ideal.Icarr by force
    5.84 +    thus "x \<otimes>\<^bsub>R Quot I\<^esub> a \<in> (+>) I ` J"
    5.85 +      using A i(1) j(1) by (simp add: ideal.I_l_closed)
    5.86 +  qed
    5.87 +qed
    5.88 +
    5.89 +lemma (in ring_hom_ring) ideal_vimage:
    5.90 +  assumes "ideal I S"
    5.91 +  shows "ideal { r \<in> carrier R. h r \<in> I } R" (* or (carrier R) \<inter> (h -` I) *)
    5.92 +proof
    5.93 +  show "{ r \<in> carrier R. h r \<in> I } \<subseteq> carrier (add_monoid R)" by auto
    5.94 +next
    5.95 +  show "\<one>\<^bsub>add_monoid R\<^esub> \<in> { r \<in> carrier R. h r \<in> I }"
    5.96 +    by (simp add: additive_subgroup.zero_closed assms ideal.axioms(1))
    5.97 +next
    5.98 +  fix a b
    5.99 +  assume "a \<in> { r \<in> carrier R. h r \<in> I }"
   5.100 +     and "b \<in> { r \<in> carrier R. h r \<in> I }"
   5.101 +  hence a: "a \<in> carrier R" "h a \<in> I"
   5.102 +    and b: "b \<in> carrier R" "h b \<in> I" by auto
   5.103 +  hence "h (a \<oplus> b) = (h a) \<oplus>\<^bsub>S\<^esub> (h b)" using hom_add by blast
   5.104 +  moreover have "(h a) \<oplus>\<^bsub>S\<^esub> (h b) \<in> I" using a b assms
   5.105 +    by (simp add: additive_subgroup.a_closed ideal.axioms(1))
   5.106 +  ultimately show "a \<otimes>\<^bsub>add_monoid R\<^esub> b \<in> { r \<in> carrier R. h r \<in> I }"
   5.107 +    using a(1) b (1) by auto
   5.108 +
   5.109 +  have "h (\<ominus> a) = \<ominus>\<^bsub>S\<^esub> (h a)" by (simp add: a)
   5.110 +  moreover have "\<ominus>\<^bsub>S\<^esub> (h a) \<in> I"
   5.111 +    by (simp add: a(2) additive_subgroup.a_inv_closed assms ideal.axioms(1))
   5.112 +  ultimately show "inv\<^bsub>add_monoid R\<^esub> a \<in> { r \<in> carrier R. h r \<in> I }"
   5.113 +    using a by (simp add: a_inv_def)
   5.114 +next
   5.115 +  fix a r
   5.116 +  assume "a \<in> { r \<in> carrier R. h r \<in> I }" and r: "r \<in> carrier R"
   5.117 +  hence a: "a \<in> carrier R" "h a \<in> I" by auto
   5.118 +
   5.119 +  have "h a \<otimes>\<^bsub>S\<^esub> h r \<in> I"
   5.120 +    using assms a r by (simp add: ideal.I_r_closed)
   5.121 +  thus "a \<otimes> r \<in> { r \<in> carrier R. h r \<in> I }" by (simp add: a(1) r)
   5.122 +
   5.123 +  have "h r \<otimes>\<^bsub>S\<^esub> h a \<in> I"
   5.124 +    using assms a r by (simp add: ideal.I_l_closed)
   5.125 +  thus "r \<otimes> a \<in> { r \<in> carrier R. h r \<in> I }" by (simp add: a(1) r)
   5.126 +qed
   5.127 +
   5.128 +lemma (in ring) canonical_proj_vimage_in_carrier:
   5.129 +  assumes "ideal I R"
   5.130 +  shows "J \<subseteq> carrier (R Quot I) \<Longrightarrow> \<Union> J \<subseteq> carrier R"
   5.131 +proof -
   5.132 +  assume A: "J \<subseteq> carrier (R Quot I)" show "\<Union> J \<subseteq> carrier R"
   5.133 +  proof
   5.134 +    fix j assume j: "j \<in> \<Union> J"
   5.135 +    then obtain j' where j': "j' \<in> J" "j \<in> j'" by blast
   5.136 +    then obtain r where r: "r \<in> carrier R" "j' = I +> r"
   5.137 +      using A j' unfolding FactRing_def using A_RCOSETS_def'[of R I] by auto
   5.138 +    thus "j \<in> carrier R" using j' assms
   5.139 +      by (meson a_r_coset_subset_G additive_subgroup.a_subset contra_subsetD ideal.axioms(1)) 
   5.140 +  qed
   5.141 +qed
   5.142 +
   5.143 +lemma (in ring) canonical_proj_vimage_mem_iff:
   5.144 +  assumes "ideal I R" "J \<subseteq> carrier (R Quot I)"
   5.145 +  shows "\<And>a. a \<in> carrier R \<Longrightarrow> (a \<in> (\<Union> J)) = (I +> a \<in> J)"
   5.146 +proof -
   5.147 +  fix a assume a: "a \<in> carrier R" show "(a \<in> (\<Union> J)) = (I +> a \<in> J)"
   5.148 +  proof
   5.149 +    assume "a \<in> \<Union> J"
   5.150 +    then obtain j where j: "j \<in> J" "a \<in> j" by blast
   5.151 +    then obtain r where r: "r \<in> carrier R" "j = I +> r"
   5.152 +      using assms j unfolding FactRing_def using A_RCOSETS_def'[of R I] by auto
   5.153 +    hence "I +> r = I +> a"
   5.154 +      using add.repr_independence[of a I r] j r
   5.155 +      by (metis a_r_coset_def additive_subgroup.a_subgroup assms(1) ideal.axioms(1))
   5.156 +    thus "I +> a \<in> J" using r j by simp
   5.157 +  next
   5.158 +    assume "I +> a \<in> J"
   5.159 +    hence "\<zero> \<oplus> a \<in> I +> a"
   5.160 +      using additive_subgroup.zero_closed[OF ideal.axioms(1)[OF assms(1)]]
   5.161 +            a_r_coset_def'[of R I a] by blast
   5.162 +    thus "a \<in> \<Union> J" using a \<open>I +> a \<in> J\<close> by auto 
   5.163 +  qed
   5.164 +qed
   5.165 +
   5.166 +corollary (in ring) quot_ideal_imp_ring_ideal:
   5.167 +  assumes "ideal I R"
   5.168 +  shows "ideal J (R Quot I) \<Longrightarrow> ideal (\<Union> J) R"
   5.169 +proof -
   5.170 +  assume A: "ideal J (R Quot I)"
   5.171 +  have "\<Union> J = { r \<in> carrier R. I +> r \<in> J }"
   5.172 +    using canonical_proj_vimage_in_carrier[OF assms, of J]
   5.173 +          canonical_proj_vimage_mem_iff[OF assms, of J]
   5.174 +          additive_subgroup.a_subset[OF ideal.axioms(1)[OF A]] by blast
   5.175 +  thus "ideal (\<Union> J) R"
   5.176 +    using ring_hom_ring.ideal_vimage[OF ideal.rcos_ring_hom_ring[OF assms] A] by simp
   5.177 +qed
   5.178 +
   5.179 +lemma (in ring) ideal_incl_iff:
   5.180 +  assumes "ideal I R" "ideal J R"
   5.181 +  shows "(I \<subseteq> J) = (J = (\<Union> j \<in> J. I +> j))"
   5.182 +proof
   5.183 +  assume A: "J = (\<Union> j \<in> J. I +> j)" hence "I +> \<zero> \<subseteq> J"
   5.184 +    using additive_subgroup.zero_closed[OF ideal.axioms(1)[OF assms(2)]] by blast
   5.185 +  thus "I \<subseteq> J" using additive_subgroup.a_subset[OF ideal.axioms(1)[OF assms(1)]] by simp 
   5.186 +next
   5.187 +  assume A: "I \<subseteq> J" show "J = (\<Union>j\<in>J. I +> j)"
   5.188 +  proof
   5.189 +    show "J \<subseteq> (\<Union> j \<in> J. I +> j)"
   5.190 +    proof
   5.191 +      fix j assume j: "j \<in> J"
   5.192 +      have "\<zero> \<in> I" by (simp add: additive_subgroup.zero_closed assms(1) ideal.axioms(1))
   5.193 +      hence "\<zero> \<oplus> j \<in> I +> j"
   5.194 +        using a_r_coset_def'[of R I j] by blast
   5.195 +      thus "j \<in> (\<Union>j\<in>J. I +> j)"
   5.196 +        using assms(2) j additive_subgroup.a_Hcarr ideal.axioms(1) by fastforce 
   5.197 +    qed
   5.198 +  next
   5.199 +    show "(\<Union> j \<in> J. I +> j) \<subseteq> J"
   5.200 +    proof
   5.201 +      fix x assume "x \<in> (\<Union> j \<in> J. I +> j)"
   5.202 +      then obtain j where j: "j \<in> J" "x \<in> I +> j" by blast
   5.203 +      then obtain i where i: "i \<in> I" "x = i \<oplus> j"
   5.204 +        using a_r_coset_def'[of R I j] by blast
   5.205 +      thus "x \<in> J"
   5.206 +        using assms(2) j A additive_subgroup.a_closed[OF ideal.axioms(1)[OF assms(2)]] by blast
   5.207 +    qed
   5.208 +  qed
   5.209 +qed
   5.210 +
   5.211 +theorem (in ring) quot_ideal_correspondence:
   5.212 +  assumes "ideal I R"
   5.213 +  shows "bij_betw (\<lambda>J. (+>) I ` J) { J. ideal J R \<and> I \<subseteq> J } { J . ideal J (R Quot I) }"
   5.214 +proof (rule bij_betw_byWitness[where ?f' = "\<lambda>X. \<Union> X"])
   5.215 +  show "\<forall>J \<in> { J. ideal J R \<and> I \<subseteq> J }. (\<lambda>X. \<Union> X) ((+>) I ` J) = J"
   5.216 +    using assms ideal_incl_iff by blast
   5.217 +next
   5.218 +  show "(\<lambda>J. (+>) I ` J) ` { J. ideal J R \<and> I \<subseteq> J } \<subseteq> { J. ideal J (R Quot I) }"
   5.219 +    using assms ring_ideal_imp_quot_ideal by auto
   5.220 +next
   5.221 +  show "(\<lambda>X. \<Union> X) ` { J. ideal J (R Quot I) } \<subseteq> { J. ideal J R \<and> I \<subseteq> J }"
   5.222 +  proof
   5.223 +    fix J assume "J \<in> ((\<lambda>X. \<Union> X) ` { J. ideal J (R Quot I) })"
   5.224 +    then obtain J' where J': "ideal J' (R Quot I)" "J = \<Union> J'" by blast
   5.225 +    hence "ideal J R"
   5.226 +      using assms quot_ideal_imp_ring_ideal by auto
   5.227 +    moreover have "I \<in> J'"
   5.228 +      using additive_subgroup.zero_closed[OF ideal.axioms(1)[OF J'(1)]] unfolding FactRing_def by simp
   5.229 +    ultimately show "J \<in> { J. ideal J R \<and> I \<subseteq> J }" using J'(2) by auto
   5.230 +  qed
   5.231 +next
   5.232 +  show "\<forall>J' \<in> { J. ideal J (R Quot I) }. ((+>) I ` (\<Union> J')) = J'"
   5.233 +  proof
   5.234 +    fix J' assume "J' \<in> { J. ideal J (R Quot I) }"
   5.235 +    hence subset: "J' \<subseteq> carrier (R Quot I) \<and> ideal J' (R Quot I)"
   5.236 +      using additive_subgroup.a_subset ideal_def by blast
   5.237 +    hence "((+>) I ` (\<Union> J')) \<subseteq> J'"
   5.238 +      using canonical_proj_vimage_in_carrier canonical_proj_vimage_mem_iff
   5.239 +      by (meson assms contra_subsetD image_subsetI)
   5.240 +    moreover have "J' \<subseteq> ((+>) I ` (\<Union> J'))"
   5.241 +    proof
   5.242 +      fix x assume "x \<in> J'"
   5.243 +      then obtain r where r: "r \<in> carrier R" "x = I +> r"
   5.244 +        using subset unfolding FactRing_def A_RCOSETS_def'[of R I] by auto
   5.245 +      hence "r \<in> (\<Union> J')"
   5.246 +        using \<open>x \<in> J'\<close> assms canonical_proj_vimage_mem_iff subset by blast
   5.247 +      thus "x \<in> ((+>) I ` (\<Union> J'))" using r(2) by blast
   5.248 +    qed
   5.249 +    ultimately show "((+>) I ` (\<Union> J')) = J'" by blast
   5.250 +  qed
   5.251 +qed
   5.252 +
   5.253 +lemma (in cring) quot_domain_imp_primeideal:
   5.254 +  assumes "ideal P R"
   5.255 +  shows "domain (R Quot P) \<Longrightarrow> primeideal P R"
   5.256 +proof -
   5.257 +  assume A: "domain (R Quot P)" show "primeideal P R"
   5.258 +  proof (rule primeidealI)
   5.259 +    show "ideal P R" using assms .
   5.260 +    show "cring R" using is_cring .
   5.261 +  next
   5.262 +    show "carrier R \<noteq> P"
   5.263 +    proof (rule ccontr)
   5.264 +      assume "\<not> carrier R \<noteq> P" hence "carrier R = P" by simp
   5.265 +      hence "\<And>I. I \<in> carrier (R Quot P) \<Longrightarrow> I = P"
   5.266 +        unfolding FactRing_def A_RCOSETS_def' apply simp
   5.267 +        using a_coset_join2 additive_subgroup.a_subgroup assms ideal.axioms(1) by blast
   5.268 +      hence "\<one>\<^bsub>(R Quot P)\<^esub> = \<zero>\<^bsub>(R Quot P)\<^esub>"
   5.269 +        by (metis assms ideal.quotient_is_ring ring.ring_simprules(2) ring.ring_simprules(6))
   5.270 +      thus False using domain.one_not_zero[OF A] by simp
   5.271 +    qed
   5.272 +  next
   5.273 +    fix a b assume a: "a \<in> carrier R" and b: "b \<in> carrier R" and ab: "a \<otimes> b \<in> P"
   5.274 +    hence "P +> (a \<otimes> b) = \<zero>\<^bsub>(R Quot P)\<^esub>" unfolding FactRing_def
   5.275 +      by (simp add: a_coset_join2 additive_subgroup.a_subgroup assms ideal.axioms(1))
   5.276 +    moreover have "(P +> a) \<otimes>\<^bsub>(R Quot P)\<^esub> (P +> b) = P +> (a \<otimes> b)" unfolding FactRing_def
   5.277 +      using a b by (simp add: assms ideal.rcoset_mult_add)
   5.278 +    moreover have "P +> a \<in> carrier (R Quot P) \<and> P +> b \<in> carrier (R Quot P)"
   5.279 +      by (simp add: a b FactRing_def a_rcosetsI additive_subgroup.a_subset assms ideal.axioms(1))
   5.280 +    ultimately have "P +> a = \<zero>\<^bsub>(R Quot P)\<^esub> \<or> P +> b = \<zero>\<^bsub>(R Quot P)\<^esub>"
   5.281 +      using domain.integral[OF A, of "P +> a" "P +> b"] by auto
   5.282 +    thus "a \<in> P \<or> b \<in> P" unfolding FactRing_def apply simp
   5.283 +      using a b assms a_coset_join1 additive_subgroup.a_subgroup ideal.axioms(1) by blast
   5.284 +  qed
   5.285 +qed
   5.286 +
   5.287 +lemma (in cring) quot_domain_iff_primeideal:
   5.288 +  assumes "ideal P R"
   5.289 +  shows "domain (R Quot P) = primeideal P R"
   5.290 +  using quot_domain_imp_primeideal[OF assms] primeideal.quotient_is_domain[of P R] by auto
   5.291 +
   5.292 +
   5.293 +subsection \<open>Isomorphism\<close>
   5.294 +
   5.295 +definition
   5.296 +  ring_iso :: "_ \<Rightarrow> _ \<Rightarrow> ('a \<Rightarrow> 'b) set"
   5.297 +  where "ring_iso R S = { h. h \<in> ring_hom R S \<and> bij_betw h (carrier R) (carrier S) }"
   5.298 +
   5.299 +definition
   5.300 +  is_ring_iso :: "_ \<Rightarrow> _ \<Rightarrow> bool" (infixr "\<simeq>" 60)
   5.301 +  where "R \<simeq> S = (ring_iso R S \<noteq> {})"
   5.302 +
   5.303 +definition
   5.304 +  morphic_prop :: "_ \<Rightarrow> ('a \<Rightarrow> bool) \<Rightarrow> bool"
   5.305 +  where "morphic_prop R P =
   5.306 +           ((P \<one>\<^bsub>R\<^esub>) \<and>
   5.307 +            (\<forall>r \<in> carrier R. P r) \<and>
   5.308 +            (\<forall>r1 \<in> carrier R. \<forall>r2 \<in> carrier R. P (r1 \<otimes>\<^bsub>R\<^esub> r2)) \<and>
   5.309 +            (\<forall>r1 \<in> carrier R. \<forall>r2 \<in> carrier R. P (r1 \<oplus>\<^bsub>R\<^esub> r2)))"
   5.310 +
   5.311 +lemma ring_iso_memI:
   5.312 +  fixes R (structure) and S (structure)
   5.313 +  assumes "\<And>x. x \<in> carrier R \<Longrightarrow> h x \<in> carrier S"
   5.314 +      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"
   5.315 +      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"
   5.316 +      and "h \<one> = \<one>\<^bsub>S\<^esub>"
   5.317 +      and "bij_betw h (carrier R) (carrier S)"
   5.318 +  shows "h \<in> ring_iso R S"
   5.319 +  by (auto simp add: ring_hom_memI assms ring_iso_def)
   5.320 +
   5.321 +lemma ring_iso_memE:
   5.322 +  fixes R (structure) and S (structure)
   5.323 +  assumes "h \<in> ring_iso R S"
   5.324 +  shows "\<And>x. x \<in> carrier R \<Longrightarrow> h x \<in> carrier S"
   5.325 +   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"
   5.326 +   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"
   5.327 +   and "h \<one> = \<one>\<^bsub>S\<^esub>"
   5.328 +   and "bij_betw h (carrier R) (carrier S)"
   5.329 +  using assms unfolding ring_iso_def ring_hom_def by auto
   5.330 +
   5.331 +lemma morphic_propI:
   5.332 +  fixes R (structure)
   5.333 +  assumes "P \<one>"
   5.334 +    and "\<And>r. r \<in> carrier R \<Longrightarrow> P r"
   5.335 +    and "\<And>r1 r2. \<lbrakk> r1 \<in> carrier R; r2 \<in> carrier R \<rbrakk> \<Longrightarrow> P (r1 \<otimes> r2)"
   5.336 +    and "\<And>r1 r2. \<lbrakk> r1 \<in> carrier R; r2 \<in> carrier R \<rbrakk> \<Longrightarrow> P (r1 \<oplus> r2)"
   5.337 +  shows "morphic_prop R P"
   5.338 +  unfolding morphic_prop_def using assms by auto
   5.339 +
   5.340 +lemma morphic_propE:
   5.341 +  fixes R (structure)
   5.342 +  assumes "morphic_prop R P"
   5.343 +  shows "P \<one>"
   5.344 +    and "\<And>r. r \<in> carrier R \<Longrightarrow> P r"
   5.345 +    and "\<And>r1 r2. \<lbrakk> r1 \<in> carrier R; r2 \<in> carrier R \<rbrakk> \<Longrightarrow> P (r1 \<otimes> r2)"
   5.346 +    and "\<And>r1 r2. \<lbrakk> r1 \<in> carrier R; r2 \<in> carrier R \<rbrakk> \<Longrightarrow> P (r1 \<oplus> r2)"
   5.347 +  using assms unfolding morphic_prop_def by auto
   5.348 +
   5.349 +lemma ring_iso_restrict:
   5.350 +  assumes "f \<in> ring_iso R S"
   5.351 +    and "\<And>r. r \<in> carrier R \<Longrightarrow> f r = g r"
   5.352 +    and "ring R"
   5.353 +  shows "g \<in> ring_iso R S"
   5.354 +proof (rule ring_iso_memI)
   5.355 +  show "bij_betw g (carrier R) (carrier S)"
   5.356 +    using assms(1-2) bij_betw_cong ring_iso_memE(5) by blast
   5.357 +  show "g \<one>\<^bsub>R\<^esub> = \<one>\<^bsub>S\<^esub>"
   5.358 +    using assms ring.ring_simprules(6) ring_iso_memE(4) by force
   5.359 +next
   5.360 +  fix x y assume x: "x \<in> carrier R" and y: "y \<in> carrier R"
   5.361 +  show "g x \<in> carrier S"
   5.362 +    using assms(1-2) ring_iso_memE(1) x by fastforce
   5.363 +  show "g (x \<otimes>\<^bsub>R\<^esub> y) = g x \<otimes>\<^bsub>S\<^esub> g y"
   5.364 +    by (metis assms ring.ring_simprules(5) ring_iso_memE(2) x y)
   5.365 +  show "g (x \<oplus>\<^bsub>R\<^esub> y) = g x \<oplus>\<^bsub>S\<^esub> g y"
   5.366 +    by (metis assms ring.ring_simprules(1) ring_iso_memE(3) x y)
   5.367 +qed
   5.368 +
   5.369 +lemma ring_iso_morphic_prop:
   5.370 +  assumes "f \<in> ring_iso R S"
   5.371 +    and "morphic_prop R P"
   5.372 +    and "\<And>r. P r \<Longrightarrow> f r = g r"
   5.373 +  shows "g \<in> ring_iso R S"
   5.374 +proof -
   5.375 +  have eq0: "\<And>r. r \<in> carrier R \<Longrightarrow> f r = g r"
   5.376 +   and eq1: "f \<one>\<^bsub>R\<^esub> = g \<one>\<^bsub>R\<^esub>"
   5.377 +   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)"
   5.378 +   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)"
   5.379 +    using assms(2-3) unfolding morphic_prop_def by auto
   5.380 +  show ?thesis
   5.381 +    apply (rule ring_iso_memI)
   5.382 +    using assms(1) eq0 ring_iso_memE(1) apply fastforce
   5.383 +    apply (metis assms(1) eq0 eq2 ring_iso_memE(2))
   5.384 +    apply (metis assms(1) eq0 eq3 ring_iso_memE(3))
   5.385 +    using assms(1) eq1 ring_iso_memE(4) apply fastforce
   5.386 +    using assms(1) bij_betw_cong eq0 ring_iso_memE(5) by blast
   5.387 +qed
   5.388 +
   5.389 +lemma (in ring) ring_hom_imp_img_ring:
   5.390 +  assumes "h \<in> ring_hom R S"
   5.391 +  shows "ring (S \<lparr> carrier := h ` (carrier R), one := h \<one>, zero := h \<zero> \<rparr>)" (is "ring ?h_img")
   5.392 +proof -
   5.393 +  have "h \<in> hom (add_monoid R) (add_monoid S)"
   5.394 +    using assms unfolding hom_def ring_hom_def by auto
   5.395 +  hence "comm_group ((add_monoid S) \<lparr>  carrier := h ` (carrier R), one := h \<zero> \<rparr>)"
   5.396 +    using add.hom_imp_img_comm_group[of h "add_monoid S"] by simp
   5.397 +  hence comm_group: "comm_group (add_monoid ?h_img)"
   5.398 +    by (auto intro: comm_monoidI simp add: monoid.defs)
   5.399 +
   5.400 +  moreover have "h \<in> hom R S"
   5.401 +    using assms unfolding ring_hom_def hom_def by auto
   5.402 +  hence "monoid (S \<lparr>  carrier := h ` (carrier R), one := h \<one> \<rparr>)"
   5.403 +    using hom_imp_img_monoid[of h S] by simp
   5.404 +  hence monoid: "monoid ?h_img"
   5.405 +    unfolding monoid_def by (simp add: monoid.defs)
   5.406 +
   5.407 +  show ?thesis
   5.408 +  proof (rule ringI, simp_all add: comm_group_abelian_groupI[OF comm_group] monoid)
   5.409 +    fix x y z assume "x \<in> h ` carrier R" "y \<in> h ` carrier R" "z \<in> h ` carrier R"
   5.410 +    then obtain r1 r2 r3
   5.411 +      where r1: "r1 \<in> carrier R" "x = h r1"
   5.412 +        and r2: "r2 \<in> carrier R" "y = h r2"
   5.413 +        and r3: "r3 \<in> carrier R" "z = h r3" by blast
   5.414 +    hence "(x \<oplus>\<^bsub>S\<^esub> y) \<otimes>\<^bsub>S\<^esub> z = h ((r1 \<oplus> r2) \<otimes> r3)"
   5.415 +      using ring_hom_memE[OF assms] by auto
   5.416 +    also have " ... = h ((r1 \<otimes> r3) \<oplus> (r2 \<otimes> r3))"
   5.417 +      using l_distr[OF r1(1) r2(1) r3(1)] by simp
   5.418 +    also have " ... = (x \<otimes>\<^bsub>S\<^esub> z) \<oplus>\<^bsub>S\<^esub> (y \<otimes>\<^bsub>S\<^esub> z)"
   5.419 +      using ring_hom_memE[OF assms] r1 r2 r3 by auto
   5.420 +    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)" .
   5.421 +
   5.422 +    have "z \<otimes>\<^bsub>S\<^esub> (x \<oplus>\<^bsub>S\<^esub> y) = h (r3 \<otimes> (r1 \<oplus> r2))"
   5.423 +      using ring_hom_memE[OF assms] r1 r2 r3 by auto
   5.424 +    also have " ... =  h ((r3 \<otimes> r1) \<oplus> (r3 \<otimes> r2))"
   5.425 +      using r_distr[OF r1(1) r2(1) r3(1)] by simp
   5.426 +    also have " ... = (z \<otimes>\<^bsub>S\<^esub> x) \<oplus>\<^bsub>S\<^esub> (z \<otimes>\<^bsub>S\<^esub> y)"
   5.427 +      using ring_hom_memE[OF assms] r1 r2 r3 by auto
   5.428 +    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)" .
   5.429 +  qed
   5.430 +qed
   5.431 +
   5.432 +lemma (in ring) ring_iso_imp_img_ring:
   5.433 +  assumes "h \<in> ring_iso R S"
   5.434 +  shows "ring (S \<lparr> one := h \<one>, zero := h \<zero> \<rparr>)"
   5.435 +proof -
   5.436 +  have "ring (S \<lparr> carrier := h ` (carrier R), one := h \<one>, zero := h \<zero> \<rparr>)"
   5.437 +    using ring_hom_imp_img_ring[of h S] assms unfolding ring_iso_def by auto
   5.438 +  moreover have "h ` (carrier R) = carrier S"
   5.439 +    using assms unfolding ring_iso_def bij_betw_def by auto
   5.440 +  ultimately show ?thesis by simp
   5.441 +qed
   5.442 +
   5.443 +lemma (in cring) ring_iso_imp_img_cring:
   5.444 +  assumes "h \<in> ring_iso R S"
   5.445 +  shows "cring (S \<lparr> one := h \<one>, zero := h \<zero> \<rparr>)" (is "cring ?h_img")
   5.446 +proof -
   5.447 +  note m_comm
   5.448 +  interpret h_img?: ring ?h_img
   5.449 +    using ring_iso_imp_img_ring[OF assms] .
   5.450 +  show ?thesis 
   5.451 +  proof (unfold_locales)
   5.452 +    fix x y assume "x \<in> carrier ?h_img" "y \<in> carrier ?h_img"
   5.453 +    then obtain r1 r2
   5.454 +      where r1: "r1 \<in> carrier R" "x = h r1"
   5.455 +        and r2: "r2 \<in> carrier R" "y = h r2"
   5.456 +      using assms image_iff[where ?f = h and ?A = "carrier R"]
   5.457 +      unfolding ring_iso_def bij_betw_def by auto
   5.458 +    have "x \<otimes>\<^bsub>(?h_img)\<^esub> y = h (r1 \<otimes> r2)"
   5.459 +      using assms r1 r2 unfolding ring_iso_def ring_hom_def by auto
   5.460 +    also have " ... = h (r2 \<otimes> r1)"
   5.461 +      using m_comm[OF r1(1) r2(1)] by simp
   5.462 +    also have " ... = y \<otimes>\<^bsub>(?h_img)\<^esub> x"
   5.463 +      using assms r1 r2 unfolding ring_iso_def ring_hom_def by auto
   5.464 +    finally show "x \<otimes>\<^bsub>(?h_img)\<^esub> y = y \<otimes>\<^bsub>(?h_img)\<^esub> x" .
   5.465 +  qed
   5.466 +qed
   5.467 +
   5.468 +lemma (in domain) ring_iso_imp_img_domain:
   5.469 +  assumes "h \<in> ring_iso R S"
   5.470 +  shows "domain (S \<lparr> one := h \<one>, zero := h \<zero> \<rparr>)" (is "domain ?h_img")
   5.471 +proof -
   5.472 +  note aux = m_closed integral one_not_zero one_closed zero_closed
   5.473 +  interpret h_img?: cring ?h_img
   5.474 +    using ring_iso_imp_img_cring[OF assms] .
   5.475 +  show ?thesis 
   5.476 +  proof (unfold_locales)
   5.477 +    show "\<one>\<^bsub>?h_img\<^esub> \<noteq> \<zero>\<^bsub>?h_img\<^esub>"
   5.478 +      using ring_iso_memE(5)[OF assms] aux(3-4)
   5.479 +      unfolding bij_betw_def inj_on_def by force
   5.480 +  next
   5.481 +    fix a b
   5.482 +    assume A: "a \<otimes>\<^bsub>?h_img\<^esub> b = \<zero>\<^bsub>?h_img\<^esub>" "a \<in> carrier ?h_img" "b \<in> carrier ?h_img"
   5.483 +    then obtain r1 r2
   5.484 +      where r1: "r1 \<in> carrier R" "a = h r1"
   5.485 +        and r2: "r2 \<in> carrier R" "b = h r2"
   5.486 +      using assms image_iff[where ?f = h and ?A = "carrier R"]
   5.487 +      unfolding ring_iso_def bij_betw_def by auto
   5.488 +    hence "a \<otimes>\<^bsub>?h_img\<^esub> b = h (r1 \<otimes> r2)"
   5.489 +      using assms r1 r2 unfolding ring_iso_def ring_hom_def by auto
   5.490 +    hence "h (r1 \<otimes> r2) = h \<zero>"
   5.491 +      using A(1) by simp
   5.492 +    hence "r1 \<otimes> r2 = \<zero>"
   5.493 +      using ring_iso_memE(5)[OF assms] aux(1)[OF r1(1) r2(1)] aux(5)
   5.494 +      unfolding bij_betw_def inj_on_def by force
   5.495 +    hence "r1 = \<zero> \<or> r2 = \<zero>"
   5.496 +      using aux(2)[OF _ r1(1) r2(1)] by simp
   5.497 +    thus "a = \<zero>\<^bsub>?h_img\<^esub> \<or> b = \<zero>\<^bsub>?h_img\<^esub>"
   5.498 +      unfolding r1 r2 by auto
   5.499 +  qed
   5.500 +qed
   5.501 +
   5.502 +lemma (in field) ring_iso_imp_img_field:
   5.503 +  assumes "h \<in> ring_iso R S"
   5.504 +  shows "field (S \<lparr> one := h \<one>, zero := h \<zero> \<rparr>)" (is "field ?h_img")
   5.505 +proof -
   5.506 +  interpret h_img?: domain ?h_img
   5.507 +    using ring_iso_imp_img_domain[OF assms] .
   5.508 +  show ?thesis
   5.509 +  proof (unfold_locales, auto simp add: Units_def)
   5.510 +    interpret field R using field_axioms .
   5.511 +    fix a assume a: "a \<in> carrier S" "a \<otimes>\<^bsub>S\<^esub> h \<zero> = h \<one>"
   5.512 +    then obtain r where r: "r \<in> carrier R" "a = h r"
   5.513 +      using assms image_iff[where ?f = h and ?A = "carrier R"]
   5.514 +      unfolding ring_iso_def bij_betw_def by auto
   5.515 +    have "a \<otimes>\<^bsub>S\<^esub> h \<zero> = h (r \<otimes> \<zero>)" unfolding r(2)
   5.516 +      using ring_iso_memE(2)[OF assms r(1)] by simp
   5.517 +    hence "h \<one> = h \<zero>"
   5.518 +      using r(1) a(2) by simp
   5.519 +    thus False
   5.520 +      using ring_iso_memE(5)[OF assms]
   5.521 +      unfolding bij_betw_def inj_on_def by force
   5.522 +  next
   5.523 +    interpret field R using field_axioms .
   5.524 +    fix s assume s: "s \<in> carrier S" "s \<noteq> h \<zero>"
   5.525 +    then obtain r where r: "r \<in> carrier R" "s = h r"
   5.526 +      using assms image_iff[where ?f = h and ?A = "carrier R"]
   5.527 +      unfolding ring_iso_def bij_betw_def by auto
   5.528 +    hence "r \<noteq> \<zero>" using s(2) by auto 
   5.529 +    hence inv_r: "inv r \<in> carrier R" "inv r \<noteq> \<zero>" "r \<otimes> inv r = \<one>" "inv r \<otimes> r = \<one>"
   5.530 +      using field_Units r(1) by auto
   5.531 +    have "h (inv r) \<otimes>\<^bsub>S\<^esub> h r = h \<one>" and "h r \<otimes>\<^bsub>S\<^esub> h (inv r) = h \<one>"
   5.532 +      using ring_iso_memE(2)[OF assms inv_r(1) r(1)] inv_r(3-4)
   5.533 +            ring_iso_memE(2)[OF assms r(1) inv_r(1)] by auto
   5.534 +    thus "\<exists>s' \<in> carrier S. s' \<otimes>\<^bsub>S\<^esub> s = h \<one> \<and> s \<otimes>\<^bsub>S\<^esub> s' = h \<one>"
   5.535 +      using ring_iso_memE(1)[OF assms inv_r(1)] r(2) by auto
   5.536 +  qed
   5.537 +qed
   5.538 +
   5.539 +lemma ring_iso_same_card: "R \<simeq> S \<Longrightarrow> card (carrier R) = card (carrier S)"
   5.540 +proof -
   5.541 +  assume "R \<simeq> S"
   5.542 +  then obtain h where "bij_betw h (carrier R) (carrier S)"
   5.543 +    unfolding is_ring_iso_def ring_iso_def by auto
   5.544 +  thus "card (carrier R) = card (carrier S)"
   5.545 +    using bij_betw_same_card[of h "carrier R" "carrier S"] by simp
   5.546 +qed
   5.547 +
   5.548 +lemma ring_iso_set_refl: "id \<in> ring_iso R R"
   5.549 +  by (rule ring_iso_memI) (auto)
   5.550 +
   5.551 +corollary ring_iso_refl: "R \<simeq> R"
   5.552 +  using is_ring_iso_def ring_iso_set_refl by auto 
   5.553 +
   5.554 +lemma ring_iso_set_trans:
   5.555 +  "\<lbrakk> f \<in> ring_iso R S; g \<in> ring_iso S Q \<rbrakk> \<Longrightarrow> (g \<circ> f) \<in> ring_iso R Q"
   5.556 +  unfolding ring_iso_def using bij_betw_trans ring_hom_trans by fastforce 
   5.557 +
   5.558 +corollary ring_iso_trans: "\<lbrakk> R \<simeq> S; S \<simeq> Q \<rbrakk> \<Longrightarrow> R \<simeq> Q"
   5.559 +  using ring_iso_set_trans unfolding is_ring_iso_def by blast 
   5.560 +
   5.561 +lemma ring_iso_set_sym:
   5.562 +  assumes "ring R"
   5.563 +  shows "h \<in> ring_iso R S \<Longrightarrow> (inv_into (carrier R) h) \<in> ring_iso S R"
   5.564 +proof -
   5.565 +  assume h: "h \<in> ring_iso R S"
   5.566 +  hence h_hom:  "h \<in> ring_hom R S"
   5.567 +    and h_surj: "h ` (carrier R) = (carrier S)"
   5.568 +    and h_inj:  "\<And> x1 x2. \<lbrakk> x1 \<in> carrier R; x2 \<in> carrier R \<rbrakk> \<Longrightarrow>  h x1 = h x2 \<Longrightarrow> x1 = x2"
   5.569 +    unfolding ring_iso_def bij_betw_def inj_on_def by auto
   5.570 +
   5.571 +  have h_inv_bij: "bij_betw (inv_into (carrier R) h) (carrier S) (carrier R)"
   5.572 +      using bij_betw_inv_into h ring_iso_def by fastforce
   5.573 +
   5.574 +  show "inv_into (carrier R) h \<in> ring_iso S R"
   5.575 +    apply (rule ring_iso_memI)
   5.576 +    apply (simp add: h_surj inv_into_into)
   5.577 +    apply (auto simp add: h_inv_bij)
   5.578 +    apply (smt assms f_inv_into_f h_hom h_inj h_surj inv_into_into
   5.579 +           ring.ring_simprules(5) ring_hom_closed ring_hom_mult)
   5.580 +    apply (smt assms f_inv_into_f h_hom h_inj h_surj inv_into_into
   5.581 +           ring.ring_simprules(1) ring_hom_add ring_hom_closed)
   5.582 +    by (metis (no_types, hide_lams) assms f_inv_into_f h_hom h_inj
   5.583 +        imageI inv_into_into ring.ring_simprules(6) ring_hom_one)
   5.584 +qed
   5.585 +
   5.586 +corollary ring_iso_sym:
   5.587 +  assumes "ring R"
   5.588 +  shows "R \<simeq> S \<Longrightarrow> S \<simeq> R"
   5.589 +  using assms ring_iso_set_sym unfolding is_ring_iso_def by auto 
   5.590 +
   5.591 +lemma (in ring_hom_ring) the_elem_simp [simp]:
   5.592 +  "\<And>x. x \<in> carrier R \<Longrightarrow> the_elem (h ` ((a_kernel R S h) +> x)) = h x"
   5.593 +proof -
   5.594 +  fix x assume x: "x \<in> carrier R"
   5.595 +  hence "h x \<in> h ` ((a_kernel R S h) +> x)"
   5.596 +    using homeq_imp_rcos by blast
   5.597 +  thus "the_elem (h ` ((a_kernel R S h) +> x)) = h x"
   5.598 +    by (metis (no_types, lifting) x empty_iff homeq_imp_rcos rcos_imp_homeq the_elem_image_unique)
   5.599 +qed
   5.600 +
   5.601 +lemma (in ring_hom_ring) the_elem_inj:
   5.602 +  "\<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>
   5.603 +           the_elem (h ` X) = the_elem (h ` Y) \<Longrightarrow> X = Y"
   5.604 +proof -
   5.605 +  fix X Y
   5.606 +  assume "X \<in> carrier (R Quot (a_kernel R S h))"
   5.607 +     and "Y \<in> carrier (R Quot (a_kernel R S h))"
   5.608 +     and Eq: "the_elem (h ` X) = the_elem (h ` Y)"
   5.609 +  then obtain x y where x: "x \<in> carrier R" "X = (a_kernel R S h) +> x"
   5.610 +                    and y: "y \<in> carrier R" "Y = (a_kernel R S h) +> y"
   5.611 +    unfolding FactRing_def A_RCOSETS_def' by auto
   5.612 +  hence "h x = h y" using Eq by simp
   5.613 +  hence "x \<ominus> y \<in> (a_kernel R S h)"
   5.614 +    by (simp add: a_minus_def abelian_subgroup.a_rcos_module_imp
   5.615 +                  abelian_subgroup_a_kernel homeq_imp_rcos x(1) y(1))
   5.616 +  thus "X = Y"
   5.617 +    by (metis R.a_coset_add_inv1 R.minus_eq abelian_subgroup.a_rcos_const
   5.618 +        abelian_subgroup_a_kernel additive_subgroup.a_subset additive_subgroup_a_kernel x y)
   5.619 +qed
   5.620 +
   5.621 +lemma (in ring_hom_ring) quot_mem:
   5.622 +  "\<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"
   5.623 +proof -
   5.624 +  fix X assume "X \<in> carrier (R Quot (a_kernel R S h))"
   5.625 +  thus "\<exists>x \<in> carrier R. X = (a_kernel R S h) +> x"
   5.626 +    unfolding FactRing_def RCOSETS_def A_RCOSETS_def by (simp add: a_r_coset_def)
   5.627 +qed
   5.628 +
   5.629 +lemma (in ring_hom_ring) the_elem_wf:
   5.630 +  "\<And>X. X \<in> carrier (R Quot (a_kernel R S h)) \<Longrightarrow> \<exists>y \<in> carrier S. (h ` X) = { y }"
   5.631 +proof -
   5.632 +  fix X assume "X \<in> carrier (R Quot (a_kernel R S h))"
   5.633 +  then obtain x where x: "x \<in> carrier R" and X: "X = (a_kernel R S h) +> x"
   5.634 +    using quot_mem by blast
   5.635 +  hence "\<And>x'. x' \<in> X \<Longrightarrow> h x' = h x"
   5.636 +  proof -
   5.637 +    fix x' assume "x' \<in> X" hence "x' \<in> (a_kernel R S h) +> x" using X by simp
   5.638 +    then obtain k where k: "k \<in> a_kernel R S h" "x' = k \<oplus> x"
   5.639 +      by (metis R.add.inv_closed R.add.m_assoc R.l_neg R.r_zero
   5.640 +          abelian_subgroup.a_elemrcos_carrier
   5.641 +          abelian_subgroup.a_rcos_module_imp abelian_subgroup_a_kernel x)
   5.642 +    hence "h x' = h k \<oplus>\<^bsub>S\<^esub> h x"
   5.643 +      by (meson additive_subgroup.a_Hcarr additive_subgroup_a_kernel hom_add x)
   5.644 +    also have " ... =  h x"
   5.645 +      using k by (auto simp add: x)
   5.646 +    finally show "h x' = h x" .
   5.647 +  qed
   5.648 +  moreover have "h x \<in> h ` X"
   5.649 +    by (simp add: X homeq_imp_rcos x)
   5.650 +  ultimately have "(h ` X) = { h x }"
   5.651 +    by blast
   5.652 +  thus "\<exists>y \<in> carrier S. (h ` X) = { y }" using x by simp
   5.653 +qed
   5.654 +
   5.655 +corollary (in ring_hom_ring) the_elem_wf':
   5.656 +  "\<And>X. X \<in> carrier (R Quot (a_kernel R S h)) \<Longrightarrow> \<exists>r \<in> carrier R. (h ` X) = { h r }"
   5.657 +  using the_elem_wf by (metis quot_mem the_elem_eq the_elem_simp) 
   5.658 +
   5.659 +lemma (in ring_hom_ring) the_elem_hom:
   5.660 +  "(\<lambda>X. the_elem (h ` X)) \<in> ring_hom (R Quot (a_kernel R S h)) S"
   5.661 +proof (rule ring_hom_memI)
   5.662 +  show "\<And>x. x \<in> carrier (R Quot a_kernel R S h) \<Longrightarrow> the_elem (h ` x) \<in> carrier S"
   5.663 +    using the_elem_wf by fastforce
   5.664 +  
   5.665 +  show "the_elem (h ` \<one>\<^bsub>R Quot a_kernel R S h\<^esub>) = \<one>\<^bsub>S\<^esub>"
   5.666 +    unfolding FactRing_def  using the_elem_simp[of "\<one>\<^bsub>R\<^esub>"] by simp
   5.667 +
   5.668 +  fix X Y
   5.669 +  assume "X \<in> carrier (R Quot a_kernel R S h)"
   5.670 +     and "Y \<in> carrier (R Quot a_kernel R S h)"
   5.671 +  then obtain x y where x: "x \<in> carrier R" "X = (a_kernel R S h) +> x"
   5.672 +                    and y: "y \<in> carrier R" "Y = (a_kernel R S h) +> y"
   5.673 +    using quot_mem by blast
   5.674 +
   5.675 +  have "X \<otimes>\<^bsub>R Quot a_kernel R S h\<^esub> Y = (a_kernel R S h) +> (x \<otimes> y)"
   5.676 +    by (simp add: FactRing_def ideal.rcoset_mult_add kernel_is_ideal x y)
   5.677 +  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)"
   5.678 +    by (simp add: x y)
   5.679 +
   5.680 +  have "X \<oplus>\<^bsub>R Quot a_kernel R S h\<^esub> Y = (a_kernel R S h) +> (x \<oplus> y)"
   5.681 +    using ideal.rcos_ring_hom kernel_is_ideal ring_hom_add x y by fastforce
   5.682 +  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)"
   5.683 +    by (simp add: x y)
   5.684 +qed
   5.685 +
   5.686 +lemma (in ring_hom_ring) the_elem_surj:
   5.687 +    "(\<lambda>X. (the_elem (h ` X))) ` carrier (R Quot (a_kernel R S h)) = (h ` (carrier R))"
   5.688 +proof
   5.689 +  show "(\<lambda>X. the_elem (h ` X)) ` carrier (R Quot a_kernel R S h) \<subseteq> h ` carrier R"
   5.690 +    using the_elem_wf' by fastforce
   5.691 +next
   5.692 +  show "h ` carrier R \<subseteq> (\<lambda>X. the_elem (h ` X)) ` carrier (R Quot a_kernel R S h)"
   5.693 +  proof
   5.694 +    fix y assume "y \<in> h ` carrier R"
   5.695 +    then obtain x where x: "x \<in> carrier R" "h x = y"
   5.696 +      by (metis image_iff)
   5.697 +    hence "the_elem (h ` ((a_kernel R S h) +> x)) = y" by simp
   5.698 +    moreover have "(a_kernel R S h) +> x \<in> carrier (R Quot (a_kernel R S h))"
   5.699 +     unfolding FactRing_def RCOSETS_def A_RCOSETS_def by (auto simp add: x a_r_coset_def)
   5.700 +    ultimately show "y \<in> (\<lambda>X. (the_elem (h ` X))) ` carrier (R Quot (a_kernel R S h))" by blast
   5.701 +  qed
   5.702 +qed
   5.703 +
   5.704 +proposition (in ring_hom_ring) FactRing_iso_set_aux:
   5.705 +  "(\<lambda>X. the_elem (h ` X)) \<in> ring_iso (R Quot (a_kernel R S h)) (S \<lparr> carrier := h ` (carrier R) \<rparr>)"
   5.706 +proof -
   5.707 +  have "bij_betw (\<lambda>X. the_elem (h ` X)) (carrier (R Quot a_kernel R S h)) (h ` (carrier R))"
   5.708 +    unfolding bij_betw_def inj_on_def using the_elem_surj the_elem_inj by simp
   5.709 +
   5.710 +  moreover
   5.711 +  have "(\<lambda>X. the_elem (h ` X)): carrier (R Quot (a_kernel R S h)) \<rightarrow> h ` (carrier R)"
   5.712 +    using the_elem_wf' by fastforce
   5.713 +  hence "(\<lambda>X. the_elem (h ` X)) \<in> ring_hom (R Quot (a_kernel R S h)) (S \<lparr> carrier := h ` (carrier R) \<rparr>)"
   5.714 +    using the_elem_hom the_elem_wf' unfolding ring_hom_def by simp
   5.715 +
   5.716 +  ultimately show ?thesis unfolding ring_iso_def using the_elem_hom by simp
   5.717 +qed
   5.718 +
   5.719 +theorem (in ring_hom_ring) FactRing_iso_set:
   5.720 +  assumes "h ` carrier R = carrier S"
   5.721 +  shows "(\<lambda>X. the_elem (h ` X)) \<in> ring_iso (R Quot (a_kernel R S h)) S"
   5.722 +  using FactRing_iso_set_aux assms by auto
   5.723 +
   5.724 +corollary (in ring_hom_ring) FactRing_iso:
   5.725 +  assumes "h ` carrier R = carrier S"
   5.726 +  shows "R Quot (a_kernel R S h) \<simeq> S"
   5.727 +  using FactRing_iso_set assms is_ring_iso_def by auto
   5.728 +
   5.729 +lemma (in ring_hom_ring) img_is_ring: "ring (S \<lparr> carrier := h ` (carrier R) \<rparr>)"
   5.730 +proof -
   5.731 +  let ?the_elem = "\<lambda>X. the_elem (h ` X)"
   5.732 +  have FactRing_is_ring: "ring (R Quot (a_kernel R S h))"
   5.733 +    by (simp add: ideal.quotient_is_ring kernel_is_ideal)
   5.734 +  have "ring ((S \<lparr> carrier := ?the_elem ` (carrier (R Quot (a_kernel R S h))) \<rparr>)
   5.735 +                 \<lparr>     one := ?the_elem \<one>\<^bsub>(R Quot (a_kernel R S h))\<^esub>,
   5.736 +                      zero := ?the_elem \<zero>\<^bsub>(R Quot (a_kernel R S h))\<^esub> \<rparr>)"
   5.737 +    using ring.ring_iso_imp_img_ring[OF FactRing_is_ring, of ?the_elem
   5.738 +          "S \<lparr> carrier := ?the_elem ` (carrier (R Quot (a_kernel R S h))) \<rparr>"]
   5.739 +          FactRing_iso_set_aux the_elem_surj by auto
   5.740 +
   5.741 +  moreover
   5.742 +  have "\<zero> \<in> (a_kernel R S h)"
   5.743 +    using a_kernel_def'[of R S h] by auto
   5.744 +  hence "\<one> \<in> (a_kernel R S h) +> \<one>"
   5.745 +    using a_r_coset_def'[of R "a_kernel R S h" \<one>] by force
   5.746 +  hence "\<one>\<^bsub>S\<^esub> \<in> (h ` ((a_kernel R S h) +> \<one>))"
   5.747 +    using hom_one by force
   5.748 +  hence "?the_elem \<one>\<^bsub>(R Quot (a_kernel R S h))\<^esub> = \<one>\<^bsub>S\<^esub>"
   5.749 +    using the_elem_wf[of "(a_kernel R S h) +> \<one>"] by (simp add: FactRing_def)
   5.750 +  
   5.751 +  moreover
   5.752 +  have "\<zero>\<^bsub>S\<^esub> \<in> (h ` (a_kernel R S h))"
   5.753 +    using a_kernel_def'[of R S h] hom_zero by force
   5.754 +  hence "\<zero>\<^bsub>S\<^esub> \<in> (h ` \<zero>\<^bsub>(R Quot (a_kernel R S h))\<^esub>)"
   5.755 +    by (simp add: FactRing_def)
   5.756 +  hence "?the_elem \<zero>\<^bsub>(R Quot (a_kernel R S h))\<^esub> = \<zero>\<^bsub>S\<^esub>"
   5.757 +    using the_elem_wf[OF ring.ring_simprules(2)[OF FactRing_is_ring]]
   5.758 +    by (metis singletonD the_elem_eq) 
   5.759 +
   5.760 +  ultimately
   5.761 +  have "ring ((S \<lparr> carrier := h ` (carrier R) \<rparr>) \<lparr> one := \<one>\<^bsub>S\<^esub>, zero := \<zero>\<^bsub>S\<^esub> \<rparr>)"
   5.762 +    using the_elem_surj by simp
   5.763 +  thus ?thesis
   5.764 +    by auto
   5.765 +qed
   5.766 +
   5.767 +lemma (in ring_hom_ring) img_is_cring:
   5.768 +  assumes "cring S"
   5.769 +  shows "cring (S \<lparr> carrier := h ` (carrier R) \<rparr>)"
   5.770 +proof -
   5.771 +  interpret ring "S \<lparr> carrier := h ` (carrier R) \<rparr>"
   5.772 +    using img_is_ring .
   5.773 +  show ?thesis
   5.774 +    apply unfold_locales
   5.775 +    using assms unfolding cring_def comm_monoid_def comm_monoid_axioms_def by auto
   5.776 +qed
   5.777 +
   5.778 +lemma (in ring_hom_ring) img_is_domain:
   5.779 +  assumes "domain S"
   5.780 +  shows "domain (S \<lparr> carrier := h ` (carrier R) \<rparr>)"
   5.781 +proof -
   5.782 +  interpret cring "S \<lparr> carrier := h ` (carrier R) \<rparr>"
   5.783 +    using img_is_cring assms unfolding domain_def by simp
   5.784 +  show ?thesis
   5.785 +    apply unfold_locales
   5.786 +    using assms unfolding domain_def domain_axioms_def apply auto
   5.787 +    using hom_closed by blast 
   5.788 +qed
   5.789 +
   5.790 +proposition (in ring_hom_ring) primeideal_vimage:
   5.791 +  assumes "cring R"
   5.792 +  shows "primeideal P S \<Longrightarrow> primeideal { r \<in> carrier R. h r \<in> P } R"
   5.793 +proof -
   5.794 +  assume A: "primeideal P S"
   5.795 +  hence is_ideal: "ideal P S" unfolding primeideal_def by simp
   5.796 +  have "ring_hom_ring R (S Quot P) (((+>\<^bsub>S\<^esub>) P) \<circ> h)" (is "ring_hom_ring ?A ?B ?h")
   5.797 +    using ring_hom_trans[OF homh, of "(+>\<^bsub>S\<^esub>) P" "S Quot P"]
   5.798 +          ideal.rcos_ring_hom_ring[OF is_ideal] assms
   5.799 +    unfolding ring_hom_ring_def ring_hom_ring_axioms_def cring_def by simp
   5.800 +  then interpret hom: ring_hom_ring R "S Quot P" "((+>\<^bsub>S\<^esub>) P) \<circ> h" by simp
   5.801 +  
   5.802 +  have "inj_on (\<lambda>X. the_elem (?h ` X)) (carrier (R Quot (a_kernel R (S Quot P) ?h)))"
   5.803 +    using hom.the_elem_inj unfolding inj_on_def by simp
   5.804 +  moreover
   5.805 +  have "ideal (a_kernel R (S Quot P) ?h) R"
   5.806 +    using hom.kernel_is_ideal by auto
   5.807 +  have hom': "ring_hom_ring (R Quot (a_kernel R (S Quot P) ?h)) (S Quot P) (\<lambda>X. the_elem (?h ` X))"
   5.808 +    using hom.the_elem_hom hom.kernel_is_ideal
   5.809 +    by (meson hom.ring_hom_ring_axioms ideal.rcos_ring_hom_ring ring_hom_ring_axioms_def ring_hom_ring_def)
   5.810 +  
   5.811 +  ultimately
   5.812 +  have "primeideal (a_kernel R (S Quot P) ?h) R"
   5.813 +    using ring_hom_ring.inj_on_domain[OF hom'] primeideal.quotient_is_domain[OF A]
   5.814 +          cring.quot_domain_imp_primeideal[OF assms hom.kernel_is_ideal] by simp
   5.815 +  
   5.816 +  moreover have "a_kernel R (S Quot P) ?h = { r \<in> carrier R. h r \<in> P }"
   5.817 +  proof
   5.818 +    show "a_kernel R (S Quot P) ?h \<subseteq> { r \<in> carrier R. h r \<in> P }"
   5.819 +    proof 
   5.820 +      fix r assume "r \<in> a_kernel R (S Quot P) ?h"
   5.821 +      hence r: "r \<in> carrier R" "P +>\<^bsub>S\<^esub> (h r) = P"
   5.822 +        unfolding a_kernel_def kernel_def FactRing_def by auto
   5.823 +      hence "h r \<in> P"
   5.824 +        using S.a_rcosI R.l_zero S.l_zero additive_subgroup.a_subset[OF ideal.axioms(1)[OF is_ideal]]
   5.825 +              additive_subgroup.zero_closed[OF ideal.axioms(1)[OF is_ideal]] hom_closed by metis
   5.826 +      thus "r \<in> { r \<in> carrier R. h r \<in> P }" using r by simp
   5.827 +    qed
   5.828 +  next
   5.829 +    show "{ r \<in> carrier R. h r \<in> P } \<subseteq> a_kernel R (S Quot P) ?h"
   5.830 +    proof
   5.831 +      fix r assume "r \<in> { r \<in> carrier R. h r \<in> P }"
   5.832 +      hence r: "r \<in> carrier R" "h r \<in> P" by simp_all
   5.833 +      hence "?h r = P"
   5.834 +        by (simp add: S.a_coset_join2 additive_subgroup.a_subgroup ideal.axioms(1) is_ideal)
   5.835 +      thus "r \<in> a_kernel R (S Quot P) ?h"
   5.836 +        unfolding a_kernel_def kernel_def FactRing_def using r(1) by auto
   5.837 +    qed
   5.838 +  qed
   5.839 +  ultimately show "primeideal { r \<in> carrier R. h r \<in> P } R" by simp
   5.840 +qed
   5.841 +
   5.842  end
     6.1 --- a/src/HOL/Algebra/Ring.thy	Fri Jun 29 23:04:36 2018 +0200
     6.2 +++ b/src/HOL/Algebra/Ring.thy	Sat Jun 30 15:44:04 2018 +0100
     6.3 @@ -333,11 +333,6 @@
     6.4      and "\<And>x y z. \<lbrakk> x \<in> carrier R; y \<in> carrier R; z \<in> carrier R \<rbrakk> \<Longrightarrow> (x \<oplus> y) \<otimes> z = x \<otimes> z \<oplus> y \<otimes> z"
     6.5    using assms cring_def apply auto by (simp add: assms cring.axioms(1) ringE(3))
     6.6  
     6.7 -(*
     6.8 -lemma (in cring) is_comm_monoid:
     6.9 -  "comm_monoid R"
    6.10 -  by (auto intro!: comm_monoidI m_assoc m_comm)
    6.11 -*)
    6.12  lemma (in cring) is_cring:
    6.13    "cring R" by (rule cring_axioms)
    6.14  
    6.15 @@ -652,6 +647,15 @@
    6.16  text \<open>Field would not need to be derived from domain, the properties
    6.17    for domain follow from the assumptions of field\<close>
    6.18  
    6.19 +lemma fieldE :
    6.20 +  fixes R (structure)
    6.21 +  assumes "field R"
    6.22 +  shows "cring R"
    6.23 +    and one_not_zero : "\<one> \<noteq> \<zero>"
    6.24 +    and integral: "\<And>a b. \<lbrakk> a \<otimes> b = \<zero>; a \<in> carrier R; b \<in> carrier R \<rbrakk> \<Longrightarrow> a = \<zero> \<or> b = \<zero>"
    6.25 +  and field_Units: "Units R = carrier R - {\<zero>}"
    6.26 +  using assms unfolding field_def field_axioms_def domain_def domain_axioms_def by simp_all
    6.27 +
    6.28  lemma (in cring) cring_fieldI:
    6.29    assumes field_Units: "Units R = carrier R - {\<zero>}"
    6.30    shows "field R"
     7.1 --- a/src/HOL/Algebra/RingHom.thy	Fri Jun 29 23:04:36 2018 +0200
     7.2 +++ b/src/HOL/Algebra/RingHom.thy	Sat Jun 30 15:44:04 2018 +0100
     7.3 @@ -203,4 +203,37 @@
     7.4        show "x \<in> a_kernel R S h +> a" by (rule homeq_imp_rcos)
     7.5  qed
     7.6  
     7.7 +(*contributed by Paulo Emílio de Vilhena*)
     7.8 +lemma (in ring_hom_ring) inj_on_domain:
     7.9 +  assumes "inj_on h (carrier R)"
    7.10 +  shows "domain S \<Longrightarrow> domain R"
    7.11 +proof -
    7.12 +  assume A: "domain S" show "domain R"
    7.13 +  proof
    7.14 +    have "h \<one> = \<one>\<^bsub>S\<^esub> \<and> h \<zero> = \<zero>\<^bsub>S\<^esub>" by simp
    7.15 +    hence "h \<one> \<noteq> h \<zero>"
    7.16 +      using domain.one_not_zero[OF A] by simp
    7.17 +    thus "\<one> \<noteq> \<zero>"
    7.18 +      using assms unfolding inj_on_def by fastforce 
    7.19 +  next
    7.20 +    fix a b
    7.21 +    assume a: "a \<in> carrier R"
    7.22 +       and b: "b \<in> carrier R"
    7.23 +    have "h (a \<otimes> b) = (h a) \<otimes>\<^bsub>S\<^esub> (h b)" by (simp add: a b)
    7.24 +    also have " ... = (h b) \<otimes>\<^bsub>S\<^esub> (h a)" using a b A cringE(1)[of S]
    7.25 +      by (simp add: cring.cring_simprules(14) domain_def)
    7.26 +    also have " ... = h (b \<otimes> a)" by (simp add: a b)
    7.27 +    finally have "h (a \<otimes> b) = h (b \<otimes> a)" .
    7.28 +    thus "a \<otimes> b = b \<otimes> a"
    7.29 +      using assms a b unfolding inj_on_def by simp 
    7.30 +    
    7.31 +    assume  ab: "a \<otimes> b = \<zero>"
    7.32 +    hence "h (a \<otimes> b) = \<zero>\<^bsub>S\<^esub>" by simp
    7.33 +    hence "(h a) \<otimes>\<^bsub>S\<^esub> (h b) = \<zero>\<^bsub>S\<^esub>" using a b by simp
    7.34 +    hence "h a =  \<zero>\<^bsub>S\<^esub> \<or> h b =  \<zero>\<^bsub>S\<^esub>" using a b domain.integral[OF A] by simp
    7.35 +    thus "a = \<zero> \<or> b = \<zero>"
    7.36 +      using a b assms unfolding inj_on_def by force
    7.37 +  qed
    7.38 +qed
    7.39 +
    7.40  end