Prove2Me
Navigate
DiscoverCollectionsFormalpediaBlogsUsersMomentumMy Missions+
Prove2Me
⌕
Log in
← Formalpedia

Stack-machine split of an integer item by a ruler 2^m (quotient and remainder)

Proved
NLogN.Runs.splitR

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σ. Assume stack iii is enc(z)\mathrm{enc}(z)enc(z) followed by RiR_iRi​ and stack jjj is enc(2m)\mathrm{enc}(2^m)enc(2m) followed by RjR_jRj​, where RiR_iRi​ and the tops of k,t1,t2k,t_1,t_2k,t1​,t2​ do not start with a bit symbol. Then splitR q i j k t1 t2 runs from σ\sigmaσ to the state where

i:=enc(sg⁡(z,⌊∣z∣/2m⌋))+ ⁣ ⁣+Ri,k+=enc(sg⁡(z, ∣z∣ mod 2m)),i := \mathrm{enc}\big(\operatorname{sg}(z,\lfloor |z|/2^m\rfloor)\big)\mathbin{+\!\!+}R_i,\qquad k \mathrel{+}= \mathrm{enc}\big(\operatorname{sg}(z,\ |z| \bmod 2^m)\big),i:=enc(sg(z,⌊∣z∣/2m⌋))++Ri​,k+=enc(sg(z, ∣z∣mod2m)),

with cost at most splitCost(m)+17=O(m)\mathrm{splitCost}(m)+17 = O(m)splitCost(m)+17=O(m). Here sg⁡(z,n)\operatorname{sg}(z,n)sg(z,n) is nnn with the sign of zzz, so this is the signed (truncating) division of zzz by 2m2^m2m; the ruler on jjj is kept.

Splitting is used to cut inputs into MMM-bit pieces, to reduce modulo 2n+12^n+12n+1 (via 2n≡−12^n\equiv -12n≡−1), and to extract carry digits; again the cost depends only on mmm.

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

open NLogN
variable {S P : ℕ} {I : List Sym} {prog : Fin P → Stmt S P}
Formal statement
theorem NLogN.Runs.splitR {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) (z : ℤ) (m : ℕ) (Ri Rj : List Sym)
    (hi : σ.stk i = (Item.int z).enc ++ Ri) (hj : σ.stk j = (Item.int ((2 : ℤ) ^ m)).enc ++ Rj)
    (hRi : bitOf Ri.head? = none) (hk : bitOf (σ.stk k).head? = none)
    (ht1 : bitOf (σ.stk t1).head? = none) (ht2 : bitOf (σ.stk t2).head? = none) :
    NLogN.Runs I prog (NLogN.splitR q i j k t1 t2 : Stmt S P) σ
      ((σ.set i ((Item.int (sg z (z.natAbs / 2 ^ m))).enc ++ Ri)).set k
        ((Item.int (sg z (z.natAbs % 2 ^ m))).enc ++ σ.stk k)) (splitCost m + 17) := 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.splitR` of the Lean development NLogN/Shift.lean (lines 230–323), 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