-- Mathlib/NumberTheory/LSeries/Basic.lean
/-- If `f = O(n^(x-1))` and `re s > x`, then the `LSeries` of `f` is summable at `s`. -/
lemma LSeriesSummable_of_isBigO_rpow {f : ℕ → ℂ} {x : ℝ} {s : ℂ} (hs : x < s.re)
    (h : f =O[atTop] fun n ↦ (n : ℝ) ^ (x - 1)) :
    LSeriesSummable f s

Proof state:
case intro.intro
f : ℕ → ℂ
x : ℝ
s : ℂ
hs : x < s.re
h : f =O[atTop] fun n => ↑n ^ (x - 1)
C : ℝ
hC : ∀ᶠ (x_1 : ℕ) in atTop, ‖f x_1‖ ≤ C * ‖↑x_1 ^ (x - 1)‖
m : ℕ
hm : ∀ b ≥ m, ‖f b‖ ≤ C * ‖↑b ^ (x - 1)‖
⊢ LSeriesSummable f s

Tactic:
let C' := max C (max' (insert 0 (image (fun n : ℕ ↦ ‖f n‖ / (n : ℝ) ^ (x - 1)) (range m)))
  (insert_nonempty 0 _))

Result:
case intro.intro
f : ℕ → ℂ
x : ℝ
s : ℂ
hs : x < s.re
h : f =O[atTop] fun n => ↑n ^ (x - 1)
C : ℝ
hC : ∀ᶠ (x_1 : ℕ) in atTop, ‖f x_1‖ ≤ C * ‖↑x_1 ^ (x - 1)‖
m : ℕ
hm : ∀ b ≥ m, ‖f b‖ ≤ C * ‖↑b ^ (x - 1)‖
C' : ℝ := C ⊔ (insert 0 (image (fun n => ‖f n‖ / ↑n ^ (x - 1)) (range m))).max' ⋯
⊢ LSeriesSummable f s

Proof state:
case intro
f : ℕ → ℂ
x : ℝ
s : ℂ
hs : x < s.re
h : f =O[atTop] fun n => ↑n ^ (x - 1)
C : ℝ
hC : ∀ᶠ (x_1 : ℕ) in atTop, ‖f x_1‖ ≤ C * ‖↑x_1 ^ (x - 1)‖
⊢ LSeriesSummable f s

Tactic:
obtain ⟨m, hm⟩ := eventually_atTop.mp hC

Result:
case intro.intro
f : ℕ → ℂ
x : ℝ
s : ℂ
hs : x < s.re
h : f =O[atTop] fun n => ↑n ^ (x - 1)
C : ℝ
hC : ∀ᶠ (x_1 : ℕ) in atTop, ‖f x_1‖ ≤ C * ‖↑x_1 ^ (x - 1)‖
m : ℕ
hm : ∀ b ≥ m, ‖f b‖ ≤ C * ‖↑b ^ (x - 1)‖
⊢ LSeriesSummable f s

Proof state:
case intro.intro
f : ℕ → ℂ
x : ℝ
s : ℂ
hs : x < s.re
h : f =O[atTop] fun n => ↑n ^ (x - 1)
C : ℝ
hC : ∀ᶠ (x_1 : ℕ) in atTop, ‖f x_1‖ ≤ C * ‖↑x_1 ^ (x - 1)‖
m : ℕ
hm : ∀ b ≥ m, ‖f b‖ ≤ C * ‖↑b ^ (x - 1)‖
C' : ℝ := C ⊔ (insert 0 (image (fun n => ‖f n‖ / ↑n ^ (x - 1)) (range m))).max' ⋯
⊢ LSeriesSummable f s

Tactic:
have hC'₀ : 0 ≤ C' := (le_max' _ _ (mem_insert.mpr (Or.inl rfl))).trans <| le_max_right ..

Result:
case intro.intro
f : ℕ → ℂ
x : ℝ
s : ℂ
hs : x < s.re
h : f =O[atTop] fun n => ↑n ^ (x - 1)
C : ℝ
hC : ∀ᶠ (x_1 : ℕ) in atTop, ‖f x_1‖ ≤ C * ‖↑x_1 ^ (x - 1)‖
m : ℕ
hm : ∀ b ≥ m, ‖f b‖ ≤ C * ‖↑b ^ (x - 1)‖
C' : ℝ := C ⊔ (insert 0 (image (fun n => ‖f n‖ / ↑n ^ (x - 1)) (range m))).max' ⋯
hC'₀ : 0 ≤ C'
⊢ LSeriesSummable f s

Proof state:
case intro.intro.inr
f : ℕ → ℂ
x : ℝ
s : ℂ
hs : x < s.re
h : f =O[atTop] fun n => ↑n ^ (x - 1)
C : ℝ
hC : ∀ᶠ (x_1 : ℕ) in atTop, ‖f x_1‖ ≤ C * ‖↑x_1 ^ (x - 1)‖
m : ℕ
hm : ∀ b ≥ m, ‖f b‖ ≤ C * ‖↑b ^ (x - 1)‖
C' : ℝ := C ⊔ (insert 0 (image (fun n => ‖f n‖ / ↑n ^ (x - 1)) (range m))).max' ⋯
hC'₀ : 0 ≤ C'
hCC' : C ≤ C'
n : ℕ
hn₀ : n ≠ 0
hn : n < m
⊢ ‖f n‖ ≤ C' * ↑n ^ (x - 1)

Tactic:
have hn' : 0 < n := Nat.pos_of_ne_zero hn₀

Result:
case intro.intro.inr
f : ℕ → ℂ
x : ℝ
s : ℂ
hs : x < s.re
h : f =O[atTop] fun n => ↑n ^ (x - 1)
C : ℝ
hC : ∀ᶠ (x_1 : ℕ) in atTop, ‖f x_1‖ ≤ C * ‖↑x_1 ^ (x - 1)‖
m : ℕ
hm : ∀ b ≥ m, ‖f b‖ ≤ C * ‖↑b ^ (x - 1)‖
C' : ℝ := C ⊔ (insert 0 (image (fun n => ‖f n‖ / ↑n ^ (x - 1)) (range m))).max' ⋯
hC'₀ : 0 ≤ C'
hCC' : C ≤ C'
n : ℕ
hn₀ : n ≠ 0
hn : n < m
hn' : 0 < n
⊢ ‖f n‖ ≤ C' * ↑n ^ (x - 1)

Proof state:
case intro.intro
f : ℕ → ℂ
x : ℝ
s : ℂ
hs : x < s.re
h : f =O[atTop] fun n => ↑n ^ (x - 1)
C : ℝ
hC : ∀ᶠ (x_1 : ℕ) in atTop, ‖f x_1‖ ≤ C * ‖↑x_1 ^ (x - 1)‖
m : ℕ
hm : ∀ b ≥ m, ‖f b‖ ≤ C * ‖↑b ^ (x - 1)‖
C' : ℝ := C ⊔ (insert 0 (image (fun n => ‖f n‖ / ↑n ^ (x - 1)) (range m))).max' ⋯
hC'₀ : 0 ≤ C'
hCC' : C ≤ C'
⊢ LSeriesSummable f s

Tactic:
refine LSeriesSummable_of_le_const_mul_rpow hs ⟨C', fun n hn₀ ↦ ?_⟩

Result:
case intro.intro
f : ℕ → ℂ
x : ℝ
s : ℂ
hs : x < s.re
h : f =O[atTop] fun n => ↑n ^ (x - 1)
C : ℝ
hC : ∀ᶠ (x_1 : ℕ) in atTop, ‖f x_1‖ ≤ C * ‖↑x_1 ^ (x - 1)‖
m : ℕ
hm : ∀ b ≥ m, ‖f b‖ ≤ C * ‖↑b ^ (x - 1)‖
C' : ℝ := C ⊔ (insert 0 (image (fun n => ‖f n‖ / ↑n ^ (x - 1)) (range m))).max' ⋯
hC'₀ : 0 ≤ C'
hCC' : C ≤ C'
n : ℕ
hn₀ : n ≠ 0
⊢ ‖f n‖ ≤ C' * ↑n ^ (x - 1)