Theorem: Real.abs_log_sub_add_sum_range_le
File: Mathlib/Analysis/SpecialFunctions/Log/Deriv.lean

tactic: let F : ℝ → ℝ := fun x => (∑ i in range n, x ^ (i + 1) / (i + 1)) + log (1 - x)
state_before: x : ℝ
h : abs x < 1
n : ℕ
⊢ abs (∑ i in Finset.range n, x ^ (i + 1) / (↑i + 1) + log (1 - x)) ≤ abs x ^ (n + 1) / (1 - abs x)

tactic: let F' : ℝ → ℝ := fun x ↦ -x ^ n / (1 - x)
state_before: x : ℝ
h : abs x < 1
n : ℕ
F : ℝ → ℝ := fun x => ∑ i in Finset.range n, x ^ (i + 1) / (↑i + 1) + log (1 - x)
⊢ abs (∑ i in Finset.range n, x ^ (i + 1) / (↑i + 1) + log (1 - x)) ≤ abs x ^ (n + 1) / (1 - abs x)

tactic: have A : ∀ y ∈ Ioo (-1 : ℝ) 1, HasDerivAt F (F' y) y := fun y hy ↦ by
  have : HasDerivAt F ((∑ i in range n, ↑(i + 1) * y ^ i / (↑i + 1)) + (-1) / (1 - y)) y :=
    .add (.sum fun i _ ↦ (hasDerivAt_pow (i + 1) y).div_const ((i : ℝ) + 1))
      (((hasDerivAt_id y).const_sub _).log <| sub_ne_zero.2 hy.2.ne')
  convert this using 1
  calc
    -y ^ n / (1 - y) = ∑ i in Finset.range n, y ^ i + -1 / (1 - y) := by
      field_simp [geom_sum_eq hy.2.ne, sub_ne_zero.2 hy.2.ne, sub_ne_zero.2 hy.2.ne']
      ring
    _ = ∑ i in Finset.range n, ↑(i + 1) * y ^ i / (↑i + 1) + -1 / (1 - y) := by
      congr with i
      rw [Nat.cast_succ, mul_div_cancel_left _ (Nat.cast_add_one_pos i).ne']
state_before: x : ℝ
h : abs x < 1
n : ℕ
F : ℝ → ℝ := fun x => ∑ i in Finset.range n, x ^ (i + 1) / (↑i + 1) + log (1 - x)
F' : ℝ → ℝ := fun x => -x ^ n / (1 - x)
⊢ abs (∑ i in Finset.range n, x ^ (i + 1) / (↑i + 1) + log (1 - x)) ≤ abs x ^ (n + 1) / (1 - abs x)

tactic: have B : ∀ y ∈ Icc (-|x|) (|x|), |F' y| ≤ |x| ^ n / (1 - |x|) := fun y hy ↦
  calc
    |F' y| = |y| ^ n / |1 - y| := by simp [abs_div]
    _ ≤ |x| ^ n / (1 - |x|) := by
      have : |y| ≤ |x| := abs_le.2 hy
      have : 1 - |x| ≤ |1 - y| := le_trans (by linarith [hy.2]) (le_abs_self _)
      gcongr
      exact sub_pos.2 h
state_before: x : ℝ
h : abs x < 1
n : ℕ
F : ℝ → ℝ := fun x => ∑ i in Finset.range n, x ^ (i + 1) / (↑i + 1) + log (1 - x)
F' : ℝ → ℝ := fun x => -x ^ n / (1 - x)
A : ∀ (y : ℝ), y ∈ Set.Ioo (-1) 1 → HasDerivAt F (F' y) y
⊢ abs (∑ i in Finset.range n, x ^ (i + 1) / (↑i + 1) + log (1 - x)) ≤ abs x ^ (n + 1) / (1 - abs x)

tactic: simpa [div_mul_eq_mul_div, pow_succ'] using C
state_before: x : ℝ
h : abs x < 1
n : ℕ
F : ℝ → ℝ := fun x => ∑ i in Finset.range n, x ^ (i + 1) / (↑i + 1) + log (1 - x)
F' : ℝ → ℝ := fun x => -x ^ n / (1 - x)
A : ∀ (y : ℝ), y ∈ Set.Ioo (-1) 1 → HasDerivAt F (F' y) y
B : ∀ (y : ℝ), y ∈ Set.Icc (-abs x) (abs x) → abs (F' y) ≤ abs x ^ n / (1 - abs x)
C : ‖F x - F 0‖ ≤ abs x ^ n / (1 - abs x) * ‖x - 0‖
⊢ abs (∑ i in Finset.range n, x ^ (i + 1) / (↑i + 1) + log (1 - x)) ≤ abs x ^ (n + 1) / (1 - abs x)

tactic: have : HasDerivAt F ((∑ i in range n, ↑(i + 1) * y ^ i / (↑i + 1)) + (-1) / (1 - y)) y :=
  .add (.sum fun i _ ↦ (hasDerivAt_pow (i + 1) y).div_const ((i : ℝ) + 1))
    (((hasDerivAt_id y).const_sub _).log <| sub_ne_zero.2 hy.2.ne')
state_before: x : ℝ
h : abs x < 1
n : ℕ
F : ℝ → ℝ := fun x => ∑ i in Finset.range n, x ^ (i + 1) / (↑i + 1) + log (1 - x)
F' : ℝ → ℝ := fun x => -x ^ n / (1 - x)
y : ℝ
hy : y ∈ Set.Ioo (-1) 1
⊢ HasDerivAt F (F' y) y

tactic: convert this using 1
state_before: x : ℝ
h : abs x < 1
n : ℕ
F : ℝ → ℝ := fun x => ∑ i in Finset.range n, x ^ (i + 1) / (↑i + 1) + log (1 - x)
F' : ℝ → ℝ := fun x => -x ^ n / (1 - x)
y : ℝ
hy : y ∈ Set.Ioo (-1) 1
this : HasDerivAt F (∑ i in Finset.range n, ↑(i + 1) * y ^ i / (↑i + 1) + -1 / (1 - y)) y
⊢ HasDerivAt F (F' y) y

tactic: calc
  -y ^ n / (1 - y) = ∑ i in Finset.range n, y ^ i + -1 / (1 - y) := by
    field_simp [geom_sum_eq hy.2.ne, sub_ne_zero.2 hy.2.ne, sub_ne_zero.2 hy.2.ne']
    ring
  _ = ∑ i in Finset.range n, ↑(i + 1) * y ^ i / (↑i + 1) + -1 / (1 - y) := by
    congr with i
    rw [Nat.cast_succ, mul_div_cancel_left _ (Nat.cast_add_one_pos i).ne']
state_before: case h.e'_7
x : ℝ
h : abs x < 1
n : ℕ
F : ℝ → ℝ := fun x => ∑ i in Finset.range n, x ^ (i + 1) / (↑i + 1) + log (1 - x)
F' : ℝ → ℝ := fun x => -x ^ n / (1 - x)
y : ℝ
hy : y ∈ Set.Ioo (-1) 1
this : HasDerivAt F (∑ i in Finset.range n, ↑(i + 1) * y ^ i / (↑i + 1) + -1 / (1 - y)) y
⊢ F' y = ∑ i in Finset.range n, ↑(i + 1) * y ^ i / (↑i + 1) + -1 / (1 - y)

tactic: field_simp [geom_sum_eq hy.2.ne, sub_ne_zero.2 hy.2.ne, sub_ne_zero.2 hy.2.ne']
state_before: x : ℝ
h : abs x < 1
n : ℕ
F : ℝ → ℝ := fun x => ∑ i in Finset.range n, x ^ (i + 1) / (↑i + 1) + log (1 - x)
F' : ℝ → ℝ := fun x => -x ^ n / (1 - x)
y : ℝ
hy : y ∈ Set.Ioo (-1) 1
this : HasDerivAt F (∑ i in Finset.range n, ↑(i + 1) * y ^ i / (↑i + 1) + -1 / (1 - y)) y
⊢ -y ^ n / (1 - y) = ∑ i in Finset.range n, y ^ i + -1 / (1 - y)

tactic: ring
state_before: x : ℝ
h : abs x < 1
n : ℕ
F : ℝ → ℝ := fun x => ∑ i in Finset.range n, x ^ (i + 1) / (↑i + 1) + log (1 - x)
F' : ℝ → ℝ := fun x => -x ^ n / (1 - x)
y : ℝ
hy : y ∈ Set.Ioo (-1) 1
this : HasDerivAt F (∑ i in Finset.range n, ↑(i + 1) * y ^ i / (↑i + 1) + -1 / (1 - y)) y
⊢ -(y ^ n * ((y - 1) * (1 - y))) = ((y ^ n - 1) * (1 - y) + (1 - y)) * (1 - y)

tactic: congr with i
state_before: x : ℝ
h : abs x < 1
n : ℕ
F : ℝ → ℝ := fun x => ∑ i in Finset.range n, x ^ (i + 1) / (↑i + 1) + log (1 - x)
F' : ℝ → ℝ := fun x => -x ^ n / (1 - x)
y : ℝ
hy : y ∈ Set.Ioo (-1) 1
this : HasDerivAt F (∑ i in Finset.range n, ↑(i + 1) * y ^ i / (↑i + 1) + -1 / (1 - y)) y
⊢ ∑ i in Finset.range n, y ^ i + -1 / (1 - y) = ∑ i in Finset.range n, ↑(i + 1) * y ^ i / (↑i + 1) + -1 / (1 - y)

tactic: rw [Nat.cast_succ, mul_div_cancel_left _ (Nat.cast_add_one_pos i).ne']
state_before: case e_a.e_f.h
x : ℝ
h : abs x < 1
n : ℕ
F : ℝ → ℝ := fun x => ∑ i in Finset.range n, x ^ (i + 1) / (↑i + 1) + log (1 - x)
F' : ℝ → ℝ := fun x => -x ^ n / (1 - x)
y : ℝ
hy : y ∈ Set.Ioo (-1) 1
this : HasDerivAt F (∑ i in Finset.range n, ↑(i + 1) * y ^ i / (↑i + 1) + -1 / (1 - y)) y
i : ℕ
⊢ y ^ i = ↑(i + 1) * y ^ i / (↑i + 1)

tactic: simp [abs_div]
state_before: x : ℝ
h : abs x < 1
n : ℕ
F : ℝ → ℝ := fun x => ∑ i in Finset.range n, x ^ (i + 1) / (↑i + 1) + log (1 - x)
F' : ℝ → ℝ := fun x => -x ^ n / (1 - x)
A : ∀ (y : ℝ), y ∈ Set.Ioo (-1) 1 → HasDerivAt F (F' y) y
y : ℝ
hy : y ∈ Set.Icc (-abs x) (abs x)
⊢ abs (F' y) = abs y ^ n / abs (1 - y)

tactic: have : |y| ≤ |x| := abs_le.2 hy
state_before: x : ℝ
h : abs x < 1
n : ℕ
F : ℝ → ℝ := fun x => ∑ i in Finset.range n, x ^ (i + 1) / (↑i + 1) + log (1 - x)
F' : ℝ → ℝ := fun x => -x ^ n / (1 - x)
A : ∀ (y : ℝ), y ∈ Set.Ioo (-1) 1 → HasDerivAt F (F' y) y
y : ℝ
hy : y ∈ Set.Icc (-abs x) (abs x)
⊢ abs y ^ n / abs (1 - y) ≤ abs x ^ n / (1 - abs x)

tactic: have : 1 - |x| ≤ |1 - y| := le_trans (by linarith [hy.2]) (le_abs_self _)
state_before: x : ℝ
h : abs x < 1
n : ℕ
F : ℝ → ℝ := fun x => ∑ i in Finset.range n, x ^ (i + 1) / (↑i + 1) + log (1 - x)
F' : ℝ → ℝ := fun x => -x ^ n / (1 - x)
A : ∀ (y : ℝ), y ∈ Set.Ioo (-1) 1 → HasDerivAt F (F' y) y
y : ℝ
hy : y ∈ Set.Icc (-abs x) (abs x)
this : abs y ≤ abs x
⊢ abs y ^ n / abs (1 - y) ≤ abs x ^ n / (1 - abs x)

tactic: gcongr
state_before: x : ℝ
h : abs x < 1
n : ℕ
F : ℝ → ℝ := fun x => ∑ i in Finset.range n, x ^ (i + 1) / (↑i + 1) + log (1 - x)
F' : ℝ → ℝ := fun x => -x ^ n / (1 - x)
A : ∀ (y : ℝ), y ∈ Set.Ioo (-1) 1 → HasDerivAt F (F' y) y
y : ℝ
hy : y ∈ Set.Icc (-abs x) (abs x)
this✝ : abs y ≤ abs x
this : 1 - abs x ≤ abs (1 - y)
⊢ abs y ^ n / abs (1 - y) ≤ abs x ^ n / (1 - abs x)

tactic: exact sub_pos.2 h
state_before: case hd
x : ℝ
h : abs x < 1
n : ℕ
F : ℝ → ℝ := fun x => ∑ i in Finset.range n, x ^ (i + 1) / (↑i + 1) + log (1 - x)
F' : ℝ → ℝ := fun x => -x ^ n / (1 - x)
A : ∀ (y : ℝ), y ∈ Set.Ioo (-1) 1 → HasDerivAt F (F' y) y
y : ℝ
hy : y ∈ Set.Icc (-abs x) (abs x)
this✝ : abs y ≤ abs x
this : 1 - abs x ≤ abs (1 - y)
⊢ 0 < 1 - abs x

tactic: linarith [hy.2]
state_before: x : ℝ
h : abs x < 1
n : ℕ
F : ℝ → ℝ := fun x => ∑ i in Finset.range n, x ^ (i + 1) / (↑i + 1) + log (1 - x)
F' : ℝ → ℝ := fun x => -x ^ n / (1 - x)
A : ∀ (y : ℝ), y ∈ Set.Ioo (-1) 1 → HasDerivAt F (F' y) y
y : ℝ
hy : y ∈ Set.Icc (-abs x) (abs x)
this : abs y ≤ abs x
⊢ 1 - abs x ≤ 1 - y

tactic: refine Convex.norm_image_sub_le_of_norm_hasDerivWithin_le
  (fun y hy ↦ (A _ ?_).hasDerivWithinAt) B (convex_Icc _ _) ?_ ?_
state_before: x : ℝ
h : abs x < 1
n : ℕ
F : ℝ → ℝ := fun x => ∑ i in Finset.range n, x ^ (i + 1) / (↑i + 1) + log (1 - x)
F' : ℝ → ℝ := fun x => -x ^ n / (1 - x)
A : ∀ (y : ℝ), y ∈ Set.Ioo (-1) 1 → HasDerivAt F (F' y) y
B : ∀ (y : ℝ), y ∈ Set.Icc (-abs x) (abs x) → abs (F' y) ≤ abs x ^ n / (1 - abs x)
⊢ ‖F x - F 0‖ ≤ abs x ^ n / (1 - abs x) * ‖x - 0‖

tactic: exact Icc_subset_Ioo (neg_lt_neg h) h hy
state_before: case refine_1
x : ℝ
h : abs x < 1
n : ℕ
F : ℝ → ℝ := fun x => ∑ i in Finset.range n, x ^ (i + 1) / (↑i + 1) + log (1 - x)
F' : ℝ → ℝ := fun x => -x ^ n / (1 - x)
A : ∀ (y : ℝ), y ∈ Set.Ioo (-1) 1 → HasDerivAt F (F' y) y
B : ∀ (y : ℝ), y ∈ Set.Icc (-abs x) (abs x) → abs (F' y) ≤ abs x ^ n / (1 - abs x)
y : ℝ
hy : y ∈ Set.Icc (-abs x) (abs x)
⊢ y ∈ Set.Ioo (-1) 1

tactic: simp
state_before: case refine_2
x : ℝ
h : abs x < 1
n : ℕ
F : ℝ → ℝ := fun x => ∑ i in Finset.range n, x ^ (i + 1) / (↑i + 1) + log (1 - x)
F' : ℝ → ℝ := fun x => -x ^ n / (1 - x)
A : ∀ (y : ℝ), y ∈ Set.Ioo (-1) 1 → HasDerivAt F (F' y) y
B : ∀ (y : ℝ), y ∈ Set.Icc (-abs x) (abs x) → abs (F' y) ≤ abs x ^ n / (1 - abs x)
⊢ 0 ∈ Set.Icc (-abs x) (abs x)

tactic: simp [le_abs_self x, neg_le.mp (neg_le_abs_self x)]
state_before: case refine_3
x : ℝ
h : abs x < 1
n : ℕ
F : ℝ → ℝ := fun x => ∑ i in Finset.range n, x ^ (i + 1) / (↑i + 1) + log (1 - x)
F' : ℝ → ℝ := fun x => -x ^ n / (1 - x)
A : ∀ (y : ℝ), y ∈ Set.Ioo (-1) 1 → HasDerivAt F (F' y) y
B : ∀ (y : ℝ), y ∈ Set.Icc (-abs x) (abs x) → abs (F' y) ≤ abs x ^ n / (1 - abs x)
⊢ x ∈ Set.Icc (-abs x) (abs x)