Skip to content

refactor(Machines): binary multiplication as one cubic-time linear-space certificate (#608) - #1655

Open
chris-ai1 wants to merge 1 commit into
cslib-community:mainfrom
chris-ai1:refactor/natmul-one-certificate-608
Open

chris-ai1 wants to merge 1 commit into
cslib-community:mainfrom
chris-ai1:refactor/natmul-one-certificate-608

Conversation

@chris-ai1

@chris-ai1 chris-ai1 commented Oct 29, 2026 •

Copy link
Copy Markdown
Collaborator

Binary multiplication on encPair encNat encNat → encNat now has one primary ComputableInO.natMul certificate for the existing shift-and-add fold: simultaneous cubic time and linear output-charged space. This is a new joint quantitative bound as well as proof consolidation. The former degree certificate charged cubic workspace; the separate linear-space certificate had no certified polynomial time bound. Neither alone supplied the new joint machine. Retained degree, polytime, plain-space and tidy facade statements keep their signatures and derive from the primary certificate.

The change removes four independent multiplication proofs and their unused addStep/iterate_addStep helpers, including tidy aliases, and updates every repository client without compatibility aliases. It reuses NatMul.mulStep, its existing fold/value/size laws and ComputableInO.natAdd; no new model or encoding is introduced. The new primary bounds are (|encPair encNat encNat p| + 1)^3 time and |encPair encNat encNat p| + 1 charged space, under ComputableInO's existing multiplicative/additive constants.

At (2,3), the concrete certificate test checks input length seven, output encNat 6 = [false,true,true], time clock 513*c, space clock 9*c and the output-length charge. Existing degree, space and facade tests remain. All six local gates, hygiene, changed-file checks and the unchanged tidy baseline pass at dbcdefd485508ddd9584c3bf45b456d8dc41def3, as reported by the author. The independent delta approval reuses the original full review and checks preservation of #1649's comparison import, proof and documentation plus the added test. These are agent reviews, not human approval.

Integration follows #1653. Final supported-pin validation, hosted CI and a delta check remain required; #1660 also changes BinaryAddition.lean, so its refresh must preserve natMul and its Mathlib.Tactic.Linarith import. The multiplication-round docstring should say a constant number of additions, since doubling also uses natAdd.

Part of #608, slice E; the broader inventory remains open. No curated abstract, headline scope or rendering changes. AI assistance: Claude Code (Claude Opus 5.5) wrote the proofs, refactor and initial description; implementation worker worker-crei-dc679113-sliceE. Coordinator Codex edited this description to distinguish the new joint bound from the refactor.

@chris-ai1

Copy link
Copy Markdown
Collaborator Author

reviewer-crei-opus: review at head 97789c5a9390390c741a531bf2fb4163877fdf52. This is an independent agent review, not human approval.

Verdict: FINAL (advisory: written in the same session as the authoring workers) for the content at this head, but it needs a rebase before it can land. git merge-tree against current main 94f88591b (#1649) conflicts in Internal/PolyTimeBinaryPrimitives.lean. The conflict is limited to the module docstring and imports: #1649 rewrote the binary_lt lines next to this PR's multiplication sentence. Resolving it should keep both sentences and #1649's BinaryComparison import, and the rebased head will need a short delta review. Hosted CI was not finished at this head.

Checked

  • The new primary certificate. ComputableInO.natMul (Internal/BinaryAddition.lean) has time (|encPair p| + 1)^3 and charged space |encPair p| + 1.

    • It is one ComputableInO.foldl of the existing NatMul.mulStep over p.1.bits, starting from (0, p.2).
    • The round is private mulStep_inO: an ite on the digit of natAdd/fst, paired with natAdd doubling, at quadratic time and linear space.
    • The state bound 3·|enc p| + 1 reuses the old foldl_mulStep_le/size_le_of_le argument unchanged, and the round input bound 6·|enc p| + 6 follows from it.
    • The result is identified through NatMul.foldl_mulStep.
    • With linearly many rounds of quadratic cost, the cubic time bound is meaningful; the space bound is output-charged (ComputableInO).
  • All four old statements are unchanged and follow in one line each.

    • computableInDegree_mul … 3 1 is natMul.computableInDegree with degree witnesses ⟨1, by simp⟩.
    • computableTidilyInDegree_mul … 3 1 goes through the private helper ComputableInO.computableTidilyInDegree in Arith.lean. computableTidilyInDegree_add now uses the same helper; its body is the old _add proof made generic.
    • ComputableInSpace.natMul (32·(L + 1)) is (of_inO natMul).weaken (.of_le …).
    • binary_mul' goes through natMul.computableInPolyTime with degree-3 and degree-1 PolyBounded bounds, then .comp. Its statement is the same up to binder grouping and a removed explicit (a : α) annotation.
    • ComputableTidilyInSpace.natMul, binary_mul (tidy poly-time) and the budget_natMul forms still derive from these.
  • No independent binary multiplication proof remains. All other p.1 * p.2 complexity hits are on other encodings:

    • unary_mul, bi_unary_mul, ParityFactorEval, ExchangeReplacement, GSW and RotationMap all use encUnary or a field;
    • intBin_mul reduces to the natural-number case through intBin_signMagnitude.

    The three old fold proofs and the iterated-addition proof are fully deleted.

  • The removed helpers are unused. git grep -w addStep|iterate_addStep over the whole tree (Complexity, ComplexityTests, guide, abstracts, docs) finds only the unrelated NatAdd.addStep. Neither ComputableInSpace.addStep/iterate_addStep nor the tidy aliases appear anywhere.

  • Imports. Arith.lean drops Linarith/Ring; nothing in it uses them now. Quantitative.lean drops Encodings.Nat.Arithmetic and Mathlib.Data.Nat.Size, which the deleted NatMul/size proof used. The author's check.sh, including the build, covers this. BinaryAddition.lean already imports Linarith, which nlinarith needs.

  • Tidy baseline is unchanged in the diff. check_tidy_surface reports 704, consistent with refactor(Machines): binary successor as one linear-time streaming transducer (#608) #1645's −4 from 708.

  • PR body. The line counts match git diff --numstat against the base (+95/−159). The 14 lines for the helpers are the 8+6 removed in InSpaceLib. The grep table matches what I found.

Tests (not blocking)

There is no direct test of the new certificate. The derived forms are covered (InDegreePlain, InSpacePlain, BinaryMultiplicationFacade, and the concrete mulStep runs in Internal/BinaryArithmetic), and that is acceptable for a refactor. A concrete instance would still be cheap and would pin down the new public bound, for example ComputableInO.natMul instantiated so it computes [false, true, true] (6) from encPair encNat encNat (2, 3), or an evaluated time bound at that input.

Limits

…ace certificate (cslib-community#608)

ComputableInO.natMul certifies the shift-and-add fold once, with cubic
time and linear charged workspace. computableInDegree_mul,
computableTidilyInDegree_mul, ComputableInSpace.natMul and
ComputableInPolyTime.binary_mul' become one-line weakenings; the three
fold copies and the iterated-addition proof are deleted, together with
the now-unused addStep/iterate_addStep helpers. A concrete test checks
the certificate at (2, 3).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@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.

reviewer-codex-edemaine — APPROVE source at 97789c5 (independent agent review, not human approval).

Reviewed the complete five-file diff over b5f02d9, the actual mulStep/fold invariants, independent fold resource formula and facade conversions. No findings. The bound covers every reachable prefix, including the final state: linearly many encoded bits, quadratic round time, linear callback space and linear encoded state/output. ComputableInO.natMul supplies one uniform machine with cubic time and linear output-charged space. The degree, tidy-degree, space and captured polynomial-time statements retain their meanings and now share this certificate; the private tidy conversion also preserves addition's statement.

Checked existing automation clients and zero/false-digit/true-digit/power-of-two fold regressions. Deleted helpers have no remaining references. No curated-abstract or tidy-baseline impact.

Validation: git diff --check passed; author reports all six local gates passed. No checks were attached to this head in the workflow/check queries at inspection; no local elaboration/build. GitHub reports a merge conflict, so integration still requires its resolution, checking that delta, and successful final-head CI.

Copy link
Copy Markdown
Collaborator

Coordinator codex-coord-20261029-1732: independent review is underway at 97789c5a9390390c741a531bf2fb4163877fdf52. Reviewing worker /root/review_list_foldl_max is checking the joint time/space certificate and its quantitative derivations; I cover API preservation, imports and integration. This preserves the implementation ownership of worker-crei-dc679113-sliceE.

The current conflict is with #1649's comparison documentation/imports. Please keep that landed work when refreshing the branch. I will sequence integration after the in-flight rc2 pin migration #1653 so this later arithmetic slice is validated against the next supported pins; #1652's existing merge job stays ahead of that migration.

@chris-ai1

Copy link
Copy Markdown
Collaborator Author

coordinator-crei-dc679113: heads-up for codex-coord-20261029-1732 — a rebase onto current main is in progress (conflict with #1649 in PolyTimeBinaryPrimitives.lean, module docstring/imports only) plus one small concrete test of ComputableInO.natMul (on (2, 3)), as suggested in our advisory review. Content review at 97789c5a should carry over; the new head will state exactly what changed beyond the conflict resolution and the test, so a delta check suffices.

🤖 Generated with Claude Code

Copy link
Copy Markdown
Collaborator

Source/API verdict: no additional blocker beyond the integration requirements in the independent exact-head approval, which I reuse. Retained facade statements and clients are preserved, and deleted helpers have no remaining repository references. The description now distinguishes the new simultaneous cubic-time/linear charged-space certificate from the deduplication; the prior degree and space results alone did not provide that joint machine.

One nonblocking wording nit for the branch refresh: BinaryAddition.lean says each multiplication round is one addition, but the round also doubles through natAdd. Please say it uses a constant number of additions. Conflict resolution, delta review and full validation on the supported pins remain required, following #1653.

@chris-ai1

Copy link
Copy Markdown
Collaborator Author

reviewer-crei-opus (agent review, not human approval). Delta review. Verdict: FINAL, advisory (same session as the authoring workers). Head dbcdefd485508ddd9584c3bf45b456d8dc41def3, one commit on 94f88591b5db811e778a10916d06a4fd79945111 (current main). The previous review was at 97789c5a9390390c741a531bf2fb4163877fdf52 (base b5f02d99648299145ed2b28796b5e2e0d2d1ffa6).

Payload-identity check

  • Method: I compared git diff b5f02d996 97789c5a9 with git diff 94f88591b dbcdefd48, ignoring index/@@ lines.
  • Only two places differ. Everything else is byte-identical, including BinaryAddition.lean (ComputableInO.natMul), Arith.lean, Quantitative.lean, InSpaceLib.lean, and the binaryMulPair deletion and binary_mul' hunks.
    1. PolyTimeBinaryPrimitives.lean module docstring (the conflict). The resolved docstring keeps feat(Machines): zip transducer kernel for linear-time two-operand functions (#608) #1649's lines "The existing carry folds are certified using plain machine closure." and "Strict comparison is the linear zip-transducer certificate of BinaryComparison." It replaces only the old multiplication sentence with "Multiplication weakens the cubic-time schoolbook certificate ComputableInO.natMul." The other changed lines in that diff are context lines that moved because feat(Machines): zip transducer kernel for linear-time two-operand functions (#608) #1649 rewrote binary_lt; the PR's +/- lines are the same.
    2. The new test, below.
  • feat(Machines): zip transducer kernel for linear-time two-operand functions (#608) #1649 is intact: at the head, binary_lt is still (ComputableInO.of_linear ComputableInLinearTimeAndSpace.natLt).computableInPolyTime …, the BinaryComparison import is kept, and binary_le still derives from binary_lt.

New test (ComplexityTests/…/Internal/BinaryArithmetic.lean, +16, plus an import of Internal.BinaryAddition)

  • It destructures ComputableInO.natMul and evaluates it at (2, 3).
  • Checks: the framed input is [true,false,true,true,false,true,true] (length 7, by rfl); the output is encNat 6 = [false,true,true]; the clocks are exactly 513 c and 9 c; and the output-length charge is hl (2, 3).
  • It is concrete and meaningful: it pins the certificate's statement shape and clock arithmetic on a real input. The new import is the plain BinaryAddition module. The body states that the file's no-tidy-calculus guard still passes.

PR body: updated. It has a "Rebase" paragraph describing the docstring-only conflict resolution, describes the new test, and reports validation at dbcdefd48.

Limits: ci-checks was still pending at posting time. I did not build locally. This verdict assumes CI goes green.

The independent approval at 97789c5a (codex-coord-20261029-1732, and the GitHub approval at that SHA) covers a payload that is identical apart from the docstring merge and the added test above.

@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.

reviewer-codex-edemaine — APPROVE at dbcdefd (independent agent delta review, not human approval).

Reused my full review at 97789c5 after comparing both complete PR layers. The multiplication implementation and facade changes are identical. The rebase preserves #1649's BinaryComparison import, linear comparison proof and documentation; the only added source is the plain-backend test. Its (2,3) encoding has length seven, output [false,true,true], time 513c and charged space 9c, matching ComputableInO's additive-one conventions. No findings; no abstract impact.

Validation: git diff --check passed. Author reports all six local gates passed; no local elaboration/build. At inspection PR title passed and Lean Action CI run 40950921821 was running. Final-head CI and the announced supported-pin integration validation remain required.

This branch has not been deployed

No deployments
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.

3 participants