Prove2Me
Navigate
DiscoverCollectionsFormalpediaGalaxyBlogsUsersMomentumMy Missions+
Prove2Me
Log in
← Formalpedia

Lemma 2 — chains W(C, k) of prescribed sizes a_k − 1 ≤ N ≤ a_k

Proved
AKSSorting.Core.chainW_exists

by mikedeng1 · Sep 27, 2026 · Mathlib 0df444a (Lean v4.33.1)

combinatoricsp2o-batch-p200ap2o-gran-per-chapterp2o-plan-paperp2o-v1sorting-networks

Let CCC be a chain on level iii and let a0,…,ai−1a_0,\dots,a_{i-1}a0​,…,ai−1​ be nonnegative integers such that

  • (2a) 2∑k<iak<N(C)\displaystyle 2\sum_{k<i}a_k<N(C)2k<i∑​ak​<N(C), and
  • (2.b) for every s<is<is<i: if as′>0a_{s'}>0as′​>0 for some s′<ss'<ss′<s, then ∑k<sak<as\sum_{k<s}a_k<a_s∑k<s​ak​<as​.

Then there are chains W(C,k)W(C,k)W(C,k) on level kkk, 0≤k<i0\le k<i0≤k<i, such that

  1. (1.2) (∪W(C,k))∩(∪W(C,k′))=∅(\cup W(C,k))\cap(\cup W(C,k'))=\emptyset(∪W(C,k))∩(∪W(C,k′))=∅ for k≠k′k\ne k'k=k′;
  2. (1.4) with j=0j=0j=0: W(C,k)(t′)⊆⋃l(t)=i, t≺t′C(t)W(C,k)(t')\subseteq\bigcup_{l(t)=i,\ t\prec t'}C(t)W(C,k)(t′)⊆⋃l(t)=i, t≺t′​C(t) for every node t′t't′ of level k<ik<ik<i;
  3. (2.3) ak−1≤N(W(C,k))≤aka_k-1\le N(W(C,k))\le a_kak​−1≤N(W(C,k))≤ak​ for all k<ik<ik<i;
  4. (2.5) the function W‾(t)=C(t)∖⋃k<i(∪W(C,k))\overline W(t)=C(t)\setminus\bigcup_{k<i}(\cup W(C,k))W(t)=C(t)∖⋃k<i​(∪W(C,k)) on level iii is a chain and
N(C)−∑k<iak≤N(W‾)≤N(C).N(C)-\sum_{k<i}a_k\le N(\overline W)\le N(C).N(C)−k<i∑​ak​≤N(W)≤N(C).

It lets the algorithm move a prescribed number of registers, up to one, from the leaves to every higher level, keeping all levels chains.

Formalization Note "For all kkk there exists a chain W(C,k)W(C,k)W(C,k)" is read as one family WWW that satisfies all conditions jointly, since (1.2) relates different kkk. The quantifiers of (2.b) are read as displayed above. (1.1) is carried by the type (W k is a function on Fin (2^k)); (1.4) is required for levels k<ik<ik<i, the ones on which WWW is defined. Inequality (2.3) and the lower bound of (2.5) are stated in Z\mathbb ZZ, since ak−1a_k-1ak​−1 can be −1-1−1. The paper's numbering skips (2.4).

Preamble
import Mathlib
import Definitions.Def_AKSSorting_Core_IsChain
Formal statement
namespace AKSSorting.Core

/-- Lemma 2 (Ajtai–Komlós–Szemerédi 1983, p. 4). Let `C` be a chain on level `i` and
`a₀, …, a_{i-1}` nonnegative integers with
(2a) `2 ∑_{k<i} a_k < N(C)` and
(2.b) for every `s < i`, if `a_{s'} > 0` for some `s' < s`, then `∑_{k<s} a_k < a_s`.
Then there are chains `W(C, k)` on level `k`, `0 ≤ k < i`, such that (1.2) and (1.4) hold with
`j = 0` and `V = W` ((1.1) is carried by the type), and
(2.3) `a_k − 1 ≤ N(W(C, k)) ≤ a_k` for all `k < i`;
(2.5) `W̄(t) = C(t) − ⋃_{k<i} ∪W(C, k)` is a chain with `N(C) − ∑_{k<i} a_k ≤ N(W̄) ≤ N(C)`. -/
theorem chainW_exists {R : Type} [DecidableEq R] {i : ℕ} (C : Fin (2 ^ i) → Finset R)
    (hC : IsChain C) (a : ℕ → ℕ)
    (h2a : 2 * ∑ k ∈ Finset.range i, a k < chainN C)
    (h2b : ∀ s < i, (∃ s' < s, 0 < a s') → ∑ k ∈ Finset.range s, a k < a s) :
    ∃ W : (k : ℕ) → Fin (2 ^ k) → Finset R,
      (∀ k < i, IsChain (W k)) ∧
      (∀ k < i, ∀ k' < i, k ≠ k' → Disjoint (chainUnion (W k)) (chainUnion (W k'))) ∧
      (∀ k < i, ∀ t' : Fin (2 ^ k), W k t' ⊆ subtreeUnion C k t') ∧
      (∀ k < i, (a k : ℤ) - 1 ≤ (chainN (W k) : ℤ) ∧ chainN (W k) ≤ a k) ∧
      (IsChain (fun t => C t \ (Finset.range i).biUnion fun k => chainUnion (W k)) ∧
        (chainN C : ℤ) - ∑ k ∈ Finset.range i, (a k : ℤ) ≤
          (chainN (fun t => C t \ (Finset.range i).biUnion fun k => chainUnion (W k)) : ℤ) ∧
        chainN (fun t => C t \ (Finset.range i).biUnion fun k => chainUnion (W k)) ≤
          chainN C) := by sorry

end AKSSorting.Core
Source
Ajtai, Komlós, Szemerédi, Sorting in c log n parallel steps, Combinatorica 3 (1983), p. 4, Lemma 2
Human review
  • Endorsed by Shuze Chen · Sep 27, 2026

    Confirmed by the moderator at approval.

  • Endorsed by mikedeng1 · Sep 27, 2026

    Confirmed by the mission captain (proposal self-audit).

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