Skip to main content

Poly

Struct Poly 

Source
pub struct Poly { /* private fields */ }
Expand description

A polynomial over ℚ: c[i] is the coefficient of xⁱ. INVARIANT: no trailing zero.

Implementations§

Source§

impl Poly

Source

pub fn zero() -> Poly

Source

pub fn one() -> Poly

Source

pub fn x() -> Poly

Source

pub fn constant(c: Rational) -> Poly

Source

pub fn from_coeffs(c: Vec<Rational>) -> Poly

From little-endian coefficients (c[i] multiplies xⁱ); trailing zeros are dropped.

Source

pub fn from_i64s(c: &[i64]) -> Poly

Source

pub fn from_bigints(c: &[BigInt]) -> Poly

Source

pub fn coeffs(&self) -> &[Rational]

Source

pub fn coeff(&self, i: usize) -> Rational

The coefficient of xⁱ (zero past the degree).

Source

pub fn degree(&self) -> Option<usize>

None for the zero polynomial.

Source

pub fn is_zero(&self) -> bool

Source

pub fn leading(&self) -> Option<&Rational>

Source

pub fn add(&self, o: &Poly) -> Poly

Source

pub fn sub(&self, o: &Poly) -> Poly

Source

pub fn neg(&self) -> Poly

Source

pub fn mul(&self, o: &Poly) -> Poly

Source

pub fn scale(&self, k: &Rational) -> Poly

Source

pub fn pow(&self, e: u32) -> Poly

Source

pub fn div_rem(&self, d: &Poly) -> Option<(Poly, Poly)>

Euclidean division over ℚ: self = q·d + r with deg r < deg d. None when d is zero.

Source

pub fn gcd(&self, o: &Poly) -> Poly

The monic greatest common divisor; gcd(0, 0) = 0.

Source

pub fn monic(&self) -> Poly

self divided by its leading coefficient; zero stays zero.

Source

pub fn derivative(&self) -> Poly

Source

pub fn eval(&self, x: &Rational) -> Rational

Horner evaluation at an exact rational point.

Source

pub fn compose(&self, inner: &Poly) -> Poly

self(inner(x)).

Source

pub fn reverse(&self) -> Poly

x^deg · self(1/x): the polynomial whose roots are the reciprocals of the nonzero roots.

Source

pub fn neg_var(&self) -> Poly

self(−x): the polynomial whose roots are the negated roots.

Source

pub fn squarefree_part(&self) -> Poly

The monic polynomial with the same roots, each once: self / gcd(self, self′).

Source

pub fn primitive_int(&self) -> Vec<BigInt>

The integer polynomial with the same roots: denominators cleared, content divided out, leading coefficient positive. Empty for the zero polynomial.

Source

pub fn root_bound(&self) -> Rational

Cauchy’s bound 1 + max |aᵢ/aₙ|: every complex root lies strictly inside it.

Source

pub fn count_real_roots(&self) -> usize

The number of distinct real roots.

Source

pub fn count_real_roots_in(&self, lo: &Rational, hi: &Rational) -> usize

The number of distinct real roots in the half-open interval (lo, hi].

Source

pub fn isolate_real_roots(&self) -> Vec<RootInterval>

Every distinct real root, isolated, in increasing order.

Source

pub fn refine(&self, iv: &RootInterval) -> RootInterval

Halve an isolating interval of one of self’s roots, keeping the root inside. An exact root stays as it is; a midpoint that is the root becomes the exact interval.

Source

pub fn resultant(&self, o: &Poly) -> Rational

The resultant lc(self)^{deg o} · ∏ o(α) over the roots α of self; zero exactly when the two share a root, and zero when either is the zero polynomial.

Source

pub fn factor_over_q(&self) -> Vec<(Poly, u32)>

The factorization over ℚ into irreducible primitive integer polynomials (positive leading coefficient) with multiplicities, in Poly::canonical_order. The constant content is dropped; a constant or zero polynomial has no factors.

Source

pub fn is_irreducible(&self) -> bool

Irreducible over ℚ: positive degree and no proper factorization.

Source

pub fn canonical_order(a: &Poly, b: &Poly) -> Ordering

The total order factors are listed in: by degree, then by coefficients from the highest power down.

Trait Implementations§

Source§

impl Clone for Poly

Source§

fn clone(&self) -> Poly

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 Debug for Poly

Source§

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

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

impl Display for Poly

Source§

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

Descending powers: x^3 - x - 1, -x^2 + 1, x^2 - (1/3)x + 1/2.

Source§

impl ExactCodec for Poly

Source§

fn write(&self, out: &mut Vec<u8>)

The coefficients, lowest power first.

Source§

fn read(buf: &[u8], pos: &mut usize) -> Option<Self>

Source§

fn to_bytes(&self) -> Vec<u8> ⓘ

Source§

fn from_bytes(buf: &[u8]) -> Option<Self>

The value buf canonically encodes, with nothing left over.
Source§

impl Hash for Poly

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl PartialEq for Poly

Source§

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

Tests for self and other values to be equal, and is used by ==.
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 Eq for Poly

Source§

impl StructuralPartialEq for Poly

Auto Trait Implementations§

§

impl Freeze for Poly

§

impl RefUnwindSafe for Poly

§

impl Send for Poly

§

impl Sync for Poly

§

impl Unpin for Poly

§

impl UnsafeUnpin for Poly

§

impl UnwindSafe for Poly

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.