pub trait HornerIter: DoubleEndedIterator + Sized {
// Provided methods
fn horner_acc<Acc, X>(self, acc: Acc, x: X) -> Acc
where Acc: Mul<X, Output = Acc> + Add<Self::Item, Output = Acc>,
X: Clone { ... }
fn horner<Acc, X>(self, x: X) -> Acc
where Acc: Default + Mul<X, Output = Acc> + Add<Self::Item, Output = Acc>,
X: Clone { ... }
}Expand description
Horner-style polynomial evaluation over a DoubleEndedIterator.
The iterator yields coefficients in ascending degree order
[c_0, c_1, …, c_{n-1}]. Both methods walk the iterator back-to-front
via DoubleEndedIterator::rfold, avoiding any allocation.
§Convention
Given an evaluation point x and accumulator acc,
HornerIter::horner_acc computes
acc · xⁿ + Σ_{i=0..n} c_i · xⁱ
= c_0 + x · (c_1 + x · (… + x · (c_{n-1} + x · acc)))HornerIter::horner is the same with acc = Acc::default(), i.e. the
polynomial evaluation Σ_i c_i · xⁱ.
For inputs in descending degree order, call .rev() on the iterator
first.
Provided Methods§
Sourcefn horner_acc<Acc, X>(self, acc: Acc, x: X) -> Acc
fn horner_acc<Acc, X>(self, acc: Acc, x: X) -> Acc
Horner fold with an explicit accumulator. See the trait docs for the evaluation convention.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".