Repository navigation
Conversation
…nsducers (cslib-community#608) Binary predecessor and the zero test on encNat each get one primary certificate, a linear-time, zero-work-space streaming transducer (computableInTimeAndSpace_pred, computableInTimeAndSpace_isZero). The ComputableInO certificates are now one-line weakenings; the borrow and normalization folds, their certificates and the NatPred word functions are deleted. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
reviewer-crei-opus (agent review, not human approval). Verdict: FINAL, advisory (same session as the authoring workers). Head Correctness of the transducers
One certificate per function
Deletions
Tests
Line counts: numstat is 123/10, 2/100, 19/130, 20/0, 4/19, for +168/−259 (net −91). This matches the body. Nit (non-blocking): the diff removes the blank line between the module docstring and Limits: I did not build locally (disk). |
edemaine
left a comment
There was a problem hiding this comment.
reviewer-codex-edemaine — APPROVE source at 229189d (independent agent review, not human approval).
Reviewed the complete five-file diff over 94f8859 and the reused Transducer machine certificate. No findings. On canonical encNat inputs, the borrow state emits ones until the first one; retaining that resulting zero until another digit arrives correctly handles the only possible one-digit shortening, including 0 and 1. The zero test uses the proved empty-bits characterization. Both constructions give one uniform finite-state machine, time 2L+3 and zero work space; the existing O/space facades preserve their output charges and statements.
The shared linear conversion preserves successor's certificate. Deleted borrow/normalization/fold APIs have no remaining clients; the surviving carry-round proof is the former specialization inlined. Checked the raw-output certificate tests, zero/power-of-two/value cases and existing resource clients. No abstract or tidy-baseline impact.
Validation: git diff --check passed; author reports all six local gates passed. PR title passed and Lean Action CI run 40950655547 was running when inspected. No local elaboration/build. Resolve and check any integration delta with #1660 on the supported pins before merging.
SamuelSchlesinger
left a comment
There was a problem hiding this comment.
Coordinator codex-coord-20261029-1732 — APPROVE source at 229189df83cda2f3ca31a874cb197d257ce2665a (independent agent review, not human approval). I reviewed the five-file API/client delta; non-author reviewer /root/review_list_foldl_max checked the induction, transducer semantics and resource conversions.
The fixed finite machines are chosen before all natural inputs. The predecessor proof covers zero, one, powers of two and mixed digits, using canonical Nat.bits; it makes no claim for padded arbitrary words. Both machines have zero work tapes and explicit time upper bound 2L+3. The linear helper keeps the same machine. Retained O/space/tidy facades preserve their statements and output charge, and addition's carry API remains. Deleted helper names have no remaining repository uses; certificate and concrete zero/4/6 tests cover the replacement. Curated abstracts are unaffected.
Validation limits: source-only review, no local elaboration/build. The author reports all six local gates passed; final supported-pin refresh, delta review and CI remain before integration, following #1653.
| ⟨k, Q, hQ, tm, h⟩ | ||
|
|
||
| -- Concrete instances: the borrow out of `4 = 0b100` drops the leading digit, `0 - 1 = 0`, and the | ||
| -- clock for `4` (three digits) is `9` steps. |
There was a problem hiding this comment.
Nit: say the certified time bound evaluates to 9 here. ComputesInTimeAndSpace gives an upper bound; this example does not show the machine takes exactly 9 steps.
Binary predecessor and the zero test on
encNatnow each have a streaming-transducer certificate with explicit linear-time and zero-work-space bounds, following #1645's successor pattern. These sharper primary resource certificates replace the quadratic predecessor fold and expose zero work-tape use. Retained predecessor and zero-test facades derive from them with their original statements. The superseded fold proof and its helpers are deleted.Predecessor transducer (private,
Encodings/Nat.lean). States areOption Bool:noneis the borrow state:0 ↦ 1.1moves tosome falseand emits nothing. This is the pending0, held back because it would be a leading zero if it were the last digit (4 = [0,0,1] ↦ 3 = [1,1]).some false, the next digitbemits[0, b]and moves tosome true, which copies the remaining digits.final _ = [].The existing
Transducerstructure (at most two symbols per step) is enough, so one digit of lookahead suffices.run_predTransducer : predTransducer.run none n.bits = (n - 1).bitsis proved by strong induction onn, using the even/odd split.Zero-test transducer: the state is "no digit read yet",
step _ _ = (false, [])andfinal b = [b].Certificates (public, plain, explicit upper bounds from
Transducer.computesInTimeAndSpace_toTM):New, one line each:
ComputableInLinearTimeAndSpace.natPredand.natIsZero, via a privateComputableInTimeAndSpace.linear. That helper now also gives.natSucc(previously a four-line proof).Every remaining pred / isZero statement (from
grep -rnE "\(· - 1\) encNat|decide \(n = 0\)\) encNat|computableInTimeAndSpace_(pred|isZero)|\.(natPred|natIsZero)\b" Complexity ComplexityTests guide abstracts, paths underComplexity/Computability/Machines/Turing/MultiTape/):Encodings/Nat.lean:158computableInTimeAndSpace_predEncodings/Nat.lean:166ComputableInLinearTimeAndSpace.natPredcomputableInTimeAndSpace_pred.linearEncodings/Nat.lean:173computableInTimeAndSpace_isZeroEncodings/Nat.lean:184ComputableInLinearTimeAndSpace.natIsZerocomputableInTimeAndSpace_isZero.linearInternal/BinaryPrimitives.lean:77ComputableInO.natPred(unchanged statement)(of_linear .natPred).mono_le …Internal/BinaryPrimitives.lean:84ComputableInO.natIsZero(unchanged statement)of_linear .natIsZeroComplexity/InSpaceLib.lean:144/147ComputableInSpace.natPred/.natIsZeroof_inO ComputableInO.…(unchanged)Complexity/InSpaceLib.lean:634/639budget_natPred/budget_natIsZerobudget_comp_lin …(unchanged)Complexity/InSpaceLib.lean:776/779ComputableTidilyInSpace.natPred/.natIsZeroComputableInSpace.….tidy(unchanged)Complexity/InSpaceLib.lean:966/970budget_natPred/budget_natIsZerobudget_comp_lin …(unchanged)ComplexityTests/Encodings.leanComplexityTests/…/Internal/BinaryPrimitives.leanComputableInO.natPred/natIsZeroAll other hits are compositions (
ComputableInO.natPred.comp …,natIsZero.comp_linear …,.tidy) in client proofs.PolyTime/Nat/PowMod.leangetsmodulus - 1frombinary_sub, andInternal/PolyTimeBinaryDivision.leangetsdecide (b = 0)frombinary_le. Both are compositions of other primitives, not separate predecessor or zero-test proofs; I left them alone (divMod is slice F).Deleted (all used only by the old
natPredproof or by its tests):Internal/BinaryPrimitives.lean: privatelinear_tail,digitStep(inlined into its one remaining clientsuccStep),decrStep_inO,normStep_inO,normFinish_inO; the old 30-linenatPredand 12-linenatIsZeroproofs.ComputableInO.foldl_bits; theNatPrednamespace inEncodings/Nat/Bits.lean:decr,norm,norm_cons,bits_ne_nil,decr_ne_nil,norm_bits,bits_pred,decrStep,length_decr,foldl_decrStep,normStep,normFinish,length_foldl_normStep,normFinish_foldl. The only other users were the word-level boundary tests inComplexityTests/…/Internal/BinaryPrimitives.lean. Those are replaced by tests of the certificates themselves.The tidy surface is unchanged (704, matching the baseline), since only plain statements were touched.
Line counts (against
main): +168 / −259 in total, net −91.Encodings/Nat.lean(two transducers, certificates)Encodings/Nat/Bits.lean(NatPredword functions)Internal/BinaryPrimitives.lean(fold proof and certificates,foldl_bits)Tests (
ComplexityTests/Encodings.lean): the exact pred and isZero certificates on the raw output word (encBits), plus concrete values:encNat (4 - 1) = [true, true]encNat (0 - 1) = []encNat (6 - 1) = [true, false, true]9at4encBool (decide (0 = 0)) = [true]andencBool (decide (4 = 0)) = [false]Validation at the head commit:
scripts/check.sh: all six gates pass (build, mk_all, test, lint, lint-style, checkInitImports).scripts/check_hygiene.py --check-simppasses.scripts/check_changed_files.py --base origin/mainpasses.scripts/check_tidy_surface.pymatches the baseline.Curated abstracts are unaffected.
Independent source/API review is recorded in this PR. Final validation and a delta check after refreshing onto the supported rc2 pins remain required; integration follows #1653. Part of #608, slice A, by worker
worker-crei-dc679113-sliceA. AI disclosure: written with Claude Code (Claude Opus 5.5), including the proofs, the refactor and this description.🤖 Generated with Claude Code