Add the interval arithmetic and grid solvers for Ross-Selinger synthesis - #643
Merged
Conversation
…s and a bounded normalization loop
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Phase 2a of Clifford+T synthesis: the interval arithmetic and grid-candidate machinery for Ross-Selinger
Rzapproximation. Builds on thepecos-synthcrate (#603); the norm equation, factoring, and thesynthesize_rzdriver are subsequent work. Governed by the phase-2 specification (v4, three math-review rounds) in the project design vault.Contents
interval.rs-- dyadic fixed-point intervals overBigIntwith sign-aware outward rounding (floor/ceil division on signed values, never%), octant-reducedcos/sinenclosures with Lagrange remainders added outward, the exact 65-bit half-angle from anAngle64fraction (thetain(-pi, pi], sotheta/2in(-pi/2, pi/2]), a 1024-bitpiconstant with documented provenance, sqrt enclosures, and a shared precision-retry policy that surfacesSynthError::Inconclusive { precision }at the caller's ceiling rather than looping.grid.rs-- the closed epsilon-cap per RS Eq. 13-14; an enclosing ellipse of the cap with in-comment proofs of BOTH containment and a uniform area bound (C = 3; ratio limits3pi/4,2,2sqrt2across the regimes), which is what RS Prop. 5.17 / Thm. 5.18 need for efficient enumeration; Appendix-A uprighting with pinned residual choices; the 1D solver per RS Prop. 4.5 with a fully SYMBOLIC normalization count (exact dyadic-vs-Z[sqrt2]comparisons -- no interval arithmetic in the loop condition); both candidate branches with the shifted branch'sk = lde(u')and recovery viadelta^{-1} = (omega - i)/sqrt2; RS Lemma 5.5 coset enumeration; and exact closed-cap filtering with an exact ring path for pi/2-grid targets (therezlies inZ[omega]; the shifted branch'sdot >= d|delta|is decided by a sign split and one squaring against|delta|^2 = 2 + sqrt2).Everything is
pub(crate); the only public additions are theSynthError::Inconclusivevariant and nothing else. No floating point exists in either module.Review history
An adversarial math review (web-verified against RS) initially returned DO-NOT-MERGE on two totality defects: valid inputs could become permanently
Inconclusiveat the 1D normalization endpoint (width exactly 1 -- two inexact enclosures of the same irrational never resolve) and at exact closed-cap boundary candidates (e.g.theta = pi/2,epsilon = 3/8,u = (119/128) z). Both are fixed by the exact symbolic paths above, each with a verbatim regression. The same review independently re-derived the ellipse (confirmingC = 3), thedelta-inverse identity, and thepiconstant via its own Chudnovsky computation. A closure round confirmed all findings resolved (MERGE-WITH-FOLLOWUPS); its one follow-up -- an impractically large tolerance exponent could eagerly allocate a ~512 MiB numerator instead of erroring -- is fixed here by cappinglog_denominatorat 4096 with a regression.A mutation test also exposed that a broken endpoint comparison would HANG the normalization loop rather than fail; the loop now carries a defensive iteration bound (
bits + precision + 8->ExponentOverflow), and the same mutant now fails fast.Verification
h ~ 1.01,h ~ 1.98); the three reviewer reproducers; determinism of the full candidate stream.kswapped tolde(u); exact-cap threshold off by one ulp; endpoint inclusivity flipped (fails fast via the loop bound).--lockedclippy with-D warnings, workspace check, fmt, pre-commit -- clean.Driver-facing note
RS Lemmas 7.2/9.6 assume
epsilon < 2 sin(pi/16); this layer accepts any0 < epsilon < 2and documents that the latersynthesize_rzdriver owns the Clifford shortcut above that threshold.