Challenge 11: If aₙ converges to L, then |aₙ| converges to |L|
Prove that if the sequence \(a_n\) converges to \(L\), then \(|a_n|\) converges to \(|L|\).
To do so, complete the following Lean 4 theory:
import Mathlib.Data.Real.Basic import Mathlib.Tactic def SeqLim (a : ℕ → ℝ) (L : ℝ) : Prop := ∀ ε > 0, ∃ k : ℕ, ∀ n ≥ k, |a n - L| < ε variable {a b : ℕ → ℝ} variable {L : ℝ} example (ha : SeqLim a L) (hb : ∀ n, b n = |a n|) : SeqLim b |L| := by sorry
1. Proof in natural language
Let \(b_n = |a_n|\), for all n. We have to prove that \(b_n\) converges to \(|L|\). To do so, let \(ε > 0\); we have to prove that there exists a \(k\) such that \[ ∀ n ≥ k, |b_n - |L|| < ε \tag{1} \]
Since \(a_n\) converges to \(L\), there exists a \(k\) such that \[ ∀ n ≥ k, |a_n - L| < ε \tag{2} \] We show that (1) holds for this \(k\). Indeed, let \[ n ≥ k. \tag{3} \] Then, \[ \begin{array}{llll} |b_n - |L|| &= ||a_n| - |L|| \\ &≤ |a_n - L| &&\text{[by the reverse triangle inequality]} \\ &< ε &&\text{[by (2) and (3)]} \\ \end{array} \]
2. Proofs in Lean 4
import Mathlib.Data.Real.Basic import Mathlib.Tactic def SeqLim (a : ℕ → ℝ) (L : ℝ) : Prop := ∀ ε > 0, ∃ k : ℕ, ∀ n ≥ k, |a n - L| < ε variable {a b : ℕ → ℝ} variable {L : ℝ} -- Proof 1 -- ======= example (ha : SeqLim a L) (hb : ∀ n, b n = |a n|) : SeqLim b |L| := by intro ε hε -- ε : ℝ -- hε : ε > 0 -- ⊢ ∃ k, ∀ n ≥ k, |b n - |L|| < ε obtain ⟨k, hk⟩ := ha ε hε -- k : ℕ -- hk : ∀ n ≥ k, |a n - L| < ε use k -- ⊢ ∀ n ≥ k, |b n - |L|| < ε intro n hn -- n : ℕ -- hn : n ≥ k -- ⊢ |b n - |L|| < ε grind -- Proof 2 -- ======= example (ha : SeqLim a L) (hb : ∀ n, b n = |a n|) : SeqLim b |L| := by intro ε hε -- ε : ℝ -- hε : ε > 0 -- ⊢ ∃ k, ∀ n ≥ k, |b n - |L|| < ε obtain ⟨k, hk⟩ := ha ε hε -- k : ℕ -- hk : ∀ n ≥ k, |a n - L| < ε refine ⟨k, fun _ _ => by grind⟩ -- Proof 3 -- ======= example (ha : SeqLim a L) (hb : ∀ n, b n = |a n|) : SeqLim b |L| := by intro ε hε -- ε : ℝ -- hε : ε > 0 -- ⊢ ∃ k, ∀ n ≥ k, |b n - |L|| < ε obtain ⟨k, hk⟩ := ha ε hε -- k : ℕ -- hk : ∀ n ≥ k, |a n - L| < ε use k -- ⊢ ∀ n ≥ k, |b n - |L|| < ε intro n hn -- n : ℕ -- hn : n ≥ k -- ⊢ |b n - |L|| < ε calc |b n - (|L|)| = |(|a n|) - (|L|)| := by grind _ ≤ |a n - L| := by grind _ < ε := by grind -- Proof 4 -- ======= example (ha : SeqLim a L) (hb : ∀ n, b n = |a n|) : SeqLim b |L| := by intro ε hε -- ε : ℝ -- hε : ε > 0 -- ⊢ ∃ k, ∀ n ≥ k, |b n - |L|| < ε obtain ⟨k, hk⟩ := ha ε hε -- k : ℕ -- hk : ∀ n ≥ k, |a n - L| < ε use k -- ⊢ ∀ n ≥ k, |b n - |L|| < ε intro n hn -- n : ℕ -- hn : n ≥ k -- ⊢ |b n - |L|| < ε calc |b n - (|L|)| = |(|a n|) - (|L|)| := by rw [hb n] _ ≤ |a n - L| := abs_abs_sub_abs_le (a n) L _ < ε := hk n hn -- Proof 5 -- ======= example (ha : SeqLim a L) (hb : ∀ n, b n = |a n|) : SeqLim b |L| := by intro ε hε -- ε : ℝ -- hε : ε > 0 -- ⊢ ∃ k, ∀ n ≥ k, |b n - |L|| < ε obtain ⟨k, hk⟩ := ha ε hε -- k : ℕ -- hk : ∀ n ≥ k, |a n - L| < ε use k -- ⊢ ∀ n ≥ k, |b n - |L|| < ε intro n hn -- n : ℕ -- hn : n ≥ k -- ⊢ |b n - |L|| < ε calc |b n - (|L|)| = |(|a n|) - (|L|)| := congrArg (|· - (|L|)|) (hb n) _ ≤ |a n - L| := abs_abs_sub_abs_le (a n) L _ < ε := hk n hn -- Lemmas used -- =========== variable (x y : ℝ) #check (abs_abs_sub_abs_le x y : |(|x|) - (|y|)| ≤ |x - y|)
The following video explains step by step how the solutions are built:
You can inspect, modify and run the code of these proofs interactively in Lean 4 Web.
3. Collaborative solutions
Have you found a proof that differs from the published ones? You can share it in the comments below by following these steps:
- Write your proof in live.lean-lang.org and check that it compiles without errors.
- Copy the code and post it in the comments of this entry, inside a Lean code block:
```lean -- your proof ```
Comments