src/HOL/Computational_Algebra/Polynomial_Factorial.thy
changeset 74362 0135a0c77b64
parent 72265 ff32ddc8165c
child 74542 d592354c4a26
equal deleted inserted replaced
74360:9e71155e3666 74362:0135a0c77b64
   355                      semiring_gcd_mult_normalize} poly"
   355                      semiring_gcd_mult_normalize} poly"
   356   assumes "fract_poly p dvd fract_poly q" "content p = 1"
   356   assumes "fract_poly p dvd fract_poly q" "content p = 1"
   357   shows   "p dvd q"
   357   shows   "p dvd q"
   358 proof -
   358 proof -
   359   from assms(1) obtain r where r: "fract_poly q = fract_poly p * r" by (erule dvdE)
   359   from assms(1) obtain r where r: "fract_poly q = fract_poly p * r" by (erule dvdE)
   360   from content_decompose_fract[of r] guess c r' . note r' = this
   360   from content_decompose_fract[of r]
       
   361   obtain c r' where r': "r = smult c (map_poly to_fract r')" "content r' = 1" .
   361   from r r' have eq: "fract_poly q = smult c (fract_poly (p * r'))" by simp  
   362   from r r' have eq: "fract_poly q = smult c (fract_poly (p * r'))" by simp  
   362   from fract_poly_smult_eqE[OF this] guess a b . note ab = this
   363   from fract_poly_smult_eqE[OF this] obtain a b
       
   364     where ab:
       
   365       "c = to_fract b / to_fract a"
       
   366       "smult a q = smult b (p * r')"
       
   367       "coprime a b"
       
   368       "normalize a = a" .
   363   have "content (smult a q) = content (smult b (p * r'))" by (simp only: ab(2))
   369   have "content (smult a q) = content (smult b (p * r'))" by (simp only: ab(2))
   364   hence eq': "normalize b = a * content q" by (simp add: assms content_mult r' ab(4))
   370   hence eq': "normalize b = a * content q" by (simp add: assms content_mult r' ab(4))
   365   have "1 = gcd a (normalize b)" by (simp add: ab)
   371   have "1 = gcd a (normalize b)" by (simp add: ab)
   366   also note eq'
   372   also note eq'
   367   also have "gcd a (a * content q) = a" by (simp add: gcd_proj1_if_dvd ab(4))
   373   also have "gcd a (a * content q) = a" by (simp add: gcd_proj1_if_dvd ab(4))
   442   assumes "degree p \<noteq> 0"
   448   assumes "degree p \<noteq> 0"
   443   shows   "irreducible p \<longleftrightarrow> irreducible (fract_poly p) \<and> content p = 1"
   449   shows   "irreducible p \<longleftrightarrow> irreducible (fract_poly p) \<and> content p = 1"
   444 proof safe
   450 proof safe
   445   assume p: "irreducible p"
   451   assume p: "irreducible p"
   446 
   452 
   447   from content_decompose[of p] guess p' . note p' = this
   453   from content_decompose[of p] obtain p' where p': "p = smult (content p) p'" "content p' = 1" .
   448   hence "p = [:content p:] * p'" by simp
   454   hence "p = [:content p:] * p'" by simp
   449   from p this have "[:content p:] dvd 1 \<or> p' dvd 1" by (rule irreducibleD)
   455   from p this have "[:content p:] dvd 1 \<or> p' dvd 1" by (rule irreducibleD)
   450   moreover have "\<not>p' dvd 1"
   456   moreover have "\<not>p' dvd 1"
   451   proof
   457   proof
   452     assume "p' dvd 1"
   458     assume "p' dvd 1"
   468       hence "degree p = 0" by (simp add: degree_map_poly)
   474       hence "degree p = 0" by (simp add: degree_map_poly)
   469       with assms show False by contradiction
   475       with assms show False by contradiction
   470    qed
   476    qed
   471  next
   477  next
   472    fix q r assume qr: "fract_poly p = q * r"
   478    fix q r assume qr: "fract_poly p = q * r"
   473    from content_decompose_fract[of q] guess cg q' . note q = this
   479    from content_decompose_fract[of q]
   474    from content_decompose_fract[of r] guess cr r' . note r = this
   480    obtain cg q' where q: "q = smult cg (map_poly to_fract q')" "content q' = 1" .
       
   481    from content_decompose_fract[of r]
       
   482    obtain cr r' where r: "r = smult cr (map_poly to_fract r')" "content r' = 1" .
   475    from qr q r p have nz: "cg \<noteq> 0" "cr \<noteq> 0" by auto
   483    from qr q r p have nz: "cg \<noteq> 0" "cr \<noteq> 0" by auto
   476    from qr have eq: "fract_poly p = smult (cr * cg) (fract_poly (q' * r'))"
   484    from qr have eq: "fract_poly p = smult (cr * cg) (fract_poly (q' * r'))"
   477      by (simp add: q r)
   485      by (simp add: q r)
   478    from fract_poly_smult_eqE[OF this] guess a b . note ab = this
   486    from fract_poly_smult_eqE[OF this] obtain a b
       
   487      where ab: "cr * cg = to_fract b / to_fract a"
       
   488        "smult a p = smult b (q' * r')" "coprime a b" "normalize a = a" .
   479    hence "content (smult a p) = content (smult b (q' * r'))" by (simp only:)
   489    hence "content (smult a p) = content (smult b (q' * r'))" by (simp only:)
   480    with ab(4) have a: "a = normalize b" by (simp add: content_mult q r)
   490    with ab(4) have a: "a = normalize b" by (simp add: content_mult q r)
   481    then have "normalize b = gcd a b"
   491    then have "normalize b = gcd a b"
   482      by simp
   492      by simp
   483    with \<open>coprime a b\<close> have "normalize b = 1"
   493    with \<open>coprime a b\<close> have "normalize b = 1"
   639   also have "[:to_fract (lead_coeff p):] * \<dots> = smult c' (fract_poly e)"
   649   also have "[:to_fract (lead_coeff p):] * \<dots> = smult c' (fract_poly e)"
   640     by (simp add: c'_def)
   650     by (simp add: c'_def)
   641   finally have eq: "fract_poly p = smult c' (fract_poly e)" .
   651   finally have eq: "fract_poly p = smult c' (fract_poly e)" .
   642   also obtain b where b: "c' = to_fract b" "is_unit b"
   652   also obtain b where b: "c' = to_fract b" "is_unit b"
   643   proof -
   653   proof -
   644     from fract_poly_smult_eqE[OF eq] guess a b . note ab = this
   654     from fract_poly_smult_eqE[OF eq]
       
   655     obtain a b where ab:
       
   656       "c' = to_fract b / to_fract a"
       
   657       "smult a p = smult b e"
       
   658       "coprime a b"
       
   659       "normalize a = a" .
   645     from ab(2) have "content (smult a p) = content (smult b e)" by (simp only: )
   660     from ab(2) have "content (smult a p) = content (smult b e)" by (simp only: )
   646     with assms content_e have "a = normalize b" by (simp add: ab(4))
   661     with assms content_e have "a = normalize b" by (simp add: ab(4))
   647     with ab have ab': "a = 1" "is_unit b"
   662     with ab have ab': "a = 1" "is_unit b"
   648       by (simp_all add: normalize_1_iff)
   663       by (simp_all add: normalize_1_iff)
   649     with ab ab' have "c' = to_fract b" by auto
   664     with ab ab' have "c' = to_fract b" by auto
   671   shows   "\<exists>A. (\<forall>p. p \<in># A \<longrightarrow> prime_elem p) \<and> normalize (prod_mset A) = normalize p"
   686   shows   "\<exists>A. (\<forall>p. p \<in># A \<longrightarrow> prime_elem p) \<and> normalize (prod_mset A) = normalize p"
   672 proof -
   687 proof -
   673   define B where "B = image_mset (\<lambda>x. [:x:]) (prime_factorization (content p))"
   688   define B where "B = image_mset (\<lambda>x. [:x:]) (prime_factorization (content p))"
   674   have "\<exists>A. (\<forall>p. p \<in># A \<longrightarrow> prime_elem p) \<and> prod_mset A = normalize (primitive_part p)"
   689   have "\<exists>A. (\<forall>p. p \<in># A \<longrightarrow> prime_elem p) \<and> prod_mset A = normalize (primitive_part p)"
   675     by (rule poly_prime_factorization_exists_content_1) (insert assms, simp_all)
   690     by (rule poly_prime_factorization_exists_content_1) (insert assms, simp_all)
   676   then guess A by (elim exE conjE) note A = this
   691   then obtain A where A: "\<forall>p. p \<in># A \<longrightarrow> prime_elem p" "\<Prod>\<^sub># A = normalize (primitive_part p)"
       
   692     by blast
   677   have "normalize (prod_mset (A + B)) = normalize (prod_mset A * normalize (prod_mset B))"
   693   have "normalize (prod_mset (A + B)) = normalize (prod_mset A * normalize (prod_mset B))"
   678     by simp
   694     by simp
   679   also from assms have "normalize (prod_mset B) = normalize [:content p:]"
   695   also from assms have "normalize (prod_mset B) = normalize [:content p:]"
   680     by (simp add: prod_mset_const_poly normalize_const_poly prod_mset_prime_factorization_weak B_def)
   696     by (simp add: prod_mset_const_poly normalize_const_poly prod_mset_prime_factorization_weak B_def)
   681   also have "prod_mset A = normalize (primitive_part p)"
   697   also have "prod_mset A = normalize (primitive_part p)"