-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Description
Summary
I have a working formalization of computational complexity classes P and NP built on top of Mathlib's existing Turing.TM1 model (from PostTuringMachine.lean). The code compiles against Mathlib v4.28.0-rc1 with zero sorry, zero warnings under Mathlib lint rules.
I would like to contribute this to Mathlib, incrementally, and am opening this issue to discuss the approach before submitting PRs.
What this adds
-
Turing.TM1.step_none_iff: Basic lemma —step M c = none ↔ c.l = none(follows directly from the definition). -
Turing.TM1.runN: Fuel-based step counter — execute a TM1 machine for at mostnsteps. Key lemmas:runN_stable(halted configs are fixed),runN_comp(composition:runN (a+b) = runN b ∘ runN a),runN_eq_of_halted(output stability). -
Complexity classes:
haltedAt,outputAt,acceptsAt,rejectsAt— predicates on TM1 executionIsPolynomial— polynomial bound on functionsℕ → ℕDecidableInTime— machine decides language within time boundInP,InNP— complexity classes parameterized by acceptance predicate on tape headp_sub_np— P ⊆ NP (proven, zerosorry)PEqNP,PNeNP— formal propositions for the open problem
Relation to existing work
PostTuringMachine.lean(Carneiro 2018): Defines TM0/TM1 models,Turing.eval,Turing.Reaches. No step counting or time bounds. Our work extends this.- PR feat(Computability): Single-tape TM complexity #33132 (BoltonBailey): Defines a new
FinTM0bundled type withEvalsTo/EvalsToInTime. Complementary approach — builds new TM definitions, while ours builds on existingTuring.TM1. TMComputable.lean: Multi-tape TM2 complexity. Orthogonal.- Simas (2026, arXiv:2601.15571): Polynomial-time reductions in Lean 4, but does not use Mathlib's TMs and does not define P/NP classes.
Design choices
- Fuel-based
runNvs. structuralEvalsTo: We userunN : Nat → Cfg → Cfg(fuel-based), which makes monotonicity proofs straightforward. PR feat(Computability): Single-tape TM complexity #33132 usesEvalsTo(a struct with steps + proof). Both are valid; ours is simpler but less informative. - Acceptance via tape head predicate: TM1 has no accept/reject states. We parameterize by
accept : Γ → Propon the tape head at halt, following Sipser §3.1. - Generalized alphabet:
InPandInNPare parameterized over{Γ : Type*} [Inhabited Γ], not a fixed alphabet.
Proposed PR sequence
- PR 1 (small):
step_none_ifflemma inPostTuringMachine.lean - PR 2 (medium):
runN+ lemmas in a new fileMathlib/Computability/TM1Complexity.lean - PR 3 (large): Complexity classes +
p_sub_nptheorem
Questions for maintainers
- Is building on
Turing.TM1the right base model, or should this wait for/coordinate with PR feat(Computability): Single-tape TM complexity #33132'sFinTM0approach? - Is
runN(fuel-based) acceptable, or would a relational approach (EvalsTo-style) be preferred? - Should
IsPolynomiallive in a separate file (e.g.,Mathlib/Computability/Polynomial.lean)?
The full code is available at: https://github.com/KrystianYCSilva/cli-and-ai/blob/main/prompt_os_lean/agente_matematico/AgenteMatematico/MathComplexityContrib.lean