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