src/HOL/Log.thy
author hoelzl
Tue Mar 26 12:20:58 2013 +0100 (2013-03-26)
changeset 51526 155263089e7b
parent 51483 dc39d69774bb
permissions -rw-r--r--
move SEQ.thy and Lim.thy to Limits.thy
     1 (*  Title       : Log.thy
     2     Author      : Jacques D. Fleuriot
     3                   Additional contributions by Jeremy Avigad
     4     Copyright   : 2000,2001 University of Edinburgh
     5 *)
     6 
     7 header{*Logarithms: Standard Version*}
     8 
     9 theory Log
    10 imports Transcendental
    11 begin
    12 
    13 definition
    14   powr  :: "[real,real] => real"     (infixr "powr" 80) where
    15     --{*exponentation with real exponent*}
    16   "x powr a = exp(a * ln x)"
    17 
    18 definition
    19   log :: "[real,real] => real" where
    20     --{*logarithm of @{term x} to base @{term a}*}
    21   "log a x = ln x / ln a"
    22 
    23 
    24 lemma tendsto_log [tendsto_intros]:
    25   "\<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"
    26   unfolding log_def by (intro tendsto_intros) auto
    27 
    28 lemma continuous_log:
    29   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))"
    30   shows "continuous F (\<lambda>x. log (f x) (g x))"
    31   using assms unfolding continuous_def by (rule tendsto_log)
    32 
    33 lemma continuous_at_within_log[continuous_intros]:
    34   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"
    35   shows "continuous (at a within s) (\<lambda>x. log (f x) (g x))"
    36   using assms unfolding continuous_within by (rule tendsto_log)
    37 
    38 lemma isCont_log[continuous_intros, simp]:
    39   assumes "isCont f a" "isCont g a" "0 < f a" "f a \<noteq> 1" "0 < g a"
    40   shows "isCont (\<lambda>x. log (f x) (g x)) a"
    41   using assms unfolding continuous_at by (rule tendsto_log)
    42 
    43 lemma continuous_on_log[continuous_on_intros]:
    44   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"
    45   shows "continuous_on s (\<lambda>x. log (f x) (g x))"
    46   using assms unfolding continuous_on_def by (fast intro: tendsto_log)
    47 
    48 lemma powr_one_eq_one [simp]: "1 powr a = 1"
    49 by (simp add: powr_def)
    50 
    51 lemma powr_zero_eq_one [simp]: "x powr 0 = 1"
    52 by (simp add: powr_def)
    53 
    54 lemma powr_one_gt_zero_iff [simp]: "(x powr 1 = x) = (0 < x)"
    55 by (simp add: powr_def)
    56 declare powr_one_gt_zero_iff [THEN iffD2, simp]
    57 
    58 lemma powr_mult: 
    59       "[| 0 < x; 0 < y |] ==> (x * y) powr a = (x powr a) * (y powr a)"
    60 by (simp add: powr_def exp_add [symmetric] ln_mult distrib_left)
    61 
    62 lemma powr_gt_zero [simp]: "0 < x powr a"
    63 by (simp add: powr_def)
    64 
    65 lemma powr_ge_pzero [simp]: "0 <= x powr y"
    66 by (rule order_less_imp_le, rule powr_gt_zero)
    67 
    68 lemma powr_not_zero [simp]: "x powr a \<noteq> 0"
    69 by (simp add: powr_def)
    70 
    71 lemma powr_divide:
    72      "[| 0 < x; 0 < y |] ==> (x / y) powr a = (x powr a)/(y powr a)"
    73 apply (simp add: divide_inverse positive_imp_inverse_positive powr_mult)
    74 apply (simp add: powr_def exp_minus [symmetric] exp_add [symmetric] ln_inverse)
    75 done
    76 
    77 lemma powr_divide2: "x powr a / x powr b = x powr (a - b)"
    78   apply (simp add: powr_def)
    79   apply (subst exp_diff [THEN sym])
    80   apply (simp add: left_diff_distrib)
    81 done
    82 
    83 lemma powr_add: "x powr (a + b) = (x powr a) * (x powr b)"
    84 by (simp add: powr_def exp_add [symmetric] distrib_right)
    85 
    86 lemma powr_mult_base:
    87   "0 < x \<Longrightarrow>x * x powr y = x powr (1 + y)"
    88 using assms by (auto simp: powr_add)
    89 
    90 lemma powr_powr: "(x powr a) powr b = x powr (a * b)"
    91 by (simp add: powr_def)
    92 
    93 lemma powr_powr_swap: "(x powr a) powr b = (x powr b) powr a"
    94 by (simp add: powr_powr mult_commute)
    95 
    96 lemma powr_minus: "x powr (-a) = inverse (x powr a)"
    97 by (simp add: powr_def exp_minus [symmetric])
    98 
    99 lemma powr_minus_divide: "x powr (-a) = 1/(x powr a)"
   100 by (simp add: divide_inverse powr_minus)
   101 
   102 lemma powr_less_mono: "[| a < b; 1 < x |] ==> x powr a < x powr b"
   103 by (simp add: powr_def)
   104 
   105 lemma powr_less_cancel: "[| x powr a < x powr b; 1 < x |] ==> a < b"
   106 by (simp add: powr_def)
   107 
   108 lemma powr_less_cancel_iff [simp]: "1 < x ==> (x powr a < x powr b) = (a < b)"
   109 by (blast intro: powr_less_cancel powr_less_mono)
   110 
   111 lemma powr_le_cancel_iff [simp]: "1 < x ==> (x powr a \<le> x powr b) = (a \<le> b)"
   112 by (simp add: linorder_not_less [symmetric])
   113 
   114 lemma log_ln: "ln x = log (exp(1)) x"
   115 by (simp add: log_def)
   116 
   117 lemma DERIV_log: assumes "x > 0" shows "DERIV (\<lambda>y. log b y) x :> 1 / (ln b * x)"
   118 proof -
   119   def lb \<equiv> "1 / ln b"
   120   moreover have "DERIV (\<lambda>y. lb * ln y) x :> lb / x"
   121     using `x > 0` by (auto intro!: DERIV_intros)
   122   ultimately show ?thesis
   123     by (simp add: log_def)
   124 qed
   125 
   126 lemmas DERIV_log[THEN DERIV_chain2, THEN DERIV_cong, DERIV_intros]
   127 
   128 lemma powr_log_cancel [simp]:
   129      "[| 0 < a; a \<noteq> 1; 0 < x |] ==> a powr (log a x) = x"
   130 by (simp add: powr_def log_def)
   131 
   132 lemma log_powr_cancel [simp]: "[| 0 < a; a \<noteq> 1 |] ==> log a (a powr y) = y"
   133 by (simp add: log_def powr_def)
   134 
   135 lemma log_mult: 
   136      "[| 0 < a; a \<noteq> 1; 0 < x; 0 < y |]  
   137       ==> log a (x * y) = log a x + log a y"
   138 by (simp add: log_def ln_mult divide_inverse distrib_right)
   139 
   140 lemma log_eq_div_ln_mult_log: 
   141      "[| 0 < a; a \<noteq> 1; 0 < b; b \<noteq> 1; 0 < x |]  
   142       ==> log a x = (ln b/ln a) * log b x"
   143 by (simp add: log_def divide_inverse)
   144 
   145 text{*Base 10 logarithms*}
   146 lemma log_base_10_eq1: "0 < x ==> log 10 x = (ln (exp 1) / ln 10) * ln x"
   147 by (simp add: log_def)
   148 
   149 lemma log_base_10_eq2: "0 < x ==> log 10 x = (log 10 (exp 1)) * ln x"
   150 by (simp add: log_def)
   151 
   152 lemma log_one [simp]: "log a 1 = 0"
   153 by (simp add: log_def)
   154 
   155 lemma log_eq_one [simp]: "[| 0 < a; a \<noteq> 1 |] ==> log a a = 1"
   156 by (simp add: log_def)
   157 
   158 lemma log_inverse:
   159      "[| 0 < a; a \<noteq> 1; 0 < x |] ==> log a (inverse x) = - log a x"
   160 apply (rule_tac a1 = "log a x" in add_left_cancel [THEN iffD1])
   161 apply (simp add: log_mult [symmetric])
   162 done
   163 
   164 lemma log_divide:
   165      "[|0 < a; a \<noteq> 1; 0 < x; 0 < y|] ==> log a (x/y) = log a x - log a y"
   166 by (simp add: log_mult divide_inverse log_inverse)
   167 
   168 lemma log_less_cancel_iff [simp]:
   169      "[| 1 < a; 0 < x; 0 < y |] ==> (log a x < log a y) = (x < y)"
   170 apply safe
   171 apply (rule_tac [2] powr_less_cancel)
   172 apply (drule_tac a = "log a x" in powr_less_mono, auto)
   173 done
   174 
   175 lemma log_inj: assumes "1 < b" shows "inj_on (log b) {0 <..}"
   176 proof (rule inj_onI, simp)
   177   fix x y assume pos: "0 < x" "0 < y" and *: "log b x = log b y"
   178   show "x = y"
   179   proof (cases rule: linorder_cases)
   180     assume "x < y" hence "log b x < log b y"
   181       using log_less_cancel_iff[OF `1 < b`] pos by simp
   182     thus ?thesis using * by simp
   183   next
   184     assume "y < x" hence "log b y < log b x"
   185       using log_less_cancel_iff[OF `1 < b`] pos by simp
   186     thus ?thesis using * by simp
   187   qed simp
   188 qed
   189 
   190 lemma log_le_cancel_iff [simp]:
   191      "[| 1 < a; 0 < x; 0 < y |] ==> (log a x \<le> log a y) = (x \<le> y)"
   192 by (simp add: linorder_not_less [symmetric])
   193 
   194 lemma zero_less_log_cancel_iff[simp]: "1 < a \<Longrightarrow> 0 < x \<Longrightarrow> 0 < log a x \<longleftrightarrow> 1 < x"
   195   using log_less_cancel_iff[of a 1 x] by simp
   196 
   197 lemma zero_le_log_cancel_iff[simp]: "1 < a \<Longrightarrow> 0 < x \<Longrightarrow> 0 \<le> log a x \<longleftrightarrow> 1 \<le> x"
   198   using log_le_cancel_iff[of a 1 x] by simp
   199 
   200 lemma log_less_zero_cancel_iff[simp]: "1 < a \<Longrightarrow> 0 < x \<Longrightarrow> log a x < 0 \<longleftrightarrow> x < 1"
   201   using log_less_cancel_iff[of a x 1] by simp
   202 
   203 lemma log_le_zero_cancel_iff[simp]: "1 < a \<Longrightarrow> 0 < x \<Longrightarrow> log a x \<le> 0 \<longleftrightarrow> x \<le> 1"
   204   using log_le_cancel_iff[of a x 1] by simp
   205 
   206 lemma one_less_log_cancel_iff[simp]: "1 < a \<Longrightarrow> 0 < x \<Longrightarrow> 1 < log a x \<longleftrightarrow> a < x"
   207   using log_less_cancel_iff[of a a x] by simp
   208 
   209 lemma one_le_log_cancel_iff[simp]: "1 < a \<Longrightarrow> 0 < x \<Longrightarrow> 1 \<le> log a x \<longleftrightarrow> a \<le> x"
   210   using log_le_cancel_iff[of a a x] by simp
   211 
   212 lemma log_less_one_cancel_iff[simp]: "1 < a \<Longrightarrow> 0 < x \<Longrightarrow> log a x < 1 \<longleftrightarrow> x < a"
   213   using log_less_cancel_iff[of a x a] by simp
   214 
   215 lemma log_le_one_cancel_iff[simp]: "1 < a \<Longrightarrow> 0 < x \<Longrightarrow> log a x \<le> 1 \<longleftrightarrow> x \<le> a"
   216   using log_le_cancel_iff[of a x a] by simp
   217 
   218 lemma powr_realpow: "0 < x ==> x powr (real n) = x^n"
   219   apply (induct n, simp)
   220   apply (subgoal_tac "real(Suc n) = real n + 1")
   221   apply (erule ssubst)
   222   apply (subst powr_add, simp, simp)
   223 done
   224 
   225 lemma powr_realpow2: "0 <= x ==> 0 < n ==> x^n = (if (x = 0) then 0 else x powr (real n))"
   226   apply (case_tac "x = 0", simp, simp)
   227   apply (rule powr_realpow [THEN sym], simp)
   228 done
   229 
   230 lemma powr_int:
   231   assumes "x > 0"
   232   shows "x powr i = (if i \<ge> 0 then x ^ nat i else 1 / x ^ nat (-i))"
   233 proof cases
   234   assume "i < 0"
   235   have r: "x powr i = 1 / x powr (-i)" by (simp add: powr_minus field_simps)
   236   show ?thesis using `i < 0` `x > 0` by (simp add: r field_simps powr_realpow[symmetric])
   237 qed (simp add: assms powr_realpow[symmetric])
   238 
   239 lemma powr_numeral: "0 < x \<Longrightarrow> x powr numeral n = x^numeral n"
   240   using powr_realpow[of x "numeral n"] by simp
   241 
   242 lemma powr_neg_numeral: "0 < x \<Longrightarrow> x powr neg_numeral n = 1 / x^numeral n"
   243   using powr_int[of x "neg_numeral n"] by simp
   244 
   245 lemma root_powr_inverse:
   246   "0 < n \<Longrightarrow> 0 < x \<Longrightarrow> root n x = x powr (1/n)"
   247   by (rule real_root_pos_unique) (auto simp: powr_realpow[symmetric] powr_powr)
   248 
   249 lemma ln_powr: "0 < x ==> 0 < y ==> ln(x powr y) = y * ln x"
   250 by (unfold powr_def, simp)
   251 
   252 lemma log_powr: "0 < x ==> 0 \<le> y ==> log b (x powr y) = y * log b x"
   253   apply (case_tac "y = 0")
   254   apply force
   255   apply (auto simp add: log_def ln_powr field_simps)
   256 done
   257 
   258 lemma log_nat_power: "0 < x ==> log b (x^n) = real n * log b x"
   259   apply (subst powr_realpow [symmetric])
   260   apply (auto simp add: log_powr)
   261 done
   262 
   263 lemma ln_bound: "1 <= x ==> ln x <= x"
   264   apply (subgoal_tac "ln(1 + (x - 1)) <= x - 1")
   265   apply simp
   266   apply (rule ln_add_one_self_le_self, simp)
   267 done
   268 
   269 lemma powr_mono: "a <= b ==> 1 <= x ==> x powr a <= x powr b"
   270   apply (case_tac "x = 1", simp)
   271   apply (case_tac "a = b", simp)
   272   apply (rule order_less_imp_le)
   273   apply (rule powr_less_mono, auto)
   274 done
   275 
   276 lemma ge_one_powr_ge_zero: "1 <= x ==> 0 <= a ==> 1 <= x powr a"
   277   apply (subst powr_zero_eq_one [THEN sym])
   278   apply (rule powr_mono, assumption+)
   279 done
   280 
   281 lemma powr_less_mono2: "0 < a ==> 0 < x ==> x < y ==> x powr a <
   282     y powr a"
   283   apply (unfold powr_def)
   284   apply (rule exp_less_mono)
   285   apply (rule mult_strict_left_mono)
   286   apply (subst ln_less_cancel_iff, assumption)
   287   apply (rule order_less_trans)
   288   prefer 2
   289   apply assumption+
   290 done
   291 
   292 lemma powr_less_mono2_neg: "a < 0 ==> 0 < x ==> x < y ==> y powr a <
   293     x powr a"
   294   apply (unfold powr_def)
   295   apply (rule exp_less_mono)
   296   apply (rule mult_strict_left_mono_neg)
   297   apply (subst ln_less_cancel_iff)
   298   apply assumption
   299   apply (rule order_less_trans)
   300   prefer 2
   301   apply assumption+
   302 done
   303 
   304 lemma powr_mono2: "0 <= a ==> 0 < x ==> x <= y ==> x powr a <= y powr a"
   305   apply (case_tac "a = 0", simp)
   306   apply (case_tac "x = y", simp)
   307   apply (rule order_less_imp_le)
   308   apply (rule powr_less_mono2, auto)
   309 done
   310 
   311 lemma powr_inj:
   312   "0 < a \<Longrightarrow> a \<noteq> 1 \<Longrightarrow> a powr x = a powr y \<longleftrightarrow> x = y"
   313   unfolding powr_def exp_inj_iff by simp
   314 
   315 lemma ln_powr_bound: "1 <= x ==> 0 < a ==> ln x <= (x powr a) / a"
   316   apply (rule mult_imp_le_div_pos)
   317   apply (assumption)
   318   apply (subst mult_commute)
   319   apply (subst ln_powr [THEN sym])
   320   apply auto
   321   apply (rule ln_bound)
   322   apply (erule ge_one_powr_ge_zero)
   323   apply (erule order_less_imp_le)
   324 done
   325 
   326 lemma ln_powr_bound2:
   327   assumes "1 < x" and "0 < a"
   328   shows "(ln x) powr a <= (a powr a) * x"
   329 proof -
   330   from assms have "ln x <= (x powr (1 / a)) / (1 / a)"
   331     apply (intro ln_powr_bound)
   332     apply (erule order_less_imp_le)
   333     apply (rule divide_pos_pos)
   334     apply simp_all
   335     done
   336   also have "... = a * (x powr (1 / a))"
   337     by simp
   338   finally have "(ln x) powr a <= (a * (x powr (1 / a))) powr a"
   339     apply (intro powr_mono2)
   340     apply (rule order_less_imp_le, rule assms)
   341     apply (rule ln_gt_zero)
   342     apply (rule assms)
   343     apply assumption
   344     done
   345   also have "... = (a powr a) * ((x powr (1 / a)) powr a)"
   346     apply (rule powr_mult)
   347     apply (rule assms)
   348     apply (rule powr_gt_zero)
   349     done
   350   also have "(x powr (1 / a)) powr a = x powr ((1 / a) * a)"
   351     by (rule powr_powr)
   352   also have "... = x"
   353     apply simp
   354     apply (subgoal_tac "a ~= 0")
   355     using assms apply auto
   356     done
   357   finally show ?thesis .
   358 qed
   359 
   360 lemma tendsto_powr [tendsto_intros]:
   361   "\<lbrakk>(f ---> a) F; (g ---> b) F; 0 < a\<rbrakk> \<Longrightarrow> ((\<lambda>x. f x powr g x) ---> a powr b) F"
   362   unfolding powr_def by (intro tendsto_intros)
   363 
   364 lemma continuous_powr:
   365   assumes "continuous F f" and "continuous F g" and "0 < f (Lim F (\<lambda>x. x))"
   366   shows "continuous F (\<lambda>x. (f x) powr (g x))"
   367   using assms unfolding continuous_def by (rule tendsto_powr)
   368 
   369 lemma continuous_at_within_powr[continuous_intros]:
   370   assumes "continuous (at a within s) f" "continuous (at a within s) g" and "0 < f a"
   371   shows "continuous (at a within s) (\<lambda>x. (f x) powr (g x))"
   372   using assms unfolding continuous_within by (rule tendsto_powr)
   373 
   374 lemma isCont_powr[continuous_intros, simp]:
   375   assumes "isCont f a" "isCont g a" "0 < f a"
   376   shows "isCont (\<lambda>x. (f x) powr g x) a"
   377   using assms unfolding continuous_at by (rule tendsto_powr)
   378 
   379 lemma continuous_on_powr[continuous_on_intros]:
   380   assumes "continuous_on s f" "continuous_on s g" and "\<forall>x\<in>s. 0 < f x"
   381   shows "continuous_on s (\<lambda>x. (f x) powr (g x))"
   382   using assms unfolding continuous_on_def by (fast intro: tendsto_powr)
   383 
   384 (* FIXME: generalize by replacing d by with g x and g ---> d? *)
   385 lemma tendsto_zero_powrI:
   386   assumes "eventually (\<lambda>x. 0 < f x ) F" and "(f ---> 0) F"
   387   assumes "0 < d"
   388   shows "((\<lambda>x. f x powr d) ---> 0) F"
   389 proof (rule tendstoI)
   390   fix e :: real assume "0 < e"
   391   def Z \<equiv> "e powr (1 / d)"
   392   with `0 < e` have "0 < Z" by simp
   393   with assms have "eventually (\<lambda>x. 0 < f x \<and> dist (f x) 0 < Z) F"
   394     by (intro eventually_conj tendstoD)
   395   moreover
   396   from assms have "\<And>x. 0 < x \<and> dist x 0 < Z \<Longrightarrow> x powr d < Z powr d"
   397     by (intro powr_less_mono2) (auto simp: dist_real_def)
   398   with assms `0 < e` have "\<And>x. 0 < x \<and> dist x 0 < Z \<Longrightarrow> dist (x powr d) 0 < e"
   399     unfolding dist_real_def Z_def by (auto simp: powr_powr)
   400   ultimately
   401   show "eventually (\<lambda>x. dist (f x powr d) 0 < e) F" by (rule eventually_elim1)
   402 qed
   403 
   404 lemma tendsto_neg_powr:
   405   assumes "s < 0" and "LIM x F. f x :> at_top"
   406   shows "((\<lambda>x. f x powr s) ---> 0) F"
   407 proof (rule tendstoI)
   408   fix e :: real assume "0 < e"
   409   def Z \<equiv> "e powr (1 / s)"
   410   from assms have "eventually (\<lambda>x. Z < f x) F"
   411     by (simp add: filterlim_at_top_dense)
   412   moreover
   413   from assms have "\<And>x. Z < x \<Longrightarrow> x powr s < Z powr s"
   414     by (auto simp: Z_def intro!: powr_less_mono2_neg)
   415   with assms `0 < e` have "\<And>x. Z < x \<Longrightarrow> dist (x powr s) 0 < e"
   416     by (simp add: powr_powr Z_def dist_real_def)
   417   ultimately
   418   show "eventually (\<lambda>x. dist (f x powr s) 0 < e) F" by (rule eventually_elim1)
   419 qed
   420 
   421 end