src/HOL/Univ_Poly.thy
 author nipkow Thu Dec 11 08:52:50 2008 +0100 (2008-12-11) changeset 29106 25e28a4070f3 parent 28952 15a4b2cf8c34 child 29292 11045b88af1a permissions -rw-r--r--
Testfile for Stefan's code generator
 chaieb@26124 ` 1` ```(* Title: Univ_Poly.thy ``` chaieb@26124 ` 2` ``` Author: Amine Chaieb ``` chaieb@26124 ` 3` ```*) ``` chaieb@26124 ` 4` chaieb@26124 ` 5` ```header{*Univariate Polynomials*} ``` chaieb@26124 ` 6` chaieb@26124 ` 7` ```theory Univ_Poly ``` haftmann@28952 ` 8` ```imports Plain List ``` 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` haftmann@26194 ` 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@28562 ` 74` ``` [code del]: "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*} ``` chaieb@26124 ` 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 ``` chaieb@26124 ` 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" ``` chaieb@26124 ` 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) ``` chaieb@26124 ` 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 recpower_semiring = semiring + recpower ``` chaieb@26124 ` 171` ```class recpower_semiring_1 = semiring_1 + recpower ``` chaieb@26124 ` 172` ```class recpower_semiring_0 = semiring_0 + recpower ``` chaieb@26124 ` 173` ```class recpower_ring = ring + recpower ``` chaieb@26124 ` 174` ```class recpower_ring_1 = ring_1 + recpower ``` haftmann@28823 ` 175` ```subclass (in recpower_ring_1) recpower_ring .. ``` chaieb@26124 ` 176` ```class recpower_comm_semiring_1 = recpower + comm_semiring_1 ``` chaieb@26124 ` 177` ```class recpower_comm_ring_1 = recpower + comm_ring_1 ``` haftmann@28823 ` 178` ```subclass (in recpower_comm_ring_1) recpower_comm_semiring_1 .. ``` chaieb@26124 ` 179` ```class recpower_idom = recpower + idom ``` haftmann@28823 ` 180` ```subclass (in recpower_idom) recpower_comm_ring_1 .. ``` chaieb@26124 ` 181` ```class idom_char_0 = idom + ring_char_0 ``` chaieb@26124 ` 182` ```class recpower_idom_char_0 = recpower + idom_char_0 ``` haftmann@28823 ` 183` ```subclass (in recpower_idom_char_0) recpower_idom .. ``` chaieb@26124 ` 184` chaieb@26124 ` 185` ```lemma (in recpower_comm_ring_1) poly_exp: "poly (p %^ n) x = (poly p x) ^ n" ``` chaieb@26124 ` 186` ```apply (induct "n") ``` chaieb@26124 ` 187` ```apply (auto simp add: poly_cmult poly_mult power_Suc) ``` chaieb@26124 ` 188` ```done ``` chaieb@26124 ` 189` chaieb@26124 ` 190` ```text{*More Polynomial Evaluation Lemmas*} ``` chaieb@26124 ` 191` chaieb@26124 ` 192` ```lemma (in semiring_0) poly_add_rzero[simp]: "poly (a +++ []) x = poly a x" ``` chaieb@26124 ` 193` ```by simp ``` chaieb@26124 ` 194` chaieb@26124 ` 195` ```lemma (in comm_semiring_0) poly_mult_assoc: "poly ((a *** b) *** c) x = poly (a *** (b *** c)) x" ``` chaieb@26124 ` 196` ``` by (simp add: poly_mult mult_assoc) ``` chaieb@26124 ` 197` chaieb@26124 ` 198` ```lemma (in semiring_0) poly_mult_Nil2[simp]: "poly (p *** []) x = 0" ``` chaieb@26124 ` 199` ```by (induct "p", auto) ``` chaieb@26124 ` 200` chaieb@26124 ` 201` ```lemma (in comm_semiring_1) poly_exp_add: "poly (p %^ (n + d)) x = poly( p %^ n *** p %^ d) x" ``` chaieb@26124 ` 202` ```apply (induct "n") ``` chaieb@26124 ` 203` ```apply (auto simp add: poly_mult mult_assoc) ``` chaieb@26124 ` 204` ```done ``` chaieb@26124 ` 205` chaieb@26124 ` 206` ```subsection{*Key Property: if @{term "f(a) = 0"} then @{term "(x - a)"} divides ``` chaieb@26124 ` 207` ``` @{term "p(x)"} *} ``` chaieb@26124 ` 208` chaieb@26124 ` 209` ```lemma (in comm_ring_1) lemma_poly_linear_rem: "\h. \q r. h#t = [r] +++ [-a, 1] *** q" ``` chaieb@26124 ` 210` ```proof(induct t) ``` chaieb@26124 ` 211` ``` case Nil ``` chaieb@26124 ` 212` ``` {fix h have "[h] = [h] +++ [- a, 1] *** []" by simp} ``` chaieb@26124 ` 213` ``` thus ?case by blast ``` chaieb@26124 ` 214` ```next ``` chaieb@26124 ` 215` ``` case (Cons x xs) ``` chaieb@26124 ` 216` ``` {fix h ``` chaieb@26124 ` 217` ``` from Cons.hyps[rule_format, of x] ``` chaieb@26124 ` 218` ``` obtain q r where qr: "x#xs = [r] +++ [- a, 1] *** q" by blast ``` chaieb@26124 ` 219` ``` have "h#x#xs = [a*r + h] +++ [-a, 1] *** (r#q)" ``` chaieb@26124 ` 220` ``` using qr by(cases q, simp_all add: ring_simps diff_def[symmetric] ``` chaieb@26124 ` 221` ``` minus_mult_left[symmetric] right_minus) ``` chaieb@26124 ` 222` ``` hence "\q r. h#x#xs = [r] +++ [-a, 1] *** q" by blast} ``` chaieb@26124 ` 223` ``` thus ?case by blast ``` chaieb@26124 ` 224` ```qed ``` chaieb@26124 ` 225` chaieb@26124 ` 226` ```lemma (in comm_ring_1) poly_linear_rem: "\q r. h#t = [r] +++ [-a, 1] *** q" ``` chaieb@26124 ` 227` ```by (cut_tac t = t and a = a in lemma_poly_linear_rem, auto) ``` chaieb@26124 ` 228` chaieb@26124 ` 229` chaieb@26124 ` 230` ```lemma (in comm_ring_1) poly_linear_divides: "(poly p a = 0) = ((p = []) | (\q. p = [-a, 1] *** q))" ``` chaieb@26124 ` 231` ```proof- ``` chaieb@26124 ` 232` ``` {assume p: "p = []" hence ?thesis by simp} ``` chaieb@26124 ` 233` ``` moreover ``` chaieb@26124 ` 234` ``` {fix x xs assume p: "p = x#xs" ``` chaieb@26124 ` 235` ``` {fix q assume "p = [-a, 1] *** q" hence "poly p a = 0" ``` chaieb@26124 ` 236` ``` by (simp add: poly_add poly_cmult minus_mult_left[symmetric])} ``` chaieb@26124 ` 237` ``` moreover ``` chaieb@26124 ` 238` ``` {assume p0: "poly p a = 0" ``` chaieb@26124 ` 239` ``` from poly_linear_rem[of x xs a] obtain q r ``` chaieb@26124 ` 240` ``` where qr: "x#xs = [r] +++ [- a, 1] *** q" by blast ``` chaieb@26124 ` 241` ``` have "r = 0" using p0 by (simp only: p qr poly_mult poly_add) simp ``` chaieb@26124 ` 242` ``` 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 ` 243` ``` ultimately have ?thesis using p by blast} ``` chaieb@26124 ` 244` ``` ultimately show ?thesis by (cases p, auto) ``` chaieb@26124 ` 245` ```qed ``` chaieb@26124 ` 246` chaieb@26124 ` 247` ```lemma (in semiring_0) lemma_poly_length_mult[simp]: "\h k a. length (k %* p +++ (h # (a %* p))) = Suc (length p)" ``` chaieb@26124 ` 248` ```by (induct "p", auto) ``` chaieb@26124 ` 249` chaieb@26124 ` 250` ```lemma (in semiring_0) lemma_poly_length_mult2[simp]: "\h k. length (k %* p +++ (h # p)) = Suc (length p)" ``` chaieb@26124 ` 251` ```by (induct "p", auto) ``` chaieb@26124 ` 252` chaieb@26124 ` 253` ```lemma (in ring_1) poly_length_mult[simp]: "length([-a,1] *** q) = Suc (length q)" ``` chaieb@26124 ` 254` ```by auto ``` chaieb@26124 ` 255` chaieb@26124 ` 256` ```subsection{*Polynomial length*} ``` chaieb@26124 ` 257` chaieb@26124 ` 258` ```lemma (in semiring_0) poly_cmult_length[simp]: "length (a %* p) = length p" ``` chaieb@26124 ` 259` ```by (induct "p", auto) ``` chaieb@26124 ` 260` chaieb@26124 ` 261` ```lemma (in semiring_0) poly_add_length: "length (p1 +++ p2) = max (length p1) (length p2)" ``` chaieb@26124 ` 262` ```apply (induct p1 arbitrary: p2, simp_all) ``` chaieb@26124 ` 263` ```apply arith ``` chaieb@26124 ` 264` ```done ``` chaieb@26124 ` 265` chaieb@26124 ` 266` ```lemma (in semiring_0) poly_root_mult_length[simp]: "length([a,b] *** p) = Suc (length p)" ``` chaieb@26124 ` 267` ```by (simp add: poly_add_length) ``` chaieb@26124 ` 268` chaieb@26124 ` 269` ```lemma (in idom) poly_mult_not_eq_poly_Nil[simp]: ``` chaieb@26124 ` 270` ``` "poly (p *** q) x \ poly [] x \ poly p x \ poly [] x \ poly q x \ poly [] x" ``` chaieb@26124 ` 271` ```by (auto simp add: poly_mult) ``` chaieb@26124 ` 272` chaieb@26124 ` 273` ```lemma (in idom) poly_mult_eq_zero_disj: "poly (p *** q) x = 0 \ poly p x = 0 \ poly q x = 0" ``` chaieb@26124 ` 274` ```by (auto simp add: poly_mult) ``` chaieb@26124 ` 275` chaieb@26124 ` 276` ```text{*Normalisation Properties*} ``` chaieb@26124 ` 277` chaieb@26124 ` 278` ```lemma (in semiring_0) poly_normalized_nil: "(pnormalize p = []) --> (poly p x = 0)" ``` chaieb@26124 ` 279` ```by (induct "p", auto) ``` chaieb@26124 ` 280` chaieb@26124 ` 281` ```text{*A nontrivial polynomial of degree n has no more than n roots*} ``` chaieb@26124 ` 282` ```lemma (in idom) poly_roots_index_lemma: ``` chaieb@26124 ` 283` ``` assumes p: "poly p x \ poly [] x" and n: "length p = n" ``` chaieb@26124 ` 284` ``` shows "\i. \x. poly p x = 0 \ (\m\n. x = i m)" ``` chaieb@26124 ` 285` ``` using p n ``` chaieb@26124 ` 286` ```proof(induct n arbitrary: p x) ``` chaieb@26124 ` 287` ``` case 0 thus ?case by simp ``` chaieb@26124 ` 288` ```next ``` chaieb@26124 ` 289` ``` case (Suc n p x) ``` chaieb@26124 ` 290` ``` {assume C: "\i. \x. poly p x = 0 \ (\m\Suc n. x \ i m)" ``` chaieb@26124 ` 291` ``` from Suc.prems have p0: "poly p x \ 0" "p\ []" by auto ``` chaieb@26124 ` 292` ``` from p0(1)[unfolded poly_linear_divides[of p x]] ``` chaieb@26124 ` 293` ``` have "\q. p \ [- x, 1] *** q" by blast ``` chaieb@26124 ` 294` ``` from C obtain a where a: "poly p a = 0" by blast ``` chaieb@26124 ` 295` ``` from a[unfolded poly_linear_divides[of p a]] p0(2) ``` chaieb@26124 ` 296` ``` obtain q where q: "p = [-a, 1] *** q" by blast ``` chaieb@26124 ` 297` ``` have lg: "length q = n" using q Suc.prems(2) by simp ``` chaieb@26124 ` 298` ``` from q p0 have qx: "poly q x \ poly [] x" ``` chaieb@26124 ` 299` ``` by (auto simp add: poly_mult poly_add poly_cmult) ``` chaieb@26124 ` 300` ``` from Suc.hyps[OF qx lg] obtain i where ``` chaieb@26124 ` 301` ``` i: "\x. poly q x = 0 \ (\m\n. x = i m)" by blast ``` chaieb@26124 ` 302` ``` let ?i = "\m. if m = Suc n then a else i m" ``` chaieb@26124 ` 303` ``` from C[of ?i] obtain y where y: "poly p y = 0" "\m\ Suc n. y \ ?i m" ``` chaieb@26124 ` 304` ``` by blast ``` chaieb@26124 ` 305` ``` from y have "y = a \ poly q y = 0" ``` chaieb@26124 ` 306` ``` by (simp only: q poly_mult_eq_zero_disj poly_add) (simp add: ring_simps) ``` chaieb@26124 ` 307` ``` with i[rule_format, of y] y(1) y(2) have False apply auto ``` chaieb@26124 ` 308` ``` apply (erule_tac x="m" in allE) ``` chaieb@26124 ` 309` ``` apply auto ``` chaieb@26124 ` 310` ``` done} ``` chaieb@26124 ` 311` ``` thus ?case by blast ``` chaieb@26124 ` 312` ```qed ``` chaieb@26124 ` 313` chaieb@26124 ` 314` chaieb@26124 ` 315` ```lemma (in idom) poly_roots_index_length: "poly p x \ poly [] x ==> ``` chaieb@26124 ` 316` ``` \i. \x. (poly p x = 0) --> (\n. n \ length p & x = i n)" ``` chaieb@26124 ` 317` ```by (blast intro: poly_roots_index_lemma) ``` chaieb@26124 ` 318` wenzelm@26313 ` 319` ```lemma (in idom) poly_roots_finite_lemma1: "poly p x \ poly [] x ==> ``` chaieb@26124 ` 320` ``` \N i. \x. (poly p x = 0) --> (\n. (n::nat) < N & x = i n)" ``` chaieb@26124 ` 321` ```apply (drule poly_roots_index_length, safe) ``` chaieb@26124 ` 322` ```apply (rule_tac x = "Suc (length p)" in exI) ``` chaieb@26124 ` 323` ```apply (rule_tac x = i in exI) ``` chaieb@26124 ` 324` ```apply (simp add: less_Suc_eq_le) ``` chaieb@26124 ` 325` ```done ``` chaieb@26124 ` 326` chaieb@26124 ` 327` chaieb@26124 ` 328` ```lemma (in idom) idom_finite_lemma: ``` chaieb@26124 ` 329` ``` assumes P: "\x. P x --> (\n. n < length j & x = j!n)" ``` chaieb@26124 ` 330` ``` shows "finite {x. P x}" ``` chaieb@26124 ` 331` ```proof- ``` chaieb@26124 ` 332` ``` let ?M = "{x. P x}" ``` chaieb@26124 ` 333` ``` let ?N = "set j" ``` chaieb@26124 ` 334` ``` have "?M \ ?N" using P by auto ``` chaieb@26124 ` 335` ``` thus ?thesis using finite_subset by auto ``` chaieb@26124 ` 336` ```qed ``` chaieb@26124 ` 337` chaieb@26124 ` 338` wenzelm@26313 ` 339` ```lemma (in idom) poly_roots_finite_lemma2: "poly p x \ poly [] x ==> ``` chaieb@26124 ` 340` ``` \i. \x. (poly p x = 0) --> x \ set i" ``` chaieb@26124 ` 341` ```apply (drule poly_roots_index_length, safe) ``` chaieb@26124 ` 342` ```apply (rule_tac x="map (\n. i n) [0 ..< Suc (length p)]" in exI) ``` chaieb@26124 ` 343` ```apply (auto simp add: image_iff) ``` chaieb@26124 ` 344` ```apply (erule_tac x="x" in allE, clarsimp) ``` chaieb@26124 ` 345` ```by (case_tac "n=length p", auto simp add: order_le_less) ``` chaieb@26124 ` 346` chaieb@26124 ` 347` ```lemma UNIV_nat_infinite: "\ finite (UNIV :: nat set)" ``` chaieb@26124 ` 348` ``` unfolding finite_conv_nat_seg_image ``` chaieb@26124 ` 349` ```proof(auto simp add: expand_set_eq image_iff) ``` chaieb@26124 ` 350` ``` fix n::nat and f:: "nat \ nat" ``` chaieb@26124 ` 351` ``` let ?N = "{i. i < n}" ``` chaieb@26124 ` 352` ``` let ?fN = "f ` ?N" ``` chaieb@26124 ` 353` ``` let ?y = "Max ?fN + 1" ``` chaieb@26124 ` 354` ``` from nat_seg_image_imp_finite[of "?fN" "f" n] ``` chaieb@26124 ` 355` ``` have thfN: "finite ?fN" by simp ``` chaieb@26124 ` 356` ``` {assume "n =0" hence "\x. \xa f xa" by auto} ``` chaieb@26124 ` 357` ``` moreover ``` chaieb@26124 ` 358` ``` {assume nz: "n \ 0" ``` chaieb@26124 ` 359` ``` hence thne: "?fN \ {}" by (auto simp add: neq0_conv) ``` chaieb@26124 ` 360` ``` have "\x\ ?fN. Max ?fN \ x" using nz Max_ge_iff[OF thfN thne] by auto ``` chaieb@26124 ` 361` ``` hence "\x\ ?fN. ?y > x" by auto ``` chaieb@26124 ` 362` ``` hence "?y \ ?fN" by auto ``` chaieb@26124 ` 363` ``` hence "\x. \xa f xa" by auto } ``` chaieb@26124 ` 364` ``` ultimately show "\x. \xa f xa" by blast ``` chaieb@26124 ` 365` ```qed ``` chaieb@26124 ` 366` chaieb@26124 ` 367` ```lemma (in ring_char_0) UNIV_ring_char_0_infinte: ``` chaieb@26124 ` 368` ``` "\ (finite (UNIV:: 'a set))" ``` chaieb@26124 ` 369` ```proof ``` chaieb@26124 ` 370` ``` assume F: "finite (UNIV :: 'a set)" ``` chaieb@26124 ` 371` ``` have th0: "of_nat ` UNIV \ UNIV" by simp ``` chaieb@26124 ` 372` ``` from finite_subset[OF th0] have th: "finite (of_nat ` UNIV :: 'a set)" . ``` chaieb@26124 ` 373` ``` have th': "inj_on (of_nat::nat \ 'a) (UNIV)" ``` chaieb@26124 ` 374` ``` unfolding inj_on_def by auto ``` chaieb@26124 ` 375` ``` from finite_imageD[OF th th'] UNIV_nat_infinite ``` chaieb@26124 ` 376` ``` show False by blast ``` chaieb@26124 ` 377` ```qed ``` chaieb@26124 ` 378` chaieb@26124 ` 379` ```lemma (in idom_char_0) poly_roots_finite: "(poly p \ poly []) = ``` chaieb@26124 ` 380` ``` finite {x. poly p x = 0}" ``` chaieb@26124 ` 381` ```proof ``` chaieb@26124 ` 382` ``` assume H: "poly p \ poly []" ``` chaieb@26124 ` 383` ``` show "finite {x. poly p x = (0::'a)}" ``` chaieb@26124 ` 384` ``` using H ``` chaieb@26124 ` 385` ``` apply - ``` chaieb@26124 ` 386` ``` apply (erule contrapos_np, rule ext) ``` chaieb@26124 ` 387` ``` apply (rule ccontr) ``` wenzelm@26313 ` 388` ``` apply (clarify dest!: poly_roots_finite_lemma2) ``` chaieb@26124 ` 389` ``` using finite_subset ``` chaieb@26124 ` 390` ``` proof- ``` chaieb@26124 ` 391` ``` fix x i ``` chaieb@26124 ` 392` ``` assume F: "\ finite {x. poly p x = (0\'a)}" ``` chaieb@26124 ` 393` ``` and P: "\x. poly p x = (0\'a) \ x \ set i" ``` chaieb@26124 ` 394` ``` let ?M= "{x. poly p x = (0\'a)}" ``` chaieb@26124 ` 395` ``` from P have "?M \ set i" by auto ``` chaieb@26124 ` 396` ``` with finite_subset F show False by auto ``` chaieb@26124 ` 397` ``` qed ``` chaieb@26124 ` 398` ```next ``` chaieb@26124 ` 399` ``` assume F: "finite {x. poly p x = (0\'a)}" ``` chaieb@26124 ` 400` ``` show "poly p \ poly []" using F UNIV_ring_char_0_infinte by auto ``` chaieb@26124 ` 401` ```qed ``` chaieb@26124 ` 402` chaieb@26124 ` 403` ```text{*Entirety and Cancellation for polynomials*} ``` chaieb@26124 ` 404` wenzelm@26313 ` 405` ```lemma (in idom_char_0) poly_entire_lemma2: ``` wenzelm@26313 ` 406` ``` assumes p0: "poly p \ poly []" and q0: "poly q \ poly []" ``` wenzelm@26313 ` 407` ``` shows "poly (p***q) \ poly []" ``` wenzelm@26313 ` 408` ```proof- ``` wenzelm@26313 ` 409` ``` let ?S = "\p. {x. poly p x = 0}" ``` wenzelm@26313 ` 410` ``` have "?S (p *** q) = ?S p \ ?S q" by (auto simp add: poly_mult) ``` wenzelm@26313 ` 411` ``` with p0 q0 show ?thesis unfolding poly_roots_finite by auto ``` wenzelm@26313 ` 412` ```qed ``` chaieb@26124 ` 413` wenzelm@26313 ` 414` ```lemma (in idom_char_0) poly_entire: ``` wenzelm@26313 ` 415` ``` "poly (p *** q) = poly [] \ poly p = poly [] \ poly q = poly []" ``` wenzelm@26313 ` 416` ```using poly_entire_lemma2[of p q] ``` wenzelm@26313 ` 417` ```by auto (rule ext, simp add: poly_mult)+ ``` chaieb@26124 ` 418` chaieb@26124 ` 419` ```lemma (in idom_char_0) poly_entire_neg: "(poly (p *** q) \ poly []) = ((poly p \ poly []) & (poly q \ poly []))" ``` chaieb@26124 ` 420` ```by (simp add: poly_entire) ``` chaieb@26124 ` 421` chaieb@26124 ` 422` ```lemma fun_eq: " (f = g) = (\x. f x = g x)" ``` chaieb@26124 ` 423` ```by (auto intro!: ext) ``` chaieb@26124 ` 424` chaieb@26124 ` 425` ```lemma (in comm_ring_1) poly_add_minus_zero_iff: "(poly (p +++ -- q) = poly []) = (poly p = poly q)" ``` chaieb@26124 ` 426` ```by (auto simp add: ring_simps poly_add poly_minus_def fun_eq poly_cmult minus_mult_left[symmetric]) ``` chaieb@26124 ` 427` chaieb@26124 ` 428` ```lemma (in comm_ring_1) poly_add_minus_mult_eq: "poly (p *** q +++ --(p *** r)) = poly (p *** (q +++ -- r))" ``` chaieb@26124 ` 429` ```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 ` 430` haftmann@28823 ` 431` ```subclass (in idom_char_0) comm_ring_1 .. ``` chaieb@26124 ` 432` ```lemma (in idom_char_0) poly_mult_left_cancel: "(poly (p *** q) = poly (p *** r)) = (poly p = poly [] | poly q = poly r)" ``` chaieb@26124 ` 433` ```proof- ``` chaieb@26124 ` 434` ``` have "poly (p *** q) = poly (p *** r) \ poly (p *** q +++ -- (p *** r)) = poly []" by (simp only: poly_add_minus_zero_iff) ``` chaieb@26124 ` 435` ``` also have "\ \ poly p = poly [] | poly q = poly r" ``` chaieb@26124 ` 436` ``` by (auto intro: ext simp add: poly_add_minus_mult_eq poly_entire poly_add_minus_zero_iff) ``` chaieb@26124 ` 437` ``` finally show ?thesis . ``` chaieb@26124 ` 438` ```qed ``` chaieb@26124 ` 439` chaieb@26124 ` 440` ```lemma (in recpower_idom) poly_exp_eq_zero[simp]: ``` chaieb@26124 ` 441` ``` "(poly (p %^ n) = poly []) = (poly p = poly [] & n \ 0)" ``` chaieb@26124 ` 442` ```apply (simp only: fun_eq add: all_simps [symmetric]) ``` chaieb@26124 ` 443` ```apply (rule arg_cong [where f = All]) ``` chaieb@26124 ` 444` ```apply (rule ext) ``` haftmann@26194 ` 445` ```apply (induct n) ``` chaieb@26124 ` 446` ```apply (auto simp add: poly_exp poly_mult) ``` chaieb@26124 ` 447` ```done ``` chaieb@26124 ` 448` chaieb@26124 ` 449` ```lemma (in semiring_1) one_neq_zero[simp]: "1 \ 0" using zero_neq_one by blast ``` chaieb@26124 ` 450` ```lemma (in comm_ring_1) poly_prime_eq_zero[simp]: "poly [a,1] \ poly []" ``` chaieb@26124 ` 451` ```apply (simp add: fun_eq) ``` chaieb@26124 ` 452` ```apply (rule_tac x = "minus one a" in exI) ``` chaieb@26124 ` 453` ```apply (unfold diff_minus) ``` chaieb@26124 ` 454` ```apply (subst add_commute) ``` chaieb@26124 ` 455` ```apply (subst add_assoc) ``` chaieb@26124 ` 456` ```apply simp ``` chaieb@26124 ` 457` ```done ``` chaieb@26124 ` 458` chaieb@26124 ` 459` ```lemma (in recpower_idom) poly_exp_prime_eq_zero: "(poly ([a, 1] %^ n) \ poly [])" ``` chaieb@26124 ` 460` ```by auto ``` chaieb@26124 ` 461` chaieb@26124 ` 462` ```text{*A more constructive notion of polynomials being trivial*} ``` chaieb@26124 ` 463` chaieb@26124 ` 464` ```lemma (in idom_char_0) poly_zero_lemma': "poly (h # t) = poly [] ==> h = 0 & poly t = poly []" ``` chaieb@26124 ` 465` ```apply(simp add: fun_eq) ``` chaieb@26124 ` 466` ```apply (case_tac "h = zero") ``` chaieb@26124 ` 467` ```apply (drule_tac [2] x = zero in spec, auto) ``` chaieb@26124 ` 468` ```apply (cases "poly t = poly []", simp) ``` chaieb@26124 ` 469` ```proof- ``` chaieb@26124 ` 470` ``` fix x ``` chaieb@26124 ` 471` ``` assume H: "\x. x = (0\'a) \ poly t x = (0\'a)" and pnz: "poly t \ poly []" ``` chaieb@26124 ` 472` ``` let ?S = "{x. poly t x = 0}" ``` chaieb@26124 ` 473` ``` from H have "\x. x \0 \ poly t x = 0" by blast ``` chaieb@26124 ` 474` ``` hence th: "?S \ UNIV - {0}" by auto ``` chaieb@26124 ` 475` ``` from poly_roots_finite pnz have th': "finite ?S" by blast ``` chaieb@26124 ` 476` ``` from finite_subset[OF th th'] UNIV_ring_char_0_infinte ``` chaieb@26124 ` 477` ``` show "poly t x = (0\'a)" by simp ``` chaieb@26124 ` 478` ``` qed ``` chaieb@26124 ` 479` chaieb@26124 ` 480` ```lemma (in idom_char_0) poly_zero: "(poly p = poly []) = list_all (%c. c = 0) p" ``` chaieb@26124 ` 481` ```apply (induct "p", simp) ``` chaieb@26124 ` 482` ```apply (rule iffI) ``` chaieb@26124 ` 483` ```apply (drule poly_zero_lemma', auto) ``` chaieb@26124 ` 484` ```done ``` chaieb@26124 ` 485` chaieb@26124 ` 486` ```lemma (in idom_char_0) poly_0: "list_all (\c. c = 0) p \ poly p x = 0" ``` chaieb@26124 ` 487` ``` unfolding poly_zero[symmetric] by simp ``` chaieb@26124 ` 488` chaieb@26124 ` 489` chaieb@26124 ` 490` chaieb@26124 ` 491` ```text{*Basics of divisibility.*} ``` chaieb@26124 ` 492` chaieb@26124 ` 493` ```lemma (in idom) poly_primes: "([a, 1] divides (p *** q)) = ([a, 1] divides p | [a, 1] divides q)" ``` chaieb@26124 ` 494` ```apply (auto simp add: divides_def fun_eq poly_mult poly_add poly_cmult left_distrib [symmetric]) ``` chaieb@26124 ` 495` ```apply (drule_tac x = "uminus a" in spec) ``` chaieb@26124 ` 496` ```apply (simp add: poly_linear_divides poly_add poly_cmult left_distrib [symmetric]) ``` chaieb@26124 ` 497` ```apply (cases "p = []") ``` chaieb@26124 ` 498` ```apply (rule exI[where x="[]"]) ``` chaieb@26124 ` 499` ```apply simp ``` chaieb@26124 ` 500` ```apply (cases "q = []") ``` chaieb@26124 ` 501` ```apply (erule allE[where x="[]"], simp) ``` chaieb@26124 ` 502` chaieb@26124 ` 503` ```apply clarsimp ``` chaieb@26124 ` 504` ```apply (cases "\q\'a list. p = a %* q +++ ((0\'a) # q)") ``` chaieb@26124 ` 505` ```apply (clarsimp simp add: poly_add poly_cmult) ``` chaieb@26124 ` 506` ```apply (rule_tac x="qa" in exI) ``` chaieb@26124 ` 507` ```apply (simp add: left_distrib [symmetric]) ``` chaieb@26124 ` 508` ```apply clarsimp ``` chaieb@26124 ` 509` chaieb@26124 ` 510` ```apply (auto simp add: right_minus poly_linear_divides poly_add poly_cmult left_distrib [symmetric]) ``` chaieb@26124 ` 511` ```apply (rule_tac x = "pmult qa q" in exI) ``` chaieb@26124 ` 512` ```apply (rule_tac [2] x = "pmult p qa" in exI) ``` chaieb@26124 ` 513` ```apply (auto simp add: poly_add poly_mult poly_cmult mult_ac) ``` chaieb@26124 ` 514` ```done ``` chaieb@26124 ` 515` chaieb@26124 ` 516` ```lemma (in comm_semiring_1) poly_divides_refl[simp]: "p divides p" ``` chaieb@26124 ` 517` ```apply (simp add: divides_def) ``` chaieb@26124 ` 518` ```apply (rule_tac x = "[one]" in exI) ``` chaieb@26124 ` 519` ```apply (auto simp add: poly_mult fun_eq) ``` chaieb@26124 ` 520` ```done ``` chaieb@26124 ` 521` chaieb@26124 ` 522` ```lemma (in comm_semiring_1) poly_divides_trans: "[| p divides q; q divides r |] ==> p divides r" ``` chaieb@26124 ` 523` ```apply (simp add: divides_def, safe) ``` chaieb@26124 ` 524` ```apply (rule_tac x = "pmult qa qaa" in exI) ``` chaieb@26124 ` 525` ```apply (auto simp add: poly_mult fun_eq mult_assoc) ``` chaieb@26124 ` 526` ```done ``` chaieb@26124 ` 527` chaieb@26124 ` 528` chaieb@26124 ` 529` ```lemma (in recpower_comm_semiring_1) poly_divides_exp: "m \ n ==> (p %^ m) divides (p %^ n)" ``` chaieb@26124 ` 530` ```apply (auto simp add: le_iff_add) ``` chaieb@26124 ` 531` ```apply (induct_tac k) ``` chaieb@26124 ` 532` ```apply (rule_tac [2] poly_divides_trans) ``` chaieb@26124 ` 533` ```apply (auto simp add: divides_def) ``` chaieb@26124 ` 534` ```apply (rule_tac x = p in exI) ``` chaieb@26124 ` 535` ```apply (auto simp add: poly_mult fun_eq mult_ac) ``` chaieb@26124 ` 536` ```done ``` chaieb@26124 ` 537` chaieb@26124 ` 538` ```lemma (in recpower_comm_semiring_1) poly_exp_divides: "[| (p %^ n) divides q; m\n |] ==> (p %^ m) divides q" ``` chaieb@26124 ` 539` ```by (blast intro: poly_divides_exp poly_divides_trans) ``` chaieb@26124 ` 540` chaieb@26124 ` 541` ```lemma (in comm_semiring_0) poly_divides_add: ``` chaieb@26124 ` 542` ``` "[| p divides q; p divides r |] ==> p divides (q +++ r)" ``` chaieb@26124 ` 543` ```apply (simp add: divides_def, auto) ``` chaieb@26124 ` 544` ```apply (rule_tac x = "padd qa qaa" in exI) ``` chaieb@26124 ` 545` ```apply (auto simp add: poly_add fun_eq poly_mult right_distrib) ``` chaieb@26124 ` 546` ```done ``` chaieb@26124 ` 547` chaieb@26124 ` 548` ```lemma (in comm_ring_1) poly_divides_diff: ``` chaieb@26124 ` 549` ``` "[| p divides q; p divides (q +++ r) |] ==> p divides r" ``` chaieb@26124 ` 550` ```apply (simp add: divides_def, auto) ``` chaieb@26124 ` 551` ```apply (rule_tac x = "padd qaa (poly_minus qa)" in exI) ``` chaieb@26124 ` 552` ```apply (auto simp add: poly_add fun_eq poly_mult poly_minus right_diff_distrib compare_rls add_ac) ``` chaieb@26124 ` 553` ```done ``` chaieb@26124 ` 554` chaieb@26124 ` 555` ```lemma (in comm_ring_1) poly_divides_diff2: "[| p divides r; p divides (q +++ r) |] ==> p divides q" ``` chaieb@26124 ` 556` ```apply (erule poly_divides_diff) ``` chaieb@26124 ` 557` ```apply (auto simp add: poly_add fun_eq poly_mult divides_def add_ac) ``` chaieb@26124 ` 558` ```done ``` chaieb@26124 ` 559` chaieb@26124 ` 560` ```lemma (in semiring_0) poly_divides_zero: "poly p = poly [] ==> q divides p" ``` chaieb@26124 ` 561` ```apply (simp add: divides_def) ``` chaieb@26124 ` 562` ```apply (rule exI[where x="[]"]) ``` chaieb@26124 ` 563` ```apply (auto simp add: fun_eq poly_mult) ``` chaieb@26124 ` 564` ```done ``` chaieb@26124 ` 565` chaieb@26124 ` 566` ```lemma (in semiring_0) poly_divides_zero2[simp]: "q divides []" ``` chaieb@26124 ` 567` ```apply (simp add: divides_def) ``` chaieb@26124 ` 568` ```apply (rule_tac x = "[]" in exI) ``` chaieb@26124 ` 569` ```apply (auto simp add: fun_eq) ``` chaieb@26124 ` 570` ```done ``` chaieb@26124 ` 571` chaieb@26124 ` 572` ```text{*At last, we can consider the order of a root.*} ``` chaieb@26124 ` 573` chaieb@26124 ` 574` ```lemma (in idom_char_0) poly_order_exists_lemma: ``` chaieb@26124 ` 575` ``` assumes lp: "length p = d" and p: "poly p \ poly []" ``` chaieb@26124 ` 576` ``` shows "\n q. p = mulexp n [-a, 1] q \ poly q a \ 0" ``` chaieb@26124 ` 577` ```using lp p ``` chaieb@26124 ` 578` ```proof(induct d arbitrary: p) ``` chaieb@26124 ` 579` ``` case 0 thus ?case by simp ``` chaieb@26124 ` 580` ```next ``` chaieb@26124 ` 581` ``` case (Suc n p) ``` chaieb@26124 ` 582` ``` {assume p0: "poly p a = 0" ``` chaieb@26124 ` 583` ``` from Suc.prems have h: "length p = Suc n" "poly p \ poly []" by blast ``` chaieb@26124 ` 584` ``` hence pN: "p \ []" by - (rule ccontr, simp) ``` chaieb@26124 ` 585` ``` from p0[unfolded poly_linear_divides] pN obtain q where ``` chaieb@26124 ` 586` ``` q: "p = [-a, 1] *** q" by blast ``` chaieb@26124 ` 587` ``` from q h p0 have qh: "length q = n" "poly q \ poly []" ``` chaieb@26124 ` 588` ``` apply - ``` chaieb@26124 ` 589` ``` apply simp ``` chaieb@26124 ` 590` ``` apply (simp only: fun_eq) ``` chaieb@26124 ` 591` ``` apply (rule ccontr) ``` chaieb@26124 ` 592` ``` apply (simp add: fun_eq poly_add poly_cmult minus_mult_left[symmetric]) ``` chaieb@26124 ` 593` ``` done ``` chaieb@26124 ` 594` ``` from Suc.hyps[OF qh] obtain m r where ``` chaieb@26124 ` 595` ``` mr: "q = mulexp m [-a,1] r" "poly r a \ 0" by blast ``` chaieb@26124 ` 596` ``` from mr q have "p = mulexp (Suc m) [-a,1] r \ poly r a \ 0" by simp ``` chaieb@26124 ` 597` ``` hence ?case by blast} ``` chaieb@26124 ` 598` ``` moreover ``` chaieb@26124 ` 599` ``` {assume p0: "poly p a \ 0" ``` chaieb@26124 ` 600` ``` hence ?case using Suc.prems apply simp by (rule exI[where x="0::nat"], simp)} ``` chaieb@26124 ` 601` ``` ultimately show ?case by blast ``` chaieb@26124 ` 602` ```qed ``` chaieb@26124 ` 603` chaieb@26124 ` 604` chaieb@26124 ` 605` ```lemma (in recpower_comm_semiring_1) poly_mulexp: "poly (mulexp n p q) x = (poly p x) ^ n * poly q x" ``` chaieb@26124 ` 606` ```by(induct n, auto simp add: poly_mult power_Suc mult_ac) ``` chaieb@26124 ` 607` chaieb@26124 ` 608` ```lemma (in comm_semiring_1) divides_left_mult: ``` chaieb@26124 ` 609` ``` assumes d:"(p***q) divides r" shows "p divides r \ q divides r" ``` chaieb@26124 ` 610` ```proof- ``` chaieb@26124 ` 611` ``` from d obtain t where r:"poly r = poly (p***q *** t)" ``` chaieb@26124 ` 612` ``` unfolding divides_def by blast ``` chaieb@26124 ` 613` ``` hence "poly r = poly (p *** (q *** t))" ``` chaieb@26124 ` 614` ``` "poly r = poly (q *** (p***t))" by(auto simp add: fun_eq poly_mult mult_ac) ``` chaieb@26124 ` 615` ``` thus ?thesis unfolding divides_def by blast ``` chaieb@26124 ` 616` ```qed ``` chaieb@26124 ` 617` chaieb@26124 ` 618` chaieb@26124 ` 619` chaieb@26124 ` 620` ```(* FIXME: Tidy up *) ``` chaieb@26124 ` 621` chaieb@26124 ` 622` ```lemma (in recpower_semiring_1) ``` chaieb@26124 ` 623` ``` zero_power_iff: "0 ^ n = (if n = 0 then 1 else 0)" ``` chaieb@26124 ` 624` ``` by (induct n, simp_all add: power_Suc) ``` chaieb@26124 ` 625` chaieb@26124 ` 626` ```lemma (in recpower_idom_char_0) poly_order_exists: ``` chaieb@26124 ` 627` ``` assumes lp: "length p = d" and p0: "poly p \ poly []" ``` chaieb@26124 ` 628` ``` shows "\n. ([-a, 1] %^ n) divides p & ~(([-a, 1] %^ (Suc n)) divides p)" ``` chaieb@26124 ` 629` ```proof- ``` chaieb@26124 ` 630` ```let ?poly = poly ``` chaieb@26124 ` 631` ```let ?mulexp = mulexp ``` chaieb@26124 ` 632` ```let ?pexp = pexp ``` chaieb@26124 ` 633` ```from lp p0 ``` chaieb@26124 ` 634` ```show ?thesis ``` chaieb@26124 ` 635` ```apply - ``` chaieb@26124 ` 636` ```apply (drule poly_order_exists_lemma [where a=a], assumption, clarify) ``` chaieb@26124 ` 637` ```apply (rule_tac x = n in exI, safe) ``` chaieb@26124 ` 638` ```apply (unfold divides_def) ``` chaieb@26124 ` 639` ```apply (rule_tac x = q in exI) ``` chaieb@26124 ` 640` ```apply (induct_tac "n", simp) ``` chaieb@26124 ` 641` ```apply (simp (no_asm_simp) add: poly_add poly_cmult poly_mult right_distrib mult_ac) ``` chaieb@26124 ` 642` ```apply safe ``` chaieb@26124 ` 643` ```apply (subgoal_tac "?poly (?mulexp n [uminus a, one] q) \ ?poly (pmult (?pexp [uminus a, one] (Suc n)) qa)") ``` chaieb@26124 ` 644` ```apply simp ``` chaieb@26124 ` 645` ```apply (induct_tac "n") ``` chaieb@26124 ` 646` ```apply (simp del: pmult_Cons pexp_Suc) ``` chaieb@26124 ` 647` ```apply (erule_tac Q = "?poly q a = zero" in contrapos_np) ``` chaieb@26124 ` 648` ```apply (simp add: poly_add poly_cmult minus_mult_left[symmetric]) ``` chaieb@26124 ` 649` ```apply (rule pexp_Suc [THEN ssubst]) ``` chaieb@26124 ` 650` ```apply (rule ccontr) ``` chaieb@26124 ` 651` ```apply (simp add: poly_mult_left_cancel poly_mult_assoc del: pmult_Cons pexp_Suc) ``` chaieb@26124 ` 652` ```done ``` chaieb@26124 ` 653` ```qed ``` chaieb@26124 ` 654` chaieb@26124 ` 655` chaieb@26124 ` 656` ```lemma (in semiring_1) poly_one_divides[simp]: "[1] divides p" ``` chaieb@26124 ` 657` ```by (simp add: divides_def, auto) ``` chaieb@26124 ` 658` chaieb@26124 ` 659` ```lemma (in recpower_idom_char_0) poly_order: "poly p \ poly [] ``` chaieb@26124 ` 660` ``` ==> EX! n. ([-a, 1] %^ n) divides p & ``` chaieb@26124 ` 661` ``` ~(([-a, 1] %^ (Suc n)) divides p)" ``` chaieb@26124 ` 662` ```apply (auto intro: poly_order_exists simp add: less_linear simp del: pmult_Cons pexp_Suc) ``` chaieb@26124 ` 663` ```apply (cut_tac x = y and y = n in less_linear) ``` chaieb@26124 ` 664` ```apply (drule_tac m = n in poly_exp_divides) ``` chaieb@26124 ` 665` ```apply (auto dest: Suc_le_eq [THEN iffD2, THEN [2] poly_exp_divides] ``` chaieb@26124 ` 666` ``` simp del: pmult_Cons pexp_Suc) ``` chaieb@26124 ` 667` ```done ``` chaieb@26124 ` 668` chaieb@26124 ` 669` ```text{*Order*} ``` chaieb@26124 ` 670` chaieb@26124 ` 671` ```lemma some1_equalityD: "[| n = (@n. P n); EX! n. P n |] ==> P n" ``` chaieb@26124 ` 672` ```by (blast intro: someI2) ``` chaieb@26124 ` 673` chaieb@26124 ` 674` ```lemma (in recpower_idom_char_0) order: ``` chaieb@26124 ` 675` ``` "(([-a, 1] %^ n) divides p & ``` chaieb@26124 ` 676` ``` ~(([-a, 1] %^ (Suc n)) divides p)) = ``` chaieb@26124 ` 677` ``` ((n = order a p) & ~(poly p = poly []))" ``` chaieb@26124 ` 678` ```apply (unfold order_def) ``` chaieb@26124 ` 679` ```apply (rule iffI) ``` chaieb@26124 ` 680` ```apply (blast dest: poly_divides_zero intro!: some1_equality [symmetric] poly_order) ``` chaieb@26124 ` 681` ```apply (blast intro!: poly_order [THEN [2] some1_equalityD]) ``` chaieb@26124 ` 682` ```done ``` chaieb@26124 ` 683` chaieb@26124 ` 684` ```lemma (in recpower_idom_char_0) order2: "[| poly p \ poly [] |] ``` chaieb@26124 ` 685` ``` ==> ([-a, 1] %^ (order a p)) divides p & ``` chaieb@26124 ` 686` ``` ~(([-a, 1] %^ (Suc(order a p))) divides p)" ``` chaieb@26124 ` 687` ```by (simp add: order del: pexp_Suc) ``` chaieb@26124 ` 688` chaieb@26124 ` 689` ```lemma (in recpower_idom_char_0) order_unique: "[| poly p \ poly []; ([-a, 1] %^ n) divides p; ``` chaieb@26124 ` 690` ``` ~(([-a, 1] %^ (Suc n)) divides p) ``` chaieb@26124 ` 691` ``` |] ==> (n = order a p)" ``` chaieb@26124 ` 692` ```by (insert order [of a n p], auto) ``` chaieb@26124 ` 693` chaieb@26124 ` 694` ```lemma (in recpower_idom_char_0) order_unique_lemma: "(poly p \ poly [] & ([-a, 1] %^ n) divides p & ``` chaieb@26124 ` 695` ``` ~(([-a, 1] %^ (Suc n)) divides p)) ``` chaieb@26124 ` 696` ``` ==> (n = order a p)" ``` chaieb@26124 ` 697` ```by (blast intro: order_unique) ``` chaieb@26124 ` 698` chaieb@26124 ` 699` ```lemma (in ring_1) order_poly: "poly p = poly q ==> order a p = order a q" ``` chaieb@26124 ` 700` ```by (auto simp add: fun_eq divides_def poly_mult order_def) ``` chaieb@26124 ` 701` chaieb@26124 ` 702` ```lemma (in semiring_1) pexp_one[simp]: "p %^ (Suc 0) = p" ``` chaieb@26124 ` 703` ```apply (induct "p") ``` chaieb@26124 ` 704` ```apply (auto simp add: numeral_1_eq_1) ``` chaieb@26124 ` 705` ```done ``` chaieb@26124 ` 706` chaieb@26124 ` 707` ```lemma (in comm_ring_1) lemma_order_root: ``` chaieb@26124 ` 708` ``` " 0 < n & [- a, 1] %^ n divides p & ~ [- a, 1] %^ (Suc n) divides p ``` chaieb@26124 ` 709` ``` \ poly p a = 0" ``` chaieb@26124 ` 710` ```apply (induct n arbitrary: a p, blast) ``` chaieb@26124 ` 711` ```apply (auto simp add: divides_def poly_mult simp del: pmult_Cons) ``` chaieb@26124 ` 712` ```done ``` chaieb@26124 ` 713` chaieb@26124 ` 714` ```lemma (in recpower_idom_char_0) order_root: "(poly p a = 0) = ((poly p = poly []) | order a p \ 0)" ``` chaieb@26124 ` 715` ```proof- ``` chaieb@26124 ` 716` ``` let ?poly = poly ``` chaieb@26124 ` 717` ``` show ?thesis ``` chaieb@26124 ` 718` ```apply (case_tac "?poly p = ?poly []", auto) ``` chaieb@26124 ` 719` ```apply (simp add: poly_linear_divides del: pmult_Cons, safe) ``` chaieb@26124 ` 720` ```apply (drule_tac [!] a = a in order2) ``` chaieb@26124 ` 721` ```apply (rule ccontr) ``` chaieb@26124 ` 722` ```apply (simp add: divides_def poly_mult fun_eq del: pmult_Cons, blast) ``` chaieb@26124 ` 723` ```using neq0_conv ``` chaieb@26124 ` 724` ```apply (blast intro: lemma_order_root) ``` chaieb@26124 ` 725` ```done ``` chaieb@26124 ` 726` ```qed ``` chaieb@26124 ` 727` chaieb@26124 ` 728` ```lemma (in recpower_idom_char_0) order_divides: "(([-a, 1] %^ n) divides p) = ((poly p = poly []) | n \ order a p)" ``` chaieb@26124 ` 729` ```proof- ``` chaieb@26124 ` 730` ``` let ?poly = poly ``` chaieb@26124 ` 731` ``` show ?thesis ``` chaieb@26124 ` 732` ```apply (case_tac "?poly p = ?poly []", auto) ``` chaieb@26124 ` 733` ```apply (simp add: divides_def fun_eq poly_mult) ``` chaieb@26124 ` 734` ```apply (rule_tac x = "[]" in exI) ``` chaieb@26124 ` 735` ```apply (auto dest!: order2 [where a=a] ``` chaieb@26124 ` 736` ``` intro: poly_exp_divides simp del: pexp_Suc) ``` chaieb@26124 ` 737` ```done ``` chaieb@26124 ` 738` ```qed ``` chaieb@26124 ` 739` chaieb@26124 ` 740` ```lemma (in recpower_idom_char_0) order_decomp: ``` chaieb@26124 ` 741` ``` "poly p \ poly [] ``` chaieb@26124 ` 742` ``` ==> \q. (poly p = poly (([-a, 1] %^ (order a p)) *** q)) & ``` chaieb@26124 ` 743` ``` ~([-a, 1] divides q)" ``` chaieb@26124 ` 744` ```apply (unfold divides_def) ``` chaieb@26124 ` 745` ```apply (drule order2 [where a = a]) ``` chaieb@26124 ` 746` ```apply (simp add: divides_def del: pexp_Suc pmult_Cons, safe) ``` chaieb@26124 ` 747` ```apply (rule_tac x = q in exI, safe) ``` chaieb@26124 ` 748` ```apply (drule_tac x = qa in spec) ``` chaieb@26124 ` 749` ```apply (auto simp add: poly_mult fun_eq poly_exp mult_ac simp del: pmult_Cons) ``` chaieb@26124 ` 750` ```done ``` chaieb@26124 ` 751` chaieb@26124 ` 752` ```text{*Important composition properties of orders.*} ``` chaieb@26124 ` 753` ```lemma order_mult: "poly (p *** q) \ poly [] ``` chaieb@26124 ` 754` ``` ==> order a (p *** q) = order a p + order (a::'a::{recpower_idom_char_0}) q" ``` chaieb@26124 ` 755` ```apply (cut_tac a = a and p = "p *** q" and n = "order a p + order a q" in order) ``` chaieb@26124 ` 756` ```apply (auto simp add: poly_entire simp del: pmult_Cons) ``` chaieb@26124 ` 757` ```apply (drule_tac a = a in order2)+ ``` chaieb@26124 ` 758` ```apply safe ``` chaieb@26124 ` 759` ```apply (simp add: divides_def fun_eq poly_exp_add poly_mult del: pmult_Cons, safe) ``` chaieb@26124 ` 760` ```apply (rule_tac x = "qa *** qaa" in exI) ``` chaieb@26124 ` 761` ```apply (simp add: poly_mult mult_ac del: pmult_Cons) ``` chaieb@26124 ` 762` ```apply (drule_tac a = a in order_decomp)+ ``` chaieb@26124 ` 763` ```apply safe ``` chaieb@26124 ` 764` ```apply (subgoal_tac "[-a,1] divides (qa *** qaa) ") ``` chaieb@26124 ` 765` ```apply (simp add: poly_primes del: pmult_Cons) ``` chaieb@26124 ` 766` ```apply (auto simp add: divides_def simp del: pmult_Cons) ``` chaieb@26124 ` 767` ```apply (rule_tac x = qb in exI) ``` chaieb@26124 ` 768` ```apply (subgoal_tac "poly ([-a, 1] %^ (order a p) *** (qa *** qaa)) = poly ([-a, 1] %^ (order a p) *** ([-a, 1] *** qb))") ``` chaieb@26124 ` 769` ```apply (drule poly_mult_left_cancel [THEN iffD1], force) ``` chaieb@26124 ` 770` ```apply (subgoal_tac "poly ([-a, 1] %^ (order a q) *** ([-a, 1] %^ (order a p) *** (qa *** qaa))) = poly ([-a, 1] %^ (order a q) *** ([-a, 1] %^ (order a p) *** ([-a, 1] *** qb))) ") ``` chaieb@26124 ` 771` ```apply (drule poly_mult_left_cancel [THEN iffD1], force) ``` chaieb@26124 ` 772` ```apply (simp add: fun_eq poly_exp_add poly_mult mult_ac del: pmult_Cons) ``` chaieb@26124 ` 773` ```done ``` chaieb@26124 ` 774` chaieb@26124 ` 775` ```lemma (in recpower_idom_char_0) order_mult: ``` chaieb@26124 ` 776` ``` assumes pq0: "poly (p *** q) \ poly []" ``` chaieb@26124 ` 777` ``` shows "order a (p *** q) = order a p + order a q" ``` chaieb@26124 ` 778` ```proof- ``` chaieb@26124 ` 779` ``` let ?order = order ``` chaieb@26124 ` 780` ``` let ?divides = "op divides" ``` chaieb@26124 ` 781` ``` let ?poly = poly ``` chaieb@26124 ` 782` ```from pq0 ``` chaieb@26124 ` 783` ```show ?thesis ``` chaieb@26124 ` 784` ```apply (cut_tac a = a and p = "pmult p q" and n = "?order a p + ?order a q" in order) ``` chaieb@26124 ` 785` ```apply (auto simp add: poly_entire simp del: pmult_Cons) ``` chaieb@26124 ` 786` ```apply (drule_tac a = a in order2)+ ``` chaieb@26124 ` 787` ```apply safe ``` chaieb@26124 ` 788` ```apply (simp add: divides_def fun_eq poly_exp_add poly_mult del: pmult_Cons, safe) ``` chaieb@26124 ` 789` ```apply (rule_tac x = "pmult qa qaa" in exI) ``` chaieb@26124 ` 790` ```apply (simp add: poly_mult mult_ac del: pmult_Cons) ``` chaieb@26124 ` 791` ```apply (drule_tac a = a in order_decomp)+ ``` chaieb@26124 ` 792` ```apply safe ``` chaieb@26124 ` 793` ```apply (subgoal_tac "?divides [uminus a,one ] (pmult qa qaa) ") ``` chaieb@26124 ` 794` ```apply (simp add: poly_primes del: pmult_Cons) ``` chaieb@26124 ` 795` ```apply (auto simp add: divides_def simp del: pmult_Cons) ``` chaieb@26124 ` 796` ```apply (rule_tac x = qb in exI) ``` chaieb@26124 ` 797` ```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 ` 798` ```apply (drule poly_mult_left_cancel [THEN iffD1], force) ``` chaieb@26124 ` 799` ```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 ` 800` ```apply (drule poly_mult_left_cancel [THEN iffD1], force) ``` chaieb@26124 ` 801` ```apply (simp add: fun_eq poly_exp_add poly_mult mult_ac del: pmult_Cons) ``` chaieb@26124 ` 802` ```done ``` chaieb@26124 ` 803` ```qed ``` chaieb@26124 ` 804` chaieb@26124 ` 805` ```lemma (in recpower_idom_char_0) order_root2: "poly p \ poly [] ==> (poly p a = 0) = (order a p \ 0)" ``` chaieb@26124 ` 806` ```by (rule order_root [THEN ssubst], auto) ``` chaieb@26124 ` 807` chaieb@26124 ` 808` ```lemma (in semiring_1) pmult_one[simp]: "[1] *** p = p" by auto ``` chaieb@26124 ` 809` chaieb@26124 ` 810` ```lemma (in semiring_0) poly_Nil_zero: "poly [] = poly [0]" ``` chaieb@26124 ` 811` ```by (simp add: fun_eq) ``` chaieb@26124 ` 812` chaieb@26124 ` 813` ```lemma (in recpower_idom_char_0) rsquarefree_decomp: ``` chaieb@26124 ` 814` ``` "[| rsquarefree p; poly p a = 0 |] ``` chaieb@26124 ` 815` ``` ==> \q. (poly p = poly ([-a, 1] *** q)) & poly q a \ 0" ``` chaieb@26124 ` 816` ```apply (simp add: rsquarefree_def, safe) ``` chaieb@26124 ` 817` ```apply (frule_tac a = a in order_decomp) ``` chaieb@26124 ` 818` ```apply (drule_tac x = a in spec) ``` chaieb@26124 ` 819` ```apply (drule_tac a = a in order_root2 [symmetric]) ``` chaieb@26124 ` 820` ```apply (auto simp del: pmult_Cons) ``` chaieb@26124 ` 821` ```apply (rule_tac x = q in exI, safe) ``` chaieb@26124 ` 822` ```apply (simp add: poly_mult fun_eq) ``` chaieb@26124 ` 823` ```apply (drule_tac p1 = q in poly_linear_divides [THEN iffD1]) ``` chaieb@26124 ` 824` ```apply (simp add: divides_def del: pmult_Cons, safe) ``` chaieb@26124 ` 825` ```apply (drule_tac x = "[]" in spec) ``` chaieb@26124 ` 826` ```apply (auto simp add: fun_eq) ``` chaieb@26124 ` 827` ```done ``` chaieb@26124 ` 828` chaieb@26124 ` 829` chaieb@26124 ` 830` ```text{*Normalization of a polynomial.*} ``` chaieb@26124 ` 831` chaieb@26124 ` 832` ```lemma (in semiring_0) poly_normalize[simp]: "poly (pnormalize p) = poly p" ``` chaieb@26124 ` 833` ```apply (induct "p") ``` chaieb@26124 ` 834` ```apply (auto simp add: fun_eq) ``` chaieb@26124 ` 835` ```done ``` chaieb@26124 ` 836` chaieb@26124 ` 837` ```text{*The degree of a polynomial.*} ``` chaieb@26124 ` 838` chaieb@26124 ` 839` ```lemma (in semiring_0) lemma_degree_zero: ``` chaieb@26124 ` 840` ``` "list_all (%c. c = 0) p \ pnormalize p = []" ``` chaieb@26124 ` 841` ```by (induct "p", auto) ``` chaieb@26124 ` 842` chaieb@26124 ` 843` ```lemma (in idom_char_0) degree_zero: ``` chaieb@26124 ` 844` ``` assumes pN: "poly p = poly []" shows"degree p = 0" ``` chaieb@26124 ` 845` ```proof- ``` chaieb@26124 ` 846` ``` let ?pn = pnormalize ``` chaieb@26124 ` 847` ``` from pN ``` chaieb@26124 ` 848` ``` show ?thesis ``` chaieb@26124 ` 849` ``` apply (simp add: degree_def) ``` chaieb@26124 ` 850` ``` apply (case_tac "?pn p = []") ``` chaieb@26124 ` 851` ``` apply (auto simp add: poly_zero lemma_degree_zero ) ``` chaieb@26124 ` 852` ``` done ``` chaieb@26124 ` 853` ```qed ``` chaieb@26124 ` 854` chaieb@26124 ` 855` ```lemma (in semiring_0) pnormalize_sing: "(pnormalize [x] = [x]) \ x \ 0" by simp ``` chaieb@26124 ` 856` ```lemma (in semiring_0) pnormalize_pair: "y \ 0 \ (pnormalize [x, y] = [x, y])" by simp ``` chaieb@26124 ` 857` ```lemma (in semiring_0) pnormal_cons: "pnormal p \ pnormal (c#p)" ``` chaieb@26124 ` 858` ``` unfolding pnormal_def by simp ``` chaieb@26124 ` 859` ```lemma (in semiring_0) pnormal_tail: "p\[] \ pnormal (c#p) \ pnormal p" ``` chaieb@26124 ` 860` ``` unfolding pnormal_def ``` chaieb@26124 ` 861` ``` apply (cases "pnormalize p = []", auto) ``` chaieb@26124 ` 862` ``` by (cases "c = 0", auto) ``` chaieb@26124 ` 863` chaieb@26124 ` 864` chaieb@26124 ` 865` ```lemma (in semiring_0) pnormal_last_nonzero: "pnormal p ==> last p \ 0" ``` chaieb@26124 ` 866` ```proof(induct p) ``` chaieb@26124 ` 867` ``` case Nil thus ?case by (simp add: pnormal_def) ``` chaieb@26124 ` 868` ```next ``` chaieb@26124 ` 869` ``` case (Cons a as) thus ?case ``` chaieb@26124 ` 870` ``` apply (simp add: pnormal_def) ``` chaieb@26124 ` 871` ``` apply (cases "pnormalize as = []", simp_all) ``` chaieb@26124 ` 872` ``` apply (cases "as = []", simp_all) ``` chaieb@26124 ` 873` ``` apply (cases "a=0", simp_all) ``` chaieb@26124 ` 874` ``` apply (cases "a=0", simp_all) ``` chaieb@26124 ` 875` ``` done ``` chaieb@26124 ` 876` ```qed ``` chaieb@26124 ` 877` chaieb@26124 ` 878` ```lemma (in semiring_0) pnormal_length: "pnormal p \ 0 < length p" ``` chaieb@26124 ` 879` ``` unfolding pnormal_def length_greater_0_conv by blast ``` chaieb@26124 ` 880` chaieb@26124 ` 881` ```lemma (in semiring_0) pnormal_last_length: "\0 < length p ; last p \ 0\ \ pnormal p" ``` chaieb@26124 ` 882` ``` apply (induct p, auto) ``` chaieb@26124 ` 883` ``` apply (case_tac "p = []", auto) ``` chaieb@26124 ` 884` ``` apply (simp add: pnormal_def) ``` chaieb@26124 ` 885` ``` by (rule pnormal_cons, auto) ``` chaieb@26124 ` 886` chaieb@26124 ` 887` ```lemma (in semiring_0) pnormal_id: "pnormal p \ (0 < length p \ last p \ 0)" ``` chaieb@26124 ` 888` ``` using pnormal_last_length pnormal_length pnormal_last_nonzero by blast ``` chaieb@26124 ` 889` chaieb@26124 ` 890` ```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 ` 891` ```proof ``` chaieb@26124 ` 892` ``` assume eq: ?lhs ``` chaieb@26124 ` 893` ``` hence "\x. poly ((c#cs) +++ -- (d#ds)) x = 0" ``` chaieb@26124 ` 894` ``` by (simp only: poly_minus poly_add ring_simps) simp ``` chaieb@26124 ` 895` ``` hence "poly ((c#cs) +++ -- (d#ds)) = poly []" by - (rule ext, simp) ``` chaieb@26124 ` 896` ``` hence "c = d \ list_all (\x. x=0) ((cs +++ -- ds))" ``` chaieb@26124 ` 897` ``` unfolding poly_zero by (simp add: poly_minus_def ring_simps minus_mult_left[symmetric]) ``` chaieb@26124 ` 898` ``` hence "c = d \ (\x. poly (cs +++ -- ds) x = 0)" ``` chaieb@26124 ` 899` ``` unfolding poly_zero[symmetric] by simp ``` chaieb@26124 ` 900` ``` thus ?rhs apply (simp add: poly_minus poly_add ring_simps) apply (rule ext, simp) done ``` chaieb@26124 ` 901` ```next ``` chaieb@26124 ` 902` ``` assume ?rhs then show ?lhs by - (rule ext,simp) ``` chaieb@26124 ` 903` ```qed ``` chaieb@26124 ` 904` ``` ``` chaieb@26124 ` 905` ```lemma (in idom_char_0) pnormalize_unique: "poly p = poly q \ pnormalize p = pnormalize q" ``` chaieb@26124 ` 906` ```proof(induct q arbitrary: p) ``` chaieb@26124 ` 907` ``` case Nil thus ?case by (simp only: poly_zero lemma_degree_zero) simp ``` chaieb@26124 ` 908` ```next ``` chaieb@26124 ` 909` ``` case (Cons c cs p) ``` chaieb@26124 ` 910` ``` thus ?case ``` chaieb@26124 ` 911` ``` proof(induct p) ``` chaieb@26124 ` 912` ``` case Nil ``` chaieb@26124 ` 913` ``` hence "poly [] = poly (c#cs)" by blast ``` chaieb@26124 ` 914` ``` then have "poly (c#cs) = poly [] " by simp ``` chaieb@26124 ` 915` ``` thus ?case by (simp only: poly_zero lemma_degree_zero) simp ``` chaieb@26124 ` 916` ``` next ``` chaieb@26124 ` 917` ``` case (Cons d ds) ``` chaieb@26124 ` 918` ``` hence eq: "poly (d # ds) = poly (c # cs)" by blast ``` chaieb@26124 ` 919` ``` hence eq': "\x. poly (d # ds) x = poly (c # cs) x" by simp ``` chaieb@26124 ` 920` ``` hence "poly (d # ds) 0 = poly (c # cs) 0" by blast ``` chaieb@26124 ` 921` ``` hence dc: "d = c" by auto ``` chaieb@26124 ` 922` ``` with eq have "poly ds = poly cs" ``` chaieb@26124 ` 923` ``` unfolding poly_Cons_eq by simp ``` chaieb@26124 ` 924` ``` with Cons.prems have "pnormalize ds = pnormalize cs" by blast ``` chaieb@26124 ` 925` ``` with dc show ?case by simp ``` chaieb@26124 ` 926` ``` qed ``` chaieb@26124 ` 927` ```qed ``` chaieb@26124 ` 928` chaieb@26124 ` 929` ```lemma (in idom_char_0) degree_unique: assumes pq: "poly p = poly q" ``` chaieb@26124 ` 930` ``` shows "degree p = degree q" ``` chaieb@26124 ` 931` ```using pnormalize_unique[OF pq] unfolding degree_def by simp ``` chaieb@26124 ` 932` chaieb@26124 ` 933` ```lemma (in semiring_0) pnormalize_length: "length (pnormalize p) \ length p" by (induct p, auto) ``` chaieb@26124 ` 934` chaieb@26124 ` 935` ```lemma (in semiring_0) last_linear_mul_lemma: ``` chaieb@26124 ` 936` ``` "last ((a %* p) +++ (x#(b %* p))) = (if p=[] then x else b*last p)" ``` chaieb@26124 ` 937` chaieb@26124 ` 938` ```apply (induct p arbitrary: a x b, auto) ``` chaieb@26124 ` 939` ```apply (subgoal_tac "padd (cmult aa p) (times b a # cmult b p) \ []", simp) ``` chaieb@26124 ` 940` ```apply (induct_tac p, auto) ``` chaieb@26124 ` 941` ```done ``` chaieb@26124 ` 942` chaieb@26124 ` 943` ```lemma (in semiring_1) last_linear_mul: assumes p:"p\[]" shows "last ([a,1] *** p) = last p" ``` chaieb@26124 ` 944` ```proof- ``` chaieb@26124 ` 945` ``` from p obtain c cs where cs: "p = c#cs" by (cases p, auto) ``` chaieb@26124 ` 946` ``` from cs have eq:"[a,1] *** p = (a %* (c#cs)) +++ (0#(1 %* (c#cs)))" ``` chaieb@26124 ` 947` ``` by (simp add: poly_cmult_distr) ``` chaieb@26124 ` 948` ``` show ?thesis using cs ``` chaieb@26124 ` 949` ``` unfolding eq last_linear_mul_lemma by simp ``` chaieb@26124 ` 950` ```qed ``` chaieb@26124 ` 951` chaieb@26124 ` 952` ```lemma (in semiring_0) pnormalize_eq: "last p \ 0 \ pnormalize p = p" ``` chaieb@26124 ` 953` ``` apply (induct p, auto) ``` chaieb@26124 ` 954` ``` apply (case_tac p, auto)+ ``` chaieb@26124 ` 955` ``` done ``` chaieb@26124 ` 956` chaieb@26124 ` 957` ```lemma (in semiring_0) last_pnormalize: "pnormalize p \ [] \ last (pnormalize p) \ 0" ``` chaieb@26124 ` 958` ``` by (induct p, auto) ``` chaieb@26124 ` 959` chaieb@26124 ` 960` ```lemma (in semiring_0) pnormal_degree: "last p \ 0 \ degree p = length p - 1" ``` chaieb@26124 ` 961` ``` using pnormalize_eq[of p] unfolding degree_def by simp ``` chaieb@26124 ` 962` wenzelm@26313 ` 963` ```lemma (in semiring_0) poly_Nil_ext: "poly [] = (\x. 0)" by (rule ext) simp ``` chaieb@26124 ` 964` chaieb@26124 ` 965` ```lemma (in idom_char_0) linear_mul_degree: assumes p: "poly p \ poly []" ``` chaieb@26124 ` 966` ``` shows "degree ([a,1] *** p) = degree p + 1" ``` chaieb@26124 ` 967` ```proof- ``` chaieb@26124 ` 968` ``` from p have pnz: "pnormalize p \ []" ``` chaieb@26124 ` 969` ``` unfolding poly_zero lemma_degree_zero . ``` chaieb@26124 ` 970` ``` ``` chaieb@26124 ` 971` ``` from last_linear_mul[OF pnz, of a] last_pnormalize[OF pnz] ``` chaieb@26124 ` 972` ``` have l0: "last ([a, 1] *** pnormalize p) \ 0" by simp ``` chaieb@26124 ` 973` ``` from last_pnormalize[OF pnz] last_linear_mul[OF pnz, of a] ``` chaieb@26124 ` 974` ``` pnormal_degree[OF l0] pnormal_degree[OF last_pnormalize[OF pnz]] pnz ``` chaieb@26124 ` 975` ``` ``` chaieb@26124 ` 976` chaieb@26124 ` 977` ``` have th: "degree ([a,1] *** pnormalize p) = degree (pnormalize p) + 1" ``` chaieb@26124 ` 978` ``` by (auto simp add: poly_length_mult) ``` chaieb@26124 ` 979` chaieb@26124 ` 980` ``` have eqs: "poly ([a,1] *** pnormalize p) = poly ([a,1] *** p)" ``` chaieb@26124 ` 981` ``` by (rule ext) (simp add: poly_mult poly_add poly_cmult) ``` chaieb@26124 ` 982` ``` from degree_unique[OF eqs] th ``` chaieb@26124 ` 983` ``` show ?thesis by (simp add: degree_unique[OF poly_normalize]) ``` chaieb@26124 ` 984` ```qed ``` chaieb@26124 ` 985` chaieb@26124 ` 986` ```lemma (in idom_char_0) linear_pow_mul_degree: ``` chaieb@26124 ` 987` ``` "degree([a,1] %^n *** p) = (if poly p = poly [] then 0 else degree p + n)" ``` chaieb@26124 ` 988` ```proof(induct n arbitrary: a p) ``` chaieb@26124 ` 989` ``` case (0 a p) ``` chaieb@26124 ` 990` ``` {assume p: "poly p = poly []" ``` chaieb@26124 ` 991` ``` hence ?case using degree_unique[OF p] by (simp add: degree_def)} ``` chaieb@26124 ` 992` ``` moreover ``` wenzelm@26313 ` 993` ``` {assume p: "poly p \ poly []" hence ?case by (auto simp add: poly_Nil_ext) } ``` chaieb@26124 ` 994` ``` ultimately show ?case by blast ``` chaieb@26124 ` 995` ```next ``` chaieb@26124 ` 996` ``` case (Suc n a p) ``` chaieb@26124 ` 997` ``` have eq: "poly ([a,1] %^(Suc n) *** p) = poly ([a,1] %^ n *** ([a,1] *** p))" ``` chaieb@26124 ` 998` ``` apply (rule ext, simp add: poly_mult poly_add poly_cmult) ``` chaieb@26124 ` 999` ``` by (simp add: mult_ac add_ac right_distrib) ``` chaieb@26124 ` 1000` ``` note deq = degree_unique[OF eq] ``` chaieb@26124 ` 1001` ``` {assume p: "poly p = poly []" ``` chaieb@26124 ` 1002` ``` with eq have eq': "poly ([a,1] %^(Suc n) *** p) = poly []" ``` chaieb@26124 ` 1003` ``` by - (rule ext,simp add: poly_mult poly_cmult poly_add) ``` chaieb@26124 ` 1004` ``` from degree_unique[OF eq'] p have ?case by (simp add: degree_def)} ``` chaieb@26124 ` 1005` ``` moreover ``` chaieb@26124 ` 1006` ``` {assume p: "poly p \ poly []" ``` chaieb@26124 ` 1007` ``` from p have ap: "poly ([a,1] *** p) \ poly []" ``` chaieb@26124 ` 1008` ``` using poly_mult_not_eq_poly_Nil unfolding poly_entire by auto ``` chaieb@26124 ` 1009` ``` have eq: "poly ([a,1] %^(Suc n) *** p) = poly ([a,1]%^n *** ([a,1] *** p))" ``` chaieb@26124 ` 1010` ``` by (rule ext, simp add: poly_mult poly_add poly_exp poly_cmult mult_ac add_ac right_distrib) ``` chaieb@26124 ` 1011` ``` from ap have ap': "(poly ([a,1] *** p) = poly []) = False" by blast ``` chaieb@26124 ` 1012` ``` have th0: "degree ([a,1]%^n *** ([a,1] *** p)) = degree ([a,1] *** p) + n" ``` chaieb@26124 ` 1013` ``` apply (simp only: Suc.hyps[of a "pmult [a,one] p"] ap') ``` chaieb@26124 ` 1014` ``` by simp ``` chaieb@26124 ` 1015` ``` ``` chaieb@26124 ` 1016` ``` from degree_unique[OF eq] ap p th0 linear_mul_degree[OF p, of a] ``` chaieb@26124 ` 1017` ``` have ?case by (auto simp del: poly.simps)} ``` chaieb@26124 ` 1018` ``` ultimately show ?case by blast ``` chaieb@26124 ` 1019` ```qed ``` chaieb@26124 ` 1020` chaieb@26124 ` 1021` ```lemma (in recpower_idom_char_0) order_degree: ``` chaieb@26124 ` 1022` ``` assumes p0: "poly p \ poly []" ``` chaieb@26124 ` 1023` ``` shows "order a p \ degree p" ``` chaieb@26124 ` 1024` ```proof- ``` chaieb@26124 ` 1025` ``` from order2[OF p0, unfolded divides_def] ``` chaieb@26124 ` 1026` ``` obtain q where q: "poly p = poly ([- a, 1]%^ (order a p) *** q)" by blast ``` chaieb@26124 ` 1027` ``` {assume "poly q = poly []" ``` chaieb@26124 ` 1028` ``` with q p0 have False by (simp add: poly_mult poly_entire)} ``` chaieb@26124 ` 1029` ``` with degree_unique[OF q, unfolded linear_pow_mul_degree] ``` chaieb@26124 ` 1030` ``` show ?thesis by auto ``` chaieb@26124 ` 1031` ```qed ``` chaieb@26124 ` 1032` chaieb@26124 ` 1033` ```text{*Tidier versions of finiteness of roots.*} ``` chaieb@26124 ` 1034` chaieb@26124 ` 1035` ```lemma (in idom_char_0) poly_roots_finite_set: "poly p \ poly [] ==> finite {x. poly p x = 0}" ``` chaieb@26124 ` 1036` ```unfolding poly_roots_finite . ``` chaieb@26124 ` 1037` chaieb@26124 ` 1038` ```text{*bound for polynomial.*} ``` chaieb@26124 ` 1039` chaieb@26124 ` 1040` ```lemma poly_mono: "abs(x) \ k ==> abs(poly p (x::'a::{ordered_idom})) \ poly (map abs p) k" ``` chaieb@26124 ` 1041` ```apply (induct "p", auto) ``` chaieb@26124 ` 1042` ```apply (rule_tac y = "abs a + abs (x * poly p x)" in order_trans) ``` chaieb@26124 ` 1043` ```apply (rule abs_triangle_ineq) ``` chaieb@26124 ` 1044` ```apply (auto intro!: mult_mono simp add: abs_mult) ``` chaieb@26124 ` 1045` ```done ``` chaieb@26124 ` 1046` chaieb@26124 ` 1047` ```lemma (in semiring_0) poly_Sing: "poly [c] x = c" by simp ``` chaieb@26124 ` 1048` chaieb@26124 ` 1049` ```end ```