pub struct ShortlexIntegerPolynomialRef<'a>(pub &'a IntegerPolynomial);Expand description
ShortlexIntegerPolynomialRef is a wrapper around an IntegerPolynomial, taking the
IntegerPolynomial by reference.
See the ShortlexIntegerPolynomial documentation for details.
Tuple Fields§
§0: &'a IntegerPolynomialMethods 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<'a> Clone for ShortlexIntegerPolynomialRef<'a>
impl<'a> Clone for ShortlexIntegerPolynomialRef<'a>
Source§impl<'a> Debug for ShortlexIntegerPolynomialRef<'a>
impl<'a> Debug for ShortlexIntegerPolynomialRef<'a>
Source§impl Deref for ShortlexIntegerPolynomialRef<'_>
impl Deref for ShortlexIntegerPolynomialRef<'_>
Source§fn deref(&self) -> &IntegerPolynomial
fn deref(&self) -> &IntegerPolynomial
Allows a ShortlexIntegerPolynomialRef to dereference to an IntegerPolynomial.
use core::str::FromStr;
use malachite_nz::integer_polynomial::{IntegerPolynomial, ShortlexIntegerPolynomialRef};
let p = IntegerPolynomial::from_str("x^2-3*x+2").unwrap();
let x = ShortlexIntegerPolynomialRef(&p);
assert_eq!(*x, p);Source§type Target = IntegerPolynomial
type Target = IntegerPolynomial
impl<'a> Eq for ShortlexIntegerPolynomialRef<'a>
Source§impl<'a> Hash for ShortlexIntegerPolynomialRef<'a>
impl<'a> Hash for ShortlexIntegerPolynomialRef<'a>
Source§impl Ord for ShortlexIntegerPolynomialRef<'_>
impl Ord for ShortlexIntegerPolynomialRef<'_>
Source§fn cmp(&self, other: &Self) -> Ordering
fn cmp(&self, other: &Self) -> Ordering
Compares two ShortlexIntegerPolynomialRefs.
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. The zero polynomial, having no degree at
all, comes first. This is a total order, and its equality agrees with
IntegerPolynomial equality. It is the
order FLINT uses for polynomials, the one fmpq_poly_cmp implements.
Where the degrees differ this parts company with
IntegerPolynomial’s own Ord, which
compares polynomials by how they behave for large arguments and so lets a negative leading
coefficient send a high-degree polynomial to the bottom. Here degree decides outright, so
$-x^3 > x^2$ where the asymptotic order has $-x^3 < x^2$.
§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, ShortlexIntegerPolynomialRef};
let zero = IntegerPolynomial::from_str("0").unwrap();
let x_squared = IntegerPolynomial::from_str("x^2").unwrap();
let negative_x_cubed = IntegerPolynomial::from_str("-x^3").unwrap();
// The zero polynomial comes first.
assert!(ShortlexIntegerPolynomialRef(&zero) < ShortlexIntegerPolynomialRef(&x_squared));
// Degree decides, whatever the sign of the leading coefficient.
assert!(
ShortlexIntegerPolynomialRef(&x_squared)
< ShortlexIntegerPolynomialRef(&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<'a> PartialEq for ShortlexIntegerPolynomialRef<'a>
impl<'a> PartialEq for ShortlexIntegerPolynomialRef<'a>
Source§impl PartialOrd for ShortlexIntegerPolynomialRef<'_>
impl PartialOrd for ShortlexIntegerPolynomialRef<'_>
Source§fn partial_cmp(
&self,
other: &ShortlexIntegerPolynomialRef<'_>,
) -> Option<Ordering>
fn partial_cmp( &self, other: &ShortlexIntegerPolynomialRef<'_>, ) -> Option<Ordering>
Compares two ShortlexIntegerPolynomialRefs.
See the documentation for the Ord implementation.
impl<'a> StructuralPartialEq for ShortlexIntegerPolynomialRef<'a>
Auto Trait Implementations§
impl<'a> Freeze for ShortlexIntegerPolynomialRef<'a>
impl<'a> RefUnwindSafe for ShortlexIntegerPolynomialRef<'a>
impl<'a> Send for ShortlexIntegerPolynomialRef<'a>
impl<'a> Sync for ShortlexIntegerPolynomialRef<'a>
impl<'a> Unpin for ShortlexIntegerPolynomialRef<'a>
impl<'a> UnsafeUnpin for ShortlexIntegerPolynomialRef<'a>
impl<'a> UnwindSafe for ShortlexIntegerPolynomialRef<'a>
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