src/HOL/Log.thy
author wenzelm
Mon Mar 16 18:24:30 2009 +0100 (2009-03-16)
changeset 30549 d2d7874648bd
parent 28952 15a4b2cf8c34
child 31336 e17f13cd1280
permissions -rw-r--r--
simplified method setup;
paulson@12224
     1
(*  Title       : Log.thy
paulson@12224
     2
    Author      : Jacques D. Fleuriot
avigad@16819
     3
                  Additional contributions by Jeremy Avigad
paulson@12224
     4
    Copyright   : 2000,2001 University of Edinburgh
paulson@12224
     5
*)
paulson@12224
     6
paulson@14411
     7
header{*Logarithms: Standard Version*}
paulson@14411
     8
nipkow@15131
     9
theory Log
nipkow@15140
    10
imports Transcendental
nipkow@15131
    11
begin
paulson@12224
    12
wenzelm@19765
    13
definition
wenzelm@21404
    14
  powr  :: "[real,real] => real"     (infixr "powr" 80) where
paulson@14411
    15
    --{*exponentation with real exponent*}
wenzelm@19765
    16
  "x powr a = exp(a * ln x)"
paulson@12224
    17
wenzelm@21404
    18
definition
wenzelm@21404
    19
  log :: "[real,real] => real" where
nipkow@15053
    20
    --{*logarithm of @{term x} to base @{term a}*}
wenzelm@19765
    21
  "log a x = ln x / ln a"
paulson@12224
    22
paulson@14411
    23
paulson@14411
    24
paulson@14411
    25
lemma powr_one_eq_one [simp]: "1 powr a = 1"
paulson@14411
    26
by (simp add: powr_def)
paulson@14411
    27
paulson@14411
    28
lemma powr_zero_eq_one [simp]: "x powr 0 = 1"
paulson@14411
    29
by (simp add: powr_def)
paulson@14411
    30
paulson@14411
    31
lemma powr_one_gt_zero_iff [simp]: "(x powr 1 = x) = (0 < x)"
paulson@14411
    32
by (simp add: powr_def)
paulson@14411
    33
declare powr_one_gt_zero_iff [THEN iffD2, simp]
paulson@14411
    34
paulson@14411
    35
lemma powr_mult: 
paulson@14411
    36
      "[| 0 < x; 0 < y |] ==> (x * y) powr a = (x powr a) * (y powr a)"
paulson@14411
    37
by (simp add: powr_def exp_add [symmetric] ln_mult right_distrib)
paulson@14411
    38
paulson@14411
    39
lemma powr_gt_zero [simp]: "0 < x powr a"
paulson@14411
    40
by (simp add: powr_def)
paulson@14411
    41
avigad@16819
    42
lemma powr_ge_pzero [simp]: "0 <= x powr y"
avigad@16819
    43
by (rule order_less_imp_le, rule powr_gt_zero)
avigad@16819
    44
paulson@14411
    45
lemma powr_not_zero [simp]: "x powr a \<noteq> 0"
paulson@14411
    46
by (simp add: powr_def)
paulson@14411
    47
paulson@14411
    48
lemma powr_divide:
paulson@14411
    49
     "[| 0 < x; 0 < y |] ==> (x / y) powr a = (x powr a)/(y powr a)"
paulson@14430
    50
apply (simp add: divide_inverse positive_imp_inverse_positive powr_mult)
paulson@14411
    51
apply (simp add: powr_def exp_minus [symmetric] exp_add [symmetric] ln_inverse)
paulson@14411
    52
done
paulson@14411
    53
avigad@16819
    54
lemma powr_divide2: "x powr a / x powr b = x powr (a - b)"
avigad@16819
    55
  apply (simp add: powr_def)
avigad@16819
    56
  apply (subst exp_diff [THEN sym])
avigad@16819
    57
  apply (simp add: left_diff_distrib)
avigad@16819
    58
done
avigad@16819
    59
paulson@14411
    60
lemma powr_add: "x powr (a + b) = (x powr a) * (x powr b)"
paulson@14411
    61
by (simp add: powr_def exp_add [symmetric] left_distrib)
paulson@14411
    62
paulson@14411
    63
lemma powr_powr: "(x powr a) powr b = x powr (a * b)"
paulson@14411
    64
by (simp add: powr_def)
paulson@14411
    65
paulson@14411
    66
lemma powr_powr_swap: "(x powr a) powr b = (x powr b) powr a"
paulson@14411
    67
by (simp add: powr_powr real_mult_commute)
paulson@14411
    68
paulson@14411
    69
lemma powr_minus: "x powr (-a) = inverse (x powr a)"
paulson@14411
    70
by (simp add: powr_def exp_minus [symmetric])
paulson@14411
    71
paulson@14411
    72
lemma powr_minus_divide: "x powr (-a) = 1/(x powr a)"
paulson@14430
    73
by (simp add: divide_inverse powr_minus)
paulson@14411
    74
paulson@14411
    75
lemma powr_less_mono: "[| a < b; 1 < x |] ==> x powr a < x powr b"
paulson@14411
    76
by (simp add: powr_def)
paulson@14411
    77
paulson@14411
    78
lemma powr_less_cancel: "[| x powr a < x powr b; 1 < x |] ==> a < b"
paulson@14411
    79
by (simp add: powr_def)
paulson@14411
    80
paulson@14411
    81
lemma powr_less_cancel_iff [simp]: "1 < x ==> (x powr a < x powr b) = (a < b)"
paulson@14411
    82
by (blast intro: powr_less_cancel powr_less_mono)
paulson@14411
    83
paulson@14411
    84
lemma powr_le_cancel_iff [simp]: "1 < x ==> (x powr a \<le> x powr b) = (a \<le> b)"
paulson@14411
    85
by (simp add: linorder_not_less [symmetric])
paulson@14411
    86
paulson@14411
    87
lemma log_ln: "ln x = log (exp(1)) x"
paulson@14411
    88
by (simp add: log_def)
paulson@14411
    89
paulson@14411
    90
lemma powr_log_cancel [simp]:
paulson@14411
    91
     "[| 0 < a; a \<noteq> 1; 0 < x |] ==> a powr (log a x) = x"
paulson@14411
    92
by (simp add: powr_def log_def)
paulson@14411
    93
paulson@14411
    94
lemma log_powr_cancel [simp]: "[| 0 < a; a \<noteq> 1 |] ==> log a (a powr y) = y"
paulson@14411
    95
by (simp add: log_def powr_def)
paulson@14411
    96
paulson@14411
    97
lemma log_mult: 
paulson@14411
    98
     "[| 0 < a; a \<noteq> 1; 0 < x; 0 < y |]  
paulson@14411
    99
      ==> log a (x * y) = log a x + log a y"
paulson@14430
   100
by (simp add: log_def ln_mult divide_inverse left_distrib)
paulson@14411
   101
paulson@14411
   102
lemma log_eq_div_ln_mult_log: 
paulson@14411
   103
     "[| 0 < a; a \<noteq> 1; 0 < b; b \<noteq> 1; 0 < x |]  
paulson@14411
   104
      ==> log a x = (ln b/ln a) * log b x"
paulson@14430
   105
by (simp add: log_def divide_inverse)
paulson@14411
   106
paulson@14411
   107
text{*Base 10 logarithms*}
paulson@14411
   108
lemma log_base_10_eq1: "0 < x ==> log 10 x = (ln (exp 1) / ln 10) * ln x"
paulson@14411
   109
by (simp add: log_def)
paulson@14411
   110
paulson@14411
   111
lemma log_base_10_eq2: "0 < x ==> log 10 x = (log 10 (exp 1)) * ln x"
paulson@14411
   112
by (simp add: log_def)
paulson@14411
   113
paulson@14411
   114
lemma log_one [simp]: "log a 1 = 0"
paulson@14411
   115
by (simp add: log_def)
paulson@14411
   116
paulson@14411
   117
lemma log_eq_one [simp]: "[| 0 < a; a \<noteq> 1 |] ==> log a a = 1"
paulson@14411
   118
by (simp add: log_def)
paulson@14411
   119
paulson@14411
   120
lemma log_inverse:
paulson@14411
   121
     "[| 0 < a; a \<noteq> 1; 0 < x |] ==> log a (inverse x) = - log a x"
paulson@14411
   122
apply (rule_tac a1 = "log a x" in add_left_cancel [THEN iffD1])
paulson@14411
   123
apply (simp add: log_mult [symmetric])
paulson@14411
   124
done
paulson@14411
   125
paulson@14411
   126
lemma log_divide:
paulson@14411
   127
     "[|0 < a; a \<noteq> 1; 0 < x; 0 < y|] ==> log a (x/y) = log a x - log a y"
paulson@14430
   128
by (simp add: log_mult divide_inverse log_inverse)
paulson@14411
   129
paulson@14411
   130
lemma log_less_cancel_iff [simp]:
paulson@14411
   131
     "[| 1 < a; 0 < x; 0 < y |] ==> (log a x < log a y) = (x < y)"
paulson@14411
   132
apply safe
paulson@14411
   133
apply (rule_tac [2] powr_less_cancel)
paulson@14411
   134
apply (drule_tac a = "log a x" in powr_less_mono, auto)
paulson@14411
   135
done
paulson@14411
   136
paulson@14411
   137
lemma log_le_cancel_iff [simp]:
paulson@14411
   138
     "[| 1 < a; 0 < x; 0 < y |] ==> (log a x \<le> log a y) = (x \<le> y)"
paulson@14411
   139
by (simp add: linorder_not_less [symmetric])
paulson@14411
   140
paulson@14411
   141
paulson@15085
   142
lemma powr_realpow: "0 < x ==> x powr (real n) = x^n"
paulson@15085
   143
  apply (induct n, simp)
paulson@15085
   144
  apply (subgoal_tac "real(Suc n) = real n + 1")
paulson@15085
   145
  apply (erule ssubst)
paulson@15085
   146
  apply (subst powr_add, simp, simp)
paulson@15085
   147
done
paulson@15085
   148
paulson@15085
   149
lemma powr_realpow2: "0 <= x ==> 0 < n ==> x^n = (if (x = 0) then 0
paulson@15085
   150
  else x powr (real n))"
paulson@15085
   151
  apply (case_tac "x = 0", simp, simp)
paulson@15085
   152
  apply (rule powr_realpow [THEN sym], simp)
paulson@15085
   153
done
paulson@15085
   154
paulson@15085
   155
lemma ln_pwr: "0 < x ==> 0 < y ==> ln(x powr y) = y * ln x"
paulson@15085
   156
by (unfold powr_def, simp)
paulson@15085
   157
paulson@15085
   158
lemma ln_bound: "1 <= x ==> ln x <= x"
paulson@15085
   159
  apply (subgoal_tac "ln(1 + (x - 1)) <= x - 1")
paulson@15085
   160
  apply simp
paulson@15085
   161
  apply (rule ln_add_one_self_le_self, simp)
paulson@15085
   162
done
paulson@15085
   163
paulson@15085
   164
lemma powr_mono: "a <= b ==> 1 <= x ==> x powr a <= x powr b"
paulson@15085
   165
  apply (case_tac "x = 1", simp)
paulson@15085
   166
  apply (case_tac "a = b", simp)
paulson@15085
   167
  apply (rule order_less_imp_le)
paulson@15085
   168
  apply (rule powr_less_mono, auto)
paulson@15085
   169
done
paulson@15085
   170
paulson@15085
   171
lemma ge_one_powr_ge_zero: "1 <= x ==> 0 <= a ==> 1 <= x powr a"
paulson@15085
   172
  apply (subst powr_zero_eq_one [THEN sym])
paulson@15085
   173
  apply (rule powr_mono, assumption+)
paulson@15085
   174
done
paulson@15085
   175
paulson@15085
   176
lemma powr_less_mono2: "0 < a ==> 0 < x ==> x < y ==> x powr a <
paulson@15085
   177
    y powr a"
paulson@15085
   178
  apply (unfold powr_def)
paulson@15085
   179
  apply (rule exp_less_mono)
paulson@15085
   180
  apply (rule mult_strict_left_mono)
paulson@15085
   181
  apply (subst ln_less_cancel_iff, assumption)
paulson@15085
   182
  apply (rule order_less_trans)
paulson@15085
   183
  prefer 2
paulson@15085
   184
  apply assumption+
paulson@15085
   185
done
paulson@15085
   186
avigad@16819
   187
lemma powr_less_mono2_neg: "a < 0 ==> 0 < x ==> x < y ==> y powr a <
avigad@16819
   188
    x powr a"
avigad@16819
   189
  apply (unfold powr_def)
avigad@16819
   190
  apply (rule exp_less_mono)
avigad@16819
   191
  apply (rule mult_strict_left_mono_neg)
avigad@16819
   192
  apply (subst ln_less_cancel_iff)
avigad@16819
   193
  apply assumption
avigad@16819
   194
  apply (rule order_less_trans)
avigad@16819
   195
  prefer 2
avigad@16819
   196
  apply assumption+
avigad@16819
   197
done
avigad@16819
   198
avigad@16819
   199
lemma powr_mono2: "0 <= a ==> 0 < x ==> x <= y ==> x powr a <= y powr a"
paulson@15085
   200
  apply (case_tac "a = 0", simp)
paulson@15085
   201
  apply (case_tac "x = y", simp)
paulson@15085
   202
  apply (rule order_less_imp_le)
paulson@15085
   203
  apply (rule powr_less_mono2, auto)
paulson@15085
   204
done
paulson@15085
   205
avigad@16819
   206
lemma ln_powr_bound: "1 <= x ==> 0 < a ==> ln x <= (x powr a) / a"
avigad@16819
   207
  apply (rule mult_imp_le_div_pos)
avigad@16819
   208
  apply (assumption)
avigad@16819
   209
  apply (subst mult_commute)
avigad@16819
   210
  apply (subst ln_pwr [THEN sym])
avigad@16819
   211
  apply auto
avigad@16819
   212
  apply (rule ln_bound)
avigad@16819
   213
  apply (erule ge_one_powr_ge_zero)
avigad@16819
   214
  apply (erule order_less_imp_le)
avigad@16819
   215
done
avigad@16819
   216
avigad@16819
   217
lemma ln_powr_bound2: "1 < x ==> 0 < a ==> (ln x) powr a <= (a powr a) * x"
avigad@16819
   218
proof -
avigad@16819
   219
  assume "1 < x" and "0 < a"
avigad@16819
   220
  then have "ln x <= (x powr (1 / a)) / (1 / a)"
avigad@16819
   221
    apply (intro ln_powr_bound)
avigad@16819
   222
    apply (erule order_less_imp_le)
avigad@16819
   223
    apply (rule divide_pos_pos)
avigad@16819
   224
    apply simp_all
avigad@16819
   225
    done
avigad@16819
   226
  also have "... = a * (x powr (1 / a))"
avigad@16819
   227
    by simp
avigad@16819
   228
  finally have "(ln x) powr a <= (a * (x powr (1 / a))) powr a"
avigad@16819
   229
    apply (intro powr_mono2)
avigad@16819
   230
    apply (rule order_less_imp_le, rule prems)
avigad@16819
   231
    apply (rule ln_gt_zero)
avigad@16819
   232
    apply (rule prems)
avigad@16819
   233
    apply assumption
avigad@16819
   234
    done
avigad@16819
   235
  also have "... = (a powr a) * ((x powr (1 / a)) powr a)"
avigad@16819
   236
    apply (rule powr_mult)
avigad@16819
   237
    apply (rule prems)
avigad@16819
   238
    apply (rule powr_gt_zero)
avigad@16819
   239
    done
avigad@16819
   240
  also have "(x powr (1 / a)) powr a = x powr ((1 / a) * a)"
avigad@16819
   241
    by (rule powr_powr)
avigad@16819
   242
  also have "... = x"
avigad@16819
   243
    apply simp
avigad@16819
   244
    apply (subgoal_tac "a ~= 0")
avigad@16819
   245
    apply (insert prems, auto)
avigad@16819
   246
    done
avigad@16819
   247
  finally show ?thesis .
avigad@16819
   248
qed
avigad@16819
   249
avigad@16819
   250
lemma LIMSEQ_neg_powr: "0 < s ==> (%x. (real x) powr - s) ----> 0"
avigad@16819
   251
  apply (unfold LIMSEQ_def)
avigad@16819
   252
  apply clarsimp
avigad@16819
   253
  apply (rule_tac x = "natfloor(r powr (1 / - s)) + 1" in exI)
avigad@16819
   254
  apply clarify
avigad@16819
   255
  proof -
avigad@16819
   256
    fix r fix n
avigad@16819
   257
    assume "0 < s" and "0 < r" and "natfloor (r powr (1 / - s)) + 1 <= n"
avigad@16819
   258
    have "r powr (1 / - s) < real(natfloor(r powr (1 / - s))) + 1"
avigad@16819
   259
      by (rule real_natfloor_add_one_gt)
avigad@16819
   260
    also have "... = real(natfloor(r powr (1 / -s)) + 1)"
avigad@16819
   261
      by simp
avigad@16819
   262
    also have "... <= real n"
avigad@16819
   263
      apply (subst real_of_nat_le_iff)
avigad@16819
   264
      apply (rule prems)
avigad@16819
   265
      done
avigad@16819
   266
    finally have "r powr (1 / - s) < real n".
avigad@16819
   267
    then have "real n powr (- s) < (r powr (1 / - s)) powr - s" 
avigad@16819
   268
      apply (intro powr_less_mono2_neg)
avigad@16819
   269
      apply (auto simp add: prems)
avigad@16819
   270
      done
avigad@16819
   271
    also have "... = r"
avigad@16819
   272
      by (simp add: powr_powr prems less_imp_neq [THEN not_sym])
avigad@16819
   273
    finally show "real n powr - s < r" .
avigad@16819
   274
  qed
avigad@16819
   275
paulson@12224
   276
end