-- Mathlib/NumberTheory/Modular.lean
theorem tendsto_abs_re_smul {p : Fin 2 → ℤ} (hp : IsCoprime (p 0) (p 1)) :
    Tendsto
      (fun g : { g : SL(2, ℤ) // g 1 = p } => |((g : SL(2, ℤ)) • z).re|) cofinite atTop

Proof state:
case h
z : ℍ
p : Fin 2 → ℤ
hp : IsCoprime (p 0) (p 1)
⊢ ↑(p 0) ^ 2 + ↑(p 1) ^ 2 ≠ 0

Tactic:
exact mod_cast hp.sq_add_sq_ne_zero

Result:
no goals

Proof state:
z : ℍ
p : Fin 2 → ℤ
hp : IsCoprime (p 0) (p 1)
this : (↑(p 0) ^ 2 + ↑(p 1) ^ 2)⁻¹ ≠ 0
⊢ Tendsto (fun g => (↑g • z).re) cofinite (cocompact ℝ)

Tactic:
let f := Homeomorph.mulRight₀ _ this

Result:
z : ℍ
p : Fin 2 → ℤ
hp : IsCoprime (p 0) (p 1)
this : (↑(p 0) ^ 2 + ↑(p 1) ^ 2)⁻¹ ≠ 0
f : ℝ ≃ₜ ℝ := Homeomorph.mulRight₀ (↑(p 0) ^ 2 + ↑(p 1) ^ 2)⁻¹ this
⊢ Tendsto (fun g => (↑g • z).re) cofinite (cocompact ℝ)

Proof state:
z : ℍ
p : Fin 2 → ℤ
hp : IsCoprime (p 0) (p 1)
this : (↑(p 0) ^ 2 + ↑(p 1) ^ 2)⁻¹ ≠ 0
f : ℝ ≃ₜ ℝ := Homeomorph.mulRight₀ (↑(p 0) ^ 2 + ↑(p 1) ^ 2)⁻¹ this
ff : ℝ ≃ₜ ℝ := Homeomorph.addRight ((↑(p 1) * ↑z - ↑(p 0)) / ((↑(p 0) ^ 2 + ↑(p 1) ^ 2) * (↑(p 0) * ↑z + ↑(p 1)))).re
⊢ Tendsto (fun g => (↑g • z).re) cofinite (cocompact ℝ)

Tactic:
convert (f.trans ff).isClosedEmbedding.tendsto_cocompact.comp (tendsto_lcRow0 hp) with _ _ g

Result:
case h.e'_3.h.h
z : ℍ
p : Fin 2 → ℤ
hp : IsCoprime (p 0) (p 1)
this : (↑(p 0) ^ 2 + ↑(p 1) ^ 2)⁻¹ ≠ 0
f : ℝ ≃ₜ ℝ := Homeomorph.mulRight₀ (↑(p 0) ^ 2 + ↑(p 1) ^ 2)⁻¹ this
ff : ℝ ≃ₜ ℝ := Homeomorph.addRight ((↑(p 1) * ↑z - ↑(p 0)) / ((↑(p 0) ^ 2 + ↑(p 1) ^ 2) * (↑(p 0) * ↑z + ↑(p 1)))).re
e_1✝ : ↑((fun g => ↑g 1) ⁻¹' {p}) = { g // ↑g 1 = p }
g : ↑((fun g => ↑g 1) ⁻¹' {p})
⊢ (↑g • z).re = (⇑(f.trans ff) ∘ fun g => (lcRow0 p) ↑((SpecialLinearGroup.map (Int.castRingHom ℝ)) ↑g)) g

Proof state:
z : ℍ
p : Fin 2 → ℤ
hp : IsCoprime (p 0) (p 1)
⊢ Tendsto (fun g => (↑g • z).re) cofinite (cocompact ℝ)

Tactic:
have : ((p 0 : ℝ) ^ 2 + (p 1 : ℝ) ^ 2)⁻¹ ≠ 0 := by
  apply inv_ne_zero
  exact mod_cast hp.sq_add_sq_ne_zero

Result:
z : ℍ
p : Fin 2 → ℤ
hp : IsCoprime (p 0) (p 1)
this : (↑(p 0) ^ 2 + ↑(p 1) ^ 2)⁻¹ ≠ 0
⊢ Tendsto (fun g => (↑g • z).re) cofinite (cocompact ℝ)

Proof state:
z : ℍ
p : Fin 2 → ℤ
hp : IsCoprime (p 0) (p 1)
⊢ Tendsto (fun g => |(↑g • z).re|) cofinite atTop

Tactic:
suffices
  Tendsto (fun g : (fun g : SL(2, ℤ) => g 1) ⁻¹' {p} => ((g : SL(2, ℤ)) • z).re) cofinite
    (cocompact ℝ)
  by exact tendsto_norm_cocompact_atTop.comp this

Result:
z : ℍ
p : Fin 2 → ℤ
hp : IsCoprime (p 0) (p 1)
⊢ Tendsto (fun g => (↑g • z).re) cofinite (cocompact ℝ)

Proof state:
case h.e'_3.h.h
z : ℍ
p : Fin 2 → ℤ
hp : IsCoprime (p 0) (p 1)
this : (↑(p 0) ^ 2 + ↑(p 1) ^ 2)⁻¹ ≠ 0
f : ℝ ≃ₜ ℝ := Homeomorph.mulRight₀ (↑(p 0) ^ 2 + ↑(p 1) ^ 2)⁻¹ this
ff : ℝ ≃ₜ ℝ := Homeomorph.addRight ((↑(p 1) * ↑z - ↑(p 0)) / ((↑(p 0) ^ 2 + ↑(p 1) ^ 2) * (↑(p 0) * ↑z + ↑(p 1)))).re
e_1✝ : ↑((fun g => ↑g 1) ⁻¹' {p}) = { g // ↑g 1 = p }
g : ↑((fun g => ↑g 1) ⁻¹' {p})
⊢ (↑g • z).re = (⇑(f.trans ff) ∘ fun g => (lcRow0 p) ↑((SpecialLinearGroup.map (Int.castRingHom ℝ)) ↑g)) g

Tactic:
change
  ((g : SL(2, ℤ)) • z).re =
    lcRow0 p ↑(↑g : SL(2, ℝ)) / ((p 0 : ℝ) ^ 2 + (p 1 : ℝ) ^ 2) +
      Complex.re (((p 1 : ℂ) * z - p 0) / (((p 0 : ℂ) ^ 2 + (p 1 : ℂ) ^ 2) * (p 0 * z + p 1)))

Result:
case h.e'_3.h.h
z : ℍ
p : Fin 2 → ℤ
hp : IsCoprime (p 0) (p 1)
this : (↑(p 0) ^ 2 + ↑(p 1) ^ 2)⁻¹ ≠ 0
f : ℝ ≃ₜ ℝ := Homeomorph.mulRight₀ (↑(p 0) ^ 2 + ↑(p 1) ^ 2)⁻¹ this
ff : ℝ ≃ₜ ℝ := Homeomorph.addRight ((↑(p 1) * ↑z - ↑(p 0)) / ((↑(p 0) ^ 2 + ↑(p 1) ^ 2) * (↑(p 0) * ↑z + ↑(p 1)))).re
e_1✝ : ↑((fun g => ↑g 1) ⁻¹' {p}) = { g // ↑g 1 = p }
g : ↑((fun g => ↑g 1) ⁻¹' {p})
⊢ (↑g • z).re =
    (lcRow0 p) ↑((SpecialLinearGroup.map (Int.castRingHom ℝ)) ↑g) / (↑(p 0) ^ 2 + ↑(p 1) ^ 2) +
      ((↑(p 1) * ↑z - ↑(p 0)) / ((↑(p 0) ^ 2 + ↑(p 1) ^ 2) * (↑(p 0) * ↑z + ↑(p 1)))).re

Proof state:
z : ℍ
p : Fin 2 → ℤ
hp : IsCoprime (p 0) (p 1)
⊢ (↑(p 0) ^ 2 + ↑(p 1) ^ 2)⁻¹ ≠ 0

Tactic:
apply inv_ne_zero

Result:
case h
z : ℍ
p : Fin 2 → ℤ
hp : IsCoprime (p 0) (p 1)
⊢ ↑(p 0) ^ 2 + ↑(p 1) ^ 2 ≠ 0

Proof state:
z : ℍ
p : Fin 2 → ℤ
hp : IsCoprime (p 0) (p 1)
this : (↑(p 0) ^ 2 + ↑(p 1) ^ 2)⁻¹ ≠ 0
f : ℝ ≃ₜ ℝ := Homeomorph.mulRight₀ (↑(p 0) ^ 2 + ↑(p 1) ^ 2)⁻¹ this
⊢ Tendsto (fun g => (↑g • z).re) cofinite (cocompact ℝ)

Tactic:
let ff := Homeomorph.addRight
  (((p 1 : ℂ) * z - p 0) / (((p 0 : ℂ) ^ 2 + (p 1 : ℂ) ^ 2) * (p 0 * z + p 1))).re

Result:
z : ℍ
p : Fin 2 → ℤ
hp : IsCoprime (p 0) (p 1)
this : (↑(p 0) ^ 2 + ↑(p 1) ^ 2)⁻¹ ≠ 0
f : ℝ ≃ₜ ℝ := Homeomorph.mulRight₀ (↑(p 0) ^ 2 + ↑(p 1) ^ 2)⁻¹ this
ff : ℝ ≃ₜ ℝ := Homeomorph.addRight ((↑(p 1) * ↑z - ↑(p 0)) / ((↑(p 0) ^ 2 + ↑(p 1) ^ 2) * (↑(p 0) * ↑z + ↑(p 1)))).re
⊢ Tendsto (fun g => (↑g • z).re) cofinite (cocompact ℝ)

Proof state:
z : ℍ
p : Fin 2 → ℤ
hp : IsCoprime (p 0) (p 1)
this : Tendsto (fun g => (↑g • z).re) cofinite (cocompact ℝ)
⊢ Tendsto (fun g => |(↑g • z).re|) cofinite atTop

Tactic:
exact tendsto_norm_cocompact_atTop.comp this

Result:
no goals

Proof state:
case h.e'_3.h.h
z : ℍ
p : Fin 2 → ℤ
hp : IsCoprime (p 0) (p 1)
this : (↑(p 0) ^ 2 + ↑(p 1) ^ 2)⁻¹ ≠ 0
f : ℝ ≃ₜ ℝ := Homeomorph.mulRight₀ (↑(p 0) ^ 2 + ↑(p 1) ^ 2)⁻¹ this
ff : ℝ ≃ₜ ℝ := Homeomorph.addRight ((↑(p 1) * ↑z - ↑(p 0)) / ((↑(p 0) ^ 2 + ↑(p 1) ^ 2) * (↑(p 0) * ↑z + ↑(p 1)))).re
e_1✝ : ↑((fun g => ↑g 1) ⁻¹' {p}) = { g // ↑g 1 = p }
g : ↑((fun g => ↑g 1) ⁻¹' {p})
⊢ (↑g • z).re =
    (lcRow0 p) ↑((SpecialLinearGroup.map (Int.castRingHom ℝ)) ↑g) / (↑(p 0) ^ 2 + ↑(p 1) ^ 2) +
      ((↑(p 1) * ↑z - ↑(p 0)) / ((↑(p 0) ^ 2 + ↑(p 1) ^ 2) * (↑(p 0) * ↑z + ↑(p 1)))).re

Tactic:
exact mod_cast congr_arg Complex.re (smul_eq_lcRow0_add z hp g.2)

Result:
no goals