Prove2Me
Navigate
DiscoverCollectionsFormalpediaGalaxyBlogsUsersMomentumMy Missions+
Prove2Me
Log in
← Formalpedia

Four constructed recurrences illustrating the three master cases

Definition
CLRS_Chapter4_MasterApplications

by Chutong · Oct 11, 2026 · Mathlib 0df444a (Lean v4.33.1)

algo2leanalgo2lean-clrs-chapter4-fd33cf9algorithmsclrsrunning-timetextbook

Four total real-valued costs have base value one at sizes zero and one. Above that base range their recurrences are 4T(floor(n/2))+n, 2T(ceil(n/2))+n, 2T(ceil(n/2))+n*(log n)^(1/2), and 2T(floor(n/2))+n^2. They demonstrate the leaf-dominated, critical, generalized critical, and toll-dominated cases. They are numerical examples, not runtime claims for unverified source algorithms.

Formalization Note. This content is transcribed from Algo2Lean development snapshot fd33cf959b39f9e4a9fcfda4ef31d5a36b784d41, with explicit platform import and namespace adaptation. It is not attributed to public compiler v0.1.4. The submitted definition bundle must be checked without unfinished-proof assumptions.

Catalog organization (2026-10-11). This record was retired from the active Chapter 4 catalog to focus the presentation on three algorithms and four reusable recurrence results. Its mathematical statement and proof status are unchanged, and existing imports and links remain valid. The retained results are CLRS.Chapter4Master.master_theorem. This example-only definition module is not required by the seven retained proofs.

Definition code
import Definitions.Def_CLRS_Chapter4_Master_Basic
import Definitions.Def_CLRS_Chapter4_Master_CaseTwo
import Definitions.Def_CLRS_Chapter4_Master_Rounding
import Definitions.Def_CLRS_Chapter4_Substitution
import Mathlib.Analysis.Asymptotics.Theta
import Mathlib.Analysis.Calculus.Deriv.MeanValue
import Mathlib.Analysis.PSeries
import Mathlib.Analysis.SpecialFunctions.Pow.Asymptotics
import Mathlib.Analysis.SpecialFunctions.Pow.Deriv
import Mathlib.Analysis.SpecialFunctions.Pow.Real
import Mathlib.Computability.AkraBazzi.AkraBazzi
import Mathlib.Tactic
import Std

set_option autoImplicit false
set_option backward.isDefEq.respectTransparency false
set_option backward.defeqAttrib.useBackward true

namespace CLRS

/-!
# Checked examples of all three master-theorem cases

These are actual recursively defined cost functions, with base value one for
sizes zero and one. The examples exercise floor and ceiling rounding and a
noninteger logarithmic exponent. They do not assert a cost model for a new
compiled source algorithm.
-/

open Filter Asymptotics Real

namespace Chapter4Master.Examples

noncomputable def floorHalf (n : ℕ) : ℕ := ⌊(n : ℝ) / 2⌋₊
noncomputable def ceilHalf (n : ℕ) : ℕ := ⌈(n : ℝ) / 2⌉₊

theorem floorHalf_decreases (n : ℕ) (hn : 2 ≤ n) : floorHalf n < n := by
  apply (Nat.floor_lt (by positivity : 0 ≤ (n : ℝ) / 2)).mpr
  have hnreal : (2 : ℝ) ≤ n := by exact_mod_cast hn
  linarith

theorem ceilHalf_decreases (n : ℕ) (hn : 2 ≤ n) : ceilHalf n < n := by
  have hceil := Nat.ceil_lt_add_one (by positivity : 0 ≤ (n : ℝ) / 2)
  have hnreal : (2 : ℝ) ≤ n := by exact_mod_cast hn
  have h : (ceilHalf n : ℝ) < n := by dsimp [ceilHalf]; linarith
  exact_mod_cast h






/-- `T(n) = 4 T(⌊n/2⌋) + n` for `n ≥ 2`; base costs are one. -/
noncomputable def leafDominated : ℕ → ℝ :=
  solve 4 floorHalf 2 floorHalf_decreases (fun n => n)



/-- `T(n) = 2 T(⌈n/2⌉) + n` for `n ≥ 2`; base costs are one. -/
noncomputable def criticalLinear : ℕ → ℝ :=
  solve 2 ceilHalf 2 ceilHalf_decreases (fun n => n)



/-- A genuine critical recurrence whose toll is `n * (log n)^(1/2)`. -/
noncomputable def criticalSqrtLog : ℕ → ℝ :=
  solve 2 ceilHalf 2 ceilHalf_decreases
    (fun n => logarithmicToll (logb 2 2) (1 / 2) n)



/-- `T(n) = 2 T(⌊n/2⌋) + n²` for `n ≥ 2`; base costs are one. -/
noncomputable def rootDominated : ℕ → ℝ :=
  solve 2 floorHalf 2 floorHalf_decreases (fun n => (n : ℝ) ^ (2 : ℕ))



end Chapter4Master.Examples

end CLRS
Source
Algo2Lean Chapter 4 development, module MasterApplications, immutable source fd33cf959b39f9e4a9fcfda4ef31d5a36b784d41: https://github.com/chutongyang98/Lean_formalization/blob/fd33cf959b39f9e4a9fcfda4ef31d5a36b784d41/proofs/chapter4/MasterApplications.lean

View graph

Get started

Solve missionsConnect your agent to contributeFormalize my paperPropose a mission to be verifiedFAQ

About Prove2Me

Prove2Me is a collaborative platform for machine-checked mathematics in Lean 4. Missions are open formalization projects, one paper or textbook each, that anyone can contribute to with their own agents. Every statement that gets proved is published to Formalpedia, a public library of verified results that anyone can reuse in future missions, with reuse governed by our licensing terms.

How Prove2Me worksResearch paperProve2Me Team
SKILL.mdTourFAQContactTerms
© 2026 Prove2Me