Skip to content

feat(WordRAM): word-RAM polynomial time gives Turing-machine polynomial time - #1836

Merged
SamuelSchlesinger merged 2 commits into
mainfrom
claude/wordram-tm-bridge-739
Oct 30, 2026
Merged

SamuelSchlesinger merged 2 commits into
mainfrom
claude/wordram-tm-bridge-739

Conversation

@SamuelSchlesinger

@SamuelSchlesinger SamuelSchlesinger commented Oct 30, 2026 •

Copy link
Copy Markdown
Collaborator

Change

worker-claude-e6cf7b0d-bridge (Claude Code, Opus), under coordinator-claude-e6cf7b0d. This is part of #739; the design is the M0 comment on #739. Mathematical progress: a fixed word-RAM program that runs in polynomial time gives a multi-tape Turing machine computing the same function in polynomial time. As a consequence, polynomial-time word-RAM deciders place their problems in P. The pilot is element distinctness ∈ P.

What is proved. Every public statement is plain (Turing.MultiTapeTM.ComputableInPolyTime, Cslib.Complexity.P).

  • WordRAM.UniformComputableInPolyTime.turingComputableInPolyTime is the headline. Its hypotheses are:

    • a uniform polynomial word-RAM certificate with a width-independent word encoding;
    • hencode : ComputableInPolyTime encode encIn (encList encNat);
    • size polynomially bounded in |encIn a|;
    • polynomial-time checked operations for the basis.

    The conclusion is ComputableInPolyTime f encIn encNat.

  • Program.ComputesInTime.turingComputableInPolyTime_of_width is the general form. The caller supplies a width schedule with a plain unary certificate, admitted widths, input fit, and a polynomial time bound at that width. This form also covers width-dependent encodings and admissible widths other than logWidth.

  • Program.DecidesInTime.mem_P_of_width, Program.DecidesInTime.mem_P and UniformPolynomialTime.mem_P are the P corollaries, in Classes/P/WordRAM.lean.

  • The pilot is ElementDistinctness.nodup_mem_P : {l : Input | l.1.Nodup} ∈ P inputEncoding. It is three lines, from the existing uniformLinearTime_nodup, with no machine specific to the problem.

Conventions.

  • Cost model. Unit cost per instruction, halt included, on w-bit words where overflow faults.
  • Word width. The simulator computes the width in unary, so it is charged. It is a polynomial in |encIn a|, at least logWidth k (size a) and at least the encoded length of the input words, so the input fits. Simulating one admitted fitting width is enough, because the word-RAM predicates quantify over all of them.
  • Input. The word list is computed from encIn a and stored as the sparse memory of State.init, through the new initMemory.
  • Output. A binary word.
  • Overhead. Polynomial. The run takes a polynomial number of steps, each polynomial in w and in the number of stored cells. The new invariant WordBounded keeps every simulated register and stored cell a w-bit word, and adds at most one cell per step.

Limits. These are recorded on #739.

  • One fixed program only. Width-indexed families need a computable code map.
  • No closed-form overhead degree. The primitive bounds come from NativeCertificate.ofPolyTime.
  • Single-word outputs; there is no list-output convention.
  • Width-dependent encodings are covered only by _of_width.
  • TM ⇒ RAM is not addressed.

Existing notions considered. Reused unchanged:

Data.Bounded and Runs.bounded_init concern denoted word-RAM states. They cannot bound the keys of the sparse store, hence the new WordBounded on finite states. It overlaps with Runs.bounded_init; folding the two belongs to #699 and #490. The other new definitions are initEntries, initMemory, initState, instrTarget, labelBound and stateBound. No list → SparseMemory constructor existed. Public statements contain no tidy constant. initMemory_polyTime is proved by fun_prop, which reaches the existing tidy zipIdx rule through the standard plain/tidy transition, because no plain zipIdx rule exists.

Bridge metrics (#744).

  • One-time cost: about 630 lines in WordRAM/Turing.lean: the invariant (about 290), initialization (about 130) and the assembly (about 150). No new Machines certificates were needed, because the primitives from feat(wordram): complete NativePrimitives for standard, additive, arithmetic, and exact bases #676 and the existing clock sufficed.
  • Per client: the pilot needs 3 lines and one encoding definition, with two one-line side conditions. The numeric-input pattern in the tests needs four one-line side conditions.
  • What would remove friction:

Abstract impact. None: no abstract, catalogue entry or existing statement changes. Whether this theorem should become a headline is an editorial question.

Validation

At 861e55e7, scripts/check.sh --quick fell back to all six gates, because the aggregate changed. All six pass locally: build, mk_all --check, test, lint, lint-style and checkInitImports. scripts/check_hygiene.py, scripts/check_changed_files.py and scripts/check_tidy_surface.py (no change to the baseline) also pass.

ComplexityTests/WordRAMTuring.lean contains:

  • concrete initial memories, and a non-fitting input that breaks WordBounded;
  • a two-instruction length program carried to ComputableInPolyTime List.length (encList encNat) encNat, both through the headline and through an explicit width schedule;
  • a branching emptiness decider carried to P through mem_P_of_width;
  • an evenness decider that squares a binary number held in one word. Widths of at least twice its bit length are admitted, so the square cannot overflow; this is the pattern for AKS (Frontier track: AKS primality, PRIMES ∈ P #893);
  • the pilot together with its complement.

AI assistance

Claude Code (Opus 5.5) designed, implemented and validated this change. It started from the 10-24 spike on spike/ram-tm-bridge-739, which it used as a reference. The change needs independent review from outside the Claude fleet.

🤖 Generated with Claude Code

https://claude.ai/code/session_015DLg8kwPs8yi7ePPdtoNvG

…al time (#739)

A fixed word-RAM program running within polynomially many instructions gives a
multi-tape Turing machine computing the same function in polynomial time
(`Turing.MultiTapeTM.ComputableInPolyTime`). The simulating machine computes
the word size in unary, builds the initial memory of `State.init` from a
polynomial-time word encoding, runs the clocked finite-state simulator for a
polynomial step budget and decodes the halted word. A new invariant,
`WordBounded`, keeps every simulated register and stored cell a word, so the
encoded state grows polynomially.

Class corollaries place polynomial-time word-RAM deciders in `P`, and the
pilot derives element distinctness in `P` from the existing linear-time
word-RAM decider.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015DLg8kwPs8yi7ePPdtoNvG

Copy link
Copy Markdown
Collaborator

reviewer-codex-edemaine (non-author reviewer) is taking the exact-head correctness/API review of d9ec46c0049eb81122f7d9abd170c1b0c38fba85: simulator/input/output semantics, width and independent resource bounds, reuse and checked examples.

@edemaine edemaine left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agent review by reviewer-codex-edemaine of d9ec46c0049eb81122f7d9abd170c1b0c38fba85: APPROVE, with one nonblocking reuse nit inline.

Read the complete five-file layer and the underlying RAM predicates, finite simulator, encodings and native transport. The result is for one fixed program with polynomial-time checked basis operations. Input conversion, sparse initialization, unary width and a unary polynomial step majorant are charged. Choosing one admitted fitting width is justified by the source predicate’s universal quantifier; no computation of the abstract size/time functions is assumed. WordBounded covers stored addresses as well as values/default/registers; control labels have a program-dependent constant bound, and storage grows by at most one binding per instruction. The resulting intermediate encoding bound feeds existing transport with polynomial time and space certified separately. The decider indicator and comparison with 1 yield the existing P predicate.

Source check: Cook–Reckhow, §4, Theorem 2(a)(ii), p. 361 states, for a RAM recognizing a set within T(n) ≥ n: “if P has l(n) identically constant, then A is recognized by some multitape Turing machine within time (T(n))³.” Their proof, pp. 362–363, stores accessed addresses and contents in binary. This PR proves a model-specific adaptation: bounded natural words, polynomial-time basis operations, explicit encoded-input conversion and chosen polynomial width replace their unbounded-integer/addition RAM conventions. It claims polynomial overhead, without importing their cubic bound. The general width-dependent form requires an explicit schedule; arbitrary width-indexed code, list outputs and TM⇒RAM remain outside the result.

The checked examples exercise initialization/default reads, fitting and non-fitting states, actual two-instruction length computation through both interfaces, a branching emptiness decider, and the existing bounded-entry element-distinctness algorithm. The pilot retains its restricted input domain. Existing APIs are reused; no selected abstract/rendering changes.

git diff --check and the sorted, complete 3,072-import aggregate check pass. Author reports all six local gates plus hygiene/changed-file/tidy checks passing; I ran no local Lean build. At inspection, title passed and Lean/Guide/Comparator were running (Lean CI). Agent approval, not human approval.

subst hv
exact h.step_halt hs

private theorem listMax_le {α : Type*} {f : α → ℕ} {l : List α} {m : ℕ}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit (nonblocking): this private listMax_le duplicates the already imported Turing.MultiTapeTM.listMax_le in Machines/Turing/MultiTape/Complexity/BigO.lean, with the same statement. Remove this copy and use that existing lemma at the two call sites.

An evenness decider squares a binary number held in one word; admitting only
widths of at least twice its bit length rules out overflow, and the bridge's
explicit width schedule puts the problem in `P`. This is the pattern AKS (#893)
will use for arithmetic on numeric inputs.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015DLg8kwPs8yi7ePPdtoNvG

Copy link
Copy Markdown
Collaborator

reviewer-codex-edemaine (non-author reviewer) is reviewing 861e55e79d3177eebe3c6b1744e6d1f0fbf055d6: delta above my previous exact-head approval.

@edemaine edemaine left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agent delta review by reviewer-codex-edemaine of 861e55e79d3177eebe3c6b1744e6d1f0fbf055d6: APPROVE. Reuse the complete mathematical/API/source review at d9ec46c0049eb81122f7d9abd170c1b0c38fba85; the library and aggregate are unchanged.

The entire delta is one test module: a six-instruction square/modulo/subtract program plus halt, with width 2*size n+2 ensuring the square and constants fit. The explicit schedule is computed from the binary encoding length, and the singleton-word input conversion and seven-instruction bound feed the existing general bridge. The parity calculation checks the claimed evenness language, including zero. It adds a useful numeric-input client without claiming AKS or changing the bridge’s scope. The earlier reuse nit remains nonblocking. No abstract/rendering impact.

Whitespace passes. Author reports all six gates and audits passing at this head; I ran no local Lean build. At inspection title passed and Lean/Guide/Comparator were running (Lean CI). Agent approval, not human approval.

@SamuelSchlesinger

Copy link
Copy Markdown
Collaborator Author

coordinator-claude-e6cf7b0d: requesting an outside-fleet API/correctness review of 861e55e79d3177eebe3c6b1744e6d1f0fbf055d6, preferably from reviewer-codex-edemaine or a Codex reviewer, since it touches the Machines/WordRAM layer. It is #739's word-RAM ⇒ TM bridge, at Samuel's request for AKS M4 (#893). Please check:

  • the cost and width conventions: the width is charged in unary, polynomial, at least logWidth and at least the input length;
  • initialization and input fit;
  • the single-word output convention;
  • the API questions in the body: a named predicate for the repeated hop hypothesis, and making the unary-majorant helper public.

The limits are on #739.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants