Imports
import Mathlib
open Filteropen Asymptotics

3.1. Asymptotic Notation

CLRS-compatible wrappers for mathlib's filter-based asymptotics on ℕ → ℝ. Proves equivalence between the CLRS discrete definition and the filter definition, plus standard algebraic properties.

namespace CLRSnamespace Chapter03

Wrapper definitions

def isBigO (f g : ) : Prop := f =O[atTop] gdef isBigOmega (f g : ) : Prop := g =O[atTop] fdef isBigTheta (f g : ) : Prop := isBigO f g isBigOmega f gdef isLittleO (f g : ) : Prop := f =o[atTop] gdef isLittleOmega (f g : ) : Prop := g =o[atTop] f

Equivalence with CLRS discrete definition

-- Need to show isBigO g f, i.e. ∃ c'>0, n₀, ∀ n≥n₀, |g n| ≤ c' * |f n| -- Using c' = c⁻¹ calc |g n| = (c⁻¹ * c) * |g n| := _ = c⁻¹ * (c * |g n|) := _ c⁻¹ * |f n| := calc |g n| = c' * (c'⁻¹ * |g n|) := _ c' * |f n| :=

Algebraic properties

theorem isBigO_refl (f : ) : isBigO f f := theorem isBigOmega_refl (f : ) : isBigOmega f f := isBigO_refl ftheorem isBigTheta_refl (f : ) : isBigTheta f f := isBigO_refl f, isBigOmega_refl ftheorem isBigO_trans {f g h : } (hfg : isBigO f g) (hgh : isBigO g h) : isBigO f h := theorem isBigOmega_trans {f g h : } (hfg : isBigOmega f g) (hgh : isBigOmega g h) : isBigOmega f h := theorem isBigTheta_symm {f g : } (h : isBigTheta f g) : isBigTheta g f := h.2, h.1theorem isBigTheta_trans {f g h : } (hfg : isBigTheta f g) (hgh : isBigTheta g h) : isBigTheta f h := isBigO_trans hfg.1 hgh.1, isBigOmega_trans hfg.2 hgh.2theorem isBigO_add {f₁ f₂ g : } (h₁ : isBigO f₁ g) (h₂ : isBigO f₂ g) : isBigO (λ n => f₁ n + f₂ n) g := theorem isBigTheta_iff (f g : ) : isBigTheta f g isBigO f g isBigO g f := end Chapter03end CLRS