pub struct Poly<T, U> { /* private fields */ }
Expand description
Generic struct to hold a polynomial and traits for operations.
The idea here is to combine some representation of the polynomial
(say, a vector of coefficients) with an implementation of PolyTraits
,
to allow implementing all the standard arithmetic and other user-facing
polynomial operations.
let f = ClassicalPoly::<f64>::new(vec![1., 2., 3.]);
let g = ClassicalPoly::<f64>::new(vec![4., 5.]);
assert_eq!(&f * &g, ClassicalPoly::new(vec![4., 13., 22., 15.]));
assert_eq!(&f + &g, ClassicalPoly::new(vec![5., 7., 3.]));
Type aliases are provided for various combinations that will work well.
So far the only alias is ClassicalPoly
.
Implementations§
Source§impl<T, U> Poly<T, U>
impl<T, U> Poly<T, U>
Sourcepub fn eval<V>(&self, x: &V) -> Result<V>
pub fn eval<V>(&self, x: &V) -> Result<V>
Evaluate this polynomial at the given point.
Uses Horner’s rule to perform the evaluation using exactly d multiplications and d additions, where d is the degree of self.
Sourcepub fn mp_eval_prep<V>(
pts: impl Iterator<Item = V>,
) -> <EvalTrait<U, V> as EvalTypes>::EvalInfo
pub fn mp_eval_prep<V>( pts: impl Iterator<Item = V>, ) -> <EvalTrait<U, V> as EvalTypes>::EvalInfo
Perform pre-processing for multi-point evaluation.
pts
is an iterator over the desired evaluation points.
See PolyTraits::mp_eval_prep()
for more details.
Sourcepub fn mp_eval<V>(
&self,
info: &<EvalTrait<U, V> as EvalTypes>::EvalInfo,
) -> Result<Vec<V>>
pub fn mp_eval<V>( &self, info: &<EvalTrait<U, V> as EvalTypes>::EvalInfo, ) -> Result<Vec<V>>
Evaluate this polynomial at all of the given points.
Performs multi-point evaluation using the underlying trait algorithms.
In general, this can be much more efficient than repeatedly calling
[self.eval()
].
info
should be the result of calling Self::mp_eval_prep()
.
Source§impl<T, U> Poly<T, U>where
U: PolyTraits,
impl<T, U> Poly<T, U>where
U: PolyTraits,
Sourcepub fn sparse_interp_prep(
sparsity: usize,
expons: impl Iterator<Item = usize>,
max_coeff: &U::Coeff,
) -> (<U::SparseInterpEval as EvalTypes>::EvalInfo, U::SparseInterpInfo)
pub fn sparse_interp_prep( sparsity: usize, expons: impl Iterator<Item = usize>, max_coeff: &U::Coeff, ) -> (<U::SparseInterpEval as EvalTypes>::EvalInfo, U::SparseInterpInfo)
Perform pre-processing for sparse interpolation.
sparsity
is an upper bound on the number of nonzero terms in the evaluated polynomial.expons
is an iteration over the possible exponents which may appear in nonzero terms.max_coeff
is an upper bound on the magnitude of any coefficient.
See PolyTraits::sparse_interp_prep()
for more details.
Sourcepub fn sparse_interp(
evals: &[<U::SparseInterpEval as EvalTypes>::Eval],
info: &U::SparseInterpInfo,
) -> Result<Vec<(usize, U::Coeff)>>
pub fn sparse_interp( evals: &[<U::SparseInterpEval as EvalTypes>::Eval], info: &U::SparseInterpInfo, ) -> Result<Vec<(usize, U::Coeff)>>
Perform sparse interpolation after evaluation.
Beforehand, Self::sparse_interp_prep()
must be called to generate two info
structs for evaluation and interpolation. These can be used repeatedly to
evaluate and interpolate many polynomials with the same sparsity and degree
bounds.
evals
should correspond evaluations according to theEvalInfo
struct returned from preprocessing. at consecutive powers of thetheta
used in preprocessing.info
should come from a previous call toSelf::sparse_interp_prep()
.
On success, a vector of (exponent, nonzero coefficient) pairs is returned, sorted by increasing exponent values.