1.1 --- a/src/HOL/Complex/Fundamental_Theorem_Algebra.thy Tue Dec 30 08:18:54 2008 +0100
1.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
1.3 @@ -1,1329 +0,0 @@
1.4 -(* Title: Fundamental_Theorem_Algebra.thy
1.5 - Author: Amine Chaieb
1.6 -*)
1.7 -
1.8 -header{*Fundamental Theorem of Algebra*}
1.9 -
1.10 -theory Fundamental_Theorem_Algebra
1.11 -imports "~~/src/HOL/Univ_Poly" "~~/src/HOL/Library/Dense_Linear_Order" "~~/src/HOL/Complex"
1.12 -begin
1.13 -
1.14 -subsection {* Square root of complex numbers *}
1.15 -definition csqrt :: "complex \<Rightarrow> complex" where
1.16 -"csqrt z = (if Im z = 0 then
1.17 - if 0 \<le> Re z then Complex (sqrt(Re z)) 0
1.18 - else Complex 0 (sqrt(- Re z))
1.19 - else Complex (sqrt((cmod z + Re z) /2))
1.20 - ((Im z / abs(Im z)) * sqrt((cmod z - Re z) /2)))"
1.21 -
1.22 -lemma csqrt[algebra]: "csqrt z ^ 2 = z"
1.23 -proof-
1.24 - obtain x y where xy: "z = Complex x y" by (cases z, simp_all)
1.25 - {assume y0: "y = 0"
1.26 - {assume x0: "x \<ge> 0"
1.27 - then have ?thesis using y0 xy real_sqrt_pow2[OF x0]
1.28 - by (simp add: csqrt_def power2_eq_square)}
1.29 - moreover
1.30 - {assume "\<not> x \<ge> 0" hence x0: "- x \<ge> 0" by arith
1.31 - then have ?thesis using y0 xy real_sqrt_pow2[OF x0]
1.32 - by (simp add: csqrt_def power2_eq_square) }
1.33 - ultimately have ?thesis by blast}
1.34 - moreover
1.35 - {assume y0: "y\<noteq>0"
1.36 - {fix x y
1.37 - let ?z = "Complex x y"
1.38 - from abs_Re_le_cmod[of ?z] have tha: "abs x \<le> cmod ?z" by auto
1.39 - hence "cmod ?z - x \<ge> 0" "cmod ?z + x \<ge> 0" by arith+
1.40 - hence "(sqrt (x * x + y * y) + x) / 2 \<ge> 0" "(sqrt (x * x + y * y) - x) / 2 \<ge> 0" by (simp_all add: power2_eq_square) }
1.41 - note th = this
1.42 - have sq4: "\<And>x::real. x^2 / 4 = (x / 2) ^ 2"
1.43 - by (simp add: power2_eq_square)
1.44 - from th[of x y]
1.45 - have sq4': "sqrt (((sqrt (x * x + y * y) + x)^2 / 4)) = (sqrt (x * x + y * y) + x) / 2" "sqrt (((sqrt (x * x + y * y) - x)^2 / 4)) = (sqrt (x * x + y * y) - x) / 2" unfolding sq4 by simp_all
1.46 - then have th1: "sqrt ((sqrt (x * x + y * y) + x) * (sqrt (x * x + y * y) + x) / 4) - sqrt ((sqrt (x * x + y * y) - x) * (sqrt (x * x + y * y) - x) / 4) = x"
1.47 - unfolding power2_eq_square by simp
1.48 - have "sqrt 4 = sqrt (2^2)" by simp
1.49 - hence sqrt4: "sqrt 4 = 2" by (simp only: real_sqrt_abs)
1.50 - have th2: "2 *(y * sqrt ((sqrt (x * x + y * y) - x) * (sqrt (x * x + y * y) + x) / 4)) / \<bar>y\<bar> = y"
1.51 - using iffD2[OF real_sqrt_pow2_iff sum_power2_ge_zero[of x y]] y0
1.52 - unfolding power2_eq_square
1.53 - by (simp add: ring_simps real_sqrt_divide sqrt4)
1.54 - from y0 xy have ?thesis apply (simp add: csqrt_def power2_eq_square)
1.55 - apply (simp add: real_sqrt_sum_squares_mult_ge_zero[of x y] real_sqrt_pow2[OF th(1)[of x y], unfolded power2_eq_square] real_sqrt_pow2[OF th(2)[of x y], unfolded power2_eq_square] real_sqrt_mult[symmetric])
1.56 - using th1 th2 ..}
1.57 - ultimately show ?thesis by blast
1.58 -qed
1.59 -
1.60 -
1.61 -subsection{* More lemmas about module of complex numbers *}
1.62 -
1.63 -lemma complex_of_real_power: "complex_of_real x ^ n = complex_of_real (x^n)"
1.64 - by (rule of_real_power [symmetric])
1.65 -
1.66 -lemma real_down2: "(0::real) < d1 \<Longrightarrow> 0 < d2 ==> EX e. 0 < e & e < d1 & e < d2"
1.67 - apply ferrack apply arith done
1.68 -
1.69 -text{* The triangle inequality for cmod *}
1.70 -lemma complex_mod_triangle_sub: "cmod w \<le> cmod (w + z) + norm z"
1.71 - using complex_mod_triangle_ineq2[of "w + z" "-z"] by auto
1.72 -
1.73 -subsection{* Basic lemmas about complex polynomials *}
1.74 -
1.75 -lemma poly_bound_exists:
1.76 - shows "\<exists>m. m > 0 \<and> (\<forall>z. cmod z <= r \<longrightarrow> cmod (poly p z) \<le> m)"
1.77 -proof(induct p)
1.78 - case Nil thus ?case by (rule exI[where x=1], simp)
1.79 -next
1.80 - case (Cons c cs)
1.81 - from Cons.hyps obtain m where m: "\<forall>z. cmod z \<le> r \<longrightarrow> cmod (poly cs z) \<le> m"
1.82 - by blast
1.83 - let ?k = " 1 + cmod c + \<bar>r * m\<bar>"
1.84 - have kp: "?k > 0" using abs_ge_zero[of "r*m"] norm_ge_zero[of c] by arith
1.85 - {fix z
1.86 - assume H: "cmod z \<le> r"
1.87 - from m H have th: "cmod (poly cs z) \<le> m" by blast
1.88 - from H have rp: "r \<ge> 0" using norm_ge_zero[of z] by arith
1.89 - have "cmod (poly (c # cs) z) \<le> cmod c + cmod (z* poly cs z)"
1.90 - using norm_triangle_ineq[of c "z* poly cs z"] by simp
1.91 - also have "\<dots> \<le> cmod c + r*m" using mult_mono[OF H th rp norm_ge_zero[of "poly cs z"]] by (simp add: norm_mult)
1.92 - also have "\<dots> \<le> ?k" by simp
1.93 - finally have "cmod (poly (c # cs) z) \<le> ?k" .}
1.94 - with kp show ?case by blast
1.95 -qed
1.96 -
1.97 -
1.98 -text{* Offsetting the variable in a polynomial gives another of same degree *}
1.99 - (* FIXME : Lemma holds also in locale --- fix it later *)
1.100 -lemma poly_offset_lemma:
1.101 - shows "\<exists>b q. (length q = length p) \<and> (\<forall>x. poly (b#q) (x::complex) = (a + x) * poly p x)"
1.102 -proof(induct p)
1.103 - case Nil thus ?case by simp
1.104 -next
1.105 - case (Cons c cs)
1.106 - from Cons.hyps obtain b q where
1.107 - bq: "length q = length cs" "\<forall>x. poly (b # q) x = (a + x) * poly cs x"
1.108 - by blast
1.109 - let ?b = "a*c"
1.110 - let ?q = "(b+c)#q"
1.111 - have lg: "length ?q = length (c#cs)" using bq(1) by simp
1.112 - {fix x
1.113 - from bq(2)[rule_format, of x]
1.114 - have "x*poly (b # q) x = x*((a + x) * poly cs x)" by simp
1.115 - hence "poly (?b# ?q) x = (a + x) * poly (c # cs) x"
1.116 - by (simp add: ring_simps)}
1.117 - with lg show ?case by blast
1.118 -qed
1.119 -
1.120 - (* FIXME : This one too*)
1.121 -lemma poly_offset: "\<exists> q. length q = length p \<and> (\<forall>x. poly q (x::complex) = poly p (a + x))"
1.122 -proof (induct p)
1.123 - case Nil thus ?case by simp
1.124 -next
1.125 - case (Cons c cs)
1.126 - from Cons.hyps obtain q where q: "length q = length cs" "\<forall>x. poly q x = poly cs (a + x)" by blast
1.127 - from poly_offset_lemma[of q a] obtain b p where
1.128 - bp: "length p = length q" "\<forall>x. poly (b # p) x = (a + x) * poly q x"
1.129 - by blast
1.130 - thus ?case using q bp by - (rule exI[where x="(c + b)#p"], simp)
1.131 -qed
1.132 -
1.133 -text{* An alternative useful formulation of completeness of the reals *}
1.134 -lemma real_sup_exists: assumes ex: "\<exists>x. P x" and bz: "\<exists>z. \<forall>x. P x \<longrightarrow> x < z"
1.135 - shows "\<exists>(s::real). \<forall>y. (\<exists>x. P x \<and> y < x) \<longleftrightarrow> y < s"
1.136 -proof-
1.137 - from ex bz obtain x Y where x: "P x" and Y: "\<And>x. P x \<Longrightarrow> x < Y" by blast
1.138 - from ex have thx:"\<exists>x. x \<in> Collect P" by blast
1.139 - from bz have thY: "\<exists>Y. isUb UNIV (Collect P) Y"
1.140 - by(auto simp add: isUb_def isLub_def setge_def setle_def leastP_def Ball_def order_le_less)
1.141 - from reals_complete[OF thx thY] obtain L where L: "isLub UNIV (Collect P) L"
1.142 - by blast
1.143 - from Y[OF x] have xY: "x < Y" .
1.144 - from L have L': "\<forall>x. P x \<longrightarrow> x \<le> L" by (auto simp add: isUb_def isLub_def setge_def setle_def leastP_def Ball_def)
1.145 - from Y have Y': "\<forall>x. P x \<longrightarrow> x \<le> Y"
1.146 - apply (clarsimp, atomize (full)) by auto
1.147 - from L Y' have "L \<le> Y" by (auto simp add: isUb_def isLub_def setge_def setle_def leastP_def Ball_def)
1.148 - {fix y
1.149 - {fix z assume z: "P z" "y < z"
1.150 - from L' z have "y < L" by auto }
1.151 - moreover
1.152 - {assume yL: "y < L" "\<forall>z. P z \<longrightarrow> \<not> y < z"
1.153 - hence nox: "\<forall>z. P z \<longrightarrow> y \<ge> z" by auto
1.154 - from nox L have "y \<ge> L" by (auto simp add: isUb_def isLub_def setge_def setle_def leastP_def Ball_def)
1.155 - with yL(1) have False by arith}
1.156 - ultimately have "(\<exists>x. P x \<and> y < x) \<longleftrightarrow> y < L" by blast}
1.157 - thus ?thesis by blast
1.158 -qed
1.159 -
1.160 -
1.161 -subsection{* Some theorems about Sequences*}
1.162 -text{* Given a binary function @{text "f:: nat \<Rightarrow> 'a \<Rightarrow> 'a"}, its values are uniquely determined by a function g *}
1.163 -
1.164 -lemma num_Axiom: "EX! g. g 0 = e \<and> (\<forall>n. g (Suc n) = f n (g n))"
1.165 - unfolding Ex1_def
1.166 - apply (rule_tac x="nat_rec e f" in exI)
1.167 - apply (rule conjI)+
1.168 -apply (rule def_nat_rec_0, simp)
1.169 -apply (rule allI, rule def_nat_rec_Suc, simp)
1.170 -apply (rule allI, rule impI, rule ext)
1.171 -apply (erule conjE)
1.172 -apply (induct_tac x)
1.173 -apply (simp add: nat_rec_0)
1.174 -apply (erule_tac x="n" in allE)
1.175 -apply (simp)
1.176 -done
1.177 -
1.178 - text{* An equivalent formulation of monotony -- Not used here, but might be useful *}
1.179 -lemma mono_Suc: "mono f = (\<forall>n. (f n :: 'a :: order) \<le> f (Suc n))"
1.180 -unfolding mono_def
1.181 -proof auto
1.182 - fix A B :: nat
1.183 - assume H: "\<forall>n. f n \<le> f (Suc n)" "A \<le> B"
1.184 - hence "\<exists>k. B = A + k" apply - apply (thin_tac "\<forall>n. f n \<le> f (Suc n)")
1.185 - by presburger
1.186 - then obtain k where k: "B = A + k" by blast
1.187 - {fix a k
1.188 - have "f a \<le> f (a + k)"
1.189 - proof (induct k)
1.190 - case 0 thus ?case by simp
1.191 - next
1.192 - case (Suc k)
1.193 - from Suc.hyps H(1)[rule_format, of "a + k"] show ?case by simp
1.194 - qed}
1.195 - with k show "f A \<le> f B" by blast
1.196 -qed
1.197 -
1.198 -text{* for any sequence, there is a mootonic subsequence *}
1.199 -lemma seq_monosub: "\<exists>f. subseq f \<and> monoseq (\<lambda> n. (s (f n)))"
1.200 -proof-
1.201 - {assume H: "\<forall>n. \<exists>p >n. \<forall> m\<ge>p. s m \<le> s p"
1.202 - let ?P = "\<lambda> p n. p > n \<and> (\<forall>m \<ge> p. s m \<le> s p)"
1.203 - from num_Axiom[of "SOME p. ?P p 0" "\<lambda>p n. SOME p. ?P p n"]
1.204 - obtain f where f: "f 0 = (SOME p. ?P p 0)" "\<forall>n. f (Suc n) = (SOME p. ?P p (f n))" by blast
1.205 - have "?P (f 0) 0" unfolding f(1) some_eq_ex[of "\<lambda>p. ?P p 0"]
1.206 - using H apply -
1.207 - apply (erule allE[where x=0], erule exE, rule_tac x="p" in exI)
1.208 - unfolding order_le_less by blast
1.209 - hence f0: "f 0 > 0" "\<forall>m \<ge> f 0. s m \<le> s (f 0)" by blast+
1.210 - {fix n
1.211 - have "?P (f (Suc n)) (f n)"
1.212 - unfolding f(2)[rule_format, of n] some_eq_ex[of "\<lambda>p. ?P p (f n)"]
1.213 - using H apply -
1.214 - apply (erule allE[where x="f n"], erule exE, rule_tac x="p" in exI)
1.215 - unfolding order_le_less by blast
1.216 - hence "f (Suc n) > f n" "\<forall>m \<ge> f (Suc n). s m \<le> s (f (Suc n))" by blast+}
1.217 - note fSuc = this
1.218 - {fix p q assume pq: "p \<ge> f q"
1.219 - have "s p \<le> s(f(q))" using f0(2)[rule_format, of p] pq fSuc
1.220 - by (cases q, simp_all) }
1.221 - note pqth = this
1.222 - {fix q
1.223 - have "f (Suc q) > f q" apply (induct q)
1.224 - using f0(1) fSuc(1)[of 0] apply simp by (rule fSuc(1))}
1.225 - note fss = this
1.226 - from fss have th1: "subseq f" unfolding subseq_Suc_iff ..
1.227 - {fix a b
1.228 - have "f a \<le> f (a + b)"
1.229 - proof(induct b)
1.230 - case 0 thus ?case by simp
1.231 - next
1.232 - case (Suc b)
1.233 - from fSuc(1)[of "a + b"] Suc.hyps show ?case by simp
1.234 - qed}
1.235 - note fmon0 = this
1.236 - have "monoseq (\<lambda>n. s (f n))"
1.237 - proof-
1.238 - {fix n
1.239 - have "s (f n) \<ge> s (f (Suc n))"
1.240 - proof(cases n)
1.241 - case 0
1.242 - assume n0: "n = 0"
1.243 - from fSuc(1)[of 0] have th0: "f 0 \<le> f (Suc 0)" by simp
1.244 - from f0(2)[rule_format, OF th0] show ?thesis using n0 by simp
1.245 - next
1.246 - case (Suc m)
1.247 - assume m: "n = Suc m"
1.248 - from fSuc(1)[of n] m have th0: "f (Suc m) \<le> f (Suc (Suc m))" by simp
1.249 - from m fSuc(2)[rule_format, OF th0] show ?thesis by simp
1.250 - qed}
1.251 - thus "monoseq (\<lambda>n. s (f n))" unfolding monoseq_Suc by blast
1.252 - qed
1.253 - with th1 have ?thesis by blast}
1.254 - moreover
1.255 - {fix N assume N: "\<forall>p >N. \<exists> m\<ge>p. s m > s p"
1.256 - {fix p assume p: "p \<ge> Suc N"
1.257 - hence pN: "p > N" by arith with N obtain m where m: "m \<ge> p" "s m > s p" by blast
1.258 - have "m \<noteq> p" using m(2) by auto
1.259 - with m have "\<exists>m>p. s p < s m" by - (rule exI[where x=m], auto)}
1.260 - note th0 = this
1.261 - let ?P = "\<lambda>m x. m > x \<and> s x < s m"
1.262 - from num_Axiom[of "SOME x. ?P x (Suc N)" "\<lambda>m x. SOME y. ?P y x"]
1.263 - obtain f where f: "f 0 = (SOME x. ?P x (Suc N))"
1.264 - "\<forall>n. f (Suc n) = (SOME m. ?P m (f n))" by blast
1.265 - have "?P (f 0) (Suc N)" unfolding f(1) some_eq_ex[of "\<lambda>p. ?P p (Suc N)"]
1.266 - using N apply -
1.267 - apply (erule allE[where x="Suc N"], clarsimp)
1.268 - apply (rule_tac x="m" in exI)
1.269 - apply auto
1.270 - apply (subgoal_tac "Suc N \<noteq> m")
1.271 - apply simp
1.272 - apply (rule ccontr, simp)
1.273 - done
1.274 - hence f0: "f 0 > Suc N" "s (Suc N) < s (f 0)" by blast+
1.275 - {fix n
1.276 - have "f n > N \<and> ?P (f (Suc n)) (f n)"
1.277 - unfolding f(2)[rule_format, of n] some_eq_ex[of "\<lambda>p. ?P p (f n)"]
1.278 - proof (induct n)
1.279 - case 0 thus ?case
1.280 - using f0 N apply auto
1.281 - apply (erule allE[where x="f 0"], clarsimp)
1.282 - apply (rule_tac x="m" in exI, simp)
1.283 - by (subgoal_tac "f 0 \<noteq> m", auto)
1.284 - next
1.285 - case (Suc n)
1.286 - from Suc.hyps have Nfn: "N < f n" by blast
1.287 - from Suc.hyps obtain m where m: "m > f n" "s (f n) < s m" by blast
1.288 - with Nfn have mN: "m > N" by arith
1.289 - note key = Suc.hyps[unfolded some_eq_ex[of "\<lambda>p. ?P p (f n)", symmetric] f(2)[rule_format, of n, symmetric]]
1.290 -
1.291 - from key have th0: "f (Suc n) > N" by simp
1.292 - from N[rule_format, OF th0]
1.293 - obtain m' where m': "m' \<ge> f (Suc n)" "s (f (Suc n)) < s m'" by blast
1.294 - have "m' \<noteq> f (Suc (n))" apply (rule ccontr) using m'(2) by auto
1.295 - hence "m' > f (Suc n)" using m'(1) by simp
1.296 - with key m'(2) show ?case by auto
1.297 - qed}
1.298 - note fSuc = this
1.299 - {fix n
1.300 - have "f n \<ge> Suc N \<and> f(Suc n) > f n \<and> s(f n) < s(f(Suc n))" using fSuc[of n] by auto
1.301 - hence "f n \<ge> Suc N" "f(Suc n) > f n" "s(f n) < s(f(Suc n))" by blast+}
1.302 - note thf = this
1.303 - have sqf: "subseq f" unfolding subseq_Suc_iff using thf by simp
1.304 - have "monoseq (\<lambda>n. s (f n))" unfolding monoseq_Suc using thf
1.305 - apply -
1.306 - apply (rule disjI1)
1.307 - apply auto
1.308 - apply (rule order_less_imp_le)
1.309 - apply blast
1.310 - done
1.311 - then have ?thesis using sqf by blast}
1.312 - ultimately show ?thesis unfolding linorder_not_less[symmetric] by blast
1.313 -qed
1.314 -
1.315 -lemma seq_suble: assumes sf: "subseq f" shows "n \<le> f n"
1.316 -proof(induct n)
1.317 - case 0 thus ?case by simp
1.318 -next
1.319 - case (Suc n)
1.320 - from sf[unfolded subseq_Suc_iff, rule_format, of n] Suc.hyps
1.321 - have "n < f (Suc n)" by arith
1.322 - thus ?case by arith
1.323 -qed
1.324 -
1.325 -subsection {* Fundamental theorem of algebra *}
1.326 -lemma unimodular_reduce_norm:
1.327 - assumes md: "cmod z = 1"
1.328 - shows "cmod (z + 1) < 1 \<or> cmod (z - 1) < 1 \<or> cmod (z + ii) < 1 \<or> cmod (z - ii) < 1"
1.329 -proof-
1.330 - obtain x y where z: "z = Complex x y " by (cases z, auto)
1.331 - from md z have xy: "x^2 + y^2 = 1" by (simp add: cmod_def)
1.332 - {assume C: "cmod (z + 1) \<ge> 1" "cmod (z - 1) \<ge> 1" "cmod (z + ii) \<ge> 1" "cmod (z - ii) \<ge> 1"
1.333 - from C z xy have "2*x \<le> 1" "2*x \<ge> -1" "2*y \<le> 1" "2*y \<ge> -1"
1.334 - by (simp_all add: cmod_def power2_eq_square ring_simps)
1.335 - hence "abs (2*x) \<le> 1" "abs (2*y) \<le> 1" by simp_all
1.336 - hence "(abs (2 * x))^2 <= 1^2" "(abs (2 * y)) ^2 <= 1^2"
1.337 - by - (rule power_mono, simp, simp)+
1.338 - hence th0: "4*x^2 \<le> 1" "4*y^2 \<le> 1"
1.339 - by (simp_all add: power2_abs power_mult_distrib)
1.340 - from add_mono[OF th0] xy have False by simp }
1.341 - thus ?thesis unfolding linorder_not_le[symmetric] by blast
1.342 -qed
1.343 -
1.344 -text{* Hence we can always reduce modulus of @{text "1 + b z^n"} if nonzero *}
1.345 -lemma reduce_poly_simple:
1.346 - assumes b: "b \<noteq> 0" and n: "n\<noteq>0"
1.347 - shows "\<exists>z. cmod (1 + b * z^n) < 1"
1.348 -using n
1.349 -proof(induct n rule: nat_less_induct)
1.350 - fix n
1.351 - assume IH: "\<forall>m<n. m \<noteq> 0 \<longrightarrow> (\<exists>z. cmod (1 + b * z ^ m) < 1)" and n: "n \<noteq> 0"
1.352 - let ?P = "\<lambda>z n. cmod (1 + b * z ^ n) < 1"
1.353 - {assume e: "even n"
1.354 - hence "\<exists>m. n = 2*m" by presburger
1.355 - then obtain m where m: "n = 2*m" by blast
1.356 - from n m have "m\<noteq>0" "m < n" by presburger+
1.357 - with IH[rule_format, of m] obtain z where z: "?P z m" by blast
1.358 - from z have "?P (csqrt z) n" by (simp add: m power_mult csqrt)
1.359 - hence "\<exists>z. ?P z n" ..}
1.360 - moreover
1.361 - {assume o: "odd n"
1.362 - from b have b': "b^2 \<noteq> 0" unfolding power2_eq_square by simp
1.363 - have "Im (inverse b) * (Im (inverse b) * \<bar>Im b * Im b + Re b * Re b\<bar>) +
1.364 - Re (inverse b) * (Re (inverse b) * \<bar>Im b * Im b + Re b * Re b\<bar>) =
1.365 - ((Re (inverse b))^2 + (Im (inverse b))^2) * \<bar>Im b * Im b + Re b * Re b\<bar>" by algebra
1.366 - also have "\<dots> = cmod (inverse b) ^2 * cmod b ^ 2"
1.367 - apply (simp add: cmod_def) using realpow_two_le_add_order[of "Re b" "Im b"]
1.368 - by (simp add: power2_eq_square)
1.369 - finally
1.370 - have th0: "Im (inverse b) * (Im (inverse b) * \<bar>Im b * Im b + Re b * Re b\<bar>) +
1.371 - Re (inverse b) * (Re (inverse b) * \<bar>Im b * Im b + Re b * Re b\<bar>) =
1.372 - 1"
1.373 - apply (simp add: power2_eq_square norm_mult[symmetric] norm_inverse[symmetric])
1.374 - using right_inverse[OF b']
1.375 - by (simp add: power2_eq_square[symmetric] power_inverse[symmetric] ring_simps)
1.376 - have th0: "cmod (complex_of_real (cmod b) / b) = 1"
1.377 - apply (simp add: complex_Re_mult cmod_def power2_eq_square Re_complex_of_real Im_complex_of_real divide_inverse ring_simps )
1.378 - by (simp add: real_sqrt_mult[symmetric] th0)
1.379 - from o have "\<exists>m. n = Suc (2*m)" by presburger+
1.380 - then obtain m where m: "n = Suc (2*m)" by blast
1.381 - from unimodular_reduce_norm[OF th0] o
1.382 - have "\<exists>v. cmod (complex_of_real (cmod b) / b + v^n) < 1"
1.383 - apply (cases "cmod (complex_of_real (cmod b) / b + 1) < 1", rule_tac x="1" in exI, simp)
1.384 - apply (cases "cmod (complex_of_real (cmod b) / b - 1) < 1", rule_tac x="-1" in exI, simp add: diff_def)
1.385 - apply (cases "cmod (complex_of_real (cmod b) / b + ii) < 1")
1.386 - apply (cases "even m", rule_tac x="ii" in exI, simp add: m power_mult)
1.387 - apply (rule_tac x="- ii" in exI, simp add: m power_mult)
1.388 - apply (cases "even m", rule_tac x="- ii" in exI, simp add: m power_mult diff_def)
1.389 - apply (rule_tac x="ii" in exI, simp add: m power_mult diff_def)
1.390 - done
1.391 - then obtain v where v: "cmod (complex_of_real (cmod b) / b + v^n) < 1" by blast
1.392 - let ?w = "v / complex_of_real (root n (cmod b))"
1.393 - from odd_real_root_pow[OF o, of "cmod b"]
1.394 - have th1: "?w ^ n = v^n / complex_of_real (cmod b)"
1.395 - by (simp add: power_divide complex_of_real_power)
1.396 - have th2:"cmod (complex_of_real (cmod b) / b) = 1" using b by (simp add: norm_divide)
1.397 - hence th3: "cmod (complex_of_real (cmod b) / b) \<ge> 0" by simp
1.398 - have th4: "cmod (complex_of_real (cmod b) / b) *
1.399 - cmod (1 + b * (v ^ n / complex_of_real (cmod b)))
1.400 - < cmod (complex_of_real (cmod b) / b) * 1"
1.401 - apply (simp only: norm_mult[symmetric] right_distrib)
1.402 - using b v by (simp add: th2)
1.403 -
1.404 - from mult_less_imp_less_left[OF th4 th3]
1.405 - have "?P ?w n" unfolding th1 .
1.406 - hence "\<exists>z. ?P z n" .. }
1.407 - ultimately show "\<exists>z. ?P z n" by blast
1.408 -qed
1.409 -
1.410 -
1.411 -text{* Bolzano-Weierstrass type property for closed disc in complex plane. *}
1.412 -
1.413 -lemma metric_bound_lemma: "cmod (x - y) <= \<bar>Re x - Re y\<bar> + \<bar>Im x - Im y\<bar>"
1.414 - using real_sqrt_sum_squares_triangle_ineq[of "Re x - Re y" 0 0 "Im x - Im y" ]
1.415 - unfolding cmod_def by simp
1.416 -
1.417 -lemma bolzano_weierstrass_complex_disc:
1.418 - assumes r: "\<forall>n. cmod (s n) \<le> r"
1.419 - shows "\<exists>f z. subseq f \<and> (\<forall>e >0. \<exists>N. \<forall>n \<ge> N. cmod (s (f n) - z) < e)"
1.420 -proof-
1.421 - from seq_monosub[of "Re o s"]
1.422 - obtain f g where f: "subseq f" "monoseq (\<lambda>n. Re (s (f n)))"
1.423 - unfolding o_def by blast
1.424 - from seq_monosub[of "Im o s o f"]
1.425 - obtain g where g: "subseq g" "monoseq (\<lambda>n. Im (s(f(g n))))" unfolding o_def by blast
1.426 - let ?h = "f o g"
1.427 - from r[rule_format, of 0] have rp: "r \<ge> 0" using norm_ge_zero[of "s 0"] by arith
1.428 - have th:"\<forall>n. r + 1 \<ge> \<bar> Re (s n)\<bar>"
1.429 - proof
1.430 - fix n
1.431 - from abs_Re_le_cmod[of "s n"] r[rule_format, of n] show "\<bar>Re (s n)\<bar> \<le> r + 1" by arith
1.432 - qed
1.433 - have conv1: "convergent (\<lambda>n. Re (s ( f n)))"
1.434 - apply (rule Bseq_monoseq_convergent)
1.435 - apply (simp add: Bseq_def)
1.436 - apply (rule exI[where x= "r + 1"])
1.437 - using th rp apply simp
1.438 - using f(2) .
1.439 - have th:"\<forall>n. r + 1 \<ge> \<bar> Im (s n)\<bar>"
1.440 - proof
1.441 - fix n
1.442 - from abs_Im_le_cmod[of "s n"] r[rule_format, of n] show "\<bar>Im (s n)\<bar> \<le> r + 1" by arith
1.443 - qed
1.444 -
1.445 - have conv2: "convergent (\<lambda>n. Im (s (f (g n))))"
1.446 - apply (rule Bseq_monoseq_convergent)
1.447 - apply (simp add: Bseq_def)
1.448 - apply (rule exI[where x= "r + 1"])
1.449 - using th rp apply simp
1.450 - using g(2) .
1.451 -
1.452 - from conv1[unfolded convergent_def] obtain x where "LIMSEQ (\<lambda>n. Re (s (f n))) x"
1.453 - by blast
1.454 - hence x: "\<forall>r>0. \<exists>n0. \<forall>n\<ge>n0. \<bar> Re (s (f n)) - x \<bar> < r"
1.455 - unfolding LIMSEQ_def real_norm_def .
1.456 -
1.457 - from conv2[unfolded convergent_def] obtain y where "LIMSEQ (\<lambda>n. Im (s (f (g n)))) y"
1.458 - by blast
1.459 - hence y: "\<forall>r>0. \<exists>n0. \<forall>n\<ge>n0. \<bar> Im (s (f (g n))) - y \<bar> < r"
1.460 - unfolding LIMSEQ_def real_norm_def .
1.461 - let ?w = "Complex x y"
1.462 - from f(1) g(1) have hs: "subseq ?h" unfolding subseq_def by auto
1.463 - {fix e assume ep: "e > (0::real)"
1.464 - hence e2: "e/2 > 0" by simp
1.465 - from x[rule_format, OF e2] y[rule_format, OF e2]
1.466 - obtain N1 N2 where N1: "\<forall>n\<ge>N1. \<bar>Re (s (f n)) - x\<bar> < e / 2" and N2: "\<forall>n\<ge>N2. \<bar>Im (s (f (g n))) - y\<bar> < e / 2" by blast
1.467 - {fix n assume nN12: "n \<ge> N1 + N2"
1.468 - hence nN1: "g n \<ge> N1" and nN2: "n \<ge> N2" using seq_suble[OF g(1), of n] by arith+
1.469 - from add_strict_mono[OF N1[rule_format, OF nN1] N2[rule_format, OF nN2]]
1.470 - have "cmod (s (?h n) - ?w) < e"
1.471 - using metric_bound_lemma[of "s (f (g n))" ?w] by simp }
1.472 - hence "\<exists>N. \<forall>n\<ge>N. cmod (s (?h n) - ?w) < e" by blast }
1.473 - with hs show ?thesis by blast
1.474 -qed
1.475 -
1.476 -text{* Polynomial is continuous. *}
1.477 -
1.478 -lemma poly_cont:
1.479 - assumes ep: "e > 0"
1.480 - shows "\<exists>d >0. \<forall>w. 0 < cmod (w - z) \<and> cmod (w - z) < d \<longrightarrow> cmod (poly p w - poly p z) < e"
1.481 -proof-
1.482 - from poly_offset[of p z] obtain q where q: "length q = length p" "\<And>x. poly q x = poly p (z + x)" by blast
1.483 - {fix w
1.484 - note q(2)[of "w - z", simplified]}
1.485 - note th = this
1.486 - show ?thesis unfolding th[symmetric]
1.487 - proof(induct q)
1.488 - case Nil thus ?case using ep by auto
1.489 - next
1.490 - case (Cons c cs)
1.491 - from poly_bound_exists[of 1 "cs"]
1.492 - obtain m where m: "m > 0" "\<And>z. cmod z \<le> 1 \<Longrightarrow> cmod (poly cs z) \<le> m" by blast
1.493 - from ep m(1) have em0: "e/m > 0" by (simp add: field_simps)
1.494 - have one0: "1 > (0::real)" by arith
1.495 - from real_lbound_gt_zero[OF one0 em0]
1.496 - obtain d where d: "d >0" "d < 1" "d < e / m" by blast
1.497 - from d(1,3) m(1) have dm: "d*m > 0" "d*m < e"
1.498 - by (simp_all add: field_simps real_mult_order)
1.499 - show ?case
1.500 - proof(rule ex_forward[OF real_lbound_gt_zero[OF one0 em0]], clarsimp simp add: norm_mult)
1.501 - fix d w
1.502 - assume H: "d > 0" "d < 1" "d < e/m" "w\<noteq>z" "cmod (w-z) < d"
1.503 - hence d1: "cmod (w-z) \<le> 1" "d \<ge> 0" by simp_all
1.504 - from H(3) m(1) have dme: "d*m < e" by (simp add: field_simps)
1.505 - from H have th: "cmod (w-z) \<le> d" by simp
1.506 - from mult_mono[OF th m(2)[OF d1(1)] d1(2) norm_ge_zero] dme
1.507 - show "cmod (w - z) * cmod (poly cs (w - z)) < e" by simp
1.508 - qed
1.509 - qed
1.510 -qed
1.511 -
1.512 -text{* Hence a polynomial attains minimum on a closed disc
1.513 - in the complex plane. *}
1.514 -lemma poly_minimum_modulus_disc:
1.515 - "\<exists>z. \<forall>w. cmod w \<le> r \<longrightarrow> cmod (poly p z) \<le> cmod (poly p w)"
1.516 -proof-
1.517 - {assume "\<not> r \<ge> 0" hence ?thesis unfolding linorder_not_le
1.518 - apply -
1.519 - apply (rule exI[where x=0])
1.520 - apply auto
1.521 - apply (subgoal_tac "cmod w < 0")
1.522 - apply simp
1.523 - apply arith
1.524 - done }
1.525 - moreover
1.526 - {assume rp: "r \<ge> 0"
1.527 - from rp have "cmod 0 \<le> r \<and> cmod (poly p 0) = - (- cmod (poly p 0))" by simp
1.528 - hence mth1: "\<exists>x z. cmod z \<le> r \<and> cmod (poly p z) = - x" by blast
1.529 - {fix x z
1.530 - assume H: "cmod z \<le> r" "cmod (poly p z) = - x" "\<not>x < 1"
1.531 - hence "- x < 0 " by arith
1.532 - with H(2) norm_ge_zero[of "poly p z"] have False by simp }
1.533 - then have mth2: "\<exists>z. \<forall>x. (\<exists>z. cmod z \<le> r \<and> cmod (poly p z) = - x) \<longrightarrow> x < z" by blast
1.534 - from real_sup_exists[OF mth1 mth2] obtain s where
1.535 - s: "\<forall>y. (\<exists>x. (\<exists>z. cmod z \<le> r \<and> cmod (poly p z) = - x) \<and> y < x) \<longleftrightarrow>(y < s)" by blast
1.536 - let ?m = "-s"
1.537 - {fix y
1.538 - from s[rule_format, of "-y"] have
1.539 - "(\<exists>z x. cmod z \<le> r \<and> -(- cmod (poly p z)) < y) \<longleftrightarrow> ?m < y"
1.540 - unfolding minus_less_iff[of y ] equation_minus_iff by blast }
1.541 - note s1 = this[unfolded minus_minus]
1.542 - from s1[of ?m] have s1m: "\<And>z x. cmod z \<le> r \<Longrightarrow> cmod (poly p z) \<ge> ?m"
1.543 - by auto
1.544 - {fix n::nat
1.545 - from s1[rule_format, of "?m + 1/real (Suc n)"]
1.546 - have "\<exists>z. cmod z \<le> r \<and> cmod (poly p z) < - s + 1 / real (Suc n)"
1.547 - by simp}
1.548 - hence th: "\<forall>n. \<exists>z. cmod z \<le> r \<and> cmod (poly p z) < - s + 1 / real (Suc n)" ..
1.549 - from choice[OF th] obtain g where
1.550 - g: "\<forall>n. cmod (g n) \<le> r" "\<forall>n. cmod (poly p (g n)) <?m+1 /real(Suc n)"
1.551 - by blast
1.552 - from bolzano_weierstrass_complex_disc[OF g(1)]
1.553 - obtain f z where fz: "subseq f" "\<forall>e>0. \<exists>N. \<forall>n\<ge>N. cmod (g (f n) - z) < e"
1.554 - by blast
1.555 - {fix w
1.556 - assume wr: "cmod w \<le> r"
1.557 - let ?e = "\<bar>cmod (poly p z) - ?m\<bar>"
1.558 - {assume e: "?e > 0"
1.559 - hence e2: "?e/2 > 0" by simp
1.560 - from poly_cont[OF e2, of z p] obtain d where
1.561 - d: "d>0" "\<forall>w. 0<cmod (w - z)\<and> cmod(w - z) < d \<longrightarrow> cmod(poly p w - poly p z) < ?e/2" by blast
1.562 - {fix w assume w: "cmod (w - z) < d"
1.563 - have "cmod(poly p w - poly p z) < ?e / 2"
1.564 - using d(2)[rule_format, of w] w e by (cases "w=z", simp_all)}
1.565 - note th1 = this
1.566 -
1.567 - from fz(2)[rule_format, OF d(1)] obtain N1 where
1.568 - N1: "\<forall>n\<ge>N1. cmod (g (f n) - z) < d" by blast
1.569 - from reals_Archimedean2[of "2/?e"] obtain N2::nat where
1.570 - N2: "2/?e < real N2" by blast
1.571 - have th2: "cmod(poly p (g(f(N1 + N2))) - poly p z) < ?e/2"
1.572 - using N1[rule_format, of "N1 + N2"] th1 by simp
1.573 - {fix a b e2 m :: real
1.574 - have "a < e2 \<Longrightarrow> abs(b - m) < e2 \<Longrightarrow> 2 * e2 <= abs(b - m) + a
1.575 - ==> False" by arith}
1.576 - note th0 = this
1.577 - have ath:
1.578 - "\<And>m x e. m <= x \<Longrightarrow> x < m + e ==> abs(x - m::real) < e" by arith
1.579 - from s1m[OF g(1)[rule_format]]
1.580 - have th31: "?m \<le> cmod(poly p (g (f (N1 + N2))))" .
1.581 - from seq_suble[OF fz(1), of "N1+N2"]
1.582 - have th00: "real (Suc (N1+N2)) \<le> real (Suc (f (N1+N2)))" by simp
1.583 - have th000: "0 \<le> (1::real)" "(1::real) \<le> 1" "real (Suc (N1+N2)) > 0"
1.584 - using N2 by auto
1.585 - from frac_le[OF th000 th00] have th00: "?m +1 / real (Suc (f (N1 + N2))) \<le> ?m + 1 / real (Suc (N1 + N2))" by simp
1.586 - from g(2)[rule_format, of "f (N1 + N2)"]
1.587 - have th01:"cmod (poly p (g (f (N1 + N2)))) < - s + 1 / real (Suc (f (N1 + N2)))" .
1.588 - from order_less_le_trans[OF th01 th00]
1.589 - have th32: "cmod(poly p (g (f (N1 + N2)))) < ?m + (1/ real(Suc (N1 + N2)))" .
1.590 - from N2 have "2/?e < real (Suc (N1 + N2))" by arith
1.591 - with e2 less_imp_inverse_less[of "2/?e" "real (Suc (N1 + N2))"]
1.592 - have "?e/2 > 1/ real (Suc (N1 + N2))" by (simp add: inverse_eq_divide)
1.593 - with ath[OF th31 th32]
1.594 - have thc1:"\<bar>cmod(poly p (g (f (N1 + N2)))) - ?m\<bar>< ?e/2" by arith
1.595 - have ath2: "\<And>(a::real) b c m. \<bar>a - b\<bar> <= c ==> \<bar>b - m\<bar> <= \<bar>a - m\<bar> + c"
1.596 - by arith
1.597 - have th22: "\<bar>cmod (poly p (g (f (N1 + N2)))) - cmod (poly p z)\<bar>
1.598 -\<le> cmod (poly p (g (f (N1 + N2))) - poly p z)"
1.599 - by (simp add: norm_triangle_ineq3)
1.600 - from ath2[OF th22, of ?m]
1.601 - have thc2: "2*(?e/2) \<le> \<bar>cmod(poly p (g (f (N1 + N2)))) - ?m\<bar> + cmod (poly p (g (f (N1 + N2))) - poly p z)" by simp
1.602 - from th0[OF th2 thc1 thc2] have False .}
1.603 - hence "?e = 0" by auto
1.604 - then have "cmod (poly p z) = ?m" by simp
1.605 - with s1m[OF wr]
1.606 - have "cmod (poly p z) \<le> cmod (poly p w)" by simp }
1.607 - hence ?thesis by blast}
1.608 - ultimately show ?thesis by blast
1.609 -qed
1.610 -
1.611 -lemma "(rcis (sqrt (abs r)) (a/2)) ^ 2 = rcis (abs r) a"
1.612 - unfolding power2_eq_square
1.613 - apply (simp add: rcis_mult)
1.614 - apply (simp add: power2_eq_square[symmetric])
1.615 - done
1.616 -
1.617 -lemma cispi: "cis pi = -1"
1.618 - unfolding cis_def
1.619 - by simp
1.620 -
1.621 -lemma "(rcis (sqrt (abs r)) ((pi + a)/2)) ^ 2 = rcis (- abs r) a"
1.622 - unfolding power2_eq_square
1.623 - apply (simp add: rcis_mult add_divide_distrib)
1.624 - apply (simp add: power2_eq_square[symmetric] rcis_def cispi cis_mult[symmetric])
1.625 - done
1.626 -
1.627 -text {* Nonzero polynomial in z goes to infinity as z does. *}
1.628 -
1.629 -instance complex::idom_char_0 by (intro_classes)
1.630 -instance complex :: recpower_idom_char_0 by intro_classes
1.631 -
1.632 -lemma poly_infinity:
1.633 - assumes ex: "list_ex (\<lambda>c. c \<noteq> 0) p"
1.634 - shows "\<exists>r. \<forall>z. r \<le> cmod z \<longrightarrow> d \<le> cmod (poly (a#p) z)"
1.635 -using ex
1.636 -proof(induct p arbitrary: a d)
1.637 - case (Cons c cs a d)
1.638 - {assume H: "list_ex (\<lambda>c. c\<noteq>0) cs"
1.639 - with Cons.hyps obtain r where r: "\<forall>z. r \<le> cmod z \<longrightarrow> d + cmod a \<le> cmod (poly (c # cs) z)" by blast
1.640 - let ?r = "1 + \<bar>r\<bar>"
1.641 - {fix z assume h: "1 + \<bar>r\<bar> \<le> cmod z"
1.642 - have r0: "r \<le> cmod z" using h by arith
1.643 - from r[rule_format, OF r0]
1.644 - have th0: "d + cmod a \<le> 1 * cmod(poly (c#cs) z)" by arith
1.645 - from h have z1: "cmod z \<ge> 1" by arith
1.646 - from order_trans[OF th0 mult_right_mono[OF z1 norm_ge_zero[of "poly (c#cs) z"]]]
1.647 - have th1: "d \<le> cmod(z * poly (c#cs) z) - cmod a"
1.648 - unfolding norm_mult by (simp add: ring_simps)
1.649 - from complex_mod_triangle_sub[of "z * poly (c#cs) z" a]
1.650 - have th2: "cmod(z * poly (c#cs) z) - cmod a \<le> cmod (poly (a#c#cs) z)"
1.651 - by (simp add: diff_le_eq ring_simps)
1.652 - from th1 th2 have "d \<le> cmod (poly (a#c#cs) z)" by arith}
1.653 - hence ?case by blast}
1.654 - moreover
1.655 - {assume cs0: "\<not> (list_ex (\<lambda>c. c \<noteq> 0) cs)"
1.656 - with Cons.prems have c0: "c \<noteq> 0" by simp
1.657 - from cs0 have cs0': "list_all (\<lambda>c. c = 0) cs"
1.658 - by (auto simp add: list_all_iff list_ex_iff)
1.659 - {fix z
1.660 - assume h: "(\<bar>d\<bar> + cmod a) / cmod c \<le> cmod z"
1.661 - from c0 have "cmod c > 0" by simp
1.662 - from h c0 have th0: "\<bar>d\<bar> + cmod a \<le> cmod (z*c)"
1.663 - by (simp add: field_simps norm_mult)
1.664 - have ath: "\<And>mzh mazh ma. mzh <= mazh + ma ==> abs(d) + ma <= mzh ==> d <= mazh" by arith
1.665 - from complex_mod_triangle_sub[of "z*c" a ]
1.666 - have th1: "cmod (z * c) \<le> cmod (a + z * c) + cmod a"
1.667 - by (simp add: ring_simps)
1.668 - from ath[OF th1 th0] have "d \<le> cmod (poly (a # c # cs) z)"
1.669 - using poly_0[OF cs0'] by simp}
1.670 - then have ?case by blast}
1.671 - ultimately show ?case by blast
1.672 -qed simp
1.673 -
1.674 -text {* Hence polynomial's modulus attains its minimum somewhere. *}
1.675 -lemma poly_minimum_modulus:
1.676 - "\<exists>z.\<forall>w. cmod (poly p z) \<le> cmod (poly p w)"
1.677 -proof(induct p)
1.678 - case (Cons c cs)
1.679 - {assume cs0: "list_ex (\<lambda>c. c \<noteq> 0) cs"
1.680 - from poly_infinity[OF cs0, of "cmod (poly (c#cs) 0)" c]
1.681 - obtain r where r: "\<And>z. r \<le> cmod z \<Longrightarrow> cmod (poly (c # cs) 0) \<le> cmod (poly (c # cs) z)" by blast
1.682 - have ath: "\<And>z r. r \<le> cmod z \<or> cmod z \<le> \<bar>r\<bar>" by arith
1.683 - from poly_minimum_modulus_disc[of "\<bar>r\<bar>" "c#cs"]
1.684 - obtain v where v: "\<And>w. cmod w \<le> \<bar>r\<bar> \<Longrightarrow> cmod (poly (c # cs) v) \<le> cmod (poly (c # cs) w)" by blast
1.685 - {fix z assume z: "r \<le> cmod z"
1.686 - from v[of 0] r[OF z]
1.687 - have "cmod (poly (c # cs) v) \<le> cmod (poly (c # cs) z)"
1.688 - by simp }
1.689 - note v0 = this
1.690 - from v0 v ath[of r] have ?case by blast}
1.691 - moreover
1.692 - {assume cs0: "\<not> (list_ex (\<lambda>c. c\<noteq>0) cs)"
1.693 - hence th:"list_all (\<lambda>c. c = 0) cs" by (simp add: list_all_iff list_ex_iff)
1.694 - from poly_0[OF th] Cons.hyps have ?case by simp}
1.695 - ultimately show ?case by blast
1.696 -qed simp
1.697 -
1.698 -text{* Constant function (non-syntactic characterization). *}
1.699 -definition "constant f = (\<forall>x y. f x = f y)"
1.700 -
1.701 -lemma nonconstant_length: "\<not> (constant (poly p)) \<Longrightarrow> length p \<ge> 2"
1.702 - unfolding constant_def
1.703 - apply (induct p, auto)
1.704 - apply (unfold not_less[symmetric])
1.705 - apply simp
1.706 - apply (rule ccontr)
1.707 - apply auto
1.708 - done
1.709 -
1.710 -lemma poly_replicate_append:
1.711 - "poly ((replicate n 0)@p) (x::'a::{recpower, comm_ring}) = x^n * poly p x"
1.712 - by(induct n, auto simp add: power_Suc ring_simps)
1.713 -
1.714 -text {* Decomposition of polynomial, skipping zero coefficients
1.715 - after the first. *}
1.716 -
1.717 -lemma poly_decompose_lemma:
1.718 - assumes nz: "\<not>(\<forall>z. z\<noteq>0 \<longrightarrow> poly p z = (0::'a::{recpower,idom}))"
1.719 - shows "\<exists>k a q. a\<noteq>0 \<and> Suc (length q + k) = length p \<and>
1.720 - (\<forall>z. poly p z = z^k * poly (a#q) z)"
1.721 -using nz
1.722 -proof(induct p)
1.723 - case Nil thus ?case by simp
1.724 -next
1.725 - case (Cons c cs)
1.726 - {assume c0: "c = 0"
1.727 -
1.728 - from Cons.hyps Cons.prems c0 have ?case apply auto
1.729 - apply (rule_tac x="k+1" in exI)
1.730 - apply (rule_tac x="a" in exI, clarsimp)
1.731 - apply (rule_tac x="q" in exI)
1.732 - by (auto simp add: power_Suc)}
1.733 - moreover
1.734 - {assume c0: "c\<noteq>0"
1.735 - hence ?case apply-
1.736 - apply (rule exI[where x=0])
1.737 - apply (rule exI[where x=c], clarsimp)
1.738 - apply (rule exI[where x=cs])
1.739 - apply auto
1.740 - done}
1.741 - ultimately show ?case by blast
1.742 -qed
1.743 -
1.744 -lemma poly_decompose:
1.745 - assumes nc: "~constant(poly p)"
1.746 - shows "\<exists>k a q. a\<noteq>(0::'a::{recpower,idom}) \<and> k\<noteq>0 \<and>
1.747 - length q + k + 1 = length p \<and>
1.748 - (\<forall>z. poly p z = poly p 0 + z^k * poly (a#q) z)"
1.749 -using nc
1.750 -proof(induct p)
1.751 - case Nil thus ?case by (simp add: constant_def)
1.752 -next
1.753 - case (Cons c cs)
1.754 - {assume C:"\<forall>z. z \<noteq> 0 \<longrightarrow> poly cs z = 0"
1.755 - {fix x y
1.756 - from C have "poly (c#cs) x = poly (c#cs) y" by (cases "x=0", auto)}
1.757 - with Cons.prems have False by (auto simp add: constant_def)}
1.758 - hence th: "\<not> (\<forall>z. z \<noteq> 0 \<longrightarrow> poly cs z = 0)" ..
1.759 - from poly_decompose_lemma[OF th]
1.760 - show ?case
1.761 - apply clarsimp
1.762 - apply (rule_tac x="k+1" in exI)
1.763 - apply (rule_tac x="a" in exI)
1.764 - apply simp
1.765 - apply (rule_tac x="q" in exI)
1.766 - apply (auto simp add: power_Suc)
1.767 - done
1.768 -qed
1.769 -
1.770 -text{* Fundamental theorem of algebral *}
1.771 -
1.772 -lemma fundamental_theorem_of_algebra:
1.773 - assumes nc: "~constant(poly p)"
1.774 - shows "\<exists>z::complex. poly p z = 0"
1.775 -using nc
1.776 -proof(induct n\<equiv> "length p" arbitrary: p rule: nat_less_induct)
1.777 - fix n fix p :: "complex list"
1.778 - let ?p = "poly p"
1.779 - assume H: "\<forall>m<n. \<forall>p. \<not> constant (poly p) \<longrightarrow> m = length p \<longrightarrow> (\<exists>(z::complex). poly p z = 0)" and nc: "\<not> constant ?p" and n: "n = length p"
1.780 - let ?ths = "\<exists>z. ?p z = 0"
1.781 -
1.782 - from nonconstant_length[OF nc] have n2: "n\<ge> 2" by (simp add: n)
1.783 - from poly_minimum_modulus obtain c where
1.784 - c: "\<forall>w. cmod (?p c) \<le> cmod (?p w)" by blast
1.785 - {assume pc: "?p c = 0" hence ?ths by blast}
1.786 - moreover
1.787 - {assume pc0: "?p c \<noteq> 0"
1.788 - from poly_offset[of p c] obtain q where
1.789 - q: "length q = length p" "\<forall>x. poly q x = ?p (c+x)" by blast
1.790 - {assume h: "constant (poly q)"
1.791 - from q(2) have th: "\<forall>x. poly q (x - c) = ?p x" by auto
1.792 - {fix x y
1.793 - from th have "?p x = poly q (x - c)" by auto
1.794 - also have "\<dots> = poly q (y - c)"
1.795 - using h unfolding constant_def by blast
1.796 - also have "\<dots> = ?p y" using th by auto
1.797 - finally have "?p x = ?p y" .}
1.798 - with nc have False unfolding constant_def by blast }
1.799 - hence qnc: "\<not> constant (poly q)" by blast
1.800 - from q(2) have pqc0: "?p c = poly q 0" by simp
1.801 - from c pqc0 have cq0: "\<forall>w. cmod (poly q 0) \<le> cmod (?p w)" by simp
1.802 - let ?a0 = "poly q 0"
1.803 - from pc0 pqc0 have a00: "?a0 \<noteq> 0" by simp
1.804 - from a00
1.805 - have qr: "\<forall>z. poly q z = poly (map (op * (inverse ?a0)) q) z * ?a0"
1.806 - by (simp add: poly_cmult_map)
1.807 - let ?r = "map (op * (inverse ?a0)) q"
1.808 - have lgqr: "length q = length ?r" by simp
1.809 - {assume h: "\<And>x y. poly ?r x = poly ?r y"
1.810 - {fix x y
1.811 - from qr[rule_format, of x]
1.812 - have "poly q x = poly ?r x * ?a0" by auto
1.813 - also have "\<dots> = poly ?r y * ?a0" using h by simp
1.814 - also have "\<dots> = poly q y" using qr[rule_format, of y] by simp
1.815 - finally have "poly q x = poly q y" .}
1.816 - with qnc have False unfolding constant_def by blast}
1.817 - hence rnc: "\<not> constant (poly ?r)" unfolding constant_def by blast
1.818 - from qr[rule_format, of 0] a00 have r01: "poly ?r 0 = 1" by auto
1.819 - {fix w
1.820 - have "cmod (poly ?r w) < 1 \<longleftrightarrow> cmod (poly q w / ?a0) < 1"
1.821 - using qr[rule_format, of w] a00 by simp
1.822 - also have "\<dots> \<longleftrightarrow> cmod (poly q w) < cmod ?a0"
1.823 - using a00 unfolding norm_divide by (simp add: field_simps)
1.824 - finally have "cmod (poly ?r w) < 1 \<longleftrightarrow> cmod (poly q w) < cmod ?a0" .}
1.825 - note mrmq_eq = this
1.826 - from poly_decompose[OF rnc] obtain k a s where
1.827 - kas: "a\<noteq>0" "k\<noteq>0" "length s + k + 1 = length ?r"
1.828 - "\<forall>z. poly ?r z = poly ?r 0 + z^k* poly (a#s) z" by blast
1.829 - {assume "k + 1 = n"
1.830 - with kas(3) lgqr[symmetric] q(1) n[symmetric] have s0:"s=[]" by auto
1.831 - {fix w
1.832 - have "cmod (poly ?r w) = cmod (1 + a * w ^ k)"
1.833 - using kas(4)[rule_format, of w] s0 r01 by (simp add: ring_simps)}
1.834 - note hth = this [symmetric]
1.835 - from reduce_poly_simple[OF kas(1,2)]
1.836 - have "\<exists>w. cmod (poly ?r w) < 1" unfolding hth by blast}
1.837 - moreover
1.838 - {assume kn: "k+1 \<noteq> n"
1.839 - from kn kas(3) q(1) n[symmetric] have k1n: "k + 1 < n" by simp
1.840 - have th01: "\<not> constant (poly (1#((replicate (k - 1) 0)@[a])))"
1.841 - unfolding constant_def poly_Nil poly_Cons poly_replicate_append
1.842 - using kas(1) apply simp
1.843 - by (rule exI[where x=0], rule exI[where x=1], simp)
1.844 - from kas(2) have th02: "k+1 = length (1#((replicate (k - 1) 0)@[a]))"
1.845 - by simp
1.846 - from H[rule_format, OF k1n th01 th02]
1.847 - obtain w where w: "1 + w^k * a = 0"
1.848 - unfolding poly_Nil poly_Cons poly_replicate_append
1.849 - using kas(2) by (auto simp add: power_Suc[symmetric, of _ "k - Suc 0"]
1.850 - mult_assoc[of _ _ a, symmetric])
1.851 - from poly_bound_exists[of "cmod w" s] obtain m where
1.852 - m: "m > 0" "\<forall>z. cmod z \<le> cmod w \<longrightarrow> cmod (poly s z) \<le> m" by blast
1.853 - have w0: "w\<noteq>0" using kas(2) w by (auto simp add: power_0_left)
1.854 - from w have "(1 + w ^ k * a) - 1 = 0 - 1" by simp
1.855 - then have wm1: "w^k * a = - 1" by simp
1.856 - have inv0: "0 < inverse (cmod w ^ (k + 1) * m)"
1.857 - using norm_ge_zero[of w] w0 m(1)
1.858 - by (simp add: inverse_eq_divide zero_less_mult_iff)
1.859 - with real_down2[OF zero_less_one] obtain t where
1.860 - t: "t > 0" "t < 1" "t < inverse (cmod w ^ (k + 1) * m)" by blast
1.861 - let ?ct = "complex_of_real t"
1.862 - let ?w = "?ct * w"
1.863 - have "1 + ?w^k * (a + ?w * poly s ?w) = 1 + ?ct^k * (w^k * a) + ?w^k * ?w * poly s ?w" using kas(1) by (simp add: ring_simps power_mult_distrib)
1.864 - also have "\<dots> = complex_of_real (1 - t^k) + ?w^k * ?w * poly s ?w"
1.865 - unfolding wm1 by (simp)
1.866 - finally have "cmod (1 + ?w^k * (a + ?w * poly s ?w)) = cmod (complex_of_real (1 - t^k) + ?w^k * ?w * poly s ?w)"
1.867 - apply -
1.868 - apply (rule cong[OF refl[of cmod]])
1.869 - apply assumption
1.870 - done
1.871 - with norm_triangle_ineq[of "complex_of_real (1 - t^k)" "?w^k * ?w * poly s ?w"]
1.872 - have th11: "cmod (1 + ?w^k * (a + ?w * poly s ?w)) \<le> \<bar>1 - t^k\<bar> + cmod (?w^k * ?w * poly s ?w)" unfolding norm_of_real by simp
1.873 - have ath: "\<And>x (t::real). 0\<le> x \<Longrightarrow> x < t \<Longrightarrow> t\<le>1 \<Longrightarrow> \<bar>1 - t\<bar> + x < 1" by arith
1.874 - have "t *cmod w \<le> 1 * cmod w" apply (rule mult_mono) using t(1,2) by auto
1.875 - then have tw: "cmod ?w \<le> cmod w" using t(1) by (simp add: norm_mult)
1.876 - from t inv0 have "t* (cmod w ^ (k + 1) * m) < 1"
1.877 - by (simp add: inverse_eq_divide field_simps)
1.878 - with zero_less_power[OF t(1), of k]
1.879 - have th30: "t^k * (t* (cmod w ^ (k + 1) * m)) < t^k * 1"
1.880 - apply - apply (rule mult_strict_left_mono) by simp_all
1.881 - have "cmod (?w^k * ?w * poly s ?w) = t^k * (t* (cmod w ^ (k+1) * cmod (poly s ?w)))" using w0 t(1)
1.882 - by (simp add: ring_simps power_mult_distrib norm_of_real norm_power norm_mult)
1.883 - then have "cmod (?w^k * ?w * poly s ?w) \<le> t^k * (t* (cmod w ^ (k + 1) * m))"
1.884 - using t(1,2) m(2)[rule_format, OF tw] w0
1.885 - apply (simp only: )
1.886 - apply auto
1.887 - apply (rule mult_mono, simp_all add: norm_ge_zero)+
1.888 - apply (simp add: zero_le_mult_iff zero_le_power)
1.889 - done
1.890 - with th30 have th120: "cmod (?w^k * ?w * poly s ?w) < t^k" by simp
1.891 - from power_strict_mono[OF t(2), of k] t(1) kas(2) have th121: "t^k \<le> 1"
1.892 - by auto
1.893 - from ath[OF norm_ge_zero[of "?w^k * ?w * poly s ?w"] th120 th121]
1.894 - have th12: "\<bar>1 - t^k\<bar> + cmod (?w^k * ?w * poly s ?w) < 1" .
1.895 - from th11 th12
1.896 - have "cmod (1 + ?w^k * (a + ?w * poly s ?w)) < 1" by arith
1.897 - then have "cmod (poly ?r ?w) < 1"
1.898 - unfolding kas(4)[rule_format, of ?w] r01 by simp
1.899 - then have "\<exists>w. cmod (poly ?r w) < 1" by blast}
1.900 - ultimately have cr0_contr: "\<exists>w. cmod (poly ?r w) < 1" by blast
1.901 - from cr0_contr cq0 q(2)
1.902 - have ?ths unfolding mrmq_eq not_less[symmetric] by auto}
1.903 - ultimately show ?ths by blast
1.904 -qed
1.905 -
1.906 -text {* Alternative version with a syntactic notion of constant polynomial. *}
1.907 -
1.908 -lemma fundamental_theorem_of_algebra_alt:
1.909 - assumes nc: "~(\<exists>a l. a\<noteq> 0 \<and> list_all(\<lambda>b. b = 0) l \<and> p = a#l)"
1.910 - shows "\<exists>z. poly p z = (0::complex)"
1.911 -using nc
1.912 -proof(induct p)
1.913 - case (Cons c cs)
1.914 - {assume "c=0" hence ?case by auto}
1.915 - moreover
1.916 - {assume c0: "c\<noteq>0"
1.917 - {assume nc: "constant (poly (c#cs))"
1.918 - from nc[unfolded constant_def, rule_format, of 0]
1.919 - have "\<forall>w. w \<noteq> 0 \<longrightarrow> poly cs w = 0" by auto
1.920 - hence "list_all (\<lambda>c. c=0) cs"
1.921 - proof(induct cs)
1.922 - case (Cons d ds)
1.923 - {assume "d=0" hence ?case using Cons.prems Cons.hyps by simp}
1.924 - moreover
1.925 - {assume d0: "d\<noteq>0"
1.926 - from poly_bound_exists[of 1 ds] obtain m where
1.927 - m: "m > 0" "\<forall>z. \<forall>z. cmod z \<le> 1 \<longrightarrow> cmod (poly ds z) \<le> m" by blast
1.928 - have dm: "cmod d / m > 0" using d0 m(1) by (simp add: field_simps)
1.929 - from real_down2[OF dm zero_less_one] obtain x where
1.930 - x: "x > 0" "x < cmod d / m" "x < 1" by blast
1.931 - let ?x = "complex_of_real x"
1.932 - from x have cx: "?x \<noteq> 0" "cmod ?x \<le> 1" by simp_all
1.933 - from Cons.prems[rule_format, OF cx(1)]
1.934 - have cth: "cmod (?x*poly ds ?x) = cmod d" by (simp add: eq_diff_eq[symmetric])
1.935 - from m(2)[rule_format, OF cx(2)] x(1)
1.936 - have th0: "cmod (?x*poly ds ?x) \<le> x*m"
1.937 - by (simp add: norm_mult)
1.938 - from x(2) m(1) have "x*m < cmod d" by (simp add: field_simps)
1.939 - with th0 have "cmod (?x*poly ds ?x) \<noteq> cmod d" by auto
1.940 - with cth have ?case by blast}
1.941 - ultimately show ?case by blast
1.942 - qed simp}
1.943 - then have nc: "\<not> constant (poly (c#cs))" using Cons.prems c0
1.944 - by blast
1.945 - from fundamental_theorem_of_algebra[OF nc] have ?case .}
1.946 - ultimately show ?case by blast
1.947 -qed simp
1.948 -
1.949 -subsection{* Nullstellenstatz, degrees and divisibility of polynomials *}
1.950 -
1.951 -lemma nullstellensatz_lemma:
1.952 - fixes p :: "complex list"
1.953 - assumes "\<forall>x. poly p x = 0 \<longrightarrow> poly q x = 0"
1.954 - and "degree p = n" and "n \<noteq> 0"
1.955 - shows "p divides (pexp q n)"
1.956 -using prems
1.957 -proof(induct n arbitrary: p q rule: nat_less_induct)
1.958 - fix n::nat fix p q :: "complex list"
1.959 - assume IH: "\<forall>m<n. \<forall>p q.
1.960 - (\<forall>x. poly p x = (0::complex) \<longrightarrow> poly q x = 0) \<longrightarrow>
1.961 - degree p = m \<longrightarrow> m \<noteq> 0 \<longrightarrow> p divides (q %^ m)"
1.962 - and pq0: "\<forall>x. poly p x = 0 \<longrightarrow> poly q x = 0"
1.963 - and dpn: "degree p = n" and n0: "n \<noteq> 0"
1.964 - let ?ths = "p divides (q %^ n)"
1.965 - {fix a assume a: "poly p a = 0"
1.966 - {assume p0: "poly p = poly []"
1.967 - hence ?ths unfolding divides_def using pq0 n0
1.968 - apply - apply (rule exI[where x="[]"], rule ext)
1.969 - by (auto simp add: poly_mult poly_exp)}
1.970 - moreover
1.971 - {assume p0: "poly p \<noteq> poly []"
1.972 - and oa: "order a p \<noteq> 0"
1.973 - from p0 have pne: "p \<noteq> []" by auto
1.974 - let ?op = "order a p"
1.975 - from p0 have ap: "([- a, 1] %^ ?op) divides p"
1.976 - "\<not> pexp [- a, 1] (Suc ?op) divides p" using order by blast+
1.977 - note oop = order_degree[OF p0, unfolded dpn]
1.978 - {assume q0: "q = []"
1.979 - hence ?ths using n0 unfolding divides_def
1.980 - apply simp
1.981 - apply (rule exI[where x="[]"], rule ext)
1.982 - by (simp add: divides_def poly_exp poly_mult)}
1.983 - moreover
1.984 - {assume q0: "q\<noteq>[]"
1.985 - from pq0[rule_format, OF a, unfolded poly_linear_divides] q0
1.986 - obtain r where r: "q = pmult [- a, 1] r" by blast
1.987 - from ap[unfolded divides_def] obtain s where
1.988 - s: "poly p = poly (pmult (pexp [- a, 1] ?op) s)" by blast
1.989 - have s0: "poly s \<noteq> poly []"
1.990 - using s p0 by (simp add: poly_entire)
1.991 - hence pns0: "poly (pnormalize s) \<noteq> poly []" and sne: "s\<noteq>[]" by auto
1.992 - {assume ds0: "degree s = 0"
1.993 - from ds0 pns0 have "\<exists>k. pnormalize s = [k]" unfolding degree_def
1.994 - by (cases "pnormalize s", auto)
1.995 - then obtain k where kpn: "pnormalize s = [k]" by blast
1.996 - from pns0[unfolded poly_zero] kpn have k: "k \<noteq>0" "poly s = poly [k]"
1.997 - using poly_normalize[of s] by simp_all
1.998 - let ?w = "pmult (pmult [1/k] (pexp [-a,1] (n - ?op))) (pexp r n)"
1.999 - from k r s oop have "poly (pexp q n) = poly (pmult p ?w)"
1.1000 - by - (rule ext, simp add: poly_mult poly_exp poly_cmult poly_add power_add[symmetric] ring_simps power_mult_distrib[symmetric])
1.1001 - hence ?ths unfolding divides_def by blast}
1.1002 - moreover
1.1003 - {assume ds0: "degree s \<noteq> 0"
1.1004 - from ds0 s0 dpn degree_unique[OF s, unfolded linear_pow_mul_degree] oa
1.1005 - have dsn: "degree s < n" by auto
1.1006 - {fix x assume h: "poly s x = 0"
1.1007 - {assume xa: "x = a"
1.1008 - from h[unfolded xa poly_linear_divides] sne obtain u where
1.1009 - u: "s = pmult [- a, 1] u" by blast
1.1010 - have "poly p = poly (pmult (pexp [- a, 1] (Suc ?op)) u)"
1.1011 - unfolding s u
1.1012 - apply (rule ext)
1.1013 - by (simp add: ring_simps power_mult_distrib[symmetric] poly_mult poly_cmult poly_add poly_exp)
1.1014 - with ap(2)[unfolded divides_def] have False by blast}
1.1015 - note xa = this
1.1016 - from h s have "poly p x = 0" by (simp add: poly_mult)
1.1017 - with pq0 have "poly q x = 0" by blast
1.1018 - with r xa have "poly r x = 0"
1.1019 - by (auto simp add: poly_mult poly_add poly_cmult eq_diff_eq[symmetric])}
1.1020 - note impth = this
1.1021 - from IH[rule_format, OF dsn, of s r] impth ds0
1.1022 - have "s divides (pexp r (degree s))" by blast
1.1023 - then obtain u where u: "poly (pexp r (degree s)) = poly (pmult s u)"
1.1024 - unfolding divides_def by blast
1.1025 - hence u': "\<And>x. poly s x * poly u x = poly r x ^ degree s"
1.1026 - by (simp add: poly_mult[symmetric] poly_exp[symmetric])
1.1027 - let ?w = "pmult (pmult u (pexp [-a,1] (n - ?op))) (pexp r (n - degree s))"
1.1028 - from u' s r oop[of a] dsn have "poly (pexp q n) = poly (pmult p ?w)"
1.1029 - apply - apply (rule ext)
1.1030 - apply (simp only: power_mult_distrib power_add[symmetric] poly_add poly_mult poly_exp poly_cmult ring_simps)
1.1031 -
1.1032 - apply (simp add: power_mult_distrib power_add[symmetric] poly_add poly_mult poly_exp poly_cmult mult_assoc[symmetric])
1.1033 - done
1.1034 - hence ?ths unfolding divides_def by blast}
1.1035 - ultimately have ?ths by blast }
1.1036 - ultimately have ?ths by blast}
1.1037 - ultimately have ?ths using a order_root by blast}
1.1038 - moreover
1.1039 - {assume exa: "\<not> (\<exists>a. poly p a = 0)"
1.1040 - from fundamental_theorem_of_algebra_alt[of p] exa obtain c cs where
1.1041 - ccs: "c\<noteq>0" "list_all (\<lambda>c. c = 0) cs" "p = c#cs" by blast
1.1042 -
1.1043 - from poly_0[OF ccs(2)] ccs(3)
1.1044 - have pp: "\<And>x. poly p x = c" by simp
1.1045 - let ?w = "pmult [1/c] (pexp q n)"
1.1046 - from pp ccs(1)
1.1047 - have "poly (pexp q n) = poly (pmult p ?w) "
1.1048 - apply - apply (rule ext)
1.1049 - unfolding poly_mult_assoc[symmetric] by (simp add: poly_mult)
1.1050 - hence ?ths unfolding divides_def by blast}
1.1051 - ultimately show ?ths by blast
1.1052 -qed
1.1053 -
1.1054 -lemma nullstellensatz_univariate:
1.1055 - "(\<forall>x. poly p x = (0::complex) \<longrightarrow> poly q x = 0) \<longleftrightarrow>
1.1056 - p divides (q %^ (degree p)) \<or> (poly p = poly [] \<and> poly q = poly [])"
1.1057 -proof-
1.1058 - {assume pe: "poly p = poly []"
1.1059 - hence eq: "(\<forall>x. poly p x = (0::complex) \<longrightarrow> poly q x = 0) \<longleftrightarrow> poly q = poly []"
1.1060 - apply auto
1.1061 - by (rule ext, simp)
1.1062 - {assume "p divides (pexp q (degree p))"
1.1063 - then obtain r where r: "poly (pexp q (degree p)) = poly (pmult p r)"
1.1064 - unfolding divides_def by blast
1.1065 - from cong[OF r refl] pe degree_unique[OF pe]
1.1066 - have False by (simp add: poly_mult degree_def)}
1.1067 - with eq pe have ?thesis by blast}
1.1068 - moreover
1.1069 - {assume pe: "poly p \<noteq> poly []"
1.1070 - have p0: "poly [0] = poly []" by (rule ext, simp)
1.1071 - {assume dp: "degree p = 0"
1.1072 - then obtain k where "pnormalize p = [k]" using pe poly_normalize[of p]
1.1073 - unfolding degree_def by (cases "pnormalize p", auto)
1.1074 - hence k: "pnormalize p = [k]" "poly p = poly [k]" "k\<noteq>0"
1.1075 - using pe poly_normalize[of p] by (auto simp add: p0)
1.1076 - hence th1: "\<forall>x. poly p x \<noteq> 0" by simp
1.1077 - from k(2,3) dp have "poly (pexp q (degree p)) = poly (pmult p [1/k]) "
1.1078 - by - (rule ext, simp add: poly_mult poly_exp)
1.1079 - hence th2: "p divides (pexp q (degree p))" unfolding divides_def by blast
1.1080 - from th1 th2 pe have ?thesis by blast}
1.1081 - moreover
1.1082 - {assume dp: "degree p \<noteq> 0"
1.1083 - then obtain n where n: "degree p = Suc n " by (cases "degree p", auto)
1.1084 - {assume "p divides (pexp q (Suc n))"
1.1085 - then obtain u where u: "poly (pexp q (Suc n)) = poly (pmult p u)"
1.1086 - unfolding divides_def by blast
1.1087 - hence u' :"\<And>x. poly (pexp q (Suc n)) x = poly (pmult p u) x" by simp_all
1.1088 - {fix x assume h: "poly p x = 0" "poly q x \<noteq> 0"
1.1089 - hence "poly (pexp q (Suc n)) x \<noteq> 0" by (simp only: poly_exp) simp
1.1090 - hence False using u' h(1) by (simp only: poly_mult poly_exp) simp}}
1.1091 - with n nullstellensatz_lemma[of p q "degree p"] dp
1.1092 - have ?thesis by auto}
1.1093 - ultimately have ?thesis by blast}
1.1094 - ultimately show ?thesis by blast
1.1095 -qed
1.1096 -
1.1097 -text{* Useful lemma *}
1.1098 -
1.1099 -lemma (in idom_char_0) constant_degree: "constant (poly p) \<longleftrightarrow> degree p = 0" (is "?lhs = ?rhs")
1.1100 -proof
1.1101 - assume l: ?lhs
1.1102 - from l[unfolded constant_def, rule_format, of _ "zero"]
1.1103 - have th: "poly p = poly [poly p 0]" apply - by (rule ext, simp)
1.1104 - from degree_unique[OF th] show ?rhs by (simp add: degree_def)
1.1105 -next
1.1106 - assume r: ?rhs
1.1107 - from r have "pnormalize p = [] \<or> (\<exists>k. pnormalize p = [k])"
1.1108 - unfolding degree_def by (cases "pnormalize p", auto)
1.1109 - then show ?lhs unfolding constant_def poly_normalize[of p, symmetric]
1.1110 - by (auto simp del: poly_normalize)
1.1111 -qed
1.1112 -
1.1113 -(* It would be nicer to prove this without using algebraic closure... *)
1.1114 -
1.1115 -lemma divides_degree_lemma: assumes dpn: "degree (p::complex list) = n"
1.1116 - shows "n \<le> degree (p *** q) \<or> poly (p *** q) = poly []"
1.1117 - using dpn
1.1118 -proof(induct n arbitrary: p q)
1.1119 - case 0 thus ?case by simp
1.1120 -next
1.1121 - case (Suc n p q)
1.1122 - from Suc.prems fundamental_theorem_of_algebra[of p] constant_degree[of p]
1.1123 - obtain a where a: "poly p a = 0" by auto
1.1124 - then obtain r where r: "p = pmult [-a, 1] r" unfolding poly_linear_divides
1.1125 - using Suc.prems by (auto simp add: degree_def)
1.1126 - {assume h: "poly (pmult r q) = poly []"
1.1127 - hence "poly (pmult p q) = poly []" using r
1.1128 - apply - apply (rule ext) by (auto simp add: poly_entire poly_mult poly_add poly_cmult) hence ?case by blast}
1.1129 - moreover
1.1130 - {assume h: "poly (pmult r q) \<noteq> poly []"
1.1131 - hence r0: "poly r \<noteq> poly []" and q0: "poly q \<noteq> poly []"
1.1132 - by (auto simp add: poly_entire)
1.1133 - have eq: "poly (pmult p q) = poly (pmult [-a, 1] (pmult r q))"
1.1134 - apply - apply (rule ext)
1.1135 - by (simp add: r poly_mult poly_add poly_cmult ring_simps)
1.1136 - from linear_mul_degree[OF h, of "- a"]
1.1137 - have dqe: "degree (pmult p q) = degree (pmult r q) + 1"
1.1138 - unfolding degree_unique[OF eq] .
1.1139 - from linear_mul_degree[OF r0, of "- a", unfolded r[symmetric]] r Suc.prems
1.1140 - have dr: "degree r = n" by auto
1.1141 - from Suc.hyps[OF dr, of q] have "Suc n \<le> degree (pmult p q)"
1.1142 - unfolding dqe using h by (auto simp del: poly.simps)
1.1143 - hence ?case by blast}
1.1144 - ultimately show ?case by blast
1.1145 -qed
1.1146 -
1.1147 -lemma divides_degree: assumes pq: "p divides (q:: complex list)"
1.1148 - shows "degree p \<le> degree q \<or> poly q = poly []"
1.1149 -using pq divides_degree_lemma[OF refl, of p]
1.1150 -apply (auto simp add: divides_def poly_entire)
1.1151 -apply atomize
1.1152 -apply (erule_tac x="qa" in allE, auto)
1.1153 -apply (subgoal_tac "degree q = degree (p *** qa)", simp)
1.1154 -apply (rule degree_unique, simp)
1.1155 -done
1.1156 -
1.1157 -(* Arithmetic operations on multivariate polynomials. *)
1.1158 -
1.1159 -lemma mpoly_base_conv:
1.1160 - "(0::complex) \<equiv> poly [] x" "c \<equiv> poly [c] x" "x \<equiv> poly [0,1] x" by simp_all
1.1161 -
1.1162 -lemma mpoly_norm_conv:
1.1163 - "poly [0] (x::complex) \<equiv> poly [] x" "poly [poly [] y] x \<equiv> poly [] x" by simp_all
1.1164 -
1.1165 -lemma mpoly_sub_conv:
1.1166 - "poly p (x::complex) - poly q x \<equiv> poly p x + -1 * poly q x"
1.1167 - by (simp add: diff_def)
1.1168 -
1.1169 -lemma poly_pad_rule: "poly p x = 0 ==> poly (0#p) x = (0::complex)" by simp
1.1170 -
1.1171 -lemma poly_cancel_eq_conv: "p = (0::complex) \<Longrightarrow> a \<noteq> 0 \<Longrightarrow> (q = 0) \<equiv> (a * q - b * p = 0)" apply (atomize (full)) by auto
1.1172 -
1.1173 -lemma resolve_eq_raw: "poly [] x \<equiv> 0" "poly [c] x \<equiv> (c::complex)" by auto
1.1174 -lemma resolve_eq_then: "(P \<Longrightarrow> (Q \<equiv> Q1)) \<Longrightarrow> (\<not>P \<Longrightarrow> (Q \<equiv> Q2))
1.1175 - \<Longrightarrow> Q \<equiv> P \<and> Q1 \<or> \<not>P\<and> Q2" apply (atomize (full)) by blast
1.1176 -lemma expand_ex_beta_conv: "list_ex P [c] \<equiv> P c" by simp
1.1177 -
1.1178 -lemma poly_divides_pad_rule:
1.1179 - fixes p q :: "complex list"
1.1180 - assumes pq: "p divides q"
1.1181 - shows "p divides ((0::complex)#q)"
1.1182 -proof-
1.1183 - from pq obtain r where r: "poly q = poly (p *** r)" unfolding divides_def by blast
1.1184 - hence "poly (0#q) = poly (p *** ([0,1] *** r))"
1.1185 - by - (rule ext, simp add: poly_mult poly_cmult poly_add)
1.1186 - thus ?thesis unfolding divides_def by blast
1.1187 -qed
1.1188 -
1.1189 -lemma poly_divides_pad_const_rule:
1.1190 - fixes p q :: "complex list"
1.1191 - assumes pq: "p divides q"
1.1192 - shows "p divides (a %* q)"
1.1193 -proof-
1.1194 - from pq obtain r where r: "poly q = poly (p *** r)" unfolding divides_def by blast
1.1195 - hence "poly (a %* q) = poly (p *** (a %* r))"
1.1196 - by - (rule ext, simp add: poly_mult poly_cmult poly_add)
1.1197 - thus ?thesis unfolding divides_def by blast
1.1198 -qed
1.1199 -
1.1200 -
1.1201 -lemma poly_divides_conv0:
1.1202 - fixes p :: "complex list"
1.1203 - assumes lgpq: "length q < length p" and lq:"last p \<noteq> 0"
1.1204 - shows "p divides q \<equiv> (\<not> (list_ex (\<lambda>c. c \<noteq> 0) q))" (is "?lhs \<equiv> ?rhs")
1.1205 -proof-
1.1206 - {assume r: ?rhs
1.1207 - hence eq: "poly q = poly []" unfolding poly_zero
1.1208 - by (simp add: list_all_iff list_ex_iff)
1.1209 - hence "poly q = poly (p *** [])" by - (rule ext, simp add: poly_mult)
1.1210 - hence ?lhs unfolding divides_def by blast}
1.1211 - moreover
1.1212 - {assume l: ?lhs
1.1213 - have ath: "\<And>lq lp dq::nat. lq < lp ==> lq \<noteq> 0 \<Longrightarrow> dq <= lq - 1 ==> dq < lp - 1"
1.1214 - by arith
1.1215 - {assume q0: "length q = 0"
1.1216 - hence "q = []" by simp
1.1217 - hence ?rhs by simp}
1.1218 - moreover
1.1219 - {assume lgq0: "length q \<noteq> 0"
1.1220 - from pnormalize_length[of q] have dql: "degree q \<le> length q - 1"
1.1221 - unfolding degree_def by simp
1.1222 - from ath[OF lgpq lgq0 dql, unfolded pnormal_degree[OF lq, symmetric]] divides_degree[OF l] have "poly q = poly []" by auto
1.1223 - hence ?rhs unfolding poly_zero by (simp add: list_all_iff list_ex_iff)}
1.1224 - ultimately have ?rhs by blast }
1.1225 - ultimately show "?lhs \<equiv> ?rhs" by - (atomize (full), blast)
1.1226 -qed
1.1227 -
1.1228 -lemma poly_divides_conv1:
1.1229 - assumes a0: "a\<noteq> (0::complex)" and pp': "(p::complex list) divides p'"
1.1230 - and qrp': "\<And>x. a * poly q x - poly p' x \<equiv> poly r x"
1.1231 - shows "p divides q \<equiv> p divides (r::complex list)" (is "?lhs \<equiv> ?rhs")
1.1232 -proof-
1.1233 - {
1.1234 - from pp' obtain t where t: "poly p' = poly (p *** t)"
1.1235 - unfolding divides_def by blast
1.1236 - {assume l: ?lhs
1.1237 - then obtain u where u: "poly q = poly (p *** u)" unfolding divides_def by blast
1.1238 - have "poly r = poly (p *** ((a %* u) +++ (-- t)))"
1.1239 - using u qrp' t
1.1240 - by - (rule ext,
1.1241 - simp add: poly_add poly_mult poly_cmult poly_minus ring_simps)
1.1242 - then have ?rhs unfolding divides_def by blast}
1.1243 - moreover
1.1244 - {assume r: ?rhs
1.1245 - then obtain u where u: "poly r = poly (p *** u)" unfolding divides_def by blast
1.1246 - from u t qrp' a0 have "poly q = poly (p *** ((1/a) %* (u +++ t)))"
1.1247 - by - (rule ext, atomize (full), simp add: poly_mult poly_add poly_cmult field_simps)
1.1248 - hence ?lhs unfolding divides_def by blast}
1.1249 - ultimately have "?lhs = ?rhs" by blast }
1.1250 -thus "?lhs \<equiv> ?rhs" by - (atomize(full), blast)
1.1251 -qed
1.1252 -
1.1253 -lemma basic_cqe_conv1:
1.1254 - "(\<exists>x. poly p x = 0 \<and> poly [] x \<noteq> 0) \<equiv> False"
1.1255 - "(\<exists>x. poly [] x \<noteq> 0) \<equiv> False"
1.1256 - "(\<exists>x. poly [c] x \<noteq> 0) \<equiv> c\<noteq>0"
1.1257 - "(\<exists>x. poly [] x = 0) \<equiv> True"
1.1258 - "(\<exists>x. poly [c] x = 0) \<equiv> c = 0" by simp_all
1.1259 -
1.1260 -lemma basic_cqe_conv2:
1.1261 - assumes l:"last (a#b#p) \<noteq> 0"
1.1262 - shows "(\<exists>x. poly (a#b#p) x = (0::complex)) \<equiv> True"
1.1263 -proof-
1.1264 - {fix h t
1.1265 - assume h: "h\<noteq>0" "list_all (\<lambda>c. c=(0::complex)) t" "a#b#p = h#t"
1.1266 - hence "list_all (\<lambda>c. c= 0) (b#p)" by simp
1.1267 - moreover have "last (b#p) \<in> set (b#p)" by simp
1.1268 - ultimately have "last (b#p) = 0" by (simp add: list_all_iff)
1.1269 - with l have False by simp}
1.1270 - hence th: "\<not> (\<exists> h t. h\<noteq>0 \<and> list_all (\<lambda>c. c=0) t \<and> a#b#p = h#t)"
1.1271 - by blast
1.1272 - from fundamental_theorem_of_algebra_alt[OF th]
1.1273 - show "(\<exists>x. poly (a#b#p) x = (0::complex)) \<equiv> True" by auto
1.1274 -qed
1.1275 -
1.1276 -lemma basic_cqe_conv_2b: "(\<exists>x. poly p x \<noteq> (0::complex)) \<equiv> (list_ex (\<lambda>c. c \<noteq> 0) p)"
1.1277 -proof-
1.1278 - have "\<not> (list_ex (\<lambda>c. c \<noteq> 0) p) \<longleftrightarrow> poly p = poly []"
1.1279 - by (simp add: poly_zero list_all_iff list_ex_iff)
1.1280 - also have "\<dots> \<longleftrightarrow> (\<not> (\<exists>x. poly p x \<noteq> 0))" by (auto intro: ext)
1.1281 - finally show "(\<exists>x. poly p x \<noteq> (0::complex)) \<equiv> (list_ex (\<lambda>c. c \<noteq> 0) p)"
1.1282 - by - (atomize (full), blast)
1.1283 -qed
1.1284 -
1.1285 -lemma basic_cqe_conv3:
1.1286 - fixes p q :: "complex list"
1.1287 - assumes l: "last (a#p) \<noteq> 0"
1.1288 - shows "(\<exists>x. poly (a#p) x =0 \<and> poly q x \<noteq> 0) \<equiv> \<not> ((a#p) divides (q %^ (length p)))"
1.1289 -proof-
1.1290 - note np = pnormalize_eq[OF l]
1.1291 - {assume "poly (a#p) = poly []" hence False using l
1.1292 - unfolding poly_zero apply (auto simp add: list_all_iff del: last.simps)
1.1293 - apply (cases p, simp_all) done}
1.1294 - then have p0: "poly (a#p) \<noteq> poly []" by blast
1.1295 - from np have dp:"degree (a#p) = length p" by (simp add: degree_def)
1.1296 - from nullstellensatz_univariate[of "a#p" q] p0 dp
1.1297 - show "(\<exists>x. poly (a#p) x =0 \<and> poly q x \<noteq> 0) \<equiv> \<not> ((a#p) divides (q %^ (length p)))"
1.1298 - by - (atomize (full), auto)
1.1299 -qed
1.1300 -
1.1301 -lemma basic_cqe_conv4:
1.1302 - fixes p q :: "complex list"
1.1303 - assumes h: "\<And>x. poly (q %^ n) x \<equiv> poly r x"
1.1304 - shows "p divides (q %^ n) \<equiv> p divides r"
1.1305 -proof-
1.1306 - from h have "poly (q %^ n) = poly r" by (auto intro: ext)
1.1307 - thus "p divides (q %^ n) \<equiv> p divides r" unfolding divides_def by simp
1.1308 -qed
1.1309 -
1.1310 -lemma pmult_Cons_Cons: "((a::complex)#b#p) *** q = (a %*q) +++ (0#((b#p) *** q))"
1.1311 - by simp
1.1312 -
1.1313 -lemma elim_neg_conv: "- z \<equiv> (-1) * (z::complex)" by simp
1.1314 -lemma eqT_intr: "PROP P \<Longrightarrow> (True \<Longrightarrow> PROP P )" "PROP P \<Longrightarrow> True" by blast+
1.1315 -lemma negate_negate_rule: "Trueprop P \<equiv> \<not> P \<equiv> False" by (atomize (full), auto)
1.1316 -lemma last_simps: "last [x] = x" "last (x#y#ys) = last (y#ys)" by simp_all
1.1317 -lemma length_simps: "length [] = 0" "length (x#y#xs) = length xs + 2" "length [x] = 1" by simp_all
1.1318 -
1.1319 -lemma complex_entire: "(z::complex) \<noteq> 0 \<and> w \<noteq> 0 \<equiv> z*w \<noteq> 0" by simp
1.1320 -lemma resolve_eq_ne: "(P \<equiv> True) \<equiv> (\<not>P \<equiv> False)" "(P \<equiv> False) \<equiv> (\<not>P \<equiv> True)"
1.1321 - by (atomize (full)) simp_all
1.1322 -lemma cqe_conv1: "poly [] x = 0 \<longleftrightarrow> True" by simp
1.1323 -lemma cqe_conv2: "(p \<Longrightarrow> (q \<equiv> r)) \<equiv> ((p \<and> q) \<equiv> (p \<and> r))" (is "?l \<equiv> ?r")
1.1324 -proof
1.1325 - assume "p \<Longrightarrow> q \<equiv> r" thus "p \<and> q \<equiv> p \<and> r" apply - apply (atomize (full)) by blast
1.1326 -next
1.1327 - assume "p \<and> q \<equiv> p \<and> r" "p"
1.1328 - thus "q \<equiv> r" apply - apply (atomize (full)) apply blast done
1.1329 -qed
1.1330 -lemma poly_const_conv: "poly [c] (x::complex) = y \<longleftrightarrow> c = y" by simp
1.1331 -
1.1332 -end
1.1333 \ No newline at end of file