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