Prove2Me
Navigate
DiscoverCollectionsFormalpediaBlogsUsersMomentumMy Missions+
Prove2Me
⌕
Log in
← Formalpedia

Matrix transposition in time O(Nlog⁡min⁡(m,k))O(N\log\min(m,k))O(Nlogmin(m,k)) on a multitape Turing machine

Proved
IntMul.TM.transpose

by avi · Oct 9, 2026 · Mathlib 0df444a (Lean v4.33.1)

complexity-theoryturing-machines

Matrix transposition. There are a single deterministic multitape Turing machine MMM and a constant c>0c>0c>0 with the following property. Let m,k,ℓ≥1m,k,\ell\ge1m,k,ℓ≥1 and let A=(aij)A=(a_{ij})A=(aij​) be an m×km\times km×k matrix whose entries are bit strings of length ℓ\ellℓ. Encode AAA row by row, with a single #\## between entries of a row and ##\#\### between rows:

a11#a12#⋯#a1k##a21#⋯##am1#⋯#amk.a_{11}\#a_{12}\#\cdots\#a_{1k}\#\#a_{21}\#\cdots\#\#a_{m1}\#\cdots\#a_{mk}.a11​#a12​#⋯#a1k​##a21​#⋯##am1​#⋯#amk​.

On this input of length NNN, the machine halts within c (N+1)(⌈log⁡2min⁡(m,k)⌉+1)c\,(N+1)(\lceil\log_2\min(m,k)\rceil+1)c(N+1)(⌈log2​min(m,k)⌉+1) steps and outputs the encoding of the k×mk\times mk×m transpose ATA^{\mathsf T}AT in the same format.

Harvey and van der Hoeven use this to move between the layouts of ddd-dimensional arrays (§2.3), at cost O(Nlog⁡min⁡(m,k))O(N\log\min(m,k))O(Nlogmin(m,k)).

Formalization Note The hypotheses m,k,ℓ≥1m,k,\ell\ge1m,k,ℓ≥1 make the input word determine mmm, kkk and AAA. Machine model: IntMul_MultitapeModel with arbitrary inputs from IntMul_MultitapeWords.

Preamble
import Mathlib
import Definitions.Def_IntMul_MultitapeModel
import Definitions.Def_IntMul_MultitapeWords
Formal statement
namespace IntMul.TM

theorem transpose :
    ∃ M : MultitapeTM, ∃ c : ℝ, 0 < c ∧
      ∀ (m k ℓ : ℕ) (A : Fin m → Fin k → List Bool), 1 ≤ m → 1 ≤ k → 1 ≤ ℓ → (∀ i j, (A i j).length = ℓ) →
        let enc : (m' k' : ℕ) → (Fin m' → Fin k' → List Bool) → List (Option Bool) :=
          fun m' k' B => List.intercalate [none, none]
            (List.ofFn fun i : Fin m' => joinSep (List.ofFn fun j : Fin k' => bits (B i j)))
        ∃ t : ℕ,
          (t : ℝ) ≤ c * (((enc m k A).length + 1 : ℕ) : ℝ) *
            ((Nat.clog 2 (min m k) + 1 : ℕ) : ℝ) ∧
          M.HaltsWithOutputW (enc m k A) t (enc k m fun j i => A i j) := by sorry

end IntMul.TM
Source
A. Bostan, P. Gaudry, É. Schost, Linear recurrences with polynomial coefficients and application to integer factorization and Cartier–Manin operator, SIAM J. Comput. 36 (2007), 1777–1806, Appendix (matrix transposition on a multitape Turing machine); used in Harvey–van der Hoeven, Ann. of Math. 193 (2021), §2.3, p. 11.
Read-back

What the Lean code literally says, in plain math · claude-opus-5-5

Theorem IntMul.TM.transpose. There exist a deterministic multitape Turing machine MMM and a real constant c>0c > 0c>0 (chosen after MMM; independent of everything below) such that for all m,k,ℓ∈Nm, k, \ell \in \mathbb Nm,k,ℓ∈N with m≥1m \ge 1m≥1, k≥1k \ge 1k≥1, ℓ≥1\ell \ge 1ℓ≥1 and every m×km \times km×k matrix A=(Ai,j)0≤i<m, 0≤j<kA = (A_{i,j})_{0 \le i < m,\ 0 \le j < k}A=(Ai,j​)0≤i<m, 0≤j<k​ whose entries are bit strings all of length exactly ℓ\ellℓ, the following holds. (Here kkk is a matrix dimension, unrelated to the machine's number of tapes.)

Define, for any m′×k′m' \times k'm′×k′ matrix BBB of bit strings, the word over {0,1,#}\{0,1,\#\}{0,1,#}

encm′,k′(B)=ρ0 ## ρ1 ## ⋯ ## ρm′−1,ρi=Bi,0#Bi,1#⋯#Bi,k′−1,\mathrm{enc}_{m',k'}(B) = \rho_0 \,\#\#\, \rho_1 \,\#\#\, \cdots \,\#\#\, \rho_{m'-1}, \qquad \rho_i = B_{i,0} \# B_{i,1} \# \cdots \# B_{i,k'-1},encm′,k′​(B)=ρ0​##ρ1​##⋯##ρm′−1​,ρi​=Bi,0​#Bi,1​#⋯#Bi,k′−1​,

i.e. row-major: entries within a row joined by a single #\##, rows joined by a double ##\#\###, nothing at the ends. Let N=∣encm,k(A)∣=mkℓ+mk+m−2N = |\mathrm{enc}_{m,k}(A)| = mk\ell + mk + m - 2N=∣encm,k​(A)∣=mkℓ+mk+m−2. Then there is t∈Nt \in \mathbb Nt∈N with

t≤c (N+1) (⌈log⁡2min⁡(m,k)⌉+1)t \le c\,(N + 1)\,\bigl(\lceil \log_2 \min(m,k) \rceil + 1\bigr)t≤c(N+1)(⌈log2​min(m,k)⌉+1)

such that MMM, started on the word encm,k(A)\mathrm{enc}_{m,k}(A)encm,k​(A), is after exactly ttt steps in qhaltq_{\mathrm{halt}}qhalt​ with output tape ▹ enck,m(AT) □□⋯\triangleright\, \mathrm{enc}_{k,m}(A^{\mathsf T})\, \square\square\cdots▹enck,m​(AT)□□⋯, where ATA^{\mathsf T}AT is the k×mk \times mk×m matrix with (AT)j,i=Ai,j(A^{\mathsf T})_{j,i} = A_{i,j}(AT)j,i​=Ai,j​ (so the output lists the columns of AAA as rows, again single #\## within and ##\#\### between). ⌈log⁡2⋅⌉\lceil \log_2 \cdot \rceil⌈log2​⋅⌉ is the integer ceiling-log with ⌈log⁡21⌉=0\lceil \log_2 1 \rceil = 0⌈log2​1⌉=0.

Started on a word www over {0,1,#}\{0,1,\#\}{0,1,#} means: state qstartq_{\mathrm{start}}qstart​, tape 000 holds ▹ w □□⋯\triangleright\, w\, \square\square\cdots▹w□□⋯ (letters as 0/1/#\mathtt 0/\mathtt 1/\#0/1/#), every other tape holds ▹□□⋯\triangleright\square\square\cdots▹□□⋯, all heads at cell 000. Machine model. A machine MMM has a finite alphabet containing pairwise distinct symbols □\square□ (blank), ▹\triangleright▹ (start marker), 0,1,#\mathtt 0, \mathtt 1, \#0,1,# plus possibly further symbols; a finite state set with qstart≠qhaltq_{\mathrm{start}} \ne q_{\mathrm{halt}}qstart​=qhalt​; a fixed number kM≥2k_M \ge 2kM​≥2 of tapes with cells 0,1,2,…0,1,2,\dots0,1,2,… (tape 000 = read-only input tape, tape 111 = output tape, others work tapes); a transition function acting simultaneously on all tapes (write one symbol and move ←,−,→\leftarrow,-,\rightarrow←,−,→ per tape), which never erases or writes ▹\triangleright▹ except by rewriting it in place, never moves left from ▹\triangleright▹, and leaves the configuration fixed in qhaltq_{\mathrm{halt}}qhalt​. "Halts with output vvv at step ttt" means: after exactly ttt steps from the initial configuration the state is qhaltq_{\mathrm{halt}}qhalt​ and the entire output tape is ▹ v □□⋯\triangleright\, v\, \square\square\cdots▹v□□⋯ (cells 1..∣v∣1..|v|1..∣v∣ hold vvv, every later cell blank); work tapes, input tape and head positions are unconstrained. Since qhaltq_{\mathrm{halt}}qhalt​ is a fixed point, "for some t≤Tt \le Tt≤T" is the same as "halts within TTT steps".

Quantifiers and edge cases. Empty matrices (m=0m = 0m=0 or k=0k = 0k=0) and empty entries (ℓ=0\ell = 0ℓ=0) are excluded by hypothesis. With ℓ≥1\ell \ge 1ℓ≥1 the input word determines mmm, kkk and AAA (entries are nonempty, so ##\#\### occurs exactly at row boundaries), so the required output is a well-defined function of the input. Degenerate shapes: m=k=1m = k = 1m=k=1 requires output = input within c(ℓ+1)c(\ell+1)c(ℓ+1) steps; m=1m = 1m=1 (a single row e0#⋯#ek−1e_0\#\cdots\#e_{k-1}e0​#⋯#ek−1​) requires output e0##e1##⋯##ek−1e_0\#\#e_1\#\#\cdots\#\#e_{k-1}e0​##e1​##⋯##ek−1​ within c(N+1)c(N+1)c(N+1) steps, and symmetrically for k=1k = 1k=1. The machine is not told m,k,ℓm, k, \ellm,k,ℓ. The log factor uses min⁡(m,k)\min(m,k)min(m,k); one constant ccc serves all m,k,ℓm, k, \ellm,k,ℓ (no threshold). Words not of this form are unconstrained.

Human review
  • Endorsed by Shuze Chen · Oct 9, 2026

    Confirmed by the moderator at approval.

  • Endorsed by avi · Oct 9, 2026

    Confirmed by the mission captain (proposal self-audit).

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