/
Basic.lean
608 lines (493 loc) Β· 23.7 KB
/
Basic.lean
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
/-
Copyright (c) 2018 Chris Hughes. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Chris Hughes, Abhimanyu Pallavi Sudhir, Jean Lo, Calle SΓΆnne
-/
import Mathlib.Analysis.SpecialFunctions.Exp
import Mathlib.Data.Nat.Factorization.Basic
import Mathlib.Analysis.NormedSpace.Real
#align_import analysis.special_functions.log.basic from "leanprover-community/mathlib"@"f23a09ce6d3f367220dc3cecad6b7eb69eb01690"
/-!
# Real logarithm
In this file we define `Real.log` to be the logarithm of a real number. As usual, we extend it from
its domain `(0, +β)` to a globally defined function. We choose to do it so that `log 0 = 0` and
`log (-x) = log x`.
We prove some basic properties of this function and show that it is continuous.
## Tags
logarithm, continuity
-/
open Set Filter Function
open Topology
noncomputable section
namespace Real
variable {x y : β}
/-- The real logarithm function, equal to the inverse of the exponential for `x > 0`,
to `log |x|` for `x < 0`, and to `0` for `0`. We use this unconventional extension to
`(-β, 0]` as it gives the formula `log (x * y) = log x + log y` for all nonzero `x` and `y`, and
the derivative of `log` is `1/x` away from `0`. -/
-- @[pp_nodot] -- Porting note: removed
noncomputable def log (x : β) : β :=
if hx : x = 0 then 0 else expOrderIso.symm β¨|x|, abs_pos.2 hxβ©
#align real.log Real.log
theorem log_of_ne_zero (hx : x β 0) : log x = expOrderIso.symm β¨|x|, abs_pos.2 hxβ© :=
dif_neg hx
#align real.log_of_ne_zero Real.log_of_ne_zero
theorem log_of_pos (hx : 0 < x) : log x = expOrderIso.symm β¨x, hxβ© := by
rw [log_of_ne_zero hx.ne']
congr
exact abs_of_pos hx
#align real.log_of_pos Real.log_of_pos
theorem exp_log_eq_abs (hx : x β 0) : exp (log x) = |x| := by
rw [log_of_ne_zero hx, β coe_expOrderIso_apply, OrderIso.apply_symm_apply, Subtype.coe_mk]
#align real.exp_log_eq_abs Real.exp_log_eq_abs
theorem exp_log (hx : 0 < x) : exp (log x) = x := by
rw [exp_log_eq_abs hx.ne']
exact abs_of_pos hx
#align real.exp_log Real.exp_log
theorem exp_log_of_neg (hx : x < 0) : exp (log x) = -x := by
rw [exp_log_eq_abs (ne_of_lt hx)]
exact abs_of_neg hx
#align real.exp_log_of_neg Real.exp_log_of_neg
theorem le_exp_log (x : β) : x β€ exp (log x) := by
by_cases h_zero : x = 0
Β· rw [h_zero, log, dif_pos rfl, exp_zero]
exact zero_le_one
Β· rw [exp_log_eq_abs h_zero]
exact le_abs_self _
#align real.le_exp_log Real.le_exp_log
@[simp]
theorem log_exp (x : β) : log (exp x) = x :=
exp_injective <| exp_log (exp_pos x)
#align real.log_exp Real.log_exp
theorem surjOn_log : SurjOn log (Ioi 0) univ := fun x _ => β¨exp x, exp_pos x, log_exp xβ©
#align real.surj_on_log Real.surjOn_log
theorem log_surjective : Surjective log := fun x => β¨exp x, log_exp xβ©
#align real.log_surjective Real.log_surjective
@[simp]
theorem range_log : range log = univ :=
log_surjective.range_eq
#align real.range_log Real.range_log
@[simp]
theorem log_zero : log 0 = 0 :=
dif_pos rfl
#align real.log_zero Real.log_zero
@[simp]
theorem log_one : log 1 = 0 :=
exp_injective <| by rw [exp_log zero_lt_one, exp_zero]
#align real.log_one Real.log_one
@[simp]
theorem log_abs (x : β) : log |x| = log x := by
by_cases h : x = 0
Β· simp [h]
Β· rw [β exp_eq_exp, exp_log_eq_abs h, exp_log_eq_abs (abs_pos.2 h).ne', abs_abs]
#align real.log_abs Real.log_abs
@[simp]
theorem log_neg_eq_log (x : β) : log (-x) = log x := by rw [β log_abs x, β log_abs (-x), abs_neg]
#align real.log_neg_eq_log Real.log_neg_eq_log
theorem sinh_log {x : β} (hx : 0 < x) : sinh (log x) = (x - xβ»ΒΉ) / 2 := by
rw [sinh_eq, exp_neg, exp_log hx]
#align real.sinh_log Real.sinh_log
theorem cosh_log {x : β} (hx : 0 < x) : cosh (log x) = (x + xβ»ΒΉ) / 2 := by
rw [cosh_eq, exp_neg, exp_log hx]
#align real.cosh_log Real.cosh_log
theorem surjOn_log' : SurjOn log (Iio 0) univ := fun x _ =>
β¨-exp x, neg_lt_zero.2 <| exp_pos x, by rw [log_neg_eq_log, log_exp]β©
#align real.surj_on_log' Real.surjOn_log'
theorem log_mul (hx : x β 0) (hy : y β 0) : log (x * y) = log x + log y :=
exp_injective <| by
rw [exp_log_eq_abs (mul_ne_zero hx hy), exp_add, exp_log_eq_abs hx, exp_log_eq_abs hy, abs_mul]
#align real.log_mul Real.log_mul
theorem log_div (hx : x β 0) (hy : y β 0) : log (x / y) = log x - log y :=
exp_injective <| by
rw [exp_log_eq_abs (div_ne_zero hx hy), exp_sub, exp_log_eq_abs hx, exp_log_eq_abs hy, abs_div]
#align real.log_div Real.log_div
@[simp]
theorem log_inv (x : β) : log xβ»ΒΉ = -log x := by
by_cases hx : x = 0; Β· simp [hx]
rw [β exp_eq_exp, exp_log_eq_abs (inv_ne_zero hx), exp_neg, exp_log_eq_abs hx, abs_inv]
#align real.log_inv Real.log_inv
theorem log_le_log_iff (h : 0 < x) (hβ : 0 < y) : log x β€ log y β x β€ y := by
rw [β exp_le_exp, exp_log h, exp_log hβ]
#align real.log_le_log Real.log_le_log_iff
@[gcongr]
lemma log_le_log (hx : 0 < x) (hxy : x β€ y) : log x β€ log y :=
(log_le_log_iff hx (hx.trans_le hxy)).2 hxy
@[gcongr]
theorem log_lt_log (hx : 0 < x) (h : x < y) : log x < log y := by
rwa [β exp_lt_exp, exp_log hx, exp_log (lt_trans hx h)]
#align real.log_lt_log Real.log_lt_log
theorem log_lt_log_iff (hx : 0 < x) (hy : 0 < y) : log x < log y β x < y := by
rw [β exp_lt_exp, exp_log hx, exp_log hy]
#align real.log_lt_log_iff Real.log_lt_log_iff
theorem log_le_iff_le_exp (hx : 0 < x) : log x β€ y β x β€ exp y := by rw [β exp_le_exp, exp_log hx]
#align real.log_le_iff_le_exp Real.log_le_iff_le_exp
theorem log_lt_iff_lt_exp (hx : 0 < x) : log x < y β x < exp y := by rw [β exp_lt_exp, exp_log hx]
#align real.log_lt_iff_lt_exp Real.log_lt_iff_lt_exp
theorem le_log_iff_exp_le (hy : 0 < y) : x β€ log y β exp x β€ y := by rw [β exp_le_exp, exp_log hy]
#align real.le_log_iff_exp_le Real.le_log_iff_exp_le
theorem lt_log_iff_exp_lt (hy : 0 < y) : x < log y β exp x < y := by rw [β exp_lt_exp, exp_log hy]
#align real.lt_log_iff_exp_lt Real.lt_log_iff_exp_lt
theorem log_pos_iff (hx : 0 < x) : 0 < log x β 1 < x := by
rw [β log_one]
exact log_lt_log_iff zero_lt_one hx
#align real.log_pos_iff Real.log_pos_iff
theorem log_pos (hx : 1 < x) : 0 < log x :=
(log_pos_iff (lt_trans zero_lt_one hx)).2 hx
#align real.log_pos Real.log_pos
theorem log_pos_of_lt_neg_one (hx : x < -1) : 0 < log x := by
rw [β neg_neg x, log_neg_eq_log]
have : 1 < -x := by linarith
exact log_pos this
theorem log_neg_iff (h : 0 < x) : log x < 0 β x < 1 := by
rw [β log_one]
exact log_lt_log_iff h zero_lt_one
#align real.log_neg_iff Real.log_neg_iff
theorem log_neg (h0 : 0 < x) (h1 : x < 1) : log x < 0 :=
(log_neg_iff h0).2 h1
#align real.log_neg Real.log_neg
theorem log_neg_of_lt_zero (h0 : x < 0) (h1 : -1 < x) : log x < 0 := by
rw [β neg_neg x, log_neg_eq_log]
have h0' : 0 < -x := by linarith
have h1' : -x < 1 := by linarith
exact log_neg h0' h1'
theorem log_nonneg_iff (hx : 0 < x) : 0 β€ log x β 1 β€ x := by rw [β not_lt, log_neg_iff hx, not_lt]
#align real.log_nonneg_iff Real.log_nonneg_iff
theorem log_nonneg (hx : 1 β€ x) : 0 β€ log x :=
(log_nonneg_iff (zero_lt_one.trans_le hx)).2 hx
#align real.log_nonneg Real.log_nonneg
theorem log_nonpos_iff (hx : 0 < x) : log x β€ 0 β x β€ 1 := by rw [β not_lt, log_pos_iff hx, not_lt]
#align real.log_nonpos_iff Real.log_nonpos_iff
theorem log_nonpos_iff' (hx : 0 β€ x) : log x β€ 0 β x β€ 1 := by
rcases hx.eq_or_lt with (rfl | hx)
Β· simp [le_refl, zero_le_one]
exact log_nonpos_iff hx
#align real.log_nonpos_iff' Real.log_nonpos_iff'
theorem log_nonpos (hx : 0 β€ x) (h'x : x β€ 1) : log x β€ 0 :=
(log_nonpos_iff' hx).2 h'x
#align real.log_nonpos Real.log_nonpos
theorem log_nat_cast_nonneg (n : β) : 0 β€ log n := by
if hn : n = 0 then
simp [hn]
else
have : (1 : β) β€ n := mod_cast Nat.one_le_of_lt <| Nat.pos_of_ne_zero hn
exact log_nonneg this
theorem log_neg_nat_cast_nonneg (n : β) : 0 β€ log (-n) := by
rw [β log_neg_eq_log, neg_neg]
exact log_nat_cast_nonneg _
theorem log_int_cast_nonneg (n : β€) : 0 β€ log n := by
cases lt_trichotomy 0 n with
| inl hn =>
have : (1 : β) β€ n := mod_cast hn
exact log_nonneg this
| inr hn =>
cases hn with
| inl hn => simp [hn.symm]
| inr hn =>
have : (1 : β) β€ -n := by rw [β neg_zero, β lt_neg] at hn; exact mod_cast hn
rw [β log_neg_eq_log]
exact log_nonneg this
theorem strictMonoOn_log : StrictMonoOn log (Set.Ioi 0) := fun _ hx _ _ hxy => log_lt_log hx hxy
#align real.strict_mono_on_log Real.strictMonoOn_log
theorem strictAntiOn_log : StrictAntiOn log (Set.Iio 0) := by
rintro x (hx : x < 0) y (hy : y < 0) hxy
rw [β log_abs y, β log_abs x]
refine' log_lt_log (abs_pos.2 hy.ne) _
rwa [abs_of_neg hy, abs_of_neg hx, neg_lt_neg_iff]
#align real.strict_anti_on_log Real.strictAntiOn_log
theorem log_injOn_pos : Set.InjOn log (Set.Ioi 0) :=
strictMonoOn_log.injOn
#align real.log_inj_on_pos Real.log_injOn_pos
theorem log_lt_sub_one_of_pos (hx1 : 0 < x) (hx2 : x β 1) : log x < x - 1 := by
have h : log x β 0 := by
rwa [β log_one, log_injOn_pos.ne_iff hx1]
exact mem_Ioi.mpr zero_lt_one
linarith [add_one_lt_exp h, exp_log hx1]
#align real.log_lt_sub_one_of_pos Real.log_lt_sub_one_of_pos
theorem eq_one_of_pos_of_log_eq_zero {x : β} (hβ : 0 < x) (hβ : log x = 0) : x = 1 :=
log_injOn_pos (Set.mem_Ioi.2 hβ) (Set.mem_Ioi.2 zero_lt_one) (hβ.trans Real.log_one.symm)
#align real.eq_one_of_pos_of_log_eq_zero Real.eq_one_of_pos_of_log_eq_zero
theorem log_ne_zero_of_pos_of_ne_one {x : β} (hx_pos : 0 < x) (hx : x β 1) : log x β 0 :=
mt (eq_one_of_pos_of_log_eq_zero hx_pos) hx
#align real.log_ne_zero_of_pos_of_ne_one Real.log_ne_zero_of_pos_of_ne_one
@[simp]
theorem log_eq_zero {x : β} : log x = 0 β x = 0 β¨ x = 1 β¨ x = -1 := by
constructor
Β· intro h
rcases lt_trichotomy x 0 with (x_lt_zero | rfl | x_gt_zero)
Β· refine' Or.inr (Or.inr (neg_eq_iff_eq_neg.mp _))
rw [β log_neg_eq_log x] at h
exact eq_one_of_pos_of_log_eq_zero (neg_pos.mpr x_lt_zero) h
Β· exact Or.inl rfl
Β· exact Or.inr (Or.inl (eq_one_of_pos_of_log_eq_zero x_gt_zero h))
Β· rintro (rfl | rfl | rfl) <;> simp only [log_one, log_zero, log_neg_eq_log]
#align real.log_eq_zero Real.log_eq_zero
theorem log_ne_zero {x : β} : log x β 0 β x β 0 β§ x β 1 β§ x β -1 := by
simpa only [not_or] using log_eq_zero.not
#align real.log_ne_zero Real.log_ne_zero
@[simp]
theorem log_pow (x : β) (n : β) : log (x ^ n) = n * log x := by
induction' n with n ih
Β· simp
rcases eq_or_ne x 0 with (rfl | hx)
Β· simp
rw [pow_succ', log_mul (pow_ne_zero _ hx) hx, ih, Nat.cast_succ, add_mul, one_mul]
#align real.log_pow Real.log_pow
@[simp]
theorem log_zpow (x : β) (n : β€) : log (x ^ n) = n * log x := by
induction n
Β· rw [Int.ofNat_eq_coe, zpow_natCast, log_pow, Int.cast_ofNat]
rw [zpow_negSucc, log_inv, log_pow, Int.cast_negSucc, Nat.cast_add_one, neg_mul_eq_neg_mul]
#align real.log_zpow Real.log_zpow
theorem log_sqrt {x : β} (hx : 0 β€ x) : log (sqrt x) = log x / 2 := by
rw [eq_div_iff, mul_comm, β Nat.cast_two, β log_pow, sq_sqrt hx]
exact two_ne_zero
#align real.log_sqrt Real.log_sqrt
theorem log_le_sub_one_of_pos {x : β} (hx : 0 < x) : log x β€ x - 1 := by
rw [le_sub_iff_add_le]
convert add_one_le_exp (log x)
rw [exp_log hx]
#align real.log_le_sub_one_of_pos Real.log_le_sub_one_of_pos
/-- Bound for `|log x * x|` in the interval `(0, 1]`. -/
theorem abs_log_mul_self_lt (x : β) (h1 : 0 < x) (h2 : x β€ 1) : |log x * x| < 1 := by
have : 0 < 1 / x := by simpa only [one_div, inv_pos] using h1
replace := log_le_sub_one_of_pos this
replace : log (1 / x) < 1 / x := by linarith
rw [log_div one_ne_zero h1.ne', log_one, zero_sub, lt_div_iff h1] at this
have aux : 0 β€ -log x * x := by
refine' mul_nonneg _ h1.le
rw [β log_inv]
apply log_nonneg
rw [β le_inv h1 zero_lt_one, inv_one]
exact h2
rw [β abs_of_nonneg aux, neg_mul, abs_neg] at this
exact this
#align real.abs_log_mul_self_lt Real.abs_log_mul_self_lt
/-- The real logarithm function tends to `+β` at `+β`. -/
theorem tendsto_log_atTop : Tendsto log atTop atTop :=
tendsto_comp_exp_atTop.1 <| by simpa only [log_exp] using tendsto_id
#align real.tendsto_log_at_top Real.tendsto_log_atTop
theorem tendsto_log_nhdsWithin_zero : Tendsto log (π[β ] 0) atBot := by
rw [β show _ = log from funext log_abs]
refine' Tendsto.comp (g := log) _ tendsto_abs_nhdsWithin_zero
simpa [β tendsto_comp_exp_atBot] using tendsto_id
#align real.tendsto_log_nhds_within_zero Real.tendsto_log_nhdsWithin_zero
lemma tendsto_log_nhdsWithin_zero_right : Tendsto log (π[>] 0) atBot :=
tendsto_log_nhdsWithin_zero.mono_left <| nhdsWithin_mono _ fun _ h β¦ ne_of_gt h
theorem continuousOn_log : ContinuousOn log {0}αΆ := by
simp (config := { unfoldPartialApp := true }) only [continuousOn_iff_continuous_restrict,
restrict]
conv in log _ => rw [log_of_ne_zero (show (x : β) β 0 from x.2)]
exact expOrderIso.symm.continuous.comp (continuous_subtype_val.norm.subtype_mk _)
#align real.continuous_on_log Real.continuousOn_log
@[continuity]
theorem continuous_log : Continuous fun x : { x : β // x β 0 } => log x :=
continuousOn_iff_continuous_restrict.1 <| continuousOn_log.mono fun _ => id
#align real.continuous_log Real.continuous_log
@[continuity]
theorem continuous_log' : Continuous fun x : { x : β // 0 < x } => log x :=
continuousOn_iff_continuous_restrict.1 <| continuousOn_log.mono fun _ hx => ne_of_gt hx
#align real.continuous_log' Real.continuous_log'
theorem continuousAt_log (hx : x β 0) : ContinuousAt log x :=
(continuousOn_log x hx).continuousAt <| isOpen_compl_singleton.mem_nhds hx
#align real.continuous_at_log Real.continuousAt_log
@[simp]
theorem continuousAt_log_iff : ContinuousAt log x β x β 0 := by
refine' β¨_, continuousAt_logβ©
rintro h rfl
exact not_tendsto_nhds_of_tendsto_atBot tendsto_log_nhdsWithin_zero _
(h.tendsto.mono_left inf_le_left)
#align real.continuous_at_log_iff Real.continuousAt_log_iff
open BigOperators
theorem log_prod {Ξ± : Type*} (s : Finset Ξ±) (f : Ξ± β β) (hf : β x β s, f x β 0) :
log (β i in s, f i) = β i in s, log (f i) := by
induction' s using Finset.cons_induction_on with a s ha ih
Β· simp
Β· rw [Finset.forall_mem_cons] at hf
simp [ih hf.2, log_mul hf.1 (Finset.prod_ne_zero_iff.2 hf.2)]
#align real.log_prod Real.log_prod
-- Porting note (#10756): new theorem
protected theorem _root_.Finsupp.log_prod {Ξ± Ξ² : Type*} [Zero Ξ²] (f : Ξ± ββ Ξ²) (g : Ξ± β Ξ² β β)
(hg : β a, g a (f a) = 0 β f a = 0) : log (f.prod g) = f.sum fun a b β¦ log (g a b) :=
log_prod _ _ fun _x hx hβ β¦ Finsupp.mem_support_iff.1 hx <| hg _ hβ
theorem log_nat_eq_sum_factorization (n : β) :
log n = n.factorization.sum fun p t => t * log p := by
rcases eq_or_ne n 0 with (rfl | hn)
Β· simp -- relies on junk values of `log` and `Nat.factorization`
Β· simp only [β log_pow, β Nat.cast_pow]
rw [β Finsupp.log_prod, β Nat.cast_finsupp_prod, Nat.factorization_prod_pow_eq_self hn]
intro p hp
rw [pow_eq_zero (Nat.cast_eq_zero.1 hp), Nat.factorization_zero_right]
#align real.log_nat_eq_sum_factorization Real.log_nat_eq_sum_factorization
theorem tendsto_pow_log_div_mul_add_atTop (a b : β) (n : β) (ha : a β 0) :
Tendsto (fun x => log x ^ n / (a * x + b)) atTop (π 0) :=
((tendsto_div_pow_mul_exp_add_atTop a b n ha.symm).comp tendsto_log_atTop).congr' <| by
filter_upwards [eventually_gt_atTop (0 : β)] with x hx using by simp [exp_log hx]
#align real.tendsto_pow_log_div_mul_add_at_top Real.tendsto_pow_log_div_mul_add_atTop
theorem isLittleO_pow_log_id_atTop {n : β} : (fun x => log x ^ n) =o[atTop] id := by
rw [Asymptotics.isLittleO_iff_tendsto']
Β· simpa using tendsto_pow_log_div_mul_add_atTop 1 0 n one_ne_zero
filter_upwards [eventually_ne_atTop (0 : β)] with x hβ hβ using (hβ hβ).elim
#align real.is_o_pow_log_id_at_top Real.isLittleO_pow_log_id_atTop
theorem isLittleO_log_id_atTop : log =o[atTop] id :=
isLittleO_pow_log_id_atTop.congr_left fun _ => pow_one _
#align real.is_o_log_id_at_top Real.isLittleO_log_id_atTop
theorem isLittleO_const_log_atTop {c : β} : (fun _ => c) =o[atTop] log := by
refine Asymptotics.isLittleO_of_tendsto' ?_
<| Tendsto.div_atTop (a := c) (by simp) tendsto_log_atTop
filter_upwards [eventually_gt_atTop 1] with x hx
aesop (add safe forward log_pos)
end Real
section Continuity
open Real
variable {Ξ± : Type*}
theorem Filter.Tendsto.log {f : Ξ± β β} {l : Filter Ξ±} {x : β} (h : Tendsto f l (π x)) (hx : x β 0) :
Tendsto (fun x => log (f x)) l (π (log x)) :=
(continuousAt_log hx).tendsto.comp h
#align filter.tendsto.log Filter.Tendsto.log
variable [TopologicalSpace Ξ±] {f : Ξ± β β} {s : Set Ξ±} {a : Ξ±}
@[fun_prop]
theorem Continuous.log (hf : Continuous f) (hβ : β x, f x β 0) : Continuous fun x => log (f x) :=
continuousOn_log.comp_continuous hf hβ
#align continuous.log Continuous.log
@[fun_prop]
nonrec theorem ContinuousAt.log (hf : ContinuousAt f a) (hβ : f a β 0) :
ContinuousAt (fun x => log (f x)) a :=
hf.log hβ
#align continuous_at.log ContinuousAt.log
nonrec theorem ContinuousWithinAt.log (hf : ContinuousWithinAt f s a) (hβ : f a β 0) :
ContinuousWithinAt (fun x => log (f x)) s a :=
hf.log hβ
#align continuous_within_at.log ContinuousWithinAt.log
@[fun_prop]
theorem ContinuousOn.log (hf : ContinuousOn f s) (hβ : β x β s, f x β 0) :
ContinuousOn (fun x => log (f x)) s := fun x hx => (hf x hx).log (hβ x hx)
#align continuous_on.log ContinuousOn.log
end Continuity
section TendstoCompAddSub
open Filter
namespace Real
theorem tendsto_log_comp_add_sub_log (y : β) :
Tendsto (fun x : β => log (x + y) - log x) atTop (π 0) := by
have : Tendsto (fun x β¦ 1 + y / x) atTop (π (1 + 0)) :=
tendsto_const_nhds.add (tendsto_const_nhds.div_atTop tendsto_id)
rw [β comap_exp_nhds_exp, exp_zero, tendsto_comap_iff, β add_zero (1 : β)]
refine' this.congr' _
filter_upwards [eventually_gt_atTop (0 : β), eventually_gt_atTop (-y)] with x hxβ hxy
rw [comp_apply, exp_sub, exp_log, exp_log, one_add_div] <;> linarith
#align real.tendsto_log_comp_add_sub_log Real.tendsto_log_comp_add_sub_log
theorem tendsto_log_nat_add_one_sub_log : Tendsto (fun k : β => log (k + 1) - log k) atTop (π 0) :=
(tendsto_log_comp_add_sub_log 1).comp tendsto_nat_cast_atTop_atTop
#align real.tendsto_log_nat_add_one_sub_log Real.tendsto_log_nat_add_one_sub_log
end Real
end TendstoCompAddSub
namespace Mathlib.Meta.Positivity
open Lean.Meta Qq
variable {e : β} {d : β}
lemma log_nonneg_of_isNat {n : β} (h : NormNum.IsNat e n) : 0 β€ Real.log (e : β) := by
rw [NormNum.IsNat.to_eq h rfl]
exact Real.log_nat_cast_nonneg _
lemma log_pos_of_isNat {n : β} (h : NormNum.IsNat e n) (w : Nat.blt 1 n = true) :
0 < Real.log (e : β) := by
rw [NormNum.IsNat.to_eq h rfl]
apply Real.log_pos
simpa using w
lemma log_nonneg_of_isNegNat {n : β} (h : NormNum.IsInt e (.negOfNat n)) :
0 β€ Real.log (e : β) := by
rw [NormNum.IsInt.neg_to_eq h rfl]
exact Real.log_neg_nat_cast_nonneg _
lemma log_pos_of_isNegNat {n : β} (h : NormNum.IsInt e (.negOfNat n)) (w : Nat.blt 1 n = true) :
0 < Real.log (e : β) := by
rw [NormNum.IsInt.neg_to_eq h rfl]
rw [Real.log_neg_eq_log]
apply Real.log_pos
simpa using w
set_option autoImplicit true in
lemma log_pos_of_isRat :
(NormNum.IsRat e n d) β (decide ((1 : β) < n / d)) β (0 < Real.log (e : β))
| β¨inv, eqβ©, h => by
rw [eq, invOf_eq_inv, β div_eq_mul_inv]
have : 1 < (n : β) / d := by exact_mod_cast of_decide_eq_true h
exact Real.log_pos this
set_option autoImplicit true in
lemma log_pos_of_isRat_neg :
(NormNum.IsRat e n d) β (decide (n / d < (-1 : β))) β (0 < Real.log (e : β))
| β¨inv, eqβ©, h => by
rw [eq, invOf_eq_inv, β div_eq_mul_inv]
have : (n : β) / d < -1 := by exact_mod_cast of_decide_eq_true h
exact Real.log_pos_of_lt_neg_one this
set_option autoImplicit true in
lemma log_nz_of_isRat : (NormNum.IsRat e n d) β (decide ((0 : β) < n / d))
β (decide (n / d < (1 : β))) β (Real.log (e : β) β 0)
| β¨inv, eqβ©, hβ, hβ => by
rw [eq, invOf_eq_inv, β div_eq_mul_inv]
have hβ' : 0 < (n : β) / d := by exact_mod_cast of_decide_eq_true hβ
have hβ' : (n : β) / d < 1 := by exact_mod_cast of_decide_eq_true hβ
exact ne_of_lt <| Real.log_neg hβ' hβ'
set_option autoImplicit true in
lemma log_nz_of_isRat_neg : (NormNum.IsRat e n d) β (decide (n / d < (0 : β)))
β (decide ((-1 : β) < n / d)) β (Real.log (e : β) β 0)
| β¨inv, eqβ©, hβ, hβ => by
rw [eq, invOf_eq_inv, β div_eq_mul_inv]
have hβ' : (n : β) / d < 0 := by exact_mod_cast of_decide_eq_true hβ
have hβ' : -1 < (n : β) / d := by exact_mod_cast of_decide_eq_true hβ
exact ne_of_lt <| Real.log_neg_of_lt_zero hβ' hβ'
/-- Extension for the `positivity` tactic: `Real.log` of a natural number is always nonnegative. -/
@[positivity Real.log (Nat.cast _)]
def evalLogNatCast : PositivityExt where eval {u Ξ±} _zΞ± _pΞ± e := do
match u, Ξ±, e with
| 0, ~q(β), ~q(Real.log (Nat.cast $a)) =>
assertInstancesCommute
pure (.nonnegative q(Real.log_nat_cast_nonneg $a))
| _, _, _ => throwError "not Real.log"
/-- Extension for the `positivity` tactic: `Real.log` of an integer is always nonnegative. -/
@[positivity Real.log (Int.cast _)]
def evalLogIntCast : PositivityExt where eval {u Ξ±} _zΞ± _pΞ± e := do
match u, Ξ±, e with
| 0, ~q(β), ~q(Real.log (Int.cast $a)) =>
assertInstancesCommute
pure (.nonnegative q(Real.log_int_cast_nonneg $a))
| _, _, _ => throwError "not Real.log"
/-- Extension for the `positivity` tactic: `Real.log` of a numeric literal. -/
@[positivity Real.log _]
def evalLogNatLit : PositivityExt where eval {u Ξ±} _ _ e := do
match u, Ξ±, e with
| 0, ~q(β), ~q(Real.log $a) =>
match β NormNum.derive a with
| .isNat (_ : Q(AddMonoidWithOne β)) lit p =>
assumeInstancesCommute
have p : Q(NormNum.IsNat $a $lit) := p
if 1 < lit.natLit! then
let p' : Q(Nat.blt 1 $lit = true) := (q(Eq.refl true) : Lean.Expr)
pure (.positive q(log_pos_of_isNat $p $p'))
else
pure (.nonnegative q(log_nonneg_of_isNat $p))
| .isNegNat _ lit p =>
assumeInstancesCommute
have p : Q(NormNum.IsInt $a (Int.negOfNat $lit)) := p
if 1 < lit.natLit! then
let p' : Q(Nat.blt 1 $lit = true) := (q(Eq.refl true) : Lean.Expr)
pure (.positive q(log_pos_of_isNegNat $p $p'))
else
pure (.nonnegative q(log_nonneg_of_isNegNat $p))
| .isRat (i : Q(DivisionRing β)) q n d p =>
assumeInstancesCommute
have p : Q(by clear! Β«$iΒ»; exact NormNum.IsRat $a $n $d) := p
if 0 < q β§ q < 1 then
let wβ : Q(decide ((0 : β) < $n / $d) = true) := (q(Eq.refl true) : Lean.Expr)
let wβ : Q(decide ($n / $d < (1 : β)) = true) := (q(Eq.refl true) : Lean.Expr)
pure (.nonzero q(log_nz_of_isRat $p $wβ $wβ))
else if 1 < q then
let w : Q(decide ((1 : β) < $n / $d) = true) := (q(Eq.refl true) : Lean.Expr)
pure (.positive q(log_pos_of_isRat $p $w))
else if -1 < q β§ q < 0 then
let wβ : Q(decide ($n / $d < (0 : β)) = true) := (q(Eq.refl true) : Lean.Expr)
let wβ : Q(decide ((-1 : β) < $n / $d) = true) := (q(Eq.refl true) : Lean.Expr)
pure (.nonzero q(log_nz_of_isRat_neg $p $wβ $wβ))
else if q < -1 then
let w : Q(decide ($n / $d < (-1 : β)) = true) := (q(Eq.refl true) : Lean.Expr)
pure (.positive q(log_pos_of_isRat_neg $p $w))
else
failure
| _ => failure
| _, _, _ => throwError "not Real.log"
end Mathlib.Meta.Positivity