Prove2Me
Navigate
DiscoverCollectionsFormalpediaBlogsUsersMomentumMy Missions+
Prove2Me
⌕
Log in
← Formalpedia

Stack-machine left shift of an integer item by a ruler 2^m

Proved
NLogN.Runs.shlR

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

integer-multiplicationschonhage-strassen-tmturing-machines

Let q,i,j,t1,t2q,i,j,t_1,t_2q,i,j,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 t1,t2t_1,t_2t1​,t2​ do not start with a bit symbol. Then shlR q i j t1 t2 runs from σ\sigmaσ to

σ[i:=enc(z⋅2m)+ ⁣ ⁣+Ri]\sigma\big[i := \mathrm{enc}(z\cdot 2^m)\mathbin{+\!\!+}R_i\big]σ[i:=enc(z⋅2m)++Ri​]

with cost at most shlCost(m)=moveCost(m)+zipCost(0,m)+23=O(m)\mathrm{shlCost}(m)=\mathrm{moveCost}(m)+\mathrm{zipCost}(0,m)+23 = O(m)shlCost(m)=moveCost(m)+zipCost(0,m)+23=O(m); the ruler on jjj is kept.

Multiplication by powers of two is the "twiddle factor" multiplication of the Fermat-ring FFT and is also used for twisting and untwisting; its cost depends only on the shift amount mmm, not on the size of zzz.

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.shlR {q i j t1 t2 : Fin S} (hqi : q ≠ i) (hqj : q ≠ j) (hqt1 : q ≠ t1)
    (hqt2 : q ≠ t2) (hij : i ≠ j) (hit1 : i ≠ t1) (hit2 : i ≠ t2) (hjt1 : j ≠ t1) (hjt2 : j ≠ 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) (ht1 : bitOf (σ.stk t1).head? = none)
    (ht2 : bitOf (σ.stk t2).head? = none) :
    NLogN.Runs I prog (NLogN.shlR q i j t1 t2 : Stmt S P) σ
      (σ.set i ((Item.int (z * 2 ^ m)).enc ++ Ri)) (shlCost 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.shlR` of the Lean development NLogN/Shift.lean (lines 142–205), 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