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: usizeImplementations§
Source§impl<N: Zero + Copy> Monomial<N>
impl<N: Zero + Copy> Monomial<N>
pub fn ordered_term_iter(&self) -> impl Iterator<Item = (N, usize)>
Source§impl<N: Copy + Zero> Monomial<N>
impl<N: Copy + Zero> Monomial<N>
Sourcepub fn root(&self) -> Roots<N>
pub fn root(&self) -> Roots<N>
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());Source§impl<N: PowUsize + Copy> Monomial<N>
impl<N: PowUsize + Copy> Monomial<N>
Sourcepub fn pow(&self, exp: usize) -> Monomial<N>
pub fn pow(&self, exp: usize) -> Monomial<N>
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§
Source§impl<N: DivAssign> DivAssign<N> for Monomial<N>
impl<N: DivAssign> DivAssign<N> for Monomial<N>
Source§fn div_assign(&mut self, rhs: N)
fn div_assign(&mut self, rhs: N)
Performs the
/= operation. Read moreSource§impl<N> Integrable<N, SparsePolynomial<N>> for Monomial<N>
impl<N> Integrable<N, SparsePolynomial<N>> for Monomial<N>
Source§fn integral(&self) -> Integral<N, SparsePolynomial<N>>
fn integral(&self) -> Integral<N, SparsePolynomial<N>>
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.));Source§impl<N> MulAssign<&Monomial<N>> for Monomial<N>
impl<N> MulAssign<&Monomial<N>> for Monomial<N>
Source§fn mul_assign(&mut self, rhs: &Monomial<N>)
fn mul_assign(&mut self, rhs: &Monomial<N>)
Performs the
*= operation. Read moreSource§impl<N: MulAssign> MulAssign<N> for Monomial<N>
impl<N: MulAssign> MulAssign<N> for Monomial<N>
Source§fn mul_assign(&mut self, rhs: N)
fn mul_assign(&mut self, rhs: N)
Performs the
*= operation. Read moreSource§impl<N: MulAssign> MulAssign for Monomial<N>
impl<N: MulAssign> MulAssign for Monomial<N>
Source§fn mul_assign(&mut self, rhs: Monomial<N>)
fn mul_assign(&mut self, rhs: Monomial<N>)
Performs the
*= operation. Read moreSource§impl<N> MutablePolynomial<N> for Monomial<N>
impl<N> MutablePolynomial<N> for Monomial<N>
Source§fn try_add_term(&mut self, coeff: N, degree: usize) -> Result<(), TryAddError>
fn try_add_term(&mut self, coeff: N, degree: usize) -> Result<(), TryAddError>
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 moreSource§fn try_sub_term(&mut self, coeff: N, degree: usize) -> Result<(), TryAddError>
fn try_sub_term(&mut self, coeff: N, degree: usize) -> Result<(), TryAddError>
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 moreSource§impl<N> PartialEq for Monomial<N>
impl<N> PartialEq for Monomial<N>
Source§impl<N: Zero + Copy> ShlAssign<i32> for Monomial<N>
impl<N: Zero + Copy> ShlAssign<i32> for Monomial<N>
Source§fn shl_assign(&mut self, rhs: i32)
fn shl_assign(&mut self, rhs: i32)
Performs the
<<= operation. Read moreSource§impl<N: Zero + Copy> ShrAssign<i32> for Monomial<N>
impl<N: Zero + Copy> ShrAssign<i32> for Monomial<N>
Source§fn shr_assign(&mut self, rhs: i32)
fn shr_assign(&mut self, rhs: i32)
Performs the
>>= operation. Read moreSource§impl<N: Copy + Zero> SizedPolynomial<N> for Monomial<N>
impl<N: Copy + Zero> SizedPolynomial<N> for Monomial<N>
Source§fn term_with_degree(&self, degree: usize) -> Term<N>
fn term_with_degree(&self, degree: usize) -> Term<N>
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));Source§fn degree(&self) -> Degree
fn degree(&self) -> Degree
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());Source§fn zero() -> Self
fn zero() -> Self
Return a Monomial which is equal to zero.
§Example
use rustnomial::{SizedPolynomial, Monomial};
assert!(Monomial::<i32>::zero().is_zero());Source§fn set_to_zero(&mut self)
fn set_to_zero(&mut self)
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());Auto Trait Implementations§
impl<N> Freeze for Monomial<N>where
N: Freeze,
impl<N> RefUnwindSafe for Monomial<N>where
N: RefUnwindSafe,
impl<N> Send for Monomial<N>where
N: Send,
impl<N> Sync for Monomial<N>where
N: Sync,
impl<N> Unpin for Monomial<N>where
N: Unpin,
impl<N> UnwindSafe for Monomial<N>where
N: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more