src/HOL/Ln.thy
author huffman
Sun Apr 01 16:09:58 2012 +0200 (2012-04-01)
changeset 47255 30a1692557b0
parent 47244 a7f85074c169
child 50326 b5afeccab2db
permissions -rw-r--r--
removed Nat_Numeral.thy, moving all theorems elsewhere
wenzelm@41959
     1
(*  Title:      HOL/Ln.thy
avigad@16959
     2
    Author:     Jeremy Avigad
avigad@16959
     3
*)
avigad@16959
     4
avigad@16959
     5
header {* Properties of ln *}
avigad@16959
     6
avigad@16959
     7
theory Ln
avigad@16959
     8
imports Transcendental
avigad@16959
     9
begin
avigad@16959
    10
avigad@16959
    11
lemma exp_first_two_terms: "exp x = 1 + x + suminf (%n. 
nipkow@40864
    12
  inverse(fact (n+2)) * (x ^ (n+2)))"
avigad@16959
    13
proof -
nipkow@40864
    14
  have "exp x = suminf (%n. inverse(fact n) * (x ^ n))"
wenzelm@19765
    15
    by (simp add: exp_def)
nipkow@40864
    16
  also from summable_exp have "... = (SUM n::nat : {0..<2}. 
nipkow@40864
    17
      inverse(fact n) * (x ^ n)) + suminf (%n.
nipkow@40864
    18
      inverse(fact(n+2)) * (x ^ (n+2)))" (is "_ = ?a + _")
avigad@16959
    19
    by (rule suminf_split_initial_segment)
avigad@16959
    20
  also have "?a = 1 + x"
huffman@44289
    21
    by (simp add: numeral_2_eq_2)
avigad@16959
    22
  finally show ?thesis .
avigad@16959
    23
qed
avigad@16959
    24
huffman@23114
    25
lemma exp_bound: "0 <= (x::real) ==> x <= 1 ==> exp x <= 1 + x + x^2"
avigad@16959
    26
proof -
avigad@16959
    27
  assume a: "0 <= x"
avigad@16959
    28
  assume b: "x <= 1"
huffman@47244
    29
  { fix n :: nat
huffman@47244
    30
    have "2 * 2 ^ n \<le> fact (n + 2)"
huffman@47244
    31
      by (induct n, simp, simp)
huffman@47244
    32
    hence "real ((2::nat) * 2 ^ n) \<le> real (fact (n + 2))"
huffman@47244
    33
      by (simp only: real_of_nat_le_iff)
huffman@47244
    34
    hence "2 * 2 ^ n \<le> real (fact (n + 2))"
huffman@47244
    35
      by simp
huffman@47244
    36
    hence "inverse (fact (n + 2)) \<le> inverse (2 * 2 ^ n)"
huffman@47244
    37
      by (rule le_imp_inverse_le) simp
huffman@47244
    38
    hence "inverse (fact (n + 2)) \<le> 1/2 * (1/2)^n"
huffman@47244
    39
      by (simp add: inverse_mult_distrib power_inverse)
huffman@47244
    40
    hence "inverse (fact (n + 2)) * (x^n * x\<twosuperior>) \<le> 1/2 * (1/2)^n * (1 * x\<twosuperior>)"
huffman@47244
    41
      by (rule mult_mono)
huffman@47244
    42
        (rule mult_mono, simp_all add: power_le_one a b mult_nonneg_nonneg)
huffman@47244
    43
    hence "inverse (fact (n + 2)) * x ^ (n + 2) \<le> (x\<twosuperior>/2) * ((1/2)^n)"
huffman@47244
    44
      unfolding power_add by (simp add: mult_ac del: fact_Suc) }
huffman@47244
    45
  note aux1 = this
huffman@47244
    46
  have "(\<lambda>n. x\<twosuperior> / 2 * (1 / 2) ^ n) sums (x\<twosuperior> / 2 * (1 / (1 - 1 / 2)))"
huffman@47244
    47
    by (intro sums_mult geometric_sums, simp)
huffman@47244
    48
  hence aux2: "(\<lambda>n. (x::real) ^ 2 / 2 * (1 / 2) ^ n) sums x^2"
huffman@47244
    49
    by simp
huffman@47244
    50
  have "suminf (%n. inverse(fact (n+2)) * (x ^ (n+2))) <= x^2"
avigad@16959
    51
  proof -
nipkow@40864
    52
    have "suminf (%n. inverse(fact (n+2)) * (x ^ (n+2))) <=
avigad@16959
    53
        suminf (%n. (x^2/2) * ((1/2)^n))"
avigad@16959
    54
      apply (rule summable_le)
huffman@47244
    55
      apply (rule allI, rule aux1)
huffman@47244
    56
      apply (rule summable_exp [THEN summable_ignore_initial_segment])
huffman@47244
    57
      by (rule sums_summable, rule aux2)
avigad@16959
    58
    also have "... = x^2"
avigad@16959
    59
      by (rule sums_unique [THEN sym], rule aux2)
avigad@16959
    60
    finally show ?thesis .
avigad@16959
    61
  qed
huffman@47244
    62
  thus ?thesis unfolding exp_first_two_terms by auto
avigad@16959
    63
qed
avigad@16959
    64
huffman@47244
    65
lemma ln_one_plus_pos_lower_bound: "0 <= x ==> x <= 1 ==> 
huffman@47244
    66
    x - x^2 <= ln (1 + x)"
avigad@16959
    67
proof -
avigad@16959
    68
  assume a: "0 <= x" and b: "x <= 1"
avigad@16959
    69
  have "exp (x - x^2) = exp x / exp (x^2)"
avigad@16959
    70
    by (rule exp_diff)
avigad@16959
    71
  also have "... <= (1 + x + x^2) / exp (x ^2)"
avigad@16959
    72
    apply (rule divide_right_mono) 
avigad@16959
    73
    apply (rule exp_bound)
avigad@16959
    74
    apply (rule a, rule b)
avigad@16959
    75
    apply simp
avigad@16959
    76
    done
avigad@16959
    77
  also have "... <= (1 + x + x^2) / (1 + x^2)"
avigad@16959
    78
    apply (rule divide_left_mono)
huffman@47244
    79
    apply (simp add: exp_ge_add_one_self_aux)
huffman@47244
    80
    apply (simp add: a)
huffman@47244
    81
    apply (simp add: mult_pos_pos add_pos_nonneg)
avigad@16959
    82
    done
avigad@16959
    83
  also from a have "... <= 1 + x"
huffman@44289
    84
    by (simp add: field_simps add_strict_increasing zero_le_mult_iff)
huffman@47244
    85
  finally have "exp (x - x^2) <= 1 + x" .
avigad@16959
    86
  also have "... = exp (ln (1 + x))"
avigad@16959
    87
  proof -
avigad@16959
    88
    from a have "0 < 1 + x" by auto
avigad@16959
    89
    thus ?thesis
avigad@16959
    90
      by (auto simp only: exp_ln_iff [THEN sym])
avigad@16959
    91
  qed
avigad@16959
    92
  finally have "exp (x - x ^ 2) <= exp (ln (1 + x))" .
avigad@16959
    93
  thus ?thesis by (auto simp only: exp_le_cancel_iff)
avigad@16959
    94
qed
avigad@16959
    95
avigad@16959
    96
lemma ln_one_minus_pos_upper_bound: "0 <= x ==> x < 1 ==> ln (1 - x) <= - x"
avigad@16959
    97
proof -
avigad@16959
    98
  assume a: "0 <= (x::real)" and b: "x < 1"
avigad@16959
    99
  have "(1 - x) * (1 + x + x^2) = (1 - x^3)"
nipkow@29667
   100
    by (simp add: algebra_simps power2_eq_square power3_eq_cube)
avigad@16959
   101
  also have "... <= 1"
nipkow@25875
   102
    by (auto simp add: a)
avigad@16959
   103
  finally have "(1 - x) * (1 + x + x ^ 2) <= 1" .
huffman@47244
   104
  moreover have c: "0 < 1 + x + x\<twosuperior>"
huffman@47244
   105
    by (simp add: add_pos_nonneg a)
avigad@16959
   106
  ultimately have "1 - x <= 1 / (1 + x + x^2)"
avigad@16959
   107
    by (elim mult_imp_le_div_pos)
avigad@16959
   108
  also have "... <= 1 / exp x"
avigad@16959
   109
    apply (rule divide_left_mono)
avigad@16959
   110
    apply (rule exp_bound, rule a)
huffman@47244
   111
    apply (rule b [THEN less_imp_le])
huffman@47244
   112
    apply simp
avigad@16959
   113
    apply (rule mult_pos_pos)
huffman@47244
   114
    apply (rule c)
huffman@47244
   115
    apply simp
avigad@16959
   116
    done
avigad@16959
   117
  also have "... = exp (-x)"
huffman@36777
   118
    by (auto simp add: exp_minus divide_inverse)
avigad@16959
   119
  finally have "1 - x <= exp (- x)" .
avigad@16959
   120
  also have "1 - x = exp (ln (1 - x))"
avigad@16959
   121
  proof -
avigad@16959
   122
    have "0 < 1 - x"
avigad@16959
   123
      by (insert b, auto)
avigad@16959
   124
    thus ?thesis
avigad@16959
   125
      by (auto simp only: exp_ln_iff [THEN sym])
avigad@16959
   126
  qed
avigad@16959
   127
  finally have "exp (ln (1 - x)) <= exp (- x)" .
avigad@16959
   128
  thus ?thesis by (auto simp only: exp_le_cancel_iff)
avigad@16959
   129
qed
avigad@16959
   130
avigad@16959
   131
lemma aux5: "x < 1 ==> ln(1 - x) = - ln(1 + x / (1 - x))"
avigad@16959
   132
proof -
avigad@16959
   133
  assume a: "x < 1"
avigad@16959
   134
  have "ln(1 - x) = - ln(1 / (1 - x))"
avigad@16959
   135
  proof -
avigad@16959
   136
    have "ln(1 - x) = - (- ln (1 - x))"
avigad@16959
   137
      by auto
avigad@16959
   138
    also have "- ln(1 - x) = ln 1 - ln(1 - x)"
avigad@16959
   139
      by simp
avigad@16959
   140
    also have "... = ln(1 / (1 - x))"
avigad@16959
   141
      apply (rule ln_div [THEN sym])
avigad@16959
   142
      by (insert a, auto)
avigad@16959
   143
    finally show ?thesis .
avigad@16959
   144
  qed
nipkow@23482
   145
  also have " 1 / (1 - x) = 1 + x / (1 - x)" using a by(simp add:field_simps)
avigad@16959
   146
  finally show ?thesis .
avigad@16959
   147
qed
avigad@16959
   148
avigad@16959
   149
lemma ln_one_minus_pos_lower_bound: "0 <= x ==> x <= (1 / 2) ==> 
avigad@16959
   150
    - x - 2 * x^2 <= ln (1 - x)"
avigad@16959
   151
proof -
avigad@16959
   152
  assume a: "0 <= x" and b: "x <= (1 / 2)"
avigad@16959
   153
  from b have c: "x < 1"
avigad@16959
   154
    by auto
avigad@16959
   155
  then have "ln (1 - x) = - ln (1 + x / (1 - x))"
avigad@16959
   156
    by (rule aux5)
avigad@16959
   157
  also have "- (x / (1 - x)) <= ..."
avigad@16959
   158
  proof - 
avigad@16959
   159
    have "ln (1 + x / (1 - x)) <= x / (1 - x)"
avigad@16959
   160
      apply (rule ln_add_one_self_le_self)
avigad@16959
   161
      apply (rule divide_nonneg_pos)
avigad@16959
   162
      by (insert a c, auto) 
avigad@16959
   163
    thus ?thesis
avigad@16959
   164
      by auto
avigad@16959
   165
  qed
avigad@16959
   166
  also have "- (x / (1 - x)) = -x / (1 - x)"
avigad@16959
   167
    by auto
avigad@16959
   168
  finally have d: "- x / (1 - x) <= ln (1 - x)" .
wenzelm@41550
   169
  have "0 < 1 - x" using a b by simp
nipkow@23482
   170
  hence e: "-x - 2 * x^2 <= - x / (1 - x)"
wenzelm@41550
   171
    using mult_right_le_one_le[of "x*x" "2*x"] a b
wenzelm@41550
   172
    by (simp add:field_simps power2_eq_square)
avigad@16959
   173
  from e d show "- x - 2 * x^2 <= ln (1 - x)"
avigad@16959
   174
    by (rule order_trans)
avigad@16959
   175
qed
avigad@16959
   176
huffman@23114
   177
lemma exp_ge_add_one_self [simp]: "1 + (x::real) <= exp x"
avigad@16959
   178
  apply (case_tac "0 <= x")
avigad@17013
   179
  apply (erule exp_ge_add_one_self_aux)
avigad@16959
   180
  apply (case_tac "x <= -1")
avigad@16959
   181
  apply (subgoal_tac "1 + x <= 0")
avigad@16959
   182
  apply (erule order_trans)
avigad@16959
   183
  apply simp
avigad@16959
   184
  apply simp
avigad@16959
   185
  apply (subgoal_tac "1 + x = exp(ln (1 + x))")
avigad@16959
   186
  apply (erule ssubst)
avigad@16959
   187
  apply (subst exp_le_cancel_iff)
avigad@16959
   188
  apply (subgoal_tac "ln (1 - (- x)) <= - (- x)")
avigad@16959
   189
  apply simp
avigad@16959
   190
  apply (rule ln_one_minus_pos_upper_bound) 
avigad@16959
   191
  apply auto
avigad@16959
   192
done
avigad@16959
   193
avigad@16959
   194
lemma ln_add_one_self_le_self2: "-1 < x ==> ln(1 + x) <= x"
huffman@47244
   195
  apply (subgoal_tac "ln (1 + x) \<le> ln (exp x)", simp)
avigad@16959
   196
  apply (subst ln_le_cancel_iff)
avigad@16959
   197
  apply auto
avigad@16959
   198
done
avigad@16959
   199
avigad@16959
   200
lemma abs_ln_one_plus_x_minus_x_bound_nonneg:
avigad@16959
   201
    "0 <= x ==> x <= 1 ==> abs(ln (1 + x) - x) <= x^2"
avigad@16959
   202
proof -
huffman@23441
   203
  assume x: "0 <= x"
wenzelm@41550
   204
  assume x1: "x <= 1"
huffman@23441
   205
  from x have "ln (1 + x) <= x"
avigad@16959
   206
    by (rule ln_add_one_self_le_self)
avigad@16959
   207
  then have "ln (1 + x) - x <= 0" 
avigad@16959
   208
    by simp
avigad@16959
   209
  then have "abs(ln(1 + x) - x) = - (ln(1 + x) - x)"
avigad@16959
   210
    by (rule abs_of_nonpos)
avigad@16959
   211
  also have "... = x - ln (1 + x)" 
avigad@16959
   212
    by simp
avigad@16959
   213
  also have "... <= x^2"
avigad@16959
   214
  proof -
wenzelm@41550
   215
    from x x1 have "x - x^2 <= ln (1 + x)"
avigad@16959
   216
      by (intro ln_one_plus_pos_lower_bound)
avigad@16959
   217
    thus ?thesis
avigad@16959
   218
      by simp
avigad@16959
   219
  qed
avigad@16959
   220
  finally show ?thesis .
avigad@16959
   221
qed
avigad@16959
   222
avigad@16959
   223
lemma abs_ln_one_plus_x_minus_x_bound_nonpos:
avigad@16959
   224
    "-(1 / 2) <= x ==> x <= 0 ==> abs(ln (1 + x) - x) <= 2 * x^2"
avigad@16959
   225
proof -
wenzelm@41550
   226
  assume a: "-(1 / 2) <= x"
wenzelm@41550
   227
  assume b: "x <= 0"
avigad@16959
   228
  have "abs(ln (1 + x) - x) = x - ln(1 - (-x))" 
avigad@16959
   229
    apply (subst abs_of_nonpos)
avigad@16959
   230
    apply simp
avigad@16959
   231
    apply (rule ln_add_one_self_le_self2)
wenzelm@41550
   232
    using a apply auto
avigad@16959
   233
    done
avigad@16959
   234
  also have "... <= 2 * x^2"
avigad@16959
   235
    apply (subgoal_tac "- (-x) - 2 * (-x)^2 <= ln (1 - (-x))")
nipkow@29667
   236
    apply (simp add: algebra_simps)
avigad@16959
   237
    apply (rule ln_one_minus_pos_lower_bound)
wenzelm@41550
   238
    using a b apply auto
nipkow@29667
   239
    done
avigad@16959
   240
  finally show ?thesis .
avigad@16959
   241
qed
avigad@16959
   242
avigad@16959
   243
lemma abs_ln_one_plus_x_minus_x_bound:
avigad@16959
   244
    "abs x <= 1 / 2 ==> abs(ln (1 + x) - x) <= 2 * x^2"
avigad@16959
   245
  apply (case_tac "0 <= x")
avigad@16959
   246
  apply (rule order_trans)
avigad@16959
   247
  apply (rule abs_ln_one_plus_x_minus_x_bound_nonneg)
avigad@16959
   248
  apply auto
avigad@16959
   249
  apply (rule abs_ln_one_plus_x_minus_x_bound_nonpos)
avigad@16959
   250
  apply auto
avigad@16959
   251
done
avigad@16959
   252
avigad@16959
   253
lemma ln_x_over_x_mono: "exp 1 <= x ==> x <= y ==> (ln y / y) <= (ln x / x)"  
avigad@16959
   254
proof -
wenzelm@41550
   255
  assume x: "exp 1 <= x" "x <= y"
huffman@44289
   256
  moreover have "0 < exp (1::real)" by simp
huffman@44289
   257
  ultimately have a: "0 < x" and b: "0 < y"
huffman@44289
   258
    by (fast intro: less_le_trans order_trans)+
avigad@16959
   259
  have "x * ln y - x * ln x = x * (ln y - ln x)"
nipkow@29667
   260
    by (simp add: algebra_simps)
avigad@16959
   261
  also have "... = x * ln(y / x)"
huffman@44289
   262
    by (simp only: ln_div a b)
avigad@16959
   263
  also have "y / x = (x + (y - x)) / x"
avigad@16959
   264
    by simp
huffman@44289
   265
  also have "... = 1 + (y - x) / x"
huffman@44289
   266
    using x a by (simp add: field_simps)
avigad@16959
   267
  also have "x * ln(1 + (y - x) / x) <= x * ((y - x) / x)"
avigad@16959
   268
    apply (rule mult_left_mono)
avigad@16959
   269
    apply (rule ln_add_one_self_le_self)
avigad@16959
   270
    apply (rule divide_nonneg_pos)
wenzelm@41550
   271
    using x a apply simp_all
avigad@16959
   272
    done
nipkow@23482
   273
  also have "... = y - x" using a by simp
nipkow@23482
   274
  also have "... = (y - x) * ln (exp 1)" by simp
avigad@16959
   275
  also have "... <= (y - x) * ln x"
avigad@16959
   276
    apply (rule mult_left_mono)
avigad@16959
   277
    apply (subst ln_le_cancel_iff)
huffman@44289
   278
    apply fact
avigad@16959
   279
    apply (rule a)
wenzelm@41550
   280
    apply (rule x)
wenzelm@41550
   281
    using x apply simp
avigad@16959
   282
    done
avigad@16959
   283
  also have "... = y * ln x - x * ln x"
avigad@16959
   284
    by (rule left_diff_distrib)
avigad@16959
   285
  finally have "x * ln y <= y * ln x"
avigad@16959
   286
    by arith
wenzelm@41550
   287
  then have "ln y <= (y * ln x) / x" using a by (simp add: field_simps)
wenzelm@41550
   288
  also have "... = y * (ln x / x)" by simp
wenzelm@41550
   289
  finally show ?thesis using b by (simp add: field_simps)
avigad@16959
   290
qed
avigad@16959
   291
hoelzl@43336
   292
lemma ln_le_minus_one:
hoelzl@43336
   293
  "0 < x \<Longrightarrow> ln x \<le> x - 1"
hoelzl@43336
   294
  using exp_ge_add_one_self[of "ln x"] by simp
hoelzl@43336
   295
hoelzl@43336
   296
lemma ln_eq_minus_one:
hoelzl@43336
   297
  assumes "0 < x" "ln x = x - 1" shows "x = 1"
hoelzl@43336
   298
proof -
hoelzl@43336
   299
  let "?l y" = "ln y - y + 1"
hoelzl@43336
   300
  have D: "\<And>x. 0 < x \<Longrightarrow> DERIV ?l x :> (1 / x - 1)"
hoelzl@43336
   301
    by (auto intro!: DERIV_intros)
hoelzl@43336
   302
hoelzl@43336
   303
  show ?thesis
hoelzl@43336
   304
  proof (cases rule: linorder_cases)
hoelzl@43336
   305
    assume "x < 1"
hoelzl@43336
   306
    from dense[OF `x < 1`] obtain a where "x < a" "a < 1" by blast
hoelzl@43336
   307
    from `x < a` have "?l x < ?l a"
hoelzl@43336
   308
    proof (rule DERIV_pos_imp_increasing, safe)
hoelzl@43336
   309
      fix y assume "x \<le> y" "y \<le> a"
hoelzl@43336
   310
      with `0 < x` `a < 1` have "0 < 1 / y - 1" "0 < y"
hoelzl@43336
   311
        by (auto simp: field_simps)
hoelzl@43336
   312
      with D show "\<exists>z. DERIV ?l y :> z \<and> 0 < z"
hoelzl@43336
   313
        by auto
hoelzl@43336
   314
    qed
hoelzl@43336
   315
    also have "\<dots> \<le> 0"
hoelzl@43336
   316
      using ln_le_minus_one `0 < x` `x < a` by (auto simp: field_simps)
hoelzl@43336
   317
    finally show "x = 1" using assms by auto
hoelzl@43336
   318
  next
hoelzl@43336
   319
    assume "1 < x"
hoelzl@43336
   320
    from dense[OF `1 < x`] obtain a where "1 < a" "a < x" by blast
hoelzl@43336
   321
    from `a < x` have "?l x < ?l a"
hoelzl@43336
   322
    proof (rule DERIV_neg_imp_decreasing, safe)
hoelzl@43336
   323
      fix y assume "a \<le> y" "y \<le> x"
hoelzl@43336
   324
      with `1 < a` have "1 / y - 1 < 0" "0 < y"
hoelzl@43336
   325
        by (auto simp: field_simps)
hoelzl@43336
   326
      with D show "\<exists>z. DERIV ?l y :> z \<and> z < 0"
hoelzl@43336
   327
        by blast
hoelzl@43336
   328
    qed
hoelzl@43336
   329
    also have "\<dots> \<le> 0"
hoelzl@43336
   330
      using ln_le_minus_one `1 < a` by (auto simp: field_simps)
hoelzl@43336
   331
    finally show "x = 1" using assms by auto
hoelzl@43336
   332
  qed simp
hoelzl@43336
   333
qed
hoelzl@43336
   334
avigad@16959
   335
end