Skip to main content

RationalPolynomial

Struct RationalPolynomial 

Source
pub struct RationalPolynomial<D: Domain, O: MonomialOrder = Grevlex> {
    pub numerator: SparseMultivariatePolynomial<D, O>,
    pub denominator: SparseMultivariatePolynomial<D, O>,
}
Expand description

A rational polynomial $\frac{\text{num}}{\text{den}}$ over a domain D.

After construction via from_num_den, the fraction is always in canonical form:

  • numerator and denominator are coprime,
  • the denominator’s leading coefficient is positive (for ordered domains) or equal to 1 (for finite fields).

Fields§

§numerator: SparseMultivariatePolynomial<D, O>

The numerator polynomial.

§denominator: SparseMultivariatePolynomial<D, O>

The denominator polynomial (always non-zero).

Implementations§

Source§

impl<D: Domain, O: MonomialOrder> RationalPolynomial<D, O>

Source

pub fn new( numerator: SparseMultivariatePolynomial<D, O>, denominator: SparseMultivariatePolynomial<D, O>, ) -> Self

Create a rational polynomial without reduction.

The caller must ensure denominator is non-zero. For a canonicalized version use from_num_den.

Source

pub fn from_polynomial(poly: SparseMultivariatePolynomial<D, O>) -> Self

Create a rational polynomial from a polynomial (denominator = 1).

Source

pub fn zero(domain: &D, n_vars: usize) -> Self

Return the zero rational polynomial in n_vars variables.

Source

pub fn one(domain: &D, n_vars: usize) -> Self

Return the unit rational polynomial (1/1) in n_vars variables.

Source

pub fn is_zero(&self) -> bool

Return whether this is the zero rational polynomial.

Source

pub fn is_one(&self) -> bool

Return whether this is the unit rational polynomial (1/1).

Source

pub fn n_vars(&self) -> usize

Return the number of variables.

Source

pub fn domain(&self) -> &D

Return a reference to the coefficient domain.

Source

pub fn neg(&self) -> Self

Return the negation: $-\frac{n}{d}$.

Source

pub fn inv(&self) -> Option<Self>

Return the multiplicative inverse: $\frac{d}{n}$.

Returns None if the numerator is zero.

Source

pub fn pow(&self, k: u32) -> Self

Return the power $\left(\frac{n}{d}\right)^k$.

Source§

impl<D: EuclideanDomain, O: MonomialOrder> RationalPolynomial<D, O>

Source

pub fn from_num_den( numerator: SparseMultivariatePolynomial<D, O>, denominator: SparseMultivariatePolynomial<D, O>, ) -> Self

Create a canonicalized rational polynomial from numerator and denominator.

The result has coprime numerator and denominator, with the denominator’s leading coefficient normalized.

Source

pub fn add(&self, other: &Self) -> Self

Add two rational polynomials: $\frac{a}{b} + \frac{c}{d}$.

Uses the denominator-GCD strategy to minimize intermediate growth.

Source

pub fn sub(&self, other: &Self) -> Self

Subtract two rational polynomials.

Source

pub fn mul(&self, other: &Self) -> Self

Multiply two rational polynomials with cross-cancellation.

Computes $\gcd(a, d)$ and $\gcd(b, c)$ before multiplying to reduce intermediate coefficient growth.

Source

pub fn div(&self, other: &Self) -> Option<Self>

Divide two rational polynomials: $\frac{a/b}{c/d} = \frac{ad}{bc}$.

Trait Implementations§

Source§

impl<D: Clone + Domain, O: Clone + MonomialOrder> Clone for RationalPolynomial<D, O>

Source§

fn clone(&self) -> RationalPolynomial<D, O>

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<D: Debug + Domain, O: Debug + MonomialOrder> Debug for RationalPolynomial<D, O>

Source§

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

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

impl<D: Domain, O: MonomialOrder> Display for RationalPolynomial<D, O>
where D::Element: Display,

Source§

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

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

impl<D: Eq + Domain, O: Eq + MonomialOrder> Eq for RationalPolynomial<D, O>

Source§

impl<D: PartialEq + Domain, O: PartialEq + MonomialOrder> PartialEq for RationalPolynomial<D, O>

Source§

fn eq(&self, other: &RationalPolynomial<D, O>) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl<D: PartialEq + Domain, O: PartialEq + MonomialOrder> StructuralPartialEq for RationalPolynomial<D, O>

Auto Trait Implementations§

§

impl<D, O> Freeze for RationalPolynomial<D, O>
where D: Freeze, O: Freeze,

§

impl<D, O> RefUnwindSafe for RationalPolynomial<D, O>

§

impl<D, O> Send for RationalPolynomial<D, O>
where D: Send, O: Send, <D as Domain>::Element: Send,

§

impl<D, O> Sync for RationalPolynomial<D, O>
where D: Sync, O: Sync, <D as Domain>::Element: Sync,

§

impl<D, O> Unpin for RationalPolynomial<D, O>
where D: Unpin, O: Unpin, <D as Domain>::Element: Unpin,

§

impl<D, O> UnsafeUnpin for RationalPolynomial<D, O>
where D: UnsafeUnpin, O: UnsafeUnpin,

§

impl<D, O> UnwindSafe for RationalPolynomial<D, O>

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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V