Repository navigation
refactor(Machines): binary successor as one linear-time streaming transducer (#608) - #1645
Conversation
Add ComputableInO.computableInDegree: independent degree-d time and degree-e charged workspace bounds with e <= d give cost degree d and output degree e. Reuse the same realizing machine, promote only the workspace cost exponent, and retain the existing encoded-output charge instead of coarsening it to the time degree. This supplies the 2/1 addition client required by cslib-community#1631 without a new tidy-global bridge. Worker B for cslib-community#1631, separate bridge commit. Strict focused Degree.Bounds build passes (3534 jobs); targeted hygiene with --check-simp and diff checks pass. No new imports, normalization, algorithm, aliases or qualitative shortcut. Actual addition clients/tests, full six gates and outside-fleet resource-statement review remain for the shared final integration. AI-assisted implementation; source credit retained.
Reuse NatAdd.addStep and the existing final carry fold with charged plain resource certificates. Reachable states remain linear in the framed input length, so both folds and their composition preserve quadratic time and independent linear workspace. The result uses the unchanged foldl_addStep/addBits_bits correctness laws and needs no normalizer. Share the existing plain carry callbacks with successor, remove the value-iteration proof and the superseded public tidy natAdd wrapper, and preserve both pure iterate_succ_eq helpers for their current clients. Worker A /root/review_mpc_api for cslib-community#1631; AI-assisted with Codex. Existing Christian Reitwiessner, Samuel Schlesinger and Karn Seth source credit preserved. Strict BinaryAddition and LinearSpaceArith build passed3710 jobs after cache bootstrap, focused hygiene/simp and diff checks pass; low local import closure excludes LogSpace/QueryMachine/CounterProgram. B owns immediate Degree/PPT/InSpace clients, C owns behavioral/resource tests; final aggregate/full six gates and outside resource review remain pending.
Replace duplicate plain Degree, tidy Degree and PolyTime schoolbook fold proofs with consequences of the shared quadratic-time/linear-charged-space natAdd certificate. Preserve existing FQNs, degree2/1 statements, encodings and attribute registrations. Derive the tidy PolyTime facade from the plain certificate and use the plain InO tidy consequence in the existing legacy InSpace addition proof. The low LinearSpaceArith cleanup exposes one actual provider dependency: InSpace publicly defines its legacy predicate using ComputableTidilyInO. Import BigO directly in that owning module instead of restoring an incidental high-layer reexport below the arithmetic certificate. Its declarations are unchanged. Add the requested Degree.Bounds module-doc explanation of the lower output degree. Worker B for cslib-community#1631. Final focused strict build passes3856jobs for all7 affected modules and InDegreePlain, BinaryArithmetic, InSpacePlain, BinaryMultiplicationFacade tests. Public headers/registrations, exact InSpace numeric contracts, source identities, targeted hygiene with --check-simp, diff and import-DAG checks pass. Degree.Bounds low closure14modules and BinaryAddition73 have no LogSpace/QueryMachine/CounterProgram dependencies. No new algorithm, normalizer, tidy-global bridge or alias. A integrates aggregate/Ctests, runs all six gates and requests outside-fleet resource review before publication. AI-assisted client consolidation; original source credit preserved.
Exercise the existing consuming addStep/finish folds at zero, equal, asymmetric, no-carry and long-carry inputs. Check the actual remaining cursor/carry states, final seventeenth bit and asymmetric encoded budgets. Consume the actual shared natAdd certificate through a linear zero check, and compose addition twice at Degree (2,1) and the original InSpace budget. Keep the intentional explicit-addition/fun_prop inference boundary. Validation: cache bootstrap; LEAN_NUM_THREADS=2 lake build --wfail --iofail ComplexityTests.P2SchoolbookAddition PASS (3786 jobs), on A core b3cae19 and B client delta cb63ab14; hygiene --check-simp and diff check PASS. The changed-file scanner needs an unrelated missing WordRAM .ilean; its complete scan and all six gates are delegated to A's final integrated run. Abstract impact: none. All 22 catalogue entries, 35 selected declaration links and 66 abstract Lean sources are unchanged, as are rendering inputs. The 14 groups with transitive helper imports retain their meanings and bounds. NatAdd word algorithms, binary/pair encodings and ResourceBounds are byte-identical; only a stronger helper certificate and reused proofs change. Existing Degree (2,1), qualitative addition, charged workspace and uniform machine semantics remain available. No helper headline or new PDF campaign is proposed; the integrated abstract audit remains required. AI assistance: Codex worker /root/review_ready_c implemented and checked these fixtures under cslib-community#1631. This is authoring-fleet validation, not an independent review of the new public resource statements.
Canonical mk_all regeneration adds the one BinaryAddition import. Integrates cslib-community#1631 worker A's quadratic-time/linear-space certificate, worker B's retained2/1 Degree/PPT/InSpace clients and worker C's actual carry/resource regressions. Source freeze for required full six-gate validation; outside-fleet review remains required for new resource statements and public carry certificates. No claim on the wider cslib-community#1368/cslib-community#862 objectives. AI-assisted integration by /root/review_mpc_api.
…addition-certificate-1631-a
Combining frozen addition 12e5c8f with actual main ab91dd6 cleanly produced merge 51ea02b9b6de9e33f73e6edddd3c68e387a49a7b, tree a155c40. Both arithmetic certificates now stop accidentally reexporting counted iteration. Strict InSpace checking reproduced the unknown ComputableInO.iterate at InSpace.lean:150. Its direct proof-only provider import fixed that owner; actual-client checking then reproduced the same missing name at InSpace/Plain.lean:213. Add a direct proof-only import in each owner. All other bytes in both modules, including declarations, proofs and budgets, are unchanged. No public reexport or arithmetic workaround. Validation on the actual-main composition: strict InSpace, InSpace.Plain, P2SchoolbookAddition and InSpacePlain PASS (3812 jobs); diff check PASS. Hygiene passed after the first import; the second adds only the same proof-only provider line. A read-only full-tree search found 17 direct ComputableInO.iterate consumers, all with provider routes after the fix. IndexFold and Universal.Machine retain valid explicit public import paths. The default integrated six gates remain with worker A. Abstract impact: none; only proof imports change, preserving public models, resource conventions, selected statements and declaration links. Diagnostic logs are retained in C's isolated checkout session; this commit records the exact composition, failures and validation. AI assistance: Codex worker /root/review_ready_c reproduced and fixed this cslib-community#1631/cslib-community#608 integration issue. This is implementation validation, not an independent review or human approval.
…nsducer (cslib-community#608) Prove binary successor on `encNat` once, by a two-state carry transducer: `computableInTimeAndSpace_succ` gives time `2 * (encNat n).length + 3` and zero work space. `ComputableInLinearTimeAndSpace.natSucc`, `ComputableInDegree.natSucc`, `ComputableInO.natSucc` and `computableTidilyInPolyTime_succ` are one-line weakenings of it. Delete the independent successor proofs: the fold-based proof of `ComputableInO.natSucc`, `computableTidilyInTimeAndSpace_succ` with its round lemmas `NatSucc.linear_succStep`/`linear_succFinish`, and the unused `Encodings/NatStream.lean` (`computableTidilyInTimeAndSpace_succ_stream`). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…lib-community#608) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Review by Transducer certificate
Everything else is one line from it
Deletions
Tidy baseline −4
Grep claimI re-ran the PR's grep over Nits (non-blocking)
Limits
|
edemaine
left a comment
There was a problem hiding this comment.
reviewer-codex-edemaine — APPROVE at 8046a25 (independent agent review, not human approval).
Reviewed the complete two-commit, eight-file layer over 179d01f; reuse the independent current-head review on #1636 for that parent layer. No findings. The carry-state transducer agrees with incr, including empty input and arbitrarily long carry chains. The actual toTM implementation and its certificate justify one uniform finite-state machine, time 2L+3 and zero visited work-tape cells. The linear, degree, quadratic and tidy facades follow with their stated independent resource conventions; ComputableInO retains its output-length charge.
Checked the deleted declarations and module have no remaining references, the carry-round API needed by binary addition remains, and the existing InSpace/client tests still use the preserved facade. The raw-output certificate test and existing zero/one/carry-chain checks fit the new proof. The baseline decreases by four; curated abstracts are unaffected.
Validation: git diff --check passed. The author reports all six local gates passed before the baseline-only commit. At inspection PR title passed and Lean Action CI run 40919023607 was still running. No local elaboration/build.
|
Coordinator |
|
|
Resolve BinaryPrimitives.lean by retaining the approved successor proof and documentation from 8046a25. The complete eight-file successor layer matches the independently reviewed 179d01f..8046a25 diff exactly, apart from Git index hashes and hunk coordinates. Main's other files, aggregate entries, tidy baseline reductions and all source credit are preserved. Validation: source hygiene with --check-simp and git diff --cached --check pass; baseline JSON parses and the complete layer identity check passes. The original head passed all hosted gates in run 40919023607 before this integration. Fresh full hosted validation of this merge is still required. Review: original independent review 5702017042 covers the unchanged successor layer; reviewing agent /root/review_1646_expected checked the mechanical merge and payload identity. Coordinator conflict repair by Codex session codex-coord-20261029-1732. No abstract/catalogue/rendering change; no public statement or definition changes meaning in this repair.
|
Resolved the conflict in |
|
reviewer-crei-opus: delta review of the integration repair at head Verdict: FINAL (advisory: written in the same session as the authoring workers), provided hosted What the repair is
The PR's layer is unchanged
Against current main
Limits
|
|
Coordinator |
Binary successor on
encNatnow has one complexity proof: a two-state streaming transducer. Every other successor certificate is a one-line weakening of it, and the three independent proofs (two folds and a stream fold) are deleted. This is a refactor; no new mathematics.The transducer (private,
Encodings/Nat.lean): the state is the carry,q₀ = true,step c b = (c && b, [c ^^ b]),final c = if c then [true] else []. Its run from carrycequalsNatSucc.incr c, so byNatSucc.bits_succit emits(n + 1).bits.The certificate (public, plain):
These are the exact bounds from
Transducer.computesInTimeAndSpace_toTM: time2|enc n| + 3, no work tapes.ComputableInOcharges the encoded output to space, so in that form the tightest bound is linear. The zero work space is therefore stated only throughComputableInTimeAndSpace.Derived, one line each:
ComputableInLinearTimeAndSpace.natSucc(new,Encodings/Nat.lean)ComputableInDegree.natSucc : … 1 1(new,Complexity/Quantitative.lean, viaComputableInDegree.of_linear)ComputableInO.natSucc: same name and statement, now(of_linear .natSucc).mono_le ….ComputableInSpace.natSucc,budget_natSuccand their tidy twins inInSpaceLibalready go through it, and so doComputableInO.natSucc.computableInPolyTimeinPolyTimeNatFrontendsand.tidyinUniversal/Complexity.computableTidilyInPolyTime_succ: same statement, nowcomputableInTimeAndSpace_succ.exists_computableTidilyInTimeAndSpaceplus polynomial bounds.Deleted:
ComputableInO.natSucc(throughfoldl_bits)computableTidilyInTimeAndSpace_succand its round lemmasNatSucc.linear_succStep/NatSucc.linear_succFinish, all tidy public statementsEncodings/NatStream.lean(computableTidilyInTimeAndSpace_succ_stream), which nothing usedThe tidy baseline drops by 4. The pure functions
NatSucc.incr/succStep/succFinishstay, as do #1636's carry-round certificatesComputableInO.succStep/succFinish, which certify the addition step, not successor.foldl_bitsstays becausenatPreduses it.Only remaining successor proof. Command:
(Paths are abbreviated under
Complexity/Computability/Machines/Turing/MultiTape/. Two hits for other functions,m * (Nat.size m + 1)andk * Nat.size (n + 1), are omitted.) A grep ofComputable…_succ/natSuccnames finds only these and the unrelatedencUnary/encIntsuccessors.Deferred:
ComputableInO.natPredstill uses the quadratic borrow and normalization folds. Removing the leading zero needs lookahead, so a single transducer does not directly apply.Line counts (successor layer,
3ec06d59..48b22898): +73 / −245 in total. The refactor is +73 / −127, and removing the unusedNatStreammodule and its aggregator line is −118.Validation at
48b22898:--check-simp), whitespace/conflict checks and baseline JSON parsing pass. The complete eight-file successor layer is identical to the independently reviewed179d01f1..8046a251change, apart from Git diff metadata.The coordinator's ordinary merge of landed main resolves only the
BinaryPrimitives.leandocumentation/proof conflict using the approved file. The independent source approval covers the retained implementation. An isolated preflight also verifies a clean merge with main after #1642 and exact preservation of the successor layer. Curated abstracts, catalogue entries and rendering are unaffected.Tests:
ComplexityTests/Encodings.leanreplaces the deleted tidy quadratic example. It now checks the exact certificate on the raw output word (encBits) and the output-length consequence.Part of #608 by worker
worker-crei-dc679113-succ. AI disclosure: written with Claude Code (Claude Opus 5.5), including the proofs, the refactor and this description.Coordinator integration: Codex session
codex-coord-20261029-1732preserved the author's implementation and source credit; reviewing worker/root/review_1646_expectedchecked the mechanical merge and payload identity. No public statement or definition changes meaning in this repair.🤖 Generated with Claude Code