pub trait SizedPolynomial<N> {
// Required methods
fn term_with_degree(&self, degree: usize) -> Term<N>;
fn terms_as_vec(&self) -> Vec<(N, usize)>;
fn degree(&self) -> Degree;
fn zero() -> Self
where Self: Sized;
fn set_to_zero(&mut self);
// Provided method
fn is_zero(&self) -> bool { ... }
}Required Methods§
Sourcefn term_with_degree(&self, degree: usize) -> Term<N>
fn term_with_degree(&self, degree: usize) -> Term<N>
Returns the term with the given degree from self.
If the term degree is larger than the actual degree, ZeroTerm will be returned.
However, terms which are zero will also be returned as ZeroTerm, so this does
not indicate that the final term has been reached.
Sourcefn terms_as_vec(&self) -> Vec<(N, usize)>
fn terms_as_vec(&self) -> Vec<(N, usize)>
Returns a Vec containing all of the terms of self, where each item is
the coefficient and degree of each non-zero term, in order of descending degree.
§Example
use rustnomial::{Polynomial, SizedPolynomial};
let polynomial = Polynomial::new(vec![1, 0, 2, 3]);
let terms = polynomial.terms_as_vec();
let mut iter = terms.into_iter();
assert_eq!(Some((1, 3)), iter.next());
assert_eq!(Some((2, 1)), iter.next());
assert_eq!(Some((3, 0)), iter.next());
assert_eq!(None, iter.next());Sourcefn set_to_zero(&mut self)
fn set_to_zero(&mut self)
Sets the terms of self to zero.
Provided Methods§
Sourcefn is_zero(&self) -> bool
fn is_zero(&self) -> bool
Returns true if all terms of self are zero, and false if a non-zero term exists.
§Example
use rustnomial::{SizedPolynomial, Polynomial};
let zero = Polynomial::new(vec![0, 0]);
assert!(zero.is_zero());
let non_zero = Polynomial::new(vec![0, 1]);
assert!(!non_zero.is_zero());