-- Lean 4 proof step from Mathlib.Computability.AkraBazzi.SumTransform (goal)
Goal:
α : Type u_1
inst : Fintype α
T : ℕ → ℝ
g : ℝ → ℝ
a b : α → ℝ
r : α → ℕ → ℕ
inst_1 : Nonempty α
R : AkraBazziRecurrence T g a b r
c₁ : ℝ
hc₁_mem : Membership.mem (γ := Set ℝ) (Set.Ioo 0 1) c₁
hc₁ : ∀ᶠ (n : ℕ) in atTop, ∀ (i : α), c₁ * (↑n : ℝ) ≤ (↑(r i n) : ℝ)
c₂ : ℝ
hc₂_mem : c₂ > 0
hc₂ : ∀ᶠ (n : ℕ) in atTop, ∀ u ∈ Set.Icc (c₁ * (↑n : ℝ)) (↑n : ℝ), g u ≤ c₂ * g (↑n : ℝ)
hc₁_pos : 0 < c₁
n : ℕ
hn₁ : ∀ (i : α), c₁ * (↑n : ℝ) ≤ (↑(r i n) : ℝ)
hn₂ : ∀ u ∈ Set.Icc (c₁ * (↑n : ℝ)) (↑n : ℝ), g u ≤ c₂ * g (↑n : ℝ)
hrpos : ∀ (i : α), 0 < r i n
hr_lt_n : ∀ (i : α), r i n < n
hn_pos : 0 < n
i : α
hrpos_i : 0 < r i n
g_nonneg : 0 ≤ g (↑n : ℝ)
hp : 0 ≤ p a b + 1
calc :
  sumTransform (p a b) g (r i n) n =
    HPow.hPow (α := ℝ) (↑n : ℝ) (p a b) * ∑ u ∈ Ico (r i n) n, g (↑u : ℝ) / HPow.hPow (α := ℝ) (↑u : ℝ) (p a b + 1)
calc₁ :
  HPow.hPow (α := ℝ) (↑n : ℝ) (p a b) * ∑ u ∈ Ico (r i n) n, g (↑u : ℝ) / HPow.hPow (α := ℝ) (↑u : ℝ) (p a b + 1) ≤
    HPow.hPow (α := ℝ) (↑n : ℝ) (p a b) * ∑ u ∈ Ico (r i n) n, c₂ * g (↑n : ℝ) / HPow.hPow (α := ℝ) (↑u : ℝ) (p a b + 1)
calc₂ :
  HPow.hPow (α := ℝ) (↑n : ℝ) (p a b) * ∑ u ∈ Ico (r i n) n, c₂ * g (↑n : ℝ) / HPow.hPow (α := ℝ) (↑u : ℝ) (p a b + 1) ≤
    HPow.hPow (α := ℝ) (↑n : ℝ) (p a b) *
      ∑ _u ∈ Ico (r i n) n, c₂ * g (↑n : ℝ) / HPow.hPow (α := ℝ) (↑(r i n) : ℝ) (p a b + 1)
calc₃ :
  HPow.hPow (α := ℝ) (↑n : ℝ) (p a b) *
      ∑ _u ∈ Ico (r i n) n, c₂ * g (↑n : ℝ) / HPow.hPow (α := ℝ) (↑(r i n) : ℝ) (p a b + 1) ≤
    HPow.hPow (α := ℝ) (↑n : ℝ) (p a b) *
      #(Ico (r i n) n) • (c₂ * g (↑n : ℝ) / HPow.hPow (α := ℝ) (↑(r i n) : ℝ) (p a b + 1))
calc₄ :
  HPow.hPow (α := ℝ) (↑n : ℝ) (p a b) *
      #(Ico (r i n) n) • (c₂ * g (↑n : ℝ) / HPow.hPow (α := ℝ) (↑(r i n) : ℝ) (p a b + 1)) =
    HPow.hPow (α := ℝ) (↑n : ℝ) (p a b) * (↑(#(Ico (r i n) n)) : ℝ) *
      (c₂ * g (↑n : ℝ) / HPow.hPow (α := ℝ) (↑(r i n) : ℝ) (p a b + 1))
calc₅ :
  HPow.hPow (α := ℝ) (↑n : ℝ) (p a b) * (↑(#(Ico (r i n) n)) : ℝ) *
      (c₂ * g (↑n : ℝ) / HPow.hPow (α := ℝ) (↑(r i n) : ℝ) (p a b + 1)) =
    HPow.hPow (α := ℝ) (↑n : ℝ) (p a b) * HSub.hSub (α := ℝ) (↑n : ℝ) (↑(r i n) : ℝ) *
      (c₂ * g (↑n : ℝ) / HPow.hPow (α := ℝ) (↑(r i n) : ℝ) (p a b + 1))
⊢ sumTransform (p a b) g (r i n) n ≤ max c₂ (c₂ / c₁ ^ (p a b + 1)) * g (↑n : ℝ)
have calc₆ : HPow.hPow (α := ℝ) (↑n : ℝ) (p a b) * HSub.hSub (α := ℝ) (↑n : ℝ) (↑(r i n) : ℝ) *
    (c₂ * g (↑n : ℝ) / HPow.hPow (α := ℝ) (↑(r i n) : ℝ) (p a b + 1)) ≤
  HPow.hPow (α := ℝ) (↑n : ℝ) (p a b) * (↑n : ℝ) * (c₂ * g (↑n : ℝ) / HPow.hPow (α := ℝ) (↑(r i n) : ℝ) (p a b + 1))
Tactic: calc sumTransform (p a b) g (r i n) n
           = n ^ (p a b) * (∑ u ∈ Finset.Ico (r i n) n, g u / u ^ ((p a b) + 1)) := by rfl
         _ ≤ n ^ (p a b) * (∑ u ∈ Finset.Ico (r i n) n, c₂ * g n / u ^ ((p a b) + 1)) := by
          gcongr with u hu
          rw [Finset.mem_Ico] at hu
          have hu' : u ∈ Set.Icc (r i n) n := ⟨hu.1, by lia⟩
          refine hn₂ u ?_
          rw [Set.mem_Icc]
          refine ⟨?_, by norm_cast; lia⟩
          calc c₁ * n ≤ r i n := by exact hn₁ i
                    _ ≤ u := by exact_mod_cast hu'.1
         _ ≤ n ^ (p a b) * (∑ _u ∈ Finset.Ico (r i n) n, c₂ * g n / (r i n) ^ ((p a b) + 1)) := by
          gcongr with u hu; rw [Finset.mem_Ico] at hu; exact hu.1
         _ ≤ n ^ p a b * #(Ico (r i n) n) • (c₂ * g n / r i n ^ (p a b + 1)) := by
          gcongr; exact Finset.sum_le_card_nsmul _ _ _ (fun x _ => by rfl)
         _ = n ^ p a b * #(Ico (r i n) n) * (c₂ * g n / r i n ^ (p a b + 1)) := by
          rw [nsmul_eq_mul, mul_assoc]
         _ = n ^ (p a b) * (n - r i n) * (c₂ * g n / (r i n) ^ ((p a b) + 1)) := by
          congr; rw [Nat.card_Ico, Nat.cast_sub (le_of_lt <| hr_lt_n i)]
         _ ≤ n ^ (p a b) * n * (c₂ * g n / (r i n) ^ ((p a b) + 1)) := by
          gcongr; simp only [tsub_le_iff_right, le_add_iff_nonneg_right, Nat.cast_nonneg]
         _ ≤ n ^ (p a b) * n * (c₂ * g n / (c₁ * n) ^ ((p a b) + 1)) := by
          gcongr; exact hn₁ i
         _ = c₂ * g n * n ^ ((p a b) + 1) / (c₁ * n) ^ ((p a b) + 1) := by
          rw [← Real.rpow_add_one (by positivity) (p a b)]; ring
         _ = c₂ * g n * n ^ ((p a b) + 1) / (n ^ ((p a b) + 1) * c₁ ^ ((p a b) + 1)) := by
          rw [mul_comm c₁, Real.mul_rpow (by positivity) (by positivity)]
         _ = c₂ * g n * (n ^ ((p a b) + 1) / (n ^ ((p a b) + 1))) / c₁ ^ ((p a b) + 1) := by ring
         _ = c₂ * g n / c₁ ^ ((p a b) + 1) := by rw [div_self (by positivity), mul_one]
         _ = (c₂ / c₁ ^ ((p a b) + 1)) * g n := by ring
         _ ≤ max c₂ (c₂ / c₁ ^ ((p a b) + 1)) * g n := by gcongr; exact le_max_right _ _