Struct LinearBinomial

Source
pub struct LinearBinomial<N> {
    pub coefficients: [N; 2],
}
Expand description

A type that stores terms of a linear binomial in a static array. Operations are much faster than on Polynomial for the same size polynomial, but terms can not be added freely.

Fields§

§coefficients: [N; 2]

Implementations§

Source§

impl<N: Sized> LinearBinomial<N>

Source

pub fn new(coefficients: [N; 2]) -> LinearBinomial<N>

Create a LinearBinomial with the given terms.

§Example
use rustnomial::{SizedPolynomial, LinearBinomial, Degree};
let binomial = LinearBinomial::new([3, 2]);
assert_eq!(Degree::Num(1), binomial.degree());
Source§

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

Source

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

Source§

impl<N> LinearBinomial<N>
where N: Copy + Neg<Output = N> + Div<Output = N> + Zero,

Source

pub fn root(&self) -> Roots<N>

Return the root of LinearBinomial.

§Example
use rustnomial::{LinearBinomial, Roots, SizedPolynomial};
let binomial = LinearBinomial::new([1.0, 2.0]);
assert_eq!(Roots::OneRealRoot(-2.0), binomial.root());
let zero = LinearBinomial::<i32>::zero();
assert_eq!(Roots::InfiniteRoots, zero.root());
let constant = LinearBinomial::new([0, 1]);
assert_eq!(Roots::NoRoots, constant.root());

Trait Implementations§

Source§

impl<N> Add for LinearBinomial<N>
where N: Add<Output = N> + Copy,

Source§

type Output = LinearBinomial<N>

The resulting type after applying the + operator.
Source§

fn add(self, rhs: LinearBinomial<N>) -> LinearBinomial<N>

Performs the + operation. Read more
Source§

impl<N: Copy + AddAssign> AddAssign for LinearBinomial<N>

Source§

fn add_assign(&mut self, rhs: LinearBinomial<N>)

Performs the += operation. Read more
Source§

impl<N: Clone> Clone for LinearBinomial<N>

Source§

fn clone(&self) -> LinearBinomial<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 LinearBinomial<N>

Source§

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

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

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

Source§

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

Returns the derivative of the LinearBinomial.

§Example
use rustnomial::{LinearBinomial, Derivable};
let binomial = LinearBinomial::new([3.0, 1.0]);
assert_eq!(LinearBinomial::new([0., 3.0]), binomial.derivative());
Source§

impl<N> Display for LinearBinomial<N>
where N: Zero + One + IsPositive + PartialEq + Abs + 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> + Copy> Div<N> for LinearBinomial<N>

Source§

type Output = LinearBinomial<N>

The resulting type after applying the / operator.
Source§

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

Performs the / operation. Read more
Source§

impl<N: DivAssign + Copy> DivAssign<N> for LinearBinomial<N>

Source§

fn div_assign(&mut self, rhs: N)

Performs the /= operation. Read more
Source§

impl<N> Evaluable<N> for LinearBinomial<N>
where N: Add<Output = N> + Mul<Output = N> + Copy,

Source§

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

Returns the value of the LinearBinomial at the given point.

§Example
use rustnomial::{LinearBinomial, Evaluable};
let binomial = LinearBinomial::new([1, 2]);
assert_eq!(7, binomial.eval(5));
assert_eq!(2, binomial.eval(0));
Source§

impl From<LinearBinomial<f32>> for LinearBinomial<f64>

Source§

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

Converts to this type from the input type.
Source§

impl From<LinearBinomial<i16>> for LinearBinomial<f32>

Source§

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

Converts to this type from the input type.
Source§

impl From<LinearBinomial<i16>> for LinearBinomial<f64>

Source§

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

Converts to this type from the input type.
Source§

impl From<LinearBinomial<i16>> for LinearBinomial<i128>

Source§

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

Converts to this type from the input type.
Source§

impl From<LinearBinomial<i16>> for LinearBinomial<i32>

Source§

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

Converts to this type from the input type.
Source§

impl From<LinearBinomial<i16>> for LinearBinomial<i64>

Source§

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

Converts to this type from the input type.
Source§

impl From<LinearBinomial<i32>> for LinearBinomial<f64>

Source§

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

Converts to this type from the input type.
Source§

impl From<LinearBinomial<i32>> for LinearBinomial<i128>

Source§

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

Converts to this type from the input type.
Source§

impl From<LinearBinomial<i32>> for LinearBinomial<i64>

Source§

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

Converts to this type from the input type.
Source§

impl From<LinearBinomial<i64>> for LinearBinomial<i128>

Source§

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

Converts to this type from the input type.
Source§

impl From<LinearBinomial<i8>> for LinearBinomial<f32>

Source§

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

Converts to this type from the input type.
Source§

impl From<LinearBinomial<i8>> for LinearBinomial<f64>

Source§

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

Converts to this type from the input type.
Source§

impl From<LinearBinomial<i8>> for LinearBinomial<i128>

Source§

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

Converts to this type from the input type.
Source§

impl From<LinearBinomial<i8>> for LinearBinomial<i16>

Source§

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

Converts to this type from the input type.
Source§

impl From<LinearBinomial<i8>> for LinearBinomial<i32>

Source§

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

Converts to this type from the input type.
Source§

impl From<LinearBinomial<i8>> for LinearBinomial<i64>

Source§

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

Converts to this type from the input type.
Source§

impl From<LinearBinomial<u16>> for LinearBinomial<f32>

Source§

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

Converts to this type from the input type.
Source§

impl From<LinearBinomial<u16>> for LinearBinomial<f64>

Source§

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

Converts to this type from the input type.
Source§

impl From<LinearBinomial<u16>> for LinearBinomial<i128>

Source§

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

Converts to this type from the input type.
Source§

impl From<LinearBinomial<u16>> for LinearBinomial<i32>

Source§

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

Converts to this type from the input type.
Source§

impl From<LinearBinomial<u16>> for LinearBinomial<i64>

Source§

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

Converts to this type from the input type.
Source§

impl From<LinearBinomial<u16>> for LinearBinomial<u128>

Source§

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

Converts to this type from the input type.
Source§

impl From<LinearBinomial<u16>> for LinearBinomial<u32>

Source§

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

Converts to this type from the input type.
Source§

impl From<LinearBinomial<u16>> for LinearBinomial<u64>

Source§

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

Converts to this type from the input type.
Source§

impl From<LinearBinomial<u32>> for LinearBinomial<f64>

Source§

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

Converts to this type from the input type.
Source§

impl From<LinearBinomial<u32>> for LinearBinomial<i128>

Source§

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

Converts to this type from the input type.
Source§

impl From<LinearBinomial<u32>> for LinearBinomial<i64>

Source§

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

Converts to this type from the input type.
Source§

impl From<LinearBinomial<u32>> for LinearBinomial<u128>

Source§

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

Converts to this type from the input type.
Source§

impl From<LinearBinomial<u32>> for LinearBinomial<u64>

Source§

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

Converts to this type from the input type.
Source§

impl From<LinearBinomial<u64>> for LinearBinomial<i128>

Source§

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

Converts to this type from the input type.
Source§

impl From<LinearBinomial<u64>> for LinearBinomial<u128>

Source§

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

Converts to this type from the input type.
Source§

impl From<LinearBinomial<u8>> for LinearBinomial<f32>

Source§

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

Converts to this type from the input type.
Source§

impl From<LinearBinomial<u8>> for LinearBinomial<f64>

Source§

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

Converts to this type from the input type.
Source§

impl From<LinearBinomial<u8>> for LinearBinomial<i128>

Source§

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

Converts to this type from the input type.
Source§

impl From<LinearBinomial<u8>> for LinearBinomial<i16>

Source§

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

Converts to this type from the input type.
Source§

impl From<LinearBinomial<u8>> for LinearBinomial<i32>

Source§

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

Converts to this type from the input type.
Source§

impl From<LinearBinomial<u8>> for LinearBinomial<i64>

Source§

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

Converts to this type from the input type.
Source§

impl From<LinearBinomial<u8>> for LinearBinomial<u128>

Source§

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

Converts to this type from the input type.
Source§

impl From<LinearBinomial<u8>> for LinearBinomial<u16>

Source§

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

Converts to this type from the input type.
Source§

impl From<LinearBinomial<u8>> for LinearBinomial<u32>

Source§

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

Converts to this type from the input type.
Source§

impl From<LinearBinomial<u8>> for LinearBinomial<u64>

Source§

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

Converts to this type from the input type.
Source§

impl<N> FromStr for LinearBinomial<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, Polynomial<N>> for LinearBinomial<N>
where N: Zero + Copy + DivAssign + Mul<Output = N> + MulAssign + AddAssign + Div<Output = N> + TryFromUsizeContinuous,

Source§

fn integral(&self) -> Integral<N, Polynomial<N>>

Returns the integral of the LinearBinomial.

§Example
use rustnomial::{LinearBinomial, Integrable, Polynomial};
let binomial = LinearBinomial::new([2.0, 0.]);
let integral = binomial.integral();
assert_eq!(&Polynomial::new(vec![1.0, 0.0, 0.0]), integral.inner());

Will panic if N can not losslessly represent 2usize.

Source§

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

Source§

type Output = LinearBinomial<N>

The resulting type after applying the * operator.
Source§

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

Performs the * operation. Read more
Source§

impl<N: MulAssign + Copy> MulAssign<N> for LinearBinomial<N>

Source§

fn mul_assign(&mut self, rhs: N)

Performs the *= operation. Read more
Source§

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

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 LinearBinomial<N>

Source§

type Output = LinearBinomial<N>

The resulting type after applying the - operator.
Source§

fn neg(self) -> LinearBinomial<N>

Performs the unary - operation. Read more
Source§

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

Source§

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

Returns true if this LinearBinomial and other are equal.

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> Shr<u32> for LinearBinomial<N>

Source§

type Output = LinearBinomial<N>

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

fn shr(self, rhs: u32) -> LinearBinomial<N>

Performs the >> operation. Read more
Source§

impl<N: Zero + Copy> ShrAssign<u32> for LinearBinomial<N>

Source§

fn shr_assign(&mut self, rhs: u32)

Performs the >>= operation. Read more
Source§

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

Source§

fn term_with_degree(&self, degree: usize) -> Term<N>

Returns the term with the given degree of the LinearBinomial.

§Example
use rustnomial::{LinearBinomial, SizedPolynomial, Term};
let binomial = LinearBinomial::new([5, 0]);
assert_eq!(Term::Term(5, 1), binomial.term_with_degree(1));
assert_eq!(Term::ZeroTerm, binomial.term_with_degree(0));
Source§

fn degree(&self) -> Degree

Returns the degree of the LinearBinomial.

§Example
use rustnomial::{SizedPolynomial, LinearBinomial, Degree};
let binomial = LinearBinomial::new([3.0, 2.0]);
assert_eq!(Degree::Num(1), binomial.degree());
let monomial = LinearBinomial::new([0.0, 1.0]);
assert_eq!(Degree::Num(0), monomial.degree());
let zero = LinearBinomial::<i32>::zero();
assert_eq!(Degree::NegInf, zero.degree());
Source§

fn zero() -> Self

Returns a LinearBinomial with no terms.

§Example
use rustnomial::{SizedPolynomial, LinearBinomial};
let zero = LinearBinomial::<i32>::zero();
assert!(zero.is_zero());
assert!(zero.ordered_term_iter().next().is_none());
Source§

fn set_to_zero(&mut self)

Sets self to zero.

§Example
use rustnomial::{SizedPolynomial, LinearBinomial};
let mut non_zero = LinearBinomial::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
Source§

impl<N> Sub for LinearBinomial<N>
where N: Copy + Sub<Output = N>,

Source§

type Output = LinearBinomial<N>

The resulting type after applying the - operator.
Source§

fn sub(self, rhs: LinearBinomial<N>) -> LinearBinomial<N>

Performs the - operation. Read more
Source§

impl<N> SubAssign for LinearBinomial<N>
where N: SubAssign + Copy,

Source§

fn sub_assign(&mut self, rhs: LinearBinomial<N>)

Performs the -= operation. Read more

Auto Trait Implementations§

§

impl<N> Freeze for LinearBinomial<N>
where N: Freeze,

§

impl<N> RefUnwindSafe for LinearBinomial<N>
where N: RefUnwindSafe,

§

impl<N> Send for LinearBinomial<N>
where N: Send,

§

impl<N> Sync for LinearBinomial<N>
where N: Sync,

§

impl<N> Unpin for LinearBinomial<N>
where N: Unpin,

§

impl<N> UnwindSafe for LinearBinomial<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<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.