[−][src]Struct polynomials::Polynomial
A Polynomial
is just a vector of coefficients. Each coefficient corresponds to a power of
x
in increasing order. For example, the following polynomial is equal to 4x^2 + 3x - 9.
// Construct polynomial 4x^2 + 3x - 9 let mut a = poly![-9, 3, 4]; assert_eq!(a[0], -9); assert_eq!(a[1], 3); assert_eq!(a[2], 4);
Implementations
impl<T> Polynomial<T>
[src]
pub fn new() -> Polynomial<T>
[src]
Create a new, empty, instance of a polynomial.
pub fn push(&mut self, value: T)
[src]
Adds a new coefficient to the Polynomial
, in the next highest order position.
let mut a = poly![-8, 2, 4]; a.push(7); assert_eq!(a, poly![-8, 2, 4, 7]);
pub fn pop(&mut self) -> Option<T>
[src]
Removes the highest order coefficient from the Polynomial
.
let mut a = poly![-8, 2, 4]; assert_eq!(a.pop().unwrap(), 4); assert_eq!(a, poly![-8, 2]);
pub fn degree(&self) -> usize where
T: Sub<T, Output = T> + Eq + Copy,
[src]
T: Sub<T, Output = T> + Eq + Copy,
Calculates the degree of a Polynomial
.
The following polynomial is of degree 2: (4x^2 + 2x - 8)
let a = poly![-8, 2, 4]; assert_eq!(a.degree(), 2);
pub fn eval<X>(&self, x: X) -> Option<T> where
T: AddAssign + Copy,
X: MulAssign + Mul<T, Output = T> + Copy,
[src]
T: AddAssign + Copy,
X: MulAssign + Mul<T, Output = T> + Copy,
Evaluate a Polynomial
for some value x
.
The following example evaluates the polynomial (4x^2 + 2x - 8) for x = 3.
let a = poly![-8, 2, 4]; assert_eq!(a.eval(3).unwrap(), 34);
pub fn iter(&self) -> impl Iterator<Item = &T>
[src]
pub fn into_iter(self) -> impl IntoIterator<Item = T, IntoIter = IntoIter<T>>
[src]
Trait Implementations
impl<T: Add<Output = T>> Add<Polynomial<T>> for Polynomial<T> where
T: Add + Copy + Clone,
[src]
T: Add + Copy + Clone,
Add two Polynomial
s.
The following example adds two polynomials: (4x^2 + 2x - 8) + (x + 1) = (4x^2 + 3x - 7)
let a = poly![-8, 2, 4]; let b = poly![1, 1]; assert_eq!(a + b, poly![-7, 3, 4]);
type Output = Self
The resulting type after applying the +
operator.
fn add(self, other: Self) -> Self::Output
[src]
impl<T> AddAssign<Polynomial<T>> for Polynomial<T> where
T: Add<Output = T> + Copy,
[src]
T: Add<Output = T> + Copy,
fn add_assign(&mut self, rhs: Self)
[src]
impl<T: Clone> Clone for Polynomial<T>
[src]
fn clone(&self) -> Polynomial<T>
[src]
fn clone_from(&mut self, source: &Self)
1.0.0[src]
impl<T: Debug> Debug for Polynomial<T>
[src]
impl<'de, T> Deserialize<'de> for Polynomial<T> where
T: Deserialize<'de>,
[src]
T: Deserialize<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error> where
__D: Deserializer<'de>,
[src]
__D: Deserializer<'de>,
impl<T> Div<T> for Polynomial<T> where
T: DivAssign + Copy,
[src]
T: DivAssign + Copy,
Divide a Polynomial
by some value.
The following example divides a polynomial (4x^2 + 2x - 8) by 2:
let p = poly![-8, 2, 4] / 2; assert_eq!(p, poly![-4, 1, 2]);
type Output = Self
The resulting type after applying the /
operator.
fn div(self, rhs: T) -> Self::Output
[src]
impl<T> DivAssign<T> for Polynomial<T> where
T: DivAssign + Copy,
[src]
T: DivAssign + Copy,
fn div_assign(&mut self, rhs: T)
[src]
impl<T> Eq for Polynomial<T> where
T: Sub<T, Output = T> + Eq + Copy,
[src]
T: Sub<T, Output = T> + Eq + Copy,
impl<T> From<Vec<T>> for Polynomial<T>
[src]
impl<T, I: SliceIndex<[T]>> Index<I> for Polynomial<T>
[src]
type Output = I::Output
The returned type after indexing.
fn index(&self, index: I) -> &Self::Output
[src]
impl<T, I: SliceIndex<[T]>> IndexMut<I> for Polynomial<T>
[src]
impl<T> Into<Vec<T>> for Polynomial<T>
[src]
impl<T> Mul<Polynomial<T>> for Polynomial<T> where
T: Mul<Output = T> + AddAssign + Sub<Output = T>,
T: Copy + Clone,
[src]
T: Mul<Output = T> + AddAssign + Sub<Output = T>,
T: Copy + Clone,
Multiply a Polynomial
by some value.
The following example multiplies a polynomial (4x^2 + 2x - 8) by 2:
let p = poly![-8, 2, 4] * 2; assert_eq!(p, poly![-16, 4, 8]);
type Output = Self
The resulting type after applying the *
operator.
fn mul(self, rhs: Self) -> Self::Output
[src]
impl<T> Mul<T> for Polynomial<T> where
T: MulAssign + Copy,
[src]
T: MulAssign + Copy,
Multiply two Polynomial
s.
The following example multiplies two polynomials: (4x^2 + 2x - 8) * (x + 1) = (4x^3 + 6x^2 - 6x - 8)
let a = poly![-8, 2, 4]; let b = poly![1, 1]; assert_eq!(a * b, poly![-8, -6, 6, 4]);
type Output = Self
The resulting type after applying the *
operator.
fn mul(self, rhs: T) -> Self::Output
[src]
impl<T> MulAssign<Polynomial<T>> for Polynomial<T> where
T: Mul<Output = T> + AddAssign + Sub<Output = T>,
T: Copy + Clone,
[src]
T: Mul<Output = T> + AddAssign + Sub<Output = T>,
T: Copy + Clone,
fn mul_assign(&mut self, rhs: Self)
[src]
impl<T> MulAssign<T> for Polynomial<T> where
T: MulAssign + Copy,
[src]
T: MulAssign + Copy,
fn mul_assign(&mut self, rhs: T)
[src]
impl<T> PartialEq<Polynomial<T>> for Polynomial<T> where
T: Sub<T, Output = T> + Eq + Copy,
[src]
T: Sub<T, Output = T> + Eq + Copy,
impl<T> Serialize for Polynomial<T> where
T: Serialize,
[src]
T: Serialize,
fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error> where
__S: Serializer,
[src]
__S: Serializer,
impl<T: Sub<Output = T>> Sub<Polynomial<T>> for Polynomial<T> where
T: Sub + Neg<Output = T> + Copy + Clone,
[src]
T: Sub + Neg<Output = T> + Copy + Clone,
Subtract two Polynomial
s.
The following example subtracts two polynomials: (4x^2 + 2x - 8) - (x + 1) = (4x^2 + x - 9)
let a = poly![-8, 2, 4]; let b = poly![1, 1]; assert_eq!(a - b, poly![-9, 1, 4]);
type Output = Self
The resulting type after applying the -
operator.
fn sub(self, other: Self) -> Self::Output
[src]
impl<T> SubAssign<Polynomial<T>> for Polynomial<T> where
T: Sub<Output = T> + Neg<Output = T> + Copy,
[src]
T: Sub<Output = T> + Neg<Output = T> + Copy,
fn sub_assign(&mut self, rhs: Self)
[src]
Auto Trait Implementations
impl<T> RefUnwindSafe for Polynomial<T> where
T: RefUnwindSafe,
T: RefUnwindSafe,
impl<T> Send for Polynomial<T> where
T: Send,
T: Send,
impl<T> Sync for Polynomial<T> where
T: Sync,
T: Sync,
impl<T> Unpin for Polynomial<T> where
T: Unpin,
T: Unpin,
impl<T> UnwindSafe for Polynomial<T> where
T: UnwindSafe,
T: UnwindSafe,
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> DeserializeOwned for T where
T: for<'de> Deserialize<'de>,
[src]
T: for<'de> Deserialize<'de>,
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
fn to_owned(&self) -> T
[src]
fn clone_into(&self, target: &mut T)
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,