Repository navigation
feat(ppvm-sym-2): symbolic sin/cos coefficient ring over ppvm-traits-2 - #313
Merged
Merged
Conversation
Contributor
|
lkdvos
force-pushed
the
claude/ppvm-sym-release-prep-6e8960
branch
from
November 19, 2026 17:49
efb472c to
bcca069
Compare
A `Term` is a polynomial in `sin(x_v)`/`cos(x_v)` of circuit parameters, with real `f64` coefficients, implementing the `ppvm-traits-2` coefficient traits (`Coefficient`, `Angle`, `ImaginaryUnit`, `Conjugate`, `Halvable`). - One representation per value: a monomial keeps only an `imag` bit and every phase operation returns the sign it moves into the coefficient; the real identity is never a table key; cancelled monomials are removed. - Equality is by value, so `Const(c)` equals a constant-only `Sum`. - `max_sin`/`min_eps` are an invariant on monomials: setting them prunes and every operation truncates its result with the left operand's settings. The constant is never truncated. - `Var` is a separate angle type, so a bare variable cannot enter arithmetic. - `eval` is the real part of `eval_complex`, with a per-call trig cache. - No dependency on the engine: scale a sum with `sum.scale(&term)`. Assisted-by: Claude Code
lkdvos
force-pushed
the
claude/ppvm-sym-release-prep-6e8960
branch
from
November 20, 2026 12:29
bcca069 to
b4cdbe5
Compare
david-pl
reviewed
Nov 20, 2026
david-pl
left a comment
Collaborator
There was a problem hiding this comment.
Just one minor thing, and I'd suggest to see if you can split the large files.
With a strict `<`, `min_eps = 0` kept exact zeros: a cancelled monomial stayed in the table and `is_zero` failed on `Const(0.0)`. Dropping at the threshold makes `min_eps = 0` remove exactly the zeros. Assisted-by: Claude Code
`Factor`/`Prod` move to `prod.rs` and `Sum` to `sum.rs`, each with its own tests; `term.rs` keeps `Inner`, `Term` and `Var`. No behaviour change. Assisted-by: Claude Code
david-pl
approved these changes
Nov 20, 2026
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.
Summary
Adds
ppvm-sym-2, the symbolic coefficient ring for the-2engine. ATermis a polynomial insin(xᵥ)andcos(xᵥ)of circuit parameters with realf64coefficients, so a circuit is propagated once and evaluated at many angles. It implementsCoefficient,Angle,ImaginaryUnit,ConjugateandHalvable, and depends only onppvm-traits-2.Design
imagbit. Every phase operation returns the ±1 it moves into the coefficient.c₀orConst.x − xis structurally empty.Const(c)equals a constant-onlySum, andOneequals a one-entrySum.max_sinandmin_epsapply to monomials, never to the constant.One × One.Varis its own angle type, so a bare variable can't enter arithmetic and no operator panics.evalis the real part ofeval_complex, with a per-callsin/coscache.sum.scale(&term).Term,Var,MissingVariableand the default thresholds are public; the representation above is crate-private.Why
ppvm-symstoresi^kon the monomial, so −1 has two spellings; every phase bug fixed in fix(ppvm-sym): correct real-valued results in Term arithmetic #305 traces back to that.i.mul_phase, which Clifford propagation (Trait 2/pauli sum cliff prop - Add Clifford propagation, arithmetic, and formatting #303) never calls.OneandConststay, because most coefficients during propagation are a single monomial (traits-2: rebuild the trait tower, engine, tableau and symbolic ring asppvm-*-2#204), and these forms never allocate a hash map.Term, notSum, becauseOneholds monomials too.Differences from #204's
ppvm-sym-2phase: u8on the monomialimagbitInner::VarVartypeppvm-pauli-sum-2, forsum *= termOpen questions for reviewers
magnitudeis +∞ for symbolic terms, which is cautious, soCoefficientThresholdnever drops one. The ℓ¹ norm would bound the value at every angle and allow more truncation.sum *= termoperator. It needs an edge between the ring and the pauli engine in one direction or the other, since that isn't done yet this is left out for now.Testing
max_sintruncation is exact for every form and operator;Follow-ups
ppvm-sym(about 2.5× faster on the ring workloads, checked locally), stacked on this PR.GaussianInttrait test forppvm-traits-2, taken from traits-2: rebuild the trait tower, engine, tableau and symbolic ring asppvm-*-2#204. (Do we still want/need this?)ppvm-pauli-sum-2has rotations.Assisted by Claude Code