Struct polynomint::Polynomial [−][src]
A wrapper struct around a Vec<isize>
which treats the entries of the Vec
as the coefficients
of a polynomial.
Examples
use polynomint::{Polynomial, poly}; let quadratic = poly![1, 2, 1]; // x^2 + 2x + 1 let linear = poly![-6, 1]; // x - 6 assert_eq!(&quadratic * 5, poly![5, 10, 5]); assert_eq!(&quadratic * &linear, poly![-6, -11, -4, 1]); let mut resultant = &quadratic * &linear; resultant %= 5; assert_eq!(resultant, poly![-1, -1, -4, 1]); let resultant2 = (&quadratic * &linear).rem_euclid(5); assert_eq!(resultant2, poly![4, 4, 1, 1]);
Implementations
impl Polynomial
[src]
pub fn new(coeffs: Vec<isize>) -> Self
[src]
Creates a polynomial with the given coefficients, stored in increasing order, with any trailing (higher-degree) zeroes removed.
Examples
use polynomint::Polynomial; let quadratic = Polynomial::new(vec![1, 2, 3]); // 3x^2 + 2x + 1 let cubic = Polynomial::new(vec![8, 12, 6, 1]); // x^3 + 6x^2 + 12x + 8
pub fn zero() -> Self
[src]
Creates the zero polynomial, which is stored internally as an empty vector.
pub fn constant(i: isize) -> Self
[src]
Creates a constant polynomial with coefficient equal to the argument passed;
if the argument passed is zero, it is stored internally as an empty vector
to match zero()
.
pub fn degree(&self) -> isize
[src]
Gives the highest power which has a nonzero coefficient; constants are degree zero, except the constant polynomial 0, which has degree -1.
Examples
use polynomint::{Polynomial, poly}; let zero = Polynomial::zero(); let alt_zero = Polynomial::constant(0); let three = Polynomial::constant(3); let classic = poly![1, 2, 1, 0, 0]; // x^2 + 2x + 1 assert_eq!(zero.degree(), -1); assert_eq!(alt_zero.degree(), -1); assert_eq!(three.degree(), 0); assert_eq!(classic.degree(), 2);
pub fn times_x(&self) -> Self
[src]
Gives a new polynomial equal to the old one times x.
Examples
use polynomint::{Polynomial, poly}; let first = poly![1, 2, 3]; let second = first.times_x(); assert_eq!(second, poly![0, 1, 2, 3]);
pub fn rem_euclid(&self, n: isize) -> Self
[src]
Gives a new polynomial equal to the remainder of the old one when taken
modulo n
.
Examples
use polynomint::{Polynomial, poly}; let poly = poly![6, -5, 3, -7, 4]; assert_eq!(poly.rem_euclid(2), poly![0, 1, 1, 1]); assert_eq!(poly.rem_euclid(4), poly![2, 3, 3, 1]); assert_eq!(poly.rem_euclid(5), poly![1, 0, 3, 3, 4]);
pub fn is_zero(&self) -> bool
[src]
Checks whether a polynomial is the zero polynomial.
Examples
use polynomint::{Polynomial, poly}; let zero = Polynomial::zero(); let also_zero = Polynomial::constant(0); let yet_again_zero = poly![0, 0, 0, 0]; let even_more_zero = poly![1, 2, 1] - poly![1, 2, 1]; let not_zero = poly![0, 1]; assert!(zero.is_zero()); assert!(also_zero.is_zero()); assert!(yet_again_zero.is_zero()); assert!(even_more_zero.is_zero()); assert!(!not_zero.is_zero());
pub fn derivative(&self) -> Self
[src]
Creates a new polynomial which is the derivative of the old one.
Examples
use polynomint::{Polynomial, poly}; let poly1 = poly![1, -2, 5, 4]; // 4x^3 + 5x^2 - 2x + 1 assert_eq!(poly1.derivative(), poly![-2, 10, 12]); // deriv. is 12x^2 + 10x - 2 let poly2 = poly![192, 3, -4, -9, 0, 38]; // 38x^5 - 9x^3 - 4x^2 + 3x + 192 assert_eq!(poly2.derivative(), poly![3, -8, -27, 0, 190]); // deriv. is 190x^4 - 27x^2 - 8x + 3
Trait Implementations
impl<'a> Add<&'a Polynomial> for &'a Polynomial
[src]
type Output = Polynomial
The resulting type after applying the +
operator.
fn add(self, rhs: Self) -> Self::Output
[src]
impl Add<Polynomial> for Polynomial
[src]
type Output = Self
The resulting type after applying the +
operator.
fn add(self, rhs: Self) -> Self::Output
[src]
impl Add<isize> for Polynomial
[src]
type Output = Self
The resulting type after applying the +
operator.
fn add(self, rhs: isize) -> Self::Output
[src]
impl<'a> Add<isize> for &'a Polynomial
[src]
type Output = Polynomial
The resulting type after applying the +
operator.
fn add(self, rhs: isize) -> Self::Output
[src]
impl<'a> AddAssign<&'a Polynomial> for Polynomial
[src]
fn add_assign(&mut self, rhs: &Self)
[src]
impl AddAssign<Polynomial> for Polynomial
[src]
fn add_assign(&mut self, rhs: Self)
[src]
impl AddAssign<isize> for Polynomial
[src]
fn add_assign(&mut self, rhs: isize)
[src]
impl Clone for Polynomial
[src]
fn clone(&self) -> Polynomial
[src]
pub fn clone_from(&mut self, source: &Self)
1.0.0[src]
impl Debug for Polynomial
[src]
impl Display for Polynomial
[src]
impl Eq for Polynomial
[src]
impl<'a> Mul<&'a Polynomial> for &'a Polynomial
[src]
type Output = Polynomial
The resulting type after applying the *
operator.
fn mul(self, rhs: Self) -> Self::Output
[src]
impl Mul<Polynomial> for Polynomial
[src]
type Output = Self
The resulting type after applying the *
operator.
fn mul(self, rhs: Self) -> Self::Output
[src]
impl Mul<isize> for Polynomial
[src]
type Output = Self
The resulting type after applying the *
operator.
fn mul(self, rhs: isize) -> Self::Output
[src]
impl<'a> Mul<isize> for &'a Polynomial
[src]
type Output = Polynomial
The resulting type after applying the *
operator.
fn mul(self, rhs: isize) -> Self::Output
[src]
impl<'a> MulAssign<&'a Polynomial> for Polynomial
[src]
fn mul_assign(&mut self, rhs: &Self)
[src]
impl MulAssign<Polynomial> for Polynomial
[src]
fn mul_assign(&mut self, rhs: Self)
[src]
impl MulAssign<isize> for Polynomial
[src]
fn mul_assign(&mut self, rhs: isize)
[src]
impl Neg for Polynomial
[src]
type Output = Self
The resulting type after applying the -
operator.
fn neg(self) -> Self::Output
[src]
impl Neg for &Polynomial
[src]
type Output = Polynomial
The resulting type after applying the -
operator.
fn neg(self) -> Self::Output
[src]
impl PartialEq<Polynomial> for Polynomial
[src]
fn eq(&self, other: &Polynomial) -> bool
[src]
fn ne(&self, other: &Polynomial) -> bool
[src]
impl Rem<isize> for Polynomial
[src]
type Output = Self
The resulting type after applying the %
operator.
fn rem(self, rhs: isize) -> Self::Output
[src]
impl<'a> Rem<isize> for &'a Polynomial
[src]
type Output = Polynomial
The resulting type after applying the %
operator.
fn rem(self, rhs: isize) -> Self::Output
[src]
impl RemAssign<isize> for Polynomial
[src]
fn rem_assign(&mut self, rhs: isize)
[src]
impl StructuralEq for Polynomial
[src]
impl StructuralPartialEq for Polynomial
[src]
impl<'a> Sub<&'a Polynomial> for &'a Polynomial
[src]
type Output = Polynomial
The resulting type after applying the -
operator.
fn sub(self, rhs: Self) -> Self::Output
[src]
impl Sub<Polynomial> for Polynomial
[src]
type Output = Self
The resulting type after applying the -
operator.
fn sub(self, rhs: Self) -> Self::Output
[src]
impl Sub<isize> for Polynomial
[src]
type Output = Self
The resulting type after applying the -
operator.
fn sub(self, rhs: isize) -> Self::Output
[src]
impl<'a> Sub<isize> for &'a Polynomial
[src]
type Output = Polynomial
The resulting type after applying the -
operator.
fn sub(self, rhs: isize) -> Self::Output
[src]
impl<'a> SubAssign<&'a Polynomial> for Polynomial
[src]
fn sub_assign(&mut self, rhs: &Self)
[src]
impl SubAssign<Polynomial> for Polynomial
[src]
fn sub_assign(&mut self, rhs: Self)
[src]
impl SubAssign<isize> for Polynomial
[src]
fn sub_assign(&mut self, rhs: isize)
[src]
Auto Trait Implementations
impl RefUnwindSafe for Polynomial
impl Send for Polynomial
impl Sync for Polynomial
impl Unpin for Polynomial
impl UnwindSafe for Polynomial
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,
pub fn borrow_mut(&mut self) -> &mut T
[src]
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.
pub fn to_owned(&self) -> T
[src]
pub fn clone_into(&self, target: &mut T)
[src]
impl<T> ToString for T where
T: Display + ?Sized,
[src]
T: Display + ?Sized,
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.
pub 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>,