src/HOL/Library/Fundamental_Theorem_Algebra.thy
author wenzelm
Tue Apr 29 21:54:26 2014 +0200 (2014-04-29)
changeset 56795 e8cce2bd23e5
parent 56778 cb0929421ca6
child 56889 48a745e1bde7
permissions -rw-r--r--
tuned proofs;
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 *}
lp15@55734
    10
wenzelm@56776
    11
definition csqrt :: "complex \<Rightarrow> complex"
wenzelm@56776
    12
where
wenzelm@56776
    13
  "csqrt z =
wenzelm@56776
    14
    (if Im z = 0 then
wenzelm@56776
    15
       if 0 \<le> Re z then Complex (sqrt(Re z)) 0
wenzelm@56776
    16
       else Complex 0 (sqrt(- Re z))
wenzelm@56776
    17
     else Complex (sqrt((cmod z + Re z) /2)) ((Im z / abs(Im z)) * sqrt((cmod z - Re z) /2)))"
chaieb@26123
    18
wenzelm@53077
    19
lemma csqrt[algebra]: "(csqrt z)\<^sup>2 = z"
wenzelm@56778
    20
proof -
wenzelm@29292
    21
  obtain x y where xy: "z = Complex x y" by (cases z)
wenzelm@56778
    22
  {
wenzelm@56778
    23
    assume y0: "y = 0"
wenzelm@56778
    24
    {
wenzelm@56778
    25
      assume x0: "x \<ge> 0"
wenzelm@56778
    26
      then have ?thesis
wenzelm@56778
    27
        using y0 xy real_sqrt_pow2[OF x0]
wenzelm@56778
    28
        by (simp add: csqrt_def power2_eq_square)
wenzelm@56778
    29
    }
chaieb@26123
    30
    moreover
wenzelm@56778
    31
    {
wenzelm@56778
    32
      assume "\<not> x \<ge> 0"
wenzelm@56778
    33
      then have x0: "- x \<ge> 0" by arith
wenzelm@56778
    34
      then have ?thesis
wenzelm@56778
    35
        using y0 xy real_sqrt_pow2[OF x0]
wenzelm@56778
    36
        by (simp add: csqrt_def power2_eq_square)
wenzelm@56778
    37
    }
wenzelm@56778
    38
    ultimately have ?thesis by blast
wenzelm@56778
    39
  }
chaieb@26123
    40
  moreover
wenzelm@56778
    41
  {
wenzelm@56778
    42
    assume y0: "y \<noteq> 0"
wenzelm@56778
    43
    {
wenzelm@56778
    44
      fix x y
chaieb@26123
    45
      let ?z = "Complex x y"
wenzelm@56778
    46
      from abs_Re_le_cmod[of ?z] have tha: "abs x \<le> cmod ?z"
wenzelm@56778
    47
        by auto
wenzelm@56778
    48
      then have "cmod ?z - x \<ge> 0" "cmod ?z + x \<ge> 0"
wenzelm@56778
    49
        by arith+
wenzelm@56778
    50
      then have "(sqrt (x * x + y * y) + x) / 2 \<ge> 0" "(sqrt (x * x + y * y) - x) / 2 \<ge> 0"
wenzelm@56778
    51
        by (simp_all add: power2_eq_square)
wenzelm@56778
    52
    }
chaieb@26123
    53
    note th = this
wenzelm@53077
    54
    have sq4: "\<And>x::real. x\<^sup>2 / 4 = (x / 2)\<^sup>2"
huffman@30488
    55
      by (simp add: power2_eq_square)
chaieb@26123
    56
    from th[of x y]
wenzelm@53077
    57
    have sq4': "sqrt (((sqrt (x * x + y * y) + x)\<^sup>2 / 4)) = (sqrt (x * x + y * y) + x) / 2"
wenzelm@53077
    58
      "sqrt (((sqrt (x * x + y * y) - x)\<^sup>2 / 4)) = (sqrt (x * x + y * y) - x) / 2"
wenzelm@53077
    59
      unfolding sq4 by simp_all
wenzelm@56778
    60
    then have th1: "sqrt ((sqrt (x * x + y * y) + x) * (sqrt (x * x + y * y) + x) / 4) -
wenzelm@56778
    61
        sqrt ((sqrt (x * x + y * y) - x) * (sqrt (x * x + y * y) - x) / 4) = x"
huffman@30488
    62
      unfolding power2_eq_square by simp
wenzelm@56778
    63
    have "sqrt 4 = sqrt (2\<^sup>2)"
wenzelm@56778
    64
      by simp
wenzelm@56778
    65
    then have sqrt4: "sqrt 4 = 2"
wenzelm@56778
    66
      by (simp only: real_sqrt_abs)
wenzelm@56778
    67
    have th2: "2 * (y * sqrt ((sqrt (x * x + y * y) - x) * (sqrt (x * x + y * y) + x) / 4)) / \<bar>y\<bar> = y"
chaieb@26123
    68
      using iffD2[OF real_sqrt_pow2_iff sum_power2_ge_zero[of x y]] y0
huffman@30488
    69
      unfolding power2_eq_square
nipkow@29667
    70
      by (simp add: algebra_simps real_sqrt_divide sqrt4)
wenzelm@56778
    71
    from y0 xy have ?thesis
wenzelm@56778
    72
      apply (simp add: csqrt_def power2_eq_square)
wenzelm@56778
    73
      apply (simp add: real_sqrt_sum_squares_mult_ge_zero[of x y]
wenzelm@56778
    74
        real_sqrt_pow2[OF th(1)[of x y], unfolded power2_eq_square]
wenzelm@56778
    75
        real_sqrt_pow2[OF th(2)[of x y], unfolded power2_eq_square]
wenzelm@56778
    76
        real_sqrt_mult[symmetric])
wenzelm@56778
    77
      using th1 th2  ..
wenzelm@56778
    78
  }
chaieb@26123
    79
  ultimately show ?thesis by blast
chaieb@26123
    80
qed
chaieb@26123
    81
lp15@55734
    82
lemma csqrt_Complex: "x \<ge> 0 \<Longrightarrow> csqrt (Complex x 0) = Complex (sqrt x) 0"
lp15@55734
    83
  by (simp add: csqrt_def)
lp15@55734
    84
lp15@55734
    85
lemma csqrt_0 [simp]: "csqrt 0 = 0"
lp15@55734
    86
  by (simp add: csqrt_def)
lp15@55734
    87
lp15@55734
    88
lemma csqrt_1 [simp]: "csqrt 1 = 1"
lp15@55734
    89
  by (simp add: csqrt_def)
lp15@55734
    90
lp15@55734
    91
lemma csqrt_principal: "0 < Re(csqrt(z)) | Re(csqrt(z)) = 0 & 0 \<le> Im(csqrt(z))"
lp15@55734
    92
proof (cases z)
lp15@55734
    93
  case (Complex x y)
lp15@55734
    94
  then show ?thesis
lp15@55734
    95
    using real_sqrt_sum_squares_ge1 [of "x" y]
lp15@55734
    96
          real_sqrt_sum_squares_ge1 [of "-x" y]
lp15@55734
    97
          real_sqrt_sum_squares_eq_cancel [of x y]
lp15@55734
    98
    apply (auto simp: csqrt_def intro!: Rings.ordered_ring_class.split_mult_pos_le)
lp15@55734
    99
    apply (metis add_commute diff_add_cancel le_add_same_cancel1 real_sqrt_sum_squares_ge1)
wenzelm@56778
   100
    apply (metis add_commute less_eq_real_def power_minus_Bit0
wenzelm@56778
   101
            real_0_less_add_iff real_sqrt_sum_squares_eq_cancel)
wenzelm@56778
   102
    done
lp15@55734
   103
qed
lp15@55734
   104
lp15@55734
   105
lemma Re_csqrt: "0 \<le> Re(csqrt z)"
lp15@55734
   106
  by (metis csqrt_principal le_less)
lp15@55734
   107
wenzelm@56778
   108
lemma csqrt_square: "0 < Re z \<or> Re z = 0 \<and> 0 \<le> Im z \<Longrightarrow> csqrt (z\<^sup>2) = z"
wenzelm@56778
   109
  using csqrt [of "z\<^sup>2"] csqrt_principal [of "z\<^sup>2"]
lp15@55734
   110
  by (cases z) (auto simp: power2_eq_iff)
lp15@55734
   111
lp15@55734
   112
lemma csqrt_eq_0 [simp]: "csqrt z = 0 \<longleftrightarrow> z = 0"
lp15@55734
   113
  by auto (metis csqrt power_eq_0_iff)
lp15@55734
   114
lp15@55734
   115
lemma csqrt_eq_1 [simp]: "csqrt z = 1 \<longleftrightarrow> z = 1"
lp15@55734
   116
  by auto (metis csqrt power2_eq_1_iff)
chaieb@26123
   117
wenzelm@56778
   118
wenzelm@56778
   119
subsection {* More lemmas about module of complex numbers *}
chaieb@26123
   120
chaieb@26123
   121
lemma complex_of_real_power: "complex_of_real x ^ n = complex_of_real (x^n)"
huffman@27514
   122
  by (rule of_real_power [symmetric])
chaieb@26123
   123
chaieb@26123
   124
text{* The triangle inequality for cmod *}
chaieb@26123
   125
lemma complex_mod_triangle_sub: "cmod w \<le> cmod (w + z) + norm z"
chaieb@26123
   126
  using complex_mod_triangle_ineq2[of "w + z" "-z"] by auto
chaieb@26123
   127
wenzelm@56778
   128
wenzelm@56778
   129
subsection {* Basic lemmas about polynomials *}
chaieb@26123
   130
chaieb@26123
   131
lemma poly_bound_exists:
wenzelm@56778
   132
  fixes p :: "'a::{comm_semiring_0,real_normed_div_algebra} poly"
wenzelm@56778
   133
  shows "\<exists>m. m > 0 \<and> (\<forall>z. norm z \<le> r \<longrightarrow> norm (poly p z) \<le> m)"
wenzelm@56778
   134
proof (induct p)
wenzelm@56778
   135
  case 0
wenzelm@56778
   136
  then show ?case by (rule exI[where x=1]) simp
chaieb@26123
   137
next
huffman@29464
   138
  case (pCons c cs)
lp15@55735
   139
  from pCons.hyps obtain m where m: "\<forall>z. norm z \<le> r \<longrightarrow> norm (poly cs z) \<le> m"
chaieb@26123
   140
    by blast
lp15@55735
   141
  let ?k = " 1 + norm c + \<bar>r * m\<bar>"
wenzelm@56795
   142
  have kp: "?k > 0"
wenzelm@56795
   143
    using abs_ge_zero[of "r*m"] norm_ge_zero[of c] by arith
wenzelm@56778
   144
  {
wenzelm@56778
   145
    fix z :: 'a
lp15@55735
   146
    assume H: "norm z \<le> r"
wenzelm@56778
   147
    from m H have th: "norm (poly cs z) \<le> m"
wenzelm@56778
   148
      by blast
wenzelm@56795
   149
    from H have rp: "r \<ge> 0"
wenzelm@56795
   150
      using norm_ge_zero[of z] by arith
wenzelm@56795
   151
    have "norm (poly (pCons c cs) z) \<le> norm c + norm (z * poly cs z)"
huffman@27514
   152
      using norm_triangle_ineq[of c "z* poly cs z"] by simp
wenzelm@56778
   153
    also have "\<dots> \<le> norm c + r * m"
wenzelm@56778
   154
      using mult_mono[OF H th rp norm_ge_zero[of "poly cs z"]]
lp15@55735
   155
      by (simp add: norm_mult)
wenzelm@56778
   156
    also have "\<dots> \<le> ?k"
wenzelm@56778
   157
      by simp
wenzelm@56778
   158
    finally have "norm (poly (pCons c cs) z) \<le> ?k" .
wenzelm@56778
   159
  }
chaieb@26123
   160
  with kp show ?case by blast
chaieb@26123
   161
qed
chaieb@26123
   162
chaieb@26123
   163
chaieb@26123
   164
text{* Offsetting the variable in a polynomial gives another of same degree *}
huffman@29464
   165
haftmann@52380
   166
definition offset_poly :: "'a::comm_semiring_0 poly \<Rightarrow> 'a \<Rightarrow> 'a poly"
wenzelm@56778
   167
  where "offset_poly p h = fold_coeffs (\<lambda>a q. smult h q + pCons a q) p 0"
huffman@29464
   168
huffman@29464
   169
lemma offset_poly_0: "offset_poly 0 h = 0"
haftmann@52380
   170
  by (simp add: offset_poly_def)
huffman@29464
   171
huffman@29464
   172
lemma offset_poly_pCons:
huffman@29464
   173
  "offset_poly (pCons a p) h =
huffman@29464
   174
    smult h (offset_poly p h) + pCons a (offset_poly p h)"
haftmann@52380
   175
  by (cases "p = 0 \<and> a = 0") (auto simp add: offset_poly_def)
huffman@29464
   176
huffman@29464
   177
lemma offset_poly_single: "offset_poly [:a:] h = [:a:]"
wenzelm@56778
   178
  by (simp add: offset_poly_pCons offset_poly_0)
huffman@29464
   179
huffman@29464
   180
lemma poly_offset_poly: "poly (offset_poly p h) x = poly p (h + x)"
wenzelm@56778
   181
  apply (induct p)
wenzelm@56778
   182
  apply (simp add: offset_poly_0)
wenzelm@56778
   183
  apply (simp add: offset_poly_pCons algebra_simps)
wenzelm@56778
   184
  done
huffman@29464
   185
huffman@29464
   186
lemma offset_poly_eq_0_lemma: "smult c p + pCons a p = 0 \<Longrightarrow> p = 0"
wenzelm@56778
   187
  by (induct p arbitrary: a) (simp, force)
chaieb@26123
   188
huffman@29464
   189
lemma offset_poly_eq_0_iff: "offset_poly p h = 0 \<longleftrightarrow> p = 0"
wenzelm@56778
   190
  apply (safe intro!: offset_poly_0)
wenzelm@56795
   191
  apply (induct p)
wenzelm@56795
   192
  apply simp
wenzelm@56778
   193
  apply (simp add: offset_poly_pCons)
wenzelm@56778
   194
  apply (frule offset_poly_eq_0_lemma, simp)
wenzelm@56778
   195
  done
huffman@29464
   196
huffman@29464
   197
lemma degree_offset_poly: "degree (offset_poly p h) = degree p"
wenzelm@56778
   198
  apply (induct p)
wenzelm@56778
   199
  apply (simp add: offset_poly_0)
wenzelm@56778
   200
  apply (case_tac "p = 0")
wenzelm@56778
   201
  apply (simp add: offset_poly_0 offset_poly_pCons)
wenzelm@56778
   202
  apply (simp add: offset_poly_pCons)
wenzelm@56778
   203
  apply (subst degree_add_eq_right)
wenzelm@56778
   204
  apply (rule le_less_trans [OF degree_smult_le])
wenzelm@56778
   205
  apply (simp add: offset_poly_eq_0_iff)
wenzelm@56778
   206
  apply (simp add: offset_poly_eq_0_iff)
wenzelm@56778
   207
  done
huffman@29464
   208
wenzelm@56778
   209
definition "psize p = (if p = 0 then 0 else Suc (degree p))"
huffman@29464
   210
huffman@29538
   211
lemma psize_eq_0_iff [simp]: "psize p = 0 \<longleftrightarrow> p = 0"
huffman@29538
   212
  unfolding psize_def by simp
huffman@29464
   213
wenzelm@56778
   214
lemma poly_offset:
wenzelm@56778
   215
  fixes p :: "'a::comm_ring_1 poly"
wenzelm@56778
   216
  shows "\<exists>q. psize q = psize p \<and> (\<forall>x. poly q x = poly p (a + x))"
huffman@29464
   217
proof (intro exI conjI)
huffman@29538
   218
  show "psize (offset_poly p a) = psize p"
huffman@29538
   219
    unfolding psize_def
huffman@29464
   220
    by (simp add: offset_poly_eq_0_iff degree_offset_poly)
huffman@29464
   221
  show "\<forall>x. poly (offset_poly p a) x = poly p (a + x)"
huffman@29464
   222
    by (simp add: poly_offset_poly)
chaieb@26123
   223
qed
chaieb@26123
   224
chaieb@26123
   225
text{* An alternative useful formulation of completeness of the reals *}
wenzelm@56778
   226
lemma real_sup_exists:
wenzelm@56778
   227
  assumes ex: "\<exists>x. P x"
wenzelm@56778
   228
    and bz: "\<exists>z. \<forall>x. P x \<longrightarrow> x < z"
wenzelm@56778
   229
  shows "\<exists>s::real. \<forall>y. (\<exists>x. P x \<and> y < x) \<longleftrightarrow> y < s"
hoelzl@54263
   230
proof
hoelzl@54263
   231
  from bz have "bdd_above (Collect P)"
hoelzl@54263
   232
    by (force intro: less_imp_le)
hoelzl@54263
   233
  then show "\<forall>y. (\<exists>x. P x \<and> y < x) \<longleftrightarrow> y < Sup (Collect P)"
hoelzl@54263
   234
    using ex bz by (subst less_cSup_iff) auto
chaieb@26123
   235
qed
chaieb@26123
   236
huffman@27445
   237
subsection {* Fundamental theorem of algebra *}
chaieb@26123
   238
lemma  unimodular_reduce_norm:
chaieb@26123
   239
  assumes md: "cmod z = 1"
chaieb@26123
   240
  shows "cmod (z + 1) < 1 \<or> cmod (z - 1) < 1 \<or> cmod (z + ii) < 1 \<or> cmod (z - ii) < 1"
wenzelm@56778
   241
proof -
wenzelm@56778
   242
  obtain x y where z: "z = Complex x y "
wenzelm@56778
   243
    by (cases z) auto
wenzelm@56778
   244
  from md z have xy: "x\<^sup>2 + y\<^sup>2 = 1"
wenzelm@56778
   245
    by (simp add: cmod_def)
wenzelm@56778
   246
  {
wenzelm@56778
   247
    assume C: "cmod (z + 1) \<ge> 1" "cmod (z - 1) \<ge> 1" "cmod (z + ii) \<ge> 1" "cmod (z - ii) \<ge> 1"
wenzelm@56778
   248
    from C z xy have "2 * x \<le> 1" "2 * x \<ge> -1" "2 * y \<le> 1" "2 * y \<ge> -1"
nipkow@29667
   249
      by (simp_all add: cmod_def power2_eq_square algebra_simps)
wenzelm@56778
   250
    then have "abs (2 * x) \<le> 1" "abs (2 * y) \<le> 1"
wenzelm@56778
   251
      by simp_all
wenzelm@56778
   252
    then have "(abs (2 * x))\<^sup>2 \<le> 1\<^sup>2" "(abs (2 * y))\<^sup>2 \<le> 1\<^sup>2"
chaieb@26123
   253
      by - (rule power_mono, simp, simp)+
wenzelm@56778
   254
    then have th0: "4 * x\<^sup>2 \<le> 1" "4 * y\<^sup>2 \<le> 1"
wenzelm@51541
   255
      by (simp_all add: power_mult_distrib)
wenzelm@56778
   256
    from add_mono[OF th0] xy have False by simp
wenzelm@56778
   257
  }
wenzelm@56778
   258
  then show ?thesis
wenzelm@56778
   259
    unfolding linorder_not_le[symmetric] by blast
chaieb@26123
   260
qed
chaieb@26123
   261
wenzelm@26135
   262
text{* Hence we can always reduce modulus of @{text "1 + b z^n"} if nonzero *}
chaieb@26123
   263
lemma reduce_poly_simple:
wenzelm@56778
   264
  assumes b: "b \<noteq> 0"
wenzelm@56778
   265
    and n: "n \<noteq> 0"
chaieb@26123
   266
  shows "\<exists>z. cmod (1 + b * z^n) < 1"
wenzelm@56778
   267
  using n
wenzelm@56778
   268
proof (induct n rule: nat_less_induct)
chaieb@26123
   269
  fix n
wenzelm@56778
   270
  assume IH: "\<forall>m<n. m \<noteq> 0 \<longrightarrow> (\<exists>z. cmod (1 + b * z ^ m) < 1)"
wenzelm@56778
   271
  assume n: "n \<noteq> 0"
chaieb@26123
   272
  let ?P = "\<lambda>z n. cmod (1 + b * z ^ n) < 1"
wenzelm@56778
   273
  {
wenzelm@56778
   274
    assume e: "even n"
wenzelm@56778
   275
    then have "\<exists>m. n = 2 * m"
wenzelm@56778
   276
      by presburger
wenzelm@56778
   277
    then obtain m where m: "n = 2 * m"
wenzelm@56778
   278
      by blast
wenzelm@56778
   279
    from n m have "m \<noteq> 0" "m < n"
wenzelm@56778
   280
      by presburger+
wenzelm@56778
   281
    with IH[rule_format, of m] obtain z where z: "?P z m"
wenzelm@56778
   282
      by blast
wenzelm@56795
   283
    from z have "?P (csqrt z) n"
wenzelm@56795
   284
      by (simp add: m power_mult csqrt)
wenzelm@56778
   285
    then have "\<exists>z. ?P z n" ..
wenzelm@56778
   286
  }
chaieb@26123
   287
  moreover
wenzelm@56778
   288
  {
wenzelm@56778
   289
    assume o: "odd n"
chaieb@26123
   290
    have th0: "cmod (complex_of_real (cmod b) / b) = 1"
huffman@36975
   291
      using b by (simp add: norm_divide)
wenzelm@56778
   292
    from o have "\<exists>m. n = Suc (2 * m)"
wenzelm@56778
   293
      by presburger+
wenzelm@56795
   294
    then obtain m where m: "n = Suc (2 * m)"
wenzelm@56778
   295
      by blast
chaieb@26123
   296
    from unimodular_reduce_norm[OF th0] o
chaieb@26123
   297
    have "\<exists>v. cmod (complex_of_real (cmod b) / b + v^n) < 1"
wenzelm@56795
   298
      apply (cases "cmod (complex_of_real (cmod b) / b + 1) < 1")
wenzelm@56795
   299
      apply (rule_tac x="1" in exI)
wenzelm@56795
   300
      apply simp
wenzelm@56795
   301
      apply (cases "cmod (complex_of_real (cmod b) / b - 1) < 1")
wenzelm@56795
   302
      apply (rule_tac x="-1" in exI)
wenzelm@56795
   303
      apply simp
chaieb@26123
   304
      apply (cases "cmod (complex_of_real (cmod b) / b + ii) < 1")
wenzelm@56795
   305
      apply (cases "even m")
wenzelm@56795
   306
      apply (rule_tac x="ii" in exI)
wenzelm@56795
   307
      apply (simp add: m power_mult)
wenzelm@56795
   308
      apply (rule_tac x="- ii" in exI)
wenzelm@56795
   309
      apply (simp add: m power_mult)
wenzelm@56795
   310
      apply (cases "even m")
wenzelm@56795
   311
      apply (rule_tac x="- ii" in exI)
wenzelm@56795
   312
      apply (simp add: m power_mult)
haftmann@54489
   313
      apply (auto simp add: m power_mult)
haftmann@54489
   314
      apply (rule_tac x="ii" in exI)
haftmann@54489
   315
      apply (auto simp add: m power_mult)
chaieb@26123
   316
      done
wenzelm@56778
   317
    then obtain v where v: "cmod (complex_of_real (cmod b) / b + v^n) < 1"
wenzelm@56778
   318
      by blast
chaieb@26123
   319
    let ?w = "v / complex_of_real (root n (cmod b))"
chaieb@26123
   320
    from odd_real_root_pow[OF o, of "cmod b"]
huffman@30488
   321
    have th1: "?w ^ n = v^n / complex_of_real (cmod b)"
chaieb@26123
   322
      by (simp add: power_divide complex_of_real_power)
wenzelm@56778
   323
    have th2:"cmod (complex_of_real (cmod b) / b) = 1"
wenzelm@56778
   324
      using b by (simp add: norm_divide)
wenzelm@56778
   325
    then have th3: "cmod (complex_of_real (cmod b) / b) \<ge> 0"
wenzelm@56778
   326
      by simp
chaieb@26123
   327
    have th4: "cmod (complex_of_real (cmod b) / b) *
wenzelm@56778
   328
        cmod (1 + b * (v ^ n / complex_of_real (cmod b))) <
wenzelm@56778
   329
        cmod (complex_of_real (cmod b) / b) * 1"
webertj@49962
   330
      apply (simp only: norm_mult[symmetric] distrib_left)
wenzelm@56778
   331
      using b v
wenzelm@56778
   332
      apply (simp add: th2)
wenzelm@56778
   333
      done
chaieb@26123
   334
    from mult_less_imp_less_left[OF th4 th3]
huffman@30488
   335
    have "?P ?w n" unfolding th1 .
wenzelm@56778
   336
    then have "\<exists>z. ?P z n" ..
wenzelm@56778
   337
  }
chaieb@26123
   338
  ultimately show "\<exists>z. ?P z n" by blast
chaieb@26123
   339
qed
chaieb@26123
   340
chaieb@26123
   341
text{* Bolzano-Weierstrass type property for closed disc in complex plane. *}
chaieb@26123
   342
wenzelm@56778
   343
lemma metric_bound_lemma: "cmod (x - y) \<le> \<bar>Re x - Re y\<bar> + \<bar>Im x - Im y\<bar>"
wenzelm@56795
   344
  using real_sqrt_sum_squares_triangle_ineq[of "Re x - Re y" 0 0 "Im x - Im y"]
chaieb@26123
   345
  unfolding cmod_def by simp
chaieb@26123
   346
chaieb@26123
   347
lemma bolzano_weierstrass_complex_disc:
chaieb@26123
   348
  assumes r: "\<forall>n. cmod (s n) \<le> r"
chaieb@26123
   349
  shows "\<exists>f z. subseq f \<and> (\<forall>e >0. \<exists>N. \<forall>n \<ge> N. cmod (s (f n) - z) < e)"
chaieb@26123
   350
proof-
wenzelm@56778
   351
  from seq_monosub[of "Re \<circ> s"]
lp15@55358
   352
  obtain f where f: "subseq f" "monoseq (\<lambda>n. Re (s (f n)))"
chaieb@26123
   353
    unfolding o_def by blast
wenzelm@56778
   354
  from seq_monosub[of "Im \<circ> s \<circ> f"]
wenzelm@56778
   355
  obtain g where g: "subseq g" "monoseq (\<lambda>n. Im (s (f (g n))))"
wenzelm@56778
   356
    unfolding o_def by blast
wenzelm@56778
   357
  let ?h = "f \<circ> g"
wenzelm@56778
   358
  from r[rule_format, of 0] have rp: "r \<ge> 0"
wenzelm@56778
   359
    using norm_ge_zero[of "s 0"] by arith
wenzelm@56778
   360
  have th: "\<forall>n. r + 1 \<ge> \<bar>Re (s n)\<bar>"
chaieb@26123
   361
  proof
chaieb@26123
   362
    fix n
wenzelm@56778
   363
    from abs_Re_le_cmod[of "s n"] r[rule_format, of n]
wenzelm@56778
   364
    show "\<bar>Re (s n)\<bar> \<le> r + 1" by arith
chaieb@26123
   365
  qed
wenzelm@56778
   366
  have conv1: "convergent (\<lambda>n. Re (s (f n)))"
chaieb@26123
   367
    apply (rule Bseq_monoseq_convergent)
chaieb@26123
   368
    apply (simp add: Bseq_def)
lp15@55358
   369
    apply (metis gt_ex le_less_linear less_trans order.trans th)
wenzelm@56778
   370
    apply (rule f(2))
wenzelm@56778
   371
    done
wenzelm@56778
   372
  have th: "\<forall>n. r + 1 \<ge> \<bar>Im (s n)\<bar>"
chaieb@26123
   373
  proof
chaieb@26123
   374
    fix n
wenzelm@56778
   375
    from abs_Im_le_cmod[of "s n"] r[rule_format, of n]
wenzelm@56778
   376
    show "\<bar>Im (s n)\<bar> \<le> r + 1"
wenzelm@56778
   377
      by arith
chaieb@26123
   378
  qed
chaieb@26123
   379
chaieb@26123
   380
  have conv2: "convergent (\<lambda>n. Im (s (f (g n))))"
chaieb@26123
   381
    apply (rule Bseq_monoseq_convergent)
chaieb@26123
   382
    apply (simp add: Bseq_def)
lp15@55358
   383
    apply (metis gt_ex le_less_linear less_trans order.trans th)
wenzelm@56778
   384
    apply (rule g(2))
wenzelm@56778
   385
    done
chaieb@26123
   386
huffman@30488
   387
  from conv1[unfolded convergent_def] obtain x where "LIMSEQ (\<lambda>n. Re (s (f n))) x"
huffman@30488
   388
    by blast
wenzelm@56795
   389
  then have x: "\<forall>r>0. \<exists>n0. \<forall>n\<ge>n0. \<bar>Re (s (f n)) - x\<bar> < r"
huffman@31337
   390
    unfolding LIMSEQ_iff real_norm_def .
chaieb@26123
   391
huffman@30488
   392
  from conv2[unfolded convergent_def] obtain y where "LIMSEQ (\<lambda>n. Im (s (f (g n)))) y"
huffman@30488
   393
    by blast
wenzelm@56795
   394
  then have y: "\<forall>r>0. \<exists>n0. \<forall>n\<ge>n0. \<bar>Im (s (f (g n))) - y\<bar> < r"
huffman@31337
   395
    unfolding LIMSEQ_iff real_norm_def .
chaieb@26123
   396
  let ?w = "Complex x y"
wenzelm@56778
   397
  from f(1) g(1) have hs: "subseq ?h"
wenzelm@56778
   398
    unfolding subseq_def by auto
wenzelm@56778
   399
  {
wenzelm@56778
   400
    fix e :: real
wenzelm@56778
   401
    assume ep: "e > 0"
wenzelm@56795
   402
    then have e2: "e/2 > 0"
wenzelm@56795
   403
      by simp
chaieb@26123
   404
    from x[rule_format, OF e2] y[rule_format, OF e2]
wenzelm@56778
   405
    obtain N1 N2 where N1: "\<forall>n\<ge>N1. \<bar>Re (s (f n)) - x\<bar> < e / 2"
wenzelm@56795
   406
      and N2: "\<forall>n\<ge>N2. \<bar>Im (s (f (g n))) - y\<bar> < e / 2"
wenzelm@56795
   407
      by blast
wenzelm@56778
   408
    {
wenzelm@56778
   409
      fix n
wenzelm@56778
   410
      assume nN12: "n \<ge> N1 + N2"
wenzelm@56778
   411
      then have nN1: "g n \<ge> N1" and nN2: "n \<ge> N2"
wenzelm@56778
   412
        using seq_suble[OF g(1), of n] by arith+
chaieb@26123
   413
      from add_strict_mono[OF N1[rule_format, OF nN1] N2[rule_format, OF nN2]]
huffman@30488
   414
      have "cmod (s (?h n) - ?w) < e"
wenzelm@56778
   415
        using metric_bound_lemma[of "s (f (g n))" ?w] by simp
wenzelm@56778
   416
    }
wenzelm@56795
   417
    then have "\<exists>N. \<forall>n\<ge>N. cmod (s (?h n) - ?w) < e"
wenzelm@56795
   418
      by blast
wenzelm@56778
   419
  }
wenzelm@56778
   420
  with hs show ?thesis by blast
chaieb@26123
   421
qed
chaieb@26123
   422
chaieb@26123
   423
text{* Polynomial is continuous. *}
chaieb@26123
   424
chaieb@26123
   425
lemma poly_cont:
wenzelm@56778
   426
  fixes p :: "'a::{comm_semiring_0,real_normed_div_algebra} poly"
huffman@30488
   427
  assumes ep: "e > 0"
lp15@55735
   428
  shows "\<exists>d >0. \<forall>w. 0 < norm (w - z) \<and> norm (w - z) < d \<longrightarrow> norm (poly p w - poly p z) < e"
wenzelm@56778
   429
proof -
huffman@29464
   430
  obtain q where q: "degree q = degree p" "\<And>x. poly q x = poly p (z + x)"
huffman@29464
   431
  proof
huffman@29464
   432
    show "degree (offset_poly p z) = degree p"
huffman@29464
   433
      by (rule degree_offset_poly)
huffman@29464
   434
    show "\<And>x. poly (offset_poly p z) x = poly p (z + x)"
huffman@29464
   435
      by (rule poly_offset_poly)
huffman@29464
   436
  qed
wenzelm@56778
   437
  have th: "\<And>w. poly q (w - z) = poly p w"
wenzelm@56778
   438
    using q(2)[of "w - z" for w] by simp
chaieb@26123
   439
  show ?thesis unfolding th[symmetric]
wenzelm@56778
   440
  proof (induct q)
wenzelm@56778
   441
    case 0
wenzelm@56778
   442
    then show ?case
wenzelm@56778
   443
      using ep by auto
chaieb@26123
   444
  next
huffman@29464
   445
    case (pCons c cs)
huffman@30488
   446
    from poly_bound_exists[of 1 "cs"]
wenzelm@56778
   447
    obtain m where m: "m > 0" "\<And>z. norm z \<le> 1 \<Longrightarrow> norm (poly cs z) \<le> m"
wenzelm@56778
   448
      by blast
wenzelm@56778
   449
    from ep m(1) have em0: "e/m > 0"
wenzelm@56778
   450
      by (simp add: field_simps)
wenzelm@56778
   451
    have one0: "1 > (0::real)"
wenzelm@56778
   452
      by arith
huffman@30488
   453
    from real_lbound_gt_zero[OF one0 em0]
wenzelm@56778
   454
    obtain d where d: "d > 0" "d < 1" "d < e / m"
wenzelm@56778
   455
      by blast
wenzelm@56778
   456
    from d(1,3) m(1) have dm: "d * m > 0" "d * m < e"
nipkow@56544
   457
      by (simp_all add: field_simps)
huffman@30488
   458
    show ?case
wenzelm@56778
   459
    proof (rule ex_forward[OF real_lbound_gt_zero[OF one0 em0]], clarsimp simp add: norm_mult)
wenzelm@56778
   460
      fix d w
wenzelm@56778
   461
      assume H: "d > 0" "d < 1" "d < e/m" "w \<noteq> z" "norm (w - z) < d"
wenzelm@56778
   462
      then have d1: "norm (w-z) \<le> 1" "d \<ge> 0"
wenzelm@56778
   463
        by simp_all
wenzelm@56778
   464
      from H(3) m(1) have dme: "d*m < e"
wenzelm@56778
   465
        by (simp add: field_simps)
wenzelm@56778
   466
      from H have th: "norm (w - z) \<le> d"
wenzelm@56778
   467
        by simp
wenzelm@56778
   468
      from mult_mono[OF th m(2)[OF d1(1)] d1(2) norm_ge_zero] dme
wenzelm@56778
   469
      show "norm (w - z) * norm (poly cs (w - z)) < e"
wenzelm@56778
   470
        by simp
chaieb@26123
   471
    qed
wenzelm@56778
   472
  qed
chaieb@26123
   473
qed
chaieb@26123
   474
huffman@30488
   475
text{* Hence a polynomial attains minimum on a closed disc
chaieb@26123
   476
  in the complex plane. *}
wenzelm@56778
   477
lemma poly_minimum_modulus_disc: "\<exists>z. \<forall>w. cmod w \<le> r \<longrightarrow> cmod (poly p z) \<le> cmod (poly p w)"
wenzelm@56778
   478
proof -
wenzelm@56778
   479
  {
wenzelm@56778
   480
    assume "\<not> r \<ge> 0"
wenzelm@56778
   481
    then have ?thesis
wenzelm@56778
   482
      by (metis norm_ge_zero order.trans)
wenzelm@56778
   483
  }
chaieb@26123
   484
  moreover
wenzelm@56778
   485
  {
wenzelm@56778
   486
    assume rp: "r \<ge> 0"
wenzelm@56778
   487
    from rp have "cmod 0 \<le> r \<and> cmod (poly p 0) = - (- cmod (poly p 0))"
wenzelm@56778
   488
      by simp
wenzelm@56778
   489
    then have mth1: "\<exists>x z. cmod z \<le> r \<and> cmod (poly p z) = - x"
wenzelm@56778
   490
      by blast
wenzelm@56778
   491
    {
wenzelm@56778
   492
      fix x z
wenzelm@56778
   493
      assume H: "cmod z \<le> r" "cmod (poly p z) = - x" "\<not> x < 1"
wenzelm@56778
   494
      then have "- x < 0 "
wenzelm@56778
   495
        by arith
wenzelm@56778
   496
      with H(2) norm_ge_zero[of "poly p z"] have False
wenzelm@56778
   497
        by simp
wenzelm@56778
   498
    }
wenzelm@56778
   499
    then have mth2: "\<exists>z. \<forall>x. (\<exists>z. cmod z \<le> r \<and> cmod (poly p z) = - x) \<longrightarrow> x < z"
wenzelm@56778
   500
      by blast
huffman@30488
   501
    from real_sup_exists[OF mth1 mth2] obtain s where
wenzelm@56778
   502
      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
wenzelm@56778
   503
    let ?m = "- s"
wenzelm@56778
   504
    {
wenzelm@56778
   505
      fix y
wenzelm@56778
   506
      from s[rule_format, of "-y"]
wenzelm@56778
   507
      have "(\<exists>z x. cmod z \<le> r \<and> - (- cmod (poly p z)) < y) \<longleftrightarrow> ?m < y"
wenzelm@56778
   508
        unfolding minus_less_iff[of y ] equation_minus_iff by blast
wenzelm@56778
   509
    }
chaieb@26123
   510
    note s1 = this[unfolded minus_minus]
huffman@30488
   511
    from s1[of ?m] have s1m: "\<And>z x. cmod z \<le> r \<Longrightarrow> cmod (poly p z) \<ge> ?m"
chaieb@26123
   512
      by auto
wenzelm@56778
   513
    {
wenzelm@56778
   514
      fix n :: nat
huffman@30488
   515
      from s1[rule_format, of "?m + 1/real (Suc n)"]
chaieb@26123
   516
      have "\<exists>z. cmod z \<le> r \<and> cmod (poly p z) < - s + 1 / real (Suc n)"
wenzelm@56778
   517
        by simp
wenzelm@56778
   518
    }
wenzelm@56778
   519
    then have th: "\<forall>n. \<exists>z. cmod z \<le> r \<and> cmod (poly p z) < - s + 1 / real (Suc n)" ..
huffman@30488
   520
    from choice[OF th] obtain g where
wenzelm@56778
   521
        g: "\<forall>n. cmod (g n) \<le> r" "\<forall>n. cmod (poly p (g n)) <?m + 1 /real(Suc n)"
chaieb@26123
   522
      by blast
huffman@30488
   523
    from bolzano_weierstrass_complex_disc[OF g(1)]
chaieb@26123
   524
    obtain f z where fz: "subseq f" "\<forall>e>0. \<exists>N. \<forall>n\<ge>N. cmod (g (f n) - z) < e"
huffman@30488
   525
      by blast
wenzelm@56778
   526
    {
wenzelm@56778
   527
      fix w
chaieb@26123
   528
      assume wr: "cmod w \<le> r"
chaieb@26123
   529
      let ?e = "\<bar>cmod (poly p z) - ?m\<bar>"
wenzelm@56778
   530
      {
wenzelm@56778
   531
        assume e: "?e > 0"
wenzelm@56795
   532
        then have e2: "?e/2 > 0"
wenzelm@56795
   533
          by simp
wenzelm@32960
   534
        from poly_cont[OF e2, of z p] obtain d where
wenzelm@56778
   535
            d: "d > 0" "\<forall>w. 0<cmod (w - z)\<and> cmod(w - z) < d \<longrightarrow> cmod(poly p w - poly p z) < ?e/2"
wenzelm@56778
   536
          by blast
wenzelm@56778
   537
        {
wenzelm@56778
   538
          fix w
wenzelm@56778
   539
          assume w: "cmod (w - z) < d"
wenzelm@32960
   540
          have "cmod(poly p w - poly p z) < ?e / 2"
wenzelm@56778
   541
            using d(2)[rule_format, of w] w e by (cases "w = z") simp_all
wenzelm@56778
   542
        }
wenzelm@32960
   543
        note th1 = this
huffman@30488
   544
wenzelm@56778
   545
        from fz(2) d(1) obtain N1 where N1: "\<forall>n\<ge>N1. cmod (g (f n) - z) < d"
wenzelm@56778
   546
          by blast
wenzelm@56778
   547
        from reals_Archimedean2[of "2/?e"] obtain N2 :: nat where N2: "2/?e < real N2"
wenzelm@56778
   548
          by blast
wenzelm@56778
   549
        have th2: "cmod (poly p (g (f (N1 + N2))) - poly p z) < ?e/2"
wenzelm@32960
   550
          using N1[rule_format, of "N1 + N2"] th1 by simp
wenzelm@56778
   551
        {
wenzelm@56778
   552
          fix a b e2 m :: real
wenzelm@56778
   553
          have "a < e2 \<Longrightarrow> \<bar>b - m\<bar> < e2 \<Longrightarrow> 2 * e2 \<le> \<bar>b - m\<bar> + a \<Longrightarrow> False"
wenzelm@56778
   554
            by arith
wenzelm@56778
   555
        }
wenzelm@56778
   556
        note th0 = this
wenzelm@56778
   557
        have ath: "\<And>m x e::real. m \<le> x \<Longrightarrow> x < m + e \<Longrightarrow> \<bar>x - m\<bar> < e"
wenzelm@56778
   558
          by arith
wenzelm@56778
   559
        from s1m[OF g(1)[rule_format]] have th31: "?m \<le> cmod(poly p (g (f (N1 + N2))))" .
wenzelm@56795
   560
        from seq_suble[OF fz(1), of "N1 + N2"]
wenzelm@56778
   561
        have th00: "real (Suc (N1 + N2)) \<le> real (Suc (f (N1 + N2)))"
wenzelm@56778
   562
          by simp
wenzelm@56778
   563
        have th000: "0 \<le> (1::real)" "(1::real) \<le> 1" "real (Suc (N1 + N2)) > 0"
wenzelm@56778
   564
          using N2 by auto
wenzelm@56778
   565
        from frac_le[OF th000 th00]
wenzelm@56795
   566
        have th00: "?m + 1 / real (Suc (f (N1 + N2))) \<le> ?m + 1 / real (Suc (N1 + N2))"
wenzelm@56778
   567
          by simp
wenzelm@56778
   568
        from g(2)[rule_format, of "f (N1 + N2)"]
wenzelm@56778
   569
        have th01:"cmod (poly p (g (f (N1 + N2)))) < - s + 1 / real (Suc (f (N1 + N2)))" .
wenzelm@56778
   570
        from order_less_le_trans[OF th01 th00]
wenzelm@56795
   571
        have th32: "cmod (poly p (g (f (N1 + N2)))) < ?m + (1/ real(Suc (N1 + N2)))" .
wenzelm@56778
   572
        from N2 have "2/?e < real (Suc (N1 + N2))"
wenzelm@56778
   573
          by arith
wenzelm@56778
   574
        with e2 less_imp_inverse_less[of "2/?e" "real (Suc (N1 + N2))"]
wenzelm@56778
   575
        have "?e/2 > 1/ real (Suc (N1 + N2))"
wenzelm@56778
   576
          by (simp add: inverse_eq_divide)
wenzelm@56778
   577
        with ath[OF th31 th32]
wenzelm@56795
   578
        have thc1: "\<bar>cmod (poly p (g (f (N1 + N2)))) - ?m\<bar> < ?e/2"
wenzelm@56778
   579
          by arith
wenzelm@56778
   580
        have ath2: "\<And>a b c m::real. \<bar>a - b\<bar> \<le> c \<Longrightarrow> \<bar>b - m\<bar> \<le> \<bar>a - m\<bar> + c"
wenzelm@56778
   581
          by arith
wenzelm@56778
   582
        have th22: "\<bar>cmod (poly p (g (f (N1 + N2)))) - cmod (poly p z)\<bar> \<le>
wenzelm@56778
   583
            cmod (poly p (g (f (N1 + N2))) - poly p z)"
wenzelm@56778
   584
          by (simp add: norm_triangle_ineq3)
wenzelm@56778
   585
        from ath2[OF th22, of ?m]
wenzelm@56778
   586
        have thc2: "2 * (?e/2) \<le>
wenzelm@56778
   587
            \<bar>cmod(poly p (g (f (N1 + N2)))) - ?m\<bar> + cmod (poly p (g (f (N1 + N2))) - poly p z)"
wenzelm@56778
   588
          by simp
wenzelm@56778
   589
        from th0[OF th2 thc1 thc2] have False .
wenzelm@56778
   590
      }
wenzelm@56778
   591
      then have "?e = 0"
wenzelm@56778
   592
        by auto
wenzelm@56778
   593
      then have "cmod (poly p z) = ?m"
wenzelm@56778
   594
        by simp
wenzelm@56778
   595
      with s1m[OF wr] have "cmod (poly p z) \<le> cmod (poly p w)"
wenzelm@56778
   596
        by simp
wenzelm@56778
   597
    }
wenzelm@56778
   598
    then have ?thesis by blast
wenzelm@56778
   599
  }
chaieb@26123
   600
  ultimately show ?thesis by blast
chaieb@26123
   601
qed
chaieb@26123
   602
wenzelm@53077
   603
lemma "(rcis (sqrt (abs r)) (a/2))\<^sup>2 = rcis (abs r) a"
chaieb@26123
   604
  unfolding power2_eq_square
chaieb@26123
   605
  apply (simp add: rcis_mult)
chaieb@26123
   606
  apply (simp add: power2_eq_square[symmetric])
chaieb@26123
   607
  done
chaieb@26123
   608
huffman@30488
   609
lemma cispi: "cis pi = -1"
wenzelm@56778
   610
  by (simp add: cis_def)
chaieb@26123
   611
wenzelm@56795
   612
lemma "(rcis (sqrt (abs r)) ((pi + a) / 2))\<^sup>2 = rcis (- abs r) a"
chaieb@26123
   613
  unfolding power2_eq_square
chaieb@26123
   614
  apply (simp add: rcis_mult add_divide_distrib)
chaieb@26123
   615
  apply (simp add: power2_eq_square[symmetric] rcis_def cispi cis_mult[symmetric])
chaieb@26123
   616
  done
chaieb@26123
   617
chaieb@26123
   618
text {* Nonzero polynomial in z goes to infinity as z does. *}
chaieb@26123
   619
chaieb@26123
   620
lemma poly_infinity:
wenzelm@56778
   621
  fixes p:: "'a::{comm_semiring_0,real_normed_div_algebra} poly"
huffman@29464
   622
  assumes ex: "p \<noteq> 0"
lp15@55735
   623
  shows "\<exists>r. \<forall>z. r \<le> norm z \<longrightarrow> d \<le> norm (poly (pCons a p) z)"
wenzelm@56778
   624
  using ex
wenzelm@56778
   625
proof (induct p arbitrary: a d)
wenzelm@56795
   626
  case 0
wenzelm@56795
   627
  then show ?case by simp
wenzelm@56795
   628
next
huffman@30488
   629
  case (pCons c cs a d)
wenzelm@56795
   630
  show ?case
wenzelm@56795
   631
  proof (cases "cs = 0")
wenzelm@56795
   632
    case False
wenzelm@56778
   633
    with pCons.hyps obtain r where r: "\<forall>z. r \<le> norm z \<longrightarrow> d + norm a \<le> norm (poly (pCons c cs) z)"
wenzelm@56778
   634
      by blast
chaieb@26123
   635
    let ?r = "1 + \<bar>r\<bar>"
wenzelm@56778
   636
    {
wenzelm@56795
   637
      fix z :: 'a
wenzelm@56778
   638
      assume h: "1 + \<bar>r\<bar> \<le> norm z"
wenzelm@56795
   639
      have r0: "r \<le> norm z"
wenzelm@56795
   640
        using h by arith
wenzelm@56778
   641
      from r[rule_format, OF r0] have th0: "d + norm a \<le> 1 * norm(poly (pCons c cs) z)"
wenzelm@56778
   642
        by arith
wenzelm@56778
   643
      from h have z1: "norm z \<ge> 1"
wenzelm@56778
   644
        by arith
huffman@29464
   645
      from order_trans[OF th0 mult_right_mono[OF z1 norm_ge_zero[of "poly (pCons c cs) z"]]]
lp15@55735
   646
      have th1: "d \<le> norm(z * poly (pCons c cs) z) - norm a"
wenzelm@32960
   647
        unfolding norm_mult by (simp add: algebra_simps)
lp15@55735
   648
      from norm_diff_ineq[of "z * poly (pCons c cs) z" a]
wenzelm@56795
   649
      have th2: "norm (z * poly (pCons c cs) z) - norm a \<le> norm (poly (pCons a (pCons c cs)) z)"
wenzelm@51541
   650
        by (simp add: algebra_simps)
wenzelm@56795
   651
      from th1 th2 have "d \<le> norm (poly (pCons a (pCons c cs)) z)"
wenzelm@56795
   652
        by arith
wenzelm@56778
   653
    }
wenzelm@56795
   654
    then show ?thesis by blast
wenzelm@56795
   655
  next
wenzelm@56795
   656
    case True
wenzelm@56778
   657
    with pCons.prems have c0: "c \<noteq> 0"
wenzelm@56778
   658
      by simp
wenzelm@56778
   659
    {
wenzelm@56795
   660
      fix z :: 'a
lp15@55735
   661
      assume h: "(\<bar>d\<bar> + norm a) / norm c \<le> norm z"
wenzelm@56778
   662
      from c0 have "norm c > 0"
wenzelm@56778
   663
        by simp
blanchet@56403
   664
      from h c0 have th0: "\<bar>d\<bar> + norm a \<le> norm (z * c)"
wenzelm@32960
   665
        by (simp add: field_simps norm_mult)
wenzelm@56778
   666
      have ath: "\<And>mzh mazh ma. mzh \<le> mazh + ma \<Longrightarrow> \<bar>d\<bar> + ma \<le> mzh \<Longrightarrow> d \<le> mazh"
wenzelm@56778
   667
        by arith
wenzelm@56778
   668
      from norm_diff_ineq[of "z * c" a] have th1: "norm (z * c) \<le> norm (a + z * c) + norm a"
wenzelm@32960
   669
        by (simp add: algebra_simps)
lp15@55735
   670
      from ath[OF th1 th0] have "d \<le> norm (poly (pCons a (pCons c cs)) z)"
wenzelm@56795
   671
        using True by simp
wenzelm@56778
   672
    }
wenzelm@56795
   673
    then show ?thesis by blast
wenzelm@56795
   674
  qed
wenzelm@56795
   675
qed
chaieb@26123
   676
chaieb@26123
   677
text {* Hence polynomial's modulus attains its minimum somewhere. *}
wenzelm@56778
   678
lemma poly_minimum_modulus: "\<exists>z.\<forall>w. cmod (poly p z) \<le> cmod (poly p w)"
wenzelm@56778
   679
proof (induct p)
wenzelm@56778
   680
  case 0
wenzelm@56778
   681
  then show ?case by simp
wenzelm@56778
   682
next
huffman@30488
   683
  case (pCons c cs)
wenzelm@56778
   684
  show ?case
wenzelm@56778
   685
  proof (cases "cs = 0")
wenzelm@56778
   686
    case False
wenzelm@56778
   687
    from poly_infinity[OF False, of "cmod (poly (pCons c cs) 0)" c]
wenzelm@56778
   688
    obtain r where r: "\<And>z. r \<le> cmod z \<Longrightarrow> cmod (poly (pCons c cs) 0) \<le> cmod (poly (pCons c cs) z)"
wenzelm@56778
   689
      by blast
wenzelm@56778
   690
    have ath: "\<And>z r. r \<le> cmod z \<or> cmod z \<le> \<bar>r\<bar>"
wenzelm@56778
   691
      by arith
huffman@30488
   692
    from poly_minimum_modulus_disc[of "\<bar>r\<bar>" "pCons c cs"]
wenzelm@56778
   693
    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)"
wenzelm@56778
   694
      by blast
wenzelm@56778
   695
    {
wenzelm@56778
   696
      fix z
wenzelm@56778
   697
      assume z: "r \<le> cmod z"
wenzelm@56778
   698
      from v[of 0] r[OF z] have "cmod (poly (pCons c cs) v) \<le> cmod (poly (pCons c cs) z)"
wenzelm@56778
   699
        by simp
wenzelm@56778
   700
    }
chaieb@26123
   701
    note v0 = this
wenzelm@56778
   702
    from v0 v ath[of r] show ?thesis
wenzelm@56778
   703
      by blast
wenzelm@56778
   704
  next
wenzelm@56778
   705
    case True
wenzelm@56778
   706
    with pCons.hyps show ?thesis by simp
wenzelm@56778
   707
  qed
wenzelm@56778
   708
qed
chaieb@26123
   709
chaieb@26123
   710
text{* Constant function (non-syntactic characterization). *}
wenzelm@56795
   711
definition "constant f \<longleftrightarrow> (\<forall>x y. f x = f y)"
chaieb@26123
   712
wenzelm@56778
   713
lemma nonconstant_length: "\<not> constant (poly p) \<Longrightarrow> psize p \<ge> 2"
wenzelm@56778
   714
  by (induct p) (auto simp: constant_def psize_def)
huffman@30488
   715
wenzelm@56795
   716
lemma poly_replicate_append: "poly (monom 1 n * p) (x::'a::comm_ring_1) = x^n * poly p x"
huffman@29464
   717
  by (simp add: poly_monom)
chaieb@26123
   718
huffman@30488
   719
text {* Decomposition of polynomial, skipping zero coefficients
chaieb@26123
   720
  after the first.  *}
chaieb@26123
   721
chaieb@26123
   722
lemma poly_decompose_lemma:
wenzelm@56778
   723
  assumes nz: "\<not> (\<forall>z. z \<noteq> 0 \<longrightarrow> poly p z = (0::'a::idom))"
wenzelm@56795
   724
  shows "\<exists>k a q. a \<noteq> 0 \<and> Suc (psize q + k) = psize p \<and> (\<forall>z. poly p z = z^k * poly (pCons a q) z)"
wenzelm@56778
   725
  unfolding psize_def
wenzelm@56778
   726
  using nz
wenzelm@56778
   727
proof (induct p)
wenzelm@56778
   728
  case 0
wenzelm@56778
   729
  then show ?case by simp
chaieb@26123
   730
next
huffman@29464
   731
  case (pCons c cs)
wenzelm@56778
   732
  show ?case
wenzelm@56778
   733
  proof (cases "c = 0")
wenzelm@56778
   734
    case True
wenzelm@56778
   735
    from pCons.hyps pCons.prems True show ?thesis
nipkow@32456
   736
      apply (auto)
chaieb@26123
   737
      apply (rule_tac x="k+1" in exI)
chaieb@26123
   738
      apply (rule_tac x="a" in exI, clarsimp)
chaieb@26123
   739
      apply (rule_tac x="q" in exI)
wenzelm@56778
   740
      apply auto
wenzelm@56778
   741
      done
wenzelm@56778
   742
  next
wenzelm@56778
   743
    case False
wenzelm@56778
   744
    show ?thesis
chaieb@26123
   745
      apply (rule exI[where x=0])
wenzelm@56778
   746
      apply (rule exI[where x=c], auto simp add: False)
wenzelm@56778
   747
      done
wenzelm@56778
   748
  qed
chaieb@26123
   749
qed
chaieb@26123
   750
chaieb@26123
   751
lemma poly_decompose:
wenzelm@56776
   752
  assumes nc: "\<not> constant (poly p)"
wenzelm@56778
   753
  shows "\<exists>k a q. a \<noteq> (0::'a::idom) \<and> k \<noteq> 0 \<and>
huffman@30488
   754
               psize q + k + 1 = psize p \<and>
huffman@29464
   755
              (\<forall>z. poly p z = poly p 0 + z^k * poly (pCons a q) z)"
wenzelm@56776
   756
  using nc
wenzelm@56776
   757
proof (induct p)
wenzelm@56776
   758
  case 0
wenzelm@56776
   759
  then show ?case
wenzelm@56776
   760
    by (simp add: constant_def)
chaieb@26123
   761
next
huffman@29464
   762
  case (pCons c cs)
wenzelm@56776
   763
  {
wenzelm@56795
   764
    assume C: "\<forall>z. z \<noteq> 0 \<longrightarrow> poly cs z = 0"
wenzelm@56776
   765
    {
wenzelm@56776
   766
      fix x y
wenzelm@56776
   767
      from C have "poly (pCons c cs) x = poly (pCons c cs) y"
wenzelm@56776
   768
        by (cases "x = 0") auto
wenzelm@56776
   769
    }
wenzelm@56778
   770
    with pCons.prems have False
wenzelm@56778
   771
      by (auto simp add: constant_def)
wenzelm@56776
   772
  }
wenzelm@56776
   773
  then have th: "\<not> (\<forall>z. z \<noteq> 0 \<longrightarrow> poly cs z = 0)" ..
huffman@30488
   774
  from poly_decompose_lemma[OF th]
huffman@30488
   775
  show ?case
huffman@29464
   776
    apply clarsimp
chaieb@26123
   777
    apply (rule_tac x="k+1" in exI)
chaieb@26123
   778
    apply (rule_tac x="a" in exI)
chaieb@26123
   779
    apply simp
chaieb@26123
   780
    apply (rule_tac x="q" in exI)
huffman@29538
   781
    apply (auto simp add: psize_def split: if_splits)
chaieb@26123
   782
    done
chaieb@26123
   783
qed
chaieb@26123
   784
berghofe@34915
   785
text{* Fundamental theorem of algebra *}
chaieb@26123
   786
chaieb@26123
   787
lemma fundamental_theorem_of_algebra:
wenzelm@56776
   788
  assumes nc: "\<not> constant (poly p)"
chaieb@26123
   789
  shows "\<exists>z::complex. poly p z = 0"
wenzelm@56776
   790
  using nc
wenzelm@56776
   791
proof (induct "psize p" arbitrary: p rule: less_induct)
berghofe@34915
   792
  case less
chaieb@26123
   793
  let ?p = "poly p"
chaieb@26123
   794
  let ?ths = "\<exists>z. ?p z = 0"
chaieb@26123
   795
berghofe@34915
   796
  from nonconstant_length[OF less(2)] have n2: "psize p \<ge> 2" .
wenzelm@56776
   797
  from poly_minimum_modulus obtain c where c: "\<forall>w. cmod (?p c) \<le> cmod (?p w)"
wenzelm@56776
   798
    by blast
wenzelm@56778
   799
wenzelm@56778
   800
  show ?ths
wenzelm@56778
   801
  proof (cases "?p c = 0")
wenzelm@56778
   802
    case True
wenzelm@56778
   803
    then show ?thesis by blast
wenzelm@56778
   804
  next
wenzelm@56778
   805
    case False
wenzelm@56778
   806
    note pc0 = this
wenzelm@56778
   807
    from poly_offset[of p c] obtain q where q: "psize q = psize p" "\<forall>x. poly q x = ?p (c + x)"
wenzelm@56778
   808
      by blast
wenzelm@56778
   809
    {
wenzelm@56778
   810
      assume h: "constant (poly q)"
wenzelm@56795
   811
      from q(2) have th: "\<forall>x. poly q (x - c) = ?p x"
wenzelm@56795
   812
        by auto
wenzelm@56778
   813
      {
wenzelm@56778
   814
        fix x y
wenzelm@56795
   815
        from th have "?p x = poly q (x - c)"
wenzelm@56795
   816
          by auto
wenzelm@32960
   817
        also have "\<dots> = poly q (y - c)"
wenzelm@32960
   818
          using h unfolding constant_def by blast
wenzelm@56795
   819
        also have "\<dots> = ?p y"
wenzelm@56795
   820
          using th by auto
wenzelm@56778
   821
        finally have "?p x = ?p y" .
wenzelm@56778
   822
      }
wenzelm@56778
   823
      with less(2) have False
wenzelm@56778
   824
        unfolding constant_def by blast
wenzelm@56778
   825
    }
wenzelm@56778
   826
    then have qnc: "\<not> constant (poly q)"
wenzelm@56778
   827
      by blast
wenzelm@56778
   828
    from q(2) have pqc0: "?p c = poly q 0"
wenzelm@56778
   829
      by simp
wenzelm@56778
   830
    from c pqc0 have cq0: "\<forall>w. cmod (poly q 0) \<le> cmod (?p w)"
wenzelm@56778
   831
      by simp
chaieb@26123
   832
    let ?a0 = "poly q 0"
wenzelm@56778
   833
    from pc0 pqc0 have a00: "?a0 \<noteq> 0"
wenzelm@56778
   834
      by simp
wenzelm@56778
   835
    from a00 have qr: "\<forall>z. poly q z = poly (smult (inverse ?a0) q) z * ?a0"
huffman@29464
   836
      by simp
huffman@29464
   837
    let ?r = "smult (inverse ?a0) q"
huffman@29538
   838
    have lgqr: "psize q = psize ?r"
wenzelm@56778
   839
      using a00
wenzelm@56778
   840
      unfolding psize_def degree_def
haftmann@52380
   841
      by (simp add: poly_eq_iff)
wenzelm@56778
   842
    {
wenzelm@56778
   843
      assume h: "\<And>x y. poly ?r x = poly ?r y"
wenzelm@56778
   844
      {
wenzelm@56778
   845
        fix x y
wenzelm@56778
   846
        from qr[rule_format, of x] have "poly q x = poly ?r x * ?a0"
wenzelm@56778
   847
          by auto
wenzelm@56778
   848
        also have "\<dots> = poly ?r y * ?a0"
wenzelm@56778
   849
          using h by simp
wenzelm@56778
   850
        also have "\<dots> = poly q y"
wenzelm@56778
   851
          using qr[rule_format, of y] by simp
wenzelm@56778
   852
        finally have "poly q x = poly q y" .
wenzelm@56778
   853
      }
wenzelm@56795
   854
      with qnc have False
wenzelm@56795
   855
        unfolding constant_def by blast
wenzelm@56778
   856
    }
wenzelm@56778
   857
    then have rnc: "\<not> constant (poly ?r)"
wenzelm@56778
   858
      unfolding constant_def by blast
wenzelm@56778
   859
    from qr[rule_format, of 0] a00 have r01: "poly ?r 0 = 1"
wenzelm@56778
   860
      by auto
wenzelm@56778
   861
    {
wenzelm@56778
   862
      fix w
chaieb@26123
   863
      have "cmod (poly ?r w) < 1 \<longleftrightarrow> cmod (poly q w / ?a0) < 1"
wenzelm@32960
   864
        using qr[rule_format, of w] a00 by (simp add: divide_inverse mult_ac)
chaieb@26123
   865
      also have "\<dots> \<longleftrightarrow> cmod (poly q w) < cmod ?a0"
wenzelm@32960
   866
        using a00 unfolding norm_divide by (simp add: field_simps)
wenzelm@56778
   867
      finally have "cmod (poly ?r w) < 1 \<longleftrightarrow> cmod (poly q w) < cmod ?a0" .
wenzelm@56778
   868
    }
chaieb@26123
   869
    note mrmq_eq = this
huffman@30488
   870
    from poly_decompose[OF rnc] obtain k a s where
wenzelm@56778
   871
      kas: "a \<noteq> 0" "k \<noteq> 0" "psize s + k + 1 = psize ?r"
wenzelm@56778
   872
        "\<forall>z. poly ?r z = poly ?r 0 + z^k* poly (pCons a s) z" by blast
wenzelm@56778
   873
    {
wenzelm@56778
   874
      assume "psize p = k + 1"
wenzelm@56778
   875
      with kas(3) lgqr[symmetric] q(1) have s0: "s = 0"
wenzelm@56778
   876
        by auto
wenzelm@56778
   877
      {
wenzelm@56778
   878
        fix w
wenzelm@32960
   879
        have "cmod (poly ?r w) = cmod (1 + a * w ^ k)"
wenzelm@56778
   880
          using kas(4)[rule_format, of w] s0 r01 by (simp add: algebra_simps)
wenzelm@56778
   881
      }
chaieb@26123
   882
      note hth = this [symmetric]
wenzelm@56778
   883
      from reduce_poly_simple[OF kas(1,2)] have "\<exists>w. cmod (poly ?r w) < 1"
wenzelm@56778
   884
        unfolding hth by blast
wenzelm@56778
   885
    }
chaieb@26123
   886
    moreover
wenzelm@56778
   887
    {
wenzelm@56778
   888
      assume kn: "psize p \<noteq> k + 1"
wenzelm@56778
   889
      from kn kas(3) q(1) lgqr have k1n: "k + 1 < psize p"
wenzelm@56778
   890
        by simp
huffman@30488
   891
      have th01: "\<not> constant (poly (pCons 1 (monom a (k - 1))))"
wenzelm@32960
   892
        unfolding constant_def poly_pCons poly_monom
wenzelm@56795
   893
        using kas(1)
wenzelm@56795
   894
        apply simp
wenzelm@56778
   895
        apply (rule exI[where x=0])
wenzelm@56778
   896
        apply (rule exI[where x=1])
wenzelm@56778
   897
        apply simp
wenzelm@56778
   898
        done
wenzelm@56778
   899
      from kas(1) kas(2) have th02: "k + 1 = psize (pCons 1 (monom a (k - 1)))"
wenzelm@32960
   900
        by (simp add: psize_def degree_monom_eq)
berghofe@34915
   901
      from less(1) [OF k1n [simplified th02] th01]
chaieb@26123
   902
      obtain w where w: "1 + w^k * a = 0"
wenzelm@32960
   903
        unfolding poly_pCons poly_monom
wenzelm@56778
   904
        using kas(2) by (cases k) (auto simp add: algebra_simps)
huffman@30488
   905
      from poly_bound_exists[of "cmod w" s] obtain m where
wenzelm@32960
   906
        m: "m > 0" "\<forall>z. cmod z \<le> cmod w \<longrightarrow> cmod (poly s z) \<le> m" by blast
wenzelm@56795
   907
      have w0: "w \<noteq> 0"
wenzelm@56795
   908
        using kas(2) w by (auto simp add: power_0_left)
wenzelm@56778
   909
      from w have "(1 + w ^ k * a) - 1 = 0 - 1"
wenzelm@56778
   910
        by simp
wenzelm@56778
   911
      then have wm1: "w^k * a = - 1"
wenzelm@56778
   912
        by simp
huffman@30488
   913
      have inv0: "0 < inverse (cmod w ^ (k + 1) * m)"
wenzelm@32960
   914
        using norm_ge_zero[of w] w0 m(1)
wenzelm@56778
   915
        by (simp add: inverse_eq_divide zero_less_mult_iff)
lp15@55358
   916
      with real_lbound_gt_zero[OF zero_less_one] obtain t where
wenzelm@32960
   917
        t: "t > 0" "t < 1" "t < inverse (cmod w ^ (k + 1) * m)" by blast
chaieb@26123
   918
      let ?ct = "complex_of_real t"
chaieb@26123
   919
      let ?w = "?ct * w"
wenzelm@56778
   920
      have "1 + ?w^k * (a + ?w * poly s ?w) = 1 + ?ct^k * (w^k * a) + ?w^k * ?w * poly s ?w"
wenzelm@56778
   921
        using kas(1) by (simp add: algebra_simps power_mult_distrib)
chaieb@26123
   922
      also have "\<dots> = complex_of_real (1 - t^k) + ?w^k * ?w * poly s ?w"
wenzelm@56778
   923
        unfolding wm1 by simp
wenzelm@56778
   924
      finally have "cmod (1 + ?w^k * (a + ?w * poly s ?w)) =
wenzelm@56778
   925
        cmod (complex_of_real (1 - t^k) + ?w^k * ?w * poly s ?w)"
lp15@55358
   926
        by metis
huffman@30488
   927
      with norm_triangle_ineq[of "complex_of_real (1 - t^k)" "?w^k * ?w * poly s ?w"]
wenzelm@56778
   928
      have th11: "cmod (1 + ?w^k * (a + ?w * poly s ?w)) \<le> \<bar>1 - t^k\<bar> + cmod (?w^k * ?w * poly s ?w)"
wenzelm@56778
   929
        unfolding norm_of_real by simp
wenzelm@56778
   930
      have ath: "\<And>x t::real. 0 \<le> x \<Longrightarrow> x < t \<Longrightarrow> t \<le> 1 \<Longrightarrow> \<bar>1 - t\<bar> + x < 1"
wenzelm@56778
   931
        by arith
wenzelm@56778
   932
      have "t * cmod w \<le> 1 * cmod w"
wenzelm@56778
   933
        apply (rule mult_mono)
wenzelm@56778
   934
        using t(1,2)
wenzelm@56778
   935
        apply auto
wenzelm@56778
   936
        done
wenzelm@56778
   937
      then have tw: "cmod ?w \<le> cmod w"
wenzelm@56778
   938
        using t(1) by (simp add: norm_mult)
wenzelm@56778
   939
      from t inv0 have "t * (cmod w ^ (k + 1) * m) < 1"
wenzelm@32960
   940
        by (simp add: inverse_eq_divide field_simps)
wenzelm@56778
   941
      with zero_less_power[OF t(1), of k] have th30: "t^k * (t* (cmod w ^ (k + 1) * m)) < t^k * 1"
lp15@55358
   942
        by (metis comm_mult_strict_left_mono)
wenzelm@56778
   943
      have "cmod (?w^k * ?w * poly s ?w) = t^k * (t* (cmod w ^ (k + 1) * cmod (poly s ?w)))"
wenzelm@56778
   944
        using w0 t(1)
wenzelm@51541
   945
        by (simp add: algebra_simps power_mult_distrib norm_power norm_mult)
chaieb@26123
   946
      then have "cmod (?w^k * ?w * poly s ?w) \<le> t^k * (t* (cmod w ^ (k + 1) * m))"
wenzelm@32960
   947
        using t(1,2) m(2)[rule_format, OF tw] w0
lp15@55358
   948
        by auto
wenzelm@56778
   949
      with th30 have th120: "cmod (?w^k * ?w * poly s ?w) < t^k"
wenzelm@56778
   950
        by simp
huffman@30488
   951
      from power_strict_mono[OF t(2), of k] t(1) kas(2) have th121: "t^k \<le> 1"
wenzelm@32960
   952
        by auto
huffman@27514
   953
      from ath[OF norm_ge_zero[of "?w^k * ?w * poly s ?w"] th120 th121]
huffman@30488
   954
      have th12: "\<bar>1 - t^k\<bar> + cmod (?w^k * ?w * poly s ?w) < 1" .
wenzelm@56778
   955
      from th11 th12 have "cmod (1 + ?w^k * (a + ?w * poly s ?w)) < 1"
wenzelm@56778
   956
        by arith
huffman@30488
   957
      then have "cmod (poly ?r ?w) < 1"
wenzelm@32960
   958
        unfolding kas(4)[rule_format, of ?w] r01 by simp
wenzelm@56778
   959
      then have "\<exists>w. cmod (poly ?r w) < 1"
wenzelm@56778
   960
        by blast
wenzelm@56778
   961
    }
wenzelm@56778
   962
    ultimately have cr0_contr: "\<exists>w. cmod (poly ?r w) < 1"
wenzelm@56778
   963
      by blast
wenzelm@56778
   964
    from cr0_contr cq0 q(2) show ?thesis
wenzelm@56778
   965
      unfolding mrmq_eq not_less[symmetric] by auto
wenzelm@56778
   966
  qed
chaieb@26123
   967
qed
chaieb@26123
   968
chaieb@26123
   969
text {* Alternative version with a syntactic notion of constant polynomial. *}
chaieb@26123
   970
chaieb@26123
   971
lemma fundamental_theorem_of_algebra_alt:
wenzelm@56778
   972
  assumes nc: "\<not> (\<exists>a l. a \<noteq> 0 \<and> l = 0 \<and> p = pCons a l)"
chaieb@26123
   973
  shows "\<exists>z. poly p z = (0::complex)"
wenzelm@56778
   974
  using nc
wenzelm@56778
   975
proof (induct p)
wenzelm@56778
   976
  case 0
wenzelm@56778
   977
  then show ?case by simp
wenzelm@56778
   978
next
huffman@29464
   979
  case (pCons c cs)
wenzelm@56778
   980
  show ?case
wenzelm@56778
   981
  proof (cases "c = 0")
wenzelm@56778
   982
    case True
wenzelm@56778
   983
    then show ?thesis by auto
wenzelm@56778
   984
  next
wenzelm@56778
   985
    case False
wenzelm@56778
   986
    {
wenzelm@56778
   987
      assume nc: "constant (poly (pCons c cs))"
huffman@30488
   988
      from nc[unfolded constant_def, rule_format, of 0]
huffman@30488
   989
      have "\<forall>w. w \<noteq> 0 \<longrightarrow> poly cs w = 0" by auto
wenzelm@56778
   990
      then have "cs = 0"
wenzelm@56778
   991
      proof (induct cs)
wenzelm@56778
   992
        case 0
wenzelm@56778
   993
        then show ?case by simp
wenzelm@56778
   994
      next
wenzelm@56778
   995
        case (pCons d ds)
wenzelm@56778
   996
        show ?case
wenzelm@56778
   997
        proof (cases "d = 0")
wenzelm@56778
   998
          case True
wenzelm@56778
   999
          then show ?thesis using pCons.prems pCons.hyps by simp
wenzelm@56778
  1000
        next
wenzelm@56778
  1001
          case False
wenzelm@56778
  1002
          from poly_bound_exists[of 1 ds] obtain m where
wenzelm@56778
  1003
            m: "m > 0" "\<forall>z. \<forall>z. cmod z \<le> 1 \<longrightarrow> cmod (poly ds z) \<le> m" by blast
wenzelm@56795
  1004
          have dm: "cmod d / m > 0"
wenzelm@56795
  1005
            using False m(1) by (simp add: field_simps)
wenzelm@56778
  1006
          from real_lbound_gt_zero[OF dm zero_less_one] obtain x where
wenzelm@56778
  1007
            x: "x > 0" "x < cmod d / m" "x < 1" by blast
wenzelm@56778
  1008
          let ?x = "complex_of_real x"
wenzelm@56795
  1009
          from x have cx: "?x \<noteq> 0"  "cmod ?x \<le> 1"
wenzelm@56795
  1010
            by simp_all
wenzelm@56778
  1011
          from pCons.prems[rule_format, OF cx(1)]
wenzelm@56795
  1012
          have cth: "cmod (?x*poly ds ?x) = cmod d"
wenzelm@56795
  1013
            by (simp add: eq_diff_eq[symmetric])
wenzelm@56778
  1014
          from m(2)[rule_format, OF cx(2)] x(1)
wenzelm@56778
  1015
          have th0: "cmod (?x*poly ds ?x) \<le> x*m"
wenzelm@56778
  1016
            by (simp add: norm_mult)
wenzelm@56795
  1017
          from x(2) m(1) have "x * m < cmod d"
wenzelm@56795
  1018
            by (simp add: field_simps)
wenzelm@56795
  1019
          with th0 have "cmod (?x*poly ds ?x) \<noteq> cmod d"
wenzelm@56795
  1020
            by auto
wenzelm@56795
  1021
          with cth show ?thesis
wenzelm@56795
  1022
            by blast
wenzelm@56778
  1023
        qed
wenzelm@56778
  1024
      qed
wenzelm@56778
  1025
    }
wenzelm@56795
  1026
    then have nc: "\<not> constant (poly (pCons c cs))"
wenzelm@56795
  1027
      using pCons.prems False by blast
wenzelm@56778
  1028
    from fundamental_theorem_of_algebra[OF nc] show ?thesis .
wenzelm@56778
  1029
  qed
wenzelm@56778
  1030
qed
chaieb@26123
  1031
huffman@29464
  1032
webertj@37093
  1033
subsection{* Nullstellensatz, degrees and divisibility of polynomials *}
chaieb@26123
  1034
chaieb@26123
  1035
lemma nullstellensatz_lemma:
huffman@29464
  1036
  fixes p :: "complex poly"
chaieb@26123
  1037
  assumes "\<forall>x. poly p x = 0 \<longrightarrow> poly q x = 0"
wenzelm@56776
  1038
    and "degree p = n"
wenzelm@56776
  1039
    and "n \<noteq> 0"
huffman@29464
  1040
  shows "p dvd (q ^ n)"
wenzelm@56776
  1041
  using assms
wenzelm@56776
  1042
proof (induct n arbitrary: p q rule: nat_less_induct)
wenzelm@56776
  1043
  fix n :: nat
wenzelm@56776
  1044
  fix p q :: "complex poly"
chaieb@26123
  1045
  assume IH: "\<forall>m<n. \<forall>p q.
chaieb@26123
  1046
                 (\<forall>x. poly p x = (0::complex) \<longrightarrow> poly q x = 0) \<longrightarrow>
huffman@29464
  1047
                 degree p = m \<longrightarrow> m \<noteq> 0 \<longrightarrow> p dvd (q ^ m)"
huffman@30488
  1048
    and pq0: "\<forall>x. poly p x = 0 \<longrightarrow> poly q x = 0"
wenzelm@56778
  1049
    and dpn: "degree p = n"
wenzelm@56778
  1050
    and n0: "n \<noteq> 0"
huffman@29464
  1051
  from dpn n0 have pne: "p \<noteq> 0" by auto
huffman@29464
  1052
  let ?ths = "p dvd (q ^ n)"
wenzelm@56778
  1053
  {
wenzelm@56778
  1054
    fix a
wenzelm@56778
  1055
    assume a: "poly p a = 0"
wenzelm@56778
  1056
    {
wenzelm@56778
  1057
      assume oa: "order a p \<noteq> 0"
chaieb@26123
  1058
      let ?op = "order a p"
wenzelm@56778
  1059
      from pne have ap: "([:- a, 1:] ^ ?op) dvd p" "\<not> [:- a, 1:] ^ (Suc ?op) dvd p"
wenzelm@56778
  1060
        using order by blast+
huffman@29464
  1061
      note oop = order_degree[OF pne, unfolded dpn]
wenzelm@56778
  1062
      {
wenzelm@56778
  1063
        assume q0: "q = 0"
wenzelm@56778
  1064
        then have ?ths using n0
wenzelm@56778
  1065
          by (simp add: power_0_left)
wenzelm@56778
  1066
      }
chaieb@26123
  1067
      moreover
wenzelm@56778
  1068
      {
wenzelm@56778
  1069
        assume q0: "q \<noteq> 0"
wenzelm@32960
  1070
        from pq0[rule_format, OF a, unfolded poly_eq_0_iff_dvd]
wenzelm@32960
  1071
        obtain r where r: "q = [:- a, 1:] * r" by (rule dvdE)
wenzelm@56778
  1072
        from ap(1) obtain s where s: "p = [:- a, 1:] ^ ?op * s"
wenzelm@56778
  1073
          by (rule dvdE)
wenzelm@56778
  1074
        have sne: "s \<noteq> 0" using s pne by auto
wenzelm@56778
  1075
        {
wenzelm@56778
  1076
          assume ds0: "degree s = 0"
wenzelm@51541
  1077
          from ds0 obtain k where kpn: "s = [:k:]"
wenzelm@51541
  1078
            by (cases s) (auto split: if_splits)
huffman@29464
  1079
          from sne kpn have k: "k \<noteq> 0" by simp
wenzelm@32960
  1080
          let ?w = "([:1/k:] * ([:-a,1:] ^ (n - ?op))) * (r ^ n)"
lp15@55358
  1081
          have "q ^ n = p * ?w"
wenzelm@56795
  1082
            apply (subst r)
wenzelm@56795
  1083
            apply (subst s)
wenzelm@56795
  1084
            apply (subst kpn)
wenzelm@56778
  1085
            using k oop [of a]
wenzelm@56795
  1086
            apply (subst power_mult_distrib)
wenzelm@56795
  1087
            apply simp
wenzelm@56795
  1088
            apply (subst power_add [symmetric])
wenzelm@56795
  1089
            apply simp
huffman@29464
  1090
            done
wenzelm@56795
  1091
          then have ?ths
wenzelm@56795
  1092
            unfolding dvd_def by blast
wenzelm@56778
  1093
        }
wenzelm@32960
  1094
        moreover
wenzelm@56778
  1095
        {
wenzelm@56778
  1096
          assume ds0: "degree s \<noteq> 0"
wenzelm@32960
  1097
          from ds0 sne dpn s oa
wenzelm@56778
  1098
            have dsn: "degree s < n"
wenzelm@56778
  1099
              apply auto
huffman@29464
  1100
              apply (erule ssubst)
huffman@29464
  1101
              apply (simp add: degree_mult_eq degree_linear_power)
huffman@29464
  1102
              done
wenzelm@56778
  1103
            {
wenzelm@56778
  1104
              fix x assume h: "poly s x = 0"
wenzelm@56778
  1105
              {
wenzelm@56778
  1106
                assume xa: "x = a"
wenzelm@56778
  1107
                from h[unfolded xa poly_eq_0_iff_dvd] obtain u where u: "s = [:- a, 1:] * u"
wenzelm@56778
  1108
                  by (rule dvdE)
wenzelm@32960
  1109
                have "p = [:- a, 1:] ^ (Suc ?op) * u"
wenzelm@56795
  1110
                  apply (subst s)
wenzelm@56795
  1111
                  apply (subst u)
wenzelm@56795
  1112
                  apply (simp only: power_Suc mult_ac)
wenzelm@56795
  1113
                  done
wenzelm@56795
  1114
                with ap(2)[unfolded dvd_def] have False
wenzelm@56795
  1115
                  by blast
wenzelm@56778
  1116
              }
wenzelm@32960
  1117
              note xa = this
wenzelm@56795
  1118
              from h have "poly p x = 0"
wenzelm@56795
  1119
                by (subst s) simp
wenzelm@56795
  1120
              with pq0 have "poly q x = 0"
wenzelm@56795
  1121
                by blast
wenzelm@32960
  1122
              with r xa have "poly r x = 0"
wenzelm@56778
  1123
                by auto
wenzelm@56778
  1124
            }
wenzelm@32960
  1125
            note impth = this
wenzelm@32960
  1126
            from IH[rule_format, OF dsn, of s r] impth ds0
wenzelm@56795
  1127
            have "s dvd (r ^ (degree s))"
wenzelm@56795
  1128
              by blast
wenzelm@32960
  1129
            then obtain u where u: "r ^ (degree s) = s * u" ..
wenzelm@56778
  1130
            then have u': "\<And>x. poly s x * poly u x = poly r x ^ degree s"
huffman@29470
  1131
              by (simp only: poly_mult[symmetric] poly_power[symmetric])
wenzelm@32960
  1132
            let ?w = "(u * ([:-a,1:] ^ (n - ?op))) * (r ^ (n - degree s))"
wenzelm@32960
  1133
            from oop[of a] dsn have "q ^ n = p * ?w"
huffman@29464
  1134
              apply -
wenzelm@56795
  1135
              apply (subst s)
wenzelm@56795
  1136
              apply (subst r)
huffman@29464
  1137
              apply (simp only: power_mult_distrib)
huffman@29464
  1138
              apply (subst mult_assoc [where b=s])
huffman@29464
  1139
              apply (subst mult_assoc [where a=u])
huffman@29464
  1140
              apply (subst mult_assoc [where b=u, symmetric])
huffman@29464
  1141
              apply (subst u [symmetric])
huffman@29464
  1142
              apply (simp add: mult_ac power_add [symmetric])
huffman@29464
  1143
              done
wenzelm@56795
  1144
            then have ?ths
wenzelm@56795
  1145
              unfolding dvd_def by blast
wenzelm@56778
  1146
        }
wenzelm@56778
  1147
        ultimately have ?ths by blast
wenzelm@56778
  1148
      }
wenzelm@56778
  1149
      ultimately have ?ths by blast
wenzelm@56778
  1150
    }
wenzelm@56778
  1151
    then have ?ths using a order_root pne by blast
wenzelm@56778
  1152
  }
chaieb@26123
  1153
  moreover
wenzelm@56778
  1154
  {
wenzelm@56778
  1155
    assume exa: "\<not> (\<exists>a. poly p a = 0)"
wenzelm@56778
  1156
    from fundamental_theorem_of_algebra_alt[of p] exa
wenzelm@56778
  1157
    obtain c where ccs: "c \<noteq> 0" "p = pCons c 0"
wenzelm@56778
  1158
      by blast
wenzelm@56778
  1159
    then have pp: "\<And>x. poly p x = c"
wenzelm@56778
  1160
      by simp
huffman@29464
  1161
    let ?w = "[:1/c:] * (q ^ n)"
wenzelm@56778
  1162
    from ccs have "(q ^ n) = (p * ?w)"
wenzelm@56778
  1163
      by simp
wenzelm@56778
  1164
    then have ?ths
wenzelm@56778
  1165
      unfolding dvd_def by blast
wenzelm@56778
  1166
  }
chaieb@26123
  1167
  ultimately show ?ths by blast
chaieb@26123
  1168
qed
chaieb@26123
  1169
chaieb@26123
  1170
lemma nullstellensatz_univariate:
huffman@30488
  1171
  "(\<forall>x. poly p x = (0::complex) \<longrightarrow> poly q x = 0) \<longleftrightarrow>
huffman@29464
  1172
    p dvd (q ^ (degree p)) \<or> (p = 0 \<and> q = 0)"
wenzelm@56776
  1173
proof -
wenzelm@56778
  1174
  {
wenzelm@56778
  1175
    assume pe: "p = 0"
wenzelm@56778
  1176
    then have eq: "(\<forall>x. poly p x = (0::complex) \<longrightarrow> poly q x = 0) \<longleftrightarrow> q = 0"
haftmann@52380
  1177
      by (auto simp add: poly_all_0_iff_0)
wenzelm@56778
  1178
    {
wenzelm@56778
  1179
      assume "p dvd (q ^ (degree p))"
huffman@29464
  1180
      then obtain r where r: "q ^ (degree p) = p * r" ..
wenzelm@56778
  1181
      from r pe have False by simp
wenzelm@56778
  1182
    }
wenzelm@56778
  1183
    with eq pe have ?thesis by blast
wenzelm@56778
  1184
  }
chaieb@26123
  1185
  moreover
wenzelm@56778
  1186
  {
wenzelm@56778
  1187
    assume pe: "p \<noteq> 0"
wenzelm@56778
  1188
    {
wenzelm@56778
  1189
      assume dp: "degree p = 0"
wenzelm@56778
  1190
      then obtain k where k: "p = [:k:]" "k \<noteq> 0" using pe
wenzelm@51541
  1191
        by (cases p) (simp split: if_splits)
wenzelm@56778
  1192
      then have th1: "\<forall>x. poly p x \<noteq> 0"
wenzelm@56778
  1193
        by simp
huffman@29464
  1194
      from k dp have "q ^ (degree p) = p * [:1/k:]"
huffman@29464
  1195
        by (simp add: one_poly_def)
wenzelm@56778
  1196
      then have th2: "p dvd (q ^ (degree p))" ..
wenzelm@56795
  1197
      from th1 th2 pe have ?thesis
wenzelm@56795
  1198
        by blast
wenzelm@56778
  1199
    }
chaieb@26123
  1200
    moreover
wenzelm@56778
  1201
    {
wenzelm@56778
  1202
      assume dp: "degree p \<noteq> 0"
wenzelm@56778
  1203
      then obtain n where n: "degree p = Suc n "
wenzelm@56778
  1204
        by (cases "degree p") auto
wenzelm@56778
  1205
      {
wenzelm@56778
  1206
        assume "p dvd (q ^ (Suc n))"
wenzelm@32960
  1207
        then obtain u where u: "q ^ (Suc n) = p * u" ..
wenzelm@56778
  1208
        {
wenzelm@56778
  1209
          fix x
wenzelm@56778
  1210
          assume h: "poly p x = 0" "poly q x \<noteq> 0"
wenzelm@56778
  1211
          then have "poly (q ^ (Suc n)) x \<noteq> 0"
wenzelm@56778
  1212
            by simp
wenzelm@56778
  1213
          then have False using u h(1)
wenzelm@56778
  1214
            by (simp only: poly_mult) simp
wenzelm@56778
  1215
        }
wenzelm@56778
  1216
      }
wenzelm@56778
  1217
      with n nullstellensatz_lemma[of p q "degree p"] dp
wenzelm@56778
  1218
      have ?thesis by auto
wenzelm@56778
  1219
    }
wenzelm@56778
  1220
    ultimately have ?thesis by blast
wenzelm@56778
  1221
  }
chaieb@26123
  1222
  ultimately show ?thesis by blast
chaieb@26123
  1223
qed
chaieb@26123
  1224
wenzelm@56795
  1225
text {* Useful lemma *}
chaieb@26123
  1226
huffman@29464
  1227
lemma constant_degree:
huffman@29464
  1228
  fixes p :: "'a::{idom,ring_char_0} poly"
huffman@29464
  1229
  shows "constant (poly p) \<longleftrightarrow> degree p = 0" (is "?lhs = ?rhs")
chaieb@26123
  1230
proof
chaieb@26123
  1231
  assume l: ?lhs
huffman@29464
  1232
  from l[unfolded constant_def, rule_format, of _ "0"]
wenzelm@56776
  1233
  have th: "poly p = poly [:poly p 0:]"
wenzelm@56776
  1234
    by auto
wenzelm@56776
  1235
  then have "p = [:poly p 0:]"
wenzelm@56776
  1236
    by (simp add: poly_eq_poly_eq_iff)
wenzelm@56776
  1237
  then have "degree p = degree [:poly p 0:]"
wenzelm@56776
  1238
    by simp
wenzelm@56776
  1239
  then show ?rhs
wenzelm@56776
  1240
    by simp
chaieb@26123
  1241
next
chaieb@26123
  1242
  assume r: ?rhs
huffman@29464
  1243
  then obtain k where "p = [:k:]"
wenzelm@51541
  1244
    by (cases p) (simp split: if_splits)
wenzelm@56776
  1245
  then show ?lhs
wenzelm@56776
  1246
    unfolding constant_def by auto
chaieb@26123
  1247
qed
chaieb@26123
  1248
wenzelm@56776
  1249
lemma divides_degree:
wenzelm@56776
  1250
  assumes pq: "p dvd (q:: complex poly)"
huffman@29464
  1251
  shows "degree p \<le> degree q \<or> q = 0"
wenzelm@56776
  1252
  by (metis dvd_imp_degree_le pq)
chaieb@26123
  1253
wenzelm@56795
  1254
text {* Arithmetic operations on multivariate polynomials. *}
chaieb@26123
  1255
huffman@30488
  1256
lemma mpoly_base_conv:
wenzelm@56778
  1257
  fixes x :: "'a::comm_ring_1"
lp15@55735
  1258
  shows "0 = poly 0 x" "c = poly [:c:] x" "x = poly [:0,1:] x"
lp15@55735
  1259
  by simp_all
chaieb@26123
  1260
huffman@30488
  1261
lemma mpoly_norm_conv:
wenzelm@56778
  1262
  fixes x :: "'a::comm_ring_1"
wenzelm@56776
  1263
  shows "poly [:0:] x = poly 0 x" "poly [:poly 0 y:] x = poly 0 x"
wenzelm@56776
  1264
  by simp_all
chaieb@26123
  1265
huffman@30488
  1266
lemma mpoly_sub_conv:
wenzelm@56778
  1267
  fixes x :: "'a::comm_ring_1"
lp15@55735
  1268
  shows "poly p x - poly q x = poly p x + -1 * poly q x"
haftmann@54230
  1269
  by simp
chaieb@26123
  1270
wenzelm@56778
  1271
lemma poly_pad_rule: "poly p x = 0 \<Longrightarrow> poly (pCons 0 p) x = 0"
wenzelm@56778
  1272
  by simp
chaieb@26123
  1273
lp15@55735
  1274
lemma poly_cancel_eq_conv:
wenzelm@56778
  1275
  fixes x :: "'a::field"
wenzelm@56795
  1276
  shows "x = 0 \<Longrightarrow> a \<noteq> 0 \<Longrightarrow> y = 0 \<longleftrightarrow> a * y - b * x = 0"
lp15@55735
  1277
  by auto
chaieb@26123
  1278
huffman@30488
  1279
lemma poly_divides_pad_rule:
wenzelm@56778
  1280
  fixes p:: "('a::comm_ring_1) poly"
huffman@29464
  1281
  assumes pq: "p dvd q"
wenzelm@56778
  1282
  shows "p dvd (pCons 0 q)"
wenzelm@56778
  1283
proof -
huffman@29464
  1284
  have "pCons 0 q = q * [:0,1:]" by simp
huffman@29464
  1285
  then have "q dvd (pCons 0 q)" ..
huffman@29464
  1286
  with pq show ?thesis by (rule dvd_trans)
chaieb@26123
  1287
qed
chaieb@26123
  1288
huffman@30488
  1289
lemma poly_divides_conv0:
wenzelm@56778
  1290
  fixes p:: "'a::field poly"
wenzelm@56776
  1291
  assumes lgpq: "degree q < degree p"
wenzelm@56776
  1292
    and lq: "p \<noteq> 0"
wenzelm@56776
  1293
  shows "p dvd q \<longleftrightarrow> q = 0" (is "?lhs \<longleftrightarrow> ?rhs")
wenzelm@56776
  1294
proof
wenzelm@56776
  1295
  assume r: ?rhs
wenzelm@56776
  1296
  then have "q = p * 0" by simp
wenzelm@56776
  1297
  then show ?lhs ..
wenzelm@56776
  1298
next
wenzelm@56776
  1299
  assume l: ?lhs
wenzelm@56778
  1300
  show ?rhs
wenzelm@56778
  1301
  proof (cases "q = 0")
wenzelm@56778
  1302
    case True
wenzelm@56778
  1303
    then show ?thesis by simp
wenzelm@56778
  1304
  next
wenzelm@56776
  1305
    assume q0: "q \<noteq> 0"
wenzelm@56776
  1306
    from l q0 have "degree p \<le> degree q"
wenzelm@56776
  1307
      by (rule dvd_imp_degree_le)
wenzelm@56778
  1308
    with lgpq show ?thesis by simp
wenzelm@56778
  1309
  qed
chaieb@26123
  1310
qed
chaieb@26123
  1311
huffman@30488
  1312
lemma poly_divides_conv1:
wenzelm@56778
  1313
  fixes p :: "'a::field poly"
wenzelm@56776
  1314
  assumes a0: "a \<noteq> 0"
wenzelm@56776
  1315
    and pp': "p dvd p'"
wenzelm@56776
  1316
    and qrp': "smult a q - p' = r"
wenzelm@56776
  1317
  shows "p dvd q \<longleftrightarrow> p dvd r" (is "?lhs \<longleftrightarrow> ?rhs")
wenzelm@56776
  1318
proof
huffman@29464
  1319
  from pp' obtain t where t: "p' = p * t" ..
wenzelm@56776
  1320
  {
wenzelm@56776
  1321
    assume l: ?lhs
huffman@29464
  1322
    then obtain u where u: "q = p * u" ..
wenzelm@56776
  1323
    have "r = p * (smult a u - t)"
wenzelm@56776
  1324
      using u qrp' [symmetric] t by (simp add: algebra_simps)
wenzelm@56776
  1325
    then show ?rhs ..
wenzelm@56776
  1326
  next
wenzelm@56776
  1327
    assume r: ?rhs
huffman@29464
  1328
    then obtain u where u: "r = p * u" ..
huffman@29464
  1329
    from u [symmetric] t qrp' [symmetric] a0
wenzelm@51541
  1330
    have "q = p * smult (1/a) (u + t)" by (simp add: algebra_simps)
wenzelm@56776
  1331
    then show ?lhs ..
wenzelm@56776
  1332
  }
chaieb@26123
  1333
qed
chaieb@26123
  1334
chaieb@26123
  1335
lemma basic_cqe_conv1:
lp15@55358
  1336
  "(\<exists>x. poly p x = 0 \<and> poly 0 x \<noteq> 0) \<longleftrightarrow> False"
lp15@55358
  1337
  "(\<exists>x. poly 0 x \<noteq> 0) \<longleftrightarrow> False"
wenzelm@56776
  1338
  "(\<exists>x. poly [:c:] x \<noteq> 0) \<longleftrightarrow> c \<noteq> 0"
lp15@55358
  1339
  "(\<exists>x. poly 0 x = 0) \<longleftrightarrow> True"
wenzelm@56776
  1340
  "(\<exists>x. poly [:c:] x = 0) \<longleftrightarrow> c = 0"
wenzelm@56776
  1341
  by simp_all
chaieb@26123
  1342
huffman@30488
  1343
lemma basic_cqe_conv2:
wenzelm@56795
  1344
  assumes l: "p \<noteq> 0"
wenzelm@56795
  1345
  shows "\<exists>x. poly (pCons a (pCons b p)) x = (0::complex)"
wenzelm@56776
  1346
proof -
wenzelm@56776
  1347
  {
wenzelm@56776
  1348
    fix h t
wenzelm@56776
  1349
    assume h: "h \<noteq> 0" "t = 0" and "pCons a (pCons b p) = pCons h t"
wenzelm@56776
  1350
    with l have False by simp
wenzelm@56776
  1351
  }
wenzelm@56776
  1352
  then have th: "\<not> (\<exists> h t. h \<noteq> 0 \<and> t = 0 \<and> pCons a (pCons b p) = pCons h t)"
chaieb@26123
  1353
    by blast
wenzelm@56776
  1354
  from fundamental_theorem_of_algebra_alt[OF th] show ?thesis
wenzelm@56776
  1355
    by auto
chaieb@26123
  1356
qed
chaieb@26123
  1357
wenzelm@56776
  1358
lemma  basic_cqe_conv_2b: "(\<exists>x. poly p x \<noteq> (0::complex)) \<longleftrightarrow> p \<noteq> 0"
wenzelm@56776
  1359
  by (metis poly_all_0_iff_0)
chaieb@26123
  1360
chaieb@26123
  1361
lemma basic_cqe_conv3:
huffman@29464
  1362
  fixes p q :: "complex poly"
huffman@30488
  1363
  assumes l: "p \<noteq> 0"
wenzelm@56795
  1364
  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
  1365
proof -
wenzelm@56776
  1366
  from l have dp: "degree (pCons a p) = psize p"
wenzelm@56776
  1367
    by (simp add: psize_def)
huffman@29464
  1368
  from nullstellensatz_univariate[of "pCons a p" q] l
lp15@55358
  1369
  show ?thesis
lp15@55358
  1370
    by (metis dp pCons_eq_0_iff)
chaieb@26123
  1371
qed
chaieb@26123
  1372
chaieb@26123
  1373
lemma basic_cqe_conv4:
huffman@29464
  1374
  fixes p q :: "complex poly"
lp15@55358
  1375
  assumes h: "\<And>x. poly (q ^ n) x = poly r x"
lp15@55358
  1376
  shows "p dvd (q ^ n) \<longleftrightarrow> p dvd r"
wenzelm@56776
  1377
proof -
wenzelm@56776
  1378
  from h have "poly (q ^ n) = poly r"
wenzelm@56776
  1379
    by auto
wenzelm@56776
  1380
  then have "(q ^ n) = r"
wenzelm@56776
  1381
    by (simp add: poly_eq_poly_eq_iff)
wenzelm@56776
  1382
  then show "p dvd (q ^ n) \<longleftrightarrow> p dvd r"
wenzelm@56776
  1383
    by simp
chaieb@26123
  1384
qed
chaieb@26123
  1385
lp15@55735
  1386
lemma poly_const_conv:
wenzelm@56778
  1387
  fixes x :: "'a::comm_ring_1"
wenzelm@56776
  1388
  shows "poly [:c:] x = y \<longleftrightarrow> c = y"
wenzelm@56776
  1389
  by simp
chaieb@26123
  1390
huffman@29464
  1391
end