haftmann@29197: (* Author: Amine Chaieb, TU Muenchen *) chaieb@26123: chaieb@26123: header{*Fundamental Theorem of Algebra*} chaieb@26123: chaieb@26123: theory Fundamental_Theorem_Algebra wenzelm@51537: imports Polynomial Complex_Main chaieb@26123: begin chaieb@26123: wenzelm@56778: subsection {* More lemmas about module of complex numbers *} chaieb@26123: chaieb@26123: text{* The triangle inequality for cmod *} chaieb@26123: lemma complex_mod_triangle_sub: "cmod w \ cmod (w + z) + norm z" chaieb@26123: using complex_mod_triangle_ineq2[of "w + z" "-z"] by auto chaieb@26123: wenzelm@56778: subsection {* Basic lemmas about polynomials *} chaieb@26123: chaieb@26123: lemma poly_bound_exists: wenzelm@56778: fixes p :: "'a::{comm_semiring_0,real_normed_div_algebra} poly" wenzelm@56778: shows "\m. m > 0 \ (\z. norm z \ r \ norm (poly p z) \ m)" wenzelm@56778: proof (induct p) wenzelm@56778: case 0 wenzelm@56778: then show ?case by (rule exI[where x=1]) simp chaieb@26123: next huffman@29464: case (pCons c cs) lp15@55735: from pCons.hyps obtain m where m: "\z. norm z \ r \ norm (poly cs z) \ m" chaieb@26123: by blast lp15@55735: let ?k = " 1 + norm c + \r * m\" wenzelm@56795: have kp: "?k > 0" wenzelm@56795: using abs_ge_zero[of "r*m"] norm_ge_zero[of c] by arith wenzelm@56778: { wenzelm@56778: fix z :: 'a lp15@55735: assume H: "norm z \ r" wenzelm@56778: from m H have th: "norm (poly cs z) \ m" wenzelm@56778: by blast wenzelm@56795: from H have rp: "r \ 0" wenzelm@56795: using norm_ge_zero[of z] by arith wenzelm@56795: have "norm (poly (pCons c cs) z) \ norm c + norm (z * poly cs z)" huffman@27514: using norm_triangle_ineq[of c "z* poly cs z"] by simp wenzelm@56778: also have "\ \ norm c + r * m" wenzelm@56778: using mult_mono[OF H th rp norm_ge_zero[of "poly cs z"]] lp15@55735: by (simp add: norm_mult) wenzelm@56778: also have "\ \ ?k" wenzelm@56778: by simp wenzelm@56778: finally have "norm (poly (pCons c cs) z) \ ?k" . wenzelm@56778: } chaieb@26123: with kp show ?case by blast chaieb@26123: qed chaieb@26123: chaieb@26123: chaieb@26123: text{* Offsetting the variable in a polynomial gives another of same degree *} huffman@29464: haftmann@52380: definition offset_poly :: "'a::comm_semiring_0 poly \ 'a \ 'a poly" wenzelm@56778: where "offset_poly p h = fold_coeffs (\a q. smult h q + pCons a q) p 0" huffman@29464: huffman@29464: lemma offset_poly_0: "offset_poly 0 h = 0" haftmann@52380: by (simp add: offset_poly_def) huffman@29464: huffman@29464: lemma offset_poly_pCons: huffman@29464: "offset_poly (pCons a p) h = huffman@29464: smult h (offset_poly p h) + pCons a (offset_poly p h)" haftmann@52380: by (cases "p = 0 \ a = 0") (auto simp add: offset_poly_def) huffman@29464: huffman@29464: lemma offset_poly_single: "offset_poly [:a:] h = [:a:]" wenzelm@56778: by (simp add: offset_poly_pCons offset_poly_0) huffman@29464: huffman@29464: lemma poly_offset_poly: "poly (offset_poly p h) x = poly p (h + x)" wenzelm@56778: apply (induct p) wenzelm@56778: apply (simp add: offset_poly_0) wenzelm@56778: apply (simp add: offset_poly_pCons algebra_simps) wenzelm@56778: done huffman@29464: huffman@29464: lemma offset_poly_eq_0_lemma: "smult c p + pCons a p = 0 \ p = 0" wenzelm@56778: by (induct p arbitrary: a) (simp, force) chaieb@26123: huffman@29464: lemma offset_poly_eq_0_iff: "offset_poly p h = 0 \ p = 0" wenzelm@56778: apply (safe intro!: offset_poly_0) wenzelm@56795: apply (induct p) wenzelm@56795: apply simp wenzelm@56778: apply (simp add: offset_poly_pCons) wenzelm@56778: apply (frule offset_poly_eq_0_lemma, simp) wenzelm@56778: done huffman@29464: huffman@29464: lemma degree_offset_poly: "degree (offset_poly p h) = degree p" wenzelm@56778: apply (induct p) wenzelm@56778: apply (simp add: offset_poly_0) wenzelm@56778: apply (case_tac "p = 0") wenzelm@56778: apply (simp add: offset_poly_0 offset_poly_pCons) wenzelm@56778: apply (simp add: offset_poly_pCons) wenzelm@56778: apply (subst degree_add_eq_right) wenzelm@56778: apply (rule le_less_trans [OF degree_smult_le]) wenzelm@56778: apply (simp add: offset_poly_eq_0_iff) wenzelm@56778: apply (simp add: offset_poly_eq_0_iff) wenzelm@56778: done huffman@29464: wenzelm@56778: definition "psize p = (if p = 0 then 0 else Suc (degree p))" huffman@29464: huffman@29538: lemma psize_eq_0_iff [simp]: "psize p = 0 \ p = 0" huffman@29538: unfolding psize_def by simp huffman@29464: wenzelm@56778: lemma poly_offset: wenzelm@56778: fixes p :: "'a::comm_ring_1 poly" wenzelm@56778: shows "\q. psize q = psize p \ (\x. poly q x = poly p (a + x))" huffman@29464: proof (intro exI conjI) huffman@29538: show "psize (offset_poly p a) = psize p" huffman@29538: unfolding psize_def huffman@29464: by (simp add: offset_poly_eq_0_iff degree_offset_poly) huffman@29464: show "\x. poly (offset_poly p a) x = poly p (a + x)" huffman@29464: by (simp add: poly_offset_poly) chaieb@26123: qed chaieb@26123: chaieb@26123: text{* An alternative useful formulation of completeness of the reals *} wenzelm@56778: lemma real_sup_exists: wenzelm@56778: assumes ex: "\x. P x" wenzelm@56778: and bz: "\z. \x. P x \ x < z" wenzelm@56778: shows "\s::real. \y. (\x. P x \ y < x) \ y < s" hoelzl@54263: proof hoelzl@54263: from bz have "bdd_above (Collect P)" hoelzl@54263: by (force intro: less_imp_le) hoelzl@54263: then show "\y. (\x. P x \ y < x) \ y < Sup (Collect P)" hoelzl@54263: using ex bz by (subst less_cSup_iff) auto chaieb@26123: qed chaieb@26123: huffman@27445: subsection {* Fundamental theorem of algebra *} chaieb@26123: lemma unimodular_reduce_norm: chaieb@26123: assumes md: "cmod z = 1" chaieb@26123: shows "cmod (z + 1) < 1 \ cmod (z - 1) < 1 \ cmod (z + ii) < 1 \ cmod (z - ii) < 1" wenzelm@56778: proof - wenzelm@56778: obtain x y where z: "z = Complex x y " wenzelm@56778: by (cases z) auto wenzelm@56778: from md z have xy: "x\<^sup>2 + y\<^sup>2 = 1" wenzelm@56778: by (simp add: cmod_def) wenzelm@56778: { wenzelm@56778: assume C: "cmod (z + 1) \ 1" "cmod (z - 1) \ 1" "cmod (z + ii) \ 1" "cmod (z - ii) \ 1" wenzelm@56778: from C z xy have "2 * x \ 1" "2 * x \ -1" "2 * y \ 1" "2 * y \ -1" nipkow@29667: by (simp_all add: cmod_def power2_eq_square algebra_simps) wenzelm@56778: then have "abs (2 * x) \ 1" "abs (2 * y) \ 1" wenzelm@56778: by simp_all wenzelm@56778: then have "(abs (2 * x))\<^sup>2 \ 1\<^sup>2" "(abs (2 * y))\<^sup>2 \ 1\<^sup>2" chaieb@26123: by - (rule power_mono, simp, simp)+ wenzelm@56778: then have th0: "4 * x\<^sup>2 \ 1" "4 * y\<^sup>2 \ 1" wenzelm@51541: by (simp_all add: power_mult_distrib) wenzelm@56778: from add_mono[OF th0] xy have False by simp wenzelm@56778: } wenzelm@56778: then show ?thesis wenzelm@56778: unfolding linorder_not_le[symmetric] by blast chaieb@26123: qed chaieb@26123: wenzelm@26135: text{* Hence we can always reduce modulus of @{text "1 + b z^n"} if nonzero *} chaieb@26123: lemma reduce_poly_simple: wenzelm@56778: assumes b: "b \ 0" wenzelm@56778: and n: "n \ 0" chaieb@26123: shows "\z. cmod (1 + b * z^n) < 1" wenzelm@56778: using n wenzelm@56778: proof (induct n rule: nat_less_induct) chaieb@26123: fix n wenzelm@56778: assume IH: "\m 0 \ (\z. cmod (1 + b * z ^ m) < 1)" wenzelm@56778: assume n: "n \ 0" chaieb@26123: let ?P = "\z n. cmod (1 + b * z ^ n) < 1" wenzelm@56778: { wenzelm@56778: assume e: "even n" wenzelm@56778: then have "\m. n = 2 * m" wenzelm@56778: by presburger wenzelm@56778: then obtain m where m: "n = 2 * m" wenzelm@56778: by blast wenzelm@56778: from n m have "m \ 0" "m < n" wenzelm@56778: by presburger+ wenzelm@56778: with IH[rule_format, of m] obtain z where z: "?P z m" wenzelm@56778: by blast wenzelm@56795: from z have "?P (csqrt z) n" hoelzl@56889: by (simp add: m power_mult power2_csqrt) wenzelm@56778: then have "\z. ?P z n" .. wenzelm@56778: } chaieb@26123: moreover wenzelm@56778: { wenzelm@56778: assume o: "odd n" chaieb@26123: have th0: "cmod (complex_of_real (cmod b) / b) = 1" huffman@36975: using b by (simp add: norm_divide) wenzelm@56778: from o have "\m. n = Suc (2 * m)" wenzelm@56778: by presburger+ wenzelm@56795: then obtain m where m: "n = Suc (2 * m)" wenzelm@56778: by blast chaieb@26123: from unimodular_reduce_norm[OF th0] o chaieb@26123: have "\v. cmod (complex_of_real (cmod b) / b + v^n) < 1" wenzelm@56795: apply (cases "cmod (complex_of_real (cmod b) / b + 1) < 1") wenzelm@56795: apply (rule_tac x="1" in exI) wenzelm@56795: apply simp wenzelm@56795: apply (cases "cmod (complex_of_real (cmod b) / b - 1) < 1") wenzelm@56795: apply (rule_tac x="-1" in exI) wenzelm@56795: apply simp chaieb@26123: apply (cases "cmod (complex_of_real (cmod b) / b + ii) < 1") wenzelm@56795: apply (cases "even m") wenzelm@56795: apply (rule_tac x="ii" in exI) wenzelm@56795: apply (simp add: m power_mult) wenzelm@56795: apply (rule_tac x="- ii" in exI) wenzelm@56795: apply (simp add: m power_mult) wenzelm@56795: apply (cases "even m") wenzelm@56795: apply (rule_tac x="- ii" in exI) wenzelm@56795: apply (simp add: m power_mult) haftmann@54489: apply (auto simp add: m power_mult) haftmann@54489: apply (rule_tac x="ii" in exI) haftmann@54489: apply (auto simp add: m power_mult) chaieb@26123: done wenzelm@56778: then obtain v where v: "cmod (complex_of_real (cmod b) / b + v^n) < 1" wenzelm@56778: by blast chaieb@26123: let ?w = "v / complex_of_real (root n (cmod b))" chaieb@26123: from odd_real_root_pow[OF o, of "cmod b"] huffman@30488: have th1: "?w ^ n = v^n / complex_of_real (cmod b)" hoelzl@56889: by (simp add: power_divide of_real_power[symmetric]) wenzelm@56778: have th2:"cmod (complex_of_real (cmod b) / b) = 1" wenzelm@56778: using b by (simp add: norm_divide) wenzelm@56778: then have th3: "cmod (complex_of_real (cmod b) / b) \ 0" wenzelm@56778: by simp chaieb@26123: have th4: "cmod (complex_of_real (cmod b) / b) * wenzelm@56778: cmod (1 + b * (v ^ n / complex_of_real (cmod b))) < wenzelm@56778: cmod (complex_of_real (cmod b) / b) * 1" webertj@49962: apply (simp only: norm_mult[symmetric] distrib_left) wenzelm@56778: using b v wenzelm@56778: apply (simp add: th2) wenzelm@56778: done chaieb@26123: from mult_less_imp_less_left[OF th4 th3] huffman@30488: have "?P ?w n" unfolding th1 . wenzelm@56778: then have "\z. ?P z n" .. wenzelm@56778: } chaieb@26123: ultimately show "\z. ?P z n" by blast chaieb@26123: qed chaieb@26123: chaieb@26123: text{* Bolzano-Weierstrass type property for closed disc in complex plane. *} chaieb@26123: wenzelm@56778: lemma metric_bound_lemma: "cmod (x - y) \ \Re x - Re y\ + \Im x - Im y\" wenzelm@56795: using real_sqrt_sum_squares_triangle_ineq[of "Re x - Re y" 0 0 "Im x - Im y"] chaieb@26123: unfolding cmod_def by simp chaieb@26123: chaieb@26123: lemma bolzano_weierstrass_complex_disc: chaieb@26123: assumes r: "\n. cmod (s n) \ r" chaieb@26123: shows "\f z. subseq f \ (\e >0. \N. \n \ N. cmod (s (f n) - z) < e)" chaieb@26123: proof- wenzelm@56778: from seq_monosub[of "Re \ s"] lp15@55358: obtain f where f: "subseq f" "monoseq (\n. Re (s (f n)))" chaieb@26123: unfolding o_def by blast wenzelm@56778: from seq_monosub[of "Im \ s \ f"] wenzelm@56778: obtain g where g: "subseq g" "monoseq (\n. Im (s (f (g n))))" wenzelm@56778: unfolding o_def by blast wenzelm@56778: let ?h = "f \ g" wenzelm@56778: from r[rule_format, of 0] have rp: "r \ 0" wenzelm@56778: using norm_ge_zero[of "s 0"] by arith wenzelm@56778: have th: "\n. r + 1 \ \Re (s n)\" chaieb@26123: proof chaieb@26123: fix n wenzelm@56778: from abs_Re_le_cmod[of "s n"] r[rule_format, of n] wenzelm@56778: show "\Re (s n)\ \ r + 1" by arith chaieb@26123: qed wenzelm@56778: have conv1: "convergent (\n. Re (s (f n)))" chaieb@26123: apply (rule Bseq_monoseq_convergent) chaieb@26123: apply (simp add: Bseq_def) lp15@55358: apply (metis gt_ex le_less_linear less_trans order.trans th) wenzelm@56778: apply (rule f(2)) wenzelm@56778: done wenzelm@56778: have th: "\n. r + 1 \ \Im (s n)\" chaieb@26123: proof chaieb@26123: fix n wenzelm@56778: from abs_Im_le_cmod[of "s n"] r[rule_format, of n] wenzelm@56778: show "\Im (s n)\ \ r + 1" wenzelm@56778: by arith chaieb@26123: qed chaieb@26123: chaieb@26123: have conv2: "convergent (\n. Im (s (f (g n))))" chaieb@26123: apply (rule Bseq_monoseq_convergent) chaieb@26123: apply (simp add: Bseq_def) lp15@55358: apply (metis gt_ex le_less_linear less_trans order.trans th) wenzelm@56778: apply (rule g(2)) wenzelm@56778: done chaieb@26123: huffman@30488: from conv1[unfolded convergent_def] obtain x where "LIMSEQ (\n. Re (s (f n))) x" huffman@30488: by blast wenzelm@56795: then have x: "\r>0. \n0. \n\n0. \Re (s (f n)) - x\ < r" huffman@31337: unfolding LIMSEQ_iff real_norm_def . chaieb@26123: huffman@30488: from conv2[unfolded convergent_def] obtain y where "LIMSEQ (\n. Im (s (f (g n)))) y" huffman@30488: by blast wenzelm@56795: then have y: "\r>0. \n0. \n\n0. \Im (s (f (g n))) - y\ < r" huffman@31337: unfolding LIMSEQ_iff real_norm_def . chaieb@26123: let ?w = "Complex x y" wenzelm@56778: from f(1) g(1) have hs: "subseq ?h" wenzelm@56778: unfolding subseq_def by auto wenzelm@56778: { wenzelm@56778: fix e :: real wenzelm@56778: assume ep: "e > 0" wenzelm@56795: then have e2: "e/2 > 0" wenzelm@56795: by simp chaieb@26123: from x[rule_format, OF e2] y[rule_format, OF e2] wenzelm@56778: obtain N1 N2 where N1: "\n\N1. \Re (s (f n)) - x\ < e / 2" wenzelm@56795: and N2: "\n\N2. \Im (s (f (g n))) - y\ < e / 2" wenzelm@56795: by blast wenzelm@56778: { wenzelm@56778: fix n wenzelm@56778: assume nN12: "n \ N1 + N2" wenzelm@56778: then have nN1: "g n \ N1" and nN2: "n \ N2" wenzelm@56778: using seq_suble[OF g(1), of n] by arith+ chaieb@26123: from add_strict_mono[OF N1[rule_format, OF nN1] N2[rule_format, OF nN2]] huffman@30488: have "cmod (s (?h n) - ?w) < e" wenzelm@56778: using metric_bound_lemma[of "s (f (g n))" ?w] by simp wenzelm@56778: } wenzelm@56795: then have "\N. \n\N. cmod (s (?h n) - ?w) < e" wenzelm@56795: by blast wenzelm@56778: } wenzelm@56778: with hs show ?thesis by blast chaieb@26123: qed chaieb@26123: chaieb@26123: text{* Polynomial is continuous. *} chaieb@26123: chaieb@26123: lemma poly_cont: wenzelm@56778: fixes p :: "'a::{comm_semiring_0,real_normed_div_algebra} poly" huffman@30488: assumes ep: "e > 0" lp15@55735: shows "\d >0. \w. 0 < norm (w - z) \ norm (w - z) < d \ norm (poly p w - poly p z) < e" wenzelm@56778: proof - huffman@29464: obtain q where q: "degree q = degree p" "\x. poly q x = poly p (z + x)" huffman@29464: proof huffman@29464: show "degree (offset_poly p z) = degree p" huffman@29464: by (rule degree_offset_poly) huffman@29464: show "\x. poly (offset_poly p z) x = poly p (z + x)" huffman@29464: by (rule poly_offset_poly) huffman@29464: qed wenzelm@56778: have th: "\w. poly q (w - z) = poly p w" wenzelm@56778: using q(2)[of "w - z" for w] by simp chaieb@26123: show ?thesis unfolding th[symmetric] wenzelm@56778: proof (induct q) wenzelm@56778: case 0 wenzelm@56778: then show ?case wenzelm@56778: using ep by auto chaieb@26123: next huffman@29464: case (pCons c cs) huffman@30488: from poly_bound_exists[of 1 "cs"] wenzelm@56778: obtain m where m: "m > 0" "\z. norm z \ 1 \ norm (poly cs z) \ m" wenzelm@56778: by blast wenzelm@56778: from ep m(1) have em0: "e/m > 0" wenzelm@56778: by (simp add: field_simps) wenzelm@56778: have one0: "1 > (0::real)" wenzelm@56778: by arith huffman@30488: from real_lbound_gt_zero[OF one0 em0] wenzelm@56778: obtain d where d: "d > 0" "d < 1" "d < e / m" wenzelm@56778: by blast wenzelm@56778: from d(1,3) m(1) have dm: "d * m > 0" "d * m < e" nipkow@56544: by (simp_all add: field_simps) huffman@30488: show ?case wenzelm@56778: proof (rule ex_forward[OF real_lbound_gt_zero[OF one0 em0]], clarsimp simp add: norm_mult) wenzelm@56778: fix d w wenzelm@56778: assume H: "d > 0" "d < 1" "d < e/m" "w \ z" "norm (w - z) < d" wenzelm@56778: then have d1: "norm (w-z) \ 1" "d \ 0" wenzelm@56778: by simp_all wenzelm@56778: from H(3) m(1) have dme: "d*m < e" wenzelm@56778: by (simp add: field_simps) wenzelm@56778: from H have th: "norm (w - z) \ d" wenzelm@56778: by simp wenzelm@56778: from mult_mono[OF th m(2)[OF d1(1)] d1(2) norm_ge_zero] dme wenzelm@56778: show "norm (w - z) * norm (poly cs (w - z)) < e" wenzelm@56778: by simp chaieb@26123: qed wenzelm@56778: qed chaieb@26123: qed chaieb@26123: huffman@30488: text{* Hence a polynomial attains minimum on a closed disc chaieb@26123: in the complex plane. *} wenzelm@56778: lemma poly_minimum_modulus_disc: "\z. \w. cmod w \ r \ cmod (poly p z) \ cmod (poly p w)" wenzelm@56778: proof - wenzelm@56778: { wenzelm@56778: assume "\ r \ 0" wenzelm@56778: then have ?thesis wenzelm@56778: by (metis norm_ge_zero order.trans) wenzelm@56778: } chaieb@26123: moreover wenzelm@56778: { wenzelm@56778: assume rp: "r \ 0" wenzelm@56778: from rp have "cmod 0 \ r \ cmod (poly p 0) = - (- cmod (poly p 0))" wenzelm@56778: by simp wenzelm@56778: then have mth1: "\x z. cmod z \ r \ cmod (poly p z) = - x" wenzelm@56778: by blast wenzelm@56778: { wenzelm@56778: fix x z wenzelm@56778: assume H: "cmod z \ r" "cmod (poly p z) = - x" "\ x < 1" wenzelm@56778: then have "- x < 0 " wenzelm@56778: by arith wenzelm@56778: with H(2) norm_ge_zero[of "poly p z"] have False wenzelm@56778: by simp wenzelm@56778: } wenzelm@56778: then have mth2: "\z. \x. (\z. cmod z \ r \ cmod (poly p z) = - x) \ x < z" wenzelm@56778: by blast huffman@30488: from real_sup_exists[OF mth1 mth2] obtain s where wenzelm@56778: s: "\y. (\x. (\z. cmod z \ r \ cmod (poly p z) = - x) \ y < x) \ y < s" by blast wenzelm@56778: let ?m = "- s" wenzelm@56778: { wenzelm@56778: fix y wenzelm@56778: from s[rule_format, of "-y"] wenzelm@56778: have "(\z x. cmod z \ r \ - (- cmod (poly p z)) < y) \ ?m < y" wenzelm@56778: unfolding minus_less_iff[of y ] equation_minus_iff by blast wenzelm@56778: } chaieb@26123: note s1 = this[unfolded minus_minus] huffman@30488: from s1[of ?m] have s1m: "\z x. cmod z \ r \ cmod (poly p z) \ ?m" chaieb@26123: by auto wenzelm@56778: { wenzelm@56778: fix n :: nat huffman@30488: from s1[rule_format, of "?m + 1/real (Suc n)"] chaieb@26123: have "\z. cmod z \ r \ cmod (poly p z) < - s + 1 / real (Suc n)" wenzelm@56778: by simp wenzelm@56778: } wenzelm@56778: then have th: "\n. \z. cmod z \ r \ cmod (poly p z) < - s + 1 / real (Suc n)" .. huffman@30488: from choice[OF th] obtain g where wenzelm@56778: g: "\n. cmod (g n) \ r" "\n. cmod (poly p (g n)) e>0. \N. \n\N. cmod (g (f n) - z) < e" huffman@30488: by blast wenzelm@56778: { wenzelm@56778: fix w chaieb@26123: assume wr: "cmod w \ r" chaieb@26123: let ?e = "\cmod (poly p z) - ?m\" wenzelm@56778: { wenzelm@56778: assume e: "?e > 0" wenzelm@56795: then have e2: "?e/2 > 0" wenzelm@56795: by simp wenzelm@32960: from poly_cont[OF e2, of z p] obtain d where wenzelm@56778: d: "d > 0" "\w. 0 cmod(w - z) < d \ cmod(poly p w - poly p z) < ?e/2" wenzelm@56778: by blast wenzelm@56778: { wenzelm@56778: fix w wenzelm@56778: assume w: "cmod (w - z) < d" wenzelm@32960: have "cmod(poly p w - poly p z) < ?e / 2" wenzelm@56778: using d(2)[rule_format, of w] w e by (cases "w = z") simp_all wenzelm@56778: } wenzelm@32960: note th1 = this huffman@30488: wenzelm@56778: from fz(2) d(1) obtain N1 where N1: "\n\N1. cmod (g (f n) - z) < d" wenzelm@56778: by blast wenzelm@56778: from reals_Archimedean2[of "2/?e"] obtain N2 :: nat where N2: "2/?e < real N2" wenzelm@56778: by blast wenzelm@56778: have th2: "cmod (poly p (g (f (N1 + N2))) - poly p z) < ?e/2" wenzelm@32960: using N1[rule_format, of "N1 + N2"] th1 by simp wenzelm@56778: { wenzelm@56778: fix a b e2 m :: real wenzelm@56778: have "a < e2 \ \b - m\ < e2 \ 2 * e2 \ \b - m\ + a \ False" wenzelm@56778: by arith wenzelm@56778: } wenzelm@56778: note th0 = this wenzelm@56778: have ath: "\m x e::real. m \ x \ x < m + e \ \x - m\ < e" wenzelm@56778: by arith wenzelm@56778: from s1m[OF g(1)[rule_format]] have th31: "?m \ cmod(poly p (g (f (N1 + N2))))" . wenzelm@56795: from seq_suble[OF fz(1), of "N1 + N2"] wenzelm@56778: have th00: "real (Suc (N1 + N2)) \ real (Suc (f (N1 + N2)))" wenzelm@56778: by simp wenzelm@56778: have th000: "0 \ (1::real)" "(1::real) \ 1" "real (Suc (N1 + N2)) > 0" wenzelm@56778: using N2 by auto wenzelm@56778: from frac_le[OF th000 th00] wenzelm@56795: have th00: "?m + 1 / real (Suc (f (N1 + N2))) \ ?m + 1 / real (Suc (N1 + N2))" wenzelm@56778: by simp wenzelm@56778: from g(2)[rule_format, of "f (N1 + N2)"] wenzelm@56778: have th01:"cmod (poly p (g (f (N1 + N2)))) < - s + 1 / real (Suc (f (N1 + N2)))" . wenzelm@56778: from order_less_le_trans[OF th01 th00] wenzelm@56795: have th32: "cmod (poly p (g (f (N1 + N2)))) < ?m + (1/ real(Suc (N1 + N2)))" . wenzelm@56778: from N2 have "2/?e < real (Suc (N1 + N2))" wenzelm@56778: by arith wenzelm@56778: with e2 less_imp_inverse_less[of "2/?e" "real (Suc (N1 + N2))"] wenzelm@56778: have "?e/2 > 1/ real (Suc (N1 + N2))" wenzelm@56778: by (simp add: inverse_eq_divide) wenzelm@56778: with ath[OF th31 th32] wenzelm@56795: have thc1: "\cmod (poly p (g (f (N1 + N2)))) - ?m\ < ?e/2" wenzelm@56778: by arith wenzelm@56778: have ath2: "\a b c m::real. \a - b\ \ c \ \b - m\ \ \a - m\ + c" wenzelm@56778: by arith wenzelm@56778: have th22: "\cmod (poly p (g (f (N1 + N2)))) - cmod (poly p z)\ \ wenzelm@56778: cmod (poly p (g (f (N1 + N2))) - poly p z)" wenzelm@56778: by (simp add: norm_triangle_ineq3) wenzelm@56778: from ath2[OF th22, of ?m] wenzelm@56778: have thc2: "2 * (?e/2) \ wenzelm@56778: \cmod(poly p (g (f (N1 + N2)))) - ?m\ + cmod (poly p (g (f (N1 + N2))) - poly p z)" wenzelm@56778: by simp wenzelm@56778: from th0[OF th2 thc1 thc2] have False . wenzelm@56778: } wenzelm@56778: then have "?e = 0" wenzelm@56778: by auto wenzelm@56778: then have "cmod (poly p z) = ?m" wenzelm@56778: by simp wenzelm@56778: with s1m[OF wr] have "cmod (poly p z) \ cmod (poly p w)" wenzelm@56778: by simp wenzelm@56778: } wenzelm@56778: then have ?thesis by blast wenzelm@56778: } chaieb@26123: ultimately show ?thesis by blast chaieb@26123: qed chaieb@26123: chaieb@26123: text {* Nonzero polynomial in z goes to infinity as z does. *} chaieb@26123: chaieb@26123: lemma poly_infinity: wenzelm@56778: fixes p:: "'a::{comm_semiring_0,real_normed_div_algebra} poly" huffman@29464: assumes ex: "p \ 0" lp15@55735: shows "\r. \z. r \ norm z \ d \ norm (poly (pCons a p) z)" wenzelm@56778: using ex wenzelm@56778: proof (induct p arbitrary: a d) wenzelm@56795: case 0 wenzelm@56795: then show ?case by simp wenzelm@56795: next huffman@30488: case (pCons c cs a d) wenzelm@56795: show ?case wenzelm@56795: proof (cases "cs = 0") wenzelm@56795: case False wenzelm@56778: with pCons.hyps obtain r where r: "\z. r \ norm z \ d + norm a \ norm (poly (pCons c cs) z)" wenzelm@56778: by blast chaieb@26123: let ?r = "1 + \r\" wenzelm@56778: { wenzelm@56795: fix z :: 'a wenzelm@56778: assume h: "1 + \r\ \ norm z" wenzelm@56795: have r0: "r \ norm z" wenzelm@56795: using h by arith wenzelm@56778: from r[rule_format, OF r0] have th0: "d + norm a \ 1 * norm(poly (pCons c cs) z)" wenzelm@56778: by arith wenzelm@56778: from h have z1: "norm z \ 1" wenzelm@56778: by arith huffman@29464: from order_trans[OF th0 mult_right_mono[OF z1 norm_ge_zero[of "poly (pCons c cs) z"]]] lp15@55735: have th1: "d \ norm(z * poly (pCons c cs) z) - norm a" wenzelm@32960: unfolding norm_mult by (simp add: algebra_simps) lp15@55735: from norm_diff_ineq[of "z * poly (pCons c cs) z" a] wenzelm@56795: have th2: "norm (z * poly (pCons c cs) z) - norm a \ norm (poly (pCons a (pCons c cs)) z)" wenzelm@51541: by (simp add: algebra_simps) wenzelm@56795: from th1 th2 have "d \ norm (poly (pCons a (pCons c cs)) z)" wenzelm@56795: by arith wenzelm@56778: } wenzelm@56795: then show ?thesis by blast wenzelm@56795: next wenzelm@56795: case True wenzelm@56778: with pCons.prems have c0: "c \ 0" wenzelm@56778: by simp wenzelm@56778: { wenzelm@56795: fix z :: 'a lp15@55735: assume h: "(\d\ + norm a) / norm c \ norm z" wenzelm@56778: from c0 have "norm c > 0" wenzelm@56778: by simp blanchet@56403: from h c0 have th0: "\d\ + norm a \ norm (z * c)" wenzelm@32960: by (simp add: field_simps norm_mult) wenzelm@56778: have ath: "\mzh mazh ma. mzh \ mazh + ma \ \d\ + ma \ mzh \ d \ mazh" wenzelm@56778: by arith wenzelm@56778: from norm_diff_ineq[of "z * c" a] have th1: "norm (z * c) \ norm (a + z * c) + norm a" wenzelm@32960: by (simp add: algebra_simps) lp15@55735: from ath[OF th1 th0] have "d \ norm (poly (pCons a (pCons c cs)) z)" wenzelm@56795: using True by simp wenzelm@56778: } wenzelm@56795: then show ?thesis by blast wenzelm@56795: qed wenzelm@56795: qed chaieb@26123: chaieb@26123: text {* Hence polynomial's modulus attains its minimum somewhere. *} wenzelm@56778: lemma poly_minimum_modulus: "\z.\w. cmod (poly p z) \ cmod (poly p w)" wenzelm@56778: proof (induct p) wenzelm@56778: case 0 wenzelm@56778: then show ?case by simp wenzelm@56778: next huffman@30488: case (pCons c cs) wenzelm@56778: show ?case wenzelm@56778: proof (cases "cs = 0") wenzelm@56778: case False wenzelm@56778: from poly_infinity[OF False, of "cmod (poly (pCons c cs) 0)" c] wenzelm@56778: obtain r where r: "\z. r \ cmod z \ cmod (poly (pCons c cs) 0) \ cmod (poly (pCons c cs) z)" wenzelm@56778: by blast wenzelm@56778: have ath: "\z r. r \ cmod z \ cmod z \ \r\" wenzelm@56778: by arith huffman@30488: from poly_minimum_modulus_disc[of "\r\" "pCons c cs"] wenzelm@56778: obtain v where v: "\w. cmod w \ \r\ \ cmod (poly (pCons c cs) v) \ cmod (poly (pCons c cs) w)" wenzelm@56778: by blast wenzelm@56778: { wenzelm@56778: fix z wenzelm@56778: assume z: "r \ cmod z" wenzelm@56778: from v[of 0] r[OF z] have "cmod (poly (pCons c cs) v) \ cmod (poly (pCons c cs) z)" wenzelm@56778: by simp wenzelm@56778: } chaieb@26123: note v0 = this wenzelm@56778: from v0 v ath[of r] show ?thesis wenzelm@56778: by blast wenzelm@56778: next wenzelm@56778: case True wenzelm@56778: with pCons.hyps show ?thesis by simp wenzelm@56778: qed wenzelm@56778: qed chaieb@26123: chaieb@26123: text{* Constant function (non-syntactic characterization). *} wenzelm@56795: definition "constant f \ (\x y. f x = f y)" chaieb@26123: wenzelm@56778: lemma nonconstant_length: "\ constant (poly p) \ psize p \ 2" wenzelm@56778: by (induct p) (auto simp: constant_def psize_def) huffman@30488: wenzelm@56795: lemma poly_replicate_append: "poly (monom 1 n * p) (x::'a::comm_ring_1) = x^n * poly p x" huffman@29464: by (simp add: poly_monom) chaieb@26123: huffman@30488: text {* Decomposition of polynomial, skipping zero coefficients chaieb@26123: after the first. *} chaieb@26123: chaieb@26123: lemma poly_decompose_lemma: wenzelm@56778: assumes nz: "\ (\z. z \ 0 \ poly p z = (0::'a::idom))" wenzelm@56795: shows "\k a q. a \ 0 \ Suc (psize q + k) = psize p \ (\z. poly p z = z^k * poly (pCons a q) z)" wenzelm@56778: unfolding psize_def wenzelm@56778: using nz wenzelm@56778: proof (induct p) wenzelm@56778: case 0 wenzelm@56778: then show ?case by simp chaieb@26123: next huffman@29464: case (pCons c cs) wenzelm@56778: show ?case wenzelm@56778: proof (cases "c = 0") wenzelm@56778: case True wenzelm@56778: from pCons.hyps pCons.prems True show ?thesis nipkow@32456: apply (auto) chaieb@26123: apply (rule_tac x="k+1" in exI) chaieb@26123: apply (rule_tac x="a" in exI, clarsimp) chaieb@26123: apply (rule_tac x="q" in exI) wenzelm@56778: apply auto wenzelm@56778: done wenzelm@56778: next wenzelm@56778: case False wenzelm@56778: show ?thesis chaieb@26123: apply (rule exI[where x=0]) wenzelm@56778: apply (rule exI[where x=c], auto simp add: False) wenzelm@56778: done wenzelm@56778: qed chaieb@26123: qed chaieb@26123: chaieb@26123: lemma poly_decompose: wenzelm@56776: assumes nc: "\ constant (poly p)" wenzelm@56778: shows "\k a q. a \ (0::'a::idom) \ k \ 0 \ huffman@30488: psize q + k + 1 = psize p \ huffman@29464: (\z. poly p z = poly p 0 + z^k * poly (pCons a q) z)" wenzelm@56776: using nc wenzelm@56776: proof (induct p) wenzelm@56776: case 0 wenzelm@56776: then show ?case wenzelm@56776: by (simp add: constant_def) chaieb@26123: next huffman@29464: case (pCons c cs) wenzelm@56776: { wenzelm@56795: assume C: "\z. z \ 0 \ poly cs z = 0" wenzelm@56776: { wenzelm@56776: fix x y wenzelm@56776: from C have "poly (pCons c cs) x = poly (pCons c cs) y" wenzelm@56776: by (cases "x = 0") auto wenzelm@56776: } wenzelm@56778: with pCons.prems have False wenzelm@56778: by (auto simp add: constant_def) wenzelm@56776: } wenzelm@56776: then have th: "\ (\z. z \ 0 \ poly cs z = 0)" .. huffman@30488: from poly_decompose_lemma[OF th] huffman@30488: show ?case huffman@29464: apply clarsimp chaieb@26123: apply (rule_tac x="k+1" in exI) chaieb@26123: apply (rule_tac x="a" in exI) chaieb@26123: apply simp chaieb@26123: apply (rule_tac x="q" in exI) huffman@29538: apply (auto simp add: psize_def split: if_splits) chaieb@26123: done chaieb@26123: qed chaieb@26123: berghofe@34915: text{* Fundamental theorem of algebra *} chaieb@26123: chaieb@26123: lemma fundamental_theorem_of_algebra: wenzelm@56776: assumes nc: "\ constant (poly p)" chaieb@26123: shows "\z::complex. poly p z = 0" wenzelm@56776: using nc wenzelm@56776: proof (induct "psize p" arbitrary: p rule: less_induct) berghofe@34915: case less chaieb@26123: let ?p = "poly p" chaieb@26123: let ?ths = "\z. ?p z = 0" chaieb@26123: berghofe@34915: from nonconstant_length[OF less(2)] have n2: "psize p \ 2" . wenzelm@56776: from poly_minimum_modulus obtain c where c: "\w. cmod (?p c) \ cmod (?p w)" wenzelm@56776: by blast wenzelm@56778: wenzelm@56778: show ?ths wenzelm@56778: proof (cases "?p c = 0") wenzelm@56778: case True wenzelm@56778: then show ?thesis by blast wenzelm@56778: next wenzelm@56778: case False wenzelm@56778: note pc0 = this wenzelm@56778: from poly_offset[of p c] obtain q where q: "psize q = psize p" "\x. poly q x = ?p (c + x)" wenzelm@56778: by blast wenzelm@56778: { wenzelm@56778: assume h: "constant (poly q)" wenzelm@56795: from q(2) have th: "\x. poly q (x - c) = ?p x" wenzelm@56795: by auto wenzelm@56778: { wenzelm@56778: fix x y wenzelm@56795: from th have "?p x = poly q (x - c)" wenzelm@56795: by auto wenzelm@32960: also have "\ = poly q (y - c)" wenzelm@32960: using h unfolding constant_def by blast wenzelm@56795: also have "\ = ?p y" wenzelm@56795: using th by auto wenzelm@56778: finally have "?p x = ?p y" . wenzelm@56778: } wenzelm@56778: with less(2) have False wenzelm@56778: unfolding constant_def by blast wenzelm@56778: } wenzelm@56778: then have qnc: "\ constant (poly q)" wenzelm@56778: by blast wenzelm@56778: from q(2) have pqc0: "?p c = poly q 0" wenzelm@56778: by simp wenzelm@56778: from c pqc0 have cq0: "\w. cmod (poly q 0) \ cmod (?p w)" wenzelm@56778: by simp chaieb@26123: let ?a0 = "poly q 0" wenzelm@56778: from pc0 pqc0 have a00: "?a0 \ 0" wenzelm@56778: by simp wenzelm@56778: from a00 have qr: "\z. poly q z = poly (smult (inverse ?a0) q) z * ?a0" huffman@29464: by simp huffman@29464: let ?r = "smult (inverse ?a0) q" huffman@29538: have lgqr: "psize q = psize ?r" wenzelm@56778: using a00 wenzelm@56778: unfolding psize_def degree_def haftmann@52380: by (simp add: poly_eq_iff) wenzelm@56778: { wenzelm@56778: assume h: "\x y. poly ?r x = poly ?r y" wenzelm@56778: { wenzelm@56778: fix x y wenzelm@56778: from qr[rule_format, of x] have "poly q x = poly ?r x * ?a0" wenzelm@56778: by auto wenzelm@56778: also have "\ = poly ?r y * ?a0" wenzelm@56778: using h by simp wenzelm@56778: also have "\ = poly q y" wenzelm@56778: using qr[rule_format, of y] by simp wenzelm@56778: finally have "poly q x = poly q y" . wenzelm@56778: } wenzelm@56795: with qnc have False wenzelm@56795: unfolding constant_def by blast wenzelm@56778: } wenzelm@56778: then have rnc: "\ constant (poly ?r)" wenzelm@56778: unfolding constant_def by blast wenzelm@56778: from qr[rule_format, of 0] a00 have r01: "poly ?r 0 = 1" wenzelm@56778: by auto wenzelm@56778: { wenzelm@56778: fix w chaieb@26123: have "cmod (poly ?r w) < 1 \ cmod (poly q w / ?a0) < 1" haftmann@57514: using qr[rule_format, of w] a00 by (simp add: divide_inverse ac_simps) chaieb@26123: also have "\ \ cmod (poly q w) < cmod ?a0" wenzelm@32960: using a00 unfolding norm_divide by (simp add: field_simps) wenzelm@56778: finally have "cmod (poly ?r w) < 1 \ cmod (poly q w) < cmod ?a0" . wenzelm@56778: } chaieb@26123: note mrmq_eq = this huffman@30488: from poly_decompose[OF rnc] obtain k a s where wenzelm@56778: kas: "a \ 0" "k \ 0" "psize s + k + 1 = psize ?r" wenzelm@56778: "\z. poly ?r z = poly ?r 0 + z^k* poly (pCons a s) z" by blast wenzelm@56778: { wenzelm@56778: assume "psize p = k + 1" wenzelm@56778: with kas(3) lgqr[symmetric] q(1) have s0: "s = 0" wenzelm@56778: by auto wenzelm@56778: { wenzelm@56778: fix w wenzelm@32960: have "cmod (poly ?r w) = cmod (1 + a * w ^ k)" wenzelm@56778: using kas(4)[rule_format, of w] s0 r01 by (simp add: algebra_simps) wenzelm@56778: } chaieb@26123: note hth = this [symmetric] wenzelm@56778: from reduce_poly_simple[OF kas(1,2)] have "\w. cmod (poly ?r w) < 1" wenzelm@56778: unfolding hth by blast wenzelm@56778: } chaieb@26123: moreover wenzelm@56778: { wenzelm@56778: assume kn: "psize p \ k + 1" wenzelm@56778: from kn kas(3) q(1) lgqr have k1n: "k + 1 < psize p" wenzelm@56778: by simp huffman@30488: have th01: "\ constant (poly (pCons 1 (monom a (k - 1))))" wenzelm@32960: unfolding constant_def poly_pCons poly_monom wenzelm@56795: using kas(1) wenzelm@56795: apply simp wenzelm@56778: apply (rule exI[where x=0]) wenzelm@56778: apply (rule exI[where x=1]) wenzelm@56778: apply simp wenzelm@56778: done wenzelm@56778: from kas(1) kas(2) have th02: "k + 1 = psize (pCons 1 (monom a (k - 1)))" wenzelm@32960: by (simp add: psize_def degree_monom_eq) berghofe@34915: from less(1) [OF k1n [simplified th02] th01] chaieb@26123: obtain w where w: "1 + w^k * a = 0" wenzelm@32960: unfolding poly_pCons poly_monom wenzelm@56778: using kas(2) by (cases k) (auto simp add: algebra_simps) huffman@30488: from poly_bound_exists[of "cmod w" s] obtain m where wenzelm@32960: m: "m > 0" "\z. cmod z \ cmod w \ cmod (poly s z) \ m" by blast wenzelm@56795: have w0: "w \ 0" wenzelm@56795: using kas(2) w by (auto simp add: power_0_left) wenzelm@56778: from w have "(1 + w ^ k * a) - 1 = 0 - 1" wenzelm@56778: by simp wenzelm@56778: then have wm1: "w^k * a = - 1" wenzelm@56778: by simp huffman@30488: have inv0: "0 < inverse (cmod w ^ (k + 1) * m)" wenzelm@32960: using norm_ge_zero[of w] w0 m(1) wenzelm@56778: by (simp add: inverse_eq_divide zero_less_mult_iff) lp15@55358: with real_lbound_gt_zero[OF zero_less_one] obtain t where wenzelm@32960: t: "t > 0" "t < 1" "t < inverse (cmod w ^ (k + 1) * m)" by blast chaieb@26123: let ?ct = "complex_of_real t" chaieb@26123: let ?w = "?ct * w" wenzelm@56778: have "1 + ?w^k * (a + ?w * poly s ?w) = 1 + ?ct^k * (w^k * a) + ?w^k * ?w * poly s ?w" wenzelm@56778: using kas(1) by (simp add: algebra_simps power_mult_distrib) chaieb@26123: also have "\ = complex_of_real (1 - t^k) + ?w^k * ?w * poly s ?w" wenzelm@56778: unfolding wm1 by simp wenzelm@56778: finally have "cmod (1 + ?w^k * (a + ?w * poly s ?w)) = wenzelm@56778: cmod (complex_of_real (1 - t^k) + ?w^k * ?w * poly s ?w)" lp15@55358: by metis huffman@30488: with norm_triangle_ineq[of "complex_of_real (1 - t^k)" "?w^k * ?w * poly s ?w"] wenzelm@56778: have th11: "cmod (1 + ?w^k * (a + ?w * poly s ?w)) \ \1 - t^k\ + cmod (?w^k * ?w * poly s ?w)" wenzelm@56778: unfolding norm_of_real by simp wenzelm@56778: have ath: "\x t::real. 0 \ x \ x < t \ t \ 1 \ \1 - t\ + x < 1" wenzelm@56778: by arith wenzelm@56778: have "t * cmod w \ 1 * cmod w" wenzelm@56778: apply (rule mult_mono) wenzelm@56778: using t(1,2) wenzelm@56778: apply auto wenzelm@56778: done wenzelm@56778: then have tw: "cmod ?w \ cmod w" wenzelm@56778: using t(1) by (simp add: norm_mult) wenzelm@56778: from t inv0 have "t * (cmod w ^ (k + 1) * m) < 1" wenzelm@57862: by (simp add: field_simps) wenzelm@56778: with zero_less_power[OF t(1), of k] have th30: "t^k * (t* (cmod w ^ (k + 1) * m)) < t^k * 1" lp15@55358: by (metis comm_mult_strict_left_mono) wenzelm@56778: have "cmod (?w^k * ?w * poly s ?w) = t^k * (t* (cmod w ^ (k + 1) * cmod (poly s ?w)))" wenzelm@56778: using w0 t(1) wenzelm@51541: by (simp add: algebra_simps power_mult_distrib norm_power norm_mult) chaieb@26123: then have "cmod (?w^k * ?w * poly s ?w) \ t^k * (t* (cmod w ^ (k + 1) * m))" wenzelm@32960: using t(1,2) m(2)[rule_format, OF tw] w0 lp15@55358: by auto wenzelm@56778: with th30 have th120: "cmod (?w^k * ?w * poly s ?w) < t^k" wenzelm@56778: by simp huffman@30488: from power_strict_mono[OF t(2), of k] t(1) kas(2) have th121: "t^k \ 1" wenzelm@32960: by auto huffman@27514: from ath[OF norm_ge_zero[of "?w^k * ?w * poly s ?w"] th120 th121] huffman@30488: have th12: "\1 - t^k\ + cmod (?w^k * ?w * poly s ?w) < 1" . wenzelm@56778: from th11 th12 have "cmod (1 + ?w^k * (a + ?w * poly s ?w)) < 1" wenzelm@56778: by arith huffman@30488: then have "cmod (poly ?r ?w) < 1" wenzelm@32960: unfolding kas(4)[rule_format, of ?w] r01 by simp wenzelm@56778: then have "\w. cmod (poly ?r w) < 1" wenzelm@56778: by blast wenzelm@56778: } wenzelm@56778: ultimately have cr0_contr: "\w. cmod (poly ?r w) < 1" wenzelm@56778: by blast wenzelm@56778: from cr0_contr cq0 q(2) show ?thesis wenzelm@56778: unfolding mrmq_eq not_less[symmetric] by auto wenzelm@56778: qed chaieb@26123: qed chaieb@26123: chaieb@26123: text {* Alternative version with a syntactic notion of constant polynomial. *} chaieb@26123: chaieb@26123: lemma fundamental_theorem_of_algebra_alt: wenzelm@56778: assumes nc: "\ (\a l. a \ 0 \ l = 0 \ p = pCons a l)" chaieb@26123: shows "\z. poly p z = (0::complex)" wenzelm@56778: using nc wenzelm@56778: proof (induct p) wenzelm@56778: case 0 wenzelm@56778: then show ?case by simp wenzelm@56778: next huffman@29464: case (pCons c cs) wenzelm@56778: show ?case wenzelm@56778: proof (cases "c = 0") wenzelm@56778: case True wenzelm@56778: then show ?thesis by auto wenzelm@56778: next wenzelm@56778: case False wenzelm@56778: { wenzelm@56778: assume nc: "constant (poly (pCons c cs))" huffman@30488: from nc[unfolded constant_def, rule_format, of 0] huffman@30488: have "\w. w \ 0 \ poly cs w = 0" by auto wenzelm@56778: then have "cs = 0" wenzelm@56778: proof (induct cs) wenzelm@56778: case 0 wenzelm@56778: then show ?case by simp wenzelm@56778: next wenzelm@56778: case (pCons d ds) wenzelm@56778: show ?case wenzelm@56778: proof (cases "d = 0") wenzelm@56778: case True wenzelm@56778: then show ?thesis using pCons.prems pCons.hyps by simp wenzelm@56778: next wenzelm@56778: case False wenzelm@56778: from poly_bound_exists[of 1 ds] obtain m where wenzelm@56778: m: "m > 0" "\z. \z. cmod z \ 1 \ cmod (poly ds z) \ m" by blast wenzelm@56795: have dm: "cmod d / m > 0" wenzelm@56795: using False m(1) by (simp add: field_simps) wenzelm@56778: from real_lbound_gt_zero[OF dm zero_less_one] obtain x where wenzelm@56778: x: "x > 0" "x < cmod d / m" "x < 1" by blast wenzelm@56778: let ?x = "complex_of_real x" wenzelm@56795: from x have cx: "?x \ 0" "cmod ?x \ 1" wenzelm@56795: by simp_all wenzelm@56778: from pCons.prems[rule_format, OF cx(1)] wenzelm@56795: have cth: "cmod (?x*poly ds ?x) = cmod d" wenzelm@56795: by (simp add: eq_diff_eq[symmetric]) wenzelm@56778: from m(2)[rule_format, OF cx(2)] x(1) wenzelm@56778: have th0: "cmod (?x*poly ds ?x) \ x*m" wenzelm@56778: by (simp add: norm_mult) wenzelm@56795: from x(2) m(1) have "x * m < cmod d" wenzelm@56795: by (simp add: field_simps) wenzelm@56795: with th0 have "cmod (?x*poly ds ?x) \ cmod d" wenzelm@56795: by auto wenzelm@56795: with cth show ?thesis wenzelm@56795: by blast wenzelm@56778: qed wenzelm@56778: qed wenzelm@56778: } wenzelm@56795: then have nc: "\ constant (poly (pCons c cs))" wenzelm@56795: using pCons.prems False by blast wenzelm@56778: from fundamental_theorem_of_algebra[OF nc] show ?thesis . wenzelm@56778: qed wenzelm@56778: qed chaieb@26123: huffman@29464: webertj@37093: subsection{* Nullstellensatz, degrees and divisibility of polynomials *} chaieb@26123: chaieb@26123: lemma nullstellensatz_lemma: huffman@29464: fixes p :: "complex poly" chaieb@26123: assumes "\x. poly p x = 0 \ poly q x = 0" wenzelm@56776: and "degree p = n" wenzelm@56776: and "n \ 0" huffman@29464: shows "p dvd (q ^ n)" wenzelm@56776: using assms wenzelm@56776: proof (induct n arbitrary: p q rule: nat_less_induct) wenzelm@56776: fix n :: nat wenzelm@56776: fix p q :: "complex poly" chaieb@26123: assume IH: "\mp q. chaieb@26123: (\x. poly p x = (0::complex) \ poly q x = 0) \ huffman@29464: degree p = m \ m \ 0 \ p dvd (q ^ m)" huffman@30488: and pq0: "\x. poly p x = 0 \ poly q x = 0" wenzelm@56778: and dpn: "degree p = n" wenzelm@56778: and n0: "n \ 0" huffman@29464: from dpn n0 have pne: "p \ 0" by auto huffman@29464: let ?ths = "p dvd (q ^ n)" wenzelm@56778: { wenzelm@56778: fix a wenzelm@56778: assume a: "poly p a = 0" wenzelm@56778: { wenzelm@56778: assume oa: "order a p \ 0" chaieb@26123: let ?op = "order a p" wenzelm@56778: from pne have ap: "([:- a, 1:] ^ ?op) dvd p" "\ [:- a, 1:] ^ (Suc ?op) dvd p" wenzelm@56778: using order by blast+ huffman@29464: note oop = order_degree[OF pne, unfolded dpn] wenzelm@56778: { wenzelm@56778: assume q0: "q = 0" wenzelm@56778: then have ?ths using n0 wenzelm@56778: by (simp add: power_0_left) wenzelm@56778: } chaieb@26123: moreover wenzelm@56778: { wenzelm@56778: assume q0: "q \ 0" wenzelm@32960: from pq0[rule_format, OF a, unfolded poly_eq_0_iff_dvd] wenzelm@32960: obtain r where r: "q = [:- a, 1:] * r" by (rule dvdE) wenzelm@56778: from ap(1) obtain s where s: "p = [:- a, 1:] ^ ?op * s" wenzelm@56778: by (rule dvdE) wenzelm@56778: have sne: "s \ 0" using s pne by auto wenzelm@56778: { wenzelm@56778: assume ds0: "degree s = 0" wenzelm@51541: from ds0 obtain k where kpn: "s = [:k:]" wenzelm@51541: by (cases s) (auto split: if_splits) huffman@29464: from sne kpn have k: "k \ 0" by simp wenzelm@32960: let ?w = "([:1/k:] * ([:-a,1:] ^ (n - ?op))) * (r ^ n)" lp15@55358: have "q ^ n = p * ?w" wenzelm@56795: apply (subst r) wenzelm@56795: apply (subst s) wenzelm@56795: apply (subst kpn) wenzelm@56778: using k oop [of a] wenzelm@56795: apply (subst power_mult_distrib) wenzelm@56795: apply simp wenzelm@56795: apply (subst power_add [symmetric]) wenzelm@56795: apply simp huffman@29464: done wenzelm@56795: then have ?ths wenzelm@56795: unfolding dvd_def by blast wenzelm@56778: } wenzelm@32960: moreover wenzelm@56778: { wenzelm@56778: assume ds0: "degree s \ 0" wenzelm@32960: from ds0 sne dpn s oa wenzelm@56778: have dsn: "degree s < n" wenzelm@56778: apply auto huffman@29464: apply (erule ssubst) huffman@29464: apply (simp add: degree_mult_eq degree_linear_power) huffman@29464: done wenzelm@56778: { wenzelm@56778: fix x assume h: "poly s x = 0" wenzelm@56778: { wenzelm@56778: assume xa: "x = a" wenzelm@56778: from h[unfolded xa poly_eq_0_iff_dvd] obtain u where u: "s = [:- a, 1:] * u" wenzelm@56778: by (rule dvdE) wenzelm@32960: have "p = [:- a, 1:] ^ (Suc ?op) * u" wenzelm@56795: apply (subst s) wenzelm@56795: apply (subst u) haftmann@57514: apply (simp only: power_Suc ac_simps) wenzelm@56795: done wenzelm@56795: with ap(2)[unfolded dvd_def] have False wenzelm@56795: by blast wenzelm@56778: } wenzelm@32960: note xa = this wenzelm@56795: from h have "poly p x = 0" wenzelm@56795: by (subst s) simp wenzelm@56795: with pq0 have "poly q x = 0" wenzelm@56795: by blast wenzelm@32960: with r xa have "poly r x = 0" wenzelm@56778: by auto wenzelm@56778: } wenzelm@32960: note impth = this wenzelm@32960: from IH[rule_format, OF dsn, of s r] impth ds0 wenzelm@56795: have "s dvd (r ^ (degree s))" wenzelm@56795: by blast wenzelm@32960: then obtain u where u: "r ^ (degree s) = s * u" .. wenzelm@56778: then have u': "\x. poly s x * poly u x = poly r x ^ degree s" huffman@29470: by (simp only: poly_mult[symmetric] poly_power[symmetric]) wenzelm@32960: let ?w = "(u * ([:-a,1:] ^ (n - ?op))) * (r ^ (n - degree s))" wenzelm@32960: from oop[of a] dsn have "q ^ n = p * ?w" huffman@29464: apply - wenzelm@56795: apply (subst s) wenzelm@56795: apply (subst r) huffman@29464: apply (simp only: power_mult_distrib) haftmann@57512: apply (subst mult.assoc [where b=s]) haftmann@57512: apply (subst mult.assoc [where a=u]) haftmann@57512: apply (subst mult.assoc [where b=u, symmetric]) huffman@29464: apply (subst u [symmetric]) haftmann@57514: apply (simp add: ac_simps power_add [symmetric]) huffman@29464: done wenzelm@56795: then have ?ths wenzelm@56795: unfolding dvd_def by blast wenzelm@56778: } wenzelm@56778: ultimately have ?ths by blast wenzelm@56778: } wenzelm@56778: ultimately have ?ths by blast wenzelm@56778: } wenzelm@56778: then have ?ths using a order_root pne by blast wenzelm@56778: } chaieb@26123: moreover wenzelm@56778: { wenzelm@56778: assume exa: "\ (\a. poly p a = 0)" wenzelm@56778: from fundamental_theorem_of_algebra_alt[of p] exa wenzelm@56778: obtain c where ccs: "c \ 0" "p = pCons c 0" wenzelm@56778: by blast wenzelm@56778: then have pp: "\x. poly p x = c" wenzelm@56778: by simp huffman@29464: let ?w = "[:1/c:] * (q ^ n)" wenzelm@56778: from ccs have "(q ^ n) = (p * ?w)" wenzelm@56778: by simp wenzelm@56778: then have ?ths wenzelm@56778: unfolding dvd_def by blast wenzelm@56778: } chaieb@26123: ultimately show ?ths by blast chaieb@26123: qed chaieb@26123: chaieb@26123: lemma nullstellensatz_univariate: huffman@30488: "(\x. poly p x = (0::complex) \ poly q x = 0) \ huffman@29464: p dvd (q ^ (degree p)) \ (p = 0 \ q = 0)" wenzelm@56776: proof - wenzelm@56778: { wenzelm@56778: assume pe: "p = 0" wenzelm@56778: then have eq: "(\x. poly p x = (0::complex) \ poly q x = 0) \ q = 0" haftmann@52380: by (auto simp add: poly_all_0_iff_0) wenzelm@56778: { wenzelm@56778: assume "p dvd (q ^ (degree p))" huffman@29464: then obtain r where r: "q ^ (degree p) = p * r" .. wenzelm@56778: from r pe have False by simp wenzelm@56778: } wenzelm@56778: with eq pe have ?thesis by blast wenzelm@56778: } chaieb@26123: moreover wenzelm@56778: { wenzelm@56778: assume pe: "p \ 0" wenzelm@56778: { wenzelm@56778: assume dp: "degree p = 0" wenzelm@56778: then obtain k where k: "p = [:k:]" "k \ 0" using pe wenzelm@51541: by (cases p) (simp split: if_splits) wenzelm@56778: then have th1: "\x. poly p x \ 0" wenzelm@56778: by simp huffman@29464: from k dp have "q ^ (degree p) = p * [:1/k:]" huffman@29464: by (simp add: one_poly_def) wenzelm@56778: then have th2: "p dvd (q ^ (degree p))" .. wenzelm@56795: from th1 th2 pe have ?thesis wenzelm@56795: by blast wenzelm@56778: } chaieb@26123: moreover wenzelm@56778: { wenzelm@56778: assume dp: "degree p \ 0" wenzelm@56778: then obtain n where n: "degree p = Suc n " wenzelm@56778: by (cases "degree p") auto wenzelm@56778: { wenzelm@56778: assume "p dvd (q ^ (Suc n))" wenzelm@32960: then obtain u where u: "q ^ (Suc n) = p * u" .. wenzelm@56778: { wenzelm@56778: fix x wenzelm@56778: assume h: "poly p x = 0" "poly q x \ 0" wenzelm@56778: then have "poly (q ^ (Suc n)) x \ 0" wenzelm@56778: by simp wenzelm@56778: then have False using u h(1) wenzelm@56778: by (simp only: poly_mult) simp wenzelm@56778: } wenzelm@56778: } wenzelm@56778: with n nullstellensatz_lemma[of p q "degree p"] dp wenzelm@56778: have ?thesis by auto wenzelm@56778: } wenzelm@56778: ultimately have ?thesis by blast wenzelm@56778: } chaieb@26123: ultimately show ?thesis by blast chaieb@26123: qed chaieb@26123: wenzelm@56795: text {* Useful lemma *} chaieb@26123: huffman@29464: lemma constant_degree: huffman@29464: fixes p :: "'a::{idom,ring_char_0} poly" huffman@29464: shows "constant (poly p) \ degree p = 0" (is "?lhs = ?rhs") chaieb@26123: proof chaieb@26123: assume l: ?lhs huffman@29464: from l[unfolded constant_def, rule_format, of _ "0"] wenzelm@56776: have th: "poly p = poly [:poly p 0:]" wenzelm@56776: by auto wenzelm@56776: then have "p = [:poly p 0:]" wenzelm@56776: by (simp add: poly_eq_poly_eq_iff) wenzelm@56776: then have "degree p = degree [:poly p 0:]" wenzelm@56776: by simp wenzelm@56776: then show ?rhs wenzelm@56776: by simp chaieb@26123: next chaieb@26123: assume r: ?rhs huffman@29464: then obtain k where "p = [:k:]" wenzelm@51541: by (cases p) (simp split: if_splits) wenzelm@56776: then show ?lhs wenzelm@56776: unfolding constant_def by auto chaieb@26123: qed chaieb@26123: wenzelm@56776: lemma divides_degree: wenzelm@56776: assumes pq: "p dvd (q:: complex poly)" huffman@29464: shows "degree p \ degree q \ q = 0" wenzelm@56776: by (metis dvd_imp_degree_le pq) chaieb@26123: wenzelm@56795: text {* Arithmetic operations on multivariate polynomials. *} chaieb@26123: huffman@30488: lemma mpoly_base_conv: wenzelm@56778: fixes x :: "'a::comm_ring_1" lp15@55735: shows "0 = poly 0 x" "c = poly [:c:] x" "x = poly [:0,1:] x" lp15@55735: by simp_all chaieb@26123: huffman@30488: lemma mpoly_norm_conv: wenzelm@56778: fixes x :: "'a::comm_ring_1" wenzelm@56776: shows "poly [:0:] x = poly 0 x" "poly [:poly 0 y:] x = poly 0 x" wenzelm@56776: by simp_all chaieb@26123: huffman@30488: lemma mpoly_sub_conv: wenzelm@56778: fixes x :: "'a::comm_ring_1" lp15@55735: shows "poly p x - poly q x = poly p x + -1 * poly q x" haftmann@54230: by simp chaieb@26123: wenzelm@56778: lemma poly_pad_rule: "poly p x = 0 \ poly (pCons 0 p) x = 0" wenzelm@56778: by simp chaieb@26123: lp15@55735: lemma poly_cancel_eq_conv: wenzelm@56778: fixes x :: "'a::field" wenzelm@56795: shows "x = 0 \ a \ 0 \ y = 0 \ a * y - b * x = 0" lp15@55735: by auto chaieb@26123: huffman@30488: lemma poly_divides_pad_rule: wenzelm@56778: fixes p:: "('a::comm_ring_1) poly" huffman@29464: assumes pq: "p dvd q" wenzelm@56778: shows "p dvd (pCons 0 q)" wenzelm@56778: proof - huffman@29464: have "pCons 0 q = q * [:0,1:]" by simp huffman@29464: then have "q dvd (pCons 0 q)" .. huffman@29464: with pq show ?thesis by (rule dvd_trans) chaieb@26123: qed chaieb@26123: huffman@30488: lemma poly_divides_conv0: wenzelm@56778: fixes p:: "'a::field poly" wenzelm@56776: assumes lgpq: "degree q < degree p" wenzelm@56776: and lq: "p \ 0" wenzelm@56776: shows "p dvd q \ q = 0" (is "?lhs \ ?rhs") wenzelm@56776: proof wenzelm@56776: assume r: ?rhs wenzelm@56776: then have "q = p * 0" by simp wenzelm@56776: then show ?lhs .. wenzelm@56776: next wenzelm@56776: assume l: ?lhs wenzelm@56778: show ?rhs wenzelm@56778: proof (cases "q = 0") wenzelm@56778: case True wenzelm@56778: then show ?thesis by simp wenzelm@56778: next wenzelm@56776: assume q0: "q \ 0" wenzelm@56776: from l q0 have "degree p \ degree q" wenzelm@56776: by (rule dvd_imp_degree_le) wenzelm@56778: with lgpq show ?thesis by simp wenzelm@56778: qed chaieb@26123: qed chaieb@26123: huffman@30488: lemma poly_divides_conv1: wenzelm@56778: fixes p :: "'a::field poly" wenzelm@56776: assumes a0: "a \ 0" wenzelm@56776: and pp': "p dvd p'" wenzelm@56776: and qrp': "smult a q - p' = r" wenzelm@56776: shows "p dvd q \ p dvd r" (is "?lhs \ ?rhs") wenzelm@56776: proof huffman@29464: from pp' obtain t where t: "p' = p * t" .. wenzelm@56776: { wenzelm@56776: assume l: ?lhs huffman@29464: then obtain u where u: "q = p * u" .. wenzelm@56776: have "r = p * (smult a u - t)" wenzelm@56776: using u qrp' [symmetric] t by (simp add: algebra_simps) wenzelm@56776: then show ?rhs .. wenzelm@56776: next wenzelm@56776: assume r: ?rhs huffman@29464: then obtain u where u: "r = p * u" .. huffman@29464: from u [symmetric] t qrp' [symmetric] a0 wenzelm@51541: have "q = p * smult (1/a) (u + t)" by (simp add: algebra_simps) wenzelm@56776: then show ?lhs .. wenzelm@56776: } chaieb@26123: qed chaieb@26123: chaieb@26123: lemma basic_cqe_conv1: lp15@55358: "(\x. poly p x = 0 \ poly 0 x \ 0) \ False" lp15@55358: "(\x. poly 0 x \ 0) \ False" wenzelm@56776: "(\x. poly [:c:] x \ 0) \ c \ 0" lp15@55358: "(\x. poly 0 x = 0) \ True" wenzelm@56776: "(\x. poly [:c:] x = 0) \ c = 0" wenzelm@56776: by simp_all chaieb@26123: huffman@30488: lemma basic_cqe_conv2: wenzelm@56795: assumes l: "p \ 0" wenzelm@56795: shows "\x. poly (pCons a (pCons b p)) x = (0::complex)" wenzelm@56776: proof - wenzelm@56776: { wenzelm@56776: fix h t wenzelm@56776: assume h: "h \ 0" "t = 0" and "pCons a (pCons b p) = pCons h t" wenzelm@56776: with l have False by simp wenzelm@56776: } wenzelm@56776: then have th: "\ (\ h t. h \ 0 \ t = 0 \ pCons a (pCons b p) = pCons h t)" chaieb@26123: by blast wenzelm@56776: from fundamental_theorem_of_algebra_alt[OF th] show ?thesis wenzelm@56776: by auto chaieb@26123: qed chaieb@26123: wenzelm@56776: lemma basic_cqe_conv_2b: "(\x. poly p x \ (0::complex)) \ p \ 0" wenzelm@56776: by (metis poly_all_0_iff_0) chaieb@26123: chaieb@26123: lemma basic_cqe_conv3: huffman@29464: fixes p q :: "complex poly" huffman@30488: assumes l: "p \ 0" wenzelm@56795: shows "(\x. poly (pCons a p) x = 0 \ poly q x \ 0) \ \ (pCons a p) dvd (q ^ psize p)" lp15@55358: proof - wenzelm@56776: from l have dp: "degree (pCons a p) = psize p" wenzelm@56776: by (simp add: psize_def) huffman@29464: from nullstellensatz_univariate[of "pCons a p" q] l lp15@55358: show ?thesis lp15@55358: by (metis dp pCons_eq_0_iff) chaieb@26123: qed chaieb@26123: chaieb@26123: lemma basic_cqe_conv4: huffman@29464: fixes p q :: "complex poly" lp15@55358: assumes h: "\x. poly (q ^ n) x = poly r x" lp15@55358: shows "p dvd (q ^ n) \ p dvd r" wenzelm@56776: proof - wenzelm@56776: from h have "poly (q ^ n) = poly r" wenzelm@56776: by auto wenzelm@56776: then have "(q ^ n) = r" wenzelm@56776: by (simp add: poly_eq_poly_eq_iff) wenzelm@56776: then show "p dvd (q ^ n) \ p dvd r" wenzelm@56776: by simp chaieb@26123: qed chaieb@26123: lp15@55735: lemma poly_const_conv: wenzelm@56778: fixes x :: "'a::comm_ring_1" wenzelm@56776: shows "poly [:c:] x = y \ c = y" wenzelm@56776: by simp chaieb@26123: huffman@29464: end