src/HOL/Library/Poly_Deriv.thy
 author hoelzl Tue Jun 30 18:21:55 2009 +0200 (2009-06-30) changeset 31881 eba74a5790d2 parent 30273 ecd6f0ca62ea child 35050 9f841f20dca6 permissions -rw-r--r--
use DERIV_intros
 huffman@29985 ` 1` ```(* Title: Poly_Deriv.thy ``` huffman@29985 ` 2` ``` Author: Amine Chaieb ``` huffman@29985 ` 3` ``` Ported to new Polynomial library by Brian Huffman ``` huffman@29985 ` 4` ```*) ``` huffman@29985 ` 5` huffman@29985 ` 6` ```header{* Polynomials and Differentiation *} ``` huffman@29985 ` 7` huffman@29985 ` 8` ```theory Poly_Deriv ``` huffman@29985 ` 9` ```imports Deriv Polynomial ``` huffman@29985 ` 10` ```begin ``` huffman@29985 ` 11` huffman@29985 ` 12` ```subsection {* Derivatives of univariate polynomials *} ``` huffman@29985 ` 13` huffman@29985 ` 14` ```definition ``` huffman@29985 ` 15` ``` pderiv :: "'a::real_normed_field poly \ 'a poly" where ``` huffman@29985 ` 16` ``` "pderiv = poly_rec 0 (\a p p'. p + pCons 0 p')" ``` huffman@29985 ` 17` huffman@29985 ` 18` ```lemma pderiv_0 [simp]: "pderiv 0 = 0" ``` huffman@29985 ` 19` ``` unfolding pderiv_def by (simp add: poly_rec_0) ``` huffman@29985 ` 20` huffman@29985 ` 21` ```lemma pderiv_pCons: "pderiv (pCons a p) = p + pCons 0 (pderiv p)" ``` huffman@29985 ` 22` ``` unfolding pderiv_def by (simp add: poly_rec_pCons) ``` huffman@29985 ` 23` huffman@29985 ` 24` ```lemma coeff_pderiv: "coeff (pderiv p) n = of_nat (Suc n) * coeff p (Suc n)" ``` huffman@29985 ` 25` ``` apply (induct p arbitrary: n, simp) ``` huffman@29985 ` 26` ``` apply (simp add: pderiv_pCons coeff_pCons algebra_simps split: nat.split) ``` huffman@29985 ` 27` ``` done ``` huffman@29985 ` 28` huffman@29985 ` 29` ```lemma pderiv_eq_0_iff: "pderiv p = 0 \ degree p = 0" ``` huffman@29985 ` 30` ``` apply (rule iffI) ``` huffman@29985 ` 31` ``` apply (cases p, simp) ``` huffman@29985 ` 32` ``` apply (simp add: expand_poly_eq coeff_pderiv del: of_nat_Suc) ``` huffman@29985 ` 33` ``` apply (simp add: expand_poly_eq coeff_pderiv coeff_eq_0) ``` huffman@29985 ` 34` ``` done ``` huffman@29985 ` 35` huffman@29985 ` 36` ```lemma degree_pderiv: "degree (pderiv p) = degree p - 1" ``` huffman@29985 ` 37` ``` apply (rule order_antisym [OF degree_le]) ``` huffman@29985 ` 38` ``` apply (simp add: coeff_pderiv coeff_eq_0) ``` huffman@29985 ` 39` ``` apply (cases "degree p", simp) ``` huffman@29985 ` 40` ``` apply (rule le_degree) ``` huffman@29985 ` 41` ``` apply (simp add: coeff_pderiv del: of_nat_Suc) ``` huffman@29985 ` 42` ``` apply (rule subst, assumption) ``` huffman@29985 ` 43` ``` apply (rule leading_coeff_neq_0, clarsimp) ``` huffman@29985 ` 44` ``` done ``` huffman@29985 ` 45` huffman@29985 ` 46` ```lemma pderiv_singleton [simp]: "pderiv [:a:] = 0" ``` huffman@29985 ` 47` ```by (simp add: pderiv_pCons) ``` huffman@29985 ` 48` huffman@29985 ` 49` ```lemma pderiv_add: "pderiv (p + q) = pderiv p + pderiv q" ``` huffman@29985 ` 50` ```by (rule poly_ext, simp add: coeff_pderiv algebra_simps) ``` huffman@29985 ` 51` huffman@29985 ` 52` ```lemma pderiv_minus: "pderiv (- p) = - pderiv p" ``` huffman@29985 ` 53` ```by (rule poly_ext, simp add: coeff_pderiv) ``` huffman@29985 ` 54` huffman@29985 ` 55` ```lemma pderiv_diff: "pderiv (p - q) = pderiv p - pderiv q" ``` huffman@29985 ` 56` ```by (rule poly_ext, simp add: coeff_pderiv algebra_simps) ``` huffman@29985 ` 57` huffman@29985 ` 58` ```lemma pderiv_smult: "pderiv (smult a p) = smult a (pderiv p)" ``` huffman@29985 ` 59` ```by (rule poly_ext, simp add: coeff_pderiv algebra_simps) ``` huffman@29985 ` 60` huffman@29985 ` 61` ```lemma pderiv_mult: "pderiv (p * q) = p * pderiv q + q * pderiv p" ``` huffman@29985 ` 62` ```apply (induct p) ``` huffman@29985 ` 63` ```apply simp ``` huffman@29985 ` 64` ```apply (simp add: pderiv_add pderiv_smult pderiv_pCons algebra_simps) ``` huffman@29985 ` 65` ```done ``` huffman@29985 ` 66` huffman@29985 ` 67` ```lemma pderiv_power_Suc: ``` huffman@29985 ` 68` ``` "pderiv (p ^ Suc n) = smult (of_nat (Suc n)) (p ^ n) * pderiv p" ``` huffman@29985 ` 69` ```apply (induct n) ``` huffman@29985 ` 70` ```apply simp ``` huffman@29985 ` 71` ```apply (subst power_Suc) ``` huffman@29985 ` 72` ```apply (subst pderiv_mult) ``` huffman@29985 ` 73` ```apply (erule ssubst) ``` huffman@29985 ` 74` ```apply (simp add: smult_add_left algebra_simps) ``` huffman@29985 ` 75` ```done ``` huffman@29985 ` 76` huffman@29985 ` 77` ```lemma DERIV_cmult2: "DERIV f x :> D ==> DERIV (%x. (f x) * c :: real) x :> D * c" ``` huffman@29985 ` 78` ```by (simp add: DERIV_cmult mult_commute [of _ c]) ``` huffman@29985 ` 79` huffman@29985 ` 80` ```lemma DERIV_pow2: "DERIV (%x. x ^ Suc n) x :> real (Suc n) * (x ^ n)" ``` huffman@29985 ` 81` ```by (rule lemma_DERIV_subst, rule DERIV_pow, simp) ``` huffman@29985 ` 82` ```declare DERIV_pow2 [simp] DERIV_pow [simp] ``` huffman@29985 ` 83` huffman@29985 ` 84` ```lemma DERIV_add_const: "DERIV f x :> D ==> DERIV (%x. a + f x :: 'a::real_normed_field) x :> D" ``` huffman@29985 ` 85` ```by (rule lemma_DERIV_subst, rule DERIV_add, auto) ``` huffman@29985 ` 86` huffman@29985 ` 87` ```lemma poly_DERIV[simp]: "DERIV (%x. poly p x) x :> poly (pderiv p) x" ``` hoelzl@31881 ` 88` ``` by (induct p, auto intro!: DERIV_intros simp add: pderiv_pCons) ``` huffman@29985 ` 89` huffman@29985 ` 90` ```text{* Consequences of the derivative theorem above*} ``` huffman@29985 ` 91` huffman@29985 ` 92` ```lemma poly_differentiable[simp]: "(%x. poly p x) differentiable (x::real)" ``` huffman@29985 ` 93` ```apply (simp add: differentiable_def) ``` huffman@29985 ` 94` ```apply (blast intro: poly_DERIV) ``` huffman@29985 ` 95` ```done ``` huffman@29985 ` 96` huffman@29985 ` 97` ```lemma poly_isCont[simp]: "isCont (%x. poly p x) (x::real)" ``` huffman@29985 ` 98` ```by (rule poly_DERIV [THEN DERIV_isCont]) ``` huffman@29985 ` 99` huffman@29985 ` 100` ```lemma poly_IVT_pos: "[| a < b; poly p (a::real) < 0; 0 < poly p b |] ``` huffman@29985 ` 101` ``` ==> \x. a < x & x < b & (poly p x = 0)" ``` huffman@29985 ` 102` ```apply (cut_tac f = "%x. poly p x" and a = a and b = b and y = 0 in IVT_objl) ``` huffman@29985 ` 103` ```apply (auto simp add: order_le_less) ``` huffman@29985 ` 104` ```done ``` huffman@29985 ` 105` huffman@29985 ` 106` ```lemma poly_IVT_neg: "[| (a::real) < b; 0 < poly p a; poly p b < 0 |] ``` huffman@29985 ` 107` ``` ==> \x. a < x & x < b & (poly p x = 0)" ``` huffman@29985 ` 108` ```by (insert poly_IVT_pos [where p = "- p" ]) simp ``` huffman@29985 ` 109` huffman@29985 ` 110` ```lemma poly_MVT: "(a::real) < b ==> ``` huffman@29985 ` 111` ``` \x. a < x & x < b & (poly p b - poly p a = (b - a) * poly (pderiv p) x)" ``` huffman@29985 ` 112` ```apply (drule_tac f = "poly p" in MVT, auto) ``` huffman@29985 ` 113` ```apply (rule_tac x = z in exI) ``` huffman@29985 ` 114` ```apply (auto simp add: real_mult_left_cancel poly_DERIV [THEN DERIV_unique]) ``` huffman@29985 ` 115` ```done ``` huffman@29985 ` 116` huffman@29985 ` 117` ```text{*Lemmas for Derivatives*} ``` huffman@29985 ` 118` huffman@29985 ` 119` ```lemma order_unique_lemma: ``` huffman@29985 ` 120` ``` fixes p :: "'a::idom poly" ``` huffman@29985 ` 121` ``` assumes "[:-a, 1:] ^ n dvd p \ \ [:-a, 1:] ^ Suc n dvd p" ``` huffman@29985 ` 122` ``` shows "n = order a p" ``` huffman@29985 ` 123` ```unfolding Polynomial.order_def ``` huffman@29985 ` 124` ```apply (rule Least_equality [symmetric]) ``` huffman@29985 ` 125` ```apply (rule assms [THEN conjunct2]) ``` huffman@29985 ` 126` ```apply (erule contrapos_np) ``` huffman@29985 ` 127` ```apply (rule power_le_dvd) ``` huffman@29985 ` 128` ```apply (rule assms [THEN conjunct1]) ``` huffman@29985 ` 129` ```apply simp ``` huffman@29985 ` 130` ```done ``` huffman@29985 ` 131` huffman@29985 ` 132` ```lemma lemma_order_pderiv1: ``` huffman@29985 ` 133` ``` "pderiv ([:- a, 1:] ^ Suc n * q) = [:- a, 1:] ^ Suc n * pderiv q + ``` huffman@29985 ` 134` ``` smult (of_nat (Suc n)) (q * [:- a, 1:] ^ n)" ``` huffman@29985 ` 135` ```apply (simp only: pderiv_mult pderiv_power_Suc) ``` huffman@30273 ` 136` ```apply (simp del: power_Suc of_nat_Suc add: pderiv_pCons) ``` huffman@29985 ` 137` ```done ``` huffman@29985 ` 138` huffman@29985 ` 139` ```lemma dvd_add_cancel1: ``` huffman@29985 ` 140` ``` fixes a b c :: "'a::comm_ring_1" ``` huffman@29985 ` 141` ``` shows "a dvd b + c \ a dvd b \ a dvd c" ``` huffman@29985 ` 142` ``` by (drule (1) Ring_and_Field.dvd_diff, simp) ``` huffman@29985 ` 143` huffman@29985 ` 144` ```lemma lemma_order_pderiv [rule_format]: ``` huffman@29985 ` 145` ``` "\p q a. 0 < n & ``` huffman@29985 ` 146` ``` pderiv p \ 0 & ``` huffman@29985 ` 147` ``` p = [:- a, 1:] ^ n * q & ~ [:- a, 1:] dvd q ``` huffman@29985 ` 148` ``` --> n = Suc (order a (pderiv p))" ``` huffman@29985 ` 149` ``` apply (cases "n", safe, rename_tac n p q a) ``` huffman@29985 ` 150` ``` apply (rule order_unique_lemma) ``` huffman@29985 ` 151` ``` apply (rule conjI) ``` huffman@29985 ` 152` ``` apply (subst lemma_order_pderiv1) ``` huffman@29985 ` 153` ``` apply (rule dvd_add) ``` huffman@29985 ` 154` ``` apply (rule dvd_mult2) ``` huffman@29985 ` 155` ``` apply (rule le_imp_power_dvd, simp) ``` huffman@29985 ` 156` ``` apply (rule dvd_smult) ``` huffman@29985 ` 157` ``` apply (rule dvd_mult) ``` huffman@29985 ` 158` ``` apply (rule dvd_refl) ``` huffman@29985 ` 159` ``` apply (subst lemma_order_pderiv1) ``` huffman@29985 ` 160` ``` apply (erule contrapos_nn) back ``` huffman@29985 ` 161` ``` apply (subgoal_tac "[:- a, 1:] ^ Suc n dvd q * [:- a, 1:] ^ n") ``` huffman@29985 ` 162` ``` apply (simp del: mult_pCons_left) ``` huffman@29985 ` 163` ``` apply (drule dvd_add_cancel1) ``` huffman@29985 ` 164` ``` apply (simp del: mult_pCons_left) ``` huffman@29985 ` 165` ``` apply (drule dvd_smult_cancel, simp del: of_nat_Suc) ``` huffman@29985 ` 166` ``` apply assumption ``` huffman@29985 ` 167` ```done ``` huffman@29985 ` 168` huffman@29985 ` 169` ```lemma order_decomp: ``` huffman@29985 ` 170` ``` "p \ 0 ``` huffman@29985 ` 171` ``` ==> \q. p = [:-a, 1:] ^ (order a p) * q & ``` huffman@29985 ` 172` ``` ~([:-a, 1:] dvd q)" ``` huffman@29985 ` 173` ```apply (drule order [where a=a]) ``` huffman@29985 ` 174` ```apply (erule conjE) ``` huffman@29985 ` 175` ```apply (erule dvdE) ``` huffman@29985 ` 176` ```apply (rule exI) ``` huffman@29985 ` 177` ```apply (rule conjI, assumption) ``` huffman@29985 ` 178` ```apply (erule contrapos_nn) ``` huffman@29985 ` 179` ```apply (erule ssubst) back ``` huffman@29985 ` 180` ```apply (subst power_Suc2) ``` huffman@29985 ` 181` ```apply (erule mult_dvd_mono [OF dvd_refl]) ``` huffman@29985 ` 182` ```done ``` huffman@29985 ` 183` huffman@29985 ` 184` ```lemma order_pderiv: "[| pderiv p \ 0; order a p \ 0 |] ``` huffman@29985 ` 185` ``` ==> (order a p = Suc (order a (pderiv p)))" ``` huffman@29985 ` 186` ```apply (case_tac "p = 0", simp) ``` huffman@29985 ` 187` ```apply (drule_tac a = a and p = p in order_decomp) ``` huffman@29985 ` 188` ```using neq0_conv ``` huffman@29985 ` 189` ```apply (blast intro: lemma_order_pderiv) ``` huffman@29985 ` 190` ```done ``` huffman@29985 ` 191` huffman@29985 ` 192` ```lemma order_mult: "p * q \ 0 \ order a (p * q) = order a p + order a q" ``` huffman@29985 ` 193` ```proof - ``` huffman@29985 ` 194` ``` def i \ "order a p" ``` huffman@29985 ` 195` ``` def j \ "order a q" ``` huffman@29985 ` 196` ``` def t \ "[:-a, 1:]" ``` huffman@29985 ` 197` ``` have t_dvd_iff: "\u. t dvd u \ poly u a = 0" ``` huffman@29985 ` 198` ``` unfolding t_def by (simp add: dvd_iff_poly_eq_0) ``` huffman@29985 ` 199` ``` assume "p * q \ 0" ``` huffman@29985 ` 200` ``` then show "order a (p * q) = i + j" ``` huffman@29985 ` 201` ``` apply clarsimp ``` huffman@29985 ` 202` ``` apply (drule order [where a=a and p=p, folded i_def t_def]) ``` huffman@29985 ` 203` ``` apply (drule order [where a=a and p=q, folded j_def t_def]) ``` huffman@29985 ` 204` ``` apply clarify ``` huffman@29985 ` 205` ``` apply (rule order_unique_lemma [symmetric], fold t_def) ``` huffman@29985 ` 206` ``` apply (erule dvdE)+ ``` huffman@29985 ` 207` ``` apply (simp add: power_add t_dvd_iff) ``` huffman@29985 ` 208` ``` done ``` huffman@29985 ` 209` ```qed ``` huffman@29985 ` 210` huffman@29985 ` 211` ```text{*Now justify the standard squarefree decomposition, i.e. f / gcd(f,f'). *} ``` huffman@29985 ` 212` huffman@29985 ` 213` ```lemma order_divides: "[:-a, 1:] ^ n dvd p \ p = 0 \ n \ order a p" ``` huffman@29985 ` 214` ```apply (cases "p = 0", auto) ``` huffman@29985 ` 215` ```apply (drule order_2 [where a=a and p=p]) ``` huffman@29985 ` 216` ```apply (erule contrapos_np) ``` huffman@29985 ` 217` ```apply (erule power_le_dvd) ``` huffman@29985 ` 218` ```apply simp ``` huffman@29985 ` 219` ```apply (erule power_le_dvd [OF order_1]) ``` huffman@29985 ` 220` ```done ``` huffman@29985 ` 221` huffman@29985 ` 222` ```lemma poly_squarefree_decomp_order: ``` huffman@29985 ` 223` ``` assumes "pderiv p \ 0" ``` huffman@29985 ` 224` ``` and p: "p = q * d" ``` huffman@29985 ` 225` ``` and p': "pderiv p = e * d" ``` huffman@29985 ` 226` ``` and d: "d = r * p + s * pderiv p" ``` huffman@29985 ` 227` ``` shows "order a q = (if order a p = 0 then 0 else 1)" ``` huffman@29985 ` 228` ```proof (rule classical) ``` huffman@29985 ` 229` ``` assume 1: "order a q \ (if order a p = 0 then 0 else 1)" ``` huffman@29985 ` 230` ``` from `pderiv p \ 0` have "p \ 0" by auto ``` huffman@29985 ` 231` ``` with p have "order a p = order a q + order a d" ``` huffman@29985 ` 232` ``` by (simp add: order_mult) ``` huffman@29985 ` 233` ``` with 1 have "order a p \ 0" by (auto split: if_splits) ``` huffman@29985 ` 234` ``` have "order a (pderiv p) = order a e + order a d" ``` huffman@29985 ` 235` ``` using `pderiv p \ 0` `pderiv p = e * d` by (simp add: order_mult) ``` huffman@29985 ` 236` ``` have "order a p = Suc (order a (pderiv p))" ``` huffman@29985 ` 237` ``` using `pderiv p \ 0` `order a p \ 0` by (rule order_pderiv) ``` huffman@29985 ` 238` ``` have "d \ 0" using `p \ 0` `p = q * d` by simp ``` huffman@29985 ` 239` ``` have "([:-a, 1:] ^ (order a (pderiv p))) dvd d" ``` huffman@29985 ` 240` ``` apply (simp add: d) ``` huffman@29985 ` 241` ``` apply (rule dvd_add) ``` huffman@29985 ` 242` ``` apply (rule dvd_mult) ``` huffman@29985 ` 243` ``` apply (simp add: order_divides `p \ 0` ``` huffman@29985 ` 244` ``` `order a p = Suc (order a (pderiv p))`) ``` huffman@29985 ` 245` ``` apply (rule dvd_mult) ``` huffman@29985 ` 246` ``` apply (simp add: order_divides) ``` huffman@29985 ` 247` ``` done ``` huffman@29985 ` 248` ``` then have "order a (pderiv p) \ order a d" ``` huffman@29985 ` 249` ``` using `d \ 0` by (simp add: order_divides) ``` huffman@29985 ` 250` ``` show ?thesis ``` huffman@29985 ` 251` ``` using `order a p = order a q + order a d` ``` huffman@29985 ` 252` ``` using `order a (pderiv p) = order a e + order a d` ``` huffman@29985 ` 253` ``` using `order a p = Suc (order a (pderiv p))` ``` huffman@29985 ` 254` ``` using `order a (pderiv p) \ order a d` ``` huffman@29985 ` 255` ``` by auto ``` huffman@29985 ` 256` ```qed ``` huffman@29985 ` 257` huffman@29985 ` 258` ```lemma poly_squarefree_decomp_order2: "[| pderiv p \ 0; ``` huffman@29985 ` 259` ``` p = q * d; ``` huffman@29985 ` 260` ``` pderiv p = e * d; ``` huffman@29985 ` 261` ``` d = r * p + s * pderiv p ``` huffman@29985 ` 262` ``` |] ==> \a. order a q = (if order a p = 0 then 0 else 1)" ``` huffman@29985 ` 263` ```apply (blast intro: poly_squarefree_decomp_order) ``` huffman@29985 ` 264` ```done ``` huffman@29985 ` 265` huffman@29985 ` 266` ```lemma order_pderiv2: "[| pderiv p \ 0; order a p \ 0 |] ``` huffman@29985 ` 267` ``` ==> (order a (pderiv p) = n) = (order a p = Suc n)" ``` huffman@29985 ` 268` ```apply (auto dest: order_pderiv) ``` huffman@29985 ` 269` ```done ``` huffman@29985 ` 270` huffman@29985 ` 271` ```definition ``` huffman@29985 ` 272` ``` rsquarefree :: "'a::idom poly => bool" where ``` huffman@29985 ` 273` ``` "rsquarefree p = (p \ 0 & (\a. (order a p = 0) | (order a p = 1)))" ``` huffman@29985 ` 274` huffman@29985 ` 275` ```lemma pderiv_iszero: "pderiv p = 0 \ \h. p = [:h:]" ``` huffman@29985 ` 276` ```apply (simp add: pderiv_eq_0_iff) ``` huffman@29985 ` 277` ```apply (case_tac p, auto split: if_splits) ``` huffman@29985 ` 278` ```done ``` huffman@29985 ` 279` huffman@29985 ` 280` ```lemma rsquarefree_roots: ``` huffman@29985 ` 281` ``` "rsquarefree p = (\a. ~(poly p a = 0 & poly (pderiv p) a = 0))" ``` huffman@29985 ` 282` ```apply (simp add: rsquarefree_def) ``` huffman@29985 ` 283` ```apply (case_tac "p = 0", simp, simp) ``` huffman@29985 ` 284` ```apply (case_tac "pderiv p = 0") ``` huffman@29985 ` 285` ```apply simp ``` huffman@29985 ` 286` ```apply (drule pderiv_iszero, clarify) ``` huffman@29985 ` 287` ```apply simp ``` huffman@29985 ` 288` ```apply (rule allI) ``` huffman@29985 ` 289` ```apply (cut_tac p = "[:h:]" and a = a in order_root) ``` huffman@29985 ` 290` ```apply simp ``` huffman@29985 ` 291` ```apply (auto simp add: order_root order_pderiv2) ``` huffman@29985 ` 292` ```apply (erule_tac x="a" in allE, simp) ``` huffman@29985 ` 293` ```done ``` huffman@29985 ` 294` huffman@29985 ` 295` ```lemma poly_squarefree_decomp: ``` huffman@29985 ` 296` ``` assumes "pderiv p \ 0" ``` huffman@29985 ` 297` ``` and "p = q * d" ``` huffman@29985 ` 298` ``` and "pderiv p = e * d" ``` huffman@29985 ` 299` ``` and "d = r * p + s * pderiv p" ``` huffman@29985 ` 300` ``` shows "rsquarefree q & (\a. (poly q a = 0) = (poly p a = 0))" ``` huffman@29985 ` 301` ```proof - ``` huffman@29985 ` 302` ``` from `pderiv p \ 0` have "p \ 0" by auto ``` huffman@29985 ` 303` ``` with `p = q * d` have "q \ 0" by simp ``` huffman@29985 ` 304` ``` have "\a. order a q = (if order a p = 0 then 0 else 1)" ``` huffman@29985 ` 305` ``` using assms by (rule poly_squarefree_decomp_order2) ``` huffman@29985 ` 306` ``` with `p \ 0` `q \ 0` show ?thesis ``` huffman@29985 ` 307` ``` by (simp add: rsquarefree_def order_root) ``` huffman@29985 ` 308` ```qed ``` huffman@29985 ` 309` huffman@29985 ` 310` ```end ```