Mathlib's stack-to-tape compiler has polynomial overhead #
Mathlib already compiles TM2 → TM1 → TM0. This module proves that its compiler
is efficient: a fixed finitely supported stack program has one finite-state
tape simulator running in C * (input.length + sourceTime + 1)^2 transitions.
The constant depends only on the program. The stack-track alphabet is finite
whenever there are finitely many stacks and each stack alphabet is finite.
exists_tm0_computer applies directly to Mathlib's bundled FinTM2 and
TM2OutputsInTime. Both the input and the complete output tape are exactly
TM2to1.trInit of the corresponding stack word, including its bottom marker.
This format stores stacks bottom first. The separate
Complexitylib.Interop.Mathlib.TM2.FP interface supplies the binary input/output
adapters and canonical FP transfer for finite working alphabets.
The timing proofs are reused from the rational hitting-list development and remain in their original modules and namespaces.
Every output stack has length at most the initial input length plus a fixed multiple of the source transition count.
Mathlib's existing stack compiler simulates every terminating source run with quadratic transition overhead, retaining the entire represented stack state.
A bundled Mathlib TM2 has a fixed finite-state tape computer with quadratic overhead and exact input/output stack-track tapes, including empty words.
A Mathlib polynomial-time certificate yields one finite-state TM0 and a polynomial time bound, with its encoded input and complete output tapes explicit.