Struct rustnomial::Monomial [−][src]
pub struct Monomial<N> { pub coefficient: N, pub deg: usize, }
Expand description
A type that represents a monomial. Operations are much faster than on other types representing the same polynomial, but terms can not be added freely.
Fields
coefficient: N
deg: usize
Implementations
Return the root of Monomial
.
Example
use rustnomial::{Monomial, Roots, SizedPolynomial}; let monomial = Monomial::new(1, 2); assert_eq!(Roots::OneRealRoot(0), monomial.root()); let zero = Monomial::<i32>::zero(); assert_eq!(Roots::InfiniteRoots, zero.root()); let constant = Monomial::new(1, 0); assert_eq!(Roots::NoRoots, constant.root());
Raises the Monomial
to the power of exp.
Example
use rustnomial::Monomial; let monomial = Monomial::new(2, 1); let monomial_sqr = monomial.pow(2); let monomial_cub = monomial.pow(3); assert_eq!(monomial.clone() * monomial.clone(), monomial_sqr); assert_eq!(monomial_sqr.clone() * monomial.clone(), monomial_cub);
Trait Implementations
Performs the /=
operation. Read more
impl<N> Integrable<N, SparsePolynomial<N>> for Monomial<N> where
N: Zero + Copy + Mul<Output = N> + AddAssign + PowUsize + Div<Output = N> + TryFromUsizeExact,
impl<N> Integrable<N, SparsePolynomial<N>> for Monomial<N> where
N: Zero + Copy + Mul<Output = N> + AddAssign + PowUsize + Div<Output = N> + TryFromUsizeExact,
Returns the integral of the Monomial
.
Example
use rustnomial::{Monomial, SparsePolynomial, Integrable, FreeSizePolynomial}; let monomial = Monomial::new(3.0, 2); let integral = monomial.integral(); assert_eq!(&SparsePolynomial::from_terms(&[(1.0, 3)]), integral.inner()); assert_eq!(1., integral.eval(0., 1.));
Performs the *=
operation. Read more
Performs the *=
operation. Read more
Performs the *=
operation. Read more
Tries to add the term with given coefficient and degree
to self
, returning an error
if the particular term can not be added to self without violating constraints. Read more
Tries to subtract the term with given coefficient and degree
from self
, returning
an error if the particular term can not be subtracted from self without violating
constraints. Read more
Returns true if this Monomial
is equal to other.
Example
use rustnomial::Monomial; let a = Monomial::new(2, 2); let b = Monomial::new(2, 2); let c = Monomial::new(1, 2); assert_eq!(a, b); assert_ne!(a, c);
Performs the <<=
operation. Read more
Performs the >>=
operation. Read more
Returns the term with the given degree
of the Monomial
.
Example
use rustnomial::{Monomial, SizedPolynomial, Term}; let monomial = Monomial::new(5, 2); assert_eq!(Term::Term(5, 2), monomial.term_with_degree(2)); assert_eq!(Term::ZeroTerm, monomial.term_with_degree(1));
Returns the degree of the Monomial
.
Example
use rustnomial::{SizedPolynomial, Monomial, Degree}; let monomial = Monomial::new(3.0, 2); assert_eq!(Degree::Num(2), monomial.degree()); let zero_with_nonzero_deg = Monomial::new(0.0, 2); assert_eq!(Degree::NegInf, zero_with_nonzero_deg.degree()); let nonzero_with_zero_degree = Monomial::new(1.0, 0); assert_eq!(Degree::Num(0), nonzero_with_zero_degree.degree());
Return a Monomial
which is equal to zero.
Example
use rustnomial::{SizedPolynomial, Monomial}; assert!(Monomial::<i32>::zero().is_zero());
Sets self to zero.
Example
use rustnomial::{SizedPolynomial, Monomial}; let mut non_zero = Monomial::new(1, 1); assert!(!non_zero.is_zero()); non_zero.set_to_zero(); assert!(non_zero.is_zero());
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. Read more
Auto Trait Implementations
impl<N> RefUnwindSafe for Monomial<N> where
N: RefUnwindSafe,
impl<N> UnwindSafe for Monomial<N> where
N: UnwindSafe,
Blanket Implementations
Mutably borrows from an owned value. Read more