src/HOL/Deriv.thy
 changeset 29470 1851088a1f87 parent 29169 6a5f1d8d7344 child 29472 a63a2e46cec9
```     1.1 --- a/src/HOL/Deriv.thy	Tue Jan 13 06:55:13 2009 -0800
1.2 +++ b/src/HOL/Deriv.thy	Tue Jan 13 06:57:08 2009 -0800
1.3 @@ -9,7 +9,7 @@
1.5
1.6  theory Deriv
1.7 -imports Lim Univ_Poly
1.8 +imports Lim Polynomial
1.9  begin
1.10
1.11  text{*Standard Definitions*}
1.12 @@ -1412,34 +1412,71 @@
1.13  lemma lemma_DERIV_subst: "[| DERIV f x :> D; D = E |] ==> DERIV f x :> E"
1.14  by auto
1.15
1.16 +
1.17  subsection {* Derivatives of univariate polynomials *}
1.18
1.19 -
1.20 -
1.21 -primrec pderiv_aux :: "nat => real list => real list" where
1.22 -   pderiv_aux_Nil:  "pderiv_aux n [] = []"
1.23 -|  pderiv_aux_Cons: "pderiv_aux n (h#t) =
1.24 -                     (real n * h)#(pderiv_aux (Suc n) t)"
1.25 -
1.26  definition
1.27 -  pderiv :: "real list => real list" where
1.28 -  "pderiv p = (if p = [] then [] else pderiv_aux 1 (tl p))"
1.29 +  pderiv :: "'a::real_normed_field poly \<Rightarrow> 'a poly" where
1.30 +  "pderiv = poly_rec 0 (\<lambda>a p p'. p + pCons 0 p')"
1.31 +
1.32 +lemma pderiv_0 [simp]: "pderiv 0 = 0"
1.33 +  unfolding pderiv_def by (simp add: poly_rec_0)
1.34
1.35 +lemma pderiv_pCons: "pderiv (pCons a p) = p + pCons 0 (pderiv p)"
1.36 +  unfolding pderiv_def by (simp add: poly_rec_pCons)
1.37 +
1.38 +lemma coeff_pderiv: "coeff (pderiv p) n = of_nat (Suc n) * coeff p (Suc n)"
1.39 +  apply (induct p arbitrary: n, simp)
1.40 +  apply (simp add: pderiv_pCons coeff_pCons ring_simps split: nat.split)
1.41 +  done
1.42
1.43 -text{*The derivative*}
1.44 +lemma pderiv_eq_0_iff: "pderiv p = 0 \<longleftrightarrow> degree p = 0"
1.45 +  apply (rule iffI)
1.46 +  apply (cases p, simp)
1.47 +  apply (simp add: expand_poly_eq coeff_pderiv del: of_nat_Suc)
1.48 +  apply (simp add: expand_poly_eq coeff_pderiv coeff_eq_0)
1.49 +  done
1.50
1.51 -lemma pderiv_Nil: "pderiv [] = []"
1.52 +lemma degree_pderiv: "degree (pderiv p) = degree p - 1"
1.53 +  apply (rule order_antisym [OF degree_le])
1.54 +  apply (simp add: coeff_pderiv coeff_eq_0)
1.55 +  apply (cases "degree p", simp)
1.56 +  apply (rule le_degree)
1.57 +  apply (simp add: coeff_pderiv del: of_nat_Suc)
1.58 +  apply (rule subst, assumption)
1.59 +  apply (rule leading_coeff_neq_0, clarsimp)
1.60 +  done
1.61
1.63 -done
1.64 -declare pderiv_Nil [simp]
1.65 +lemma pderiv_singleton [simp]: "pderiv [:a:] = 0"
1.67 +
1.68 +lemma pderiv_add: "pderiv (p + q) = pderiv p + pderiv q"
1.69 +by (rule poly_ext, simp add: coeff_pderiv ring_simps)
1.70 +
1.71 +lemma pderiv_minus: "pderiv (- p) = - pderiv p"
1.72 +by (rule poly_ext, simp add: coeff_pderiv)
1.73 +
1.74 +lemma pderiv_diff: "pderiv (p - q) = pderiv p - pderiv q"
1.75 +by (rule poly_ext, simp add: coeff_pderiv ring_simps)
1.76 +
1.77 +lemma pderiv_smult: "pderiv (smult a p) = smult a (pderiv p)"
1.78 +by (rule poly_ext, simp add: coeff_pderiv ring_simps)
1.79
1.80 -lemma pderiv_singleton: "pderiv [c] = []"
1.82 -declare pderiv_singleton [simp]
1.83 +lemma pderiv_mult: "pderiv (p * q) = p * pderiv q + q * pderiv p"
1.84 +apply (induct p)
1.85 +apply simp
1.87 +done
1.88
1.89 -lemma pderiv_Cons: "pderiv (h#t) = pderiv_aux 1 t"
1.91 +lemma pderiv_power_Suc:
1.92 +  "pderiv (p ^ Suc n) = smult (of_nat (Suc n)) (p ^ n) * pderiv p"
1.93 +apply (induct n)
1.94 +apply simp
1.95 +apply (subst power_Suc)
1.96 +apply (subst pderiv_mult)
1.97 +apply (erule ssubst)
1.99 +done
1.100
1.101  lemma DERIV_cmult2: "DERIV f x :> D ==> DERIV (%x. (f x) * c :: real) x :> D * c"
1.102  by (simp add: DERIV_cmult mult_commute [of _ c])
1.103 @@ -1448,33 +1485,18 @@
1.104  by (rule lemma_DERIV_subst, rule DERIV_pow, simp)
1.105  declare DERIV_pow2 [simp] DERIV_pow [simp]
1.106
1.107 -lemma lemma_DERIV_poly1: "\<forall>n. DERIV (%x. (x ^ (Suc n) * poly p x)) x :>
1.108 -        x ^ n * poly (pderiv_aux (Suc n) p) x "
1.109 -apply (induct "p")
1.110 -apply (auto intro!: DERIV_add DERIV_cmult2
1.111 -            simp add: pderiv_def right_distrib real_mult_assoc [symmetric]
1.112 -            simp del: realpow_Suc)
1.113 -apply (subst mult_commute)
1.114 -apply (simp del: realpow_Suc)
1.115 -apply (simp add: mult_commute realpow_Suc [symmetric] del: realpow_Suc)
1.116 -done
1.117 -
1.118 -lemma lemma_DERIV_poly: "DERIV (%x. (x ^ (Suc n) * poly p x)) x :>
1.119 -        x ^ n * poly (pderiv_aux (Suc n) p) x "
1.120 -by (simp add: lemma_DERIV_poly1 del: realpow_Suc)
1.121 -
1.122 -lemma DERIV_add_const: "DERIV f x :> D ==>  DERIV (%x. a + f x :: real) x :> D"
1.123 +lemma DERIV_add_const: "DERIV f x :> D ==>  DERIV (%x. a + f x :: 'a::real_normed_field) x :> D"
1.124  by (rule lemma_DERIV_subst, rule DERIV_add, auto)
1.125
1.126  lemma poly_DERIV[simp]: "DERIV (%x. poly p x) x :> poly (pderiv p) x"
1.127 -apply (induct "p")
1.128 -apply (auto simp add: pderiv_Cons)
1.130 +apply (induct p)
1.131 +apply simp
1.133  apply (rule lemma_DERIV_subst)
1.134 -apply (rule lemma_DERIV_poly [where n=0, simplified], simp)
1.135 +apply (rule DERIV_add DERIV_mult DERIV_const DERIV_ident | assumption)+
1.136 +apply simp
1.137  done
1.138
1.139 -
1.140  text{* Consequences of the derivative theorem above*}
1.141
1.142  lemma poly_differentiable[simp]: "(%x. poly p x) differentiable (x::real)"
1.143 @@ -1493,11 +1515,9 @@
1.144
1.145  lemma poly_IVT_neg: "[| (a::real) < b; 0 < poly p a; poly p b < 0 |]
1.146        ==> \<exists>x. a < x & x < b & (poly p x = 0)"
1.147 -apply (insert poly_IVT_pos [where p = "-- p" ])
1.148 -apply (simp add: poly_minus neg_less_0_iff_less)
1.149 -done
1.150 +by (insert poly_IVT_pos [where p = "- p" ]) simp
1.151
1.152 -lemma poly_MVT: "a < b ==>
1.153 +lemma poly_MVT: "(a::real) < b ==>
1.154       \<exists>x. a < x & x < b & (poly p b - poly p a = (b - a) * poly (pderiv p) x)"
1.155  apply (drule_tac f = "poly p" in MVT, auto)
1.156  apply (rule_tac x = z in exI)
1.157 @@ -1506,136 +1526,7 @@
1.158
1.159  text{*Lemmas for Derivatives*}
1.160
1.161 -lemma lemma_poly_pderiv_aux_add: "\<forall>p2 n. poly (pderiv_aux n (p1 +++ p2)) x =
1.162 -                poly (pderiv_aux n p1 +++ pderiv_aux n p2) x"
1.163 -apply (induct "p1", simp, clarify)
1.164 -apply (case_tac "p2")
1.165 -apply (auto simp add: right_distrib)
1.166 -done
1.167 -
1.168 -lemma poly_pderiv_aux_add: "poly (pderiv_aux n (p1 +++ p2)) x =
1.169 -      poly (pderiv_aux n p1 +++ pderiv_aux n p2) x"
1.171 -done
1.172 -
1.173 -lemma lemma_poly_pderiv_aux_cmult: "\<forall>n. poly (pderiv_aux n (c %* p)) x = poly (c %* pderiv_aux n p) x"
1.174 -apply (induct "p")
1.175 -apply (auto simp add: poly_cmult mult_ac)
1.176 -done
1.177 -
1.178 -lemma poly_pderiv_aux_cmult: "poly (pderiv_aux n (c %* p)) x = poly (c %* pderiv_aux n p) x"
1.180 -
1.181 -lemma poly_pderiv_aux_minus:
1.182 -   "poly (pderiv_aux n (-- p)) x = poly (-- pderiv_aux n p) x"
1.183 -apply (simp add: poly_minus_def poly_pderiv_aux_cmult)
1.184 -done
1.185 -
1.186 -lemma lemma_poly_pderiv_aux_mult1: "\<forall>n. poly (pderiv_aux (Suc n) p) x = poly ((pderiv_aux n p) +++ p) x"
1.187 -apply (induct "p")
1.188 -apply (auto simp add: real_of_nat_Suc left_distrib)
1.189 -done
1.190 -
1.191 -lemma lemma_poly_pderiv_aux_mult: "poly (pderiv_aux (Suc n) p) x = poly ((pderiv_aux n p) +++ p) x"
1.193 -
1.194 -lemma lemma_poly_pderiv_add: "\<forall>q. poly (pderiv (p +++ q)) x = poly (pderiv p +++ pderiv q) x"
1.195 -apply (induct "p", simp, clarify)
1.196 -apply (case_tac "q")
1.198 -done
1.199 -
1.200 -lemma poly_pderiv_add: "poly (pderiv (p +++ q)) x = poly (pderiv p +++ pderiv q) x"
1.202 -
1.203 -lemma poly_pderiv_cmult: "poly (pderiv (c %* p)) x = poly (c %* (pderiv p)) x"
1.204 -apply (induct "p")
1.205 -apply (auto simp add: poly_pderiv_aux_cmult poly_cmult pderiv_def)
1.206 -done
1.207 -
1.208 -lemma poly_pderiv_minus: "poly (pderiv (--p)) x = poly (--(pderiv p)) x"
1.209 -by (simp add: poly_minus_def poly_pderiv_cmult)
1.210 -
1.211 -lemma lemma_poly_mult_pderiv:
1.212 -   "poly (pderiv (h#t)) x = poly ((0 # (pderiv t)) +++ t) x"
1.214 -apply (induct "t")
1.216 -done
1.217 -
1.218 -lemma poly_pderiv_mult: "\<forall>q. poly (pderiv (p *** q)) x =
1.219 -      poly (p *** (pderiv q) +++ q *** (pderiv p)) x"
1.220 -apply (induct "p")
1.222 -apply (rule lemma_poly_mult_pderiv [THEN ssubst])
1.223 -apply (rule lemma_poly_mult_pderiv [THEN ssubst])
1.224 -apply (rule poly_add [THEN ssubst])
1.225 -apply (rule poly_add [THEN ssubst])
1.227 -done
1.228 -
1.229 -lemma poly_pderiv_exp: "poly (pderiv (p %^ (Suc n))) x =
1.230 -         poly ((real (Suc n)) %* (p %^ n) *** pderiv p) x"
1.231 -apply (induct "n")
1.233 -                      real_of_nat_zero poly_mult real_of_nat_Suc
1.234 -                      right_distrib left_distrib mult_ac)
1.235 -done
1.236 -
1.237 -lemma poly_pderiv_exp_prime: "poly (pderiv ([-a, 1] %^ (Suc n))) x =
1.238 -      poly (real (Suc n) %* ([-a, 1] %^ n)) x"
1.239 -apply (simp add: poly_pderiv_exp poly_mult del: pexp_Suc)
1.240 -apply (simp add: poly_cmult pderiv_def)
1.241 -done
1.242 -
1.243 -
1.244 -lemma real_mult_zero_disj_iff[simp]: "(x * y = 0) = (x = (0::real) | y = 0)"
1.245 -by simp
1.246 -
1.247 -lemma pderiv_aux_iszero [rule_format, simp]:
1.248 -    "\<forall>n. list_all (%c. c = 0) (pderiv_aux (Suc n) p) = list_all (%c. c = 0) p"
1.249 -by (induct "p", auto)
1.250 -
1.251 -lemma pderiv_aux_iszero_num: "(number_of n :: nat) \<noteq> 0
1.252 -      ==> (list_all (%c. c = 0) (pderiv_aux (number_of n) p) =
1.253 -      list_all (%c. c = 0) p)"
1.254 -unfolding neq0_conv
1.255 -apply (rule_tac n1 = "number_of n" and m1 = 0 in less_imp_Suc_add [THEN exE], force)
1.256 -apply (rule_tac n1 = "0 + x" in pderiv_aux_iszero [THEN subst])
1.257 -apply (simp (no_asm_simp) del: pderiv_aux_iszero)
1.258 -done
1.259 -
1.260 -instance real:: idom_char_0
1.261 -apply (intro_classes)
1.262 -done
1.263 -
1.264 -instance real:: recpower_idom_char_0
1.265 -apply (intro_classes)
1.266 -done
1.267 -
1.268 -lemma pderiv_iszero [rule_format]:
1.269 -     "poly (pderiv p) = poly [] --> (\<exists>h. poly p = poly [h])"
1.271 -apply (induct "p", force)
1.272 -apply (simp add: pderiv_Cons pderiv_aux_iszero_num del: poly_Cons)
1.273 -apply (auto simp add: poly_zero [symmetric])
1.274 -done
1.275 -
1.276 -lemma pderiv_zero_obj: "poly p = poly [] --> (poly (pderiv p) = poly [])"
1.278 -apply (induct "p", force)
1.279 -apply (simp add: pderiv_Cons pderiv_aux_iszero_num del: poly_Cons)
1.280 -done
1.281 -
1.282 -lemma pderiv_zero: "poly p = poly [] ==> (poly (pderiv p) = poly [])"
1.283 -by (blast elim: pderiv_zero_obj [THEN impE])
1.284 -declare pderiv_zero [simp]
1.285 -
1.286 -lemma poly_pderiv_welldef: "poly p = poly q ==> (poly (pderiv p) = poly (pderiv q))"
1.287 -apply (cut_tac p = "p +++ --q" in pderiv_zero_obj)
1.289 -done
1.290 -
1.291 +(* FIXME
1.292  lemma lemma_order_pderiv [rule_format]:
1.293       "\<forall>p q a. 0 < n &
1.294         poly (pderiv p) \<noteq> poly [] &
1.295 @@ -1756,7 +1647,7 @@
1.296  apply (simp (no_asm) add: rsquarefree_def order_root del: pmult_Cons)
1.297  apply (simp add: poly_entire del: pmult_Cons)
1.298  done
1.299 -
1.300 +*)
1.301
1.302  subsection {* Theorems about Limits *}
1.303
```