Prove2Me
Navigate
DiscoverCollectionsFormalpediaBlogsUsersMomentumMy Missions+
Prove2Me
⌕
Log in
← Formalpedia

Cost bound for attaching target indices to the rows of an array

Proved
NLogN.attachP_cost

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

harvey-van-der-hoeven-tminteger-multiplicationturing-machines

Let DDD be a list of n⋅mn\cdot mn⋅m rows of ddd integers (m≥1m \ge 1m≥1) stored flattened on stack 0, with stacks 1, 2 holding nnn, mmm, and let XXX bound the bit lengths of all entries and of nm+nnm+nnm+n, nm(d+1)nm(d+1)nm(d+1), d+1d+1d+1. Then the program attachP d (which prefixes each row with its index in the transposed order) costs at most 105(nm+1)(d+1)(X+2)10^5(nm+1)(d+1)(X+2)105(nm+1)(d+1)(X+2).

Formalization Note. The machine layer: IState HS is a state with 646464 stacks of items (Item = integer or mark), an input position and an output; RM programs (straight-line register code RS, loops rep, conditionals, calls of the multiplication procedure through a MulSpec MMM giving its domain and cost) have a functional semantics p.run s, a definedness predicate p.ok M s and a cost p.cost M s; Spec M p s s' c abbreviates p.ok M s ∧ p.run s = s' ∧ p.cost M s ≤ c. ints L / gints U push an integer list / a list of pairs as items (head = top); zsz z is the bit length of ∣z∣|z|∣z∣. MulBnd M m Φ says the multiplication procedure accepts all pairs of integers of bit length ≤m\le m≤m at cost ≤Φ\le Φ≤Φ. Register names (GU, CR, KB, XN, …) are fixed stack indices.

Preamble
-- Harvey–van der Hoeven multitape-TM development (NLogN), generated by skeleton subtraction.

import Definitions.Def_IntMul_HvdH_M_Defs4

set_option autoImplicit false
set_option relaxedAutoImplicit false
set_option maxHeartbeats 1000000

set_option linter.unusedSimpArgs false
open NLogN
open IntMul RS
Formal statement
theorem NLogN.attachP_cost (d n m : ℕ) (D : List (List ℤ)) (Rest : List Item) (s : IState HS)
    (hD : D.length = n * m) (hDw : ∀ r ∈ D, r.length = d) (hm : 1 ≤ m)
    (L1 L2 : List Item) (h0 : s.G 0 = ints D.flatten ++ Rest) (h1 : s.G 1 = .int n :: L1)
    (h2 : s.G 2 = .int m :: L2) (X : ℕ) (hDB : ∀ r ∈ D, Bnd X r)
    (hX1 : zsz ((n * m + n : ℕ) : ℤ) ≤ X) (hX2 : zsz ((n * m * (d + 1) : ℕ) : ℤ) ≤ X)
    (hXd : zsz ((d + 1 : ℕ) : ℤ) ≤ X) :
    (attachP d).cost s ≤ 100000 * (n * m + 1) * (d + 1) * (X + 2) := by sorry
Source
D. Harvey, J. van der Hoeven, Integer multiplication in time O(n log n), Ann. of Math. 193 (2021), 563–617 (Theorem 1.1: multitape Turing machine multiplication in O(n log n)). Lemma `NLogN.attachP_cost` of the Lean development NLogN/HTrans.lean (lines 890–970), 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