Created
November 20, 2025 04:35
-
-
Save b-mehta/4441d9b911b399a5b81ea5a42c381c52 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import GlimpseOfLean.Library.Basic | |
| -- This file is adapted from Patrick Massot's Glimpse of Lean: | |
| -- https://github.com/PatrickMassot/GlimpseOfLean | |
| namespace Introduction | |
| /-- A sequence `u` of real numbers converges to `l` if `∀ ε > 0, ∃ N, ∀ n ≥ N, |u_n - l| ≤ ε`. | |
| This condition will be spelled `seq_limit u l`. -/ | |
| def seq_limit (u : ℕ → ℝ) (l : ℝ) := | |
| ∀ ε > 0, ∃ N, ∀ n ≥ N, |u n - l| ≤ ε | |
| /- In the above definition, note that the `n`-th term of the sequence `u` is denoted | |
| simply by `u n`. | |
| Similarly, in the next definition, `f x` is what we would write `f(x)` on paper. | |
| -/ | |
| /-- A function `f : ℝ → ℝ` is continuous at `x₀` if | |
| `∀ ε > 0, ∃ δ > 0, ∀ x, |x - x₀| ≤ δ ⇒ |f(x) - f(x₀)| ≤ ε`. | |
| This condition will be spelled `continuous_at f x₀`.-/ | |
| def continuous_at (f : ℝ → ℝ) (x₀ : ℝ) := | |
| ∀ ε > 0, ∃ δ > 0, ∀ x, |x - x₀| ≤ δ → |f x - f x₀| ≤ ε | |
| /-- Now we claim that if `f` is continuous at `x₀` then it is sequentially continuous | |
| at `x₀`: for any sequence `u` converging to `x₀`, the sequence `f ∘ u` converges | |
| to `f x₀`. | |
| Every thing on the next line describes the objects and assumptions, each with its name. | |
| The following line is the claim we need to prove. -/ | |
| example (f : ℝ → ℝ) (u : ℕ → ℝ) (x₀ : ℝ) (hu : seq_limit u x₀) (hf : continuous_at f x₀) : | |
| seq_limit (f ∘ u) (f x₀) := by -- This `by` keyword marks the beginning of the proof | |
| -- Our goal is to prove that, for any positive `ε`, there exists a natural | |
| -- number `N` such that, for any natural number `n` at least `N`, | |
| -- `|f(u_n) - f(x₀)|` is at most `ε`. | |
| unfold seq_limit | |
| -- Fix a positive number `ε`. | |
| intros ε hε | |
| -- By assumption on `f` applied to this positive `ε`, we get a positive `δ` | |
| -- such that, for all real numbers `x`, if `|x - x₀| ≤ δ` then `|f(x) - f(x₀)| ≤ ε` (1). | |
| obtain ⟨δ, δ_pos, Hf⟩ : ∃ δ > 0, ∀ x, |x - x₀| ≤ δ → |f x - f x₀| ≤ ε := hf ε hε | |
| -- The assumption on `u` applied to this `δ` gives a natural number `N` such that | |
| -- for every natural number `n`, if `n ≥ N` then `|u_n - x₀| ≤ δ` (2). | |
| obtain ⟨N, Hu⟩ : ∃ N, ∀ n ≥ N, |u n - x₀| ≤ δ := hu δ δ_pos | |
| -- Let's prove `N` is suitable. | |
| use N | |
| -- Fix `n` which is at least `N`. Let's prove `|f(u_n) - f(x₀)| ≤ ε`. | |
| intros n hn | |
| -- Thanks to (1) applied to `u_n`, it suffices to prove that `|u_n - x₀| ≤ δ`. | |
| apply Hf | |
| -- This follows from property (2) and our assumption on `n`. | |
| apply Hu n hn | |
| -- This finishes the proof! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment