Repository navigation
Bridge Mathlib's TM2 machines to canonical FP - #72
Merged
SamuelSchlesinger merged 1 commit intoOct 21, 2026
Merged
Conversation
Prove quadratic transition overhead for the existing Mathlib stack-to-tape compiler using the RationalHitting simulation tools in place. Add binary and finite-alphabet input/output adapters, malformed-code rejection, and DFA-guarded FP transfer. Include API regressions, blueprint entries, documentation, and axiom checks.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Context: I proved a lot of complexity/algorithm theorems in https://github.com/edemaine/lean-trominoes and am now trying to "rationalize" against more common infrastructure. Complexitylib seems like one target, and one thing I could use is Mathlib's TM2. In any case this seems like a useful tool for others, and even on your roadmap, so thought I'd make it my first contribution. As it is my first, I may have made some mistakes; happy to revise as you request. (Or feel free to edit yourself.) I haven't actually tried using these theorems yet...
Mathlib’s TM2 machines compute using several stacks, making them convenient for implementing algorithms. Complexitylib’s
FPclass consists of functions on binary strings computable in polynomial time. Complexitylib already connects Mathlib’s single-tape TM0 machines toFP; this PR extends that connection to TM2.Mathlib already compiles TM2 machines into TM0 machines, but its correctness theorem does not bound the simulation’s runtime. This PR establishes a quadratic bound: an input of length
nand a TM2 computation takingtsteps require at mostC * (n + t + 1)²compiled steps, whereCdepends only on the machine. It also proves that the compiled machine produces the expected tape contents, including empty outputs.Combined with Complexitylib’s existing TM0-to-
FPbridge, the new input/output adapters support:Malformed symbol encodings and inputs rejected by the validator return empty output. Output-length bounds follow from the source runtime. Every working stack must have a finite symbol set.
The bridge reuses existing simulation tools from the rational hitting-list development. The original compiler files and their attribution remain unchanged.
This completes the
OAI-TM2-BRIDGEmilestone in the roadmap. That section describes the intended application to OpenAI’s formalization of choiceless polynomial time. Connecting its concrete algorithm and structure encodings to Complexitylib, and completing the planned separation theorem, remain separate work underOAI-CPT-STRUCTURESandOAI-CPT-SEPARATION. The integration notes distinguish the completed bridge from those remaining tasks.Validation passed: the full library build, five validation suites, nine API checks, linters, 29 maintenance-script tests, axiom audit, and blueprint consistency checks. Examples cover different input/output symbol sets, empty symbol sets, malformed encodings, and restricted input domains.