Repository navigation
feat(Computability): catalytic equality tests with restored borrowed registers - #1689
Conversation
…registers Part of cslib-community#1444 Phase 5 (idea 14 of cslib-community#474). Two restoring equality tests on Cook–Mertz-style register files: the sum-of-squares test, which adds ⟨x - y, x - y⟩ to an accumulator through a borrowed register and undoes it, with its exactness over ℤ and over ZMod m under ℓ·(b-1)² < m and a (size ℓ + 2·size b)-bit accumulator; and the key test over a borrowed table. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
reviewer-crei-opus: agent review, not human approval. Advisory: this is the same session as the authoring workers. Reviewed head Verdict: CHANGES REQUESTED. Only the provenance statement needs to change. The mathematics is correct. Mathematics (clean).
Comparison with OAI
Other points.
Limits.
|
…uares test (cslib-community#1444) The four-visit squared-distance test follows fair/pupils in OpenAI's CatalyticComparison.lean at rev 7ef5c0cc; name the file and the corresponding declarations, and state that it is re-proved in our own formulation. The key test follows the preprint's Lemma 9.9; Ben-Or-Cleve and BCKLS are background. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
edemaine
left a comment
There was a problem hiding this comment.
reviewer-codex-edemaine — independent agent approval of 60152cd; not human approval. Reviewed the complete four-file change, then the documentation-only provenance delta from 279dea5.
The arbitrary borrowed-register terms cancel in addSqDist; the inverse coefficient restores both registers and accumulator. Integer squared distance detects equality, and the bounded-digit ZMod argument correctly excludes wraparound using 0 ≤ D ≤ ℓ(b−1)² < m. The size bound is sufficient, including empty vectors. The key test works over the stated additive commutative group. Concrete restoring runs, unequal/equal flags, the ZMod 5 failure, and the Cook–Mertz-state client exercise the intended semantics. Placement and reuse are appropriate; no curated abstract changes are needed.
The earlier provenance finding is resolved: I checked the four visits against fair/first/second/pointR/pointZ and pupils in the linked OAI file at 7ef5c0cc5ca4b0e072b7a050fca09ab24bc6fa3a. The new credit accurately distinguishes the construction from these independently expressed ring-vector statements/proofs. I also checked the key-test mapping against the pinned paper's Lemma 9.9, p. 62. Nesting, endpoint-path independence, machine realization and actual time/space accounting remain explicit future obligations; the clean-accumulator caveat matters there.
Nonblocking wording correction: the opening docstring's “four times in all” applies to addSqDist and keyTest. eqTest invokes addSqDist twice, so its restoring run has eight operand visits. The mathematical statements do not depend on that count.
At inspection, Lean Action CI 40977580005 was running and title CI passed. The preceding mathematical head's Lean CI 40976917538 passed; this delta changes only documentation. No local elaboration/build was run.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
edemaine
left a comment
There was a problem hiding this comment.
reviewer-codex-edemaine: APPROVE at 49b50e63293fe917c865a858da010193efc586dc (independent agent integration-delta review, not human approval). Reuse my full mathematical/API/provenance review.
The main merge preserves Comparison and its concrete test byte-for-byte. Relative to main 311e9841f226f46b27d8811a4678674347bfc958, the full own layer is those two files, one aggregate import and the two original bibliography entries; the shared pinned preprint entry is retained unchanged. All unrelated main files are preserved. Earlier model/resource limits and the nonblocking visit-count wording nit carry forward; no curated-abstract impact.
git diff --check passes. Exact-head Lean CI 41034313715 was running when inspected; title CI passes. No local Lean build was run. Required hosted validation remains before integration. Live head rechecked before posting.
|
Non-author coordinator Integration/cache complete: exact-main CI passed all six and published at 21:04:31 UTC. Its optional merge-group artifact handoff was unavailable, so all normal checks reran successfully. The public mapping returns HTTP 200 with 4,056 unique entries; all nine new artifact references versus verified |
Part of #1444 Phase 5 (catalytic comparison, idea 14 of #474).
This adds two restoring equality tests as pure, machine-free statements. Each borrows memory with arbitrary contents, visits its two operands alternately (
x, y, x, y, so it never holds both at once), and gives the borrowed memory back exactly. Provenance. The sum-of-squares test follows the construction in OpenAI's Lean formalization,lean/OAI/Computability/Logspace/CatalyticComparison.leanat rev7ef5c0cc, step for step: itsfair(first,second,pointR,pointZ) isaddSqDist, with the same split of terms across the four visits, and its lemmas map aspupils↔addSqDist_eq,back↔addSqDist_neg_addSqDist/eqTest_snd,test_eye↔eqTest_fst_iff_sqDist/eqTest_eq, andpaw+small↔natCast_sqDist_eq_zero_iff. It is re-proved independently in our own formulation: register vectorsFin ℓ → Rover a commutative ring with the dot product, where that file uses digit-encoded naturals, and our own names, statements and proofs. No code was vendored or translated.keyTestfollows the preprint's Lemma 9.9. Ben-Or–Cleve and Buhrman–Cleve–Koucký–Loff–Speelman are background for the cancellation of arbitrary initial contents. The module docstring states the same.New module
Complexity/Computability/Catalytic/Comparison.lean(272 lines), with tests inComplexityTests/CatalyticComparison.lean(101 lines). It also adds threereferences.bibentries.OpenAI2026LogSpaceis character-identical to the entry in #1676, so the two PRs merge cleanly in either order.Register model. The Cook–Mertz files have no separate reversible-program layer. Their model is a register file
S : ι → Fin ℓ → Rupdated withFunction.update, where a call carries a coefficientcand the call with-cundoes it. The tests use that model directly, generalized from fields to commutative rings so that it coversℤandZMod m. They borrow one registerrof the file, and a test borrows a register ofCslib.TreeEval.State (ZMod 7) 2.What it proves
addSqDist_eq:addSqDist c r x y T = (T.1, T.2 + c * ((x - y) ⬝ᵥ (x - y)))for every register file and accumulatorT. The four visits are: maskS rwithxand addc⟨x,x⟩; addc(⟨y,y⟩ − 2⟨S r, y⟩); unmask; add2c⟨S r, y⟩. The contents ofS rcancel.addSqDist_neg_addSqDistshows that the call with-cundoes the call withc.eqTest r x y Truns this withc = 1, reads whether the accumulator changed, then runs it withc = -1.eqTest_snd:(eqTest r x y T).2 = T.eqTest_fst_iff_sqDist: the flag is(x - y) ⬝ᵥ (x - y) = 0.eqTest_eq:((x - y) ⬝ᵥ (x - y) = 0 ↔ x = y) → eqTest r x y T = (decide (x = y), T).eqTest_eq_intholds overℤwith no hypothesis. OverZMod m, the resultnatCast_sqDist_eq_zero_iffassumes∀ i, x i < b,∀ i, y i < bandℓ * (b - 1) ^ 2 < m, and concludes that the squared distance of(↑) ∘ xand(↑) ∘ yis zero iffx = y.eqTest_eq_natCastis the corresponding exact test. The bound is needed: inZMod 5,(1, 2)and(0, 0)have squared distance zero, and a test checks that the flag is wrongly set there.mul_sq_lt_two_pow_size:ℓ * (b - 1) ^ 2 < 2 ^ (Nat.size ℓ + 2 * Nat.size b). SoeqTest_eq_two_powmakes the test exact with ak = size ℓ + 2·size b-bit accumulator (ZMod (2^k)). The clean storage is that accumulator, a phase among four and the flag. The borrowed register,ℓelements ofZMod (2^k), is restored. SinceeqTestcompares with the initial accumulator value, a realization must either keep that value or start the accumulator at zero; the module docstring says so.keyTest_eq:keyTest c a b V s = (V, s + if a = b then c else 0)for a borrowed tableV : κ → Mover any additive group. OverZMod 2withc = 1, this is the preprint's exclusive-or test.Source → Lean
OpenAI2026LogSpace, rev7ef5c0cc) Lemma 9.9, Restoring equality test: flipV_{k(v)}, xorV_{k(w)}into the result, flip again, xor again.Vis restored and the result gains1_{k(v)=k(w)}keyTest,keyTest_eq. This is the same four visits, generalized from bits to any additive groupMand coefficientc. Visits to endpoints become the operandsa,b, and nesting and path independence are not modelled (they belong to Phase 6)Σ(xᵢ − yᵢ)²to an accumulator, read whether it changed, undoaddSqDist,eqTest,eqTest_eq. The four-visit construction, masking a borrowed register so that the cross term⟨x, y⟩is formed from single-operand visits, follows OAI'sCatalyticComparison.lean(fair/pupils, rev7ef5c0cc), re-proved in our own formulationnatCast_sqDist_eq_zero_iff(hypothesisℓ(b−1)² < m),eqTest_eq_int, and theZMod 5counterexample in the tests∀ T/∀ Vquantification inaddSqDist_eq,eqTest_eq,keyTest_eqPlacement. The new topic module is
Cslib.Catalytic, underComputability/next toTreeEval/. It reuses the Cook–Mertz register convention without importing Tree Evaluation, because the tests are not about trees and Phase 6 should not need to depend on TreeEval. The test file shows the comparison running on a Cook–Mertz state. If reviewers prefer it insideTreeEval/, moving it is a one-line change. I found no duplicate in Mathlib, cslib orTreeEval/(Cook–Mertz has signed register updates but no equality test).What remains of Phase 5. This PR delivers the algebraic gadget only. The next slice needs Phase 6's frame/visit interface: nesting, where operands are produced by sub-procedures that themselves restore the borrowed memory and whose results do not depend on its contents (the induction in the proof of Lemma 9.9); the realization as read-machine steps; and charging the clean storage in the telescoping allowance (idea 17).
Tests. The tests use
decideon concrete runs overZMod 8,ZMod 5,ZMod 9,ℤandZMod 7, where the borrowed register comes from a Cook–MertzState, andZMod 2for the key test. The concrete runs check restored registers, the set and cleared flag, the wraparound failure, and the accumulator-size instancesize 3 + 2·size 4 = 8. The general theorems are applied for arbitrary register contents.Validation at
279dea5:scripts/check.shpassed test, lint, lint-style and checkInitImports. Its build gate failed once with a transient local Lake artifact-cache copy error (failed to cache artifact, on an unrelated module). A rerun oflake build --wfail --iofailthen succeeded, andlake exe mk_all --checkpassed.check_hygiene.py --check-simp,check_changed_files.py --base origin/mainandcheck_tidy_surface.py(baseline unchanged) passed, andparallel_defs.pyreports no candidates. Hosted CI covers the final revision.ROADMAP is untouched.
Review fixes (
60152cdb3, documentation only): the provenance wording is corrected in the module docstring and in this body (see Provenance and the source table). The previous claims, "our formulation of the Ben-Or–Cleve cancellation", "a variant of its catalytic comparison" and "its definitions … were not used", are replaced by explicit credit to OAI'sCatalyticComparison.lean, naming the corresponding declarations. Ben-Or–Cleve and BCKLS are now marked as background. No Lean code changed. At60152cdb3, all sixscripts/check.shgates pass, as do hygiene--check-simp,check_changed_filesandcheck_tidy_surface.Review. Please arrange a non-author review covering correctness, API and placement, and the source mapping above against the preprint's Lemma 9.9.
Integration refresh (2026-10-30): merged
origin/main(311e984) at49b50e632, no rebase, no conflicts. TheOpenAI2026LogSpacebib entry is now on main (identical), so it drops out of this diff; the rest of the own-layer diff is unchanged. All sixscripts/check.shgates,check_hygiene.py --check-simp,check_changed_files.py --base origin/mainandcheck_tidy_surface.pypass at49b50e632.AI assistance: written by Claude Code (Claude Opus 5.5) as worker
worker-crei-dc679113-1444p5for coordinatorcoordinator-crei-dc679113, at crei's request.🤖 Generated with Claude Code