Skip to main content

ShortlexIntegerPolynomial

Struct ShortlexIntegerPolynomial 

Source
pub struct ShortlexIntegerPolynomial(pub IntegerPolynomial);
Expand description

ShortlexIntegerPolynomial is a wrapper around an IntegerPolynomial, taking the IntegerPolynomial by value.

IntegerPolynomial is ordered by how its polynomials behave for large arguments, which is the order that respects their arithmetic. Sometimes a different order is wanted: one that puts the smaller polynomials first, whatever their signs, so that a list of them is enumerated from the simplest upward. Wrapping an IntegerPolynomial in a ShortlexIntegerPolynomial provides one: polynomials are compared first by degree and then, in case of a tie, by their coefficients from highest to lowest. This is a total order whose equality agrees with IntegerPolynomial equality; it is FLINT’s order for polynomials, the one fmpq_poly_cmp implements.

The difference from the Ord implementation on IntegerPolynomial is what happens when the degrees differ. There, a polynomial of higher degree dominates, so it is the greater one only if its leading coefficient is positive, and $-x^3 < x^2$. Here, degree decides outright, so $-x^3 > x^2$.

Neither order is a well-order. Ordering by degree first does not make one: $x > x - 1 > x - 2 > \ldots$ all have degree 1, so the chain descends forever under either order. No order that restricts to the usual order on the constant polynomials can be a well-order, since the Integers are not well-ordered.

ShortlexIntegerPolynomial owns its value. This is useful in many cases, for example if you want to use IntegerPolynomials as keys in a map. In other situations, it is better to use ShortlexIntegerPolynomialRef, which only has a reference to its value.

Tuple Fields§

§0: IntegerPolynomial

Implementations§

Source§

impl ShortlexIntegerPolynomial

Source

pub const fn as_ref(&self) -> ShortlexIntegerPolynomialRef<'_>

Borrows a ShortlexIntegerPolynomial as a ShortlexIntegerPolynomialRef.

§Worst-case complexity

Constant time and additional memory.

§Examples
use core::str::FromStr;
use malachite_nz::integer_polynomial::{
    IntegerPolynomial, ShortlexIntegerPolynomial, ShortlexIntegerPolynomialRef,
};

let p = IntegerPolynomial::from_str("x^2-3*x+2").unwrap();
let x = ShortlexIntegerPolynomial(p.clone());
assert_eq!(x.as_ref(), ShortlexIntegerPolynomialRef(&p));

Methods from Deref<Target = IntegerPolynomial>§

Source

pub fn coefficients_asc(&self) -> &[Integer]

Returns a reference to an IntegerPolynomial’s coefficients, in ascending order.

The first is the constant term and the last is the leading coefficient, so the slice is what from_coefficients_asc would take back. It holds no trailing zeros, and for the zero polynomial it is empty.

§Worst-case complexity

Constant time and additional memory.

§Examples
use core::str::FromStr;
use malachite_base::num::basic::traits::Zero;
use malachite_base::strings::ToDebugString;
use malachite_nz::integer_polynomial::IntegerPolynomial;

let p = IntegerPolynomial::from_str("x^2+3*x+2").unwrap();
assert_eq!(p.coefficients_asc().to_debug_string(), "[2, 3, 1]");
assert_eq!(
    IntegerPolynomial::ZERO.coefficients_asc().to_debug_string(),
    "[]"
);

Trait Implementations§

Source§

impl Clone for ShortlexIntegerPolynomial

Source§

fn clone(&self) -> Self

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

Source§

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

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

impl Default for ShortlexIntegerPolynomial

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl Deref for ShortlexIntegerPolynomial

Source§

fn deref(&self) -> &IntegerPolynomial

Allows a ShortlexIntegerPolynomial to dereference to an IntegerPolynomial.

use core::str::FromStr;
use malachite_nz::integer_polynomial::{IntegerPolynomial, ShortlexIntegerPolynomial};

let p = IntegerPolynomial::from_str("x^2-3*x+2").unwrap();
let x = ShortlexIntegerPolynomial(p.clone());
assert_eq!(*x, p);
Source§

type Target = IntegerPolynomial

The resulting type after dereferencing.
Source§

impl Eq for ShortlexIntegerPolynomial

Source§

impl Hash for ShortlexIntegerPolynomial

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 Ord for ShortlexIntegerPolynomial

Source§

fn cmp(&self, other: &Self) -> Ordering

Compares two ShortlexIntegerPolynomials.

The order is shortlex: the polynomials are compared first by degree, and then, in case of a tie, by their coefficients from highest to lowest. See the Ord implementation for ShortlexIntegerPolynomialRef for details.

§Worst-case complexity

$T(n) = O(n)$

$M(n) = O(1)$

where $T$ is time, $M$ is additional memory, and $n$ is the smaller of the two polynomials’ total number of bits, summed over their coefficients. Polynomials of different degrees are compared in constant time.

§Examples
use core::str::FromStr;
use malachite_nz::integer_polynomial::{IntegerPolynomial, ShortlexIntegerPolynomial};

let x_squared = IntegerPolynomial::from_str("x^2").unwrap();
let negative_x_cubed = IntegerPolynomial::from_str("-x^3").unwrap();

// Degree decides, whatever the sign of the leading coefficient.
assert!(ShortlexIntegerPolynomial(x_squared) < ShortlexIntegerPolynomial(negative_x_cubed));
1.21.0 (const: unstable) · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 (const: unstable) · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 (const: unstable) · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

fn clamp_to<R>(self, range: R) -> Self
where Self: Sized, R: ClampBounds<Self>,

🔬This is a nightly-only experimental API. (clamp_to)
Restrict a value to a certain range. Read more
Source§

impl PartialEq for ShortlexIntegerPolynomial

Source§

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

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

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

Inequality operator !=. Read more
Source§

impl PartialOrd for ShortlexIntegerPolynomial

Source§

fn partial_cmp(&self, other: &Self) -> Option<Ordering>

Compares two ShortlexIntegerPolynomials.

See the documentation for the Ord implementation.

1.0.0 (const: unstable) · Source§

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

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 (const: unstable) · Source§

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

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 (const: unstable) · Source§

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

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 (const: unstable) · Source§

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

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl StructuralPartialEq for ShortlexIntegerPolynomial

Auto Trait Implementations§

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<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<T, U> ExactFrom<T> for U
where U: TryFrom<T>,

Source§

fn exact_from(value: T) -> U

Source§

impl<T, U> ExactInto<U> for T
where U: ExactFrom<T>,

Source§

fn exact_into(self) -> U

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> ImaginaryInto<U> for T
where U: ImaginaryFrom<T>,

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, U> OverflowingInto<U> for T
where U: OverflowingFrom<T>,

Source§

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

Source§

impl<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
Source§

impl<T, U> RoundingInto<U> for T
where U: RoundingFrom<T>,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> SaturatingInto<U> for T
where U: SaturatingFrom<T>,

Source§

impl<T> ToDebugString for T
where T: Debug,

Source§

fn to_debug_string(&self) -> String

Returns the String produced by Ts Debug implementation.

§Examples
use malachite_base::strings::ToDebugString;

assert_eq!([1, 2, 3].to_debug_string(), "[1, 2, 3]");
assert_eq!(
    [vec![2, 3], vec![], vec![4]].to_debug_string(),
    "[[2, 3], [], [4]]"
);
assert_eq!(Some(5).to_debug_string(), "Some(5)");
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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

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

Source§

impl<T, U> WrappingInto<U> for T
where U: WrappingFrom<T>,

Source§

fn wrapping_into(self) -> U