Skip to content

feat: add List.mergeSort_append and List.mergeSort_pair - #14995

Merged
kim-em merged 1 commit into
masterfrom
mergeSort_cons_cons
Sep 2, 2026
Merged

feat: add List.mergeSort_append and List.mergeSort_pair#14995
kim-em merged 1 commit into
masterfrom
mergeSort_cons_cons

Conversation

@kim-em

@kim-em kim-em commented Sep 2, 2026

Copy link
Copy Markdown
Collaborator

This PR adds two lemmas exposing the recursion of List.mergeSort without reference to MergeSort.Internal.splitInTwo:

  • mergeSort_append: merging the sorted halves of any balanced split (l₂.length ≤ l₁.length ≤ l₂.length + 1) gives (l₁ ++ l₂).mergeSort. This is the primary statement: it has no index arithmetic, holds uniformly for every list length, and any specific unfolding (take/drop at the midpoint, cons-cons forms) is a two-line corollary.
  • @[simp] mergeSort_pair: [a, b].mergeSort le = if le a b then [a, b] else [b, a], completing the mergeSort_nil/mergeSort_singleton progression. Unlike mergeSort_append it genuinely simplifies, so it is marked @[simp].

Downstream libraries currently have to use the auto-generated List.mergeSort.eq_3 (whose numbering is unstable, and which is not accessible from files using the module system without import all) or unfold splitInTwo's subtype plumbing by hand; this came up in leanprover/cslib#401, where a query-complexity model of merge sort is proved to agree with List.mergeSort.

🤖 Prepared with Claude Code

kim-em added a commit to kim-em/cslib that referenced this pull request Sep 2, 2026
State countQueries_mergeSort_cons_cons with List.mergeSort arguments (the
form eval_mergeSort rewrites to), isolate the List.mergeSort.eq_3 use in a
private helper linking leanprover/lean4#14995, and
derive mergeSort_upperBound through UpperBound.of_pointwise.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Pxy48TaP92UgEq28KGm8BG
@github-actions github-actions Bot added the toolchain-available A toolchain is available for this PR, at leanprover/lean4-pr-releases:pr-release-NNNN label Sep 2, 2026
@mathlib-lean-pr-testing

Copy link
Copy Markdown

Mathlib CI status (docs):

  • ❗ Batteries/Mathlib CI will not be attempted unless your PR branches off the nightly-with-mathlib branch. Try git rebase 0f523461d7a0b12e7ab76e86d8cab60c362af9ef --onto 138ca9f20763523c4093baa092cf371e89535098. You can force Mathlib CI using the force-mathlib-ci label. (2026-09-02 01:49:47)

@leanprover-bot

Copy link
Copy Markdown
Collaborator

Reference manual CI status:

  • ❗ Reference manual CI will not be attempted unless your PR branches off the nightly-with-manual branch. Try git rebase 0f523461d7a0b12e7ab76e86d8cab60c362af9ef --onto c8e19cca2547a89c3aba401afaab9a8808f490a2. You can force reference manual CI using the force-manual-ci label. (2026-09-02 01:49:49)

@kim-em kim-em added the changelog-library Library label Sep 2, 2026
@kim-em
kim-em force-pushed the mergeSort_cons_cons branch from fcae755 to 1aed0ac Compare September 2, 2026 02:27
@kim-em kim-em changed the title feat: List.mergeSort_cons_cons equation lemma feat: List.mergeSort_append and List.mergeSort_pair Sep 2, 2026
kim-em added a commit to kim-em/cslib that referenced this pull request Sep 2, 2026
Replace the private cons-cons unfolding with a mirror of the
mergeSort_append lemma proposed in
leanprover/lean4#14995 (merging the sorted halves
of any balanced split gives mergeSort), deriving the split form from it.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Pxy48TaP92UgEq28KGm8BG
mergeSort_append states that merging the sorted halves of any balanced
split of a list gives mergeSort of the list, exposing the recursion of
mergeSort without reference to MergeSort.Internal.splitInTwo or any index
arithmetic. mergeSort_pair is the two-element simp lemma completing the
mergeSort_nil / mergeSort_singleton progression. Needed by cslib.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Pxy48TaP92UgEq28KGm8BG
@kim-em kim-em changed the title feat: List.mergeSort_append and List.mergeSort_pair feat: add List.mergeSort_append and List.mergeSort_pair Sep 2, 2026
@kim-em
kim-em force-pushed the mergeSort_cons_cons branch from 1aed0ac to dcd3139 Compare September 2, 2026 02:34
@kim-em
kim-em added this pull request to the merge queue Sep 2, 2026
Merged via the queue into master with commit 6778cc8 Sep 2, 2026
21 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

changelog-library Library toolchain-available A toolchain is available for this PR, at leanprover/lean4-pr-releases:pr-release-NNNN

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants