Add the norm equation and factoring layer for Ross-Selinger synthesis - #662
Add the norm equation and factoring layer for Ross-Selinger synthesis#662ciaranra wants to merge 3 commits into
Conversation
|
A second adversarial review, scoped to the fix commit The load-bearing question was whether the replacement normalization bound in Also confirmed: the worklist reproduces the recursive depth-first order (larger child pushed first), leaving seed-stream consumption and per-node budgets unchanged, and Pollard-Brent returns only One low-severity item is deliberately deferred rather than fixed here. |
Phase 2b of Clifford+T synthesis: the norm-equation and factoring layer. Builds on the exact rings and Matsumoto-Amano synthesis (#603) and the interval/grid machinery (#643). The
synthesize_rzdriver is the next and final phase. Governed by the phase-2 specification in the project design vault.Contents
diophantine.rs-- solvest^dagger t = xioverD[omega]for a grid candidate'sxi, returning one of three resolutions with deliberately asymmetric evidence rules:Solved { t }-- only ever constructed after an exactt^dagger t == xicheck in the rings, on every path includingxi = 0.Unsolvable-- requires PROOF: either strict double positivity fails (RS Definition C.1, needs no factoring, so it is checked first), or an odd exponent of a provedZ[sqrt2]prime over a proved rational primep = 7 (mod 8)(RS Lemmas C.19/C.21/C.23).Exhausted-- everything else, including any obstruction resting on merely PROBABLE primality.That asymmetry is the design's core: a wrong
tis caught by the exact gate at the return boundary, but a wrongly DISCARDED candidate is invisible to it forever, so probable primality may be used constructively and may never obstruct.The scaled equation is solved UP TO ASSOCIATES. Demanding an exact
s^dagger s = xi'after the RS Lemma C.25 scaling is unsatisfiable for odd scaling exponents -- scaling bysqrt2can destroy double positivity (xi = (2+sqrt2)/2is solvable byt = delta/sqrt2, yetsqrt2 xi = 1+sqrt2has negative bullet embedding, and every nonzero dagger norm is doubly positive). The leftover unit afterdelta^-lunscaling is doubly positive, hence exactlylambda^2k, and is square-rooted exactly per RS Lemma C.2 and the proof of C.16. The counterexample is a regression test.factor.rs-- sieve below2^16, Brent-cycle Pollard rho over an explicit heap worklist, deterministic 12-base Miller-Rabin below2^64(valid becausepsi_12 > 2^64, Sorenson-Webster Theorem 1.1) and seeded probable-prime rounds above it, Tonelli-Shanks with a canonical[0, p/2]root, and domain-separated seed streams vianth_derived_seed. Every loop carries a budget; there are no wall-clock budgets and no floating point anywhere in the crate.Supporting exact gcds, canonical associates (absolute embedding ratio normalized into
[1, lambda^2)), and quotient rounding were added to theZ[sqrt2]andZ[omega]rings. Everything ispub(crate); this PR adds no public API.Review history
An adversarial review of the packet against the specification, before any code existed, found seven defects -- including one INHERITED FROM THE SPEC: it demanded the exact scaled solve described above as unsatisfiable. Three prior review rounds on that spec had missed it. The spec was corrected first (vault marker F15), then the packet.
An adversarial review of the implementation returned REVISE with four findings, all reproduced or confirmed against the code before being acted on:
canonical_associatebounded its normalization loop by field norm -- unsound, because every unitlambda^khas field norm 1 while normalization takes|k|steps.gcd(lambda^100, 0)panicked. The bound now derives from coordinate bit length, and exhaustion returnsNonerather than asserting.lambda^llinearly; scaling exponents are now capped at 4096 (following the tolerance-exponent precedent from Add the interval arithmetic and grid solvers for Ross-Selinger synthesis #643) and all powers use exponentiation by squaring.primality_rounds == 0returnedProbablehaving tested nothing; zero rounds are now rejected at parameter validation.The same review independently confirmed the mathematics against RS Appendix C, audited every
Unsolvablereturn and every discard path for silent factor loss (none found), and ran 12,000 generated norms and 277,050 modular-root cases against brute force.Verification
Unsolvableon probable-prime evidence; skipping the double-positivity check; flattening the odd-exponent bullet parity; removing zero-round validation; removing the scale cap; restoring the unsound field-norm bound.gcd(lambda^k, 0)for k up to 500) no longer panics.--lockedclippy with-D warnings, workspace check, fmt, pre-commit -- all clean, run cold.