pith. machine review for the scientific record. sign in

IndisputableMonolith.Relativity.Analysis.Limits

IndisputableMonolith/Relativity/Analysis/Limits.lean · 177 lines · 13 declarations

show as:
view math explainer →

open module explainer GitHub source

Explainer status: pending

   1import Mathlib
   2
   3/-!
   4# Limits and Asymptotic Analysis
   5
   6Integrates with Mathlib's asymptotics library for rigorous O(·) and o(·) notation.
   7Replaces placeholder error bounds with proper Filter-based definitions.
   8-/
   9
  10namespace IndisputableMonolith
  11namespace Relativity
  12namespace Analysis
  13
  14-- Using Mathlib's Asymptotics when available
  15-- For now, define our own versions
  16
  17/-- Big-O notation: ∃ C, M such that |f(x)| ≤ C|g(x)| for |x-a| < M. -/
  18def IsBigO (f g : ℝ → ℝ) (a : ℝ) : Prop :=
  19  ∃ C > 0, ∃ M > 0, ∀ x, |x - a| < M → |f x| ≤ C * |g x|
  20
  21/-- Little-o notation: ∀ ε > 0, ∃ M such that |f(x)| ≤ ε|g(x)| for |x-a| < M. -/
  22def IsLittleO (f g : ℝ → ℝ) (a : ℝ) : Prop :=
  23  ∀ ε > 0, ∃ M > 0, ∀ x, |x - a| < M → |f x| ≤ ε * |g x|
  24
  25/-- f = O(x^n) as x → 0. -/
  26def IsBigOPower (f : ℝ → ℝ) (n : ℕ) : Prop :=
  27  IsBigO f (fun x => x ^ n) 0
  28
  29/-- f = o(x^n) as x → 0. -/
  30def IsLittleOPower (f : ℝ → ℝ) (n : ℕ) : Prop :=
  31  IsLittleO f (fun x => x ^ n) 0
  32
  33/-- Constant function is O(1). -/
  34theorem const_is_O_one (c : ℝ) :
  35  IsBigO (fun _ => c) (fun _ => 1) 0 := by
  36  unfold IsBigO
  37  have hpos : (0 : ℝ) < |c| + 1 := by have := abs_nonneg c; linarith
  38  refine ⟨|c| + 1, hpos, 1, by norm_num, ?_⟩
  39  intro x _
  40  have h1 : |c| ≤ |c| + 1 := by linarith
  41  simp only [abs_one, mul_one]
  42  exact h1
  43
  44/-- Linear function is O(x). -/
  45theorem linear_is_O_x (c : ℝ) :
  46  IsBigO (fun x => c * x) (fun x => x) 0 := by
  47  unfold IsBigO
  48  have hpos : (0 : ℝ) < |c| + 1 := by have := abs_nonneg c; linarith
  49  refine ⟨|c| + 1, hpos, 1, by norm_num, ?_⟩
  50  intro x _
  51  rw [abs_mul]
  52  have h1 : |c| ≤ |c| + 1 := by linarith
  53  have h2 : |c| * |x| ≤ (|c| + 1) * |x| := by
  54    apply mul_le_mul_of_nonneg_right h1 (abs_nonneg _)
  55  exact h2
  56
  57/-- x² is O(x²) (reflexive). -/
  58theorem x_squared_is_O_x_squared :
  59  IsBigOPower (fun x => x ^ 2) 2 := by
  60  unfold IsBigOPower IsBigO
  61  refine ⟨1, by norm_num, 1, by norm_num, ?_⟩
  62  intro x _
  63  have : |(x ^ 2)| ≤ 1 * |(x ^ 2)| := by simpa
  64  simpa using this
  65
  66/-- O(f) + O(g) = O(h). -/
  67theorem bigO_add (f g h : ℝ → ℝ) (a : ℝ) :
  68  IsBigO f h a → IsBigO g h a → IsBigO (fun x => f x + g x) h a := by
  69  intro hf hg
  70  rcases hf with ⟨C₁, hC₁pos, M₁, hM₁pos, hf⟩
  71  rcases hg with ⟨C₂, hC₂pos, M₂, hM₂pos, hg⟩
  72  have hMinPos : 0 < min M₁ M₂ := lt_min hM₁pos hM₂pos
  73  refine ⟨C₁ + C₂, by linarith, min M₁ M₂, hMinPos, ?_⟩
  74  intro x hx
  75  have hx₁ : |x - a| < M₁ := lt_of_lt_of_le hx (min_le_left _ _)
  76  have hx₂ : |x - a| < M₂ := lt_of_lt_of_le hx (min_le_right _ _)
  77  have hf' := hf x hx₁
  78  have hg' := hg x hx₂
  79  have htri : |f x + g x| ≤ |f x| + |g x| := abs_add_le _ _
  80  have hsum : |f x| + |g x| ≤ (C₁ + C₂) * |h x| := by
  81    have hadd := add_le_add hf' hg'
  82    linarith [mul_nonneg (le_of_lt hC₁pos) (abs_nonneg (h x)),
  83              mul_nonneg (le_of_lt hC₂pos) (abs_nonneg (h x))]
  84  exact le_trans htri hsum
  85
  86/-- O(f) · O(g) = O(f·g). -/
  87theorem bigO_mul (f₁ f₂ g₁ g₂ : ℝ → ℝ) (a : ℝ) :
  88  IsBigO f₁ g₁ a → IsBigO f₂ g₂ a → IsBigO (fun x => f₁ x * f₂ x) (fun x => g₁ x * g₂ x) a := by
  89  intro hf hg
  90  rcases hf with ⟨C₁, hC₁pos, M₁, hM₁pos, hf⟩
  91  rcases hg with ⟨C₂, hC₂pos, M₂, hM₂pos, hg⟩
  92  have hMinPos : 0 < min M₁ M₂ := lt_min hM₁pos hM₂pos
  93  have hCpos : 0 < C₁ * C₂ := mul_pos hC₁pos hC₂pos
  94  refine ⟨C₁ * C₂, hCpos, min M₁ M₂, hMinPos, ?_⟩
  95  intro x hx
  96  have hx₁ : |x - a| < M₁ := lt_of_lt_of_le hx (min_le_left _ _)
  97  have hx₂ : |x - a| < M₂ := lt_of_lt_of_le hx (min_le_right _ _)
  98  have hf' := hf x hx₁
  99  have hg' := hg x hx₂
 100  rw [abs_mul, abs_mul]
 101  have hmul := mul_le_mul hf' hg' (abs_nonneg _) (by linarith [mul_nonneg (le_of_lt hC₁pos) (abs_nonneg (g₁ x))])
 102  calc |f₁ x| * |f₂ x| ≤ (C₁ * |g₁ x|) * (C₂ * |g₂ x|) := hmul
 103    _ = (C₁ * C₂) * (|g₁ x| * |g₂ x|) := by ring
 104
 105/-- Composition preserves O(·) when k is uniformly bounded.
 106
 107    This simplified version assumes k is uniformly bounded, which is
 108    sufficient for our applications. The more general version would require
 109    k → 0 as its argument → 0, combined with f → 0 as x → a. -/
 110theorem bigO_comp (f g h : ℝ → ℝ) (k : ℝ → ℝ) (a : ℝ)
 111  (hfg : IsBigO f g a)
 112  (hk_bound : ∃ K > 0, ∀ y, |k y| ≤ K)  -- Simplified: k uniformly bounded
 113  (hg : ∀ x, |h x| ≤ |g x|) :
 114  IsBigO (fun x => k (f x) * h x) (fun x => g x) a := by
 115  -- With k uniformly bounded by K, we have |k(f x) * h x| ≤ K * |h x| ≤ K * |g x|
 116  rcases hk_bound with ⟨K, hKpos, hK⟩
 117  unfold IsBigO
 118  refine ⟨K, hKpos, 1, by norm_num, ?_⟩
 119  intro x _
 120  rw [abs_mul]
 121  have hk_fx : |k (f x)| ≤ K := hK (f x)
 122  have hh_x : |h x| ≤ |g x| := hg x
 123  calc |k (f x)| * |h x| ≤ K * |h x| := by
 124        apply mul_le_mul_of_nonneg_right hk_fx (abs_nonneg _)
 125    _ ≤ K * |g x| := by
 126        apply mul_le_mul_of_nonneg_left hh_x (le_of_lt hKpos)
 127
 128/-- Little-o is stronger than big-O. -/
 129theorem littleO_implies_bigO (f g : ℝ → ℝ) (a : ℝ) :
 130  IsLittleO f g a → IsBigO f g a := by
 131  intro h
 132  -- Use ε = 1 to obtain a specific bound
 133  have hε := h 1 (by norm_num : (0 : ℝ) < 1)
 134  rcases hε with ⟨M, hMpos, hbound⟩
 135  refine ⟨1, by norm_num, M, hMpos, ?_⟩
 136  intro x hx
 137  simpa using hbound x hx
 138
 139/-- f = o(g) and g = O(h) implies f = o(h). -/
 140theorem littleO_bigO_trans (f g h : ℝ → ℝ) (a : ℝ) :
 141  IsLittleO f g a → IsBigO g h a → IsLittleO f h a := by
 142  intro hfo hgoh ε hεpos
 143  rcases hgoh with ⟨C, hCpos, M₂, hM₂pos, hbound₂⟩
 144  -- Choose ε' so that ε' * C = ε
 145  have hCpos' : 0 < C := hCpos
 146  have hCne : C ≠ 0 := (ne_of_gt hCpos')
 147  let ε' := ε / C
 148  have hε'pos : 0 < ε' := div_pos hεpos hCpos'
 149  rcases hfo ε' hε'pos with ⟨M₁, hM₁pos, hbound₁⟩
 150  have hMinPos : 0 < min M₁ M₂ := lt_min hM₁pos hM₂pos
 151  refine ⟨min M₁ M₂, hMinPos, ?_⟩
 152  intro x hx
 153  have hx₁ : |x - a| < M₁ := lt_of_lt_of_le hx (min_le_left _ _)
 154  have hx₂ : |x - a| < M₂ := lt_of_lt_of_le hx (min_le_right _ _)
 155  have h1 := hbound₁ x hx₁
 156  have h2 := hbound₂ x hx₂
 157  -- |f| ≤ ε'|g| and |g| ≤ C|h| ⇒ |f| ≤ ε' C |h| = ε |h|
 158  have hε'C : ε' * C = ε := div_mul_cancel₀ ε hCne
 159  have hmul : ε' * |g x| ≤ ε' * (C * |h x|) := by
 160    apply mul_le_mul_of_nonneg_left h2 (le_of_lt hε'pos)
 161  have hchain : |f x| ≤ ε' * (C * |h x|) := le_trans h1 hmul
 162  calc |f x| ≤ ε' * (C * |h x|) := hchain
 163    _ = (ε' * C) * |h x| := by ring
 164    _ = ε * |h x| := by rw [hε'C]
 165
 166/-- Stub lemma: linear bound under rescaling. -/
 167lemma stretch_bound (c : ℝ) : |c| + 1 > 0 := by
 168  have : 0 ≤ |c| := abs_nonneg _
 169  linarith
 170
 171/-! **Little-o Multiplication**: If f = o(g) and h is bounded, then f·h = o(g·h).
 172    This is a placeholder for the actual asymptotic result. -/
 173
 174end Analysis
 175end Relativity
 176end IndisputableMonolith
 177

source mirrored from github.com/jonwashburn/shape-of-logic