
paulson@12224: (*  Title       : Log.thy
paulson@12224:     Author      : Jacques D. Fleuriot
avigad@16819:                   Additional contributions by Jeremy Avigad
paulson@12224:     Copyright   : 2000,2001 University of Edinburgh
paulson@12224: *)
paulson@12224: 
paulson@14411: header{*Logarithms: Standard Version*}
paulson@14411: 
nipkow@15131: theory Log
nipkow@15140: imports Transcendental
nipkow@15131: begin
paulson@12224: 
wenzelm@19765: definition
wenzelm@21404:   powr  :: "[real,real] => real"     (infixr "powr" 80) where
paulson@14411:     --{*exponentation with real exponent*}
wenzelm@19765:   "x powr a = exp(a * ln x)"
paulson@12224: 
wenzelm@21404: definition
wenzelm@21404:   log :: "[real,real] => real" where
nipkow@15053:     --{*logarithm of @{term x} to base @{term a}*}
wenzelm@19765:   "log a x = ln x / ln a"
paulson@12224: 
paulson@14411: 
paulson@14411: 
paulson@14411: lemma powr_one_eq_one [simp]: "1 powr a = 1"
paulson@14411: by (simp add: powr_def)
paulson@14411: 
paulson@14411: lemma powr_zero_eq_one [simp]: "x powr 0 = 1"
paulson@14411: by (simp add: powr_def)
paulson@14411: 
paulson@14411: lemma powr_one_gt_zero_iff [simp]: "(x powr 1 = x) = (0 < x)"
paulson@14411: by (simp add: powr_def)
paulson@14411: declare powr_one_gt_zero_iff [THEN iffD2, simp]
paulson@14411: 
paulson@14411: lemma powr_mult: 
paulson@14411:       "[| 0 < x; 0 < y |] ==> (x * y) powr a = (x powr a) * (y powr a)"
paulson@14411: by (simp add: powr_def exp_add [symmetric] ln_mult right_distrib)
paulson@14411: 
paulson@14411: lemma powr_gt_zero [simp]: "0 < x powr a"
paulson@14411: by (simp add: powr_def)
paulson@14411: 
avigad@16819: lemma powr_ge_pzero [simp]: "0 <= x powr y"
avigad@16819: by (rule order_less_imp_le, rule powr_gt_zero)
avigad@16819: 
paulson@14411: lemma powr_not_zero [simp]: "x powr a \<noteq> 0"
paulson@14411: by (simp add: powr_def)
paulson@14411: 
paulson@14411: lemma powr_divide:
paulson@14411:      "[| 0 < x; 0 < y |] ==> (x / y) powr a = (x powr a)/(y powr a)"
paulson@14430: apply (simp add: divide_inverse positive_imp_inverse_positive powr_mult)
paulson@14411: apply (simp add: powr_def exp_minus [symmetric] exp_add [symmetric] ln_inverse)
paulson@14411: done
paulson@14411: 
avigad@16819: lemma powr_divide2: "x powr a / x powr b = x powr (a - b)"
avigad@16819:   apply (simp add: powr_def)
avigad@16819:   apply (subst exp_diff [THEN sym])
avigad@16819:   apply (simp add: left_diff_distrib)
avigad@16819: done
avigad@16819: 
paulson@14411: lemma powr_add: "x powr (a + b) = (x powr a) * (x powr b)"
paulson@14411: by (simp add: powr_def exp_add [symmetric] left_distrib)
paulson@14411: 
paulson@14411: lemma powr_powr: "(x powr a) powr b = x powr (a * b)"
paulson@14411: by (simp add: powr_def)
paulson@14411: 
paulson@14411: lemma powr_powr_swap: "(x powr a) powr b = (x powr b) powr a"
huffman@36777: by (simp add: powr_powr mult_commute)
paulson@14411: 
paulson@14411: lemma powr_minus: "x powr (-a) = inverse (x powr a)"
paulson@14411: by (simp add: powr_def exp_minus [symmetric])
paulson@14411: 
paulson@14411: lemma powr_minus_divide: "x powr (-a) = 1/(x powr a)"
paulson@14430: by (simp add: divide_inverse powr_minus)
paulson@14411: 
paulson@14411: lemma powr_less_mono: "[| a < b; 1 < x |] ==> x powr a < x powr b"
paulson@14411: by (simp add: powr_def)
paulson@14411: 
paulson@14411: lemma powr_less_cancel: "[| x powr a < x powr b; 1 < x |] ==> a < b"
paulson@14411: by (simp add: powr_def)
paulson@14411: 
paulson@14411: lemma powr_less_cancel_iff [simp]: "1 < x ==> (x powr a < x powr b) = (a < b)"
paulson@14411: by (blast intro: powr_less_cancel powr_less_mono)
paulson@14411: 
paulson@14411: lemma powr_le_cancel_iff [simp]: "1 < x ==> (x powr a \<le> x powr b) = (a \<le> b)"
paulson@14411: by (simp add: linorder_not_less [symmetric])
paulson@14411: 
paulson@14411: lemma log_ln: "ln x = log (exp(1)) x"
paulson@14411: by (simp add: log_def)
paulson@14411: 
hoelzl@45916: lemma DERIV_log: assumes "x > 0" shows "DERIV (\<lambda>y. log b y) x :> 1 / (ln b * x)"
hoelzl@45916: proof -
hoelzl@45916:   def lb \<equiv> "1 / ln b"
hoelzl@45916:   moreover have "DERIV (\<lambda>y. lb * ln y) x :> lb / x"
hoelzl@45916:     using `x > 0` by (auto intro!: DERIV_intros)
hoelzl@45916:   ultimately show ?thesis
hoelzl@45916:     by (simp add: log_def)
hoelzl@45916: qed
hoelzl@45916: 
hoelzl@45916: lemmas DERIV_log[THEN DERIV_chain2, THEN DERIV_cong, DERIV_intros]
paulson@33716: 
paulson@14411: lemma powr_log_cancel [simp]:
paulson@14411:      "[| 0 < a; a \<noteq> 1; 0 < x |] ==> a powr (log a x) = x"
paulson@14411: by (simp add: powr_def log_def)
paulson@14411: 
paulson@14411: lemma log_powr_cancel [simp]: "[| 0 < a; a \<noteq> 1 |] ==> log a (a powr y) = y"
paulson@14411: by (simp add: log_def powr_def)
paulson@14411: 
paulson@14411: lemma log_mult: 
paulson@14411:      "[| 0 < a; a \<noteq> 1; 0 < x; 0 < y |]  
paulson@14411:       ==> log a (x * y) = log a x + log a y"
paulson@14430: by (simp add: log_def ln_mult divide_inverse left_distrib)
paulson@14411: 
paulson@14411: lemma log_eq_div_ln_mult_log: 
paulson@14411:      "[| 0 < a; a \<noteq> 1; 0 < b; b \<noteq> 1; 0 < x |]  
paulson@14411:       ==> log a x = (ln b/ln a) * log b x"
paulson@14430: by (simp add: log_def divide_inverse)
paulson@14411: 
paulson@14411: text{*Base 10 logarithms*}
paulson@14411: lemma log_base_10_eq1: "0 < x ==> log 10 x = (ln (exp 1) / ln 10) * ln x"
paulson@14411: by (simp add: log_def)
paulson@14411: 
paulson@14411: lemma log_base_10_eq2: "0 < x ==> log 10 x = (log 10 (exp 1)) * ln x"
paulson@14411: by (simp add: log_def)
paulson@14411: 
paulson@14411: lemma log_one [simp]: "log a 1 = 0"
paulson@14411: by (simp add: log_def)
paulson@14411: 
paulson@14411: lemma log_eq_one [simp]: "[| 0 < a; a \<noteq> 1 |] ==> log a a = 1"
paulson@14411: by (simp add: log_def)
paulson@14411: 
paulson@14411: lemma log_inverse:
paulson@14411:      "[| 0 < a; a \<noteq> 1; 0 < x |] ==> log a (inverse x) = - log a x"
paulson@14411: apply (rule_tac a1 = "log a x" in add_left_cancel [THEN iffD1])
paulson@14411: apply (simp add: log_mult [symmetric])
paulson@14411: done
paulson@14411: 
paulson@14411: lemma log_divide:
paulson@14411:      "[|0 < a; a \<noteq> 1; 0 < x; 0 < y|] ==> log a (x/y) = log a x - log a y"
paulson@14430: by (simp add: log_mult divide_inverse log_inverse)
paulson@14411: 
paulson@14411: lemma log_less_cancel_iff [simp]:
paulson@14411:      "[| 1 < a; 0 < x; 0 < y |] ==> (log a x < log a y) = (x < y)"
paulson@14411: apply safe
paulson@14411: apply (rule_tac [2] powr_less_cancel)
paulson@14411: apply (drule_tac a = "log a x" in powr_less_mono, auto)
paulson@14411: done
paulson@14411: 
hoelzl@36622: lemma log_inj: assumes "1 < b" shows "inj_on (log b) {0 <..}"
hoelzl@36622: proof (rule inj_onI, simp)
hoelzl@36622:   fix x y assume pos: "0 < x" "0 < y" and *: "log b x = log b y"
hoelzl@36622:   show "x = y"
hoelzl@36622:   proof (cases rule: linorder_cases)
hoelzl@36622:     assume "x < y" hence "log b x < log b y"
hoelzl@36622:       using log_less_cancel_iff[OF `1 < b`] pos by simp
hoelzl@36622:     thus ?thesis using * by simp
hoelzl@36622:   next
hoelzl@36622:     assume "y < x" hence "log b y < log b x"
hoelzl@36622:       using log_less_cancel_iff[OF `1 < b`] pos by simp
hoelzl@36622:     thus ?thesis using * by simp
hoelzl@36622:   qed simp
hoelzl@36622: qed
hoelzl@36622: 
paulson@14411: lemma log_le_cancel_iff [simp]:
paulson@14411:      "[| 1 < a; 0 < x; 0 < y |] ==> (log a x \<le> log a y) = (x \<le> y)"
paulson@14411: by (simp add: linorder_not_less [symmetric])
paulson@14411: 
paulson@14411: 
paulson@15085: lemma powr_realpow: "0 < x ==> x powr (real n) = x^n"
paulson@15085:   apply (induct n, simp)
paulson@15085:   apply (subgoal_tac "real(Suc n) = real n + 1")
paulson@15085:   apply (erule ssubst)
paulson@15085:   apply (subst powr_add, simp, simp)
paulson@15085: done
paulson@15085: 
paulson@15085: lemma powr_realpow2: "0 <= x ==> 0 < n ==> x^n = (if (x = 0) then 0
paulson@15085:   else x powr (real n))"
paulson@15085:   apply (case_tac "x = 0", simp, simp)
paulson@15085:   apply (rule powr_realpow [THEN sym], simp)
paulson@15085: done
paulson@15085: 
paulson@33716: lemma ln_powr: "0 < x ==> 0 < y ==> ln(x powr y) = y * ln x"
paulson@15085: by (unfold powr_def, simp)
paulson@15085: 
paulson@33716: lemma log_powr: "0 < x ==> 0 \<le> y ==> log b (x powr y) = y * log b x"
paulson@33716:   apply (case_tac "y = 0")
paulson@33716:   apply force
paulson@33716:   apply (auto simp add: log_def ln_powr field_simps)
paulson@33716: done
paulson@33716: 
paulson@33716: lemma log_nat_power: "0 < x ==> log b (x^n) = real n * log b x"
paulson@33716:   apply (subst powr_realpow [symmetric])
paulson@33716:   apply (auto simp add: log_powr)
paulson@33716: done
paulson@33716: 
paulson@15085: lemma ln_bound: "1 <= x ==> ln x <= x"
paulson@15085:   apply (subgoal_tac "ln(1 + (x - 1)) <= x - 1")
paulson@15085:   apply simp
paulson@15085:   apply (rule ln_add_one_self_le_self, simp)
paulson@15085: done
paulson@15085: 
paulson@15085: lemma powr_mono: "a <= b ==> 1 <= x ==> x powr a <= x powr b"
paulson@15085:   apply (case_tac "x = 1", simp)
paulson@15085:   apply (case_tac "a = b", simp)
paulson@15085:   apply (rule order_less_imp_le)
paulson@15085:   apply (rule powr_less_mono, auto)
paulson@15085: done
paulson@15085: 
paulson@15085: lemma ge_one_powr_ge_zero: "1 <= x ==> 0 <= a ==> 1 <= x powr a"
paulson@15085:   apply (subst powr_zero_eq_one [THEN sym])
paulson@15085:   apply (rule powr_mono, assumption+)
paulson@15085: done
paulson@15085: 
paulson@15085: lemma powr_less_mono2: "0 < a ==> 0 < x ==> x < y ==> x powr a <
paulson@15085:     y powr a"
paulson@15085:   apply (unfold powr_def)
paulson@15085:   apply (rule exp_less_mono)
paulson@15085:   apply (rule mult_strict_left_mono)
paulson@15085:   apply (subst ln_less_cancel_iff, assumption)
paulson@15085:   apply (rule order_less_trans)
paulson@15085:   prefer 2
paulson@15085:   apply assumption+
paulson@15085: done
paulson@15085: 
avigad@16819: lemma powr_less_mono2_neg: "a < 0 ==> 0 < x ==> x < y ==> y powr a <
avigad@16819:     x powr a"
avigad@16819:   apply (unfold powr_def)
avigad@16819:   apply (rule exp_less_mono)
avigad@16819:   apply (rule mult_strict_left_mono_neg)
avigad@16819:   apply (subst ln_less_cancel_iff)
avigad@16819:   apply assumption
avigad@16819:   apply (rule order_less_trans)
avigad@16819:   prefer 2
avigad@16819:   apply assumption+
avigad@16819: done
avigad@16819: 
avigad@16819: lemma powr_mono2: "0 <= a ==> 0 < x ==> x <= y ==> x powr a <= y powr a"
paulson@15085:   apply (case_tac "a = 0", simp)
paulson@15085:   apply (case_tac "x = y", simp)
paulson@15085:   apply (rule order_less_imp_le)
paulson@15085:   apply (rule powr_less_mono2, auto)
paulson@15085: done
paulson@15085: 
avigad@16819: lemma ln_powr_bound: "1 <= x ==> 0 < a ==> ln x <= (x powr a) / a"
avigad@16819:   apply (rule mult_imp_le_div_pos)
avigad@16819:   apply (assumption)
avigad@16819:   apply (subst mult_commute)
paulson@33716:   apply (subst ln_powr [THEN sym])
avigad@16819:   apply auto
avigad@16819:   apply (rule ln_bound)
avigad@16819:   apply (erule ge_one_powr_ge_zero)
avigad@16819:   apply (erule order_less_imp_le)
avigad@16819: done
avigad@16819: 
wenzelm@41550: lemma ln_powr_bound2:
wenzelm@41550:   assumes "1 < x" and "0 < a"
wenzelm@41550:   shows "(ln x) powr a <= (a powr a) * x"
avigad@16819: proof -
wenzelm@41550:   from assms have "ln x <= (x powr (1 / a)) / (1 / a)"
avigad@16819:     apply (intro ln_powr_bound)
avigad@16819:     apply (erule order_less_imp_le)
avigad@16819:     apply (rule divide_pos_pos)
avigad@16819:     apply simp_all
avigad@16819:     done
avigad@16819:   also have "... = a * (x powr (1 / a))"
avigad@16819:     by simp
avigad@16819:   finally have "(ln x) powr a <= (a * (x powr (1 / a))) powr a"
avigad@16819:     apply (intro powr_mono2)
wenzelm@41550:     apply (rule order_less_imp_le, rule assms)
avigad@16819:     apply (rule ln_gt_zero)
wenzelm@41550:     apply (rule assms)
avigad@16819:     apply assumption
avigad@16819:     done
avigad@16819:   also have "... = (a powr a) * ((x powr (1 / a)) powr a)"
avigad@16819:     apply (rule powr_mult)
wenzelm@41550:     apply (rule assms)
avigad@16819:     apply (rule powr_gt_zero)
avigad@16819:     done
avigad@16819:   also have "(x powr (1 / a)) powr a = x powr ((1 / a) * a)"
avigad@16819:     by (rule powr_powr)
avigad@16819:   also have "... = x"
avigad@16819:     apply simp
avigad@16819:     apply (subgoal_tac "a ~= 0")
wenzelm@41550:     using assms apply auto
avigad@16819:     done
avigad@16819:   finally show ?thesis .
avigad@16819: qed
avigad@16819: 
huffman@45915: lemma tendsto_powr [tendsto_intros]:
huffman@45915:   "\<lbrakk>(f ---> a) F; (g ---> b) F; 0 < a\<rbrakk> \<Longrightarrow> ((\<lambda>x. f x powr g x) ---> a powr b) F"
huffman@45915:   unfolding powr_def by (intro tendsto_intros)
huffman@45915: 
noschinl@45892: (* FIXME: generalize by replacing d by with g x and g ---> d? *)
noschinl@45892: lemma tendsto_zero_powrI:
noschinl@45892:   assumes "eventually (\<lambda>x. 0 < f x ) F" and "(f ---> 0) F"
noschinl@45892:   assumes "0 < d"
noschinl@45892:   shows "((\<lambda>x. f x powr d) ---> 0) F"
noschinl@45892: proof (rule tendstoI)
noschinl@45892:   fix e :: real assume "0 < e"
noschinl@45892:   def Z \<equiv> "e powr (1 / d)"
noschinl@45892:   with `0 < e` have "0 < Z" by simp
noschinl@45892:   with assms have "eventually (\<lambda>x. 0 < f x \<and> dist (f x) 0 < Z) F"
noschinl@45892:     by (intro eventually_conj tendstoD)
noschinl@45892:   moreover
noschinl@45892:   from assms have "\<And>x. 0 < x \<and> dist x 0 < Z \<Longrightarrow> x powr d < Z powr d"
noschinl@45892:     by (intro powr_less_mono2) (auto simp: dist_real_def)
noschinl@45892:   with assms `0 < e` have "\<And>x. 0 < x \<and> dist x 0 < Z \<Longrightarrow> dist (x powr d) 0 < e"
noschinl@45892:     unfolding dist_real_def Z_def by (auto simp: powr_powr)
noschinl@45892:   ultimately
noschinl@45892:   show "eventually (\<lambda>x. dist (f x powr d) 0 < e) F" by (rule eventually_elim1)
noschinl@45892: qed
noschinl@45892: 
noschinl@45892: lemma tendsto_neg_powr:
noschinl@45892:   assumes "s < 0" and "real_tendsto_inf f F"
noschinl@45892:   shows "((\<lambda>x. f x powr s) ---> 0) F"
noschinl@45892: proof (rule tendstoI)
noschinl@45892:   fix e :: real assume "0 < e"
noschinl@45892:   def Z \<equiv> "e powr (1 / s)"
noschinl@45892:   from assms have "eventually (\<lambda>x. Z < f x) F" by (simp add: real_tendsto_inf_def)
noschinl@45892:   moreover
noschinl@45892:   from assms have "\<And>x. Z < x \<Longrightarrow> x powr s < Z powr s"
noschinl@45892:     by (auto simp: Z_def intro!: powr_less_mono2_neg)
noschinl@45892:   with assms `0 < e` have "\<And>x. Z < x \<Longrightarrow> dist (x powr s) 0 < e"
noschinl@45892:     by (simp add: powr_powr Z_def dist_real_def)
noschinl@45892:   ultimately
noschinl@45892:   show "eventually (\<lambda>x. dist (f x powr s) 0 < e) F" by (rule eventually_elim1)
wenzelm@41550: qed
avigad@16819: 
paulson@12224: end




