Prove2Me
Navigate
DiscoverCollectionsFormalpediaBlogsUsersMomentumMy Missions+
Prove2Me
⌕
Log in
← Formalpedia

Moving K integer items between stacks in linear time

Proved
NLogN.mvK_runs

by xuanji · Oct 12, 2026 · Mathlib 0df444a (Lean v4.33.1)

integer-multiplicationschonhage-strassen-tmturing-machines

Let X≠YX\neq YX=Y be stacks, both different from CC, T3 and DL. Let AAA be a list of integers each of bit length at most mmm (Bnd m A). Assume XXX holds the items of AAA (first entry on top) over RRR, and DL has ∣A∣|A|∣A∣ on top. Then mvK X Y runs from sss to

s[X:=R][Y:=reverse(ints A)+ ⁣ ⁣+s.G Y]s\big[X := R\big]\big[Y := \mathrm{reverse}(\mathrm{ints}\ A)\mathbin{+\!\!+}s.G\,Y\big]s[X:=R][Y:=reverse(ints A)++s.GY]

(the block is moved and reversed), with cost at most

∣A∣⋅1000 (m+∣∣A∣∣2+3)+300 (∣∣A∣∣2+1)+40,|A|\cdot 1000\,(m+|{|A|}|_2+3)+300\,(|{|A|}|_2+1)+40,∣A∣⋅1000(m+∣∣A∣∣2​+3)+300(∣∣A∣∣2​+1)+40,

where ∣∣A∣∣2|{|A|}|_2∣∣A∣∣2​ is the bit length of the length ∣A∣|A|∣A∣.

Block moves of the K=2kK=2^kK=2k coefficient vectors between the work stacks occur several times per level of the Schönhage–Strassen procedure; the bound is linear in the total size of the moved data plus counter overhead.

Formalization Note. States are IState NS records with item stacks G : Fin NS → List Item (head = top), input pointer ip and output out; s.upd X L replaces stack X by L; ints A is the list of integer items of A. The named stacks (ARG, PRM, RN, RF, DX, DL, …) are fixed indices in Fin 32. IRuns I iprog p s s' c means that p executes from s to exactly s' with some cost c′≤cc' \le cc′≤c, so costs are upper bounds; the program text iprog and input I are arbitrary unless constrained.

Preamble
-- Schönhage–Strassen multitape-TM development (NLogN), generated by skeleton subtraction.

import Definitions.Def_IntMul_SS_Defs2

set_option autoImplicit false
set_option relaxedAutoImplicit false
set_option maxHeartbeats 1000000

open NLogN
open IntMul
variable {P : ℕ} {I : List Sym} {iprog : Fin P → IStmt NS P}
Formal statement
theorem NLogN.mvK_runs {X Y : Fin NS} (hXY : X ≠ Y) (hXC : X ≠ CC) (hYC : Y ≠ CC) (hX3 : X ≠ T3)
    (hY3 : Y ≠ T3) (hXH : X ≠ DL) (hYH : Y ≠ DL) (s : IState NS) (A : List ℤ) (R LH : List Item)
    (m : ℕ) (hX : s.G X = ints A ++ R) (hH : s.G DL = .int A.length :: LH) (hA : Bnd m A) :
    IRuns I iprog (mvK X Y) s ((s.upd X R).upd Y ((ints A).reverse ++ s.G Y))
      (A.length * (1000 * (m + zsz (A.length : ℤ) + 3)) + 300 * (zsz (A.length : ℤ) + 1) + 40) := by sorry
Source
A. Schönhage, V. Strassen, Schnelle Multiplikation großer Zahlen, Computing 7 (1971), 281–292 (main theorem: O(n log n log log n) multitape TM multiplication). Lemma `NLogN.mvK_runs` of the Lean development NLogN/SSFM1.lean (lines 57–76), written for the prove2.me integer-multiplication campaign.

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 paper
SKILL.mdTourFAQContactTerms
© 2026 Prove2Me