src/HOL/Computational_Algebra/Fundamental_Theorem_Algebra.thy
author wenzelm
Mon, 11 Sep 2023 19:30:48 +0200
changeset 78659 b5f3d1051b13
parent 77341 127a51771f34
child 80061 4c1347e172b1
permissions -rw-r--r--
tuned;
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
65435
378175f44328 tuned headers;
wenzelm
parents: 65417
diff changeset
     1
(*  Title:      HOL/Computational_Algebra/Fundamental_Theorem_Algebra.thy
378175f44328 tuned headers;
wenzelm
parents: 65417
diff changeset
     2
    Author:     Amine Chaieb, TU Muenchen
378175f44328 tuned headers;
wenzelm
parents: 65417
diff changeset
     3
*)
26123
44384b5c4fc0 A proof a the fundamental theorem of algebra
chaieb
parents:
diff changeset
     4
60424
c96fff9dcdbc misc tuning;
wenzelm
parents: 59557
diff changeset
     5
section \<open>Fundamental Theorem of Algebra\<close>
26123
44384b5c4fc0 A proof a the fundamental theorem of algebra
chaieb
parents:
diff changeset
     6
44384b5c4fc0 A proof a the fundamental theorem of algebra
chaieb
parents:
diff changeset
     7
theory Fundamental_Theorem_Algebra
51537
abcd6d5f7508 more standard imports;
wenzelm
parents: 50636
diff changeset
     8
imports Polynomial Complex_Main
26123
44384b5c4fc0 A proof a the fundamental theorem of algebra
chaieb
parents:
diff changeset
     9
begin
44384b5c4fc0 A proof a the fundamental theorem of algebra
chaieb
parents:
diff changeset
    10
60424
c96fff9dcdbc misc tuning;
wenzelm
parents: 59557
diff changeset
    11
subsection \<open>More lemmas about module of complex numbers\<close>
26123
44384b5c4fc0 A proof a the fundamental theorem of algebra
chaieb
parents:
diff changeset
    12
60424
c96fff9dcdbc misc tuning;
wenzelm
parents: 59557
diff changeset
    13
text \<open>The triangle inequality for cmod\<close>
c96fff9dcdbc misc tuning;
wenzelm
parents: 59557
diff changeset
    14
26123
44384b5c4fc0 A proof a the fundamental theorem of algebra
chaieb
parents:
diff changeset
    15
lemma complex_mod_triangle_sub: "cmod w \<le> cmod (w + z) + norm z"
77341
127a51771f34 Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 77303
diff changeset
    16
  by (metis add_diff_cancel norm_triangle_ineq4)
26123
44384b5c4fc0 A proof a the fundamental theorem of algebra
chaieb
parents:
diff changeset
    17
60424
c96fff9dcdbc misc tuning;
wenzelm
parents: 59557
diff changeset
    18
c96fff9dcdbc misc tuning;
wenzelm
parents: 59557
diff changeset
    19
subsection \<open>Basic lemmas about polynomials\<close>
26123
44384b5c4fc0 A proof a the fundamental theorem of algebra
chaieb
parents:
diff changeset
    20
44384b5c4fc0 A proof a the fundamental theorem of algebra
chaieb
parents:
diff changeset
    21
lemma poly_bound_exists:
56778
cb0929421ca6 tuned proofs;
wenzelm
parents: 56776
diff changeset
    22
  fixes p :: "'a::{comm_semiring_0,real_normed_div_algebra} poly"
cb0929421ca6 tuned proofs;
wenzelm
parents: 56776
diff changeset
    23
  shows "\<exists>m. m > 0 \<and> (\<forall>z. norm z \<le> r \<longrightarrow> norm (poly p z) \<le> m)"
cb0929421ca6 tuned proofs;
wenzelm
parents: 56776
diff changeset
    24
proof (induct p)
cb0929421ca6 tuned proofs;
wenzelm
parents: 56776
diff changeset
    25
  case 0
cb0929421ca6 tuned proofs;
wenzelm
parents: 56776
diff changeset
    26
  then show ?case by (rule exI[where x=1]) simp
26123
44384b5c4fc0 A proof a the fundamental theorem of algebra
chaieb
parents:
diff changeset
    27
next
29464
c0d225a7f6ff convert Fundamental_Theorem_Algebra.thy to use new Polynomial library
huffman
parents: 29292
diff changeset
    28
  case (pCons c cs)
55735
81ba62493610 generalised some results using type classes
paulson <lp15@cam.ac.uk>
parents: 55734
diff changeset
    29
  from pCons.hyps obtain m where m: "\<forall>z. norm z \<le> r \<longrightarrow> norm (poly cs z) \<le> m"
26123
44384b5c4fc0 A proof a the fundamental theorem of algebra
chaieb
parents:
diff changeset
    30
    by blast
55735
81ba62493610 generalised some results using type classes
paulson <lp15@cam.ac.uk>
parents: 55734
diff changeset
    31
  let ?k = " 1 + norm c + \<bar>r * m\<bar>"
56795
e8cce2bd23e5 tuned proofs;
wenzelm
parents: 56778
diff changeset
    32
  have kp: "?k > 0"
e8cce2bd23e5 tuned proofs;
wenzelm
parents: 56778
diff changeset
    33
    using abs_ge_zero[of "r*m"] norm_ge_zero[of c] by arith
60424
c96fff9dcdbc misc tuning;
wenzelm
parents: 59557
diff changeset
    34
  have "norm (poly (pCons c cs) z) \<le> ?k" if H: "norm z \<le> r" for z
c96fff9dcdbc misc tuning;
wenzelm
parents: 59557
diff changeset
    35
  proof -
56778
cb0929421ca6 tuned proofs;
wenzelm
parents: 56776
diff changeset
    36
    from m H have th: "norm (poly cs z) \<le> m"
cb0929421ca6 tuned proofs;
wenzelm
parents: 56776
diff changeset
    37
      by blast
56795
e8cce2bd23e5 tuned proofs;
wenzelm
parents: 56778
diff changeset
    38
    from H have rp: "r \<ge> 0"
e8cce2bd23e5 tuned proofs;
wenzelm
parents: 56778
diff changeset
    39
      using norm_ge_zero[of z] by arith
e8cce2bd23e5 tuned proofs;
wenzelm
parents: 56778
diff changeset
    40
    have "norm (poly (pCons c cs) z) \<le> norm c + norm (z * poly cs z)"
27514
6fcf6864d703 remove redundant lemmas about cmod
huffman
parents: 27445
diff changeset
    41
      using norm_triangle_ineq[of c "z* poly cs z"] by simp
77303
3c4aca1266eb Simplifying more proofs
paulson <lp15@cam.ac.uk>
parents: 77282
diff changeset
    42
    also have "\<dots> \<le> ?k"
56778
cb0929421ca6 tuned proofs;
wenzelm
parents: 56776
diff changeset
    43
      using mult_mono[OF H th rp norm_ge_zero[of "poly cs z"]]
55735
81ba62493610 generalised some results using type classes
paulson <lp15@cam.ac.uk>
parents: 55734
diff changeset
    44
      by (simp add: norm_mult)
60424
c96fff9dcdbc misc tuning;
wenzelm
parents: 59557
diff changeset
    45
    finally show ?thesis .
c96fff9dcdbc misc tuning;
wenzelm
parents: 59557
diff changeset
    46
  qed
26123
44384b5c4fc0 A proof a the fundamental theorem of algebra
chaieb
parents:
diff changeset
    47
  with kp show ?case by blast
44384b5c4fc0 A proof a the fundamental theorem of algebra
chaieb
parents:
diff changeset
    48
qed
44384b5c4fc0 A proof a the fundamental theorem of algebra
chaieb
parents:
diff changeset
    49
44384b5c4fc0 A proof a the fundamental theorem of algebra
chaieb
parents:
diff changeset
    50
60424
c96fff9dcdbc misc tuning;
wenzelm
parents: 59557
diff changeset
    51
text \<open>Offsetting the variable in a polynomial gives another of same degree\<close>
29464
c0d225a7f6ff convert Fundamental_Theorem_Algebra.thy to use new Polynomial library
huffman
parents: 29292
diff changeset
    52
52380
3cc46b8cca5e lifting for primitive definitions;
haftmann
parents: 51541
diff changeset
    53
definition offset_poly :: "'a::comm_semiring_0 poly \<Rightarrow> 'a \<Rightarrow> 'a poly"
56778
cb0929421ca6 tuned proofs;
wenzelm
parents: 56776
diff changeset
    54
  where "offset_poly p h = fold_coeffs (\<lambda>a q. smult h q + pCons a q) p 0"
29464
c0d225a7f6ff convert Fundamental_Theorem_Algebra.thy to use new Polynomial library
huffman
parents: 29292
diff changeset
    55
c0d225a7f6ff convert Fundamental_Theorem_Algebra.thy to use new Polynomial library
huffman
parents: 29292
diff changeset
    56
lemma offset_poly_0: "offset_poly 0 h = 0"
52380
3cc46b8cca5e lifting for primitive definitions;
haftmann
parents: 51541
diff changeset
    57
  by (simp add: offset_poly_def)
29464
c0d225a7f6ff convert Fundamental_Theorem_Algebra.thy to use new Polynomial library
huffman
parents: 29292
diff changeset
    58
c0d225a7f6ff convert Fundamental_Theorem_Algebra.thy to use new Polynomial library
huffman
parents: 29292
diff changeset
    59
lemma offset_poly_pCons:
c0d225a7f6ff convert Fundamental_Theorem_Algebra.thy to use new Polynomial library
huffman
parents: 29292
diff changeset
    60
  "offset_poly (pCons a p) h =
c0d225a7f6ff convert Fundamental_Theorem_Algebra.thy to use new Polynomial library
huffman
parents: 29292
diff changeset
    61
    smult h (offset_poly p h) + pCons a (offset_poly p h)"
52380
3cc46b8cca5e lifting for primitive definitions;
haftmann
parents: 51541
diff changeset
    62
  by (cases "p = 0 \<and> a = 0") (auto simp add: offset_poly_def)
29464
c0d225a7f6ff convert Fundamental_Theorem_Algebra.thy to use new Polynomial library
huffman
parents: 29292
diff changeset
    63
77282
3fc7c85fdbb5 Tidied some really messy proofs
paulson <lp15@cam.ac.uk>
parents: 69529
diff changeset
    64
lemma offset_poly_single [simp]: "offset_poly [:a:] h = [:a:]"
56778
cb0929421ca6 tuned proofs;
wenzelm
parents: 56776
diff changeset
    65
  by (simp add: offset_poly_pCons offset_poly_0)
29464
c0d225a7f6ff convert Fundamental_Theorem_Algebra.thy to use new Polynomial library
huffman
parents: 29292
diff changeset
    66
c0d225a7f6ff convert Fundamental_Theorem_Algebra.thy to use new Polynomial library
huffman
parents: 29292
diff changeset
    67
lemma poly_offset_poly: "poly (offset_poly p h) x = poly p (h + x)"
77282
3fc7c85fdbb5 Tidied some really messy proofs
paulson <lp15@cam.ac.uk>
parents: 69529
diff changeset
    68
  by (induct p) (auto simp add: offset_poly_0 offset_poly_pCons algebra_simps)
29464
c0d225a7f6ff convert Fundamental_Theorem_Algebra.thy to use new Polynomial library
huffman
parents: 29292
diff changeset
    69
c0d225a7f6ff convert Fundamental_Theorem_Algebra.thy to use new Polynomial library
huffman
parents: 29292
diff changeset
    70
lemma offset_poly_eq_0_lemma: "smult c p + pCons a p = 0 \<Longrightarrow> p = 0"
56778
cb0929421ca6 tuned proofs;
wenzelm
parents: 56776
diff changeset
    71
  by (induct p arbitrary: a) (simp, force)
26123
44384b5c4fc0 A proof a the fundamental theorem of algebra
chaieb
parents:
diff changeset
    72
77282
3fc7c85fdbb5 Tidied some really messy proofs
paulson <lp15@cam.ac.uk>
parents: 69529
diff changeset
    73
lemma offset_poly_eq_0_iff [simp]: "offset_poly p h = 0 \<longleftrightarrow> p = 0"
3fc7c85fdbb5 Tidied some really messy proofs
paulson <lp15@cam.ac.uk>
parents: 69529
diff changeset
    74
proof
3fc7c85fdbb5 Tidied some really messy proofs
paulson <lp15@cam.ac.uk>
parents: 69529
diff changeset
    75
  show "offset_poly p h = 0 \<Longrightarrow> p = 0"
3fc7c85fdbb5 Tidied some really messy proofs
paulson <lp15@cam.ac.uk>
parents: 69529
diff changeset
    76
  proof(induction p)
3fc7c85fdbb5 Tidied some really messy proofs
paulson <lp15@cam.ac.uk>
parents: 69529
diff changeset
    77
    case 0
3fc7c85fdbb5 Tidied some really messy proofs
paulson <lp15@cam.ac.uk>
parents: 69529
diff changeset
    78
    then show ?case by blast
3fc7c85fdbb5 Tidied some really messy proofs
paulson <lp15@cam.ac.uk>
parents: 69529
diff changeset
    79
  next
3fc7c85fdbb5 Tidied some really messy proofs
paulson <lp15@cam.ac.uk>
parents: 69529
diff changeset
    80
    case (pCons a p)
3fc7c85fdbb5 Tidied some really messy proofs
paulson <lp15@cam.ac.uk>
parents: 69529
diff changeset
    81
    then show ?case   
3fc7c85fdbb5 Tidied some really messy proofs
paulson <lp15@cam.ac.uk>
parents: 69529
diff changeset
    82
      by (metis offset_poly_eq_0_lemma offset_poly_pCons offset_poly_single)
3fc7c85fdbb5 Tidied some really messy proofs
paulson <lp15@cam.ac.uk>
parents: 69529
diff changeset
    83
  qed
3fc7c85fdbb5 Tidied some really messy proofs
paulson <lp15@cam.ac.uk>
parents: 69529
diff changeset
    84
qed (simp add: offset_poly_0)
29464
c0d225a7f6ff convert Fundamental_Theorem_Algebra.thy to use new Polynomial library
huffman
parents: 29292
diff changeset
    85
77282
3fc7c85fdbb5 Tidied some really messy proofs
paulson <lp15@cam.ac.uk>
parents: 69529
diff changeset
    86
lemma degree_offset_poly [simp]: "degree (offset_poly p h) = degree p"
3fc7c85fdbb5 Tidied some really messy proofs
paulson <lp15@cam.ac.uk>
parents: 69529
diff changeset
    87
proof(induction p)
3fc7c85fdbb5 Tidied some really messy proofs
paulson <lp15@cam.ac.uk>
parents: 69529
diff changeset
    88
  case 0
3fc7c85fdbb5 Tidied some really messy proofs
paulson <lp15@cam.ac.uk>
parents: 69529
diff changeset
    89
  then show ?case
3fc7c85fdbb5 Tidied some really messy proofs
paulson <lp15@cam.ac.uk>
parents: 69529
diff changeset
    90
    by (simp add: offset_poly_0)
3fc7c85fdbb5 Tidied some really messy proofs
paulson <lp15@cam.ac.uk>
parents: 69529
diff changeset
    91
next
3fc7c85fdbb5 Tidied some really messy proofs
paulson <lp15@cam.ac.uk>
parents: 69529
diff changeset
    92
  case (pCons a p)
3fc7c85fdbb5 Tidied some really messy proofs
paulson <lp15@cam.ac.uk>
parents: 69529
diff changeset
    93
  have "p \<noteq> 0 \<Longrightarrow> degree (offset_poly (pCons a p) h) = Suc (degree p)"
3fc7c85fdbb5 Tidied some really messy proofs
paulson <lp15@cam.ac.uk>
parents: 69529
diff changeset
    94
    by (metis degree_add_eq_right degree_pCons_eq degree_smult_le le_imp_less_Suc offset_poly_eq_0_iff offset_poly_pCons pCons.IH)
3fc7c85fdbb5 Tidied some really messy proofs
paulson <lp15@cam.ac.uk>
parents: 69529
diff changeset
    95
  then show ?case
3fc7c85fdbb5 Tidied some really messy proofs
paulson <lp15@cam.ac.uk>
parents: 69529
diff changeset
    96
    by simp
3fc7c85fdbb5 Tidied some really messy proofs
paulson <lp15@cam.ac.uk>
parents: 69529
diff changeset
    97
qed
29464
c0d225a7f6ff convert Fundamental_Theorem_Algebra.thy to use new Polynomial library
huffman
parents: 29292
diff changeset
    98
56778
cb0929421ca6 tuned proofs;
wenzelm
parents: 56776
diff changeset
    99
definition "psize p = (if p = 0 then 0 else Suc (degree p))"
29464
c0d225a7f6ff convert Fundamental_Theorem_Algebra.thy to use new Polynomial library
huffman
parents: 29292
diff changeset
   100
29538
5cc98af1398d rename plength to psize
huffman
parents: 29485
diff changeset
   101
lemma psize_eq_0_iff [simp]: "psize p = 0 \<longleftrightarrow> p = 0"
5cc98af1398d rename plength to psize
huffman
parents: 29485
diff changeset
   102
  unfolding psize_def by simp
29464
c0d225a7f6ff convert Fundamental_Theorem_Algebra.thy to use new Polynomial library
huffman
parents: 29292
diff changeset
   103
56778
cb0929421ca6 tuned proofs;
wenzelm
parents: 56776
diff changeset
   104
lemma poly_offset:
cb0929421ca6 tuned proofs;
wenzelm
parents: 56776
diff changeset
   105
  fixes p :: "'a::comm_ring_1 poly"
cb0929421ca6 tuned proofs;
wenzelm
parents: 56776
diff changeset
   106
  shows "\<exists>q. psize q = psize p \<and> (\<forall>x. poly q x = poly p (a + x))"
77282
3fc7c85fdbb5 Tidied some really messy proofs
paulson <lp15@cam.ac.uk>
parents: 69529
diff changeset
   107
  by (metis degree_offset_poly offset_poly_eq_0_iff poly_offset_poly psize_def)
26123
44384b5c4fc0 A proof a the fundamental theorem of algebra
chaieb
parents:
diff changeset
   108
60424
c96fff9dcdbc misc tuning;
wenzelm
parents: 59557
diff changeset
   109
text \<open>An alternative useful formulation of completeness of the reals\<close>
56778
cb0929421ca6 tuned proofs;
wenzelm
parents: 56776
diff changeset
   110
lemma real_sup_exists:
cb0929421ca6 tuned proofs;
wenzelm
parents: 56776
diff changeset
   111
  assumes ex: "\<exists>x. P x"
cb0929421ca6 tuned proofs;
wenzelm
parents: 56776
diff changeset
   112
    and bz: "\<exists>z. \<forall>x. P x \<longrightarrow> x < z"
cb0929421ca6 tuned proofs;
wenzelm
parents: 56776
diff changeset
   113
  shows "\<exists>s::real. \<forall>y. (\<exists>x. P x \<and> y < x) \<longleftrightarrow> y < s"
54263
c4159fe6fa46 move Lubs from HOL to HOL-Library (replaced by conditionally complete lattices)
hoelzl
parents: 54230
diff changeset
   114
proof
c4159fe6fa46 move Lubs from HOL to HOL-Library (replaced by conditionally complete lattices)
hoelzl
parents: 54230
diff changeset
   115
  from bz have "bdd_above (Collect P)"
c4159fe6fa46 move Lubs from HOL to HOL-Library (replaced by conditionally complete lattices)
hoelzl
parents: 54230
diff changeset
   116
    by (force intro: less_imp_le)
c4159fe6fa46 move Lubs from HOL to HOL-Library (replaced by conditionally complete lattices)
hoelzl
parents: 54230
diff changeset
   117
  then show "\<forall>y. (\<exists>x. P x \<and> y < x) \<longleftrightarrow> y < Sup (Collect P)"
c4159fe6fa46 move Lubs from HOL to HOL-Library (replaced by conditionally complete lattices)
hoelzl
parents: 54230
diff changeset
   118
    using ex bz by (subst less_cSup_iff) auto
26123
44384b5c4fc0 A proof a the fundamental theorem of algebra
chaieb
parents:
diff changeset
   119
qed
44384b5c4fc0 A proof a the fundamental theorem of algebra
chaieb
parents:
diff changeset
   120
60424
c96fff9dcdbc misc tuning;
wenzelm
parents: 59557
diff changeset
   121
c96fff9dcdbc misc tuning;
wenzelm
parents: 59557
diff changeset
   122
subsection \<open>Fundamental theorem of algebra\<close>
c96fff9dcdbc misc tuning;
wenzelm
parents: 59557
diff changeset
   123
c96fff9dcdbc misc tuning;
wenzelm
parents: 59557
diff changeset
   124
lemma unimodular_reduce_norm:
26123
44384b5c4fc0 A proof a the fundamental theorem of algebra
chaieb
parents:
diff changeset
   125
  assumes md: "cmod z = 1"
63589
58aab4745e85 more symbols;
wenzelm
parents: 63060
diff changeset
   126
  shows "cmod (z + 1) < 1 \<or> cmod (z - 1) < 1 \<or> cmod (z + \<i>) < 1 \<or> cmod (z - \<i>) < 1"
56778
cb0929421ca6 tuned proofs;
wenzelm
parents: 56776
diff changeset
   127
proof -
cb0929421ca6 tuned proofs;
wenzelm
parents: 56776
diff changeset
   128
  obtain x y where z: "z = Complex x y "
cb0929421ca6 tuned proofs;
wenzelm
parents: 56776
diff changeset
   129
    by (cases z) auto
cb0929421ca6 tuned proofs;
wenzelm
parents: 56776
diff changeset
   130
  from md z have xy: "x\<^sup>2 + y\<^sup>2 = 1"
cb0929421ca6 tuned proofs;
wenzelm
parents: 56776
diff changeset
   131
    by (simp add: cmod_def)
63589
58aab4745e85 more symbols;
wenzelm
parents: 63060
diff changeset
   132
  have False if "cmod (z + 1) \<ge> 1" "cmod (z - 1) \<ge> 1" "cmod (z + \<i>) \<ge> 1" "cmod (z - \<i>) \<ge> 1"
60557
5854821993d2 tuned proofs;
wenzelm
parents: 60457
diff changeset
   133
  proof -
77303
3c4aca1266eb Simplifying more proofs
paulson <lp15@cam.ac.uk>
parents: 77282
diff changeset
   134
    from that z xy have *: "2 * x \<le> 1" "2 * x \<ge> -1" "2 * y \<le> 1" "2 * y \<ge> -1"
29667
53103fc8ffa3 Replaced group_ and ring_simps by algebra_simps;
nipkow
parents: 29538
diff changeset
   135
      by (simp_all add: cmod_def power2_eq_square algebra_simps)
61945
1135b8de26c3 more symbols;
wenzelm
parents: 61585
diff changeset
   136
    then have "\<bar>2 * x\<bar> \<le> 1" "\<bar>2 * y\<bar> \<le> 1"
56778
cb0929421ca6 tuned proofs;
wenzelm
parents: 56776
diff changeset
   137
      by simp_all
61945
1135b8de26c3 more symbols;
wenzelm
parents: 61585
diff changeset
   138
    then have "\<bar>2 * x\<bar>\<^sup>2 \<le> 1\<^sup>2" "\<bar>2 * y\<bar>\<^sup>2 \<le> 1\<^sup>2"
77282
3fc7c85fdbb5 Tidied some really messy proofs
paulson <lp15@cam.ac.uk>
parents: 69529
diff changeset
   139
      by (metis abs_square_le_1 one_power2 power2_abs)+
77303
3c4aca1266eb Simplifying more proofs
paulson <lp15@cam.ac.uk>
parents: 77282
diff changeset
   140
    with xy * show ?thesis
3c4aca1266eb Simplifying more proofs
paulson <lp15@cam.ac.uk>
parents: 77282
diff changeset
   141
      by (smt (verit, best) four_x_squared square_le_1)
60557
5854821993d2 tuned proofs;
wenzelm
parents: 60457
diff changeset
   142
  qed
56778
cb0929421ca6 tuned proofs;
wenzelm
parents: 56776
diff changeset
   143
  then show ?thesis
77303
3c4aca1266eb Simplifying more proofs
paulson <lp15@cam.ac.uk>
parents: 77282
diff changeset
   144
    by force
26123
44384b5c4fc0 A proof a the fundamental theorem of algebra
chaieb
parents:
diff changeset
   145
qed
44384b5c4fc0 A proof a the fundamental theorem of algebra
chaieb
parents:
diff changeset
   146
61585
a9599d3d7610 isabelle update_cartouches -c -t;
wenzelm
parents: 60567
diff changeset
   147
text \<open>Hence we can always reduce modulus of \<open>1 + b z^n\<close> if nonzero\<close>
26123
44384b5c4fc0 A proof a the fundamental theorem of algebra
chaieb
parents:
diff changeset
   148
lemma reduce_poly_simple:
56778
cb0929421ca6 tuned proofs;
wenzelm
parents: 56776
diff changeset
   149
  assumes b: "b \<noteq> 0"
cb0929421ca6 tuned proofs;
wenzelm
parents: 56776
diff changeset
   150
    and n: "n \<noteq> 0"
26123
44384b5c4fc0 A proof a the fundamental theorem of algebra
chaieb
parents:
diff changeset
   151
  shows "\<exists>z. cmod (1 + b * z^n) < 1"
56778
cb0929421ca6 tuned proofs;
wenzelm
parents: 56776
diff changeset
   152
  using n
cb0929421ca6 tuned proofs;
wenzelm
parents: 56776
diff changeset
   153
proof (induct n rule: nat_less_induct)
26123
44384b5c4fc0 A proof a the fundamental theorem of algebra
chaieb
parents:
diff changeset
   154
  fix n
56778
cb0929421ca6 tuned proofs;
wenzelm
parents: 56776
diff changeset
   155
  assume IH: "\<forall>m<n. m \<noteq> 0 \<longrightarrow> (\<exists>z. cmod (1 + b * z ^ m) < 1)"
cb0929421ca6 tuned proofs;
wenzelm
parents: 56776
diff changeset
   156
  assume n: "n \<noteq> 0"
26123
44384b5c4fc0 A proof a the fundamental theorem of algebra
chaieb
parents:
diff changeset
   157
  let ?P = "\<lambda>z n. cmod (1 + b * z ^ n) < 1"
60457
f31f7599ef55 tuned proofs;
wenzelm
parents: 60449
diff changeset
   158
  show "\<exists>z. ?P z n"
f31f7599ef55 tuned proofs;
wenzelm
parents: 60449
diff changeset
   159
  proof cases
77282
3fc7c85fdbb5 Tidied some really messy proofs
paulson <lp15@cam.ac.uk>
parents: 69529
diff changeset
   160
    assume "even n" 
3fc7c85fdbb5 Tidied some really messy proofs
paulson <lp15@cam.ac.uk>
parents: 69529
diff changeset
   161
    then obtain m where m: "n = 2 * m" and "m \<noteq> 0" "m < n"
3fc7c85fdbb5 Tidied some really messy proofs
paulson <lp15@cam.ac.uk>
parents: 69529
diff changeset
   162
      using n by auto
3fc7c85fdbb5 Tidied some really messy proofs
paulson <lp15@cam.ac.uk>
parents: 69529
diff changeset
   163
    with IH obtain z where z: "?P z m"
56778
cb0929421ca6 tuned proofs;
wenzelm
parents: 56776
diff changeset
   164
      by blast
56795
e8cce2bd23e5 tuned proofs;
wenzelm
parents: 56778
diff changeset
   165
    from z have "?P (csqrt z) n"
60457
f31f7599ef55 tuned proofs;
wenzelm
parents: 60449
diff changeset
   166
      by (simp add: m power_mult)
f31f7599ef55 tuned proofs;
wenzelm
parents: 60449
diff changeset
   167
    then show ?thesis ..
f31f7599ef55 tuned proofs;
wenzelm
parents: 60449
diff changeset
   168
  next
f31f7599ef55 tuned proofs;
wenzelm
parents: 60449
diff changeset
   169
    assume "odd n"
f31f7599ef55 tuned proofs;
wenzelm
parents: 60449
diff changeset
   170
    then have "\<exists>m. n = Suc (2 * m)"
56778
cb0929421ca6 tuned proofs;
wenzelm
parents: 56776
diff changeset
   171
      by presburger+
56795
e8cce2bd23e5 tuned proofs;
wenzelm
parents: 56778
diff changeset
   172
    then obtain m where m: "n = Suc (2 * m)"
56778
cb0929421ca6 tuned proofs;
wenzelm
parents: 56776
diff changeset
   173
      by blast
77303
3c4aca1266eb Simplifying more proofs
paulson <lp15@cam.ac.uk>
parents: 77282
diff changeset
   174
    have 0: "cmod (complex_of_real (cmod b) / b) = 1"
60457
f31f7599ef55 tuned proofs;
wenzelm
parents: 60449
diff changeset
   175
      using b by (simp add: norm_divide)
26123
44384b5c4fc0 A proof a the fundamental theorem of algebra
chaieb
parents:
diff changeset
   176
    have "\<exists>v. cmod (complex_of_real (cmod b) / b + v^n) < 1"
77282
3fc7c85fdbb5 Tidied some really messy proofs
paulson <lp15@cam.ac.uk>
parents: 69529
diff changeset
   177
    proof (cases "cmod (complex_of_real (cmod b) / b + 1) < 1")
3fc7c85fdbb5 Tidied some really messy proofs
paulson <lp15@cam.ac.uk>
parents: 69529
diff changeset
   178
      case True
3fc7c85fdbb5 Tidied some really messy proofs
paulson <lp15@cam.ac.uk>
parents: 69529
diff changeset
   179
      then show ?thesis
3fc7c85fdbb5 Tidied some really messy proofs
paulson <lp15@cam.ac.uk>
parents: 69529
diff changeset
   180
        by (metis power_one)
3fc7c85fdbb5 Tidied some really messy proofs
paulson <lp15@cam.ac.uk>
parents: 69529
diff changeset
   181
    next
77303
3c4aca1266eb Simplifying more proofs
paulson <lp15@cam.ac.uk>
parents: 77282
diff changeset
   182
      case F1: False
77282
3fc7c85fdbb5 Tidied some really messy proofs
paulson <lp15@cam.ac.uk>
parents: 69529
diff changeset
   183
      show ?thesis
3fc7c85fdbb5 Tidied some really messy proofs
paulson <lp15@cam.ac.uk>
parents: 69529
diff changeset
   184
      proof (cases "cmod (complex_of_real (cmod b) / b - 1) < 1")
3fc7c85fdbb5 Tidied some really messy proofs
paulson <lp15@cam.ac.uk>
parents: 69529
diff changeset
   185
        case True
3fc7c85fdbb5 Tidied some really messy proofs
paulson <lp15@cam.ac.uk>
parents: 69529
diff changeset
   186
        with \<open>odd n\<close> show ?thesis
3fc7c85fdbb5 Tidied some really messy proofs
paulson <lp15@cam.ac.uk>
parents: 69529
diff changeset
   187
          by (metis add_uminus_conv_diff neg_one_odd_power)
3fc7c85fdbb5 Tidied some really messy proofs
paulson <lp15@cam.ac.uk>
parents: 69529
diff changeset
   188
      next
77303
3c4aca1266eb Simplifying more proofs
paulson <lp15@cam.ac.uk>
parents: 77282
diff changeset
   189
        case F2: False
77282
3fc7c85fdbb5 Tidied some really messy proofs
paulson <lp15@cam.ac.uk>
parents: 69529
diff changeset
   190
        show ?thesis
3fc7c85fdbb5 Tidied some really messy proofs
paulson <lp15@cam.ac.uk>
parents: 69529
diff changeset
   191
        proof (cases "cmod (complex_of_real (cmod b) / b + \<i>) < 1")
77303
3c4aca1266eb Simplifying more proofs
paulson <lp15@cam.ac.uk>
parents: 77282
diff changeset
   192
          case T1: True
77282
3fc7c85fdbb5 Tidied some really messy proofs
paulson <lp15@cam.ac.uk>
parents: 69529
diff changeset
   193
          show ?thesis
3fc7c85fdbb5 Tidied some really messy proofs
paulson <lp15@cam.ac.uk>
parents: 69529
diff changeset
   194
          proof (cases "even m")
3fc7c85fdbb5 Tidied some really messy proofs
paulson <lp15@cam.ac.uk>
parents: 69529
diff changeset
   195
            case True
3fc7c85fdbb5 Tidied some really messy proofs
paulson <lp15@cam.ac.uk>
parents: 69529
diff changeset
   196
            with T1 show ?thesis
3fc7c85fdbb5 Tidied some really messy proofs
paulson <lp15@cam.ac.uk>
parents: 69529
diff changeset
   197
              by (rule_tac x="\<i>" in exI) (simp add: m power_mult)
3fc7c85fdbb5 Tidied some really messy proofs
paulson <lp15@cam.ac.uk>
parents: 69529
diff changeset
   198
          next
3fc7c85fdbb5 Tidied some really messy proofs
paulson <lp15@cam.ac.uk>
parents: 69529
diff changeset
   199
            case False
3fc7c85fdbb5 Tidied some really messy proofs
paulson <lp15@cam.ac.uk>
parents: 69529
diff changeset
   200
            with T1 show ?thesis 
3fc7c85fdbb5 Tidied some really messy proofs
paulson <lp15@cam.ac.uk>
parents: 69529
diff changeset
   201
              by (rule_tac x="- \<i>" in exI) (simp add: m power_mult)
3fc7c85fdbb5 Tidied some really messy proofs
paulson <lp15@cam.ac.uk>
parents: 69529
diff changeset
   202
          qed
3fc7c85fdbb5 Tidied some really messy proofs
paulson <lp15@cam.ac.uk>
parents: 69529
diff changeset
   203
        next
3fc7c85fdbb5 Tidied some really messy proofs
paulson <lp15@cam.ac.uk>
parents: 69529
diff changeset
   204
          case False
77341
127a51771f34 Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 77303
diff changeset
   205
          then have lt1: "cmod (of_real (cmod b) / b - \<i>) < 1"
127a51771f34 Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 77303
diff changeset
   206
            using "0" F1 F2 unimodular_reduce_norm by blast
127a51771f34 Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 77303
diff changeset
   207
          show ?thesis
127a51771f34 Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 77303
diff changeset
   208
          proof (cases "even m")
127a51771f34 Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 77303
diff changeset
   209
            case True
127a51771f34 Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 77303
diff changeset
   210
            with m lt1 show ?thesis 
127a51771f34 Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 77303
diff changeset
   211
              by (rule_tac x="- \<i>" in exI) (simp add: power_mult)
127a51771f34 Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 77303
diff changeset
   212
          next
127a51771f34 Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 77303
diff changeset
   213
            case False
127a51771f34 Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 77303
diff changeset
   214
            with m lt1 show ?thesis 
127a51771f34 Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 77303
diff changeset
   215
              by (rule_tac x="\<i>" in exI) (simp add: power_mult)
127a51771f34 Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 77303
diff changeset
   216
          qed
77282
3fc7c85fdbb5 Tidied some really messy proofs
paulson <lp15@cam.ac.uk>
parents: 69529
diff changeset
   217
        qed
3fc7c85fdbb5 Tidied some really messy proofs
paulson <lp15@cam.ac.uk>
parents: 69529
diff changeset
   218
      qed
3fc7c85fdbb5 Tidied some really messy proofs
paulson <lp15@cam.ac.uk>
parents: 69529
diff changeset
   219
    qed
56778
cb0929421ca6 tuned proofs;
wenzelm
parents: 56776
diff changeset
   220
    then obtain v where v: "cmod (complex_of_real (cmod b) / b + v^n) < 1"
cb0929421ca6 tuned proofs;
wenzelm
parents: 56776
diff changeset
   221
      by blast
26123
44384b5c4fc0 A proof a the fundamental theorem of algebra
chaieb
parents:
diff changeset
   222
    let ?w = "v / complex_of_real (root n (cmod b))"
60457
f31f7599ef55 tuned proofs;
wenzelm
parents: 60449
diff changeset
   223
    from odd_real_root_pow[OF \<open>odd n\<close>, of "cmod b"]
77303
3c4aca1266eb Simplifying more proofs
paulson <lp15@cam.ac.uk>
parents: 77282
diff changeset
   224
    have 1: "?w ^ n = v^n / complex_of_real (cmod b)"
56889
48a745e1bde7 avoid the Complex constructor, use the more natural Re/Im view; moved csqrt to Complex.
hoelzl
parents: 56795
diff changeset
   225
      by (simp add: power_divide of_real_power[symmetric])
77303
3c4aca1266eb Simplifying more proofs
paulson <lp15@cam.ac.uk>
parents: 77282
diff changeset
   226
    have 2:"cmod (complex_of_real (cmod b) / b) = 1"
56778
cb0929421ca6 tuned proofs;
wenzelm
parents: 56776
diff changeset
   227
      using b by (simp add: norm_divide)
77303
3c4aca1266eb Simplifying more proofs
paulson <lp15@cam.ac.uk>
parents: 77282
diff changeset
   228
    then have 3: "cmod (complex_of_real (cmod b) / b) \<ge> 0"
56778
cb0929421ca6 tuned proofs;
wenzelm
parents: 56776
diff changeset
   229
      by simp
77303
3c4aca1266eb Simplifying more proofs
paulson <lp15@cam.ac.uk>
parents: 77282
diff changeset
   230
    have 4: "cmod (complex_of_real (cmod b) / b) *
56778
cb0929421ca6 tuned proofs;
wenzelm
parents: 56776
diff changeset
   231
        cmod (1 + b * (v ^ n / complex_of_real (cmod b))) <
cb0929421ca6 tuned proofs;
wenzelm
parents: 56776
diff changeset
   232
        cmod (complex_of_real (cmod b) / b) * 1"
49962
a8cc904a6820 Renamed {left,right}_distrib to distrib_{right,left}.
webertj
parents: 46240
diff changeset
   233
      apply (simp only: norm_mult[symmetric] distrib_left)
56778
cb0929421ca6 tuned proofs;
wenzelm
parents: 56776
diff changeset
   234
      using b v
77303
3c4aca1266eb Simplifying more proofs
paulson <lp15@cam.ac.uk>
parents: 77282
diff changeset
   235
      apply (simp add: 2)
56778
cb0929421ca6 tuned proofs;
wenzelm
parents: 56776
diff changeset
   236
      done
77282
3fc7c85fdbb5 Tidied some really messy proofs
paulson <lp15@cam.ac.uk>
parents: 69529
diff changeset
   237
    show ?thesis
77303
3c4aca1266eb Simplifying more proofs
paulson <lp15@cam.ac.uk>
parents: 77282
diff changeset
   238
      by (metis 1 mult_left_less_imp_less[OF 4 3])
60457
f31f7599ef55 tuned proofs;
wenzelm
parents: 60449
diff changeset
   239
  qed
26123
44384b5c4fc0 A proof a the fundamental theorem of algebra
chaieb
parents:
diff changeset
   240
qed
44384b5c4fc0 A proof a the fundamental theorem of algebra
chaieb
parents:
diff changeset
   241
60424
c96fff9dcdbc misc tuning;
wenzelm
parents: 59557
diff changeset
   242
text \<open>Bolzano-Weierstrass type property for closed disc in complex plane.\<close>
26123
44384b5c4fc0 A proof a the fundamental theorem of algebra
chaieb
parents:
diff changeset
   243
56778
cb0929421ca6 tuned proofs;
wenzelm
parents: 56776
diff changeset
   244
lemma metric_bound_lemma: "cmod (x - y) \<le> \<bar>Re x - Re y\<bar> + \<bar>Im x - Im y\<bar>"
56795
e8cce2bd23e5 tuned proofs;
wenzelm
parents: 56778
diff changeset
   245
  using real_sqrt_sum_squares_triangle_ineq[of "Re x - Re y" 0 0 "Im x - Im y"]
26123
44384b5c4fc0 A proof a the fundamental theorem of algebra
chaieb
parents:
diff changeset
   246
  unfolding cmod_def by simp
44384b5c4fc0 A proof a the fundamental theorem of algebra
chaieb
parents:
diff changeset
   247
69529
4ab9657b3257 capitalize proper names in lemma names
nipkow
parents: 68527
diff changeset
   248
lemma Bolzano_Weierstrass_complex_disc:
26123
44384b5c4fc0 A proof a the fundamental theorem of algebra
chaieb
parents:
diff changeset
   249
  assumes r: "\<forall>n. cmod (s n) \<le> r"
66447
a1f5c5c26fa6 Replaced subseq with strict_mono
eberlm <eberlm@in.tum.de>
parents: 65486
diff changeset
   250
  shows "\<exists>f z. strict_mono (f :: nat \<Rightarrow> nat) \<and> (\<forall>e >0. \<exists>N. \<forall>n \<ge> N. cmod (s (f n) - z) < e)"
60424
c96fff9dcdbc misc tuning;
wenzelm
parents: 59557
diff changeset
   251
proof -
56778
cb0929421ca6 tuned proofs;
wenzelm
parents: 56776
diff changeset
   252
  from seq_monosub[of "Re \<circ> s"]
66447
a1f5c5c26fa6 Replaced subseq with strict_mono
eberlm <eberlm@in.tum.de>
parents: 65486
diff changeset
   253
  obtain f where f: "strict_mono f" "monoseq (\<lambda>n. Re (s (f n)))"
26123
44384b5c4fc0 A proof a the fundamental theorem of algebra
chaieb
parents:
diff changeset
   254
    unfolding o_def by blast
56778
cb0929421ca6 tuned proofs;
wenzelm
parents: 56776
diff changeset
   255
  from seq_monosub[of "Im \<circ> s \<circ> f"]
66447
a1f5c5c26fa6 Replaced subseq with strict_mono
eberlm <eberlm@in.tum.de>
parents: 65486
diff changeset
   256
  obtain g where g: "strict_mono g" "monoseq (\<lambda>n. Im (s (f (g n))))"
56778
cb0929421ca6 tuned proofs;
wenzelm
parents: 56776
diff changeset
   257
    unfolding o_def by blast
cb0929421ca6 tuned proofs;
wenzelm
parents: 56776
diff changeset
   258
  let ?h = "f \<circ> g"
77303
3c4aca1266eb Simplifying more proofs
paulson <lp15@cam.ac.uk>
parents: 77282
diff changeset
   259
  have "r \<ge> 0"
3c4aca1266eb Simplifying more proofs
paulson <lp15@cam.ac.uk>
parents: 77282
diff changeset
   260
    by (meson norm_ge_zero order_trans r)
3c4aca1266eb Simplifying more proofs
paulson <lp15@cam.ac.uk>
parents: 77282
diff changeset
   261
  have "\<forall>n. r + 1 \<ge> \<bar>Re (s n)\<bar>"
77282
3fc7c85fdbb5 Tidied some really messy proofs
paulson <lp15@cam.ac.uk>
parents: 69529
diff changeset
   262
    by (smt (verit, ccfv_threshold) abs_Re_le_cmod r)
77303
3c4aca1266eb Simplifying more proofs
paulson <lp15@cam.ac.uk>
parents: 77282
diff changeset
   263
  then have conv1: "convergent (\<lambda>n. Re (s (f n)))"
3c4aca1266eb Simplifying more proofs
paulson <lp15@cam.ac.uk>
parents: 77282
diff changeset
   264
    by (metis Bseq_monoseq_convergent f(2) BseqI' real_norm_def)
3c4aca1266eb Simplifying more proofs
paulson <lp15@cam.ac.uk>
parents: 77282
diff changeset
   265
  have "\<forall>n. r + 1 \<ge> \<bar>Im (s n)\<bar>"
77282
3fc7c85fdbb5 Tidied some really messy proofs
paulson <lp15@cam.ac.uk>
parents: 69529
diff changeset
   266
    by (smt (verit) abs_Im_le_cmod r)
77303
3c4aca1266eb Simplifying more proofs
paulson <lp15@cam.ac.uk>
parents: 77282
diff changeset
   267
  then have conv2: "convergent (\<lambda>n. Im (s (f (g n))))"
3c4aca1266eb Simplifying more proofs
paulson <lp15@cam.ac.uk>
parents: 77282
diff changeset
   268
    by (metis Bseq_monoseq_convergent g(2) BseqI' real_norm_def)
26123
44384b5c4fc0 A proof a the fundamental theorem of algebra
chaieb
parents:
diff changeset
   269
77303
3c4aca1266eb Simplifying more proofs
paulson <lp15@cam.ac.uk>
parents: 77282
diff changeset
   270
  obtain x where  x: "\<forall>r>0. \<exists>n0. \<forall>n\<ge>n0. \<bar>Re (s (f n)) - x\<bar> < r"
3c4aca1266eb Simplifying more proofs
paulson <lp15@cam.ac.uk>
parents: 77282
diff changeset
   271
    using conv1[unfolded convergent_def] LIMSEQ_iff real_norm_def by metis 
77282
3fc7c85fdbb5 Tidied some really messy proofs
paulson <lp15@cam.ac.uk>
parents: 69529
diff changeset
   272
  obtain y where  y: "\<forall>r>0. \<exists>n0. \<forall>n\<ge>n0. \<bar>Im (s (f (g n))) - y\<bar> < r"
77303
3c4aca1266eb Simplifying more proofs
paulson <lp15@cam.ac.uk>
parents: 77282
diff changeset
   273
    using conv2[unfolded convergent_def] LIMSEQ_iff real_norm_def by metis
26123
44384b5c4fc0 A proof a the fundamental theorem of algebra
chaieb
parents:
diff changeset
   274
  let ?w = "Complex x y"
66447
a1f5c5c26fa6 Replaced subseq with strict_mono
eberlm <eberlm@in.tum.de>
parents: 65486
diff changeset
   275
  from f(1) g(1) have hs: "strict_mono ?h"
a1f5c5c26fa6 Replaced subseq with strict_mono
eberlm <eberlm@in.tum.de>
parents: 65486
diff changeset
   276
    unfolding strict_mono_def by auto
60557
5854821993d2 tuned proofs;
wenzelm
parents: 60457
diff changeset
   277
  have "\<exists>N. \<forall>n\<ge>N. cmod (s (?h n) - ?w) < e" if "e > 0" for e
5854821993d2 tuned proofs;
wenzelm
parents: 60457
diff changeset
   278
  proof -
5854821993d2 tuned proofs;
wenzelm
parents: 60457
diff changeset
   279
    from that have e2: "e/2 > 0"
56795
e8cce2bd23e5 tuned proofs;
wenzelm
parents: 56778
diff changeset
   280
      by simp
77282
3fc7c85fdbb5 Tidied some really messy proofs
paulson <lp15@cam.ac.uk>
parents: 69529
diff changeset
   281
    from x y e2
56778
cb0929421ca6 tuned proofs;
wenzelm
parents: 56776
diff changeset
   282
    obtain N1 N2 where N1: "\<forall>n\<ge>N1. \<bar>Re (s (f n)) - x\<bar> < e / 2"
56795
e8cce2bd23e5 tuned proofs;
wenzelm
parents: 56778
diff changeset
   283
      and N2: "\<forall>n\<ge>N2. \<bar>Im (s (f (g n))) - y\<bar> < e / 2"
e8cce2bd23e5 tuned proofs;
wenzelm
parents: 56778
diff changeset
   284
      by blast
60557
5854821993d2 tuned proofs;
wenzelm
parents: 60457
diff changeset
   285
    have "cmod (s (?h n) - ?w) < e" if "n \<ge> N1 + N2" for n
5854821993d2 tuned proofs;
wenzelm
parents: 60457
diff changeset
   286
    proof -
5854821993d2 tuned proofs;
wenzelm
parents: 60457
diff changeset
   287
      from that have nN1: "g n \<ge> N1" and nN2: "n \<ge> N2"
56778
cb0929421ca6 tuned proofs;
wenzelm
parents: 56776
diff changeset
   288
        using seq_suble[OF g(1), of n] by arith+
60557
5854821993d2 tuned proofs;
wenzelm
parents: 60457
diff changeset
   289
      show ?thesis
77282
3fc7c85fdbb5 Tidied some really messy proofs
paulson <lp15@cam.ac.uk>
parents: 69529
diff changeset
   290
        using metric_bound_lemma[of "s (f (g n))" ?w] N1 N2 nN1 nN2 by fastforce
60557
5854821993d2 tuned proofs;
wenzelm
parents: 60457
diff changeset
   291
    qed
5854821993d2 tuned proofs;
wenzelm
parents: 60457
diff changeset
   292
    then show ?thesis by blast
5854821993d2 tuned proofs;
wenzelm
parents: 60457
diff changeset
   293
  qed
56778
cb0929421ca6 tuned proofs;
wenzelm
parents: 56776
diff changeset
   294
  with hs show ?thesis by blast
26123
44384b5c4fc0 A proof a the fundamental theorem of algebra
chaieb
parents:
diff changeset
   295
qed
44384b5c4fc0 A proof a the fundamental theorem of algebra
chaieb
parents:
diff changeset
   296
60424
c96fff9dcdbc misc tuning;
wenzelm
parents: 59557
diff changeset
   297
text \<open>Polynomial is continuous.\<close>
26123
44384b5c4fc0 A proof a the fundamental theorem of algebra
chaieb
parents:
diff changeset
   298
44384b5c4fc0 A proof a the fundamental theorem of algebra
chaieb
parents:
diff changeset
   299
lemma poly_cont:
56778
cb0929421ca6 tuned proofs;
wenzelm
parents: 56776
diff changeset
   300
  fixes p :: "'a::{comm_semiring_0,real_normed_div_algebra} poly"
30488
5c4c3a9e9102 remove trailing spaces
huffman
parents: 30242
diff changeset
   301
  assumes ep: "e > 0"
55735
81ba62493610 generalised some results using type classes
paulson <lp15@cam.ac.uk>
parents: 55734
diff changeset
   302
  shows "\<exists>d >0. \<forall>w. 0 < norm (w - z) \<and> norm (w - z) < d \<longrightarrow> norm (poly p w - poly p z) < e"
56778
cb0929421ca6 tuned proofs;
wenzelm
parents: 56776
diff changeset
   303
proof -
77341
127a51771f34 Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 77303
diff changeset
   304
  obtain q where "degree q = degree p" and q: "\<And>w. poly p w = poly q (w - z)"
127a51771f34 Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 77303
diff changeset
   305
    by (metis add.commute degree_offset_poly diff_add_cancel poly_offset_poly)
127a51771f34 Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 77303
diff changeset
   306
  show ?thesis unfolding q
56778
cb0929421ca6 tuned proofs;
wenzelm
parents: 56776
diff changeset
   307
  proof (induct q)
cb0929421ca6 tuned proofs;
wenzelm
parents: 56776
diff changeset
   308
    case 0
cb0929421ca6 tuned proofs;
wenzelm
parents: 56776
diff changeset
   309
    then show ?case
cb0929421ca6 tuned proofs;
wenzelm
parents: 56776
diff changeset
   310
      using ep by auto
26123
44384b5c4fc0 A proof a the fundamental theorem of algebra
chaieb
parents:
diff changeset
   311
  next
29464
c0d225a7f6ff convert Fundamental_Theorem_Algebra.thy to use new Polynomial library
huffman
parents: 29292
diff changeset
   312
    case (pCons c cs)
63060
293ede07b775 some uses of 'obtain' with structure statement;
wenzelm
parents: 62128
diff changeset
   313
    obtain m where m: "m > 0" "norm z \<le> 1 \<Longrightarrow> norm (poly cs z) \<le> m" for z
77341
127a51771f34 Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 77303
diff changeset
   314
      using poly_bound_exists[of 1 "cs"] by blast
77303
3c4aca1266eb Simplifying more proofs
paulson <lp15@cam.ac.uk>
parents: 77282
diff changeset
   315
    with ep have em0: "e/m > 0"
56778
cb0929421ca6 tuned proofs;
wenzelm
parents: 56776
diff changeset
   316
      by (simp add: field_simps)
cb0929421ca6 tuned proofs;
wenzelm
parents: 56776
diff changeset
   317
    obtain d where d: "d > 0" "d < 1" "d < e / m"
77341
127a51771f34 Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 77303
diff changeset
   318
      by (meson em0 field_lbound_gt_zero zero_less_one)
127a51771f34 Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 77303
diff changeset
   319
    then have "\<And>w. norm (w - z) < d \<Longrightarrow> norm (w - z) * norm (poly cs (w - z)) < e"
127a51771f34 Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 77303
diff changeset
   320
      by (smt (verit, del_insts) m mult_left_mono norm_ge_zero pos_less_divide_eq)
127a51771f34 Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 77303
diff changeset
   321
    with d show ?case
127a51771f34 Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 77303
diff changeset
   322
      by (force simp add: norm_mult)
56778
cb0929421ca6 tuned proofs;
wenzelm
parents: 56776
diff changeset
   323
  qed
26123
44384b5c4fc0 A proof a the fundamental theorem of algebra
chaieb
parents:
diff changeset
   324
qed
44384b5c4fc0 A proof a the fundamental theorem of algebra
chaieb
parents:
diff changeset
   325
60424
c96fff9dcdbc misc tuning;
wenzelm
parents: 59557
diff changeset
   326
text \<open>Hence a polynomial attains minimum on a closed disc
c96fff9dcdbc misc tuning;
wenzelm
parents: 59557
diff changeset
   327
  in the complex plane.\<close>
56778
cb0929421ca6 tuned proofs;
wenzelm
parents: 56776
diff changeset
   328
lemma poly_minimum_modulus_disc: "\<exists>z. \<forall>w. cmod w \<le> r \<longrightarrow> cmod (poly p z) \<le> cmod (poly p w)"
cb0929421ca6 tuned proofs;
wenzelm
parents: 56776
diff changeset
   329
proof -
60424
c96fff9dcdbc misc tuning;
wenzelm
parents: 59557
diff changeset
   330
  show ?thesis
c96fff9dcdbc misc tuning;
wenzelm
parents: 59557
diff changeset
   331
  proof (cases "r \<ge> 0")
c96fff9dcdbc misc tuning;
wenzelm
parents: 59557
diff changeset
   332
    case False
c96fff9dcdbc misc tuning;
wenzelm
parents: 59557
diff changeset
   333
    then show ?thesis
56778
cb0929421ca6 tuned proofs;
wenzelm
parents: 56776
diff changeset
   334
      by (metis norm_ge_zero order.trans)
60424
c96fff9dcdbc misc tuning;
wenzelm
parents: 59557
diff changeset
   335
  next
c96fff9dcdbc misc tuning;
wenzelm
parents: 59557
diff changeset
   336
    case True
56778
cb0929421ca6 tuned proofs;
wenzelm
parents: 56776
diff changeset
   337
    then have mth1: "\<exists>x z. cmod z \<le> r \<and> cmod (poly p z) = - x"
77303
3c4aca1266eb Simplifying more proofs
paulson <lp15@cam.ac.uk>
parents: 77282
diff changeset
   338
      by (metis add.inverse_inverse norm_zero)
3c4aca1266eb Simplifying more proofs
paulson <lp15@cam.ac.uk>
parents: 77282
diff changeset
   339
    obtain s where s: "\<forall>y. (\<exists>x. (\<exists>z. cmod z \<le> r \<and> cmod (poly p z) = - x) \<and> y < x) \<longleftrightarrow> y < s"
77341
127a51771f34 Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 77303
diff changeset
   340
      by (smt (verit, del_insts) real_sup_exists[OF mth1] norm_zero zero_less_norm_iff)
77303
3c4aca1266eb Simplifying more proofs
paulson <lp15@cam.ac.uk>
parents: 77282
diff changeset
   341
56778
cb0929421ca6 tuned proofs;
wenzelm
parents: 56776
diff changeset
   342
    let ?m = "- s"
77341
127a51771f34 Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 77303
diff changeset
   343
    have s1: "(\<exists>z. cmod z \<le> r \<and> - (- cmod (poly p z)) < y) \<longleftrightarrow> ?m < y" for y
77282
3fc7c85fdbb5 Tidied some really messy proofs
paulson <lp15@cam.ac.uk>
parents: 69529
diff changeset
   344
      by (metis add.inverse_inverse minus_less_iff s)
77341
127a51771f34 Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 77303
diff changeset
   345
    then have s1m: "\<And>z. cmod z \<le> r \<Longrightarrow> cmod (poly p z) \<ge> ?m"
127a51771f34 Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 77303
diff changeset
   346
      by force
60557
5854821993d2 tuned proofs;
wenzelm
parents: 60457
diff changeset
   347
    have "\<exists>z. cmod z \<le> r \<and> cmod (poly p z) < - s + 1 / real (Suc n)" for n
77341
127a51771f34 Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 77303
diff changeset
   348
      using s1[of "?m + 1/real (Suc n)"] by simp
77303
3c4aca1266eb Simplifying more proofs
paulson <lp15@cam.ac.uk>
parents: 77282
diff changeset
   349
    then obtain g where g: "\<forall>n. cmod (g n) \<le> r" "\<forall>n. cmod (poly p (g n)) <?m + 1 /real(Suc n)"
3c4aca1266eb Simplifying more proofs
paulson <lp15@cam.ac.uk>
parents: 77282
diff changeset
   350
      by metis
69529
4ab9657b3257 capitalize proper names in lemma names
nipkow
parents: 68527
diff changeset
   351
    from Bolzano_Weierstrass_complex_disc[OF g(1)]
77341
127a51771f34 Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 77303
diff changeset
   352
    obtain f::"nat \<Rightarrow> nat" and z where fz: "strict_mono f" "\<forall>e>0. \<exists>N. \<forall>n\<ge>N. cmod (g (f n) - z) < e"
30488
5c4c3a9e9102 remove trailing spaces
huffman
parents: 30242
diff changeset
   353
      by blast
56778
cb0929421ca6 tuned proofs;
wenzelm
parents: 56776
diff changeset
   354
    {
cb0929421ca6 tuned proofs;
wenzelm
parents: 56776
diff changeset
   355
      fix w
26123
44384b5c4fc0 A proof a the fundamental theorem of algebra
chaieb
parents:
diff changeset
   356
      assume wr: "cmod w \<le> r"
44384b5c4fc0 A proof a the fundamental theorem of algebra
chaieb
parents:
diff changeset
   357
      let ?e = "\<bar>cmod (poly p z) - ?m\<bar>"
56778
cb0929421ca6 tuned proofs;
wenzelm
parents: 56776
diff changeset
   358
      {
cb0929421ca6 tuned proofs;
wenzelm
parents: 56776
diff changeset
   359
        assume e: "?e > 0"
56795
e8cce2bd23e5 tuned proofs;
wenzelm
parents: 56778
diff changeset
   360
        then have e2: "?e/2 > 0"
e8cce2bd23e5 tuned proofs;
wenzelm
parents: 56778
diff changeset
   361
          by simp
77341
127a51771f34 Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 77303
diff changeset
   362
        with poly_cont obtain d 
127a51771f34 Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 77303
diff changeset
   363
          where "d > 0" and d: "\<And>w. 0<cmod (w - z)\<and> cmod(w - z) < d \<longrightarrow> cmod(poly p w - poly p z) < ?e/2"
56778
cb0929421ca6 tuned proofs;
wenzelm
parents: 56776
diff changeset
   364
          by blast
77303
3c4aca1266eb Simplifying more proofs
paulson <lp15@cam.ac.uk>
parents: 77282
diff changeset
   365
        have 1: "cmod(poly p w - poly p z) < ?e / 2" if w: "cmod (w - z) < d" for w
77341
127a51771f34 Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 77303
diff changeset
   366
          using d[of w] w e by (cases "w = z") simp_all
127a51771f34 Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 77303
diff changeset
   367
        from fz(2) \<open>d > 0\<close> obtain N1 where N1: "\<forall>n\<ge>N1. cmod (g (f n) - z) < d"
56778
cb0929421ca6 tuned proofs;
wenzelm
parents: 56776
diff changeset
   368
          by blast
77303
3c4aca1266eb Simplifying more proofs
paulson <lp15@cam.ac.uk>
parents: 77282
diff changeset
   369
        from reals_Archimedean2 obtain N2 :: nat where N2: "2/?e < real N2"
56778
cb0929421ca6 tuned proofs;
wenzelm
parents: 56776
diff changeset
   370
          by blast
77303
3c4aca1266eb Simplifying more proofs
paulson <lp15@cam.ac.uk>
parents: 77282
diff changeset
   371
        have 2: "cmod (poly p (g (f (N1 + N2))) - poly p z) < ?e/2"
3c4aca1266eb Simplifying more proofs
paulson <lp15@cam.ac.uk>
parents: 77282
diff changeset
   372
          using N1 1 by auto
3c4aca1266eb Simplifying more proofs
paulson <lp15@cam.ac.uk>
parents: 77282
diff changeset
   373
        have 0: "a < e2 \<Longrightarrow> \<bar>b - m\<bar> < e2 \<Longrightarrow> 2 * e2 \<le> \<bar>b - m\<bar> + a \<Longrightarrow> False"
60424
c96fff9dcdbc misc tuning;
wenzelm
parents: 59557
diff changeset
   374
          for a b e2 m :: real
c96fff9dcdbc misc tuning;
wenzelm
parents: 59557
diff changeset
   375
          by arith
56795
e8cce2bd23e5 tuned proofs;
wenzelm
parents: 56778
diff changeset
   376
        from seq_suble[OF fz(1), of "N1 + N2"]
77303
3c4aca1266eb Simplifying more proofs
paulson <lp15@cam.ac.uk>
parents: 77282
diff changeset
   377
        have 00: "?m + 1 / real (Suc (f (N1 + N2))) \<le> ?m + 1 / real (Suc (N1 + N2))"
3c4aca1266eb Simplifying more proofs
paulson <lp15@cam.ac.uk>
parents: 77282
diff changeset
   378
          by (simp add: frac_le)
3c4aca1266eb Simplifying more proofs
paulson <lp15@cam.ac.uk>
parents: 77282
diff changeset
   379
        from N2 e2 less_imp_inverse_less[of "2/?e" "real (Suc (N1 + N2))"]
56778
cb0929421ca6 tuned proofs;
wenzelm
parents: 56776
diff changeset
   380
        have "?e/2 > 1/ real (Suc (N1 + N2))"
cb0929421ca6 tuned proofs;
wenzelm
parents: 56776
diff changeset
   381
          by (simp add: inverse_eq_divide)
77303
3c4aca1266eb Simplifying more proofs
paulson <lp15@cam.ac.uk>
parents: 77282
diff changeset
   382
        with  order_less_le_trans[OF _ 00]
3c4aca1266eb Simplifying more proofs
paulson <lp15@cam.ac.uk>
parents: 77282
diff changeset
   383
        have 1: "\<bar>cmod (poly p (g (f (N1 + N2)))) - ?m\<bar> < ?e/2"
77341
127a51771f34 Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 77303
diff changeset
   384
          using g s1 by (smt (verit))
77303
3c4aca1266eb Simplifying more proofs
paulson <lp15@cam.ac.uk>
parents: 77282
diff changeset
   385
        with 0[OF 2] have False
77282
3fc7c85fdbb5 Tidied some really messy proofs
paulson <lp15@cam.ac.uk>
parents: 69529
diff changeset
   386
          by (smt (verit) field_sum_of_halves norm_triangle_ineq3)
56778
cb0929421ca6 tuned proofs;
wenzelm
parents: 56776
diff changeset
   387
      }
cb0929421ca6 tuned proofs;
wenzelm
parents: 56776
diff changeset
   388
      then have "?e = 0"
cb0929421ca6 tuned proofs;
wenzelm
parents: 56776
diff changeset
   389
        by auto
cb0929421ca6 tuned proofs;
wenzelm
parents: 56776
diff changeset
   390
      with s1m[OF wr] have "cmod (poly p z) \<le> cmod (poly p w)"
cb0929421ca6 tuned proofs;
wenzelm
parents: 56776
diff changeset
   391
        by simp
cb0929421ca6 tuned proofs;
wenzelm
parents: 56776
diff changeset
   392
    }
60424
c96fff9dcdbc misc tuning;
wenzelm
parents: 59557
diff changeset
   393
    then show ?thesis by blast
c96fff9dcdbc misc tuning;
wenzelm
parents: 59557
diff changeset
   394
  qed
26123
44384b5c4fc0 A proof a the fundamental theorem of algebra
chaieb
parents:
diff changeset
   395
qed
44384b5c4fc0 A proof a the fundamental theorem of algebra
chaieb
parents:
diff changeset
   396
60424
c96fff9dcdbc misc tuning;
wenzelm
parents: 59557
diff changeset
   397
text \<open>Nonzero polynomial in z goes to infinity as z does.\<close>
26123
44384b5c4fc0 A proof a the fundamental theorem of algebra
chaieb
parents:
diff changeset
   398
44384b5c4fc0 A proof a the fundamental theorem of algebra
chaieb
parents:
diff changeset
   399
lemma poly_infinity:
56778
cb0929421ca6 tuned proofs;
wenzelm
parents: 56776
diff changeset
   400
  fixes p:: "'a::{comm_semiring_0,real_normed_div_algebra} poly"
29464
c0d225a7f6ff convert Fundamental_Theorem_Algebra.thy to use new Polynomial library
huffman
parents: 29292
diff changeset
   401
  assumes ex: "p \<noteq> 0"
55735
81ba62493610 generalised some results using type classes
paulson <lp15@cam.ac.uk>
parents: 55734
diff changeset
   402
  shows "\<exists>r. \<forall>z. r \<le> norm z \<longrightarrow> d \<le> norm (poly (pCons a p) z)"
56778
cb0929421ca6 tuned proofs;
wenzelm
parents: 56776
diff changeset
   403
  using ex
cb0929421ca6 tuned proofs;
wenzelm
parents: 56776
diff changeset
   404
proof (induct p arbitrary: a d)
56795
e8cce2bd23e5 tuned proofs;
wenzelm
parents: 56778
diff changeset
   405
  case 0
e8cce2bd23e5 tuned proofs;
wenzelm
parents: 56778
diff changeset
   406
  then show ?case by simp
e8cce2bd23e5 tuned proofs;
wenzelm
parents: 56778
diff changeset
   407
next
30488
5c4c3a9e9102 remove trailing spaces
huffman
parents: 30242
diff changeset
   408
  case (pCons c cs a d)
56795
e8cce2bd23e5 tuned proofs;
wenzelm
parents: 56778
diff changeset
   409
  show ?case
e8cce2bd23e5 tuned proofs;
wenzelm
parents: 56778
diff changeset
   410
  proof (cases "cs = 0")
e8cce2bd23e5 tuned proofs;
wenzelm
parents: 56778
diff changeset
   411
    case False
56778
cb0929421ca6 tuned proofs;
wenzelm
parents: 56776
diff changeset
   412
    with pCons.hyps obtain r where r: "\<forall>z. r \<le> norm z \<longrightarrow> d + norm a \<le> norm (poly (pCons c cs) z)"
cb0929421ca6 tuned proofs;
wenzelm
parents: 56776
diff changeset
   413
      by blast
26123
44384b5c4fc0 A proof a the fundamental theorem of algebra
chaieb
parents:
diff changeset
   414
    let ?r = "1 + \<bar>r\<bar>"
60557
5854821993d2 tuned proofs;
wenzelm
parents: 60457
diff changeset
   415
    have "d \<le> norm (poly (pCons a (pCons c cs)) z)" if "1 + \<bar>r\<bar> \<le> norm z" for z
5854821993d2 tuned proofs;
wenzelm
parents: 60457
diff changeset
   416
    proof -
77282
3fc7c85fdbb5 Tidied some really messy proofs
paulson <lp15@cam.ac.uk>
parents: 69529
diff changeset
   417
      have "d \<le> norm(z * poly (pCons c cs) z) - norm a"
77303
3c4aca1266eb Simplifying more proofs
paulson <lp15@cam.ac.uk>
parents: 77282
diff changeset
   418
        by (smt (verit, best) norm_ge_zero mult_less_cancel_right2 norm_mult r that)
3c4aca1266eb Simplifying more proofs
paulson <lp15@cam.ac.uk>
parents: 77282
diff changeset
   419
      with norm_diff_ineq add.commute
3c4aca1266eb Simplifying more proofs
paulson <lp15@cam.ac.uk>
parents: 77282
diff changeset
   420
      show ?thesis
3c4aca1266eb Simplifying more proofs
paulson <lp15@cam.ac.uk>
parents: 77282
diff changeset
   421
        by (metis order.trans poly_pCons)
60557
5854821993d2 tuned proofs;
wenzelm
parents: 60457
diff changeset
   422
    qed
56795
e8cce2bd23e5 tuned proofs;
wenzelm
parents: 56778
diff changeset
   423
    then show ?thesis by blast
e8cce2bd23e5 tuned proofs;
wenzelm
parents: 56778
diff changeset
   424
  next
e8cce2bd23e5 tuned proofs;
wenzelm
parents: 56778
diff changeset
   425
    case True
60424
c96fff9dcdbc misc tuning;
wenzelm
parents: 59557
diff changeset
   426
    have "d \<le> norm (poly (pCons a (pCons c cs)) z)"
77303
3c4aca1266eb Simplifying more proofs
paulson <lp15@cam.ac.uk>
parents: 77282
diff changeset
   427
      if "(\<bar>d\<bar> + norm a) / norm c \<le> norm z" for z :: 'a
60424
c96fff9dcdbc misc tuning;
wenzelm
parents: 59557
diff changeset
   428
    proof -
77303
3c4aca1266eb Simplifying more proofs
paulson <lp15@cam.ac.uk>
parents: 77282
diff changeset
   429
      have "\<bar>d\<bar> + norm a \<le> norm (z * c)"
3c4aca1266eb Simplifying more proofs
paulson <lp15@cam.ac.uk>
parents: 77282
diff changeset
   430
        by (metis that True norm_mult pCons.hyps(1) pos_divide_le_eq zero_less_norm_iff)
3c4aca1266eb Simplifying more proofs
paulson <lp15@cam.ac.uk>
parents: 77282
diff changeset
   431
      also have "\<dots> \<le> norm (a + z * c) + norm a"
3c4aca1266eb Simplifying more proofs
paulson <lp15@cam.ac.uk>
parents: 77282
diff changeset
   432
        by (simp add: add.commute norm_add_leD)
3c4aca1266eb Simplifying more proofs
paulson <lp15@cam.ac.uk>
parents: 77282
diff changeset
   433
      finally show ?thesis
3c4aca1266eb Simplifying more proofs
paulson <lp15@cam.ac.uk>
parents: 77282
diff changeset
   434
        using True by auto
60424
c96fff9dcdbc misc tuning;
wenzelm
parents: 59557
diff changeset
   435
    qed
56795
e8cce2bd23e5 tuned proofs;
wenzelm
parents: 56778
diff changeset
   436
    then show ?thesis by blast
e8cce2bd23e5 tuned proofs;
wenzelm
parents: 56778
diff changeset
   437
  qed
e8cce2bd23e5 tuned proofs;
wenzelm
parents: 56778
diff changeset
   438
qed
26123
44384b5c4fc0 A proof a the fundamental theorem of algebra
chaieb
parents:
diff changeset
   439
60424
c96fff9dcdbc misc tuning;
wenzelm
parents: 59557
diff changeset
   440
text \<open>Hence polynomial's modulus attains its minimum somewhere.\<close>
56778
cb0929421ca6 tuned proofs;
wenzelm
parents: 56776
diff changeset
   441
lemma poly_minimum_modulus: "\<exists>z.\<forall>w. cmod (poly p z) \<le> cmod (poly p w)"
cb0929421ca6 tuned proofs;
wenzelm
parents: 56776
diff changeset
   442
proof (induct p)
cb0929421ca6 tuned proofs;
wenzelm
parents: 56776
diff changeset
   443
  case 0
cb0929421ca6 tuned proofs;
wenzelm
parents: 56776
diff changeset
   444
  then show ?case by simp
cb0929421ca6 tuned proofs;
wenzelm
parents: 56776
diff changeset
   445
next
30488
5c4c3a9e9102 remove trailing spaces
huffman
parents: 30242
diff changeset
   446
  case (pCons c cs)
56778
cb0929421ca6 tuned proofs;
wenzelm
parents: 56776
diff changeset
   447
  show ?case
cb0929421ca6 tuned proofs;
wenzelm
parents: 56776
diff changeset
   448
  proof (cases "cs = 0")
cb0929421ca6 tuned proofs;
wenzelm
parents: 56776
diff changeset
   449
    case False
cb0929421ca6 tuned proofs;
wenzelm
parents: 56776
diff changeset
   450
    from poly_infinity[OF False, of "cmod (poly (pCons c cs) 0)" c]
63060
293ede07b775 some uses of 'obtain' with structure statement;
wenzelm
parents: 62128
diff changeset
   451
    obtain r where r: "cmod (poly (pCons c cs) 0) \<le> cmod (poly (pCons c cs) z)"
293ede07b775 some uses of 'obtain' with structure statement;
wenzelm
parents: 62128
diff changeset
   452
      if "r \<le> cmod z" for z
56778
cb0929421ca6 tuned proofs;
wenzelm
parents: 56776
diff changeset
   453
      by blast
77282
3fc7c85fdbb5 Tidied some really messy proofs
paulson <lp15@cam.ac.uk>
parents: 69529
diff changeset
   454
    from poly_minimum_modulus_disc[of "\<bar>r\<bar>" "pCons c cs"] show ?thesis
77303
3c4aca1266eb Simplifying more proofs
paulson <lp15@cam.ac.uk>
parents: 77282
diff changeset
   455
      by (smt (verit, del_insts) order.trans linorder_linear r)
77282
3fc7c85fdbb5 Tidied some really messy proofs
paulson <lp15@cam.ac.uk>
parents: 69529
diff changeset
   456
  qed (use pCons.hyps in auto)
56778
cb0929421ca6 tuned proofs;
wenzelm
parents: 56776
diff changeset
   457
qed
26123
44384b5c4fc0 A proof a the fundamental theorem of algebra
chaieb
parents:
diff changeset
   458
60424
c96fff9dcdbc misc tuning;
wenzelm
parents: 59557
diff changeset
   459
text \<open>Constant function (non-syntactic characterization).\<close>
56795
e8cce2bd23e5 tuned proofs;
wenzelm
parents: 56778
diff changeset
   460
definition "constant f \<longleftrightarrow> (\<forall>x y. f x = f y)"
26123
44384b5c4fc0 A proof a the fundamental theorem of algebra
chaieb
parents:
diff changeset
   461
56778
cb0929421ca6 tuned proofs;
wenzelm
parents: 56776
diff changeset
   462
lemma nonconstant_length: "\<not> constant (poly p) \<Longrightarrow> psize p \<ge> 2"
cb0929421ca6 tuned proofs;
wenzelm
parents: 56776
diff changeset
   463
  by (induct p) (auto simp: constant_def psize_def)
30488
5c4c3a9e9102 remove trailing spaces
huffman
parents: 30242
diff changeset
   464
56795
e8cce2bd23e5 tuned proofs;
wenzelm
parents: 56778
diff changeset
   465
lemma poly_replicate_append: "poly (monom 1 n * p) (x::'a::comm_ring_1) = x^n * poly p x"
29464
c0d225a7f6ff convert Fundamental_Theorem_Algebra.thy to use new Polynomial library
huffman
parents: 29292
diff changeset
   466
  by (simp add: poly_monom)
26123
44384b5c4fc0 A proof a the fundamental theorem of algebra
chaieb
parents:
diff changeset
   467
60424
c96fff9dcdbc misc tuning;
wenzelm
parents: 59557
diff changeset
   468
text \<open>Decomposition of polynomial, skipping zero coefficients after the first.\<close>
26123
44384b5c4fc0 A proof a the fundamental theorem of algebra
chaieb
parents:
diff changeset
   469
44384b5c4fc0 A proof a the fundamental theorem of algebra
chaieb
parents:
diff changeset
   470
lemma poly_decompose_lemma:
56778
cb0929421ca6 tuned proofs;
wenzelm
parents: 56776
diff changeset
   471
  assumes nz: "\<not> (\<forall>z. z \<noteq> 0 \<longrightarrow> poly p z = (0::'a::idom))"
56795
e8cce2bd23e5 tuned proofs;
wenzelm
parents: 56778
diff changeset
   472
  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)"
56778
cb0929421ca6 tuned proofs;
wenzelm
parents: 56776
diff changeset
   473
  unfolding psize_def
cb0929421ca6 tuned proofs;
wenzelm
parents: 56776
diff changeset
   474
  using nz
cb0929421ca6 tuned proofs;
wenzelm
parents: 56776
diff changeset
   475
proof (induct p)
cb0929421ca6 tuned proofs;
wenzelm
parents: 56776
diff changeset
   476
  case 0
cb0929421ca6 tuned proofs;
wenzelm
parents: 56776
diff changeset
   477
  then show ?case by simp
26123
44384b5c4fc0 A proof a the fundamental theorem of algebra
chaieb
parents:
diff changeset
   478
next
29464
c0d225a7f6ff convert Fundamental_Theorem_Algebra.thy to use new Polynomial library
huffman
parents: 29292
diff changeset
   479
  case (pCons c cs)
56778
cb0929421ca6 tuned proofs;
wenzelm
parents: 56776
diff changeset
   480
  show ?case
cb0929421ca6 tuned proofs;
wenzelm
parents: 56776
diff changeset
   481
  proof (cases "c = 0")
cb0929421ca6 tuned proofs;
wenzelm
parents: 56776
diff changeset
   482
    case True
cb0929421ca6 tuned proofs;
wenzelm
parents: 56776
diff changeset
   483
    from pCons.hyps pCons.prems True show ?thesis
60424
c96fff9dcdbc misc tuning;
wenzelm
parents: 59557
diff changeset
   484
      apply auto
26123
44384b5c4fc0 A proof a the fundamental theorem of algebra
chaieb
parents:
diff changeset
   485
      apply (rule_tac x="k+1" in exI)
60557
5854821993d2 tuned proofs;
wenzelm
parents: 60457
diff changeset
   486
      apply (rule_tac x="a" in exI)
5854821993d2 tuned proofs;
wenzelm
parents: 60457
diff changeset
   487
      apply clarsimp
26123
44384b5c4fc0 A proof a the fundamental theorem of algebra
chaieb
parents:
diff changeset
   488
      apply (rule_tac x="q" in exI)
56778
cb0929421ca6 tuned proofs;
wenzelm
parents: 56776
diff changeset
   489
      apply auto
cb0929421ca6 tuned proofs;
wenzelm
parents: 56776
diff changeset
   490
      done
77303
3c4aca1266eb Simplifying more proofs
paulson <lp15@cam.ac.uk>
parents: 77282
diff changeset
   491
  qed force
26123
44384b5c4fc0 A proof a the fundamental theorem of algebra
chaieb
parents:
diff changeset
   492
qed
44384b5c4fc0 A proof a the fundamental theorem of algebra
chaieb
parents:
diff changeset
   493
44384b5c4fc0 A proof a the fundamental theorem of algebra
chaieb
parents:
diff changeset
   494
lemma poly_decompose:
77303
3c4aca1266eb Simplifying more proofs
paulson <lp15@cam.ac.uk>
parents: 77282
diff changeset
   495
  fixes p :: "'a::idom poly"
56776
309e1a61ee7c tuned proofs;
wenzelm
parents: 56544
diff changeset
   496
  assumes nc: "\<not> constant (poly p)"
77303
3c4aca1266eb Simplifying more proofs
paulson <lp15@cam.ac.uk>
parents: 77282
diff changeset
   497
  shows "\<exists>k a q. a \<noteq> 0 \<and> k \<noteq> 0 \<and>
30488
5c4c3a9e9102 remove trailing spaces
huffman
parents: 30242
diff changeset
   498
               psize q + k + 1 = psize p \<and>
77303
3c4aca1266eb Simplifying more proofs
paulson <lp15@cam.ac.uk>
parents: 77282
diff changeset
   499
              (\<forall>z. poly p z = poly p 0 + z^k * poly (pCons a q) z)" 
56776
309e1a61ee7c tuned proofs;
wenzelm
parents: 56544
diff changeset
   500
  using nc
309e1a61ee7c tuned proofs;
wenzelm
parents: 56544
diff changeset
   501
proof (induct p)
309e1a61ee7c tuned proofs;
wenzelm
parents: 56544
diff changeset
   502
  case 0
309e1a61ee7c tuned proofs;
wenzelm
parents: 56544
diff changeset
   503
  then show ?case
309e1a61ee7c tuned proofs;
wenzelm
parents: 56544
diff changeset
   504
    by (simp add: constant_def)
26123
44384b5c4fc0 A proof a the fundamental theorem of algebra
chaieb
parents:
diff changeset
   505
next
29464
c0d225a7f6ff convert Fundamental_Theorem_Algebra.thy to use new Polynomial library
huffman
parents: 29292
diff changeset
   506
  case (pCons c cs)
60557
5854821993d2 tuned proofs;
wenzelm
parents: 60457
diff changeset
   507
  have "\<not> (\<forall>z. z \<noteq> 0 \<longrightarrow> poly cs z = 0)"
77282
3fc7c85fdbb5 Tidied some really messy proofs
paulson <lp15@cam.ac.uk>
parents: 69529
diff changeset
   508
    by (smt (verit) constant_def mult_eq_0_iff pCons.prems poly_pCons)
60557
5854821993d2 tuned proofs;
wenzelm
parents: 60457
diff changeset
   509
  from poly_decompose_lemma[OF this]
77303
3c4aca1266eb Simplifying more proofs
paulson <lp15@cam.ac.uk>
parents: 77282
diff changeset
   510
  obtain k a q where *: "a \<noteq> 0 \<and>
3c4aca1266eb Simplifying more proofs
paulson <lp15@cam.ac.uk>
parents: 77282
diff changeset
   511
     Suc (psize q + k) = psize cs \<and> (\<forall>z. poly cs z = z ^ k * poly (pCons a q) z)"
3c4aca1266eb Simplifying more proofs
paulson <lp15@cam.ac.uk>
parents: 77282
diff changeset
   512
    by blast
3c4aca1266eb Simplifying more proofs
paulson <lp15@cam.ac.uk>
parents: 77282
diff changeset
   513
  then have "psize q + k + 2 = psize (pCons c cs)"
3c4aca1266eb Simplifying more proofs
paulson <lp15@cam.ac.uk>
parents: 77282
diff changeset
   514
    by (auto simp add: psize_def split: if_splits)
3c4aca1266eb Simplifying more proofs
paulson <lp15@cam.ac.uk>
parents: 77282
diff changeset
   515
  then show ?case
3c4aca1266eb Simplifying more proofs
paulson <lp15@cam.ac.uk>
parents: 77282
diff changeset
   516
    using "*" by force
26123
44384b5c4fc0 A proof a the fundamental theorem of algebra
chaieb
parents:
diff changeset
   517
qed
44384b5c4fc0 A proof a the fundamental theorem of algebra
chaieb
parents:
diff changeset
   518
60424
c96fff9dcdbc misc tuning;
wenzelm
parents: 59557
diff changeset
   519
text \<open>Fundamental theorem of algebra\<close>
26123
44384b5c4fc0 A proof a the fundamental theorem of algebra
chaieb
parents:
diff changeset
   520
44384b5c4fc0 A proof a the fundamental theorem of algebra
chaieb
parents:
diff changeset
   521
lemma fundamental_theorem_of_algebra:
56776
309e1a61ee7c tuned proofs;
wenzelm
parents: 56544
diff changeset
   522
  assumes nc: "\<not> constant (poly p)"
26123
44384b5c4fc0 A proof a the fundamental theorem of algebra
chaieb
parents:
diff changeset
   523
  shows "\<exists>z::complex. poly p z = 0"
56776
309e1a61ee7c tuned proofs;
wenzelm
parents: 56544
diff changeset
   524
  using nc
309e1a61ee7c tuned proofs;
wenzelm
parents: 56544
diff changeset
   525
proof (induct "psize p" arbitrary: p rule: less_induct)
34915
7894c7dab132 Adapted to changes in induct method.
berghofe
parents: 32960
diff changeset
   526
  case less
26123
44384b5c4fc0 A proof a the fundamental theorem of algebra
chaieb
parents:
diff changeset
   527
  let ?p = "poly p"
44384b5c4fc0 A proof a the fundamental theorem of algebra
chaieb
parents:
diff changeset
   528
  let ?ths = "\<exists>z. ?p z = 0"
44384b5c4fc0 A proof a the fundamental theorem of algebra
chaieb
parents:
diff changeset
   529
34915
7894c7dab132 Adapted to changes in induct method.
berghofe
parents: 32960
diff changeset
   530
  from nonconstant_length[OF less(2)] have n2: "psize p \<ge> 2" .
56776
309e1a61ee7c tuned proofs;
wenzelm
parents: 56544
diff changeset
   531
  from poly_minimum_modulus obtain c where c: "\<forall>w. cmod (?p c) \<le> cmod (?p w)"
309e1a61ee7c tuned proofs;
wenzelm
parents: 56544
diff changeset
   532
    by blast
56778
cb0929421ca6 tuned proofs;
wenzelm
parents: 56776
diff changeset
   533
cb0929421ca6 tuned proofs;
wenzelm
parents: 56776
diff changeset
   534
  show ?ths
cb0929421ca6 tuned proofs;
wenzelm
parents: 56776
diff changeset
   535
  proof (cases "?p c = 0")
cb0929421ca6 tuned proofs;
wenzelm
parents: 56776
diff changeset
   536
    case True
cb0929421ca6 tuned proofs;
wenzelm
parents: 56776
diff changeset
   537
    then show ?thesis by blast
cb0929421ca6 tuned proofs;
wenzelm
parents: 56776
diff changeset
   538
  next
cb0929421ca6 tuned proofs;
wenzelm
parents: 56776
diff changeset
   539
    case False
77303
3c4aca1266eb Simplifying more proofs
paulson <lp15@cam.ac.uk>
parents: 77282
diff changeset
   540
    obtain q where q: "psize q = psize p" "\<forall>x. poly q x = ?p (c + x)"
3c4aca1266eb Simplifying more proofs
paulson <lp15@cam.ac.uk>
parents: 77282
diff changeset
   541
      using poly_offset[of p c] by blast
56778
cb0929421ca6 tuned proofs;
wenzelm
parents: 56776
diff changeset
   542
    then have qnc: "\<not> constant (poly q)"
77303
3c4aca1266eb Simplifying more proofs
paulson <lp15@cam.ac.uk>
parents: 77282
diff changeset
   543
      by (metis (no_types, opaque_lifting) add.commute constant_def diff_add_cancel less.prems)
56778
cb0929421ca6 tuned proofs;
wenzelm
parents: 56776
diff changeset
   544
    from q(2) have pqc0: "?p c = poly q 0"
cb0929421ca6 tuned proofs;
wenzelm
parents: 56776
diff changeset
   545
      by simp
cb0929421ca6 tuned proofs;
wenzelm
parents: 56776
diff changeset
   546
    from c pqc0 have cq0: "\<forall>w. cmod (poly q 0) \<le> cmod (?p w)"
cb0929421ca6 tuned proofs;
wenzelm
parents: 56776
diff changeset
   547
      by simp
26123
44384b5c4fc0 A proof a the fundamental theorem of algebra
chaieb
parents:
diff changeset
   548
    let ?a0 = "poly q 0"
60424
c96fff9dcdbc misc tuning;
wenzelm
parents: 59557
diff changeset
   549
    from False pqc0 have a00: "?a0 \<noteq> 0"
56778
cb0929421ca6 tuned proofs;
wenzelm
parents: 56776
diff changeset
   550
      by simp
cb0929421ca6 tuned proofs;
wenzelm
parents: 56776
diff changeset
   551
    from a00 have qr: "\<forall>z. poly q z = poly (smult (inverse ?a0) q) z * ?a0"
29464
c0d225a7f6ff convert Fundamental_Theorem_Algebra.thy to use new Polynomial library
huffman
parents: 29292
diff changeset
   552
      by simp
c0d225a7f6ff convert Fundamental_Theorem_Algebra.thy to use new Polynomial library
huffman
parents: 29292
diff changeset
   553
    let ?r = "smult (inverse ?a0) q"
29538
5cc98af1398d rename plength to psize
huffman
parents: 29485
diff changeset
   554
    have lgqr: "psize q = psize ?r"
77282
3fc7c85fdbb5 Tidied some really messy proofs
paulson <lp15@cam.ac.uk>
parents: 69529
diff changeset
   555
      by (simp add: a00 psize_def)
77303
3c4aca1266eb Simplifying more proofs
paulson <lp15@cam.ac.uk>
parents: 77282
diff changeset
   556
    have rnc: "\<not> constant (poly ?r)"
3c4aca1266eb Simplifying more proofs
paulson <lp15@cam.ac.uk>
parents: 77282
diff changeset
   557
      using constant_def qnc qr by fastforce 
3c4aca1266eb Simplifying more proofs
paulson <lp15@cam.ac.uk>
parents: 77282
diff changeset
   558
    have r01: "poly ?r 0 = 1"
3c4aca1266eb Simplifying more proofs
paulson <lp15@cam.ac.uk>
parents: 77282
diff changeset
   559
      by (simp add: a00)
60424
c96fff9dcdbc misc tuning;
wenzelm
parents: 59557
diff changeset
   560
    have mrmq_eq: "cmod (poly ?r w) < 1 \<longleftrightarrow> cmod (poly q w) < cmod ?a0" for w
77282
3fc7c85fdbb5 Tidied some really messy proofs
paulson <lp15@cam.ac.uk>
parents: 69529
diff changeset
   561
      by (smt (verit, del_insts) a00 mult_less_cancel_right2 norm_mult qr zero_less_norm_iff)
30488
5c4c3a9e9102 remove trailing spaces
huffman
parents: 30242
diff changeset
   562
    from poly_decompose[OF rnc] obtain k a s where
56778
cb0929421ca6 tuned proofs;
wenzelm
parents: 56776
diff changeset
   563
      kas: "a \<noteq> 0" "k \<noteq> 0" "psize s + k + 1 = psize ?r"
cb0929421ca6 tuned proofs;
wenzelm
parents: 56776
diff changeset
   564
        "\<forall>z. poly ?r z = poly ?r 0 + z^k* poly (pCons a s) z" by blast
60424
c96fff9dcdbc misc tuning;
wenzelm
parents: 59557
diff changeset
   565
    have "\<exists>w. cmod (poly ?r w) < 1"
c96fff9dcdbc misc tuning;
wenzelm
parents: 59557
diff changeset
   566
    proof (cases "psize p = k + 1")
77341
127a51771f34 Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 77303
diff changeset
   567
      case True 
127a51771f34 Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 77303
diff changeset
   568
      with kas q have s0: "s = 0"
127a51771f34 Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 77303
diff changeset
   569
        by (simp add: lgqr)
77303
3c4aca1266eb Simplifying more proofs
paulson <lp15@cam.ac.uk>
parents: 77282
diff changeset
   570
      with reduce_poly_simple kas show ?thesis
3c4aca1266eb Simplifying more proofs
paulson <lp15@cam.ac.uk>
parents: 77282
diff changeset
   571
        by (metis mult.commute mult.right_neutral poly_1 poly_smult r01 smult_one)
60424
c96fff9dcdbc misc tuning;
wenzelm
parents: 59557
diff changeset
   572
    next
c96fff9dcdbc misc tuning;
wenzelm
parents: 59557
diff changeset
   573
      case False note kn = this
56778
cb0929421ca6 tuned proofs;
wenzelm
parents: 56776
diff changeset
   574
      from kn kas(3) q(1) lgqr have k1n: "k + 1 < psize p"
cb0929421ca6 tuned proofs;
wenzelm
parents: 56776
diff changeset
   575
        by simp
77303
3c4aca1266eb Simplifying more proofs
paulson <lp15@cam.ac.uk>
parents: 77282
diff changeset
   576
      have 01: "\<not> constant (poly (pCons 1 (monom a (k - 1))))"
32960
69916a850301 eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents: 32456
diff changeset
   577
        unfolding constant_def poly_pCons poly_monom
77282
3fc7c85fdbb5 Tidied some really messy proofs
paulson <lp15@cam.ac.uk>
parents: 69529
diff changeset
   578
        by (metis add_cancel_left_right kas(1) mult.commute mult_cancel_right2 power_one)
77341
127a51771f34 Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 77303
diff changeset
   579
      have 02: "k + 1 = psize (pCons 1 (monom a (k - 1)))"
127a51771f34 Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 77303
diff changeset
   580
        using kas by (simp add: psize_def degree_monom_eq)
127a51771f34 Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 77303
diff changeset
   581
      from less(1) [OF _ 01] k1n 02
26123
44384b5c4fc0 A proof a the fundamental theorem of algebra
chaieb
parents:
diff changeset
   582
      obtain w where w: "1 + w^k * a = 0"
77303
3c4aca1266eb Simplifying more proofs
paulson <lp15@cam.ac.uk>
parents: 77282
diff changeset
   583
        by (metis kas(2) mult.commute mult.left_commute poly_monom poly_pCons power_eq_if)
30488
5c4c3a9e9102 remove trailing spaces
huffman
parents: 30242
diff changeset
   584
      from poly_bound_exists[of "cmod w" s] obtain m where
32960
69916a850301 eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents: 32456
diff changeset
   585
        m: "m > 0" "\<forall>z. cmod z \<le> cmod w \<longrightarrow> cmod (poly s z) \<le> m" by blast
77303
3c4aca1266eb Simplifying more proofs
paulson <lp15@cam.ac.uk>
parents: 77282
diff changeset
   586
      have "w \<noteq> 0"
56795
e8cce2bd23e5 tuned proofs;
wenzelm
parents: 56778
diff changeset
   587
        using kas(2) w by (auto simp add: power_0_left)
77303
3c4aca1266eb Simplifying more proofs
paulson <lp15@cam.ac.uk>
parents: 77282
diff changeset
   588
      from w have wm1: "w^k * a = - 1"
3c4aca1266eb Simplifying more proofs
paulson <lp15@cam.ac.uk>
parents: 77282
diff changeset
   589
        by (simp add: add_eq_0_iff)
30488
5c4c3a9e9102 remove trailing spaces
huffman
parents: 30242
diff changeset
   590
      have inv0: "0 < inverse (cmod w ^ (k + 1) * m)"
77303
3c4aca1266eb Simplifying more proofs
paulson <lp15@cam.ac.uk>
parents: 77282
diff changeset
   591
        by (simp add: \<open>w \<noteq> 0\<close> m(1))
68527
2f4e2aab190a Generalising and renaming some basic results
paulson <lp15@cam.ac.uk>
parents: 66447
diff changeset
   592
      with field_lbound_gt_zero[OF zero_less_one] obtain t where
32960
69916a850301 eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents: 32456
diff changeset
   593
        t: "t > 0" "t < 1" "t < inverse (cmod w ^ (k + 1) * m)" by blast
26123
44384b5c4fc0 A proof a the fundamental theorem of algebra
chaieb
parents:
diff changeset
   594
      let ?ct = "complex_of_real t"
44384b5c4fc0 A proof a the fundamental theorem of algebra
chaieb
parents:
diff changeset
   595
      let ?w = "?ct * w"
56778
cb0929421ca6 tuned proofs;
wenzelm
parents: 56776
diff changeset
   596
      have "1 + ?w^k * (a + ?w * poly s ?w) = 1 + ?ct^k * (w^k * a) + ?w^k * ?w * poly s ?w"
cb0929421ca6 tuned proofs;
wenzelm
parents: 56776
diff changeset
   597
        using kas(1) by (simp add: algebra_simps power_mult_distrib)
26123
44384b5c4fc0 A proof a the fundamental theorem of algebra
chaieb
parents:
diff changeset
   598
      also have "\<dots> = complex_of_real (1 - t^k) + ?w^k * ?w * poly s ?w"
56778
cb0929421ca6 tuned proofs;
wenzelm
parents: 56776
diff changeset
   599
        unfolding wm1 by simp
cb0929421ca6 tuned proofs;
wenzelm
parents: 56776
diff changeset
   600
      finally have "cmod (1 + ?w^k * (a + ?w * poly s ?w)) =
cb0929421ca6 tuned proofs;
wenzelm
parents: 56776
diff changeset
   601
        cmod (complex_of_real (1 - t^k) + ?w^k * ?w * poly s ?w)"
55358
85d81bc281d0 Simplified some proofs, deleting a lot of strange unused material at the end of the theory.
paulson <lp15@cam.ac.uk>
parents: 54489
diff changeset
   602
        by metis
30488
5c4c3a9e9102 remove trailing spaces
huffman
parents: 30242
diff changeset
   603
      with norm_triangle_ineq[of "complex_of_real (1 - t^k)" "?w^k * ?w * poly s ?w"]
77303
3c4aca1266eb Simplifying more proofs
paulson <lp15@cam.ac.uk>
parents: 77282
diff changeset
   604
      have 11: "cmod (1 + ?w^k * (a + ?w * poly s ?w)) \<le> \<bar>1 - t^k\<bar> + cmod (?w^k * ?w * poly s ?w)"
56778
cb0929421ca6 tuned proofs;
wenzelm
parents: 56776
diff changeset
   605
        unfolding norm_of_real by simp
cb0929421ca6 tuned proofs;
wenzelm
parents: 56776
diff changeset
   606
      have ath: "\<And>x t::real. 0 \<le> x \<Longrightarrow> x < t \<Longrightarrow> t \<le> 1 \<Longrightarrow> \<bar>1 - t\<bar> + x < 1"
cb0929421ca6 tuned proofs;
wenzelm
parents: 56776
diff changeset
   607
        by arith
77303
3c4aca1266eb Simplifying more proofs
paulson <lp15@cam.ac.uk>
parents: 77282
diff changeset
   608
      have tw: "cmod ?w \<le> cmod w"
3c4aca1266eb Simplifying more proofs
paulson <lp15@cam.ac.uk>
parents: 77282
diff changeset
   609
        by (smt (verit) mult_le_cancel_right2 norm_ge_zero norm_mult norm_of_real t)
3c4aca1266eb Simplifying more proofs
paulson <lp15@cam.ac.uk>
parents: 77282
diff changeset
   610
      have "t * (cmod w ^ (k + 1) * m) < 1"
3c4aca1266eb Simplifying more proofs
paulson <lp15@cam.ac.uk>
parents: 77282
diff changeset
   611
        by (smt (verit, best) inv0 inverse_positive_iff_positive left_inverse mult_strict_right_mono t(3))
77341
127a51771f34 Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 77303
diff changeset
   612
      with zero_less_power[OF t(1), of k] have 30: "t^k * (t* (cmod w ^ (k + 1) * m)) < t^k"
59557
ebd8ecacfba6 establish unique preferred fact names
haftmann
parents: 59555
diff changeset
   613
        by simp
56778
cb0929421ca6 tuned proofs;
wenzelm
parents: 56776
diff changeset
   614
      have "cmod (?w^k * ?w * poly s ?w) = t^k * (t* (cmod w ^ (k + 1) * cmod (poly s ?w)))"
77303
3c4aca1266eb Simplifying more proofs
paulson <lp15@cam.ac.uk>
parents: 77282
diff changeset
   615
        using \<open>w \<noteq> 0\<close> t(1) by (simp add: algebra_simps norm_power norm_mult)
3c4aca1266eb Simplifying more proofs
paulson <lp15@cam.ac.uk>
parents: 77282
diff changeset
   616
      with 30 have 120: "cmod (?w^k * ?w * poly s ?w) < t^k"
3c4aca1266eb Simplifying more proofs
paulson <lp15@cam.ac.uk>
parents: 77282
diff changeset
   617
        by (smt (verit, ccfv_SIG) m(2) mult_left_mono norm_ge_zero t(1) tw zero_le_power)
3c4aca1266eb Simplifying more proofs
paulson <lp15@cam.ac.uk>
parents: 77282
diff changeset
   618
      from power_strict_mono[OF t(2), of k] t(1) kas(2) have 121: "t^k \<le> 1"
55358
85d81bc281d0 Simplified some proofs, deleting a lot of strange unused material at the end of the theory.
paulson <lp15@cam.ac.uk>
parents: 54489
diff changeset
   619
        by auto
77303
3c4aca1266eb Simplifying more proofs
paulson <lp15@cam.ac.uk>
parents: 77282
diff changeset
   620
      from ath[OF norm_ge_zero[of "?w^k * ?w * poly s ?w"] 120 121]
77341
127a51771f34 Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 77303
diff changeset
   621
      show ?thesis
77303
3c4aca1266eb Simplifying more proofs
paulson <lp15@cam.ac.uk>
parents: 77282
diff changeset
   622
        by (smt (verit) "11" kas(4) poly_pCons r01)
60424
c96fff9dcdbc misc tuning;
wenzelm
parents: 59557
diff changeset
   623
    qed
c96fff9dcdbc misc tuning;
wenzelm
parents: 59557
diff changeset
   624
    with cq0 q(2) show ?thesis
77303
3c4aca1266eb Simplifying more proofs
paulson <lp15@cam.ac.uk>
parents: 77282
diff changeset
   625
      by (smt (verit) mrmq_eq)
56778
cb0929421ca6 tuned proofs;
wenzelm
parents: 56776
diff changeset
   626
  qed
26123
44384b5c4fc0 A proof a the fundamental theorem of algebra
chaieb
parents:
diff changeset
   627
qed
44384b5c4fc0 A proof a the fundamental theorem of algebra
chaieb
parents:
diff changeset
   628
60424
c96fff9dcdbc misc tuning;
wenzelm
parents: 59557
diff changeset
   629
text \<open>Alternative version with a syntactic notion of constant polynomial.\<close>
26123
44384b5c4fc0 A proof a the fundamental theorem of algebra
chaieb
parents:
diff changeset
   630
44384b5c4fc0 A proof a the fundamental theorem of algebra
chaieb
parents:
diff changeset
   631
lemma fundamental_theorem_of_algebra_alt:
56778
cb0929421ca6 tuned proofs;
wenzelm
parents: 56776
diff changeset
   632
  assumes nc: "\<not> (\<exists>a l. a \<noteq> 0 \<and> l = 0 \<and> p = pCons a l)"
26123
44384b5c4fc0 A proof a the fundamental theorem of algebra
chaieb
parents:
diff changeset
   633
  shows "\<exists>z. poly p z = (0::complex)"
77341
127a51771f34 Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 77303
diff changeset
   634
proof (rule ccontr)
127a51771f34 Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 77303
diff changeset
   635
  assume N: "\<nexists>z. poly p z = 0"
127a51771f34 Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 77303
diff changeset
   636
  then have "\<not> constant (poly p)"
127a51771f34 Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 77303
diff changeset
   637
    unfolding constant_def
127a51771f34 Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 77303
diff changeset
   638
    by (metis (no_types, opaque_lifting) nc poly_pcompose pcompose_0' pcompose_const poly_0_coeff_0 
127a51771f34 Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 77303
diff changeset
   639
        poly_all_0_iff_0 poly_diff right_minus_eq)
127a51771f34 Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 77303
diff changeset
   640
  then show False
127a51771f34 Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 77303
diff changeset
   641
    using N fundamental_theorem_of_algebra by blast
56778
cb0929421ca6 tuned proofs;
wenzelm
parents: 56776
diff changeset
   642
qed
26123
44384b5c4fc0 A proof a the fundamental theorem of algebra
chaieb
parents:
diff changeset
   643
60424
c96fff9dcdbc misc tuning;
wenzelm
parents: 59557
diff changeset
   644
subsection \<open>Nullstellensatz, degrees and divisibility of polynomials\<close>
26123
44384b5c4fc0 A proof a the fundamental theorem of algebra
chaieb
parents:
diff changeset
   645
44384b5c4fc0 A proof a the fundamental theorem of algebra
chaieb
parents:
diff changeset
   646
lemma nullstellensatz_lemma:
29464
c0d225a7f6ff convert Fundamental_Theorem_Algebra.thy to use new Polynomial library
huffman
parents: 29292
diff changeset
   647
  fixes p :: "complex poly"
26123
44384b5c4fc0 A proof a the fundamental theorem of algebra
chaieb
parents:
diff changeset
   648
  assumes "\<forall>x. poly p x = 0 \<longrightarrow> poly q x = 0"
56776
309e1a61ee7c tuned proofs;
wenzelm
parents: 56544
diff changeset
   649
    and "degree p = n"
309e1a61ee7c tuned proofs;
wenzelm
parents: 56544
diff changeset
   650
    and "n \<noteq> 0"
29464
c0d225a7f6ff convert Fundamental_Theorem_Algebra.thy to use new Polynomial library
huffman
parents: 29292
diff changeset
   651
  shows "p dvd (q ^ n)"
56776
309e1a61ee7c tuned proofs;
wenzelm
parents: 56544
diff changeset
   652
  using assms
309e1a61ee7c tuned proofs;
wenzelm
parents: 56544
diff changeset
   653
proof (induct n arbitrary: p q rule: nat_less_induct)
309e1a61ee7c tuned proofs;
wenzelm
parents: 56544
diff changeset
   654
  fix n :: nat
309e1a61ee7c tuned proofs;
wenzelm
parents: 56544
diff changeset
   655
  fix p q :: "complex poly"
26123
44384b5c4fc0 A proof a the fundamental theorem of algebra
chaieb
parents:
diff changeset
   656
  assume IH: "\<forall>m<n. \<forall>p q.
44384b5c4fc0 A proof a the fundamental theorem of algebra
chaieb
parents:
diff changeset
   657
                 (\<forall>x. poly p x = (0::complex) \<longrightarrow> poly q x = 0) \<longrightarrow>
29464
c0d225a7f6ff convert Fundamental_Theorem_Algebra.thy to use new Polynomial library
huffman
parents: 29292
diff changeset
   658
                 degree p = m \<longrightarrow> m \<noteq> 0 \<longrightarrow> p dvd (q ^ m)"
30488
5c4c3a9e9102 remove trailing spaces
huffman
parents: 30242
diff changeset
   659
    and pq0: "\<forall>x. poly p x = 0 \<longrightarrow> poly q x = 0"
56778
cb0929421ca6 tuned proofs;
wenzelm
parents: 56776
diff changeset
   660
    and dpn: "degree p = n"
cb0929421ca6 tuned proofs;
wenzelm
parents: 56776
diff changeset
   661
    and n0: "n \<noteq> 0"
29464
c0d225a7f6ff convert Fundamental_Theorem_Algebra.thy to use new Polynomial library
huffman
parents: 29292
diff changeset
   662
  from dpn n0 have pne: "p \<noteq> 0" by auto
60557
5854821993d2 tuned proofs;
wenzelm
parents: 60457
diff changeset
   663
  show "p dvd (q ^ n)"
5854821993d2 tuned proofs;
wenzelm
parents: 60457
diff changeset
   664
  proof (cases "\<exists>a. poly p a = 0")
5854821993d2 tuned proofs;
wenzelm
parents: 60457
diff changeset
   665
    case True
5854821993d2 tuned proofs;
wenzelm
parents: 60457
diff changeset
   666
    then obtain a where a: "poly p a = 0" ..
5854821993d2 tuned proofs;
wenzelm
parents: 60457
diff changeset
   667
    have ?thesis if oa: "order a p \<noteq> 0"
60424
c96fff9dcdbc misc tuning;
wenzelm
parents: 59557
diff changeset
   668
    proof -
26123
44384b5c4fc0 A proof a the fundamental theorem of algebra
chaieb
parents:
diff changeset
   669
      let ?op = "order a p"
56778
cb0929421ca6 tuned proofs;
wenzelm
parents: 56776
diff changeset
   670
      from pne have ap: "([:- a, 1:] ^ ?op) dvd p" "\<not> [:- a, 1:] ^ (Suc ?op) dvd p"
cb0929421ca6 tuned proofs;
wenzelm
parents: 56776
diff changeset
   671
        using order by blast+
29464
c0d225a7f6ff convert Fundamental_Theorem_Algebra.thy to use new Polynomial library
huffman
parents: 29292
diff changeset
   672
      note oop = order_degree[OF pne, unfolded dpn]
60424
c96fff9dcdbc misc tuning;
wenzelm
parents: 59557
diff changeset
   673
      show ?thesis
c96fff9dcdbc misc tuning;
wenzelm
parents: 59557
diff changeset
   674
      proof (cases "q = 0")
c96fff9dcdbc misc tuning;
wenzelm
parents: 59557
diff changeset
   675
        case True
c96fff9dcdbc misc tuning;
wenzelm
parents: 59557
diff changeset
   676
        with n0 show ?thesis by (simp add: power_0_left)
c96fff9dcdbc misc tuning;
wenzelm
parents: 59557
diff changeset
   677
      next
c96fff9dcdbc misc tuning;
wenzelm
parents: 59557
diff changeset
   678
        case False
32960
69916a850301 eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents: 32456
diff changeset
   679
        from pq0[rule_format, OF a, unfolded poly_eq_0_iff_dvd]
69916a850301 eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents: 32456
diff changeset
   680
        obtain r where r: "q = [:- a, 1:] * r" by (rule dvdE)
56778
cb0929421ca6 tuned proofs;
wenzelm
parents: 56776
diff changeset
   681
        from ap(1) obtain s where s: "p = [:- a, 1:] ^ ?op * s"
cb0929421ca6 tuned proofs;
wenzelm
parents: 56776
diff changeset
   682
          by (rule dvdE)
60424
c96fff9dcdbc misc tuning;
wenzelm
parents: 59557
diff changeset
   683
        have sne: "s \<noteq> 0"
c96fff9dcdbc misc tuning;
wenzelm
parents: 59557
diff changeset
   684
          using s pne by auto
c96fff9dcdbc misc tuning;
wenzelm
parents: 59557
diff changeset
   685
        show ?thesis
c96fff9dcdbc misc tuning;
wenzelm
parents: 59557
diff changeset
   686
        proof (cases "degree s = 0")
c96fff9dcdbc misc tuning;
wenzelm
parents: 59557
diff changeset
   687
          case True
c96fff9dcdbc misc tuning;
wenzelm
parents: 59557
diff changeset
   688
          then obtain k where kpn: "s = [:k:]"
51541
e7b6b61b7be2 tuned proofs;
wenzelm
parents: 51537
diff changeset
   689
            by (cases s) (auto split: if_splits)
29464
c0d225a7f6ff convert Fundamental_Theorem_Algebra.thy to use new Polynomial library
huffman
parents: 29292
diff changeset
   690
          from sne kpn have k: "k \<noteq> 0" by simp
32960
69916a850301 eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents: 32456
diff changeset
   691
          let ?w = "([:1/k:] * ([:-a,1:] ^ (n - ?op))) * (r ^ n)"
77341
127a51771f34 Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 77303
diff changeset
   692
          have "q^n = [:- a, 1:] ^ n * r ^ n"
127a51771f34 Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 77303
diff changeset
   693
            using power_mult_distrib r by blast
127a51771f34 Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 77303
diff changeset
   694
          also have "... = [:- a, 1:] ^ order a p * [:k:] * ([:1 / k:] * [:- a, 1:] ^ (n - order a p) * r ^ n)"
127a51771f34 Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 77303
diff changeset
   695
            using k oop [of a] by (simp flip: power_add)
127a51771f34 Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 77303
diff changeset
   696
          also have "... = p * ?w"
127a51771f34 Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 77303
diff changeset
   697
            by (metis s kpn)
127a51771f34 Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 77303
diff changeset
   698
          finally show ?thesis
56795
e8cce2bd23e5 tuned proofs;
wenzelm
parents: 56778
diff changeset
   699
            unfolding dvd_def by blast
60424
c96fff9dcdbc misc tuning;
wenzelm
parents: 59557
diff changeset
   700
        next
c96fff9dcdbc misc tuning;
wenzelm
parents: 59557
diff changeset
   701
          case False
c96fff9dcdbc misc tuning;
wenzelm
parents: 59557
diff changeset
   702
          with sne dpn s oa have dsn: "degree s < n"
77341
127a51771f34 Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 77303
diff changeset
   703
            by (metis add_diff_cancel_right' degree_0 degree_linear_power degree_mult_eq gr0I zero_less_diff)
60557
5854821993d2 tuned proofs;
wenzelm
parents: 60457
diff changeset
   704
          have "poly r x = 0" if h: "poly s x = 0" for x
5854821993d2 tuned proofs;
wenzelm
parents: 60457
diff changeset
   705
          proof -
77341
127a51771f34 Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 77303
diff changeset
   706
            have "x \<noteq> a"
127a51771f34 Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 77303
diff changeset
   707
              by (metis ap(2) dvd_refl mult_dvd_mono poly_eq_0_iff_dvd power_Suc power_commutes s that)
127a51771f34 Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 77303
diff changeset
   708
            moreover have "poly p x = 0"
127a51771f34 Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 77303
diff changeset
   709
              by (metis (no_types) mult_eq_0_iff poly_mult s that)
127a51771f34 Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 77303
diff changeset
   710
            ultimately show ?thesis
127a51771f34 Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 77303
diff changeset
   711
              using pq0 r by auto
60557
5854821993d2 tuned proofs;
wenzelm
parents: 60457
diff changeset
   712
          qed
77303
3c4aca1266eb Simplifying more proofs
paulson <lp15@cam.ac.uk>
parents: 77282
diff changeset
   713
          with False IH dsn obtain u where u: "r ^ (degree s) = s * u"
60557
5854821993d2 tuned proofs;
wenzelm
parents: 60457
diff changeset
   714
            by blast
5854821993d2 tuned proofs;
wenzelm
parents: 60457
diff changeset
   715
          then have u': "\<And>x. poly s x * poly u x = poly r x ^ degree s"
5854821993d2 tuned proofs;
wenzelm
parents: 60457
diff changeset
   716
            by (simp only: poly_mult[symmetric] poly_power[symmetric])
77341
127a51771f34 Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 77303
diff changeset
   717
          have "q^n = [:- a, 1:] ^ n * r ^ n"
127a51771f34 Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 77303
diff changeset
   718
            using power_mult_distrib r by blast
127a51771f34 Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 77303
diff changeset
   719
          also have "... = [:- a, 1:] ^ order a p * (s * u * ([:- a, 1:] ^ (n - order a p) * r ^ (n - degree s)))"
127a51771f34 Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 77303
diff changeset
   720
            by (smt (verit, del_insts) s u mult_ac power_add add_diff_cancel_right' degree_linear_power degree_mult_eq dpn mult_zero_left)
127a51771f34 Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 77303
diff changeset
   721
          also have "... = p * (u * ([:-a,1:] ^ (n - ?op))) * (r ^ (n - degree s))"
127a51771f34 Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 77303
diff changeset
   722
            using s by force
127a51771f34 Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 77303
diff changeset
   723
          finally show ?thesis
127a51771f34 Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 77303
diff changeset
   724
            unfolding dvd_def by auto
60424
c96fff9dcdbc misc tuning;
wenzelm
parents: 59557
diff changeset
   725
        qed
c96fff9dcdbc misc tuning;
wenzelm
parents: 59557
diff changeset
   726
      qed
c96fff9dcdbc misc tuning;
wenzelm
parents: 59557
diff changeset
   727
    qed
60557
5854821993d2 tuned proofs;
wenzelm
parents: 60457
diff changeset
   728
    then show ?thesis
5854821993d2 tuned proofs;
wenzelm
parents: 60457
diff changeset
   729
      using a order_root pne by blast
5854821993d2 tuned proofs;
wenzelm
parents: 60457
diff changeset
   730
  next
5854821993d2 tuned proofs;
wenzelm
parents: 60457
diff changeset
   731
    case False
5854821993d2 tuned proofs;
wenzelm
parents: 60457
diff changeset
   732
    then show ?thesis
77282
3fc7c85fdbb5 Tidied some really messy proofs
paulson <lp15@cam.ac.uk>
parents: 69529
diff changeset
   733
      using dpn n0 fundamental_theorem_of_algebra_alt[of p]
3fc7c85fdbb5 Tidied some really messy proofs
paulson <lp15@cam.ac.uk>
parents: 69529
diff changeset
   734
      by fastforce
60557
5854821993d2 tuned proofs;
wenzelm
parents: 60457
diff changeset
   735
  qed
26123
44384b5c4fc0 A proof a the fundamental theorem of algebra
chaieb
parents:
diff changeset
   736
qed
44384b5c4fc0 A proof a the fundamental theorem of algebra
chaieb
parents:
diff changeset
   737
44384b5c4fc0 A proof a the fundamental theorem of algebra
chaieb
parents:
diff changeset
   738
lemma nullstellensatz_univariate:
30488
5c4c3a9e9102 remove trailing spaces
huffman
parents: 30242
diff changeset
   739
  "(\<forall>x. poly p x = (0::complex) \<longrightarrow> poly q x = 0) \<longleftrightarrow>
29464
c0d225a7f6ff convert Fundamental_Theorem_Algebra.thy to use new Polynomial library
huffman
parents: 29292
diff changeset
   740
    p dvd (q ^ (degree p)) \<or> (p = 0 \<and> q = 0)"
56776
309e1a61ee7c tuned proofs;
wenzelm
parents: 56544
diff changeset
   741
proof -
60457
f31f7599ef55 tuned proofs;
wenzelm
parents: 60449
diff changeset
   742
  consider "p = 0" | "p \<noteq> 0" "degree p = 0" | n where "p \<noteq> 0" "degree p = Suc n"
f31f7599ef55 tuned proofs;
wenzelm
parents: 60449
diff changeset
   743
    by (cases "degree p") auto
f31f7599ef55 tuned proofs;
wenzelm
parents: 60449
diff changeset
   744
  then show ?thesis
f31f7599ef55 tuned proofs;
wenzelm
parents: 60449
diff changeset
   745
  proof cases
60567
19c277ea65ae tuned proofs -- less digits;
wenzelm
parents: 60557
diff changeset
   746
    case p: 1
77303
3c4aca1266eb Simplifying more proofs
paulson <lp15@cam.ac.uk>
parents: 77282
diff changeset
   747
    then have "(\<forall>x. poly p x = (0::complex) \<longrightarrow> poly q x = 0) \<longleftrightarrow> q = 0"
52380
3cc46b8cca5e lifting for primitive definitions;
haftmann
parents: 51541
diff changeset
   748
      by (auto simp add: poly_all_0_iff_0)
77303
3c4aca1266eb Simplifying more proofs
paulson <lp15@cam.ac.uk>
parents: 77282
diff changeset
   749
    with p show ?thesis
3c4aca1266eb Simplifying more proofs
paulson <lp15@cam.ac.uk>
parents: 77282
diff changeset
   750
      by force
60424
c96fff9dcdbc misc tuning;
wenzelm
parents: 59557
diff changeset
   751
  next
60567
19c277ea65ae tuned proofs -- less digits;
wenzelm
parents: 60557
diff changeset
   752
    case dp: 2
77282
3fc7c85fdbb5 Tidied some really messy proofs
paulson <lp15@cam.ac.uk>
parents: 69529
diff changeset
   753
    then show ?thesis
77303
3c4aca1266eb Simplifying more proofs
paulson <lp15@cam.ac.uk>
parents: 77282
diff changeset
   754
      by (meson dvd_trans is_unit_iff_degree poly_eq_0_iff_dvd unit_imp_dvd)
60457
f31f7599ef55 tuned proofs;
wenzelm
parents: 60449
diff changeset
   755
  next
60567
19c277ea65ae tuned proofs -- less digits;
wenzelm
parents: 60557
diff changeset
   756
    case dp: 3
77282
3fc7c85fdbb5 Tidied some really messy proofs
paulson <lp15@cam.ac.uk>
parents: 69529
diff changeset
   757
    have False if "p dvd (q ^ (Suc n))" "poly p x = 0" "poly q x \<noteq> 0" for x
3fc7c85fdbb5 Tidied some really messy proofs
paulson <lp15@cam.ac.uk>
parents: 69529
diff changeset
   758
      by (metis dvd_trans poly_eq_0_iff_dvd poly_power power_eq_0_iff that)
60567
19c277ea65ae tuned proofs -- less digits;
wenzelm
parents: 60557
diff changeset
   759
    with dp nullstellensatz_lemma[of p q "degree p"] show ?thesis
19c277ea65ae tuned proofs -- less digits;
wenzelm
parents: 60557
diff changeset
   760
      by auto
60424
c96fff9dcdbc misc tuning;
wenzelm
parents: 59557
diff changeset
   761
  qed
26123
44384b5c4fc0 A proof a the fundamental theorem of algebra
chaieb
parents:
diff changeset
   762
qed
44384b5c4fc0 A proof a the fundamental theorem of algebra
chaieb
parents:
diff changeset
   763
60424
c96fff9dcdbc misc tuning;
wenzelm
parents: 59557
diff changeset
   764
text \<open>Useful lemma\<close>
29464
c0d225a7f6ff convert Fundamental_Theorem_Algebra.thy to use new Polynomial library
huffman
parents: 29292
diff changeset
   765
lemma constant_degree:
c0d225a7f6ff convert Fundamental_Theorem_Algebra.thy to use new Polynomial library
huffman
parents: 29292
diff changeset
   766
  fixes p :: "'a::{idom,ring_char_0} poly"
c0d225a7f6ff convert Fundamental_Theorem_Algebra.thy to use new Polynomial library
huffman
parents: 29292
diff changeset
   767
  shows "constant (poly p) \<longleftrightarrow> degree p = 0" (is "?lhs = ?rhs")
26123
44384b5c4fc0 A proof a the fundamental theorem of algebra
chaieb
parents:
diff changeset
   768
proof
60557
5854821993d2 tuned proofs;
wenzelm
parents: 60457
diff changeset
   769
  show ?rhs if ?lhs
5854821993d2 tuned proofs;
wenzelm
parents: 60457
diff changeset
   770
  proof -
5854821993d2 tuned proofs;
wenzelm
parents: 60457
diff changeset
   771
    from that[unfolded constant_def, rule_format, of _ "0"]
77282
3fc7c85fdbb5 Tidied some really messy proofs
paulson <lp15@cam.ac.uk>
parents: 69529
diff changeset
   772
    have "poly p = poly [:poly p 0:]"
60557
5854821993d2 tuned proofs;
wenzelm
parents: 60457
diff changeset
   773
      by auto
5854821993d2 tuned proofs;
wenzelm
parents: 60457
diff changeset
   774
    then show ?thesis
77282
3fc7c85fdbb5 Tidied some really messy proofs
paulson <lp15@cam.ac.uk>
parents: 69529
diff changeset
   775
      by (metis degree_pCons_0 poly_eq_poly_eq_iff)
60557
5854821993d2 tuned proofs;
wenzelm
parents: 60457
diff changeset
   776
  qed
5854821993d2 tuned proofs;
wenzelm
parents: 60457
diff changeset
   777
  show ?lhs if ?rhs
77303
3c4aca1266eb Simplifying more proofs
paulson <lp15@cam.ac.uk>
parents: 77282
diff changeset
   778
    unfolding constant_def
3c4aca1266eb Simplifying more proofs
paulson <lp15@cam.ac.uk>
parents: 77282
diff changeset
   779
    by (metis degree_eq_zeroE pcompose_const poly_0 poly_pcompose that)
26123
44384b5c4fc0 A proof a the fundamental theorem of algebra
chaieb
parents:
diff changeset
   780
qed
44384b5c4fc0 A proof a the fundamental theorem of algebra
chaieb
parents:
diff changeset
   781
60424
c96fff9dcdbc misc tuning;
wenzelm
parents: 59557
diff changeset
   782
text \<open>Arithmetic operations on multivariate polynomials.\<close>
26123
44384b5c4fc0 A proof a the fundamental theorem of algebra
chaieb
parents:
diff changeset
   783
30488
5c4c3a9e9102 remove trailing spaces
huffman
parents: 30242
diff changeset
   784
lemma mpoly_base_conv:
56778
cb0929421ca6 tuned proofs;
wenzelm
parents: 56776
diff changeset
   785
  fixes x :: "'a::comm_ring_1"
55735
81ba62493610 generalised some results using type classes
paulson <lp15@cam.ac.uk>
parents: 55734
diff changeset
   786
  shows "0 = poly 0 x" "c = poly [:c:] x" "x = poly [:0,1:] x"
81ba62493610 generalised some results using type classes
paulson <lp15@cam.ac.uk>
parents: 55734
diff changeset
   787
  by simp_all
26123
44384b5c4fc0 A proof a the fundamental theorem of algebra
chaieb
parents:
diff changeset
   788
30488
5c4c3a9e9102 remove trailing spaces
huffman
parents: 30242
diff changeset
   789
lemma mpoly_norm_conv:
56778
cb0929421ca6 tuned proofs;
wenzelm
parents: 56776
diff changeset
   790
  fixes x :: "'a::comm_ring_1"
56776
309e1a61ee7c tuned proofs;
wenzelm
parents: 56544
diff changeset
   791
  shows "poly [:0:] x = poly 0 x" "poly [:poly 0 y:] x = poly 0 x"
309e1a61ee7c tuned proofs;
wenzelm
parents: 56544
diff changeset
   792
  by simp_all
26123
44384b5c4fc0 A proof a the fundamental theorem of algebra
chaieb
parents:
diff changeset
   793
30488
5c4c3a9e9102 remove trailing spaces
huffman
parents: 30242
diff changeset
   794
lemma mpoly_sub_conv:
56778
cb0929421ca6 tuned proofs;
wenzelm
parents: 56776
diff changeset
   795
  fixes x :: "'a::comm_ring_1"
55735
81ba62493610 generalised some results using type classes
paulson <lp15@cam.ac.uk>
parents: 55734
diff changeset
   796
  shows "poly p x - poly q x = poly p x + -1 * poly q x"
54230
b1d955791529 more simplification rules on unary and binary minus
haftmann
parents: 53077
diff changeset
   797
  by simp
26123
44384b5c4fc0 A proof a the fundamental theorem of algebra
chaieb
parents:
diff changeset
   798
56778
cb0929421ca6 tuned proofs;
wenzelm
parents: 56776
diff changeset
   799
lemma poly_pad_rule: "poly p x = 0 \<Longrightarrow> poly (pCons 0 p) x = 0"
cb0929421ca6 tuned proofs;
wenzelm
parents: 56776
diff changeset
   800
  by simp
26123
44384b5c4fc0 A proof a the fundamental theorem of algebra
chaieb
parents:
diff changeset
   801
55735
81ba62493610 generalised some results using type classes
paulson <lp15@cam.ac.uk>
parents: 55734
diff changeset
   802
lemma poly_cancel_eq_conv:
56778
cb0929421ca6 tuned proofs;
wenzelm
parents: 56776
diff changeset
   803
  fixes x :: "'a::field"
56795
e8cce2bd23e5 tuned proofs;
wenzelm
parents: 56778
diff changeset
   804
  shows "x = 0 \<Longrightarrow> a \<noteq> 0 \<Longrightarrow> y = 0 \<longleftrightarrow> a * y - b * x = 0"
55735
81ba62493610 generalised some results using type classes
paulson <lp15@cam.ac.uk>
parents: 55734
diff changeset
   805
  by auto
26123
44384b5c4fc0 A proof a the fundamental theorem of algebra
chaieb
parents:
diff changeset
   806
30488
5c4c3a9e9102 remove trailing spaces
huffman
parents: 30242
diff changeset
   807
lemma poly_divides_pad_rule:
56778
cb0929421ca6 tuned proofs;
wenzelm
parents: 56776
diff changeset
   808
  fixes p:: "('a::comm_ring_1) poly"
29464
c0d225a7f6ff convert Fundamental_Theorem_Algebra.thy to use new Polynomial library
huffman
parents: 29292
diff changeset
   809
  assumes pq: "p dvd q"
56778
cb0929421ca6 tuned proofs;
wenzelm
parents: 56776
diff changeset
   810
  shows "p dvd (pCons 0 q)"
77282
3fc7c85fdbb5 Tidied some really messy proofs
paulson <lp15@cam.ac.uk>
parents: 69529
diff changeset
   811
  by (metis add_0 dvd_def mult_pCons_right pq smult_0_left)
26123
44384b5c4fc0 A proof a the fundamental theorem of algebra
chaieb
parents:
diff changeset
   812
30488
5c4c3a9e9102 remove trailing spaces
huffman
parents: 30242
diff changeset
   813
lemma poly_divides_conv0:
56778
cb0929421ca6 tuned proofs;
wenzelm
parents: 56776
diff changeset
   814
  fixes p:: "'a::field poly"
77282
3fc7c85fdbb5 Tidied some really messy proofs
paulson <lp15@cam.ac.uk>
parents: 69529
diff changeset
   815
  assumes lgpq: "degree q < degree p" and lq: "p \<noteq> 0"
3fc7c85fdbb5 Tidied some really messy proofs
paulson <lp15@cam.ac.uk>
parents: 69529
diff changeset
   816
  shows "p dvd q \<longleftrightarrow> q = 0"
3fc7c85fdbb5 Tidied some really messy proofs
paulson <lp15@cam.ac.uk>
parents: 69529
diff changeset
   817
  using lgpq mod_poly_less by fastforce
26123
44384b5c4fc0 A proof a the fundamental theorem of algebra
chaieb
parents:
diff changeset
   818
30488
5c4c3a9e9102 remove trailing spaces
huffman
parents: 30242
diff changeset
   819
lemma poly_divides_conv1:
56778
cb0929421ca6 tuned proofs;
wenzelm
parents: 56776
diff changeset
   820
  fixes p :: "'a::field poly"
56776
309e1a61ee7c tuned proofs;
wenzelm
parents: 56544
diff changeset
   821
  assumes a0: "a \<noteq> 0"
309e1a61ee7c tuned proofs;
wenzelm
parents: 56544
diff changeset
   822
    and pp': "p dvd p'"
309e1a61ee7c tuned proofs;
wenzelm
parents: 56544
diff changeset
   823
    and qrp': "smult a q - p' = r"
77282
3fc7c85fdbb5 Tidied some really messy proofs
paulson <lp15@cam.ac.uk>
parents: 69529
diff changeset
   824
  shows "p dvd q \<longleftrightarrow> p dvd r"
3fc7c85fdbb5 Tidied some really messy proofs
paulson <lp15@cam.ac.uk>
parents: 69529
diff changeset
   825
  by (metis a0 diff_add_cancel dvd_add_left_iff dvd_smult_iff pp' qrp')
26123
44384b5c4fc0 A proof a the fundamental theorem of algebra
chaieb
parents:
diff changeset
   826
44384b5c4fc0 A proof a the fundamental theorem of algebra
chaieb
parents:
diff changeset
   827
lemma basic_cqe_conv1:
55358
85d81bc281d0 Simplified some proofs, deleting a lot of strange unused material at the end of the theory.
paulson <lp15@cam.ac.uk>
parents: 54489
diff changeset
   828
  "(\<exists>x. poly p x = 0 \<and> poly 0 x \<noteq> 0) \<longleftrightarrow> False"
85d81bc281d0 Simplified some proofs, deleting a lot of strange unused material at the end of the theory.
paulson <lp15@cam.ac.uk>
parents: 54489
diff changeset
   829
  "(\<exists>x. poly 0 x \<noteq> 0) \<longleftrightarrow> False"
56776
309e1a61ee7c tuned proofs;
wenzelm
parents: 56544
diff changeset
   830
  "(\<exists>x. poly [:c:] x \<noteq> 0) \<longleftrightarrow> c \<noteq> 0"
55358
85d81bc281d0 Simplified some proofs, deleting a lot of strange unused material at the end of the theory.
paulson <lp15@cam.ac.uk>
parents: 54489
diff changeset
   831
  "(\<exists>x. poly 0 x = 0) \<longleftrightarrow> True"
56776
309e1a61ee7c tuned proofs;
wenzelm
parents: 56544
diff changeset
   832
  "(\<exists>x. poly [:c:] x = 0) \<longleftrightarrow> c = 0"
309e1a61ee7c tuned proofs;
wenzelm
parents: 56544
diff changeset
   833
  by simp_all
26123
44384b5c4fc0 A proof a the fundamental theorem of algebra
chaieb
parents:
diff changeset
   834
30488
5c4c3a9e9102 remove trailing spaces
huffman
parents: 30242
diff changeset
   835
lemma basic_cqe_conv2:
56795
e8cce2bd23e5 tuned proofs;
wenzelm
parents: 56778
diff changeset
   836
  assumes l: "p \<noteq> 0"
e8cce2bd23e5 tuned proofs;
wenzelm
parents: 56778
diff changeset
   837
  shows "\<exists>x. poly (pCons a (pCons b p)) x = (0::complex)"
77282
3fc7c85fdbb5 Tidied some really messy proofs
paulson <lp15@cam.ac.uk>
parents: 69529
diff changeset
   838
  by (meson fundamental_theorem_of_algebra_alt l pCons_eq_0_iff pCons_eq_iff)
26123
44384b5c4fc0 A proof a the fundamental theorem of algebra
chaieb
parents:
diff changeset
   839
56776
309e1a61ee7c tuned proofs;
wenzelm
parents: 56544
diff changeset
   840
lemma  basic_cqe_conv_2b: "(\<exists>x. poly p x \<noteq> (0::complex)) \<longleftrightarrow> p \<noteq> 0"
309e1a61ee7c tuned proofs;
wenzelm
parents: 56544
diff changeset
   841
  by (metis poly_all_0_iff_0)
26123
44384b5c4fc0 A proof a the fundamental theorem of algebra
chaieb
parents:
diff changeset
   842
44384b5c4fc0 A proof a the fundamental theorem of algebra
chaieb
parents:
diff changeset
   843
lemma basic_cqe_conv3:
29464
c0d225a7f6ff convert Fundamental_Theorem_Algebra.thy to use new Polynomial library
huffman
parents: 29292
diff changeset
   844
  fixes p q :: "complex poly"
30488
5c4c3a9e9102 remove trailing spaces
huffman
parents: 30242
diff changeset
   845
  assumes l: "p \<noteq> 0"
56795
e8cce2bd23e5 tuned proofs;
wenzelm
parents: 56778
diff changeset
   846
  shows "(\<exists>x. poly (pCons a p) x = 0 \<and> poly q x \<noteq> 0) \<longleftrightarrow> \<not> (pCons a p) dvd (q ^ psize p)"
77282
3fc7c85fdbb5 Tidied some really messy proofs
paulson <lp15@cam.ac.uk>
parents: 69529
diff changeset
   847
  by (metis degree_pCons_eq_if l nullstellensatz_univariate pCons_eq_0_iff psize_def)
26123
44384b5c4fc0 A proof a the fundamental theorem of algebra
chaieb
parents:
diff changeset
   848
44384b5c4fc0 A proof a the fundamental theorem of algebra
chaieb
parents:
diff changeset
   849
lemma basic_cqe_conv4:
29464
c0d225a7f6ff convert Fundamental_Theorem_Algebra.thy to use new Polynomial library
huffman
parents: 29292
diff changeset
   850
  fixes p q :: "complex poly"
55358
85d81bc281d0 Simplified some proofs, deleting a lot of strange unused material at the end of the theory.
paulson <lp15@cam.ac.uk>
parents: 54489
diff changeset
   851
  assumes h: "\<And>x. poly (q ^ n) x = poly r x"
85d81bc281d0 Simplified some proofs, deleting a lot of strange unused material at the end of the theory.
paulson <lp15@cam.ac.uk>
parents: 54489
diff changeset
   852
  shows "p dvd (q ^ n) \<longleftrightarrow> p dvd r"
77341
127a51771f34 Simplified some proofs
paulson <lp15@cam.ac.uk>
parents: 77303
diff changeset
   853
  by (metis (no_types) basic_cqe_conv_2b h poly_diff right_minus_eq)
26123
44384b5c4fc0 A proof a the fundamental theorem of algebra
chaieb
parents:
diff changeset
   854
55735
81ba62493610 generalised some results using type classes
paulson <lp15@cam.ac.uk>
parents: 55734
diff changeset
   855
lemma poly_const_conv:
56778
cb0929421ca6 tuned proofs;
wenzelm
parents: 56776
diff changeset
   856
  fixes x :: "'a::comm_ring_1"
56776
309e1a61ee7c tuned proofs;
wenzelm
parents: 56544
diff changeset
   857
  shows "poly [:c:] x = y \<longleftrightarrow> c = y"
309e1a61ee7c tuned proofs;
wenzelm
parents: 56544
diff changeset
   858
  by simp
26123
44384b5c4fc0 A proof a the fundamental theorem of algebra
chaieb
parents:
diff changeset
   859
29464
c0d225a7f6ff convert Fundamental_Theorem_Algebra.thy to use new Polynomial library
huffman
parents: 29292
diff changeset
   860
end