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