-- Mathlib/Computability/AkraBazzi/GrowsPolynomially.lean
lemma eventually_atTop_nonneg_or_nonpos (hf : GrowsPolynomially f) :
    (∀ᶠ x in atTop, 0 ≤ f x) ∨ (∀ᶠ x in atTop, f x ≤ 0)

Proof state:
f : ℝ → ℝ
hf : GrowsPolynomially f
c₁ : ℝ
left✝¹ : c₁ > 0
c₂ : ℝ
left✝ : c₂ > 0
heq : c₁ = c₂
n₀ : ℝ
hn₀ : ∀ b ≥ n₀, ∀ u ∈ Set.Icc (1 / 2 * b) b, f u = c₂ * f b
n : ℕ
hn : n ≥ 1
hyp_ind : ∀ z ∈ Set.Ico (n₀ ⊔ 2) (2 ^ n * (n₀ ⊔ 2)), f z = f (n₀ ⊔ 2)
z : ℝ
hz : z ∈ Set.Ico (2 ^ n * (n₀ ⊔ 2)) (2 ^ (n + 1) * (n₀ ⊔ 2))
⊢ f z = f (n₀ ⊔ 2)

Tactic:
have z_nonneg : 0 ≤ z := by
  calc (0 : ℝ) ≤ (2 : ℝ)^n * max n₀ 2 := by
                exact mul_nonneg (pow_nonneg (by norm_num) _) (by norm_num)
          _ ≤ z := by exact_mod_cast hz.1

Result:
f : ℝ → ℝ
hf : GrowsPolynomially f
c₁ : ℝ
left✝¹ : c₁ > 0
c₂ : ℝ
left✝ : c₂ > 0
heq : c₁ = c₂
n₀ : ℝ
hn₀ : ∀ b ≥ n₀, ∀ u ∈ Set.Icc (1 / 2 * b) b, f u = c₂ * f b
n : ℕ
hn : n ≥ 1
hyp_ind : ∀ z ∈ Set.Ico (n₀ ⊔ 2) (2 ^ n * (n₀ ⊔ 2)), f z = f (n₀ ⊔ 2)
z : ℝ
hz : z ∈ Set.Ico (2 ^ n * (n₀ ⊔ 2)) (2 ^ (n + 1) * (n₀ ⊔ 2))
z_nonneg : 0 ≤ z
⊢ f z = f (n₀ ⊔ 2)

Proof state:
f : ℝ → ℝ
hf : GrowsPolynomially f
c₁ : ℝ
left✝¹ : c₁ > 0
c₂ : ℝ
left✝ : c₂ > 0
heq : c₁ = c₂
n₀ : ℝ
hn₀ : ∀ b ≥ n₀, ∀ u ∈ Set.Icc (1 / 2 * b) b, f u = c₂ * f b
n : ℕ
hn : n ≥ 1
hyp_ind : ∀ z ∈ Set.Ico (n₀ ⊔ 2) (2 ^ n * (n₀ ⊔ 2)), f z = f (n₀ ⊔ 2)
z : ℝ
hz : z ∈ Set.Ico (2 ^ n * (n₀ ⊔ 2)) (2 ^ (n + 1) * (n₀ ⊔ 2))
z_nonneg : 0 ≤ z
le_2n : n₀ ⊔ 2 ≤ 2 ^ n * (n₀ ⊔ 2)
n₀_le_z : n₀ ≤ z
fz_eq_c₂fz : f z = c₂ * f z
z_to_half_z' : f (1 / 2 * z) = c₂ * f z
⊢ f (1 / 2 * z) = f z

Tactic:
rwa [← fz_eq_c₂fz] at z_to_half_z'

Result:
no goals

Proof state:
case h
f : ℝ → ℝ
hf : GrowsPolynomially f
c₁ : ℝ
left✝¹ : c₁ > 0
c₂ : ℝ
left✝ : c₂ > 0
h : ∀ᶠ (x : ℝ) in atTop, ∀ u ∈ Set.Icc (1 / 2 * x) x, f u ∈ Set.Icc (c₁ * f x) (c₂ * f x)
hgt : c₂ < c₁
x : ℝ
hx : ∀ u ∈ Set.Icc (1 / 2 * x) x, f u ∈ Set.Icc (c₁ * f x) (c₂ * f x)
hx_nonneg : 0 ≤ x
h' : 3 / 4 * x ∈ Set.Icc (1 / 2 * x) x
hu✝ : f (3 / 4 * x) ∈ Set.Icc (c₁ * f x) (c₂ * f x)
hu : c₁ * f x ≤ c₂ * f x
⊢ f x ≤ 0

Tactic:
have hu' : (c₁ - c₂) * f x ≤ 0 := by linarith

Result:
case h
f : ℝ → ℝ
hf : GrowsPolynomially f
c₁ : ℝ
left✝¹ : c₁ > 0
c₂ : ℝ
left✝ : c₂ > 0
h : ∀ᶠ (x : ℝ) in atTop, ∀ u ∈ Set.Icc (1 / 2 * x) x, f u ∈ Set.Icc (c₁ * f x) (c₂ * f x)
hgt : c₂ < c₁
x : ℝ
hx : ∀ u ∈ Set.Icc (1 / 2 * x) x, f u ∈ Set.Icc (c₁ * f x) (c₂ * f x)
hx_nonneg : 0 ≤ x
h' : 3 / 4 * x ∈ Set.Icc (1 / 2 * x) x
hu✝ : f (3 / 4 * x) ∈ Set.Icc (c₁ * f x) (c₂ * f x)
hu : c₁ * f x ≤ c₂ * f x
hu' : (c₁ - c₂) * f x ≤ 0
⊢ f x ≤ 0

Proof state:
f : ℝ → ℝ
hf : GrowsPolynomially f
c₁ : ℝ
left✝¹ : c₁ > 0
c₂ : ℝ
left✝ : c₂ > 0
heq : c₁ = c₂
n₀ : ℝ
hn₀ : ∀ b ≥ n₀, ∀ u ∈ Set.Icc (1 / 2 * b) b, f u = c₂ * f b
n : ℕ
hn : n ≥ 1
hyp_ind : ∀ z ∈ Set.Ico (n₀ ⊔ 2) (2 ^ n * (n₀ ⊔ 2)), f z = f (n₀ ⊔ 2)
z : ℝ
hz : z ∈ Set.Ico (2 ^ n * (n₀ ⊔ 2)) (2 ^ (n + 1) * (n₀ ⊔ 2))
⊢ 2 ^ n * (n₀ ⊔ 2) ≤ z

Tactic:
exact_mod_cast hz.1

Result:
no goals

Proof state:
case intro
f : ℝ → ℝ
hf : GrowsPolynomially f
c₁ : ℝ
left✝¹ : c₁ > 0
c₂ : ℝ
left✝ : c₂ > 0
heq : c₁ = c₂
n₀ : ℝ
hn₀ : ∀ b ≥ n₀, ∀ u ∈ Set.Icc (1 / 2 * b) b, f u = c₂ * f b
⊢ ∀ b ≥ n₀ ⊔ 2, f b = f (n₀ ⊔ 2)

Tactic:
refine Real.induction_Ico_mul _ 2 (by norm_num) (by positivity) ?base ?step

Result:
case base
f : ℝ → ℝ
hf : GrowsPolynomially f
c₁ : ℝ
left✝¹ : c₁ > 0
c₂ : ℝ
left✝ : c₂ > 0
heq : c₁ = c₂
n₀ : ℝ
hn₀ : ∀ b ≥ n₀, ∀ u ∈ Set.Icc (1 / 2 * b) b, f u = c₂ * f b
⊢ ∀ x ∈ Set.Ico (n₀ ⊔ 2) (2 * (n₀ ⊔ 2)), f x = f (n₀ ⊔ 2)

case step
f : ℝ → ℝ
hf : GrowsPolynomially f
c₁ : ℝ
left✝¹ : c₁ > 0
c₂ : ℝ
left✝ : c₂ > 0
heq : c₁ = c₂
n₀ : ℝ
hn₀ : ∀ b ≥ n₀, ∀ u ∈ Set.Icc (1 / 2 * b) b, f u = c₂ * f b
⊢ ∀ n ≥ 1,
    (∀ z ∈ Set.Ico (n₀ ⊔ 2) (2 ^ n * (n₀ ⊔ 2)), f z = f (n₀ ⊔ 2)) →
      ∀ z ∈ Set.Ico (2 ^ n * (n₀ ⊔ 2)) (2 ^ (n + 1) * (n₀ ⊔ 2)), f z = f (n₀ ⊔ 2)

Proof state:
case bc
f : ℝ → ℝ
hf : GrowsPolynomially f
c₁ : ℝ
left✝¹ : c₁ > 0
c₂ : ℝ
left✝ : c₂ > 0
heq : c₁ = c₂
n₀ : ℝ
hn₀ : ∀ b ≥ n₀, ∀ u ∈ Set.Icc (1 / 2 * b) b, f u = c₂ * f b
n : ℕ
hn : n ≥ 1
hyp_ind : ∀ z ∈ Set.Ico (n₀ ⊔ 2) (2 ^ n * (n₀ ⊔ 2)), f z = f (n₀ ⊔ 2)
z : ℝ
hz : z ∈ Set.Ico (2 ^ n * (n₀ ⊔ 2)) (2 ^ (n + 1) * (n₀ ⊔ 2))
z_nonneg : 0 ≤ z
le_2n : n₀ ⊔ 2 ≤ 2 ^ n * (n₀ ⊔ 2)
n₀_le_z : n₀ ≤ z
fz_eq_c₂fz : f z = c₂ * f z
z_to_half_z' : f (1 / 2 * z) = c₂ * f z
z_to_half_z : f (1 / 2 * z) = f z
h₁ : 2 ^ n = 1 / 2 * 2 ^ (n + 1)
⊢ z < 2 ^ (n + 1) * (n₀ ⊔ 2)

Tactic:
exact_mod_cast hz.2

Result:
no goals

Proof state:
f : ℝ → ℝ
hf : GrowsPolynomially f
c₁ : ℝ
left✝¹ : c₁ > 0
c₂ : ℝ
left✝ : c₂ > 0
heq : c₁ = c₂
n₀ : ℝ
hn₀ : ∀ b ≥ n₀, ∀ u ∈ Set.Icc (1 / 2 * b) b, f u = c₂ * f b
n : ℕ
hn : n ≥ 1
hyp_ind : ∀ z ∈ Set.Ico (n₀ ⊔ 2) (2 ^ n * (n₀ ⊔ 2)), f z = f (n₀ ⊔ 2)
z : ℝ
hz : z ∈ Set.Ico (2 ^ n * (n₀ ⊔ 2)) (2 ^ (n + 1) * (n₀ ⊔ 2))
z_nonneg : 0 ≤ z
le_2n : n₀ ⊔ 2 ≤ 2 ^ n * (n₀ ⊔ 2)
n₀_le_z : n₀ ≤ z
fz_eq_c₂fz : f z = c₂ * f z
z_to_half_z' : f (1 / 2 * z) = c₂ * f z
z_to_half_z : f (1 / 2 * z) = f z
⊢ 1 / 2 * 2 ^ 1 * (n₀ ⊔ 2) ≤ 1 / 2 * 2 ^ n * (n₀ ⊔ 2)

Tactic:
gcongr

Result:
case h.h.ha
f : ℝ → ℝ
hf : GrowsPolynomially f
c₁ : ℝ
left✝¹ : c₁ > 0
c₂ : ℝ
left✝ : c₂ > 0
heq : c₁ = c₂
n₀ : ℝ
hn₀ : ∀ b ≥ n₀, ∀ u ∈ Set.Icc (1 / 2 * b) b, f u = c₂ * f b
n : ℕ
hn : n ≥ 1
hyp_ind : ∀ z ∈ Set.Ico (n₀ ⊔ 2) (2 ^ n * (n₀ ⊔ 2)), f z = f (n₀ ⊔ 2)
z : ℝ
hz : z ∈ Set.Ico (2 ^ n * (n₀ ⊔ 2)) (2 ^ (n + 1) * (n₀ ⊔ 2))
z_nonneg : 0 ≤ z
le_2n : n₀ ⊔ 2 ≤ 2 ^ n * (n₀ ⊔ 2)
n₀_le_z : n₀ ≤ z
fz_eq_c₂fz : f z = c₂ * f z
z_to_half_z' : f (1 / 2 * z) = c₂ * f z
z_to_half_z : f (1 / 2 * z) = f z
⊢ 1 ≤ 2

Proof state:
f : ℝ → ℝ
hf : GrowsPolynomially f
c₁ : ℝ
left✝¹ : c₁ > 0
c₂ : ℝ
left✝ : c₂ > 0
heq : c₁ = c₂
n₀ : ℝ
hn₀ : ∀ b ≥ n₀, ∀ u ∈ Set.Icc (1 / 2 * b) b, f u = c₂ * f b
x : ℝ
hxlb : n₀ ⊔ 2 ≤ x
hxub : x < 2 * (n₀ ⊔ 2)
h₁ : n₀ ≤ 2 * (n₀ ⊔ 2)
⊢ n₀ ⊔ 2 ≤ 2 * (n₀ ⊔ 2)

Tactic:
linarith

Result:
no goals

Proof state:
case h
f : ℝ → ℝ
hf : GrowsPolynomially f
c₁ : ℝ
left✝¹ : c₁ > 0
c₂ : ℝ
left✝ : c₂ > 0
h : ∀ᶠ (x : ℝ) in atTop, ∀ u ∈ Set.Icc (1 / 2 * x) x, f u ∈ Set.Icc (c₁ * f x) (c₂ * f x)
hgt : c₂ < c₁
x : ℝ
hx : ∀ u ∈ Set.Icc (1 / 2 * x) x, f u ∈ Set.Icc (c₁ * f x) (c₂ * f x)
hx_nonneg : 0 ≤ x
h' : 3 / 4 * x ∈ Set.Icc (1 / 2 * x) x
hu✝ : f (3 / 4 * x) ∈ Set.Icc (c₁ * f x) (c₂ * f x)
hu : c₁ * f x ≤ c₂ * f x
hu' : (c₁ - c₂) * f x ≤ 0
⊢ f x ≤ 0

Tactic:
exact nonpos_of_mul_nonpos_right hu' (by linarith)

Result:
no goals

Proof state:
case intro.inr
f : ℝ → ℝ
hf : GrowsPolynomially f
c₁ : ℝ
left✝¹ : c₁ > 0
c₂ : ℝ
left✝ : c₂ > 0
h : ∀ᶠ (x : ℝ) in atTop, ∀ u ∈ Set.Icc (1 / 2 * x) x, f u ∈ Set.Icc (c₁ * f x) (c₂ * f x)
heq : c₁ = c₂
c : ℝ
hc : ∀ᶠ (x : ℝ) in atTop, f x = c
hneg : c < 0
⊢ (∀ᶠ (x : ℝ) in atTop, 0 ≤ f x) ∨ ∀ᶠ (x : ℝ) in atTop, f x ≤ 0

Tactic:
right

Result:
case intro.inr.h
f : ℝ → ℝ
hf : GrowsPolynomially f
c₁ : ℝ
left✝¹ : c₁ > 0
c₂ : ℝ
left✝ : c₂ > 0
h : ∀ᶠ (x : ℝ) in atTop, ∀ u ∈ Set.Icc (1 / 2 * x) x, f u ∈ Set.Icc (c₁ * f x) (c₂ * f x)
heq : c₁ = c₂
c : ℝ
hc : ∀ᶠ (x : ℝ) in atTop, f x = c
hneg : c < 0
⊢ ∀ᶠ (x : ℝ) in atTop, f x ≤ 0