Struct polynomial_ring::Polynomial [−][src]
pub struct Polynomial<T> { /* fields omitted */ }
Implementations
degree of polynomial
use polynomial_ring::Polynomial;
let p = Polynomial::new(vec![3, 2, 1]); // 3+2x+x^2
assert_eq!(p.deg(), Some(2));
let q = Polynomial::new(vec![0]); // 0
assert_eq!(q.deg(), None);
construct polynomial
use polynomial_ring::Polynomial;
let p = Polynomial::new(vec![3, 2, 1]);
assert_eq!(p.to_string(), "x^2+2*x+3");
construct polynomial from monomial $cx^d
$ ($c
$=coefficent, $d
$=degree)
use polynomial_ring::Polynomial;
let p = Polynomial::from_monomial(3, 2);
let q = Polynomial::new(vec![0, 0, 3]);
assert_eq!(p, q);
evaluate polynomial by Horner’s method
use polynomial_ring::Polynomial;
let p = Polynomial::new(vec![3, 2, 1]); // 3+2x+x^2
assert_eq!(p.eval(&1), 6);
assert_eq!(p.eval(&2), 11);
derivative
use polynomial_ring::{Polynomial, polynomial};
let p = polynomial![1, 2, 3, 2, 1]; // 1+2x+3x^2+2x^3+x^4
assert_eq!(p.derivative(), polynomial![2, 6, 6, 4]);
make polynomial monic
use num::Rational;
use polynomial_ring::Polynomial;
let mut p = Polynomial::new(vec![1, 2, 3].into_iter().map(|x| Rational::from_integer(x)).collect());
p.monic();
let q = Polynomial::new(vec![(1, 3), (2, 3), (1, 1)].into_iter().map(|(n, d)| Rational::new(n, d)).collect());
assert_eq!(p, q);
polynomial division
use num::Rational;
use polynomial_ring::Polynomial;
let p = Polynomial::new(vec![3, 1, 4, 1, 5].into_iter().map(|x| Rational::from_integer(x)).collect());
let q = Polynomial::new(vec![2, 7, 1].into_iter().map(|x| Rational::from_integer(x)).collect());
let mut r = p.clone();
let d = r.division(&q);
assert_eq!(p, d * q + r);
Trait Implementations
type Output = Polynomial<M>
type Output = Polynomial<M>
The resulting type after applying the +
operator.
Performs the +
operation. Read more
Performs the +=
operation. Read more
Performs the +=
operation. Read more
Returns the “default value” for a type. Read more
impl<'a, K> Div<&'a Polynomial<K>> for &'a Polynomial<K> where
K: AddAssignRequire<K> + for<'x> SubAssign<&'x K>,
for<'x> &'x K: Mul<Output = K> + Div<Output = K>,
impl<'a, K> Div<&'a Polynomial<K>> for &'a Polynomial<K> where
K: AddAssignRequire<K> + for<'x> SubAssign<&'x K>,
for<'x> &'x K: Mul<Output = K> + Div<Output = K>,
impl<'a, K> DivAssign<&'a Polynomial<K>> for Polynomial<K> where
K: AddAssignRequire<K> + for<'x> SubAssign<&'x K>,
for<'x> &'x K: Mul<Output = K> + Div<Output = K>,
impl<'a, K> DivAssign<&'a Polynomial<K>> for Polynomial<K> where
K: AddAssignRequire<K> + for<'x> SubAssign<&'x K>,
for<'x> &'x K: Mul<Output = K> + Div<Output = K>,
Performs the /=
operation. Read more
impl<'a, R> Mul<&'a Polynomial<R>> for &'a Polynomial<R> where
R: AddAssignRequire<R>,
for<'x> &'x R: Mul<Output = R>,
impl<'a, R> Mul<&'a Polynomial<R>> for &'a Polynomial<R> where
R: AddAssignRequire<R>,
for<'x> &'x R: Mul<Output = R>,
impl<'a, R> Mul<&'a Polynomial<R>> for Polynomial<R> where
R: AddAssignRequire<R>,
for<'x> &'x R: Mul<Output = R>,
impl<'a, R> Mul<&'a Polynomial<R>> for Polynomial<R> where
R: AddAssignRequire<R>,
for<'x> &'x R: Mul<Output = R>,
impl<'a, R> Mul<Polynomial<R>> for &'a Polynomial<R> where
R: AddAssignRequire<R>,
for<'x> &'x R: Mul<Output = R>,
impl<'a, R> Mul<Polynomial<R>> for &'a Polynomial<R> where
R: AddAssignRequire<R>,
for<'x> &'x R: Mul<Output = R>,
type Output = Polynomial<R>
type Output = Polynomial<R>
The resulting type after applying the *
operator.
Performs the *
operation. Read more
impl<R> Mul<Polynomial<R>> for Polynomial<R> where
R: AddAssignRequire<R>,
for<'x> &'x R: Mul<Output = R>,
impl<R> Mul<Polynomial<R>> for Polynomial<R> where
R: AddAssignRequire<R>,
for<'x> &'x R: Mul<Output = R>,
impl<'a, R> MulAssign<&'a Polynomial<R>> for Polynomial<R> where
R: AddAssignRequire<R>,
for<'x> &'x R: Mul<Output = R>,
impl<'a, R> MulAssign<&'a Polynomial<R>> for Polynomial<R> where
R: AddAssignRequire<R>,
for<'x> &'x R: Mul<Output = R>,
Performs the *=
operation. Read more
impl<R> MulAssign<Polynomial<R>> for Polynomial<R> where
R: AddAssignRequire<R>,
for<'x> &'x R: Mul<Output = R>,
impl<R> MulAssign<Polynomial<R>> for Polynomial<R> where
R: AddAssignRequire<R>,
for<'x> &'x R: Mul<Output = R>,
Performs the *=
operation. Read more
impl<R> One for Polynomial<R> where
R: AddAssignRequire<R> + One,
for<'x> &'x R: Mul<Output = R>,
impl<R> One for Polynomial<R> where
R: AddAssignRequire<R> + One,
for<'x> &'x R: Mul<Output = R>,
This method tests for self
and other
values to be equal, and is used
by ==
. Read more
This method tests for !=
.
impl<R> Product<Polynomial<R>> for Polynomial<R> where
R: AddAssignRequire<R> + One,
for<'x> &'x R: Mul<Output = R>,
impl<R> Product<Polynomial<R>> for Polynomial<R> where
R: AddAssignRequire<R> + One,
for<'x> &'x R: Mul<Output = R>,
impl<'a, K> Rem<&'a Polynomial<K>> for &'a Polynomial<K> where
K: AddAssignRequire<K> + for<'x> SubAssign<&'x K>,
for<'x> &'x K: Mul<Output = K> + Div<Output = K>,
impl<'a, K> Rem<&'a Polynomial<K>> for &'a Polynomial<K> where
K: AddAssignRequire<K> + for<'x> SubAssign<&'x K>,
for<'x> &'x K: Mul<Output = K> + Div<Output = K>,
impl<'a, K> RemAssign<&'a Polynomial<K>> for Polynomial<K> where
K: AddAssignRequire<K> + for<'x> SubAssign<&'x K>,
for<'x> &'x K: Mul<Output = K> + Div<Output = K>,
impl<'a, K> RemAssign<&'a Polynomial<K>> for Polynomial<K> where
K: AddAssignRequire<K> + for<'x> SubAssign<&'x K>,
for<'x> &'x K: Mul<Output = K> + Div<Output = K>,
Performs the %=
operation. Read more
impl<K> RingNormalize for Polynomial<K> where
K: AddAssignRequire<K> + One + for<'x> DivAssign<&'x K>,
for<'x> &'x K: Mul<Output = K>,
impl<K> RingNormalize for Polynomial<K> where
K: AddAssignRequire<K> + One + for<'x> DivAssign<&'x K>,
for<'x> &'x K: Mul<Output = K>,
type Output = Polynomial<G>
type Output = Polynomial<G>
The resulting type after applying the -
operator.
Performs the -
operation. Read more
Performs the -=
operation. Read more
Performs the -=
operation. Read more
Auto Trait Implementations
impl<T> RefUnwindSafe for Polynomial<T> where
T: RefUnwindSafe,
impl<T> Send for Polynomial<T> where
T: Send,
impl<T> Sync for Polynomial<T> where
T: Sync,
impl<T> Unpin for Polynomial<T> where
T: Unpin,
impl<T> UnwindSafe for Polynomial<T> where
T: UnwindSafe,
Blanket Implementations
Mutably borrows from an owned value. Read more