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: Ndeg: usize

Implementations

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

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

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

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.

Formats the value using the given formatter. Read more

The resulting type after applying the / operator.

Performs the / operation. Read more

Performs the /= operation. Read more

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));

Performs the conversion.

Performs the conversion.

Performs the conversion.

Performs the conversion.

Performs the conversion.

Performs the conversion.

Performs the conversion.

Performs the conversion.

Performs the conversion.

Performs the conversion.

Performs the conversion.

Performs the conversion.

Performs the conversion.

Performs the conversion.

Performs the conversion.

Performs the conversion.

Performs the conversion.

Performs the conversion.

Performs the conversion.

Performs the conversion.

Performs the conversion.

Performs the conversion.

Performs the conversion.

Performs the conversion.

Performs the conversion.

Performs the conversion.

Performs the conversion.

Performs the conversion.

Performs the conversion.

Performs the conversion.

Performs the conversion.

Performs the conversion.

Performs the conversion.

Performs the conversion.

Performs the conversion.

Performs the conversion.

Performs the conversion.

Performs the conversion.

Performs the conversion.

Performs the conversion.

Performs the conversion.

Performs the conversion.

The associated error which can be returned from parsing.

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

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.));

The resulting type after applying the * operator.

Performs the * operation. Read more

The resulting type after applying the * operator.

Performs the * operation. Read more

The resulting type after applying the * operator.

Performs the * operation. Read more

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

The resulting type after applying the - operator.

Performs the unary - operation. 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);

This method tests for !=.

The resulting type after applying the << operator.

Performs the << operation. Read more

Performs the <<= operation. Read more

The resulting type after applying the >> operator.

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

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

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

Performs the conversion.

The resulting type after obtaining ownership.

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

🔬 This is a nightly-only experimental API. (toowned_clone_into)

recently added

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

Converts the given value to a String. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.