Skip to content

ppvm_sym (crate)

ppvm_sym

ppvm_sym

Symbolic, parametric Pauli propagation.

`ppvm-sym` provides a Term type that represents a polynomial in sines and cosines of symbolic parameters. It is used by ppvm to propagate Pauli operators through parametric circuits (e.g., variational ansätze) without committing to specific angle values until the very end.

Build the symbolic expression `sin(x0) * cos(x1)`, then evaluate it at a concrete `(x0, x1)`:

``` use ppvm_sym::Term;

let expr = Term::var(0).sin() * Term::var(1).cos();

let v = expr.eval(&[0.5, 1.0]).unwrap(); let expected = 0.5_f64.sin() * 1.0_f64.cos(); assert!((v - expected).abs() < 1e-12); ```

classProdsource

ppvm_sym::Prod

Bases: AddAssign&lt;Prod&gt;, Display, Mul, MulAssign, Debug, Clone, StructuralPartialEq, PartialEq, Eq, Hash, Default

Rust struct. `<coeff> sin^m cos^n`

pub struct Prod

A single product of trigonometric atoms over symbolic variables. Sines and cosines are grouped by variable id; powers are tracked as totals so we can quickly compute and bound them. The order of variables is kept canonical (ascending) so two `Prod` values representing the same monomial compare equal.

source

methodadd_phasesource

ppvm_sym::Prod::add_phase

pub fn add_phase(&mut self, phase: u8)

Parameters

NameTypeDescription
phaseu8

Multiply the phase by `i^phase` (modulo `4`).

source

methodcossource

ppvm_sym::Prod::cos

pub fn cos(id: u32) -> Self

Parameters

NameTypeDescription
idu32

Returns

Self

Build the singleton product `cos(x_id)`.

source

methodcos_powsource

ppvm_sym::Prod::cos_pow

pub fn cos_pow(&self) -> usize

Returns

usize

Total power of the cosine factors.

source

methodevalsource

ppvm_sym::Prod::eval

pub fn eval(&self, vals: &[f64]) -> Result<f64>

Parameters

NameTypeDescription
vals&amp;[f64]

Returns

Result<f64>

Evaluate the product at the variable assignment `vals`, where `vals[i]` is the value substituted for variable `i`.

source

methodmul_cossource

ppvm_sym::Prod::mul_cos

pub fn mul_cos(&mut self, u: u32)

Parameters

NameTypeDescription
uu32

Multiply this product by an additional `cos(x_u)`.

source

methodmul_sinsource

ppvm_sym::Prod::mul_sin

pub fn mul_sin(&mut self, u: u32)

Parameters

NameTypeDescription
uu32

Multiply this product by an additional `sin(x_u)`.

source

methodnewsource

ppvm_sym::Prod::new

pub fn new() -> Self

Returns

Self

Construct the empty product (the multiplicative identity, value `1`).

source

methodpowsource

ppvm_sym::Prod::pow

pub fn pow(&self) -> usize

Returns

usize

Total power of all sine and cosine factors.

source

methodsinsource

ppvm_sym::Prod::sin

pub fn sin(id: u32) -> Self

Parameters

NameTypeDescription
idu32

Returns

Self

Build the singleton product `sin(x_id)`.

source

methodsin_powsource

ppvm_sym::Prod::sin_pow

pub fn sin_pow(&self) -> usize

Returns

usize

Total power of the sine factors.

source

classSumsource

ppvm_sym::Sum

Bases: AddAssign&lt;f64&gt;, AddAssign&lt;Prod&gt;, Display, MulAssign&lt;f64&gt;, Debug, Clone, StructuralPartialEq, PartialEq, Default

Rust struct. A formal sum `c₀ + Σᵢ cᵢ · pᵢ`, where each `pᵢ` is a [`Prod`] and `cᵢ` is an `f64` coefficient.

pub struct Sum
source

methodadd_constsource

ppvm_sym::Sum::add_const

pub fn add_const(&mut self, c: f64, min_eps: f64)

Parameters

NameTypeDescription
cf64
min_epsf64

Add the constant `c` into the sum’s `c₀`, dropping it if `|c| < min_eps`.

source

methodadd_termsource

ppvm_sym::Sum::add_term

Signature
pub fn add_term(&mut self, p: Prod, coeff: f64, max: usize, min_eps: f64)

Parameters

NameTypeDescription
pProd
coefff64
maxusize
min_epsf64

Add `coeff · p` into the sum, subject to the same trunation constraints used elsewhere (`max` caps the sine power, `min_eps` drops near-zero coefficients).

source

methodevalsource

ppvm_sym::Sum::eval

pub fn eval(&self, vals: &[f64]) -> Result<f64>

Parameters

NameTypeDescription
vals&amp;[f64]

Returns

Result<f64>

Evaluate the sum at `vals`.

source

methodmul_termsource

ppvm_sym::Sum::mul_term

Signature
pub fn mul_term(&mut self, p: Prod, coeff: f64, max: usize, min_eps: f64)

Parameters

NameTypeDescription
pProd
coefff64
maxusize
min_epsf64

Multiply this sum in place by `coeff · p`, respecting the same `max` / `min_eps` truncation bounds used elsewhere.

source

methodnewsource

ppvm_sym::Sum::new

pub fn new() -> Self

Returns

Self

Construct an empty sum (value `0`).

source

classTermsource

ppvm_sym::Term

Bases: AddAssign&lt;f64&gt;, AddAssign&lt;Prod&gt;, AddAssign, Add, Add&lt;f64&gt;, Add&lt;Term&gt;, Sub, Sub&lt;f64&gt;, Coefficient, ComplexCoefficient, Sum, Neg, From&lt;f32&gt;, From&lt;f64&gt;, From&lt;i32&gt;, From&lt;i64&gt;, Zero, Display, MulAssign&lt;Term&gt;, MulAssign&lt;f64&gt;, MulAssign, Mul&lt;f64&gt;, Mul&lt;Term&gt;, Mul, Debug, Clone, StructuralPartialEq, PartialEq

Rust struct. A symbolic polynomial in `sin(x_i)` and `cos(x_i)`.

pub struct Term

`Term` is the public-facing wrapper around its Inner enum. It also carries two truncation parameters, applied during multiplication and addition:

``` use ppvm_sym::Term;

// sin²(x0) at x0 = π/2 equals 1. let expr = Term::var(0).sin() * Term::var(0).sin(); let v = expr.eval(&[std::f64::consts::FRAC_PI_2]).unwrap(); assert!((v - 1.0).abs() < 1e-12); ```

  • `max_sin` — drop terms whose total sine power exceeds this bound.
  • `min_eps` — drop terms whose coefficient magnitude falls below this threshold.
source

methodcossource

ppvm_sym::Term::cos

pub fn cos(self) -> Self

Returns

Self

Apply `cos(·)` to the term. Only valid on variables and constants.

source

methodevalsource

ppvm_sym::Term::eval

pub fn eval(&self, vals: &[f64]) -> Result<f64>

Parameters

NameTypeDescription
vals&amp;[f64]

Returns

Result<f64>

Evaluate this symbolic term at `vals`.

source

methodfrom_f64source

ppvm_sym::Term::from_f64

pub fn from_f64(c: f64) -> Self

Parameters

NameTypeDescription
cf64

Returns

Self

Build a constant term from `c`.

source

methodset_max_sinsource

ppvm_sym::Term::set_max_sin

pub fn set_max_sin(&mut self, max: usize)

Parameters

NameTypeDescription
maxusize

Set the maximum sine power retained during arithmetic.

source

methodset_min_epssource

ppvm_sym::Term::set_min_eps

pub fn set_min_eps(&mut self, eps: f64)

Parameters

NameTypeDescription
epsf64

Set the coefficient cutoff used during arithmetic.

source

methodsinsource

ppvm_sym::Term::sin

pub fn sin(self) -> Self

Returns

Self

Apply `sin(·)` to the term. Only valid on variables and constants.

source

methodvarsource

ppvm_sym::Term::var

pub fn var(u: u32) -> Self

Parameters

NameTypeDescription
uu32

Returns

Self

Construct a bare symbolic variable.

source

classInnersource

ppvm_sym::Inner

Bases: Debug, Clone, StructuralPartialEq, PartialEq

Rust enum. Internal representation of a [`Term`].

pub enum Inner

Variants

NameTypeDescription
Sum(Sum)A general sum of products.
One(Prod, f64)A single weighted product.
Var(u32)A bare symbolic variable (only valid as the argument of `sin` or `cos`).
Const(f64)A numeric constant.

`Sum` holds a full formal sum; `One` is the optimisation for a single weighted product; `Var` is a bare symbolic variable used before it has been wrapped in a `sin` or `cos`; `Const` is a numeric scalar.

source