src/HOL/Log.thy
 author noschinl Thu Dec 15 15:55:39 2011 +0100 (2011-12-15) changeset 45892 8dcf6692433f parent 41550 efa734d9b221 child 45915 0e5a87b772f9 permissions -rw-r--r--
```     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
```
```    25 lemma powr_one_eq_one [simp]: "1 powr a = 1"
```
```    26 by (simp add: powr_def)
```
```    27
```
```    28 lemma powr_zero_eq_one [simp]: "x powr 0 = 1"
```
```    29 by (simp add: powr_def)
```
```    30
```
```    31 lemma powr_one_gt_zero_iff [simp]: "(x powr 1 = x) = (0 < x)"
```
```    32 by (simp add: powr_def)
```
```    33 declare powr_one_gt_zero_iff [THEN iffD2, simp]
```
```    34
```
```    35 lemma powr_mult:
```
```    36       "[| 0 < x; 0 < y |] ==> (x * y) powr a = (x powr a) * (y powr a)"
```
```    37 by (simp add: powr_def exp_add [symmetric] ln_mult right_distrib)
```
```    38
```
```    39 lemma powr_gt_zero [simp]: "0 < x powr a"
```
```    40 by (simp add: powr_def)
```
```    41
```
```    42 lemma powr_ge_pzero [simp]: "0 <= x powr y"
```
```    43 by (rule order_less_imp_le, rule powr_gt_zero)
```
```    44
```
```    45 lemma powr_not_zero [simp]: "x powr a \<noteq> 0"
```
```    46 by (simp add: powr_def)
```
```    47
```
```    48 lemma powr_divide:
```
```    49      "[| 0 < x; 0 < y |] ==> (x / y) powr a = (x powr a)/(y powr a)"
```
```    50 apply (simp add: divide_inverse positive_imp_inverse_positive powr_mult)
```
```    51 apply (simp add: powr_def exp_minus [symmetric] exp_add [symmetric] ln_inverse)
```
```    52 done
```
```    53
```
```    54 lemma powr_divide2: "x powr a / x powr b = x powr (a - b)"
```
```    55   apply (simp add: powr_def)
```
```    56   apply (subst exp_diff [THEN sym])
```
```    57   apply (simp add: left_diff_distrib)
```
```    58 done
```
```    59
```
```    60 lemma powr_add: "x powr (a + b) = (x powr a) * (x powr b)"
```
```    61 by (simp add: powr_def exp_add [symmetric] left_distrib)
```
```    62
```
```    63 lemma powr_powr: "(x powr a) powr b = x powr (a * b)"
```
```    64 by (simp add: powr_def)
```
```    65
```
```    66 lemma powr_powr_swap: "(x powr a) powr b = (x powr b) powr a"
```
```    67 by (simp add: powr_powr mult_commute)
```
```    68
```
```    69 lemma powr_minus: "x powr (-a) = inverse (x powr a)"
```
```    70 by (simp add: powr_def exp_minus [symmetric])
```
```    71
```
```    72 lemma powr_minus_divide: "x powr (-a) = 1/(x powr a)"
```
```    73 by (simp add: divide_inverse powr_minus)
```
```    74
```
```    75 lemma powr_less_mono: "[| a < b; 1 < x |] ==> x powr a < x powr b"
```
```    76 by (simp add: powr_def)
```
```    77
```
```    78 lemma powr_less_cancel: "[| x powr a < x powr b; 1 < x |] ==> a < b"
```
```    79 by (simp add: powr_def)
```
```    80
```
```    81 lemma powr_less_cancel_iff [simp]: "1 < x ==> (x powr a < x powr b) = (a < b)"
```
```    82 by (blast intro: powr_less_cancel powr_less_mono)
```
```    83
```
```    84 lemma powr_le_cancel_iff [simp]: "1 < x ==> (x powr a \<le> x powr b) = (a \<le> b)"
```
```    85 by (simp add: linorder_not_less [symmetric])
```
```    86
```
```    87 lemma log_ln: "ln x = log (exp(1)) x"
```
```    88 by (simp add: log_def)
```
```    89
```
```    90 lemma DERIV_log: "x > 0 ==> DERIV (%y. log b y) x :> 1 / (ln b * x)"
```
```    91   apply (subst log_def)
```
```    92   apply (subgoal_tac "(%y. ln y / ln b) = (%y. (1 / ln b) * ln y)")
```
```    93   apply (erule ssubst)
```
```    94   apply (subgoal_tac "1 / (ln b * x) = (1 / ln b) * (1 / x)")
```
```    95   apply (erule ssubst)
```
```    96   apply (rule DERIV_cmult)
```
```    97   apply (erule DERIV_ln_divide)
```
```    98   apply auto
```
```    99 done
```
```   100
```
```   101 lemma powr_log_cancel [simp]:
```
```   102      "[| 0 < a; a \<noteq> 1; 0 < x |] ==> a powr (log a x) = x"
```
```   103 by (simp add: powr_def log_def)
```
```   104
```
```   105 lemma log_powr_cancel [simp]: "[| 0 < a; a \<noteq> 1 |] ==> log a (a powr y) = y"
```
```   106 by (simp add: log_def powr_def)
```
```   107
```
```   108 lemma log_mult:
```
```   109      "[| 0 < a; a \<noteq> 1; 0 < x; 0 < y |]
```
```   110       ==> log a (x * y) = log a x + log a y"
```
```   111 by (simp add: log_def ln_mult divide_inverse left_distrib)
```
```   112
```
```   113 lemma log_eq_div_ln_mult_log:
```
```   114      "[| 0 < a; a \<noteq> 1; 0 < b; b \<noteq> 1; 0 < x |]
```
```   115       ==> log a x = (ln b/ln a) * log b x"
```
```   116 by (simp add: log_def divide_inverse)
```
```   117
```
```   118 text{*Base 10 logarithms*}
```
```   119 lemma log_base_10_eq1: "0 < x ==> log 10 x = (ln (exp 1) / ln 10) * ln x"
```
```   120 by (simp add: log_def)
```
```   121
```
```   122 lemma log_base_10_eq2: "0 < x ==> log 10 x = (log 10 (exp 1)) * ln x"
```
```   123 by (simp add: log_def)
```
```   124
```
```   125 lemma log_one [simp]: "log a 1 = 0"
```
```   126 by (simp add: log_def)
```
```   127
```
```   128 lemma log_eq_one [simp]: "[| 0 < a; a \<noteq> 1 |] ==> log a a = 1"
```
```   129 by (simp add: log_def)
```
```   130
```
```   131 lemma log_inverse:
```
```   132      "[| 0 < a; a \<noteq> 1; 0 < x |] ==> log a (inverse x) = - log a x"
```
```   133 apply (rule_tac a1 = "log a x" in add_left_cancel [THEN iffD1])
```
```   134 apply (simp add: log_mult [symmetric])
```
```   135 done
```
```   136
```
```   137 lemma log_divide:
```
```   138      "[|0 < a; a \<noteq> 1; 0 < x; 0 < y|] ==> log a (x/y) = log a x - log a y"
```
```   139 by (simp add: log_mult divide_inverse log_inverse)
```
```   140
```
```   141 lemma log_less_cancel_iff [simp]:
```
```   142      "[| 1 < a; 0 < x; 0 < y |] ==> (log a x < log a y) = (x < y)"
```
```   143 apply safe
```
```   144 apply (rule_tac [2] powr_less_cancel)
```
```   145 apply (drule_tac a = "log a x" in powr_less_mono, auto)
```
```   146 done
```
```   147
```
```   148 lemma log_inj: assumes "1 < b" shows "inj_on (log b) {0 <..}"
```
```   149 proof (rule inj_onI, simp)
```
```   150   fix x y assume pos: "0 < x" "0 < y" and *: "log b x = log b y"
```
```   151   show "x = y"
```
```   152   proof (cases rule: linorder_cases)
```
```   153     assume "x < y" hence "log b x < log b y"
```
```   154       using log_less_cancel_iff[OF `1 < b`] pos by simp
```
```   155     thus ?thesis using * by simp
```
```   156   next
```
```   157     assume "y < x" hence "log b y < log b x"
```
```   158       using log_less_cancel_iff[OF `1 < b`] pos by simp
```
```   159     thus ?thesis using * by simp
```
```   160   qed simp
```
```   161 qed
```
```   162
```
```   163 lemma log_le_cancel_iff [simp]:
```
```   164      "[| 1 < a; 0 < x; 0 < y |] ==> (log a x \<le> log a y) = (x \<le> y)"
```
```   165 by (simp add: linorder_not_less [symmetric])
```
```   166
```
```   167
```
```   168 lemma powr_realpow: "0 < x ==> x powr (real n) = x^n"
```
```   169   apply (induct n, simp)
```
```   170   apply (subgoal_tac "real(Suc n) = real n + 1")
```
```   171   apply (erule ssubst)
```
```   172   apply (subst powr_add, simp, simp)
```
```   173 done
```
```   174
```
```   175 lemma powr_realpow2: "0 <= x ==> 0 < n ==> x^n = (if (x = 0) then 0
```
```   176   else x powr (real n))"
```
```   177   apply (case_tac "x = 0", simp, simp)
```
```   178   apply (rule powr_realpow [THEN sym], simp)
```
```   179 done
```
```   180
```
```   181 lemma ln_powr: "0 < x ==> 0 < y ==> ln(x powr y) = y * ln x"
```
```   182 by (unfold powr_def, simp)
```
```   183
```
```   184 lemma log_powr: "0 < x ==> 0 \<le> y ==> log b (x powr y) = y * log b x"
```
```   185   apply (case_tac "y = 0")
```
```   186   apply force
```
```   187   apply (auto simp add: log_def ln_powr field_simps)
```
```   188 done
```
```   189
```
```   190 lemma log_nat_power: "0 < x ==> log b (x^n) = real n * log b x"
```
```   191   apply (subst powr_realpow [symmetric])
```
```   192   apply (auto simp add: log_powr)
```
```   193 done
```
```   194
```
```   195 lemma ln_bound: "1 <= x ==> ln x <= x"
```
```   196   apply (subgoal_tac "ln(1 + (x - 1)) <= x - 1")
```
```   197   apply simp
```
```   198   apply (rule ln_add_one_self_le_self, simp)
```
```   199 done
```
```   200
```
```   201 lemma powr_mono: "a <= b ==> 1 <= x ==> x powr a <= x powr b"
```
```   202   apply (case_tac "x = 1", simp)
```
```   203   apply (case_tac "a = b", simp)
```
```   204   apply (rule order_less_imp_le)
```
```   205   apply (rule powr_less_mono, auto)
```
```   206 done
```
```   207
```
```   208 lemma ge_one_powr_ge_zero: "1 <= x ==> 0 <= a ==> 1 <= x powr a"
```
```   209   apply (subst powr_zero_eq_one [THEN sym])
```
```   210   apply (rule powr_mono, assumption+)
```
```   211 done
```
```   212
```
```   213 lemma powr_less_mono2: "0 < a ==> 0 < x ==> x < y ==> x powr a <
```
```   214     y powr a"
```
```   215   apply (unfold powr_def)
```
```   216   apply (rule exp_less_mono)
```
```   217   apply (rule mult_strict_left_mono)
```
```   218   apply (subst ln_less_cancel_iff, assumption)
```
```   219   apply (rule order_less_trans)
```
```   220   prefer 2
```
```   221   apply assumption+
```
```   222 done
```
```   223
```
```   224 lemma powr_less_mono2_neg: "a < 0 ==> 0 < x ==> x < y ==> y powr a <
```
```   225     x powr a"
```
```   226   apply (unfold powr_def)
```
```   227   apply (rule exp_less_mono)
```
```   228   apply (rule mult_strict_left_mono_neg)
```
```   229   apply (subst ln_less_cancel_iff)
```
```   230   apply assumption
```
```   231   apply (rule order_less_trans)
```
```   232   prefer 2
```
```   233   apply assumption+
```
```   234 done
```
```   235
```
```   236 lemma powr_mono2: "0 <= a ==> 0 < x ==> x <= y ==> x powr a <= y powr a"
```
```   237   apply (case_tac "a = 0", simp)
```
```   238   apply (case_tac "x = y", simp)
```
```   239   apply (rule order_less_imp_le)
```
```   240   apply (rule powr_less_mono2, auto)
```
```   241 done
```
```   242
```
```   243 lemma ln_powr_bound: "1 <= x ==> 0 < a ==> ln x <= (x powr a) / a"
```
```   244   apply (rule mult_imp_le_div_pos)
```
```   245   apply (assumption)
```
```   246   apply (subst mult_commute)
```
```   247   apply (subst ln_powr [THEN sym])
```
```   248   apply auto
```
```   249   apply (rule ln_bound)
```
```   250   apply (erule ge_one_powr_ge_zero)
```
```   251   apply (erule order_less_imp_le)
```
```   252 done
```
```   253
```
```   254 lemma ln_powr_bound2:
```
```   255   assumes "1 < x" and "0 < a"
```
```   256   shows "(ln x) powr a <= (a powr a) * x"
```
```   257 proof -
```
```   258   from assms have "ln x <= (x powr (1 / a)) / (1 / a)"
```
```   259     apply (intro ln_powr_bound)
```
```   260     apply (erule order_less_imp_le)
```
```   261     apply (rule divide_pos_pos)
```
```   262     apply simp_all
```
```   263     done
```
```   264   also have "... = a * (x powr (1 / a))"
```
```   265     by simp
```
```   266   finally have "(ln x) powr a <= (a * (x powr (1 / a))) powr a"
```
```   267     apply (intro powr_mono2)
```
```   268     apply (rule order_less_imp_le, rule assms)
```
```   269     apply (rule ln_gt_zero)
```
```   270     apply (rule assms)
```
```   271     apply assumption
```
```   272     done
```
```   273   also have "... = (a powr a) * ((x powr (1 / a)) powr a)"
```
```   274     apply (rule powr_mult)
```
```   275     apply (rule assms)
```
```   276     apply (rule powr_gt_zero)
```
```   277     done
```
```   278   also have "(x powr (1 / a)) powr a = x powr ((1 / a) * a)"
```
```   279     by (rule powr_powr)
```
```   280   also have "... = x"
```
```   281     apply simp
```
```   282     apply (subgoal_tac "a ~= 0")
```
```   283     using assms apply auto
```
```   284     done
```
```   285   finally show ?thesis .
```
```   286 qed
```
```   287
```
```   288 (* FIXME: generalize by replacing d by with g x and g ---> d? *)
```
```   289 lemma tendsto_zero_powrI:
```
```   290   assumes "eventually (\<lambda>x. 0 < f x ) F" and "(f ---> 0) F"
```
```   291   assumes "0 < d"
```
```   292   shows "((\<lambda>x. f x powr d) ---> 0) F"
```
```   293 proof (rule tendstoI)
```
```   294   fix e :: real assume "0 < e"
```
```   295   def Z \<equiv> "e powr (1 / d)"
```
```   296   with `0 < e` have "0 < Z" by simp
```
```   297   with assms have "eventually (\<lambda>x. 0 < f x \<and> dist (f x) 0 < Z) F"
```
```   298     by (intro eventually_conj tendstoD)
```
```   299   moreover
```
```   300   from assms have "\<And>x. 0 < x \<and> dist x 0 < Z \<Longrightarrow> x powr d < Z powr d"
```
```   301     by (intro powr_less_mono2) (auto simp: dist_real_def)
```
```   302   with assms `0 < e` have "\<And>x. 0 < x \<and> dist x 0 < Z \<Longrightarrow> dist (x powr d) 0 < e"
```
```   303     unfolding dist_real_def Z_def by (auto simp: powr_powr)
```
```   304   ultimately
```
```   305   show "eventually (\<lambda>x. dist (f x powr d) 0 < e) F" by (rule eventually_elim1)
```
```   306 qed
```
```   307
```
```   308 lemma tendsto_neg_powr:
```
```   309   assumes "s < 0" and "real_tendsto_inf f F"
```
```   310   shows "((\<lambda>x. f x powr s) ---> 0) F"
```
```   311 proof (rule tendstoI)
```
```   312   fix e :: real assume "0 < e"
```
```   313   def Z \<equiv> "e powr (1 / s)"
```
```   314   from assms have "eventually (\<lambda>x. Z < f x) F" by (simp add: real_tendsto_inf_def)
```
```   315   moreover
```
```   316   from assms have "\<And>x. Z < x \<Longrightarrow> x powr s < Z powr s"
```
```   317     by (auto simp: Z_def intro!: powr_less_mono2_neg)
```
```   318   with assms `0 < e` have "\<And>x. Z < x \<Longrightarrow> dist (x powr s) 0 < e"
```
```   319     by (simp add: powr_powr Z_def dist_real_def)
```
```   320   ultimately
```
```   321   show "eventually (\<lambda>x. dist (f x powr s) 0 < e) F" by (rule eventually_elim1)
```
```   322 qed
```
```   323
```
```   324 end
```