pub struct UnsignedPolynomial<T: PrimitiveUnsigned> { /* private fields */ }Expand description
A polynomial in one variable whose coefficients are unsigned primitive integers.
The coefficients are held in ascending order, so that the coefficient of $x^i$ is the one at
index $i$, and the last is the leading one. Trailing zero coefficients are not held at all: the
zero polynomial has no coefficients, and every other polynomial’s last coefficient is nonzero.
That is what makes a polynomial’s representation unique, and so what lets Eq be derived.
The field is private, since not every Vec of Ts is one:
from_coefficients_asc is how a Vec becomes
one.
Implementations§
Source§impl<T: PrimitiveUnsigned> UnsignedPolynomial<T>
impl<T: PrimitiveUnsigned> UnsignedPolynomial<T>
Sourcepub fn coefficients_asc(&self) -> &[T]
pub fn coefficients_asc(&self) -> &[T]
Returns a reference to a UnsignedPolynomial’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_base::unsigned_polynomial::UnsignedPolynomial;
let p = UnsignedPolynomial::<u64>::from_str("x^2+3*x+2").unwrap();
assert_eq!(p.coefficients_asc().to_debug_string(), "[2, 3, 1]");
assert_eq!(
UnsignedPolynomial::<u64>::ZERO
.coefficients_asc()
.to_debug_string(),
"[]"
);Trait Implementations§
Source§impl<T: PrimitiveUnsigned> CanonicalizeUnit for UnsignedPolynomial<T>
impl<T: PrimitiveUnsigned> CanonicalizeUnit for UnsignedPolynomial<T>
Source§fn canonicalize_unit(self) -> Self
fn canonicalize_unit(self) -> Self
Brings an UnsignedPolynomial into canonical unit form, taking it by value.
The coefficients are non-negative, so the leading coefficient already is, and the polynomial is its own canonical associate: this is the identity, as it is for the coefficient type.
§Worst-case complexity
Constant time and additional memory.
§Examples
use core::str::FromStr;
use malachite_base::num::arithmetic::traits::CanonicalizeUnit;
use malachite_base::num::basic::traits::Zero;
use malachite_base::unsigned_polynomial::UnsignedPolynomial;
assert_eq!(
UnsignedPolynomial::<u8>::from_str("3*x^2+2")
.unwrap()
.canonicalize_unit()
.to_string(),
"3*x^2+2"
);
assert_eq!(
UnsignedPolynomial::<u8>::ZERO.canonicalize_unit(),
UnsignedPolynomial::<u8>::ZERO
);type Output = UnsignedPolynomial<T>
Source§impl<T: PrimitiveUnsigned> CanonicalizeUnit for &UnsignedPolynomial<T>
impl<T: PrimitiveUnsigned> CanonicalizeUnit for &UnsignedPolynomial<T>
Source§fn canonicalize_unit(self) -> UnsignedPolynomial<T>
fn canonicalize_unit(self) -> UnsignedPolynomial<T>
Brings an UnsignedPolynomial into canonical unit form, taking it by reference.
The coefficients are non-negative, so the leading coefficient already is, and the polynomial is its own canonical associate: this is the identity, as it is for the coefficient type.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is the total size of the coefficients.
§Examples
use core::str::FromStr;
use malachite_base::num::arithmetic::traits::CanonicalizeUnit;
use malachite_base::num::basic::traits::Zero;
use malachite_base::unsigned_polynomial::UnsignedPolynomial;
assert_eq!(
(&UnsignedPolynomial::<u8>::from_str("3*x^2+2").unwrap())
.canonicalize_unit()
.to_string(),
"3*x^2+2"
);
assert_eq!(
(&UnsignedPolynomial::<u8>::ZERO).canonicalize_unit(),
UnsignedPolynomial::<u8>::ZERO
);type Output = UnsignedPolynomial<T>
Source§impl<T: PrimitiveUnsigned> CanonicalizeUnitAssign for UnsignedPolynomial<T>
impl<T: PrimitiveUnsigned> CanonicalizeUnitAssign for UnsignedPolynomial<T>
Source§fn canonicalize_unit_assign(&mut self)
fn canonicalize_unit_assign(&mut self)
Brings an UnsignedPolynomial into canonical unit form, in place.
See canonicalize_unit.
§Worst-case complexity
Constant time and additional memory.
§Examples
use core::str::FromStr;
use malachite_base::num::arithmetic::traits::CanonicalizeUnitAssign;
use malachite_base::unsigned_polynomial::UnsignedPolynomial;
let mut p = UnsignedPolynomial::<u8>::from_str("3*x^2+2").unwrap();
p.canonicalize_unit_assign();
assert_eq!(p.to_string(), "3*x^2+2");Source§impl<T: Clone + PrimitiveUnsigned> Clone for UnsignedPolynomial<T>
impl<T: Clone + PrimitiveUnsigned> Clone for UnsignedPolynomial<T>
Source§impl<T: PrimitiveUnsigned> ComposePowerOfX for UnsignedPolynomial<T>
impl<T: PrimitiveUnsigned> ComposePowerOfX for UnsignedPolynomial<T>
Source§fn compose_power_of_x(self, k: u64) -> Self
fn compose_power_of_x(self, k: u64) -> Self
Composes an UnsignedPolynomial with $x^k$, giving $p(x^k)$, taking it by value. The
coefficient of $x^i$ moves to $x^{ik}$, and zeros fill the places in between.
$$ f(p, k) = p(x^k). $$
When $k$ is 0 the result is the constant $p(1)$, the sum of the coefficients; when $k$ is 1, or the polynomial is constant, nothing changes.
§Worst-case complexity
$T(m, k) = O(mk)$
$M(m, k) = O(mk)$
where $T$ is time, $M$ is additional memory, $k$ is k, and $m$ is self.len().
§Panics
Panics if the degree of the result is greater than usize::MAX, or if k is 0 and the sum
of the coefficients overflows T.
§Examples
use core::str::FromStr;
use malachite_base::polynomial::ComposePowerOfX;
use malachite_base::unsigned_polynomial::UnsignedPolynomial;
let p = UnsignedPolynomial::<u8>::from_str("x^2+3*x+2").unwrap();
assert_eq!(p.compose_power_of_x(2).to_string(), "x^4+3*x^2+2");
// With k = 0, this is p(1).
let p = UnsignedPolynomial::<u8>::from_str("x^2+3*x+2").unwrap();
assert_eq!(p.compose_power_of_x(0).to_string(), "6");This is equivalent to nmod_poly_inflate from nmod_poly/inflate.c, FLINT 3.6.0.
type Output = UnsignedPolynomial<T>
Source§impl<T: PrimitiveUnsigned> ComposePowerOfX for &UnsignedPolynomial<T>
impl<T: PrimitiveUnsigned> ComposePowerOfX for &UnsignedPolynomial<T>
Source§fn compose_power_of_x(self, k: u64) -> UnsignedPolynomial<T>
fn compose_power_of_x(self, k: u64) -> UnsignedPolynomial<T>
Composes an UnsignedPolynomial with $x^k$, giving $p(x^k)$, taking it by reference. The
coefficient of $x^i$ moves to $x^{ik}$, and zeros fill the places in between.
$$ f(p, k) = p(x^k). $$
When $k$ is 0 the result is the constant $p(1)$, the sum of the coefficients; when $k$ is 1, or the polynomial is constant, nothing changes.
§Worst-case complexity
$T(m, k) = O(mk)$
$M(m, k) = O(mk)$
where $T$ is time, $M$ is additional memory, $k$ is k, and $m$ is self.len().
§Panics
Panics if the degree of the result is greater than usize::MAX, or if k is 0 and the sum
of the coefficients overflows T.
§Examples
use core::str::FromStr;
use malachite_base::polynomial::ComposePowerOfX;
use malachite_base::unsigned_polynomial::UnsignedPolynomial;
let p = UnsignedPolynomial::<u8>::from_str("x^2+3*x+2").unwrap();
assert_eq!((&p).compose_power_of_x(2).to_string(), "x^4+3*x^2+2");
// With k = 0, this is p(1).
let p = UnsignedPolynomial::<u8>::from_str("x^2+3*x+2").unwrap();
assert_eq!((&p).compose_power_of_x(0).to_string(), "6");This is equivalent to nmod_poly_inflate from nmod_poly/inflate.c, FLINT 3.6.0.
type Output = UnsignedPolynomial<T>
Source§impl<T: PrimitiveUnsigned> ComposePowerOfXAssign for UnsignedPolynomial<T>
impl<T: PrimitiveUnsigned> ComposePowerOfXAssign for UnsignedPolynomial<T>
Source§fn compose_power_of_x_assign(&mut self, k: u64)
fn compose_power_of_x_assign(&mut self, k: u64)
Composes an UnsignedPolynomial with $x^k$ in place, replacing $p$ with $p(x^k)$. The
coefficient of $x^i$ moves to $x^{ik}$, and zeros fill the places in between.
$$ p \gets p(x^k). $$
When $k$ is 0 the result is the constant $p(1)$, the sum of the coefficients; when $k$ is 1, or the polynomial is constant, nothing changes.
§Worst-case complexity
$T(m, k) = O(mk)$
$M(m, k) = O(mk)$
where $T$ is time, $M$ is additional memory, $k$ is k, and $m$ is self.len().
§Panics
Panics if the degree of the result is greater than usize::MAX, or if k is 0 and the sum
of the coefficients overflows T.
§Examples
use core::str::FromStr;
use malachite_base::polynomial::ComposePowerOfXAssign;
use malachite_base::unsigned_polynomial::UnsignedPolynomial;
let mut p = UnsignedPolynomial::<u8>::from_str("x^2+3*x+2").unwrap();
p.compose_power_of_x_assign(2);
assert_eq!(p.to_string(), "x^4+3*x^2+2");
// With k = 0, this is p(1).
let mut p = UnsignedPolynomial::<u8>::from_str("x^2+3*x+2").unwrap();
p.compose_power_of_x_assign(0);
assert_eq!(p.to_string(), "6");This is equivalent to nmod_poly_inflate from nmod_poly/inflate.c, FLINT 3.6.0.
Source§impl<T: PrimitiveUnsigned> Content for UnsignedPolynomial<T>
impl<T: PrimitiveUnsigned> Content for UnsignedPolynomial<T>
Source§fn content(self) -> T
fn content(self) -> T
Computes the content of an UnsignedPolynomial, the GCD of its coefficients, taking the
polynomial by value.
The content of the zero polynomial is zero. The GCD is taken coefficient by coefficient, stopping early once it reaches 1.
$$ f(p) = \gcd(c_0, c_1, \ldots, c_{n-1}), $$
where $c_i$ is the coefficient of $x^i$ in $p$ and $n$ is its length.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is self.len().
§Examples
use core::str::FromStr;
use malachite_base::num::basic::traits::Zero;
use malachite_base::polynomial::Content;
use malachite_base::unsigned_polynomial::UnsignedPolynomial;
let p = UnsignedPolynomial::<u8>::from_str("6*x^2+4*x+10").unwrap();
assert_eq!(p.clone().content(), 2);
assert_eq!(UnsignedPolynomial::<u8>::ZERO.content(), 0);This is equivalent to fmpz_poly_content from fmpz_poly/content.c, FLINT 3.6.0.
Source§impl<T: PrimitiveUnsigned> Content for &UnsignedPolynomial<T>
impl<T: PrimitiveUnsigned> Content for &UnsignedPolynomial<T>
Source§fn content(self) -> T
fn content(self) -> T
Computes the content of an UnsignedPolynomial, the GCD of its coefficients, taking the
polynomial by reference.
The content of the zero polynomial is zero. The GCD is taken coefficient by coefficient, stopping early once it reaches 1.
$$ f(p) = \gcd(c_0, c_1, \ldots, c_{n-1}), $$
where $c_i$ is the coefficient of $x^i$ in $p$ and $n$ is its length.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is self.len().
§Examples
use core::str::FromStr;
use malachite_base::num::basic::traits::Zero;
use malachite_base::polynomial::Content;
use malachite_base::unsigned_polynomial::UnsignedPolynomial;
let p = UnsignedPolynomial::<u8>::from_str("6*x^2+4*x+10").unwrap();
assert_eq!((&p).content(), 2);
assert_eq!((&UnsignedPolynomial::<u8>::ZERO).content(), 0);This is equivalent to fmpz_poly_content from fmpz_poly/content.c, FLINT 3.6.0.
Source§impl<T: PrimitiveUnsigned> ContentAndPrimitivePart for UnsignedPolynomial<T>
impl<T: PrimitiveUnsigned> ContentAndPrimitivePart for UnsignedPolynomial<T>
Source§fn content_and_primitive_part(self) -> (T, Self)
fn content_and_primitive_part(self) -> (T, Self)
Computes the content and the primitive part of an UnsignedPolynomial together, taking
the polynomial by value.
See content and primitive_part; the
content is found once rather than twice.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is self.len().
§Examples
use core::str::FromStr;
use malachite_base::polynomial::ContentAndPrimitivePart;
use malachite_base::unsigned_polynomial::UnsignedPolynomial;
let p = UnsignedPolynomial::<u8>::from_str("6*x^2+4*x+10").unwrap();
let (content, primitive_part) = p.clone().content_and_primitive_part();
assert_eq!(content, 2);
assert_eq!(primitive_part.to_string(), "3*x^2+2*x+5");Source§type PrimitivePart = UnsignedPolynomial<T>
type PrimitivePart = UnsignedPolynomial<T>
Source§impl<T: PrimitiveUnsigned> ContentAndPrimitivePart for &UnsignedPolynomial<T>
impl<T: PrimitiveUnsigned> ContentAndPrimitivePart for &UnsignedPolynomial<T>
Source§fn content_and_primitive_part(self) -> (T, UnsignedPolynomial<T>)
fn content_and_primitive_part(self) -> (T, UnsignedPolynomial<T>)
Computes the content and the primitive part of an UnsignedPolynomial together, taking
the polynomial by reference.
See content and primitive_part; the
content is found once rather than twice.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is self.len().
§Examples
use core::str::FromStr;
use malachite_base::polynomial::ContentAndPrimitivePart;
use malachite_base::unsigned_polynomial::UnsignedPolynomial;
let p = UnsignedPolynomial::<u8>::from_str("6*x^2+4*x+10").unwrap();
let (content, primitive_part) = (&p).content_and_primitive_part();
assert_eq!(content, 2);
assert_eq!(primitive_part.to_string(), "3*x^2+2*x+5");Source§type PrimitivePart = UnsignedPolynomial<T>
type PrimitivePart = UnsignedPolynomial<T>
Source§impl<T: PrimitiveUnsigned> Debug for UnsignedPolynomial<T>
impl<T: PrimitiveUnsigned> Debug for UnsignedPolynomial<T>
Source§fn fmt(&self, f: &mut Formatter<'_>) -> Result
fn fmt(&self, f: &mut Formatter<'_>) -> Result
Converts an UnsignedPolynomial to a String.
This is the same as the Display::fmt implementation, so that a collection of
UnsignedPolynomials is written the same way its elements are displayed.
§Worst-case complexity
$T(n) = O(n \log n \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, and $n$ is the sum of the bits of the coefficients.
§Examples
use core::str::FromStr;
use malachite_base::strings::ToDebugString;
use malachite_base::unsigned_polynomial::UnsignedPolynomial;
let xs = vec![
UnsignedPolynomial::<u8>::from_str("x^2+3*x+2").unwrap(),
UnsignedPolynomial::<u8>::from_str("0").unwrap(),
UnsignedPolynomial::<u8>::from_str("5").unwrap(),
];
assert_eq!(xs[0].to_debug_string(), "x^2+3*x+2");
assert_eq!(xs[1].to_debug_string(), "0");
assert_eq!(xs[2].to_debug_string(), "5");
assert_eq!(xs.to_debug_string(), "[x^2+3*x+2, 0, 5]");Source§impl<T: Default + PrimitiveUnsigned> Default for UnsignedPolynomial<T>
impl<T: Default + PrimitiveUnsigned> Default for UnsignedPolynomial<T>
Source§impl<T: PrimitiveUnsigned> DeflatePowerOfX for UnsignedPolynomial<T>
impl<T: PrimitiveUnsigned> DeflatePowerOfX for UnsignedPolynomial<T>
Source§fn deflate_power_of_x(self, n: u64) -> Self
fn deflate_power_of_x(self, n: u64) -> Self
Deflates an UnsignedPolynomial by $n$, taking it by value, giving the polynomial $q$
with $q(x^n) = p(x)$. The coefficient of $x^{in}$ moves to $x^i$.
$$ f(p, n) = q, \quad \text{where} \quad q(x^n) = p(x). $$
A constant polynomial deflates to itself, and deflating by 1 changes nothing.
§Worst-case complexity
$T(m) = O(m)$
$M(m) = O(1)$
where $T$ is time, $M$ is additional memory, and $m$ is self.len().
§Panics
Panics if n is 0, or if the polynomial has a nonzero coefficient at an exponent that is
not a multiple of n.
§Examples
use core::str::FromStr;
use malachite_base::polynomial::DeflatePowerOfX;
use malachite_base::unsigned_polynomial::UnsignedPolynomial;
let p = UnsignedPolynomial::<u8>::from_str("x^6+2*x^3+1").unwrap();
assert_eq!(p.deflate_power_of_x(3).to_string(), "x^2+2*x+1");This is equivalent to nmod_poly_deflate from nmod_poly/deflate.c, FLINT 3.6.0, except
that it panics rather than dropping the coefficients at other exponents.
type Output = UnsignedPolynomial<T>
Source§impl<T: PrimitiveUnsigned> DeflatePowerOfX for &UnsignedPolynomial<T>
impl<T: PrimitiveUnsigned> DeflatePowerOfX for &UnsignedPolynomial<T>
Source§fn deflate_power_of_x(self, n: u64) -> UnsignedPolynomial<T>
fn deflate_power_of_x(self, n: u64) -> UnsignedPolynomial<T>
Deflates an UnsignedPolynomial by $n$, taking it by reference, giving the polynomial $q$
with $q(x^n) = p(x)$. The coefficient of $x^{in}$ moves to $x^i$.
$$ f(p, n) = q, \quad \text{where} \quad q(x^n) = p(x). $$
A constant polynomial deflates to itself, and deflating by 1 changes nothing.
§Worst-case complexity
$T(m) = O(m)$
$M(m) = O(m)$
where $T$ is time, $M$ is additional memory, and $m$ is self.len().
§Panics
Panics if n is 0, or if the polynomial has a nonzero coefficient at an exponent that is
not a multiple of n.
§Examples
use core::str::FromStr;
use malachite_base::polynomial::DeflatePowerOfX;
use malachite_base::unsigned_polynomial::UnsignedPolynomial;
let p = UnsignedPolynomial::<u8>::from_str("x^6+2*x^3+1").unwrap();
assert_eq!((&p).deflate_power_of_x(3).to_string(), "x^2+2*x+1");This is equivalent to nmod_poly_deflate from nmod_poly/deflate.c, FLINT 3.6.0, except
that it panics rather than dropping the coefficients at other exponents.
type Output = UnsignedPolynomial<T>
Source§impl<T: PrimitiveUnsigned> DeflatePowerOfXAssign for UnsignedPolynomial<T>
impl<T: PrimitiveUnsigned> DeflatePowerOfXAssign for UnsignedPolynomial<T>
Source§fn deflate_power_of_x_assign(&mut self, n: u64)
fn deflate_power_of_x_assign(&mut self, n: u64)
Deflates an UnsignedPolynomial by $n$ in place, replacing $p$ with the polynomial $q$
such that $q(x^n) = p(x)$. The coefficient of $x^{in}$ moves to $x^i$.
$$ p \gets q, \quad \text{where} \quad q(x^n) = p(x). $$
A constant polynomial deflates to itself, and deflating by 1 changes nothing.
§Worst-case complexity
$T(m) = O(m)$
$M(m) = O(1)$
where $T$ is time, $M$ is additional memory, and $m$ is self.len().
§Panics
Panics if n is 0, or if the polynomial has a nonzero coefficient at an exponent that is
not a multiple of n.
§Examples
use core::str::FromStr;
use malachite_base::polynomial::DeflatePowerOfXAssign;
use malachite_base::unsigned_polynomial::UnsignedPolynomial;
let mut p = UnsignedPolynomial::<u8>::from_str("x^6+2*x^3+1").unwrap();
p.deflate_power_of_x_assign(3);
assert_eq!(p.to_string(), "x^2+2*x+1");This is equivalent to nmod_poly_deflate from nmod_poly/deflate.c, FLINT 3.6.0, except
that it panics rather than dropping the coefficients at other exponents.
Source§impl<T: PrimitiveUnsigned> Display for UnsignedPolynomial<T>
impl<T: PrimitiveUnsigned> Display for UnsignedPolynomial<T>
Source§fn fmt(&self, f: &mut Formatter<'_>) -> Result
fn fmt(&self, f: &mut Formatter<'_>) -> Result
Converts a UnsignedPolynomial to a String.
The variable is called x.
to_string_with is the way to call it
something else.
The terms are written in order of decreasing degree and joined with +. A term is its
coefficient, then *, then the variable, then ^ and the exponent; but a coefficient of 1
is left off along with its *, an exponent of 1 is left off along with its ^, and the
constant term is its coefficient alone. The zero polynomial, which has no terms at all, is
0.
The syntax is the one Azurite writes polynomials in,
and holds no characters that char_is_reserved allows in a
variable’s name, so a polynomial can be read back whatever its variable is called.
§Worst-case complexity
$T(n) = O(n \log n \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, and $n$ is the sum of the bits of the coefficients.
§Examples
use core::str::FromStr;
use malachite_base::unsigned_polynomial::UnsignedPolynomial;
assert_eq!(
UnsignedPolynomial::<u64>::from_str("x^2+3*x+2")
.unwrap()
.to_string(),
"x^2+3*x+2"
);
assert_eq!(
UnsignedPolynomial::<u64>::from_str("0")
.unwrap()
.to_string(),
"0"
);
assert_eq!(
UnsignedPolynomial::<u64>::from_str("5")
.unwrap()
.to_string(),
"5"
);
assert_eq!(
UnsignedPolynomial::<u64>::from_str("x")
.unwrap()
.to_string(),
"x"
);
assert_eq!(
UnsignedPolynomial::<u64>::from_str("2*x^3")
.unwrap()
.to_string(),
"2*x^3"
);
// The terms come out in decreasing degree, whatever order they went in, and an exponent
// of 1 is left off.
assert_eq!(
UnsignedPolynomial::<u64>::from_str("2+3*x+x^2")
.unwrap()
.to_string(),
"x^2+3*x+2"
);
assert_eq!(
UnsignedPolynomial::<u64>::from_str("x^1")
.unwrap()
.to_string(),
"x"
);Source§impl<T: PrimitiveUnsigned> DivPowerOfX for UnsignedPolynomial<T>
impl<T: PrimitiveUnsigned> DivPowerOfX for UnsignedPolynomial<T>
Source§fn div_power_of_x(self, n: u64) -> Self
fn div_power_of_x(self, n: u64) -> Self
Divides an UnsignedPolynomial by $x^n$, discarding the remainder, taking it by value.
Every coefficient moves down by $n$ places, and the lowest $n$ are dropped.
$$ f(p, n) = \sum_{i \geq n} p_ix^{i-n}. $$
The result is zero when $n$ is at least the number of coefficients, and dividing by $x^0$ changes nothing. Multiplying the result by $x^n$ and adding back the dropped low part, the truncation to $n$ coefficients, gives the polynomial back.
§Worst-case complexity
$T(m) = O(m)$
$M(m) = O(1)$
where $T$ is time, $M$ is additional memory, and $m$ is self.len().
§Examples
use core::str::FromStr;
use malachite_base::num::basic::traits::Zero;
use malachite_base::polynomial::DivPowerOfX;
use malachite_base::unsigned_polynomial::UnsignedPolynomial;
let p = UnsignedPolynomial::<u8>::from_str("x^3+3*x^2+2*x+5").unwrap();
assert_eq!(p.div_power_of_x(2).to_string(), "x+3");
let p = UnsignedPolynomial::<u8>::from_str("5*x").unwrap();
assert_eq!(p.div_power_of_x(1).to_string(), "5");
let p = UnsignedPolynomial::<u8>::from_str("x^3+3*x^2+2*x+5").unwrap();
assert_eq!(p.div_power_of_x(10), UnsignedPolynomial::<u8>::ZERO);This is equivalent to nmod_poly_shift_right from nmod_poly/shift_right.c, FLINT 3.6.0.
type Output = UnsignedPolynomial<T>
Source§impl<T: PrimitiveUnsigned> DivPowerOfX for &UnsignedPolynomial<T>
impl<T: PrimitiveUnsigned> DivPowerOfX for &UnsignedPolynomial<T>
Source§fn div_power_of_x(self, n: u64) -> UnsignedPolynomial<T>
fn div_power_of_x(self, n: u64) -> UnsignedPolynomial<T>
Divides an UnsignedPolynomial by $x^n$, discarding the remainder, taking it by
reference. Every coefficient moves down by $n$ places, and the lowest $n$ are dropped.
$$ f(p, n) = \sum_{i \geq n} p_ix^{i-n}. $$
The result is zero when $n$ is at least the number of coefficients, and dividing by $x^0$ changes nothing. Multiplying the result by $x^n$ and adding back the dropped low part, the truncation to $n$ coefficients, gives the polynomial back.
§Worst-case complexity
$T(m) = O(m)$
$M(m) = O(m)$
where $T$ is time, $M$ is additional memory, and $m$ is self.len().
§Examples
use core::str::FromStr;
use malachite_base::num::basic::traits::Zero;
use malachite_base::polynomial::DivPowerOfX;
use malachite_base::unsigned_polynomial::UnsignedPolynomial;
let p = UnsignedPolynomial::<u8>::from_str("x^3+3*x^2+2*x+5").unwrap();
assert_eq!((&p).div_power_of_x(2).to_string(), "x+3");
let p = UnsignedPolynomial::<u8>::from_str("5*x").unwrap();
assert_eq!((&p).div_power_of_x(1).to_string(), "5");
let p = UnsignedPolynomial::<u8>::from_str("x^3+3*x^2+2*x+5").unwrap();
assert_eq!((&p).div_power_of_x(10), UnsignedPolynomial::<u8>::ZERO);This is equivalent to nmod_poly_shift_right from nmod_poly/shift_right.c, FLINT 3.6.0.
type Output = UnsignedPolynomial<T>
Source§impl<T: PrimitiveUnsigned> DivPowerOfXAssign for UnsignedPolynomial<T>
impl<T: PrimitiveUnsigned> DivPowerOfXAssign for UnsignedPolynomial<T>
Source§fn div_power_of_x_assign(&mut self, n: u64)
fn div_power_of_x_assign(&mut self, n: u64)
Divides an UnsignedPolynomial by $x^n$ in place, discarding the remainder. Every
coefficient moves down by $n$ places, and the lowest $n$ are dropped.
$$ p \gets \sum_{i \geq n} p_ix^{i-n}. $$
The result is zero when $n$ is at least the number of coefficients, and dividing by $x^0$ changes nothing. Multiplying the result by $x^n$ and adding back the dropped low part, the truncation to $n$ coefficients, gives the polynomial back.
§Worst-case complexity
$T(m) = O(m)$
$M(m) = O(1)$
where $T$ is time, $M$ is additional memory, and $m$ is self.len().
§Examples
use core::str::FromStr;
use malachite_base::num::basic::traits::Zero;
use malachite_base::polynomial::DivPowerOfXAssign;
use malachite_base::unsigned_polynomial::UnsignedPolynomial;
let mut p = UnsignedPolynomial::<u8>::from_str("x^3+3*x^2+2*x+5").unwrap();
p.div_power_of_x_assign(2);
assert_eq!(p.to_string(), "x+3");
let mut p = UnsignedPolynomial::<u8>::from_str("5*x").unwrap();
p.div_power_of_x_assign(1);
assert_eq!(p.to_string(), "5");
let mut p = UnsignedPolynomial::<u8>::from_str("x^3+3*x^2+2*x+5").unwrap();
p.div_power_of_x_assign(10);
assert_eq!(p, UnsignedPolynomial::<u8>::ZERO);This is equivalent to nmod_poly_shift_right from nmod_poly/shift_right.c, FLINT 3.6.0.
impl<T: Eq + PrimitiveUnsigned> Eq for UnsignedPolynomial<T>
Source§impl<T: PrimitiveUnsigned> EqTruncated for UnsignedPolynomial<T>
impl<T: PrimitiveUnsigned> EqTruncated for UnsignedPolynomial<T>
Source§fn eq_truncated(&self, other: &Self, len: u64) -> bool
fn eq_truncated(&self, other: &Self, len: u64) -> bool
Determines whether an UnsignedPolynomial and another agree below $x^{\mathrm{len}}$:
that is, whether they have the same coefficient of $x^i$ for every $i$ less than len.
Any two polynomials agree below $x^0$, and once len is at least both of their lengths,
they agree exactly when they are equal.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is min(len, max(self.len(), other.len())).
§Examples
See here.
This is equivalent to nmod_poly_equal_trunc from nmod_poly/equal_trunc.c, FLINT 3.6.0.
Source§impl<T: PrimitiveUnsigned> ExponentGcd for UnsignedPolynomial<T>
impl<T: PrimitiveUnsigned> ExponentGcd for UnsignedPolynomial<T>
Source§fn exponent_gcd(&self) -> u64
fn exponent_gcd(&self) -> u64
Computes the greatest common divisor of the exponents at which an UnsignedPolynomial has
nonzero coefficients.
$$ f(p) = \gcd \{i : p_i \neq 0\}. $$
When the polynomial is not constant, this is the largest $k$ such that $p(x) = q(x^k)$ for
some polynomial $q$, and
compose_power_of_x with $k$
recovers $p$ from $q$. A constant polynomial, including zero, gives 0.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is self.len().
§Examples
use core::str::FromStr;
use malachite_base::num::basic::traits::Zero;
use malachite_base::polynomial::ExponentGcd;
use malachite_base::unsigned_polynomial::UnsignedPolynomial;
assert_eq!(
UnsignedPolynomial::<u8>::from_str("x^6+2*x^3+1")
.unwrap()
.exponent_gcd(),
3
);
assert_eq!(
UnsignedPolynomial::<u8>::from_str("x^4+x")
.unwrap()
.exponent_gcd(),
1
);
assert_eq!(
UnsignedPolynomial::<u8>::from_str("x^4")
.unwrap()
.exponent_gcd(),
4
);
assert_eq!(
UnsignedPolynomial::<u8>::from_str("5")
.unwrap()
.exponent_gcd(),
0
);
assert_eq!(UnsignedPolynomial::<u8>::ZERO.exponent_gcd(), 0);This is equivalent to nmod_poly_deflation from nmod_poly/deflation.c, FLINT 3.6.0,
except that a constant gives 0 rather than 1.
Source§impl<T: PrimitiveUnsigned> From<T> for UnsignedPolynomial<T>
impl<T: PrimitiveUnsigned> From<T> for UnsignedPolynomial<T>
Source§fn from(x: T) -> Self
fn from(x: T) -> Self
Converts a value to a constant UnsignedPolynomial.
This works for anything a u64 can be converted from, and for a u64 itself. The
polynomial is the constant one, whose only coefficient is the value; zero becomes the zero
polynomial, which has no coefficients at all.
$f(x) = x$, read on the left as a number and on the right as a polynomial.
§Worst-case complexity
Constant time and additional memory.
§Examples
use malachite_base::unsigned_polynomial::UnsignedPolynomial;
assert_eq!(UnsignedPolynomial::<u64>::from(123u64).to_string(), "123");
assert_eq!(UnsignedPolynomial::<u64>::from(123u64).to_string(), "123");
assert_eq!(UnsignedPolynomial::<u64>::from(true).to_string(), "1");
// Zero is the zero polynomial, which has no coefficients.
assert_eq!(
UnsignedPolynomial::<u64>::from(0u64),
UnsignedPolynomial::<u64>::default()
);Source§impl<T: PrimitiveUnsigned> From<bool> for UnsignedPolynomial<T>
impl<T: PrimitiveUnsigned> From<bool> for UnsignedPolynomial<T>
Source§fn from(b: bool) -> Self
fn from(b: bool) -> Self
Converts a bool to an UnsignedPolynomial: the constant polynomial 0 or 1.
§Worst-case complexity
Constant time and additional memory.
§Examples
use malachite_base::unsigned_polynomial::UnsignedPolynomial;
assert_eq!(UnsignedPolynomial::<u64>::from(false).to_string(), "0");
assert_eq!(UnsignedPolynomial::<u64>::from(true).to_string(), "1");Source§impl<T: PrimitiveUnsigned> FromStr for UnsignedPolynomial<T>
impl<T: PrimitiveUnsigned> FromStr for UnsignedPolynomial<T>
Source§fn from_str(s: &str) -> Result<Self, ()>
fn from_str(s: &str) -> Result<Self, ()>
Converts a string to a UnsignedPolynomial.
The variable is called x. from_string_with is
the way to call it something else.
This reads back everything Display writes, and more besides: the
terms may come in any order, an exponent may be written ^1, and a coefficient may have
leading zeros. What it will not accept is a term whose coefficient is zero, two terms of the
same degree, a variable other than the one asked for, or anything with a space in it. The
zero polynomial is 0, and is the only string in which a zero coefficient may be written.
If the string does not represent a UnsignedPolynomial, an Err is returned.
§Worst-case complexity
$T(n) = O(n (\log n)^2 \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, and $n$ is s.len().
§Examples
use core::str::FromStr;
use malachite_base::unsigned_polynomial::UnsignedPolynomial;
assert_eq!(
UnsignedPolynomial::<u64>::from_str("x^2+3*x+2")
.unwrap()
.to_string(),
"x^2+3*x+2"
);
assert_eq!(
UnsignedPolynomial::<u64>::from_str("0")
.unwrap()
.to_string(),
"0"
);
assert_eq!(
UnsignedPolynomial::<u64>::from_str("5")
.unwrap()
.to_string(),
"5"
);
assert_eq!(
UnsignedPolynomial::<u64>::from_str("x")
.unwrap()
.to_string(),
"x"
);
// The terms may come in any order.
assert_eq!(
UnsignedPolynomial::<u64>::from_str("2+3*x+x^2")
.unwrap()
.to_string(),
"x^2+3*x+2"
);
assert!(UnsignedPolynomial::<u64>::from_str("").is_err());
assert!(UnsignedPolynomial::<u64>::from_str("y").is_err());
assert!(UnsignedPolynomial::<u64>::from_str("x^2 + 1").is_err());
assert!(UnsignedPolynomial::<u64>::from_str("0*x").is_err());
assert!(UnsignedPolynomial::<u64>::from_str("x+x").is_err());
assert!(UnsignedPolynomial::<u64>::from_str("-x").is_err());Source§impl<T: Hash + PrimitiveUnsigned> Hash for UnsignedPolynomial<T>
impl<T: Hash + PrimitiveUnsigned> Hash for UnsignedPolynomial<T>
Source§impl<T: PrimitiveUnsigned> Height for UnsignedPolynomial<T>
impl<T: PrimitiveUnsigned> Height for UnsignedPolynomial<T>
Source§fn to_height(&self) -> T
fn to_height(&self) -> T
Returns the height of a UnsignedPolynomial: the largest of its coefficients.
The zero polynomial has no coefficients, and its height is 0.
$$ f(p) = H(p) = \max_i |p_i|. $$
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is the number of coefficients.
§Examples
use core::str::FromStr;
use malachite_base::num::arithmetic::traits::Height;
use malachite_base::unsigned_polynomial::UnsignedPolynomial;
assert_eq!(
UnsignedPolynomial::<u64>::from_str("x^2+3*x+2")
.unwrap()
.to_height(),
3
);
assert_eq!(
UnsignedPolynomial::<u64>::from_str("x^100")
.unwrap()
.to_height(),
1
);
assert_eq!(
UnsignedPolynomial::<u64>::from_str("0")
.unwrap()
.to_height(),
0
);This is equivalent to fmpz_poly_height from fmpz_poly/norms.c, FLINT 3.6.0, for a
polynomial whose coefficients are all nonnegative.
Source§fn into_height(self) -> T
fn into_height(self) -> T
Returns the height of a UnsignedPolynomial, taking it by value.
A u64 is Copy, so this is the same work as to_height; it is
here so that the two spellings agree across the types that implement Height.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is the number of coefficients.
§Examples
use core::str::FromStr;
use malachite_base::num::arithmetic::traits::Height;
use malachite_base::unsigned_polynomial::UnsignedPolynomial;
assert_eq!(
UnsignedPolynomial::<u64>::from_str("x^2+3*x+2")
.unwrap()
.into_height(),
3
);
assert_eq!(
UnsignedPolynomial::<u64>::from_str("0")
.unwrap()
.into_height(),
0
);Source§fn height_significant_bits(&self) -> u64
fn height_significant_bits(&self) -> u64
Returns the number of significant bits of the height of a UnsignedPolynomial.
Since bit length is monotone, this is the largest of the coefficients’ bit lengths, which is the bit length of the largest coefficient.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is the number of coefficients.
§Examples
use core::str::FromStr;
use malachite_base::num::arithmetic::traits::Height;
use malachite_base::unsigned_polynomial::UnsignedPolynomial;
assert_eq!(
UnsignedPolynomial::<u64>::from_str("x^2+3*x+2")
.unwrap()
.height_significant_bits(),
2
);
assert_eq!(
UnsignedPolynomial::<u64>::from_str("0")
.unwrap()
.height_significant_bits(),
0
);type Output = T
Source§impl<T: PrimitiveUnsigned> IsUnit for UnsignedPolynomial<T>
impl<T: PrimitiveUnsigned> IsUnit for UnsignedPolynomial<T>
Source§fn is_unit(&self) -> bool
fn is_unit(&self) -> bool
Determines whether an UnsignedPolynomial is a unit: whether it is the constant
polynomial 1, the only polynomial with non-negative integer coefficients that has a
multiplicative inverse.
No modulus is involved, as with IsUnit for the unsigned primitive types. Modulo $n$,
every constant coprime to $n$ is also a unit, and so, when $n$ is composite, are some
polynomials of positive degree.
§Worst-case complexity
Constant time and additional memory.
§Examples
use core::str::FromStr;
use malachite_base::num::arithmetic::traits::IsUnit;
use malachite_base::num::basic::traits::Zero;
use malachite_base::polynomial::Polynomial;
use malachite_base::unsigned_polynomial::UnsignedPolynomial;
assert_eq!(UnsignedPolynomial::<u64>::one().is_unit(), true);
assert_eq!(UnsignedPolynomial::<u64>::ZERO.is_unit(), false);
assert_eq!(UnsignedPolynomial::<u64>::two().is_unit(), false);
assert_eq!(UnsignedPolynomial::<u8>::x().is_unit(), false);
assert_eq!(
UnsignedPolynomial::<u8>::from_str("x+1").unwrap().is_unit(),
false
);Source§impl<T: PrimitiveUnsigned> Mod<T> for UnsignedPolynomial<T>
impl<T: PrimitiveUnsigned> Mod<T> for UnsignedPolynomial<T>
Source§fn mod_op(self, m: T) -> Self
fn mod_op(self, m: T) -> Self
Divides every coefficient of a UnsignedPolynomial by a u64, keeping the remainders,
taking the polynomial by value.
A UnsignedPolynomial’s coefficients are never negative, so there is nothing for this to
do that % does not: the two agree everywhere, and this is the same operation under the
name the mod-family traits use. See the documentation for the Rem implementation for
details, including how reducing can lower the degree.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is the number of coefficients.
§Panics
Panics if m is 0.
§Examples
use core::str::FromStr;
use malachite_base::num::arithmetic::traits::Mod;
use malachite_base::unsigned_polynomial::UnsignedPolynomial;
assert_eq!(
UnsignedPolynomial::<u64>::from_str("x^2+4*x+5")
.unwrap()
.mod_op(3)
.to_string(),
"x^2+x+2"
);
// Reducing the leading coefficient to zero lowers the degree.
assert_eq!(
UnsignedPolynomial::<u64>::from_str("4*x^2+3")
.unwrap()
.mod_op(4)
.to_string(),
"3"
);type Output = UnsignedPolynomial<T>
Source§impl<T: PrimitiveUnsigned> Mod<T> for &UnsignedPolynomial<T>
impl<T: PrimitiveUnsigned> Mod<T> for &UnsignedPolynomial<T>
Source§fn mod_op(self, m: T) -> UnsignedPolynomial<T>
fn mod_op(self, m: T) -> UnsignedPolynomial<T>
Divides every coefficient of a UnsignedPolynomial by a u64, keeping the remainders,
taking the polynomial by reference.
This agrees with % everywhere, a UnsignedPolynomial’s coefficients never being
negative. See the documentation for the Rem implementation on UnsignedPolynomial for
details.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is the number of coefficients.
§Panics
Panics if m is 0.
§Examples
use core::str::FromStr;
use malachite_base::num::arithmetic::traits::Mod;
use malachite_base::unsigned_polynomial::UnsignedPolynomial;
let p = UnsignedPolynomial::<u64>::from_str("4*x^2+3").unwrap();
assert_eq!((&p).mod_op(4).to_string(), "3");
// The polynomial is left alone.
assert_eq!(p.to_string(), "4*x^2+3");type Output = UnsignedPolynomial<T>
Source§impl<T: PrimitiveUnsigned> ModAdd<&UnsignedPolynomial<T>, T> for UnsignedPolynomial<T>
impl<T: PrimitiveUnsigned> ModAdd<&UnsignedPolynomial<T>, T> for UnsignedPolynomial<T>
Source§fn mod_add(self, other: &Self, m: T) -> Self
fn mod_add(self, other: &Self, m: T) -> Self
Adds two UnsignedPolynomials modulo m, taking the first by value and the second by
reference. The coefficients of both must already be reduced modulo m.
$$ f(p, q, m) = p + q \bmod m. $$
Coefficients past the end of the shorter polynomial are taken to be zero. When the two
polynomials have the same degree, their leading coefficients can cancel modulo m, and then
the degree of the sum is lower.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is the number of coefficients of the longer polynomial.
§Panics
Panics if m is 0, or if any coefficient of self or other is greater than or equal to
m.
§Examples
use core::str::FromStr;
use malachite_base::num::arithmetic::traits::ModAdd;
use malachite_base::unsigned_polynomial::UnsignedPolynomial;
// The leading coefficients cancel, and so do the linear ones.
assert_eq!(
UnsignedPolynomial::<u8>::from_str("5*x^2+x+3")
.unwrap()
.mod_add(&UnsignedPolynomial::from_str("2*x^2+6*x+1").unwrap(), 7)
.to_string(),
"4"
);
// Wrapping around makes the constant term 2.
assert_eq!(
UnsignedPolynomial::<u8>::from_str("x+3")
.unwrap()
.mod_add(&UnsignedPolynomial::from_str("x^2+6").unwrap(), 7)
.to_string(),
"x^2+x+2"
);This is equivalent to nmod_poly_add from nmod_poly/add.c, FLINT 3.6.0.
type Output = UnsignedPolynomial<T>
Source§impl<T: PrimitiveUnsigned> ModAdd<&UnsignedPolynomial<T>, T> for &UnsignedPolynomial<T>
impl<T: PrimitiveUnsigned> ModAdd<&UnsignedPolynomial<T>, T> for &UnsignedPolynomial<T>
Source§fn mod_add(self, other: &UnsignedPolynomial<T>, m: T) -> UnsignedPolynomial<T>
fn mod_add(self, other: &UnsignedPolynomial<T>, m: T) -> UnsignedPolynomial<T>
Adds two UnsignedPolynomials modulo m, taking both by reference. The coefficients of
both must already be reduced modulo m.
$$ f(p, q, m) = p + q \bmod m. $$
Coefficients past the end of the shorter polynomial are taken to be zero. When the two
polynomials have the same degree, their leading coefficients can cancel modulo m, and then
the degree of the sum is lower.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is the number of coefficients of the longer polynomial.
§Panics
Panics if m is 0, or if any coefficient of self or other is greater than or equal to
m.
§Examples
use core::str::FromStr;
use malachite_base::num::arithmetic::traits::ModAdd;
use malachite_base::unsigned_polynomial::UnsignedPolynomial;
// The leading coefficients cancel, and so do the linear ones.
assert_eq!(
(&UnsignedPolynomial::<u8>::from_str("5*x^2+x+3").unwrap())
.mod_add(&UnsignedPolynomial::from_str("2*x^2+6*x+1").unwrap(), 7)
.to_string(),
"4"
);
// Wrapping around makes the constant term 2.
assert_eq!(
(&UnsignedPolynomial::<u8>::from_str("x+3").unwrap())
.mod_add(&UnsignedPolynomial::from_str("x^2+6").unwrap(), 7)
.to_string(),
"x^2+x+2"
);This is equivalent to nmod_poly_add from nmod_poly/add.c, FLINT 3.6.0.
type Output = UnsignedPolynomial<T>
Source§impl<T: PrimitiveUnsigned> ModAdd<UnsignedPolynomial<T>, T> for UnsignedPolynomial<T>
impl<T: PrimitiveUnsigned> ModAdd<UnsignedPolynomial<T>, T> for UnsignedPolynomial<T>
Source§fn mod_add(self, other: Self, m: T) -> Self
fn mod_add(self, other: Self, m: T) -> Self
Adds two UnsignedPolynomials modulo m, taking both by value. The coefficients of both
must already be reduced modulo m.
$$ f(p, q, m) = p + q \bmod m. $$
Coefficients past the end of the shorter polynomial are taken to be zero. When the two
polynomials have the same degree, their leading coefficients can cancel modulo m, and then
the degree of the sum is lower.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is the number of coefficients of the longer polynomial.
§Panics
Panics if m is 0, or if any coefficient of self or other is greater than or equal to
m.
§Examples
use core::str::FromStr;
use malachite_base::num::arithmetic::traits::ModAdd;
use malachite_base::unsigned_polynomial::UnsignedPolynomial;
// The leading coefficients cancel, and so do the linear ones.
assert_eq!(
UnsignedPolynomial::<u8>::from_str("5*x^2+x+3")
.unwrap()
.mod_add(UnsignedPolynomial::from_str("2*x^2+6*x+1").unwrap(), 7)
.to_string(),
"4"
);
// Wrapping around makes the constant term 2.
assert_eq!(
UnsignedPolynomial::<u8>::from_str("x+3")
.unwrap()
.mod_add(UnsignedPolynomial::from_str("x^2+6").unwrap(), 7)
.to_string(),
"x^2+x+2"
);This is equivalent to nmod_poly_add from nmod_poly/add.c, FLINT 3.6.0.
type Output = UnsignedPolynomial<T>
Source§impl<T: PrimitiveUnsigned> ModAdd<UnsignedPolynomial<T>, T> for &UnsignedPolynomial<T>
impl<T: PrimitiveUnsigned> ModAdd<UnsignedPolynomial<T>, T> for &UnsignedPolynomial<T>
Source§fn mod_add(self, other: UnsignedPolynomial<T>, m: T) -> UnsignedPolynomial<T>
fn mod_add(self, other: UnsignedPolynomial<T>, m: T) -> UnsignedPolynomial<T>
Adds two UnsignedPolynomials modulo m, taking the first by reference and the second by
value. The coefficients of both must already be reduced modulo m.
$$ f(p, q, m) = p + q \bmod m. $$
Coefficients past the end of the shorter polynomial are taken to be zero. When the two
polynomials have the same degree, their leading coefficients can cancel modulo m, and then
the degree of the sum is lower.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is the number of coefficients of the longer polynomial.
§Panics
Panics if m is 0, or if any coefficient of self or other is greater than or equal to
m.
§Examples
use core::str::FromStr;
use malachite_base::num::arithmetic::traits::ModAdd;
use malachite_base::unsigned_polynomial::UnsignedPolynomial;
// The leading coefficients cancel, and so do the linear ones.
assert_eq!(
(&UnsignedPolynomial::<u8>::from_str("5*x^2+x+3").unwrap())
.mod_add(UnsignedPolynomial::from_str("2*x^2+6*x+1").unwrap(), 7)
.to_string(),
"4"
);
// Wrapping around makes the constant term 2.
assert_eq!(
(&UnsignedPolynomial::<u8>::from_str("x+3").unwrap())
.mod_add(UnsignedPolynomial::from_str("x^2+6").unwrap(), 7)
.to_string(),
"x^2+x+2"
);This is equivalent to nmod_poly_add from nmod_poly/add.c, FLINT 3.6.0.
type Output = UnsignedPolynomial<T>
Source§impl<T: PrimitiveUnsigned> ModAddAssign<&UnsignedPolynomial<T>, T> for UnsignedPolynomial<T>
impl<T: PrimitiveUnsigned> ModAddAssign<&UnsignedPolynomial<T>, T> for UnsignedPolynomial<T>
Source§fn mod_add_assign(&mut self, other: &Self, m: T)
fn mod_add_assign(&mut self, other: &Self, m: T)
Adds an UnsignedPolynomial to an UnsignedPolynomial modulo m, in place, taking the
second by reference. The coefficients of both must already be reduced modulo m.
$$ p \gets p + q \bmod m. $$
Coefficients past the end of the shorter polynomial are taken to be zero. When the two
polynomials have the same degree, their leading coefficients can cancel modulo m, and then
the degree of the sum is lower.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is the number of coefficients of the longer polynomial.
§Panics
Panics if m is 0, or if any coefficient of self or other is greater than or equal to
m.
§Examples
use core::str::FromStr;
use malachite_base::num::arithmetic::traits::ModAddAssign;
use malachite_base::unsigned_polynomial::UnsignedPolynomial;
// The leading coefficients cancel, and so do the linear ones.
let mut p = UnsignedPolynomial::<u8>::from_str("5*x^2+x+3").unwrap();
p.mod_add_assign(&UnsignedPolynomial::from_str("2*x^2+6*x+1").unwrap(), 7);
assert_eq!(p.to_string(), "4");
// Wrapping around makes the constant term 2.
let mut p = UnsignedPolynomial::<u8>::from_str("x+3").unwrap();
p.mod_add_assign(&UnsignedPolynomial::from_str("x^2+6").unwrap(), 7);
assert_eq!(p.to_string(), "x^2+x+2");This is equivalent to nmod_poly_add from nmod_poly/add.c, FLINT 3.6.0.
Source§impl<T: PrimitiveUnsigned> ModAddAssign<UnsignedPolynomial<T>, T> for UnsignedPolynomial<T>
impl<T: PrimitiveUnsigned> ModAddAssign<UnsignedPolynomial<T>, T> for UnsignedPolynomial<T>
Source§fn mod_add_assign(&mut self, other: Self, m: T)
fn mod_add_assign(&mut self, other: Self, m: T)
Adds an UnsignedPolynomial to an UnsignedPolynomial modulo m, in place, taking the
second by value. The coefficients of both must already be reduced modulo m.
$$ p \gets p + q \bmod m. $$
Coefficients past the end of the shorter polynomial are taken to be zero. When the two
polynomials have the same degree, their leading coefficients can cancel modulo m, and then
the degree of the sum is lower.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is the number of coefficients of the longer polynomial.
§Panics
Panics if m is 0, or if any coefficient of self or other is greater than or equal to
m.
§Examples
use core::str::FromStr;
use malachite_base::num::arithmetic::traits::ModAddAssign;
use malachite_base::unsigned_polynomial::UnsignedPolynomial;
// The leading coefficients cancel, and so do the linear ones.
let mut p = UnsignedPolynomial::<u8>::from_str("5*x^2+x+3").unwrap();
p.mod_add_assign(UnsignedPolynomial::from_str("2*x^2+6*x+1").unwrap(), 7);
assert_eq!(p.to_string(), "4");
// Wrapping around makes the constant term 2.
let mut p = UnsignedPolynomial::<u8>::from_str("x+3").unwrap();
p.mod_add_assign(UnsignedPolynomial::from_str("x^2+6").unwrap(), 7);
assert_eq!(p.to_string(), "x^2+x+2");This is equivalent to nmod_poly_add from nmod_poly/add.c, FLINT 3.6.0.
Source§impl<T: PrimitiveUnsigned> ModAddTruncated<&UnsignedPolynomial<T>, T> for UnsignedPolynomial<T>
impl<T: PrimitiveUnsigned> ModAddTruncated<&UnsignedPolynomial<T>, T> for UnsignedPolynomial<T>
Source§fn mod_add_truncated(self, other: &Self, len: u64, m: T) -> Self
fn mod_add_truncated(self, other: &Self, len: u64, m: T) -> Self
Adds two UnsignedPolynomials modulo m, keeping only the coefficients of $x^i$ for $i$
less than len, taking the first by value and the second by reference. The coefficients of
both must already be reduced modulo m.
$$ f(p, q, n, m) = ((p + q) \bmod x^n) \bmod m. $$
The polynomials need not already be truncated: this is the sum of their images modulo $x^n$,
so only the first len coefficients of each are read. The sum is trimmed, so when
coefficients cancel modulo m at the top of the kept range, the degree is lower still.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is the number of coefficients of the longer polynomial.
§Panics
Panics if m is 0, or if any coefficient of self or other is greater than or equal to
m.
§Examples
use core::str::FromStr;
use malachite_base::polynomial::ModAddTruncated;
use malachite_base::unsigned_polynomial::UnsignedPolynomial;
// The linear and constant coefficients wrap around to 0.
assert_eq!(
UnsignedPolynomial::<u8>::from_str("x^3+2*x^2+x+5")
.unwrap()
.mod_add_truncated(&UnsignedPolynomial::from_str("4*x^2+6*x+2").unwrap(), 3, 7)
.to_string(),
"6*x^2"
);
assert_eq!(
UnsignedPolynomial::<u8>::from_str("x^3+2*x^2+x+5")
.unwrap()
.mod_add_truncated(&UnsignedPolynomial::from_str("4*x^2+6*x+2").unwrap(), 1, 7)
.to_string(),
"0"
);This is equivalent to nmod_poly_add_series from nmod_poly/add_series.c, FLINT 3.6.0.
type Output = UnsignedPolynomial<T>
Source§impl<T: PrimitiveUnsigned> ModAddTruncated<&UnsignedPolynomial<T>, T> for &UnsignedPolynomial<T>
impl<T: PrimitiveUnsigned> ModAddTruncated<&UnsignedPolynomial<T>, T> for &UnsignedPolynomial<T>
Source§fn mod_add_truncated(
self,
other: &UnsignedPolynomial<T>,
len: u64,
m: T,
) -> UnsignedPolynomial<T>
fn mod_add_truncated( self, other: &UnsignedPolynomial<T>, len: u64, m: T, ) -> UnsignedPolynomial<T>
Adds two UnsignedPolynomials modulo m, keeping only the coefficients of $x^i$ for $i$
less than len, taking both by reference. The coefficients of both must already be reduced
modulo m.
$$ f(p, q, n, m) = ((p + q) \bmod x^n) \bmod m. $$
The polynomials need not already be truncated: this is the sum of their images modulo $x^n$,
so only the first len coefficients of each are read. The sum is trimmed, so when
coefficients cancel modulo m at the top of the kept range, the degree is lower still.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is the number of coefficients of the longer polynomial.
§Panics
Panics if m is 0, or if any coefficient of self or other is greater than or equal to
m.
§Examples
use core::str::FromStr;
use malachite_base::polynomial::ModAddTruncated;
use malachite_base::unsigned_polynomial::UnsignedPolynomial;
// The linear and constant coefficients wrap around to 0.
assert_eq!(
(&UnsignedPolynomial::<u8>::from_str("x^3+2*x^2+x+5").unwrap())
.mod_add_truncated(&UnsignedPolynomial::from_str("4*x^2+6*x+2").unwrap(), 3, 7)
.to_string(),
"6*x^2"
);
assert_eq!(
(&UnsignedPolynomial::<u8>::from_str("x^3+2*x^2+x+5").unwrap())
.mod_add_truncated(&UnsignedPolynomial::from_str("4*x^2+6*x+2").unwrap(), 1, 7)
.to_string(),
"0"
);This is equivalent to nmod_poly_add_series from nmod_poly/add_series.c, FLINT 3.6.0.
type Output = UnsignedPolynomial<T>
Source§impl<T: PrimitiveUnsigned> ModAddTruncated<UnsignedPolynomial<T>, T> for UnsignedPolynomial<T>
impl<T: PrimitiveUnsigned> ModAddTruncated<UnsignedPolynomial<T>, T> for UnsignedPolynomial<T>
Source§fn mod_add_truncated(self, other: Self, len: u64, m: T) -> Self
fn mod_add_truncated(self, other: Self, len: u64, m: T) -> Self
Adds two UnsignedPolynomials modulo m, keeping only the coefficients of $x^i$ for $i$
less than len, taking both by value. The coefficients of both must already be reduced
modulo m.
$$ f(p, q, n, m) = ((p + q) \bmod x^n) \bmod m. $$
The polynomials need not already be truncated: this is the sum of their images modulo $x^n$,
so only the first len coefficients of each are read. The sum is trimmed, so when
coefficients cancel modulo m at the top of the kept range, the degree is lower still.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is the number of coefficients of the longer polynomial.
§Panics
Panics if m is 0, or if any coefficient of self or other is greater than or equal to
m.
§Examples
use core::str::FromStr;
use malachite_base::polynomial::ModAddTruncated;
use malachite_base::unsigned_polynomial::UnsignedPolynomial;
// The linear and constant coefficients wrap around to 0.
assert_eq!(
UnsignedPolynomial::<u8>::from_str("x^3+2*x^2+x+5")
.unwrap()
.mod_add_truncated(UnsignedPolynomial::from_str("4*x^2+6*x+2").unwrap(), 3, 7)
.to_string(),
"6*x^2"
);
assert_eq!(
UnsignedPolynomial::<u8>::from_str("x^3+2*x^2+x+5")
.unwrap()
.mod_add_truncated(UnsignedPolynomial::from_str("4*x^2+6*x+2").unwrap(), 1, 7)
.to_string(),
"0"
);This is equivalent to nmod_poly_add_series from nmod_poly/add_series.c, FLINT 3.6.0.
type Output = UnsignedPolynomial<T>
Source§impl<T: PrimitiveUnsigned> ModAddTruncated<UnsignedPolynomial<T>, T> for &UnsignedPolynomial<T>
impl<T: PrimitiveUnsigned> ModAddTruncated<UnsignedPolynomial<T>, T> for &UnsignedPolynomial<T>
Source§fn mod_add_truncated(
self,
other: UnsignedPolynomial<T>,
len: u64,
m: T,
) -> UnsignedPolynomial<T>
fn mod_add_truncated( self, other: UnsignedPolynomial<T>, len: u64, m: T, ) -> UnsignedPolynomial<T>
Adds two UnsignedPolynomials modulo m, keeping only the coefficients of $x^i$ for $i$
less than len, taking the first by reference and the second by value. The coefficients of
both must already be reduced modulo m.
$$ f(p, q, n, m) = ((p + q) \bmod x^n) \bmod m. $$
The polynomials need not already be truncated: this is the sum of their images modulo $x^n$,
so only the first len coefficients of each are read. The sum is trimmed, so when
coefficients cancel modulo m at the top of the kept range, the degree is lower still.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is the number of coefficients of the longer polynomial.
§Panics
Panics if m is 0, or if any coefficient of self or other is greater than or equal to
m.
§Examples
use core::str::FromStr;
use malachite_base::polynomial::ModAddTruncated;
use malachite_base::unsigned_polynomial::UnsignedPolynomial;
// The linear and constant coefficients wrap around to 0.
assert_eq!(
(&UnsignedPolynomial::<u8>::from_str("x^3+2*x^2+x+5").unwrap())
.mod_add_truncated(UnsignedPolynomial::from_str("4*x^2+6*x+2").unwrap(), 3, 7)
.to_string(),
"6*x^2"
);
assert_eq!(
(&UnsignedPolynomial::<u8>::from_str("x^3+2*x^2+x+5").unwrap())
.mod_add_truncated(UnsignedPolynomial::from_str("4*x^2+6*x+2").unwrap(), 1, 7)
.to_string(),
"0"
);This is equivalent to nmod_poly_add_series from nmod_poly/add_series.c, FLINT 3.6.0.
type Output = UnsignedPolynomial<T>
Source§impl<T: PrimitiveUnsigned> ModAddTruncatedAssign<&UnsignedPolynomial<T>, T> for UnsignedPolynomial<T>
impl<T: PrimitiveUnsigned> ModAddTruncatedAssign<&UnsignedPolynomial<T>, T> for UnsignedPolynomial<T>
Source§fn mod_add_truncated_assign(&mut self, other: &Self, len: u64, m: T)
fn mod_add_truncated_assign(&mut self, other: &Self, len: u64, m: T)
Adds an UnsignedPolynomial to an UnsignedPolynomial modulo m in place, keeping
only the coefficients of $x^i$ for $i$ less than len, taking the second polynomial by
reference. The coefficients of both must already be reduced modulo m.
$$ p \gets ((p + q) \bmod x^n) \bmod m. $$
The polynomials need not already be truncated: this is the sum of their images modulo $x^n$,
so only the first len coefficients of each are read. The sum is trimmed, so when
coefficients cancel modulo m at the top of the kept range, the degree is lower still.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is the number of coefficients of the longer polynomial.
§Panics
Panics if m is 0, or if any coefficient of self or other is greater than or equal to
m.
§Examples
use core::str::FromStr;
use malachite_base::polynomial::ModAddTruncatedAssign;
use malachite_base::unsigned_polynomial::UnsignedPolynomial;
// The linear and constant coefficients wrap around to 0.
let mut p = UnsignedPolynomial::<u8>::from_str("x^3+2*x^2+x+5").unwrap();
p.mod_add_truncated_assign(&UnsignedPolynomial::from_str("4*x^2+6*x+2").unwrap(), 3, 7);
assert_eq!(p.to_string(), "6*x^2");
let mut p = UnsignedPolynomial::<u8>::from_str("x^3+2*x^2+x+5").unwrap();
p.mod_add_truncated_assign(&UnsignedPolynomial::from_str("4*x^2+6*x+2").unwrap(), 1, 7);
assert_eq!(p.to_string(), "0");This is equivalent to nmod_poly_add_series from nmod_poly/add_series.c, FLINT 3.6.0.
Source§impl<T: PrimitiveUnsigned> ModAddTruncatedAssign<UnsignedPolynomial<T>, T> for UnsignedPolynomial<T>
impl<T: PrimitiveUnsigned> ModAddTruncatedAssign<UnsignedPolynomial<T>, T> for UnsignedPolynomial<T>
Source§fn mod_add_truncated_assign(&mut self, other: Self, len: u64, m: T)
fn mod_add_truncated_assign(&mut self, other: Self, len: u64, m: T)
Adds an UnsignedPolynomial to an UnsignedPolynomial modulo m in place, keeping
only the coefficients of $x^i$ for $i$ less than len, taking the second polynomial by
value. The coefficients of both must already be reduced modulo m.
$$ p \gets ((p + q) \bmod x^n) \bmod m. $$
The polynomials need not already be truncated: this is the sum of their images modulo $x^n$,
so only the first len coefficients of each are read. The sum is trimmed, so when
coefficients cancel modulo m at the top of the kept range, the degree is lower still.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is the number of coefficients of the longer polynomial.
§Panics
Panics if m is 0, or if any coefficient of self or other is greater than or equal to
m.
§Examples
use core::str::FromStr;
use malachite_base::polynomial::ModAddTruncatedAssign;
use malachite_base::unsigned_polynomial::UnsignedPolynomial;
// The linear and constant coefficients wrap around to 0.
let mut p = UnsignedPolynomial::<u8>::from_str("x^3+2*x^2+x+5").unwrap();
p.mod_add_truncated_assign(UnsignedPolynomial::from_str("4*x^2+6*x+2").unwrap(), 3, 7);
assert_eq!(p.to_string(), "6*x^2");
let mut p = UnsignedPolynomial::<u8>::from_str("x^3+2*x^2+x+5").unwrap();
p.mod_add_truncated_assign(UnsignedPolynomial::from_str("4*x^2+6*x+2").unwrap(), 1, 7);
assert_eq!(p.to_string(), "0");This is equivalent to nmod_poly_add_series from nmod_poly/add_series.c, FLINT 3.6.0.
Source§impl<T: PrimitiveUnsigned> ModAssign<T> for UnsignedPolynomial<T>
impl<T: PrimitiveUnsigned> ModAssign<T> for UnsignedPolynomial<T>
Source§fn mod_assign(&mut self, m: T)
fn mod_assign(&mut self, m: T)
Divides every coefficient of a UnsignedPolynomial by a u64, replacing the polynomial
by the one whose coefficients are the remainders.
This agrees with %= everywhere, a UnsignedPolynomial’s coefficients never being
negative. See the documentation for the Rem implementation on UnsignedPolynomial 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 number of coefficients.
§Panics
Panics if m is 0.
§Examples
use core::str::FromStr;
use malachite_base::num::arithmetic::traits::ModAssign;
use malachite_base::unsigned_polynomial::UnsignedPolynomial;
let mut p = UnsignedPolynomial::<u64>::from_str("x^2+4*x+5").unwrap();
p.mod_assign(3);
assert_eq!(p.to_string(), "x^2+x+2");Source§impl<T: PrimitiveUnsigned> ModDerivative<T> for UnsignedPolynomial<T>
impl<T: PrimitiveUnsigned> ModDerivative<T> for UnsignedPolynomial<T>
Source§fn mod_derivative(self, m: T) -> Self
fn mod_derivative(self, m: T) -> Self
Computes the derivative of an UnsignedPolynomial modulo m, taking the polynomial by
value. The coefficients must already be reduced modulo m.
$$ f(p, m) = p’ \bmod m. $$
The coefficient of $x^i$ is multiplied by $i$, reduced, and moved to $x^{i-1}$. Since $ia_i$ can be divisible by the modulus even when $a_i$ is not zero, the derivative can lose any number of degrees. A constant polynomial, including zero, has derivative zero.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is self.len().
§Panics
Panics if m is 0, or if any coefficient of self is greater than or equal to m.
§Examples
use core::str::FromStr;
use malachite_base::polynomial::ModDerivative;
use malachite_base::unsigned_polynomial::UnsignedPolynomial;
let p = UnsignedPolynomial::<u8>::from_str("x^3+3*x^2+2*x+5").unwrap();
assert_eq!(p.mod_derivative(6).to_string(), "3*x^2+2");
// The derivative can lose more than one degree.
let p = UnsignedPolynomial::<u8>::from_str("x^3+2*x+1").unwrap();
assert_eq!(p.mod_derivative(3).to_string(), "2");This is equivalent to nmod_poly_derivative from nmod_poly/derivative.c, FLINT 3.6.0.
type Output = UnsignedPolynomial<T>
Source§impl<T: PrimitiveUnsigned> ModDerivative<T> for &UnsignedPolynomial<T>
impl<T: PrimitiveUnsigned> ModDerivative<T> for &UnsignedPolynomial<T>
Source§fn mod_derivative(self, m: T) -> UnsignedPolynomial<T>
fn mod_derivative(self, m: T) -> UnsignedPolynomial<T>
Computes the derivative of an UnsignedPolynomial modulo m, taking the polynomial by
reference. The coefficients must already be reduced modulo m.
$$ f(p, m) = p’ \bmod m. $$
The coefficient of $x^i$ is multiplied by $i$, reduced, and moved to $x^{i-1}$. Since $ia_i$ can be divisible by the modulus even when $a_i$ is not zero, the derivative can lose any number of degrees. A constant polynomial, including zero, has derivative zero.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is self.len().
§Panics
Panics if m is 0, or if any coefficient of self is greater than or equal to m.
§Examples
use core::str::FromStr;
use malachite_base::polynomial::ModDerivative;
use malachite_base::unsigned_polynomial::UnsignedPolynomial;
let p = UnsignedPolynomial::<u8>::from_str("x^3+3*x^2+2*x+5").unwrap();
assert_eq!((&p).mod_derivative(6).to_string(), "3*x^2+2");
// The derivative can lose more than one degree.
let p = UnsignedPolynomial::<u8>::from_str("x^3+2*x+1").unwrap();
assert_eq!((&p).mod_derivative(3).to_string(), "2");This is equivalent to nmod_poly_derivative from nmod_poly/derivative.c, FLINT 3.6.0.
type Output = UnsignedPolynomial<T>
Source§impl<T: PrimitiveUnsigned> ModDerivativeAssign<T> for UnsignedPolynomial<T>
impl<T: PrimitiveUnsigned> ModDerivativeAssign<T> for UnsignedPolynomial<T>
Source§fn mod_derivative_assign(&mut self, m: T)
fn mod_derivative_assign(&mut self, m: T)
Replaces an UnsignedPolynomial with its derivative modulo m, in place. The
coefficients must already be reduced modulo m.
$$ p \gets p’ \bmod m. $$
The coefficient of $x^i$ is multiplied by $i$, reduced, and moved to $x^{i-1}$. Since $ia_i$ can be divisible by the modulus even when $a_i$ is not zero, the derivative can lose any number of degrees. A constant polynomial, including zero, has derivative zero.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is self.len().
§Panics
Panics if m is 0, or if any coefficient of self is greater than or equal to m.
§Examples
use core::str::FromStr;
use malachite_base::polynomial::ModDerivativeAssign;
use malachite_base::unsigned_polynomial::UnsignedPolynomial;
let mut p = UnsignedPolynomial::<u8>::from_str("x^3+3*x^2+2*x+5").unwrap();
p.mod_derivative_assign(6);
assert_eq!(p.to_string(), "3*x^2+2");
// The derivative can lose more than one degree.
let mut p = UnsignedPolynomial::<u8>::from_str("x^3+2*x+1").unwrap();
p.mod_derivative_assign(3);
assert_eq!(p.to_string(), "2");This is equivalent to nmod_poly_derivative from nmod_poly/derivative.c, FLINT 3.6.0.
Source§impl<T: PrimitiveUnsigned> ModEvaluate<T> for &UnsignedPolynomial<T>
impl<T: PrimitiveUnsigned> ModEvaluate<T> for &UnsignedPolynomial<T>
Source§fn mod_evaluate(self, x: T, m: T) -> T
fn mod_evaluate(self, x: T, m: T) -> T
Evaluates an UnsignedPolynomial at a value of its coefficient type, modulo a value of
that type, taking the polynomial by reference. The coefficients and the value must already
be reduced modulo m.
$$ f(p, x, m) = \sum_{i=0}^{n-1} c_i x^i \bmod m, $$
where $c_i$ is the coefficient of $x^i$ in $p$ and $n$ is its length. The zero polynomial evaluates to 0 everywhere.
The value is found with Horner’s rule, reducing after every step. When the polynomial is
long enough and the top bit of m is clear, every multiplication is by the same x, so
Shoup’s method is used: $\lfloor x 2^W / m \rfloor$, where $W$ is the width of T, is
computed once, and each product is then reduced with a multiplication in place of a
division. When $m \leq (2^W - 1) / 3$ the reductions are also lazy, leaving the value below
$3m - 1$ until the end.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is self.len().
§Panics
Panics if m is 0, or if any coefficient of self or x is greater than or equal to m.
§Examples
use core::str::FromStr;
use malachite_base::polynomial::ModEvaluate;
use malachite_base::unsigned_polynomial::UnsignedPolynomial;
let p = UnsignedPolynomial::<u8>::from_str("5*x^2+3*x+7").unwrap();
// 5 * 36 + 3 * 6 + 7 = 205, which is 10 mod 13.
assert_eq!((&p).mod_evaluate(6, 13), 10);
assert_eq!((&p).mod_evaluate(0, 13), 7);
// 205 itself, modulo a larger modulus.
assert_eq!((&p).mod_evaluate(6, 211), 205);This is equivalent to nmod_poly_evaluate_nmod from nmod_poly/evaluate_nmod.c, FLINT
3.6.0, except that the value must be reduced.
Source§impl<T: PrimitiveUnsigned> ModEvaluate<T> for UnsignedPolynomial<T>
impl<T: PrimitiveUnsigned> ModEvaluate<T> for UnsignedPolynomial<T>
Source§fn mod_evaluate(self, x: T, m: T) -> T
fn mod_evaluate(self, x: T, m: T) -> T
Evaluates an UnsignedPolynomial at a value of its coefficient type, modulo a value of
that type, taking the polynomial by value. The coefficients and the value must already be
reduced modulo m.
$$ f(p, x, m) = \sum_{i=0}^{n-1} c_i x^i \bmod m, $$
where $c_i$ is the coefficient of $x^i$ in $p$ and $n$ is its length. The zero polynomial evaluates to 0 everywhere.
The value is found with Horner’s rule, reducing after every step. When the polynomial is
long enough and the top bit of m is clear, every multiplication is by the same x, so
Shoup’s method is used: $\lfloor x 2^W / m \rfloor$, where $W$ is the width of T, is
computed once, and each product is then reduced with a multiplication in place of a
division. When $m \leq (2^W - 1) / 3$ the reductions are also lazy, leaving the value below
$3m - 1$ until the end.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is self.len().
§Panics
Panics if m is 0, or if any coefficient of self or x is greater than or equal to m.
§Examples
use core::str::FromStr;
use malachite_base::polynomial::ModEvaluate;
use malachite_base::unsigned_polynomial::UnsignedPolynomial;
let p = UnsignedPolynomial::<u8>::from_str("5*x^2+3*x+7").unwrap();
// 5 * 36 + 3 * 6 + 7 = 205, which is 10 mod 13.
assert_eq!(p.clone().mod_evaluate(6, 13), 10);
assert_eq!(p.clone().mod_evaluate(0, 13), 7);
// 205 itself, modulo a larger modulus.
assert_eq!(p.mod_evaluate(6, 211), 205);This is equivalent to nmod_poly_evaluate_nmod from nmod_poly/evaluate_nmod.c, FLINT
3.6.0, except that the value must be reduced.
Source§impl<T: PrimitiveUnsigned> ModEvaluateGeometric<T> for &UnsignedPolynomial<T>
impl<T: PrimitiveUnsigned> ModEvaluateGeometric<T> for &UnsignedPolynomial<T>
Source§fn mod_evaluate_geometric(self, q: T, k: u64, m: T) -> Vec<T>
fn mod_evaluate_geometric(self, q: T, k: u64, m: T) -> Vec<T>
Evaluates an UnsignedPolynomial at $1, q, q^2, \ldots, q^{k-1}$, modulo a value of its
coefficient type. The coefficients and q must already be reduced modulo m.
$$ f(p, q, k, m) = \left ( \sum_{i=0}^{n-1} c_i q^{ij} \bmod m \right )_{j=0}^{k-1}, $$
where $c_i$ is the coefficient of $x^i$ in $p$ and $n$ is its length.
The powers of q are computed with Shoup’s method when the top bit of m is clear, since
every multiplication is by q, and are then evaluated as by
mod_evaluate_many, in place.
§Worst-case complexity
$T(n, k) = O(nk)$
$M(k) = O(k)$
where $T$ is time, $M$ is additional memory, $n$ is self.len(), and $k$ is k.
§Panics
Panics if m is 0, or if any coefficient of self or q is greater than or equal to m.
§Examples
use core::str::FromStr;
use malachite_base::polynomial::ModEvaluateGeometric;
use malachite_base::unsigned_polynomial::UnsignedPolynomial;
let p = UnsignedPolynomial::<u8>::from_str("5*x^2+3*x+7").unwrap();
// At 1, 2, 4, and 8: 15, 33, 99, and 351, mod 13
assert_eq!((&p).mod_evaluate_geometric(2, 4, 13), &[2, 7, 8, 0]);This is equivalent to nmod_poly_evaluate_geometric_nmod_vec_iter from
nmod_poly/evaluate_geometric_nmod_vec.c, FLINT 3.6.0, with q in place of FLINT’s $r^2$:
FLINT evaluates at the powers of the square of its argument.
Source§impl<T: PrimitiveUnsigned> ModEvaluateMany<T> for &UnsignedPolynomial<T>
impl<T: PrimitiveUnsigned> ModEvaluateMany<T> for &UnsignedPolynomial<T>
Source§fn mod_evaluate_many(self, xs: &[T], m: T) -> Vec<T>
fn mod_evaluate_many(self, xs: &[T], m: T) -> Vec<T>
Evaluates an UnsignedPolynomial at each of several values of its coefficient type,
modulo a value of that type. The coefficients and the values must already be reduced modulo
m.
$$ f(p, (x_j){j=0}^{k-1}, m) = \left ( \sum{i=0}^{n-1} c_i x_j^i \bmod m \right )_{j=0}^{k-1}, $$
where $c_i$ is the coefficient of $x^i$ in $p$ and $n$ is its length.
The result is the same as calling
mod_evaluate at each value, with the same
choice between Horner’s rule and Shoup’s method, but the polynomial is checked once, and
several values are evaluated together in each pass over the coefficients. Horner’s rule is a
chain of dependent multiplications, so interleaving independent chains keeps the processor’s
multipliers busy.
§Worst-case complexity
$T(n, k) = O(nk)$
$M(k) = O(k)$
where $T$ is time, $M$ is additional memory, $n$ is self.len(), and $k$ is xs.len().
§Panics
Panics if m is 0, or if any coefficient of self or any value in xs is greater than or
equal to m.
§Examples
use core::str::FromStr;
use malachite_base::polynomial::ModEvaluateMany;
use malachite_base::unsigned_polynomial::UnsignedPolynomial;
let p = UnsignedPolynomial::<u8>::from_str("5*x^2+3*x+7").unwrap();
// 7, 15, 33, 61, 99, and 147, mod 13
assert_eq!(
(&p).mod_evaluate_many(&[0, 1, 2, 3, 4, 5], 13),
&[7, 2, 7, 9, 8, 4]
);This is equivalent to nmod_poly_evaluate_nmod_vec_iter from
nmod_poly/evaluate_nmod_vec.c, FLINT 3.6.0, except that the values must be reduced.
Source§impl<T: PrimitiveUnsigned> ModIntegral<T> for UnsignedPolynomial<T>
impl<T: PrimitiveUnsigned> ModIntegral<T> for UnsignedPolynomial<T>
Source§fn mod_integral(self, m: T) -> Self
fn mod_integral(self, m: T) -> Self
Computes the integral modulo $m$ of an UnsignedPolynomial whose constant term is zero,
taking the polynomial by value. Its coefficients must already be reduced modulo $m$.
$$ f(p, m) = \int_0^x p(t),dt \bmod m = \sum_{i=0}^{n-1} \frac{a_i}{i+1}x^{i+1} \bmod m. $$
The coefficient of $x^{k-1}$ is divided by $k$ and moved to $x^k$, so every $k$ for which that coefficient is nonzero must be a unit modulo $m$; a zero coefficient stays zero. The divisions share a single modular inversion. The integral of zero is zero, for every $m$.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is self.len().
§Panics
Panics if m is 0, if any coefficient is greater than or equal to m, or if, for some $k$,
the coefficient of $x^{k-1}$ is nonzero and $k$ is not a unit modulo $m$.
§Examples
use core::str::FromStr;
use malachite_base::polynomial::ModIntegral;
use malachite_base::unsigned_polynomial::UnsignedPolynomial;
assert_eq!(
UnsignedPolynomial::<u8>::from_str("3*x^2+4*x+5")
.unwrap()
.mod_integral(7)
.to_string(),
"x^3+2*x^2+5*x"
);
// Dividing by 3 is multiplying by 5 modulo 7.
assert_eq!(
UnsignedPolynomial::<u8>::from_str("x^2")
.unwrap()
.mod_integral(7)
.to_string(),
"5*x^3"
);This is equivalent to nmod_poly_integral from nmod_poly/integral.c, FLINT 3.6.0, except
that FLINT needs every $k$ from 1 to the degree plus 1 to be a unit modulo $m$, even when
the coefficient of $x^{k-1}$ is zero, and aborts otherwise; so, for example, FLINT cannot
integrate $x^2$ modulo 8, whose integral is $3x^3$.
type Output = UnsignedPolynomial<T>
Source§impl<T: PrimitiveUnsigned> ModIntegral<T> for &UnsignedPolynomial<T>
impl<T: PrimitiveUnsigned> ModIntegral<T> for &UnsignedPolynomial<T>
Source§fn mod_integral(self, m: T) -> UnsignedPolynomial<T>
fn mod_integral(self, m: T) -> UnsignedPolynomial<T>
Computes the integral modulo $m$ of an UnsignedPolynomial whose constant term is zero,
taking the polynomial by reference. Its coefficients must already be reduced modulo $m$.
$$ f(p, m) = \int_0^x p(t),dt \bmod m = \sum_{i=0}^{n-1} \frac{a_i}{i+1}x^{i+1} \bmod m. $$
The coefficient of $x^{k-1}$ is divided by $k$ and moved to $x^k$, so every $k$ for which that coefficient is nonzero must be a unit modulo $m$; a zero coefficient stays zero. The divisions share a single modular inversion. The integral of zero is zero, for every $m$.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is self.len().
§Panics
Panics if m is 0, if any coefficient is greater than or equal to m, or if, for some $k$,
the coefficient of $x^{k-1}$ is nonzero and $k$ is not a unit modulo $m$.
§Examples
use core::str::FromStr;
use malachite_base::polynomial::ModIntegral;
use malachite_base::unsigned_polynomial::UnsignedPolynomial;
assert_eq!(
(&UnsignedPolynomial::<u8>::from_str("3*x^2+4*x+5").unwrap())
.mod_integral(7)
.to_string(),
"x^3+2*x^2+5*x"
);
// Dividing by 3 is multiplying by 5 modulo 7.
assert_eq!(
(&UnsignedPolynomial::<u8>::from_str("x^2").unwrap())
.mod_integral(7)
.to_string(),
"5*x^3"
);This is equivalent to nmod_poly_integral from nmod_poly/integral.c, FLINT 3.6.0, except
that FLINT needs every $k$ from 1 to the degree plus 1 to be a unit modulo $m$, even when
the coefficient of $x^{k-1}$ is zero, and aborts otherwise; so, for example, FLINT cannot
integrate $x^2$ modulo 8, whose integral is $3x^3$.
type Output = UnsignedPolynomial<T>
Source§impl<T: PrimitiveUnsigned> ModIntegralAssign<T> for UnsignedPolynomial<T>
impl<T: PrimitiveUnsigned> ModIntegralAssign<T> for UnsignedPolynomial<T>
Source§fn mod_integral_assign(&mut self, m: T)
fn mod_integral_assign(&mut self, m: T)
Replaces an UnsignedPolynomial with its integral modulo $m$ whose constant term is zero.
Its coefficients must already be reduced modulo $m$.
$$ p \gets \int_0^x p(t),dt \bmod m = \sum_{i=0}^{n-1} \frac{a_i}{i+1}x^{i+1} \bmod m. $$
The coefficient of $x^{k-1}$ is divided by $k$ and moved to $x^k$, so every $k$ for which that coefficient is nonzero must be a unit modulo $m$; a zero coefficient stays zero. The divisions share a single modular inversion. The integral of zero is zero, for every $m$.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is self.len().
§Panics
Panics if m is 0, if any coefficient is greater than or equal to m, or if, for some $k$,
the coefficient of $x^{k-1}$ is nonzero and $k$ is not a unit modulo $m$.
§Examples
use core::str::FromStr;
use malachite_base::polynomial::ModIntegralAssign;
use malachite_base::unsigned_polynomial::UnsignedPolynomial;
let mut p = UnsignedPolynomial::<u8>::from_str("3*x^2+4*x+5").unwrap();
p.mod_integral_assign(7);
assert_eq!(p.to_string(), "x^3+2*x^2+5*x");This is equivalent to nmod_poly_integral from nmod_poly/integral.c, FLINT 3.6.0, except
that FLINT needs every $k$ from 1 to the degree plus 1 to be a unit modulo $m$, even when
the coefficient of $x^{k-1}$ is zero, and aborts otherwise; so, for example, FLINT cannot
integrate $x^2$ modulo 8, whose integral is $3x^3$.
Source§impl<T: PrimitiveUnsigned> ModIsReduced<T> for UnsignedPolynomial<T>
impl<T: PrimitiveUnsigned> ModIsReduced<T> for UnsignedPolynomial<T>
Source§fn mod_is_reduced(&self, m: &T) -> bool
fn mod_is_reduced(&self, m: &T) -> bool
Returns whether a UnsignedPolynomial is reduced modulo a u64 $m$; in other words,
whether every one of its coefficients is less than $m$.
Asking that of every coefficient is asking it of the largest, so this is a comparison
against the polynomial’s Height. The zero polynomial has no
coefficients and is reduced modulo every $m$.
$m$ cannot be zero.
$f(p, m) = (\max_i p_i < m)$.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is the number of coefficients.
§Panics
Panics if m is 0.
§Examples
use core::str::FromStr;
use malachite_base::num::arithmetic::traits::ModIsReduced;
use malachite_base::unsigned_polynomial::UnsignedPolynomial;
// The coefficients are 2, 3, and 1, so 4 is large enough and 3 is not.
let p = UnsignedPolynomial::<u64>::from_str("x^2+3*x+2").unwrap();
assert_eq!(p.mod_is_reduced(&4), true);
assert_eq!(p.mod_is_reduced(&3), false);
// The zero polynomial is reduced modulo everything.
assert_eq!(
UnsignedPolynomial::<u64>::from_str("0")
.unwrap()
.mod_is_reduced(&1),
true
);Source§impl<T: PrimitiveUnsigned> ModMakeMonic<T> for UnsignedPolynomial<T>
impl<T: PrimitiveUnsigned> ModMakeMonic<T> for UnsignedPolynomial<T>
Source§fn mod_make_monic(self, m: T) -> Result<Self, T>
fn mod_make_monic(self, m: T) -> Result<Self, T>
Makes an UnsignedPolynomial monic modulo m, by multiplying it by the inverse of its
leading coefficient, taking the polynomial by value. The coefficients must already be
reduced modulo m.
If the leading coefficient has no inverse modulo m, the error is its GCD with m, a
nontrivial factor of m. The zero polynomial is returned unchanged.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is self.len().
§Panics
Panics if m is 0, or if any coefficient of self is greater than or equal to m.
§Examples
use core::str::FromStr;
use malachite_base::num::basic::traits::Zero;
use malachite_base::polynomial::ModMakeMonic;
use malachite_base::unsigned_polynomial::UnsignedPolynomial;
// 3 * 5 = 15, which is 1 mod 7.
let p = UnsignedPolynomial::<u8>::from_str("3*x^2+x+2").unwrap();
assert_eq!(
p.clone().mod_make_monic(7).unwrap().to_string(),
"x^2+5*x+3"
);
// 2 has no inverse mod 4, and shares the factor 2 with it.
let p = UnsignedPolynomial::<u8>::from_str("2*x+1").unwrap();
assert_eq!(p.clone().mod_make_monic(4), Err(2));
assert_eq!(
UnsignedPolynomial::<u8>::ZERO.mod_make_monic(7),
Ok(UnsignedPolynomial::ZERO)
);This is equivalent to fmpz_mod_poly_make_monic_f from fmpz_mod_poly/make_monic.c, FLINT
3.6.0, with the factor returned as the error; nmod_poly_make_monic aborts instead.
Source§type Output = UnsignedPolynomial<T>
type Output = UnsignedPolynomial<T>
Source§impl<T: PrimitiveUnsigned> ModMakeMonic<T> for &UnsignedPolynomial<T>
impl<T: PrimitiveUnsigned> ModMakeMonic<T> for &UnsignedPolynomial<T>
Source§fn mod_make_monic(self, m: T) -> Result<UnsignedPolynomial<T>, T>
fn mod_make_monic(self, m: T) -> Result<UnsignedPolynomial<T>, T>
Makes an UnsignedPolynomial monic modulo m, by multiplying it by the inverse of its
leading coefficient, taking the polynomial by reference. The coefficients must already be
reduced modulo m.
If the leading coefficient has no inverse modulo m, the error is its GCD with m, a
nontrivial factor of m. The zero polynomial is returned unchanged.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is self.len().
§Panics
Panics if m is 0, or if any coefficient of self is greater than or equal to m.
§Examples
use core::str::FromStr;
use malachite_base::num::basic::traits::Zero;
use malachite_base::polynomial::ModMakeMonic;
use malachite_base::unsigned_polynomial::UnsignedPolynomial;
// 3 * 5 = 15, which is 1 mod 7.
let p = UnsignedPolynomial::<u8>::from_str("3*x^2+x+2").unwrap();
assert_eq!((&p).mod_make_monic(7).unwrap().to_string(), "x^2+5*x+3");
// 2 has no inverse mod 4, and shares the factor 2 with it.
let p = UnsignedPolynomial::<u8>::from_str("2*x+1").unwrap();
assert_eq!((&p).mod_make_monic(4), Err(2));
assert_eq!(
(&UnsignedPolynomial::<u8>::ZERO).mod_make_monic(7),
Ok(UnsignedPolynomial::ZERO)
);This is equivalent to fmpz_mod_poly_make_monic_f from fmpz_mod_poly/make_monic.c, FLINT
3.6.0, with the factor returned as the error; nmod_poly_make_monic aborts instead.
Source§type Output = UnsignedPolynomial<T>
type Output = UnsignedPolynomial<T>
Source§impl<T: PrimitiveUnsigned> ModMakeMonicAssign<T> for UnsignedPolynomial<T>
impl<T: PrimitiveUnsigned> ModMakeMonicAssign<T> for UnsignedPolynomial<T>
Source§fn mod_make_monic_assign(&mut self, m: T) -> Result<(), T>
fn mod_make_monic_assign(&mut self, m: T) -> Result<(), T>
Makes an UnsignedPolynomial monic modulo m in place, by multiplying it by the inverse
of its leading coefficient. The coefficients must already be reduced modulo m.
If the leading coefficient has no inverse modulo m, the polynomial is left unchanged and
the error is the leading coefficient’s GCD with m, a nontrivial factor of m. The zero
polynomial is left unchanged.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is self.len().
§Panics
Panics if m is 0, or if any coefficient of self is greater than or equal to m.
§Examples
use core::str::FromStr;
use malachite_base::polynomial::ModMakeMonicAssign;
use malachite_base::unsigned_polynomial::UnsignedPolynomial;
let mut p = UnsignedPolynomial::<u8>::from_str("3*x^2+x+2").unwrap();
assert_eq!(p.mod_make_monic_assign(7), Ok(()));
assert_eq!(p.to_string(), "x^2+5*x+3");
let mut p = UnsignedPolynomial::<u8>::from_str("2*x+1").unwrap();
assert_eq!(p.mod_make_monic_assign(4), Err(2));
assert_eq!(p.to_string(), "2*x+1");Source§impl<T: PrimitiveUnsigned> ModMul<&UnsignedPolynomial<T>, T> for UnsignedPolynomial<T>
impl<T: PrimitiveUnsigned> ModMul<&UnsignedPolynomial<T>, T> for UnsignedPolynomial<T>
Source§fn mod_mul(self, other: &Self, m: T) -> Self
fn mod_mul(self, other: &Self, m: T) -> Self
Multiplies two UnsignedPolynomials modulo $m$, taking the first by value and the second
by reference. The coefficients of both must already be reduced modulo $m$.
$$ f(p, q, m) = pq \bmod m. $$
When $m$ is not prime, the leading coefficient of the product can vanish modulo $m$, and then the degree of the product is lower than the sum of the degrees.
§Worst-case complexity
$T(n) = O(n^{\log_2 3})$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is the length of the longer polynomial.
§Panics
Panics if m is 0, or if any coefficient of self or other is greater than or equal to
m.
§Examples
use core::str::FromStr;
use malachite_base::num::arithmetic::traits::ModMul;
use malachite_base::unsigned_polynomial::UnsignedPolynomial;
// The product is 2*x^3+11*x^2+19*x+10; its coefficients modulo 7.
assert_eq!(
UnsignedPolynomial::<u8>::from_str("x^2+3*x+2")
.unwrap()
.mod_mul(&UnsignedPolynomial::<u8>::from_str("2*x+5").unwrap(), 7)
.to_string(),
"2*x^3+4*x^2+5*x+3"
);
// The leading coefficient of the product, 6, vanishes modulo 6, so the degree drops.
assert_eq!(
UnsignedPolynomial::<u8>::from_str("2*x+1")
.unwrap()
.mod_mul(&UnsignedPolynomial::<u8>::from_str("3*x+1").unwrap(), 6)
.to_string(),
"5*x+1"
);This is equivalent to nmod_poly_mul from nmod_poly/mul.c, FLINT 3.6.0.
type Output = UnsignedPolynomial<T>
Source§impl<T: PrimitiveUnsigned> ModMul<&UnsignedPolynomial<T>, T> for &UnsignedPolynomial<T>
impl<T: PrimitiveUnsigned> ModMul<&UnsignedPolynomial<T>, T> for &UnsignedPolynomial<T>
Source§fn mod_mul(self, other: &UnsignedPolynomial<T>, m: T) -> UnsignedPolynomial<T>
fn mod_mul(self, other: &UnsignedPolynomial<T>, m: T) -> UnsignedPolynomial<T>
Multiplies two UnsignedPolynomials modulo $m$, taking both by reference. The
coefficients of both must already be reduced modulo $m$.
$$ f(p, q, m) = pq \bmod m. $$
When $m$ is not prime, the leading coefficient of the product can vanish modulo $m$, and then the degree of the product is lower than the sum of the degrees.
§Worst-case complexity
$T(n) = O(n^{\log_2 3})$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is the length of the longer polynomial.
§Panics
Panics if m is 0, or if any coefficient of self or other is greater than or equal to
m.
§Examples
use core::str::FromStr;
use malachite_base::num::arithmetic::traits::ModMul;
use malachite_base::unsigned_polynomial::UnsignedPolynomial;
// The product is 2*x^3+11*x^2+19*x+10; its coefficients modulo 7.
assert_eq!(
(&UnsignedPolynomial::<u8>::from_str("x^2+3*x+2").unwrap())
.mod_mul(&UnsignedPolynomial::<u8>::from_str("2*x+5").unwrap(), 7)
.to_string(),
"2*x^3+4*x^2+5*x+3"
);
// The leading coefficient of the product, 6, vanishes modulo 6, so the degree drops.
assert_eq!(
(&UnsignedPolynomial::<u8>::from_str("2*x+1").unwrap())
.mod_mul(&UnsignedPolynomial::<u8>::from_str("3*x+1").unwrap(), 6)
.to_string(),
"5*x+1"
);This is equivalent to nmod_poly_mul from nmod_poly/mul.c, FLINT 3.6.0.
type Output = UnsignedPolynomial<T>
Source§impl<T: PrimitiveUnsigned> ModMul<UnsignedPolynomial<T>, T> for UnsignedPolynomial<T>
impl<T: PrimitiveUnsigned> ModMul<UnsignedPolynomial<T>, T> for UnsignedPolynomial<T>
Source§fn mod_mul(self, other: Self, m: T) -> Self
fn mod_mul(self, other: Self, m: T) -> Self
Multiplies two UnsignedPolynomials modulo $m$, taking both by value. The coefficients of
both must already be reduced modulo $m$.
$$ f(p, q, m) = pq \bmod m. $$
When $m$ is not prime, the leading coefficient of the product can vanish modulo $m$, and then the degree of the product is lower than the sum of the degrees.
§Worst-case complexity
$T(n) = O(n^{\log_2 3})$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is the length of the longer polynomial.
§Panics
Panics if m is 0, or if any coefficient of self or other is greater than or equal to
m.
§Examples
use core::str::FromStr;
use malachite_base::num::arithmetic::traits::ModMul;
use malachite_base::unsigned_polynomial::UnsignedPolynomial;
// The product is 2*x^3+11*x^2+19*x+10; its coefficients modulo 7.
assert_eq!(
UnsignedPolynomial::<u8>::from_str("x^2+3*x+2")
.unwrap()
.mod_mul(UnsignedPolynomial::<u8>::from_str("2*x+5").unwrap(), 7)
.to_string(),
"2*x^3+4*x^2+5*x+3"
);
// The leading coefficient of the product, 6, vanishes modulo 6, so the degree drops.
assert_eq!(
UnsignedPolynomial::<u8>::from_str("2*x+1")
.unwrap()
.mod_mul(UnsignedPolynomial::<u8>::from_str("3*x+1").unwrap(), 6)
.to_string(),
"5*x+1"
);This is equivalent to nmod_poly_mul from nmod_poly/mul.c, FLINT 3.6.0.
type Output = UnsignedPolynomial<T>
Source§impl<T: PrimitiveUnsigned> ModMul<UnsignedPolynomial<T>, T> for &UnsignedPolynomial<T>
impl<T: PrimitiveUnsigned> ModMul<UnsignedPolynomial<T>, T> for &UnsignedPolynomial<T>
Source§fn mod_mul(self, other: UnsignedPolynomial<T>, m: T) -> UnsignedPolynomial<T>
fn mod_mul(self, other: UnsignedPolynomial<T>, m: T) -> UnsignedPolynomial<T>
Multiplies two UnsignedPolynomials modulo $m$, taking the first by reference and the
second by value. The coefficients of both must already be reduced modulo $m$.
$$ f(p, q, m) = pq \bmod m. $$
When $m$ is not prime, the leading coefficient of the product can vanish modulo $m$, and then the degree of the product is lower than the sum of the degrees.
§Worst-case complexity
$T(n) = O(n^{\log_2 3})$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is the length of the longer polynomial.
§Panics
Panics if m is 0, or if any coefficient of self or other is greater than or equal to
m.
§Examples
use core::str::FromStr;
use malachite_base::num::arithmetic::traits::ModMul;
use malachite_base::unsigned_polynomial::UnsignedPolynomial;
// The product is 2*x^3+11*x^2+19*x+10; its coefficients modulo 7.
assert_eq!(
(&UnsignedPolynomial::<u8>::from_str("x^2+3*x+2").unwrap())
.mod_mul(UnsignedPolynomial::<u8>::from_str("2*x+5").unwrap(), 7)
.to_string(),
"2*x^3+4*x^2+5*x+3"
);
// The leading coefficient of the product, 6, vanishes modulo 6, so the degree drops.
assert_eq!(
(&UnsignedPolynomial::<u8>::from_str("2*x+1").unwrap())
.mod_mul(UnsignedPolynomial::<u8>::from_str("3*x+1").unwrap(), 6)
.to_string(),
"5*x+1"
);This is equivalent to nmod_poly_mul from nmod_poly/mul.c, FLINT 3.6.0.
type Output = UnsignedPolynomial<T>
Source§impl<T: PrimitiveUnsigned> ModMulAssign<&UnsignedPolynomial<T>, T> for UnsignedPolynomial<T>
impl<T: PrimitiveUnsigned> ModMulAssign<&UnsignedPolynomial<T>, T> for UnsignedPolynomial<T>
Source§fn mod_mul_assign(&mut self, other: &Self, m: T)
fn mod_mul_assign(&mut self, other: &Self, m: T)
Multiplies an UnsignedPolynomial by another UnsignedPolynomial modulo $m$ in place,
taking the right-hand side by reference. The coefficients of both must already be reduced
modulo $m$.
$$ p \gets pq \bmod m. $$
§Worst-case complexity
$T(n) = O(n^{\log_2 3})$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is the length of the longer polynomial.
§Panics
Panics if m is 0, or if any coefficient of self or other is greater than or equal to
m.
§Examples
use core::str::FromStr;
use malachite_base::num::arithmetic::traits::ModMulAssign;
use malachite_base::unsigned_polynomial::UnsignedPolynomial;
let mut p = UnsignedPolynomial::<u8>::from_str("x^2+3*x+2").unwrap();
p.mod_mul_assign(&UnsignedPolynomial::<u8>::from_str("2*x+5").unwrap(), 7);
assert_eq!(p.to_string(), "2*x^3+4*x^2+5*x+3");This is equivalent to nmod_poly_mul from nmod_poly/mul.c, FLINT 3.6.0.
Source§impl<T: PrimitiveUnsigned> ModMulAssign<UnsignedPolynomial<T>, T> for UnsignedPolynomial<T>
impl<T: PrimitiveUnsigned> ModMulAssign<UnsignedPolynomial<T>, T> for UnsignedPolynomial<T>
Source§fn mod_mul_assign(&mut self, other: Self, m: T)
fn mod_mul_assign(&mut self, other: Self, m: T)
Multiplies an UnsignedPolynomial by another UnsignedPolynomial modulo $m$ in place,
taking the right-hand side by value. The coefficients of both must already be reduced modulo
$m$.
$$ p \gets pq \bmod m. $$
§Worst-case complexity
$T(n) = O(n^{\log_2 3})$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is the length of the longer polynomial.
§Panics
Panics if m is 0, or if any coefficient of self or other is greater than or equal to
m.
§Examples
use core::str::FromStr;
use malachite_base::num::arithmetic::traits::ModMulAssign;
use malachite_base::unsigned_polynomial::UnsignedPolynomial;
let mut p = UnsignedPolynomial::<u8>::from_str("x^2+3*x+2").unwrap();
p.mod_mul_assign(UnsignedPolynomial::<u8>::from_str("2*x+5").unwrap(), 7);
assert_eq!(p.to_string(), "2*x^3+4*x^2+5*x+3");This is equivalent to nmod_poly_mul from nmod_poly/mul.c, FLINT 3.6.0.
Source§impl<T: PrimitiveUnsigned> ModMulTruncated<&UnsignedPolynomial<T>, T> for UnsignedPolynomial<T>
impl<T: PrimitiveUnsigned> ModMulTruncated<&UnsignedPolynomial<T>, T> for UnsignedPolynomial<T>
Source§fn mod_mul_truncated(self, other: &Self, len: u64, m: T) -> Self
fn mod_mul_truncated(self, other: &Self, len: u64, m: T) -> Self
Multiplies two UnsignedPolynomials modulo $m$, keeping only the coefficients of $x^i$
for $i$ less than len, taking the first by value and the second by reference. The
coefficients of both must already be reduced modulo $m$.
$$ f(p, q, n, m) = (pq \bmod x^n) \bmod m. $$
The polynomials need not already be truncated: this is the product of their images modulo
$x^n$, so only their first len coefficients are read.
§Worst-case complexity
$T(n) = O(n^{\log_2 3})$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is len.
§Panics
Panics if m is 0, or if any coefficient of self or other is greater than or equal to
m.
§Examples
use core::str::FromStr;
use malachite_base::polynomial::ModMulTruncated;
use malachite_base::unsigned_polynomial::UnsignedPolynomial;
// The product is 2*x^3+11*x^2+19*x+10; its low two coefficients, modulo 7.
assert_eq!(
UnsignedPolynomial::<u8>::from_str("x^2+3*x+2")
.unwrap()
.mod_mul_truncated(&UnsignedPolynomial::<u8>::from_str("2*x+5").unwrap(), 2, 7)
.to_string(),
"5*x+3"
);
// The linear coefficient of the product, 7, vanishes modulo 7.
assert_eq!(
UnsignedPolynomial::<u8>::from_str("x+6")
.unwrap()
.mod_mul_truncated(&UnsignedPolynomial::<u8>::from_str("x+1").unwrap(), 2, 7)
.to_string(),
"6"
);This is equivalent to nmod_poly_mullow from nmod_poly/mullow.c, FLINT 3.6.0.
type Output = UnsignedPolynomial<T>
Source§impl<T: PrimitiveUnsigned> ModMulTruncated<&UnsignedPolynomial<T>, T> for &UnsignedPolynomial<T>
impl<T: PrimitiveUnsigned> ModMulTruncated<&UnsignedPolynomial<T>, T> for &UnsignedPolynomial<T>
Source§fn mod_mul_truncated(
self,
other: &UnsignedPolynomial<T>,
len: u64,
m: T,
) -> UnsignedPolynomial<T>
fn mod_mul_truncated( self, other: &UnsignedPolynomial<T>, len: u64, m: T, ) -> UnsignedPolynomial<T>
Multiplies two UnsignedPolynomials modulo $m$, keeping only the coefficients of $x^i$
for $i$ less than len, taking both by reference. The coefficients of both must already be
reduced modulo $m$.
$$ f(p, q, n, m) = (pq \bmod x^n) \bmod m. $$
The polynomials need not already be truncated: this is the product of their images modulo
$x^n$, so only their first len coefficients are read.
§Worst-case complexity
$T(n) = O(n^{\log_2 3})$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is len.
§Panics
Panics if m is 0, or if any coefficient of self or other is greater than or equal to
m.
§Examples
use core::str::FromStr;
use malachite_base::polynomial::ModMulTruncated;
use malachite_base::unsigned_polynomial::UnsignedPolynomial;
// The product is 2*x^3+11*x^2+19*x+10; its low two coefficients, modulo 7.
assert_eq!(
(&UnsignedPolynomial::<u8>::from_str("x^2+3*x+2").unwrap())
.mod_mul_truncated(&UnsignedPolynomial::<u8>::from_str("2*x+5").unwrap(), 2, 7)
.to_string(),
"5*x+3"
);
// The linear coefficient of the product, 7, vanishes modulo 7.
assert_eq!(
(&UnsignedPolynomial::<u8>::from_str("x+6").unwrap())
.mod_mul_truncated(&UnsignedPolynomial::<u8>::from_str("x+1").unwrap(), 2, 7)
.to_string(),
"6"
);This is equivalent to nmod_poly_mullow from nmod_poly/mullow.c, FLINT 3.6.0.
type Output = UnsignedPolynomial<T>
Source§impl<T: PrimitiveUnsigned> ModMulTruncated<UnsignedPolynomial<T>, T> for UnsignedPolynomial<T>
impl<T: PrimitiveUnsigned> ModMulTruncated<UnsignedPolynomial<T>, T> for UnsignedPolynomial<T>
Source§fn mod_mul_truncated(self, other: Self, len: u64, m: T) -> Self
fn mod_mul_truncated(self, other: Self, len: u64, m: T) -> Self
Multiplies two UnsignedPolynomials modulo $m$, keeping only the coefficients of $x^i$
for $i$ less than len, taking both by value. The coefficients of both must already be
reduced modulo $m$.
$$ f(p, q, n, m) = (pq \bmod x^n) \bmod m. $$
The polynomials need not already be truncated: this is the product of their images modulo
$x^n$, so only their first len coefficients are read.
§Worst-case complexity
$T(n) = O(n^{\log_2 3})$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is len.
§Panics
Panics if m is 0, or if any coefficient of self or other is greater than or equal to
m.
§Examples
use core::str::FromStr;
use malachite_base::polynomial::ModMulTruncated;
use malachite_base::unsigned_polynomial::UnsignedPolynomial;
// The product is 2*x^3+11*x^2+19*x+10; its low two coefficients, modulo 7.
assert_eq!(
UnsignedPolynomial::<u8>::from_str("x^2+3*x+2")
.unwrap()
.mod_mul_truncated(UnsignedPolynomial::<u8>::from_str("2*x+5").unwrap(), 2, 7)
.to_string(),
"5*x+3"
);
// The linear coefficient of the product, 7, vanishes modulo 7.
assert_eq!(
UnsignedPolynomial::<u8>::from_str("x+6")
.unwrap()
.mod_mul_truncated(UnsignedPolynomial::<u8>::from_str("x+1").unwrap(), 2, 7)
.to_string(),
"6"
);This is equivalent to nmod_poly_mullow from nmod_poly/mullow.c, FLINT 3.6.0.
type Output = UnsignedPolynomial<T>
Source§impl<T: PrimitiveUnsigned> ModMulTruncated<UnsignedPolynomial<T>, T> for &UnsignedPolynomial<T>
impl<T: PrimitiveUnsigned> ModMulTruncated<UnsignedPolynomial<T>, T> for &UnsignedPolynomial<T>
Source§fn mod_mul_truncated(
self,
other: UnsignedPolynomial<T>,
len: u64,
m: T,
) -> UnsignedPolynomial<T>
fn mod_mul_truncated( self, other: UnsignedPolynomial<T>, len: u64, m: T, ) -> UnsignedPolynomial<T>
Multiplies two UnsignedPolynomials modulo $m$, keeping only the coefficients of $x^i$
for $i$ less than len, taking the first by reference and the second by value. The
coefficients of both must already be reduced modulo $m$.
$$ f(p, q, n, m) = (pq \bmod x^n) \bmod m. $$
The polynomials need not already be truncated: this is the product of their images modulo
$x^n$, so only their first len coefficients are read.
§Worst-case complexity
$T(n) = O(n^{\log_2 3})$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is len.
§Panics
Panics if m is 0, or if any coefficient of self or other is greater than or equal to
m.
§Examples
use core::str::FromStr;
use malachite_base::polynomial::ModMulTruncated;
use malachite_base::unsigned_polynomial::UnsignedPolynomial;
// The product is 2*x^3+11*x^2+19*x+10; its low two coefficients, modulo 7.
assert_eq!(
(&UnsignedPolynomial::<u8>::from_str("x^2+3*x+2").unwrap())
.mod_mul_truncated(UnsignedPolynomial::<u8>::from_str("2*x+5").unwrap(), 2, 7)
.to_string(),
"5*x+3"
);
// The linear coefficient of the product, 7, vanishes modulo 7.
assert_eq!(
(&UnsignedPolynomial::<u8>::from_str("x+6").unwrap())
.mod_mul_truncated(UnsignedPolynomial::<u8>::from_str("x+1").unwrap(), 2, 7)
.to_string(),
"6"
);This is equivalent to nmod_poly_mullow from nmod_poly/mullow.c, FLINT 3.6.0.
type Output = UnsignedPolynomial<T>
Source§impl<T: PrimitiveUnsigned> ModMulTruncatedAssign<&UnsignedPolynomial<T>, T> for UnsignedPolynomial<T>
impl<T: PrimitiveUnsigned> ModMulTruncatedAssign<&UnsignedPolynomial<T>, T> for UnsignedPolynomial<T>
Source§fn mod_mul_truncated_assign(&mut self, other: &Self, len: u64, m: T)
fn mod_mul_truncated_assign(&mut self, other: &Self, len: u64, m: T)
Multiplies an UnsignedPolynomial by another UnsignedPolynomial modulo $m$ in place,
keeping only the coefficients of $x^i$ for $i$ less than len, taking the right-hand side
by reference. The coefficients of both must already be reduced modulo $m$.
$$ p \gets (pq \bmod x^n) \bmod m. $$
§Worst-case complexity
$T(n) = O(n^{\log_2 3})$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is len.
§Panics
Panics if m is 0, or if any coefficient of self or other is greater than or equal to
m.
§Examples
use core::str::FromStr;
use malachite_base::polynomial::ModMulTruncatedAssign;
use malachite_base::unsigned_polynomial::UnsignedPolynomial;
let mut p = UnsignedPolynomial::<u8>::from_str("x^2+3*x+2").unwrap();
p.mod_mul_truncated_assign(&UnsignedPolynomial::<u8>::from_str("2*x+5").unwrap(), 2, 7);
assert_eq!(p.to_string(), "5*x+3");This is equivalent to nmod_poly_mullow from nmod_poly/mullow.c, FLINT 3.6.0.
Source§impl<T: PrimitiveUnsigned> ModMulTruncatedAssign<UnsignedPolynomial<T>, T> for UnsignedPolynomial<T>
impl<T: PrimitiveUnsigned> ModMulTruncatedAssign<UnsignedPolynomial<T>, T> for UnsignedPolynomial<T>
Source§fn mod_mul_truncated_assign(&mut self, other: Self, len: u64, m: T)
fn mod_mul_truncated_assign(&mut self, other: Self, len: u64, m: T)
Multiplies an UnsignedPolynomial by another UnsignedPolynomial modulo $m$ in place,
keeping only the coefficients of $x^i$ for $i$ less than len, taking the right-hand side
by value. The coefficients of both must already be reduced modulo $m$.
$$ p \gets (pq \bmod x^n) \bmod m. $$
§Worst-case complexity
$T(n) = O(n^{\log_2 3})$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is len.
§Panics
Panics if m is 0, or if any coefficient of self or other is greater than or equal to
m.
§Examples
use core::str::FromStr;
use malachite_base::polynomial::ModMulTruncatedAssign;
use malachite_base::unsigned_polynomial::UnsignedPolynomial;
let mut p = UnsignedPolynomial::<u8>::from_str("x^2+3*x+2").unwrap();
p.mod_mul_truncated_assign(UnsignedPolynomial::<u8>::from_str("2*x+5").unwrap(), 2, 7);
assert_eq!(p.to_string(), "5*x+3");This is equivalent to nmod_poly_mullow from nmod_poly/mullow.c, FLINT 3.6.0.
Source§impl<T: PrimitiveUnsigned> ModNeg<T> for UnsignedPolynomial<T>
impl<T: PrimitiveUnsigned> ModNeg<T> for UnsignedPolynomial<T>
Source§fn mod_neg(self, m: T) -> Self
fn mod_neg(self, m: T) -> Self
Negates an UnsignedPolynomial modulo m, taking the polynomial by value. The
coefficients must already be reduced modulo m.
Each nonzero coefficient $c$ becomes $m - c$, which is also nonzero, so the degree is unchanged. The zero polynomial is its own negation.
$$ f(p, m) = -p \bmod m. $$
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is self.len().
§Panics
Panics if m is 0, or if any coefficient of self is greater than or equal to m.
§Examples
use core::str::FromStr;
use malachite_base::num::arithmetic::traits::ModNeg;
use malachite_base::num::basic::traits::Zero;
use malachite_base::unsigned_polynomial::UnsignedPolynomial;
let p = UnsignedPolynomial::<u8>::from_str("5*x^2+x+3").unwrap();
assert_eq!(p.clone().mod_neg(7).to_string(), "2*x^2+6*x+4");
assert_eq!(
UnsignedPolynomial::<u8>::ZERO.mod_neg(7),
UnsignedPolynomial::<u8>::ZERO
);This is equivalent to nmod_poly_neg from nmod_poly/neg.c, FLINT 3.6.0.
type Output = UnsignedPolynomial<T>
Source§impl<T: PrimitiveUnsigned> ModNeg<T> for &UnsignedPolynomial<T>
impl<T: PrimitiveUnsigned> ModNeg<T> for &UnsignedPolynomial<T>
Source§fn mod_neg(self, m: T) -> UnsignedPolynomial<T>
fn mod_neg(self, m: T) -> UnsignedPolynomial<T>
Negates an UnsignedPolynomial modulo m, taking the polynomial by reference. The
coefficients must already be reduced modulo m.
Each nonzero coefficient $c$ becomes $m - c$, which is also nonzero, so the degree is unchanged. The zero polynomial is its own negation.
$$ f(p, m) = -p \bmod m. $$
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is self.len().
§Panics
Panics if m is 0, or if any coefficient of self is greater than or equal to m.
§Examples
use core::str::FromStr;
use malachite_base::num::arithmetic::traits::ModNeg;
use malachite_base::num::basic::traits::Zero;
use malachite_base::unsigned_polynomial::UnsignedPolynomial;
let p = UnsignedPolynomial::<u8>::from_str("5*x^2+x+3").unwrap();
assert_eq!((&p).mod_neg(7).to_string(), "2*x^2+6*x+4");
assert_eq!(
(&UnsignedPolynomial::<u8>::ZERO).mod_neg(7),
UnsignedPolynomial::<u8>::ZERO
);This is equivalent to nmod_poly_neg from nmod_poly/neg.c, FLINT 3.6.0.
type Output = UnsignedPolynomial<T>
Source§impl<T: PrimitiveUnsigned> ModNegAssign<T> for UnsignedPolynomial<T>
impl<T: PrimitiveUnsigned> ModNegAssign<T> for UnsignedPolynomial<T>
Source§fn mod_neg_assign(&mut self, m: T)
fn mod_neg_assign(&mut self, m: T)
Negates an UnsignedPolynomial modulo m, in place. The coefficients must already be
reduced modulo m.
See mod_neg.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is self.len().
§Panics
Panics if m is 0, or if any coefficient of self is greater than or equal to m.
§Examples
use core::str::FromStr;
use malachite_base::num::arithmetic::traits::ModNegAssign;
use malachite_base::unsigned_polynomial::UnsignedPolynomial;
let mut p = UnsignedPolynomial::<u8>::from_str("5*x^2+x+3").unwrap();
p.mod_neg_assign(7);
assert_eq!(p.to_string(), "2*x^2+6*x+4");Source§impl<T: PrimitiveUnsigned> ModNthDerivative<T> for UnsignedPolynomial<T>
impl<T: PrimitiveUnsigned> ModNthDerivative<T> for UnsignedPolynomial<T>
Source§fn mod_nth_derivative(self, n: u64, m: T) -> Self
fn mod_nth_derivative(self, n: u64, m: T) -> Self
Computes the $n$th derivative of an UnsignedPolynomial modulo m, taking the polynomial
by value. The coefficients must already be reduced modulo m.
$$ f(p, n, m) = p^{(n)} \bmod m. $$
The coefficient of $x^i$ is multiplied by the falling factorial $i^{\underline n} =
i(i-1)\cdots(i-n+1)$, reduced, and moved to $x^{i-n}$. The products can be zero even when
the coefficients are not, so the derivative can lose any number of degrees; if m divides
$n!$, every falling factorial is a multiple of the modulus, and the result is zero.
§Worst-case complexity
$T(k, n) = O(kn)$
$M(k) = O(k)$
where $T$ is time, $M$ is additional memory, $k$ is self.len(), and $n$ is n.
§Panics
Panics if m is 0, or if any coefficient of self is greater than or equal to m.
§Examples
use core::str::FromStr;
use malachite_base::polynomial::ModNthDerivative;
use malachite_base::unsigned_polynomial::UnsignedPolynomial;
let p = UnsignedPolynomial::<u8>::from_str("x^4+3*x^3+2*x+4").unwrap();
assert_eq!(p.clone().mod_nth_derivative(2, 5).to_string(), "2*x^2+3*x");
assert_eq!(p.mod_nth_derivative(0, 5).to_string(), "x^4+3*x^3+2*x+4");
// 6 divides 3!.
let p = UnsignedPolynomial::<u8>::from_str("x^4+x^3").unwrap();
assert_eq!(p.mod_nth_derivative(3, 6).to_string(), "0");FLINT has no nmod_poly_nth_derivative; this computes the same multipliers as
fmpz_poly_nth_derivative from fmpz_poly/nth_derivative.c, FLINT 3.6.0, directly modulo
m.
type Output = UnsignedPolynomial<T>
Source§impl<T: PrimitiveUnsigned> ModNthDerivative<T> for &UnsignedPolynomial<T>
impl<T: PrimitiveUnsigned> ModNthDerivative<T> for &UnsignedPolynomial<T>
Source§fn mod_nth_derivative(self, n: u64, m: T) -> UnsignedPolynomial<T>
fn mod_nth_derivative(self, n: u64, m: T) -> UnsignedPolynomial<T>
Computes the $n$th derivative of an UnsignedPolynomial modulo m, taking the polynomial
by reference. The coefficients must already be reduced modulo m.
$$ f(p, n, m) = p^{(n)} \bmod m. $$
The coefficient of $x^i$ is multiplied by the falling factorial $i^{\underline n} =
i(i-1)\cdots(i-n+1)$, reduced, and moved to $x^{i-n}$. The products can be zero even when
the coefficients are not, so the derivative can lose any number of degrees; if m divides
$n!$, every falling factorial is a multiple of the modulus, and the result is zero.
§Worst-case complexity
$T(k, n) = O(kn)$
$M(k) = O(k)$
where $T$ is time, $M$ is additional memory, $k$ is self.len(), and $n$ is n.
§Panics
Panics if m is 0, or if any coefficient of self is greater than or equal to m.
§Examples
use core::str::FromStr;
use malachite_base::polynomial::ModNthDerivative;
use malachite_base::unsigned_polynomial::UnsignedPolynomial;
let p = UnsignedPolynomial::<u8>::from_str("x^4+3*x^3+2*x+4").unwrap();
assert_eq!((&p).mod_nth_derivative(2, 5).to_string(), "2*x^2+3*x");
assert_eq!((&p).mod_nth_derivative(0, 5).to_string(), "x^4+3*x^3+2*x+4");
// 6 divides 3!.
let p = UnsignedPolynomial::<u8>::from_str("x^4+x^3").unwrap();
assert_eq!((&p).mod_nth_derivative(3, 6).to_string(), "0");FLINT has no nmod_poly_nth_derivative; this computes the same multipliers as
fmpz_poly_nth_derivative from fmpz_poly/nth_derivative.c, FLINT 3.6.0, directly modulo
m.
type Output = UnsignedPolynomial<T>
Source§impl<T: PrimitiveUnsigned> ModNthDerivativeAssign<T> for UnsignedPolynomial<T>
impl<T: PrimitiveUnsigned> ModNthDerivativeAssign<T> for UnsignedPolynomial<T>
Source§fn mod_nth_derivative_assign(&mut self, n: u64, m: T)
fn mod_nth_derivative_assign(&mut self, n: u64, m: T)
Replaces an UnsignedPolynomial with its $n$th derivative modulo m, in place. The
coefficients must already be reduced modulo m.
$$ p \gets p^{(n)} \bmod m. $$
The coefficient of $x^i$ is multiplied by the falling factorial $i^{\underline n} =
i(i-1)\cdots(i-n+1)$, reduced, and moved to $x^{i-n}$. The products can be zero even when
the coefficients are not, so the derivative can lose any number of degrees; if m divides
$n!$, every falling factorial is a multiple of the modulus, and the result is zero.
§Worst-case complexity
$T(k, n) = O(kn)$
$M(k) = O(k)$
where $T$ is time, $M$ is additional memory, $k$ is self.len(), and $n$ is n.
§Panics
Panics if m is 0, or if any coefficient of self is greater than or equal to m.
§Examples
use core::str::FromStr;
use malachite_base::polynomial::ModNthDerivativeAssign;
use malachite_base::unsigned_polynomial::UnsignedPolynomial;
let mut p = UnsignedPolynomial::<u8>::from_str("x^4+3*x^3+2*x+4").unwrap();
p.mod_nth_derivative_assign(2, 5);
assert_eq!(p.to_string(), "2*x^2+3*x");
// 6 divides 3!.
let mut p = UnsignedPolynomial::<u8>::from_str("x^4+x^3").unwrap();
p.mod_nth_derivative_assign(3, 6);
assert_eq!(p.to_string(), "0");FLINT has no nmod_poly_nth_derivative; this computes the same multipliers as
fmpz_poly_nth_derivative from fmpz_poly/nth_derivative.c, FLINT 3.6.0, directly modulo
m.
Source§impl<T: PrimitiveUnsigned> ModPow<u64, T> for UnsignedPolynomial<T>
impl<T: PrimitiveUnsigned> ModPow<u64, T> for UnsignedPolynomial<T>
Source§fn mod_pow(self, exp: u64, m: T) -> Self
fn mod_pow(self, exp: u64, m: T) -> Self
Raises an UnsignedPolynomial to a power modulo $m$, taking it by value. Its coefficients
must already be reduced modulo $m$.
$$ f(p, e, k) = p^e \bmod m. $$
The zeroth power of every polynomial, including 0, is 1, which is 0 modulo 1. When m is
not prime, the leading coefficients of a power can vanish modulo m, and then its degree is
lower than $e$ times the degree of the polynomial. The power is computed by repeated
squaring modulo $m$.
§Worst-case complexity
$T(n) = O(n^{\log_2 3} \log e)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, $n$ is exp times the length of the
polynomial, and $e$ is exp.
§Panics
Panics if m is 0, or if any coefficient of self is greater than or equal to m.
§Examples
use core::str::FromStr;
use malachite_base::num::arithmetic::traits::ModPow;
use malachite_base::unsigned_polynomial::UnsignedPolynomial;
assert_eq!(
(UnsignedPolynomial::<u8>::from_str("x+1").unwrap())
.mod_pow(5, 7)
.to_string(),
"x^5+5*x^4+3*x^3+3*x^2+5*x+1"
);
// The square of 2*x+1 is 4*x^2+4*x+1, which is 1 modulo 4.
assert_eq!(
(UnsignedPolynomial::<u8>::from_str("2*x+1").unwrap())
.mod_pow(2, 4)
.to_string(),
"1"
);This is equivalent to nmod_poly_pow from nmod_poly/pow.c, FLINT 3.6.0, except that a
factor of $x^\ell$ is removed before powering and that the intermediate powers are trimmed.
type Output = UnsignedPolynomial<T>
Source§impl<T: PrimitiveUnsigned> ModPow<u64, T> for &UnsignedPolynomial<T>
impl<T: PrimitiveUnsigned> ModPow<u64, T> for &UnsignedPolynomial<T>
Source§fn mod_pow(self, exp: u64, m: T) -> UnsignedPolynomial<T>
fn mod_pow(self, exp: u64, m: T) -> UnsignedPolynomial<T>
Raises an UnsignedPolynomial to a power modulo $m$, taking it by reference. Its
coefficients must already be reduced modulo $m$.
$$ f(p, e, k) = p^e \bmod m. $$
The zeroth power of every polynomial, including 0, is 1, which is 0 modulo 1. When m is
not prime, the leading coefficients of a power can vanish modulo m, and then its degree is
lower than $e$ times the degree of the polynomial. The power is computed by repeated
squaring modulo $m$.
§Worst-case complexity
$T(n) = O(n^{\log_2 3} \log e)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, $n$ is exp times the length of the
polynomial, and $e$ is exp.
§Panics
Panics if m is 0, or if any coefficient of self is greater than or equal to m.
§Examples
use core::str::FromStr;
use malachite_base::num::arithmetic::traits::ModPow;
use malachite_base::unsigned_polynomial::UnsignedPolynomial;
assert_eq!(
(&UnsignedPolynomial::<u8>::from_str("x+1").unwrap())
.mod_pow(5, 7)
.to_string(),
"x^5+5*x^4+3*x^3+3*x^2+5*x+1"
);
// The square of 2*x+1 is 4*x^2+4*x+1, which is 1 modulo 4.
assert_eq!(
(&UnsignedPolynomial::<u8>::from_str("2*x+1").unwrap())
.mod_pow(2, 4)
.to_string(),
"1"
);This is equivalent to nmod_poly_pow from nmod_poly/pow.c, FLINT 3.6.0, except that a
factor of $x^\ell$ is removed before powering and that the intermediate powers are trimmed.
type Output = UnsignedPolynomial<T>
Source§impl<T: PrimitiveUnsigned> ModPowAssign<u64, T> for UnsignedPolynomial<T>
impl<T: PrimitiveUnsigned> ModPowAssign<u64, T> for UnsignedPolynomial<T>
Source§fn mod_pow_assign(&mut self, exp: u64, m: T)
fn mod_pow_assign(&mut self, exp: u64, m: T)
Raises an UnsignedPolynomial to a power modulo $m$ in place. Its coefficients must
already be reduced modulo $m$.
$$ p \gets p^e \bmod m. $$
The zeroth power of every polynomial, including 0, is 1, which is 0 modulo 1. When m is
not prime, the leading coefficients of a power can vanish modulo m, and then its degree is
lower than $e$ times the degree of the polynomial. The power is computed by repeated
squaring modulo $m$.
§Worst-case complexity
$T(n) = O(n^{\log_2 3} \log e)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, $n$ is exp times the length of the
polynomial, and $e$ is exp.
§Panics
Panics if m is 0, or if any coefficient of self is greater than or equal to m.
§Examples
use core::str::FromStr;
use malachite_base::num::arithmetic::traits::ModPowAssign;
use malachite_base::unsigned_polynomial::UnsignedPolynomial;
let mut p = UnsignedPolynomial::<u8>::from_str("x+1").unwrap();
p.mod_pow_assign(5, 7);
assert_eq!(p.to_string(), "x^5+5*x^4+3*x^3+3*x^2+5*x+1");
// The square of 2*x+1 is 4*x^2+4*x+1, which is 1 modulo 4.
let mut p = UnsignedPolynomial::<u8>::from_str("2*x+1").unwrap();
p.mod_pow_assign(2, 4);
assert_eq!(p.to_string(), "1");This is equivalent to nmod_poly_pow from nmod_poly/pow.c, FLINT 3.6.0, except that a
factor of $x^\ell$ is removed before powering and that the intermediate powers are trimmed.
Source§impl<T: PrimitiveUnsigned> ModPowTruncated<T> for UnsignedPolynomial<T>
impl<T: PrimitiveUnsigned> ModPowTruncated<T> for UnsignedPolynomial<T>
Source§fn mod_pow_truncated(self, exp: u64, len: u64, m: T) -> Self
fn mod_pow_truncated(self, exp: u64, len: u64, m: T) -> Self
Raises an UnsignedPolynomial to a power modulo $m$, keeping only the coefficients of
$x^i$ for $i$ less than len, taking it by value. Its coefficients must already be reduced
modulo $m$.
$$ f(p, e, n, k) = (p^e \bmod x^n) \bmod m. $$
The polynomial need not already be truncated: only its first len coefficients are read.
The zeroth power of every polynomial is 1, truncated to 0 when len is 0 and reduced to 0
when $k$ is 0. The power is computed by repeated truncated squaring modulo $m$.
§Worst-case complexity
$T(n) = O(n^{\log_2 3} \log e)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, $n$ is len, and $e$ is exp.
§Panics
Panics if m is 0, or if any coefficient of self is greater than or equal to m.
§Examples
use core::str::FromStr;
use malachite_base::polynomial::ModPowTruncated;
use malachite_base::unsigned_polynomial::UnsignedPolynomial;
assert_eq!(
(UnsignedPolynomial::<u8>::from_str("x+1").unwrap())
.mod_pow_truncated(5, 3, 7)
.to_string(),
"3*x^2+5*x+1"
);
// The power is a multiple of x^4.
assert_eq!(
(UnsignedPolynomial::<u8>::from_str("x^2+x").unwrap())
.mod_pow_truncated(4, 4, 7)
.to_string(),
"0"
);This is equivalent to nmod_poly_pow_trunc from nmod_poly/pow_trunc.c, FLINT 3.6.0,
except that a factor of $x^\ell$ is removed before powering, that the intermediate powers
are trimmed rather than padded to len, and that the zeroth power of the zero polynomial is
1 (modulo $m$), where FLINT gives 0.
type Output = UnsignedPolynomial<T>
Source§impl<T: PrimitiveUnsigned> ModPowTruncated<T> for &UnsignedPolynomial<T>
impl<T: PrimitiveUnsigned> ModPowTruncated<T> for &UnsignedPolynomial<T>
Source§fn mod_pow_truncated(self, exp: u64, len: u64, m: T) -> UnsignedPolynomial<T>
fn mod_pow_truncated(self, exp: u64, len: u64, m: T) -> UnsignedPolynomial<T>
Raises an UnsignedPolynomial to a power modulo $m$, keeping only the coefficients of
$x^i$ for $i$ less than len, taking it by reference. Its coefficients must already be
reduced modulo $m$.
$$ f(p, e, n, k) = (p^e \bmod x^n) \bmod m. $$
The polynomial need not already be truncated: only its first len coefficients are read.
The zeroth power of every polynomial is 1, truncated to 0 when len is 0 and reduced to 0
when $k$ is 0. The power is computed by repeated truncated squaring modulo $m$.
§Worst-case complexity
$T(n) = O(n^{\log_2 3} \log e)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, $n$ is len, and $e$ is exp.
§Panics
Panics if m is 0, or if any coefficient of self is greater than or equal to m.
§Examples
use core::str::FromStr;
use malachite_base::polynomial::ModPowTruncated;
use malachite_base::unsigned_polynomial::UnsignedPolynomial;
assert_eq!(
(&UnsignedPolynomial::<u8>::from_str("x+1").unwrap())
.mod_pow_truncated(5, 3, 7)
.to_string(),
"3*x^2+5*x+1"
);
// The power is a multiple of x^4.
assert_eq!(
(&UnsignedPolynomial::<u8>::from_str("x^2+x").unwrap())
.mod_pow_truncated(4, 4, 7)
.to_string(),
"0"
);This is equivalent to nmod_poly_pow_trunc from nmod_poly/pow_trunc.c, FLINT 3.6.0,
except that a factor of $x^\ell$ is removed before powering, that the intermediate powers
are trimmed rather than padded to len, and that the zeroth power of the zero polynomial is
1 (modulo $m$), where FLINT gives 0.
type Output = UnsignedPolynomial<T>
Source§impl<T: PrimitiveUnsigned> ModPowTruncatedAssign<T> for UnsignedPolynomial<T>
impl<T: PrimitiveUnsigned> ModPowTruncatedAssign<T> for UnsignedPolynomial<T>
Source§fn mod_pow_truncated_assign(&mut self, exp: u64, len: u64, m: T)
fn mod_pow_truncated_assign(&mut self, exp: u64, len: u64, m: T)
Raises an UnsignedPolynomial to a power modulo $m$ in place, keeping only the
coefficients of $x^i$ for $i$ less than len. Its coefficients must already be reduced
modulo $m$.
$$ p \gets (p^e \bmod x^n) \bmod m. $$
The polynomial need not already be truncated: only its first len coefficients are read.
The zeroth power of every polynomial is 1, truncated to 0 when len is 0 and reduced to 0
when $k$ is 0. The power is computed by repeated truncated squaring modulo $m$.
§Worst-case complexity
$T(n) = O(n^{\log_2 3} \log e)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, $n$ is len, and $e$ is exp.
§Panics
Panics if m is 0, or if any coefficient of self is greater than or equal to m.
§Examples
use core::str::FromStr;
use malachite_base::polynomial::ModPowTruncatedAssign;
use malachite_base::unsigned_polynomial::UnsignedPolynomial;
let mut p = UnsignedPolynomial::<u8>::from_str("x+1").unwrap();
p.mod_pow_truncated_assign(5, 3, 7);
assert_eq!(p.to_string(), "3*x^2+5*x+1");
// The power is a multiple of x^4.
let mut p = UnsignedPolynomial::<u8>::from_str("x^2+x").unwrap();
p.mod_pow_truncated_assign(4, 4, 7);
assert_eq!(p.to_string(), "0");This is equivalent to nmod_poly_pow_trunc from nmod_poly/pow_trunc.c, FLINT 3.6.0,
except that a factor of $x^\ell$ is removed before powering, that the intermediate powers
are trimmed rather than padded to len, and that the zeroth power of the zero polynomial is
1 (modulo $m$), where FLINT gives 0.
Source§impl<T: PrimitiveUnsigned> ModPowerOf2 for UnsignedPolynomial<T>
impl<T: PrimitiveUnsigned> ModPowerOf2 for UnsignedPolynomial<T>
Source§fn mod_power_of_2(self, pow: u64) -> Self
fn mod_power_of_2(self, pow: u64) -> Self
Divides every coefficient of a UnsignedPolynomial by $2^k$, keeping the remainders,
taking the polynomial by value.
The result is reduced modulo $2^k$, which is to say that mod_power_of_2_is_reduced returns
true for it.
Reducing can lower the degree, and can even give the zero polynomial: a leading coefficient that is a multiple of $2^k$ becomes zero, and a polynomial does not hold trailing zero coefficients. So $4x^2 + 3$ modulo $4$ is the constant $3$, not a quadratic with a zero leading coefficient.
$$ f(p, k) = q, \quad \text{where} \quad q_i = p_i - 2^k \left \lfloor \frac{p_i}{2^k} \right \rfloor. $$
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is the number of coefficients.
§Examples
use core::str::FromStr;
use malachite_base::num::arithmetic::traits::ModPowerOf2;
use malachite_base::unsigned_polynomial::UnsignedPolynomial;
// Every coefficient is taken modulo 2.
assert_eq!(
UnsignedPolynomial::<u64>::from_str("x^2+3*x+2")
.unwrap()
.mod_power_of_2(1)
.to_string(),
"x^2+x"
);
// Reducing the leading coefficient to zero lowers the degree.
assert_eq!(
UnsignedPolynomial::<u64>::from_str("4*x^2+3")
.unwrap()
.mod_power_of_2(2)
.to_string(),
"3"
);
// Modulo 2^0 every coefficient is zero, so the whole polynomial is.
assert_eq!(
UnsignedPolynomial::<u64>::from_str("x^2+3*x+2")
.unwrap()
.mod_power_of_2(0)
.to_string(),
"0"
);type Output = UnsignedPolynomial<T>
Source§impl<T: PrimitiveUnsigned> ModPowerOf2 for &UnsignedPolynomial<T>
impl<T: PrimitiveUnsigned> ModPowerOf2 for &UnsignedPolynomial<T>
Source§fn mod_power_of_2(self, pow: u64) -> UnsignedPolynomial<T>
fn mod_power_of_2(self, pow: u64) -> UnsignedPolynomial<T>
Divides every coefficient of a UnsignedPolynomial by $2^k$, keeping the remainders,
taking the polynomial by reference.
See the documentation for the ModPowerOf2 implementation on UnsignedPolynomial for
details, including how reducing can lower the degree.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is the number of coefficients.
§Examples
use core::str::FromStr;
use malachite_base::num::arithmetic::traits::ModPowerOf2;
use malachite_base::unsigned_polynomial::UnsignedPolynomial;
let p = UnsignedPolynomial::<u64>::from_str("4*x^2+3").unwrap();
assert_eq!((&p).mod_power_of_2(2).to_string(), "3");
// The polynomial is left alone.
assert_eq!(p.to_string(), "4*x^2+3");type Output = UnsignedPolynomial<T>
Source§impl<T: PrimitiveUnsigned> ModPowerOf2Add for UnsignedPolynomial<T>
impl<T: PrimitiveUnsigned> ModPowerOf2Add for UnsignedPolynomial<T>
Source§fn mod_power_of_2_add(self, other: Self, pow: u64) -> Self
fn mod_power_of_2_add(self, other: Self, pow: u64) -> Self
Adds two UnsignedPolynomials modulo $2^k$, taking both by value. The coefficients of
both must already be reduced modulo $2^k$.
$$ f(p, q, k) = p + q \bmod 2^k. $$
Coefficients past the end of the shorter polynomial are taken to be zero. When the two polynomials have the same degree, their leading coefficients can cancel modulo $2^k$, and then the degree of the sum is lower.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is the number of coefficients of the
longer polynomial times pow.
§Panics
Panics if pow is greater than T::WIDTH, or if any coefficient of self or other is
greater than or equal to $2^k$.
§Examples
use core::str::FromStr;
use malachite_base::num::arithmetic::traits::ModPowerOf2Add;
use malachite_base::unsigned_polynomial::UnsignedPolynomial;
// The leading coefficients cancel, and so do the linear ones.
assert_eq!(
UnsignedPolynomial::<u8>::from_str("5*x^2+x+3")
.unwrap()
.mod_power_of_2_add(
UnsignedPolynomial::<u8>::from_str("3*x^2+7*x+1").unwrap(),
3
)
.to_string(),
"4"
);
// Wrapping around makes the constant term 1.
assert_eq!(
UnsignedPolynomial::<u8>::from_str("x+3")
.unwrap()
.mod_power_of_2_add(UnsignedPolynomial::<u8>::from_str("x^2+6").unwrap(), 3)
.to_string(),
"x^2+x+1"
);This is equivalent to nmod_poly_add from nmod_poly/add.c, FLINT 3.6.0, with the modulus
$2^k$.
type Output = UnsignedPolynomial<T>
Source§impl<T: PrimitiveUnsigned> ModPowerOf2Add<&UnsignedPolynomial<T>> for UnsignedPolynomial<T>
impl<T: PrimitiveUnsigned> ModPowerOf2Add<&UnsignedPolynomial<T>> for UnsignedPolynomial<T>
Source§fn mod_power_of_2_add(self, other: &Self, pow: u64) -> Self
fn mod_power_of_2_add(self, other: &Self, pow: u64) -> Self
Adds two UnsignedPolynomials modulo $2^k$, taking the first by value and the second by
reference. The coefficients of both must already be reduced modulo $2^k$.
$$ f(p, q, k) = p + q \bmod 2^k. $$
Coefficients past the end of the shorter polynomial are taken to be zero. When the two polynomials have the same degree, their leading coefficients can cancel modulo $2^k$, and then the degree of the sum is lower.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is the number of coefficients of the
longer polynomial times pow.
§Panics
Panics if pow is greater than T::WIDTH, or if any coefficient of self or other is
greater than or equal to $2^k$.
§Examples
use core::str::FromStr;
use malachite_base::num::arithmetic::traits::ModPowerOf2Add;
use malachite_base::unsigned_polynomial::UnsignedPolynomial;
// The leading coefficients cancel, and so do the linear ones.
assert_eq!(
UnsignedPolynomial::<u8>::from_str("5*x^2+x+3")
.unwrap()
.mod_power_of_2_add(
&UnsignedPolynomial::<u8>::from_str("3*x^2+7*x+1").unwrap(),
3
)
.to_string(),
"4"
);
// Wrapping around makes the constant term 1.
assert_eq!(
UnsignedPolynomial::<u8>::from_str("x+3")
.unwrap()
.mod_power_of_2_add(&UnsignedPolynomial::<u8>::from_str("x^2+6").unwrap(), 3)
.to_string(),
"x^2+x+1"
);This is equivalent to nmod_poly_add from nmod_poly/add.c, FLINT 3.6.0, with the modulus
$2^k$.
type Output = UnsignedPolynomial<T>
Source§impl<T: PrimitiveUnsigned> ModPowerOf2Add<&UnsignedPolynomial<T>> for &UnsignedPolynomial<T>
impl<T: PrimitiveUnsigned> ModPowerOf2Add<&UnsignedPolynomial<T>> for &UnsignedPolynomial<T>
Source§fn mod_power_of_2_add(
self,
other: &UnsignedPolynomial<T>,
pow: u64,
) -> UnsignedPolynomial<T>
fn mod_power_of_2_add( self, other: &UnsignedPolynomial<T>, pow: u64, ) -> UnsignedPolynomial<T>
Adds two UnsignedPolynomials modulo $2^k$, taking both by reference. The coefficients of
both must already be reduced modulo $2^k$.
$$ f(p, q, k) = p + q \bmod 2^k. $$
Coefficients past the end of the shorter polynomial are taken to be zero. When the two polynomials have the same degree, their leading coefficients can cancel modulo $2^k$, and then the degree of the sum is lower.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is the number of coefficients of the
longer polynomial times pow.
§Panics
Panics if pow is greater than T::WIDTH, or if any coefficient of self or other is
greater than or equal to $2^k$.
§Examples
use core::str::FromStr;
use malachite_base::num::arithmetic::traits::ModPowerOf2Add;
use malachite_base::unsigned_polynomial::UnsignedPolynomial;
// The leading coefficients cancel, and so do the linear ones.
assert_eq!(
(&UnsignedPolynomial::<u8>::from_str("5*x^2+x+3").unwrap())
.mod_power_of_2_add(
&UnsignedPolynomial::<u8>::from_str("3*x^2+7*x+1").unwrap(),
3
)
.to_string(),
"4"
);
// Wrapping around makes the constant term 1.
assert_eq!(
(&UnsignedPolynomial::<u8>::from_str("x+3").unwrap())
.mod_power_of_2_add(&UnsignedPolynomial::<u8>::from_str("x^2+6").unwrap(), 3)
.to_string(),
"x^2+x+1"
);This is equivalent to nmod_poly_add from nmod_poly/add.c, FLINT 3.6.0, with the modulus
$2^k$.
type Output = UnsignedPolynomial<T>
Source§impl<T: PrimitiveUnsigned> ModPowerOf2Add<UnsignedPolynomial<T>> for &UnsignedPolynomial<T>
impl<T: PrimitiveUnsigned> ModPowerOf2Add<UnsignedPolynomial<T>> for &UnsignedPolynomial<T>
Source§fn mod_power_of_2_add(
self,
other: UnsignedPolynomial<T>,
pow: u64,
) -> UnsignedPolynomial<T>
fn mod_power_of_2_add( self, other: UnsignedPolynomial<T>, pow: u64, ) -> UnsignedPolynomial<T>
Adds two UnsignedPolynomials modulo $2^k$, taking the first by reference and the second
by value. The coefficients of both must already be reduced modulo $2^k$.
$$ f(p, q, k) = p + q \bmod 2^k. $$
Coefficients past the end of the shorter polynomial are taken to be zero. When the two polynomials have the same degree, their leading coefficients can cancel modulo $2^k$, and then the degree of the sum is lower.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is the number of coefficients of the
longer polynomial times pow.
§Panics
Panics if pow is greater than T::WIDTH, or if any coefficient of self or other is
greater than or equal to $2^k$.
§Examples
use core::str::FromStr;
use malachite_base::num::arithmetic::traits::ModPowerOf2Add;
use malachite_base::unsigned_polynomial::UnsignedPolynomial;
// The leading coefficients cancel, and so do the linear ones.
assert_eq!(
(&UnsignedPolynomial::<u8>::from_str("5*x^2+x+3").unwrap())
.mod_power_of_2_add(
UnsignedPolynomial::<u8>::from_str("3*x^2+7*x+1").unwrap(),
3
)
.to_string(),
"4"
);
// Wrapping around makes the constant term 1.
assert_eq!(
(&UnsignedPolynomial::<u8>::from_str("x+3").unwrap())
.mod_power_of_2_add(UnsignedPolynomial::<u8>::from_str("x^2+6").unwrap(), 3)
.to_string(),
"x^2+x+1"
);This is equivalent to nmod_poly_add from nmod_poly/add.c, FLINT 3.6.0, with the modulus
$2^k$.
type Output = UnsignedPolynomial<T>
Source§impl<T: PrimitiveUnsigned> ModPowerOf2AddAssign for UnsignedPolynomial<T>
impl<T: PrimitiveUnsigned> ModPowerOf2AddAssign for UnsignedPolynomial<T>
Source§fn mod_power_of_2_add_assign(&mut self, other: Self, pow: u64)
fn mod_power_of_2_add_assign(&mut self, other: Self, pow: u64)
Adds a UnsignedPolynomial to a UnsignedPolynomial modulo $2^k$, in place, taking the
second by value. The coefficients of both must already be reduced modulo $2^k$.
$$ p \gets p + q \bmod 2^k. $$
Coefficients past the end of the shorter polynomial are taken to be zero. When the two polynomials have the same degree, their leading coefficients can cancel modulo $2^k$, and then the degree of the sum is lower.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is the number of coefficients of the
longer polynomial times pow.
§Panics
Panics if pow is greater than T::WIDTH, or if any coefficient of self or other is
greater than or equal to $2^k$.
§Examples
use core::str::FromStr;
use malachite_base::num::arithmetic::traits::ModPowerOf2AddAssign;
use malachite_base::unsigned_polynomial::UnsignedPolynomial;
// The leading coefficients cancel, and so do the linear ones.
let mut p = UnsignedPolynomial::<u8>::from_str("5*x^2+x+3").unwrap();
p.mod_power_of_2_add_assign(
UnsignedPolynomial::<u8>::from_str("3*x^2+7*x+1").unwrap(),
3,
);
assert_eq!(p.to_string(), "4");
// Wrapping around makes the constant term 1.
let mut p = UnsignedPolynomial::<u8>::from_str("x+3").unwrap();
p.mod_power_of_2_add_assign(UnsignedPolynomial::<u8>::from_str("x^2+6").unwrap(), 3);
assert_eq!(p.to_string(), "x^2+x+1");This is equivalent to nmod_poly_add from nmod_poly/add.c, FLINT 3.6.0, with the modulus
$2^k$.
Source§impl<T: PrimitiveUnsigned> ModPowerOf2AddAssign<&UnsignedPolynomial<T>> for UnsignedPolynomial<T>
impl<T: PrimitiveUnsigned> ModPowerOf2AddAssign<&UnsignedPolynomial<T>> for UnsignedPolynomial<T>
Source§fn mod_power_of_2_add_assign(&mut self, other: &Self, pow: u64)
fn mod_power_of_2_add_assign(&mut self, other: &Self, pow: u64)
Adds a UnsignedPolynomial to a UnsignedPolynomial modulo $2^k$, in place, taking the
second by reference. The coefficients of both must already be reduced modulo $2^k$.
$$ p \gets p + q \bmod 2^k. $$
Coefficients past the end of the shorter polynomial are taken to be zero. When the two polynomials have the same degree, their leading coefficients can cancel modulo $2^k$, and then the degree of the sum is lower.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is the number of coefficients of the
longer polynomial times pow.
§Panics
Panics if pow is greater than T::WIDTH, or if any coefficient of self or other is
greater than or equal to $2^k$.
§Examples
use core::str::FromStr;
use malachite_base::num::arithmetic::traits::ModPowerOf2AddAssign;
use malachite_base::unsigned_polynomial::UnsignedPolynomial;
// The leading coefficients cancel, and so do the linear ones.
let mut p = UnsignedPolynomial::<u8>::from_str("5*x^2+x+3").unwrap();
p.mod_power_of_2_add_assign(
&UnsignedPolynomial::<u8>::from_str("3*x^2+7*x+1").unwrap(),
3,
);
assert_eq!(p.to_string(), "4");
// Wrapping around makes the constant term 1.
let mut p = UnsignedPolynomial::<u8>::from_str("x+3").unwrap();
p.mod_power_of_2_add_assign(&UnsignedPolynomial::<u8>::from_str("x^2+6").unwrap(), 3);
assert_eq!(p.to_string(), "x^2+x+1");This is equivalent to nmod_poly_add from nmod_poly/add.c, FLINT 3.6.0, with the modulus
$2^k$.
Source§impl<T: PrimitiveUnsigned> ModPowerOf2AddTruncated for UnsignedPolynomial<T>
impl<T: PrimitiveUnsigned> ModPowerOf2AddTruncated for UnsignedPolynomial<T>
Source§fn mod_power_of_2_add_truncated(self, other: Self, len: u64, pow: u64) -> Self
fn mod_power_of_2_add_truncated(self, other: Self, len: u64, pow: u64) -> Self
Adds two UnsignedPolynomials modulo $2^k$, keeping only the coefficients of $x^i$ for
$i$ less than len, taking both by value. The coefficients of both must already be reduced
modulo $2^k$.
$$ f(p, q, n, k) = ((p + q) \bmod x^n) \bmod 2^k. $$
The polynomials need not already be truncated: this is the sum of their images modulo $x^n$,
so only the first len coefficients of each are read. The sum is trimmed, so when
coefficients cancel modulo $2^k$ at the top of the kept range, the degree is lower still.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is the number of coefficients of the
longer polynomial times pow.
§Panics
Panics if pow is greater than T::WIDTH, or if any coefficient of self or other is
greater than or equal to $2^k$.
§Examples
use core::str::FromStr;
use malachite_base::polynomial::ModPowerOf2AddTruncated;
use malachite_base::unsigned_polynomial::UnsignedPolynomial;
// The linear coefficients wrap around to 0.
assert_eq!(
UnsignedPolynomial::<u8>::from_str("x^3+2*x^2+x+5")
.unwrap()
.mod_power_of_2_add_truncated(
UnsignedPolynomial::<u8>::from_str("4*x^2+7*x+2").unwrap(),
3,
3
)
.to_string(),
"6*x^2+7"
);
assert_eq!(
UnsignedPolynomial::<u8>::from_str("x^3+2*x^2+x+5")
.unwrap()
.mod_power_of_2_add_truncated(
UnsignedPolynomial::<u8>::from_str("4*x^2+7*x+2").unwrap(),
1,
3
)
.to_string(),
"7"
);This is equivalent to nmod_poly_add_series from nmod_poly/add_series.c, FLINT 3.6.0,
with the modulus $2^k$.
type Output = UnsignedPolynomial<T>
Source§impl<T: PrimitiveUnsigned> ModPowerOf2AddTruncated<&UnsignedPolynomial<T>> for UnsignedPolynomial<T>
impl<T: PrimitiveUnsigned> ModPowerOf2AddTruncated<&UnsignedPolynomial<T>> for UnsignedPolynomial<T>
Source§fn mod_power_of_2_add_truncated(self, other: &Self, len: u64, pow: u64) -> Self
fn mod_power_of_2_add_truncated(self, other: &Self, len: u64, pow: u64) -> Self
Adds two UnsignedPolynomials modulo $2^k$, keeping only the coefficients of $x^i$ for
$i$ less than len, taking the first by value and the second by reference. The coefficients
of both must already be reduced modulo $2^k$.
$$ f(p, q, n, k) = ((p + q) \bmod x^n) \bmod 2^k. $$
The polynomials need not already be truncated: this is the sum of their images modulo $x^n$,
so only the first len coefficients of each are read. The sum is trimmed, so when
coefficients cancel modulo $2^k$ at the top of the kept range, the degree is lower still.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is the number of coefficients of the
longer polynomial times pow.
§Panics
Panics if pow is greater than T::WIDTH, or if any coefficient of self or other is
greater than or equal to $2^k$.
§Examples
use core::str::FromStr;
use malachite_base::polynomial::ModPowerOf2AddTruncated;
use malachite_base::unsigned_polynomial::UnsignedPolynomial;
// The linear coefficients wrap around to 0.
assert_eq!(
UnsignedPolynomial::<u8>::from_str("x^3+2*x^2+x+5")
.unwrap()
.mod_power_of_2_add_truncated(
&UnsignedPolynomial::<u8>::from_str("4*x^2+7*x+2").unwrap(),
3,
3
)
.to_string(),
"6*x^2+7"
);
assert_eq!(
UnsignedPolynomial::<u8>::from_str("x^3+2*x^2+x+5")
.unwrap()
.mod_power_of_2_add_truncated(
&UnsignedPolynomial::<u8>::from_str("4*x^2+7*x+2").unwrap(),
1,
3
)
.to_string(),
"7"
);This is equivalent to nmod_poly_add_series from nmod_poly/add_series.c, FLINT 3.6.0,
with the modulus $2^k$.
type Output = UnsignedPolynomial<T>
Source§impl<T: PrimitiveUnsigned> ModPowerOf2AddTruncated<&UnsignedPolynomial<T>> for &UnsignedPolynomial<T>
impl<T: PrimitiveUnsigned> ModPowerOf2AddTruncated<&UnsignedPolynomial<T>> for &UnsignedPolynomial<T>
Source§fn mod_power_of_2_add_truncated(
self,
other: &UnsignedPolynomial<T>,
len: u64,
pow: u64,
) -> UnsignedPolynomial<T>
fn mod_power_of_2_add_truncated( self, other: &UnsignedPolynomial<T>, len: u64, pow: u64, ) -> UnsignedPolynomial<T>
Adds two UnsignedPolynomials modulo $2^k$, keeping only the coefficients of $x^i$ for
$i$ less than len, taking both by reference. The coefficients of both must already be
reduced modulo $2^k$.
$$ f(p, q, n, k) = ((p + q) \bmod x^n) \bmod 2^k. $$
The polynomials need not already be truncated: this is the sum of their images modulo $x^n$,
so only the first len coefficients of each are read. The sum is trimmed, so when
coefficients cancel modulo $2^k$ at the top of the kept range, the degree is lower still.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is the number of coefficients of the
longer polynomial times pow.
§Panics
Panics if pow is greater than T::WIDTH, or if any coefficient of self or other is
greater than or equal to $2^k$.
§Examples
use core::str::FromStr;
use malachite_base::polynomial::ModPowerOf2AddTruncated;
use malachite_base::unsigned_polynomial::UnsignedPolynomial;
// The linear coefficients wrap around to 0.
assert_eq!(
(&UnsignedPolynomial::<u8>::from_str("x^3+2*x^2+x+5").unwrap())
.mod_power_of_2_add_truncated(
&UnsignedPolynomial::<u8>::from_str("4*x^2+7*x+2").unwrap(),
3,
3
)
.to_string(),
"6*x^2+7"
);
assert_eq!(
(&UnsignedPolynomial::<u8>::from_str("x^3+2*x^2+x+5").unwrap())
.mod_power_of_2_add_truncated(
&UnsignedPolynomial::<u8>::from_str("4*x^2+7*x+2").unwrap(),
1,
3
)
.to_string(),
"7"
);This is equivalent to nmod_poly_add_series from nmod_poly/add_series.c, FLINT 3.6.0,
with the modulus $2^k$.
type Output = UnsignedPolynomial<T>
Source§impl<T: PrimitiveUnsigned> ModPowerOf2AddTruncated<UnsignedPolynomial<T>> for &UnsignedPolynomial<T>
impl<T: PrimitiveUnsigned> ModPowerOf2AddTruncated<UnsignedPolynomial<T>> for &UnsignedPolynomial<T>
Source§fn mod_power_of_2_add_truncated(
self,
other: UnsignedPolynomial<T>,
len: u64,
pow: u64,
) -> UnsignedPolynomial<T>
fn mod_power_of_2_add_truncated( self, other: UnsignedPolynomial<T>, len: u64, pow: u64, ) -> UnsignedPolynomial<T>
Adds two UnsignedPolynomials modulo $2^k$, keeping only the coefficients of $x^i$ for
$i$ less than len, taking the first by reference and the second by value. The coefficients
of both must already be reduced modulo $2^k$.
$$ f(p, q, n, k) = ((p + q) \bmod x^n) \bmod 2^k. $$
The polynomials need not already be truncated: this is the sum of their images modulo $x^n$,
so only the first len coefficients of each are read. The sum is trimmed, so when
coefficients cancel modulo $2^k$ at the top of the kept range, the degree is lower still.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is the number of coefficients of the
longer polynomial times pow.
§Panics
Panics if pow is greater than T::WIDTH, or if any coefficient of self or other is
greater than or equal to $2^k$.
§Examples
use core::str::FromStr;
use malachite_base::polynomial::ModPowerOf2AddTruncated;
use malachite_base::unsigned_polynomial::UnsignedPolynomial;
// The linear coefficients wrap around to 0.
assert_eq!(
(&UnsignedPolynomial::<u8>::from_str("x^3+2*x^2+x+5").unwrap())
.mod_power_of_2_add_truncated(
UnsignedPolynomial::<u8>::from_str("4*x^2+7*x+2").unwrap(),
3,
3
)
.to_string(),
"6*x^2+7"
);
assert_eq!(
(&UnsignedPolynomial::<u8>::from_str("x^3+2*x^2+x+5").unwrap())
.mod_power_of_2_add_truncated(
UnsignedPolynomial::<u8>::from_str("4*x^2+7*x+2").unwrap(),
1,
3
)
.to_string(),
"7"
);This is equivalent to nmod_poly_add_series from nmod_poly/add_series.c, FLINT 3.6.0,
with the modulus $2^k$.
type Output = UnsignedPolynomial<T>
Source§impl<T: PrimitiveUnsigned> ModPowerOf2AddTruncatedAssign for UnsignedPolynomial<T>
impl<T: PrimitiveUnsigned> ModPowerOf2AddTruncatedAssign for UnsignedPolynomial<T>
Source§fn mod_power_of_2_add_truncated_assign(
&mut self,
other: Self,
len: u64,
pow: u64,
)
fn mod_power_of_2_add_truncated_assign( &mut self, other: Self, len: u64, pow: u64, )
Adds an UnsignedPolynomial to an UnsignedPolynomial modulo $2^k$ in place, keeping
only the coefficients of $x^i$ for $i$ less than len, taking the second polynomial by
value. The coefficients of both must already be reduced modulo $2^k$.
$$ p \gets ((p + q) \bmod x^n) \bmod 2^k. $$
The polynomials need not already be truncated: this is the sum of their images modulo $x^n$,
so only the first len coefficients of each are read. The sum is trimmed, so when
coefficients cancel modulo $2^k$ at the top of the kept range, the degree is lower still.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is the number of coefficients of the
longer polynomial times pow.
§Panics
Panics if pow is greater than T::WIDTH, or if any coefficient of self or other is
greater than or equal to $2^k$.
§Examples
use core::str::FromStr;
use malachite_base::polynomial::ModPowerOf2AddTruncatedAssign;
use malachite_base::unsigned_polynomial::UnsignedPolynomial;
// The linear coefficients wrap around to 0.
let mut p = UnsignedPolynomial::<u8>::from_str("x^3+2*x^2+x+5").unwrap();
p.mod_power_of_2_add_truncated_assign(
UnsignedPolynomial::<u8>::from_str("4*x^2+7*x+2").unwrap(),
3,
3,
);
assert_eq!(p.to_string(), "6*x^2+7");
let mut p = UnsignedPolynomial::<u8>::from_str("x^3+2*x^2+x+5").unwrap();
p.mod_power_of_2_add_truncated_assign(
UnsignedPolynomial::<u8>::from_str("4*x^2+7*x+2").unwrap(),
1,
3,
);
assert_eq!(p.to_string(), "7");This is equivalent to nmod_poly_add_series from nmod_poly/add_series.c, FLINT 3.6.0,
with the modulus $2^k$.
Source§impl<T: PrimitiveUnsigned> ModPowerOf2AddTruncatedAssign<&UnsignedPolynomial<T>> for UnsignedPolynomial<T>
impl<T: PrimitiveUnsigned> ModPowerOf2AddTruncatedAssign<&UnsignedPolynomial<T>> for UnsignedPolynomial<T>
Source§fn mod_power_of_2_add_truncated_assign(
&mut self,
other: &Self,
len: u64,
pow: u64,
)
fn mod_power_of_2_add_truncated_assign( &mut self, other: &Self, len: u64, pow: u64, )
Adds an UnsignedPolynomial to an UnsignedPolynomial modulo $2^k$ in place, keeping
only the coefficients of $x^i$ for $i$ less than len, taking the second polynomial by
reference. The coefficients of both must already be reduced modulo $2^k$.
$$ p \gets ((p + q) \bmod x^n) \bmod 2^k. $$
The polynomials need not already be truncated: this is the sum of their images modulo $x^n$,
so only the first len coefficients of each are read. The sum is trimmed, so when
coefficients cancel modulo $2^k$ at the top of the kept range, the degree is lower still.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is the number of coefficients of the
longer polynomial times pow.
§Panics
Panics if pow is greater than T::WIDTH, or if any coefficient of self or other is
greater than or equal to $2^k$.
§Examples
use core::str::FromStr;
use malachite_base::polynomial::ModPowerOf2AddTruncatedAssign;
use malachite_base::unsigned_polynomial::UnsignedPolynomial;
// The linear coefficients wrap around to 0.
let mut p = UnsignedPolynomial::<u8>::from_str("x^3+2*x^2+x+5").unwrap();
p.mod_power_of_2_add_truncated_assign(
&UnsignedPolynomial::<u8>::from_str("4*x^2+7*x+2").unwrap(),
3,
3,
);
assert_eq!(p.to_string(), "6*x^2+7");
let mut p = UnsignedPolynomial::<u8>::from_str("x^3+2*x^2+x+5").unwrap();
p.mod_power_of_2_add_truncated_assign(
&UnsignedPolynomial::<u8>::from_str("4*x^2+7*x+2").unwrap(),
1,
3,
);
assert_eq!(p.to_string(), "7");This is equivalent to nmod_poly_add_series from nmod_poly/add_series.c, FLINT 3.6.0,
with the modulus $2^k$.
Source§impl<T: PrimitiveUnsigned> ModPowerOf2Assign for UnsignedPolynomial<T>
impl<T: PrimitiveUnsigned> ModPowerOf2Assign for UnsignedPolynomial<T>
Source§fn mod_power_of_2_assign(&mut self, pow: u64)
fn mod_power_of_2_assign(&mut self, pow: u64)
Divides every coefficient of a UnsignedPolynomial by $2^k$, replacing the polynomial by
the one whose coefficients are the remainders.
See the documentation for the ModPowerOf2 implementation on UnsignedPolynomial for
details, including how reducing can lower the degree.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is the number of coefficients.
§Examples
use core::str::FromStr;
use malachite_base::num::arithmetic::traits::ModPowerOf2Assign;
use malachite_base::unsigned_polynomial::UnsignedPolynomial;
let mut p = UnsignedPolynomial::<u64>::from_str("x^2+3*x+2").unwrap();
p.mod_power_of_2_assign(1);
assert_eq!(p.to_string(), "x^2+x");
let mut p = UnsignedPolynomial::<u64>::from_str("4*x^2+3").unwrap();
p.mod_power_of_2_assign(2);
assert_eq!(p.to_string(), "3");Source§impl<T: PrimitiveUnsigned> ModPowerOf2Derivative for UnsignedPolynomial<T>
impl<T: PrimitiveUnsigned> ModPowerOf2Derivative for UnsignedPolynomial<T>
Source§fn mod_power_of_2_derivative(self, pow: u64) -> Self
fn mod_power_of_2_derivative(self, pow: u64) -> Self
Computes the derivative of an UnsignedPolynomial modulo $2^k$, taking the polynomial by
value. The coefficients must already be reduced modulo $2^k$.
$$ f(p, k) = p’ \bmod 2^k. $$
The coefficient of $x^i$ is multiplied by $i$, reduced, and moved to $x^{i-1}$. Since $ia_i$ can be divisible by the modulus even when $a_i$ is not zero, the derivative can lose any number of degrees. A constant polynomial, including zero, has derivative zero.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is self.len().
§Panics
Panics if pow is greater than T::WIDTH, or if any coefficient of self is greater than
or equal to $2^k$.
§Examples
use core::str::FromStr;
use malachite_base::polynomial::ModPowerOf2Derivative;
use malachite_base::unsigned_polynomial::UnsignedPolynomial;
let p = UnsignedPolynomial::<u8>::from_str("x^3+3*x^2+2*x+1").unwrap();
assert_eq!(p.mod_power_of_2_derivative(2).to_string(), "3*x^2+2*x+2");
let p = UnsignedPolynomial::<u8>::from_str("x^5+x").unwrap();
assert_eq!(p.mod_power_of_2_derivative(1).to_string(), "x^4+1");
// The derivative can lose more than one degree.
let p = UnsignedPolynomial::<u8>::from_str("x^4+x^3+1").unwrap();
assert_eq!(p.mod_power_of_2_derivative(1).to_string(), "x^2");This is equivalent to nmod_poly_derivative from nmod_poly/derivative.c, FLINT 3.6.0,
with the modulus $2^k$.
type Output = UnsignedPolynomial<T>
Source§impl<T: PrimitiveUnsigned> ModPowerOf2Derivative for &UnsignedPolynomial<T>
impl<T: PrimitiveUnsigned> ModPowerOf2Derivative for &UnsignedPolynomial<T>
Source§fn mod_power_of_2_derivative(self, pow: u64) -> UnsignedPolynomial<T>
fn mod_power_of_2_derivative(self, pow: u64) -> UnsignedPolynomial<T>
Computes the derivative of an UnsignedPolynomial modulo $2^k$, taking the polynomial by
reference. The coefficients must already be reduced modulo $2^k$.
$$ f(p, k) = p’ \bmod 2^k. $$
The coefficient of $x^i$ is multiplied by $i$, reduced, and moved to $x^{i-1}$. Since $ia_i$ can be divisible by the modulus even when $a_i$ is not zero, the derivative can lose any number of degrees. A constant polynomial, including zero, has derivative zero.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is self.len().
§Panics
Panics if pow is greater than T::WIDTH, or if any coefficient of self is greater than
or equal to $2^k$.
§Examples
use core::str::FromStr;
use malachite_base::polynomial::ModPowerOf2Derivative;
use malachite_base::unsigned_polynomial::UnsignedPolynomial;
let p = UnsignedPolynomial::<u8>::from_str("x^3+3*x^2+2*x+1").unwrap();
assert_eq!((&p).mod_power_of_2_derivative(2).to_string(), "3*x^2+2*x+2");
let p = UnsignedPolynomial::<u8>::from_str("x^5+x").unwrap();
assert_eq!((&p).mod_power_of_2_derivative(1).to_string(), "x^4+1");
// The derivative can lose more than one degree.
let p = UnsignedPolynomial::<u8>::from_str("x^4+x^3+1").unwrap();
assert_eq!((&p).mod_power_of_2_derivative(1).to_string(), "x^2");This is equivalent to nmod_poly_derivative from nmod_poly/derivative.c, FLINT 3.6.0,
with the modulus $2^k$.
type Output = UnsignedPolynomial<T>
Source§impl<T: PrimitiveUnsigned> ModPowerOf2DerivativeAssign for UnsignedPolynomial<T>
impl<T: PrimitiveUnsigned> ModPowerOf2DerivativeAssign for UnsignedPolynomial<T>
Source§fn mod_power_of_2_derivative_assign(&mut self, pow: u64)
fn mod_power_of_2_derivative_assign(&mut self, pow: u64)
Replaces an UnsignedPolynomial with its derivative modulo $2^k$, in place. The
coefficients must already be reduced modulo $2^k$.
$$ p \gets p’ \bmod 2^k. $$
The coefficient of $x^i$ is multiplied by $i$, reduced, and moved to $x^{i-1}$. Since $ia_i$ can be divisible by the modulus even when $a_i$ is not zero, the derivative can lose any number of degrees. A constant polynomial, including zero, has derivative zero.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is self.len().
§Panics
Panics if pow is greater than T::WIDTH, or if any coefficient of self is greater than
or equal to $2^k$.
§Examples
use core::str::FromStr;
use malachite_base::polynomial::ModPowerOf2DerivativeAssign;
use malachite_base::unsigned_polynomial::UnsignedPolynomial;
let mut p = UnsignedPolynomial::<u8>::from_str("x^3+3*x^2+2*x+1").unwrap();
p.mod_power_of_2_derivative_assign(2);
assert_eq!(p.to_string(), "3*x^2+2*x+2");
let mut p = UnsignedPolynomial::<u8>::from_str("x^5+x").unwrap();
p.mod_power_of_2_derivative_assign(1);
assert_eq!(p.to_string(), "x^4+1");
// The derivative can lose more than one degree.
let mut p = UnsignedPolynomial::<u8>::from_str("x^4+x^3+1").unwrap();
p.mod_power_of_2_derivative_assign(1);
assert_eq!(p.to_string(), "x^2");This is equivalent to nmod_poly_derivative from nmod_poly/derivative.c, FLINT 3.6.0,
with the modulus $2^k$.
Source§impl<T: PrimitiveUnsigned> ModPowerOf2Evaluate<T> for &UnsignedPolynomial<T>
impl<T: PrimitiveUnsigned> ModPowerOf2Evaluate<T> for &UnsignedPolynomial<T>
Source§fn mod_power_of_2_evaluate(self, x: T, pow: u64) -> T
fn mod_power_of_2_evaluate(self, x: T, pow: u64) -> T
Evaluates an UnsignedPolynomial at a value of its coefficient type, modulo $2^k$, taking
the polynomial by reference. The coefficients and the value must already be reduced modulo
$2^k$, and $k$ may be at most the width of the type.
$$ f(p, x, k) = \sum_{i=0}^{n-1} c_i x^i \bmod 2^k, $$
where $c_i$ is the coefficient of $x^i$ in $p$ and $n$ is its length. The zero polynomial evaluates to 0 everywhere.
Reducing modulo $2^k$ commutes with wrapping arithmetic, which works modulo $2^w$ for the type’s width $w \geq k$, so Horner’s rule is carried out with wrapping multiplications and additions and the value is reduced once, at the end.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is self.len().
§Panics
Panics if pow is greater than T::WIDTH, or if any coefficient of self or x is
greater than or equal to $2^k$.
§Examples
use core::str::FromStr;
use malachite_base::polynomial::ModPowerOf2Evaluate;
use malachite_base::unsigned_polynomial::UnsignedPolynomial;
let p = UnsignedPolynomial::<u8>::from_str("5*x^2+3*x+7").unwrap();
// 5 * 36 + 3 * 6 + 7 = 205, which is 13 mod 16.
assert_eq!((&p).mod_power_of_2_evaluate(6, 4), 13);
assert_eq!((&p).mod_power_of_2_evaluate(0, 4), 7);
// All 8 bits of a u8: 205 itself.
assert_eq!((&p).mod_power_of_2_evaluate(6, 8), 205);This is equivalent to nmod_poly_evaluate_nmod from nmod_poly/evaluate_nmod.c, FLINT
3.6.0, with the modulus $2^k$, except that the value must be reduced.
Source§impl<T: PrimitiveUnsigned> ModPowerOf2Evaluate<T> for UnsignedPolynomial<T>
impl<T: PrimitiveUnsigned> ModPowerOf2Evaluate<T> for UnsignedPolynomial<T>
Source§fn mod_power_of_2_evaluate(self, x: T, pow: u64) -> T
fn mod_power_of_2_evaluate(self, x: T, pow: u64) -> T
Evaluates an UnsignedPolynomial at a value of its coefficient type, modulo $2^k$, taking
the polynomial by value. The coefficients and the value must already be reduced modulo
$2^k$, and $k$ may be at most the width of the type.
$$ f(p, x, k) = \sum_{i=0}^{n-1} c_i x^i \bmod 2^k, $$
where $c_i$ is the coefficient of $x^i$ in $p$ and $n$ is its length. The zero polynomial evaluates to 0 everywhere.
Reducing modulo $2^k$ commutes with wrapping arithmetic, which works modulo $2^w$ for the type’s width $w \geq k$, so Horner’s rule is carried out with wrapping multiplications and additions and the value is reduced once, at the end.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is self.len().
§Panics
Panics if pow is greater than T::WIDTH, or if any coefficient of self or x is
greater than or equal to $2^k$.
§Examples
use core::str::FromStr;
use malachite_base::polynomial::ModPowerOf2Evaluate;
use malachite_base::unsigned_polynomial::UnsignedPolynomial;
let p = UnsignedPolynomial::<u8>::from_str("5*x^2+3*x+7").unwrap();
// 5 * 36 + 3 * 6 + 7 = 205, which is 13 mod 16.
assert_eq!(p.clone().mod_power_of_2_evaluate(6, 4), 13);
assert_eq!(p.clone().mod_power_of_2_evaluate(0, 4), 7);
// All 8 bits of a u8: 205 itself.
assert_eq!(p.mod_power_of_2_evaluate(6, 8), 205);This is equivalent to nmod_poly_evaluate_nmod from nmod_poly/evaluate_nmod.c, FLINT
3.6.0, with the modulus $2^k$, except that the value must be reduced.
Source§impl<T: PrimitiveUnsigned> ModPowerOf2Integral for UnsignedPolynomial<T>
impl<T: PrimitiveUnsigned> ModPowerOf2Integral for UnsignedPolynomial<T>
Source§fn mod_power_of_2_integral(self, pow: u64) -> Self
fn mod_power_of_2_integral(self, pow: u64) -> Self
Computes the integral modulo $2^k$ of an UnsignedPolynomial whose constant term is zero,
taking the polynomial by value. Its coefficients must already be reduced modulo $2^k$.
$$ f(p, k) = \int_0^x p(t),dt \bmod 2^k = \sum_{i=0}^{n-1} \frac{a_i}{i+1}x^{i+1} \bmod 2^k. $$
The coefficient of $x^{i-1}$ is divided by $i$ and moved to $x^i$. Only odd numbers are units modulo $2^k$, so every nonzero coefficient must belong to an even power of $x$; a zero coefficient stays zero. The divisions share a single inversion modulo $2^k$. The integral of zero is zero, for every $k$.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is self.len().
§Panics
Panics if pow is greater than T::WIDTH, if any coefficient is greater than or equal to
$2^k$, or if the coefficient of an odd power of $x$ is nonzero.
§Examples
use core::str::FromStr;
use malachite_base::polynomial::ModPowerOf2Integral;
use malachite_base::unsigned_polynomial::UnsignedPolynomial;
// Dividing by 3 is multiplying by 3 modulo 8.
assert_eq!(
UnsignedPolynomial::<u8>::from_str("x^2")
.unwrap()
.mod_power_of_2_integral(3)
.to_string(),
"3*x^3"
);
// Dividing by 5 is multiplying by 13 modulo 16.
assert_eq!(
UnsignedPolynomial::<u8>::from_str("x^4+1")
.unwrap()
.mod_power_of_2_integral(4)
.to_string(),
"13*x^5+x"
);This is nmod_poly_integral from nmod_poly/integral.c, FLINT 3.6.0, with the modulus
$2^k$, except that FLINT needs every index from 1 to the degree plus 1 to be a unit, even
when its coefficient is zero, and so cannot integrate any polynomial of degree at least 1
modulo $2^k$.
type Output = UnsignedPolynomial<T>
Source§impl<T: PrimitiveUnsigned> ModPowerOf2Integral for &UnsignedPolynomial<T>
impl<T: PrimitiveUnsigned> ModPowerOf2Integral for &UnsignedPolynomial<T>
Source§fn mod_power_of_2_integral(self, pow: u64) -> UnsignedPolynomial<T>
fn mod_power_of_2_integral(self, pow: u64) -> UnsignedPolynomial<T>
Computes the integral modulo $2^k$ of an UnsignedPolynomial whose constant term is zero,
taking the polynomial by reference. Its coefficients must already be reduced modulo $2^k$.
$$ f(p, k) = \int_0^x p(t),dt \bmod 2^k = \sum_{i=0}^{n-1} \frac{a_i}{i+1}x^{i+1} \bmod 2^k. $$
The coefficient of $x^{i-1}$ is divided by $i$ and moved to $x^i$. Only odd numbers are units modulo $2^k$, so every nonzero coefficient must belong to an even power of $x$; a zero coefficient stays zero. The divisions share a single inversion modulo $2^k$. The integral of zero is zero, for every $k$.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is self.len().
§Panics
Panics if pow is greater than T::WIDTH, if any coefficient is greater than or equal to
$2^k$, or if the coefficient of an odd power of $x$ is nonzero.
§Examples
use core::str::FromStr;
use malachite_base::polynomial::ModPowerOf2Integral;
use malachite_base::unsigned_polynomial::UnsignedPolynomial;
// Dividing by 3 is multiplying by 3 modulo 8.
assert_eq!(
(&UnsignedPolynomial::<u8>::from_str("x^2").unwrap())
.mod_power_of_2_integral(3)
.to_string(),
"3*x^3"
);
// Dividing by 5 is multiplying by 13 modulo 16.
assert_eq!(
(&UnsignedPolynomial::<u8>::from_str("x^4+1").unwrap())
.mod_power_of_2_integral(4)
.to_string(),
"13*x^5+x"
);This is nmod_poly_integral from nmod_poly/integral.c, FLINT 3.6.0, with the modulus
$2^k$, except that FLINT needs every index from 1 to the degree plus 1 to be a unit, even
when its coefficient is zero, and so cannot integrate any polynomial of degree at least 1
modulo $2^k$.
type Output = UnsignedPolynomial<T>
Source§impl<T: PrimitiveUnsigned> ModPowerOf2IntegralAssign for UnsignedPolynomial<T>
impl<T: PrimitiveUnsigned> ModPowerOf2IntegralAssign for UnsignedPolynomial<T>
Source§fn mod_power_of_2_integral_assign(&mut self, pow: u64)
fn mod_power_of_2_integral_assign(&mut self, pow: u64)
Replaces an UnsignedPolynomial with its integral modulo $2^k$ whose constant term is
zero. Its coefficients must already be reduced modulo $2^k$.
$$ p \gets \int_0^x p(t),dt \bmod 2^k = \sum_{i=0}^{n-1} \frac{a_i}{i+1}x^{i+1} \bmod 2^k. $$
The coefficient of $x^{i-1}$ is divided by $i$ and moved to $x^i$. Only odd numbers are units modulo $2^k$, so every nonzero coefficient must belong to an even power of $x$; a zero coefficient stays zero. The divisions share a single inversion modulo $2^k$. The integral of zero is zero, for every $k$.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is self.len().
§Panics
Panics if pow is greater than T::WIDTH, if any coefficient is greater than or equal to
$2^k$, or if the coefficient of an odd power of $x$ is nonzero.
§Examples
use core::str::FromStr;
use malachite_base::polynomial::ModPowerOf2IntegralAssign;
use malachite_base::unsigned_polynomial::UnsignedPolynomial;
let mut p = UnsignedPolynomial::<u8>::from_str("x^2").unwrap();
p.mod_power_of_2_integral_assign(3);
assert_eq!(p.to_string(), "3*x^3");This is nmod_poly_integral from nmod_poly/integral.c, FLINT 3.6.0, with the modulus
$2^k$, except that FLINT needs every index from 1 to the degree plus 1 to be a unit, even
when its coefficient is zero, and so cannot integrate any polynomial of degree at least 1
modulo $2^k$.
Source§impl<T: PrimitiveUnsigned> ModPowerOf2IsReduced for UnsignedPolynomial<T>
impl<T: PrimitiveUnsigned> ModPowerOf2IsReduced for UnsignedPolynomial<T>
Source§fn mod_power_of_2_is_reduced(&self, pow: u64) -> bool
fn mod_power_of_2_is_reduced(&self, pow: u64) -> bool
Returns whether a UnsignedPolynomial is reduced modulo $2^k$; in other words, whether
every one of its coefficients has no more than $k$ significant bits.
Asking that of every coefficient is asking it of the largest, so this is the number of
significant bits of the polynomial’s Height — which bit length
being monotone means is the largest of the coefficients’ bit lengths, so the height itself
never has to be built. The zero polynomial has no coefficients and is reduced modulo every
power of 2, including $2^0$.
$f(p, k) = (\max_i p_i < 2^k)$.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is the number of coefficients.
§Examples
use core::str::FromStr;
use malachite_base::num::arithmetic::traits::ModPowerOf2IsReduced;
use malachite_base::unsigned_polynomial::UnsignedPolynomial;
// The largest coefficient is 3, which needs two bits.
let p = UnsignedPolynomial::<u64>::from_str("x^2+3*x+2").unwrap();
assert_eq!(p.mod_power_of_2_is_reduced(2), true);
assert_eq!(p.mod_power_of_2_is_reduced(1), false);
// The zero polynomial is reduced modulo every power of 2.
assert_eq!(
UnsignedPolynomial::<u64>::from_str("0")
.unwrap()
.mod_power_of_2_is_reduced(0),
true
);Source§impl<T: PrimitiveUnsigned> ModPowerOf2Mul for UnsignedPolynomial<T>
impl<T: PrimitiveUnsigned> ModPowerOf2Mul for UnsignedPolynomial<T>
Source§fn mod_power_of_2_mul(self, other: Self, pow: u64) -> Self
fn mod_power_of_2_mul(self, other: Self, pow: u64) -> Self
Multiplies two UnsignedPolynomials modulo $2^k$, taking both by value. The coefficients
of both must already be reduced modulo $2^k$.
$$ f(p, q, k) = pq \bmod 2^k. $$
The leading coefficient of the product can vanish modulo $2^k$, and then the degree of the product is lower than the sum of the degrees.
§Worst-case complexity
$T(n) = O(n^{\log_2 3})$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is the length of the longer polynomial.
§Panics
Panics if pow is greater than T::WIDTH, or if any coefficient of self or other is
greater than or equal to $2^k$.
§Examples
use core::str::FromStr;
use malachite_base::num::arithmetic::traits::ModPowerOf2Mul;
use malachite_base::unsigned_polynomial::UnsignedPolynomial;
// The coefficients wrap around modulo 16.
assert_eq!(
UnsignedPolynomial::<u8>::from_str("x^2+3*x+2")
.unwrap()
.mod_power_of_2_mul(UnsignedPolynomial::<u8>::from_str("2*x+5").unwrap(), 4)
.to_string(),
"2*x^3+11*x^2+3*x+10"
);
// The leading coefficient vanishes modulo 16, so the degree drops.
assert_eq!(
UnsignedPolynomial::<u8>::from_str("8*x+1")
.unwrap()
.mod_power_of_2_mul(UnsignedPolynomial::<u8>::from_str("2*x+1").unwrap(), 4)
.to_string(),
"10*x+1"
);This is equivalent to nmod_poly_mul from nmod_poly/mul.c, FLINT 3.6.0, with the modulus
$2^k$.
type Output = UnsignedPolynomial<T>
Source§impl<T: PrimitiveUnsigned> ModPowerOf2Mul<&UnsignedPolynomial<T>> for UnsignedPolynomial<T>
impl<T: PrimitiveUnsigned> ModPowerOf2Mul<&UnsignedPolynomial<T>> for UnsignedPolynomial<T>
Source§fn mod_power_of_2_mul(self, other: &Self, pow: u64) -> Self
fn mod_power_of_2_mul(self, other: &Self, pow: u64) -> Self
Multiplies two UnsignedPolynomials modulo $2^k$, taking the first by value and the
second by reference. The coefficients of both must already be reduced modulo $2^k$.
$$ f(p, q, k) = pq \bmod 2^k. $$
The leading coefficient of the product can vanish modulo $2^k$, and then the degree of the product is lower than the sum of the degrees.
§Worst-case complexity
$T(n) = O(n^{\log_2 3})$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is the length of the longer polynomial.
§Panics
Panics if pow is greater than T::WIDTH, or if any coefficient of self or other is
greater than or equal to $2^k$.
§Examples
use core::str::FromStr;
use malachite_base::num::arithmetic::traits::ModPowerOf2Mul;
use malachite_base::unsigned_polynomial::UnsignedPolynomial;
// The coefficients wrap around modulo 16.
assert_eq!(
UnsignedPolynomial::<u8>::from_str("x^2+3*x+2")
.unwrap()
.mod_power_of_2_mul(&UnsignedPolynomial::<u8>::from_str("2*x+5").unwrap(), 4)
.to_string(),
"2*x^3+11*x^2+3*x+10"
);
// The leading coefficient vanishes modulo 16, so the degree drops.
assert_eq!(
UnsignedPolynomial::<u8>::from_str("8*x+1")
.unwrap()
.mod_power_of_2_mul(&UnsignedPolynomial::<u8>::from_str("2*x+1").unwrap(), 4)
.to_string(),
"10*x+1"
);This is equivalent to nmod_poly_mul from nmod_poly/mul.c, FLINT 3.6.0, with the modulus
$2^k$.
type Output = UnsignedPolynomial<T>
Source§impl<T: PrimitiveUnsigned> ModPowerOf2Mul<&UnsignedPolynomial<T>> for &UnsignedPolynomial<T>
impl<T: PrimitiveUnsigned> ModPowerOf2Mul<&UnsignedPolynomial<T>> for &UnsignedPolynomial<T>
Source§fn mod_power_of_2_mul(
self,
other: &UnsignedPolynomial<T>,
pow: u64,
) -> UnsignedPolynomial<T>
fn mod_power_of_2_mul( self, other: &UnsignedPolynomial<T>, pow: u64, ) -> UnsignedPolynomial<T>
Multiplies two UnsignedPolynomials modulo $2^k$, taking both by reference. The
coefficients of both must already be reduced modulo $2^k$.
$$ f(p, q, k) = pq \bmod 2^k. $$
The leading coefficient of the product can vanish modulo $2^k$, and then the degree of the product is lower than the sum of the degrees.
§Worst-case complexity
$T(n) = O(n^{\log_2 3})$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is the length of the longer polynomial.
§Panics
Panics if pow is greater than T::WIDTH, or if any coefficient of self or other is
greater than or equal to $2^k$.
§Examples
use core::str::FromStr;
use malachite_base::num::arithmetic::traits::ModPowerOf2Mul;
use malachite_base::unsigned_polynomial::UnsignedPolynomial;
// The coefficients wrap around modulo 16.
assert_eq!(
(&UnsignedPolynomial::<u8>::from_str("x^2+3*x+2").unwrap())
.mod_power_of_2_mul(&UnsignedPolynomial::<u8>::from_str("2*x+5").unwrap(), 4)
.to_string(),
"2*x^3+11*x^2+3*x+10"
);
// The leading coefficient vanishes modulo 16, so the degree drops.
assert_eq!(
(&UnsignedPolynomial::<u8>::from_str("8*x+1").unwrap())
.mod_power_of_2_mul(&UnsignedPolynomial::<u8>::from_str("2*x+1").unwrap(), 4)
.to_string(),
"10*x+1"
);This is equivalent to nmod_poly_mul from nmod_poly/mul.c, FLINT 3.6.0, with the modulus
$2^k$.
type Output = UnsignedPolynomial<T>
Source§impl<T: PrimitiveUnsigned> ModPowerOf2Mul<UnsignedPolynomial<T>> for &UnsignedPolynomial<T>
impl<T: PrimitiveUnsigned> ModPowerOf2Mul<UnsignedPolynomial<T>> for &UnsignedPolynomial<T>
Source§fn mod_power_of_2_mul(
self,
other: UnsignedPolynomial<T>,
pow: u64,
) -> UnsignedPolynomial<T>
fn mod_power_of_2_mul( self, other: UnsignedPolynomial<T>, pow: u64, ) -> UnsignedPolynomial<T>
Multiplies two UnsignedPolynomials modulo $2^k$, taking the first by reference and the
second by value. The coefficients of both must already be reduced modulo $2^k$.
$$ f(p, q, k) = pq \bmod 2^k. $$
The leading coefficient of the product can vanish modulo $2^k$, and then the degree of the product is lower than the sum of the degrees.
§Worst-case complexity
$T(n) = O(n^{\log_2 3})$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is the length of the longer polynomial.
§Panics
Panics if pow is greater than T::WIDTH, or if any coefficient of self or other is
greater than or equal to $2^k$.
§Examples
use core::str::FromStr;
use malachite_base::num::arithmetic::traits::ModPowerOf2Mul;
use malachite_base::unsigned_polynomial::UnsignedPolynomial;
// The coefficients wrap around modulo 16.
assert_eq!(
(&UnsignedPolynomial::<u8>::from_str("x^2+3*x+2").unwrap())
.mod_power_of_2_mul(UnsignedPolynomial::<u8>::from_str("2*x+5").unwrap(), 4)
.to_string(),
"2*x^3+11*x^2+3*x+10"
);
// The leading coefficient vanishes modulo 16, so the degree drops.
assert_eq!(
(&UnsignedPolynomial::<u8>::from_str("8*x+1").unwrap())
.mod_power_of_2_mul(UnsignedPolynomial::<u8>::from_str("2*x+1").unwrap(), 4)
.to_string(),
"10*x+1"
);This is equivalent to nmod_poly_mul from nmod_poly/mul.c, FLINT 3.6.0, with the modulus
$2^k$.
type Output = UnsignedPolynomial<T>
Source§impl<T: PrimitiveUnsigned> ModPowerOf2MulAssign for UnsignedPolynomial<T>
impl<T: PrimitiveUnsigned> ModPowerOf2MulAssign for UnsignedPolynomial<T>
Source§fn mod_power_of_2_mul_assign(&mut self, other: Self, pow: u64)
fn mod_power_of_2_mul_assign(&mut self, other: Self, pow: u64)
Multiplies an UnsignedPolynomial by another UnsignedPolynomial modulo $2^k$ in
place, taking the right-hand side by value. The coefficients of both must already be reduced
modulo $2^k$.
$$ p \gets pq \bmod 2^k. $$
§Worst-case complexity
$T(n) = O(n^{\log_2 3})$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is the length of the longer polynomial.
§Panics
Panics if pow is greater than T::WIDTH, or if any coefficient of self or other is
greater than or equal to $2^k$.
§Examples
use core::str::FromStr;
use malachite_base::num::arithmetic::traits::ModPowerOf2MulAssign;
use malachite_base::unsigned_polynomial::UnsignedPolynomial;
let mut p = UnsignedPolynomial::<u8>::from_str("x^2+3*x+2").unwrap();
p.mod_power_of_2_mul_assign(UnsignedPolynomial::<u8>::from_str("2*x+5").unwrap(), 4);
assert_eq!(p.to_string(), "2*x^3+11*x^2+3*x+10");This is equivalent to nmod_poly_mul from nmod_poly/mul.c, FLINT 3.6.0, with the modulus
$2^k$.
Source§impl<T: PrimitiveUnsigned> ModPowerOf2MulAssign<&UnsignedPolynomial<T>> for UnsignedPolynomial<T>
impl<T: PrimitiveUnsigned> ModPowerOf2MulAssign<&UnsignedPolynomial<T>> for UnsignedPolynomial<T>
Source§fn mod_power_of_2_mul_assign(&mut self, other: &Self, pow: u64)
fn mod_power_of_2_mul_assign(&mut self, other: &Self, pow: u64)
Multiplies an UnsignedPolynomial by another UnsignedPolynomial modulo $2^k$ in
place, taking the right-hand side by reference. The coefficients of both must already be
reduced modulo $2^k$.
$$ p \gets pq \bmod 2^k. $$
§Worst-case complexity
$T(n) = O(n^{\log_2 3})$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is the length of the longer polynomial.
§Panics
Panics if pow is greater than T::WIDTH, or if any coefficient of self or other is
greater than or equal to $2^k$.
§Examples
use core::str::FromStr;
use malachite_base::num::arithmetic::traits::ModPowerOf2MulAssign;
use malachite_base::unsigned_polynomial::UnsignedPolynomial;
let mut p = UnsignedPolynomial::<u8>::from_str("x^2+3*x+2").unwrap();
p.mod_power_of_2_mul_assign(&UnsignedPolynomial::<u8>::from_str("2*x+5").unwrap(), 4);
assert_eq!(p.to_string(), "2*x^3+11*x^2+3*x+10");This is equivalent to nmod_poly_mul from nmod_poly/mul.c, FLINT 3.6.0, with the modulus
$2^k$.
Source§impl<T: PrimitiveUnsigned> ModPowerOf2MulTruncated for UnsignedPolynomial<T>
impl<T: PrimitiveUnsigned> ModPowerOf2MulTruncated for UnsignedPolynomial<T>
Source§fn mod_power_of_2_mul_truncated(self, other: Self, len: u64, pow: u64) -> Self
fn mod_power_of_2_mul_truncated(self, other: Self, len: u64, pow: u64) -> Self
Multiplies two UnsignedPolynomials modulo $2^k$, keeping only the coefficients of $x^i$
for $i$ less than len, taking both by value. The coefficients of both must already be
reduced modulo $2^k$.
$$ f(p, q, n, k) = (pq \bmod x^n) \bmod 2^k. $$
The polynomials need not already be truncated: this is the product of their images modulo
$x^n$, so only their first len coefficients are read.
§Worst-case complexity
$T(n) = O(n^{\log_2 3})$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is len.
§Panics
Panics if pow is greater than T::WIDTH, or if any coefficient of self or other is
greater than or equal to $2^k$.
§Examples
use core::str::FromStr;
use malachite_base::polynomial::ModPowerOf2MulTruncated;
use malachite_base::unsigned_polynomial::UnsignedPolynomial;
// The product is 2*x^3+11*x^2+19*x+10; its low two coefficients, modulo 16.
assert_eq!(
UnsignedPolynomial::<u8>::from_str("x^2+3*x+2")
.unwrap()
.mod_power_of_2_mul_truncated(
UnsignedPolynomial::<u8>::from_str("2*x+5").unwrap(),
2,
4
)
.to_string(),
"3*x+10"
);
// The linear coefficient of the product, 16, vanishes modulo 16.
assert_eq!(
UnsignedPolynomial::<u8>::from_str("x+15")
.unwrap()
.mod_power_of_2_mul_truncated(
UnsignedPolynomial::<u8>::from_str("x+1").unwrap(),
2,
4
)
.to_string(),
"15"
);This is equivalent to nmod_poly_mullow from nmod_poly/mullow.c, FLINT 3.6.0, with the
modulus $2^k$.
type Output = UnsignedPolynomial<T>
Source§impl<T: PrimitiveUnsigned> ModPowerOf2MulTruncated<&UnsignedPolynomial<T>> for UnsignedPolynomial<T>
impl<T: PrimitiveUnsigned> ModPowerOf2MulTruncated<&UnsignedPolynomial<T>> for UnsignedPolynomial<T>
Source§fn mod_power_of_2_mul_truncated(self, other: &Self, len: u64, pow: u64) -> Self
fn mod_power_of_2_mul_truncated(self, other: &Self, len: u64, pow: u64) -> Self
Multiplies two UnsignedPolynomials modulo $2^k$, keeping only the coefficients of $x^i$
for $i$ less than len, taking the first by value and the second by reference. The
coefficients of both must already be reduced modulo $2^k$.
$$ f(p, q, n, k) = (pq \bmod x^n) \bmod 2^k. $$
The polynomials need not already be truncated: this is the product of their images modulo
$x^n$, so only their first len coefficients are read.
§Worst-case complexity
$T(n) = O(n^{\log_2 3})$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is len.
§Panics
Panics if pow is greater than T::WIDTH, or if any coefficient of self or other is
greater than or equal to $2^k$.
§Examples
use core::str::FromStr;
use malachite_base::polynomial::ModPowerOf2MulTruncated;
use malachite_base::unsigned_polynomial::UnsignedPolynomial;
// The product is 2*x^3+11*x^2+19*x+10; its low two coefficients, modulo 16.
assert_eq!(
UnsignedPolynomial::<u8>::from_str("x^2+3*x+2")
.unwrap()
.mod_power_of_2_mul_truncated(
&UnsignedPolynomial::<u8>::from_str("2*x+5").unwrap(),
2,
4
)
.to_string(),
"3*x+10"
);
// The linear coefficient of the product, 16, vanishes modulo 16.
assert_eq!(
UnsignedPolynomial::<u8>::from_str("x+15")
.unwrap()
.mod_power_of_2_mul_truncated(
&UnsignedPolynomial::<u8>::from_str("x+1").unwrap(),
2,
4
)
.to_string(),
"15"
);This is equivalent to nmod_poly_mullow from nmod_poly/mullow.c, FLINT 3.6.0, with the
modulus $2^k$.
type Output = UnsignedPolynomial<T>
Source§impl<T: PrimitiveUnsigned> ModPowerOf2MulTruncated<&UnsignedPolynomial<T>> for &UnsignedPolynomial<T>
impl<T: PrimitiveUnsigned> ModPowerOf2MulTruncated<&UnsignedPolynomial<T>> for &UnsignedPolynomial<T>
Source§fn mod_power_of_2_mul_truncated(
self,
other: &UnsignedPolynomial<T>,
len: u64,
pow: u64,
) -> UnsignedPolynomial<T>
fn mod_power_of_2_mul_truncated( self, other: &UnsignedPolynomial<T>, len: u64, pow: u64, ) -> UnsignedPolynomial<T>
Multiplies two UnsignedPolynomials modulo $2^k$, keeping only the coefficients of $x^i$
for $i$ less than len, taking both by reference. The coefficients of both must already be
reduced modulo $2^k$.
$$ f(p, q, n, k) = (pq \bmod x^n) \bmod 2^k. $$
The polynomials need not already be truncated: this is the product of their images modulo
$x^n$, so only their first len coefficients are read.
§Worst-case complexity
$T(n) = O(n^{\log_2 3})$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is len.
§Panics
Panics if pow is greater than T::WIDTH, or if any coefficient of self or other is
greater than or equal to $2^k$.
§Examples
use core::str::FromStr;
use malachite_base::polynomial::ModPowerOf2MulTruncated;
use malachite_base::unsigned_polynomial::UnsignedPolynomial;
// The product is 2*x^3+11*x^2+19*x+10; its low two coefficients, modulo 16.
assert_eq!(
(&UnsignedPolynomial::<u8>::from_str("x^2+3*x+2").unwrap())
.mod_power_of_2_mul_truncated(
&UnsignedPolynomial::<u8>::from_str("2*x+5").unwrap(),
2,
4
)
.to_string(),
"3*x+10"
);
// The linear coefficient of the product, 16, vanishes modulo 16.
assert_eq!(
(&UnsignedPolynomial::<u8>::from_str("x+15").unwrap())
.mod_power_of_2_mul_truncated(
&UnsignedPolynomial::<u8>::from_str("x+1").unwrap(),
2,
4
)
.to_string(),
"15"
);This is equivalent to nmod_poly_mullow from nmod_poly/mullow.c, FLINT 3.6.0, with the
modulus $2^k$.
type Output = UnsignedPolynomial<T>
Source§impl<T: PrimitiveUnsigned> ModPowerOf2MulTruncated<UnsignedPolynomial<T>> for &UnsignedPolynomial<T>
impl<T: PrimitiveUnsigned> ModPowerOf2MulTruncated<UnsignedPolynomial<T>> for &UnsignedPolynomial<T>
Source§fn mod_power_of_2_mul_truncated(
self,
other: UnsignedPolynomial<T>,
len: u64,
pow: u64,
) -> UnsignedPolynomial<T>
fn mod_power_of_2_mul_truncated( self, other: UnsignedPolynomial<T>, len: u64, pow: u64, ) -> UnsignedPolynomial<T>
Multiplies two UnsignedPolynomials modulo $2^k$, keeping only the coefficients of $x^i$
for $i$ less than len, taking the first by reference and the second by value. The
coefficients of both must already be reduced modulo $2^k$.
$$ f(p, q, n, k) = (pq \bmod x^n) \bmod 2^k. $$
The polynomials need not already be truncated: this is the product of their images modulo
$x^n$, so only their first len coefficients are read.
§Worst-case complexity
$T(n) = O(n^{\log_2 3})$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is len.
§Panics
Panics if pow is greater than T::WIDTH, or if any coefficient of self or other is
greater than or equal to $2^k$.
§Examples
use core::str::FromStr;
use malachite_base::polynomial::ModPowerOf2MulTruncated;
use malachite_base::unsigned_polynomial::UnsignedPolynomial;
// The product is 2*x^3+11*x^2+19*x+10; its low two coefficients, modulo 16.
assert_eq!(
(&UnsignedPolynomial::<u8>::from_str("x^2+3*x+2").unwrap())
.mod_power_of_2_mul_truncated(
UnsignedPolynomial::<u8>::from_str("2*x+5").unwrap(),
2,
4
)
.to_string(),
"3*x+10"
);
// The linear coefficient of the product, 16, vanishes modulo 16.
assert_eq!(
(&UnsignedPolynomial::<u8>::from_str("x+15").unwrap())
.mod_power_of_2_mul_truncated(
UnsignedPolynomial::<u8>::from_str("x+1").unwrap(),
2,
4
)
.to_string(),
"15"
);This is equivalent to nmod_poly_mullow from nmod_poly/mullow.c, FLINT 3.6.0, with the
modulus $2^k$.
type Output = UnsignedPolynomial<T>
Source§impl<T: PrimitiveUnsigned> ModPowerOf2MulTruncatedAssign for UnsignedPolynomial<T>
impl<T: PrimitiveUnsigned> ModPowerOf2MulTruncatedAssign for UnsignedPolynomial<T>
Source§fn mod_power_of_2_mul_truncated_assign(
&mut self,
other: Self,
len: u64,
pow: u64,
)
fn mod_power_of_2_mul_truncated_assign( &mut self, other: Self, len: u64, pow: u64, )
Multiplies an UnsignedPolynomial by another UnsignedPolynomial modulo $2^k$ in
place, keeping only the coefficients of $x^i$ for $i$ less than len, taking the right-hand
side by value. The coefficients of both must already be reduced modulo $2^k$.
$$ p \gets (pq \bmod x^n) \bmod 2^k. $$
§Worst-case complexity
$T(n) = O(n^{\log_2 3})$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is len.
§Panics
Panics if pow is greater than T::WIDTH, or if any coefficient of self or other is
greater than or equal to $2^k$.
§Examples
use core::str::FromStr;
use malachite_base::polynomial::ModPowerOf2MulTruncatedAssign;
use malachite_base::unsigned_polynomial::UnsignedPolynomial;
let mut p = UnsignedPolynomial::<u8>::from_str("x^2+3*x+2").unwrap();
p.mod_power_of_2_mul_truncated_assign(
UnsignedPolynomial::<u8>::from_str("2*x+5").unwrap(),
2,
4,
);
assert_eq!(p.to_string(), "3*x+10");This is equivalent to nmod_poly_mullow from nmod_poly/mullow.c, FLINT 3.6.0, with the
modulus $2^k$.
Source§impl<T: PrimitiveUnsigned> ModPowerOf2MulTruncatedAssign<&UnsignedPolynomial<T>> for UnsignedPolynomial<T>
impl<T: PrimitiveUnsigned> ModPowerOf2MulTruncatedAssign<&UnsignedPolynomial<T>> for UnsignedPolynomial<T>
Source§fn mod_power_of_2_mul_truncated_assign(
&mut self,
other: &Self,
len: u64,
pow: u64,
)
fn mod_power_of_2_mul_truncated_assign( &mut self, other: &Self, len: u64, pow: u64, )
Multiplies an UnsignedPolynomial by another UnsignedPolynomial modulo $2^k$ in
place, keeping only the coefficients of $x^i$ for $i$ less than len, taking the right-hand
side by reference. The coefficients of both must already be reduced modulo $2^k$.
$$ p \gets (pq \bmod x^n) \bmod 2^k. $$
§Worst-case complexity
$T(n) = O(n^{\log_2 3})$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is len.
§Panics
Panics if pow is greater than T::WIDTH, or if any coefficient of self or other is
greater than or equal to $2^k$.
§Examples
use core::str::FromStr;
use malachite_base::polynomial::ModPowerOf2MulTruncatedAssign;
use malachite_base::unsigned_polynomial::UnsignedPolynomial;
let mut p = UnsignedPolynomial::<u8>::from_str("x^2+3*x+2").unwrap();
p.mod_power_of_2_mul_truncated_assign(
&UnsignedPolynomial::<u8>::from_str("2*x+5").unwrap(),
2,
4,
);
assert_eq!(p.to_string(), "3*x+10");This is equivalent to nmod_poly_mullow from nmod_poly/mullow.c, FLINT 3.6.0, with the
modulus $2^k$.
Source§impl<T: PrimitiveUnsigned> ModPowerOf2Neg for UnsignedPolynomial<T>
impl<T: PrimitiveUnsigned> ModPowerOf2Neg for UnsignedPolynomial<T>
Source§fn mod_power_of_2_neg(self, pow: u64) -> Self
fn mod_power_of_2_neg(self, pow: u64) -> Self
Negates an UnsignedPolynomial modulo $2^k$, taking the polynomial by value. The
coefficients must already be reduced modulo $2^k$.
Each nonzero coefficient $c$ becomes $2^k - c$, which is also nonzero, so the degree is unchanged. The zero polynomial is its own negation.
$$ f(p, k) = -p \bmod 2^k. $$
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is the number of coefficients.
§Panics
Panics if pow is greater than T::WIDTH, or if any coefficient of self is greater than
or equal to $2^k$.
§Examples
use core::str::FromStr;
use malachite_base::num::arithmetic::traits::ModPowerOf2Neg;
use malachite_base::num::basic::traits::Zero;
use malachite_base::unsigned_polynomial::UnsignedPolynomial;
let p = UnsignedPolynomial::<u8>::from_str("5*x^2+x+3").unwrap();
assert_eq!(p.clone().mod_power_of_2_neg(3).to_string(), "3*x^2+7*x+5");
let p = UnsignedPolynomial::<u8>::from_str("x").unwrap();
assert_eq!(p.clone().mod_power_of_2_neg(8).to_string(), "255*x");
assert_eq!(
UnsignedPolynomial::<u8>::ZERO.mod_power_of_2_neg(3),
UnsignedPolynomial::<u8>::ZERO
);This is equivalent to nmod_poly_neg from nmod_poly/neg.c, FLINT 3.6.0, with the modulus
$2^k$.
type Output = UnsignedPolynomial<T>
Source§impl<T: PrimitiveUnsigned> ModPowerOf2Neg for &UnsignedPolynomial<T>
impl<T: PrimitiveUnsigned> ModPowerOf2Neg for &UnsignedPolynomial<T>
Source§fn mod_power_of_2_neg(self, pow: u64) -> UnsignedPolynomial<T>
fn mod_power_of_2_neg(self, pow: u64) -> UnsignedPolynomial<T>
Negates an UnsignedPolynomial modulo $2^k$, taking the polynomial by reference. The
coefficients must already be reduced modulo $2^k$.
Each nonzero coefficient $c$ becomes $2^k - c$, which is also nonzero, so the degree is unchanged. The zero polynomial is its own negation.
$$ f(p, k) = -p \bmod 2^k. $$
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is the number of coefficients.
§Panics
Panics if pow is greater than T::WIDTH, or if any coefficient of self is greater than
or equal to $2^k$.
§Examples
use core::str::FromStr;
use malachite_base::num::arithmetic::traits::ModPowerOf2Neg;
use malachite_base::num::basic::traits::Zero;
use malachite_base::unsigned_polynomial::UnsignedPolynomial;
let p = UnsignedPolynomial::<u8>::from_str("5*x^2+x+3").unwrap();
assert_eq!((&p).mod_power_of_2_neg(3).to_string(), "3*x^2+7*x+5");
let p = UnsignedPolynomial::<u8>::from_str("x").unwrap();
assert_eq!((&p).mod_power_of_2_neg(8).to_string(), "255*x");
assert_eq!(
UnsignedPolynomial::<u8>::ZERO.mod_power_of_2_neg(3),
UnsignedPolynomial::<u8>::ZERO
);This is equivalent to nmod_poly_neg from nmod_poly/neg.c, FLINT 3.6.0, with the modulus
$2^k$.
type Output = UnsignedPolynomial<T>
Source§impl<T: PrimitiveUnsigned> ModPowerOf2NegAssign for UnsignedPolynomial<T>
impl<T: PrimitiveUnsigned> ModPowerOf2NegAssign for UnsignedPolynomial<T>
Source§fn mod_power_of_2_neg_assign(&mut self, pow: u64)
fn mod_power_of_2_neg_assign(&mut self, pow: u64)
Negates an UnsignedPolynomial modulo $2^k$, in place. The coefficients must already be
reduced modulo $2^k$.
See mod_power_of_2_neg.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is the number of coefficients.
§Panics
Panics if pow is greater than T::WIDTH, or if any coefficient of self is greater than
or equal to $2^k$.
§Examples
use core::str::FromStr;
use malachite_base::num::arithmetic::traits::ModPowerOf2NegAssign;
use malachite_base::unsigned_polynomial::UnsignedPolynomial;
let mut p = UnsignedPolynomial::<u8>::from_str("5*x^2+x+3").unwrap();
p.mod_power_of_2_neg_assign(3);
assert_eq!(p.to_string(), "3*x^2+7*x+5");Source§impl<T: PrimitiveUnsigned> ModPowerOf2NthDerivative for UnsignedPolynomial<T>
impl<T: PrimitiveUnsigned> ModPowerOf2NthDerivative for UnsignedPolynomial<T>
Source§fn mod_power_of_2_nth_derivative(self, n: u64, pow: u64) -> Self
fn mod_power_of_2_nth_derivative(self, n: u64, pow: u64) -> Self
Computes the $n$th derivative of an UnsignedPolynomial modulo $2^k$, taking the
polynomial by value. The coefficients must already be reduced modulo $2^k$.
$$ f(p, n, k) = p^{(n)} \bmod 2^k. $$
The coefficient of $x^i$ is multiplied by the falling factorial $i^{\underline n} = i(i-1)\cdots(i-n+1)$, reduced, and moved to $x^{i-n}$. The products can be zero even when the coefficients are not, so the derivative can lose any number of degrees; if $2^k$ divides $n!$, every falling factorial is a multiple of the modulus, and the result is zero.
§Worst-case complexity
$T(k, n) = O(kn)$
$M(k) = O(k)$
where $T$ is time, $M$ is additional memory, $k$ is self.len(), and $n$ is n.
§Panics
Panics if pow is greater than T::WIDTH, or if any coefficient of self is greater than
or equal to $2^k$.
§Examples
use core::str::FromStr;
use malachite_base::polynomial::ModPowerOf2NthDerivative;
use malachite_base::unsigned_polynomial::UnsignedPolynomial;
let p = UnsignedPolynomial::<u8>::from_str("x^4+3*x^3+2*x+5").unwrap();
assert_eq!(
p.clone().mod_power_of_2_nth_derivative(2, 3).to_string(),
"4*x^2+2*x"
);
assert_eq!(
p.mod_power_of_2_nth_derivative(0, 3).to_string(),
"x^4+3*x^3+2*x+5"
);
// 2^3 divides 4!.
let p = UnsignedPolynomial::<u8>::from_str("x^5+x^4").unwrap();
assert_eq!(p.mod_power_of_2_nth_derivative(4, 3).to_string(), "0");FLINT has no nmod_poly_nth_derivative; this computes the same multipliers as
fmpz_poly_nth_derivative from fmpz_poly/nth_derivative.c, FLINT 3.6.0, directly modulo
$2^k$.
type Output = UnsignedPolynomial<T>
Source§impl<T: PrimitiveUnsigned> ModPowerOf2NthDerivative for &UnsignedPolynomial<T>
impl<T: PrimitiveUnsigned> ModPowerOf2NthDerivative for &UnsignedPolynomial<T>
Source§fn mod_power_of_2_nth_derivative(
self,
n: u64,
pow: u64,
) -> UnsignedPolynomial<T>
fn mod_power_of_2_nth_derivative( self, n: u64, pow: u64, ) -> UnsignedPolynomial<T>
Computes the $n$th derivative of an UnsignedPolynomial modulo $2^k$, taking the
polynomial by reference. The coefficients must already be reduced modulo $2^k$.
$$ f(p, n, k) = p^{(n)} \bmod 2^k. $$
The coefficient of $x^i$ is multiplied by the falling factorial $i^{\underline n} = i(i-1)\cdots(i-n+1)$, reduced, and moved to $x^{i-n}$. The products can be zero even when the coefficients are not, so the derivative can lose any number of degrees; if $2^k$ divides $n!$, every falling factorial is a multiple of the modulus, and the result is zero.
§Worst-case complexity
$T(k, n) = O(kn)$
$M(k) = O(k)$
where $T$ is time, $M$ is additional memory, $k$ is self.len(), and $n$ is n.
§Panics
Panics if pow is greater than T::WIDTH, or if any coefficient of self is greater than
or equal to $2^k$.
§Examples
use core::str::FromStr;
use malachite_base::polynomial::ModPowerOf2NthDerivative;
use malachite_base::unsigned_polynomial::UnsignedPolynomial;
let p = UnsignedPolynomial::<u8>::from_str("x^4+3*x^3+2*x+5").unwrap();
assert_eq!(
(&p).mod_power_of_2_nth_derivative(2, 3).to_string(),
"4*x^2+2*x"
);
assert_eq!(
(&p).mod_power_of_2_nth_derivative(0, 3).to_string(),
"x^4+3*x^3+2*x+5"
);
// 2^3 divides 4!.
let p = UnsignedPolynomial::<u8>::from_str("x^5+x^4").unwrap();
assert_eq!((&p).mod_power_of_2_nth_derivative(4, 3).to_string(), "0");FLINT has no nmod_poly_nth_derivative; this computes the same multipliers as
fmpz_poly_nth_derivative from fmpz_poly/nth_derivative.c, FLINT 3.6.0, directly modulo
$2^k$.
type Output = UnsignedPolynomial<T>
Source§impl<T: PrimitiveUnsigned> ModPowerOf2NthDerivativeAssign for UnsignedPolynomial<T>
impl<T: PrimitiveUnsigned> ModPowerOf2NthDerivativeAssign for UnsignedPolynomial<T>
Source§fn mod_power_of_2_nth_derivative_assign(&mut self, n: u64, pow: u64)
fn mod_power_of_2_nth_derivative_assign(&mut self, n: u64, pow: u64)
Replaces an UnsignedPolynomial with its $n$th derivative modulo $2^k$, in place. The
coefficients must already be reduced modulo $2^k$.
$$ p \gets p^{(n)} \bmod 2^k. $$
The coefficient of $x^i$ is multiplied by the falling factorial $i^{\underline n} = i(i-1)\cdots(i-n+1)$, reduced, and moved to $x^{i-n}$. The products can be zero even when the coefficients are not, so the derivative can lose any number of degrees; if $2^k$ divides $n!$, every falling factorial is a multiple of the modulus, and the result is zero.
§Worst-case complexity
$T(k, n) = O(kn)$
$M(k) = O(k)$
where $T$ is time, $M$ is additional memory, $k$ is self.len(), and $n$ is n.
§Panics
Panics if pow is greater than T::WIDTH, or if any coefficient of self is greater than
or equal to $2^k$.
§Examples
use core::str::FromStr;
use malachite_base::polynomial::ModPowerOf2NthDerivativeAssign;
use malachite_base::unsigned_polynomial::UnsignedPolynomial;
let mut p = UnsignedPolynomial::<u8>::from_str("x^4+3*x^3+2*x+5").unwrap();
p.mod_power_of_2_nth_derivative_assign(2, 3);
assert_eq!(p.to_string(), "4*x^2+2*x");
// 2^3 divides 4!.
let mut p = UnsignedPolynomial::<u8>::from_str("x^5+x^4").unwrap();
p.mod_power_of_2_nth_derivative_assign(4, 3);
assert_eq!(p.to_string(), "0");FLINT has no nmod_poly_nth_derivative; this computes the same multipliers as
fmpz_poly_nth_derivative from fmpz_poly/nth_derivative.c, FLINT 3.6.0, directly modulo
$2^k$.
Source§impl<T: PrimitiveUnsigned> ModPowerOf2Pow<u64> for UnsignedPolynomial<T>
impl<T: PrimitiveUnsigned> ModPowerOf2Pow<u64> for UnsignedPolynomial<T>
Source§fn mod_power_of_2_pow(self, exp: u64, pow: u64) -> Self
fn mod_power_of_2_pow(self, exp: u64, pow: u64) -> Self
Raises an UnsignedPolynomial to a power modulo $2^k$, taking it by value. Its
coefficients must already be reduced modulo $2^k$.
$$ f(p, e, k) = p^e \bmod 2^k. $$
The zeroth power of every polynomial, including 0, is 1, which is 0 modulo $2^0$. The leading coefficients of a power can vanish modulo $2^k$, and then its degree is lower than $e$ times the degree of the polynomial. The power is computed by repeated squaring modulo $2^k$.
§Worst-case complexity
$T(n) = O(n^{\log_2 3} \log e)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, $n$ is exp times the length of the
polynomial, and $e$ is exp.
§Panics
Panics if pow is greater than T::WIDTH, or if any coefficient of self is greater than
or equal to $2^k$.
§Examples
use core::str::FromStr;
use malachite_base::num::arithmetic::traits::ModPowerOf2Pow;
use malachite_base::unsigned_polynomial::UnsignedPolynomial;
assert_eq!(
(UnsignedPolynomial::<u8>::from_str("x+1").unwrap())
.mod_power_of_2_pow(5, 3)
.to_string(),
"x^5+5*x^4+2*x^3+2*x^2+5*x+1"
);
// The square of 2*x+1 is 4*x^2+4*x+1, which is 1 modulo 4.
assert_eq!(
(UnsignedPolynomial::<u8>::from_str("2*x+1").unwrap())
.mod_power_of_2_pow(2, 2)
.to_string(),
"1"
);This is equivalent to nmod_poly_pow from nmod_poly/pow.c, FLINT 3.6.0, with the modulus
$2^k$, except that a factor of $x^\ell$ is removed before powering and that the intermediate
powers are trimmed.
type Output = UnsignedPolynomial<T>
Source§impl<T: PrimitiveUnsigned> ModPowerOf2Pow<u64> for &UnsignedPolynomial<T>
impl<T: PrimitiveUnsigned> ModPowerOf2Pow<u64> for &UnsignedPolynomial<T>
Source§fn mod_power_of_2_pow(self, exp: u64, pow: u64) -> UnsignedPolynomial<T>
fn mod_power_of_2_pow(self, exp: u64, pow: u64) -> UnsignedPolynomial<T>
Raises an UnsignedPolynomial to a power modulo $2^k$, taking it by reference. Its
coefficients must already be reduced modulo $2^k$.
$$ f(p, e, k) = p^e \bmod 2^k. $$
The zeroth power of every polynomial, including 0, is 1, which is 0 modulo $2^0$. The leading coefficients of a power can vanish modulo $2^k$, and then its degree is lower than $e$ times the degree of the polynomial. The power is computed by repeated squaring modulo $2^k$.
§Worst-case complexity
$T(n) = O(n^{\log_2 3} \log e)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, $n$ is exp times the length of the
polynomial, and $e$ is exp.
§Panics
Panics if pow is greater than T::WIDTH, or if any coefficient of self is greater than
or equal to $2^k$.
§Examples
use core::str::FromStr;
use malachite_base::num::arithmetic::traits::ModPowerOf2Pow;
use malachite_base::unsigned_polynomial::UnsignedPolynomial;
assert_eq!(
(&UnsignedPolynomial::<u8>::from_str("x+1").unwrap())
.mod_power_of_2_pow(5, 3)
.to_string(),
"x^5+5*x^4+2*x^3+2*x^2+5*x+1"
);
// The square of 2*x+1 is 4*x^2+4*x+1, which is 1 modulo 4.
assert_eq!(
(&UnsignedPolynomial::<u8>::from_str("2*x+1").unwrap())
.mod_power_of_2_pow(2, 2)
.to_string(),
"1"
);This is equivalent to nmod_poly_pow from nmod_poly/pow.c, FLINT 3.6.0, with the modulus
$2^k$, except that a factor of $x^\ell$ is removed before powering and that the intermediate
powers are trimmed.
type Output = UnsignedPolynomial<T>
Source§impl<T: PrimitiveUnsigned> ModPowerOf2PowAssign<u64> for UnsignedPolynomial<T>
impl<T: PrimitiveUnsigned> ModPowerOf2PowAssign<u64> for UnsignedPolynomial<T>
Source§fn mod_power_of_2_pow_assign(&mut self, exp: u64, pow: u64)
fn mod_power_of_2_pow_assign(&mut self, exp: u64, pow: u64)
Raises an UnsignedPolynomial to a power modulo $2^k$ in place. Its coefficients must
already be reduced modulo $2^k$.
$$ p \gets p^e \bmod 2^k. $$
The zeroth power of every polynomial, including 0, is 1, which is 0 modulo $2^0$. The leading coefficients of a power can vanish modulo $2^k$, and then its degree is lower than $e$ times the degree of the polynomial. The power is computed by repeated squaring modulo $2^k$.
§Worst-case complexity
$T(n) = O(n^{\log_2 3} \log e)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, $n$ is exp times the length of the
polynomial, and $e$ is exp.
§Panics
Panics if pow is greater than T::WIDTH, or if any coefficient of self is greater than
or equal to $2^k$.
§Examples
use core::str::FromStr;
use malachite_base::num::arithmetic::traits::ModPowerOf2PowAssign;
use malachite_base::unsigned_polynomial::UnsignedPolynomial;
let mut p = UnsignedPolynomial::<u8>::from_str("x+1").unwrap();
p.mod_power_of_2_pow_assign(5, 3);
assert_eq!(p.to_string(), "x^5+5*x^4+2*x^3+2*x^2+5*x+1");
// The square of 2*x+1 is 4*x^2+4*x+1, which is 1 modulo 4.
let mut p = UnsignedPolynomial::<u8>::from_str("2*x+1").unwrap();
p.mod_power_of_2_pow_assign(2, 2);
assert_eq!(p.to_string(), "1");This is equivalent to nmod_poly_pow from nmod_poly/pow.c, FLINT 3.6.0, with the modulus
$2^k$, except that a factor of $x^\ell$ is removed before powering and that the intermediate
powers are trimmed.
Source§impl<T: PrimitiveUnsigned> ModPowerOf2PowTruncated for UnsignedPolynomial<T>
impl<T: PrimitiveUnsigned> ModPowerOf2PowTruncated for UnsignedPolynomial<T>
Source§fn mod_power_of_2_pow_truncated(self, exp: u64, len: u64, pow: u64) -> Self
fn mod_power_of_2_pow_truncated(self, exp: u64, len: u64, pow: u64) -> Self
Raises an UnsignedPolynomial to a power modulo $2^k$, keeping only the coefficients of
$x^i$ for $i$ less than len, taking it by value. Its coefficients must already be reduced
modulo $2^k$.
$$ f(p, e, n, k) = (p^e \bmod x^n) \bmod 2^k. $$
The polynomial need not already be truncated: only its first len coefficients are read.
The zeroth power of every polynomial is 1, truncated to 0 when len is 0 and reduced to 0
when $k$ is 0. The power is computed by repeated truncated squaring modulo $2^k$.
§Worst-case complexity
$T(n) = O(n^{\log_2 3} \log e)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, $n$ is len, and $e$ is exp.
§Panics
Panics if pow is greater than T::WIDTH, or if any coefficient of self is greater than
or equal to $2^k$.
§Examples
use core::str::FromStr;
use malachite_base::polynomial::ModPowerOf2PowTruncated;
use malachite_base::unsigned_polynomial::UnsignedPolynomial;
assert_eq!(
(UnsignedPolynomial::<u8>::from_str("x+1").unwrap())
.mod_power_of_2_pow_truncated(5, 3, 3)
.to_string(),
"2*x^2+5*x+1"
);
// The power is a multiple of x^4.
assert_eq!(
(UnsignedPolynomial::<u8>::from_str("x^2+x").unwrap())
.mod_power_of_2_pow_truncated(4, 4, 3)
.to_string(),
"0"
);This is equivalent to nmod_poly_pow_trunc from nmod_poly/pow_trunc.c, FLINT 3.6.0, with
the modulus $2^k$, except that a factor of $x^\ell$ is removed before powering, that the
intermediate powers are trimmed rather than padded to len, and that the zeroth power of
the zero polynomial is 1 (modulo $2^k$), where FLINT gives 0.
type Output = UnsignedPolynomial<T>
Source§impl<T: PrimitiveUnsigned> ModPowerOf2PowTruncated for &UnsignedPolynomial<T>
impl<T: PrimitiveUnsigned> ModPowerOf2PowTruncated for &UnsignedPolynomial<T>
Source§fn mod_power_of_2_pow_truncated(
self,
exp: u64,
len: u64,
pow: u64,
) -> UnsignedPolynomial<T>
fn mod_power_of_2_pow_truncated( self, exp: u64, len: u64, pow: u64, ) -> UnsignedPolynomial<T>
Raises an UnsignedPolynomial to a power modulo $2^k$, keeping only the coefficients of
$x^i$ for $i$ less than len, taking it by reference. Its coefficients must already be
reduced modulo $2^k$.
$$ f(p, e, n, k) = (p^e \bmod x^n) \bmod 2^k. $$
The polynomial need not already be truncated: only its first len coefficients are read.
The zeroth power of every polynomial is 1, truncated to 0 when len is 0 and reduced to 0
when $k$ is 0. The power is computed by repeated truncated squaring modulo $2^k$.
§Worst-case complexity
$T(n) = O(n^{\log_2 3} \log e)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, $n$ is len, and $e$ is exp.
§Panics
Panics if pow is greater than T::WIDTH, or if any coefficient of self is greater than
or equal to $2^k$.
§Examples
use core::str::FromStr;
use malachite_base::polynomial::ModPowerOf2PowTruncated;
use malachite_base::unsigned_polynomial::UnsignedPolynomial;
assert_eq!(
(&UnsignedPolynomial::<u8>::from_str("x+1").unwrap())
.mod_power_of_2_pow_truncated(5, 3, 3)
.to_string(),
"2*x^2+5*x+1"
);
// The power is a multiple of x^4.
assert_eq!(
(&UnsignedPolynomial::<u8>::from_str("x^2+x").unwrap())
.mod_power_of_2_pow_truncated(4, 4, 3)
.to_string(),
"0"
);This is equivalent to nmod_poly_pow_trunc from nmod_poly/pow_trunc.c, FLINT 3.6.0, with
the modulus $2^k$, except that a factor of $x^\ell$ is removed before powering, that the
intermediate powers are trimmed rather than padded to len, and that the zeroth power of
the zero polynomial is 1 (modulo $2^k$), where FLINT gives 0.
type Output = UnsignedPolynomial<T>
Source§impl<T: PrimitiveUnsigned> ModPowerOf2PowTruncatedAssign for UnsignedPolynomial<T>
impl<T: PrimitiveUnsigned> ModPowerOf2PowTruncatedAssign for UnsignedPolynomial<T>
Source§fn mod_power_of_2_pow_truncated_assign(&mut self, exp: u64, len: u64, pow: u64)
fn mod_power_of_2_pow_truncated_assign(&mut self, exp: u64, len: u64, pow: u64)
Raises an UnsignedPolynomial to a power modulo $2^k$ in place, keeping only the
coefficients of $x^i$ for $i$ less than len. Its coefficients must already be reduced
modulo $2^k$.
$$ p \gets (p^e \bmod x^n) \bmod 2^k. $$
The polynomial need not already be truncated: only its first len coefficients are read.
The zeroth power of every polynomial is 1, truncated to 0 when len is 0 and reduced to 0
when $k$ is 0. The power is computed by repeated truncated squaring modulo $2^k$.
§Worst-case complexity
$T(n) = O(n^{\log_2 3} \log e)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, $n$ is len, and $e$ is exp.
§Panics
Panics if pow is greater than T::WIDTH, or if any coefficient of self is greater than
or equal to $2^k$.
§Examples
use core::str::FromStr;
use malachite_base::polynomial::ModPowerOf2PowTruncatedAssign;
use malachite_base::unsigned_polynomial::UnsignedPolynomial;
let mut p = UnsignedPolynomial::<u8>::from_str("x+1").unwrap();
p.mod_power_of_2_pow_truncated_assign(5, 3, 3);
assert_eq!(p.to_string(), "2*x^2+5*x+1");
// The power is a multiple of x^4.
let mut p = UnsignedPolynomial::<u8>::from_str("x^2+x").unwrap();
p.mod_power_of_2_pow_truncated_assign(4, 4, 3);
assert_eq!(p.to_string(), "0");This is equivalent to nmod_poly_pow_trunc from nmod_poly/pow_trunc.c, FLINT 3.6.0, with
the modulus $2^k$, except that a factor of $x^\ell$ is removed before powering, that the
intermediate powers are trimmed rather than padded to len, and that the zeroth power of
the zero polynomial is 1 (modulo $2^k$), where FLINT gives 0.
Source§impl<T: PrimitiveUnsigned> ModPowerOf2Shl<u8> for UnsignedPolynomial<T>
impl<T: PrimitiveUnsigned> ModPowerOf2Shl<u8> for UnsignedPolynomial<T>
Source§fn mod_power_of_2_shl(self, bits: u8, pow: u64) -> UnsignedPolynomial<T>
fn mod_power_of_2_shl(self, bits: u8, pow: u64) -> UnsignedPolynomial<T>
Left-shifts an UnsignedPolynomial (multiplies it by a power of 2) modulo $2^k$,
taking the polynomial by value. The coefficients must already be reduced modulo
$2^k$.
Every coefficient is shifted and reduced. Coefficients can become zero, so the
degree can drop; if bits is at least pow, the result is zero.
$$ f(p, m, k) = 2^mp \bmod 2^k. $$
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is self.len().
§Panics
Panics if pow is greater than T::WIDTH, or if any coefficient of self is
greater than or equal to $2^k$.
§Examples
See here.
type Output = UnsignedPolynomial<T>
Source§impl<T: PrimitiveUnsigned> ModPowerOf2Shl<u8> for &UnsignedPolynomial<T>
impl<T: PrimitiveUnsigned> ModPowerOf2Shl<u8> for &UnsignedPolynomial<T>
Source§fn mod_power_of_2_shl(self, bits: u8, pow: u64) -> UnsignedPolynomial<T>
fn mod_power_of_2_shl(self, bits: u8, pow: u64) -> UnsignedPolynomial<T>
Left-shifts an UnsignedPolynomial (multiplies it by a power of 2) modulo $2^k$,
taking the polynomial by reference. The coefficients must already be reduced modulo
$2^k$.
Every coefficient is shifted and reduced. Coefficients can become zero, so the
degree can drop; if bits is at least pow, the result is zero.
$$ f(p, m, k) = 2^mp \bmod 2^k. $$
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is self.len().
§Panics
Panics if pow is greater than T::WIDTH, or if any coefficient of self is
greater than or equal to $2^k$.
§Examples
See here.
type Output = UnsignedPolynomial<T>
Source§impl<T: PrimitiveUnsigned> ModPowerOf2Shl<u16> for UnsignedPolynomial<T>
impl<T: PrimitiveUnsigned> ModPowerOf2Shl<u16> for UnsignedPolynomial<T>
Source§fn mod_power_of_2_shl(self, bits: u16, pow: u64) -> UnsignedPolynomial<T>
fn mod_power_of_2_shl(self, bits: u16, pow: u64) -> UnsignedPolynomial<T>
Left-shifts an UnsignedPolynomial (multiplies it by a power of 2) modulo $2^k$,
taking the polynomial by value. The coefficients must already be reduced modulo
$2^k$.
Every coefficient is shifted and reduced. Coefficients can become zero, so the
degree can drop; if bits is at least pow, the result is zero.
$$ f(p, m, k) = 2^mp \bmod 2^k. $$
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is self.len().
§Panics
Panics if pow is greater than T::WIDTH, or if any coefficient of self is
greater than or equal to $2^k$.
§Examples
See here.
type Output = UnsignedPolynomial<T>
Source§impl<T: PrimitiveUnsigned> ModPowerOf2Shl<u16> for &UnsignedPolynomial<T>
impl<T: PrimitiveUnsigned> ModPowerOf2Shl<u16> for &UnsignedPolynomial<T>
Source§fn mod_power_of_2_shl(self, bits: u16, pow: u64) -> UnsignedPolynomial<T>
fn mod_power_of_2_shl(self, bits: u16, pow: u64) -> UnsignedPolynomial<T>
Left-shifts an UnsignedPolynomial (multiplies it by a power of 2) modulo $2^k$,
taking the polynomial by reference. The coefficients must already be reduced modulo
$2^k$.
Every coefficient is shifted and reduced. Coefficients can become zero, so the
degree can drop; if bits is at least pow, the result is zero.
$$ f(p, m, k) = 2^mp \bmod 2^k. $$
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is self.len().
§Panics
Panics if pow is greater than T::WIDTH, or if any coefficient of self is
greater than or equal to $2^k$.
§Examples
See here.
type Output = UnsignedPolynomial<T>
Source§impl<T: PrimitiveUnsigned> ModPowerOf2Shl<u32> for UnsignedPolynomial<T>
impl<T: PrimitiveUnsigned> ModPowerOf2Shl<u32> for UnsignedPolynomial<T>
Source§fn mod_power_of_2_shl(self, bits: u32, pow: u64) -> UnsignedPolynomial<T>
fn mod_power_of_2_shl(self, bits: u32, pow: u64) -> UnsignedPolynomial<T>
Left-shifts an UnsignedPolynomial (multiplies it by a power of 2) modulo $2^k$,
taking the polynomial by value. The coefficients must already be reduced modulo
$2^k$.
Every coefficient is shifted and reduced. Coefficients can become zero, so the
degree can drop; if bits is at least pow, the result is zero.
$$ f(p, m, k) = 2^mp \bmod 2^k. $$
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is self.len().
§Panics
Panics if pow is greater than T::WIDTH, or if any coefficient of self is
greater than or equal to $2^k$.
§Examples
See here.
type Output = UnsignedPolynomial<T>
Source§impl<T: PrimitiveUnsigned> ModPowerOf2Shl<u32> for &UnsignedPolynomial<T>
impl<T: PrimitiveUnsigned> ModPowerOf2Shl<u32> for &UnsignedPolynomial<T>
Source§fn mod_power_of_2_shl(self, bits: u32, pow: u64) -> UnsignedPolynomial<T>
fn mod_power_of_2_shl(self, bits: u32, pow: u64) -> UnsignedPolynomial<T>
Left-shifts an UnsignedPolynomial (multiplies it by a power of 2) modulo $2^k$,
taking the polynomial by reference. The coefficients must already be reduced modulo
$2^k$.
Every coefficient is shifted and reduced. Coefficients can become zero, so the
degree can drop; if bits is at least pow, the result is zero.
$$ f(p, m, k) = 2^mp \bmod 2^k. $$
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is self.len().
§Panics
Panics if pow is greater than T::WIDTH, or if any coefficient of self is
greater than or equal to $2^k$.
§Examples
See here.
type Output = UnsignedPolynomial<T>
Source§impl<T: PrimitiveUnsigned> ModPowerOf2Shl<u64> for UnsignedPolynomial<T>
impl<T: PrimitiveUnsigned> ModPowerOf2Shl<u64> for UnsignedPolynomial<T>
Source§fn mod_power_of_2_shl(self, bits: u64, pow: u64) -> UnsignedPolynomial<T>
fn mod_power_of_2_shl(self, bits: u64, pow: u64) -> UnsignedPolynomial<T>
Left-shifts an UnsignedPolynomial (multiplies it by a power of 2) modulo $2^k$,
taking the polynomial by value. The coefficients must already be reduced modulo
$2^k$.
Every coefficient is shifted and reduced. Coefficients can become zero, so the
degree can drop; if bits is at least pow, the result is zero.
$$ f(p, m, k) = 2^mp \bmod 2^k. $$
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is self.len().
§Panics
Panics if pow is greater than T::WIDTH, or if any coefficient of self is
greater than or equal to $2^k$.
§Examples
See here.
type Output = UnsignedPolynomial<T>
Source§impl<T: PrimitiveUnsigned> ModPowerOf2Shl<u64> for &UnsignedPolynomial<T>
impl<T: PrimitiveUnsigned> ModPowerOf2Shl<u64> for &UnsignedPolynomial<T>
Source§fn mod_power_of_2_shl(self, bits: u64, pow: u64) -> UnsignedPolynomial<T>
fn mod_power_of_2_shl(self, bits: u64, pow: u64) -> UnsignedPolynomial<T>
Left-shifts an UnsignedPolynomial (multiplies it by a power of 2) modulo $2^k$,
taking the polynomial by reference. The coefficients must already be reduced modulo
$2^k$.
Every coefficient is shifted and reduced. Coefficients can become zero, so the
degree can drop; if bits is at least pow, the result is zero.
$$ f(p, m, k) = 2^mp \bmod 2^k. $$
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is self.len().
§Panics
Panics if pow is greater than T::WIDTH, or if any coefficient of self is
greater than or equal to $2^k$.
§Examples
See here.
type Output = UnsignedPolynomial<T>
Source§impl<T: PrimitiveUnsigned> ModPowerOf2Shl<u128> for UnsignedPolynomial<T>
impl<T: PrimitiveUnsigned> ModPowerOf2Shl<u128> for UnsignedPolynomial<T>
Source§fn mod_power_of_2_shl(self, bits: u128, pow: u64) -> UnsignedPolynomial<T>
fn mod_power_of_2_shl(self, bits: u128, pow: u64) -> UnsignedPolynomial<T>
Left-shifts an UnsignedPolynomial (multiplies it by a power of 2) modulo $2^k$,
taking the polynomial by value. The coefficients must already be reduced modulo
$2^k$.
Every coefficient is shifted and reduced. Coefficients can become zero, so the
degree can drop; if bits is at least pow, the result is zero.
$$ f(p, m, k) = 2^mp \bmod 2^k. $$
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is self.len().
§Panics
Panics if pow is greater than T::WIDTH, or if any coefficient of self is
greater than or equal to $2^k$.
§Examples
See here.
type Output = UnsignedPolynomial<T>
Source§impl<T: PrimitiveUnsigned> ModPowerOf2Shl<u128> for &UnsignedPolynomial<T>
impl<T: PrimitiveUnsigned> ModPowerOf2Shl<u128> for &UnsignedPolynomial<T>
Source§fn mod_power_of_2_shl(self, bits: u128, pow: u64) -> UnsignedPolynomial<T>
fn mod_power_of_2_shl(self, bits: u128, pow: u64) -> UnsignedPolynomial<T>
Left-shifts an UnsignedPolynomial (multiplies it by a power of 2) modulo $2^k$,
taking the polynomial by reference. The coefficients must already be reduced modulo
$2^k$.
Every coefficient is shifted and reduced. Coefficients can become zero, so the
degree can drop; if bits is at least pow, the result is zero.
$$ f(p, m, k) = 2^mp \bmod 2^k. $$
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is self.len().
§Panics
Panics if pow is greater than T::WIDTH, or if any coefficient of self is
greater than or equal to $2^k$.
§Examples
See here.
type Output = UnsignedPolynomial<T>
Source§impl<T: PrimitiveUnsigned> ModPowerOf2Shl<usize> for UnsignedPolynomial<T>
impl<T: PrimitiveUnsigned> ModPowerOf2Shl<usize> for UnsignedPolynomial<T>
Source§fn mod_power_of_2_shl(self, bits: usize, pow: u64) -> UnsignedPolynomial<T>
fn mod_power_of_2_shl(self, bits: usize, pow: u64) -> UnsignedPolynomial<T>
Left-shifts an UnsignedPolynomial (multiplies it by a power of 2) modulo $2^k$,
taking the polynomial by value. The coefficients must already be reduced modulo
$2^k$.
Every coefficient is shifted and reduced. Coefficients can become zero, so the
degree can drop; if bits is at least pow, the result is zero.
$$ f(p, m, k) = 2^mp \bmod 2^k. $$
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is self.len().
§Panics
Panics if pow is greater than T::WIDTH, or if any coefficient of self is
greater than or equal to $2^k$.
§Examples
See here.
type Output = UnsignedPolynomial<T>
Source§impl<T: PrimitiveUnsigned> ModPowerOf2Shl<usize> for &UnsignedPolynomial<T>
impl<T: PrimitiveUnsigned> ModPowerOf2Shl<usize> for &UnsignedPolynomial<T>
Source§fn mod_power_of_2_shl(self, bits: usize, pow: u64) -> UnsignedPolynomial<T>
fn mod_power_of_2_shl(self, bits: usize, pow: u64) -> UnsignedPolynomial<T>
Left-shifts an UnsignedPolynomial (multiplies it by a power of 2) modulo $2^k$,
taking the polynomial by reference. The coefficients must already be reduced modulo
$2^k$.
Every coefficient is shifted and reduced. Coefficients can become zero, so the
degree can drop; if bits is at least pow, the result is zero.
$$ f(p, m, k) = 2^mp \bmod 2^k. $$
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is self.len().
§Panics
Panics if pow is greater than T::WIDTH, or if any coefficient of self is
greater than or equal to $2^k$.
§Examples
See here.
type Output = UnsignedPolynomial<T>
Source§impl<T: PrimitiveUnsigned> ModPowerOf2ShlAssign<u8> for UnsignedPolynomial<T>
impl<T: PrimitiveUnsigned> ModPowerOf2ShlAssign<u8> for UnsignedPolynomial<T>
Source§fn mod_power_of_2_shl_assign(&mut self, bits: u8, pow: u64)
fn mod_power_of_2_shl_assign(&mut self, bits: u8, pow: u64)
Left-shifts an UnsignedPolynomial (multiplies it by a power of 2) modulo $2^k$,
in place. The coefficients must already be reduced modulo $2^k$.
Every coefficient is shifted and reduced. Coefficients can become zero, so the
degree can drop; if bits is at least pow, the result is zero.
$$ p \gets 2^mp \bmod 2^k. $$
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is self.len().
§Panics
Panics if pow is greater than T::WIDTH, or if any coefficient of self is
greater than or equal to $2^k$.
§Examples
See here.
Source§impl<T: PrimitiveUnsigned> ModPowerOf2ShlAssign<u16> for UnsignedPolynomial<T>
impl<T: PrimitiveUnsigned> ModPowerOf2ShlAssign<u16> for UnsignedPolynomial<T>
Source§fn mod_power_of_2_shl_assign(&mut self, bits: u16, pow: u64)
fn mod_power_of_2_shl_assign(&mut self, bits: u16, pow: u64)
Left-shifts an UnsignedPolynomial (multiplies it by a power of 2) modulo $2^k$,
in place. The coefficients must already be reduced modulo $2^k$.
Every coefficient is shifted and reduced. Coefficients can become zero, so the
degree can drop; if bits is at least pow, the result is zero.
$$ p \gets 2^mp \bmod 2^k. $$
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is self.len().
§Panics
Panics if pow is greater than T::WIDTH, or if any coefficient of self is
greater than or equal to $2^k$.
§Examples
See here.
Source§impl<T: PrimitiveUnsigned> ModPowerOf2ShlAssign<u32> for UnsignedPolynomial<T>
impl<T: PrimitiveUnsigned> ModPowerOf2ShlAssign<u32> for UnsignedPolynomial<T>
Source§fn mod_power_of_2_shl_assign(&mut self, bits: u32, pow: u64)
fn mod_power_of_2_shl_assign(&mut self, bits: u32, pow: u64)
Left-shifts an UnsignedPolynomial (multiplies it by a power of 2) modulo $2^k$,
in place. The coefficients must already be reduced modulo $2^k$.
Every coefficient is shifted and reduced. Coefficients can become zero, so the
degree can drop; if bits is at least pow, the result is zero.
$$ p \gets 2^mp \bmod 2^k. $$
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is self.len().
§Panics
Panics if pow is greater than T::WIDTH, or if any coefficient of self is
greater than or equal to $2^k$.
§Examples
See here.
Source§impl<T: PrimitiveUnsigned> ModPowerOf2ShlAssign<u64> for UnsignedPolynomial<T>
impl<T: PrimitiveUnsigned> ModPowerOf2ShlAssign<u64> for UnsignedPolynomial<T>
Source§fn mod_power_of_2_shl_assign(&mut self, bits: u64, pow: u64)
fn mod_power_of_2_shl_assign(&mut self, bits: u64, pow: u64)
Left-shifts an UnsignedPolynomial (multiplies it by a power of 2) modulo $2^k$,
in place. The coefficients must already be reduced modulo $2^k$.
Every coefficient is shifted and reduced. Coefficients can become zero, so the
degree can drop; if bits is at least pow, the result is zero.
$$ p \gets 2^mp \bmod 2^k. $$
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is self.len().
§Panics
Panics if pow is greater than T::WIDTH, or if any coefficient of self is
greater than or equal to $2^k$.
§Examples
See here.
Source§impl<T: PrimitiveUnsigned> ModPowerOf2ShlAssign<u128> for UnsignedPolynomial<T>
impl<T: PrimitiveUnsigned> ModPowerOf2ShlAssign<u128> for UnsignedPolynomial<T>
Source§fn mod_power_of_2_shl_assign(&mut self, bits: u128, pow: u64)
fn mod_power_of_2_shl_assign(&mut self, bits: u128, pow: u64)
Left-shifts an UnsignedPolynomial (multiplies it by a power of 2) modulo $2^k$,
in place. The coefficients must already be reduced modulo $2^k$.
Every coefficient is shifted and reduced. Coefficients can become zero, so the
degree can drop; if bits is at least pow, the result is zero.
$$ p \gets 2^mp \bmod 2^k. $$
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is self.len().
§Panics
Panics if pow is greater than T::WIDTH, or if any coefficient of self is
greater than or equal to $2^k$.
§Examples
See here.
Source§impl<T: PrimitiveUnsigned> ModPowerOf2ShlAssign<usize> for UnsignedPolynomial<T>
impl<T: PrimitiveUnsigned> ModPowerOf2ShlAssign<usize> for UnsignedPolynomial<T>
Source§fn mod_power_of_2_shl_assign(&mut self, bits: usize, pow: u64)
fn mod_power_of_2_shl_assign(&mut self, bits: usize, pow: u64)
Left-shifts an UnsignedPolynomial (multiplies it by a power of 2) modulo $2^k$,
in place. The coefficients must already be reduced modulo $2^k$.
Every coefficient is shifted and reduced. Coefficients can become zero, so the
degree can drop; if bits is at least pow, the result is zero.
$$ p \gets 2^mp \bmod 2^k. $$
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is self.len().
§Panics
Panics if pow is greater than T::WIDTH, or if any coefficient of self is
greater than or equal to $2^k$.
§Examples
See here.
Source§impl<T: PrimitiveUnsigned> ModPowerOf2Square for UnsignedPolynomial<T>
impl<T: PrimitiveUnsigned> ModPowerOf2Square for UnsignedPolynomial<T>
Source§fn mod_power_of_2_square(self, pow: u64) -> Self
fn mod_power_of_2_square(self, pow: u64) -> Self
Squares an UnsignedPolynomial modulo $2^k$, taking it by value. Its coefficients must
already be reduced modulo $2^k$.
$$ f(p, k) = p^2 \bmod 2^k. $$
The leading coefficient of the square can vanish modulo $2^k$, and then the degree of the square is lower than twice the degree.
§Worst-case complexity
$T(n) = O(n^{\log_2 3})$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is self.len().
§Panics
Panics if pow is greater than T::WIDTH, or if any coefficient of self is greater than
or equal to $2^k$.
§Examples
use core::str::FromStr;
use malachite_base::num::arithmetic::traits::ModPowerOf2Square;
use malachite_base::unsigned_polynomial::UnsignedPolynomial;
// The square is x^4+6*x^3+13*x^2+12*x+4; its coefficients wrap around modulo 8.
assert_eq!(
UnsignedPolynomial::<u8>::from_str("x^2+3*x+2")
.unwrap()
.mod_power_of_2_square(3)
.to_string(),
"x^4+6*x^3+5*x^2+4*x+4"
);
// The square is 16*x^2+8*x+1, which is 1 modulo 8.
assert_eq!(
UnsignedPolynomial::<u8>::from_str("4*x+1")
.unwrap()
.mod_power_of_2_square(3)
.to_string(),
"1"
);This is equivalent to nmod_poly_mul from nmod_poly/mul.c, FLINT 3.6.0, with both factors
equal and the modulus $2^k$.
type Output = UnsignedPolynomial<T>
Source§impl<T: PrimitiveUnsigned> ModPowerOf2Square for &UnsignedPolynomial<T>
impl<T: PrimitiveUnsigned> ModPowerOf2Square for &UnsignedPolynomial<T>
Source§fn mod_power_of_2_square(self, pow: u64) -> UnsignedPolynomial<T>
fn mod_power_of_2_square(self, pow: u64) -> UnsignedPolynomial<T>
Squares an UnsignedPolynomial modulo $2^k$, taking it by reference. Its coefficients
must already be reduced modulo $2^k$.
$$ f(p, k) = p^2 \bmod 2^k. $$
The leading coefficient of the square can vanish modulo $2^k$, and then the degree of the square is lower than twice the degree.
§Worst-case complexity
$T(n) = O(n^{\log_2 3})$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is self.len().
§Panics
Panics if pow is greater than T::WIDTH, or if any coefficient of self is greater than
or equal to $2^k$.
§Examples
use core::str::FromStr;
use malachite_base::num::arithmetic::traits::ModPowerOf2Square;
use malachite_base::unsigned_polynomial::UnsignedPolynomial;
// The square is x^4+6*x^3+13*x^2+12*x+4; its coefficients wrap around modulo 8.
assert_eq!(
(&UnsignedPolynomial::<u8>::from_str("x^2+3*x+2").unwrap())
.mod_power_of_2_square(3)
.to_string(),
"x^4+6*x^3+5*x^2+4*x+4"
);
// The square is 16*x^2+8*x+1, which is 1 modulo 8.
assert_eq!(
(&UnsignedPolynomial::<u8>::from_str("4*x+1").unwrap())
.mod_power_of_2_square(3)
.to_string(),
"1"
);This is equivalent to nmod_poly_mul from nmod_poly/mul.c, FLINT 3.6.0, with both factors
equal and the modulus $2^k$.
type Output = UnsignedPolynomial<T>
Source§impl<T: PrimitiveUnsigned> ModPowerOf2SquareAssign for UnsignedPolynomial<T>
impl<T: PrimitiveUnsigned> ModPowerOf2SquareAssign for UnsignedPolynomial<T>
Source§fn mod_power_of_2_square_assign(&mut self, pow: u64)
fn mod_power_of_2_square_assign(&mut self, pow: u64)
Squares an UnsignedPolynomial modulo $2^k$ in place. Its coefficients must already be
reduced modulo $2^k$.
$$ p \gets p^2 \bmod 2^k. $$
§Worst-case complexity
$T(n) = O(n^{\log_2 3})$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is self.len().
§Panics
Panics if pow is greater than T::WIDTH, or if any coefficient of self is greater than
or equal to $2^k$.
§Examples
use core::str::FromStr;
use malachite_base::num::arithmetic::traits::ModPowerOf2SquareAssign;
use malachite_base::unsigned_polynomial::UnsignedPolynomial;
let mut p = UnsignedPolynomial::<u8>::from_str("x^2+3*x+2").unwrap();
p.mod_power_of_2_square_assign(3);
assert_eq!(p.to_string(), "x^4+6*x^3+5*x^2+4*x+4");This is equivalent to nmod_poly_mul from nmod_poly/mul.c, FLINT 3.6.0, with both factors
equal and the modulus $2^k$.
Source§impl<T: PrimitiveUnsigned> ModPowerOf2SquareTruncated for UnsignedPolynomial<T>
impl<T: PrimitiveUnsigned> ModPowerOf2SquareTruncated for UnsignedPolynomial<T>
Source§fn mod_power_of_2_square_truncated(self, len: u64, pow: u64) -> Self
fn mod_power_of_2_square_truncated(self, len: u64, pow: u64) -> Self
Squares an UnsignedPolynomial modulo $2^k$, keeping only the coefficients of $x^i$ for
$i$ less than len, taking it by value. Its coefficients must already be reduced modulo
$2^k$.
$$ f(p, n, k) = (p^2 \bmod x^n) \bmod 2^k. $$
The polynomial need not already be truncated: this is the square of its image modulo $x^n$,
so only its first len coefficients are read.
§Worst-case complexity
$T(n) = O(n^{\log_2 3})$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is len.
§Panics
Panics if pow is greater than T::WIDTH, or if any coefficient of self is greater than
or equal to $2^k$.
§Examples
use core::str::FromStr;
use malachite_base::polynomial::ModPowerOf2SquareTruncated;
use malachite_base::unsigned_polynomial::UnsignedPolynomial;
// The square is x^4+6*x^3+13*x^2+12*x+4; its low three coefficients, modulo 8.
assert_eq!(
UnsignedPolynomial::<u8>::from_str("x^2+3*x+2")
.unwrap()
.mod_power_of_2_square_truncated(3, 3)
.to_string(),
"5*x^2+4*x+4"
);
// The linear coefficient of the square, 8, vanishes modulo 8.
assert_eq!(
UnsignedPolynomial::<u8>::from_str("4*x+1")
.unwrap()
.mod_power_of_2_square_truncated(2, 3)
.to_string(),
"1"
);This is equivalent to nmod_poly_mullow from nmod_poly/mullow.c, FLINT 3.6.0, with both
factors equal and the modulus $2^k$.
type Output = UnsignedPolynomial<T>
Source§impl<T: PrimitiveUnsigned> ModPowerOf2SquareTruncated for &UnsignedPolynomial<T>
impl<T: PrimitiveUnsigned> ModPowerOf2SquareTruncated for &UnsignedPolynomial<T>
Source§fn mod_power_of_2_square_truncated(
self,
len: u64,
pow: u64,
) -> UnsignedPolynomial<T>
fn mod_power_of_2_square_truncated( self, len: u64, pow: u64, ) -> UnsignedPolynomial<T>
Squares an UnsignedPolynomial modulo $2^k$, keeping only the coefficients of $x^i$ for
$i$ less than len, taking it by reference. Its coefficients must already be reduced modulo
$2^k$.
$$ f(p, n, k) = (p^2 \bmod x^n) \bmod 2^k. $$
The polynomial need not already be truncated: this is the square of its image modulo $x^n$,
so only its first len coefficients are read.
§Worst-case complexity
$T(n) = O(n^{\log_2 3})$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is len.
§Panics
Panics if pow is greater than T::WIDTH, or if any coefficient of self is greater than
or equal to $2^k$.
§Examples
use core::str::FromStr;
use malachite_base::polynomial::ModPowerOf2SquareTruncated;
use malachite_base::unsigned_polynomial::UnsignedPolynomial;
// The square is x^4+6*x^3+13*x^2+12*x+4; its low three coefficients, modulo 8.
assert_eq!(
(&UnsignedPolynomial::<u8>::from_str("x^2+3*x+2").unwrap())
.mod_power_of_2_square_truncated(3, 3)
.to_string(),
"5*x^2+4*x+4"
);
// The linear coefficient of the square, 8, vanishes modulo 8.
assert_eq!(
(&UnsignedPolynomial::<u8>::from_str("4*x+1").unwrap())
.mod_power_of_2_square_truncated(2, 3)
.to_string(),
"1"
);This is equivalent to nmod_poly_mullow from nmod_poly/mullow.c, FLINT 3.6.0, with both
factors equal and the modulus $2^k$.
type Output = UnsignedPolynomial<T>
Source§impl<T: PrimitiveUnsigned> ModPowerOf2SquareTruncatedAssign for UnsignedPolynomial<T>
impl<T: PrimitiveUnsigned> ModPowerOf2SquareTruncatedAssign for UnsignedPolynomial<T>
Source§fn mod_power_of_2_square_truncated_assign(&mut self, len: u64, pow: u64)
fn mod_power_of_2_square_truncated_assign(&mut self, len: u64, pow: u64)
Squares an UnsignedPolynomial modulo $2^k$ in place, keeping only the coefficients of
$x^i$ for $i$ less than len. Its coefficients must already be reduced modulo $2^k$.
$$ p \gets (p^2 \bmod x^n) \bmod 2^k. $$
§Worst-case complexity
$T(n) = O(n^{\log_2 3})$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is len.
§Panics
Panics if pow is greater than T::WIDTH, or if any coefficient of self is greater than
or equal to $2^k$.
§Examples
use core::str::FromStr;
use malachite_base::polynomial::ModPowerOf2SquareTruncatedAssign;
use malachite_base::unsigned_polynomial::UnsignedPolynomial;
let mut p = UnsignedPolynomial::<u8>::from_str("x^2+3*x+2").unwrap();
p.mod_power_of_2_square_truncated_assign(3, 3);
assert_eq!(p.to_string(), "5*x^2+4*x+4");This is equivalent to nmod_poly_mullow from nmod_poly/mullow.c, FLINT 3.6.0, with both
factors equal and the modulus $2^k$.
Source§impl<T: PrimitiveUnsigned> ModPowerOf2Sub for UnsignedPolynomial<T>
impl<T: PrimitiveUnsigned> ModPowerOf2Sub for UnsignedPolynomial<T>
Source§fn mod_power_of_2_sub(self, other: Self, pow: u64) -> Self
fn mod_power_of_2_sub(self, other: Self, pow: u64) -> Self
Subtracts one UnsignedPolynomial from another modulo $2^k$, taking both by value. The
coefficients of both must already be reduced modulo $2^k$.
$$ f(p, q, k) = p - q \bmod 2^k. $$
Coefficients past the end of the shorter polynomial are taken to be zero. Where the second polynomial is longer, its coefficients are negated modulo $2^k$. When the two polynomials have the same degree, their leading coefficients can cancel modulo $2^k$, and then the degree of the difference is lower.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is the number of coefficients of the
longer polynomial times pow.
§Panics
Panics if pow is greater than T::WIDTH, or if any coefficient of self or other is
greater than or equal to $2^k$.
§Examples
use core::str::FromStr;
use malachite_base::num::arithmetic::traits::ModPowerOf2Sub;
use malachite_base::unsigned_polynomial::UnsignedPolynomial;
assert_eq!(
UnsignedPolynomial::<u8>::from_str("5*x^2+x+3")
.unwrap()
.mod_power_of_2_sub(
UnsignedPolynomial::<u8>::from_str("3*x^2+7*x+1").unwrap(),
3
)
.to_string(),
"2*x^2+2*x+2"
);
// The leading coefficients cancel.
assert_eq!(
UnsignedPolynomial::<u8>::from_str("5*x^2+x")
.unwrap()
.mod_power_of_2_sub(UnsignedPolynomial::<u8>::from_str("5*x^2+3").unwrap(), 3)
.to_string(),
"x+5"
);This is equivalent to nmod_poly_sub from nmod_poly/sub.c, FLINT 3.6.0, with the modulus
$2^k$.
type Output = UnsignedPolynomial<T>
Source§impl<T: PrimitiveUnsigned> ModPowerOf2Sub<&UnsignedPolynomial<T>> for UnsignedPolynomial<T>
impl<T: PrimitiveUnsigned> ModPowerOf2Sub<&UnsignedPolynomial<T>> for UnsignedPolynomial<T>
Source§fn mod_power_of_2_sub(self, other: &Self, pow: u64) -> Self
fn mod_power_of_2_sub(self, other: &Self, pow: u64) -> Self
Subtracts one UnsignedPolynomial from another modulo $2^k$, taking the first by value
and the second by reference. The coefficients of both must already be reduced modulo $2^k$.
$$ f(p, q, k) = p - q \bmod 2^k. $$
Coefficients past the end of the shorter polynomial are taken to be zero. Where the second polynomial is longer, its coefficients are negated modulo $2^k$. When the two polynomials have the same degree, their leading coefficients can cancel modulo $2^k$, and then the degree of the difference is lower.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is the number of coefficients of the
longer polynomial times pow.
§Panics
Panics if pow is greater than T::WIDTH, or if any coefficient of self or other is
greater than or equal to $2^k$.
§Examples
use core::str::FromStr;
use malachite_base::num::arithmetic::traits::ModPowerOf2Sub;
use malachite_base::unsigned_polynomial::UnsignedPolynomial;
assert_eq!(
UnsignedPolynomial::<u8>::from_str("5*x^2+x+3")
.unwrap()
.mod_power_of_2_sub(
&UnsignedPolynomial::<u8>::from_str("3*x^2+7*x+1").unwrap(),
3
)
.to_string(),
"2*x^2+2*x+2"
);
// The leading coefficients cancel.
assert_eq!(
UnsignedPolynomial::<u8>::from_str("5*x^2+x")
.unwrap()
.mod_power_of_2_sub(&UnsignedPolynomial::<u8>::from_str("5*x^2+3").unwrap(), 3)
.to_string(),
"x+5"
);This is equivalent to nmod_poly_sub from nmod_poly/sub.c, FLINT 3.6.0, with the modulus
$2^k$.
type Output = UnsignedPolynomial<T>
Source§impl<T: PrimitiveUnsigned> ModPowerOf2Sub<&UnsignedPolynomial<T>> for &UnsignedPolynomial<T>
impl<T: PrimitiveUnsigned> ModPowerOf2Sub<&UnsignedPolynomial<T>> for &UnsignedPolynomial<T>
Source§fn mod_power_of_2_sub(
self,
other: &UnsignedPolynomial<T>,
pow: u64,
) -> UnsignedPolynomial<T>
fn mod_power_of_2_sub( self, other: &UnsignedPolynomial<T>, pow: u64, ) -> UnsignedPolynomial<T>
Subtracts one UnsignedPolynomial from another modulo $2^k$, taking both by reference.
The coefficients of both must already be reduced modulo $2^k$.
$$ f(p, q, k) = p - q \bmod 2^k. $$
Coefficients past the end of the shorter polynomial are taken to be zero. Where the second polynomial is longer, its coefficients are negated modulo $2^k$. When the two polynomials have the same degree, their leading coefficients can cancel modulo $2^k$, and then the degree of the difference is lower.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is the number of coefficients of the
longer polynomial times pow.
§Panics
Panics if pow is greater than T::WIDTH, or if any coefficient of self or other is
greater than or equal to $2^k$.
§Examples
use core::str::FromStr;
use malachite_base::num::arithmetic::traits::ModPowerOf2Sub;
use malachite_base::unsigned_polynomial::UnsignedPolynomial;
assert_eq!(
(&UnsignedPolynomial::<u8>::from_str("5*x^2+x+3").unwrap())
.mod_power_of_2_sub(
&UnsignedPolynomial::<u8>::from_str("3*x^2+7*x+1").unwrap(),
3
)
.to_string(),
"2*x^2+2*x+2"
);
// The leading coefficients cancel.
assert_eq!(
(&UnsignedPolynomial::<u8>::from_str("5*x^2+x").unwrap())
.mod_power_of_2_sub(&UnsignedPolynomial::<u8>::from_str("5*x^2+3").unwrap(), 3)
.to_string(),
"x+5"
);This is equivalent to nmod_poly_sub from nmod_poly/sub.c, FLINT 3.6.0, with the modulus
$2^k$.
type Output = UnsignedPolynomial<T>
Source§impl<T: PrimitiveUnsigned> ModPowerOf2Sub<UnsignedPolynomial<T>> for &UnsignedPolynomial<T>
impl<T: PrimitiveUnsigned> ModPowerOf2Sub<UnsignedPolynomial<T>> for &UnsignedPolynomial<T>
Source§fn mod_power_of_2_sub(
self,
other: UnsignedPolynomial<T>,
pow: u64,
) -> UnsignedPolynomial<T>
fn mod_power_of_2_sub( self, other: UnsignedPolynomial<T>, pow: u64, ) -> UnsignedPolynomial<T>
Subtracts one UnsignedPolynomial from another modulo $2^k$, taking the first by
reference and the second by value. The coefficients of both must already be reduced modulo
$2^k$.
$$ f(p, q, k) = p - q \bmod 2^k. $$
Coefficients past the end of the shorter polynomial are taken to be zero. Where the second polynomial is longer, its coefficients are negated modulo $2^k$. When the two polynomials have the same degree, their leading coefficients can cancel modulo $2^k$, and then the degree of the difference is lower.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is the number of coefficients of the
longer polynomial times pow.
§Panics
Panics if pow is greater than T::WIDTH, or if any coefficient of self or other is
greater than or equal to $2^k$.
§Examples
use core::str::FromStr;
use malachite_base::num::arithmetic::traits::ModPowerOf2Sub;
use malachite_base::unsigned_polynomial::UnsignedPolynomial;
assert_eq!(
(&UnsignedPolynomial::<u8>::from_str("5*x^2+x+3").unwrap())
.mod_power_of_2_sub(
UnsignedPolynomial::<u8>::from_str("3*x^2+7*x+1").unwrap(),
3
)
.to_string(),
"2*x^2+2*x+2"
);
// The leading coefficients cancel.
assert_eq!(
(&UnsignedPolynomial::<u8>::from_str("5*x^2+x").unwrap())
.mod_power_of_2_sub(UnsignedPolynomial::<u8>::from_str("5*x^2+3").unwrap(), 3)
.to_string(),
"x+5"
);This is equivalent to nmod_poly_sub from nmod_poly/sub.c, FLINT 3.6.0, with the modulus
$2^k$.
type Output = UnsignedPolynomial<T>
Source§impl<T: PrimitiveUnsigned> ModPowerOf2SubAssign for UnsignedPolynomial<T>
impl<T: PrimitiveUnsigned> ModPowerOf2SubAssign for UnsignedPolynomial<T>
Source§fn mod_power_of_2_sub_assign(&mut self, other: Self, pow: u64)
fn mod_power_of_2_sub_assign(&mut self, other: Self, pow: u64)
Subtracts a UnsignedPolynomial from a UnsignedPolynomial modulo $2^k$, in place,
taking the second by value. The coefficients of both must already be reduced modulo $2^k$.
$$ p \gets p - q \bmod 2^k. $$
Coefficients past the end of the shorter polynomial are taken to be zero. Where the second polynomial is longer, its coefficients are negated modulo $2^k$. When the two polynomials have the same degree, their leading coefficients can cancel modulo $2^k$, and then the degree of the difference is lower.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is the number of coefficients of the
longer polynomial times pow.
§Panics
Panics if pow is greater than T::WIDTH, or if any coefficient of self or other is
greater than or equal to $2^k$.
§Examples
use core::str::FromStr;
use malachite_base::num::arithmetic::traits::ModPowerOf2SubAssign;
use malachite_base::unsigned_polynomial::UnsignedPolynomial;
let mut p = UnsignedPolynomial::<u8>::from_str("5*x^2+x+3").unwrap();
p.mod_power_of_2_sub_assign(
UnsignedPolynomial::<u8>::from_str("3*x^2+7*x+1").unwrap(),
3,
);
assert_eq!(p.to_string(), "2*x^2+2*x+2");
// The leading coefficients cancel.
let mut p = UnsignedPolynomial::<u8>::from_str("5*x^2+x").unwrap();
p.mod_power_of_2_sub_assign(UnsignedPolynomial::<u8>::from_str("5*x^2+3").unwrap(), 3);
assert_eq!(p.to_string(), "x+5");This is equivalent to nmod_poly_sub from nmod_poly/sub.c, FLINT 3.6.0, with the modulus
$2^k$.
Source§impl<T: PrimitiveUnsigned> ModPowerOf2SubAssign<&UnsignedPolynomial<T>> for UnsignedPolynomial<T>
impl<T: PrimitiveUnsigned> ModPowerOf2SubAssign<&UnsignedPolynomial<T>> for UnsignedPolynomial<T>
Source§fn mod_power_of_2_sub_assign(&mut self, other: &Self, pow: u64)
fn mod_power_of_2_sub_assign(&mut self, other: &Self, pow: u64)
Subtracts a UnsignedPolynomial from a UnsignedPolynomial modulo $2^k$, in place,
taking the second by reference. The coefficients of both must already be reduced modulo
$2^k$.
$$ p \gets p - q \bmod 2^k. $$
Coefficients past the end of the shorter polynomial are taken to be zero. Where the second polynomial is longer, its coefficients are negated modulo $2^k$. When the two polynomials have the same degree, their leading coefficients can cancel modulo $2^k$, and then the degree of the difference is lower.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is the number of coefficients of the
longer polynomial times pow.
§Panics
Panics if pow is greater than T::WIDTH, or if any coefficient of self or other is
greater than or equal to $2^k$.
§Examples
use core::str::FromStr;
use malachite_base::num::arithmetic::traits::ModPowerOf2SubAssign;
use malachite_base::unsigned_polynomial::UnsignedPolynomial;
let mut p = UnsignedPolynomial::<u8>::from_str("5*x^2+x+3").unwrap();
p.mod_power_of_2_sub_assign(
&UnsignedPolynomial::<u8>::from_str("3*x^2+7*x+1").unwrap(),
3,
);
assert_eq!(p.to_string(), "2*x^2+2*x+2");
// The leading coefficients cancel.
let mut p = UnsignedPolynomial::<u8>::from_str("5*x^2+x").unwrap();
p.mod_power_of_2_sub_assign(&UnsignedPolynomial::<u8>::from_str("5*x^2+3").unwrap(), 3);
assert_eq!(p.to_string(), "x+5");This is equivalent to nmod_poly_sub from nmod_poly/sub.c, FLINT 3.6.0, with the modulus
$2^k$.
Source§impl<T: PrimitiveUnsigned> ModPowerOf2SubTruncated for UnsignedPolynomial<T>
impl<T: PrimitiveUnsigned> ModPowerOf2SubTruncated for UnsignedPolynomial<T>
Source§fn mod_power_of_2_sub_truncated(self, other: Self, len: u64, pow: u64) -> Self
fn mod_power_of_2_sub_truncated(self, other: Self, len: u64, pow: u64) -> Self
Subtracts one UnsignedPolynomial from another modulo $2^k$, keeping only the
coefficients of $x^i$ for $i$ less than len, taking both by value. The coefficients of
both must already be reduced modulo $2^k$.
$$ f(p, q, n, k) = ((p - q) \bmod x^n) \bmod 2^k. $$
The polynomials need not already be truncated: this is the difference of their images modulo
$x^n$, so only the first len coefficients of each are read. Where the second polynomial
has more of those, they are negated modulo $2^k$. The difference is trimmed, so when
coefficients cancel modulo $2^k$ at the top of the kept range, the degree is lower still.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is the number of coefficients of the
longer polynomial times pow.
§Panics
Panics if pow is greater than T::WIDTH, or if any coefficient of self or other is
greater than or equal to $2^k$.
§Examples
use core::str::FromStr;
use malachite_base::polynomial::ModPowerOf2SubTruncated;
use malachite_base::unsigned_polynomial::UnsignedPolynomial;
// The quadratic and linear coefficients wrap around.
assert_eq!(
UnsignedPolynomial::<u8>::from_str("x^3+2*x^2+x+5")
.unwrap()
.mod_power_of_2_sub_truncated(
UnsignedPolynomial::<u8>::from_str("4*x^2+7*x+2").unwrap(),
3,
3
)
.to_string(),
"6*x^2+2*x+3"
);
assert_eq!(
UnsignedPolynomial::<u8>::from_str("x^3+2*x^2+x+5")
.unwrap()
.mod_power_of_2_sub_truncated(
UnsignedPolynomial::<u8>::from_str("4*x^2+7*x+2").unwrap(),
1,
3
)
.to_string(),
"3"
);This is equivalent to nmod_poly_sub_series from nmod_poly/sub_series.c, FLINT 3.6.0,
with the modulus $2^k$.
type Output = UnsignedPolynomial<T>
Source§impl<T: PrimitiveUnsigned> ModPowerOf2SubTruncated<&UnsignedPolynomial<T>> for UnsignedPolynomial<T>
impl<T: PrimitiveUnsigned> ModPowerOf2SubTruncated<&UnsignedPolynomial<T>> for UnsignedPolynomial<T>
Source§fn mod_power_of_2_sub_truncated(self, other: &Self, len: u64, pow: u64) -> Self
fn mod_power_of_2_sub_truncated(self, other: &Self, len: u64, pow: u64) -> Self
Subtracts one UnsignedPolynomial from another modulo $2^k$, keeping only the
coefficients of $x^i$ for $i$ less than len, taking the first by value and the second by
reference. The coefficients of both must already be reduced modulo $2^k$.
$$ f(p, q, n, k) = ((p - q) \bmod x^n) \bmod 2^k. $$
The polynomials need not already be truncated: this is the difference of their images modulo
$x^n$, so only the first len coefficients of each are read. Where the second polynomial
has more of those, they are negated modulo $2^k$. The difference is trimmed, so when
coefficients cancel modulo $2^k$ at the top of the kept range, the degree is lower still.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is the number of coefficients of the
longer polynomial times pow.
§Panics
Panics if pow is greater than T::WIDTH, or if any coefficient of self or other is
greater than or equal to $2^k$.
§Examples
use core::str::FromStr;
use malachite_base::polynomial::ModPowerOf2SubTruncated;
use malachite_base::unsigned_polynomial::UnsignedPolynomial;
// The quadratic and linear coefficients wrap around.
assert_eq!(
UnsignedPolynomial::<u8>::from_str("x^3+2*x^2+x+5")
.unwrap()
.mod_power_of_2_sub_truncated(
&UnsignedPolynomial::<u8>::from_str("4*x^2+7*x+2").unwrap(),
3,
3
)
.to_string(),
"6*x^2+2*x+3"
);
assert_eq!(
UnsignedPolynomial::<u8>::from_str("x^3+2*x^2+x+5")
.unwrap()
.mod_power_of_2_sub_truncated(
&UnsignedPolynomial::<u8>::from_str("4*x^2+7*x+2").unwrap(),
1,
3
)
.to_string(),
"3"
);This is equivalent to nmod_poly_sub_series from nmod_poly/sub_series.c, FLINT 3.6.0,
with the modulus $2^k$.
type Output = UnsignedPolynomial<T>
Source§impl<T: PrimitiveUnsigned> ModPowerOf2SubTruncated<&UnsignedPolynomial<T>> for &UnsignedPolynomial<T>
impl<T: PrimitiveUnsigned> ModPowerOf2SubTruncated<&UnsignedPolynomial<T>> for &UnsignedPolynomial<T>
Source§fn mod_power_of_2_sub_truncated(
self,
other: &UnsignedPolynomial<T>,
len: u64,
pow: u64,
) -> UnsignedPolynomial<T>
fn mod_power_of_2_sub_truncated( self, other: &UnsignedPolynomial<T>, len: u64, pow: u64, ) -> UnsignedPolynomial<T>
Subtracts one UnsignedPolynomial from another modulo $2^k$, keeping only the
coefficients of $x^i$ for $i$ less than len, taking both by reference. The coefficients of
both must already be reduced modulo $2^k$.
$$ f(p, q, n, k) = ((p - q) \bmod x^n) \bmod 2^k. $$
The polynomials need not already be truncated: this is the difference of their images modulo
$x^n$, so only the first len coefficients of each are read. Where the second polynomial
has more of those, they are negated modulo $2^k$. The difference is trimmed, so when
coefficients cancel modulo $2^k$ at the top of the kept range, the degree is lower still.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is the number of coefficients of the
longer polynomial times pow.
§Panics
Panics if pow is greater than T::WIDTH, or if any coefficient of self or other is
greater than or equal to $2^k$.
§Examples
use core::str::FromStr;
use malachite_base::polynomial::ModPowerOf2SubTruncated;
use malachite_base::unsigned_polynomial::UnsignedPolynomial;
// The quadratic and linear coefficients wrap around.
assert_eq!(
(&UnsignedPolynomial::<u8>::from_str("x^3+2*x^2+x+5").unwrap())
.mod_power_of_2_sub_truncated(
&UnsignedPolynomial::<u8>::from_str("4*x^2+7*x+2").unwrap(),
3,
3
)
.to_string(),
"6*x^2+2*x+3"
);
assert_eq!(
(&UnsignedPolynomial::<u8>::from_str("x^3+2*x^2+x+5").unwrap())
.mod_power_of_2_sub_truncated(
&UnsignedPolynomial::<u8>::from_str("4*x^2+7*x+2").unwrap(),
1,
3
)
.to_string(),
"3"
);This is equivalent to nmod_poly_sub_series from nmod_poly/sub_series.c, FLINT 3.6.0,
with the modulus $2^k$.
type Output = UnsignedPolynomial<T>
Source§impl<T: PrimitiveUnsigned> ModPowerOf2SubTruncated<UnsignedPolynomial<T>> for &UnsignedPolynomial<T>
impl<T: PrimitiveUnsigned> ModPowerOf2SubTruncated<UnsignedPolynomial<T>> for &UnsignedPolynomial<T>
Source§fn mod_power_of_2_sub_truncated(
self,
other: UnsignedPolynomial<T>,
len: u64,
pow: u64,
) -> UnsignedPolynomial<T>
fn mod_power_of_2_sub_truncated( self, other: UnsignedPolynomial<T>, len: u64, pow: u64, ) -> UnsignedPolynomial<T>
Subtracts one UnsignedPolynomial from another modulo $2^k$, keeping only the
coefficients of $x^i$ for $i$ less than len, taking the first by reference and the second
by value. The coefficients of both must already be reduced modulo $2^k$.
$$ f(p, q, n, k) = ((p - q) \bmod x^n) \bmod 2^k. $$
The polynomials need not already be truncated: this is the difference of their images modulo
$x^n$, so only the first len coefficients of each are read. Where the second polynomial
has more of those, they are negated modulo $2^k$. The difference is trimmed, so when
coefficients cancel modulo $2^k$ at the top of the kept range, the degree is lower still.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is the number of coefficients of the
longer polynomial times pow.
§Panics
Panics if pow is greater than T::WIDTH, or if any coefficient of self or other is
greater than or equal to $2^k$.
§Examples
use core::str::FromStr;
use malachite_base::polynomial::ModPowerOf2SubTruncated;
use malachite_base::unsigned_polynomial::UnsignedPolynomial;
// The quadratic and linear coefficients wrap around.
assert_eq!(
(&UnsignedPolynomial::<u8>::from_str("x^3+2*x^2+x+5").unwrap())
.mod_power_of_2_sub_truncated(
UnsignedPolynomial::<u8>::from_str("4*x^2+7*x+2").unwrap(),
3,
3
)
.to_string(),
"6*x^2+2*x+3"
);
assert_eq!(
(&UnsignedPolynomial::<u8>::from_str("x^3+2*x^2+x+5").unwrap())
.mod_power_of_2_sub_truncated(
UnsignedPolynomial::<u8>::from_str("4*x^2+7*x+2").unwrap(),
1,
3
)
.to_string(),
"3"
);This is equivalent to nmod_poly_sub_series from nmod_poly/sub_series.c, FLINT 3.6.0,
with the modulus $2^k$.
type Output = UnsignedPolynomial<T>
Source§impl<T: PrimitiveUnsigned> ModPowerOf2SubTruncatedAssign for UnsignedPolynomial<T>
impl<T: PrimitiveUnsigned> ModPowerOf2SubTruncatedAssign for UnsignedPolynomial<T>
Source§fn mod_power_of_2_sub_truncated_assign(
&mut self,
other: Self,
len: u64,
pow: u64,
)
fn mod_power_of_2_sub_truncated_assign( &mut self, other: Self, len: u64, pow: u64, )
Subtracts an UnsignedPolynomial from an UnsignedPolynomial modulo $2^k$ in place,
keeping only the coefficients of $x^i$ for $i$ less than len, taking the second polynomial
by value. The coefficients of both must already be reduced modulo $2^k$.
$$ p \gets ((p - q) \bmod x^n) \bmod 2^k. $$
The polynomials need not already be truncated: this is the difference of their images modulo
$x^n$, so only the first len coefficients of each are read. Where the second polynomial
has more of those, they are negated modulo $2^k$. The difference is trimmed, so when
coefficients cancel modulo $2^k$ at the top of the kept range, the degree is lower still.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is the number of coefficients of the
longer polynomial times pow.
§Panics
Panics if pow is greater than T::WIDTH, or if any coefficient of self or other is
greater than or equal to $2^k$.
§Examples
use core::str::FromStr;
use malachite_base::polynomial::ModPowerOf2SubTruncatedAssign;
use malachite_base::unsigned_polynomial::UnsignedPolynomial;
// The quadratic and linear coefficients wrap around.
let mut p = UnsignedPolynomial::<u8>::from_str("x^3+2*x^2+x+5").unwrap();
p.mod_power_of_2_sub_truncated_assign(
UnsignedPolynomial::<u8>::from_str("4*x^2+7*x+2").unwrap(),
3,
3,
);
assert_eq!(p.to_string(), "6*x^2+2*x+3");
let mut p = UnsignedPolynomial::<u8>::from_str("x^3+2*x^2+x+5").unwrap();
p.mod_power_of_2_sub_truncated_assign(
UnsignedPolynomial::<u8>::from_str("4*x^2+7*x+2").unwrap(),
1,
3,
);
assert_eq!(p.to_string(), "3");This is equivalent to nmod_poly_sub_series from nmod_poly/sub_series.c, FLINT 3.6.0,
with the modulus $2^k$.
Source§impl<T: PrimitiveUnsigned> ModPowerOf2SubTruncatedAssign<&UnsignedPolynomial<T>> for UnsignedPolynomial<T>
impl<T: PrimitiveUnsigned> ModPowerOf2SubTruncatedAssign<&UnsignedPolynomial<T>> for UnsignedPolynomial<T>
Source§fn mod_power_of_2_sub_truncated_assign(
&mut self,
other: &Self,
len: u64,
pow: u64,
)
fn mod_power_of_2_sub_truncated_assign( &mut self, other: &Self, len: u64, pow: u64, )
Subtracts an UnsignedPolynomial from an UnsignedPolynomial modulo $2^k$ in place,
keeping only the coefficients of $x^i$ for $i$ less than len, taking the second polynomial
by reference. The coefficients of both must already be reduced modulo $2^k$.
$$ p \gets ((p - q) \bmod x^n) \bmod 2^k. $$
The polynomials need not already be truncated: this is the difference of their images modulo
$x^n$, so only the first len coefficients of each are read. Where the second polynomial
has more of those, they are negated modulo $2^k$. The difference is trimmed, so when
coefficients cancel modulo $2^k$ at the top of the kept range, the degree is lower still.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is the number of coefficients of the
longer polynomial times pow.
§Panics
Panics if pow is greater than T::WIDTH, or if any coefficient of self or other is
greater than or equal to $2^k$.
§Examples
use core::str::FromStr;
use malachite_base::polynomial::ModPowerOf2SubTruncatedAssign;
use malachite_base::unsigned_polynomial::UnsignedPolynomial;
// The quadratic and linear coefficients wrap around.
let mut p = UnsignedPolynomial::<u8>::from_str("x^3+2*x^2+x+5").unwrap();
p.mod_power_of_2_sub_truncated_assign(
&UnsignedPolynomial::<u8>::from_str("4*x^2+7*x+2").unwrap(),
3,
3,
);
assert_eq!(p.to_string(), "6*x^2+2*x+3");
let mut p = UnsignedPolynomial::<u8>::from_str("x^3+2*x^2+x+5").unwrap();
p.mod_power_of_2_sub_truncated_assign(
&UnsignedPolynomial::<u8>::from_str("4*x^2+7*x+2").unwrap(),
1,
3,
);
assert_eq!(p.to_string(), "3");This is equivalent to nmod_poly_sub_series from nmod_poly/sub_series.c, FLINT 3.6.0,
with the modulus $2^k$.
Source§impl<T: PrimitiveUnsigned + ModShl<u8, T, Output = T>> ModShl<u8, T> for UnsignedPolynomial<T>
impl<T: PrimitiveUnsigned + ModShl<u8, T, Output = T>> ModShl<u8, T> for UnsignedPolynomial<T>
Source§fn mod_shl(self, bits: u8, m: T) -> UnsignedPolynomial<T>
fn mod_shl(self, bits: u8, m: T) -> UnsignedPolynomial<T>
Left-shifts an UnsignedPolynomial (multiplies it by a power of 2) modulo m,
taking the polynomial by value. The coefficients must already be reduced modulo m.
$2^k \bmod m$ is computed once, and every coefficient is multiplied by it. Since m
need not be odd, coefficients can become zero, so the degree can drop.
$$ f(p, k, m) = 2^kp \bmod m. $$
§Worst-case complexity
$T(n, m) = O(n + m)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, $n$ is self.len(), and $m$ is
bits.significant_bits().
§Panics
Panics if m is 0, or if any coefficient of self is greater than or equal to m.
§Examples
See here.
type Output = UnsignedPolynomial<T>
Source§impl<T: PrimitiveUnsigned + ModShl<u8, T, Output = T>> ModShl<u8, T> for &UnsignedPolynomial<T>
impl<T: PrimitiveUnsigned + ModShl<u8, T, Output = T>> ModShl<u8, T> for &UnsignedPolynomial<T>
Source§fn mod_shl(self, bits: u8, m: T) -> UnsignedPolynomial<T>
fn mod_shl(self, bits: u8, m: T) -> UnsignedPolynomial<T>
Left-shifts an UnsignedPolynomial (multiplies it by a power of 2) modulo m,
taking the polynomial by reference. The coefficients must already be reduced modulo
m.
$2^k \bmod m$ is computed once, and every coefficient is multiplied by it. Since m
need not be odd, coefficients can become zero, so the degree can drop.
$$ f(p, k, m) = 2^kp \bmod m. $$
§Worst-case complexity
$T(n, m) = O(n + m)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, $n$ is self.len(), and $m$ is
bits.significant_bits().
§Panics
Panics if m is 0, or if any coefficient of self is greater than or equal to m.
§Examples
See here.
type Output = UnsignedPolynomial<T>
Source§impl<T: PrimitiveUnsigned + ModShl<u16, T, Output = T>> ModShl<u16, T> for UnsignedPolynomial<T>
impl<T: PrimitiveUnsigned + ModShl<u16, T, Output = T>> ModShl<u16, T> for UnsignedPolynomial<T>
Source§fn mod_shl(self, bits: u16, m: T) -> UnsignedPolynomial<T>
fn mod_shl(self, bits: u16, m: T) -> UnsignedPolynomial<T>
Left-shifts an UnsignedPolynomial (multiplies it by a power of 2) modulo m,
taking the polynomial by value. The coefficients must already be reduced modulo m.
$2^k \bmod m$ is computed once, and every coefficient is multiplied by it. Since m
need not be odd, coefficients can become zero, so the degree can drop.
$$ f(p, k, m) = 2^kp \bmod m. $$
§Worst-case complexity
$T(n, m) = O(n + m)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, $n$ is self.len(), and $m$ is
bits.significant_bits().
§Panics
Panics if m is 0, or if any coefficient of self is greater than or equal to m.
§Examples
See here.
type Output = UnsignedPolynomial<T>
Source§impl<T: PrimitiveUnsigned + ModShl<u16, T, Output = T>> ModShl<u16, T> for &UnsignedPolynomial<T>
impl<T: PrimitiveUnsigned + ModShl<u16, T, Output = T>> ModShl<u16, T> for &UnsignedPolynomial<T>
Source§fn mod_shl(self, bits: u16, m: T) -> UnsignedPolynomial<T>
fn mod_shl(self, bits: u16, m: T) -> UnsignedPolynomial<T>
Left-shifts an UnsignedPolynomial (multiplies it by a power of 2) modulo m,
taking the polynomial by reference. The coefficients must already be reduced modulo
m.
$2^k \bmod m$ is computed once, and every coefficient is multiplied by it. Since m
need not be odd, coefficients can become zero, so the degree can drop.
$$ f(p, k, m) = 2^kp \bmod m. $$
§Worst-case complexity
$T(n, m) = O(n + m)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, $n$ is self.len(), and $m$ is
bits.significant_bits().
§Panics
Panics if m is 0, or if any coefficient of self is greater than or equal to m.
§Examples
See here.
type Output = UnsignedPolynomial<T>
Source§impl<T: PrimitiveUnsigned + ModShl<u32, T, Output = T>> ModShl<u32, T> for UnsignedPolynomial<T>
impl<T: PrimitiveUnsigned + ModShl<u32, T, Output = T>> ModShl<u32, T> for UnsignedPolynomial<T>
Source§fn mod_shl(self, bits: u32, m: T) -> UnsignedPolynomial<T>
fn mod_shl(self, bits: u32, m: T) -> UnsignedPolynomial<T>
Left-shifts an UnsignedPolynomial (multiplies it by a power of 2) modulo m,
taking the polynomial by value. The coefficients must already be reduced modulo m.
$2^k \bmod m$ is computed once, and every coefficient is multiplied by it. Since m
need not be odd, coefficients can become zero, so the degree can drop.
$$ f(p, k, m) = 2^kp \bmod m. $$
§Worst-case complexity
$T(n, m) = O(n + m)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, $n$ is self.len(), and $m$ is
bits.significant_bits().
§Panics
Panics if m is 0, or if any coefficient of self is greater than or equal to m.
§Examples
See here.
type Output = UnsignedPolynomial<T>
Source§impl<T: PrimitiveUnsigned + ModShl<u32, T, Output = T>> ModShl<u32, T> for &UnsignedPolynomial<T>
impl<T: PrimitiveUnsigned + ModShl<u32, T, Output = T>> ModShl<u32, T> for &UnsignedPolynomial<T>
Source§fn mod_shl(self, bits: u32, m: T) -> UnsignedPolynomial<T>
fn mod_shl(self, bits: u32, m: T) -> UnsignedPolynomial<T>
Left-shifts an UnsignedPolynomial (multiplies it by a power of 2) modulo m,
taking the polynomial by reference. The coefficients must already be reduced modulo
m.
$2^k \bmod m$ is computed once, and every coefficient is multiplied by it. Since m
need not be odd, coefficients can become zero, so the degree can drop.
$$ f(p, k, m) = 2^kp \bmod m. $$
§Worst-case complexity
$T(n, m) = O(n + m)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, $n$ is self.len(), and $m$ is
bits.significant_bits().
§Panics
Panics if m is 0, or if any coefficient of self is greater than or equal to m.
§Examples
See here.
type Output = UnsignedPolynomial<T>
Source§impl<T: PrimitiveUnsigned + ModShl<u64, T, Output = T>> ModShl<u64, T> for UnsignedPolynomial<T>
impl<T: PrimitiveUnsigned + ModShl<u64, T, Output = T>> ModShl<u64, T> for UnsignedPolynomial<T>
Source§fn mod_shl(self, bits: u64, m: T) -> UnsignedPolynomial<T>
fn mod_shl(self, bits: u64, m: T) -> UnsignedPolynomial<T>
Left-shifts an UnsignedPolynomial (multiplies it by a power of 2) modulo m,
taking the polynomial by value. The coefficients must already be reduced modulo m.
$2^k \bmod m$ is computed once, and every coefficient is multiplied by it. Since m
need not be odd, coefficients can become zero, so the degree can drop.
$$ f(p, k, m) = 2^kp \bmod m. $$
§Worst-case complexity
$T(n, m) = O(n + m)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, $n$ is self.len(), and $m$ is
bits.significant_bits().
§Panics
Panics if m is 0, or if any coefficient of self is greater than or equal to m.
§Examples
See here.
type Output = UnsignedPolynomial<T>
Source§impl<T: PrimitiveUnsigned + ModShl<u64, T, Output = T>> ModShl<u64, T> for &UnsignedPolynomial<T>
impl<T: PrimitiveUnsigned + ModShl<u64, T, Output = T>> ModShl<u64, T> for &UnsignedPolynomial<T>
Source§fn mod_shl(self, bits: u64, m: T) -> UnsignedPolynomial<T>
fn mod_shl(self, bits: u64, m: T) -> UnsignedPolynomial<T>
Left-shifts an UnsignedPolynomial (multiplies it by a power of 2) modulo m,
taking the polynomial by reference. The coefficients must already be reduced modulo
m.
$2^k \bmod m$ is computed once, and every coefficient is multiplied by it. Since m
need not be odd, coefficients can become zero, so the degree can drop.
$$ f(p, k, m) = 2^kp \bmod m. $$
§Worst-case complexity
$T(n, m) = O(n + m)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, $n$ is self.len(), and $m$ is
bits.significant_bits().
§Panics
Panics if m is 0, or if any coefficient of self is greater than or equal to m.
§Examples
See here.
type Output = UnsignedPolynomial<T>
Source§impl<T: PrimitiveUnsigned + ModShl<u128, T, Output = T>> ModShl<u128, T> for UnsignedPolynomial<T>
impl<T: PrimitiveUnsigned + ModShl<u128, T, Output = T>> ModShl<u128, T> for UnsignedPolynomial<T>
Source§fn mod_shl(self, bits: u128, m: T) -> UnsignedPolynomial<T>
fn mod_shl(self, bits: u128, m: T) -> UnsignedPolynomial<T>
Left-shifts an UnsignedPolynomial (multiplies it by a power of 2) modulo m,
taking the polynomial by value. The coefficients must already be reduced modulo m.
$2^k \bmod m$ is computed once, and every coefficient is multiplied by it. Since m
need not be odd, coefficients can become zero, so the degree can drop.
$$ f(p, k, m) = 2^kp \bmod m. $$
§Worst-case complexity
$T(n, m) = O(n + m)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, $n$ is self.len(), and $m$ is
bits.significant_bits().
§Panics
Panics if m is 0, or if any coefficient of self is greater than or equal to m.
§Examples
See here.
type Output = UnsignedPolynomial<T>
Source§impl<T: PrimitiveUnsigned + ModShl<u128, T, Output = T>> ModShl<u128, T> for &UnsignedPolynomial<T>
impl<T: PrimitiveUnsigned + ModShl<u128, T, Output = T>> ModShl<u128, T> for &UnsignedPolynomial<T>
Source§fn mod_shl(self, bits: u128, m: T) -> UnsignedPolynomial<T>
fn mod_shl(self, bits: u128, m: T) -> UnsignedPolynomial<T>
Left-shifts an UnsignedPolynomial (multiplies it by a power of 2) modulo m,
taking the polynomial by reference. The coefficients must already be reduced modulo
m.
$2^k \bmod m$ is computed once, and every coefficient is multiplied by it. Since m
need not be odd, coefficients can become zero, so the degree can drop.
$$ f(p, k, m) = 2^kp \bmod m. $$
§Worst-case complexity
$T(n, m) = O(n + m)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, $n$ is self.len(), and $m$ is
bits.significant_bits().
§Panics
Panics if m is 0, or if any coefficient of self is greater than or equal to m.
§Examples
See here.
type Output = UnsignedPolynomial<T>
Source§impl<T: PrimitiveUnsigned + ModShl<usize, T, Output = T>> ModShl<usize, T> for UnsignedPolynomial<T>
impl<T: PrimitiveUnsigned + ModShl<usize, T, Output = T>> ModShl<usize, T> for UnsignedPolynomial<T>
Source§fn mod_shl(self, bits: usize, m: T) -> UnsignedPolynomial<T>
fn mod_shl(self, bits: usize, m: T) -> UnsignedPolynomial<T>
Left-shifts an UnsignedPolynomial (multiplies it by a power of 2) modulo m,
taking the polynomial by value. The coefficients must already be reduced modulo m.
$2^k \bmod m$ is computed once, and every coefficient is multiplied by it. Since m
need not be odd, coefficients can become zero, so the degree can drop.
$$ f(p, k, m) = 2^kp \bmod m. $$
§Worst-case complexity
$T(n, m) = O(n + m)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, $n$ is self.len(), and $m$ is
bits.significant_bits().
§Panics
Panics if m is 0, or if any coefficient of self is greater than or equal to m.
§Examples
See here.
type Output = UnsignedPolynomial<T>
Source§impl<T: PrimitiveUnsigned + ModShl<usize, T, Output = T>> ModShl<usize, T> for &UnsignedPolynomial<T>
impl<T: PrimitiveUnsigned + ModShl<usize, T, Output = T>> ModShl<usize, T> for &UnsignedPolynomial<T>
Source§fn mod_shl(self, bits: usize, m: T) -> UnsignedPolynomial<T>
fn mod_shl(self, bits: usize, m: T) -> UnsignedPolynomial<T>
Left-shifts an UnsignedPolynomial (multiplies it by a power of 2) modulo m,
taking the polynomial by reference. The coefficients must already be reduced modulo
m.
$2^k \bmod m$ is computed once, and every coefficient is multiplied by it. Since m
need not be odd, coefficients can become zero, so the degree can drop.
$$ f(p, k, m) = 2^kp \bmod m. $$
§Worst-case complexity
$T(n, m) = O(n + m)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, $n$ is self.len(), and $m$ is
bits.significant_bits().
§Panics
Panics if m is 0, or if any coefficient of self is greater than or equal to m.
§Examples
See here.
type Output = UnsignedPolynomial<T>
Source§impl<T: PrimitiveUnsigned + ModShl<u8, T, Output = T>> ModShlAssign<u8, T> for UnsignedPolynomial<T>
impl<T: PrimitiveUnsigned + ModShl<u8, T, Output = T>> ModShlAssign<u8, T> for UnsignedPolynomial<T>
Source§fn mod_shl_assign(&mut self, bits: u8, m: T)
fn mod_shl_assign(&mut self, bits: u8, m: T)
Left-shifts an UnsignedPolynomial (multiplies it by a power of 2) modulo m, in
place. The coefficients must already be reduced modulo m.
$2^k \bmod m$ is computed once, and every coefficient is multiplied by it. Since m
need not be odd, coefficients can become zero, so the degree can drop.
$$ p \gets 2^kp \bmod m. $$
§Worst-case complexity
$T(n, m) = O(n + m)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, $n$ is self.len(), and $m$ is
bits.significant_bits().
§Panics
Panics if m is 0, or if any coefficient of self is greater than or equal to m.
§Examples
See here.
Source§impl<T: PrimitiveUnsigned + ModShl<u16, T, Output = T>> ModShlAssign<u16, T> for UnsignedPolynomial<T>
impl<T: PrimitiveUnsigned + ModShl<u16, T, Output = T>> ModShlAssign<u16, T> for UnsignedPolynomial<T>
Source§fn mod_shl_assign(&mut self, bits: u16, m: T)
fn mod_shl_assign(&mut self, bits: u16, m: T)
Left-shifts an UnsignedPolynomial (multiplies it by a power of 2) modulo m, in
place. The coefficients must already be reduced modulo m.
$2^k \bmod m$ is computed once, and every coefficient is multiplied by it. Since m
need not be odd, coefficients can become zero, so the degree can drop.
$$ p \gets 2^kp \bmod m. $$
§Worst-case complexity
$T(n, m) = O(n + m)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, $n$ is self.len(), and $m$ is
bits.significant_bits().
§Panics
Panics if m is 0, or if any coefficient of self is greater than or equal to m.
§Examples
See here.
Source§impl<T: PrimitiveUnsigned + ModShl<u32, T, Output = T>> ModShlAssign<u32, T> for UnsignedPolynomial<T>
impl<T: PrimitiveUnsigned + ModShl<u32, T, Output = T>> ModShlAssign<u32, T> for UnsignedPolynomial<T>
Source§fn mod_shl_assign(&mut self, bits: u32, m: T)
fn mod_shl_assign(&mut self, bits: u32, m: T)
Left-shifts an UnsignedPolynomial (multiplies it by a power of 2) modulo m, in
place. The coefficients must already be reduced modulo m.
$2^k \bmod m$ is computed once, and every coefficient is multiplied by it. Since m
need not be odd, coefficients can become zero, so the degree can drop.
$$ p \gets 2^kp \bmod m. $$
§Worst-case complexity
$T(n, m) = O(n + m)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, $n$ is self.len(), and $m$ is
bits.significant_bits().
§Panics
Panics if m is 0, or if any coefficient of self is greater than or equal to m.
§Examples
See here.
Source§impl<T: PrimitiveUnsigned + ModShl<u64, T, Output = T>> ModShlAssign<u64, T> for UnsignedPolynomial<T>
impl<T: PrimitiveUnsigned + ModShl<u64, T, Output = T>> ModShlAssign<u64, T> for UnsignedPolynomial<T>
Source§fn mod_shl_assign(&mut self, bits: u64, m: T)
fn mod_shl_assign(&mut self, bits: u64, m: T)
Left-shifts an UnsignedPolynomial (multiplies it by a power of 2) modulo m, in
place. The coefficients must already be reduced modulo m.
$2^k \bmod m$ is computed once, and every coefficient is multiplied by it. Since m
need not be odd, coefficients can become zero, so the degree can drop.
$$ p \gets 2^kp \bmod m. $$
§Worst-case complexity
$T(n, m) = O(n + m)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, $n$ is self.len(), and $m$ is
bits.significant_bits().
§Panics
Panics if m is 0, or if any coefficient of self is greater than or equal to m.
§Examples
See here.
Source§impl<T: PrimitiveUnsigned + ModShl<u128, T, Output = T>> ModShlAssign<u128, T> for UnsignedPolynomial<T>
impl<T: PrimitiveUnsigned + ModShl<u128, T, Output = T>> ModShlAssign<u128, T> for UnsignedPolynomial<T>
Source§fn mod_shl_assign(&mut self, bits: u128, m: T)
fn mod_shl_assign(&mut self, bits: u128, m: T)
Left-shifts an UnsignedPolynomial (multiplies it by a power of 2) modulo m, in
place. The coefficients must already be reduced modulo m.
$2^k \bmod m$ is computed once, and every coefficient is multiplied by it. Since m
need not be odd, coefficients can become zero, so the degree can drop.
$$ p \gets 2^kp \bmod m. $$
§Worst-case complexity
$T(n, m) = O(n + m)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, $n$ is self.len(), and $m$ is
bits.significant_bits().
§Panics
Panics if m is 0, or if any coefficient of self is greater than or equal to m.
§Examples
See here.
Source§impl<T: PrimitiveUnsigned + ModShl<usize, T, Output = T>> ModShlAssign<usize, T> for UnsignedPolynomial<T>
impl<T: PrimitiveUnsigned + ModShl<usize, T, Output = T>> ModShlAssign<usize, T> for UnsignedPolynomial<T>
Source§fn mod_shl_assign(&mut self, bits: usize, m: T)
fn mod_shl_assign(&mut self, bits: usize, m: T)
Left-shifts an UnsignedPolynomial (multiplies it by a power of 2) modulo m, in
place. The coefficients must already be reduced modulo m.
$2^k \bmod m$ is computed once, and every coefficient is multiplied by it. Since m
need not be odd, coefficients can become zero, so the degree can drop.
$$ p \gets 2^kp \bmod m. $$
§Worst-case complexity
$T(n, m) = O(n + m)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, $n$ is self.len(), and $m$ is
bits.significant_bits().
§Panics
Panics if m is 0, or if any coefficient of self is greater than or equal to m.
§Examples
See here.
Source§impl<T: PrimitiveUnsigned> ModSquare<T> for UnsignedPolynomial<T>
impl<T: PrimitiveUnsigned> ModSquare<T> for UnsignedPolynomial<T>
Source§fn mod_square(self, m: T) -> Self
fn mod_square(self, m: T) -> Self
Squares an UnsignedPolynomial modulo $m$, taking it by value. Its coefficients must
already be reduced modulo $m$.
$$ f(p, m) = p^2 \bmod m. $$
When $m$ is not prime, the leading coefficient of the square can vanish modulo $m$, and then the degree of the square is lower than twice the degree.
§Worst-case complexity
$T(n) = O(n^{\log_2 3})$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is self.len().
§Panics
Panics if m is 0, or if any coefficient of self is greater than or equal to m.
§Examples
use core::str::FromStr;
use malachite_base::num::arithmetic::traits::ModSquare;
use malachite_base::unsigned_polynomial::UnsignedPolynomial;
// The square is x^4+6*x^3+13*x^2+12*x+4; its coefficients modulo 7.
assert_eq!(
UnsignedPolynomial::<u8>::from_str("x^2+3*x+2")
.unwrap()
.mod_square(7)
.to_string(),
"x^4+6*x^3+6*x^2+5*x+4"
);
// The square is 4*x^2+4*x+1, which is 1 modulo 4.
assert_eq!(
UnsignedPolynomial::<u8>::from_str("2*x+1")
.unwrap()
.mod_square(4)
.to_string(),
"1"
);This is equivalent to nmod_poly_mul from nmod_poly/mul.c, FLINT 3.6.0, with both factors
equal.
type Output = UnsignedPolynomial<T>
Source§impl<T: PrimitiveUnsigned> ModSquare<T> for &UnsignedPolynomial<T>
impl<T: PrimitiveUnsigned> ModSquare<T> for &UnsignedPolynomial<T>
Source§fn mod_square(self, m: T) -> UnsignedPolynomial<T>
fn mod_square(self, m: T) -> UnsignedPolynomial<T>
Squares an UnsignedPolynomial modulo $m$, taking it by reference. Its coefficients must
already be reduced modulo $m$.
$$ f(p, m) = p^2 \bmod m. $$
When $m$ is not prime, the leading coefficient of the square can vanish modulo $m$, and then the degree of the square is lower than twice the degree.
§Worst-case complexity
$T(n) = O(n^{\log_2 3})$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is self.len().
§Panics
Panics if m is 0, or if any coefficient of self is greater than or equal to m.
§Examples
use core::str::FromStr;
use malachite_base::num::arithmetic::traits::ModSquare;
use malachite_base::unsigned_polynomial::UnsignedPolynomial;
// The square is x^4+6*x^3+13*x^2+12*x+4; its coefficients modulo 7.
assert_eq!(
(&UnsignedPolynomial::<u8>::from_str("x^2+3*x+2").unwrap())
.mod_square(7)
.to_string(),
"x^4+6*x^3+6*x^2+5*x+4"
);
// The square is 4*x^2+4*x+1, which is 1 modulo 4.
assert_eq!(
(&UnsignedPolynomial::<u8>::from_str("2*x+1").unwrap())
.mod_square(4)
.to_string(),
"1"
);This is equivalent to nmod_poly_mul from nmod_poly/mul.c, FLINT 3.6.0, with both factors
equal.
type Output = UnsignedPolynomial<T>
Source§impl<T: PrimitiveUnsigned> ModSquareAssign<T> for UnsignedPolynomial<T>
impl<T: PrimitiveUnsigned> ModSquareAssign<T> for UnsignedPolynomial<T>
Source§fn mod_square_assign(&mut self, m: T)
fn mod_square_assign(&mut self, m: T)
Squares an UnsignedPolynomial modulo $m$ in place. Its coefficients must already be
reduced modulo $m$.
$$ p \gets p^2 \bmod m. $$
§Worst-case complexity
$T(n) = O(n^{\log_2 3})$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is self.len().
§Panics
Panics if m is 0, or if any coefficient of self is greater than or equal to m.
§Examples
use core::str::FromStr;
use malachite_base::num::arithmetic::traits::ModSquareAssign;
use malachite_base::unsigned_polynomial::UnsignedPolynomial;
let mut p = UnsignedPolynomial::<u8>::from_str("x^2+3*x+2").unwrap();
p.mod_square_assign(7);
assert_eq!(p.to_string(), "x^4+6*x^3+6*x^2+5*x+4");This is equivalent to nmod_poly_mul from nmod_poly/mul.c, FLINT 3.6.0, with both factors
equal.
Source§impl<T: PrimitiveUnsigned> ModSquareTruncated<T> for UnsignedPolynomial<T>
impl<T: PrimitiveUnsigned> ModSquareTruncated<T> for UnsignedPolynomial<T>
Source§fn mod_square_truncated(self, len: u64, m: T) -> Self
fn mod_square_truncated(self, len: u64, m: T) -> Self
Squares an UnsignedPolynomial modulo $m$, keeping only the coefficients of $x^i$ for $i$
less than len, taking it by value. Its coefficients must already be reduced modulo $m$.
$$ f(p, n, m) = (p^2 \bmod x^n) \bmod m. $$
The polynomial need not already be truncated: this is the square of its image modulo $x^n$,
so only its first len coefficients are read.
§Worst-case complexity
$T(n) = O(n^{\log_2 3})$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is len.
§Panics
Panics if m is 0, or if any coefficient of self is greater than or equal to m.
§Examples
use core::str::FromStr;
use malachite_base::polynomial::ModSquareTruncated;
use malachite_base::unsigned_polynomial::UnsignedPolynomial;
// The square is x^4+6*x^3+13*x^2+12*x+4; its low three coefficients, modulo 7.
assert_eq!(
UnsignedPolynomial::<u8>::from_str("x^2+3*x+2")
.unwrap()
.mod_square_truncated(3, 7)
.to_string(),
"6*x^2+5*x+4"
);
// The linear coefficient of the square, 4, vanishes modulo 4.
assert_eq!(
UnsignedPolynomial::<u8>::from_str("2*x+1")
.unwrap()
.mod_square_truncated(2, 4)
.to_string(),
"1"
);This is equivalent to nmod_poly_mullow from nmod_poly/mullow.c, FLINT 3.6.0, with both
factors equal.
type Output = UnsignedPolynomial<T>
Source§impl<T: PrimitiveUnsigned> ModSquareTruncated<T> for &UnsignedPolynomial<T>
impl<T: PrimitiveUnsigned> ModSquareTruncated<T> for &UnsignedPolynomial<T>
Source§fn mod_square_truncated(self, len: u64, m: T) -> UnsignedPolynomial<T>
fn mod_square_truncated(self, len: u64, m: T) -> UnsignedPolynomial<T>
Squares an UnsignedPolynomial modulo $m$, keeping only the coefficients of $x^i$ for $i$
less than len, taking it by reference. Its coefficients must already be reduced modulo
$m$.
$$ f(p, n, m) = (p^2 \bmod x^n) \bmod m. $$
The polynomial need not already be truncated: this is the square of its image modulo $x^n$,
so only its first len coefficients are read.
§Worst-case complexity
$T(n) = O(n^{\log_2 3})$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is len.
§Panics
Panics if m is 0, or if any coefficient of self is greater than or equal to m.
§Examples
use core::str::FromStr;
use malachite_base::polynomial::ModSquareTruncated;
use malachite_base::unsigned_polynomial::UnsignedPolynomial;
// The square is x^4+6*x^3+13*x^2+12*x+4; its low three coefficients, modulo 7.
assert_eq!(
(&UnsignedPolynomial::<u8>::from_str("x^2+3*x+2").unwrap())
.mod_square_truncated(3, 7)
.to_string(),
"6*x^2+5*x+4"
);
// The linear coefficient of the square, 4, vanishes modulo 4.
assert_eq!(
(&UnsignedPolynomial::<u8>::from_str("2*x+1").unwrap())
.mod_square_truncated(2, 4)
.to_string(),
"1"
);This is equivalent to nmod_poly_mullow from nmod_poly/mullow.c, FLINT 3.6.0, with both
factors equal.
type Output = UnsignedPolynomial<T>
Source§impl<T: PrimitiveUnsigned> ModSquareTruncatedAssign<T> for UnsignedPolynomial<T>
impl<T: PrimitiveUnsigned> ModSquareTruncatedAssign<T> for UnsignedPolynomial<T>
Source§fn mod_square_truncated_assign(&mut self, len: u64, m: T)
fn mod_square_truncated_assign(&mut self, len: u64, m: T)
Squares an UnsignedPolynomial modulo $m$ in place, keeping only the coefficients of
$x^i$ for $i$ less than len. Its coefficients must already be reduced modulo $m$.
$$ p \gets (p^2 \bmod x^n) \bmod m. $$
§Worst-case complexity
$T(n) = O(n^{\log_2 3})$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is len.
§Panics
Panics if m is 0, or if any coefficient of self is greater than or equal to m.
§Examples
use core::str::FromStr;
use malachite_base::polynomial::ModSquareTruncatedAssign;
use malachite_base::unsigned_polynomial::UnsignedPolynomial;
let mut p = UnsignedPolynomial::<u8>::from_str("x^2+3*x+2").unwrap();
p.mod_square_truncated_assign(3, 7);
assert_eq!(p.to_string(), "6*x^2+5*x+4");This is equivalent to nmod_poly_mullow from nmod_poly/mullow.c, FLINT 3.6.0, with both
factors equal.
Source§impl<T: PrimitiveUnsigned> ModSub<&UnsignedPolynomial<T>, T> for UnsignedPolynomial<T>
impl<T: PrimitiveUnsigned> ModSub<&UnsignedPolynomial<T>, T> for UnsignedPolynomial<T>
Source§fn mod_sub(self, other: &Self, m: T) -> Self
fn mod_sub(self, other: &Self, m: T) -> Self
Subtracts one UnsignedPolynomial from another modulo m, taking the first by value and
the second by reference. The coefficients of both must already be reduced modulo m.
$$ f(p, q, m) = p - q \bmod m. $$
Coefficients past the end of the shorter polynomial are taken to be zero. Where the second
polynomial is longer, its coefficients are negated modulo m. When the two polynomials have
the same degree, their leading coefficients can cancel modulo m, and then the degree of
the difference is lower.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is the number of coefficients of the longer polynomial.
§Panics
Panics if m is 0, or if any coefficient of self or other is greater than or equal to
m.
§Examples
use core::str::FromStr;
use malachite_base::num::arithmetic::traits::ModSub;
use malachite_base::unsigned_polynomial::UnsignedPolynomial;
assert_eq!(
UnsignedPolynomial::<u8>::from_str("5*x^2+x+3")
.unwrap()
.mod_sub(&UnsignedPolynomial::from_str("2*x^2+6*x+1").unwrap(), 7)
.to_string(),
"3*x^2+2*x+2"
);
// The leading coefficients cancel.
assert_eq!(
UnsignedPolynomial::<u8>::from_str("5*x^2+x")
.unwrap()
.mod_sub(&UnsignedPolynomial::from_str("5*x^2+3").unwrap(), 7)
.to_string(),
"x+4"
);This is equivalent to nmod_poly_sub from nmod_poly/sub.c, FLINT 3.6.0.
type Output = UnsignedPolynomial<T>
Source§impl<T: PrimitiveUnsigned> ModSub<&UnsignedPolynomial<T>, T> for &UnsignedPolynomial<T>
impl<T: PrimitiveUnsigned> ModSub<&UnsignedPolynomial<T>, T> for &UnsignedPolynomial<T>
Source§fn mod_sub(self, other: &UnsignedPolynomial<T>, m: T) -> UnsignedPolynomial<T>
fn mod_sub(self, other: &UnsignedPolynomial<T>, m: T) -> UnsignedPolynomial<T>
Subtracts one UnsignedPolynomial from another modulo m, taking both by reference. The
coefficients of both must already be reduced modulo m.
$$ f(p, q, m) = p - q \bmod m. $$
Coefficients past the end of the shorter polynomial are taken to be zero. Where the second
polynomial is longer, its coefficients are negated modulo m. When the two polynomials have
the same degree, their leading coefficients can cancel modulo m, and then the degree of
the difference is lower.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is the number of coefficients of the longer polynomial.
§Panics
Panics if m is 0, or if any coefficient of self or other is greater than or equal to
m.
§Examples
use core::str::FromStr;
use malachite_base::num::arithmetic::traits::ModSub;
use malachite_base::unsigned_polynomial::UnsignedPolynomial;
assert_eq!(
(&UnsignedPolynomial::<u8>::from_str("5*x^2+x+3").unwrap())
.mod_sub(&UnsignedPolynomial::from_str("2*x^2+6*x+1").unwrap(), 7)
.to_string(),
"3*x^2+2*x+2"
);
// The leading coefficients cancel.
assert_eq!(
(&UnsignedPolynomial::<u8>::from_str("5*x^2+x").unwrap())
.mod_sub(&UnsignedPolynomial::from_str("5*x^2+3").unwrap(), 7)
.to_string(),
"x+4"
);This is equivalent to nmod_poly_sub from nmod_poly/sub.c, FLINT 3.6.0.
type Output = UnsignedPolynomial<T>
Source§impl<T: PrimitiveUnsigned> ModSub<UnsignedPolynomial<T>, T> for UnsignedPolynomial<T>
impl<T: PrimitiveUnsigned> ModSub<UnsignedPolynomial<T>, T> for UnsignedPolynomial<T>
Source§fn mod_sub(self, other: Self, m: T) -> Self
fn mod_sub(self, other: Self, m: T) -> Self
Subtracts one UnsignedPolynomial from another modulo m, taking both by value. The
coefficients of both must already be reduced modulo m.
$$ f(p, q, m) = p - q \bmod m. $$
Coefficients past the end of the shorter polynomial are taken to be zero. Where the second
polynomial is longer, its coefficients are negated modulo m. When the two polynomials have
the same degree, their leading coefficients can cancel modulo m, and then the degree of
the difference is lower.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is the number of coefficients of the longer polynomial.
§Panics
Panics if m is 0, or if any coefficient of self or other is greater than or equal to
m.
§Examples
use core::str::FromStr;
use malachite_base::num::arithmetic::traits::ModSub;
use malachite_base::unsigned_polynomial::UnsignedPolynomial;
assert_eq!(
UnsignedPolynomial::<u8>::from_str("5*x^2+x+3")
.unwrap()
.mod_sub(UnsignedPolynomial::from_str("2*x^2+6*x+1").unwrap(), 7)
.to_string(),
"3*x^2+2*x+2"
);
// The leading coefficients cancel.
assert_eq!(
UnsignedPolynomial::<u8>::from_str("5*x^2+x")
.unwrap()
.mod_sub(UnsignedPolynomial::from_str("5*x^2+3").unwrap(), 7)
.to_string(),
"x+4"
);This is equivalent to nmod_poly_sub from nmod_poly/sub.c, FLINT 3.6.0.
type Output = UnsignedPolynomial<T>
Source§impl<T: PrimitiveUnsigned> ModSub<UnsignedPolynomial<T>, T> for &UnsignedPolynomial<T>
impl<T: PrimitiveUnsigned> ModSub<UnsignedPolynomial<T>, T> for &UnsignedPolynomial<T>
Source§fn mod_sub(self, other: UnsignedPolynomial<T>, m: T) -> UnsignedPolynomial<T>
fn mod_sub(self, other: UnsignedPolynomial<T>, m: T) -> UnsignedPolynomial<T>
Subtracts one UnsignedPolynomial from another modulo m, taking the first by reference
and the second by value. The coefficients of both must already be reduced modulo m.
$$ f(p, q, m) = p - q \bmod m. $$
Coefficients past the end of the shorter polynomial are taken to be zero. Where the second
polynomial is longer, its coefficients are negated modulo m. When the two polynomials have
the same degree, their leading coefficients can cancel modulo m, and then the degree of
the difference is lower.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is the number of coefficients of the longer polynomial.
§Panics
Panics if m is 0, or if any coefficient of self or other is greater than or equal to
m.
§Examples
use core::str::FromStr;
use malachite_base::num::arithmetic::traits::ModSub;
use malachite_base::unsigned_polynomial::UnsignedPolynomial;
assert_eq!(
(&UnsignedPolynomial::<u8>::from_str("5*x^2+x+3").unwrap())
.mod_sub(UnsignedPolynomial::from_str("2*x^2+6*x+1").unwrap(), 7)
.to_string(),
"3*x^2+2*x+2"
);
// The leading coefficients cancel.
assert_eq!(
(&UnsignedPolynomial::<u8>::from_str("5*x^2+x").unwrap())
.mod_sub(UnsignedPolynomial::from_str("5*x^2+3").unwrap(), 7)
.to_string(),
"x+4"
);This is equivalent to nmod_poly_sub from nmod_poly/sub.c, FLINT 3.6.0.
type Output = UnsignedPolynomial<T>
Source§impl<T: PrimitiveUnsigned> ModSubAssign<&UnsignedPolynomial<T>, T> for UnsignedPolynomial<T>
impl<T: PrimitiveUnsigned> ModSubAssign<&UnsignedPolynomial<T>, T> for UnsignedPolynomial<T>
Source§fn mod_sub_assign(&mut self, other: &Self, m: T)
fn mod_sub_assign(&mut self, other: &Self, m: T)
Subtracts an UnsignedPolynomial from an UnsignedPolynomial modulo m, in place,
taking the second by reference. The coefficients of both must already be reduced modulo m.
$$ p \gets p - q \bmod m. $$
Coefficients past the end of the shorter polynomial are taken to be zero. Where the second
polynomial is longer, its coefficients are negated modulo m. When the two polynomials have
the same degree, their leading coefficients can cancel modulo m, and then the degree of
the difference is lower.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is the number of coefficients of the longer polynomial.
§Panics
Panics if m is 0, or if any coefficient of self or other is greater than or equal to
m.
§Examples
use core::str::FromStr;
use malachite_base::num::arithmetic::traits::ModSubAssign;
use malachite_base::unsigned_polynomial::UnsignedPolynomial;
let mut p = UnsignedPolynomial::<u8>::from_str("5*x^2+x+3").unwrap();
p.mod_sub_assign(&UnsignedPolynomial::from_str("2*x^2+6*x+1").unwrap(), 7);
assert_eq!(p.to_string(), "3*x^2+2*x+2");
// The leading coefficients cancel.
let mut p = UnsignedPolynomial::<u8>::from_str("5*x^2+x").unwrap();
p.mod_sub_assign(&UnsignedPolynomial::from_str("5*x^2+3").unwrap(), 7);
assert_eq!(p.to_string(), "x+4");This is equivalent to nmod_poly_sub from nmod_poly/sub.c, FLINT 3.6.0.
Source§impl<T: PrimitiveUnsigned> ModSubAssign<UnsignedPolynomial<T>, T> for UnsignedPolynomial<T>
impl<T: PrimitiveUnsigned> ModSubAssign<UnsignedPolynomial<T>, T> for UnsignedPolynomial<T>
Source§fn mod_sub_assign(&mut self, other: Self, m: T)
fn mod_sub_assign(&mut self, other: Self, m: T)
Subtracts an UnsignedPolynomial from an UnsignedPolynomial modulo m, in place,
taking the second by value. The coefficients of both must already be reduced modulo m.
$$ p \gets p - q \bmod m. $$
Coefficients past the end of the shorter polynomial are taken to be zero. Where the second
polynomial is longer, its coefficients are negated modulo m. When the two polynomials have
the same degree, their leading coefficients can cancel modulo m, and then the degree of
the difference is lower.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is the number of coefficients of the longer polynomial.
§Panics
Panics if m is 0, or if any coefficient of self or other is greater than or equal to
m.
§Examples
use core::str::FromStr;
use malachite_base::num::arithmetic::traits::ModSubAssign;
use malachite_base::unsigned_polynomial::UnsignedPolynomial;
let mut p = UnsignedPolynomial::<u8>::from_str("5*x^2+x+3").unwrap();
p.mod_sub_assign(UnsignedPolynomial::from_str("2*x^2+6*x+1").unwrap(), 7);
assert_eq!(p.to_string(), "3*x^2+2*x+2");
// The leading coefficients cancel.
let mut p = UnsignedPolynomial::<u8>::from_str("5*x^2+x").unwrap();
p.mod_sub_assign(UnsignedPolynomial::from_str("5*x^2+3").unwrap(), 7);
assert_eq!(p.to_string(), "x+4");This is equivalent to nmod_poly_sub from nmod_poly/sub.c, FLINT 3.6.0.
Source§impl<T: PrimitiveUnsigned> ModSubTruncated<&UnsignedPolynomial<T>, T> for UnsignedPolynomial<T>
impl<T: PrimitiveUnsigned> ModSubTruncated<&UnsignedPolynomial<T>, T> for UnsignedPolynomial<T>
Source§fn mod_sub_truncated(self, other: &Self, len: u64, m: T) -> Self
fn mod_sub_truncated(self, other: &Self, len: u64, m: T) -> Self
Subtracts one UnsignedPolynomial from another modulo m, keeping only the coefficients
of $x^i$ for $i$ less than len, taking the first by value and the second by reference. The
coefficients of both must already be reduced modulo m.
$$ f(p, q, n, m) = ((p - q) \bmod x^n) \bmod m. $$
The polynomials need not already be truncated: this is the difference of their images modulo
$x^n$, so only the first len coefficients of each are read. Where the second polynomial
has more of those, they are negated modulo m. The difference is trimmed, so when
coefficients cancel modulo m at the top of the kept range, the degree is lower still.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is the number of coefficients of the longer polynomial.
§Panics
Panics if m is 0, or if any coefficient of self or other is greater than or equal to
m.
§Examples
use core::str::FromStr;
use malachite_base::polynomial::ModSubTruncated;
use malachite_base::unsigned_polynomial::UnsignedPolynomial;
// The quadratic and linear coefficients wrap around.
assert_eq!(
UnsignedPolynomial::<u8>::from_str("x^3+2*x^2+x+5")
.unwrap()
.mod_sub_truncated(&UnsignedPolynomial::from_str("4*x^2+6*x+2").unwrap(), 3, 7)
.to_string(),
"5*x^2+2*x+3"
);
assert_eq!(
UnsignedPolynomial::<u8>::from_str("x^3+2*x^2+x+5")
.unwrap()
.mod_sub_truncated(&UnsignedPolynomial::from_str("4*x^2+6*x+2").unwrap(), 1, 7)
.to_string(),
"3"
);This is equivalent to nmod_poly_sub_series from nmod_poly/sub_series.c, FLINT 3.6.0.
type Output = UnsignedPolynomial<T>
Source§impl<T: PrimitiveUnsigned> ModSubTruncated<&UnsignedPolynomial<T>, T> for &UnsignedPolynomial<T>
impl<T: PrimitiveUnsigned> ModSubTruncated<&UnsignedPolynomial<T>, T> for &UnsignedPolynomial<T>
Source§fn mod_sub_truncated(
self,
other: &UnsignedPolynomial<T>,
len: u64,
m: T,
) -> UnsignedPolynomial<T>
fn mod_sub_truncated( self, other: &UnsignedPolynomial<T>, len: u64, m: T, ) -> UnsignedPolynomial<T>
Subtracts one UnsignedPolynomial from another modulo m, keeping only the coefficients
of $x^i$ for $i$ less than len, taking both by reference. The coefficients of both must
already be reduced modulo m.
$$ f(p, q, n, m) = ((p - q) \bmod x^n) \bmod m. $$
The polynomials need not already be truncated: this is the difference of their images modulo
$x^n$, so only the first len coefficients of each are read. Where the second polynomial
has more of those, they are negated modulo m. The difference is trimmed, so when
coefficients cancel modulo m at the top of the kept range, the degree is lower still.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is the number of coefficients of the longer polynomial.
§Panics
Panics if m is 0, or if any coefficient of self or other is greater than or equal to
m.
§Examples
use core::str::FromStr;
use malachite_base::polynomial::ModSubTruncated;
use malachite_base::unsigned_polynomial::UnsignedPolynomial;
// The quadratic and linear coefficients wrap around.
assert_eq!(
(&UnsignedPolynomial::<u8>::from_str("x^3+2*x^2+x+5").unwrap())
.mod_sub_truncated(&UnsignedPolynomial::from_str("4*x^2+6*x+2").unwrap(), 3, 7)
.to_string(),
"5*x^2+2*x+3"
);
assert_eq!(
(&UnsignedPolynomial::<u8>::from_str("x^3+2*x^2+x+5").unwrap())
.mod_sub_truncated(&UnsignedPolynomial::from_str("4*x^2+6*x+2").unwrap(), 1, 7)
.to_string(),
"3"
);This is equivalent to nmod_poly_sub_series from nmod_poly/sub_series.c, FLINT 3.6.0.
type Output = UnsignedPolynomial<T>
Source§impl<T: PrimitiveUnsigned> ModSubTruncated<UnsignedPolynomial<T>, T> for UnsignedPolynomial<T>
impl<T: PrimitiveUnsigned> ModSubTruncated<UnsignedPolynomial<T>, T> for UnsignedPolynomial<T>
Source§fn mod_sub_truncated(self, other: Self, len: u64, m: T) -> Self
fn mod_sub_truncated(self, other: Self, len: u64, m: T) -> Self
Subtracts one UnsignedPolynomial from another modulo m, keeping only the coefficients
of $x^i$ for $i$ less than len, taking both by value. The coefficients of both must
already be reduced modulo m.
$$ f(p, q, n, m) = ((p - q) \bmod x^n) \bmod m. $$
The polynomials need not already be truncated: this is the difference of their images modulo
$x^n$, so only the first len coefficients of each are read. Where the second polynomial
has more of those, they are negated modulo m. The difference is trimmed, so when
coefficients cancel modulo m at the top of the kept range, the degree is lower still.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is the number of coefficients of the longer polynomial.
§Panics
Panics if m is 0, or if any coefficient of self or other is greater than or equal to
m.
§Examples
use core::str::FromStr;
use malachite_base::polynomial::ModSubTruncated;
use malachite_base::unsigned_polynomial::UnsignedPolynomial;
// The quadratic and linear coefficients wrap around.
assert_eq!(
UnsignedPolynomial::<u8>::from_str("x^3+2*x^2+x+5")
.unwrap()
.mod_sub_truncated(UnsignedPolynomial::from_str("4*x^2+6*x+2").unwrap(), 3, 7)
.to_string(),
"5*x^2+2*x+3"
);
assert_eq!(
UnsignedPolynomial::<u8>::from_str("x^3+2*x^2+x+5")
.unwrap()
.mod_sub_truncated(UnsignedPolynomial::from_str("4*x^2+6*x+2").unwrap(), 1, 7)
.to_string(),
"3"
);This is equivalent to nmod_poly_sub_series from nmod_poly/sub_series.c, FLINT 3.6.0.
type Output = UnsignedPolynomial<T>
Source§impl<T: PrimitiveUnsigned> ModSubTruncated<UnsignedPolynomial<T>, T> for &UnsignedPolynomial<T>
impl<T: PrimitiveUnsigned> ModSubTruncated<UnsignedPolynomial<T>, T> for &UnsignedPolynomial<T>
Source§fn mod_sub_truncated(
self,
other: UnsignedPolynomial<T>,
len: u64,
m: T,
) -> UnsignedPolynomial<T>
fn mod_sub_truncated( self, other: UnsignedPolynomial<T>, len: u64, m: T, ) -> UnsignedPolynomial<T>
Subtracts one UnsignedPolynomial from another modulo m, keeping only the coefficients
of $x^i$ for $i$ less than len, taking the first by reference and the second by value. The
coefficients of both must already be reduced modulo m.
$$ f(p, q, n, m) = ((p - q) \bmod x^n) \bmod m. $$
The polynomials need not already be truncated: this is the difference of their images modulo
$x^n$, so only the first len coefficients of each are read. Where the second polynomial
has more of those, they are negated modulo m. The difference is trimmed, so when
coefficients cancel modulo m at the top of the kept range, the degree is lower still.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is the number of coefficients of the longer polynomial.
§Panics
Panics if m is 0, or if any coefficient of self or other is greater than or equal to
m.
§Examples
use core::str::FromStr;
use malachite_base::polynomial::ModSubTruncated;
use malachite_base::unsigned_polynomial::UnsignedPolynomial;
// The quadratic and linear coefficients wrap around.
assert_eq!(
(&UnsignedPolynomial::<u8>::from_str("x^3+2*x^2+x+5").unwrap())
.mod_sub_truncated(UnsignedPolynomial::from_str("4*x^2+6*x+2").unwrap(), 3, 7)
.to_string(),
"5*x^2+2*x+3"
);
assert_eq!(
(&UnsignedPolynomial::<u8>::from_str("x^3+2*x^2+x+5").unwrap())
.mod_sub_truncated(UnsignedPolynomial::from_str("4*x^2+6*x+2").unwrap(), 1, 7)
.to_string(),
"3"
);This is equivalent to nmod_poly_sub_series from nmod_poly/sub_series.c, FLINT 3.6.0.
type Output = UnsignedPolynomial<T>
Source§impl<T: PrimitiveUnsigned> ModSubTruncatedAssign<&UnsignedPolynomial<T>, T> for UnsignedPolynomial<T>
impl<T: PrimitiveUnsigned> ModSubTruncatedAssign<&UnsignedPolynomial<T>, T> for UnsignedPolynomial<T>
Source§fn mod_sub_truncated_assign(&mut self, other: &Self, len: u64, m: T)
fn mod_sub_truncated_assign(&mut self, other: &Self, len: u64, m: T)
Subtracts an UnsignedPolynomial from an UnsignedPolynomial modulo m in place,
keeping only the coefficients of $x^i$ for $i$ less than len, taking the second polynomial
by reference. The coefficients of both must already be reduced modulo m.
$$ p \gets ((p - q) \bmod x^n) \bmod m. $$
The polynomials need not already be truncated: this is the difference of their images modulo
$x^n$, so only the first len coefficients of each are read. Where the second polynomial
has more of those, they are negated modulo m. The difference is trimmed, so when
coefficients cancel modulo m at the top of the kept range, the degree is lower still.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is the number of coefficients of the longer polynomial.
§Panics
Panics if m is 0, or if any coefficient of self or other is greater than or equal to
m.
§Examples
use core::str::FromStr;
use malachite_base::polynomial::ModSubTruncatedAssign;
use malachite_base::unsigned_polynomial::UnsignedPolynomial;
// The quadratic and linear coefficients wrap around.
let mut p = UnsignedPolynomial::<u8>::from_str("x^3+2*x^2+x+5").unwrap();
p.mod_sub_truncated_assign(&UnsignedPolynomial::from_str("4*x^2+6*x+2").unwrap(), 3, 7);
assert_eq!(p.to_string(), "5*x^2+2*x+3");
let mut p = UnsignedPolynomial::<u8>::from_str("x^3+2*x^2+x+5").unwrap();
p.mod_sub_truncated_assign(&UnsignedPolynomial::from_str("4*x^2+6*x+2").unwrap(), 1, 7);
assert_eq!(p.to_string(), "3");This is equivalent to nmod_poly_sub_series from nmod_poly/sub_series.c, FLINT 3.6.0.
Source§impl<T: PrimitiveUnsigned> ModSubTruncatedAssign<UnsignedPolynomial<T>, T> for UnsignedPolynomial<T>
impl<T: PrimitiveUnsigned> ModSubTruncatedAssign<UnsignedPolynomial<T>, T> for UnsignedPolynomial<T>
Source§fn mod_sub_truncated_assign(&mut self, other: Self, len: u64, m: T)
fn mod_sub_truncated_assign(&mut self, other: Self, len: u64, m: T)
Subtracts an UnsignedPolynomial from an UnsignedPolynomial modulo m in place,
keeping only the coefficients of $x^i$ for $i$ less than len, taking the second polynomial
by value. The coefficients of both must already be reduced modulo m.
$$ p \gets ((p - q) \bmod x^n) \bmod m. $$
The polynomials need not already be truncated: this is the difference of their images modulo
$x^n$, so only the first len coefficients of each are read. Where the second polynomial
has more of those, they are negated modulo m. The difference is trimmed, so when
coefficients cancel modulo m at the top of the kept range, the degree is lower still.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is the number of coefficients of the longer polynomial.
§Panics
Panics if m is 0, or if any coefficient of self or other is greater than or equal to
m.
§Examples
use core::str::FromStr;
use malachite_base::polynomial::ModSubTruncatedAssign;
use malachite_base::unsigned_polynomial::UnsignedPolynomial;
// The quadratic and linear coefficients wrap around.
let mut p = UnsignedPolynomial::<u8>::from_str("x^3+2*x^2+x+5").unwrap();
p.mod_sub_truncated_assign(UnsignedPolynomial::from_str("4*x^2+6*x+2").unwrap(), 3, 7);
assert_eq!(p.to_string(), "5*x^2+2*x+3");
let mut p = UnsignedPolynomial::<u8>::from_str("x^3+2*x^2+x+5").unwrap();
p.mod_sub_truncated_assign(UnsignedPolynomial::from_str("4*x^2+6*x+2").unwrap(), 1, 7);
assert_eq!(p.to_string(), "3");This is equivalent to nmod_poly_sub_series from nmod_poly/sub_series.c, FLINT 3.6.0.
Source§impl<T: PrimitiveUnsigned> MulPowerOfX for UnsignedPolynomial<T>
impl<T: PrimitiveUnsigned> MulPowerOfX for UnsignedPolynomial<T>
Source§fn mul_power_of_x(self, n: u64) -> Self
fn mul_power_of_x(self, n: u64) -> Self
Multiplies an UnsignedPolynomial by $x^n$, taking it by value. Every coefficient moves
up by $n$ places, and $n$ zeros fill the places below them.
$$ f(p, n) = x^np. $$
The zero polynomial stays zero, and multiplying by $x^0$ changes nothing.
§Worst-case complexity
$T(n, m) = O(n + m)$
$M(n, m) = O(1)$
where $T$ is time, $M$ is additional memory, $n$ is n, and $m$ is self.len().
§Panics
Panics if the polynomial is nonzero and n is greater than usize::MAX.
§Examples
use core::str::FromStr;
use malachite_base::num::basic::traits::Zero;
use malachite_base::polynomial::MulPowerOfX;
use malachite_base::unsigned_polynomial::UnsignedPolynomial;
assert_eq!(
UnsignedPolynomial::<u8>::from_str("x^2+3*x+2")
.unwrap()
.mul_power_of_x(2)
.to_string(),
"x^4+3*x^3+2*x^2"
);
assert_eq!(
UnsignedPolynomial::<u8>::from_str("5")
.unwrap()
.mul_power_of_x(1)
.to_string(),
"5*x"
);
assert_eq!(
UnsignedPolynomial::<u8>::ZERO.mul_power_of_x(3),
UnsignedPolynomial::<u8>::ZERO
);This is equivalent to nmod_poly_shift_left from nmod_poly/shift_left.c, FLINT 3.6.0.
type Output = UnsignedPolynomial<T>
Source§impl<T: PrimitiveUnsigned> MulPowerOfX for &UnsignedPolynomial<T>
impl<T: PrimitiveUnsigned> MulPowerOfX for &UnsignedPolynomial<T>
Source§fn mul_power_of_x(self, n: u64) -> UnsignedPolynomial<T>
fn mul_power_of_x(self, n: u64) -> UnsignedPolynomial<T>
Multiplies an UnsignedPolynomial by $x^n$, taking it by reference. Every coefficient
moves up by $n$ places, and $n$ zeros fill the places below them.
$$ f(p, n) = x^np. $$
The zero polynomial stays zero, and multiplying by $x^0$ changes nothing.
§Worst-case complexity
$T(n, m) = O(n + m)$
$M(n, m) = O(n + m)$
where $T$ is time, $M$ is additional memory, $n$ is n, and $m$ is self.len().
§Panics
Panics if the polynomial is nonzero and n is greater than usize::MAX.
§Examples
use core::str::FromStr;
use malachite_base::num::basic::traits::Zero;
use malachite_base::polynomial::MulPowerOfX;
use malachite_base::unsigned_polynomial::UnsignedPolynomial;
assert_eq!(
(&UnsignedPolynomial::<u8>::from_str("x^2+3*x+2").unwrap())
.mul_power_of_x(2)
.to_string(),
"x^4+3*x^3+2*x^2"
);
assert_eq!(
(&UnsignedPolynomial::<u8>::from_str("5").unwrap())
.mul_power_of_x(1)
.to_string(),
"5*x"
);
assert_eq!(
(&UnsignedPolynomial::<u8>::ZERO).mul_power_of_x(3),
UnsignedPolynomial::<u8>::ZERO
);This is equivalent to nmod_poly_shift_left from nmod_poly/shift_left.c, FLINT 3.6.0.
type Output = UnsignedPolynomial<T>
Source§impl<T: PrimitiveUnsigned> MulPowerOfXAssign for UnsignedPolynomial<T>
impl<T: PrimitiveUnsigned> MulPowerOfXAssign for UnsignedPolynomial<T>
Source§fn mul_power_of_x_assign(&mut self, n: u64)
fn mul_power_of_x_assign(&mut self, n: u64)
Multiplies an UnsignedPolynomial by $x^n$ in place. Every coefficient moves up by $n$
places, and $n$ zeros fill the places below them.
$$ p \gets x^np. $$
The zero polynomial stays zero, and multiplying by $x^0$ changes nothing.
§Worst-case complexity
$T(n, m) = O(n + m)$
$M(n, m) = O(n)$
where $T$ is time, $M$ is additional memory, $n$ is n, and $m$ is self.len().
§Panics
Panics if the polynomial is nonzero and n is greater than usize::MAX.
§Examples
use core::str::FromStr;
use malachite_base::num::basic::traits::Zero;
use malachite_base::polynomial::MulPowerOfXAssign;
use malachite_base::unsigned_polynomial::UnsignedPolynomial;
let mut p = UnsignedPolynomial::<u8>::from_str("x^2+3*x+2").unwrap();
p.mul_power_of_x_assign(2);
assert_eq!(p.to_string(), "x^4+3*x^3+2*x^2");
let mut p = UnsignedPolynomial::<u8>::from_str("5").unwrap();
p.mul_power_of_x_assign(1);
assert_eq!(p.to_string(), "5*x");
let mut p = UnsignedPolynomial::<u8>::ZERO;
p.mul_power_of_x_assign(3);
assert_eq!(p, UnsignedPolynomial::<u8>::ZERO);This is equivalent to nmod_poly_shift_left from nmod_poly/shift_left.c, FLINT 3.6.0.
Source§impl Named for UnsignedPolynomial<u8>
impl Named for UnsignedPolynomial<u8>
Source§impl Named for UnsignedPolynomial<u16>
impl Named for UnsignedPolynomial<u16>
Source§impl Named for UnsignedPolynomial<u32>
impl Named for UnsignedPolynomial<u32>
Source§impl Named for UnsignedPolynomial<u64>
impl Named for UnsignedPolynomial<u64>
Source§impl Named for UnsignedPolynomial<u128>
impl Named for UnsignedPolynomial<u128>
Source§impl Named for UnsignedPolynomial<usize>
impl Named for UnsignedPolynomial<usize>
Source§impl<T: PrimitiveUnsigned> Ord for UnsignedPolynomial<T>
impl<T: PrimitiveUnsigned> Ord for UnsignedPolynomial<T>
Source§fn cmp(&self, other: &Self) -> Ordering
fn cmp(&self, other: &Self) -> Ordering
Compares two UnsignedPolynomials by how they behave for large arguments.
The greater polynomial is the one that is eventually greater: the comparison is the one that $p(x)$ and $q(x)$ eventually settle into as $x$ grows. The coefficients are read as the numbers they are, so the values being compared are the ones a polynomial over the integers would take, not ones reduced by any modulus.
$$ f(p, q) = \lim_{x \to \infty} \operatorname{cmp}(p(x), q(x)). $$
The limit always exists. $p - q$ is a polynomial, so it has finitely many roots, and past
the largest of them its sign is the sign of its leading coefficient and never changes again.
That also makes this a total order agreeing with Eq: the limit is $0$ exactly when $p -
q$ is the zero polynomial.
Finding it needs no evaluation. A polynomial of higher degree eventually outgrows one of lower degree, whatever their coefficients, so the degrees decide first; the zero polynomial, having no degree at all, is below every other polynomial. Polynomials of equal degree are decided by the highest-degree coefficient at which they differ, since that term eventually outgrows the sum of everything below it.
This is the order that makes the polynomials an ordered ring: it is unchanged by adding a
polynomial to both sides, and by multiplying both sides by a nonzero one. Restricted to the
constant polynomials it is the order on the Ts, so the embedding of a number as a
polynomial preserves comparisons. It is not a well-order, and no order compatible with
addition can be: $x > x - 1 > x - 2 > \ldots$ descends forever. A well-order on polynomials
needs to weigh a polynomial’s size against its degree, which this order does not do.
§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’ numbers of coefficients. Polynomials of different degrees are compared in constant time.
§Examples
use core::str::FromStr;
use malachite_base::unsigned_polynomial::UnsignedPolynomial;
// A higher degree wins however small its coefficients: x^2 eventually passes 1000000*x.
assert!(
UnsignedPolynomial::<u64>::from_str("x^2").unwrap()
> UnsignedPolynomial::<u64>::from_str("1000000*x").unwrap()
);
// At equal degrees the leading coefficient decides.
assert!(
UnsignedPolynomial::<u64>::from_str("2*x^2").unwrap()
> UnsignedPolynomial::<u64>::from_str("x^2+1000000").unwrap()
);
// When that ties, the next coefficient down does.
assert!(
UnsignedPolynomial::<u64>::from_str("x^2+3*x").unwrap()
> UnsignedPolynomial::<u64>::from_str("x^2+2*x+1000000").unwrap()
);
// The zero polynomial is below everything else.
assert!(
UnsignedPolynomial::<u64>::from_str("0").unwrap()
< UnsignedPolynomial::<u64>::from_str("1").unwrap()
);
// Constant polynomials compare as the numbers they are.
assert!(
UnsignedPolynomial::<u64>::from_str("123").unwrap()
> UnsignedPolynomial::<u64>::from_str("122").unwrap()
);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<T: PartialEq + PrimitiveUnsigned> PartialEq for UnsignedPolynomial<T>
impl<T: PartialEq + PrimitiveUnsigned> PartialEq for UnsignedPolynomial<T>
Source§impl<T: PrimitiveUnsigned> PartialEq<T> for UnsignedPolynomial<T>
impl<T: PrimitiveUnsigned> PartialEq<T> for UnsignedPolynomial<T>
Source§fn eq(&self, other: &T) -> bool
fn eq(&self, other: &T) -> bool
Determines whether an UnsignedPolynomial is equal to a value of its coefficient type.
The polynomial is equal to the value when it is the constant polynomial with that value, so
the zero polynomial is equal to 0 and nothing else, and no polynomial of positive degree is
equal to any value. In particular, p == 0 and p == 1 test whether p is the zero
polynomial or the polynomial 1, without building either.
§Worst-case complexity
Constant time and additional memory.
§Examples
See here.
Source§impl PartialEq<UnsignedPolynomial<u8>> for u8
impl PartialEq<UnsignedPolynomial<u8>> for u8
Source§fn eq(&self, other: &UnsignedPolynomial<u8>) -> bool
fn eq(&self, other: &UnsignedPolynomial<u8>) -> bool
Determines whether a value is equal to an UnsignedPolynomial with coefficients
of the value’s type.
The value is equal to the polynomial when the polynomial is the constant polynomial with that value, so 0 is equal to the zero polynomial.
§Worst-case complexity
Constant time and additional memory.
§Examples
See here.
Source§impl PartialEq<UnsignedPolynomial<u16>> for u16
impl PartialEq<UnsignedPolynomial<u16>> for u16
Source§fn eq(&self, other: &UnsignedPolynomial<u16>) -> bool
fn eq(&self, other: &UnsignedPolynomial<u16>) -> bool
Determines whether a value is equal to an UnsignedPolynomial with coefficients
of the value’s type.
The value is equal to the polynomial when the polynomial is the constant polynomial with that value, so 0 is equal to the zero polynomial.
§Worst-case complexity
Constant time and additional memory.
§Examples
See here.
Source§impl PartialEq<UnsignedPolynomial<u32>> for u32
impl PartialEq<UnsignedPolynomial<u32>> for u32
Source§fn eq(&self, other: &UnsignedPolynomial<u32>) -> bool
fn eq(&self, other: &UnsignedPolynomial<u32>) -> bool
Determines whether a value is equal to an UnsignedPolynomial with coefficients
of the value’s type.
The value is equal to the polynomial when the polynomial is the constant polynomial with that value, so 0 is equal to the zero polynomial.
§Worst-case complexity
Constant time and additional memory.
§Examples
See here.
Source§impl PartialEq<UnsignedPolynomial<u64>> for u64
impl PartialEq<UnsignedPolynomial<u64>> for u64
Source§fn eq(&self, other: &UnsignedPolynomial<u64>) -> bool
fn eq(&self, other: &UnsignedPolynomial<u64>) -> bool
Determines whether a value is equal to an UnsignedPolynomial with coefficients
of the value’s type.
The value is equal to the polynomial when the polynomial is the constant polynomial with that value, so 0 is equal to the zero polynomial.
§Worst-case complexity
Constant time and additional memory.
§Examples
See here.
Source§impl PartialEq<UnsignedPolynomial<u128>> for u128
impl PartialEq<UnsignedPolynomial<u128>> for u128
Source§fn eq(&self, other: &UnsignedPolynomial<u128>) -> bool
fn eq(&self, other: &UnsignedPolynomial<u128>) -> bool
Determines whether a value is equal to an UnsignedPolynomial with coefficients
of the value’s type.
The value is equal to the polynomial when the polynomial is the constant polynomial with that value, so 0 is equal to the zero polynomial.
§Worst-case complexity
Constant time and additional memory.
§Examples
See here.
Source§impl PartialEq<UnsignedPolynomial<usize>> for usize
impl PartialEq<UnsignedPolynomial<usize>> for usize
Source§fn eq(&self, other: &UnsignedPolynomial<usize>) -> bool
fn eq(&self, other: &UnsignedPolynomial<usize>) -> bool
Determines whether a value is equal to an UnsignedPolynomial with coefficients
of the value’s type.
The value is equal to the polynomial when the polynomial is the constant polynomial with that value, so 0 is equal to the zero polynomial.
§Worst-case complexity
Constant time and additional memory.
§Examples
See here.
Source§impl<T: PrimitiveUnsigned> PartialOrd for UnsignedPolynomial<T>
impl<T: PrimitiveUnsigned> PartialOrd for UnsignedPolynomial<T>
Source§fn partial_cmp(&self, other: &Self) -> Option<Ordering>
fn partial_cmp(&self, other: &Self) -> Option<Ordering>
Compares two UnsignedPolynomials.
See the documentation for the Ord implementation.
Source§impl<T: PrimitiveUnsigned> Polynomial for UnsignedPolynomial<T>
impl<T: PrimitiveUnsigned> Polynomial for UnsignedPolynomial<T>
Source§fn one() -> Self
fn one() -> Self
The constant polynomial 1.
This is a function rather than an associated constant, and
One is not implemented, because a polynomial holds its
coefficients in a Vec and a Vec with anything in it cannot be built at compile time.
The zero polynomial has no coefficients, so ZERO
is a constant after all.
§Worst-case complexity
Constant time and additional memory.
§Examples
use malachite_base::polynomial::Polynomial;
use malachite_base::unsigned_polynomial::UnsignedPolynomial;
assert_eq!(UnsignedPolynomial::<u64>::one().to_string(), "1");
assert_eq!(UnsignedPolynomial::<u64>::one().degree(), Some(0));Source§fn two() -> Self
fn two() -> Self
The constant polynomial 2.
This is a function rather than an associated constant, for the reason given by
one.
§Worst-case complexity
Constant time and additional memory.
§Examples
use malachite_base::polynomial::Polynomial;
use malachite_base::unsigned_polynomial::UnsignedPolynomial;
assert_eq!(UnsignedPolynomial::<u64>::two().to_string(), "2");
assert_eq!(UnsignedPolynomial::<u64>::two().degree(), Some(0));Source§fn x() -> Self
fn x() -> Self
The polynomial $x$, of degree 1 with leading coefficient 1 and constant term 0.
This is a function rather than an associated constant, for the reason given by
one.
§Worst-case complexity
Constant time and additional memory.
§Examples
use malachite_base::polynomial::Polynomial;
use malachite_base::unsigned_polynomial::UnsignedPolynomial;
assert_eq!(UnsignedPolynomial::<u64>::x().to_string(), "x");
assert_eq!(UnsignedPolynomial::<u64>::x().degree(), Some(1));Source§fn from_coefficients_asc(coefficients: Vec<T>) -> Self
fn from_coefficients_asc(coefficients: Vec<T>) -> Self
Converts a Vec of u64s to a UnsignedPolynomial.
The coefficients are in ascending order, so that the first is the constant term. Trailing
zeros are dropped, since a polynomial does not hold them; the Vec may therefore end with
as many as it likes, and the empty Vec is the zero polynomial.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is coefficients.len().
§Examples
use malachite_base::polynomial::Polynomial;
use malachite_base::unsigned_polynomial::UnsignedPolynomial;
use u64;
let p = UnsignedPolynomial::<u64>::from_coefficients_asc(vec![2, u64::from(3u32), 1]);
assert_eq!(p.to_string(), "x^2+3*x+2");
// The trailing zeros are not part of the polynomial.
let q = UnsignedPolynomial::<u64>::from_coefficients_asc(vec![2, u64::from(3u32), 1, 0, 0]);
assert_eq!(q.to_string(), "x^2+3*x+2");
assert_eq!(
UnsignedPolynomial::<u64>::from_coefficients_asc(vec![]).to_string(),
"0"
);Source§fn into_coefficients_asc(self) -> Vec<T>
fn into_coefficients_asc(self) -> Vec<T>
Converts a UnsignedPolynomial to a Vec of u64s, in ascending order.
The first is the constant term and the last is the leading coefficient, so the Vec 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::polynomial::Polynomial;
use malachite_base::strings::ToDebugString;
use malachite_base::unsigned_polynomial::UnsignedPolynomial;
let p = UnsignedPolynomial::<u64>::from_str("x^2+3*x+2").unwrap();
assert_eq!(p.into_coefficients_asc().to_debug_string(), "[2, 3, 1]");
assert_eq!(
UnsignedPolynomial::<u64>::ZERO
.into_coefficients_asc()
.to_debug_string(),
"[]"
);Source§fn degree(&self) -> Option<u64>
fn degree(&self) -> Option<u64>
Returns the degree of a UnsignedPolynomial.
The zero polynomial has no degree, and gives None. Every other polynomial’s degree is the
index of its leading coefficient, so that a nonzero constant has degree 0.
§Worst-case complexity
Constant time and additional memory.
§Examples
use core::str::FromStr;
use malachite_base::num::basic::traits::Zero;
use malachite_base::polynomial::Polynomial;
use malachite_base::unsigned_polynomial::UnsignedPolynomial;
assert_eq!(UnsignedPolynomial::<u64>::ZERO.degree(), None);
assert_eq!(
UnsignedPolynomial::<u64>::from_str("5").unwrap().degree(),
Some(0)
);
assert_eq!(
UnsignedPolynomial::<u64>::from_str("x").unwrap().degree(),
Some(1)
);
assert_eq!(
UnsignedPolynomial::<u64>::from_str("x^2+3*x+2")
.unwrap()
.degree(),
Some(2)
);Source§fn len(&self) -> u64
fn len(&self) -> u64
Returns the length of a UnsignedPolynomial: the number of coefficients it holds.
A polynomial holds no trailing zeros, so its length is one more than its
degree, and the zero polynomial, which has no degree, has length 0.
§Worst-case complexity
Constant time and additional memory.
§Examples
use core::str::FromStr;
use malachite_base::num::basic::traits::Zero;
use malachite_base::polynomial::Polynomial;
use malachite_base::unsigned_polynomial::UnsignedPolynomial;
assert_eq!(UnsignedPolynomial::<u64>::ZERO.len(), 0);
assert_eq!(UnsignedPolynomial::<u64>::from_str("5").unwrap().len(), 1);
assert_eq!(UnsignedPolynomial::<u64>::from_str("x").unwrap().len(), 2);
assert_eq!(
UnsignedPolynomial::<u64>::from_str("x^2+3*x+2")
.unwrap()
.len(),
3
);This is equivalent to nmod_poly_length from nmod_poly.h, FLINT 3.6.0.
Source§fn coefficient(&self, index: u64) -> T
fn coefficient(&self, index: u64) -> T
Returns one of a UnsignedPolynomial’s coefficients.
The index is the power of the variable the coefficient belongs to, so that index 0 gives the
constant term. An index past the degree gives zero, which is the coefficient a polynomial
has there. A u64 is Copy, so this hands back a value rather than a reference.
§Worst-case complexity
Constant time and additional memory.
§Examples
use core::str::FromStr;
use malachite_base::polynomial::Polynomial;
use malachite_base::unsigned_polynomial::UnsignedPolynomial;
let p = UnsignedPolynomial::<u64>::from_str("x^2+3*x+2").unwrap();
assert_eq!(p.coefficient(0), 2);
assert_eq!(p.coefficient(1), 3);
assert_eq!(p.coefficient(2), 1);
assert_eq!(p.coefficient(100), 0);Source§fn leading_coefficient(&self) -> T
fn leading_coefficient(&self) -> T
Returns a UnsignedPolynomial’s leading coefficient.
This is the coefficient of the highest power of the variable that the polynomial has one for. The zero polynomial has no such power, and gives zero, which is what every one of its coefficients is.
§Worst-case complexity
Constant time and additional memory.
§Examples
use core::str::FromStr;
use malachite_base::num::basic::traits::Zero;
use malachite_base::polynomial::Polynomial;
use malachite_base::unsigned_polynomial::UnsignedPolynomial;
let p = UnsignedPolynomial::<u64>::from_str("7*x^2+3*x+2").unwrap();
assert_eq!(p.leading_coefficient(), 7);
assert_eq!(UnsignedPolynomial::<u64>::ZERO.leading_coefficient(), 0);Source§fn is_monic(&self) -> bool
fn is_monic(&self) -> bool
Determines whether an UnsignedPolynomial is monic: nonzero, with leading coefficient 1.
The zero polynomial is not monic.
§Worst-case complexity
Constant time and additional memory.
§Examples
use core::str::FromStr;
use malachite_base::num::basic::traits::Zero;
use malachite_base::polynomial::Polynomial;
use malachite_base::unsigned_polynomial::UnsignedPolynomial;
assert!(
UnsignedPolynomial::<u8>::from_str("x^2+3*x+2")
.unwrap()
.is_monic()
);
assert!(
!UnsignedPolynomial::<u8>::from_str("2*x^2+3")
.unwrap()
.is_monic()
);
assert!(!UnsignedPolynomial::<u8>::ZERO.is_monic());Source§fn mutate_coefficient<F: FnOnce(&mut T) -> U, U>(
&mut self,
index: u64,
f: F,
) -> U
fn mutate_coefficient<F: FnOnce(&mut T) -> U, U>( &mut self, index: u64, f: F, ) -> U
Mutates one of a UnsignedPolynomial’s coefficients using a provided closure, and then
returns whatever the closure returns.
The index is the power of the variable the coefficient belongs to. An index past the degree is not an error: the polynomial grows to reach it, and the closure is handed the zero that was there all along.
After the closure executes, this function drops whatever trailing zero coefficients the polynomial has acquired, so that a coefficient set to zero, or a growth that came to nothing, leaves no trace.
§Worst-case complexity
$T(n, m) = O(n + m)$
$M(n, m) = O(n + m)$
where $T$ is time, $M$ is additional memory, $n$ is index, and $m$ is the cost of the
closure.
§Panics
Panics if index does not fit in a usize, which cannot happen on a target with 64-bit
pointers, or if growing to reach index would exceed the maximum length of a Vec.
§Examples
use core::str::FromStr;
use malachite_base::polynomial::Polynomial;
use malachite_base::unsigned_polynomial::UnsignedPolynomial;
use u64;
let mut p = UnsignedPolynomial::<u64>::from_str("x^2+3*x+2").unwrap();
let ret = p.mutate_coefficient(1, |c| {
*c += 1;
true
});
assert_eq!(p.to_string(), "x^2+4*x+2");
assert_eq!(ret, true);
// The polynomial grows to reach a coefficient it did not have.
p.mutate_coefficient(5, |c| *c += 1);
assert_eq!(p.to_string(), "x^5+x^2+4*x+2");
// Clearing the leading coefficient lowers the degree.
p.mutate_coefficient(5, |c| *c = 0);
assert_eq!(p.to_string(), "x^2+4*x+2");Source§fn zero_coefficients(&mut self, start: u64, end: u64)
fn zero_coefficients(&mut self, start: u64, end: u64)
Sets the coefficients of a UnsignedPolynomial of $x^i$ for $i$ in start..end to zero.
Indices past the degree are allowed; the coefficients there are zero already. Zeroing the leading coefficient lowers the degree, to that of the highest nonzero coefficient that remains.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is self.len().
§Panics
Panics if start > end.
§Examples
use core::str::FromStr;
use malachite_base::polynomial::Polynomial;
use malachite_base::unsigned_polynomial::UnsignedPolynomial;
let mut p;
p = UnsignedPolynomial::<u64>::from_str("x^4+x^3+x^2+x+1").unwrap();
p.zero_coefficients(1, 3);
assert_eq!(p.to_string(), "x^4+x^3+1");
p = UnsignedPolynomial::<u64>::from_str("x^4+x^3+x^2+x+1").unwrap();
p.zero_coefficients(2, 10);
assert_eq!(p.to_string(), "x+1");
p = UnsignedPolynomial::<u64>::from_str("x^4+x^3+x^2+x+1").unwrap();
p.zero_coefficients(5, 10);
assert_eq!(p.to_string(), "x^4+x^3+x^2+x+1");FLINT has no counterpart for nmod_poly; this is the counterpart of fmpz_poly_zero_coeffs
from fmpz_poly/zero_coeffs.c, FLINT 3.6.0.
Source§fn truncate(&self, len: u64) -> Self
fn truncate(&self, len: u64) -> Self
Truncates a UnsignedPolynomial to its first len coefficients, taking the polynomial by
reference and returning the result.
The result is the polynomial reduced modulo $x^{\mathrm{len}}$: every term of degree len
or more is dropped, and then any zeros left at the top go too, so the result may have fewer
than len coefficients. A polynomial with at most len coefficients is returned unchanged.
$$ f(p, n) = p \bmod x^n. $$
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is min(len, self.len()).
§Examples
use core::str::FromStr;
use malachite_base::polynomial::Polynomial;
use malachite_base::unsigned_polynomial::UnsignedPolynomial;
assert_eq!(
UnsignedPolynomial::<u64>::from_str("x^3+2*x^2+3*x+4")
.unwrap()
.truncate(2)
.to_string(),
"3*x+4"
);
// A polynomial with no more than len coefficients is unchanged.
assert_eq!(
UnsignedPolynomial::<u64>::from_str("x^3+2*x^2+3*x+4")
.unwrap()
.truncate(10)
.to_string(),
"x^3+2*x^2+3*x+4"
);
// Truncating can uncover zeros, which are dropped too.
assert_eq!(
UnsignedPolynomial::<u64>::from_str("x^3+3*x+4")
.unwrap()
.truncate(3)
.to_string(),
"3*x+4"
);
assert_eq!(
UnsignedPolynomial::<u64>::from_str("x^3+2*x^2+3*x+4")
.unwrap()
.truncate(0)
.to_string(),
"0"
);This is equivalent to nmod_poly_set_trunc from nmod_poly/set_trunc.c, FLINT 3.6.0.
Source§fn truncate_assign(&mut self, len: u64)
fn truncate_assign(&mut self, len: u64)
Truncates a UnsignedPolynomial to its first len coefficients, in place.
See truncate for what the result is.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is self.len().
§Examples
use core::str::FromStr;
use malachite_base::polynomial::Polynomial;
use malachite_base::unsigned_polynomial::UnsignedPolynomial;
let mut p;
p = UnsignedPolynomial::<u64>::from_str("x^3+2*x^2+3*x+4").unwrap();
p.truncate_assign(2);
assert_eq!(p.to_string(), "3*x+4");
// A polynomial with no more than len coefficients is unchanged.
p = UnsignedPolynomial::<u64>::from_str("x^3+2*x^2+3*x+4").unwrap();
p.truncate_assign(10);
assert_eq!(p.to_string(), "x^3+2*x^2+3*x+4");
// Truncating can uncover zeros, which are dropped too.
p = UnsignedPolynomial::<u64>::from_str("x^3+3*x+4").unwrap();
p.truncate_assign(3);
assert_eq!(p.to_string(), "3*x+4");
p = UnsignedPolynomial::<u64>::from_str("x^3+2*x^2+3*x+4").unwrap();
p.truncate_assign(0);
assert_eq!(p.to_string(), "0");This is equivalent to nmod_poly_truncate from nmod_poly.h, FLINT 3.6.0.
Source§fn reverse(&self, len: u64) -> Self
fn reverse(&self, len: u64) -> Self
Reverses the coefficients of a UnsignedPolynomial, considered as having length len,
taking the polynomial by reference.
The polynomial is first truncated, or padded with zeros, to exactly len coefficients, and
those are then reversed, so that the result’s coefficient of $x^i$ is the polynomial’s
coefficient of $x^{\mathrm{len} - 1 - i}$:
$$ f(p, n) = x^{n-1} \left( p \bmod x^n \right)!\left(\frac{1}{x}\right). $$
A polynomial holds no trailing zeros, so the result may have fewer than len coefficients:
it does whenever the polynomial’s constant term is zero.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is len.
§Panics
Panics if len exceeds self.len() and does not fit in a usize, which cannot happen on
a target with 64-bit pointers.
§Examples
use core::str::FromStr;
use malachite_base::polynomial::Polynomial;
use malachite_base::unsigned_polynomial::UnsignedPolynomial;
assert_eq!(
UnsignedPolynomial::<u64>::from_str("x^2+2*x+3")
.unwrap()
.reverse(3)
.to_string(),
"3*x^2+2*x+1"
);
// Padding to length 5 adds low zeros.
assert_eq!(
UnsignedPolynomial::<u64>::from_str("x^2+2*x+3")
.unwrap()
.reverse(5)
.to_string(),
"3*x^4+2*x^3+x^2"
);
// Truncating to length 2 drops x^2 first.
assert_eq!(
UnsignedPolynomial::<u64>::from_str("x^2+2*x+3")
.unwrap()
.reverse(2)
.to_string(),
"3*x+2"
);
// A zero constant term becomes a trailing zero, and is dropped.
assert_eq!(
UnsignedPolynomial::<u64>::from_str("x^2+2*x")
.unwrap()
.reverse(3)
.to_string(),
"2*x+1"
);This is equivalent to nmod_poly_reverse from nmod_poly/reverse.c, FLINT 3.6.0.
Source§fn reverse_assign(&mut self, len: u64)
fn reverse_assign(&mut self, len: u64)
Reverses the coefficients of a UnsignedPolynomial, considered as having length len, in
place.
See reverse for what the result is.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is the larger of len and
self.len().
§Panics
Panics if len exceeds self.len() and does not fit in a usize, which cannot happen on
a target with 64-bit pointers.
§Examples
use core::str::FromStr;
use malachite_base::polynomial::Polynomial;
use malachite_base::unsigned_polynomial::UnsignedPolynomial;
let mut p;
p = UnsignedPolynomial::<u64>::from_str("x^2+2*x+3").unwrap();
p.reverse_assign(3);
assert_eq!(p.to_string(), "3*x^2+2*x+1");
// Padding to length 5 adds low zeros.
p = UnsignedPolynomial::<u64>::from_str("x^2+2*x+3").unwrap();
p.reverse_assign(5);
assert_eq!(p.to_string(), "3*x^4+2*x^3+x^2");
// Truncating to length 2 drops x^2 first.
p = UnsignedPolynomial::<u64>::from_str("x^2+2*x+3").unwrap();
p.reverse_assign(2);
assert_eq!(p.to_string(), "3*x+2");
// A zero constant term becomes a trailing zero, and is dropped.
p = UnsignedPolynomial::<u64>::from_str("x^2+2*x").unwrap();
p.reverse_assign(3);
assert_eq!(p.to_string(), "2*x+1");This is equivalent to nmod_poly_reverse from nmod_poly/reverse.c, FLINT 3.6.0.
Source§fn to_string_with<S: VarScheme + ?Sized>(&self, var: Var<'_, S>) -> String
fn to_string_with<S: VarScheme + ?Sized>(&self, var: Var<'_, S>) -> String
Converts a UnsignedPolynomial to a String, naming its variable with any
VarScheme.
The syntax is the one Display writes, which that implementation
describes; the only difference is that the variable is whichever one is handed in rather
than x.
§Worst-case complexity
$T(n) = O(n \log n \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, and $n$ is the sum of the bits of the coefficients.
§Panics
Panics if var’s index is not less than its scheme’s capacity.
§Examples
use core::str::FromStr;
use malachite_base::polynomial::Polynomial;
use malachite_base::unsigned_polynomial::UnsignedPolynomial;
use malachite_base::vars::VarScheme;
use malachite_base::vars::greek::GreekVars;
use malachite_base::vars::indexed::IndexedVars;
use malachite_base::vars::list::ListVars;
let p = UnsignedPolynomial::<u64>::from_str("x^2+3*x+2").unwrap();
assert_eq!(p.to_string_with(GreekVars.var(0)), "α^2+3*α+2");
assert_eq!(p.to_string_with(IndexedVars.var(7)), "x₇^2+3*x₇+2");
let vars = ListVars::new(["t"]);
assert_eq!(p.to_string_with(vars.var(0)), "t^2+3*t+2");Source§fn to_latex_string_with<S: VarScheme + ?Sized>(&self, var: Var<'_, S>) -> String
fn to_latex_string_with<S: VarScheme + ?Sized>(&self, var: Var<'_, S>) -> String
Converts a UnsignedPolynomial to a LaTeX math-mode fragment, naming its variable with
any VarScheme.
The fragment is the one ToLatex writes, which that
implementation describes; the only difference is that the variable is whichever one is
handed in rather than x.
§Worst-case complexity
$T(n) = O(n \log n \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, and $n$ is the sum of the bits of the coefficients.
§Panics
Panics if var’s index is not less than its scheme’s capacity.
§Examples
use core::str::FromStr;
use malachite_base::polynomial::Polynomial;
use malachite_base::unsigned_polynomial::UnsignedPolynomial;
use malachite_base::vars::VarScheme;
use malachite_base::vars::greek::GreekVars;
use malachite_base::vars::indexed::IndexedVars;
let p = UnsignedPolynomial::<u64>::from_str("x^2+3*x+2").unwrap();
assert_eq!(
p.to_latex_string_with(GreekVars.var(0)),
r"\alpha^2+3\alpha+2"
);
assert_eq!(p.to_latex_string_with(IndexedVars.var(7)), "x_7^2+3x_7+2");The polynomial is x^2+3*x+2 in each row; only its variable differs.
| variable | fragment | renders as |
|---|---|---|
α | \alpha^2+3\alpha+2 | $\alpha^2+3\alpha+2$ |
x₇ | x_7^2+3x_7+2 | $x_7^2+3x_7+2$ |
Source§fn to_typst_string_with<S: VarScheme + ?Sized>(&self, var: Var<'_, S>) -> String
fn to_typst_string_with<S: VarScheme + ?Sized>(&self, var: Var<'_, S>) -> String
Converts a UnsignedPolynomial to a Typst math-mode fragment, naming its variable with
any VarScheme.
The fragment is the one ToTypst writes, which that
implementation describes; the only difference is that the variable is whichever one is
handed in rather than x.
§Worst-case complexity
$T(n) = O(n \log n \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, and $n$ is the sum of the bits of the coefficients.
§Panics
Panics if var’s index is not less than its scheme’s capacity.
§Examples
use core::str::FromStr;
use malachite_base::polynomial::Polynomial;
use malachite_base::unsigned_polynomial::UnsignedPolynomial;
use malachite_base::vars::VarScheme;
use malachite_base::vars::greek::GreekVars;
use malachite_base::vars::indexed::IndexedVars;
let p = UnsignedPolynomial::<u64>::from_str("x^2+3*x+2").unwrap();
assert_eq!(p.to_typst_string_with(GreekVars.var(0)), "α^2+3α+2");
assert_eq!(p.to_typst_string_with(IndexedVars.var(7)), "x_7^2+3x_7+2");The polynomial is x^2+3*x+2 in each row; only its variable differs.
| variable | fragment |
|---|---|
α | α^2+3α+2 |
x₇ | x_7^2+3x_7+2 |
Source§fn from_string_with<S: VarScheme + ?Sized>(
var: Var<'_, S>,
s: &str,
) -> Option<Self>
fn from_string_with<S: VarScheme + ?Sized>( var: Var<'_, S>, s: &str, ) -> Option<Self>
Converts a string to a UnsignedPolynomial, with its variable named by any VarScheme.
The syntax is the one FromStr reads, which that implementation
describes; the only difference is that the variable is whichever one is handed in rather
than x.
§Worst-case complexity
$T(n) = O(n (\log n)^2 \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, and $n$ is s.len().
§Examples
use malachite_base::polynomial::Polynomial;
use malachite_base::unsigned_polynomial::UnsignedPolynomial;
use malachite_base::vars::VarScheme;
use malachite_base::vars::greek::GreekVars;
use malachite_base::vars::list::ListVars;
let p = UnsignedPolynomial::<u64>::from_string_with(GreekVars.var(0), "α^2+3*α+2").unwrap();
assert_eq!(p.to_string(), "x^2+3*x+2");
let vars = ListVars::new(["t"]);
assert_eq!(
UnsignedPolynomial::<u64>::from_string_with(vars.var(0), "t^2+1")
.unwrap()
.to_string(),
"x^2+1"
);
// The variable must be the one that was asked for.
assert!(UnsignedPolynomial::<u64>::from_string_with(GreekVars.var(0), "β^2").is_none());Source§type Coefficient = T
type Coefficient = T
Source§type CoefficientOutput<'a> = T
where
Self: 'a
type CoefficientOutput<'a> = T where Self: 'a
Source§impl<T: PrimitiveUnsigned> PrimitivePart for UnsignedPolynomial<T>
impl<T: PrimitiveUnsigned> PrimitivePart for UnsignedPolynomial<T>
Source§fn primitive_part(self) -> Self
fn primitive_part(self) -> Self
Computes the primitive part of an UnsignedPolynomial, the polynomial divided by its
content, taking the polynomial by value.
The coefficients are non-negative, so no sign needs normalizing and $p = \operatorname{cont}(p) \operatorname{pp}(p)$. The primitive part of the zero polynomial is zero.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is self.len().
§Examples
use core::str::FromStr;
use malachite_base::num::basic::traits::Zero;
use malachite_base::polynomial::PrimitivePart;
use malachite_base::unsigned_polynomial::UnsignedPolynomial;
let p = UnsignedPolynomial::<u8>::from_str("6*x^2+4*x+10").unwrap();
assert_eq!(p.clone().primitive_part().to_string(), "3*x^2+2*x+5");
assert_eq!(
UnsignedPolynomial::<u8>::ZERO.primitive_part(),
UnsignedPolynomial::<u8>::ZERO
);This is equivalent to fmpz_poly_primitive_part from fmpz_poly/primitive_part.c, FLINT
3.6.0.
Source§type Output = UnsignedPolynomial<T>
type Output = UnsignedPolynomial<T>
Source§impl<T: PrimitiveUnsigned> PrimitivePart for &UnsignedPolynomial<T>
impl<T: PrimitiveUnsigned> PrimitivePart for &UnsignedPolynomial<T>
Source§fn primitive_part(self) -> UnsignedPolynomial<T>
fn primitive_part(self) -> UnsignedPolynomial<T>
Computes the primitive part of an UnsignedPolynomial, the polynomial divided by its
content, taking the polynomial by reference.
The coefficients are non-negative, so no sign needs normalizing and $p = \operatorname{cont}(p) \operatorname{pp}(p)$. The primitive part of the zero polynomial is zero.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is self.len().
§Examples
use core::str::FromStr;
use malachite_base::num::basic::traits::Zero;
use malachite_base::polynomial::PrimitivePart;
use malachite_base::unsigned_polynomial::UnsignedPolynomial;
let p = UnsignedPolynomial::<u8>::from_str("6*x^2+4*x+10").unwrap();
assert_eq!((&p).primitive_part().to_string(), "3*x^2+2*x+5");
assert_eq!(
(&UnsignedPolynomial::<u8>::ZERO).primitive_part(),
UnsignedPolynomial::<u8>::ZERO
);This is equivalent to fmpz_poly_primitive_part from fmpz_poly/primitive_part.c, FLINT
3.6.0.
Source§type Output = UnsignedPolynomial<T>
type Output = UnsignedPolynomial<T>
Source§impl<T: PrimitiveUnsigned> PrimitivePartAssign for UnsignedPolynomial<T>
impl<T: PrimitiveUnsigned> PrimitivePartAssign for UnsignedPolynomial<T>
Source§fn primitive_part_assign(&mut self)
fn primitive_part_assign(&mut self)
Replaces an UnsignedPolynomial with its primitive part, the polynomial divided by its
content.
See primitive_part.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is self.len().
§Examples
use core::str::FromStr;
use malachite_base::polynomial::PrimitivePartAssign;
use malachite_base::unsigned_polynomial::UnsignedPolynomial;
let mut p = UnsignedPolynomial::<u8>::from_str("6*x^2+4*x+10").unwrap();
p.primitive_part_assign();
assert_eq!(p.to_string(), "3*x^2+2*x+5");Source§impl<T: PrimitiveUnsigned> Rem<T> for UnsignedPolynomial<T>
impl<T: PrimitiveUnsigned> Rem<T> for UnsignedPolynomial<T>
Source§fn rem(self, m: T) -> Self
fn rem(self, m: T) -> Self
Divides every coefficient of a UnsignedPolynomial by a u64, keeping the remainders,
taking the polynomial by value.
$p \% m$ is the polynomial whose $i$th coefficient is $p_i \% m$, and this is the
remainder of dividing $p$ by the constant polynomial $m$ — under the convention that
applies over the integers, where a remainder is bounded coefficient by coefficient rather
than by degree. Over a field the answer would be different: there a remainder must have
lower degree than the divisor, and a nonzero constant has degree 0, so dividing by one
leaves a remainder of 0. The Ts are not a field, division by $m$ is not exact, and
bounding the remainder’s coefficients is what is left.
There is a quotient to go with it: the polynomial whose $i$th coefficient is $p_i / m$, for which $p = mq + r$ holds exactly.
The result is reduced modulo $m$, which is to say that
mod_is_reduced returns
true for it.
Reducing can lower the degree, and can even give the zero polynomial: a leading coefficient that is a multiple of $m$ becomes zero, and a polynomial does not hold trailing zero coefficients. So $4x^2 + 3$ modulo $4$ is the constant $3$, not a quadratic with a zero leading coefficient.
$$ f(p, m) = q, \quad \text{where} \quad q_i = p_i - m \left \lfloor \frac{p_i}{m} \right \rfloor. $$
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is the number of coefficients.
§Panics
Panics if m is 0.
§Examples
use core::str::FromStr;
use malachite_base::unsigned_polynomial::UnsignedPolynomial;
// Every coefficient is taken modulo 3.
assert_eq!(
(UnsignedPolynomial::<u64>::from_str("x^2+4*x+5").unwrap() % 3).to_string(),
"x^2+x+2"
);
// Reducing the leading coefficient to zero lowers the degree.
assert_eq!(
(UnsignedPolynomial::<u64>::from_str("4*x^2+3").unwrap() % 4).to_string(),
"3"
);
// Modulo 1 every coefficient is zero, so the whole polynomial is.
assert_eq!(
(UnsignedPolynomial::<u64>::from_str("x^2+4*x+5").unwrap() % 1).to_string(),
"0"
);This is equivalent to fmpz_poly_scalar_mod_fmpz from fmpz_poly/scalar_mod_fmpz.c, FLINT
3.6.0, for a polynomial whose coefficients are all nonnegative.
Source§type Output = UnsignedPolynomial<T>
type Output = UnsignedPolynomial<T>
% operator.Source§impl<T: PrimitiveUnsigned> Rem<T> for &UnsignedPolynomial<T>
impl<T: PrimitiveUnsigned> Rem<T> for &UnsignedPolynomial<T>
Source§fn rem(self, m: T) -> UnsignedPolynomial<T>
fn rem(self, m: T) -> UnsignedPolynomial<T>
Divides every coefficient of a UnsignedPolynomial by a u64, keeping the remainders,
taking the polynomial by reference.
See the documentation for the Rem implementation on UnsignedPolynomial for details,
including how reducing can lower the degree.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(n)$
where $T$ is time, $M$ is additional memory, and $n$ is the number of coefficients.
§Panics
Panics if m is 0.
§Examples
use core::str::FromStr;
use malachite_base::unsigned_polynomial::UnsignedPolynomial;
let p = UnsignedPolynomial::<u64>::from_str("4*x^2+3").unwrap();
assert_eq!((&p % 4).to_string(), "3");
// The polynomial is left alone.
assert_eq!(p.to_string(), "4*x^2+3");Source§type Output = UnsignedPolynomial<T>
type Output = UnsignedPolynomial<T>
% operator.Source§impl<T: PrimitiveUnsigned> RemAssign<T> for UnsignedPolynomial<T>
impl<T: PrimitiveUnsigned> RemAssign<T> for UnsignedPolynomial<T>
Source§fn rem_assign(&mut self, m: T)
fn rem_assign(&mut self, m: T)
Divides every coefficient of a UnsignedPolynomial by a u64, replacing the polynomial
by the one whose coefficients are the remainders.
See the documentation for the Rem implementation on UnsignedPolynomial for details,
including how reducing can lower the degree.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is the number of coefficients.
§Panics
Panics if m is 0.
§Examples
use core::str::FromStr;
use malachite_base::unsigned_polynomial::UnsignedPolynomial;
let mut p = UnsignedPolynomial::<u64>::from_str("x^2+4*x+5").unwrap();
p %= 3;
assert_eq!(p.to_string(), "x^2+x+2");
let mut p = UnsignedPolynomial::<u64>::from_str("4*x^2+3").unwrap();
p %= 4;
assert_eq!(p.to_string(), "3");impl<T: PartialEq + PrimitiveUnsigned> StructuralPartialEq for UnsignedPolynomial<T>
Source§impl<T: PrimitiveUnsigned> ToLatex for UnsignedPolynomial<T>
impl<T: PrimitiveUnsigned> ToLatex for UnsignedPolynomial<T>
Source§fn fmt_latex(&self, f: &mut Formatter<'_>) -> Result
fn fmt_latex(&self, f: &mut Formatter<'_>) -> Result
Writes a UnsignedPolynomial as a LaTeX math-mode fragment.
The variable is called x.
to_latex_string_with is the way to
call it something else.
The fragment is the polynomial as it would be written by hand: the terms in order of
decreasing degree, joined with +, each one its coefficient followed by its variable and
then a superscript. A coefficient of 1 is left off, and so is an exponent of 1; the constant
term is its coefficient alone, and the zero polynomial, which has no terms, is 0. Nothing
stands between a coefficient and its variable, since a number written against a variable can
only be multiplying it.
A superscript is braced only when the exponent has more than one digit, since a superscript of one character needs nothing to hold it together.
§Worst-case complexity
$T(n) = O(n \log n \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, and $n$ is the sum of the bits of the coefficients.
§Examples
use core::str::FromStr;
use malachite_base::strings::latex::ToLatex;
use malachite_base::unsigned_polynomial::UnsignedPolynomial;
assert_eq!(
UnsignedPolynomial::<u64>::from_str("x^2+3*x+2")
.unwrap()
.to_latex_string(),
"x^2+3x+2"
);
assert_eq!(
UnsignedPolynomial::<u64>::from_str("0")
.unwrap()
.to_latex_string(),
"0"
);
assert_eq!(
UnsignedPolynomial::<u64>::from_str("5")
.unwrap()
.to_latex_string(),
"5"
);
assert_eq!(
UnsignedPolynomial::<u64>::from_str("x")
.unwrap()
.to_latex_string(),
"x"
);
assert_eq!(
UnsignedPolynomial::<u64>::from_str("2*x^3")
.unwrap()
.to_latex_string(),
"2x^3"
);
// An exponent of more than one digit is braced.
assert_eq!(
UnsignedPolynomial::<u64>::from_str("x^12+x^2")
.unwrap()
.to_latex_string(),
"x^{12}+x^2"
);The value column holds each polynomial as Display writes it.
| value | fragment | renders as |
|---|---|---|
x^2+3*x+2 | x^2+3x+2 | $x^2+3x+2$ |
0 | 0 | $0$ |
5 | 5 | $5$ |
x | x | $x$ |
2*x^3 | 2x^3 | $2x^3$ |
x^12+x^2 | x^{12}+x^2 | $x^{12}+x^2$ |
Source§impl<T: PrimitiveUnsigned> ToTypst for UnsignedPolynomial<T>
impl<T: PrimitiveUnsigned> ToTypst for UnsignedPolynomial<T>
Source§fn fmt_typst(&self, f: &mut Formatter<'_>) -> Result
fn fmt_typst(&self, f: &mut Formatter<'_>) -> Result
Writes a UnsignedPolynomial as a Typst math-mode fragment.
The variable is called x.
to_typst_string_with is the way to
call it something else.
The fragment is the polynomial as it would be written by hand: the terms in order of
decreasing degree, joined with +, each one its coefficient followed by its variable and
then a superscript. A coefficient of 1 is left off, and so is an exponent of 1; the constant
term is its coefficient alone, and the zero polynomial, which has no terms, is 0. Nothing
stands between a coefficient and its variable, since a number written against a variable can
only be multiplying it, and a digit ends the run of letters that Typst would otherwise read
as one name.
A superscript is parenthesized only when the exponent has more than one digit, since a superscript of one character needs nothing to hold it together.
§Worst-case complexity
$T(n) = O(n \log n \log\log n)$
$M(n) = O(n \log n)$
where $T$ is time, $M$ is additional memory, and $n$ is the sum of the bits of the coefficients.
§Examples
use core::str::FromStr;
use malachite_base::strings::typst::ToTypst;
use malachite_base::unsigned_polynomial::UnsignedPolynomial;
assert_eq!(
UnsignedPolynomial::<u64>::from_str("x^2+3*x+2")
.unwrap()
.to_typst_string(),
"x^2+3x+2"
);
assert_eq!(
UnsignedPolynomial::<u64>::from_str("0")
.unwrap()
.to_typst_string(),
"0"
);
assert_eq!(
UnsignedPolynomial::<u64>::from_str("5")
.unwrap()
.to_typst_string(),
"5"
);
assert_eq!(
UnsignedPolynomial::<u64>::from_str("x")
.unwrap()
.to_typst_string(),
"x"
);
assert_eq!(
UnsignedPolynomial::<u64>::from_str("2*x^3")
.unwrap()
.to_typst_string(),
"2x^3"
);
// An exponent of more than one digit is parenthesized.
assert_eq!(
UnsignedPolynomial::<u64>::from_str("x^12+x^2")
.unwrap()
.to_typst_string(),
"x^(12)+x^2"
);The value column holds each polynomial as Display writes it.
| value | fragment |
|---|---|
x^2+3*x+2 | x^2+3x+2 |
0 | 0 |
5 | 5 |
x | x |
2*x^3 | 2x^3 |
x^12+x^2 | x^(12)+x^2 |
Source§impl<T: PrimitiveUnsigned> Zero for UnsignedPolynomial<T>
The constant 0.
impl<T: PrimitiveUnsigned> Zero for UnsignedPolynomial<T>
The constant 0.
Auto Trait Implementations§
impl<T> Freeze for UnsignedPolynomial<T>
impl<T> RefUnwindSafe for UnsignedPolynomial<T>
impl<T> Send for UnsignedPolynomial<T>
impl<T> Sync for UnsignedPolynomial<T>
impl<T> Unpin for UnsignedPolynomial<T>
impl<T> UnsafeUnpin for UnsignedPolynomial<T>
impl<T> UnwindSafe for UnsignedPolynomial<T>
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