Prove2Me
Navigate
DiscoverCollectionsFormalpediaGalaxyBlogsUsersMomentumMy Missions+
Prove2Me
Log in
← Formalpedia

Lemma 4 — one round of expander comparisons is an ε-halver

Proved
AKSSorting.Core.halver_property

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

expander-graphsp2o-batch-p200ap2o-gran-per-chapterp2o-plan-paperp2o-v1sorting-networks

Let AAA and BBB be disjoint sets of registers, ε>0\varepsilon>0ε>0, and let GGG be a ⟨k,ε⟩\langle k,\varepsilon\rangle⟨k,ε⟩ expander on ⟨A,B⟩\langle A,B\rangle⟨A,B⟩ for some kkk. Let Eε(A,B)E_\varepsilon(A,B)Eε​(A,B) be the set of elementary steps "if the content of aaa is greater than the content of bbb, exchange them", one for each edge {a,b}\{a,b\}{a,b} of GGG with a∈Aa\in Aa∈A, b∈Bb\in Bb∈B. Start from an injective assignment of contents to registers and perform all steps of Eε(A,B)E_\varepsilon(A,B)Eε​(A,B), each exactly once, in an arbitrary order. Write Cont(X)\mathrm{Cont}(X)Cont(X) for the set of final contents of the registers in XXX. Then:

  1. if SSS is a lower section of Cont(A∪B)\mathrm{Cont}(A\cup B)Cont(A∪B) with ∣S∣≤∣A∣|S|\le|A|∣S∣≤∣A∣, then
∣S∖Cont(A)∣≤ε∣S∣;|S\setminus\mathrm{Cont}(A)|\le\varepsilon|S|;∣S∖Cont(A)∣≤ε∣S∣;
  1. if SSS is an upper section of Cont(A∪B)\mathrm{Cont}(A\cup B)Cont(A∪B) with ∣S∣≤∣B∣|S|\le|B|∣S∣≤∣B∣, then ∣S∖Cont(B)∣≤ε∣S∣|S\setminus\mathrm{Cont}(B)|\le\varepsilon|S|∣S∖Cont(B)∣≤ε∣S∣.

So after one round, all but an ε\varepsilonε-fraction of any initial segment of small elements sits in AAA, and symmetrically for large elements in BBB. This approximate halving is the only use of expanders in the AKS network.

Formalization Note The order of the steps is a list steps whose members are exactly the pairs (a,b)(a,b)(a,b) with a∈Aa\in Aa∈A, b∈Bb\in Bb∈B adjacent in GGG, without repetitions; the conclusion must hold for every such list. The lemma is stated for every expander GGG with any degree bound, which covers the paper's fixed choice Gε(A,B)G_\varepsilon(A,B)Gε​(A,B). Contents come from an arbitrary linearly ordered type and the initial position is injective, as in the paper's "one-to-one map of R\mathcal RR onto LLL".

Preamble
import Mathlib
import Definitions.Def_AKSSorting_Core_compareExchange
import Definitions.Def_AKSSorting_Core_IsExpander
import Definitions.Def_AKSSorting_Core_IsLowerSection
Formal statement
namespace AKSSorting.Core

/-- Lemma 4 (Ajtai–Komlós–Szemerédi 1983, p. 7; proved on p. 9). Let `A, B` be disjoint sets of
registers, `ε > 0`, and `G` any `⟨k, ε⟩` expander on `⟨A, B⟩`. Perform every elementary step
of `E_ε(A, B)` — for every edge `{a, b}` of `G` with `a ∈ A`, `b ∈ B`, the compare-exchange that
leaves the smaller content in `a` — exactly once, in an arbitrary order `steps`, starting from
the position `F`. With `F'` the resulting position:
* if `S` is a lower section of `Cont(A ∪ B)` with `|S| ≤ |A|`, then `|S − Cont(A)| ≤ ε|S|`;
* if `S` is an upper section of `Cont(A ∪ B)` with `|S| ≤ |B|`, then `|S − Cont(B)| ≤ ε|S|`. -/
theorem halver_property {R : Type} [DecidableEq R] {α : Type} [LinearOrder α]
    (A B : Finset R) (hAB : Disjoint A B) (ε : ℝ) (hε : 0 < ε) (k : ℕ) (G : SimpleGraph R)
    (hG : IsExpander G A B k ε) (steps : List (R × R))
    (hsteps : ∀ p : R × R, p ∈ steps ↔ (p.1 ∈ A ∧ p.2 ∈ B ∧ G.Adj p.1 p.2))
    (hnodup : steps.Nodup) (F : R → α) (hF : Function.Injective F) :
    let F' := steps.foldl (fun x p => compareExchange p.1 p.2 x) F
    (∀ S : Finset α, IsLowerSection ((A ∪ B).image F') S → S.card ≤ A.card →
        ((S \ A.image F').card : ℝ) ≤ ε * S.card) ∧
    (∀ S : Finset α, IsUpperSection ((A ∪ B).image F') S → S.card ≤ B.card →
        ((S \ B.image F').card : ℝ) ≤ ε * S.card) := by sorry

end AKSSorting.Core
Source
Ajtai, Komlós, Szemerédi, Sorting in c log n parallel steps, Combinatorica 3 (1983), p. 7, Lemma 4 (proof p. 9); p. 6, Definitions 3.1-3.3
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