src/HOL/Decision_Procs/Polynomial_List.thy
author wenzelm
Wed, 12 Mar 2025 11:39:00 +0100
changeset 82265 4b875a4c83b0
parent 80098 c06c95576ea9
permissions -rw-r--r--
update for release;
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
33268
02de0317f66f eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents: 33153
diff changeset
     1
(*  Title:      HOL/Decision_Procs/Polynomial_List.thy
02de0317f66f eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents: 33153
diff changeset
     2
    Author:     Amine Chaieb
33153
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
     3
*)
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
     4
60533
1e7ccd864b62 isabelle update_cartouches;
wenzelm
parents: 59807
diff changeset
     5
section \<open>Univariate Polynomials as lists\<close>
33153
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
     6
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
     7
theory Polynomial_List
80098
c06c95576ea9 Tidied some messy proofs
paulson <lp15@cam.ac.uk>
parents: 69597
diff changeset
     8
  imports Complex_Main 
c06c95576ea9 Tidied some messy proofs
paulson <lp15@cam.ac.uk>
parents: 69597
diff changeset
     9
33153
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
    10
begin
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
    11
60536
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
    12
text \<open>Application of polynomial as a function.\<close>
33153
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
    13
54219
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
    14
primrec (in semiring_0) poly :: "'a list \<Rightarrow> 'a \<Rightarrow> 'a"
52778
19fa3e3964f0 tuned proofs;
wenzelm
parents: 49962
diff changeset
    15
where
60536
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
    16
  poly_Nil: "poly [] x = 0"
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
    17
| poly_Cons: "poly (h # t) x = h + x * poly t x"
33153
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
    18
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
    19
60536
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
    20
subsection \<open>Arithmetic Operations on Polynomials\<close>
33153
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
    21
60536
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
    22
text \<open>Addition\<close>
69597
ff784d5a5bfb isabelle update -u control_cartouches;
wenzelm
parents: 69064
diff changeset
    23
primrec (in semiring_0) padd :: "'a list \<Rightarrow> 'a list \<Rightarrow> 'a list"  (infixl \<open>+++\<close> 65)
52778
19fa3e3964f0 tuned proofs;
wenzelm
parents: 49962
diff changeset
    24
where
60536
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
    25
  padd_Nil: "[] +++ l2 = l2"
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
    26
| padd_Cons: "(h # t) +++ l2 = (if l2 = [] then h # t else (h + hd l2) # (t +++ tl l2))"
33153
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
    27
60536
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
    28
text \<open>Multiplication by a constant\<close>
69597
ff784d5a5bfb isabelle update -u control_cartouches;
wenzelm
parents: 69064
diff changeset
    29
primrec (in semiring_0) cmult :: "'a \<Rightarrow> 'a list \<Rightarrow> 'a list"  (infixl \<open>%*\<close> 70) where
60536
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
    30
  cmult_Nil: "c %* [] = []"
54219
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
    31
| cmult_Cons: "c %* (h#t) = (c * h)#(c %* t)"
33153
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
    32
60536
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
    33
text \<open>Multiplication by a polynomial\<close>
69597
ff784d5a5bfb isabelle update -u control_cartouches;
wenzelm
parents: 69064
diff changeset
    34
primrec (in semiring_0) pmult :: "'a list \<Rightarrow> 'a list \<Rightarrow> 'a list"  (infixl \<open>***\<close> 70)
52778
19fa3e3964f0 tuned proofs;
wenzelm
parents: 49962
diff changeset
    35
where
60536
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
    36
  pmult_Nil: "[] *** l2 = []"
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
    37
| pmult_Cons: "(h # t) *** l2 = (if t = [] then h %* l2 else (h %* l2) +++ (0 # (t *** l2)))"
33153
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
    38
60536
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
    39
text \<open>Repeated multiplication by a polynomial\<close>
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
    40
primrec (in semiring_0) mulexp :: "nat \<Rightarrow> 'a list \<Rightarrow> 'a  list \<Rightarrow> 'a list"
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
    41
where
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
    42
  mulexp_zero: "mulexp 0 p q = q"
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
    43
| mulexp_Suc: "mulexp (Suc n) p q = p *** mulexp n p q"
33153
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
    44
60536
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
    45
text \<open>Exponential\<close>
69597
ff784d5a5bfb isabelle update -u control_cartouches;
wenzelm
parents: 69064
diff changeset
    46
primrec (in semiring_1) pexp :: "'a list \<Rightarrow> nat \<Rightarrow> 'a list"  (infixl \<open>%^\<close> 80)
60536
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
    47
where
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
    48
  pexp_0: "p %^ 0 = [1]"
39246
9e58f0499f57 modernized primrec
haftmann
parents: 39198
diff changeset
    49
| pexp_Suc: "p %^ (Suc n) = p *** (p %^ n)"
33153
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
    50
60536
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
    51
text \<open>Quotient related value of dividing a polynomial by x + a.
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
    52
  Useful for divisor properties in inductive proofs.\<close>
54219
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
    53
primrec (in field) "pquot" :: "'a list \<Rightarrow> 'a \<Rightarrow> 'a list"
52778
19fa3e3964f0 tuned proofs;
wenzelm
parents: 49962
diff changeset
    54
where
60536
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
    55
  pquot_Nil: "pquot [] a = []"
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
    56
| pquot_Cons: "pquot (h # t) a =
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
    57
    (if t = [] then [h] else (inverse a * (h - hd( pquot t a))) # pquot t a)"
33153
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
    58
60536
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
    59
text \<open>Normalization of polynomials (remove extra 0 coeff).\<close>
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
    60
primrec (in semiring_0) pnormalize :: "'a list \<Rightarrow> 'a list"
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
    61
where
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
    62
  pnormalize_Nil: "pnormalize [] = []"
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
    63
| pnormalize_Cons: "pnormalize (h # p) =
54219
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
    64
    (if pnormalize p = [] then (if h = 0 then [] else [h]) else h # pnormalize p)"
33153
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
    65
60536
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
    66
definition (in semiring_0) "pnormal p \<longleftrightarrow> pnormalize p = p \<and> p \<noteq> []"
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
    67
definition (in semiring_0) "nonconstant p \<longleftrightarrow> pnormal p \<and> (\<forall>x. p \<noteq> [x])"
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
    68
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
    69
text \<open>Other definitions.\<close>
33153
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
    70
69597
ff784d5a5bfb isabelle update -u control_cartouches;
wenzelm
parents: 69064
diff changeset
    71
definition (in ring_1) poly_minus :: "'a list \<Rightarrow> 'a list" (\<open>-- _\<close> [80] 80)
52778
19fa3e3964f0 tuned proofs;
wenzelm
parents: 49962
diff changeset
    72
  where "-- p = (- 1) %* p"
33153
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
    73
69597
ff784d5a5bfb isabelle update -u control_cartouches;
wenzelm
parents: 69064
diff changeset
    74
definition (in semiring_0) divides :: "'a list \<Rightarrow> 'a list \<Rightarrow> bool"  (infixl \<open>divides\<close> 70)
60536
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
    75
  where "p1 divides p2 \<longleftrightarrow> (\<exists>q. poly p2 = poly(p1 *** q))"
54219
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
    76
60536
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
    77
lemma (in semiring_0) dividesI: "poly p2 = poly (p1 *** q) \<Longrightarrow> p1 divides p2"
54219
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
    78
  by (auto simp add: divides_def)
33153
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
    79
54219
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
    80
lemma (in semiring_0) dividesE:
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
    81
  assumes "p1 divides p2"
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
    82
  obtains q where "poly p2 = poly (p1 *** q)"
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
    83
  using assms by (auto simp add: divides_def)
33153
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
    84
61586
5197a2ecb658 isabelle update_cartouches -c -t;
wenzelm
parents: 60698
diff changeset
    85
\<comment> \<open>order of a polynomial\<close>
60536
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
    86
definition (in ring_1) order :: "'a \<Rightarrow> 'a list \<Rightarrow> nat"
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
    87
  where "order a p = (SOME n. ([-a, 1] %^ n) divides p \<and> \<not> (([-a, 1] %^ (Suc n)) divides p))"
54219
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
    88
61586
5197a2ecb658 isabelle update_cartouches -c -t;
wenzelm
parents: 60698
diff changeset
    89
\<comment> \<open>degree of a polynomial\<close>
54219
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
    90
definition (in semiring_0) degree :: "'a list \<Rightarrow> nat"
52778
19fa3e3964f0 tuned proofs;
wenzelm
parents: 49962
diff changeset
    91
  where "degree p = length (pnormalize p) - 1"
33153
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
    92
61586
5197a2ecb658 isabelle update_cartouches -c -t;
wenzelm
parents: 60698
diff changeset
    93
\<comment> \<open>squarefree polynomials --- NB with respect to real roots only\<close>
54219
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
    94
definition (in ring_1) rsquarefree :: "'a list \<Rightarrow> bool"
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
    95
  where "rsquarefree p \<longleftrightarrow> poly p \<noteq> poly [] \<and> (\<forall>a. order a p = 0 \<or> order a p = 1)"
33153
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
    96
54219
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
    97
context semiring_0
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
    98
begin
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
    99
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   100
lemma padd_Nil2[simp]: "p +++ [] = p"
52778
19fa3e3964f0 tuned proofs;
wenzelm
parents: 49962
diff changeset
   101
  by (induct p) auto
33153
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   102
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   103
lemma padd_Cons_Cons: "(h1 # p1) +++ (h2 # p2) = (h1 + h2) # (p1 +++ p2)"
52778
19fa3e3964f0 tuned proofs;
wenzelm
parents: 49962
diff changeset
   104
  by auto
33153
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   105
54219
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   106
lemma pminus_Nil: "-- [] = []"
52778
19fa3e3964f0 tuned proofs;
wenzelm
parents: 49962
diff changeset
   107
  by (simp add: poly_minus_def)
33153
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   108
54219
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   109
lemma pmult_singleton: "[h1] *** p1 = h1 %* p1" by simp
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   110
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   111
end
33153
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   112
60536
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   113
lemma (in semiring_1) poly_ident_mult[simp]: "1 %* t = t"
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   114
  by (induct t) auto
33153
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   115
60536
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   116
lemma (in semiring_0) poly_simple_add_Cons[simp]: "[a] +++ (0 # t) = a # t"
52778
19fa3e3964f0 tuned proofs;
wenzelm
parents: 49962
diff changeset
   117
  by simp
33153
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   118
60536
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   119
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   120
text \<open>Handy general properties.\<close>
33153
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   121
54219
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   122
lemma (in comm_semiring_0) padd_commut: "b +++ a = a +++ b"
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   123
proof (induct b arbitrary: a)
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   124
  case Nil
60536
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   125
  then show ?case
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   126
    by auto
54219
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   127
next
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   128
  case (Cons b bs a)
60536
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   129
  then show ?case
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   130
    by (cases a) (simp_all add: add.commute)
54219
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   131
qed
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   132
60698
29e8bdc41f90 tuned proofs;
wenzelm
parents: 60537
diff changeset
   133
lemma (in comm_semiring_0) padd_assoc: "(a +++ b) +++ c = a +++ (b +++ c)"
29e8bdc41f90 tuned proofs;
wenzelm
parents: 60537
diff changeset
   134
proof (induct a arbitrary: b c)
29e8bdc41f90 tuned proofs;
wenzelm
parents: 60537
diff changeset
   135
  case Nil
29e8bdc41f90 tuned proofs;
wenzelm
parents: 60537
diff changeset
   136
  then show ?case
29e8bdc41f90 tuned proofs;
wenzelm
parents: 60537
diff changeset
   137
    by simp
29e8bdc41f90 tuned proofs;
wenzelm
parents: 60537
diff changeset
   138
next
29e8bdc41f90 tuned proofs;
wenzelm
parents: 60537
diff changeset
   139
  case Cons
29e8bdc41f90 tuned proofs;
wenzelm
parents: 60537
diff changeset
   140
  then show ?case
29e8bdc41f90 tuned proofs;
wenzelm
parents: 60537
diff changeset
   141
    by (cases b) (simp_all add: ac_simps)
29e8bdc41f90 tuned proofs;
wenzelm
parents: 60537
diff changeset
   142
qed
33153
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   143
60536
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   144
lemma (in semiring_0) poly_cmult_distr: "a %* (p +++ q) = a %* p +++ a %* q"
60698
29e8bdc41f90 tuned proofs;
wenzelm
parents: 60537
diff changeset
   145
proof (induct p arbitrary: q)
29e8bdc41f90 tuned proofs;
wenzelm
parents: 60537
diff changeset
   146
  case Nil
29e8bdc41f90 tuned proofs;
wenzelm
parents: 60537
diff changeset
   147
  then show ?case
29e8bdc41f90 tuned proofs;
wenzelm
parents: 60537
diff changeset
   148
    by simp
29e8bdc41f90 tuned proofs;
wenzelm
parents: 60537
diff changeset
   149
next
29e8bdc41f90 tuned proofs;
wenzelm
parents: 60537
diff changeset
   150
  case Cons
29e8bdc41f90 tuned proofs;
wenzelm
parents: 60537
diff changeset
   151
  then show ?case
29e8bdc41f90 tuned proofs;
wenzelm
parents: 60537
diff changeset
   152
    by (cases q) (simp_all add: distrib_left)
29e8bdc41f90 tuned proofs;
wenzelm
parents: 60537
diff changeset
   153
qed
33153
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   154
60536
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   155
lemma (in ring_1) pmult_by_x[simp]: "[0, 1] *** t = 0 # t"
60698
29e8bdc41f90 tuned proofs;
wenzelm
parents: 60537
diff changeset
   156
proof (induct t)
29e8bdc41f90 tuned proofs;
wenzelm
parents: 60537
diff changeset
   157
  case Nil
29e8bdc41f90 tuned proofs;
wenzelm
parents: 60537
diff changeset
   158
  then show ?case
29e8bdc41f90 tuned proofs;
wenzelm
parents: 60537
diff changeset
   159
    by simp
29e8bdc41f90 tuned proofs;
wenzelm
parents: 60537
diff changeset
   160
next
29e8bdc41f90 tuned proofs;
wenzelm
parents: 60537
diff changeset
   161
  case (Cons a t)
29e8bdc41f90 tuned proofs;
wenzelm
parents: 60537
diff changeset
   162
  then show ?case
29e8bdc41f90 tuned proofs;
wenzelm
parents: 60537
diff changeset
   163
    by (cases t) (auto simp add: padd_commut)
29e8bdc41f90 tuned proofs;
wenzelm
parents: 60537
diff changeset
   164
qed
60536
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   165
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   166
text \<open>Properties of evaluation of polynomials.\<close>
33153
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   167
54219
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   168
lemma (in semiring_0) poly_add: "poly (p1 +++ p2) x = poly p1 x + poly p2 x"
60536
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   169
proof (induct p1 arbitrary: p2)
54219
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   170
  case Nil
60536
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   171
  then show ?case
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   172
    by simp
54219
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   173
next
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   174
  case (Cons a as p2)
60536
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   175
  then show ?case
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   176
    by (cases p2) (simp_all add: ac_simps distrib_left)
54219
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   177
qed
33153
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   178
54219
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   179
lemma (in comm_semiring_0) poly_cmult: "poly (c %* p) x = c * poly p x"
60698
29e8bdc41f90 tuned proofs;
wenzelm
parents: 60537
diff changeset
   180
proof (induct p)
29e8bdc41f90 tuned proofs;
wenzelm
parents: 60537
diff changeset
   181
  case Nil
29e8bdc41f90 tuned proofs;
wenzelm
parents: 60537
diff changeset
   182
  then show ?case
29e8bdc41f90 tuned proofs;
wenzelm
parents: 60537
diff changeset
   183
    by simp
29e8bdc41f90 tuned proofs;
wenzelm
parents: 60537
diff changeset
   184
next
29e8bdc41f90 tuned proofs;
wenzelm
parents: 60537
diff changeset
   185
  case Cons
29e8bdc41f90 tuned proofs;
wenzelm
parents: 60537
diff changeset
   186
  then show ?case
29e8bdc41f90 tuned proofs;
wenzelm
parents: 60537
diff changeset
   187
    by (cases "x = zero") (auto simp add: distrib_left ac_simps)
29e8bdc41f90 tuned proofs;
wenzelm
parents: 60537
diff changeset
   188
qed
33153
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   189
69064
5840724b1d71 Prefix form of infix with * on either side no longer needs special treatment
nipkow
parents: 67399
diff changeset
   190
lemma (in comm_semiring_0) poly_cmult_map: "poly (map ((*) c) p) x = c * poly p x"
57514
bdc2c6b40bf2 prefer ac_simps collections over separate name bindings for add and mult
haftmann
parents: 57512
diff changeset
   191
  by (induct p) (auto simp add: distrib_left ac_simps)
33153
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   192
54219
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   193
lemma (in comm_ring_1) poly_minus: "poly (-- p) x = - (poly p x)"
60698
29e8bdc41f90 tuned proofs;
wenzelm
parents: 60537
diff changeset
   194
  by (simp add: poly_minus_def) (auto simp add: poly_cmult)
33153
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   195
54219
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   196
lemma (in comm_semiring_0) poly_mult: "poly (p1 *** p2) x = poly p1 x * poly p2 x"
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   197
proof (induct p1 arbitrary: p2)
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   198
  case Nil
60536
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   199
  then show ?case
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   200
    by simp
54219
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   201
next
60698
29e8bdc41f90 tuned proofs;
wenzelm
parents: 60537
diff changeset
   202
  case (Cons a as)
60536
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   203
  then show ?case
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   204
    by (cases as) (simp_all add: poly_cmult poly_add distrib_right distrib_left ac_simps)
54219
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   205
qed
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   206
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   207
class idom_char_0 = idom + ring_char_0
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   208
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   209
subclass (in field_char_0) idom_char_0 ..
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   210
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   211
lemma (in comm_ring_1) poly_exp: "poly (p %^ n) x = (poly p x) ^ n"
52881
4eb44754f1bb misc tuning and simplification;
wenzelm
parents: 52778
diff changeset
   212
  by (induct n) (auto simp add: poly_cmult poly_mult)
33153
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   213
60536
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   214
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   215
text \<open>More Polynomial Evaluation lemmas.\<close>
33153
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   216
54219
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   217
lemma (in semiring_0) poly_add_rzero[simp]: "poly (a +++ []) x = poly a x"
52778
19fa3e3964f0 tuned proofs;
wenzelm
parents: 49962
diff changeset
   218
  by simp
33153
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   219
54219
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   220
lemma (in comm_semiring_0) poly_mult_assoc: "poly ((a *** b) *** c) x = poly (a *** (b *** c)) x"
57512
cc97b347b301 reduced name variants for assoc and commute on plus and mult
haftmann
parents: 55417
diff changeset
   221
  by (simp add: poly_mult mult.assoc)
33153
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   222
54219
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   223
lemma (in semiring_0) poly_mult_Nil2[simp]: "poly (p *** []) x = 0"
52881
4eb44754f1bb misc tuning and simplification;
wenzelm
parents: 52778
diff changeset
   224
  by (induct p) auto
33153
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   225
60536
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   226
lemma (in comm_semiring_1) poly_exp_add: "poly (p %^ (n + d)) x = poly (p %^ n *** p %^ d) x"
57512
cc97b347b301 reduced name variants for assoc and commute on plus and mult
haftmann
parents: 55417
diff changeset
   227
  by (induct n) (auto simp add: poly_mult mult.assoc)
33153
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   228
60536
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   229
69597
ff784d5a5bfb isabelle update -u control_cartouches;
wenzelm
parents: 69064
diff changeset
   230
subsection \<open>Key Property: if \<^term>\<open>f a = 0\<close> then \<^term>\<open>(x - a)\<close> divides \<^term>\<open>p(x)\<close>.\<close>
33153
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   231
60698
29e8bdc41f90 tuned proofs;
wenzelm
parents: 60537
diff changeset
   232
lemma (in comm_ring_1) lemma_poly_linear_rem: "\<exists>q r. h#t = [r] +++ [-a, 1] *** q"
29e8bdc41f90 tuned proofs;
wenzelm
parents: 60537
diff changeset
   233
proof (induct t arbitrary: h)
54219
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   234
  case Nil
60698
29e8bdc41f90 tuned proofs;
wenzelm
parents: 60537
diff changeset
   235
  have "[h] = [h] +++ [- a, 1] *** []" by simp
60536
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   236
  then show ?case by blast
54219
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   237
next
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   238
  case (Cons  x xs)
60698
29e8bdc41f90 tuned proofs;
wenzelm
parents: 60537
diff changeset
   239
  have "\<exists>q r. h # x # xs = [r] +++ [-a, 1] *** q"
60536
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   240
  proof -
60698
29e8bdc41f90 tuned proofs;
wenzelm
parents: 60537
diff changeset
   241
    from Cons obtain q r where qr: "x # xs = [r] +++ [- a, 1] *** q"
60536
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   242
      by blast
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   243
    have "h # x # xs = [a * r + h] +++ [-a, 1] *** (r # q)"
54219
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   244
      using qr by (cases q) (simp_all add: algebra_simps)
60536
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   245
    then show ?thesis by blast
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   246
  qed
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   247
  then show ?case by blast
54219
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   248
qed
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   249
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   250
lemma (in comm_ring_1) poly_linear_rem: "\<exists>q r. h#t = [r] +++ [-a, 1] *** q"
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   251
  using lemma_poly_linear_rem [where t = t and a = a] by auto
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   252
60698
29e8bdc41f90 tuned proofs;
wenzelm
parents: 60537
diff changeset
   253
lemma (in comm_ring_1) poly_linear_divides: "poly p a = 0 \<longleftrightarrow> p = [] \<or> (\<exists>q. p = [-a, 1] *** q)"
60536
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   254
proof (cases p)
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   255
  case Nil
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   256
  then show ?thesis by simp
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   257
next
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   258
  case (Cons x xs)
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   259
  have "poly p a = 0" if "p = [-a, 1] *** q" for q
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   260
    using that by (simp add: poly_add poly_cmult)
54219
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   261
  moreover
60536
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   262
  have "\<exists>q. p = [- a, 1] *** q" if p0: "poly p a = 0"
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   263
  proof -
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   264
    from poly_linear_rem[of x xs a] obtain q r where qr: "x#xs = [r] +++ [- a, 1] *** q"
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   265
      by blast
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   266
    have "r = 0"
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   267
      using p0 by (simp only: Cons qr poly_mult poly_add) simp
80098
c06c95576ea9 Tidied some messy proofs
paulson <lp15@cam.ac.uk>
parents: 69597
diff changeset
   268
    with Cons qr have "p = [- a, 1] *** q"
c06c95576ea9 Tidied some messy proofs
paulson <lp15@cam.ac.uk>
parents: 69597
diff changeset
   269
      by (simp add: local.padd_commut)
c06c95576ea9 Tidied some messy proofs
paulson <lp15@cam.ac.uk>
parents: 69597
diff changeset
   270
    then show ?thesis ..
60536
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   271
  qed
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   272
  ultimately show ?thesis using Cons by blast
54219
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   273
qed
33153
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   274
60536
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   275
lemma (in semiring_0) lemma_poly_length_mult[simp]:
60698
29e8bdc41f90 tuned proofs;
wenzelm
parents: 60537
diff changeset
   276
  "length (k %* p +++  (h # (a %* p))) = Suc (length p)"
29e8bdc41f90 tuned proofs;
wenzelm
parents: 60537
diff changeset
   277
  by (induct p arbitrary: h k a) auto
33153
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   278
60536
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   279
lemma (in semiring_0) lemma_poly_length_mult2[simp]:
60698
29e8bdc41f90 tuned proofs;
wenzelm
parents: 60537
diff changeset
   280
  "length (k %* p +++  (h # p)) = Suc (length p)"
29e8bdc41f90 tuned proofs;
wenzelm
parents: 60537
diff changeset
   281
  by (induct p arbitrary: h k) auto
33153
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   282
54219
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   283
lemma (in ring_1) poly_length_mult[simp]: "length([-a,1] *** q) = Suc (length q)"
52778
19fa3e3964f0 tuned proofs;
wenzelm
parents: 49962
diff changeset
   284
  by auto
33153
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   285
60536
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   286
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   287
subsection \<open>Polynomial length\<close>
33153
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   288
54219
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   289
lemma (in semiring_0) poly_cmult_length[simp]: "length (a %* p) = length p"
52778
19fa3e3964f0 tuned proofs;
wenzelm
parents: 49962
diff changeset
   290
  by (induct p) auto
33153
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   291
54219
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   292
lemma (in semiring_0) poly_add_length: "length (p1 +++ p2) = max (length p1) (length p2)"
60698
29e8bdc41f90 tuned proofs;
wenzelm
parents: 60537
diff changeset
   293
  by (induct p1 arbitrary: p2) auto
33153
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   294
60698
29e8bdc41f90 tuned proofs;
wenzelm
parents: 60537
diff changeset
   295
lemma (in semiring_0) poly_root_mult_length[simp]: "length ([a, b] *** p) = Suc (length p)"
54219
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   296
  by (simp add: poly_add_length)
33153
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   297
54219
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   298
lemma (in idom) poly_mult_not_eq_poly_Nil[simp]:
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   299
  "poly (p *** q) x \<noteq> poly [] x \<longleftrightarrow> poly p x \<noteq> poly [] x \<and> poly q x \<noteq> poly [] x"
52778
19fa3e3964f0 tuned proofs;
wenzelm
parents: 49962
diff changeset
   300
  by (auto simp add: poly_mult)
33153
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   301
54219
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   302
lemma (in idom) poly_mult_eq_zero_disj: "poly (p *** q) x = 0 \<longleftrightarrow> poly p x = 0 \<or> poly q x = 0"
52778
19fa3e3964f0 tuned proofs;
wenzelm
parents: 49962
diff changeset
   303
  by (auto simp add: poly_mult)
33153
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   304
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   305
60536
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   306
text \<open>Normalisation Properties.\<close>
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   307
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   308
lemma (in semiring_0) poly_normalized_nil: "pnormalize p = [] \<longrightarrow> poly p x = 0"
52778
19fa3e3964f0 tuned proofs;
wenzelm
parents: 49962
diff changeset
   309
  by (induct p) auto
33153
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   310
60536
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   311
text \<open>A nontrivial polynomial of degree n has no more than n roots.\<close>
54219
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   312
lemma (in idom) poly_roots_index_lemma:
60698
29e8bdc41f90 tuned proofs;
wenzelm
parents: 60537
diff changeset
   313
  assumes "poly p x \<noteq> poly [] x"
29e8bdc41f90 tuned proofs;
wenzelm
parents: 60537
diff changeset
   314
    and "length p = n"
54219
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   315
  shows "\<exists>i. \<forall>x. poly p x = 0 \<longrightarrow> (\<exists>m\<le>n. x = i m)"
60698
29e8bdc41f90 tuned proofs;
wenzelm
parents: 60537
diff changeset
   316
  using assms
54219
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   317
proof (induct n arbitrary: p x)
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   318
  case 0
60536
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   319
  then show ?case by simp
54219
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   320
next
60698
29e8bdc41f90 tuned proofs;
wenzelm
parents: 60537
diff changeset
   321
  case (Suc n)
60536
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   322
  have False if C: "\<And>i. \<exists>x. poly p x = 0 \<and> (\<forall>m\<le>Suc n. x \<noteq> i m)"
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   323
  proof -
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   324
    from Suc.prems have p0: "poly p x \<noteq> 0" "p \<noteq> []"
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   325
      by auto
54219
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   326
    from p0(1)[unfolded poly_linear_divides[of p x]]
60536
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   327
    have "\<forall>q. p \<noteq> [- x, 1] *** q"
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   328
      by blast
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   329
    from C obtain a where a: "poly p a = 0"
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   330
      by blast
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   331
    from a[unfolded poly_linear_divides[of p a]] p0(2) obtain q where q: "p = [-a, 1] *** q"
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   332
      by blast
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   333
    have lg: "length q = n"
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   334
      using q Suc.prems(2) by simp
54219
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   335
    from q p0 have qx: "poly q x \<noteq> poly [] x"
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   336
      by (auto simp add: poly_mult poly_add poly_cmult)
60698
29e8bdc41f90 tuned proofs;
wenzelm
parents: 60537
diff changeset
   337
    from Suc.hyps[OF qx lg] obtain i where i: "\<And>x. poly q x = 0 \<longrightarrow> (\<exists>m\<le>n. x = i m)"
60536
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   338
      by blast
54219
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   339
    let ?i = "\<lambda>m. if m = Suc n then a else i m"
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   340
    from C[of ?i] obtain y where y: "poly p y = 0" "\<forall>m\<le> Suc n. y \<noteq> ?i m"
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   341
      by blast
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   342
    from y have "y = a \<or> poly q y = 0"
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   343
      by (simp only: q poly_mult_eq_zero_disj poly_add) (simp add: algebra_simps)
80098
c06c95576ea9 Tidied some messy proofs
paulson <lp15@cam.ac.uk>
parents: 69597
diff changeset
   344
    with i[of y] y show ?thesis
c06c95576ea9 Tidied some messy proofs
paulson <lp15@cam.ac.uk>
parents: 69597
diff changeset
   345
      using le_Suc_eq by auto
60536
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   346
  qed
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   347
  then show ?case by blast
54219
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   348
qed
33153
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   349
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   350
54219
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   351
lemma (in idom) poly_roots_index_length:
60698
29e8bdc41f90 tuned proofs;
wenzelm
parents: 60537
diff changeset
   352
  "poly p x \<noteq> poly [] x \<Longrightarrow> \<exists>i. \<forall>x. poly p x = 0 \<longrightarrow> (\<exists>n. n \<le> length p \<and> x = i n)"
54219
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   353
  by (blast intro: poly_roots_index_lemma)
33153
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   354
54219
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   355
lemma (in idom) poly_roots_finite_lemma1:
60698
29e8bdc41f90 tuned proofs;
wenzelm
parents: 60537
diff changeset
   356
  "poly p x \<noteq> poly [] x \<Longrightarrow> \<exists>N i. \<forall>x. poly p x = 0 \<longrightarrow> (\<exists>n::nat. n < N \<and> x = i n)"
80098
c06c95576ea9 Tidied some messy proofs
paulson <lp15@cam.ac.uk>
parents: 69597
diff changeset
   357
  by (metis le_imp_less_Suc poly_roots_index_length)
33153
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   358
54219
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   359
lemma (in idom) idom_finite_lemma:
60536
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   360
  assumes "\<forall>x. P x \<longrightarrow> (\<exists>n. n < length j \<and> x = j!n)"
54219
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   361
  shows "finite {x. P x}"
52778
19fa3e3964f0 tuned proofs;
wenzelm
parents: 49962
diff changeset
   362
proof -
60698
29e8bdc41f90 tuned proofs;
wenzelm
parents: 60537
diff changeset
   363
  from assms have "{x. P x} \<subseteq> set j"
29e8bdc41f90 tuned proofs;
wenzelm
parents: 60537
diff changeset
   364
    by auto
29e8bdc41f90 tuned proofs;
wenzelm
parents: 60537
diff changeset
   365
  then show ?thesis
29e8bdc41f90 tuned proofs;
wenzelm
parents: 60537
diff changeset
   366
    using finite_subset by auto
33153
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   367
qed
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   368
54219
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   369
lemma (in idom) poly_roots_finite_lemma2:
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   370
  "poly p x \<noteq> poly [] x \<Longrightarrow> \<exists>i. \<forall>x. poly p x = 0 \<longrightarrow> x \<in> set i"
80098
c06c95576ea9 Tidied some messy proofs
paulson <lp15@cam.ac.uk>
parents: 69597
diff changeset
   371
  using poly_roots_index_length atMost_iff atMost_upto imageI set_map
c06c95576ea9 Tidied some messy proofs
paulson <lp15@cam.ac.uk>
parents: 69597
diff changeset
   372
  by metis
33153
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   373
60536
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   374
lemma (in ring_char_0) UNIV_ring_char_0_infinte: "\<not> finite (UNIV :: 'a set)"
54219
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   375
proof
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   376
  assume F: "finite (UNIV :: 'a set)"
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   377
  have "finite (UNIV :: nat set)"
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   378
  proof (rule finite_imageD)
60698
29e8bdc41f90 tuned proofs;
wenzelm
parents: 60537
diff changeset
   379
    have "of_nat ` UNIV \<subseteq> UNIV"
29e8bdc41f90 tuned proofs;
wenzelm
parents: 60537
diff changeset
   380
      by simp
60536
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   381
    then show "finite (of_nat ` UNIV :: 'a set)"
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   382
      using F by (rule finite_subset)
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   383
    show "inj (of_nat :: nat \<Rightarrow> 'a)"
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   384
      by (simp add: inj_on_def)
54219
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   385
  qed
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   386
  with infinite_UNIV_nat show False ..
33153
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   387
qed
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   388
54219
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   389
lemma (in idom_char_0) poly_roots_finite: "poly p \<noteq> poly [] \<longleftrightarrow> finite {x. poly p x = 0}"
60536
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   390
  (is "?lhs \<longleftrightarrow> ?rhs")
33153
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   391
proof
60536
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   392
  show ?rhs if ?lhs
52778
19fa3e3964f0 tuned proofs;
wenzelm
parents: 49962
diff changeset
   393
  proof -
80098
c06c95576ea9 Tidied some messy proofs
paulson <lp15@cam.ac.uk>
parents: 69597
diff changeset
   394
    have False if  F: "\<not> finite {x. poly p x = 0}"
c06c95576ea9 Tidied some messy proofs
paulson <lp15@cam.ac.uk>
parents: 69597
diff changeset
   395
      and P: "\<forall>x. poly p x = 0 \<longrightarrow> x \<in> set i" for  i
c06c95576ea9 Tidied some messy proofs
paulson <lp15@cam.ac.uk>
parents: 69597
diff changeset
   396
      by (smt (verit, del_insts) in_set_conv_nth local.idom_finite_lemma that)
c06c95576ea9 Tidied some messy proofs
paulson <lp15@cam.ac.uk>
parents: 69597
diff changeset
   397
    with that show ?thesis
c06c95576ea9 Tidied some messy proofs
paulson <lp15@cam.ac.uk>
parents: 69597
diff changeset
   398
      using local.poly_roots_finite_lemma2 by blast
33153
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   399
  qed
60536
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   400
  show ?lhs if ?rhs
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   401
    using UNIV_ring_char_0_infinte that by auto
33153
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   402
qed
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   403
60536
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   404
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   405
text \<open>Entirety and Cancellation for polynomials\<close>
33153
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   406
54219
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   407
lemma (in idom_char_0) poly_entire_lemma2:
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   408
  assumes p0: "poly p \<noteq> poly []"
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   409
    and q0: "poly q \<noteq> poly []"
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   410
  shows "poly (p***q) \<noteq> poly []"
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   411
proof -
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   412
  let ?S = "\<lambda>p. {x. poly p x = 0}"
60536
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   413
  have "?S (p *** q) = ?S p \<union> ?S q"
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   414
    by (auto simp add: poly_mult)
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   415
  with p0 q0 show ?thesis
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   416
    unfolding poly_roots_finite by auto
54219
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   417
qed
33153
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   418
54219
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   419
lemma (in idom_char_0) poly_entire:
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   420
  "poly (p *** q) = poly [] \<longleftrightarrow> poly p = poly [] \<or> poly q = poly []"
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   421
  using poly_entire_lemma2[of p q]
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   422
  by (auto simp add: fun_eq_iff poly_mult)
33153
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   423
54219
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   424
lemma (in idom_char_0) poly_entire_neg:
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   425
  "poly (p *** q) \<noteq> poly [] \<longleftrightarrow> poly p \<noteq> poly [] \<and> poly q \<noteq> poly []"
52778
19fa3e3964f0 tuned proofs;
wenzelm
parents: 49962
diff changeset
   426
  by (simp add: poly_entire)
33153
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   427
54219
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   428
lemma (in comm_ring_1) poly_add_minus_zero_iff:
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   429
  "poly (p +++ -- q) = poly [] \<longleftrightarrow> poly p = poly q"
60536
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   430
  by (auto simp add: algebra_simps poly_add poly_minus_def fun_eq_iff poly_cmult)
33153
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   431
54219
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   432
lemma (in comm_ring_1) poly_add_minus_mult_eq:
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   433
  "poly (p *** q +++ --(p *** r)) = poly (p *** (q +++ -- r))"
60536
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   434
  by (auto simp add: poly_add poly_minus_def fun_eq_iff poly_mult poly_cmult algebra_simps)
33153
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   435
54219
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   436
subclass (in idom_char_0) comm_ring_1 ..
33153
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   437
54219
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   438
lemma (in idom_char_0) poly_mult_left_cancel:
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   439
  "poly (p *** q) = poly (p *** r) \<longleftrightarrow> poly p = poly [] \<or> poly q = poly r"
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   440
proof -
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   441
  have "poly (p *** q) = poly (p *** r) \<longleftrightarrow> poly (p *** q +++ -- (p *** r)) = poly []"
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   442
    by (simp only: poly_add_minus_zero_iff)
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   443
  also have "\<dots> \<longleftrightarrow> poly p = poly [] \<or> poly q = poly r"
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   444
    by (auto intro: simp add: poly_add_minus_mult_eq poly_entire poly_add_minus_zero_iff)
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   445
  finally show ?thesis .
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   446
qed
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   447
60536
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   448
lemma (in idom) poly_exp_eq_zero[simp]: "poly (p %^ n) = poly [] \<longleftrightarrow> poly p = poly [] \<and> n \<noteq> 0"
80098
c06c95576ea9 Tidied some messy proofs
paulson <lp15@cam.ac.uk>
parents: 69597
diff changeset
   449
  by (simp add: local.poly_exp fun_eq_iff)
33153
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   450
60536
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   451
lemma (in comm_ring_1) poly_prime_eq_zero[simp]: "poly [a, 1] \<noteq> poly []"
80098
c06c95576ea9 Tidied some messy proofs
paulson <lp15@cam.ac.uk>
parents: 69597
diff changeset
   452
proof -
c06c95576ea9 Tidied some messy proofs
paulson <lp15@cam.ac.uk>
parents: 69597
diff changeset
   453
  have "\<exists>x. a + x \<noteq> 0"
c06c95576ea9 Tidied some messy proofs
paulson <lp15@cam.ac.uk>
parents: 69597
diff changeset
   454
    by (metis add_cancel_left_right zero_neq_one)
c06c95576ea9 Tidied some messy proofs
paulson <lp15@cam.ac.uk>
parents: 69597
diff changeset
   455
  then show ?thesis
c06c95576ea9 Tidied some messy proofs
paulson <lp15@cam.ac.uk>
parents: 69597
diff changeset
   456
    by (simp add: fun_eq_iff)
c06c95576ea9 Tidied some messy proofs
paulson <lp15@cam.ac.uk>
parents: 69597
diff changeset
   457
qed
33153
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   458
54219
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   459
lemma (in idom) poly_exp_prime_eq_zero: "poly ([a, 1] %^ n) \<noteq> poly []"
52778
19fa3e3964f0 tuned proofs;
wenzelm
parents: 49962
diff changeset
   460
  by auto
33153
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   461
60536
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   462
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   463
text \<open>A more constructive notion of polynomials being trivial.\<close>
33153
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   464
80098
c06c95576ea9 Tidied some messy proofs
paulson <lp15@cam.ac.uk>
parents: 69597
diff changeset
   465
lemma (in idom_char_0) poly_zero_lemma': 
c06c95576ea9 Tidied some messy proofs
paulson <lp15@cam.ac.uk>
parents: 69597
diff changeset
   466
  assumes "poly (h # t) = poly []" shows "h = 0 \<and> poly t = poly []"
52778
19fa3e3964f0 tuned proofs;
wenzelm
parents: 49962
diff changeset
   467
proof -
80098
c06c95576ea9 Tidied some messy proofs
paulson <lp15@cam.ac.uk>
parents: 69597
diff changeset
   468
  have "poly t x = 0" if H: "\<forall>x. x = 0 \<or> poly t x = 0" and pnz: "poly t \<noteq> poly []" for x
c06c95576ea9 Tidied some messy proofs
paulson <lp15@cam.ac.uk>
parents: 69597
diff changeset
   469
  proof -
c06c95576ea9 Tidied some messy proofs
paulson <lp15@cam.ac.uk>
parents: 69597
diff changeset
   470
    from H have "{x. poly t x = 0} \<supseteq> UNIV - {0}"
c06c95576ea9 Tidied some messy proofs
paulson <lp15@cam.ac.uk>
parents: 69597
diff changeset
   471
      by auto
c06c95576ea9 Tidied some messy proofs
paulson <lp15@cam.ac.uk>
parents: 69597
diff changeset
   472
    then show ?thesis
c06c95576ea9 Tidied some messy proofs
paulson <lp15@cam.ac.uk>
parents: 69597
diff changeset
   473
      using finite_subset local.poly_roots_finite pnz by fastforce
c06c95576ea9 Tidied some messy proofs
paulson <lp15@cam.ac.uk>
parents: 69597
diff changeset
   474
  qed
c06c95576ea9 Tidied some messy proofs
paulson <lp15@cam.ac.uk>
parents: 69597
diff changeset
   475
  with assms show ?thesis
c06c95576ea9 Tidied some messy proofs
paulson <lp15@cam.ac.uk>
parents: 69597
diff changeset
   476
    by (simp add: fun_eq_iff) (metis add_cancel_right_left mult_eq_0_iff)
52778
19fa3e3964f0 tuned proofs;
wenzelm
parents: 49962
diff changeset
   477
qed
33153
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   478
60537
5398aa5a4df9 eliminated list_all;
wenzelm
parents: 60536
diff changeset
   479
lemma (in idom_char_0) poly_zero: "poly p = poly [] \<longleftrightarrow> (\<forall>c \<in> set p. c = 0)"
60698
29e8bdc41f90 tuned proofs;
wenzelm
parents: 60537
diff changeset
   480
proof (induct p)
29e8bdc41f90 tuned proofs;
wenzelm
parents: 60537
diff changeset
   481
  case Nil
29e8bdc41f90 tuned proofs;
wenzelm
parents: 60537
diff changeset
   482
  then show ?case by simp
29e8bdc41f90 tuned proofs;
wenzelm
parents: 60537
diff changeset
   483
next
29e8bdc41f90 tuned proofs;
wenzelm
parents: 60537
diff changeset
   484
  case Cons
80098
c06c95576ea9 Tidied some messy proofs
paulson <lp15@cam.ac.uk>
parents: 69597
diff changeset
   485
  then show ?case
c06c95576ea9 Tidied some messy proofs
paulson <lp15@cam.ac.uk>
parents: 69597
diff changeset
   486
    by (smt (verit) list.set_intros pmult_by_x poly_entire poly_zero_lemma' set_ConsD)
60698
29e8bdc41f90 tuned proofs;
wenzelm
parents: 60537
diff changeset
   487
qed
33153
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   488
60537
5398aa5a4df9 eliminated list_all;
wenzelm
parents: 60536
diff changeset
   489
lemma (in idom_char_0) poly_0: "\<forall>c \<in> set p. c = 0 \<Longrightarrow> poly p x = 0"
54219
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   490
  unfolding poly_zero[symmetric] by simp
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   491
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   492
60536
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   493
text \<open>Basics of divisibility.\<close>
33153
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   494
60536
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   495
lemma (in idom) poly_primes: "[a, 1] divides (p *** q) \<longleftrightarrow> [a, 1] divides p \<or> [a, 1] divides q"
80098
c06c95576ea9 Tidied some messy proofs
paulson <lp15@cam.ac.uk>
parents: 69597
diff changeset
   496
proof -
c06c95576ea9 Tidied some messy proofs
paulson <lp15@cam.ac.uk>
parents: 69597
diff changeset
   497
  have "\<exists>q. \<forall>x. poly p x = (a + x) * poly q x"
c06c95576ea9 Tidied some messy proofs
paulson <lp15@cam.ac.uk>
parents: 69597
diff changeset
   498
    if "poly p (uminus a) * poly q (uminus a) = (a + (uminus a)) * poly qa (uminus a)"
c06c95576ea9 Tidied some messy proofs
paulson <lp15@cam.ac.uk>
parents: 69597
diff changeset
   499
      and "\<forall>qa. \<exists>x. poly q x \<noteq> (a + x) * poly qa x"
c06c95576ea9 Tidied some messy proofs
paulson <lp15@cam.ac.uk>
parents: 69597
diff changeset
   500
    for qa 
c06c95576ea9 Tidied some messy proofs
paulson <lp15@cam.ac.uk>
parents: 69597
diff changeset
   501
    using that   
c06c95576ea9 Tidied some messy proofs
paulson <lp15@cam.ac.uk>
parents: 69597
diff changeset
   502
    apply (simp add: poly_linear_divides poly_add)
c06c95576ea9 Tidied some messy proofs
paulson <lp15@cam.ac.uk>
parents: 69597
diff changeset
   503
    by (metis add_cancel_left_right combine_common_factor mult_eq_0_iff poly.poly_Cons poly.poly_Nil poly_add poly_cmult)
c06c95576ea9 Tidied some messy proofs
paulson <lp15@cam.ac.uk>
parents: 69597
diff changeset
   504
  moreover have "\<exists>qb. \<forall>x. (a + x) * poly qa x * poly q x = (a + x) * poly qb x" for qa
c06c95576ea9 Tidied some messy proofs
paulson <lp15@cam.ac.uk>
parents: 69597
diff changeset
   505
    by (metis local.poly_mult mult_assoc)
c06c95576ea9 Tidied some messy proofs
paulson <lp15@cam.ac.uk>
parents: 69597
diff changeset
   506
  moreover have "\<exists>q. \<forall>x. poly p x * ((a + x) * poly qa x) = (a + x) * poly q x" for qa 
c06c95576ea9 Tidied some messy proofs
paulson <lp15@cam.ac.uk>
parents: 69597
diff changeset
   507
    by (metis mult.left_commute local.poly_mult)
c06c95576ea9 Tidied some messy proofs
paulson <lp15@cam.ac.uk>
parents: 69597
diff changeset
   508
  ultimately show ?thesis
c06c95576ea9 Tidied some messy proofs
paulson <lp15@cam.ac.uk>
parents: 69597
diff changeset
   509
    by (auto simp: divides_def divisors_zero fun_eq_iff poly_mult poly_add poly_cmult simp flip: distrib_right)
c06c95576ea9 Tidied some messy proofs
paulson <lp15@cam.ac.uk>
parents: 69597
diff changeset
   510
qed
33153
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   511
54219
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   512
lemma (in comm_semiring_1) poly_divides_refl[simp]: "p divides p"
80098
c06c95576ea9 Tidied some messy proofs
paulson <lp15@cam.ac.uk>
parents: 69597
diff changeset
   513
proof -
c06c95576ea9 Tidied some messy proofs
paulson <lp15@cam.ac.uk>
parents: 69597
diff changeset
   514
  have "poly p = poly (p *** [1])"
c06c95576ea9 Tidied some messy proofs
paulson <lp15@cam.ac.uk>
parents: 69597
diff changeset
   515
    by (auto simp add: poly_mult fun_eq_iff)
c06c95576ea9 Tidied some messy proofs
paulson <lp15@cam.ac.uk>
parents: 69597
diff changeset
   516
  then show ?thesis
c06c95576ea9 Tidied some messy proofs
paulson <lp15@cam.ac.uk>
parents: 69597
diff changeset
   517
    using local.dividesI by blast
c06c95576ea9 Tidied some messy proofs
paulson <lp15@cam.ac.uk>
parents: 69597
diff changeset
   518
qed
33153
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   519
54219
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   520
lemma (in comm_semiring_1) poly_divides_trans: "p divides q \<Longrightarrow> q divides r \<Longrightarrow> p divides r"
80098
c06c95576ea9 Tidied some messy proofs
paulson <lp15@cam.ac.uk>
parents: 69597
diff changeset
   521
  unfolding divides_def
c06c95576ea9 Tidied some messy proofs
paulson <lp15@cam.ac.uk>
parents: 69597
diff changeset
   522
  by (metis ext local.poly_mult local.poly_mult_assoc)
33153
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   523
54219
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   524
lemma (in comm_semiring_1) poly_divides_exp: "m \<le> n \<Longrightarrow> (p %^ m) divides (p %^ n)"
62378
85ed00c1fe7c generalize more theorems to support enat and ennreal
hoelzl
parents: 61945
diff changeset
   525
  by (auto simp: le_iff_add divides_def poly_exp_add fun_eq_iff)
33153
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   526
60536
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   527
lemma (in comm_semiring_1) poly_exp_divides: "(p %^ n) divides q \<Longrightarrow> m \<le> n \<Longrightarrow> (p %^ m) divides q"
52778
19fa3e3964f0 tuned proofs;
wenzelm
parents: 49962
diff changeset
   528
  by (blast intro: poly_divides_exp poly_divides_trans)
33153
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   529
80098
c06c95576ea9 Tidied some messy proofs
paulson <lp15@cam.ac.uk>
parents: 69597
diff changeset
   530
lemma (in comm_semiring_0) poly_divides_add:
c06c95576ea9 Tidied some messy proofs
paulson <lp15@cam.ac.uk>
parents: 69597
diff changeset
   531
  assumes "p divides q" and "p divides r" shows "p divides (q +++ r)"
c06c95576ea9 Tidied some messy proofs
paulson <lp15@cam.ac.uk>
parents: 69597
diff changeset
   532
proof -
c06c95576ea9 Tidied some messy proofs
paulson <lp15@cam.ac.uk>
parents: 69597
diff changeset
   533
  have "\<And>qa qb. \<lbrakk>poly q = poly (p *** qa); poly r = poly (p *** qb)\<rbrakk>
c06c95576ea9 Tidied some messy proofs
paulson <lp15@cam.ac.uk>
parents: 69597
diff changeset
   534
       \<Longrightarrow> poly (q +++ r) = poly (p *** (qa +++ qb))"
c06c95576ea9 Tidied some messy proofs
paulson <lp15@cam.ac.uk>
parents: 69597
diff changeset
   535
    by (auto simp add: poly_add fun_eq_iff poly_mult distrib_left)
c06c95576ea9 Tidied some messy proofs
paulson <lp15@cam.ac.uk>
parents: 69597
diff changeset
   536
  with assms show ?thesis
c06c95576ea9 Tidied some messy proofs
paulson <lp15@cam.ac.uk>
parents: 69597
diff changeset
   537
    by (auto simp add: divides_def)
c06c95576ea9 Tidied some messy proofs
paulson <lp15@cam.ac.uk>
parents: 69597
diff changeset
   538
qed
33153
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   539
80098
c06c95576ea9 Tidied some messy proofs
paulson <lp15@cam.ac.uk>
parents: 69597
diff changeset
   540
lemma (in comm_ring_1) poly_divides_diff:
c06c95576ea9 Tidied some messy proofs
paulson <lp15@cam.ac.uk>
parents: 69597
diff changeset
   541
  assumes "p divides q" and "p divides (q +++ r)"
c06c95576ea9 Tidied some messy proofs
paulson <lp15@cam.ac.uk>
parents: 69597
diff changeset
   542
  shows "p divides r"
c06c95576ea9 Tidied some messy proofs
paulson <lp15@cam.ac.uk>
parents: 69597
diff changeset
   543
proof -
c06c95576ea9 Tidied some messy proofs
paulson <lp15@cam.ac.uk>
parents: 69597
diff changeset
   544
  have "\<And>qa qb. \<lbrakk>poly q = poly (p *** qa); poly (q +++ r) = poly (p *** qb)\<rbrakk>
c06c95576ea9 Tidied some messy proofs
paulson <lp15@cam.ac.uk>
parents: 69597
diff changeset
   545
         \<Longrightarrow> poly r = poly (p *** (qb +++ -- qa))"
c06c95576ea9 Tidied some messy proofs
paulson <lp15@cam.ac.uk>
parents: 69597
diff changeset
   546
  by (auto simp add: poly_add fun_eq_iff poly_mult poly_minus algebra_simps)
c06c95576ea9 Tidied some messy proofs
paulson <lp15@cam.ac.uk>
parents: 69597
diff changeset
   547
  with assms show ?thesis
c06c95576ea9 Tidied some messy proofs
paulson <lp15@cam.ac.uk>
parents: 69597
diff changeset
   548
    by (auto simp add: divides_def)
c06c95576ea9 Tidied some messy proofs
paulson <lp15@cam.ac.uk>
parents: 69597
diff changeset
   549
qed
33153
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   550
60536
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   551
lemma (in comm_ring_1) poly_divides_diff2: "p divides r \<Longrightarrow> p divides (q +++ r) \<Longrightarrow> p divides q"
80098
c06c95576ea9 Tidied some messy proofs
paulson <lp15@cam.ac.uk>
parents: 69597
diff changeset
   552
  by (metis local.padd_commut local.poly_divides_diff)
33153
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   553
54219
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   554
lemma (in semiring_0) poly_divides_zero: "poly p = poly [] \<Longrightarrow> q divides p"
80098
c06c95576ea9 Tidied some messy proofs
paulson <lp15@cam.ac.uk>
parents: 69597
diff changeset
   555
  by (metis ext dividesI poly.poly_Nil poly_mult_Nil2)
33153
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   556
54219
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   557
lemma (in semiring_0) poly_divides_zero2 [simp]: "q divides []"
80098
c06c95576ea9 Tidied some messy proofs
paulson <lp15@cam.ac.uk>
parents: 69597
diff changeset
   558
  using local.poly_divides_zero by force
33153
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   559
60536
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   560
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   561
text \<open>At last, we can consider the order of a root.\<close>
33153
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   562
54219
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   563
lemma (in idom_char_0) poly_order_exists_lemma:
60698
29e8bdc41f90 tuned proofs;
wenzelm
parents: 60537
diff changeset
   564
  assumes "length p = d"
29e8bdc41f90 tuned proofs;
wenzelm
parents: 60537
diff changeset
   565
    and "poly p \<noteq> poly []"
54219
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   566
  shows "\<exists>n q. p = mulexp n [-a, 1] q \<and> poly q a \<noteq> 0"
60698
29e8bdc41f90 tuned proofs;
wenzelm
parents: 60537
diff changeset
   567
  using assms
54219
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   568
proof (induct d arbitrary: p)
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   569
  case 0
60536
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   570
  then show ?case by simp
54219
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   571
next
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   572
  case (Suc n p)
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   573
  show ?case
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   574
  proof (cases "poly p a = 0")
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   575
    case True
60536
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   576
    from Suc.prems have h: "length p = Suc n" "poly p \<noteq> poly []"
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   577
      by auto
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   578
    then have pN: "p \<noteq> []"
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   579
      by auto
54219
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   580
    from True[unfolded poly_linear_divides] pN obtain q where q: "p = [-a, 1] *** q"
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   581
      by blast
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   582
    from q h True have qh: "length q = n" "poly q \<noteq> poly []"
80098
c06c95576ea9 Tidied some messy proofs
paulson <lp15@cam.ac.uk>
parents: 69597
diff changeset
   583
      using h(2) local.poly_entire q by fastforce+
54219
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   584
    from Suc.hyps[OF qh] obtain m r where mr: "q = mulexp m [-a,1] r" "poly r a \<noteq> 0"
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   585
      by blast
60698
29e8bdc41f90 tuned proofs;
wenzelm
parents: 60537
diff changeset
   586
    from mr q have "p = mulexp (Suc m) [-a,1] r \<and> poly r a \<noteq> 0"
29e8bdc41f90 tuned proofs;
wenzelm
parents: 60537
diff changeset
   587
      by simp
54219
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   588
    then show ?thesis by blast
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   589
  next
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   590
    case False
80098
c06c95576ea9 Tidied some messy proofs
paulson <lp15@cam.ac.uk>
parents: 69597
diff changeset
   591
    with Suc.prems show ?thesis
c06c95576ea9 Tidied some messy proofs
paulson <lp15@cam.ac.uk>
parents: 69597
diff changeset
   592
      by (smt (verit, best) local.mulexp.mulexp_zero)
54219
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   593
  qed
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   594
qed
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   595
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   596
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   597
lemma (in comm_semiring_1) poly_mulexp: "poly (mulexp n p q) x = (poly p x) ^ n * poly q x"
57514
bdc2c6b40bf2 prefer ac_simps collections over separate name bindings for add and mult
haftmann
parents: 57512
diff changeset
   598
  by (induct n) (auto simp add: poly_mult ac_simps)
54219
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   599
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   600
lemma (in comm_semiring_1) divides_left_mult:
60536
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   601
  assumes "(p *** q) divides r"
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   602
  shows "p divides r \<and> q divides r"
54219
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   603
proof-
60536
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   604
  from assms obtain t where "poly r = poly (p *** q *** t)"
54219
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   605
    unfolding divides_def by blast
60536
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   606
  then have "poly r = poly (p *** (q *** t))" and "poly r = poly (q *** (p *** t))"
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   607
    by (auto simp add: fun_eq_iff poly_mult ac_simps)
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   608
  then show ?thesis
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   609
    unfolding divides_def by blast
54219
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   610
qed
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   611
33153
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   612
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   613
(* FIXME: Tidy up *)
54219
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   614
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   615
lemma (in semiring_1) zero_power_iff: "0 ^ n = (if n = 0 then 1 else 0)"
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   616
  by (induct n) simp_all
33153
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   617
54219
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   618
lemma (in idom_char_0) poly_order_exists:
60536
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   619
  assumes "length p = d"
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   620
    and "poly p \<noteq> poly []"
54219
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   621
  shows "\<exists>n. [- a, 1] %^ n divides p \<and> \<not> [- a, 1] %^ Suc n divides p"
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   622
proof -
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   623
  from assms have "\<exists>n q. p = mulexp n [- a, 1] q \<and> poly q a \<noteq> 0"
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   624
    by (rule poly_order_exists_lemma)
60536
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   625
  then obtain n q where p: "p = mulexp n [- a, 1] q" and "poly q a \<noteq> 0"
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   626
    by blast
54219
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   627
  have "[- a, 1] %^ n divides mulexp n [- a, 1] q"
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   628
  proof (rule dividesI)
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   629
    show "poly (mulexp n [- a, 1] q) = poly ([- a, 1] %^ n *** q)"
54230
b1d955791529 more simplification rules on unary and binary minus
haftmann
parents: 54219
diff changeset
   630
      by (induct n) (simp_all add: poly_add poly_cmult poly_mult algebra_simps)
54219
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   631
  qed
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   632
  moreover have "\<not> [- a, 1] %^ Suc n divides mulexp n [- a, 1] q"
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   633
  proof
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   634
    assume "[- a, 1] %^ Suc n divides mulexp n [- a, 1] q"
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   635
    then obtain m where "poly (mulexp n [- a, 1] q) = poly ([- a, 1] %^ Suc n *** m)"
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   636
      by (rule dividesE)
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   637
    moreover have "poly (mulexp n [- a, 1] q) \<noteq> poly ([- a, 1] %^ Suc n *** m)"
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   638
    proof (induct n)
60536
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   639
      case 0
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   640
      show ?case
54219
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   641
      proof (rule ccontr)
60698
29e8bdc41f90 tuned proofs;
wenzelm
parents: 60537
diff changeset
   642
        assume "\<not> ?thesis"
54219
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   643
        then have "poly q a = 0"
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   644
          by (simp add: poly_add poly_cmult)
60536
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   645
        with \<open>poly q a \<noteq> 0\<close> show False
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   646
          by simp
54219
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   647
      qed
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   648
    next
60536
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   649
      case (Suc n)
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   650
      show ?case
60698
29e8bdc41f90 tuned proofs;
wenzelm
parents: 60537
diff changeset
   651
        by (rule pexp_Suc [THEN ssubst])
54219
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   652
          (simp add: poly_mult_left_cancel poly_mult_assoc Suc del: pmult_Cons pexp_Suc)
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   653
    qed
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   654
    ultimately show False by simp
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   655
  qed
60536
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   656
  ultimately show ?thesis
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   657
    by (auto simp add: p)
54219
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   658
qed
33153
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   659
54219
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   660
lemma (in semiring_1) poly_one_divides[simp]: "[1] divides p"
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   661
  by (auto simp add: divides_def)
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   662
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   663
lemma (in idom_char_0) poly_order:
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   664
  "poly p \<noteq> poly [] \<Longrightarrow> \<exists>!n. ([-a, 1] %^ n) divides p \<and> \<not> (([-a, 1] %^ Suc n) divides p)"
80098
c06c95576ea9 Tidied some messy proofs
paulson <lp15@cam.ac.uk>
parents: 69597
diff changeset
   665
  by (meson Suc_le_eq linorder_neqE_nat local.poly_exp_divides poly_order_exists)
33153
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   666
60536
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   667
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   668
text \<open>Order\<close>
33153
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   669
54219
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   670
lemma some1_equalityD: "n = (SOME n. P n) \<Longrightarrow> \<exists>!n. P n \<Longrightarrow> P n"
52778
19fa3e3964f0 tuned proofs;
wenzelm
parents: 49962
diff changeset
   671
  by (blast intro: someI2)
33153
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   672
54219
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   673
lemma (in idom_char_0) order:
60536
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   674
  "([-a, 1] %^ n) divides p \<and> \<not> (([-a, 1] %^ Suc n) divides p) \<longleftrightarrow>
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   675
    n = order a p \<and> poly p \<noteq> poly []"
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   676
  unfolding order_def
80098
c06c95576ea9 Tidied some messy proofs
paulson <lp15@cam.ac.uk>
parents: 69597
diff changeset
   677
  by (metis (no_types, lifting) local.poly_divides_zero local.poly_order someI)
33153
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   678
54219
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   679
lemma (in idom_char_0) order2:
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   680
  "poly p \<noteq> poly [] \<Longrightarrow>
60536
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   681
    ([-a, 1] %^ (order a p)) divides p \<and> \<not> ([-a, 1] %^ Suc (order a p)) divides p"
52778
19fa3e3964f0 tuned proofs;
wenzelm
parents: 49962
diff changeset
   682
  by (simp add: order del: pexp_Suc)
33153
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   683
54219
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   684
lemma (in idom_char_0) order_unique:
60536
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   685
  "poly p \<noteq> poly [] \<Longrightarrow> ([-a, 1] %^ n) divides p \<Longrightarrow> \<not> ([-a, 1] %^ (Suc n)) divides p \<Longrightarrow>
54219
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   686
    n = order a p"
52778
19fa3e3964f0 tuned proofs;
wenzelm
parents: 49962
diff changeset
   687
  using order [of a n p] by auto
33153
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   688
54219
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   689
lemma (in idom_char_0) order_unique_lemma:
60536
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   690
  "poly p \<noteq> poly [] \<and> ([-a, 1] %^ n) divides p \<and> \<not> ([-a, 1] %^ (Suc n)) divides p \<Longrightarrow>
52881
4eb44754f1bb misc tuning and simplification;
wenzelm
parents: 52778
diff changeset
   691
    n = order a p"
52778
19fa3e3964f0 tuned proofs;
wenzelm
parents: 49962
diff changeset
   692
  by (blast intro: order_unique)
33153
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   693
54219
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   694
lemma (in ring_1) order_poly: "poly p = poly q \<Longrightarrow> order a p = order a q"
60536
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   695
  by (auto simp add: fun_eq_iff divides_def poly_mult order_def)
33153
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   696
54219
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   697
lemma (in semiring_1) pexp_one[simp]: "p %^ (Suc 0) = p"
60536
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   698
  by (induct p) auto
54219
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   699
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   700
lemma (in comm_ring_1) lemma_order_root:
60536
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   701
  "0 < n \<and> [- a, 1] %^ n divides p \<and> \<not> [- a, 1] %^ (Suc n) divides p \<Longrightarrow> poly p a = 0"
54219
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   702
  by (induct n arbitrary: a p) (auto simp add: divides_def poly_mult simp del: pmult_Cons)
33153
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   703
60536
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   704
lemma (in idom_char_0) order_root: "poly p a = 0 \<longleftrightarrow> poly p = poly [] \<or> order a p \<noteq> 0"
80098
c06c95576ea9 Tidied some messy proofs
paulson <lp15@cam.ac.uk>
parents: 69597
diff changeset
   705
proof (cases "poly p = poly []")
c06c95576ea9 Tidied some messy proofs
paulson <lp15@cam.ac.uk>
parents: 69597
diff changeset
   706
  case False
c06c95576ea9 Tidied some messy proofs
paulson <lp15@cam.ac.uk>
parents: 69597
diff changeset
   707
  then show ?thesis 
c06c95576ea9 Tidied some messy proofs
paulson <lp15@cam.ac.uk>
parents: 69597
diff changeset
   708
    by (metis (mono_tags, lifting) dividesI lemma_order_root order2 pexp_one poly_linear_divides neq0_conv)
c06c95576ea9 Tidied some messy proofs
paulson <lp15@cam.ac.uk>
parents: 69597
diff changeset
   709
qed auto
33153
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   710
54219
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   711
lemma (in idom_char_0) order_divides:
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   712
  "([-a, 1] %^ n) divides p \<longleftrightarrow> poly p = poly [] \<or> n \<le> order a p"
80098
c06c95576ea9 Tidied some messy proofs
paulson <lp15@cam.ac.uk>
parents: 69597
diff changeset
   713
proof (cases "poly p = poly []")
c06c95576ea9 Tidied some messy proofs
paulson <lp15@cam.ac.uk>
parents: 69597
diff changeset
   714
  case True
c06c95576ea9 Tidied some messy proofs
paulson <lp15@cam.ac.uk>
parents: 69597
diff changeset
   715
  then show ?thesis 
c06c95576ea9 Tidied some messy proofs
paulson <lp15@cam.ac.uk>
parents: 69597
diff changeset
   716
    using local.poly_divides_zero by force
c06c95576ea9 Tidied some messy proofs
paulson <lp15@cam.ac.uk>
parents: 69597
diff changeset
   717
next
c06c95576ea9 Tidied some messy proofs
paulson <lp15@cam.ac.uk>
parents: 69597
diff changeset
   718
  case False
c06c95576ea9 Tidied some messy proofs
paulson <lp15@cam.ac.uk>
parents: 69597
diff changeset
   719
  then show ?thesis 
c06c95576ea9 Tidied some messy proofs
paulson <lp15@cam.ac.uk>
parents: 69597
diff changeset
   720
    by (meson local.order2 local.poly_exp_divides not_less_eq_eq)
c06c95576ea9 Tidied some messy proofs
paulson <lp15@cam.ac.uk>
parents: 69597
diff changeset
   721
qed
33153
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   722
54219
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   723
lemma (in idom_char_0) order_decomp:
80098
c06c95576ea9 Tidied some messy proofs
paulson <lp15@cam.ac.uk>
parents: 69597
diff changeset
   724
  assumes "poly p \<noteq> poly []"
c06c95576ea9 Tidied some messy proofs
paulson <lp15@cam.ac.uk>
parents: 69597
diff changeset
   725
  shows "\<exists>q. poly p = poly (([-a, 1] %^ order a p) *** q) \<and> \<not> [-a, 1] divides q"
c06c95576ea9 Tidied some messy proofs
paulson <lp15@cam.ac.uk>
parents: 69597
diff changeset
   726
proof -
c06c95576ea9 Tidied some messy proofs
paulson <lp15@cam.ac.uk>
parents: 69597
diff changeset
   727
  obtain q where q: "poly p = poly ([- a, 1] %^ order a p *** q)"
c06c95576ea9 Tidied some messy proofs
paulson <lp15@cam.ac.uk>
parents: 69597
diff changeset
   728
    using assms local.order2 divides_def by blast
c06c95576ea9 Tidied some messy proofs
paulson <lp15@cam.ac.uk>
parents: 69597
diff changeset
   729
  have False if "poly q = poly ([- a, 1] *** qa)" for qa
c06c95576ea9 Tidied some messy proofs
paulson <lp15@cam.ac.uk>
parents: 69597
diff changeset
   730
  proof -
c06c95576ea9 Tidied some messy proofs
paulson <lp15@cam.ac.uk>
parents: 69597
diff changeset
   731
    have "poly p \<noteq> poly ([- a, 1] %^ Suc (order a p) *** qa)"
c06c95576ea9 Tidied some messy proofs
paulson <lp15@cam.ac.uk>
parents: 69597
diff changeset
   732
      using assms local.divides_def local.order2 by blast
c06c95576ea9 Tidied some messy proofs
paulson <lp15@cam.ac.uk>
parents: 69597
diff changeset
   733
    with q that show False
c06c95576ea9 Tidied some messy proofs
paulson <lp15@cam.ac.uk>
parents: 69597
diff changeset
   734
      by (auto simp add: poly_mult ac_simps simp del: pmult_Cons)
c06c95576ea9 Tidied some messy proofs
paulson <lp15@cam.ac.uk>
parents: 69597
diff changeset
   735
  qed 
c06c95576ea9 Tidied some messy proofs
paulson <lp15@cam.ac.uk>
parents: 69597
diff changeset
   736
  with q show ?thesis
c06c95576ea9 Tidied some messy proofs
paulson <lp15@cam.ac.uk>
parents: 69597
diff changeset
   737
    unfolding divides_def by blast
c06c95576ea9 Tidied some messy proofs
paulson <lp15@cam.ac.uk>
parents: 69597
diff changeset
   738
qed
33153
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   739
60536
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   740
text \<open>Important composition properties of orders.\<close>
54219
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   741
lemma order_mult:
60536
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   742
  fixes a :: "'a::idom_char_0"
54219
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   743
  assumes "poly (p *** q) \<noteq> poly []"
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   744
  shows "order a (p *** q) = order a p + order a q"
80098
c06c95576ea9 Tidied some messy proofs
paulson <lp15@cam.ac.uk>
parents: 69597
diff changeset
   745
proof -
c06c95576ea9 Tidied some messy proofs
paulson <lp15@cam.ac.uk>
parents: 69597
diff changeset
   746
  have p: "poly p \<noteq> poly []" and q: "poly q \<noteq> poly []"
c06c95576ea9 Tidied some messy proofs
paulson <lp15@cam.ac.uk>
parents: 69597
diff changeset
   747
    using assms poly_entire by auto
c06c95576ea9 Tidied some messy proofs
paulson <lp15@cam.ac.uk>
parents: 69597
diff changeset
   748
  obtain p' where p': 
c06c95576ea9 Tidied some messy proofs
paulson <lp15@cam.ac.uk>
parents: 69597
diff changeset
   749
          "\<And>x. poly p x = poly ([- a, 1] %^ order a p) x * poly p' x"
c06c95576ea9 Tidied some messy proofs
paulson <lp15@cam.ac.uk>
parents: 69597
diff changeset
   750
          "\<not> [- a, 1] divides p'"
c06c95576ea9 Tidied some messy proofs
paulson <lp15@cam.ac.uk>
parents: 69597
diff changeset
   751
    by (metis order_decomp p poly_mult)
c06c95576ea9 Tidied some messy proofs
paulson <lp15@cam.ac.uk>
parents: 69597
diff changeset
   752
  obtain q' where q': 
c06c95576ea9 Tidied some messy proofs
paulson <lp15@cam.ac.uk>
parents: 69597
diff changeset
   753
          "\<And>x. poly q x = poly ([- a, 1] %^ order a q) x * poly q' x"
c06c95576ea9 Tidied some messy proofs
paulson <lp15@cam.ac.uk>
parents: 69597
diff changeset
   754
          "\<not> [- a, 1] divides q'"
c06c95576ea9 Tidied some messy proofs
paulson <lp15@cam.ac.uk>
parents: 69597
diff changeset
   755
    by (metis order_decomp q poly_mult)
c06c95576ea9 Tidied some messy proofs
paulson <lp15@cam.ac.uk>
parents: 69597
diff changeset
   756
  have "[- a, 1] %^ (order a p + order a q) divides (p *** q)"
c06c95576ea9 Tidied some messy proofs
paulson <lp15@cam.ac.uk>
parents: 69597
diff changeset
   757
  proof -
c06c95576ea9 Tidied some messy proofs
paulson <lp15@cam.ac.uk>
parents: 69597
diff changeset
   758
    have *: "poly p x * poly q x =
c06c95576ea9 Tidied some messy proofs
paulson <lp15@cam.ac.uk>
parents: 69597
diff changeset
   759
          poly ([- a, 1] %^ order a p) x * poly ([- a, 1] %^ order a q) x * poly (p' *** q') x" for x
c06c95576ea9 Tidied some messy proofs
paulson <lp15@cam.ac.uk>
parents: 69597
diff changeset
   760
      using p' q' by (simp add: poly_mult)
c06c95576ea9 Tidied some messy proofs
paulson <lp15@cam.ac.uk>
parents: 69597
diff changeset
   761
    then show ?thesis
c06c95576ea9 Tidied some messy proofs
paulson <lp15@cam.ac.uk>
parents: 69597
diff changeset
   762
      unfolding divides_def  poly_exp_add poly_mult using * by blast
c06c95576ea9 Tidied some messy proofs
paulson <lp15@cam.ac.uk>
parents: 69597
diff changeset
   763
  qed
c06c95576ea9 Tidied some messy proofs
paulson <lp15@cam.ac.uk>
parents: 69597
diff changeset
   764
  moreover have False
c06c95576ea9 Tidied some messy proofs
paulson <lp15@cam.ac.uk>
parents: 69597
diff changeset
   765
    if pq: "order a (p *** q) \<noteq> order a p + order a q"
c06c95576ea9 Tidied some messy proofs
paulson <lp15@cam.ac.uk>
parents: 69597
diff changeset
   766
      and dv: "[- a, 1] *** [- a, 1] %^ (order a p + order a q) divides (p *** q)"
c06c95576ea9 Tidied some messy proofs
paulson <lp15@cam.ac.uk>
parents: 69597
diff changeset
   767
  proof -
c06c95576ea9 Tidied some messy proofs
paulson <lp15@cam.ac.uk>
parents: 69597
diff changeset
   768
    obtain pq' :: "'a list"
c06c95576ea9 Tidied some messy proofs
paulson <lp15@cam.ac.uk>
parents: 69597
diff changeset
   769
      where pq': "poly (p *** q) = poly ([- a, 1] *** [- a, 1] %^ (order a p + order a q) *** pq')"
c06c95576ea9 Tidied some messy proofs
paulson <lp15@cam.ac.uk>
parents: 69597
diff changeset
   770
      using dv unfolding divides_def by auto
c06c95576ea9 Tidied some messy proofs
paulson <lp15@cam.ac.uk>
parents: 69597
diff changeset
   771
    have "poly ([-a, 1] %^ (order a q) *** ([-a, 1] %^ (order a p) *** (p' *** q'))) =
c06c95576ea9 Tidied some messy proofs
paulson <lp15@cam.ac.uk>
parents: 69597
diff changeset
   772
          poly ([-a, 1] %^ (order a q) *** ([-a, 1] %^ (order a p) *** ([-a, 1] *** pq')))"
c06c95576ea9 Tidied some messy proofs
paulson <lp15@cam.ac.uk>
parents: 69597
diff changeset
   773
      using p' q' pq pq'
c06c95576ea9 Tidied some messy proofs
paulson <lp15@cam.ac.uk>
parents: 69597
diff changeset
   774
      by (simp add: fun_eq_iff poly_exp_add poly_mult ac_simps del: pmult_Cons)
c06c95576ea9 Tidied some messy proofs
paulson <lp15@cam.ac.uk>
parents: 69597
diff changeset
   775
    then have "poly ([-a, 1] %^ (order a p) *** (p' *** q')) = poly ([-a, 1] %^ (order a p) *** ([-a, 1] *** pq'))"
c06c95576ea9 Tidied some messy proofs
paulson <lp15@cam.ac.uk>
parents: 69597
diff changeset
   776
      by (simp add: poly_mult_left_cancel)
c06c95576ea9 Tidied some messy proofs
paulson <lp15@cam.ac.uk>
parents: 69597
diff changeset
   777
    then have "[-a, 1] divides (p' *** q')"
c06c95576ea9 Tidied some messy proofs
paulson <lp15@cam.ac.uk>
parents: 69597
diff changeset
   778
      unfolding divides_def by (meson poly_exp_prime_eq_zero poly_mult_left_cancel)
c06c95576ea9 Tidied some messy proofs
paulson <lp15@cam.ac.uk>
parents: 69597
diff changeset
   779
    with p' q' show ?thesis
c06c95576ea9 Tidied some messy proofs
paulson <lp15@cam.ac.uk>
parents: 69597
diff changeset
   780
      by (simp add: poly_primes)
c06c95576ea9 Tidied some messy proofs
paulson <lp15@cam.ac.uk>
parents: 69597
diff changeset
   781
  qed
c06c95576ea9 Tidied some messy proofs
paulson <lp15@cam.ac.uk>
parents: 69597
diff changeset
   782
  ultimately show ?thesis
c06c95576ea9 Tidied some messy proofs
paulson <lp15@cam.ac.uk>
parents: 69597
diff changeset
   783
    by (metis order pexp_Suc)
c06c95576ea9 Tidied some messy proofs
paulson <lp15@cam.ac.uk>
parents: 69597
diff changeset
   784
qed
54219
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   785
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   786
lemma (in idom_char_0) order_root2: "poly p \<noteq> poly [] \<Longrightarrow> poly p a = 0 \<longleftrightarrow> order a p \<noteq> 0"
80098
c06c95576ea9 Tidied some messy proofs
paulson <lp15@cam.ac.uk>
parents: 69597
diff changeset
   787
  using order_root by presburger
33153
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   788
60536
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   789
lemma (in semiring_1) pmult_one[simp]: "[1] *** p = p"
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   790
  by auto
33153
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   791
54219
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   792
lemma (in semiring_0) poly_Nil_zero: "poly [] = poly [0]"
60536
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   793
  by (simp add: fun_eq_iff)
33153
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   794
54219
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   795
lemma (in idom_char_0) rsquarefree_decomp:
80098
c06c95576ea9 Tidied some messy proofs
paulson <lp15@cam.ac.uk>
parents: 69597
diff changeset
   796
  assumes "rsquarefree p" and "poly p a = 0"
c06c95576ea9 Tidied some messy proofs
paulson <lp15@cam.ac.uk>
parents: 69597
diff changeset
   797
  shows "\<exists>q. poly p = poly ([-a, 1] *** q) \<and> poly q a \<noteq> 0"
c06c95576ea9 Tidied some messy proofs
paulson <lp15@cam.ac.uk>
parents: 69597
diff changeset
   798
proof -
c06c95576ea9 Tidied some messy proofs
paulson <lp15@cam.ac.uk>
parents: 69597
diff changeset
   799
  have "order a p = Suc 0"
c06c95576ea9 Tidied some messy proofs
paulson <lp15@cam.ac.uk>
parents: 69597
diff changeset
   800
    using assms local.order_root2 rsquarefree_def by force
c06c95576ea9 Tidied some messy proofs
paulson <lp15@cam.ac.uk>
parents: 69597
diff changeset
   801
  moreover
c06c95576ea9 Tidied some messy proofs
paulson <lp15@cam.ac.uk>
parents: 69597
diff changeset
   802
  obtain q where "poly p = poly ([- a, 1] %^ order a p *** q)" 
c06c95576ea9 Tidied some messy proofs
paulson <lp15@cam.ac.uk>
parents: 69597
diff changeset
   803
                 "\<not> [- a, 1] divides q"
c06c95576ea9 Tidied some messy proofs
paulson <lp15@cam.ac.uk>
parents: 69597
diff changeset
   804
    using assms(1) order_decomp rsquarefree_def by blast
c06c95576ea9 Tidied some messy proofs
paulson <lp15@cam.ac.uk>
parents: 69597
diff changeset
   805
  ultimately show ?thesis
c06c95576ea9 Tidied some messy proofs
paulson <lp15@cam.ac.uk>
parents: 69597
diff changeset
   806
    using dividesI poly_linear_divides by auto
c06c95576ea9 Tidied some messy proofs
paulson <lp15@cam.ac.uk>
parents: 69597
diff changeset
   807
qed
33153
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   808
60536
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   809
text \<open>Normalization of a polynomial.\<close>
33153
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   810
54219
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   811
lemma (in semiring_0) poly_normalize[simp]: "poly (pnormalize p) = poly p"
60536
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   812
  by (induct p) (auto simp add: fun_eq_iff)
33153
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   813
60536
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   814
text \<open>The degree of a polynomial.\<close>
33153
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   815
60537
5398aa5a4df9 eliminated list_all;
wenzelm
parents: 60536
diff changeset
   816
lemma (in semiring_0) lemma_degree_zero: "(\<forall>c \<in> set p. c = 0) \<longleftrightarrow> pnormalize p = []"
52778
19fa3e3964f0 tuned proofs;
wenzelm
parents: 49962
diff changeset
   817
  by (induct p) auto
33153
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   818
54219
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   819
lemma (in idom_char_0) degree_zero:
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   820
  assumes "poly p = poly []"
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   821
  shows "degree p = 0"
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   822
  using assms
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   823
  by (cases "pnormalize p = []") (auto simp add: degree_def poly_zero lemma_degree_zero)
33153
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   824
60536
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   825
lemma (in semiring_0) pnormalize_sing: "pnormalize [x] = [x] \<longleftrightarrow> x \<noteq> 0"
54219
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   826
  by simp
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   827
60536
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   828
lemma (in semiring_0) pnormalize_pair: "y \<noteq> 0 \<longleftrightarrow> pnormalize [x, y] = [x, y]"
52881
4eb44754f1bb misc tuning and simplification;
wenzelm
parents: 52778
diff changeset
   829
  by simp
52778
19fa3e3964f0 tuned proofs;
wenzelm
parents: 49962
diff changeset
   830
60536
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   831
lemma (in semiring_0) pnormal_cons: "pnormal p \<Longrightarrow> pnormal (c # p)"
33153
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
   832
  unfolding pnormal_def by simp
52778
19fa3e3964f0 tuned proofs;
wenzelm
parents: 49962
diff changeset
   833
60536
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   834
lemma (in semiring_0) pnormal_tail: "p \<noteq> [] \<Longrightarrow> pnormal (c # p) \<Longrightarrow> pnormal p"
62390
842917225d56 more canonical names
nipkow
parents: 62378
diff changeset
   835
  unfolding pnormal_def by (auto split: if_split_asm)
54219
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   836
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   837
lemma (in semiring_0) pnormal_last_nonzero: "pnormal p \<Longrightarrow> last p \<noteq> 0"
62390
842917225d56 more canonical names
nipkow
parents: 62378
diff changeset
   838
  by (induct p) (simp_all add: pnormal_def split: if_split_asm)
54219
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   839
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   840
lemma (in semiring_0) pnormal_length: "pnormal p \<Longrightarrow> 0 < length p"
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   841
  unfolding pnormal_def length_greater_0_conv by blast
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   842
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   843
lemma (in semiring_0) pnormal_last_length: "0 < length p \<Longrightarrow> last p \<noteq> 0 \<Longrightarrow> pnormal p"
62390
842917225d56 more canonical names
nipkow
parents: 62378
diff changeset
   844
  by (induct p) (auto simp: pnormal_def  split: if_split_asm)
54219
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   845
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   846
lemma (in semiring_0) pnormal_id: "pnormal p \<longleftrightarrow> 0 < length p \<and> last p \<noteq> 0"
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   847
  using pnormal_last_length pnormal_length pnormal_last_nonzero by blast
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   848
60698
29e8bdc41f90 tuned proofs;
wenzelm
parents: 60537
diff changeset
   849
lemma (in idom_char_0) poly_Cons_eq: "poly (c # cs) = poly (d # ds) \<longleftrightarrow> c = d \<and> poly cs = poly ds"
54219
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   850
  (is "?lhs \<longleftrightarrow> ?rhs")
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   851
proof
60536
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   852
  show ?rhs if ?lhs
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   853
  proof -
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   854
    from that have "poly ((c # cs) +++ -- (d # ds)) x = 0" for x
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   855
      by (simp only: poly_minus poly_add algebra_simps) (simp add: algebra_simps)
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   856
    then have "poly ((c # cs) +++ -- (d # ds)) = poly []"
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   857
      by (simp add: fun_eq_iff)
60537
5398aa5a4df9 eliminated list_all;
wenzelm
parents: 60536
diff changeset
   858
    then have "c = d" and "\<forall>x \<in> set (cs +++ -- ds). x = 0"
60536
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   859
      unfolding poly_zero by (simp_all add: poly_minus_def algebra_simps)
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   860
    from this(2) have "poly (cs +++ -- ds) x = 0" for x
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   861
      unfolding poly_zero[symmetric] by simp
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   862
    with \<open>c = d\<close> show ?thesis
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   863
      by (simp add: poly_minus poly_add algebra_simps fun_eq_iff)
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   864
  qed
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   865
  show ?lhs if ?rhs
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   866
    using that by (simp add:fun_eq_iff)
54219
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   867
qed
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   868
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   869
lemma (in idom_char_0) pnormalize_unique: "poly p = poly q \<Longrightarrow> pnormalize p = pnormalize q"
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   870
proof (induct q arbitrary: p)
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   871
  case Nil
60536
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   872
  then show ?case
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   873
    by (simp only: poly_zero lemma_degree_zero) simp
54219
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   874
next
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   875
  case (Cons c cs p)
60536
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   876
  then show ?case
54219
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   877
  proof (induct p)
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   878
    case Nil
60536
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   879
    then show ?case
80098
c06c95576ea9 Tidied some messy proofs
paulson <lp15@cam.ac.uk>
parents: 69597
diff changeset
   880
      by (metis local.poly_zero_lemma')
54219
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   881
  next
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   882
    case (Cons d ds)
80098
c06c95576ea9 Tidied some messy proofs
paulson <lp15@cam.ac.uk>
parents: 69597
diff changeset
   883
    then show ?case
c06c95576ea9 Tidied some messy proofs
paulson <lp15@cam.ac.uk>
parents: 69597
diff changeset
   884
      by (metis pnormalize.pnormalize_Cons local.poly_Cons_eq)
54219
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   885
  qed
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   886
qed
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   887
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   888
lemma (in idom_char_0) degree_unique:
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   889
  assumes pq: "poly p = poly q"
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   890
  shows "degree p = degree q"
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   891
  using pnormalize_unique[OF pq] unfolding degree_def by simp
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   892
60536
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   893
lemma (in semiring_0) pnormalize_length: "length (pnormalize p) \<le> length p"
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   894
  by (induct p) auto
54219
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   895
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   896
lemma (in semiring_0) last_linear_mul_lemma:
60536
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   897
  "last ((a %* p) +++ (x # (b %* p))) = (if p = [] then x else b * last p)"
80098
c06c95576ea9 Tidied some messy proofs
paulson <lp15@cam.ac.uk>
parents: 69597
diff changeset
   898
proof (induct p arbitrary: a x b)
c06c95576ea9 Tidied some messy proofs
paulson <lp15@cam.ac.uk>
parents: 69597
diff changeset
   899
  case Nil
c06c95576ea9 Tidied some messy proofs
paulson <lp15@cam.ac.uk>
parents: 69597
diff changeset
   900
  then show ?case by auto
c06c95576ea9 Tidied some messy proofs
paulson <lp15@cam.ac.uk>
parents: 69597
diff changeset
   901
next
c06c95576ea9 Tidied some messy proofs
paulson <lp15@cam.ac.uk>
parents: 69597
diff changeset
   902
  case (Cons a p c x b)
c06c95576ea9 Tidied some messy proofs
paulson <lp15@cam.ac.uk>
parents: 69597
diff changeset
   903
  then have "padd (cmult c p) (times b a # cmult b p) \<noteq> []"
c06c95576ea9 Tidied some messy proofs
paulson <lp15@cam.ac.uk>
parents: 69597
diff changeset
   904
    by (metis local.padd.padd_Nil local.padd_Cons_Cons neq_Nil_conv)
c06c95576ea9 Tidied some messy proofs
paulson <lp15@cam.ac.uk>
parents: 69597
diff changeset
   905
  then show ?case
c06c95576ea9 Tidied some messy proofs
paulson <lp15@cam.ac.uk>
parents: 69597
diff changeset
   906
    by (simp add: local.Cons)
c06c95576ea9 Tidied some messy proofs
paulson <lp15@cam.ac.uk>
parents: 69597
diff changeset
   907
qed
52778
19fa3e3964f0 tuned proofs;
wenzelm
parents: 49962
diff changeset
   908
54219
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   909
lemma (in semiring_1) last_linear_mul:
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   910
  assumes p: "p \<noteq> []"
60536
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   911
  shows "last ([a, 1] *** p) = last p"
54219
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   912
proof -
60536
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   913
  from p obtain c cs where cs: "p = c # cs"
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   914
    by (cases p) auto
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   915
  from cs have eq: "[a, 1] *** p = (a %* (c # cs)) +++ (0 # (1 %* (c # cs)))"
54219
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   916
    by (simp add: poly_cmult_distr)
60536
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   917
  show ?thesis
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   918
    using cs unfolding eq last_linear_mul_lemma by simp
54219
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   919
qed
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   920
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   921
lemma (in semiring_0) pnormalize_eq: "last p \<noteq> 0 \<Longrightarrow> pnormalize p = p"
62390
842917225d56 more canonical names
nipkow
parents: 62378
diff changeset
   922
  by (induct p) (auto split: if_split_asm)
54219
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   923
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   924
lemma (in semiring_0) last_pnormalize: "pnormalize p \<noteq> [] \<Longrightarrow> last (pnormalize p) \<noteq> 0"
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   925
  by (induct p) auto
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   926
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   927
lemma (in semiring_0) pnormal_degree: "last p \<noteq> 0 \<Longrightarrow> degree p = length p - 1"
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   928
  using pnormalize_eq[of p] unfolding degree_def by simp
52778
19fa3e3964f0 tuned proofs;
wenzelm
parents: 49962
diff changeset
   929
54219
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   930
lemma (in semiring_0) poly_Nil_ext: "poly [] = (\<lambda>x. 0)"
60536
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   931
  by auto
54219
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   932
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   933
lemma (in idom_char_0) linear_mul_degree:
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   934
  assumes p: "poly p \<noteq> poly []"
60536
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   935
  shows "degree ([a, 1] *** p) = degree p + 1"
54219
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   936
proof -
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   937
  from p have pnz: "pnormalize p \<noteq> []"
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   938
    unfolding poly_zero lemma_degree_zero .
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   939
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   940
  from last_linear_mul[OF pnz, of a] last_pnormalize[OF pnz]
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   941
  have l0: "last ([a, 1] *** pnormalize p) \<noteq> 0" by simp
60536
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   942
54219
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   943
  from last_pnormalize[OF pnz] last_linear_mul[OF pnz, of a]
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   944
    pnormal_degree[OF l0] pnormal_degree[OF last_pnormalize[OF pnz]] pnz
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   945
  have th: "degree ([a,1] *** pnormalize p) = degree (pnormalize p) + 1"
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   946
    by simp
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   947
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   948
  have eqs: "poly ([a,1] *** pnormalize p) = poly ([a,1] *** p)"
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   949
    by (rule ext) (simp add: poly_mult poly_add poly_cmult)
60536
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   950
  from degree_unique[OF eqs] th show ?thesis
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   951
    by (simp add: degree_unique[OF poly_normalize])
54219
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   952
qed
52778
19fa3e3964f0 tuned proofs;
wenzelm
parents: 49962
diff changeset
   953
54219
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   954
lemma (in idom_char_0) linear_pow_mul_degree:
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   955
  "degree([a,1] %^n *** p) = (if poly p = poly [] then 0 else degree p + n)"
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   956
proof (induct n arbitrary: a p)
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   957
  case (0 a p)
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   958
  show ?case
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   959
  proof (cases "poly p = poly []")
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   960
    case True
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   961
    then show ?thesis
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   962
      using degree_unique[OF True] by (simp add: degree_def)
80098
c06c95576ea9 Tidied some messy proofs
paulson <lp15@cam.ac.uk>
parents: 69597
diff changeset
   963
  qed (auto simp add: poly_Nil_ext)
54219
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   964
next
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   965
  case (Suc n a p)
60536
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   966
  have eq: "poly ([a, 1] %^(Suc n) *** p) = poly ([a, 1] %^ n *** ([a, 1] *** p))"
80098
c06c95576ea9 Tidied some messy proofs
paulson <lp15@cam.ac.uk>
parents: 69597
diff changeset
   967
    by (force simp add: poly_mult poly_add poly_cmult ac_simps distrib_left)
54219
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   968
  note deq = degree_unique[OF eq]
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   969
  show ?case
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   970
  proof (cases "poly p = poly []")
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   971
    case True
60536
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   972
    with eq have eq': "poly ([a, 1] %^(Suc n) *** p) = poly []"
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   973
      by (auto simp add: poly_mult poly_cmult poly_add)
54219
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   974
    from degree_unique[OF eq'] True show ?thesis
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   975
      by (simp add: degree_def)
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   976
  next
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   977
    case False
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   978
    then have ap: "poly ([a,1] *** p) \<noteq> poly []"
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   979
      using poly_mult_not_eq_poly_Nil unfolding poly_entire by auto
60536
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   980
    have eq: "poly ([a, 1] %^(Suc n) *** p) = poly ([a, 1]%^n *** ([a, 1] *** p))"
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   981
      by (auto simp add: poly_mult poly_add poly_exp poly_cmult algebra_simps)
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   982
    from ap have ap': "poly ([a, 1] *** p) = poly [] \<longleftrightarrow> False"
54219
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   983
      by blast
60536
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   984
    have th0: "degree ([a, 1]%^n *** ([a, 1] *** p)) = degree ([a, 1] *** p) + n"
80098
c06c95576ea9 Tidied some messy proofs
paulson <lp15@cam.ac.uk>
parents: 69597
diff changeset
   985
      unfolding Suc.hyps[of a "pmult [a,one] p"] ap' by simp
54219
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   986
    from degree_unique[OF eq] ap False th0 linear_mul_degree[OF False, of a]
60536
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   987
    show ?thesis
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   988
      by (auto simp del: poly.simps)
54219
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   989
  qed
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   990
qed
52778
19fa3e3964f0 tuned proofs;
wenzelm
parents: 49962
diff changeset
   991
54219
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   992
lemma (in idom_char_0) order_degree:
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   993
  assumes p0: "poly p \<noteq> poly []"
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   994
  shows "order a p \<le> degree p"
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   995
proof -
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
   996
  from order2[OF p0, unfolded divides_def]
60536
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   997
  obtain q where q: "poly p = poly ([- a, 1]%^ (order a p) *** q)"
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   998
    by blast
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
   999
  with q p0 have "poly q \<noteq> poly []"
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
  1000
    by (simp add: poly_mult poly_entire)
54219
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
  1001
  with degree_unique[OF q, unfolded linear_pow_mul_degree] show ?thesis
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
  1002
    by auto
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
  1003
qed
33153
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
  1004
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
  1005
60536
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
  1006
text \<open>Tidier versions of finiteness of roots.\<close>
54219
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
  1007
lemma (in idom_char_0) poly_roots_finite_set:
63fe59f64578 consolidated clone theory
haftmann
parents: 52881
diff changeset
  1008
  "poly p \<noteq> poly [] \<Longrightarrow> finite {x. poly p x = 0}"
52778
19fa3e3964f0 tuned proofs;
wenzelm
parents: 49962
diff changeset
  1009
  unfolding poly_roots_finite .
33153
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
  1010
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
  1011
60536
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
  1012
text \<open>Bound for polynomial.\<close>
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
  1013
lemma poly_mono:
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
  1014
  fixes x :: "'a::linordered_idom"
61945
1135b8de26c3 more symbols;
wenzelm
parents: 61586
diff changeset
  1015
  shows "\<bar>x\<bar> \<le> k \<Longrightarrow> \<bar>poly p x\<bar> \<le> poly (map abs p) k"
60698
29e8bdc41f90 tuned proofs;
wenzelm
parents: 60537
diff changeset
  1016
proof (induct p)
29e8bdc41f90 tuned proofs;
wenzelm
parents: 60537
diff changeset
  1017
  case Nil
29e8bdc41f90 tuned proofs;
wenzelm
parents: 60537
diff changeset
  1018
  then show ?case by simp
29e8bdc41f90 tuned proofs;
wenzelm
parents: 60537
diff changeset
  1019
next
29e8bdc41f90 tuned proofs;
wenzelm
parents: 60537
diff changeset
  1020
  case (Cons a p)
80098
c06c95576ea9 Tidied some messy proofs
paulson <lp15@cam.ac.uk>
parents: 69597
diff changeset
  1021
  have "\<bar>a + x * poly p x\<bar> \<le> \<bar>a\<bar> + \<bar>x * poly p x\<bar>"
c06c95576ea9 Tidied some messy proofs
paulson <lp15@cam.ac.uk>
parents: 69597
diff changeset
  1022
    using abs_triangle_ineq by blast
c06c95576ea9 Tidied some messy proofs
paulson <lp15@cam.ac.uk>
parents: 69597
diff changeset
  1023
  also have "\<dots> \<le> \<bar>a\<bar> + k * poly (map abs p) k"
c06c95576ea9 Tidied some messy proofs
paulson <lp15@cam.ac.uk>
parents: 69597
diff changeset
  1024
    by (simp add: Cons.hyps Cons.prems abs_mult mult_mono')
c06c95576ea9 Tidied some messy proofs
paulson <lp15@cam.ac.uk>
parents: 69597
diff changeset
  1025
  finally show ?case
c06c95576ea9 Tidied some messy proofs
paulson <lp15@cam.ac.uk>
parents: 69597
diff changeset
  1026
    using Cons by auto
60698
29e8bdc41f90 tuned proofs;
wenzelm
parents: 60537
diff changeset
  1027
qed
33153
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
  1028
60536
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
  1029
lemma (in semiring_0) poly_Sing: "poly [c] x = c"
00db0d934a7d tuned proofs;
wenzelm
parents: 60533
diff changeset
  1030
  by simp
33268
02de0317f66f eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents: 33153
diff changeset
  1031
33153
92080294beb8 A theory of polynomials based on lists
chaieb
parents:
diff changeset
  1032
end