Matrix transposition in time on a multitape Turing machine
ProvedIntMul.TM.transposeMatrix transposition. There are a single deterministic multitape Turing machine and a constant with the following property. Let and let be an matrix whose entries are bit strings of length . Encode row by row, with a single between entries of a row and between rows:
On this input of length , the machine halts within steps and outputs the encoding of the transpose in the same format.
Harvey and van der Hoeven use this to move between the layouts of -dimensional arrays (§2.3), at cost .
Formalization Note The hypotheses make the input word determine , and . Machine model: IntMul_MultitapeModel with arbitrary inputs from IntMul_MultitapeWords.
import Mathlib import Definitions.Def_IntMul_MultitapeModel import Definitions.Def_IntMul_MultitapeWords
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.TMRead-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 and a real constant (chosen after ; independent of everything below) such that for all with , , and every matrix whose entries are bit strings all of length exactly , the following holds. (Here is a matrix dimension, unrelated to the machine's number of tapes.)
Define, for any matrix of bit strings, the word over
i.e. row-major: entries within a row joined by a single , rows joined by a double , nothing at the ends. Let . Then there is with
such that , started on the word , is after exactly steps in with output tape , where is the matrix with (so the output lists the columns of as rows, again single within and between). is the integer ceiling-log with .
Started on a word over means: state , tape holds (letters as ), every other tape holds , all heads at cell . Machine model. A machine has a finite alphabet containing pairwise distinct symbols (blank), (start marker), plus possibly further symbols; a finite state set with ; a fixed number of tapes with cells (tape = read-only input tape, tape = output tape, others work tapes); a transition function acting simultaneously on all tapes (write one symbol and move per tape), which never erases or writes except by rewriting it in place, never moves left from , and leaves the configuration fixed in . "Halts with output at step " means: after exactly steps from the initial configuration the state is and the entire output tape is (cells hold , every later cell blank); work tapes, input tape and head positions are unconstrained. Since is a fixed point, "for some " is the same as "halts within steps".
Quantifiers and edge cases. Empty matrices ( or ) and empty entries () are excluded by hypothesis. With the input word determines , and (entries are nonempty, so occurs exactly at row boundaries), so the required output is a well-defined function of the input. Degenerate shapes: requires output = input within steps; (a single row ) requires output within steps, and symmetrically for . The machine is not told . The log factor uses ; one constant serves all (no threshold). Words not of this form are unconstrained.
Confirmed by the mission captain (proposal self-audit).
Confirmed by the moderator at approval.