Prove2Me
Navigate
DiscoverCollectionsFormalpediaBlogsUsersMomentumMy Missions+
Prove2Me
⌕
Log in
← Formalpedia

Stack-machine concatenation a·2^m + b of integer items runs in O(m)

Proved
NLogN.Runs.catR

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

integer-multiplicationschonhage-strassen-tmturing-machines

Let q,i,j,k,t1,t2q,i,j,k,t_1,t_2q,i,j,k,t1​,t2​ be pairwise distinct stacks of a state σ\sigmaσ (qqq control stack, t1,t2t_1,t_2t1​,t2​ scratch). Let a≠0a\neq 0a=0 be an integer, m∈Nm\in\mathbb Nm∈N and 0≤b<2m0\le b<2^m0≤b<2m. Assume stack iii is enc(a)\mathrm{enc}(a)enc(a) followed by RiR_iRi​, stack jjj is enc(2m)\mathrm{enc}(2^m)enc(2m) (a "ruler") followed by RjR_jRj​, stack kkk is enc(b)\mathrm{enc}(b)enc(b) followed by RkR_kRk​; RiR_iRi​, RkR_kRk​ and the tops of t1,t2t_1,t_2t1​,t2​ do not start with a bit symbol. Then catR q i j k t1 t2 runs from σ\sigmaσ to

(σ[i:=enc(sg⁡(a, ∣a∣ 2m+b))+ ⁣ ⁣+Ri])[k:=Rk]\big(\sigma[i := \mathrm{enc}(\operatorname{sg}(a,\ |a|\,2^m+b)) \mathbin{+\!\!+} R_i]\big)[k := R_k](σ[i:=enc(sg(a, ∣a∣2m+b))++Ri​])[k:=Rk​]

with cost at most catCost(m)=2 moveCost(m)+zipCost(0,m)+23=O(m)\mathrm{catCost}(m) = 2\,\mathrm{moveCost}(m)+\mathrm{zipCost}(0,m)+23 = O(m)catCost(m)=2moveCost(m)+zipCost(0,m)+23=O(m). Here sg⁡(a,n)\operatorname{sg}(a,n)sg(a,n) is nnn with the sign of aaa; for a>0a>0a>0 the result is a 2m+ba\,2^m+ba2m+b. The ruler on jjj is left in place.

The operation appends the mmm-bit block bbb below the bits of aaa in time linear in mmm only (independent of the size of aaa), which is what makes the Horner recombination of the MMM-bit output digits linear-time.

Formalization Note. Machine states are St S records: stacks stk : Fin S → List Sym over the 16-letter alphabet Sym = Fin 16 (head = top), input position ip and output out; σ.set i L replaces stack i. An integer item is stored as (Item.int z).enc: a sign header followed by the minimal binary magnitude, least significant bit nearest the header; bitOf detects bit symbols, and the hypotheses bitOf (…).head? = none say that the following stack content does not start with a bit (so item boundaries are recognisable). Runs I prog p σ σ' c means p runs from σ to exactly σ' with some cost c′≤cc'\le cc′≤c; the procedures prog and input I are arbitrary.

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

set_option linter.unusedSimpArgs false
open NLogN
variable {S P : ℕ} {I : List Sym} {prog : Fin P → Stmt S P}
Formal statement
theorem NLogN.Runs.catR {q i j k t1 t2 : Fin S} (hqi : q ≠ i) (hqj : q ≠ j) (hqk : q ≠ k)
    (hqt1 : q ≠ t1) (hqt2 : q ≠ t2) (hij : i ≠ j) (hik : i ≠ k) (hit1 : i ≠ t1) (hit2 : i ≠ t2)
    (hjk : j ≠ k) (hjt1 : j ≠ t1) (hjt2 : j ≠ t2) (hkt1 : k ≠ t1) (hkt2 : k ≠ t2) (ht12 : t1 ≠ t2)
    (σ : St S) (a : ℤ) (b m : ℕ) (ha : a ≠ 0) (hb : b < 2 ^ m) (Ri Rj Rk : List Sym)
    (hi : σ.stk i = (Item.int a).enc ++ Ri) (hj : σ.stk j = (Item.int ((2 : ℤ) ^ m)).enc ++ Rj)
    (hk : σ.stk k = (Item.int (b : ℤ)).enc ++ Rk)
    (hRi : bitOf Ri.head? = none) (hRk : bitOf Rk.head? = none)
    (ht1 : bitOf (σ.stk t1).head? = none) (ht2 : bitOf (σ.stk t2).head? = none) :
    Runs I prog (NLogN.catR q i j k t1 t2 : Stmt S P) σ
      ((σ.set i ((Item.int (sg a (a.natAbs * 2 ^ m + b))).enc ++ Ri)).set k Rk) (catCost m) := 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.Runs.catR` of the Lean development NLogN/Cat.lean (lines 71–144), 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