src/HOL/Deriv.thy
 changeset 29985 57975b45ab70 parent 29982 6ec97eba1ee3 child 29987 391dcbd7e4dd
```     1.1 --- a/src/HOL/Deriv.thy	Wed Feb 18 17:02:38 2009 -0800
1.2 +++ b/src/HOL/Deriv.thy	Wed Feb 18 19:32:26 2009 -0800
1.3 @@ -1457,311 +1457,6 @@
1.4  qed
1.5
1.6
1.7 -subsection {* Derivatives of univariate polynomials *}
1.8 -
1.9 -definition
1.10 -  pderiv :: "'a::real_normed_field poly \<Rightarrow> 'a poly" where
1.11 -  "pderiv = poly_rec 0 (\<lambda>a p p'. p + pCons 0 p')"
1.12 -
1.13 -lemma pderiv_0 [simp]: "pderiv 0 = 0"
1.14 -  unfolding pderiv_def by (simp add: poly_rec_0)
1.15 -
1.16 -lemma pderiv_pCons: "pderiv (pCons a p) = p + pCons 0 (pderiv p)"
1.17 -  unfolding pderiv_def by (simp add: poly_rec_pCons)
1.18 -
1.19 -lemma coeff_pderiv: "coeff (pderiv p) n = of_nat (Suc n) * coeff p (Suc n)"
1.20 -  apply (induct p arbitrary: n, simp)
1.21 -  apply (simp add: pderiv_pCons coeff_pCons algebra_simps split: nat.split)
1.22 -  done
1.23 -
1.24 -lemma pderiv_eq_0_iff: "pderiv p = 0 \<longleftrightarrow> degree p = 0"
1.25 -  apply (rule iffI)
1.26 -  apply (cases p, simp)
1.27 -  apply (simp add: expand_poly_eq coeff_pderiv del: of_nat_Suc)
1.28 -  apply (simp add: expand_poly_eq coeff_pderiv coeff_eq_0)
1.29 -  done
1.30 -
1.31 -lemma degree_pderiv: "degree (pderiv p) = degree p - 1"
1.32 -  apply (rule order_antisym [OF degree_le])
1.33 -  apply (simp add: coeff_pderiv coeff_eq_0)
1.34 -  apply (cases "degree p", simp)
1.35 -  apply (rule le_degree)
1.36 -  apply (simp add: coeff_pderiv del: of_nat_Suc)
1.37 -  apply (rule subst, assumption)
1.38 -  apply (rule leading_coeff_neq_0, clarsimp)
1.39 -  done
1.40 -
1.41 -lemma pderiv_singleton [simp]: "pderiv [:a:] = 0"
1.43 -
1.44 -lemma pderiv_add: "pderiv (p + q) = pderiv p + pderiv q"
1.45 -by (rule poly_ext, simp add: coeff_pderiv algebra_simps)
1.46 -
1.47 -lemma pderiv_minus: "pderiv (- p) = - pderiv p"
1.48 -by (rule poly_ext, simp add: coeff_pderiv)
1.49 -
1.50 -lemma pderiv_diff: "pderiv (p - q) = pderiv p - pderiv q"
1.51 -by (rule poly_ext, simp add: coeff_pderiv algebra_simps)
1.52 -
1.53 -lemma pderiv_smult: "pderiv (smult a p) = smult a (pderiv p)"
1.54 -by (rule poly_ext, simp add: coeff_pderiv algebra_simps)
1.55 -
1.56 -lemma pderiv_mult: "pderiv (p * q) = p * pderiv q + q * pderiv p"
1.57 -apply (induct p)
1.58 -apply simp
1.60 -done
1.61 -
1.62 -lemma pderiv_power_Suc:
1.63 -  "pderiv (p ^ Suc n) = smult (of_nat (Suc n)) (p ^ n) * pderiv p"
1.64 -apply (induct n)
1.65 -apply simp
1.66 -apply (subst power_Suc)
1.67 -apply (subst pderiv_mult)
1.68 -apply (erule ssubst)
1.70 -done
1.71 -
1.72 -lemma DERIV_cmult2: "DERIV f x :> D ==> DERIV (%x. (f x) * c :: real) x :> D * c"
1.73 -by (simp add: DERIV_cmult mult_commute [of _ c])
1.74 -
1.75 -lemma DERIV_pow2: "DERIV (%x. x ^ Suc n) x :> real (Suc n) * (x ^ n)"
1.76 -by (rule lemma_DERIV_subst, rule DERIV_pow, simp)
1.77 -declare DERIV_pow2 [simp] DERIV_pow [simp]
1.78 -
1.79 -lemma DERIV_add_const: "DERIV f x :> D ==>  DERIV (%x. a + f x :: 'a::real_normed_field) x :> D"
1.80 -by (rule lemma_DERIV_subst, rule DERIV_add, auto)
1.81 -
1.82 -lemma poly_DERIV[simp]: "DERIV (%x. poly p x) x :> poly (pderiv p) x"
1.83 -apply (induct p)
1.84 -apply simp
1.86 -apply (rule lemma_DERIV_subst)
1.87 -apply (rule DERIV_add DERIV_mult DERIV_const DERIV_ident | assumption)+
1.88 -apply simp
1.89 -done
1.90 -
1.91 -text{* Consequences of the derivative theorem above*}
1.92 -
1.93 -lemma poly_differentiable[simp]: "(%x. poly p x) differentiable (x::real)"
1.95 -apply (blast intro: poly_DERIV)
1.96 -done
1.97 -
1.98 -lemma poly_isCont[simp]: "isCont (%x. poly p x) (x::real)"
1.99 -by (rule poly_DERIV [THEN DERIV_isCont])
1.100 -
1.101 -lemma poly_IVT_pos: "[| a < b; poly p (a::real) < 0; 0 < poly p b |]
1.102 -      ==> \<exists>x. a < x & x < b & (poly p x = 0)"
1.103 -apply (cut_tac f = "%x. poly p x" and a = a and b = b and y = 0 in IVT_objl)
1.104 -apply (auto simp add: order_le_less)
1.105 -done
1.106 -
1.107 -lemma poly_IVT_neg: "[| (a::real) < b; 0 < poly p a; poly p b < 0 |]
1.108 -      ==> \<exists>x. a < x & x < b & (poly p x = 0)"
1.109 -by (insert poly_IVT_pos [where p = "- p" ]) simp
1.110 -
1.111 -lemma poly_MVT: "(a::real) < b ==>
1.112 -     \<exists>x. a < x & x < b & (poly p b - poly p a = (b - a) * poly (pderiv p) x)"
1.113 -apply (drule_tac f = "poly p" in MVT, auto)
1.114 -apply (rule_tac x = z in exI)
1.115 -apply (auto simp add: real_mult_left_cancel poly_DERIV [THEN DERIV_unique])
1.116 -done
1.117 -
1.118 -text{*Lemmas for Derivatives*}
1.119 -
1.120 -lemma order_unique_lemma:
1.121 -  fixes p :: "'a::idom poly"
1.122 -  assumes "[:-a, 1:] ^ n dvd p \<and> \<not> [:-a, 1:] ^ Suc n dvd p"
1.123 -  shows "n = order a p"
1.124 -unfolding Polynomial.order_def
1.125 -apply (rule Least_equality [symmetric])
1.126 -apply (rule assms [THEN conjunct2])
1.127 -apply (erule contrapos_np)
1.128 -apply (rule power_le_dvd)
1.129 -apply (rule assms [THEN conjunct1])
1.130 -apply simp
1.131 -done
1.132 -
1.133 -lemma lemma_order_pderiv1:
1.134 -  "pderiv ([:- a, 1:] ^ Suc n * q) = [:- a, 1:] ^ Suc n * pderiv q +
1.135 -    smult (of_nat (Suc n)) (q * [:- a, 1:] ^ n)"
1.136 -apply (simp only: pderiv_mult pderiv_power_Suc)
1.137 -apply (simp del: power_poly_Suc of_nat_Suc add: pderiv_pCons)
1.138 -done
1.139 -
1.141 -  fixes a b c :: "'a::comm_ring_1"
1.142 -  shows "a dvd b + c \<Longrightarrow> a dvd b \<Longrightarrow> a dvd c"
1.143 -  by (drule (1) Ring_and_Field.dvd_diff, simp)
1.144 -
1.145 -lemma lemma_order_pderiv [rule_format]:
1.146 -     "\<forall>p q a. 0 < n &
1.147 -       pderiv p \<noteq> 0 &
1.148 -       p = [:- a, 1:] ^ n * q & ~ [:- a, 1:] dvd q
1.149 -       --> n = Suc (order a (pderiv p))"
1.150 - apply (cases "n", safe, rename_tac n p q a)
1.151 - apply (rule order_unique_lemma)
1.152 - apply (rule conjI)
1.153 -  apply (subst lemma_order_pderiv1)
1.155 -   apply (rule dvd_mult2)
1.156 -   apply (rule le_imp_power_dvd, simp)
1.157 -  apply (rule dvd_smult)
1.158 -  apply (rule dvd_mult)
1.159 -  apply (rule dvd_refl)
1.160 - apply (subst lemma_order_pderiv1)
1.161 - apply (erule contrapos_nn) back
1.162 - apply (subgoal_tac "[:- a, 1:] ^ Suc n dvd q * [:- a, 1:] ^ n")
1.163 -  apply (simp del: mult_pCons_left)
1.165 -  apply (simp del: mult_pCons_left)
1.166 - apply (drule dvd_smult_cancel, simp del: of_nat_Suc)
1.167 - apply assumption
1.168 -done
1.169 -
1.170 -lemma order_decomp:
1.171 -     "p \<noteq> 0
1.172 -      ==> \<exists>q. p = [:-a, 1:] ^ (order a p) * q &
1.173 -                ~([:-a, 1:] dvd q)"
1.174 -apply (drule order [where a=a])
1.175 -apply (erule conjE)
1.176 -apply (erule dvdE)
1.177 -apply (rule exI)
1.178 -apply (rule conjI, assumption)
1.179 -apply (erule contrapos_nn)
1.180 -apply (erule ssubst) back
1.181 -apply (subst power_Suc2)
1.182 -apply (erule mult_dvd_mono [OF dvd_refl])
1.183 -done
1.184 -
1.185 -lemma order_pderiv: "[| pderiv p \<noteq> 0; order a p \<noteq> 0 |]
1.186 -      ==> (order a p = Suc (order a (pderiv p)))"
1.187 -apply (case_tac "p = 0", simp)
1.188 -apply (drule_tac a = a and p = p in order_decomp)
1.189 -using neq0_conv
1.190 -apply (blast intro: lemma_order_pderiv)
1.191 -done
1.192 -
1.193 -lemma order_mult: "p * q \<noteq> 0 \<Longrightarrow> order a (p * q) = order a p + order a q"
1.194 -proof -
1.195 -  def i \<equiv> "order a p"
1.196 -  def j \<equiv> "order a q"
1.197 -  def t \<equiv> "[:-a, 1:]"
1.198 -  have t_dvd_iff: "\<And>u. t dvd u \<longleftrightarrow> poly u a = 0"
1.199 -    unfolding t_def by (simp add: dvd_iff_poly_eq_0)
1.200 -  assume "p * q \<noteq> 0"
1.201 -  then show "order a (p * q) = i + j"
1.202 -    apply clarsimp
1.203 -    apply (drule order [where a=a and p=p, folded i_def t_def])
1.204 -    apply (drule order [where a=a and p=q, folded j_def t_def])
1.205 -    apply clarify
1.206 -    apply (rule order_unique_lemma [symmetric], fold t_def)
1.207 -    apply (erule dvdE)+
1.209 -    done
1.210 -qed
1.211 -
1.212 -text{*Now justify the standard squarefree decomposition, i.e. f / gcd(f,f'). *}
1.213 -
1.214 -lemma order_divides: "[:-a, 1:] ^ n dvd p \<longleftrightarrow> p = 0 \<or> n \<le> order a p"
1.215 -apply (cases "p = 0", auto)
1.216 -apply (drule order_2 [where a=a and p=p])
1.217 -apply (erule contrapos_np)
1.218 -apply (erule power_le_dvd)
1.219 -apply simp
1.220 -apply (erule power_le_dvd [OF order_1])
1.221 -done
1.222 -
1.223 -lemma poly_squarefree_decomp_order:
1.224 -  assumes "pderiv p \<noteq> 0"
1.225 -  and p: "p = q * d"
1.226 -  and p': "pderiv p = e * d"
1.227 -  and d: "d = r * p + s * pderiv p"
1.228 -  shows "order a q = (if order a p = 0 then 0 else 1)"
1.229 -proof (rule classical)
1.230 -  assume 1: "order a q \<noteq> (if order a p = 0 then 0 else 1)"
1.231 -  from `pderiv p \<noteq> 0` have "p \<noteq> 0" by auto
1.232 -  with p have "order a p = order a q + order a d"
1.233 -    by (simp add: order_mult)
1.234 -  with 1 have "order a p \<noteq> 0" by (auto split: if_splits)
1.235 -  have "order a (pderiv p) = order a e + order a d"
1.236 -    using `pderiv p \<noteq> 0` `pderiv p = e * d` by (simp add: order_mult)
1.237 -  have "order a p = Suc (order a (pderiv p))"
1.238 -    using `pderiv p \<noteq> 0` `order a p \<noteq> 0` by (rule order_pderiv)
1.239 -  have "d \<noteq> 0" using `p \<noteq> 0` `p = q * d` by simp
1.240 -  have "([:-a, 1:] ^ (order a (pderiv p))) dvd d"
1.241 -    apply (simp add: d)
1.243 -    apply (rule dvd_mult)
1.244 -    apply (simp add: order_divides `p \<noteq> 0`
1.245 -           `order a p = Suc (order a (pderiv p))`)
1.246 -    apply (rule dvd_mult)
1.247 -    apply (simp add: order_divides)
1.248 -    done
1.249 -  then have "order a (pderiv p) \<le> order a d"
1.250 -    using `d \<noteq> 0` by (simp add: order_divides)
1.251 -  show ?thesis
1.252 -    using `order a p = order a q + order a d`
1.253 -    using `order a (pderiv p) = order a e + order a d`
1.254 -    using `order a p = Suc (order a (pderiv p))`
1.255 -    using `order a (pderiv p) \<le> order a d`
1.256 -    by auto
1.257 -qed
1.258 -
1.259 -lemma poly_squarefree_decomp_order2: "[| pderiv p \<noteq> 0;
1.260 -         p = q * d;
1.261 -         pderiv p = e * d;
1.262 -         d = r * p + s * pderiv p
1.263 -      |] ==> \<forall>a. order a q = (if order a p = 0 then 0 else 1)"
1.264 -apply (blast intro: poly_squarefree_decomp_order)
1.265 -done
1.266 -
1.267 -lemma order_pderiv2: "[| pderiv p \<noteq> 0; order a p \<noteq> 0 |]
1.268 -      ==> (order a (pderiv p) = n) = (order a p = Suc n)"
1.269 -apply (auto dest: order_pderiv)
1.270 -done
1.271 -
1.272 -definition
1.273 -  rsquarefree :: "'a::idom poly => bool" where
1.274 -  "rsquarefree p = (p \<noteq> 0 & (\<forall>a. (order a p = 0) | (order a p = 1)))"
1.275 -
1.276 -lemma pderiv_iszero: "pderiv p = 0 \<Longrightarrow> \<exists>h. p = [:h:]"
1.278 -apply (case_tac p, auto split: if_splits)
1.279 -done
1.280 -
1.281 -lemma rsquarefree_roots:
1.282 -  "rsquarefree p = (\<forall>a. ~(poly p a = 0 & poly (pderiv p) a = 0))"
1.284 -apply (case_tac "p = 0", simp, simp)
1.285 -apply (case_tac "pderiv p = 0")
1.286 -apply simp
1.287 -apply (drule pderiv_iszero, clarify)
1.288 -apply simp
1.289 -apply (rule allI)
1.290 -apply (cut_tac p = "[:h:]" and a = a in order_root)
1.291 -apply simp
1.292 -apply (auto simp add: order_root order_pderiv2)
1.293 -apply (erule_tac x="a" in allE, simp)
1.294 -done
1.295 -
1.296 -lemma poly_squarefree_decomp:
1.297 -  assumes "pderiv p \<noteq> 0"
1.298 -    and "p = q * d"
1.299 -    and "pderiv p = e * d"
1.300 -    and "d = r * p + s * pderiv p"
1.301 -  shows "rsquarefree q & (\<forall>a. (poly q a = 0) = (poly p a = 0))"
1.302 -proof -
1.303 -  from `pderiv p \<noteq> 0` have "p \<noteq> 0" by auto
1.304 -  with `p = q * d` have "q \<noteq> 0" by simp
1.305 -  have "\<forall>a. order a q = (if order a p = 0 then 0 else 1)"
1.306 -    using assms by (rule poly_squarefree_decomp_order2)
1.307 -  with `p \<noteq> 0` `q \<noteq> 0` show ?thesis
1.308 -    by (simp add: rsquarefree_def order_root)
1.309 -qed
1.310 -
1.311 -
1.312  subsection {* Theorems about Limits *}
1.313
1.314  (* need to rename second isCont_inverse *)
```