Partial limit of periodic functions

Problem

The intuition is as follows: for any y in the range of f, there exists a strictly increasing sequence of points {x1,x2,} such that y=limif(xi).

Proof

A point yR is called a cluster point of f as x+ if there exists a sequence {xn}nN such that xn+ as n and f(xn)y as n.

Define the sequence {xn} as xn=x0+nT for all nN.
Since T>0, for any BR, there exists an integer N=Bx0T such that for all nN:

xn=x0+nTx0+(Bx0T)T=BxnB

Consequently, limnxn=+.

Using the periodicity of f, we show by induction that f(xn)=y for any nN:

Thus,

limnf(xn)=limny=y

Therefore, yLim(f,+).


Lean

The formal proof of lemma verified in Lean:

import Mathlib.Topology.Basic
import Mathlib
open Set Filter Topology

theorem periodic_cluster_pt
  {f : ℝ → ℝ} {T : ℝ}
  (hT : 0 < T)
  (h_per : ∀ x, f (x + T) = f x) :

  ∀ y ∈ range f, MapClusterPt y atTop f := by
  intro y hy
  rcases hy with ⟨x₀, rfl⟩

  -- Define sequence xₙ = x₀ + nT
  let x : ℕ → ℝ := fun n => x₀ + n * T

  have hx_tendsto : Tendsto x atTop atTop := by
    rw [tendsto_atTop_atTop]
    intro B
    have hmul : Tendsto (fun n : ℕ => (n : ℝ) * T) atTop atTop :=
      tendsto_natCast_atTop_atTop.atTop_mul_const' hT
    rcases (tendsto_atTop_atTop.mp hmul) (B - x₀ + 1) with ⟨N, hN⟩
    use N
    intro n hn
    have h : (n : ℝ) * T ≥ B - x₀ + 1 := hN n hn
    unfold x
    linarith

  -- f(xₙ) = f(x₀)
  have h_const : ∀ n, f (x n) = f x₀ := by
    intro n
    induction n with
    | zero =>
        simp [x]
    | succ n ih =>
        have : x₀ + (n + 1) * T = (x₀ + n * T) + T := by ring
        simp [x, this, h_per, ih]

  -- Therefore, f ∘ x → y
  have h_fx_tendsto : Tendsto (fun n => f (x n)) atTop (𝓝 (f x₀)) := by
    have : (fun n => f (x n)) = fun _ => f x₀ := by
      funext n
      exact h_const n
    simp [this]

  -- Show that (𝓝 (f x₀) ⊓ map f atTop).NeBot
  have h_both : Tendsto (fun n => f (x n)) (atTop ⊓ atTop) (𝓝 (f x₀) ⊓ map (f ∘ x) atTop) :=
    h_fx_tendsto.inf tendsto_map
  have h_neBot : (𝓝 (f x₀) ⊓ map (f ∘ x) atTop).NeBot := by
    rw [inf_idem] at h_both
    exact h_both.neBot

  -- Prove MapClusterPt
  rw [MapClusterPt, ClusterPt]
  apply h_neBot.mono
  apply inf_le_inf_left
  rw [← map_map]
  apply map_mono
  exact hx_tendsto