src/HOL/Transcendental.thy
changeset 51527 bd62e7ff103b
parent 51482 80efd8c49f52
child 51641 cd05e9fcc63d
     1.1 --- a/src/HOL/Transcendental.thy	Tue Mar 26 12:20:58 2013 +0100
     1.2 +++ b/src/HOL/Transcendental.thy	Tue Mar 26 12:20:59 2013 +0100
     1.3 @@ -1,6 +1,8 @@
     1.4  (*  Title:      HOL/Transcendental.thy
     1.5      Author:     Jacques D. Fleuriot, University of Cambridge, University of Edinburgh
     1.6      Author:     Lawrence C Paulson
     1.7 +    Author:     Jeremy Avigad
     1.8 +
     1.9  *)
    1.10  
    1.11  header{*Power Series, Transcendental Functions etc.*}
    1.12 @@ -871,6 +873,8 @@
    1.13  apply (simp del: of_real_add)
    1.14  done
    1.15  
    1.16 +declare DERIV_exp[THEN DERIV_chain2, THEN DERIV_cong, DERIV_intros]
    1.17 +
    1.18  lemma isCont_exp: "isCont exp x"
    1.19    by (rule DERIV_exp [THEN DERIV_isCont])
    1.20  
    1.21 @@ -1200,6 +1204,8 @@
    1.22  lemma DERIV_ln_divide: "0 < x ==> DERIV ln x :> 1 / x"
    1.23    by (rule DERIV_ln[THEN DERIV_cong], simp, simp add: divide_inverse)
    1.24  
    1.25 +declare DERIV_ln_divide[THEN DERIV_chain2, THEN DERIV_cong, DERIV_intros]
    1.26 +
    1.27  lemma ln_series: assumes "0 < x" and "x < 2"
    1.28    shows "ln x = (\<Sum> n. (-1)^n * (1 / real (n + 1)) * (x - 1)^(Suc n))" (is "ln x = suminf (?f (x - 1))")
    1.29  proof -
    1.30 @@ -1337,6 +1343,223 @@
    1.31    apply auto
    1.32  done
    1.33  
    1.34 +lemma ln_one_plus_pos_lower_bound: "0 <= x ==> x <= 1 ==> x - x^2 <= ln (1 + x)"
    1.35 +proof -
    1.36 +  assume a: "0 <= x" and b: "x <= 1"
    1.37 +  have "exp (x - x^2) = exp x / exp (x^2)"
    1.38 +    by (rule exp_diff)
    1.39 +  also have "... <= (1 + x + x^2) / exp (x ^2)"
    1.40 +    apply (rule divide_right_mono) 
    1.41 +    apply (rule exp_bound)
    1.42 +    apply (rule a, rule b)
    1.43 +    apply simp
    1.44 +    done
    1.45 +  also have "... <= (1 + x + x^2) / (1 + x^2)"
    1.46 +    apply (rule divide_left_mono)
    1.47 +    apply (simp add: exp_ge_add_one_self_aux)
    1.48 +    apply (simp add: a)
    1.49 +    apply (simp add: mult_pos_pos add_pos_nonneg)
    1.50 +    done
    1.51 +  also from a have "... <= 1 + x"
    1.52 +    by (simp add: field_simps add_strict_increasing zero_le_mult_iff)
    1.53 +  finally have "exp (x - x^2) <= 1 + x" .
    1.54 +  also have "... = exp (ln (1 + x))"
    1.55 +  proof -
    1.56 +    from a have "0 < 1 + x" by auto
    1.57 +    thus ?thesis
    1.58 +      by (auto simp only: exp_ln_iff [THEN sym])
    1.59 +  qed
    1.60 +  finally have "exp (x - x ^ 2) <= exp (ln (1 + x))" .
    1.61 +  thus ?thesis by (auto simp only: exp_le_cancel_iff)
    1.62 +qed
    1.63 +
    1.64 +lemma aux5: "x < 1 ==> ln(1 - x) = - ln(1 + x / (1 - x))"
    1.65 +proof -
    1.66 +  assume a: "x < 1"
    1.67 +  have "ln(1 - x) = - ln(1 / (1 - x))"
    1.68 +  proof -
    1.69 +    have "ln(1 - x) = - (- ln (1 - x))"
    1.70 +      by auto
    1.71 +    also have "- ln(1 - x) = ln 1 - ln(1 - x)"
    1.72 +      by simp
    1.73 +    also have "... = ln(1 / (1 - x))"
    1.74 +      apply (rule ln_div [THEN sym])
    1.75 +      by (insert a, auto)
    1.76 +    finally show ?thesis .
    1.77 +  qed
    1.78 +  also have " 1 / (1 - x) = 1 + x / (1 - x)" using a by(simp add:field_simps)
    1.79 +  finally show ?thesis .
    1.80 +qed
    1.81 +
    1.82 +lemma ln_one_minus_pos_lower_bound: "0 <= x ==> x <= (1 / 2) ==> 
    1.83 +    - x - 2 * x^2 <= ln (1 - x)"
    1.84 +proof -
    1.85 +  assume a: "0 <= x" and b: "x <= (1 / 2)"
    1.86 +  from b have c: "x < 1"
    1.87 +    by auto
    1.88 +  then have "ln (1 - x) = - ln (1 + x / (1 - x))"
    1.89 +    by (rule aux5)
    1.90 +  also have "- (x / (1 - x)) <= ..."
    1.91 +  proof - 
    1.92 +    have "ln (1 + x / (1 - x)) <= x / (1 - x)"
    1.93 +      apply (rule ln_add_one_self_le_self)
    1.94 +      apply (rule divide_nonneg_pos)
    1.95 +      by (insert a c, auto) 
    1.96 +    thus ?thesis
    1.97 +      by auto
    1.98 +  qed
    1.99 +  also have "- (x / (1 - x)) = -x / (1 - x)"
   1.100 +    by auto
   1.101 +  finally have d: "- x / (1 - x) <= ln (1 - x)" .
   1.102 +  have "0 < 1 - x" using a b by simp
   1.103 +  hence e: "-x - 2 * x^2 <= - x / (1 - x)"
   1.104 +    using mult_right_le_one_le[of "x*x" "2*x"] a b
   1.105 +    by (simp add:field_simps power2_eq_square)
   1.106 +  from e d show "- x - 2 * x^2 <= ln (1 - x)"
   1.107 +    by (rule order_trans)
   1.108 +qed
   1.109 +
   1.110 +lemma ln_add_one_self_le_self2: "-1 < x ==> ln(1 + x) <= x"
   1.111 +  apply (subgoal_tac "ln (1 + x) \<le> ln (exp x)", simp)
   1.112 +  apply (subst ln_le_cancel_iff)
   1.113 +  apply auto
   1.114 +done
   1.115 +
   1.116 +lemma abs_ln_one_plus_x_minus_x_bound_nonneg:
   1.117 +    "0 <= x ==> x <= 1 ==> abs(ln (1 + x) - x) <= x^2"
   1.118 +proof -
   1.119 +  assume x: "0 <= x"
   1.120 +  assume x1: "x <= 1"
   1.121 +  from x have "ln (1 + x) <= x"
   1.122 +    by (rule ln_add_one_self_le_self)
   1.123 +  then have "ln (1 + x) - x <= 0" 
   1.124 +    by simp
   1.125 +  then have "abs(ln(1 + x) - x) = - (ln(1 + x) - x)"
   1.126 +    by (rule abs_of_nonpos)
   1.127 +  also have "... = x - ln (1 + x)" 
   1.128 +    by simp
   1.129 +  also have "... <= x^2"
   1.130 +  proof -
   1.131 +    from x x1 have "x - x^2 <= ln (1 + x)"
   1.132 +      by (intro ln_one_plus_pos_lower_bound)
   1.133 +    thus ?thesis
   1.134 +      by simp
   1.135 +  qed
   1.136 +  finally show ?thesis .
   1.137 +qed
   1.138 +
   1.139 +lemma abs_ln_one_plus_x_minus_x_bound_nonpos:
   1.140 +    "-(1 / 2) <= x ==> x <= 0 ==> abs(ln (1 + x) - x) <= 2 * x^2"
   1.141 +proof -
   1.142 +  assume a: "-(1 / 2) <= x"
   1.143 +  assume b: "x <= 0"
   1.144 +  have "abs(ln (1 + x) - x) = x - ln(1 - (-x))" 
   1.145 +    apply (subst abs_of_nonpos)
   1.146 +    apply simp
   1.147 +    apply (rule ln_add_one_self_le_self2)
   1.148 +    using a apply auto
   1.149 +    done
   1.150 +  also have "... <= 2 * x^2"
   1.151 +    apply (subgoal_tac "- (-x) - 2 * (-x)^2 <= ln (1 - (-x))")
   1.152 +    apply (simp add: algebra_simps)
   1.153 +    apply (rule ln_one_minus_pos_lower_bound)
   1.154 +    using a b apply auto
   1.155 +    done
   1.156 +  finally show ?thesis .
   1.157 +qed
   1.158 +
   1.159 +lemma abs_ln_one_plus_x_minus_x_bound:
   1.160 +    "abs x <= 1 / 2 ==> abs(ln (1 + x) - x) <= 2 * x^2"
   1.161 +  apply (case_tac "0 <= x")
   1.162 +  apply (rule order_trans)
   1.163 +  apply (rule abs_ln_one_plus_x_minus_x_bound_nonneg)
   1.164 +  apply auto
   1.165 +  apply (rule abs_ln_one_plus_x_minus_x_bound_nonpos)
   1.166 +  apply auto
   1.167 +done
   1.168 +
   1.169 +lemma ln_x_over_x_mono: "exp 1 <= x ==> x <= y ==> (ln y / y) <= (ln x / x)"  
   1.170 +proof -
   1.171 +  assume x: "exp 1 <= x" "x <= y"
   1.172 +  moreover have "0 < exp (1::real)" by simp
   1.173 +  ultimately have a: "0 < x" and b: "0 < y"
   1.174 +    by (fast intro: less_le_trans order_trans)+
   1.175 +  have "x * ln y - x * ln x = x * (ln y - ln x)"
   1.176 +    by (simp add: algebra_simps)
   1.177 +  also have "... = x * ln(y / x)"
   1.178 +    by (simp only: ln_div a b)
   1.179 +  also have "y / x = (x + (y - x)) / x"
   1.180 +    by simp
   1.181 +  also have "... = 1 + (y - x) / x"
   1.182 +    using x a by (simp add: field_simps)
   1.183 +  also have "x * ln(1 + (y - x) / x) <= x * ((y - x) / x)"
   1.184 +    apply (rule mult_left_mono)
   1.185 +    apply (rule ln_add_one_self_le_self)
   1.186 +    apply (rule divide_nonneg_pos)
   1.187 +    using x a apply simp_all
   1.188 +    done
   1.189 +  also have "... = y - x" using a by simp
   1.190 +  also have "... = (y - x) * ln (exp 1)" by simp
   1.191 +  also have "... <= (y - x) * ln x"
   1.192 +    apply (rule mult_left_mono)
   1.193 +    apply (subst ln_le_cancel_iff)
   1.194 +    apply fact
   1.195 +    apply (rule a)
   1.196 +    apply (rule x)
   1.197 +    using x apply simp
   1.198 +    done
   1.199 +  also have "... = y * ln x - x * ln x"
   1.200 +    by (rule left_diff_distrib)
   1.201 +  finally have "x * ln y <= y * ln x"
   1.202 +    by arith
   1.203 +  then have "ln y <= (y * ln x) / x" using a by (simp add: field_simps)
   1.204 +  also have "... = y * (ln x / x)" by simp
   1.205 +  finally show ?thesis using b by (simp add: field_simps)
   1.206 +qed
   1.207 +
   1.208 +lemma ln_le_minus_one:
   1.209 +  "0 < x \<Longrightarrow> ln x \<le> x - 1"
   1.210 +  using exp_ge_add_one_self[of "ln x"] by simp
   1.211 +
   1.212 +lemma ln_eq_minus_one:
   1.213 +  assumes "0 < x" "ln x = x - 1" shows "x = 1"
   1.214 +proof -
   1.215 +  let "?l y" = "ln y - y + 1"
   1.216 +  have D: "\<And>x. 0 < x \<Longrightarrow> DERIV ?l x :> (1 / x - 1)"
   1.217 +    by (auto intro!: DERIV_intros)
   1.218 +
   1.219 +  show ?thesis
   1.220 +  proof (cases rule: linorder_cases)
   1.221 +    assume "x < 1"
   1.222 +    from dense[OF `x < 1`] obtain a where "x < a" "a < 1" by blast
   1.223 +    from `x < a` have "?l x < ?l a"
   1.224 +    proof (rule DERIV_pos_imp_increasing, safe)
   1.225 +      fix y assume "x \<le> y" "y \<le> a"
   1.226 +      with `0 < x` `a < 1` have "0 < 1 / y - 1" "0 < y"
   1.227 +        by (auto simp: field_simps)
   1.228 +      with D show "\<exists>z. DERIV ?l y :> z \<and> 0 < z"
   1.229 +        by auto
   1.230 +    qed
   1.231 +    also have "\<dots> \<le> 0"
   1.232 +      using ln_le_minus_one `0 < x` `x < a` by (auto simp: field_simps)
   1.233 +    finally show "x = 1" using assms by auto
   1.234 +  next
   1.235 +    assume "1 < x"
   1.236 +    from dense[OF `1 < x`] obtain a where "1 < a" "a < x" by blast
   1.237 +    from `a < x` have "?l x < ?l a"
   1.238 +    proof (rule DERIV_neg_imp_decreasing, safe)
   1.239 +      fix y assume "a \<le> y" "y \<le> x"
   1.240 +      with `1 < a` have "1 / y - 1 < 0" "0 < y"
   1.241 +        by (auto simp: field_simps)
   1.242 +      with D show "\<exists>z. DERIV ?l y :> z \<and> z < 0"
   1.243 +        by blast
   1.244 +    qed
   1.245 +    also have "\<dots> \<le> 0"
   1.246 +      using ln_le_minus_one `1 < a` by (auto simp: field_simps)
   1.247 +    finally show "x = 1" using assms by auto
   1.248 +  qed simp
   1.249 +qed
   1.250 +
   1.251  lemma exp_at_bot: "(exp ---> (0::real)) at_bot"
   1.252    unfolding tendsto_Zfun_iff
   1.253  proof (rule ZfunI, simp add: eventually_at_bot_dense)
   1.254 @@ -1383,6 +1606,415 @@
   1.255    qed (rule exp_at_top)
   1.256  qed
   1.257  
   1.258 +
   1.259 +definition
   1.260 +  powr  :: "[real,real] => real"     (infixr "powr" 80) where
   1.261 +    --{*exponentation with real exponent*}
   1.262 +  "x powr a = exp(a * ln x)"
   1.263 +
   1.264 +definition
   1.265 +  log :: "[real,real] => real" where
   1.266 +    --{*logarithm of @{term x} to base @{term a}*}
   1.267 +  "log a x = ln x / ln a"
   1.268 +
   1.269 +
   1.270 +lemma tendsto_log [tendsto_intros]:
   1.271 +  "\<lbrakk>(f ---> a) F; (g ---> b) F; 0 < a; a \<noteq> 1; 0 < b\<rbrakk> \<Longrightarrow> ((\<lambda>x. log (f x) (g x)) ---> log a b) F"
   1.272 +  unfolding log_def by (intro tendsto_intros) auto
   1.273 +
   1.274 +lemma continuous_log:
   1.275 +  assumes "continuous F f" and "continuous F g" and "0 < f (Lim F (\<lambda>x. x))" and "f (Lim F (\<lambda>x. x)) \<noteq> 1" and "0 < g (Lim F (\<lambda>x. x))"
   1.276 +  shows "continuous F (\<lambda>x. log (f x) (g x))"
   1.277 +  using assms unfolding continuous_def by (rule tendsto_log)
   1.278 +
   1.279 +lemma continuous_at_within_log[continuous_intros]:
   1.280 +  assumes "continuous (at a within s) f" "continuous (at a within s) g" and "0 < f a" and "f a \<noteq> 1" and "0 < g a"
   1.281 +  shows "continuous (at a within s) (\<lambda>x. log (f x) (g x))"
   1.282 +  using assms unfolding continuous_within by (rule tendsto_log)
   1.283 +
   1.284 +lemma isCont_log[continuous_intros, simp]:
   1.285 +  assumes "isCont f a" "isCont g a" "0 < f a" "f a \<noteq> 1" "0 < g a"
   1.286 +  shows "isCont (\<lambda>x. log (f x) (g x)) a"
   1.287 +  using assms unfolding continuous_at by (rule tendsto_log)
   1.288 +
   1.289 +lemma continuous_on_log[continuous_on_intros]:
   1.290 +  assumes "continuous_on s f" "continuous_on s g" and "\<forall>x\<in>s. 0 < f x" "\<forall>x\<in>s. f x \<noteq> 1" "\<forall>x\<in>s. 0 < g x"
   1.291 +  shows "continuous_on s (\<lambda>x. log (f x) (g x))"
   1.292 +  using assms unfolding continuous_on_def by (fast intro: tendsto_log)
   1.293 +
   1.294 +lemma powr_one_eq_one [simp]: "1 powr a = 1"
   1.295 +by (simp add: powr_def)
   1.296 +
   1.297 +lemma powr_zero_eq_one [simp]: "x powr 0 = 1"
   1.298 +by (simp add: powr_def)
   1.299 +
   1.300 +lemma powr_one_gt_zero_iff [simp]: "(x powr 1 = x) = (0 < x)"
   1.301 +by (simp add: powr_def)
   1.302 +declare powr_one_gt_zero_iff [THEN iffD2, simp]
   1.303 +
   1.304 +lemma powr_mult: 
   1.305 +      "[| 0 < x; 0 < y |] ==> (x * y) powr a = (x powr a) * (y powr a)"
   1.306 +by (simp add: powr_def exp_add [symmetric] ln_mult distrib_left)
   1.307 +
   1.308 +lemma powr_gt_zero [simp]: "0 < x powr a"
   1.309 +by (simp add: powr_def)
   1.310 +
   1.311 +lemma powr_ge_pzero [simp]: "0 <= x powr y"
   1.312 +by (rule order_less_imp_le, rule powr_gt_zero)
   1.313 +
   1.314 +lemma powr_not_zero [simp]: "x powr a \<noteq> 0"
   1.315 +by (simp add: powr_def)
   1.316 +
   1.317 +lemma powr_divide:
   1.318 +     "[| 0 < x; 0 < y |] ==> (x / y) powr a = (x powr a)/(y powr a)"
   1.319 +apply (simp add: divide_inverse positive_imp_inverse_positive powr_mult)
   1.320 +apply (simp add: powr_def exp_minus [symmetric] exp_add [symmetric] ln_inverse)
   1.321 +done
   1.322 +
   1.323 +lemma powr_divide2: "x powr a / x powr b = x powr (a - b)"
   1.324 +  apply (simp add: powr_def)
   1.325 +  apply (subst exp_diff [THEN sym])
   1.326 +  apply (simp add: left_diff_distrib)
   1.327 +done
   1.328 +
   1.329 +lemma powr_add: "x powr (a + b) = (x powr a) * (x powr b)"
   1.330 +by (simp add: powr_def exp_add [symmetric] distrib_right)
   1.331 +
   1.332 +lemma powr_mult_base:
   1.333 +  "0 < x \<Longrightarrow>x * x powr y = x powr (1 + y)"
   1.334 +using assms by (auto simp: powr_add)
   1.335 +
   1.336 +lemma powr_powr: "(x powr a) powr b = x powr (a * b)"
   1.337 +by (simp add: powr_def)
   1.338 +
   1.339 +lemma powr_powr_swap: "(x powr a) powr b = (x powr b) powr a"
   1.340 +by (simp add: powr_powr mult_commute)
   1.341 +
   1.342 +lemma powr_minus: "x powr (-a) = inverse (x powr a)"
   1.343 +by (simp add: powr_def exp_minus [symmetric])
   1.344 +
   1.345 +lemma powr_minus_divide: "x powr (-a) = 1/(x powr a)"
   1.346 +by (simp add: divide_inverse powr_minus)
   1.347 +
   1.348 +lemma powr_less_mono: "[| a < b; 1 < x |] ==> x powr a < x powr b"
   1.349 +by (simp add: powr_def)
   1.350 +
   1.351 +lemma powr_less_cancel: "[| x powr a < x powr b; 1 < x |] ==> a < b"
   1.352 +by (simp add: powr_def)
   1.353 +
   1.354 +lemma powr_less_cancel_iff [simp]: "1 < x ==> (x powr a < x powr b) = (a < b)"
   1.355 +by (blast intro: powr_less_cancel powr_less_mono)
   1.356 +
   1.357 +lemma powr_le_cancel_iff [simp]: "1 < x ==> (x powr a \<le> x powr b) = (a \<le> b)"
   1.358 +by (simp add: linorder_not_less [symmetric])
   1.359 +
   1.360 +lemma log_ln: "ln x = log (exp(1)) x"
   1.361 +by (simp add: log_def)
   1.362 +
   1.363 +lemma DERIV_log: assumes "x > 0" shows "DERIV (\<lambda>y. log b y) x :> 1 / (ln b * x)"
   1.364 +proof -
   1.365 +  def lb \<equiv> "1 / ln b"
   1.366 +  moreover have "DERIV (\<lambda>y. lb * ln y) x :> lb / x"
   1.367 +    using `x > 0` by (auto intro!: DERIV_intros)
   1.368 +  ultimately show ?thesis
   1.369 +    by (simp add: log_def)
   1.370 +qed
   1.371 +
   1.372 +lemmas DERIV_log[THEN DERIV_chain2, THEN DERIV_cong, DERIV_intros]
   1.373 +
   1.374 +lemma powr_log_cancel [simp]:
   1.375 +     "[| 0 < a; a \<noteq> 1; 0 < x |] ==> a powr (log a x) = x"
   1.376 +by (simp add: powr_def log_def)
   1.377 +
   1.378 +lemma log_powr_cancel [simp]: "[| 0 < a; a \<noteq> 1 |] ==> log a (a powr y) = y"
   1.379 +by (simp add: log_def powr_def)
   1.380 +
   1.381 +lemma log_mult: 
   1.382 +     "[| 0 < a; a \<noteq> 1; 0 < x; 0 < y |]  
   1.383 +      ==> log a (x * y) = log a x + log a y"
   1.384 +by (simp add: log_def ln_mult divide_inverse distrib_right)
   1.385 +
   1.386 +lemma log_eq_div_ln_mult_log: 
   1.387 +     "[| 0 < a; a \<noteq> 1; 0 < b; b \<noteq> 1; 0 < x |]  
   1.388 +      ==> log a x = (ln b/ln a) * log b x"
   1.389 +by (simp add: log_def divide_inverse)
   1.390 +
   1.391 +text{*Base 10 logarithms*}
   1.392 +lemma log_base_10_eq1: "0 < x ==> log 10 x = (ln (exp 1) / ln 10) * ln x"
   1.393 +by (simp add: log_def)
   1.394 +
   1.395 +lemma log_base_10_eq2: "0 < x ==> log 10 x = (log 10 (exp 1)) * ln x"
   1.396 +by (simp add: log_def)
   1.397 +
   1.398 +lemma log_one [simp]: "log a 1 = 0"
   1.399 +by (simp add: log_def)
   1.400 +
   1.401 +lemma log_eq_one [simp]: "[| 0 < a; a \<noteq> 1 |] ==> log a a = 1"
   1.402 +by (simp add: log_def)
   1.403 +
   1.404 +lemma log_inverse:
   1.405 +     "[| 0 < a; a \<noteq> 1; 0 < x |] ==> log a (inverse x) = - log a x"
   1.406 +apply (rule_tac a1 = "log a x" in add_left_cancel [THEN iffD1])
   1.407 +apply (simp add: log_mult [symmetric])
   1.408 +done
   1.409 +
   1.410 +lemma log_divide:
   1.411 +     "[|0 < a; a \<noteq> 1; 0 < x; 0 < y|] ==> log a (x/y) = log a x - log a y"
   1.412 +by (simp add: log_mult divide_inverse log_inverse)
   1.413 +
   1.414 +lemma log_less_cancel_iff [simp]:
   1.415 +     "[| 1 < a; 0 < x; 0 < y |] ==> (log a x < log a y) = (x < y)"
   1.416 +apply safe
   1.417 +apply (rule_tac [2] powr_less_cancel)
   1.418 +apply (drule_tac a = "log a x" in powr_less_mono, auto)
   1.419 +done
   1.420 +
   1.421 +lemma log_inj: assumes "1 < b" shows "inj_on (log b) {0 <..}"
   1.422 +proof (rule inj_onI, simp)
   1.423 +  fix x y assume pos: "0 < x" "0 < y" and *: "log b x = log b y"
   1.424 +  show "x = y"
   1.425 +  proof (cases rule: linorder_cases)
   1.426 +    assume "x < y" hence "log b x < log b y"
   1.427 +      using log_less_cancel_iff[OF `1 < b`] pos by simp
   1.428 +    thus ?thesis using * by simp
   1.429 +  next
   1.430 +    assume "y < x" hence "log b y < log b x"
   1.431 +      using log_less_cancel_iff[OF `1 < b`] pos by simp
   1.432 +    thus ?thesis using * by simp
   1.433 +  qed simp
   1.434 +qed
   1.435 +
   1.436 +lemma log_le_cancel_iff [simp]:
   1.437 +     "[| 1 < a; 0 < x; 0 < y |] ==> (log a x \<le> log a y) = (x \<le> y)"
   1.438 +by (simp add: linorder_not_less [symmetric])
   1.439 +
   1.440 +lemma zero_less_log_cancel_iff[simp]: "1 < a \<Longrightarrow> 0 < x \<Longrightarrow> 0 < log a x \<longleftrightarrow> 1 < x"
   1.441 +  using log_less_cancel_iff[of a 1 x] by simp
   1.442 +
   1.443 +lemma zero_le_log_cancel_iff[simp]: "1 < a \<Longrightarrow> 0 < x \<Longrightarrow> 0 \<le> log a x \<longleftrightarrow> 1 \<le> x"
   1.444 +  using log_le_cancel_iff[of a 1 x] by simp
   1.445 +
   1.446 +lemma log_less_zero_cancel_iff[simp]: "1 < a \<Longrightarrow> 0 < x \<Longrightarrow> log a x < 0 \<longleftrightarrow> x < 1"
   1.447 +  using log_less_cancel_iff[of a x 1] by simp
   1.448 +
   1.449 +lemma log_le_zero_cancel_iff[simp]: "1 < a \<Longrightarrow> 0 < x \<Longrightarrow> log a x \<le> 0 \<longleftrightarrow> x \<le> 1"
   1.450 +  using log_le_cancel_iff[of a x 1] by simp
   1.451 +
   1.452 +lemma one_less_log_cancel_iff[simp]: "1 < a \<Longrightarrow> 0 < x \<Longrightarrow> 1 < log a x \<longleftrightarrow> a < x"
   1.453 +  using log_less_cancel_iff[of a a x] by simp
   1.454 +
   1.455 +lemma one_le_log_cancel_iff[simp]: "1 < a \<Longrightarrow> 0 < x \<Longrightarrow> 1 \<le> log a x \<longleftrightarrow> a \<le> x"
   1.456 +  using log_le_cancel_iff[of a a x] by simp
   1.457 +
   1.458 +lemma log_less_one_cancel_iff[simp]: "1 < a \<Longrightarrow> 0 < x \<Longrightarrow> log a x < 1 \<longleftrightarrow> x < a"
   1.459 +  using log_less_cancel_iff[of a x a] by simp
   1.460 +
   1.461 +lemma log_le_one_cancel_iff[simp]: "1 < a \<Longrightarrow> 0 < x \<Longrightarrow> log a x \<le> 1 \<longleftrightarrow> x \<le> a"
   1.462 +  using log_le_cancel_iff[of a x a] by simp
   1.463 +
   1.464 +lemma powr_realpow: "0 < x ==> x powr (real n) = x^n"
   1.465 +  apply (induct n, simp)
   1.466 +  apply (subgoal_tac "real(Suc n) = real n + 1")
   1.467 +  apply (erule ssubst)
   1.468 +  apply (subst powr_add, simp, simp)
   1.469 +done
   1.470 +
   1.471 +lemma powr_realpow2: "0 <= x ==> 0 < n ==> x^n = (if (x = 0) then 0 else x powr (real n))"
   1.472 +  apply (case_tac "x = 0", simp, simp)
   1.473 +  apply (rule powr_realpow [THEN sym], simp)
   1.474 +done
   1.475 +
   1.476 +lemma powr_int:
   1.477 +  assumes "x > 0"
   1.478 +  shows "x powr i = (if i \<ge> 0 then x ^ nat i else 1 / x ^ nat (-i))"
   1.479 +proof cases
   1.480 +  assume "i < 0"
   1.481 +  have r: "x powr i = 1 / x powr (-i)" by (simp add: powr_minus field_simps)
   1.482 +  show ?thesis using `i < 0` `x > 0` by (simp add: r field_simps powr_realpow[symmetric])
   1.483 +qed (simp add: assms powr_realpow[symmetric])
   1.484 +
   1.485 +lemma powr_numeral: "0 < x \<Longrightarrow> x powr numeral n = x^numeral n"
   1.486 +  using powr_realpow[of x "numeral n"] by simp
   1.487 +
   1.488 +lemma powr_neg_numeral: "0 < x \<Longrightarrow> x powr neg_numeral n = 1 / x^numeral n"
   1.489 +  using powr_int[of x "neg_numeral n"] by simp
   1.490 +
   1.491 +lemma root_powr_inverse:
   1.492 +  "0 < n \<Longrightarrow> 0 < x \<Longrightarrow> root n x = x powr (1/n)"
   1.493 +  by (rule real_root_pos_unique) (auto simp: powr_realpow[symmetric] powr_powr)
   1.494 +
   1.495 +lemma ln_powr: "0 < x ==> 0 < y ==> ln(x powr y) = y * ln x"
   1.496 +by (unfold powr_def, simp)
   1.497 +
   1.498 +lemma log_powr: "0 < x ==> 0 \<le> y ==> log b (x powr y) = y * log b x"
   1.499 +  apply (case_tac "y = 0")
   1.500 +  apply force
   1.501 +  apply (auto simp add: log_def ln_powr field_simps)
   1.502 +done
   1.503 +
   1.504 +lemma log_nat_power: "0 < x ==> log b (x^n) = real n * log b x"
   1.505 +  apply (subst powr_realpow [symmetric])
   1.506 +  apply (auto simp add: log_powr)
   1.507 +done
   1.508 +
   1.509 +lemma ln_bound: "1 <= x ==> ln x <= x"
   1.510 +  apply (subgoal_tac "ln(1 + (x - 1)) <= x - 1")
   1.511 +  apply simp
   1.512 +  apply (rule ln_add_one_self_le_self, simp)
   1.513 +done
   1.514 +
   1.515 +lemma powr_mono: "a <= b ==> 1 <= x ==> x powr a <= x powr b"
   1.516 +  apply (case_tac "x = 1", simp)
   1.517 +  apply (case_tac "a = b", simp)
   1.518 +  apply (rule order_less_imp_le)
   1.519 +  apply (rule powr_less_mono, auto)
   1.520 +done
   1.521 +
   1.522 +lemma ge_one_powr_ge_zero: "1 <= x ==> 0 <= a ==> 1 <= x powr a"
   1.523 +  apply (subst powr_zero_eq_one [THEN sym])
   1.524 +  apply (rule powr_mono, assumption+)
   1.525 +done
   1.526 +
   1.527 +lemma powr_less_mono2: "0 < a ==> 0 < x ==> x < y ==> x powr a <
   1.528 +    y powr a"
   1.529 +  apply (unfold powr_def)
   1.530 +  apply (rule exp_less_mono)
   1.531 +  apply (rule mult_strict_left_mono)
   1.532 +  apply (subst ln_less_cancel_iff, assumption)
   1.533 +  apply (rule order_less_trans)
   1.534 +  prefer 2
   1.535 +  apply assumption+
   1.536 +done
   1.537 +
   1.538 +lemma powr_less_mono2_neg: "a < 0 ==> 0 < x ==> x < y ==> y powr a <
   1.539 +    x powr a"
   1.540 +  apply (unfold powr_def)
   1.541 +  apply (rule exp_less_mono)
   1.542 +  apply (rule mult_strict_left_mono_neg)
   1.543 +  apply (subst ln_less_cancel_iff)
   1.544 +  apply assumption
   1.545 +  apply (rule order_less_trans)
   1.546 +  prefer 2
   1.547 +  apply assumption+
   1.548 +done
   1.549 +
   1.550 +lemma powr_mono2: "0 <= a ==> 0 < x ==> x <= y ==> x powr a <= y powr a"
   1.551 +  apply (case_tac "a = 0", simp)
   1.552 +  apply (case_tac "x = y", simp)
   1.553 +  apply (rule order_less_imp_le)
   1.554 +  apply (rule powr_less_mono2, auto)
   1.555 +done
   1.556 +
   1.557 +lemma powr_inj:
   1.558 +  "0 < a \<Longrightarrow> a \<noteq> 1 \<Longrightarrow> a powr x = a powr y \<longleftrightarrow> x = y"
   1.559 +  unfolding powr_def exp_inj_iff by simp
   1.560 +
   1.561 +lemma ln_powr_bound: "1 <= x ==> 0 < a ==> ln x <= (x powr a) / a"
   1.562 +  apply (rule mult_imp_le_div_pos)
   1.563 +  apply (assumption)
   1.564 +  apply (subst mult_commute)
   1.565 +  apply (subst ln_powr [THEN sym])
   1.566 +  apply auto
   1.567 +  apply (rule ln_bound)
   1.568 +  apply (erule ge_one_powr_ge_zero)
   1.569 +  apply (erule order_less_imp_le)
   1.570 +done
   1.571 +
   1.572 +lemma ln_powr_bound2:
   1.573 +  assumes "1 < x" and "0 < a"
   1.574 +  shows "(ln x) powr a <= (a powr a) * x"
   1.575 +proof -
   1.576 +  from assms have "ln x <= (x powr (1 / a)) / (1 / a)"
   1.577 +    apply (intro ln_powr_bound)
   1.578 +    apply (erule order_less_imp_le)
   1.579 +    apply (rule divide_pos_pos)
   1.580 +    apply simp_all
   1.581 +    done
   1.582 +  also have "... = a * (x powr (1 / a))"
   1.583 +    by simp
   1.584 +  finally have "(ln x) powr a <= (a * (x powr (1 / a))) powr a"
   1.585 +    apply (intro powr_mono2)
   1.586 +    apply (rule order_less_imp_le, rule assms)
   1.587 +    apply (rule ln_gt_zero)
   1.588 +    apply (rule assms)
   1.589 +    apply assumption
   1.590 +    done
   1.591 +  also have "... = (a powr a) * ((x powr (1 / a)) powr a)"
   1.592 +    apply (rule powr_mult)
   1.593 +    apply (rule assms)
   1.594 +    apply (rule powr_gt_zero)
   1.595 +    done
   1.596 +  also have "(x powr (1 / a)) powr a = x powr ((1 / a) * a)"
   1.597 +    by (rule powr_powr)
   1.598 +  also have "... = x"
   1.599 +    apply simp
   1.600 +    apply (subgoal_tac "a ~= 0")
   1.601 +    using assms apply auto
   1.602 +    done
   1.603 +  finally show ?thesis .
   1.604 +qed
   1.605 +
   1.606 +lemma tendsto_powr [tendsto_intros]:
   1.607 +  "\<lbrakk>(f ---> a) F; (g ---> b) F; 0 < a\<rbrakk> \<Longrightarrow> ((\<lambda>x. f x powr g x) ---> a powr b) F"
   1.608 +  unfolding powr_def by (intro tendsto_intros)
   1.609 +
   1.610 +lemma continuous_powr:
   1.611 +  assumes "continuous F f" and "continuous F g" and "0 < f (Lim F (\<lambda>x. x))"
   1.612 +  shows "continuous F (\<lambda>x. (f x) powr (g x))"
   1.613 +  using assms unfolding continuous_def by (rule tendsto_powr)
   1.614 +
   1.615 +lemma continuous_at_within_powr[continuous_intros]:
   1.616 +  assumes "continuous (at a within s) f" "continuous (at a within s) g" and "0 < f a"
   1.617 +  shows "continuous (at a within s) (\<lambda>x. (f x) powr (g x))"
   1.618 +  using assms unfolding continuous_within by (rule tendsto_powr)
   1.619 +
   1.620 +lemma isCont_powr[continuous_intros, simp]:
   1.621 +  assumes "isCont f a" "isCont g a" "0 < f a"
   1.622 +  shows "isCont (\<lambda>x. (f x) powr g x) a"
   1.623 +  using assms unfolding continuous_at by (rule tendsto_powr)
   1.624 +
   1.625 +lemma continuous_on_powr[continuous_on_intros]:
   1.626 +  assumes "continuous_on s f" "continuous_on s g" and "\<forall>x\<in>s. 0 < f x"
   1.627 +  shows "continuous_on s (\<lambda>x. (f x) powr (g x))"
   1.628 +  using assms unfolding continuous_on_def by (fast intro: tendsto_powr)
   1.629 +
   1.630 +(* FIXME: generalize by replacing d by with g x and g ---> d? *)
   1.631 +lemma tendsto_zero_powrI:
   1.632 +  assumes "eventually (\<lambda>x. 0 < f x ) F" and "(f ---> 0) F"
   1.633 +  assumes "0 < d"
   1.634 +  shows "((\<lambda>x. f x powr d) ---> 0) F"
   1.635 +proof (rule tendstoI)
   1.636 +  fix e :: real assume "0 < e"
   1.637 +  def Z \<equiv> "e powr (1 / d)"
   1.638 +  with `0 < e` have "0 < Z" by simp
   1.639 +  with assms have "eventually (\<lambda>x. 0 < f x \<and> dist (f x) 0 < Z) F"
   1.640 +    by (intro eventually_conj tendstoD)
   1.641 +  moreover
   1.642 +  from assms have "\<And>x. 0 < x \<and> dist x 0 < Z \<Longrightarrow> x powr d < Z powr d"
   1.643 +    by (intro powr_less_mono2) (auto simp: dist_real_def)
   1.644 +  with assms `0 < e` have "\<And>x. 0 < x \<and> dist x 0 < Z \<Longrightarrow> dist (x powr d) 0 < e"
   1.645 +    unfolding dist_real_def Z_def by (auto simp: powr_powr)
   1.646 +  ultimately
   1.647 +  show "eventually (\<lambda>x. dist (f x powr d) 0 < e) F" by (rule eventually_elim1)
   1.648 +qed
   1.649 +
   1.650 +lemma tendsto_neg_powr:
   1.651 +  assumes "s < 0" and "LIM x F. f x :> at_top"
   1.652 +  shows "((\<lambda>x. f x powr s) ---> 0) F"
   1.653 +proof (rule tendstoI)
   1.654 +  fix e :: real assume "0 < e"
   1.655 +  def Z \<equiv> "e powr (1 / s)"
   1.656 +  from assms have "eventually (\<lambda>x. Z < f x) F"
   1.657 +    by (simp add: filterlim_at_top_dense)
   1.658 +  moreover
   1.659 +  from assms have "\<And>x. Z < x \<Longrightarrow> x powr s < Z powr s"
   1.660 +    by (auto simp: Z_def intro!: powr_less_mono2_neg)
   1.661 +  with assms `0 < e` have "\<And>x. Z < x \<Longrightarrow> dist (x powr s) 0 < e"
   1.662 +    by (simp add: powr_powr Z_def dist_real_def)
   1.663 +  ultimately
   1.664 +  show "eventually (\<lambda>x. dist (f x powr s) 0 < e) F" by (rule eventually_elim1)
   1.665 +qed
   1.666 +
   1.667  subsection {* Sine and Cosine *}
   1.668  
   1.669  definition sin_coeff :: "nat \<Rightarrow> real" where
   1.670 @@ -1444,6 +2076,8 @@
   1.671      summable_minus summable_sin summable_cos)
   1.672    done
   1.673  
   1.674 +declare DERIV_sin[THEN DERIV_chain2, THEN DERIV_cong, DERIV_intros]
   1.675 +
   1.676  lemma DERIV_cos [simp]: "DERIV cos x :> -sin(x)"
   1.677    unfolding cos_def sin_def
   1.678    apply (rule DERIV_cong, rule termdiffs [where K="1 + \<bar>x\<bar>"])
   1.679 @@ -1451,6 +2085,8 @@
   1.680      summable_minus summable_sin summable_cos suminf_minus)
   1.681    done
   1.682  
   1.683 +declare DERIV_cos[THEN DERIV_chain2, THEN DERIV_cong, DERIV_intros]
   1.684 +
   1.685  lemma isCont_sin: "isCont sin x"
   1.686    by (rule DERIV_sin [THEN DERIV_isCont])
   1.687  
   1.688 @@ -1487,12 +2123,6 @@
   1.689    "continuous_on s f \<Longrightarrow> continuous_on s (\<lambda>x. cos (f x))"
   1.690    unfolding continuous_on_def by (auto intro: tendsto_cos)
   1.691  
   1.692 -declare
   1.693 -  DERIV_exp[THEN DERIV_chain2, THEN DERIV_cong, DERIV_intros]
   1.694 -  DERIV_ln_divide[THEN DERIV_chain2, THEN DERIV_cong, DERIV_intros]
   1.695 -  DERIV_sin[THEN DERIV_chain2, THEN DERIV_cong, DERIV_intros]
   1.696 -  DERIV_cos[THEN DERIV_chain2, THEN DERIV_cong, DERIV_intros]
   1.697 -
   1.698  subsection {* Properties of Sine and Cosine *}
   1.699  
   1.700  lemma sin_zero [simp]: "sin 0 = 0"