Skip to main content

RationalPolynomial

Struct RationalPolynomial 

Source
pub struct RationalPolynomial<D, O = Grevlex>
where D: Domain, O: MonomialOrder,
{ 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, O> RationalPolynomial<D, O>
where D: Domain, O: MonomialOrder,

Source

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

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>, ) -> RationalPolynomial<D, O>

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

Source

pub fn zero(domain: &D, n_vars: usize) -> RationalPolynomial<D, O>

Return the zero rational polynomial in n_vars variables.

Source

pub fn one(domain: &D, n_vars: usize) -> RationalPolynomial<D, O>

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) -> RationalPolynomial<D, O>

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

Source

pub fn inv(&self) -> Option<RationalPolynomial<D, O>>

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

Returns None if the numerator is zero.

Source

pub fn pow(&self, k: u32) -> RationalPolynomial<D, O>

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

Source§

impl<D, O> RationalPolynomial<D, O>

Source

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

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: &RationalPolynomial<D, O>) -> RationalPolynomial<D, O>

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: &RationalPolynomial<D, O>) -> RationalPolynomial<D, O>

Subtract two rational polynomials.

Source

pub fn mul(&self, other: &RationalPolynomial<D, O>) -> RationalPolynomial<D, O>

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: &RationalPolynomial<D, O>, ) -> Option<RationalPolynomial<D, O>>

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

Trait Implementations§

Source§

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

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, O> Debug for RationalPolynomial<D, O>
where D: Debug + Domain, O: Debug + MonomialOrder,

Source§

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

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

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

Source§

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

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

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

Source§

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

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · 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<D, O> StructuralPartialEq for RationalPolynomial<D, O>

Auto Trait Implementations§

§

impl<D, O> Freeze for RationalPolynomial<D, O>
where D: 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,

§

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<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<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
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<SS, SP> SupersetOf<SS> for SP
where SS: SubsetOf<SP>,

Source§

fn to_subset(&self) -> Option<SS>

The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more
Source§

fn is_in_subset(&self) -> bool

Checks if self is actually part of its subset T (and can be converted to it).
Source§

unsafe fn to_subset_unchecked(&self) -> SS

Use with care! Same as self.to_subset but without any property checks. Always succeeds.
Source§

fn from_subset(element: &SS) -> SP

The inclusion map: converts self to the equivalent element of its superset.
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.