src/HOL/Library/Fundamental_Theorem_Algebra.thy
author paulson <lp15@cam.ac.uk>
Fri Feb 07 17:43:47 2014 +0000 (2014-02-07)
changeset 55358 85d81bc281d0
parent 54489 03ff4d1e6784
child 55734 3f5b2745d659
permissions -rw-r--r--
Simplified some proofs, deleting a lot of strange unused material at the end of the theory.
haftmann@29197
     1
(* Author: Amine Chaieb, TU Muenchen *)
chaieb@26123
     2
chaieb@26123
     3
header{*Fundamental Theorem of Algebra*}
chaieb@26123
     4
chaieb@26123
     5
theory Fundamental_Theorem_Algebra
wenzelm@51537
     6
imports Polynomial Complex_Main
chaieb@26123
     7
begin
chaieb@26123
     8
huffman@27445
     9
subsection {* Square root of complex numbers *}
chaieb@26123
    10
definition csqrt :: "complex \<Rightarrow> complex" where
chaieb@26123
    11
"csqrt z = (if Im z = 0 then
chaieb@26123
    12
            if 0 \<le> Re z then Complex (sqrt(Re z)) 0
chaieb@26123
    13
            else Complex 0 (sqrt(- Re z))
chaieb@26123
    14
           else Complex (sqrt((cmod z + Re z) /2))
chaieb@26123
    15
                        ((Im z / abs(Im z)) * sqrt((cmod z - Re z) /2)))"
chaieb@26123
    16
wenzelm@53077
    17
lemma csqrt[algebra]: "(csqrt z)\<^sup>2 = z"
chaieb@26123
    18
proof-
wenzelm@29292
    19
  obtain x y where xy: "z = Complex x y" by (cases z)
chaieb@26123
    20
  {assume y0: "y = 0"
huffman@30488
    21
    {assume x0: "x \<ge> 0"
chaieb@26123
    22
      then have ?thesis using y0 xy real_sqrt_pow2[OF x0]
wenzelm@32960
    23
        by (simp add: csqrt_def power2_eq_square)}
chaieb@26123
    24
    moreover
chaieb@26123
    25
    {assume "\<not> x \<ge> 0" hence x0: "- x \<ge> 0" by arith
huffman@30488
    26
      then have ?thesis using y0 xy real_sqrt_pow2[OF x0]
wenzelm@32960
    27
        by (simp add: csqrt_def power2_eq_square) }
chaieb@26123
    28
    ultimately have ?thesis by blast}
chaieb@26123
    29
  moreover
chaieb@26123
    30
  {assume y0: "y\<noteq>0"
chaieb@26123
    31
    {fix x y
chaieb@26123
    32
      let ?z = "Complex x y"
chaieb@26123
    33
      from abs_Re_le_cmod[of ?z] have tha: "abs x \<le> cmod ?z" by auto
huffman@30488
    34
      hence "cmod ?z - x \<ge> 0" "cmod ?z + x \<ge> 0" by arith+
chaieb@26123
    35
      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) }
chaieb@26123
    36
    note th = this
wenzelm@53077
    37
    have sq4: "\<And>x::real. x\<^sup>2 / 4 = (x / 2)\<^sup>2"
huffman@30488
    38
      by (simp add: power2_eq_square)
chaieb@26123
    39
    from th[of x y]
wenzelm@53077
    40
    have sq4': "sqrt (((sqrt (x * x + y * y) + x)\<^sup>2 / 4)) = (sqrt (x * x + y * y) + x) / 2"
wenzelm@53077
    41
      "sqrt (((sqrt (x * x + y * y) - x)\<^sup>2 / 4)) = (sqrt (x * x + y * y) - x) / 2"
wenzelm@53077
    42
      unfolding sq4 by simp_all
chaieb@26123
    43
    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"
huffman@30488
    44
      unfolding power2_eq_square by simp
wenzelm@53077
    45
    have "sqrt 4 = sqrt (2\<^sup>2)" by simp
chaieb@26123
    46
    hence sqrt4: "sqrt 4 = 2" by (simp only: real_sqrt_abs)
chaieb@26123
    47
    have th2: "2 *(y * sqrt ((sqrt (x * x + y * y) - x) * (sqrt (x * x + y * y) + x) / 4)) / \<bar>y\<bar> = y"
chaieb@26123
    48
      using iffD2[OF real_sqrt_pow2_iff sum_power2_ge_zero[of x y]] y0
huffman@30488
    49
      unfolding power2_eq_square
nipkow@29667
    50
      by (simp add: algebra_simps real_sqrt_divide sqrt4)
chaieb@26123
    51
     from y0 xy have ?thesis  apply (simp add: csqrt_def power2_eq_square)
chaieb@26123
    52
       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])
chaieb@26123
    53
      using th1 th2  ..}
chaieb@26123
    54
  ultimately show ?thesis by blast
chaieb@26123
    55
qed
chaieb@26123
    56
chaieb@26123
    57
huffman@27445
    58
subsection{* More lemmas about module of complex numbers *}
chaieb@26123
    59
chaieb@26123
    60
lemma complex_of_real_power: "complex_of_real x ^ n = complex_of_real (x^n)"
huffman@27514
    61
  by (rule of_real_power [symmetric])
chaieb@26123
    62
chaieb@26123
    63
text{* The triangle inequality for cmod *}
chaieb@26123
    64
lemma complex_mod_triangle_sub: "cmod w \<le> cmod (w + z) + norm z"
chaieb@26123
    65
  using complex_mod_triangle_ineq2[of "w + z" "-z"] by auto
chaieb@26123
    66
huffman@27445
    67
subsection{* Basic lemmas about complex polynomials *}
chaieb@26123
    68
chaieb@26123
    69
lemma poly_bound_exists:
chaieb@26123
    70
  shows "\<exists>m. m > 0 \<and> (\<forall>z. cmod z <= r \<longrightarrow> cmod (poly p z) \<le> m)"
chaieb@26123
    71
proof(induct p)
huffman@30488
    72
  case 0 thus ?case by (rule exI[where x=1], simp)
chaieb@26123
    73
next
huffman@29464
    74
  case (pCons c cs)
huffman@29464
    75
  from pCons.hyps obtain m where m: "\<forall>z. cmod z \<le> r \<longrightarrow> cmod (poly cs z) \<le> m"
chaieb@26123
    76
    by blast
chaieb@26123
    77
  let ?k = " 1 + cmod c + \<bar>r * m\<bar>"
huffman@27514
    78
  have kp: "?k > 0" using abs_ge_zero[of "r*m"] norm_ge_zero[of c] by arith
chaieb@26123
    79
  {fix z
chaieb@26123
    80
    assume H: "cmod z \<le> r"
chaieb@26123
    81
    from m H have th: "cmod (poly cs z) \<le> m" by blast
huffman@27514
    82
    from H have rp: "r \<ge> 0" using norm_ge_zero[of z] by arith
huffman@29464
    83
    have "cmod (poly (pCons c cs) z) \<le> cmod c + cmod (z* poly cs z)"
huffman@27514
    84
      using norm_triangle_ineq[of c "z* poly cs z"] by simp
huffman@27514
    85
    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)
chaieb@26123
    86
    also have "\<dots> \<le> ?k" by simp
huffman@29464
    87
    finally have "cmod (poly (pCons c cs) z) \<le> ?k" .}
chaieb@26123
    88
  with kp show ?case by blast
chaieb@26123
    89
qed
chaieb@26123
    90
chaieb@26123
    91
chaieb@26123
    92
text{* Offsetting the variable in a polynomial gives another of same degree *}
huffman@29464
    93
haftmann@52380
    94
definition offset_poly :: "'a::comm_semiring_0 poly \<Rightarrow> 'a \<Rightarrow> 'a poly"
haftmann@52380
    95
where
haftmann@52380
    96
  "offset_poly p h = fold_coeffs (\<lambda>a q. smult h q + pCons a q) p 0"
huffman@29464
    97
huffman@29464
    98
lemma offset_poly_0: "offset_poly 0 h = 0"
haftmann@52380
    99
  by (simp add: offset_poly_def)
huffman@29464
   100
huffman@29464
   101
lemma offset_poly_pCons:
huffman@29464
   102
  "offset_poly (pCons a p) h =
huffman@29464
   103
    smult h (offset_poly p h) + pCons a (offset_poly p h)"
haftmann@52380
   104
  by (cases "p = 0 \<and> a = 0") (auto simp add: offset_poly_def)
huffman@29464
   105
huffman@29464
   106
lemma offset_poly_single: "offset_poly [:a:] h = [:a:]"
huffman@29464
   107
by (simp add: offset_poly_pCons offset_poly_0)
huffman@29464
   108
huffman@29464
   109
lemma poly_offset_poly: "poly (offset_poly p h) x = poly p (h + x)"
huffman@29464
   110
apply (induct p)
huffman@29464
   111
apply (simp add: offset_poly_0)
nipkow@29667
   112
apply (simp add: offset_poly_pCons algebra_simps)
huffman@29464
   113
done
huffman@29464
   114
huffman@29464
   115
lemma offset_poly_eq_0_lemma: "smult c p + pCons a p = 0 \<Longrightarrow> p = 0"
huffman@29464
   116
by (induct p arbitrary: a, simp, force)
chaieb@26123
   117
huffman@29464
   118
lemma offset_poly_eq_0_iff: "offset_poly p h = 0 \<longleftrightarrow> p = 0"
huffman@29464
   119
apply (safe intro!: offset_poly_0)
huffman@29464
   120
apply (induct p, simp)
huffman@29464
   121
apply (simp add: offset_poly_pCons)
huffman@29464
   122
apply (frule offset_poly_eq_0_lemma, simp)
huffman@29464
   123
done
huffman@29464
   124
huffman@29464
   125
lemma degree_offset_poly: "degree (offset_poly p h) = degree p"
huffman@29464
   126
apply (induct p)
huffman@29464
   127
apply (simp add: offset_poly_0)
huffman@29464
   128
apply (case_tac "p = 0")
huffman@29464
   129
apply (simp add: offset_poly_0 offset_poly_pCons)
huffman@29464
   130
apply (simp add: offset_poly_pCons)
huffman@29464
   131
apply (subst degree_add_eq_right)
huffman@29464
   132
apply (rule le_less_trans [OF degree_smult_le])
huffman@29464
   133
apply (simp add: offset_poly_eq_0_iff)
huffman@29464
   134
apply (simp add: offset_poly_eq_0_iff)
huffman@29464
   135
done
huffman@29464
   136
huffman@29478
   137
definition
huffman@29538
   138
  "psize p = (if p = 0 then 0 else Suc (degree p))"
huffman@29464
   139
huffman@29538
   140
lemma psize_eq_0_iff [simp]: "psize p = 0 \<longleftrightarrow> p = 0"
huffman@29538
   141
  unfolding psize_def by simp
huffman@29464
   142
huffman@29538
   143
lemma poly_offset: "\<exists> q. psize q = psize p \<and> (\<forall>x. poly q (x::complex) = poly p (a + x))"
huffman@29464
   144
proof (intro exI conjI)
huffman@29538
   145
  show "psize (offset_poly p a) = psize p"
huffman@29538
   146
    unfolding psize_def
huffman@29464
   147
    by (simp add: offset_poly_eq_0_iff degree_offset_poly)
huffman@29464
   148
  show "\<forall>x. poly (offset_poly p a) x = poly p (a + x)"
huffman@29464
   149
    by (simp add: poly_offset_poly)
chaieb@26123
   150
qed
chaieb@26123
   151
chaieb@26123
   152
text{* An alternative useful formulation of completeness of the reals *}
chaieb@26123
   153
lemma real_sup_exists: assumes ex: "\<exists>x. P x" and bz: "\<exists>z. \<forall>x. P x \<longrightarrow> x < z"
chaieb@26123
   154
  shows "\<exists>(s::real). \<forall>y. (\<exists>x. P x \<and> y < x) \<longleftrightarrow> y < s"
hoelzl@54263
   155
proof
hoelzl@54263
   156
  from bz have "bdd_above (Collect P)"
hoelzl@54263
   157
    by (force intro: less_imp_le)
hoelzl@54263
   158
  then show "\<forall>y. (\<exists>x. P x \<and> y < x) \<longleftrightarrow> y < Sup (Collect P)"
hoelzl@54263
   159
    using ex bz by (subst less_cSup_iff) auto
chaieb@26123
   160
qed
chaieb@26123
   161
huffman@27445
   162
subsection {* Fundamental theorem of algebra *}
chaieb@26123
   163
lemma  unimodular_reduce_norm:
chaieb@26123
   164
  assumes md: "cmod z = 1"
chaieb@26123
   165
  shows "cmod (z + 1) < 1 \<or> cmod (z - 1) < 1 \<or> cmod (z + ii) < 1 \<or> cmod (z - ii) < 1"
chaieb@26123
   166
proof-
chaieb@26123
   167
  obtain x y where z: "z = Complex x y " by (cases z, auto)
wenzelm@53077
   168
  from md z have xy: "x\<^sup>2 + y\<^sup>2 = 1" by (simp add: cmod_def)
chaieb@26123
   169
  {assume C: "cmod (z + 1) \<ge> 1" "cmod (z - 1) \<ge> 1" "cmod (z + ii) \<ge> 1" "cmod (z - ii) \<ge> 1"
chaieb@26123
   170
    from C z xy have "2*x \<le> 1" "2*x \<ge> -1" "2*y \<le> 1" "2*y \<ge> -1"
nipkow@29667
   171
      by (simp_all add: cmod_def power2_eq_square algebra_simps)
chaieb@26123
   172
    hence "abs (2*x) \<le> 1" "abs (2*y) \<le> 1" by simp_all
wenzelm@53077
   173
    hence "(abs (2 * x))\<^sup>2 <= 1\<^sup>2" "(abs (2 * y))\<^sup>2 <= 1\<^sup>2"
chaieb@26123
   174
      by - (rule power_mono, simp, simp)+
wenzelm@53077
   175
    hence th0: "4*x\<^sup>2 \<le> 1" "4*y\<^sup>2 \<le> 1"
wenzelm@51541
   176
      by (simp_all add: power_mult_distrib)
chaieb@26123
   177
    from add_mono[OF th0] xy have False by simp }
chaieb@26123
   178
  thus ?thesis unfolding linorder_not_le[symmetric] by blast
chaieb@26123
   179
qed
chaieb@26123
   180
wenzelm@26135
   181
text{* Hence we can always reduce modulus of @{text "1 + b z^n"} if nonzero *}
chaieb@26123
   182
lemma reduce_poly_simple:
chaieb@26123
   183
 assumes b: "b \<noteq> 0" and n: "n\<noteq>0"
chaieb@26123
   184
  shows "\<exists>z. cmod (1 + b * z^n) < 1"
chaieb@26123
   185
using n
chaieb@26123
   186
proof(induct n rule: nat_less_induct)
chaieb@26123
   187
  fix n
chaieb@26123
   188
  assume IH: "\<forall>m<n. m \<noteq> 0 \<longrightarrow> (\<exists>z. cmod (1 + b * z ^ m) < 1)" and n: "n \<noteq> 0"
chaieb@26123
   189
  let ?P = "\<lambda>z n. cmod (1 + b * z ^ n) < 1"
chaieb@26123
   190
  {assume e: "even n"
chaieb@26123
   191
    hence "\<exists>m. n = 2*m" by presburger
chaieb@26123
   192
    then obtain m where m: "n = 2*m" by blast
chaieb@26123
   193
    from n m have "m\<noteq>0" "m < n" by presburger+
chaieb@26123
   194
    with IH[rule_format, of m] obtain z where z: "?P z m" by blast
chaieb@26123
   195
    from z have "?P (csqrt z) n" by (simp add: m power_mult csqrt)
chaieb@26123
   196
    hence "\<exists>z. ?P z n" ..}
chaieb@26123
   197
  moreover
chaieb@26123
   198
  {assume o: "odd n"
chaieb@26123
   199
    have th0: "cmod (complex_of_real (cmod b) / b) = 1"
huffman@36975
   200
      using b by (simp add: norm_divide)
chaieb@26123
   201
    from o have "\<exists>m. n = Suc (2*m)" by presburger+
chaieb@26123
   202
    then obtain m where m: "n = Suc (2*m)" by blast
chaieb@26123
   203
    from unimodular_reduce_norm[OF th0] o
chaieb@26123
   204
    have "\<exists>v. cmod (complex_of_real (cmod b) / b + v^n) < 1"
chaieb@26123
   205
      apply (cases "cmod (complex_of_real (cmod b) / b + 1) < 1", rule_tac x="1" in exI, simp)
haftmann@54489
   206
      apply (cases "cmod (complex_of_real (cmod b) / b - 1) < 1", rule_tac x="-1" in exI, simp)
chaieb@26123
   207
      apply (cases "cmod (complex_of_real (cmod b) / b + ii) < 1")
chaieb@26123
   208
      apply (cases "even m", rule_tac x="ii" in exI, simp add: m power_mult)
chaieb@26123
   209
      apply (rule_tac x="- ii" in exI, simp add: m power_mult)
haftmann@54230
   210
      apply (cases "even m", rule_tac x="- ii" in exI, simp add: m power_mult)
haftmann@54489
   211
      apply (auto simp add: m power_mult)
haftmann@54489
   212
      apply (rule_tac x="ii" in exI)
haftmann@54489
   213
      apply (auto simp add: m power_mult)
chaieb@26123
   214
      done
chaieb@26123
   215
    then obtain v where v: "cmod (complex_of_real (cmod b) / b + v^n) < 1" by blast
chaieb@26123
   216
    let ?w = "v / complex_of_real (root n (cmod b))"
chaieb@26123
   217
    from odd_real_root_pow[OF o, of "cmod b"]
huffman@30488
   218
    have th1: "?w ^ n = v^n / complex_of_real (cmod b)"
chaieb@26123
   219
      by (simp add: power_divide complex_of_real_power)
huffman@27514
   220
    have th2:"cmod (complex_of_real (cmod b) / b) = 1" using b by (simp add: norm_divide)
chaieb@26123
   221
    hence th3: "cmod (complex_of_real (cmod b) / b) \<ge> 0" by simp
chaieb@26123
   222
    have th4: "cmod (complex_of_real (cmod b) / b) *
chaieb@26123
   223
   cmod (1 + b * (v ^ n / complex_of_real (cmod b)))
chaieb@26123
   224
   < cmod (complex_of_real (cmod b) / b) * 1"
webertj@49962
   225
      apply (simp only: norm_mult[symmetric] distrib_left)
chaieb@26123
   226
      using b v by (simp add: th2)
chaieb@26123
   227
chaieb@26123
   228
    from mult_less_imp_less_left[OF th4 th3]
huffman@30488
   229
    have "?P ?w n" unfolding th1 .
chaieb@26123
   230
    hence "\<exists>z. ?P z n" .. }
chaieb@26123
   231
  ultimately show "\<exists>z. ?P z n" by blast
chaieb@26123
   232
qed
chaieb@26123
   233
chaieb@26123
   234
text{* Bolzano-Weierstrass type property for closed disc in complex plane. *}
chaieb@26123
   235
chaieb@26123
   236
lemma metric_bound_lemma: "cmod (x - y) <= \<bar>Re x - Re y\<bar> + \<bar>Im x - Im y\<bar>"
chaieb@26123
   237
  using real_sqrt_sum_squares_triangle_ineq[of "Re x - Re y" 0 0 "Im x - Im y" ]
chaieb@26123
   238
  unfolding cmod_def by simp
chaieb@26123
   239
chaieb@26123
   240
lemma bolzano_weierstrass_complex_disc:
chaieb@26123
   241
  assumes r: "\<forall>n. cmod (s n) \<le> r"
chaieb@26123
   242
  shows "\<exists>f z. subseq f \<and> (\<forall>e >0. \<exists>N. \<forall>n \<ge> N. cmod (s (f n) - z) < e)"
chaieb@26123
   243
proof-
huffman@30488
   244
  from seq_monosub[of "Re o s"]
lp15@55358
   245
  obtain f where f: "subseq f" "monoseq (\<lambda>n. Re (s (f n)))"
chaieb@26123
   246
    unfolding o_def by blast
huffman@30488
   247
  from seq_monosub[of "Im o s o f"]
huffman@30488
   248
  obtain g where g: "subseq g" "monoseq (\<lambda>n. Im (s(f(g n))))" unfolding o_def by blast
chaieb@26123
   249
  let ?h = "f o g"
huffman@30488
   250
  from r[rule_format, of 0] have rp: "r \<ge> 0" using norm_ge_zero[of "s 0"] by arith
huffman@30488
   251
  have th:"\<forall>n. r + 1 \<ge> \<bar> Re (s n)\<bar>"
chaieb@26123
   252
  proof
chaieb@26123
   253
    fix n
chaieb@26123
   254
    from abs_Re_le_cmod[of "s n"] r[rule_format, of n]  show "\<bar>Re (s n)\<bar> \<le> r + 1" by arith
chaieb@26123
   255
  qed
chaieb@26123
   256
  have conv1: "convergent (\<lambda>n. Re (s ( f n)))"
chaieb@26123
   257
    apply (rule Bseq_monoseq_convergent)
chaieb@26123
   258
    apply (simp add: Bseq_def)
lp15@55358
   259
    apply (metis gt_ex le_less_linear less_trans order.trans th)
chaieb@26123
   260
    using f(2) .
huffman@30488
   261
  have th:"\<forall>n. r + 1 \<ge> \<bar> Im (s n)\<bar>"
chaieb@26123
   262
  proof
chaieb@26123
   263
    fix n
chaieb@26123
   264
    from abs_Im_le_cmod[of "s n"] r[rule_format, of n]  show "\<bar>Im (s n)\<bar> \<le> r + 1" by arith
chaieb@26123
   265
  qed
chaieb@26123
   266
chaieb@26123
   267
  have conv2: "convergent (\<lambda>n. Im (s (f (g n))))"
chaieb@26123
   268
    apply (rule Bseq_monoseq_convergent)
chaieb@26123
   269
    apply (simp add: Bseq_def)
lp15@55358
   270
    apply (metis gt_ex le_less_linear less_trans order.trans th)
chaieb@26123
   271
    using g(2) .
chaieb@26123
   272
huffman@30488
   273
  from conv1[unfolded convergent_def] obtain x where "LIMSEQ (\<lambda>n. Re (s (f n))) x"
huffman@30488
   274
    by blast
huffman@30488
   275
  hence  x: "\<forall>r>0. \<exists>n0. \<forall>n\<ge>n0. \<bar> Re (s (f n)) - x \<bar> < r"
huffman@31337
   276
    unfolding LIMSEQ_iff real_norm_def .
chaieb@26123
   277
huffman@30488
   278
  from conv2[unfolded convergent_def] obtain y where "LIMSEQ (\<lambda>n. Im (s (f (g n)))) y"
huffman@30488
   279
    by blast
huffman@30488
   280
  hence  y: "\<forall>r>0. \<exists>n0. \<forall>n\<ge>n0. \<bar> Im (s (f (g n))) - y \<bar> < r"
huffman@31337
   281
    unfolding LIMSEQ_iff real_norm_def .
chaieb@26123
   282
  let ?w = "Complex x y"
huffman@30488
   283
  from f(1) g(1) have hs: "subseq ?h" unfolding subseq_def by auto
chaieb@26123
   284
  {fix e assume ep: "e > (0::real)"
chaieb@26123
   285
    hence e2: "e/2 > 0" by simp
chaieb@26123
   286
    from x[rule_format, OF e2] y[rule_format, OF e2]
chaieb@26123
   287
    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
chaieb@26123
   288
    {fix n assume nN12: "n \<ge> N1 + N2"
chaieb@26123
   289
      hence nN1: "g n \<ge> N1" and nN2: "n \<ge> N2" using seq_suble[OF g(1), of n] by arith+
chaieb@26123
   290
      from add_strict_mono[OF N1[rule_format, OF nN1] N2[rule_format, OF nN2]]
huffman@30488
   291
      have "cmod (s (?h n) - ?w) < e"
wenzelm@32960
   292
        using metric_bound_lemma[of "s (f (g n))" ?w] by simp }
chaieb@26123
   293
    hence "\<exists>N. \<forall>n\<ge>N. cmod (s (?h n) - ?w) < e" by blast }
huffman@30488
   294
  with hs show ?thesis  by blast
chaieb@26123
   295
qed
chaieb@26123
   296
chaieb@26123
   297
text{* Polynomial is continuous. *}
chaieb@26123
   298
chaieb@26123
   299
lemma poly_cont:
huffman@30488
   300
  assumes ep: "e > 0"
chaieb@26123
   301
  shows "\<exists>d >0. \<forall>w. 0 < cmod (w - z) \<and> cmod (w - z) < d \<longrightarrow> cmod (poly p w - poly p z) < e"
chaieb@26123
   302
proof-
huffman@29464
   303
  obtain q where q: "degree q = degree p" "\<And>x. poly q x = poly p (z + x)"
huffman@29464
   304
  proof
huffman@29464
   305
    show "degree (offset_poly p z) = degree p"
huffman@29464
   306
      by (rule degree_offset_poly)
huffman@29464
   307
    show "\<And>x. poly (offset_poly p z) x = poly p (z + x)"
huffman@29464
   308
      by (rule poly_offset_poly)
huffman@29464
   309
  qed
chaieb@26123
   310
  {fix w
chaieb@26123
   311
    note q(2)[of "w - z", simplified]}
chaieb@26123
   312
  note th = this
chaieb@26123
   313
  show ?thesis unfolding th[symmetric]
chaieb@26123
   314
  proof(induct q)
huffman@29464
   315
    case 0 thus ?case  using ep by auto
chaieb@26123
   316
  next
huffman@29464
   317
    case (pCons c cs)
huffman@30488
   318
    from poly_bound_exists[of 1 "cs"]
chaieb@26123
   319
    obtain m where m: "m > 0" "\<And>z. cmod z \<le> 1 \<Longrightarrow> cmod (poly cs z) \<le> m" by blast
chaieb@26123
   320
    from ep m(1) have em0: "e/m > 0" by (simp add: field_simps)
chaieb@26123
   321
    have one0: "1 > (0::real)"  by arith
huffman@30488
   322
    from real_lbound_gt_zero[OF one0 em0]
chaieb@26123
   323
    obtain d where d: "d >0" "d < 1" "d < e / m" by blast
huffman@30488
   324
    from d(1,3) m(1) have dm: "d*m > 0" "d*m < e"
huffman@36778
   325
      by (simp_all add: field_simps mult_pos_pos)
huffman@30488
   326
    show ?case
huffman@27514
   327
      proof(rule ex_forward[OF real_lbound_gt_zero[OF one0 em0]], clarsimp simp add: norm_mult)
wenzelm@32960
   328
        fix d w
wenzelm@32960
   329
        assume H: "d > 0" "d < 1" "d < e/m" "w\<noteq>z" "cmod (w-z) < d"
wenzelm@32960
   330
        hence d1: "cmod (w-z) \<le> 1" "d \<ge> 0" by simp_all
wenzelm@32960
   331
        from H(3) m(1) have dme: "d*m < e" by (simp add: field_simps)
wenzelm@32960
   332
        from H have th: "cmod (w-z) \<le> d" by simp
wenzelm@32960
   333
        from mult_mono[OF th m(2)[OF d1(1)] d1(2) norm_ge_zero] dme
wenzelm@32960
   334
        show "cmod (w - z) * cmod (poly cs (w - z)) < e" by simp
huffman@30488
   335
      qed
chaieb@26123
   336
    qed
chaieb@26123
   337
qed
chaieb@26123
   338
huffman@30488
   339
text{* Hence a polynomial attains minimum on a closed disc
chaieb@26123
   340
  in the complex plane. *}
chaieb@26123
   341
lemma  poly_minimum_modulus_disc:
chaieb@26123
   342
  "\<exists>z. \<forall>w. cmod w \<le> r \<longrightarrow> cmod (poly p z) \<le> cmod (poly p w)"
chaieb@26123
   343
proof-
lp15@55358
   344
  {assume "\<not> r \<ge> 0" hence ?thesis
lp15@55358
   345
    by (metis norm_ge_zero order.trans)}
chaieb@26123
   346
  moreover
chaieb@26123
   347
  {assume rp: "r \<ge> 0"
huffman@30488
   348
    from rp have "cmod 0 \<le> r \<and> cmod (poly p 0) = - (- cmod (poly p 0))" by simp
chaieb@26123
   349
    hence mth1: "\<exists>x z. cmod z \<le> r \<and> cmod (poly p z) = - x"  by blast
chaieb@26123
   350
    {fix x z
chaieb@26123
   351
      assume H: "cmod z \<le> r" "cmod (poly p z) = - x" "\<not>x < 1"
chaieb@26123
   352
      hence "- x < 0 " by arith
huffman@27514
   353
      with H(2) norm_ge_zero[of "poly p z"]  have False by simp }
chaieb@26123
   354
    then have mth2: "\<exists>z. \<forall>x. (\<exists>z. cmod z \<le> r \<and> cmod (poly p z) = - x) \<longrightarrow> x < z" by blast
huffman@30488
   355
    from real_sup_exists[OF mth1 mth2] obtain s where
chaieb@26123
   356
      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
chaieb@26123
   357
    let ?m = "-s"
chaieb@26123
   358
    {fix y
huffman@30488
   359
      from s[rule_format, of "-y"] have
huffman@30488
   360
    "(\<exists>z x. cmod z \<le> r \<and> -(- cmod (poly p z)) < y) \<longleftrightarrow> ?m < y"
wenzelm@32960
   361
        unfolding minus_less_iff[of y ] equation_minus_iff by blast }
chaieb@26123
   362
    note s1 = this[unfolded minus_minus]
huffman@30488
   363
    from s1[of ?m] have s1m: "\<And>z x. cmod z \<le> r \<Longrightarrow> cmod (poly p z) \<ge> ?m"
chaieb@26123
   364
      by auto
chaieb@26123
   365
    {fix n::nat
huffman@30488
   366
      from s1[rule_format, of "?m + 1/real (Suc n)"]
chaieb@26123
   367
      have "\<exists>z. cmod z \<le> r \<and> cmod (poly p z) < - s + 1 / real (Suc n)"
wenzelm@32960
   368
        by simp}
chaieb@26123
   369
    hence th: "\<forall>n. \<exists>z. cmod z \<le> r \<and> cmod (poly p z) < - s + 1 / real (Suc n)" ..
huffman@30488
   370
    from choice[OF th] obtain g where
huffman@30488
   371
      g: "\<forall>n. cmod (g n) \<le> r" "\<forall>n. cmod (poly p (g n)) <?m+1 /real(Suc n)"
chaieb@26123
   372
      by blast
huffman@30488
   373
    from bolzano_weierstrass_complex_disc[OF g(1)]
chaieb@26123
   374
    obtain f z where fz: "subseq f" "\<forall>e>0. \<exists>N. \<forall>n\<ge>N. cmod (g (f n) - z) < e"
huffman@30488
   375
      by blast
huffman@30488
   376
    {fix w
chaieb@26123
   377
      assume wr: "cmod w \<le> r"
chaieb@26123
   378
      let ?e = "\<bar>cmod (poly p z) - ?m\<bar>"
chaieb@26123
   379
      {assume e: "?e > 0"
wenzelm@32960
   380
        hence e2: "?e/2 > 0" by simp
wenzelm@32960
   381
        from poly_cont[OF e2, of z p] obtain d where
wenzelm@32960
   382
          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
wenzelm@32960
   383
        {fix w assume w: "cmod (w - z) < d"
wenzelm@32960
   384
          have "cmod(poly p w - poly p z) < ?e / 2"
wenzelm@32960
   385
            using d(2)[rule_format, of w] w e by (cases "w=z", simp_all)}
wenzelm@32960
   386
        note th1 = this
huffman@30488
   387
wenzelm@32960
   388
        from fz(2)[rule_format, OF d(1)] obtain N1 where
wenzelm@32960
   389
          N1: "\<forall>n\<ge>N1. cmod (g (f n) - z) < d" by blast
wenzelm@32960
   390
        from reals_Archimedean2[of "2/?e"] obtain N2::nat where
wenzelm@32960
   391
          N2: "2/?e < real N2" by blast
wenzelm@32960
   392
        have th2: "cmod(poly p (g(f(N1 + N2))) - poly p z) < ?e/2"
wenzelm@32960
   393
          using N1[rule_format, of "N1 + N2"] th1 by simp
wenzelm@32960
   394
        {fix a b e2 m :: real
wenzelm@32960
   395
        have "a < e2 \<Longrightarrow> abs(b - m) < e2 \<Longrightarrow> 2 * e2 <= abs(b - m) + a
chaieb@26123
   396
          ==> False" by arith}
chaieb@26123
   397
      note th0 = this
huffman@30488
   398
      have ath:
wenzelm@32960
   399
        "\<And>m x e. m <= x \<Longrightarrow>  x < m + e ==> abs(x - m::real) < e" by arith
chaieb@26123
   400
      from s1m[OF g(1)[rule_format]]
chaieb@26123
   401
      have th31: "?m \<le> cmod(poly p (g (f (N1 + N2))))" .
chaieb@26123
   402
      from seq_suble[OF fz(1), of "N1+N2"]
chaieb@26123
   403
      have th00: "real (Suc (N1+N2)) \<le> real (Suc (f (N1+N2)))" by simp
huffman@30488
   404
      have th000: "0 \<le> (1::real)" "(1::real) \<le> 1" "real (Suc (N1+N2)) > 0"
wenzelm@32960
   405
        using N2 by auto
chaieb@26123
   406
      from frac_le[OF th000 th00] have th00: "?m +1 / real (Suc (f (N1 + N2))) \<le> ?m + 1 / real (Suc (N1 + N2))" by simp
chaieb@26123
   407
      from g(2)[rule_format, of "f (N1 + N2)"]
chaieb@26123
   408
      have th01:"cmod (poly p (g (f (N1 + N2)))) < - s + 1 / real (Suc (f (N1 + N2)))" .
chaieb@26123
   409
      from order_less_le_trans[OF th01 th00]
chaieb@26123
   410
      have th32: "cmod(poly p (g (f (N1 + N2)))) < ?m + (1/ real(Suc (N1 + N2)))" .
chaieb@26123
   411
      from N2 have "2/?e < real (Suc (N1 + N2))" by arith
chaieb@26123
   412
      with e2 less_imp_inverse_less[of "2/?e" "real (Suc (N1 + N2))"]
chaieb@26123
   413
      have "?e/2 > 1/ real (Suc (N1 + N2))" by (simp add: inverse_eq_divide)
chaieb@26123
   414
      with ath[OF th31 th32]
huffman@30488
   415
      have thc1:"\<bar>cmod(poly p (g (f (N1 + N2)))) - ?m\<bar>< ?e/2" by arith
huffman@30488
   416
      have ath2: "\<And>(a::real) b c m. \<bar>a - b\<bar> <= c ==> \<bar>b - m\<bar> <= \<bar>a - m\<bar> + c"
wenzelm@32960
   417
        by arith
chaieb@26123
   418
      have th22: "\<bar>cmod (poly p (g (f (N1 + N2)))) - cmod (poly p z)\<bar>
huffman@30488
   419
\<le> cmod (poly p (g (f (N1 + N2))) - poly p z)"
wenzelm@32960
   420
        by (simp add: norm_triangle_ineq3)
chaieb@26123
   421
      from ath2[OF th22, of ?m]
chaieb@26123
   422
      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
chaieb@26123
   423
      from th0[OF th2 thc1 thc2] have False .}
chaieb@26123
   424
      hence "?e = 0" by auto
huffman@30488
   425
      then have "cmod (poly p z) = ?m" by simp
chaieb@26123
   426
      with s1m[OF wr]
chaieb@26123
   427
      have "cmod (poly p z) \<le> cmod (poly p w)" by simp }
chaieb@26123
   428
    hence ?thesis by blast}
chaieb@26123
   429
  ultimately show ?thesis by blast
chaieb@26123
   430
qed
chaieb@26123
   431
wenzelm@53077
   432
lemma "(rcis (sqrt (abs r)) (a/2))\<^sup>2 = rcis (abs r) a"
chaieb@26123
   433
  unfolding power2_eq_square
chaieb@26123
   434
  apply (simp add: rcis_mult)
chaieb@26123
   435
  apply (simp add: power2_eq_square[symmetric])
chaieb@26123
   436
  done
chaieb@26123
   437
huffman@30488
   438
lemma cispi: "cis pi = -1"
chaieb@26123
   439
  unfolding cis_def
chaieb@26123
   440
  by simp
chaieb@26123
   441
wenzelm@53077
   442
lemma "(rcis (sqrt (abs r)) ((pi + a)/2))\<^sup>2 = rcis (- abs r) a"
chaieb@26123
   443
  unfolding power2_eq_square
chaieb@26123
   444
  apply (simp add: rcis_mult add_divide_distrib)
chaieb@26123
   445
  apply (simp add: power2_eq_square[symmetric] rcis_def cispi cis_mult[symmetric])
chaieb@26123
   446
  done
chaieb@26123
   447
chaieb@26123
   448
text {* Nonzero polynomial in z goes to infinity as z does. *}
chaieb@26123
   449
chaieb@26123
   450
lemma poly_infinity:
huffman@29464
   451
  assumes ex: "p \<noteq> 0"
huffman@29464
   452
  shows "\<exists>r. \<forall>z. r \<le> cmod z \<longrightarrow> d \<le> cmod (poly (pCons a p) z)"
chaieb@26123
   453
using ex
chaieb@26123
   454
proof(induct p arbitrary: a d)
huffman@30488
   455
  case (pCons c cs a d)
huffman@29464
   456
  {assume H: "cs \<noteq> 0"
huffman@29464
   457
    with pCons.hyps obtain r where r: "\<forall>z. r \<le> cmod z \<longrightarrow> d + cmod a \<le> cmod (poly (pCons c cs) z)" by blast
chaieb@26123
   458
    let ?r = "1 + \<bar>r\<bar>"
chaieb@26123
   459
    {fix z assume h: "1 + \<bar>r\<bar> \<le> cmod z"
chaieb@26123
   460
      have r0: "r \<le> cmod z" using h by arith
chaieb@26123
   461
      from r[rule_format, OF r0]
huffman@29464
   462
      have th0: "d + cmod a \<le> 1 * cmod(poly (pCons c cs) z)" by arith
chaieb@26123
   463
      from h have z1: "cmod z \<ge> 1" by arith
huffman@29464
   464
      from order_trans[OF th0 mult_right_mono[OF z1 norm_ge_zero[of "poly (pCons c cs) z"]]]
huffman@29464
   465
      have th1: "d \<le> cmod(z * poly (pCons c cs) z) - cmod a"
wenzelm@32960
   466
        unfolding norm_mult by (simp add: algebra_simps)
huffman@29464
   467
      from complex_mod_triangle_sub[of "z * poly (pCons c cs) z" a]
huffman@30488
   468
      have th2: "cmod(z * poly (pCons c cs) z) - cmod a \<le> cmod (poly (pCons a (pCons c cs)) z)"
wenzelm@51541
   469
        by (simp add: algebra_simps)
huffman@29464
   470
      from th1 th2 have "d \<le> cmod (poly (pCons a (pCons c cs)) z)"  by arith}
chaieb@26123
   471
    hence ?case by blast}
chaieb@26123
   472
  moreover
huffman@29464
   473
  {assume cs0: "\<not> (cs \<noteq> 0)"
huffman@29464
   474
    with pCons.prems have c0: "c \<noteq> 0" by simp
huffman@29464
   475
    from cs0 have cs0': "cs = 0" by simp
chaieb@26123
   476
    {fix z
chaieb@26123
   477
      assume h: "(\<bar>d\<bar> + cmod a) / cmod c \<le> cmod z"
chaieb@26123
   478
      from c0 have "cmod c > 0" by simp
huffman@30488
   479
      from h c0 have th0: "\<bar>d\<bar> + cmod a \<le> cmod (z*c)"
wenzelm@32960
   480
        by (simp add: field_simps norm_mult)
chaieb@26123
   481
      have ath: "\<And>mzh mazh ma. mzh <= mazh + ma ==> abs(d) + ma <= mzh ==> d <= mazh" by arith
chaieb@26123
   482
      from complex_mod_triangle_sub[of "z*c" a ]
chaieb@26123
   483
      have th1: "cmod (z * c) \<le> cmod (a + z * c) + cmod a"
wenzelm@32960
   484
        by (simp add: algebra_simps)
huffman@30488
   485
      from ath[OF th1 th0] have "d \<le> cmod (poly (pCons a (pCons c cs)) z)"
huffman@29464
   486
        using cs0' by simp}
chaieb@26123
   487
    then have ?case  by blast}
chaieb@26123
   488
  ultimately show ?case by blast
chaieb@26123
   489
qed simp
chaieb@26123
   490
chaieb@26123
   491
text {* Hence polynomial's modulus attains its minimum somewhere. *}
chaieb@26123
   492
lemma poly_minimum_modulus:
chaieb@26123
   493
  "\<exists>z.\<forall>w. cmod (poly p z) \<le> cmod (poly p w)"
chaieb@26123
   494
proof(induct p)
huffman@30488
   495
  case (pCons c cs)
huffman@29464
   496
  {assume cs0: "cs \<noteq> 0"
huffman@29464
   497
    from poly_infinity[OF cs0, of "cmod (poly (pCons c cs) 0)" c]
huffman@29464
   498
    obtain r where r: "\<And>z. r \<le> cmod z \<Longrightarrow> cmod (poly (pCons c cs) 0) \<le> cmod (poly (pCons c cs) z)" by blast
chaieb@26123
   499
    have ath: "\<And>z r. r \<le> cmod z \<or> cmod z \<le> \<bar>r\<bar>" by arith
huffman@30488
   500
    from poly_minimum_modulus_disc[of "\<bar>r\<bar>" "pCons c cs"]
huffman@29464
   501
    obtain v where v: "\<And>w. cmod w \<le> \<bar>r\<bar> \<Longrightarrow> cmod (poly (pCons c cs) v) \<le> cmod (poly (pCons c cs) w)" by blast
chaieb@26123
   502
    {fix z assume z: "r \<le> cmod z"
huffman@30488
   503
      from v[of 0] r[OF z]
huffman@29464
   504
      have "cmod (poly (pCons c cs) v) \<le> cmod (poly (pCons c cs) z)"
wenzelm@32960
   505
        by simp }
chaieb@26123
   506
    note v0 = this
chaieb@26123
   507
    from v0 v ath[of r] have ?case by blast}
chaieb@26123
   508
  moreover
huffman@29464
   509
  {assume cs0: "\<not> (cs \<noteq> 0)"
huffman@29464
   510
    hence th:"cs = 0" by simp
huffman@29464
   511
    from th pCons.hyps have ?case by simp}
chaieb@26123
   512
  ultimately show ?case by blast
chaieb@26123
   513
qed simp
chaieb@26123
   514
chaieb@26123
   515
text{* Constant function (non-syntactic characterization). *}
chaieb@26123
   516
definition "constant f = (\<forall>x y. f x = f y)"
chaieb@26123
   517
huffman@29538
   518
lemma nonconstant_length: "\<not> (constant (poly p)) \<Longrightarrow> psize p \<ge> 2"
huffman@29538
   519
  unfolding constant_def psize_def
chaieb@26123
   520
  apply (induct p, auto)
chaieb@26123
   521
  done
huffman@30488
   522
chaieb@26123
   523
lemma poly_replicate_append:
haftmann@31021
   524
  "poly (monom 1 n * p) (x::'a::{comm_ring_1}) = x^n * poly p x"
huffman@29464
   525
  by (simp add: poly_monom)
chaieb@26123
   526
huffman@30488
   527
text {* Decomposition of polynomial, skipping zero coefficients
chaieb@26123
   528
  after the first.  *}
chaieb@26123
   529
chaieb@26123
   530
lemma poly_decompose_lemma:
haftmann@31021
   531
 assumes nz: "\<not>(\<forall>z. z\<noteq>0 \<longrightarrow> poly p z = (0::'a::{idom}))"
huffman@30488
   532
  shows "\<exists>k a q. a\<noteq>0 \<and> Suc (psize q + k) = psize p \<and>
huffman@29464
   533
                 (\<forall>z. poly p z = z^k * poly (pCons a q) z)"
huffman@29538
   534
unfolding psize_def
chaieb@26123
   535
using nz
chaieb@26123
   536
proof(induct p)
huffman@29464
   537
  case 0 thus ?case by simp
chaieb@26123
   538
next
huffman@29464
   539
  case (pCons c cs)
chaieb@26123
   540
  {assume c0: "c = 0"
nipkow@32456
   541
    from pCons.hyps pCons.prems c0 have ?case
nipkow@32456
   542
      apply (auto)
chaieb@26123
   543
      apply (rule_tac x="k+1" in exI)
chaieb@26123
   544
      apply (rule_tac x="a" in exI, clarsimp)
chaieb@26123
   545
      apply (rule_tac x="q" in exI)
nipkow@32456
   546
      by (auto)}
chaieb@26123
   547
  moreover
chaieb@26123
   548
  {assume c0: "c\<noteq>0"
lp15@55358
   549
    have ?case 
chaieb@26123
   550
      apply (rule exI[where x=0])
lp15@55358
   551
      apply (rule exI[where x=c], auto simp add: c0)
chaieb@26123
   552
      done}
chaieb@26123
   553
  ultimately show ?case by blast
chaieb@26123
   554
qed
chaieb@26123
   555
chaieb@26123
   556
lemma poly_decompose:
chaieb@26123
   557
  assumes nc: "~constant(poly p)"
haftmann@31021
   558
  shows "\<exists>k a q. a\<noteq>(0::'a::{idom}) \<and> k\<noteq>0 \<and>
huffman@30488
   559
               psize q + k + 1 = psize p \<and>
huffman@29464
   560
              (\<forall>z. poly p z = poly p 0 + z^k * poly (pCons a q) z)"
huffman@30488
   561
using nc
chaieb@26123
   562
proof(induct p)
huffman@29464
   563
  case 0 thus ?case by (simp add: constant_def)
chaieb@26123
   564
next
huffman@29464
   565
  case (pCons c cs)
chaieb@26123
   566
  {assume C:"\<forall>z. z \<noteq> 0 \<longrightarrow> poly cs z = 0"
chaieb@26123
   567
    {fix x y
huffman@29464
   568
      from C have "poly (pCons c cs) x = poly (pCons c cs) y" by (cases "x=0", auto)}
huffman@29464
   569
    with pCons.prems have False by (auto simp add: constant_def)}
chaieb@26123
   570
  hence th: "\<not> (\<forall>z. z \<noteq> 0 \<longrightarrow> poly cs z = 0)" ..
huffman@30488
   571
  from poly_decompose_lemma[OF th]
huffman@30488
   572
  show ?case
huffman@29464
   573
    apply clarsimp
chaieb@26123
   574
    apply (rule_tac x="k+1" in exI)
chaieb@26123
   575
    apply (rule_tac x="a" in exI)
chaieb@26123
   576
    apply simp
chaieb@26123
   577
    apply (rule_tac x="q" in exI)
huffman@29538
   578
    apply (auto simp add: psize_def split: if_splits)
chaieb@26123
   579
    done
chaieb@26123
   580
qed
chaieb@26123
   581
berghofe@34915
   582
text{* Fundamental theorem of algebra *}
chaieb@26123
   583
chaieb@26123
   584
lemma fundamental_theorem_of_algebra:
chaieb@26123
   585
  assumes nc: "~constant(poly p)"
chaieb@26123
   586
  shows "\<exists>z::complex. poly p z = 0"
chaieb@26123
   587
using nc
berghofe@34915
   588
proof(induct "psize p" arbitrary: p rule: less_induct)
berghofe@34915
   589
  case less
chaieb@26123
   590
  let ?p = "poly p"
chaieb@26123
   591
  let ?ths = "\<exists>z. ?p z = 0"
chaieb@26123
   592
berghofe@34915
   593
  from nonconstant_length[OF less(2)] have n2: "psize p \<ge> 2" .
huffman@30488
   594
  from poly_minimum_modulus obtain c where
chaieb@26123
   595
    c: "\<forall>w. cmod (?p c) \<le> cmod (?p w)" by blast
chaieb@26123
   596
  {assume pc: "?p c = 0" hence ?ths by blast}
chaieb@26123
   597
  moreover
chaieb@26123
   598
  {assume pc0: "?p c \<noteq> 0"
chaieb@26123
   599
    from poly_offset[of p c] obtain q where
huffman@29538
   600
      q: "psize q = psize p" "\<forall>x. poly q x = ?p (c+x)" by blast
chaieb@26123
   601
    {assume h: "constant (poly q)"
chaieb@26123
   602
      from q(2) have th: "\<forall>x. poly q (x - c) = ?p x" by auto
chaieb@26123
   603
      {fix x y
wenzelm@32960
   604
        from th have "?p x = poly q (x - c)" by auto
wenzelm@32960
   605
        also have "\<dots> = poly q (y - c)"
wenzelm@32960
   606
          using h unfolding constant_def by blast
wenzelm@32960
   607
        also have "\<dots> = ?p y" using th by auto
wenzelm@32960
   608
        finally have "?p x = ?p y" .}
berghofe@34915
   609
      with less(2) have False unfolding constant_def by blast }
chaieb@26123
   610
    hence qnc: "\<not> constant (poly q)" by blast
chaieb@26123
   611
    from q(2) have pqc0: "?p c = poly q 0" by simp
huffman@30488
   612
    from c pqc0 have cq0: "\<forall>w. cmod (poly q 0) \<le> cmod (?p w)" by simp
chaieb@26123
   613
    let ?a0 = "poly q 0"
huffman@30488
   614
    from pc0 pqc0 have a00: "?a0 \<noteq> 0" by simp
huffman@30488
   615
    from a00
huffman@29464
   616
    have qr: "\<forall>z. poly q z = poly (smult (inverse ?a0) q) z * ?a0"
huffman@29464
   617
      by simp
huffman@29464
   618
    let ?r = "smult (inverse ?a0) q"
huffman@29538
   619
    have lgqr: "psize q = psize ?r"
huffman@29538
   620
      using a00 unfolding psize_def degree_def
haftmann@52380
   621
      by (simp add: poly_eq_iff)
chaieb@26123
   622
    {assume h: "\<And>x y. poly ?r x = poly ?r y"
chaieb@26123
   623
      {fix x y
wenzelm@32960
   624
        from qr[rule_format, of x]
wenzelm@32960
   625
        have "poly q x = poly ?r x * ?a0" by auto
wenzelm@32960
   626
        also have "\<dots> = poly ?r y * ?a0" using h by simp
wenzelm@32960
   627
        also have "\<dots> = poly q y" using qr[rule_format, of y] by simp
wenzelm@32960
   628
        finally have "poly q x = poly q y" .}
chaieb@26123
   629
      with qnc have False unfolding constant_def by blast}
chaieb@26123
   630
    hence rnc: "\<not> constant (poly ?r)" unfolding constant_def by blast
chaieb@26123
   631
    from qr[rule_format, of 0] a00  have r01: "poly ?r 0 = 1" by auto
huffman@30488
   632
    {fix w
chaieb@26123
   633
      have "cmod (poly ?r w) < 1 \<longleftrightarrow> cmod (poly q w / ?a0) < 1"
wenzelm@32960
   634
        using qr[rule_format, of w] a00 by (simp add: divide_inverse mult_ac)
chaieb@26123
   635
      also have "\<dots> \<longleftrightarrow> cmod (poly q w) < cmod ?a0"
wenzelm@32960
   636
        using a00 unfolding norm_divide by (simp add: field_simps)
chaieb@26123
   637
      finally have "cmod (poly ?r w) < 1 \<longleftrightarrow> cmod (poly q w) < cmod ?a0" .}
chaieb@26123
   638
    note mrmq_eq = this
huffman@30488
   639
    from poly_decompose[OF rnc] obtain k a s where
huffman@30488
   640
      kas: "a\<noteq>0" "k\<noteq>0" "psize s + k + 1 = psize ?r"
huffman@29464
   641
      "\<forall>z. poly ?r z = poly ?r 0 + z^k* poly (pCons a s) z" by blast
berghofe@34915
   642
    {assume "psize p = k + 1"
berghofe@34915
   643
      with kas(3) lgqr[symmetric] q(1) have s0:"s=0" by auto
chaieb@26123
   644
      {fix w
wenzelm@32960
   645
        have "cmod (poly ?r w) = cmod (1 + a * w ^ k)"
wenzelm@32960
   646
          using kas(4)[rule_format, of w] s0 r01 by (simp add: algebra_simps)}
chaieb@26123
   647
      note hth = this [symmetric]
wenzelm@32960
   648
        from reduce_poly_simple[OF kas(1,2)]
chaieb@26123
   649
      have "\<exists>w. cmod (poly ?r w) < 1" unfolding hth by blast}
chaieb@26123
   650
    moreover
berghofe@34915
   651
    {assume kn: "psize p \<noteq> k+1"
berghofe@34915
   652
      from kn kas(3) q(1) lgqr have k1n: "k + 1 < psize p" by simp
huffman@30488
   653
      have th01: "\<not> constant (poly (pCons 1 (monom a (k - 1))))"
wenzelm@32960
   654
        unfolding constant_def poly_pCons poly_monom
wenzelm@32960
   655
        using kas(1) apply simp
wenzelm@32960
   656
        by (rule exI[where x=0], rule exI[where x=1], simp)
huffman@29538
   657
      from kas(1) kas(2) have th02: "k+1 = psize (pCons 1 (monom a (k - 1)))"
wenzelm@32960
   658
        by (simp add: psize_def degree_monom_eq)
berghofe@34915
   659
      from less(1) [OF k1n [simplified th02] th01]
chaieb@26123
   660
      obtain w where w: "1 + w^k * a = 0"
wenzelm@32960
   661
        unfolding poly_pCons poly_monom
wenzelm@32960
   662
        using kas(2) by (cases k, auto simp add: algebra_simps)
huffman@30488
   663
      from poly_bound_exists[of "cmod w" s] obtain m where
wenzelm@32960
   664
        m: "m > 0" "\<forall>z. cmod z \<le> cmod w \<longrightarrow> cmod (poly s z) \<le> m" by blast
chaieb@26123
   665
      have w0: "w\<noteq>0" using kas(2) w by (auto simp add: power_0_left)
chaieb@26123
   666
      from w have "(1 + w ^ k * a) - 1 = 0 - 1" by simp
chaieb@26123
   667
      then have wm1: "w^k * a = - 1" by simp
huffman@30488
   668
      have inv0: "0 < inverse (cmod w ^ (k + 1) * m)"
wenzelm@32960
   669
        using norm_ge_zero[of w] w0 m(1)
wenzelm@32960
   670
          by (simp add: inverse_eq_divide zero_less_mult_iff)
lp15@55358
   671
      with real_lbound_gt_zero[OF zero_less_one] obtain t where
wenzelm@32960
   672
        t: "t > 0" "t < 1" "t < inverse (cmod w ^ (k + 1) * m)" by blast
chaieb@26123
   673
      let ?ct = "complex_of_real t"
chaieb@26123
   674
      let ?w = "?ct * w"
nipkow@29667
   675
      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: algebra_simps power_mult_distrib)
chaieb@26123
   676
      also have "\<dots> = complex_of_real (1 - t^k) + ?w^k * ?w * poly s ?w"
wenzelm@32960
   677
        unfolding wm1 by (simp)
huffman@30488
   678
      finally have "cmod (1 + ?w^k * (a + ?w * poly s ?w)) = cmod (complex_of_real (1 - t^k) + ?w^k * ?w * poly s ?w)"
lp15@55358
   679
        by metis
huffman@30488
   680
      with norm_triangle_ineq[of "complex_of_real (1 - t^k)" "?w^k * ?w * poly s ?w"]
huffman@30488
   681
      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
chaieb@26123
   682
      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
chaieb@26123
   683
      have "t *cmod w \<le> 1 * cmod w" apply (rule mult_mono) using t(1,2) by auto
huffman@30488
   684
      then have tw: "cmod ?w \<le> cmod w" using t(1) by (simp add: norm_mult)
chaieb@26123
   685
      from t inv0 have "t* (cmod w ^ (k + 1) * m) < 1"
wenzelm@32960
   686
        by (simp add: inverse_eq_divide field_simps)
huffman@30488
   687
      with zero_less_power[OF t(1), of k]
huffman@30488
   688
      have th30: "t^k * (t* (cmod w ^ (k + 1) * m)) < t^k * 1"
lp15@55358
   689
        by (metis comm_mult_strict_left_mono)
chaieb@26123
   690
      have "cmod (?w^k * ?w * poly s ?w) = t^k * (t* (cmod w ^ (k+1) * cmod (poly s ?w)))"  using w0 t(1)
wenzelm@51541
   691
        by (simp add: algebra_simps power_mult_distrib norm_power norm_mult)
chaieb@26123
   692
      then have "cmod (?w^k * ?w * poly s ?w) \<le> t^k * (t* (cmod w ^ (k + 1) * m))"
wenzelm@32960
   693
        using t(1,2) m(2)[rule_format, OF tw] w0
lp15@55358
   694
        by auto
huffman@30488
   695
      with th30 have th120: "cmod (?w^k * ?w * poly s ?w) < t^k" by simp
huffman@30488
   696
      from power_strict_mono[OF t(2), of k] t(1) kas(2) have th121: "t^k \<le> 1"
wenzelm@32960
   697
        by auto
huffman@27514
   698
      from ath[OF norm_ge_zero[of "?w^k * ?w * poly s ?w"] th120 th121]
huffman@30488
   699
      have th12: "\<bar>1 - t^k\<bar> + cmod (?w^k * ?w * poly s ?w) < 1" .
chaieb@26123
   700
      from th11 th12
huffman@30488
   701
      have "cmod (1 + ?w^k * (a + ?w * poly s ?w)) < 1"  by arith
huffman@30488
   702
      then have "cmod (poly ?r ?w) < 1"
wenzelm@32960
   703
        unfolding kas(4)[rule_format, of ?w] r01 by simp
chaieb@26123
   704
      then have "\<exists>w. cmod (poly ?r w) < 1" by blast}
chaieb@26123
   705
    ultimately have cr0_contr: "\<exists>w. cmod (poly ?r w) < 1" by blast
chaieb@26123
   706
    from cr0_contr cq0 q(2)
chaieb@26123
   707
    have ?ths unfolding mrmq_eq not_less[symmetric] by auto}
chaieb@26123
   708
  ultimately show ?ths by blast
chaieb@26123
   709
qed
chaieb@26123
   710
chaieb@26123
   711
text {* Alternative version with a syntactic notion of constant polynomial. *}
chaieb@26123
   712
chaieb@26123
   713
lemma fundamental_theorem_of_algebra_alt:
huffman@29464
   714
  assumes nc: "~(\<exists>a l. a\<noteq> 0 \<and> l = 0 \<and> p = pCons a l)"
chaieb@26123
   715
  shows "\<exists>z. poly p z = (0::complex)"
chaieb@26123
   716
using nc
chaieb@26123
   717
proof(induct p)
huffman@29464
   718
  case (pCons c cs)
chaieb@26123
   719
  {assume "c=0" hence ?case by auto}
chaieb@26123
   720
  moreover
chaieb@26123
   721
  {assume c0: "c\<noteq>0"
huffman@29464
   722
    {assume nc: "constant (poly (pCons c cs))"
huffman@30488
   723
      from nc[unfolded constant_def, rule_format, of 0]
huffman@30488
   724
      have "\<forall>w. w \<noteq> 0 \<longrightarrow> poly cs w = 0" by auto
huffman@29464
   725
      hence "cs = 0"
wenzelm@32960
   726
        proof(induct cs)
wenzelm@32960
   727
          case (pCons d ds)
wenzelm@32960
   728
          {assume "d=0" hence ?case using pCons.prems pCons.hyps by simp}
wenzelm@32960
   729
          moreover
wenzelm@32960
   730
          {assume d0: "d\<noteq>0"
wenzelm@32960
   731
            from poly_bound_exists[of 1 ds] obtain m where
wenzelm@32960
   732
              m: "m > 0" "\<forall>z. \<forall>z. cmod z \<le> 1 \<longrightarrow> cmod (poly ds z) \<le> m" by blast
wenzelm@32960
   733
            have dm: "cmod d / m > 0" using d0 m(1) by (simp add: field_simps)
lp15@55358
   734
            from real_lbound_gt_zero[OF dm zero_less_one] obtain x where
wenzelm@32960
   735
              x: "x > 0" "x < cmod d / m" "x < 1" by blast
wenzelm@32960
   736
            let ?x = "complex_of_real x"
wenzelm@32960
   737
            from x have cx: "?x \<noteq> 0"  "cmod ?x \<le> 1" by simp_all
wenzelm@32960
   738
            from pCons.prems[rule_format, OF cx(1)]
wenzelm@32960
   739
            have cth: "cmod (?x*poly ds ?x) = cmod d" by (simp add: eq_diff_eq[symmetric])
wenzelm@32960
   740
            from m(2)[rule_format, OF cx(2)] x(1)
wenzelm@32960
   741
            have th0: "cmod (?x*poly ds ?x) \<le> x*m"
wenzelm@32960
   742
              by (simp add: norm_mult)
wenzelm@32960
   743
            from x(2) m(1) have "x*m < cmod d" by (simp add: field_simps)
wenzelm@32960
   744
            with th0 have "cmod (?x*poly ds ?x) \<noteq> cmod d" by auto
wenzelm@32960
   745
            with cth  have ?case by blast}
wenzelm@32960
   746
          ultimately show ?case by blast
wenzelm@32960
   747
        qed simp}
huffman@30488
   748
      then have nc: "\<not> constant (poly (pCons c cs))" using pCons.prems c0
wenzelm@32960
   749
        by blast
chaieb@26123
   750
      from fundamental_theorem_of_algebra[OF nc] have ?case .}
huffman@30488
   751
  ultimately show ?case by blast
chaieb@26123
   752
qed simp
chaieb@26123
   753
huffman@29464
   754
webertj@37093
   755
subsection{* Nullstellensatz, degrees and divisibility of polynomials *}
chaieb@26123
   756
chaieb@26123
   757
lemma nullstellensatz_lemma:
huffman@29464
   758
  fixes p :: "complex poly"
chaieb@26123
   759
  assumes "\<forall>x. poly p x = 0 \<longrightarrow> poly q x = 0"
chaieb@26123
   760
  and "degree p = n" and "n \<noteq> 0"
huffman@29464
   761
  shows "p dvd (q ^ n)"
wenzelm@41529
   762
using assms
chaieb@26123
   763
proof(induct n arbitrary: p q rule: nat_less_induct)
huffman@29464
   764
  fix n::nat fix p q :: "complex poly"
chaieb@26123
   765
  assume IH: "\<forall>m<n. \<forall>p q.
chaieb@26123
   766
                 (\<forall>x. poly p x = (0::complex) \<longrightarrow> poly q x = 0) \<longrightarrow>
huffman@29464
   767
                 degree p = m \<longrightarrow> m \<noteq> 0 \<longrightarrow> p dvd (q ^ m)"
huffman@30488
   768
    and pq0: "\<forall>x. poly p x = 0 \<longrightarrow> poly q x = 0"
chaieb@26123
   769
    and dpn: "degree p = n" and n0: "n \<noteq> 0"
huffman@29464
   770
  from dpn n0 have pne: "p \<noteq> 0" by auto
huffman@29464
   771
  let ?ths = "p dvd (q ^ n)"
chaieb@26123
   772
  {fix a assume a: "poly p a = 0"
huffman@29464
   773
    {assume oa: "order a p \<noteq> 0"
chaieb@26123
   774
      let ?op = "order a p"
huffman@30488
   775
      from pne have ap: "([:- a, 1:] ^ ?op) dvd p"
wenzelm@32960
   776
        "\<not> [:- a, 1:] ^ (Suc ?op) dvd p" using order by blast+
huffman@29464
   777
      note oop = order_degree[OF pne, unfolded dpn]
huffman@29464
   778
      {assume q0: "q = 0"
wenzelm@32960
   779
        hence ?ths using n0
huffman@29464
   780
          by (simp add: power_0_left)}
chaieb@26123
   781
      moreover
huffman@29464
   782
      {assume q0: "q \<noteq> 0"
wenzelm@32960
   783
        from pq0[rule_format, OF a, unfolded poly_eq_0_iff_dvd]
wenzelm@32960
   784
        obtain r where r: "q = [:- a, 1:] * r" by (rule dvdE)
wenzelm@32960
   785
        from ap(1) obtain s where
wenzelm@32960
   786
          s: "p = [:- a, 1:] ^ ?op * s" by (rule dvdE)
wenzelm@32960
   787
        have sne: "s \<noteq> 0"
wenzelm@32960
   788
          using s pne by auto
wenzelm@32960
   789
        {assume ds0: "degree s = 0"
wenzelm@51541
   790
          from ds0 obtain k where kpn: "s = [:k:]"
wenzelm@51541
   791
            by (cases s) (auto split: if_splits)
huffman@29464
   792
          from sne kpn have k: "k \<noteq> 0" by simp
wenzelm@32960
   793
          let ?w = "([:1/k:] * ([:-a,1:] ^ (n - ?op))) * (r ^ n)"
lp15@55358
   794
          have "q ^ n = p * ?w"
huffman@29464
   795
            apply (subst r, subst s, subst kpn)
lp15@55358
   796
            using k oop [of a] 
huffman@29472
   797
            apply (subst power_mult_distrib, simp)
huffman@29464
   798
            apply (subst power_add [symmetric], simp)
huffman@29464
   799
            done
wenzelm@32960
   800
          hence ?ths unfolding dvd_def by blast}
wenzelm@32960
   801
        moreover
wenzelm@32960
   802
        {assume ds0: "degree s \<noteq> 0"
wenzelm@32960
   803
          from ds0 sne dpn s oa
wenzelm@32960
   804
            have dsn: "degree s < n" apply auto
huffman@29464
   805
              apply (erule ssubst)
huffman@29464
   806
              apply (simp add: degree_mult_eq degree_linear_power)
huffman@29464
   807
              done
wenzelm@32960
   808
            {fix x assume h: "poly s x = 0"
wenzelm@32960
   809
              {assume xa: "x = a"
wenzelm@32960
   810
                from h[unfolded xa poly_eq_0_iff_dvd] obtain u where
wenzelm@32960
   811
                  u: "s = [:- a, 1:] * u" by (rule dvdE)
wenzelm@32960
   812
                have "p = [:- a, 1:] ^ (Suc ?op) * u"
huffman@29464
   813
                  by (subst s, subst u, simp only: power_Suc mult_ac)
wenzelm@32960
   814
                with ap(2)[unfolded dvd_def] have False by blast}
wenzelm@32960
   815
              note xa = this
wenzelm@32960
   816
              from h have "poly p x = 0" by (subst s, simp)
wenzelm@32960
   817
              with pq0 have "poly q x = 0" by blast
wenzelm@32960
   818
              with r xa have "poly r x = 0"
huffman@29464
   819
                by (auto simp add: uminus_add_conv_diff)}
wenzelm@32960
   820
            note impth = this
wenzelm@32960
   821
            from IH[rule_format, OF dsn, of s r] impth ds0
wenzelm@32960
   822
            have "s dvd (r ^ (degree s))" by blast
wenzelm@32960
   823
            then obtain u where u: "r ^ (degree s) = s * u" ..
wenzelm@32960
   824
            hence u': "\<And>x. poly s x * poly u x = poly r x ^ degree s"
huffman@29470
   825
              by (simp only: poly_mult[symmetric] poly_power[symmetric])
wenzelm@32960
   826
            let ?w = "(u * ([:-a,1:] ^ (n - ?op))) * (r ^ (n - degree s))"
wenzelm@32960
   827
            from oop[of a] dsn have "q ^ n = p * ?w"
huffman@29464
   828
              apply -
huffman@29464
   829
              apply (subst s, subst r)
huffman@29464
   830
              apply (simp only: power_mult_distrib)
huffman@29464
   831
              apply (subst mult_assoc [where b=s])
huffman@29464
   832
              apply (subst mult_assoc [where a=u])
huffman@29464
   833
              apply (subst mult_assoc [where b=u, symmetric])
huffman@29464
   834
              apply (subst u [symmetric])
huffman@29464
   835
              apply (simp add: mult_ac power_add [symmetric])
huffman@29464
   836
              done
wenzelm@32960
   837
            hence ?ths unfolding dvd_def by blast}
chaieb@26123
   838
      ultimately have ?ths by blast }
chaieb@26123
   839
      ultimately have ?ths by blast}
huffman@29464
   840
    then have ?ths using a order_root pne by blast}
chaieb@26123
   841
  moreover
chaieb@26123
   842
  {assume exa: "\<not> (\<exists>a. poly p a = 0)"
huffman@29464
   843
    from fundamental_theorem_of_algebra_alt[of p] exa obtain c where
huffman@29464
   844
      ccs: "c\<noteq>0" "p = pCons c 0" by blast
huffman@30488
   845
huffman@29464
   846
    then have pp: "\<And>x. poly p x =  c" by simp
huffman@29464
   847
    let ?w = "[:1/c:] * (q ^ n)"
wenzelm@51541
   848
    from ccs have "(q ^ n) = (p * ?w)" by simp
huffman@29464
   849
    hence ?ths unfolding dvd_def by blast}
chaieb@26123
   850
  ultimately show ?ths by blast
chaieb@26123
   851
qed
chaieb@26123
   852
chaieb@26123
   853
lemma nullstellensatz_univariate:
huffman@30488
   854
  "(\<forall>x. poly p x = (0::complex) \<longrightarrow> poly q x = 0) \<longleftrightarrow>
huffman@29464
   855
    p dvd (q ^ (degree p)) \<or> (p = 0 \<and> q = 0)"
chaieb@26123
   856
proof-
huffman@29464
   857
  {assume pe: "p = 0"
huffman@29464
   858
    hence eq: "(\<forall>x. poly p x = (0::complex) \<longrightarrow> poly q x = 0) \<longleftrightarrow> q = 0"
haftmann@52380
   859
      by (auto simp add: poly_all_0_iff_0)
huffman@29464
   860
    {assume "p dvd (q ^ (degree p))"
huffman@29464
   861
      then obtain r where r: "q ^ (degree p) = p * r" ..
huffman@29464
   862
      from r pe have False by simp}
chaieb@26123
   863
    with eq pe have ?thesis by blast}
chaieb@26123
   864
  moreover
huffman@29464
   865
  {assume pe: "p \<noteq> 0"
chaieb@26123
   866
    {assume dp: "degree p = 0"
huffman@29464
   867
      then obtain k where k: "p = [:k:]" "k\<noteq>0" using pe
wenzelm@51541
   868
        by (cases p) (simp split: if_splits)
chaieb@26123
   869
      hence th1: "\<forall>x. poly p x \<noteq> 0" by simp
huffman@29464
   870
      from k dp have "q ^ (degree p) = p * [:1/k:]"
huffman@29464
   871
        by (simp add: one_poly_def)
huffman@29464
   872
      hence th2: "p dvd (q ^ (degree p))" ..
chaieb@26123
   873
      from th1 th2 pe have ?thesis by blast}
chaieb@26123
   874
    moreover
chaieb@26123
   875
    {assume dp: "degree p \<noteq> 0"
chaieb@26123
   876
      then obtain n where n: "degree p = Suc n " by (cases "degree p", auto)
huffman@29464
   877
      {assume "p dvd (q ^ (Suc n))"
wenzelm@32960
   878
        then obtain u where u: "q ^ (Suc n) = p * u" ..
wenzelm@32960
   879
        {fix x assume h: "poly p x = 0" "poly q x \<noteq> 0"
wenzelm@32960
   880
          hence "poly (q ^ (Suc n)) x \<noteq> 0" by simp
wenzelm@32960
   881
          hence False using u h(1) by (simp only: poly_mult) simp}}
wenzelm@32960
   882
        with n nullstellensatz_lemma[of p q "degree p"] dp
wenzelm@32960
   883
        have ?thesis by auto}
chaieb@26123
   884
    ultimately have ?thesis by blast}
chaieb@26123
   885
  ultimately show ?thesis by blast
chaieb@26123
   886
qed
chaieb@26123
   887
chaieb@26123
   888
text{* Useful lemma *}
chaieb@26123
   889
huffman@29464
   890
lemma constant_degree:
huffman@29464
   891
  fixes p :: "'a::{idom,ring_char_0} poly"
huffman@29464
   892
  shows "constant (poly p) \<longleftrightarrow> degree p = 0" (is "?lhs = ?rhs")
chaieb@26123
   893
proof
chaieb@26123
   894
  assume l: ?lhs
huffman@29464
   895
  from l[unfolded constant_def, rule_format, of _ "0"]
huffman@29464
   896
  have th: "poly p = poly [:poly p 0:]" apply - by (rule ext, simp)
haftmann@52380
   897
  then have "p = [:poly p 0:]" by (simp add: poly_eq_poly_eq_iff)
huffman@29464
   898
  then have "degree p = degree [:poly p 0:]" by simp
huffman@29464
   899
  then show ?rhs by simp
chaieb@26123
   900
next
chaieb@26123
   901
  assume r: ?rhs
huffman@29464
   902
  then obtain k where "p = [:k:]"
wenzelm@51541
   903
    by (cases p) (simp split: if_splits)
huffman@29464
   904
  then show ?lhs unfolding constant_def by auto
chaieb@26123
   905
qed
chaieb@26123
   906
huffman@29464
   907
lemma divides_degree: assumes pq: "p dvd (q:: complex poly)"
huffman@29464
   908
  shows "degree p \<le> degree q \<or> q = 0"
lp15@55358
   909
by (metis dvd_imp_degree_le pq)
chaieb@26123
   910
chaieb@26123
   911
(* Arithmetic operations on multivariate polynomials.                        *)
chaieb@26123
   912
huffman@30488
   913
lemma mpoly_base_conv:
huffman@29464
   914
  "(0::complex) \<equiv> poly 0 x" "c \<equiv> poly [:c:] x" "x \<equiv> poly [:0,1:] x" by simp_all
chaieb@26123
   915
huffman@30488
   916
lemma mpoly_norm_conv:
huffman@29464
   917
  "poly [:0:] (x::complex) \<equiv> poly 0 x" "poly [:poly 0 y:] x \<equiv> poly 0 x" by simp_all
chaieb@26123
   918
huffman@30488
   919
lemma mpoly_sub_conv:
chaieb@26123
   920
  "poly p (x::complex) - poly q x \<equiv> poly p x + -1 * poly q x"
haftmann@54230
   921
  by simp
chaieb@26123
   922
huffman@29464
   923
lemma poly_pad_rule: "poly p x = 0 ==> poly (pCons 0 p) x = (0::complex)" by simp
chaieb@26123
   924
chaieb@26123
   925
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
chaieb@26123
   926
huffman@29464
   927
lemma resolve_eq_raw:  "poly 0 x \<equiv> 0" "poly [:c:] x \<equiv> (c::complex)" by auto
chaieb@26123
   928
huffman@30488
   929
lemma poly_divides_pad_rule:
huffman@29464
   930
  fixes p q :: "complex poly"
huffman@29464
   931
  assumes pq: "p dvd q"
huffman@29464
   932
  shows "p dvd (pCons (0::complex) q)"
chaieb@26123
   933
proof-
huffman@29464
   934
  have "pCons 0 q = q * [:0,1:]" by simp
huffman@29464
   935
  then have "q dvd (pCons 0 q)" ..
huffman@29464
   936
  with pq show ?thesis by (rule dvd_trans)
chaieb@26123
   937
qed
chaieb@26123
   938
huffman@30488
   939
lemma poly_divides_pad_const_rule:
huffman@29464
   940
  fixes p q :: "complex poly"
huffman@29464
   941
  assumes pq: "p dvd q"
huffman@29464
   942
  shows "p dvd (smult a q)"
chaieb@26123
   943
proof-
huffman@29464
   944
  have "smult a q = q * [:a:]" by simp
huffman@29464
   945
  then have "q dvd smult a q" ..
huffman@29464
   946
  with pq show ?thesis by (rule dvd_trans)
chaieb@26123
   947
qed
chaieb@26123
   948
chaieb@26123
   949
huffman@30488
   950
lemma poly_divides_conv0:
huffman@29464
   951
  fixes p :: "complex poly"
huffman@29464
   952
  assumes lgpq: "degree q < degree p" and lq:"p \<noteq> 0"
huffman@29464
   953
  shows "p dvd q \<equiv> q = 0" (is "?lhs \<equiv> ?rhs")
chaieb@26123
   954
proof-
huffman@30488
   955
  {assume r: ?rhs
huffman@29464
   956
    hence "q = p * 0" by simp
huffman@29464
   957
    hence ?lhs ..}
chaieb@26123
   958
  moreover
chaieb@26123
   959
  {assume l: ?lhs
huffman@29464
   960
    {assume q0: "q = 0"
chaieb@26123
   961
      hence ?rhs by simp}
chaieb@26123
   962
    moreover
huffman@29464
   963
    {assume q0: "q \<noteq> 0"
huffman@29464
   964
      from l q0 have "degree p \<le> degree q"
huffman@29464
   965
        by (rule dvd_imp_degree_le)
huffman@29464
   966
      with lgpq have ?rhs by simp }
chaieb@26123
   967
    ultimately have ?rhs by blast }
huffman@30488
   968
  ultimately show "?lhs \<equiv> ?rhs" by - (atomize (full), blast)
chaieb@26123
   969
qed
chaieb@26123
   970
huffman@30488
   971
lemma poly_divides_conv1:
huffman@29464
   972
  assumes a0: "a\<noteq> (0::complex)" and pp': "(p::complex poly) dvd p'"
huffman@29464
   973
  and qrp': "smult a q - p' \<equiv> r"
huffman@29464
   974
  shows "p dvd q \<equiv> p dvd (r::complex poly)" (is "?lhs \<equiv> ?rhs")
chaieb@26123
   975
proof-
chaieb@26123
   976
  {
huffman@29464
   977
  from pp' obtain t where t: "p' = p * t" ..
chaieb@26123
   978
  {assume l: ?lhs
huffman@29464
   979
    then obtain u where u: "q = p * u" ..
huffman@29464
   980
     have "r = p * (smult a u - t)"
wenzelm@51541
   981
       using u qrp' [symmetric] t by (simp add: algebra_simps)
huffman@29464
   982
     then have ?rhs ..}
chaieb@26123
   983
  moreover
chaieb@26123
   984
  {assume r: ?rhs
huffman@29464
   985
    then obtain u where u: "r = p * u" ..
huffman@29464
   986
    from u [symmetric] t qrp' [symmetric] a0
wenzelm@51541
   987
    have "q = p * smult (1/a) (u + t)" by (simp add: algebra_simps)
huffman@29464
   988
    hence ?lhs ..}
chaieb@26123
   989
  ultimately have "?lhs = ?rhs" by blast }
huffman@30488
   990
thus "?lhs \<equiv> ?rhs"  by - (atomize(full), blast)
chaieb@26123
   991
qed
chaieb@26123
   992
chaieb@26123
   993
lemma basic_cqe_conv1:
lp15@55358
   994
  "(\<exists>x. poly p x = 0 \<and> poly 0 x \<noteq> 0) \<longleftrightarrow> False"
lp15@55358
   995
  "(\<exists>x. poly 0 x \<noteq> 0) \<longleftrightarrow> False"
lp15@55358
   996
  "(\<exists>x. poly [:c:] x \<noteq> 0) \<longleftrightarrow> c\<noteq>0"
lp15@55358
   997
  "(\<exists>x. poly 0 x = 0) \<longleftrightarrow> True"
lp15@55358
   998
  "(\<exists>x. poly [:c:] x = 0) \<longleftrightarrow> c = 0" by simp_all
chaieb@26123
   999
huffman@30488
  1000
lemma basic_cqe_conv2:
huffman@30488
  1001
  assumes l:"p \<noteq> 0"
lp15@55358
  1002
  shows "(\<exists>x. poly (pCons a (pCons b p)) x = (0::complex))"
chaieb@26123
  1003
proof-
chaieb@26123
  1004
  {fix h t
huffman@29464
  1005
    assume h: "h\<noteq>0" "t=0"  "pCons a (pCons b p) = pCons h t"
chaieb@26123
  1006
    with l have False by simp}
huffman@29464
  1007
  hence th: "\<not> (\<exists> h t. h\<noteq>0 \<and> t=0 \<and> pCons a (pCons b p) = pCons h t)"
chaieb@26123
  1008
    by blast
huffman@30488
  1009
  from fundamental_theorem_of_algebra_alt[OF th]
lp15@55358
  1010
  show ?thesis by auto
chaieb@26123
  1011
qed
chaieb@26123
  1012
lp15@55358
  1013
lemma  basic_cqe_conv_2b: "(\<exists>x. poly p x \<noteq> (0::complex)) \<longleftrightarrow> (p \<noteq> 0)"
lp15@55358
  1014
by (metis poly_all_0_iff_0)
chaieb@26123
  1015
chaieb@26123
  1016
lemma basic_cqe_conv3:
huffman@29464
  1017
  fixes p q :: "complex poly"
huffman@30488
  1018
  assumes l: "p \<noteq> 0"
lp15@55358
  1019
  shows "(\<exists>x. poly (pCons a p) x = 0 \<and> poly q x \<noteq> 0) \<longleftrightarrow> \<not> ((pCons a p) dvd (q ^ (psize p)))"
lp15@55358
  1020
proof -
huffman@29538
  1021
  from l have dp:"degree (pCons a p) = psize p" by (simp add: psize_def)
huffman@29464
  1022
  from nullstellensatz_univariate[of "pCons a p" q] l
lp15@55358
  1023
  show ?thesis
lp15@55358
  1024
    by (metis dp pCons_eq_0_iff)
chaieb@26123
  1025
qed
chaieb@26123
  1026
chaieb@26123
  1027
lemma basic_cqe_conv4:
huffman@29464
  1028
  fixes p q :: "complex poly"
lp15@55358
  1029
  assumes h: "\<And>x. poly (q ^ n) x = poly r x"
lp15@55358
  1030
  shows "p dvd (q ^ n) \<longleftrightarrow> p dvd r"
chaieb@26123
  1031
proof-
wenzelm@51541
  1032
  from h have "poly (q ^ n) = poly r" by auto
haftmann@52380
  1033
  then have "(q ^ n) = r" by (simp add: poly_eq_poly_eq_iff)
lp15@55358
  1034
  thus "p dvd (q ^ n) \<longleftrightarrow> p dvd r" by simp
chaieb@26123
  1035
qed
chaieb@26123
  1036
chaieb@26123
  1037
lemma complex_entire: "(z::complex) \<noteq> 0 \<and> w \<noteq> 0 \<equiv> z*w \<noteq> 0" by simp
lp15@55358
  1038
huffman@29464
  1039
lemma poly_const_conv: "poly [:c:] (x::complex) = y \<longleftrightarrow> c = y" by simp
chaieb@26123
  1040
huffman@29464
  1041
end