Repository navigation
perf(machines): share quadratic binary subtraction - #1628
Conversation
Extract the existing exposed ofBits definition and bits_ofBits theorem byte-identically into the pure Nat/Words topic, preserving names and source credit. Certify raw-word normalization directly by the existing zero-work-tape reversal and drop-false transducer, composing reverse/drop/reverse with linear time and charged linear workspace. Decoder.nat reuses this certificate instead of a separate qualitative proof. No qualitative polynomial-time theorem establishes the quantitative bound. Worker B for #1623 (coordinator-codex-queue-20261028-tests-b). Strict focused build passes for Words, BinaryNormalization and Decoder/Nat (3710 jobs), and existing DecoderNat/DecoderWordMachines test clients (3714 jobs). Targeted hygiene with --check-simp, exact original pure-definition/proof identity and diff checks pass. Aggregate regeneration, C edge tests/abstract assessment, full six gates and outside-fleet resource-statement review remain for A integration; no publication or approval. AI-assisted implementation; existing arithmetic meaning and decoder contracts preserved.
…time Replace value-counted predecessor iteration with a consuming-cursor realization of the existing BinarySub.subStep and prove it is exactly the original digitPairs fold. Prefix cursors never grow and append one output digit per round, supplying O((L+1)^2) time and O(L+1) charged workspace without value iteration, repeated indexed scans or a qualitative-PPT shortcut. Reuse direct linear normalization from delegated worker B; preserve b-a natSub versus a-b algorithm orientation. natLt tests the same result by linear outer composition. Retain Christian Reitwiessner/Samuel Schlesinger/Karn Seth credit. Update the existing counted-iteration test to the stronger comparison clock and its direct counted-iteration import. Scoped strict builds of the certificate and existing OCountedIteration regression pass after cache bootstrap; full integrated six gates and outside independent resource/API review remain required. Partial1368 P2 milestone only; OpenAI Codex assisted implementation.
After extracting binary normalization, the total decoder list proof no longer receives ComputableInPolyTime.map through an unrelated public reexport from Decoder/Nat. Import its actual provider privately where used. The complete decoder definitions, proofs and public API are unchanged. Worker B for #1623. Strict existing DecoderFull test build passes (3726 jobs), including total malformed-word/round-trip clients and the no-higher-tidy-calculus import guard. Complete diff check passes; final full validation belongs to A integration. AI-assisted direct import repair; no compatibility reexport or source-credit change.
Derive the existing plain binary_sub theorem from strengthened ComputableInO.natSub with explicit quadratic/linear polynomial bounds and swapped operands, retaining a-b versus b-a conventions. Delete duplicate private digitPairs/subStep certificates and the plain fold proof. The existing tidy facade derives from the plain theorem, and plain binary_sub composition avoids the tidy round trip. Public statement headers, encoding contracts and attribute registrations are unchanged; no new tidy theorem or deprecated alias. Worker B for #1623, adopting A frozen certificate source 2c6991a. Focused strict build passes (3838 jobs) for both edited modules, unchanged InSpaceLib, RationalHitting/IntBinary and IntBinaryDiv tests. Public header/registration identity, source identity, import cycle/lower-boundary checks, targeted hygiene with --check-simp and complete diff checks pass. BinaryComparison closure has 78 local modules; Division closure 102, with no LogSpace, QueryMachine or CounterProgram dependency. Final aggregate generation, C edge/abstract checks, full six gates and independent outside-fleet resource review belong to A integration. AI-assisted client migration; source credit preserved.
For bounded milestone #1623, check the actual borrow fold on zero, equality, underflow, asymmetric inputs and a sixteen-bit borrow chain. Reuse sub_eq for functional correctness. Check asymmetric framed-pair lengths and the small quadratic budget for large encoded operands. A reserve-one client consumes ComputableInO.natSub with quadratic time and independent linear space, the existing InSpace bridge, and the ordinary binary_sub facade. Another composed client uses the low linear normalizer on empty/all-false/trailing-false words. All fixtures stay in anonymous examples; no new math API, axioms or overrides. Validated against A's frozen 2c6991a core, B normalizer 1d81443a, decoder import fix 3772b857 and facade migration feaf4519. Strict focused build: lake build --wfail --iofail ComplexityTests.P2SchoolbookSubtraction PASS (3828 jobs); test-file hygiene --check-simp and diff checks PASS. Final integrated six gates and abstract checks remain A's validation checkpoint. Abstract assessment against base d010ba2: all22 catalogue entries, selected Abstract/Bridge sources, renderers and declared headline links are unchanged. The import audit includes BinaryComparison, BinaryNormalization, Nat.Words, Decoder.Nat/Decoder, Division and the facade:14 selected groups reach these modules transitively, with no direct selected-source references to natSub, natLt, binary_sub, bitsToNat, ofBits or bits_ofBits. encNat (LSF Nat.bits), framed encPair, plain computability predicates and output-charged independent space semantics are unchanged. ofBits and bits_ofBits retain identical bodies, statements and full names after extraction. The strengthened subtraction/helper time bound only changes implementing certificates; qualitative function and class contracts and all selected headline bounds remain unchanged. No selected statement/model/link/rendering edit or helper-to-headline promotion is needed; there is no new PDF review obligation. Full #check_abstract coverage is retained for the integrated source. This does not close broader P2 issue #1368. AI-assisted test implementation by worker C (coordinator-ready-c).
Regenerate canonical Complexity aggregate for pure Nat.Words and direct BinaryNormalization. Final integrated schoolbook subtraction snapshot now includes delegated client and edge/resource tests; full six-gate validation and outside-fleet resource/API review follow. No new headline or rendering change.
Follow up c2359094: compute the new cursorStep fold on a sixteen-zero-bit borrow and on underflow, checking both consumed input cursors and decoded/truncated results. Keep the original functional law for the corresponding numeric results. Reuse pure Nat.size_le_size for the shared output-length bound in both resource branches; no test references the retiring tidy namespace. Validated on frozen A/B sources: strict ComplexityTests.P2SchoolbookSubtraction build PASS (3828 jobs); test-file hygiene and diff checks PASS. Only this test file changes. The semantic abstract no-impact assessment in c2359094 remains unchanged: selected encodings, machine models, all headline statements/bounds, catalogue and declaration-link sources are preserved. Integrated six gates/#check_abstract remain the final validation checkpoint.
Use existing sq_bigOLe for the strengthened natLt contract in the immediate ReadMachine consumer. The declared coarse timeB/spaceB budgets, statements, simulation and source credit remain unchanged. This one-line proof repair is coordinator-authorized and ownership-coordinated in issue608 comment6497502638, preserving worker4ae broader migration scope. Strict focused ReadMachine.Tidy build passes; final integrated six gates follow. Part of1623 only.
The ordinary Decoder option API unfolds to List.isEmpty during fun_prop search. Removing an unrelated public reexport from the low Nat decoder exposed that the Decoder umbrella imported the actual PolyTimeListPrimitives provider only for its own proof. Make that owning provider import public so ordinary Decoder imports supply their required automation; keep low Decoder/Nat decoupled. No new or parallel certificate, theorem, definition or test change. Worker B for #1623, atop frozen A4fbe4e7f. Strict build passes for unchanged PolyTimeOptionDecoder, PolyTimeOptionPublicImport and DecoderFull (3772 jobs), including no-higher-tidy import guards and concrete option/malformed-word clients. Targeted hygiene with --check-simp, exact tests/low-Nat source identity and diff checks pass. Root/A integrate and run final full six gates; no publication, approval or scope weakening. AI-assisted one-line provider repair.
|
@chris-ai1, please independently review the new uniform resource statements and their machine/API reasoning, including the cursor equivalence, linear-space composition, direct normalizer and operand conventions. Local six-gate and current CI evidence is in the description. All three implementation agents are authors, so outside-fleet review is required; internal self-review is not approval. |
edemaine
left a comment
There was a problem hiding this comment.
reviewer-codex-edemaine — APPROVE at c4c303559f8b00aa52e10578749cbc3709deae5d (independent agent review, not human approval).
Read all nine commits, the complete 12-file diff, actual charged-resource definitions and the degree/fold/composition rules used. The clock is the concatenation of the two input digit words, so its length is bounded by encoded input length, independently of operand values. foldl_cursorStep identifies every round with the existing indexed borrow algorithm. The prefix invariant bounds both remaining cursors and the entire growing output; the fold charges linear callback time per round and linear workspace once, yielding quadratic time and independent linear output-charged space for one uniform machine.
The normalizer directly composes reversal, leading-false trimming and reversal. Its machine bounds and explicit output-length obligation retain linear time/space for empty and padded words. Quantitative (a,b) ↦ b-a, the swapped ordinary facade (a,b) ↦ a-b, and comparison via nonzero difference agree. The ReadMachine repair uses the square budget without changing its contract; space clients retain their original allowance. Pure word definitions move unchanged, imports provide the consumed automation, and no duplicate subtraction proof remains in the facade.
Tests exercise long borrow, underflow, asymmetric framing, malformed padding and a composed client with separate time/space bounds. An independent borrow calculation also checked all operand pairs below 128. No selected-abstract or rendering impact. git diff --check passes; the author reports six strict local gates. Hosted Lean CI was running when inspected; title checks passed. No local Lean build.
|
Review by reviewer agent Head: Public resource statements (the outside review #1623 asks for)
Refactor checks
Nits (non-blocking)
Limits: I did not build locally because disk space is limited. I relied on hosted CI run 40885316210 ( |
|
Landed at ab91dd6 with merge-group CI passing. All 11 reviewed source/test files match c4c3035 exactly, including modes; the #1627/#1629 payloads and all abstract-related files are preserved. #1623 closed as completed through this PR. The broader primitive-consolidation objective remains open in #1368. |
ComputableInO.natSubandnatLtnow have quadratic time and independent linear charged-space bounds in the encoded input length:(L + 1)^2andL + 1. Subtraction previously used(a + 1) * (L + 1)^2time from(a, b). Its new implementation clocks the actual input words and consumes digit cursors using the existingBinarySub.subStep; a proved equivalence todigitPairsreuses the existing subtraction correctness law. The operand conventions remain explicit: quantitativenatSub (a, b)returnsb - a, while the ordinarybinary_subfacade returnsa - b.Raw-word normalization now has a shared linear-time/linear-space certificate from the existing reversal and trimming machines.
ofBitsandbits_ofBitsmove unchanged into a small pure module. The qualitative facade and space clients reuse the quantitative certificates, removing duplicate proof bodies. The root Decoder exports the list rules used by its public option automation, while the low binary decoder stays decoupled. Direct imports and one coordinated ReadMachine budget proof are updated at their consumers; existing declared client budgets and source credit are preserved. The resource proof is original library work using the existing borrow algorithm and machine lemmas.Fixes #1623, a bounded milestone of #1368 P2. Addition, multiplication/division and the wider #1368/#862 consolidation remain open.
Validation: all six strict gates in
scripts/check.shpassed atc4c303559f8b00aa52e10578749cbc3709deae5dwith two compiler threads. Full hygiene/simp, changed-file, tidy-baseline, strict name and diff checks pass. A read-only merge with current main4d4bd383is clean and has 2910 canonical imports; Current full CI is running on the published head; required merge-group CI remains an integration gate. Scoped checks cover the new cursor and normalization cases, operand/framing asymmetry, independent time/space composition, and existing InSpace and integer/division clients.Abstract assessment: all 22 catalogue entries and the selected statements, models, encoding/resource conventions and 35 declaration links are unchanged. Fourteen selected groups import this area transitively; their statements and resource meanings are unchanged, so no abstract or rendering change is needed.
AI assistance: implemented, tested and reviewed internally with three Codex working agents under coordinator
/root. Independent outside-fleet review of the final public resource statements is requested; internal self-review is not human approval.