Monomial

Struct Monomial 

Source
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§

Source§

impl<N> Monomial<N>

Source

pub fn new(coefficient: N, degree: usize) -> Monomial<N>

Create a Monomial with coefficient and degree.

§Example
use rustnomial::{Monomial, Degree, SizedPolynomial};
let monomial = Monomial::new(3.0, 2);
assert_eq!(3.0, monomial.coefficient);
assert_eq!(Degree::Num(2), monomial.degree());
Source§

impl<N: Zero + Copy> Monomial<N>

Source

pub fn ordered_term_iter(&self) -> impl Iterator<Item = (N, usize)>

Source§

impl<N: Copy + Zero> Monomial<N>

Source

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>

Source

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: Clone> Clone for Monomial<N>

Source§

fn clone(&self) -> Monomial<N>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<N: Debug> Debug for Monomial<N>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<N> Derivable<N> for Monomial<N>
where N: Zero + Copy + Mul<Output = N> + TryFromUsizeExact,

Source§

fn derivative(&self) -> Monomial<N>

Returns the derivative of the Monomial.

§Example
use rustnomial::{Monomial, Derivable};
let monomial = Monomial::new(3.0, 2);
assert_eq!(Monomial::new(6.0, 1), monomial.derivative());
§Errors

Will panic if N can not losslessly represent the degree of self.

Source§

impl<N> Display for Monomial<N>
where N: Zero + One + PartialEq + Copy + IsNegativeOne + Display,

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<N: Div<Output = N>> Div<N> for Monomial<N>

Source§

type Output = Monomial<N>

The resulting type after applying the / operator.
Source§

fn div(self, rhs: N) -> Monomial<N>

Performs the / operation. Read more
Source§

impl<N: DivAssign> DivAssign<N> for Monomial<N>

Source§

fn div_assign(&mut self, rhs: N)

Performs the /= operation. Read more
Source§

impl<N> Evaluable<N> for Monomial<N>
where N: PowUsize + Mul<Output = N> + Copy,

Source§

fn eval(&self, point: N) -> N

Returns the value of the Monomial at the given point.

§Example
use rustnomial::{Monomial, Evaluable};
let monomial = Monomial::new(5, 2);
assert_eq!(125, monomial.eval(5));
assert_eq!(1, Monomial::new(1, 0).eval(0));
Source§

impl From<Monomial<f32>> for Monomial<f64>

Source§

fn from(item: Monomial<f32>) -> Self

Converts to this type from the input type.
Source§

impl From<Monomial<i16>> for Monomial<f32>

Source§

fn from(item: Monomial<i16>) -> Self

Converts to this type from the input type.
Source§

impl From<Monomial<i16>> for Monomial<f64>

Source§

fn from(item: Monomial<i16>) -> Self

Converts to this type from the input type.
Source§

impl From<Monomial<i16>> for Monomial<i128>

Source§

fn from(item: Monomial<i16>) -> Self

Converts to this type from the input type.
Source§

impl From<Monomial<i16>> for Monomial<i32>

Source§

fn from(item: Monomial<i16>) -> Self

Converts to this type from the input type.
Source§

impl From<Monomial<i16>> for Monomial<i64>

Source§

fn from(item: Monomial<i16>) -> Self

Converts to this type from the input type.
Source§

impl From<Monomial<i32>> for Monomial<f64>

Source§

fn from(item: Monomial<i32>) -> Self

Converts to this type from the input type.
Source§

impl From<Monomial<i32>> for Monomial<i128>

Source§

fn from(item: Monomial<i32>) -> Self

Converts to this type from the input type.
Source§

impl From<Monomial<i32>> for Monomial<i64>

Source§

fn from(item: Monomial<i32>) -> Self

Converts to this type from the input type.
Source§

impl From<Monomial<i64>> for Monomial<i128>

Source§

fn from(item: Monomial<i64>) -> Self

Converts to this type from the input type.
Source§

impl From<Monomial<i8>> for Monomial<f32>

Source§

fn from(item: Monomial<i8>) -> Self

Converts to this type from the input type.
Source§

impl From<Monomial<i8>> for Monomial<f64>

Source§

fn from(item: Monomial<i8>) -> Self

Converts to this type from the input type.
Source§

impl From<Monomial<i8>> for Monomial<i128>

Source§

fn from(item: Monomial<i8>) -> Self

Converts to this type from the input type.
Source§

impl From<Monomial<i8>> for Monomial<i16>

Source§

fn from(item: Monomial<i8>) -> Self

Converts to this type from the input type.
Source§

impl From<Monomial<i8>> for Monomial<i32>

Source§

fn from(item: Monomial<i8>) -> Self

Converts to this type from the input type.
Source§

impl From<Monomial<i8>> for Monomial<i64>

Source§

fn from(item: Monomial<i8>) -> Self

Converts to this type from the input type.
Source§

impl From<Monomial<u16>> for Monomial<f32>

Source§

fn from(item: Monomial<u16>) -> Self

Converts to this type from the input type.
Source§

impl From<Monomial<u16>> for Monomial<f64>

Source§

fn from(item: Monomial<u16>) -> Self

Converts to this type from the input type.
Source§

impl From<Monomial<u16>> for Monomial<i128>

Source§

fn from(item: Monomial<u16>) -> Self

Converts to this type from the input type.
Source§

impl From<Monomial<u16>> for Monomial<i32>

Source§

fn from(item: Monomial<u16>) -> Self

Converts to this type from the input type.
Source§

impl From<Monomial<u16>> for Monomial<i64>

Source§

fn from(item: Monomial<u16>) -> Self

Converts to this type from the input type.
Source§

impl From<Monomial<u16>> for Monomial<u128>

Source§

fn from(item: Monomial<u16>) -> Self

Converts to this type from the input type.
Source§

impl From<Monomial<u16>> for Monomial<u32>

Source§

fn from(item: Monomial<u16>) -> Self

Converts to this type from the input type.
Source§

impl From<Monomial<u16>> for Monomial<u64>

Source§

fn from(item: Monomial<u16>) -> Self

Converts to this type from the input type.
Source§

impl From<Monomial<u32>> for Monomial<f64>

Source§

fn from(item: Monomial<u32>) -> Self

Converts to this type from the input type.
Source§

impl From<Monomial<u32>> for Monomial<i128>

Source§

fn from(item: Monomial<u32>) -> Self

Converts to this type from the input type.
Source§

impl From<Monomial<u32>> for Monomial<i64>

Source§

fn from(item: Monomial<u32>) -> Self

Converts to this type from the input type.
Source§

impl From<Monomial<u32>> for Monomial<u128>

Source§

fn from(item: Monomial<u32>) -> Self

Converts to this type from the input type.
Source§

impl From<Monomial<u32>> for Monomial<u64>

Source§

fn from(item: Monomial<u32>) -> Self

Converts to this type from the input type.
Source§

impl From<Monomial<u64>> for Monomial<i128>

Source§

fn from(item: Monomial<u64>) -> Self

Converts to this type from the input type.
Source§

impl From<Monomial<u64>> for Monomial<u128>

Source§

fn from(item: Monomial<u64>) -> Self

Converts to this type from the input type.
Source§

impl From<Monomial<u8>> for Monomial<f32>

Source§

fn from(item: Monomial<u8>) -> Self

Converts to this type from the input type.
Source§

impl From<Monomial<u8>> for Monomial<f64>

Source§

fn from(item: Monomial<u8>) -> Self

Converts to this type from the input type.
Source§

impl From<Monomial<u8>> for Monomial<i128>

Source§

fn from(item: Monomial<u8>) -> Self

Converts to this type from the input type.
Source§

impl From<Monomial<u8>> for Monomial<i16>

Source§

fn from(item: Monomial<u8>) -> Self

Converts to this type from the input type.
Source§

impl From<Monomial<u8>> for Monomial<i32>

Source§

fn from(item: Monomial<u8>) -> Self

Converts to this type from the input type.
Source§

impl From<Monomial<u8>> for Monomial<i64>

Source§

fn from(item: Monomial<u8>) -> Self

Converts to this type from the input type.
Source§

impl From<Monomial<u8>> for Monomial<u128>

Source§

fn from(item: Monomial<u8>) -> Self

Converts to this type from the input type.
Source§

impl From<Monomial<u8>> for Monomial<u16>

Source§

fn from(item: Monomial<u8>) -> Self

Converts to this type from the input type.
Source§

impl From<Monomial<u8>> for Monomial<u32>

Source§

fn from(item: Monomial<u8>) -> Self

Converts to this type from the input type.
Source§

impl From<Monomial<u8>> for Monomial<u64>

Source§

fn from(item: Monomial<u8>) -> Self

Converts to this type from the input type.
Source§

impl<N> From<N> for Monomial<N>

Source§

fn from(item: N) -> Self

Converts to this type from the input type.
Source§

impl<N> FromStr for Monomial<N>
where N: Zero + One + Copy + SubAssign + AddAssign + FromStr + CanNegate,

Source§

type Err = PolynomialFromStringError

The associated error which can be returned from parsing.
Source§

fn from_str(s: &str) -> Result<Self, Self::Err>

Parses a string s to return a value of this type. Read more
Source§

impl<N> Integrable<N, SparsePolynomial<N>> for Monomial<N>
where N: Zero + Copy + Mul<Output = N> + AddAssign + PowUsize + Div<Output = N> + TryFromUsizeExact,

Source§

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: Copy + Mul<Output = N>> Mul<&Monomial<N>> for Monomial<N>

Source§

type Output = Monomial<N>

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: &Monomial<N>) -> Monomial<N>

Performs the * operation. Read more
Source§

impl<N: Mul<Output = N>> Mul<N> for Monomial<N>

Source§

type Output = Monomial<N>

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: N) -> Monomial<N>

Performs the * operation. Read more
Source§

impl<N: Copy + Mul<Output = N>> Mul for Monomial<N>

Source§

type Output = Monomial<N>

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: Monomial<N>) -> Monomial<N>

Performs the * operation. Read more
Source§

impl<N> MulAssign<&Monomial<N>> for Monomial<N>
where N: MulAssign + AddAssign + Copy,

Source§

fn mul_assign(&mut self, rhs: &Monomial<N>)

Performs the *= operation. Read more
Source§

impl<N: MulAssign> MulAssign<N> for Monomial<N>

Source§

fn mul_assign(&mut self, rhs: N)

Performs the *= operation. Read more
Source§

impl<N: MulAssign> MulAssign for Monomial<N>

Source§

fn mul_assign(&mut self, rhs: Monomial<N>)

Performs the *= operation. Read more
Source§

impl<N> MutablePolynomial<N> for Monomial<N>
where N: SubAssign + AddAssign + Copy + Zero,

Source§

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 more
Source§

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 more
Source§

impl<N: Copy + Neg<Output = N>> Neg for Monomial<N>

Source§

type Output = Monomial<N>

The resulting type after applying the - operator.
Source§

fn neg(self) -> Monomial<N>

Performs the unary - operation. Read more
Source§

impl<N> PartialEq for Monomial<N>
where N: Zero + PartialEq + Copy,

Source§

fn eq(&self, other: &Self) -> bool

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);
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<N: Zero + Copy> Shl<i32> for Monomial<N>

Source§

type Output = Monomial<N>

The resulting type after applying the << operator.
Source§

fn shl(self, rhs: i32) -> Monomial<N>

Performs the << operation. Read more
Source§

impl<N: Zero + Copy> ShlAssign<i32> for Monomial<N>

Source§

fn shl_assign(&mut self, rhs: i32)

Performs the <<= operation. Read more
Source§

impl<N: Zero + Copy> Shr<i32> for Monomial<N>

Source§

type Output = Monomial<N>

The resulting type after applying the >> operator.
Source§

fn shr(self, rhs: i32) -> Monomial<N>

Performs the >> operation. Read more
Source§

impl<N: Zero + Copy> ShrAssign<i32> for Monomial<N>

Source§

fn shr_assign(&mut self, rhs: i32)

Performs the >>= operation. Read more
Source§

impl<N: Copy + Zero> SizedPolynomial<N> for Monomial<N>

Source§

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

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

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)

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());
Source§

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. Read more
Source§

fn is_zero(&self) -> bool

Returns true if all terms of self are zero, and false if a non-zero term exists. Read more

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<!> for T

Source§

fn from(t: !) -> T

Converts to this type from the input type.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.