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: IntegerPolynomialImplementations§
Source§impl ShortlexIntegerPolynomial
impl ShortlexIntegerPolynomial
Sourcepub const fn as_ref(&self) -> ShortlexIntegerPolynomialRef<'_>
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>§
Sourcepub fn coefficients_asc(&self) -> &[Integer]
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
impl Clone for ShortlexIntegerPolynomial
Source§impl Debug for ShortlexIntegerPolynomial
impl Debug for ShortlexIntegerPolynomial
Source§impl Default for ShortlexIntegerPolynomial
impl Default for ShortlexIntegerPolynomial
Source§impl Deref for ShortlexIntegerPolynomial
impl Deref for ShortlexIntegerPolynomial
Source§fn deref(&self) -> &IntegerPolynomial
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
type Target = IntegerPolynomial
impl Eq for ShortlexIntegerPolynomial
Source§impl Hash for ShortlexIntegerPolynomial
impl Hash for ShortlexIntegerPolynomial
Source§impl Ord for ShortlexIntegerPolynomial
impl Ord for ShortlexIntegerPolynomial
Source§fn cmp(&self, other: &Self) -> Ordering
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) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
1.21.0 (const: unstable) · Source§fn min(self, other: Self) -> Selfwhere
Self: Sized,
fn min(self, other: Self) -> Selfwhere
Self: Sized,
Source§impl PartialOrd for ShortlexIntegerPolynomial
impl PartialOrd for ShortlexIntegerPolynomial
Source§fn partial_cmp(&self, other: &Self) -> Option<Ordering>
fn partial_cmp(&self, other: &Self) -> Option<Ordering>
Compares two ShortlexIntegerPolynomials.
See the documentation for the Ord implementation.
impl StructuralPartialEq for ShortlexIntegerPolynomial
Auto Trait Implementations§
impl Freeze for ShortlexIntegerPolynomial
impl RefUnwindSafe for ShortlexIntegerPolynomial
impl Send for ShortlexIntegerPolynomial
impl Sync for ShortlexIntegerPolynomial
impl Unpin for ShortlexIntegerPolynomial
impl UnsafeUnpin for ShortlexIntegerPolynomial
impl UnwindSafe for ShortlexIntegerPolynomial
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<T, U> ImaginaryInto<U> for Twhere
U: ImaginaryFrom<T>,
impl<T, U> ImaginaryInto<U> for Twhere
U: ImaginaryFrom<T>,
fn imaginary_into(self) -> U
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
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