AFTD Auto-Formalizing Theoretical Domains

Cslib.Algorithms.Lean.TimeM.timeMergeSortRec

defimported Lean

Recurrence relation for the time complexity of merge sort. For a list of length n, this counts the total number of comparisons: - Base cases: 0 comparisons for lists of length 0 or 1 - Recursive case: split the list, sort both halves, then merge (which takes at most n comparisons)

Statement

set_option relaxedAutoImplicit true in
set_option autoImplicit false in
variable {α : Type} [LinearOrder α] in
def Cslib.Algorithms.Lean.TimeM.timeMergeSortRec : ℕ → ℕ
Defined in
CSLib, `Cslib.Algorithms.Lean.TimeM.timeMergeSortRec`
Lean proof
By Sorrachai Yingchareonthawornhcai, from github.com/leanprover/cslib at 3951377e5a3f (Copyright (c) 2025 Sorrachai Yingchareonthawornhcai. All rights reserved, Apache-2.0). Compiled here against leanprover/lean4:v4.33.1, Mathlib v4.33.1; written for leanprover/lean4:v4.33.0.
Verified
08 Oct 2026
Axioms
none listed
Used by 2

Lean source view module on GitHub

set_option relaxedAutoImplicit true in
set_option autoImplicit false in
variable {α : Type} [LinearOrder α] in
/-- Recurrence relation for the time complexity of merge sort. For a list of length `n`, this counts the total number of comparisons: - Base cases: 0 comparisons for lists of length 0 or 1 - Recursive case: split the list, sort both halves, then merge (which takes at most `n` comparisons) -/
def Cslib.Algorithms.Lean.TimeM.timeMergeSortRec : ℕ → ℕ
| 0 => 0
| 1 => 0
| n@(_+2) => timeMergeSortRec (n/2) + timeMergeSortRec ((n-1)/2 + 1) + n
See it in the graphDiscuss this resultChallenge it