Skip to main content

IntegerPolynomial

Struct IntegerPolynomial 

Source
pub struct IntegerPolynomial { /* private fields */ }
Expand description

A polynomial in one variable whose coefficients are 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 Integers is one: from_coefficients_asc is how a Vec becomes one.

Implementations§

Source§

impl IntegerPolynomial

Source

pub fn negative_one() -> Self

The constant polynomial -1.

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_nz::integer_polynomial::IntegerPolynomial;

assert_eq!(IntegerPolynomial::negative_one().to_string(), "-1");
assert_eq!(IntegerPolynomial::negative_one().degree(), Some(0));
Source

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

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

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

§Worst-case complexity

Constant time and additional memory.

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

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

Trait Implementations§

Source§

impl Add for IntegerPolynomial

Source§

fn add(self, other: Self) -> Self

Adds two IntegerPolynomials, taking both by value.

$$ f(p, q) = p + q. $$

When the two polynomials have the same degree, their leading coefficients can cancel, 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 total number of bits of the coefficients of both polynomials.

§Examples
use core::str::FromStr;
use malachite_nz::integer_polynomial::IntegerPolynomial;

assert_eq!(
    (IntegerPolynomial::from_str("x^2-3*x+2").unwrap()
        + IntegerPolynomial::from_str("2*x+5").unwrap())
    .to_string(),
    "x^2-x+7"
);
// The leading coefficients cancel, and so does the next.
assert_eq!(
    (IntegerPolynomial::from_str("-x^2+3*x+1").unwrap()
        + IntegerPolynomial::from_str("x^2-3*x+2").unwrap())
    .to_string(),
    "3"
);

This is equivalent to fmpz_poly_add from fmpz_poly/add.c, FLINT 3.6.0.

Source§

type Output = IntegerPolynomial

The resulting type after applying the + operator.
Source§

impl Add<&IntegerPolynomial> for IntegerPolynomial

Source§

fn add(self, other: &Self) -> Self

Adds two IntegerPolynomials, taking the first by value and the second by reference.

$$ f(p, q) = p + q. $$

When the two polynomials have the same degree, their leading coefficients can cancel, 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 total number of bits of the coefficients of both polynomials.

§Examples
use core::str::FromStr;
use malachite_nz::integer_polynomial::IntegerPolynomial;

assert_eq!(
    (IntegerPolynomial::from_str("x^2-3*x+2").unwrap()
        + &IntegerPolynomial::from_str("2*x+5").unwrap())
        .to_string(),
    "x^2-x+7"
);
// The leading coefficients cancel, and so does the next.
assert_eq!(
    (IntegerPolynomial::from_str("-x^2+3*x+1").unwrap()
        + &IntegerPolynomial::from_str("x^2-3*x+2").unwrap())
        .to_string(),
    "3"
);

This is equivalent to fmpz_poly_add from fmpz_poly/add.c, FLINT 3.6.0.

Source§

type Output = IntegerPolynomial

The resulting type after applying the + operator.
Source§

impl Add<&IntegerPolynomial> for &IntegerPolynomial

Source§

fn add(self, other: &IntegerPolynomial) -> IntegerPolynomial

Adds two IntegerPolynomials, taking both by reference.

$$ f(p, q) = p + q. $$

When the two polynomials have the same degree, their leading coefficients can cancel, 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 total number of bits of the coefficients of both polynomials.

§Examples
use core::str::FromStr;
use malachite_nz::integer_polynomial::IntegerPolynomial;

assert_eq!(
    (&IntegerPolynomial::from_str("x^2-3*x+2").unwrap()
        + &IntegerPolynomial::from_str("2*x+5").unwrap())
        .to_string(),
    "x^2-x+7"
);
// The leading coefficients cancel, and so does the next.
assert_eq!(
    (&IntegerPolynomial::from_str("-x^2+3*x+1").unwrap()
        + &IntegerPolynomial::from_str("x^2-3*x+2").unwrap())
        .to_string(),
    "3"
);

This is equivalent to fmpz_poly_add from fmpz_poly/add.c, FLINT 3.6.0.

Source§

type Output = IntegerPolynomial

The resulting type after applying the + operator.
Source§

impl Add<IntegerPolynomial> for &IntegerPolynomial

Source§

fn add(self, other: IntegerPolynomial) -> IntegerPolynomial

Adds two IntegerPolynomials, taking the first by reference and the second by value.

$$ f(p, q) = p + q. $$

When the two polynomials have the same degree, their leading coefficients can cancel, 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 total number of bits of the coefficients of both polynomials.

§Examples
use core::str::FromStr;
use malachite_nz::integer_polynomial::IntegerPolynomial;

assert_eq!(
    (&IntegerPolynomial::from_str("x^2-3*x+2").unwrap()
        + IntegerPolynomial::from_str("2*x+5").unwrap())
    .to_string(),
    "x^2-x+7"
);
// The leading coefficients cancel, and so does the next.
assert_eq!(
    (&IntegerPolynomial::from_str("-x^2+3*x+1").unwrap()
        + IntegerPolynomial::from_str("x^2-3*x+2").unwrap())
    .to_string(),
    "3"
);

This is equivalent to fmpz_poly_add from fmpz_poly/add.c, FLINT 3.6.0.

Source§

type Output = IntegerPolynomial

The resulting type after applying the + operator.
Source§

impl AddAssign for IntegerPolynomial

Source§

fn add_assign(&mut self, other: Self)

Adds another IntegerPolynomial to an IntegerPolynomial in place, taking the right-hand side by value.

$$ p \gets p + q. $$

§Worst-case complexity

$T(n) = O(n)$

$M(n) = O(n)$

where $T$ is time, $M$ is additional memory, and $n$ is the total number of bits of the coefficients of both polynomials.

§Examples
use core::str::FromStr;
use malachite_nz::integer_polynomial::IntegerPolynomial;

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

impl AddAssign<&IntegerPolynomial> for IntegerPolynomial

Source§

fn add_assign(&mut self, other: &Self)

Adds another IntegerPolynomial to an IntegerPolynomial in place, taking the right-hand side by reference.

$$ p \gets p + q. $$

§Worst-case complexity

$T(n) = O(n)$

$M(n) = O(n)$

where $T$ is time, $M$ is additional memory, and $n$ is the total number of bits of the coefficients of both polynomials.

§Examples
use core::str::FromStr;
use malachite_nz::integer_polynomial::IntegerPolynomial;

let mut p = IntegerPolynomial::from_str("x^2-3*x+2").unwrap();
p += &IntegerPolynomial::from_str("2*x+5").unwrap();
assert_eq!(p.to_string(), "x^2-x+7");
Source§

impl AddTruncated for IntegerPolynomial

Source§

fn add_truncated(self, other: Self, len: u64) -> Self

Adds two IntegerPolynomials, keeping only the coefficients of $x^i$ for $i$ less than len, taking both by value.

$$ f(p, q, n) = (p + q) \bmod x^n. $$

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 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 total number of bits of the first len coefficients of both polynomials.

§Examples
use core::str::FromStr;
use malachite_base::polynomial::AddTruncated;
use malachite_nz::integer_polynomial::IntegerPolynomial;

assert_eq!(
    IntegerPolynomial::from_str("x^3+2*x^2-x+5")
        .unwrap()
        .add_truncated(IntegerPolynomial::from_str("4*x^2+x-2").unwrap(), 3)
        .to_string(),
    "6*x^2+3"
);
// The linear coefficients cancel.
assert_eq!(
    IntegerPolynomial::from_str("x^3+2*x^2-x+5")
        .unwrap()
        .add_truncated(IntegerPolynomial::from_str("4*x^2+x-2").unwrap(), 2)
        .to_string(),
    "3"
);

This is equivalent to fmpz_poly_add_series from fmpz_poly/add_series.c, FLINT 3.6.0.

Source§

type Output = IntegerPolynomial

Source§

impl AddTruncated<&IntegerPolynomial> for IntegerPolynomial

Source§

fn add_truncated(self, other: &Self, len: u64) -> Self

Adds two IntegerPolynomials, keeping only the coefficients of $x^i$ for $i$ less than len, taking the first by value and the second by reference.

$$ f(p, q, n) = (p + q) \bmod x^n. $$

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 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 total number of bits of the first len coefficients of both polynomials.

§Examples
use core::str::FromStr;
use malachite_base::polynomial::AddTruncated;
use malachite_nz::integer_polynomial::IntegerPolynomial;

assert_eq!(
    IntegerPolynomial::from_str("x^3+2*x^2-x+5")
        .unwrap()
        .add_truncated(&IntegerPolynomial::from_str("4*x^2+x-2").unwrap(), 3)
        .to_string(),
    "6*x^2+3"
);
// The linear coefficients cancel.
assert_eq!(
    IntegerPolynomial::from_str("x^3+2*x^2-x+5")
        .unwrap()
        .add_truncated(&IntegerPolynomial::from_str("4*x^2+x-2").unwrap(), 2)
        .to_string(),
    "3"
);

This is equivalent to fmpz_poly_add_series from fmpz_poly/add_series.c, FLINT 3.6.0.

Source§

type Output = IntegerPolynomial

Source§

impl AddTruncated<&IntegerPolynomial> for &IntegerPolynomial

Source§

fn add_truncated(self, other: &IntegerPolynomial, len: u64) -> IntegerPolynomial

Adds two IntegerPolynomials, keeping only the coefficients of $x^i$ for $i$ less than len, taking both by reference.

$$ f(p, q, n) = (p + q) \bmod x^n. $$

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 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 total number of bits of the first len coefficients of both polynomials.

§Examples
use core::str::FromStr;
use malachite_base::polynomial::AddTruncated;
use malachite_nz::integer_polynomial::IntegerPolynomial;

assert_eq!(
    (&IntegerPolynomial::from_str("x^3+2*x^2-x+5").unwrap())
        .add_truncated(&IntegerPolynomial::from_str("4*x^2+x-2").unwrap(), 3)
        .to_string(),
    "6*x^2+3"
);
// The linear coefficients cancel.
assert_eq!(
    (&IntegerPolynomial::from_str("x^3+2*x^2-x+5").unwrap())
        .add_truncated(&IntegerPolynomial::from_str("4*x^2+x-2").unwrap(), 2)
        .to_string(),
    "3"
);

This is equivalent to fmpz_poly_add_series from fmpz_poly/add_series.c, FLINT 3.6.0.

Source§

type Output = IntegerPolynomial

Source§

impl AddTruncated<IntegerPolynomial> for &IntegerPolynomial

Source§

fn add_truncated(self, other: IntegerPolynomial, len: u64) -> IntegerPolynomial

Adds two IntegerPolynomials, keeping only the coefficients of $x^i$ for $i$ less than len, taking the first by reference and the second by value.

$$ f(p, q, n) = (p + q) \bmod x^n. $$

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 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 total number of bits of the first len coefficients of both polynomials.

§Examples
use core::str::FromStr;
use malachite_base::polynomial::AddTruncated;
use malachite_nz::integer_polynomial::IntegerPolynomial;

assert_eq!(
    (&IntegerPolynomial::from_str("x^3+2*x^2-x+5").unwrap())
        .add_truncated(IntegerPolynomial::from_str("4*x^2+x-2").unwrap(), 3)
        .to_string(),
    "6*x^2+3"
);
// The linear coefficients cancel.
assert_eq!(
    (&IntegerPolynomial::from_str("x^3+2*x^2-x+5").unwrap())
        .add_truncated(IntegerPolynomial::from_str("4*x^2+x-2").unwrap(), 2)
        .to_string(),
    "3"
);

This is equivalent to fmpz_poly_add_series from fmpz_poly/add_series.c, FLINT 3.6.0.

Source§

type Output = IntegerPolynomial

Source§

impl AddTruncatedAssign for IntegerPolynomial

Source§

fn add_truncated_assign(&mut self, other: Self, len: u64)

Adds an IntegerPolynomial to an IntegerPolynomial in place, keeping only the coefficients of $x^i$ for $i$ less than len, taking the second polynomial by value.

$$ p \gets (p + q) \bmod x^n. $$

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 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 total number of bits of the first len coefficients of both polynomials.

§Examples
use core::str::FromStr;
use malachite_base::polynomial::AddTruncatedAssign;
use malachite_nz::integer_polynomial::IntegerPolynomial;

let mut p = IntegerPolynomial::from_str("x^3+2*x^2-x+5").unwrap();
p.add_truncated_assign(IntegerPolynomial::from_str("4*x^2+x-2").unwrap(), 3);
assert_eq!(p.to_string(), "6*x^2+3");

// The linear coefficients cancel.
let mut p = IntegerPolynomial::from_str("x^3+2*x^2-x+5").unwrap();
p.add_truncated_assign(IntegerPolynomial::from_str("4*x^2+x-2").unwrap(), 2);
assert_eq!(p.to_string(), "3");

This is equivalent to fmpz_poly_add_series from fmpz_poly/add_series.c, FLINT 3.6.0.

Source§

impl AddTruncatedAssign<&IntegerPolynomial> for IntegerPolynomial

Source§

fn add_truncated_assign(&mut self, other: &Self, len: u64)

Adds an IntegerPolynomial to an IntegerPolynomial in place, keeping only the coefficients of $x^i$ for $i$ less than len, taking the second polynomial by reference.

$$ p \gets (p + q) \bmod x^n. $$

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 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 total number of bits of the first len coefficients of both polynomials.

§Examples
use core::str::FromStr;
use malachite_base::polynomial::AddTruncatedAssign;
use malachite_nz::integer_polynomial::IntegerPolynomial;

let mut p = IntegerPolynomial::from_str("x^3+2*x^2-x+5").unwrap();
p.add_truncated_assign(&IntegerPolynomial::from_str("4*x^2+x-2").unwrap(), 3);
assert_eq!(p.to_string(), "6*x^2+3");

// The linear coefficients cancel.
let mut p = IntegerPolynomial::from_str("x^3+2*x^2-x+5").unwrap();
p.add_truncated_assign(&IntegerPolynomial::from_str("4*x^2+x-2").unwrap(), 2);
assert_eq!(p.to_string(), "3");

This is equivalent to fmpz_poly_add_series from fmpz_poly/add_series.c, FLINT 3.6.0.

Source§

impl<'a> BalancedMod<&'a Integer> for IntegerPolynomial

Source§

fn balanced_mod(self, m: &'a Integer) -> Self

Reduces every coefficient of an IntegerPolynomial modulo an Integer to the representative closest to zero, taking the polynomial by value and the modulus by reference.

See the documentation for the BalancedMod implementation on IntegerPolynomial that takes both arguments by value for details.

§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 total number of bits in the polynomial’s coefficients.

§Panics

Panics if m is zero.

§Examples
use core::str::FromStr;
use malachite_base::num::arithmetic::traits::BalancedMod;
use malachite_nz::integer::Integer;
use malachite_nz::integer_polynomial::IntegerPolynomial;

// Each coefficient goes to the representative closest to zero.
let p = IntegerPolynomial::from_str("x^2+27*x-23").unwrap();
assert_eq!(
    p.clone().balanced_mod(&Integer::from(10)).to_string(),
    "x^2-3*x-3"
);

// Half the modulus stays positive, only the modulus's magnitude matters, and reducing the
// leading coefficient to zero lowers the degree.
let p = IntegerPolynomial::from_str("10*x^2+7*x+5").unwrap();
assert_eq!(
    p.clone().balanced_mod(&Integer::from(-10)).to_string(),
    "-3*x+5"
);
Source§

type Output = IntegerPolynomial

Source§

impl<'a> BalancedMod<&'a Integer> for &IntegerPolynomial

Source§

fn balanced_mod(self, m: &'a Integer) -> IntegerPolynomial

Reduces every coefficient of an IntegerPolynomial modulo an Integer to the representative closest to zero, taking the polynomial by reference and the modulus by reference.

See the documentation for the BalancedMod implementation on IntegerPolynomial that takes both arguments by value for details.

§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 total number of bits in the polynomial’s coefficients.

§Panics

Panics if m is zero.

§Examples
use core::str::FromStr;
use malachite_base::num::arithmetic::traits::BalancedMod;
use malachite_nz::integer::Integer;
use malachite_nz::integer_polynomial::IntegerPolynomial;

// Each coefficient goes to the representative closest to zero.
let p = IntegerPolynomial::from_str("x^2+27*x-23").unwrap();
assert_eq!(
    (&p).balanced_mod(&Integer::from(10)).to_string(),
    "x^2-3*x-3"
);

// Half the modulus stays positive, only the modulus's magnitude matters, and reducing the
// leading coefficient to zero lowers the degree.
let p = IntegerPolynomial::from_str("10*x^2+7*x+5").unwrap();
assert_eq!((&p).balanced_mod(&Integer::from(-10)).to_string(), "-3*x+5");
Source§

type Output = IntegerPolynomial

Source§

impl BalancedMod<Integer> for IntegerPolynomial

Source§

fn balanced_mod(self, m: Integer) -> Self

Reduces every coefficient of an IntegerPolynomial modulo an Integer to the representative closest to zero, taking the polynomial by value and the modulus by value.

Each coefficient $r_i$ of the result satisfies $-|m|/2 < r_i \leq |m|/2$ and $r_i \equiv p_i \bmod m$, which determine it uniquely, as with BalancedMod for Integers. A remainder of exactly $|m|/2$ is positive, and only the magnitude of $m$ matters.

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 $10x^2 + 7x + 5$ modulo $10$ is $-3x + 5$.

§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 total number of bits in the polynomial’s coefficients.

§Panics

Panics if m is zero.

§Examples
use core::str::FromStr;
use malachite_base::num::arithmetic::traits::BalancedMod;
use malachite_nz::integer::Integer;
use malachite_nz::integer_polynomial::IntegerPolynomial;

// Each coefficient goes to the representative closest to zero.
let p = IntegerPolynomial::from_str("x^2+27*x-23").unwrap();
assert_eq!(
    p.clone().balanced_mod(Integer::from(10)).to_string(),
    "x^2-3*x-3"
);

// Half the modulus stays positive, only the modulus's magnitude matters, and reducing the
// leading coefficient to zero lowers the degree.
let p = IntegerPolynomial::from_str("10*x^2+7*x+5").unwrap();
assert_eq!(
    p.clone().balanced_mod(Integer::from(-10)).to_string(),
    "-3*x+5"
);
Source§

type Output = IntegerPolynomial

Source§

impl BalancedMod<Integer> for &IntegerPolynomial

Source§

fn balanced_mod(self, m: Integer) -> IntegerPolynomial

Reduces every coefficient of an IntegerPolynomial modulo an Integer to the representative closest to zero, taking the polynomial by reference and the modulus by value.

See the documentation for the BalancedMod implementation on IntegerPolynomial that takes both arguments by value for details.

§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 total number of bits in the polynomial’s coefficients.

§Panics

Panics if m is zero.

§Examples
use core::str::FromStr;
use malachite_base::num::arithmetic::traits::BalancedMod;
use malachite_nz::integer::Integer;
use malachite_nz::integer_polynomial::IntegerPolynomial;

// Each coefficient goes to the representative closest to zero.
let p = IntegerPolynomial::from_str("x^2+27*x-23").unwrap();
assert_eq!(
    (&p).balanced_mod(Integer::from(10)).to_string(),
    "x^2-3*x-3"
);

// Half the modulus stays positive, only the modulus's magnitude matters, and reducing the
// leading coefficient to zero lowers the degree.
let p = IntegerPolynomial::from_str("10*x^2+7*x+5").unwrap();
assert_eq!((&p).balanced_mod(Integer::from(-10)).to_string(), "-3*x+5");
Source§

type Output = IntegerPolynomial

Source§

impl<'a> BalancedModAssign<&'a Integer> for IntegerPolynomial

Source§

fn balanced_mod_assign(&mut self, m: &'a Integer)

Reduces every coefficient of an IntegerPolynomial modulo an Integer to the representative closest to zero, in place, taking the modulus by reference.

See the documentation for the BalancedMod implementation on IntegerPolynomial that takes both arguments by value for details.

§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 total number of bits in the polynomial’s coefficients.

§Panics

Panics if m is zero.

§Examples
use core::str::FromStr;
use malachite_base::num::arithmetic::traits::BalancedModAssign;
use malachite_nz::integer::Integer;
use malachite_nz::integer_polynomial::IntegerPolynomial;

let mut p = IntegerPolynomial::from_str("x^2+27*x-23").unwrap();
p.balanced_mod_assign(&Integer::from(10));
assert_eq!(p.to_string(), "x^2-3*x-3");

let mut p = IntegerPolynomial::from_str("10*x^2+7*x+5").unwrap();
p.balanced_mod_assign(&Integer::from(-10));
assert_eq!(p.to_string(), "-3*x+5");
Source§

impl BalancedModAssign<Integer> for IntegerPolynomial

Source§

fn balanced_mod_assign(&mut self, m: Integer)

Reduces every coefficient of an IntegerPolynomial modulo an Integer to the representative closest to zero, in place, taking the modulus by value.

See the documentation for the BalancedMod implementation on IntegerPolynomial that takes both arguments by value for details.

§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 total number of bits in the polynomial’s coefficients.

§Panics

Panics if m is zero.

§Examples
use core::str::FromStr;
use malachite_base::num::arithmetic::traits::BalancedModAssign;
use malachite_nz::integer::Integer;
use malachite_nz::integer_polynomial::IntegerPolynomial;

let mut p = IntegerPolynomial::from_str("x^2+27*x-23").unwrap();
p.balanced_mod_assign(Integer::from(10));
assert_eq!(p.to_string(), "x^2-3*x-3");

let mut p = IntegerPolynomial::from_str("10*x^2+7*x+5").unwrap();
p.balanced_mod_assign(Integer::from(-10));
assert_eq!(p.to_string(), "-3*x+5");
Source§

impl BitPack for IntegerPolynomial

Source§

fn bit_pack(self, bits: u64) -> Integer

Packs the coefficients of an IntegerPolynomial into an Integer, placing the coefficient of $x^i$ at bit $ib$, taking it by value. The result is the value of the polynomial at $2^b$.

$$ f(p, b) = p(2^b) = \sum_i a_i2^{ib}. $$

When every coefficient’s absolute value is less than $2^b$, each occupies its own $b$-bit field, and the sign of the result is the sign of the leading coefficient. Wider coefficients overlap the fields above them, and the result is still $p(2^b)$.

§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 the total number of bits of the coefficients, and $m$ is self.len() times bits.

§Examples
use core::str::FromStr;
use malachite_base::polynomial::BitPack;
use malachite_nz::integer_polynomial::IntegerPolynomial;

// 3 * 2^16 + 2 * 2^8 + 1
let p = IntegerPolynomial::from_str("3*x^2+2*x+1").unwrap();
assert_eq!(p.clone().bit_pack(8).to_string(), "197121");
// A negative coefficient borrows from the field above it: 3 * 2^16 - 2 * 2^8 + 1.
let p = IntegerPolynomial::from_str("3*x^2-2*x+1").unwrap();
assert_eq!(p.clone().bit_pack(8).to_string(), "196097");
// The sign of the result is the sign of the leading coefficient.
let p = IntegerPolynomial::from_str("-x^2+255*x+255").unwrap();
assert_eq!(p.clone().bit_pack(8).to_string(), "-1");
// Coefficients wider than the fields overlap, and the result is still p(2^b).
let p = IntegerPolynomial::from_str("1000*x+1000").unwrap();
assert_eq!(p.bit_pack(8).to_string(), "257000");

This is equivalent to fmpz_poly_bit_pack from fmpz_poly/bit_pack.c, FLINT 3.6.0, when bits is positive and every coefficient’s absolute value is less than $2^b$; FLINT gives 0 when bits is 0 rather than $p(1)$, and truncates wider coefficients.

Source§

type Output = Integer

Source§

impl BitPack for &IntegerPolynomial

Source§

fn bit_pack(self, bits: u64) -> Integer

Packs the coefficients of an IntegerPolynomial into an Integer, placing the coefficient of $x^i$ at bit $ib$, taking it by reference. The result is the value of the polynomial at $2^b$.

$$ f(p, b) = p(2^b) = \sum_i a_i2^{ib}. $$

When every coefficient’s absolute value is less than $2^b$, each occupies its own $b$-bit field, and the sign of the result is the sign of the leading coefficient. Wider coefficients overlap the fields above them, and the result is still $p(2^b)$.

§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 the total number of bits of the coefficients, and $m$ is self.len() times bits.

§Examples
use core::str::FromStr;
use malachite_base::polynomial::BitPack;
use malachite_nz::integer_polynomial::IntegerPolynomial;

// 3 * 2^16 + 2 * 2^8 + 1
let p = IntegerPolynomial::from_str("3*x^2+2*x+1").unwrap();
assert_eq!((&p).bit_pack(8).to_string(), "197121");
// A negative coefficient borrows from the field above it: 3 * 2^16 - 2 * 2^8 + 1.
let p = IntegerPolynomial::from_str("3*x^2-2*x+1").unwrap();
assert_eq!((&p).bit_pack(8).to_string(), "196097");
// The sign of the result is the sign of the leading coefficient.
let p = IntegerPolynomial::from_str("-x^2+255*x+255").unwrap();
assert_eq!((&p).bit_pack(8).to_string(), "-1");
// Coefficients wider than the fields overlap, and the result is still p(2^b).
let p = IntegerPolynomial::from_str("1000*x+1000").unwrap();
assert_eq!((&p).bit_pack(8).to_string(), "257000");

This is equivalent to fmpz_poly_bit_pack from fmpz_poly/bit_pack.c, FLINT 3.6.0, when bits is positive and every coefficient’s absolute value is less than $2^b$; FLINT gives 0 when bits is 0 rather than $p(1)$, and truncates wider coefficients.

Source§

type Output = Integer

Source§

impl BitUnpack<&Integer> for IntegerPolynomial

Source§

fn bit_unpack(n: &Integer, bits: u64) -> Self

Unpacks an IntegerPolynomial from the bits-bit fields of an Integer, taking it by reference. The result $p$ satisfies $p(2^b) = n$.

$$ f(n, b) = p, \quad \text{where} \quad p(2^b) = n. $$

The fields of $|n|$ are read as signed $b$-bit numbers, in two’s complement, and each negative one borrows 1 from the field above, so the coefficients lie in $[-2^{b-1}, 2^{b-1}]$; if $n$ is negative, every coefficient is then negated. This inverts bit_pack on polynomials whose coefficients’ absolute values are less than $2^{b-1}$.

§Worst-case complexity

$T(n) = O(n)$

$M(n) = O(n)$

where $T$ is time, $M$ is additional memory, and $n$ is n.significant_bits().

§Panics

Panics if bits is 0.

§Examples
use malachite_base::polynomial::BitUnpack;
use malachite_nz::integer::Integer;
use malachite_nz::integer_polynomial::IntegerPolynomial;

assert_eq!(
    IntegerPolynomial::bit_unpack(&Integer::from(197121), 8).to_string(),
    "3*x^2+2*x+1"
);
// A field whose top bit is set is negative, and borrows from the field above.
assert_eq!(
    IntegerPolynomial::bit_unpack(&Integer::from(196097), 8).to_string(),
    "3*x^2-2*x+1"
);
assert_eq!(
    IntegerPolynomial::bit_unpack(&Integer::from(128), 8).to_string(),
    "x-128"
);
assert_eq!(
    IntegerPolynomial::bit_unpack(&Integer::from(-196097), 8).to_string(),
    "-3*x^2+2*x-1"
);

This is equivalent to fmpz_poly_bit_unpack from fmpz_poly/bit_unpack.c, FLINT 3.6.0, except that it panics when bits is 0, where FLINT gives the zero polynomial.

Source§

impl BitUnpack<Integer> for IntegerPolynomial

Source§

fn bit_unpack(n: Integer, bits: u64) -> Self

Unpacks an IntegerPolynomial from the bits-bit fields of an Integer, taking it by value. The result $p$ satisfies $p(2^b) = n$.

$$ f(n, b) = p, \quad \text{where} \quad p(2^b) = n. $$

The fields of $|n|$ are read as signed $b$-bit numbers, in two’s complement, and each negative one borrows 1 from the field above, so the coefficients lie in $[-2^{b-1}, 2^{b-1}]$; if $n$ is negative, every coefficient is then negated. This inverts bit_pack on polynomials whose coefficients’ absolute values are less than $2^{b-1}$.

§Worst-case complexity

$T(n) = O(n)$

$M(n) = O(n)$

where $T$ is time, $M$ is additional memory, and $n$ is n.significant_bits().

§Panics

Panics if bits is 0.

§Examples
use malachite_base::polynomial::BitUnpack;
use malachite_nz::integer::Integer;
use malachite_nz::integer_polynomial::IntegerPolynomial;

assert_eq!(
    IntegerPolynomial::bit_unpack(Integer::from(197121), 8).to_string(),
    "3*x^2+2*x+1"
);
// A field whose top bit is set is negative, and borrows from the field above.
assert_eq!(
    IntegerPolynomial::bit_unpack(Integer::from(196097), 8).to_string(),
    "3*x^2-2*x+1"
);
assert_eq!(
    IntegerPolynomial::bit_unpack(Integer::from(128), 8).to_string(),
    "x-128"
);
assert_eq!(
    IntegerPolynomial::bit_unpack(Integer::from(-196097), 8).to_string(),
    "-3*x^2+2*x-1"
);

This is equivalent to fmpz_poly_bit_unpack from fmpz_poly/bit_unpack.c, FLINT 3.6.0, except that it panics when bits is 0, where FLINT gives the zero polynomial.

Source§

impl CanonicalizeUnit for IntegerPolynomial

Source§

fn canonicalize_unit(self) -> Self

Brings an IntegerPolynomial into canonical unit form, taking it by value.

The canonical associate is the one whose leading coefficient is non-negative, so a polynomial with a negative leading coefficient is negated and any other is left alone. The zero polynomial is its own canonical associate.

§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::arithmetic::traits::CanonicalizeUnit;
use malachite_base::num::basic::traits::Zero;
use malachite_nz::integer_polynomial::IntegerPolynomial;

assert_eq!(
    IntegerPolynomial::from_str("-3*x^2+2")
        .unwrap()
        .canonicalize_unit()
        .to_string(),
    "3*x^2-2"
);
assert_eq!(
    IntegerPolynomial::from_str("3*x^2-2")
        .unwrap()
        .canonicalize_unit()
        .to_string(),
    "3*x^2-2"
);
assert_eq!(
    IntegerPolynomial::ZERO.canonicalize_unit(),
    IntegerPolynomial::ZERO
);
Source§

type Output = IntegerPolynomial

Source§

impl CanonicalizeUnit for &IntegerPolynomial

Source§

fn canonicalize_unit(self) -> IntegerPolynomial

Brings an IntegerPolynomial into canonical unit form, taking it by reference.

The canonical associate is the one whose leading coefficient is non-negative, so a polynomial with a negative leading coefficient is negated and any other is left alone. The zero polynomial is its own canonical associate.

§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_nz::integer_polynomial::IntegerPolynomial;

assert_eq!(
    (&IntegerPolynomial::from_str("-3*x^2+2").unwrap())
        .canonicalize_unit()
        .to_string(),
    "3*x^2-2"
);
assert_eq!(
    (&IntegerPolynomial::from_str("3*x^2-2").unwrap())
        .canonicalize_unit()
        .to_string(),
    "3*x^2-2"
);
assert_eq!(
    (&IntegerPolynomial::ZERO).canonicalize_unit(),
    IntegerPolynomial::ZERO
);
Source§

type Output = IntegerPolynomial

Source§

impl CanonicalizeUnitAssign for IntegerPolynomial

Source§

fn canonicalize_unit_assign(&mut self)

Brings an IntegerPolynomial into canonical unit form, in place.

See canonicalize_unit.

§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::arithmetic::traits::CanonicalizeUnitAssign;
use malachite_nz::integer_polynomial::IntegerPolynomial;

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

impl Clone for IntegerPolynomial

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl ComposePowerOfX for IntegerPolynomial

Source§

fn compose_power_of_x(self, k: u64) -> Self

Composes an IntegerPolynomial 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 the total number of bits of the coefficients.

§Panics

Panics if the degree of the result is greater than usize::MAX.

§Examples
use core::str::FromStr;
use malachite_base::polynomial::ComposePowerOfX;
use malachite_nz::integer_polynomial::IntegerPolynomial;

let p = IntegerPolynomial::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 = IntegerPolynomial::from_str("x^2-3*x+2").unwrap();
assert_eq!(p.compose_power_of_x(0).to_string(), "0");

This is equivalent to fmpz_poly_inflate from fmpz_poly/inflate.c, FLINT 3.6.0.

Source§

type Output = IntegerPolynomial

Source§

impl ComposePowerOfX for &IntegerPolynomial

Source§

fn compose_power_of_x(self, k: u64) -> IntegerPolynomial

Composes an IntegerPolynomial 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 the total number of bits of the coefficients.

§Panics

Panics if the degree of the result is greater than usize::MAX.

§Examples
use core::str::FromStr;
use malachite_base::polynomial::ComposePowerOfX;
use malachite_nz::integer_polynomial::IntegerPolynomial;

let p = IntegerPolynomial::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 = IntegerPolynomial::from_str("x^2-3*x+2").unwrap();
assert_eq!((&p).compose_power_of_x(0).to_string(), "0");

This is equivalent to fmpz_poly_inflate from fmpz_poly/inflate.c, FLINT 3.6.0.

Source§

type Output = IntegerPolynomial

Source§

impl ComposePowerOfXAssign for IntegerPolynomial

Source§

fn compose_power_of_x_assign(&mut self, k: u64)

Composes an IntegerPolynomial 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 the total number of bits of the coefficients.

§Panics

Panics if the degree of the result is greater than usize::MAX.

§Examples
use core::str::FromStr;
use malachite_base::polynomial::ComposePowerOfXAssign;
use malachite_nz::integer_polynomial::IntegerPolynomial;

let mut p = IntegerPolynomial::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 = IntegerPolynomial::from_str("x^2-3*x+2").unwrap();
p.compose_power_of_x_assign(0);
assert_eq!(p.to_string(), "0");

This is equivalent to fmpz_poly_inflate from fmpz_poly/inflate.c, FLINT 3.6.0.

Source§

impl Content for IntegerPolynomial

Source§

fn content(self) -> Natural

Computes the content of an IntegerPolynomial, the GCD of its coefficients, taking the polynomial by value.

The content is non-negative, and 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 (\log n)^2 \log\log n)$

$M(n) = O(n)$

where $T$ is time, $M$ is additional memory, and $n$ is the total number of bits of the coefficients.

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

let p = IntegerPolynomial::from_str("-6*x^2+4*x-10").unwrap();
assert_eq!(p.clone().content(), 2);
assert_eq!(IntegerPolynomial::ZERO.content(), 0);

This is equivalent to fmpz_poly_content from fmpz_poly/content.c, FLINT 3.6.0.

Source§

type Output = Natural

The type of the content.
Source§

impl Content for &IntegerPolynomial

Source§

fn content(self) -> Natural

Computes the content of an IntegerPolynomial, the GCD of its coefficients, taking the polynomial by reference.

The content is non-negative, and 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 (\log n)^2 \log\log n)$

$M(n) = O(n)$

where $T$ is time, $M$ is additional memory, and $n$ is the total number of bits of the coefficients.

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

let p = IntegerPolynomial::from_str("-6*x^2+4*x-10").unwrap();
assert_eq!((&p).content(), 2);
assert_eq!((&IntegerPolynomial::ZERO).content(), 0);

This is equivalent to fmpz_poly_content from fmpz_poly/content.c, FLINT 3.6.0.

Source§

type Output = Natural

The type of the content.
Source§

impl ContentAndPrimitivePart for IntegerPolynomial

Source§

fn content_and_primitive_part(self) -> (Natural, Self)

Computes the content and the primitive part of an IntegerPolynomial 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 (\log n)^2 \log\log n)$

$M(n) = O(1)$

where $T$ is time, $M$ is additional memory, and $n$ is the total number of bits of the coefficients.

§Examples
use core::str::FromStr;
use malachite_base::polynomial::ContentAndPrimitivePart;
use malachite_nz::integer_polynomial::IntegerPolynomial;

let p = IntegerPolynomial::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 Content = Natural

The type of the content.
Source§

type PrimitivePart = IntegerPolynomial

The type of the primitive part.
Source§

impl ContentAndPrimitivePart for &IntegerPolynomial

Source§

fn content_and_primitive_part(self) -> (Natural, IntegerPolynomial)

Computes the content and the primitive part of an IntegerPolynomial 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 (\log n)^2 \log\log n)$

$M(n) = O(n)$

where $T$ is time, $M$ is additional memory, and $n$ is the total number of bits of the coefficients.

§Examples
use core::str::FromStr;
use malachite_base::polynomial::ContentAndPrimitivePart;
use malachite_nz::integer_polynomial::IntegerPolynomial;

let p = IntegerPolynomial::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 Content = Natural

The type of the content.
Source§

type PrimitivePart = IntegerPolynomial

The type of the primitive part.
Source§

impl ConvertibleFrom<&IntegerPolynomial> for NaturalPolynomial

Source§

fn convertible_from(p: &IntegerPolynomial) -> bool

Determines whether an IntegerPolynomial can be converted to a NaturalPolynomial (when none of its coefficients is negative). Takes the IntegerPolynomial by reference.

Unlike checking whether TryFrom succeeds, this allocates nothing.

§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

See here.

Source§

impl<T: PrimitiveUnsigned + for<'a> ConvertibleFrom<&'a Integer>> ConvertibleFrom<&IntegerPolynomial> for UnsignedPolynomial<T>

Source§

fn convertible_from(p: &IntegerPolynomial) -> bool

Determines whether an IntegerPolynomial can be converted to an UnsignedPolynomial (when every coefficient is non-negative and representable as a T). Takes the IntegerPolynomial by reference.

Unlike checking whether TryFrom succeeds, this allocates nothing.

§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

See here.

Source§

impl Debug for IntegerPolynomial

Source§

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

Converts an IntegerPolynomial to a String.

This is the same as the Display::fmt implementation, so that a collection of IntegerPolynomials 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_nz::integer_polynomial::IntegerPolynomial;

let xs = vec![
    IntegerPolynomial::from_str("x^2-3*x+2").unwrap(),
    IntegerPolynomial::from_str("0").unwrap(),
    IntegerPolynomial::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 Default for IntegerPolynomial

Source§

fn default() -> Self

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

impl DeflatePowerOfX for IntegerPolynomial

Source§

fn deflate_power_of_x(self, n: u64) -> Self

Deflates an IntegerPolynomial 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_nz::integer_polynomial::IntegerPolynomial;

let p = IntegerPolynomial::from_str("x^4-3*x^2+2").unwrap();
assert_eq!(p.deflate_power_of_x(2).to_string(), "x^2-3*x+2");

This is equivalent to fmpz_poly_deflate from fmpz_poly/deflate.c, FLINT 3.6.0, except that it panics rather than dropping the coefficients at other exponents.

Source§

type Output = IntegerPolynomial

Source§

impl DeflatePowerOfX for &IntegerPolynomial

Source§

fn deflate_power_of_x(self, n: u64) -> IntegerPolynomial

Deflates an IntegerPolynomial 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 the total number of bits of the coefficients.

§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_nz::integer_polynomial::IntegerPolynomial;

let p = IntegerPolynomial::from_str("x^4-3*x^2+2").unwrap();
assert_eq!((&p).deflate_power_of_x(2).to_string(), "x^2-3*x+2");

This is equivalent to fmpz_poly_deflate from fmpz_poly/deflate.c, FLINT 3.6.0, except that it panics rather than dropping the coefficients at other exponents.

Source§

type Output = IntegerPolynomial

Source§

impl DeflatePowerOfXAssign for IntegerPolynomial

Source§

fn deflate_power_of_x_assign(&mut self, n: u64)

Deflates an IntegerPolynomial 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_nz::integer_polynomial::IntegerPolynomial;

let mut p = IntegerPolynomial::from_str("x^4-3*x^2+2").unwrap();
p.deflate_power_of_x_assign(2);
assert_eq!(p.to_string(), "x^2-3*x+2");

This is equivalent to fmpz_poly_deflate from fmpz_poly/deflate.c, FLINT 3.6.0, except that it panics rather than dropping the coefficients at other exponents.

Source§

impl Derivative for IntegerPolynomial

Source§

fn derivative(self) -> Self

Computes the derivative of an IntegerPolynomial, taking it by value.

$$ f(p) = p’ = \sum_{i=1}^n ia_ix^{i-1}. $$

The coefficient of $x^i$ is multiplied by $i$ and moves to $x^{i-1}$. A constant polynomial, including zero, has derivative zero.

§Worst-case complexity

$T(n, m) = O(n + m \log m)$

$M(n, m) = O(n + m \log m)$

where $T$ is time, $M$ is additional memory, $n$ is the total number of bits of the coefficients, and $m$ is self.len().

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

let p = IntegerPolynomial::from_str("x^3-3*x^2+2*x-5").unwrap();
assert_eq!(p.derivative().to_string(), "3*x^2-6*x+2");

let p = IntegerPolynomial::from_str("7").unwrap();
assert_eq!(p.derivative(), IntegerPolynomial::ZERO);

This is equivalent to fmpz_poly_derivative from fmpz_poly/derivative.c, FLINT 3.6.0.

Source§

type Output = IntegerPolynomial

Source§

impl Derivative for &IntegerPolynomial

Source§

fn derivative(self) -> IntegerPolynomial

Computes the derivative of an IntegerPolynomial, taking it by reference.

$$ f(p) = p’ = \sum_{i=1}^n ia_ix^{i-1}. $$

The coefficient of $x^i$ is multiplied by $i$ and moves to $x^{i-1}$. A constant polynomial, including zero, has derivative zero.

§Worst-case complexity

$T(n, m) = O(n + m \log m)$

$M(n, m) = O(n + m \log m)$

where $T$ is time, $M$ is additional memory, $n$ is the total number of bits of the coefficients, and $m$ is self.len().

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

let p = IntegerPolynomial::from_str("x^3-3*x^2+2*x-5").unwrap();
assert_eq!((&p).derivative().to_string(), "3*x^2-6*x+2");

let p = IntegerPolynomial::from_str("7").unwrap();
assert_eq!((&p).derivative(), IntegerPolynomial::ZERO);

This is equivalent to fmpz_poly_derivative from fmpz_poly/derivative.c, FLINT 3.6.0.

Source§

type Output = IntegerPolynomial

Source§

impl DerivativeAssign for IntegerPolynomial

Source§

fn derivative_assign(&mut self)

Replaces an IntegerPolynomial with its derivative.

$$ p \gets p’ = \sum_{i=1}^n ia_ix^{i-1}. $$

The coefficient of $x^i$ is multiplied by $i$ and moves to $x^{i-1}$. A constant polynomial, including zero, has derivative zero.

§Worst-case complexity

$T(n, m) = O(n + m \log m)$

$M(n, m) = O(n + m \log m)$

where $T$ is time, $M$ is additional memory, $n$ is the total number of bits of the coefficients, and $m$ is self.len().

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

let mut p = IntegerPolynomial::from_str("x^3-3*x^2+2*x-5").unwrap();
p.derivative_assign();
assert_eq!(p.to_string(), "3*x^2-6*x+2");

let mut p = IntegerPolynomial::from_str("7").unwrap();
p.derivative_assign();
assert_eq!(p, IntegerPolynomial::ZERO);

This is equivalent to fmpz_poly_derivative from fmpz_poly/derivative.c, FLINT 3.6.0.

Source§

impl Display for IntegerPolynomial

Source§

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

Converts an IntegerPolynomial 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.

A negative term joins the one before it with the - its coefficient already carries, rather than with a +, and a coefficient of -1 leaves only that sign behind: the polynomial with coefficients 5, -2, 1 is x^2-2*x+5, and the one with 0, 1, -1 is -x^2+x.

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_nz::integer_polynomial::IntegerPolynomial;

assert_eq!(
    IntegerPolynomial::from_str("x^2+3*x+2")
        .unwrap()
        .to_string(),
    "x^2+3*x+2"
);
assert_eq!(IntegerPolynomial::from_str("0").unwrap().to_string(), "0");
assert_eq!(IntegerPolynomial::from_str("5").unwrap().to_string(), "5");
assert_eq!(IntegerPolynomial::from_str("x").unwrap().to_string(), "x");
assert_eq!(
    IntegerPolynomial::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!(
    IntegerPolynomial::from_str("2+3*x+x^2")
        .unwrap()
        .to_string(),
    "x^2+3*x+2"
);
assert_eq!(IntegerPolynomial::from_str("x^1").unwrap().to_string(), "x");
Source§

impl<'a> DivExact<&'a Integer> for IntegerPolynomial

Source§

fn div_exact(self, c: &'a Integer) -> Self

Divides an IntegerPolynomial by an Integer, taking the polynomial by value and the Integer by reference. Every coefficient of the polynomial must be exactly divisible by the Integer. If one isn’t, this function may panic or return a meaningless result.

See the documentation for the DivExact implementation on IntegerPolynomial that takes both arguments by value for details.

§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 total number of bits in the polynomial’s coefficients.

§Panics

Panics if c is zero. May panic if a coefficient of the polynomial is not divisible by c.

§Examples
use core::str::FromStr;
use malachite_base::num::arithmetic::traits::DivExact;
use malachite_base::num::basic::traits::Zero;
use malachite_nz::integer::Integer;
use malachite_nz::integer_polynomial::IntegerPolynomial;

let p = IntegerPolynomial::from_str("6*x^2-3*x+9").unwrap();
assert_eq!(
    p.clone().div_exact(&Integer::from(3)).to_string(),
    "2*x^2-x+3"
);
assert_eq!(
    p.clone().div_exact(&Integer::from(-3)).to_string(),
    "-2*x^2+x-3"
);
assert_eq!(
    IntegerPolynomial::ZERO.div_exact(&Integer::from(5)),
    IntegerPolynomial::ZERO
);

This is equivalent to fmpz_poly_scalar_divexact_fmpz from fmpz_poly/scalar_divexact_fmpz.c, FLINT 3.6.0.

Source§

type Output = IntegerPolynomial

Source§

impl<'a> DivExact<&'a Integer> for &IntegerPolynomial

Source§

fn div_exact(self, c: &'a Integer) -> IntegerPolynomial

Divides an IntegerPolynomial by an Integer, taking both by reference. Every coefficient of the polynomial must be exactly divisible by the Integer. If one isn’t, this function may panic or return a meaningless result.

See the documentation for the DivExact implementation on IntegerPolynomial that takes both arguments by value for details.

§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 total number of bits in the polynomial’s coefficients.

§Panics

Panics if c is zero. May panic if a coefficient of the polynomial is not divisible by c.

§Examples
use core::str::FromStr;
use malachite_base::num::arithmetic::traits::DivExact;
use malachite_base::num::basic::traits::Zero;
use malachite_nz::integer::Integer;
use malachite_nz::integer_polynomial::IntegerPolynomial;

let p = IntegerPolynomial::from_str("6*x^2-3*x+9").unwrap();
assert_eq!((&p).div_exact(&Integer::from(3)).to_string(), "2*x^2-x+3");
assert_eq!((&p).div_exact(&Integer::from(-3)).to_string(), "-2*x^2+x-3");
assert_eq!(
    IntegerPolynomial::ZERO.div_exact(&Integer::from(5)),
    IntegerPolynomial::ZERO
);

This is equivalent to fmpz_poly_scalar_divexact_fmpz from fmpz_poly/scalar_divexact_fmpz.c, FLINT 3.6.0.

Source§

type Output = IntegerPolynomial

Source§

impl DivExact<Integer> for IntegerPolynomial

Source§

fn div_exact(self, c: Integer) -> Self

Divides an IntegerPolynomial by an Integer, taking both by value. Every coefficient of the polynomial must be exactly divisible by the Integer. If one isn’t, this function may panic or return a meaningless result.

$$ f(p, c) = \frac{p}{c}. $$

A polynomial is divisible by $c$ exactly when $|c|$ divides its content, so that is how to check beforehand.

§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 total number of bits in the polynomial’s coefficients.

§Panics

Panics if c is zero. May panic if a coefficient of the polynomial is not divisible by c.

§Examples
use core::str::FromStr;
use malachite_base::num::arithmetic::traits::DivExact;
use malachite_base::num::basic::traits::Zero;
use malachite_nz::integer::Integer;
use malachite_nz::integer_polynomial::IntegerPolynomial;

let p = IntegerPolynomial::from_str("6*x^2-3*x+9").unwrap();
assert_eq!(
    p.clone().div_exact(Integer::from(3)).to_string(),
    "2*x^2-x+3"
);
assert_eq!(
    p.clone().div_exact(Integer::from(-3)).to_string(),
    "-2*x^2+x-3"
);
assert_eq!(
    IntegerPolynomial::ZERO.div_exact(Integer::from(5)),
    IntegerPolynomial::ZERO
);

This is equivalent to fmpz_poly_scalar_divexact_fmpz from fmpz_poly/scalar_divexact_fmpz.c, FLINT 3.6.0.

Source§

type Output = IntegerPolynomial

Source§

impl DivExact<Integer> for &IntegerPolynomial

Source§

fn div_exact(self, c: Integer) -> IntegerPolynomial

Divides an IntegerPolynomial by an Integer, taking the polynomial by reference and the Integer by value. Every coefficient of the polynomial must be exactly divisible by the Integer. If one isn’t, this function may panic or return a meaningless result.

See the documentation for the DivExact implementation on IntegerPolynomial that takes both arguments by value for details.

§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 total number of bits in the polynomial’s coefficients.

§Panics

Panics if c is zero. May panic if a coefficient of the polynomial is not divisible by c.

§Examples
use core::str::FromStr;
use malachite_base::num::arithmetic::traits::DivExact;
use malachite_base::num::basic::traits::Zero;
use malachite_nz::integer::Integer;
use malachite_nz::integer_polynomial::IntegerPolynomial;

let p = IntegerPolynomial::from_str("6*x^2-3*x+9").unwrap();
assert_eq!((&p).div_exact(Integer::from(3)).to_string(), "2*x^2-x+3");
assert_eq!((&p).div_exact(Integer::from(-3)).to_string(), "-2*x^2+x-3");
assert_eq!(
    IntegerPolynomial::ZERO.div_exact(Integer::from(5)),
    IntegerPolynomial::ZERO
);

This is equivalent to fmpz_poly_scalar_divexact_fmpz from fmpz_poly/scalar_divexact_fmpz.c, FLINT 3.6.0.

Source§

type Output = IntegerPolynomial

Source§

impl<'a> DivExactAssign<&'a Integer> for IntegerPolynomial

Source§

fn div_exact_assign(&mut self, c: &'a Integer)

Divides an IntegerPolynomial by an Integer in place, taking the Integer by reference. Every coefficient of the polynomial must be exactly divisible by the Integer. If one isn’t, this function may panic or leave a meaningless result.

$$ p \gets \frac{p}{c}. $$

See the documentation for the DivExact implementation on IntegerPolynomial that takes both arguments by value for details.

§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 total number of bits in the polynomial’s coefficients.

§Panics

Panics if c is zero. May panic if a coefficient of the polynomial is not divisible by c.

§Examples
use core::str::FromStr;
use malachite_base::num::arithmetic::traits::DivExactAssign;
use malachite_nz::integer::Integer;
use malachite_nz::integer_polynomial::IntegerPolynomial;

let mut p = IntegerPolynomial::from_str("6*x^2-3*x+9").unwrap();
p.div_exact_assign(&Integer::from(3));
assert_eq!(p.to_string(), "2*x^2-x+3");

let mut p = IntegerPolynomial::from_str("6*x^2-3*x+9").unwrap();
p.div_exact_assign(&Integer::from(-3));
assert_eq!(p.to_string(), "-2*x^2+x-3");

This is equivalent to fmpz_poly_scalar_divexact_fmpz from fmpz_poly/scalar_divexact_fmpz.c, FLINT 3.6.0.

Source§

impl DivExactAssign<Integer> for IntegerPolynomial

Source§

fn div_exact_assign(&mut self, c: Integer)

Divides an IntegerPolynomial by an Integer in place, taking the Integer by value. Every coefficient of the polynomial must be exactly divisible by the Integer. If one isn’t, this function may panic or leave a meaningless result.

$$ p \gets \frac{p}{c}. $$

See the documentation for the DivExact implementation on IntegerPolynomial that takes both arguments by value for details.

§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 total number of bits in the polynomial’s coefficients.

§Panics

Panics if c is zero. May panic if a coefficient of the polynomial is not divisible by c.

§Examples
use core::str::FromStr;
use malachite_base::num::arithmetic::traits::DivExactAssign;
use malachite_nz::integer::Integer;
use malachite_nz::integer_polynomial::IntegerPolynomial;

let mut p = IntegerPolynomial::from_str("6*x^2-3*x+9").unwrap();
p.div_exact_assign(Integer::from(3));
assert_eq!(p.to_string(), "2*x^2-x+3");

let mut p = IntegerPolynomial::from_str("6*x^2-3*x+9").unwrap();
p.div_exact_assign(Integer::from(-3));
assert_eq!(p.to_string(), "-2*x^2+x-3");

This is equivalent to fmpz_poly_scalar_divexact_fmpz from fmpz_poly/scalar_divexact_fmpz.c, FLINT 3.6.0.

Source§

impl DivPowerOfX for IntegerPolynomial

Source§

fn div_power_of_x(self, n: u64) -> Self

Divides an IntegerPolynomial 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 the total number of bits of the coefficients.

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

let p = IntegerPolynomial::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 = IntegerPolynomial::from_str("-5*x").unwrap();
assert_eq!(p.div_power_of_x(1).to_string(), "-5");
let p = IntegerPolynomial::from_str("x^3-3*x^2+2*x-5").unwrap();
assert_eq!(p.div_power_of_x(10), IntegerPolynomial::ZERO);

This is equivalent to fmpz_poly_shift_right from fmpz_poly/shift_right.c, FLINT 3.6.0.

Source§

type Output = IntegerPolynomial

Source§

impl DivPowerOfX for &IntegerPolynomial

Source§

fn div_power_of_x(self, n: u64) -> IntegerPolynomial

Divides an IntegerPolynomial 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 the total number of bits of the coefficients.

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

let p = IntegerPolynomial::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 = IntegerPolynomial::from_str("-5*x").unwrap();
assert_eq!((&p).div_power_of_x(1).to_string(), "-5");
let p = IntegerPolynomial::from_str("x^3-3*x^2+2*x-5").unwrap();
assert_eq!((&p).div_power_of_x(10), IntegerPolynomial::ZERO);

This is equivalent to fmpz_poly_shift_right from fmpz_poly/shift_right.c, FLINT 3.6.0.

Source§

type Output = IntegerPolynomial

Source§

impl DivPowerOfXAssign for IntegerPolynomial

Source§

fn div_power_of_x_assign(&mut self, n: u64)

Divides an IntegerPolynomial 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 the total number of bits of the coefficients.

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

let mut p = IntegerPolynomial::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 = IntegerPolynomial::from_str("-5*x").unwrap();
p.div_power_of_x_assign(1);
assert_eq!(p.to_string(), "-5");

let mut p = IntegerPolynomial::from_str("x^3-3*x^2+2*x-5").unwrap();
p.div_power_of_x_assign(10);
assert_eq!(p, IntegerPolynomial::ZERO);

This is equivalent to fmpz_poly_shift_right from fmpz_poly/shift_right.c, FLINT 3.6.0.

Source§

impl Eq for IntegerPolynomial

Source§

impl EqTruncated for IntegerPolynomial

Source§

fn eq_truncated(&self, other: &Self, len: u64) -> bool

Determines whether an IntegerPolynomial 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 the total number of bits of the coefficients below $x^{\mathrm{len}}$.

§Examples

See here.

This is equivalent to fmpz_poly_equal_trunc from fmpz_poly/equal_trunc.c, FLINT 3.6.0.

Source§

impl<T: PrimitiveUnsigned> EqTruncated<IntegerPolynomial> for UnsignedPolynomial<T>
where Integer: PartialEq<T>,

Source§

fn eq_truncated(&self, other: &IntegerPolynomial, len: u64) -> bool

Determines whether an UnsignedPolynomial and an IntegerPolynomial 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 the total number of bits of the coefficients below $x^{\mathrm{len}}$.

§Examples

See here.

Source§

impl EqTruncated<IntegerPolynomial> for NaturalPolynomial

Source§

fn eq_truncated(&self, other: &IntegerPolynomial, len: u64) -> bool

Determines whether a NaturalPolynomial and an IntegerPolynomial 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 the total number of bits of the coefficients below $x^{\mathrm{len}}$.

§Examples

See here.

Source§

impl EqTruncated<NaturalPolynomial> for IntegerPolynomial

Source§

fn eq_truncated(&self, other: &NaturalPolynomial, len: u64) -> bool

Determines whether an IntegerPolynomial and a NaturalPolynomial 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 the total number of bits of the coefficients below $x^{\mathrm{len}}$.

§Examples

See here.

Source§

impl<T: PrimitiveUnsigned> EqTruncated<UnsignedPolynomial<T>> for IntegerPolynomial
where Integer: PartialEq<T>,

Source§

fn eq_truncated(&self, other: &UnsignedPolynomial<T>, len: u64) -> bool

Determines whether an IntegerPolynomial and an UnsignedPolynomial 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 the total number of bits of the coefficients below $x^{\mathrm{len}}$.

§Examples

See here.

Source§

impl Evaluate<&Integer> for &IntegerPolynomial

Source§

fn evaluate(self, x: &Integer) -> Integer

Evaluates an IntegerPolynomial at an Integer, taking both by reference.

$$ f(p, x) = \sum_{i=0}^{n-1} c_i x^i, $$

where $c_i$ is the coefficient of $x^i$ in $p$ and $n$ is its length. The zero polynomial evaluates to 0 everywhere.

Horner’s rule is used unless the polynomial is long compared with the size of x, in which case divide and conquer, which pairs off coefficients and merges the pairs so that each multiplication has operands of about the same size, is faster.

§Worst-case complexity

$T(n) = O(n \log^2 n \log\log n)$

$M(n) = O(n \log n)$

where $T$ is time, $M$ is additional memory, and $n$ is self.len() times the larger of the greatest number of bits of any coefficient and the number of bits of x.

§Examples
use core::str::FromStr;
use malachite_base::num::basic::traits::{One, Two, Zero};
use malachite_base::polynomial::Evaluate;
use malachite_nz::integer::Integer;
use malachite_nz::integer_polynomial::IntegerPolynomial;

let p = IntegerPolynomial::from_str("x^2-3*x+2").unwrap();
assert_eq!((&p).evaluate(&Integer::ZERO), 2);
assert_eq!((&p).evaluate(&Integer::ONE), 0);
assert_eq!((&p).evaluate(&Integer::from(-2)), 12);
assert_eq!((&p).evaluate(&Integer::from(10)), 72);

let q = IntegerPolynomial::from_str("x^100-1").unwrap();
assert_eq!(
    (&q).evaluate(&Integer::TWO).to_string(),
    "1267650600228229401496703205375"
);

This is equivalent to fmpz_poly_evaluate_fmpz from fmpz_poly/evaluate_fmpz.c, FLINT 3.6.0.

Source§

type Output = Integer

The type of the polynomial’s value.
Source§

impl Evaluate<Integer> for &IntegerPolynomial

Source§

fn evaluate(self, x: Integer) -> Integer

Evaluates an IntegerPolynomial at an Integer, taking the polynomial by reference and the value by value.

$$ f(p, x) = \sum_{i=0}^{n-1} c_i x^i, $$

where $c_i$ is the coefficient of $x^i$ in $p$ and $n$ is its length. The zero polynomial evaluates to 0 everywhere.

Horner’s rule is used unless the polynomial is long compared with the size of x, in which case divide and conquer, which pairs off coefficients and merges the pairs so that each multiplication has operands of about the same size, is faster.

§Worst-case complexity

$T(n) = O(n \log^2 n \log\log n)$

$M(n) = O(n \log n)$

where $T$ is time, $M$ is additional memory, and $n$ is self.len() times the larger of the greatest number of bits of any coefficient and the number of bits of x.

§Examples
use core::str::FromStr;
use malachite_base::num::basic::traits::{One, Two, Zero};
use malachite_base::polynomial::Evaluate;
use malachite_nz::integer::Integer;
use malachite_nz::integer_polynomial::IntegerPolynomial;

let p = IntegerPolynomial::from_str("x^2-3*x+2").unwrap();
assert_eq!((&p).evaluate(Integer::ZERO), 2);
assert_eq!((&p).evaluate(Integer::ONE), 0);
assert_eq!((&p).evaluate(Integer::from(-2)), 12);
assert_eq!((&p).evaluate(Integer::from(10)), 72);

let q = IntegerPolynomial::from_str("x^100-1").unwrap();
assert_eq!(
    (&q).evaluate(Integer::TWO).to_string(),
    "1267650600228229401496703205375"
);

This is equivalent to fmpz_poly_evaluate_fmpz from fmpz_poly/evaluate_fmpz.c, FLINT 3.6.0.

Source§

type Output = Integer

The type of the polynomial’s value.
Source§

impl EvaluateMany<Integer> for &IntegerPolynomial

Source§

fn evaluate_many(self, xs: &[Integer]) -> Vec<Integer>

Evaluates an IntegerPolynomial at each of several Integers.

$$ f(p, (x_j){j=0}^{k-1}) = \left ( \sum{i=0}^{n-1} c_i x_j^i \right )_{j=0}^{k-1}, $$

where $c_i$ is the coefficient of $x^i$ in $p$ and $n$ is its length.

Each value is found as by evaluate, which chooses between Horner’s rule and divide and conquer by the length of the polynomial and the size of the value.

§Worst-case complexity

$T(n, k) = O(kn \log^2 n \log\log n)$

$M(n, k) = O(kn \log n)$

where $T$ is time, $M$ is additional memory, $k$ is xs.len(), and $n$ is self.len() times the larger of the greatest number of bits of any coefficient and the greatest number of bits of any value in xs.

§Examples
use core::str::FromStr;
use malachite_base::polynomial::EvaluateMany;
use malachite_nz::integer::Integer;
use malachite_nz::integer_polynomial::IntegerPolynomial;

let p = IntegerPolynomial::from_str("x^2-3*x+2").unwrap();
let xs = [-1i32, 0, 1, 2, 3].map(Integer::from);
assert_eq!(
    (&p).evaluate_many(&xs),
    [6i32, 2, 0, 0, 2].map(Integer::from)
);

This is equivalent to fmpz_poly_evaluate_fmpz_vec from fmpz_poly/evaluate_fmpz_vec.c, FLINT 3.6.0.

Source§

type Output = Integer

The type of the polynomial’s values.
Source§

impl ExponentGcd for IntegerPolynomial

Source§

fn exponent_gcd(&self) -> u64

Computes the greatest common divisor of the exponents at which an IntegerPolynomial 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_nz::integer_polynomial::IntegerPolynomial;

assert_eq!(
    IntegerPolynomial::from_str("x^6-2*x^3+1")
        .unwrap()
        .exponent_gcd(),
    3
);
assert_eq!(
    IntegerPolynomial::from_str("x^4-x").unwrap().exponent_gcd(),
    1
);
assert_eq!(
    IntegerPolynomial::from_str("-x^4").unwrap().exponent_gcd(),
    4
);
assert_eq!(IntegerPolynomial::from_str("-5").unwrap().exponent_gcd(), 0);
assert_eq!(IntegerPolynomial::ZERO.exponent_gcd(), 0);

This is equivalent to fmpz_poly_deflation from fmpz_poly/deflation.c, FLINT 3.6.0, except that a constant gives 0 rather than 1.

Source§

impl FloorL2Norm for &IntegerPolynomial

Source§

fn floor_l2_norm(self) -> Natural

Computes the floor of an IntegerPolynomial’s $L^2$ norm: the floor of the square root of the sum of the squares of its coefficients.

$$ f(p) = \left \lfloor \sqrt{\sum_i p_i^2} \right \rfloor. $$

The exact square of the norm is l2_norm_squared.

§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 total number of bits of the coefficients.

§Examples
use core::str::FromStr;
use malachite_base::polynomial::FloorL2Norm;
use malachite_nz::integer_polynomial::IntegerPolynomial;

assert_eq!(
    IntegerPolynomial::from_str("x^2-3*x+2")
        .unwrap()
        .floor_l2_norm(),
    3u32
);
assert_eq!(
    IntegerPolynomial::from_str("0").unwrap().floor_l2_norm(),
    0u32
);
assert_eq!(
    IntegerPolynomial::from_str("-5").unwrap().floor_l2_norm(),
    5u32
);

This is equivalent to fmpz_poly_2norm from fmpz_poly/2norm.c, FLINT 3.6.0.

Source§

type Output = Natural

Source§

impl From<NaturalPolynomial> for IntegerPolynomial

Source§

fn from(p: NaturalPolynomial) -> Self

Converts a NaturalPolynomial to an IntegerPolynomial.

Every polynomial with Natural coefficients is one with Integer coefficients, so nothing is lost and nothing can fail. The coefficients are converted one by one, and the leading one stays nonzero, so the degree is unchanged.

$f(p) = p$, read on the left over $\N$ and on the right over $\Z$.

§Worst-case complexity

$T(n) = O(n)$

$M(n) = O(n)$

where $T$ is time, $M$ is additional memory, and $n$ is the total number of bits of the coefficients.

§Examples
use core::str::FromStr;
use malachite_nz::integer_polynomial::IntegerPolynomial;
use malachite_nz::natural_polynomial::NaturalPolynomial;

let p = NaturalPolynomial::from_str("x^2+3*x+2").unwrap();
assert_eq!(IntegerPolynomial::from(p).to_string(), "x^2+3*x+2");

assert_eq!(
    IntegerPolynomial::from(NaturalPolynomial::default()).to_string(),
    "0"
);
Source§

impl<T: Into<Integer>> From<T> for IntegerPolynomial

Source§

fn from(x: T) -> Self

Converts a value to a constant IntegerPolynomial.

This works for anything a Integer can be converted from, and for a Integer 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

Same as the time and additional memory complexity of converting the value to a Integer.

§Examples
use malachite_base::num::arithmetic::traits::Pow;
use malachite_nz::integer::Integer;
use malachite_nz::integer_polynomial::IntegerPolynomial;

assert_eq!(IntegerPolynomial::from(123u32).to_string(), "123");
assert_eq!(IntegerPolynomial::from(true).to_string(), "1");
assert_eq!(
    IntegerPolynomial::from(Integer::from(10u32).pow(20)).to_string(),
    "100000000000000000000"
);

// Zero is the zero polynomial, which has no coefficients.
assert_eq!(IntegerPolynomial::from(0u32).to_string(), "0");
Source§

impl<T: PrimitiveUnsigned> From<UnsignedPolynomial<T>> for IntegerPolynomial
where Integer: From<T>,

Source§

fn from(p: UnsignedPolynomial<T>) -> Self

Converts a UnsignedPolynomial to an IntegerPolynomial.

Every unsigned primitive is an Integer, so nothing is lost and nothing can fail. The coefficients are converted one by one, and the leading one stays nonzero, so the degree is unchanged.

$f(p) = p$, read on the left over the coefficients and on the right over $\Z$.

§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::unsigned_polynomial::UnsignedPolynomial;
use malachite_nz::integer_polynomial::IntegerPolynomial;

let p = UnsignedPolynomial::<u64>::from_str("x^2+3*x+2").unwrap();
assert_eq!(IntegerPolynomial::from(p).to_string(), "x^2+3*x+2");

assert_eq!(
    IntegerPolynomial::from(UnsignedPolynomial::<u64>::default()).to_string(),
    "0"
);
Source§

impl FromStr for IntegerPolynomial

Source§

fn from_str(s: &str) -> Result<Self, ()>

Converts a string to an IntegerPolynomial.

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. A term may be negative, in which case the - that separates it from the term before it is the same - that its coefficient carries; a term at the front keeps its sign and has nothing to be separated from. What it will not accept is a term whose coefficient is zero, two terms of the same degree, a leading +, 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 an IntegerPolynomial, 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_nz::integer_polynomial::IntegerPolynomial;

assert_eq!(
    IntegerPolynomial::from_str("x^2+3*x+2")
        .unwrap()
        .to_string(),
    "x^2+3*x+2"
);
assert_eq!(IntegerPolynomial::from_str("0").unwrap().to_string(), "0");
assert_eq!(IntegerPolynomial::from_str("5").unwrap().to_string(), "5");
assert_eq!(IntegerPolynomial::from_str("x").unwrap().to_string(), "x");

// A term may be negative, and a leading `-` belongs to the first term rather than
// separating it from anything.
assert_eq!(IntegerPolynomial::from_str("-5").unwrap().to_string(), "-5");
assert_eq!(IntegerPolynomial::from_str("-x").unwrap().to_string(), "-x");
assert_eq!(
    IntegerPolynomial::from_str("x^2-2*x+5")
        .unwrap()
        .to_string(),
    "x^2-2*x+5"
);

// The terms may come in any order.
assert_eq!(
    IntegerPolynomial::from_str("2+3*x+x^2")
        .unwrap()
        .to_string(),
    "x^2+3*x+2"
);

assert!(IntegerPolynomial::from_str("").is_err());
assert!(IntegerPolynomial::from_str("y").is_err());
assert!(IntegerPolynomial::from_str("x^2 + 1").is_err());
assert!(IntegerPolynomial::from_str("0*x").is_err());
assert!(IntegerPolynomial::from_str("x+x").is_err());
// A `+` is a separator, so a leading one is neither written nor read, and two signs in a
// row leave a term with nothing in it.
assert!(IntegerPolynomial::from_str("+x").is_err());
assert!(IntegerPolynomial::from_str("x--1").is_err());
Source§

type Err = ()

The associated error which can be returned from parsing.
Source§

impl Hash for IntegerPolynomial

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl Height for IntegerPolynomial

Source§

fn to_height(&self) -> Natural

Returns the height of an IntegerPolynomial: the largest of the absolute values of its coefficients, taking the polynomial by reference and cloning.

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(m)$

where $T$ is time, $M$ is additional memory, $n$ is the total number of bits of the coefficients, and $m$ is the number of bits of the height.

§Examples
use core::str::FromStr;
use malachite_base::num::arithmetic::traits::Height;
use malachite_nz::integer_polynomial::IntegerPolynomial;

assert_eq!(
    IntegerPolynomial::from_str("x^2-3*x+2")
        .unwrap()
        .to_height(),
    3
);
assert_eq!(
    IntegerPolynomial::from_str("-x^100").unwrap().to_height(),
    1
);
assert_eq!(IntegerPolynomial::from_str("0").unwrap().to_height(), 0);

This is fmpz_poly_height from fmpz_poly/norms.c, FLINT 3.6.0.

Source§

fn into_height(self) -> Natural

Returns the height of an IntegerPolynomial: the largest of the absolute values of its coefficients, taking the polynomial by value.

The coefficient of largest magnitude is moved out of the polynomial rather than cloned.

§Worst-case complexity

$T(n) = O(n)$

$M(n) = O(1)$

where $T$ is time, $M$ is additional memory, and $n$ is the total number of bits of the coefficients.

§Examples
use core::str::FromStr;
use malachite_base::num::arithmetic::traits::Height;
use malachite_nz::integer_polynomial::IntegerPolynomial;

assert_eq!(
    IntegerPolynomial::from_str("x^2-3*x+2")
        .unwrap()
        .into_height(),
    3
);
assert_eq!(IntegerPolynomial::from_str("0").unwrap().into_height(), 0);
Source§

fn height_significant_bits(&self) -> u64

Returns the number of significant bits of the height of an IntegerPolynomial.

Since bit length is monotone, this is the largest of the coefficients’ bit lengths, without materializing the 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_nz::integer_polynomial::IntegerPolynomial;

assert_eq!(
    IntegerPolynomial::from_str("x^2-3*x+2")
        .unwrap()
        .height_significant_bits(),
    2
);
assert_eq!(
    IntegerPolynomial::from_str("0")
        .unwrap()
        .height_significant_bits(),
    0
);
Source§

type Output = Natural

Source§

impl HeightRef for IntegerPolynomial

Source§

fn height_ref(&self) -> &Natural

Returns a reference to the height of an IntegerPolynomial: the largest of the absolute values of its coefficients.

An Integer holds its magnitude as a Natural, so the height is already there to be lent and nothing needs to be built. The zero polynomial has no coefficients, and a reference to zero is returned for it.

§Worst-case complexity

$T(n) = O(n)$

$M(n) = O(1)$

where $T$ is time, $M$ is additional memory, and $n$ is the total number of bits of the coefficients.

§Examples
use core::str::FromStr;
use malachite_base::num::arithmetic::traits::HeightRef;
use malachite_nz::integer_polynomial::IntegerPolynomial;

assert_eq!(
    *IntegerPolynomial::from_str("x^2-3*x+2")
        .unwrap()
        .height_ref(),
    3
);
assert_eq!(*IntegerPolynomial::from_str("0").unwrap().height_ref(), 0);
Source§

impl IsUnit for IntegerPolynomial

Source§

fn is_unit(&self) -> bool

Determines whether an IntegerPolynomial is a unit: whether it is the constant polynomial 1 or $-1$, the only polynomials with integer coefficients that have a multiplicative inverse.

§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_nz::integer_polynomial::IntegerPolynomial;

assert_eq!(IntegerPolynomial::one().is_unit(), true);
assert_eq!(IntegerPolynomial::negative_one().is_unit(), true);
assert_eq!(IntegerPolynomial::ZERO.is_unit(), false);
assert_eq!(IntegerPolynomial::two().is_unit(), false);
assert_eq!(IntegerPolynomial::x().is_unit(), false);
assert_eq!(
    IntegerPolynomial::from_str("-x-1").unwrap().is_unit(),
    false
);
Source§

impl L2NormSquared for &IntegerPolynomial

Source§

fn l2_norm_squared(self) -> Natural

Computes the sum of the squares of an IntegerPolynomial’s coefficients, which is the square of its $L^2$ norm.

$$ f(p) = \sum_i p_i^2. $$

§Worst-case complexity

$T(n) = O(n \log n \log\log n)$

$M(n) = O(n)$

where $T$ is time, $M$ is additional memory, and $n$ is the total number of bits of the coefficients.

§Examples
use core::str::FromStr;
use malachite_base::polynomial::L2NormSquared;
use malachite_nz::integer_polynomial::IntegerPolynomial;

assert_eq!(
    IntegerPolynomial::from_str("x^2-3*x+2")
        .unwrap()
        .l2_norm_squared(),
    14u32
);
assert_eq!(
    IntegerPolynomial::from_str("0").unwrap().l2_norm_squared(),
    0u32
);
assert_eq!(
    IntegerPolynomial::from_str("-5").unwrap().l2_norm_squared(),
    25u32
);

This is the dot product of the coefficients with themselves that _fmpz_poly_2norm in fmpz_poly/2norm.c, FLINT 3.6.0, computes before taking the square root.

Source§

type Output = Natural

Source§

impl<'a> Mod<&'a Natural> for IntegerPolynomial

Source§

fn mod_op(self, m: &'a Natural) -> NaturalPolynomial

Divides every coefficient of an IntegerPolynomial by a Natural, keeping the remainders as a NaturalPolynomial, taking the polynomial by value and the modulus by reference.

See the documentation for the Mod implementation on IntegerPolynomial that takes both arguments by value for details, including how negative coefficients are handled and how reducing can lower the degree.

§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 total number of bits in the polynomial’s coefficients.

§Panics

Panics if m is zero.

§Examples
use core::str::FromStr;
use malachite_base::num::arithmetic::traits::Mod;
use malachite_nz::integer_polynomial::IntegerPolynomial;
use malachite_nz::natural::Natural;

// Every coefficient is taken modulo 3, and negative ones become non-negative.
let p = IntegerPolynomial::from_str("x^2-4*x-5").unwrap();
assert_eq!(
    p.clone().mod_op(&Natural::from(3u32)).to_string(),
    "x^2+2*x+1"
);

// Reducing the leading coefficient to zero lowers the degree.
let p = IntegerPolynomial::from_str("-6*x^2+3*x-1").unwrap();
assert_eq!(p.clone().mod_op(&Natural::from(3u32)).to_string(), "2");
Source§

type Output = NaturalPolynomial

Source§

impl<'a> Mod<&'a Natural> for &IntegerPolynomial

Source§

fn mod_op(self, m: &'a Natural) -> NaturalPolynomial

Divides every coefficient of an IntegerPolynomial by a Natural, keeping the remainders as a NaturalPolynomial, taking the polynomial by reference and the modulus by reference.

See the documentation for the Mod implementation on IntegerPolynomial that takes both arguments by value for details, including how negative coefficients are handled and how reducing can lower the degree.

§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 total number of bits in the polynomial’s coefficients.

§Panics

Panics if m is zero.

§Examples
use core::str::FromStr;
use malachite_base::num::arithmetic::traits::Mod;
use malachite_nz::integer_polynomial::IntegerPolynomial;
use malachite_nz::natural::Natural;

// Every coefficient is taken modulo 3, and negative ones become non-negative.
let p = IntegerPolynomial::from_str("x^2-4*x-5").unwrap();
assert_eq!((&p).mod_op(&Natural::from(3u32)).to_string(), "x^2+2*x+1");

// Reducing the leading coefficient to zero lowers the degree.
let p = IntegerPolynomial::from_str("-6*x^2+3*x-1").unwrap();
assert_eq!((&p).mod_op(&Natural::from(3u32)).to_string(), "2");
Source§

type Output = NaturalPolynomial

Source§

impl Mod<Natural> for IntegerPolynomial

Source§

fn mod_op(self, m: Natural) -> NaturalPolynomial

Divides every coefficient of an IntegerPolynomial by a Natural, keeping the remainders as a NaturalPolynomial, taking the polynomial by value and the modulus by value.

Each remainder is taken in $[0, m)$, the way Mod does for Integers, so a negative coefficient $c$ that is not a multiple of $m$ becomes $m - (-c \bmod m)$. The result is therefore reduced modulo $m$, which is to say that mod_is_reduced returns true for it, and every coefficient of the result is congruent to the corresponding coefficient of the input.

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 $-6x^2 + 3x - 1$ modulo $3$ is the constant $2$.

$$ 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 \log n \log\log n)$

$M(n) = O(n \log n)$

where $T$ is time, $M$ is additional memory, and $n$ is the total number of bits in the polynomial’s coefficients.

§Panics

Panics if m is zero.

§Examples
use core::str::FromStr;
use malachite_base::num::arithmetic::traits::Mod;
use malachite_nz::integer_polynomial::IntegerPolynomial;
use malachite_nz::natural::Natural;

// Every coefficient is taken modulo 3, and negative ones become non-negative.
let p = IntegerPolynomial::from_str("x^2-4*x-5").unwrap();
assert_eq!(
    p.clone().mod_op(Natural::from(3u32)).to_string(),
    "x^2+2*x+1"
);

// Reducing the leading coefficient to zero lowers the degree.
let p = IntegerPolynomial::from_str("-6*x^2+3*x-1").unwrap();
assert_eq!(p.clone().mod_op(Natural::from(3u32)).to_string(), "2");
Source§

type Output = NaturalPolynomial

Source§

impl Mod<Natural> for &IntegerPolynomial

Source§

fn mod_op(self, m: Natural) -> NaturalPolynomial

Divides every coefficient of an IntegerPolynomial by a Natural, keeping the remainders as a NaturalPolynomial, taking the polynomial by reference and the modulus by value.

See the documentation for the Mod implementation on IntegerPolynomial that takes both arguments by value for details, including how negative coefficients are handled and how reducing can lower the degree.

§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 total number of bits in the polynomial’s coefficients.

§Panics

Panics if m is zero.

§Examples
use core::str::FromStr;
use malachite_base::num::arithmetic::traits::Mod;
use malachite_nz::integer_polynomial::IntegerPolynomial;
use malachite_nz::natural::Natural;

// Every coefficient is taken modulo 3, and negative ones become non-negative.
let p = IntegerPolynomial::from_str("x^2-4*x-5").unwrap();
assert_eq!((&p).mod_op(Natural::from(3u32)).to_string(), "x^2+2*x+1");

// Reducing the leading coefficient to zero lowers the degree.
let p = IntegerPolynomial::from_str("-6*x^2+3*x-1").unwrap();
assert_eq!((&p).mod_op(Natural::from(3u32)).to_string(), "2");
Source§

type Output = NaturalPolynomial

Source§

impl<T: PrimitiveUnsigned + for<'a> ExactFrom<&'a Natural>> Mod<T> for &IntegerPolynomial
where Natural: From<T>,

Source§

fn mod_op(self, m: T) -> UnsignedPolynomial<T>

Divides every coefficient of an IntegerPolynomial by a value of an unsigned primitive integer type, keeping the remainders as an UnsignedPolynomial with that coefficient type, taking the polynomial by reference.

Each remainder is taken in $[0, m)$, so negative coefficients become non-negative, and every remainder fits in m’s type. Apart from the result’s type, this is the same operation as reducing modulo Natural::from(m); see the documentation for the Mod implementation on IntegerPolynomial that takes both arguments by value for details, including how reducing can lower the degree.

The result is reduced modulo $m$, which is to say that mod_is_reduced returns true for it.

§Worst-case complexity

$T(n) = O(n)$

$M(n) = O(m)$

where $T$ is time, $M$ is additional memory, $n$ is the total number of bits in the polynomial’s coefficients, and $m$ is the number of coefficients.

§Panics

Panics if m is zero.

§Examples
use core::str::FromStr;
use malachite_base::num::arithmetic::traits::Mod;
use malachite_base::unsigned_polynomial::UnsignedPolynomial;
use malachite_nz::integer_polynomial::IntegerPolynomial;

let p = IntegerPolynomial::from_str("-1000000000001*x^2+2000000000003*x-5").unwrap();
let q: UnsignedPolynomial<u8> = (&p).mod_op(7u8);
assert_eq!(q.to_string(), "5*x^2+5*x+2");

// Reducing the leading coefficient to zero lowers the degree.
let p = IntegerPolynomial::from_str("-1024*x^2-3").unwrap();
assert_eq!((&p).mod_op(4u64).to_string(), "1");
Source§

type Output = UnsignedPolynomial<T>

Source§

impl<T: PrimitiveUnsigned + for<'a> ExactFrom<&'a Natural>> Mod<T> for IntegerPolynomial
where Natural: From<T>,

Source§

fn mod_op(self, m: T) -> UnsignedPolynomial<T>

Divides every coefficient of an IntegerPolynomial by a value of an unsigned primitive integer type, keeping the remainders as an UnsignedPolynomial with that coefficient type, taking the polynomial by value.

Taking the polynomial by value saves nothing, since the remainders go into new storage either way. See the documentation for the Mod implementation that takes the polynomial by reference for details.

§Worst-case complexity

$T(n) = O(n)$

$M(n) = O(m)$

where $T$ is time, $M$ is additional memory, $n$ is the total number of bits in the polynomial’s coefficients, and $m$ is the number of coefficients.

§Panics

Panics if m is zero.

§Examples
use core::str::FromStr;
use malachite_base::num::arithmetic::traits::Mod;
use malachite_nz::integer_polynomial::IntegerPolynomial;

let p = IntegerPolynomial::from_str("x^2-4*x-5").unwrap();
assert_eq!(p.mod_op(3u32).to_string(), "x^2+2*x+1");
Source§

type Output = UnsignedPolynomial<T>

Source§

impl ModEvaluate<u64> for &IntegerPolynomial

Source§

fn mod_evaluate(self, x: u64, m: u64) -> u64

Evaluates an IntegerPolynomial at a u64, modulo a u64. The coefficients may be any Integers, and are reduced as the evaluation goes; x must already be reduced modulo m.

$$ f(p, x, m) = \left ( \sum_{i=0}^{n-1} c_i x^i \right ) \bmod m, $$

where $c_i$ is the coefficient of $x^i$ in $p$, $n$ is its length, and the result is in $[0, m)$. The zero polynomial evaluates to 0 everywhere.

Each coefficient is reduced to a word, and the words are then evaluated as by UnsignedPolynomial::mod_evaluate, with Horner’s rule and, for longer polynomials, Shoup’s method.

§Worst-case complexity

$T(n, m) = O(n + m)$

$M(m) = O(m)$

where $T$ is time, $M$ is additional memory, $n$ is the total number of bits of the coefficients, and $m$ is self.len().

§Panics

Panics if m is 0, or if x is greater than or equal to m.

§Examples
use core::str::FromStr;
use malachite_base::polynomial::ModEvaluate;
use malachite_nz::integer_polynomial::IntegerPolynomial;

let p = IntegerPolynomial::from_str("-5*x^2+3*x-7").unwrap();
// -5 * 36 + 3 * 6 - 7 = -169, which is 7 mod 11.
assert_eq!((&p).mod_evaluate(6, 11), 7);
// The coefficients need not be reduced.
let p = IntegerPolynomial::from_str("100*x+1").unwrap();
assert_eq!((&p).mod_evaluate(3, 10), 1);

This is equivalent to fmpz_poly_evaluate_mod from fmpz_poly/mod_evaluate.c, FLINT 3.6.0, except that x must be reduced.

Source§

type Output = u64

The type of the polynomial’s value.
Source§

impl ModPowerOf2 for IntegerPolynomial

Source§

fn mod_power_of_2(self, pow: u64) -> NaturalPolynomial

Divides every coefficient of an IntegerPolynomial by $2^k$, keeping the remainders as a NaturalPolynomial, taking the polynomial by value.

Each remainder is non-negative, as with ModPowerOf2 for Integer: a negative coefficient $c$ becomes $2^k - (-c \bmod 2^k)$ unless it is a multiple of $2^k$. So the result has natural coefficients, and 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$.

$$ 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(n)$

where $T$ is time, $M$ is additional memory, and $n$ is the total number of bits of the coefficients.

§Examples
use core::str::FromStr;
use malachite_base::num::arithmetic::traits::ModPowerOf2;
use malachite_nz::integer_polynomial::IntegerPolynomial;

// Every coefficient is taken modulo 4, and negative ones become non-negative.
assert_eq!(
    IntegerPolynomial::from_str("x^2-3*x-2")
        .unwrap()
        .mod_power_of_2(2)
        .to_string(),
    "x^2+x+2"
);

// Reducing the leading coefficient to zero lowers the degree.
assert_eq!(
    IntegerPolynomial::from_str("-4*x^2+3")
        .unwrap()
        .mod_power_of_2(2)
        .to_string(),
    "3"
);
Source§

type Output = NaturalPolynomial

Source§

impl ModPowerOf2 for &IntegerPolynomial

Source§

fn mod_power_of_2(self, pow: u64) -> NaturalPolynomial

Divides every coefficient of an IntegerPolynomial by $2^k$, keeping the remainders as a NaturalPolynomial, taking the polynomial by reference.

See the documentation for the ModPowerOf2 implementation on IntegerPolynomial for details, including how negative coefficients are handled and 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 total number of bits of the coefficients.

§Examples
use core::str::FromStr;
use malachite_base::num::arithmetic::traits::ModPowerOf2;
use malachite_nz::integer_polynomial::IntegerPolynomial;

// Every coefficient is taken modulo 4, and negative ones become non-negative.
assert_eq!(
    (&IntegerPolynomial::from_str("x^2-3*x-2").unwrap())
        .mod_power_of_2(2)
        .to_string(),
    "x^2+x+2"
);

// Reducing the leading coefficient to zero lowers the degree.
assert_eq!(
    (&IntegerPolynomial::from_str("-4*x^2+3").unwrap())
        .mod_power_of_2(2)
        .to_string(),
    "3"
);
Source§

type Output = NaturalPolynomial

Source§

impl Mul for IntegerPolynomial

Source§

fn mul(self, other: Self) -> Self

Multiplies two IntegerPolynomials, taking both by value.

$$ f(p, q) = pq. $$

The integers have no zero divisors, so the degree of a product of nonzero polynomials is the sum of their degrees.

§Worst-case complexity

$T(n, m) = O(n^{\log_2 3} m \log m \log\log m)$

$M(n, m) = O(n(m + \log n) \log (nm))$

where $T$ is time, $M$ is additional memory, $n$ is the length of the longer polynomial, and $m$ is the largest number of significant bits of any coefficient of either polynomial.

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

assert_eq!(
    (IntegerPolynomial::from_str("x^2-3*x+2").unwrap()
        * IntegerPolynomial::from_str("2*x+5").unwrap())
    .to_string(),
    "2*x^3-x^2-11*x+10"
);
assert_eq!(
    (IntegerPolynomial::from_str("x+1").unwrap()
        * IntegerPolynomial::from_str("x-1").unwrap())
    .to_string(),
    "x^2-1"
);
assert_eq!(
    (IntegerPolynomial::from_str("x+1").unwrap() * IntegerPolynomial::ZERO).to_string(),
    "0"
);

This is equivalent to fmpz_poly_mul from fmpz_poly/mul.c, FLINT 3.6.0.

Source§

type Output = IntegerPolynomial

The resulting type after applying the * operator.
Source§

impl Mul<&IntegerPolynomial> for IntegerPolynomial

Source§

fn mul(self, other: &Self) -> Self

Multiplies two IntegerPolynomials, taking the first by value and the second by reference.

$$ f(p, q) = pq. $$

The integers have no zero divisors, so the degree of a product of nonzero polynomials is the sum of their degrees.

§Worst-case complexity

$T(n, m) = O(n^{\log_2 3} m \log m \log\log m)$

$M(n, m) = O(n(m + \log n) \log (nm))$

where $T$ is time, $M$ is additional memory, $n$ is the length of the longer polynomial, and $m$ is the largest number of significant bits of any coefficient of either polynomial.

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

assert_eq!(
    (IntegerPolynomial::from_str("x^2-3*x+2").unwrap()
        * &IntegerPolynomial::from_str("2*x+5").unwrap())
        .to_string(),
    "2*x^3-x^2-11*x+10"
);
assert_eq!(
    (IntegerPolynomial::from_str("x+1").unwrap()
        * &IntegerPolynomial::from_str("x-1").unwrap())
        .to_string(),
    "x^2-1"
);
assert_eq!(
    (IntegerPolynomial::from_str("x+1").unwrap() * &IntegerPolynomial::ZERO).to_string(),
    "0"
);

This is equivalent to fmpz_poly_mul from fmpz_poly/mul.c, FLINT 3.6.0.

Source§

type Output = IntegerPolynomial

The resulting type after applying the * operator.
Source§

impl Mul<&IntegerPolynomial> for &IntegerPolynomial

Source§

fn mul(self, other: &IntegerPolynomial) -> IntegerPolynomial

Multiplies two IntegerPolynomials, taking both by reference.

$$ f(p, q) = pq. $$

The integers have no zero divisors, so the degree of a product of nonzero polynomials is the sum of their degrees.

§Worst-case complexity

$T(n, m) = O(n^{\log_2 3} m \log m \log\log m)$

$M(n, m) = O(n(m + \log n) \log (nm))$

where $T$ is time, $M$ is additional memory, $n$ is the length of the longer polynomial, and $m$ is the largest number of significant bits of any coefficient of either polynomial.

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

assert_eq!(
    (&IntegerPolynomial::from_str("x^2-3*x+2").unwrap()
        * &IntegerPolynomial::from_str("2*x+5").unwrap())
        .to_string(),
    "2*x^3-x^2-11*x+10"
);
assert_eq!(
    (&IntegerPolynomial::from_str("x+1").unwrap()
        * &IntegerPolynomial::from_str("x-1").unwrap())
        .to_string(),
    "x^2-1"
);
assert_eq!(
    (&IntegerPolynomial::from_str("x+1").unwrap() * &IntegerPolynomial::ZERO).to_string(),
    "0"
);

This is equivalent to fmpz_poly_mul from fmpz_poly/mul.c, FLINT 3.6.0.

Source§

type Output = IntegerPolynomial

The resulting type after applying the * operator.
Source§

impl Mul<IntegerPolynomial> for &IntegerPolynomial

Source§

fn mul(self, other: IntegerPolynomial) -> IntegerPolynomial

Multiplies two IntegerPolynomials, taking the first by reference and the second by value.

$$ f(p, q) = pq. $$

The integers have no zero divisors, so the degree of a product of nonzero polynomials is the sum of their degrees.

§Worst-case complexity

$T(n, m) = O(n^{\log_2 3} m \log m \log\log m)$

$M(n, m) = O(n(m + \log n) \log (nm))$

where $T$ is time, $M$ is additional memory, $n$ is the length of the longer polynomial, and $m$ is the largest number of significant bits of any coefficient of either polynomial.

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

assert_eq!(
    (&IntegerPolynomial::from_str("x^2-3*x+2").unwrap()
        * IntegerPolynomial::from_str("2*x+5").unwrap())
    .to_string(),
    "2*x^3-x^2-11*x+10"
);
assert_eq!(
    (&IntegerPolynomial::from_str("x+1").unwrap()
        * IntegerPolynomial::from_str("x-1").unwrap())
    .to_string(),
    "x^2-1"
);
assert_eq!(
    (&IntegerPolynomial::from_str("x+1").unwrap() * IntegerPolynomial::ZERO).to_string(),
    "0"
);

This is equivalent to fmpz_poly_mul from fmpz_poly/mul.c, FLINT 3.6.0.

Source§

type Output = IntegerPolynomial

The resulting type after applying the * operator.
Source§

impl MulAssign for IntegerPolynomial

Source§

fn mul_assign(&mut self, other: Self)

Multiplies an IntegerPolynomial by another IntegerPolynomial in place, taking the right-hand side by value.

$$ p \gets pq. $$

§Worst-case complexity

$T(n, m) = O(n^{\log_2 3} m \log m \log\log m)$

$M(n, m) = O(n(m + \log n) \log (nm))$

where $T$ is time, $M$ is additional memory, $n$ is the length of the longer polynomial, and $m$ is the largest number of significant bits of any coefficient of either polynomial.

§Examples
use core::str::FromStr;
use malachite_nz::integer_polynomial::IntegerPolynomial;

let mut p = IntegerPolynomial::from_str("x^2-3*x+2").unwrap();
p *= IntegerPolynomial::from_str("2*x+5").unwrap();
assert_eq!(p.to_string(), "2*x^3-x^2-11*x+10");

This is equivalent to fmpz_poly_mul from fmpz_poly/mul.c, FLINT 3.6.0.

Source§

impl MulAssign<&IntegerPolynomial> for IntegerPolynomial

Source§

fn mul_assign(&mut self, other: &Self)

Multiplies an IntegerPolynomial by another IntegerPolynomial in place, taking the right-hand side by reference.

$$ p \gets pq. $$

§Worst-case complexity

$T(n, m) = O(n^{\log_2 3} m \log m \log\log m)$

$M(n, m) = O(n(m + \log n) \log (nm))$

where $T$ is time, $M$ is additional memory, $n$ is the length of the longer polynomial, and $m$ is the largest number of significant bits of any coefficient of either polynomial.

§Examples
use core::str::FromStr;
use malachite_nz::integer_polynomial::IntegerPolynomial;

let mut p = IntegerPolynomial::from_str("x^2-3*x+2").unwrap();
p *= &IntegerPolynomial::from_str("2*x+5").unwrap();
assert_eq!(p.to_string(), "2*x^3-x^2-11*x+10");

This is equivalent to fmpz_poly_mul from fmpz_poly/mul.c, FLINT 3.6.0.

Source§

impl MulPowerOfX for IntegerPolynomial

Source§

fn mul_power_of_x(self, n: u64) -> Self

Multiplies an IntegerPolynomial 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 the total number of bits of the coefficients.

§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_nz::integer_polynomial::IntegerPolynomial;

assert_eq!(
    IntegerPolynomial::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!(
    IntegerPolynomial::from_str("-5")
        .unwrap()
        .mul_power_of_x(1)
        .to_string(),
    "-5*x"
);
assert_eq!(
    IntegerPolynomial::ZERO.mul_power_of_x(3),
    IntegerPolynomial::ZERO
);

This is equivalent to fmpz_poly_shift_left from fmpz_poly/shift_left.c, FLINT 3.6.0.

Source§

type Output = IntegerPolynomial

Source§

impl MulPowerOfX for &IntegerPolynomial

Source§

fn mul_power_of_x(self, n: u64) -> IntegerPolynomial

Multiplies an IntegerPolynomial 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 the total number of bits of the coefficients.

§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_nz::integer_polynomial::IntegerPolynomial;

assert_eq!(
    (&IntegerPolynomial::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!(
    (&IntegerPolynomial::from_str("-5").unwrap())
        .mul_power_of_x(1)
        .to_string(),
    "-5*x"
);
assert_eq!(
    (&IntegerPolynomial::ZERO).mul_power_of_x(3),
    IntegerPolynomial::ZERO
);

This is equivalent to fmpz_poly_shift_left from fmpz_poly/shift_left.c, FLINT 3.6.0.

Source§

type Output = IntegerPolynomial

Source§

impl MulPowerOfXAssign for IntegerPolynomial

Source§

fn mul_power_of_x_assign(&mut self, n: u64)

Multiplies an IntegerPolynomial 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 the total number of bits of the coefficients.

§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_nz::integer_polynomial::IntegerPolynomial;

let mut p = IntegerPolynomial::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 = IntegerPolynomial::from_str("-5").unwrap();
p.mul_power_of_x_assign(1);
assert_eq!(p.to_string(), "-5*x");

let mut p = IntegerPolynomial::ZERO;
p.mul_power_of_x_assign(3);
assert_eq!(p, IntegerPolynomial::ZERO);

This is equivalent to fmpz_poly_shift_left from fmpz_poly/shift_left.c, FLINT 3.6.0.

Source§

impl MulTruncated for IntegerPolynomial

Source§

fn mul_truncated(self, other: Self, len: u64) -> Self

Multiplies two IntegerPolynomials, keeping only the coefficients of $x^i$ for $i$ less than len, taking both by value.

$$ f(p, q, n) = pq \bmod x^n. $$

The polynomials need not already be truncated: this is the product of their images modulo $x^n$, so only the first len coefficients of each are read. The product is trimmed, so when the coefficient of $x^{n-1}$ is zero, the degree is lower still.

§Worst-case complexity

$T(n, m) = O(n^{\log_2 3} m \log m \log\log m)$

$M(n, m) = O(n(m + \log n) \log (nm))$

where $T$ is time, $M$ is additional memory, $n$ is len, and $m$ is the largest number of significant bits of any of the first len coefficients of either polynomial.

§Examples
use core::str::FromStr;
use malachite_base::polynomial::MulTruncated;
use malachite_nz::integer_polynomial::IntegerPolynomial;

assert_eq!(
    (IntegerPolynomial::from_str("x^2-3*x+2").unwrap())
        .mul_truncated(IntegerPolynomial::from_str("2*x+5").unwrap(), 2)
        .to_string(),
    "-11*x+10"
);
// The linear coefficient cancels.
assert_eq!(
    (IntegerPolynomial::from_str("x+1").unwrap())
        .mul_truncated(IntegerPolynomial::from_str("x-1").unwrap(), 2)
        .to_string(),
    "-1"
);

This is equivalent to fmpz_poly_mullow from fmpz_poly/mullow.c, FLINT 3.6.0.

Source§

type Output = IntegerPolynomial

Source§

impl MulTruncated<&IntegerPolynomial> for IntegerPolynomial

Source§

fn mul_truncated(self, other: &Self, len: u64) -> Self

Multiplies two IntegerPolynomials, keeping only the coefficients of $x^i$ for $i$ less than len, taking the first by value and the second by reference.

$$ f(p, q, n) = pq \bmod x^n. $$

The polynomials need not already be truncated: this is the product of their images modulo $x^n$, so only the first len coefficients of each are read. The product is trimmed, so when the coefficient of $x^{n-1}$ is zero, the degree is lower still.

§Worst-case complexity

$T(n, m) = O(n^{\log_2 3} m \log m \log\log m)$

$M(n, m) = O(n(m + \log n) \log (nm))$

where $T$ is time, $M$ is additional memory, $n$ is len, and $m$ is the largest number of significant bits of any of the first len coefficients of either polynomial.

§Examples
use core::str::FromStr;
use malachite_base::polynomial::MulTruncated;
use malachite_nz::integer_polynomial::IntegerPolynomial;

assert_eq!(
    (IntegerPolynomial::from_str("x^2-3*x+2").unwrap())
        .mul_truncated(&IntegerPolynomial::from_str("2*x+5").unwrap(), 2)
        .to_string(),
    "-11*x+10"
);
// The linear coefficient cancels.
assert_eq!(
    (IntegerPolynomial::from_str("x+1").unwrap())
        .mul_truncated(&IntegerPolynomial::from_str("x-1").unwrap(), 2)
        .to_string(),
    "-1"
);

This is equivalent to fmpz_poly_mullow from fmpz_poly/mullow.c, FLINT 3.6.0.

Source§

type Output = IntegerPolynomial

Source§

impl MulTruncated<&IntegerPolynomial> for &IntegerPolynomial

Source§

fn mul_truncated(self, other: &IntegerPolynomial, len: u64) -> IntegerPolynomial

Multiplies two IntegerPolynomials, keeping only the coefficients of $x^i$ for $i$ less than len, taking both by reference.

$$ f(p, q, n) = pq \bmod x^n. $$

The polynomials need not already be truncated: this is the product of their images modulo $x^n$, so only the first len coefficients of each are read. The product is trimmed, so when the coefficient of $x^{n-1}$ is zero, the degree is lower still.

§Worst-case complexity

$T(n, m) = O(n^{\log_2 3} m \log m \log\log m)$

$M(n, m) = O(n(m + \log n) \log (nm))$

where $T$ is time, $M$ is additional memory, $n$ is len, and $m$ is the largest number of significant bits of any of the first len coefficients of either polynomial.

§Examples
use core::str::FromStr;
use malachite_base::polynomial::MulTruncated;
use malachite_nz::integer_polynomial::IntegerPolynomial;

assert_eq!(
    (&IntegerPolynomial::from_str("x^2-3*x+2").unwrap())
        .mul_truncated(&IntegerPolynomial::from_str("2*x+5").unwrap(), 2)
        .to_string(),
    "-11*x+10"
);
// The linear coefficient cancels.
assert_eq!(
    (&IntegerPolynomial::from_str("x+1").unwrap())
        .mul_truncated(&IntegerPolynomial::from_str("x-1").unwrap(), 2)
        .to_string(),
    "-1"
);

This is equivalent to fmpz_poly_mullow from fmpz_poly/mullow.c, FLINT 3.6.0.

Source§

type Output = IntegerPolynomial

Source§

impl MulTruncated<IntegerPolynomial> for &IntegerPolynomial

Source§

fn mul_truncated(self, other: IntegerPolynomial, len: u64) -> IntegerPolynomial

Multiplies two IntegerPolynomials, keeping only the coefficients of $x^i$ for $i$ less than len, taking the first by reference and the second by value.

$$ f(p, q, n) = pq \bmod x^n. $$

The polynomials need not already be truncated: this is the product of their images modulo $x^n$, so only the first len coefficients of each are read. The product is trimmed, so when the coefficient of $x^{n-1}$ is zero, the degree is lower still.

§Worst-case complexity

$T(n, m) = O(n^{\log_2 3} m \log m \log\log m)$

$M(n, m) = O(n(m + \log n) \log (nm))$

where $T$ is time, $M$ is additional memory, $n$ is len, and $m$ is the largest number of significant bits of any of the first len coefficients of either polynomial.

§Examples
use core::str::FromStr;
use malachite_base::polynomial::MulTruncated;
use malachite_nz::integer_polynomial::IntegerPolynomial;

assert_eq!(
    (&IntegerPolynomial::from_str("x^2-3*x+2").unwrap())
        .mul_truncated(IntegerPolynomial::from_str("2*x+5").unwrap(), 2)
        .to_string(),
    "-11*x+10"
);
// The linear coefficient cancels.
assert_eq!(
    (&IntegerPolynomial::from_str("x+1").unwrap())
        .mul_truncated(IntegerPolynomial::from_str("x-1").unwrap(), 2)
        .to_string(),
    "-1"
);

This is equivalent to fmpz_poly_mullow from fmpz_poly/mullow.c, FLINT 3.6.0.

Source§

type Output = IntegerPolynomial

Source§

impl MulTruncatedAssign for IntegerPolynomial

Source§

fn mul_truncated_assign(&mut self, other: Self, len: u64)

Multiplies an IntegerPolynomial by another IntegerPolynomial in place, keeping only the coefficients of $x^i$ for $i$ less than len, taking the right-hand side by value.

$$ p \gets pq \bmod x^n. $$

§Worst-case complexity

$T(n, m) = O(n^{\log_2 3} m \log m \log\log m)$

$M(n, m) = O(n(m + \log n) \log (nm))$

where $T$ is time, $M$ is additional memory, $n$ is len, and $m$ is the largest number of significant bits of any of the first len coefficients of either polynomial.

§Examples
use core::str::FromStr;
use malachite_base::polynomial::MulTruncatedAssign;
use malachite_nz::integer_polynomial::IntegerPolynomial;

let mut p = IntegerPolynomial::from_str("x^2-3*x+2").unwrap();
p.mul_truncated_assign(IntegerPolynomial::from_str("2*x+5").unwrap(), 2);
assert_eq!(p.to_string(), "-11*x+10");

This is equivalent to fmpz_poly_mullow from fmpz_poly/mullow.c, FLINT 3.6.0.

Source§

impl MulTruncatedAssign<&IntegerPolynomial> for IntegerPolynomial

Source§

fn mul_truncated_assign(&mut self, other: &Self, len: u64)

Multiplies an IntegerPolynomial by another IntegerPolynomial in place, keeping only the coefficients of $x^i$ for $i$ less than len, taking the right-hand side by reference.

$$ p \gets pq \bmod x^n. $$

§Worst-case complexity

$T(n, m) = O(n^{\log_2 3} m \log m \log\log m)$

$M(n, m) = O(n(m + \log n) \log (nm))$

where $T$ is time, $M$ is additional memory, $n$ is len, and $m$ is the largest number of significant bits of any of the first len coefficients of either polynomial.

§Examples
use core::str::FromStr;
use malachite_base::polynomial::MulTruncatedAssign;
use malachite_nz::integer_polynomial::IntegerPolynomial;

let mut p = IntegerPolynomial::from_str("x^2-3*x+2").unwrap();
p.mul_truncated_assign(&IntegerPolynomial::from_str("2*x+5").unwrap(), 2);
assert_eq!(p.to_string(), "-11*x+10");

This is equivalent to fmpz_poly_mullow from fmpz_poly/mullow.c, FLINT 3.6.0.

Source§

impl Named for IntegerPolynomial

Source§

const NAME: &'static str = "IntegerPolynomial"

The name of this type, as given by the stringify macro.

See the documentation for impl_named for more details.

Source§

impl Neg for IntegerPolynomial

Source§

fn neg(self) -> Self

Negates an IntegerPolynomial, taking it by value.

$$ f(p) = -p. $$

§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_nz::integer_polynomial::IntegerPolynomial;

let p = IntegerPolynomial::from_str("x^2-3*x+2").unwrap();
assert_eq!((-p).to_string(), "-x^2+3*x-2");
assert_eq!(-IntegerPolynomial::ZERO, IntegerPolynomial::ZERO);

This is equivalent to fmpz_poly_neg from fmpz_poly/neg.c, FLINT 3.6.0.

Source§

type Output = IntegerPolynomial

The resulting type after applying the - operator.
Source§

impl Neg for &IntegerPolynomial

Source§

fn neg(self) -> IntegerPolynomial

Negates an IntegerPolynomial, taking it by reference.

$$ f(p) = -p. $$

§Worst-case complexity

$T(n) = O(n)$

$M(n) = O(n)$

where $T$ is time, $M$ is additional memory, and $n$ is the total number of bits of the coefficients.

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

let p = IntegerPolynomial::from_str("x^2-3*x+2").unwrap();
assert_eq!((-&p).to_string(), "-x^2+3*x-2");
assert_eq!(-&IntegerPolynomial::ZERO, IntegerPolynomial::ZERO);

This is equivalent to fmpz_poly_neg from fmpz_poly/neg.c, FLINT 3.6.0.

Source§

type Output = IntegerPolynomial

The resulting type after applying the - operator.
Source§

impl NegAssign for IntegerPolynomial

Source§

fn neg_assign(&mut self)

Negates an IntegerPolynomial in place.

$$ p \gets -p. $$

§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::arithmetic::traits::NegAssign;
use malachite_nz::integer_polynomial::IntegerPolynomial;

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

impl NthDerivative for IntegerPolynomial

Source§

fn nth_derivative(self, n: u64) -> Self

Computes the $n$th derivative of an IntegerPolynomial, taking it by value.

$$ f(p, n) = p^{(n)} = \sum_{i=n}^d i^{\underline n}a_ix^{i-n}. $$

Here $i^{\underline n} = i(i-1)\cdots(i-n+1)$ is a falling factorial, and $d$ is the degree. The zeroth derivative is the polynomial itself, and a polynomial of degree less than $n$ has $n$th derivative zero.

§Worst-case complexity

$T(b, k) = O(k(b + k \log k))$

$M(b, k) = O(b + k^2 \log k)$

where $T$ is time, $M$ is additional memory, $b$ is the total number of bits of the coefficients, and $k$ is self.len().

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

let p = IntegerPolynomial::from_str("x^4-3*x^3+2*x-5").unwrap();
assert_eq!(p.clone().nth_derivative(2).to_string(), "12*x^2-18*x");
assert_eq!(p.clone().nth_derivative(0).to_string(), "x^4-3*x^3+2*x-5");
assert_eq!(p.nth_derivative(5), IntegerPolynomial::ZERO);

This is equivalent to fmpz_poly_nth_derivative from fmpz_poly/nth_derivative.c, FLINT 3.6.0.

Source§

type Output = IntegerPolynomial

Source§

impl NthDerivative for &IntegerPolynomial

Source§

fn nth_derivative(self, n: u64) -> IntegerPolynomial

Computes the $n$th derivative of an IntegerPolynomial, taking it by reference.

$$ f(p, n) = p^{(n)} = \sum_{i=n}^d i^{\underline n}a_ix^{i-n}. $$

Here $i^{\underline n} = i(i-1)\cdots(i-n+1)$ is a falling factorial, and $d$ is the degree. The zeroth derivative is the polynomial itself, and a polynomial of degree less than $n$ has $n$th derivative zero.

§Worst-case complexity

$T(b, k) = O(k(b + k \log k))$

$M(b, k) = O(b + k^2 \log k)$

where $T$ is time, $M$ is additional memory, $b$ is the total number of bits of the coefficients, and $k$ is self.len().

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

let p = IntegerPolynomial::from_str("x^4-3*x^3+2*x-5").unwrap();
assert_eq!((&p).nth_derivative(2).to_string(), "12*x^2-18*x");
assert_eq!((&p).nth_derivative(0).to_string(), "x^4-3*x^3+2*x-5");
assert_eq!((&p).nth_derivative(5), IntegerPolynomial::ZERO);

This is equivalent to fmpz_poly_nth_derivative from fmpz_poly/nth_derivative.c, FLINT 3.6.0.

Source§

type Output = IntegerPolynomial

Source§

impl NthDerivativeAssign for IntegerPolynomial

Source§

fn nth_derivative_assign(&mut self, n: u64)

Replaces an IntegerPolynomial with its $n$th derivative.

$$ p \gets p^{(n)} = \sum_{i=n}^d i^{\underline n}a_ix^{i-n}. $$

Here $i^{\underline n} = i(i-1)\cdots(i-n+1)$ is a falling factorial, and $d$ is the degree. The zeroth derivative is the polynomial itself, and a polynomial of degree less than $n$ has $n$th derivative zero.

§Worst-case complexity

$T(b, k) = O(k(b + k \log k))$

$M(b, k) = O(b + k^2 \log k)$

where $T$ is time, $M$ is additional memory, $b$ is the total number of bits of the coefficients, and $k$ is self.len().

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

let mut p = IntegerPolynomial::from_str("x^4-3*x^3+2*x-5").unwrap();
p.nth_derivative_assign(2);
assert_eq!(p.to_string(), "12*x^2-18*x");

let mut p = IntegerPolynomial::from_str("x^4-3*x^3+2*x-5").unwrap();
p.nth_derivative_assign(0);
assert_eq!(p.to_string(), "x^4-3*x^3+2*x-5");

let mut p = IntegerPolynomial::from_str("x^4-3*x^3+2*x-5").unwrap();
p.nth_derivative_assign(5);
assert_eq!(p, IntegerPolynomial::ZERO);

This is equivalent to fmpz_poly_nth_derivative from fmpz_poly/nth_derivative.c, FLINT 3.6.0.

Source§

impl Ord for IntegerPolynomial

Source§

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

Compares two IntegerPolynomials 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.

$$ 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, but a higher degree alone does not settle it the way it does over the Naturals. A polynomial of higher degree does dominate one of lower degree, so the difference’s leading coefficient is its own; but that coefficient may be negative, in which case the dominating polynomial runs off to $-\infty$ and is the smaller of the two. So $-x^3 < x$, and the zero polynomial is above every polynomial with a negative leading coefficient and below every polynomial with a positive one. 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 positive one. Restricted to the constant polynomials it is the order on the Integers, 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.

§Worst-case complexity

$T(n) = O(n)$

$M(n) = O(1)$

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

§Examples
use core::str::FromStr;
use malachite_nz::integer_polynomial::IntegerPolynomial;

// A higher degree dominates, and a positive leading coefficient makes it the greater.
assert!(
    IntegerPolynomial::from_str("x^2").unwrap()
        > IntegerPolynomial::from_str("1000000*x").unwrap()
);

// But a dominating polynomial with a negative leading coefficient runs off downwards, so
// it is the smaller one.
assert!(
    IntegerPolynomial::from_str("-x^3").unwrap()
        < IntegerPolynomial::from_str("x").unwrap()
);

// The zero polynomial sits between the two signs.
assert!(
    IntegerPolynomial::from_str("-x").unwrap() < IntegerPolynomial::from_str("0").unwrap()
);
assert!(
    IntegerPolynomial::from_str("0").unwrap() < IntegerPolynomial::from_str("x").unwrap()
);

// At equal degrees the highest coefficient at which they differ decides.
assert!(
    IntegerPolynomial::from_str("-x^2+5").unwrap()
        > IntegerPolynomial::from_str("-2*x^2+1000000").unwrap()
);

// Constant polynomials compare as the numbers they are.
assert!(
    IntegerPolynomial::from_str("-122").unwrap()
        > IntegerPolynomial::from_str("-123").unwrap()
);
1.21.0 (const: unstable) · Source§

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

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

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

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

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

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

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

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

impl PartialEq for IntegerPolynomial

Source§

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

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

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

Inequality operator !=. Read more
Source§

impl PartialEq<GaussianInteger> for IntegerPolynomial

Source§

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

Determines whether an IntegerPolynomial is equal to a GaussianInteger.

The polynomial is equal to the GaussianInteger when it is the constant polynomial with that value, so the zero polynomial is equal to 0 and nothing else, no polynomial is equal to a GaussianInteger with a nonzero imaginary part, and no polynomial of positive degree is equal to any GaussianInteger.

§Worst-case complexity

$T(n) = O(n)$

$M(n) = O(1)$

where $T$ is time, $M$ is additional memory, and $n$ is min(self.coefficient(0).significant_bits(), other.real.significant_bits()).

§Examples

See here.

1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more
Source§

impl PartialEq<Integer> for IntegerPolynomial

Source§

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

Determines whether an IntegerPolynomial is equal to an Integer.

The polynomial is equal to the Integer 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 Integer.

§Worst-case complexity

$T(n) = O(n)$

$M(n) = O(1)$

where $T$ is time, $M$ is additional memory, and $n$ is min(self.coefficient(0).significant_bits(), other.significant_bits()).

§Examples

See here.

1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more
Source§

impl PartialEq<IntegerPolynomial> for GaussianInteger

Source§

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

Determines whether a GaussianInteger is equal to an IntegerPolynomial.

The GaussianInteger is equal to the polynomial when the polynomial is the constant polynomial with that value, so 0 is equal to the zero polynomial, and a GaussianInteger with a nonzero imaginary part is equal to no polynomial.

§Worst-case complexity

$T(n) = O(n)$

$M(n) = O(1)$

where $T$ is time, $M$ is additional memory, and $n$ is min(self.real.significant_bits(), other.coefficient(0).significant_bits()).

§Examples

See here.

1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more
Source§

impl PartialEq<IntegerPolynomial> for Integer

Source§

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

Determines whether an Integer is equal to an IntegerPolynomial.

The Integer 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

$T(n) = O(n)$

$M(n) = O(1)$

where $T$ is time, $M$ is additional memory, and $n$ is min(self.significant_bits(), other.coefficient(0).significant_bits()).

§Examples

See here.

1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more
Source§

impl PartialEq<IntegerPolynomial> for Natural

Source§

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

Determines whether a Natural is equal to an IntegerPolynomial.

The Natural 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

$T(n) = O(n)$

$M(n) = O(1)$

where $T$ is time, $M$ is additional memory, and $n$ is min(self.significant_bits(), other.coefficient(0).significant_bits()).

§Examples

See here.

1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more
Source§

impl PartialEq<IntegerPolynomial> for NaturalPolynomial

Source§

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

Determines whether a NaturalPolynomial is equal to an IntegerPolynomial.

The two are equal when they have the same coefficients, so the zero polynomials are equal.

§Worst-case complexity

$T(n) = O(n)$

$M(n) = O(1)$

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

§Examples

See here.

1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more
Source§

impl PartialEq<IntegerPolynomial> for u8

Source§

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

Determines whether a value of a primitive integer type is equal to an IntegerPolynomial.

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.

1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more
Source§

impl PartialEq<IntegerPolynomial> for u16

Source§

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

Determines whether a value of a primitive integer type is equal to an IntegerPolynomial.

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.

1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more
Source§

impl PartialEq<IntegerPolynomial> for u32

Source§

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

Determines whether a value of a primitive integer type is equal to an IntegerPolynomial.

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.

1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more
Source§

impl PartialEq<IntegerPolynomial> for u64

Source§

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

Determines whether a value of a primitive integer type is equal to an IntegerPolynomial.

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.

1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more
Source§

impl PartialEq<IntegerPolynomial> for u128

Source§

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

Determines whether a value of a primitive integer type is equal to an IntegerPolynomial.

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.

1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more
Source§

impl PartialEq<IntegerPolynomial> for usize

Source§

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

Determines whether a value of a primitive integer type is equal to an IntegerPolynomial.

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.

1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more
Source§

impl PartialEq<IntegerPolynomial> for i8

Source§

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

Determines whether a value of a primitive integer type is equal to an IntegerPolynomial.

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.

1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more
Source§

impl PartialEq<IntegerPolynomial> for i16

Source§

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

Determines whether a value of a primitive integer type is equal to an IntegerPolynomial.

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.

1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more
Source§

impl PartialEq<IntegerPolynomial> for i32

Source§

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

Determines whether a value of a primitive integer type is equal to an IntegerPolynomial.

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.

1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more
Source§

impl PartialEq<IntegerPolynomial> for i64

Source§

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

Determines whether a value of a primitive integer type is equal to an IntegerPolynomial.

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.

1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more
Source§

impl PartialEq<IntegerPolynomial> for i128

Source§

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

Determines whether a value of a primitive integer type is equal to an IntegerPolynomial.

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.

1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more
Source§

impl PartialEq<IntegerPolynomial> for isize

Source§

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

Determines whether a value of a primitive integer type is equal to an IntegerPolynomial.

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.

1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more
Source§

impl<T: PrimitiveUnsigned> PartialEq<IntegerPolynomial> for UnsignedPolynomial<T>
where Integer: PartialEq<T>,

Source§

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

Determines whether an UnsignedPolynomial is equal to an IntegerPolynomial.

The two are equal when they have the same coefficients, so the zero polynomials are equal.

§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. Polynomials of different degrees are compared in constant time.

§Examples

See here.

1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more
Source§

impl PartialEq<Natural> for IntegerPolynomial

Source§

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

Determines whether an IntegerPolynomial is equal to a Natural.

The polynomial is equal to the Natural when it is the constant polynomial with that value, so the zero polynomial is equal to 0 and nothing else, no polynomial with a negative constant term is equal to any Natural, and no polynomial of positive degree is equal to any Natural.

§Worst-case complexity

$T(n) = O(n)$

$M(n) = O(1)$

where $T$ is time, $M$ is additional memory, and $n$ is min(self.coefficient(0).significant_bits(), other.significant_bits()).

§Examples

See here.

1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more
Source§

impl PartialEq<NaturalPolynomial> for IntegerPolynomial

Source§

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

Determines whether an IntegerPolynomial is equal to a NaturalPolynomial.

The two are equal when they have the same coefficients, which, since neither stores trailing zeros, means the same number of coefficients and equal coefficients in each position. So the zero polynomials are equal, and an IntegerPolynomial with a negative coefficient is equal to no NaturalPolynomial.

§Worst-case complexity

$T(n) = O(n)$

$M(n) = O(1)$

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

§Examples

See here.

1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more
Source§

impl<T: PrimitiveUnsigned> PartialEq<UnsignedPolynomial<T>> for IntegerPolynomial
where Integer: PartialEq<T>,

Source§

fn eq(&self, other: &UnsignedPolynomial<T>) -> bool

Determines whether an IntegerPolynomial is equal to an UnsignedPolynomial.

The two are equal when they have the same coefficients, which, since neither stores trailing zeros, means the same number of coefficients and equal coefficients in each position. So the zero polynomials are equal, and an IntegerPolynomial with a negative coefficient, or one too large for T, is equal to no UnsignedPolynomial<T>.

§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. Polynomials of different degrees are compared in constant time.

§Examples

See here.

1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more
Source§

impl PartialEq<i8> for IntegerPolynomial

Source§

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

Determines whether an IntegerPolynomial is equal to a value of a primitive integer 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.

1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more
Source§

impl PartialEq<i16> for IntegerPolynomial

Source§

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

Determines whether an IntegerPolynomial is equal to a value of a primitive integer 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.

1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more
Source§

impl PartialEq<i32> for IntegerPolynomial

Source§

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

Determines whether an IntegerPolynomial is equal to a value of a primitive integer 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.

1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more
Source§

impl PartialEq<i64> for IntegerPolynomial

Source§

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

Determines whether an IntegerPolynomial is equal to a value of a primitive integer 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.

1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more
Source§

impl PartialEq<i128> for IntegerPolynomial

Source§

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

Determines whether an IntegerPolynomial is equal to a value of a primitive integer 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.

1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more
Source§

impl PartialEq<isize> for IntegerPolynomial

Source§

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

Determines whether an IntegerPolynomial is equal to a value of a primitive integer 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.

1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more
Source§

impl PartialEq<u8> for IntegerPolynomial

Source§

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

Determines whether an IntegerPolynomial is equal to a value of a primitive integer 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.

1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more
Source§

impl PartialEq<u16> for IntegerPolynomial

Source§

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

Determines whether an IntegerPolynomial is equal to a value of a primitive integer 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.

1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more
Source§

impl PartialEq<u32> for IntegerPolynomial

Source§

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

Determines whether an IntegerPolynomial is equal to a value of a primitive integer 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.

1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more
Source§

impl PartialEq<u64> for IntegerPolynomial

Source§

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

Determines whether an IntegerPolynomial is equal to a value of a primitive integer 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.

1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more
Source§

impl PartialEq<u128> for IntegerPolynomial

Source§

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

Determines whether an IntegerPolynomial is equal to a value of a primitive integer 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.

1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more
Source§

impl PartialEq<usize> for IntegerPolynomial

Source§

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

Determines whether an IntegerPolynomial is equal to a value of a primitive integer 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.

1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more
Source§

impl PartialOrd for IntegerPolynomial

Source§

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

Compares two IntegerPolynomials.

See the documentation for the Ord implementation.

1.0.0 (const: unstable) · Source§

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

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

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

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

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

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

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

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

impl Polynomial for IntegerPolynomial

Source§

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_nz::integer_polynomial::IntegerPolynomial;

assert_eq!(IntegerPolynomial::one().to_string(), "1");
assert_eq!(IntegerPolynomial::one().degree(), Some(0));
Source§

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_nz::integer_polynomial::IntegerPolynomial;

assert_eq!(IntegerPolynomial::two().to_string(), "2");
assert_eq!(IntegerPolynomial::two().degree(), Some(0));
Source§

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_nz::integer_polynomial::IntegerPolynomial;

assert_eq!(IntegerPolynomial::x().to_string(), "x");
assert_eq!(IntegerPolynomial::x().degree(), Some(1));
Source§

fn from_coefficients_asc(coefficients: Vec<Integer>) -> Self

Converts a Vec of Integers to an IntegerPolynomial.

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::num::basic::traits::{One, Two, Zero};
use malachite_base::polynomial::Polynomial;
use malachite_nz::integer::Integer;
use malachite_nz::integer_polynomial::IntegerPolynomial;

let p = IntegerPolynomial::from_coefficients_asc(vec![
    Integer::TWO,
    Integer::from(3u32),
    Integer::ONE,
]);
assert_eq!(p.to_string(), "x^2+3*x+2");

// The trailing zeros are not part of the polynomial.
let q = IntegerPolynomial::from_coefficients_asc(vec![
    Integer::TWO,
    Integer::from(3u32),
    Integer::ONE,
    Integer::ZERO,
    Integer::ZERO,
]);
assert_eq!(q.to_string(), "x^2+3*x+2");

assert_eq!(
    IntegerPolynomial::from_coefficients_asc(vec![]).to_string(),
    "0"
);
Source§

fn into_coefficients_asc(self) -> Vec<Integer>

Converts an IntegerPolynomial to a Vec of Integers, 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_nz::integer_polynomial::IntegerPolynomial;

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

fn degree(&self) -> Option<u64>

Returns the degree of an IntegerPolynomial.

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_nz::integer_polynomial::IntegerPolynomial;

assert_eq!(IntegerPolynomial::ZERO.degree(), None);
assert_eq!(IntegerPolynomial::from_str("5").unwrap().degree(), Some(0));
assert_eq!(IntegerPolynomial::from_str("x").unwrap().degree(), Some(1));
assert_eq!(
    IntegerPolynomial::from_str("x^2+3*x+2").unwrap().degree(),
    Some(2)
);
Source§

fn len(&self) -> u64

Returns the length of a IntegerPolynomial: 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_nz::integer_polynomial::IntegerPolynomial;

assert_eq!(IntegerPolynomial::ZERO.len(), 0);
assert_eq!(IntegerPolynomial::from_str("-5").unwrap().len(), 1);
assert_eq!(IntegerPolynomial::from_str("x").unwrap().len(), 2);
assert_eq!(IntegerPolynomial::from_str("x^2-3*x+2").unwrap().len(), 3);

This is equivalent to fmpz_poly_length from fmpz_poly.h, FLINT 3.6.0.

Source§

fn coefficient(&self, index: u64) -> &Integer

Returns a reference to one of an IntegerPolynomial’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.

§Worst-case complexity

Constant time and additional memory.

§Examples
use core::str::FromStr;
use malachite_base::polynomial::Polynomial;
use malachite_nz::integer_polynomial::IntegerPolynomial;

let p = IntegerPolynomial::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) -> &Integer

Returns a reference to an IntegerPolynomial’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_nz::integer_polynomial::IntegerPolynomial;

let p = IntegerPolynomial::from_str("7*x^2+3*x+2").unwrap();
assert_eq!(*p.leading_coefficient(), 7);
assert_eq!(*IntegerPolynomial::ZERO.leading_coefficient(), 0);
Source§

fn is_monic(&self) -> bool

Determines whether an IntegerPolynomial 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_nz::integer_polynomial::IntegerPolynomial;

assert!(IntegerPolynomial::from_str("x^2-3*x+2").unwrap().is_monic());
assert!(!IntegerPolynomial::from_str("-x^2+3").unwrap().is_monic());
assert!(!IntegerPolynomial::ZERO.is_monic());
Source§

fn mutate_coefficient<F: FnOnce(&mut Integer) -> T, T>( &mut self, index: u64, f: F, ) -> T

Mutates one of an IntegerPolynomial’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::num::basic::traits::{One, Zero};
use malachite_base::polynomial::Polynomial;
use malachite_nz::integer::Integer;
use malachite_nz::integer_polynomial::IntegerPolynomial;

let mut p = IntegerPolynomial::from_str("x^2+3*x+2").unwrap();

let ret = p.mutate_coefficient(1, |c| {
    *c += Integer::ONE;
    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 += Integer::ONE);
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 = Integer::ZERO);
assert_eq!(p.to_string(), "x^2+4*x+2");
Source§

fn zero_coefficients(&mut self, start: u64, end: u64)

Sets the coefficients of a IntegerPolynomial 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_nz::integer_polynomial::IntegerPolynomial;

let mut p;
p = IntegerPolynomial::from_str("5*x^4-4*x^3+3*x^2-2*x+1").unwrap();
p.zero_coefficients(1, 3);
assert_eq!(p.to_string(), "5*x^4-4*x^3+1");
p = IntegerPolynomial::from_str("5*x^4-4*x^3+3*x^2-2*x+1").unwrap();
p.zero_coefficients(2, 10);
assert_eq!(p.to_string(), "-2*x+1");
p = IntegerPolynomial::from_str("5*x^4-4*x^3+3*x^2-2*x+1").unwrap();
p.zero_coefficients(5, 10);
assert_eq!(p.to_string(), "5*x^4-4*x^3+3*x^2-2*x+1");

This is equivalent to fmpz_poly_zero_coeffs from fmpz_poly/zero_coeffs.c, FLINT 3.6.0.

Source§

fn truncate(&self, len: u64) -> Self

Truncates a IntegerPolynomial 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 the total number of bits of the coefficients that are kept.

§Examples
use core::str::FromStr;
use malachite_base::polynomial::Polynomial;
use malachite_nz::integer_polynomial::IntegerPolynomial;

assert_eq!(
    IntegerPolynomial::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!(
    IntegerPolynomial::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!(
    IntegerPolynomial::from_str("x^3+3*x-4")
        .unwrap()
        .truncate(3)
        .to_string(),
    "3*x-4"
);
assert_eq!(
    IntegerPolynomial::from_str("x^3-2*x^2+3*x-4")
        .unwrap()
        .truncate(0)
        .to_string(),
    "0"
);

This is equivalent to fmpz_poly_set_trunc from fmpz_poly/set_trunc.c, FLINT 3.6.0.

Source§

fn truncate_assign(&mut self, len: u64)

Truncates a IntegerPolynomial 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_nz::integer_polynomial::IntegerPolynomial;

let mut p;
p = IntegerPolynomial::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 = IntegerPolynomial::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 = IntegerPolynomial::from_str("x^3+3*x-4").unwrap();
p.truncate_assign(3);
assert_eq!(p.to_string(), "3*x-4");
p = IntegerPolynomial::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 fmpz_poly_truncate from fmpz_poly/truncate.c, FLINT 3.6.0.

Source§

fn reverse(&self, len: u64) -> Self

Reverses the coefficients of a IntegerPolynomial, 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, m) = O(n + m)$

$M(n, m) = O(n + m)$

where $T$ is time, $M$ is additional memory, $n$ is len, and $m$ is the total number of bits of the coefficients.

§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_nz::integer_polynomial::IntegerPolynomial;

assert_eq!(
    IntegerPolynomial::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!(
    IntegerPolynomial::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!(
    IntegerPolynomial::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!(
    IntegerPolynomial::from_str("x^2-2*x")
        .unwrap()
        .reverse(3)
        .to_string(),
    "-2*x+1"
);

This is equivalent to fmpz_poly_reverse from fmpz_poly/reverse.c, FLINT 3.6.0.

Source§

fn reverse_assign(&mut self, len: u64)

Reverses the coefficients of a IntegerPolynomial, 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_nz::integer_polynomial::IntegerPolynomial;

let mut p;
p = IntegerPolynomial::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 = IntegerPolynomial::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 = IntegerPolynomial::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 = IntegerPolynomial::from_str("x^2-2*x").unwrap();
p.reverse_assign(3);
assert_eq!(p.to_string(), "-2*x+1");

This is equivalent to fmpz_poly_reverse from fmpz_poly/reverse.c, FLINT 3.6.0.

Source§

fn to_string_with<S: VarScheme + ?Sized>(&self, var: Var<'_, S>) -> String

Converts an IntegerPolynomial 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::vars::VarScheme;
use malachite_base::vars::greek::GreekVars;
use malachite_base::vars::indexed::IndexedVars;
use malachite_base::vars::list::ListVars;
use malachite_nz::integer_polynomial::IntegerPolynomial;

let p = IntegerPolynomial::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

Converts an IntegerPolynomial 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::vars::VarScheme;
use malachite_base::vars::greek::GreekVars;
use malachite_base::vars::indexed::IndexedVars;
use malachite_nz::integer_polynomial::IntegerPolynomial;

let p = IntegerPolynomial::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.

variablefragmentrenders 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

Converts an IntegerPolynomial 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::vars::VarScheme;
use malachite_base::vars::greek::GreekVars;
use malachite_base::vars::indexed::IndexedVars;
use malachite_nz::integer_polynomial::IntegerPolynomial;

let p = IntegerPolynomial::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.

variablefragment
αα^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>

Converts a string to an IntegerPolynomial, 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::vars::VarScheme;
use malachite_base::vars::greek::GreekVars;
use malachite_base::vars::list::ListVars;
use malachite_nz::integer_polynomial::IntegerPolynomial;

let p = IntegerPolynomial::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!(
    IntegerPolynomial::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!(IntegerPolynomial::from_string_with(GreekVars.var(0), "β^2").is_none());
Source§

type Coefficient = Integer

The type of a coefficient.
Source§

type CoefficientOutput<'a> = &'a Integer where Self: 'a

Source§

impl Pow<u64> for IntegerPolynomial

Source§

fn pow(self, exp: u64) -> Self

Raises an IntegerPolynomial to a power, taking it by value.

$$ f(p, e) = p^e. $$

The zeroth power of every polynomial, including 0, is 1. Depending on the length of the polynomial, the size of its coefficients, and the exponent, the power is computed by the binomial theorem, by J. C. P. Miller’s recurrence for the coefficients of a power, by an addition chain, or by repeated squaring.

§Worst-case complexity

$T(n, m) = O(n(m + \log n) \log (nm) \log\log (nm))$

$M(n, m) = O(n(m + \log n) \log (nm))$

where $T$ is time, $M$ is additional memory, $n$ is exp times the length of the polynomial, and $m$ is exp times the largest number of significant bits of any of its coefficients.

§Examples
use core::str::FromStr;
use malachite_base::num::arithmetic::traits::Pow;
use malachite_nz::integer_polynomial::IntegerPolynomial;

assert_eq!(
    IntegerPolynomial::from_str("x+1")
        .unwrap()
        .pow(3)
        .to_string(),
    "x^3+3*x^2+3*x+1"
);
assert_eq!(
    IntegerPolynomial::from_str("2*x-1")
        .unwrap()
        .pow(4)
        .to_string(),
    "16*x^4-32*x^3+24*x^2-8*x+1"
);
assert_eq!(
    IntegerPolynomial::from_str("x^2-x")
        .unwrap()
        .pow(0)
        .to_string(),
    "1"
);

This is equivalent to fmpz_poly_pow from fmpz_poly/pow.c, FLINT 3.6.0, except that a factor of $x^k$ is removed before powering, and that the algorithm is chosen by measured criteria, which include addition chains.

Source§

type Output = IntegerPolynomial

Source§

impl Pow<u64> for &IntegerPolynomial

Source§

fn pow(self, exp: u64) -> IntegerPolynomial

Raises an IntegerPolynomial to a power, taking it by reference.

$$ f(p, e) = p^e. $$

The zeroth power of every polynomial, including 0, is 1. Depending on the length of the polynomial, the size of its coefficients, and the exponent, the power is computed by the binomial theorem, by J. C. P. Miller’s recurrence for the coefficients of a power, by an addition chain, or by repeated squaring.

§Worst-case complexity

$T(n, m) = O(n(m + \log n) \log (nm) \log\log (nm))$

$M(n, m) = O(n(m + \log n) \log (nm))$

where $T$ is time, $M$ is additional memory, $n$ is exp times the length of the polynomial, and $m$ is exp times the largest number of significant bits of any of its coefficients.

§Examples
use core::str::FromStr;
use malachite_base::num::arithmetic::traits::Pow;
use malachite_nz::integer_polynomial::IntegerPolynomial;

assert_eq!(
    (&IntegerPolynomial::from_str("x+1").unwrap())
        .pow(3)
        .to_string(),
    "x^3+3*x^2+3*x+1"
);
assert_eq!(
    (&IntegerPolynomial::from_str("2*x-1").unwrap())
        .pow(4)
        .to_string(),
    "16*x^4-32*x^3+24*x^2-8*x+1"
);
assert_eq!(
    (&IntegerPolynomial::from_str("x^2-x").unwrap())
        .pow(0)
        .to_string(),
    "1"
);

This is equivalent to fmpz_poly_pow from fmpz_poly/pow.c, FLINT 3.6.0, except that a factor of $x^k$ is removed before powering, and that the algorithm is chosen by measured criteria, which include addition chains.

Source§

type Output = IntegerPolynomial

Source§

impl PowAssign<u64> for IntegerPolynomial

Source§

fn pow_assign(&mut self, exp: u64)

Raises an IntegerPolynomial to a power in place.

$$ p \gets p^e. $$

The zeroth power of every polynomial, including 0, is 1. Depending on the length of the polynomial, the size of its coefficients, and the exponent, the power is computed by the binomial theorem, by J. C. P. Miller’s recurrence for the coefficients of a power, by an addition chain, or by repeated squaring.

§Worst-case complexity

$T(n, m) = O(n(m + \log n) \log (nm) \log\log (nm))$

$M(n, m) = O(n(m + \log n) \log (nm))$

where $T$ is time, $M$ is additional memory, $n$ is exp times the length of the polynomial, and $m$ is exp times the largest number of significant bits of any of its coefficients.

§Examples
use core::str::FromStr;
use malachite_base::num::arithmetic::traits::PowAssign;
use malachite_nz::integer_polynomial::IntegerPolynomial;

let mut p = IntegerPolynomial::from_str("x+1").unwrap();
p.pow_assign(3);
assert_eq!(p.to_string(), "x^3+3*x^2+3*x+1");

let mut p = IntegerPolynomial::from_str("2*x-1").unwrap();
p.pow_assign(4);
assert_eq!(p.to_string(), "16*x^4-32*x^3+24*x^2-8*x+1");

let mut p = IntegerPolynomial::from_str("x^2-x").unwrap();
p.pow_assign(0);
assert_eq!(p.to_string(), "1");

This is equivalent to fmpz_poly_pow from fmpz_poly/pow.c, FLINT 3.6.0, except that a factor of $x^k$ is removed before powering, and that the algorithm is chosen by measured criteria, which include addition chains.

Source§

impl PowTruncated for IntegerPolynomial

Source§

fn pow_truncated(self, exp: u64, len: u64) -> Self

Raises an IntegerPolynomial to a power, keeping only the coefficients of $x^i$ for $i$ less than len, taking it by value.

$$ f(p, e, n) = p^e \bmod x^n. $$

The polynomial need not already be truncated: this is the power of its image modulo $x^n$, so only its first len coefficients are read. The zeroth power of every polynomial is 1, truncated to 0 when len is 0. The power is computed by repeated truncated squaring and multiplication.

§Worst-case complexity

$T(n, m) = O(n(m + \log n) \log (nm) \log\log (nm))$

$M(n, m) = O(n(m + \log n) \log (nm))$

where $T$ is time, $M$ is additional memory, $n$ is len, and $m$ is exp times the largest number of significant bits of any of the first len coefficients of the polynomial.

§Examples
use core::str::FromStr;
use malachite_base::polynomial::PowTruncated;
use malachite_nz::integer_polynomial::IntegerPolynomial;

assert_eq!(
    (IntegerPolynomial::from_str("x+1").unwrap())
        .pow_truncated(5, 3)
        .to_string(),
    "10*x^2+5*x+1"
);
// The power is a multiple of x^4.
assert_eq!(
    (IntegerPolynomial::from_str("x^2+x").unwrap())
        .pow_truncated(4, 4)
        .to_string(),
    "0"
);

This is equivalent to fmpz_poly_pow_trunc from fmpz_poly/pow_trunc.c, FLINT 3.6.0, except that a factor of $x^k$ is removed before powering, and that the intermediate powers are kept at their own lengths rather than padded to len.

Source§

type Output = IntegerPolynomial

Source§

impl PowTruncated for &IntegerPolynomial

Source§

fn pow_truncated(self, exp: u64, len: u64) -> IntegerPolynomial

Raises an IntegerPolynomial to a power, keeping only the coefficients of $x^i$ for $i$ less than len, taking it by reference.

$$ f(p, e, n) = p^e \bmod x^n. $$

The polynomial need not already be truncated: this is the power of its image modulo $x^n$, so only its first len coefficients are read. The zeroth power of every polynomial is 1, truncated to 0 when len is 0. The power is computed by repeated truncated squaring and multiplication.

§Worst-case complexity

$T(n, m) = O(n(m + \log n) \log (nm) \log\log (nm))$

$M(n, m) = O(n(m + \log n) \log (nm))$

where $T$ is time, $M$ is additional memory, $n$ is len, and $m$ is exp times the largest number of significant bits of any of the first len coefficients of the polynomial.

§Examples
use core::str::FromStr;
use malachite_base::polynomial::PowTruncated;
use malachite_nz::integer_polynomial::IntegerPolynomial;

assert_eq!(
    (&IntegerPolynomial::from_str("x+1").unwrap())
        .pow_truncated(5, 3)
        .to_string(),
    "10*x^2+5*x+1"
);
// The power is a multiple of x^4.
assert_eq!(
    (&IntegerPolynomial::from_str("x^2+x").unwrap())
        .pow_truncated(4, 4)
        .to_string(),
    "0"
);

This is equivalent to fmpz_poly_pow_trunc from fmpz_poly/pow_trunc.c, FLINT 3.6.0, except that a factor of $x^k$ is removed before powering, and that the intermediate powers are kept at their own lengths rather than padded to len.

Source§

type Output = IntegerPolynomial

Source§

impl PowTruncatedAssign for IntegerPolynomial

Source§

fn pow_truncated_assign(&mut self, exp: u64, len: u64)

Raises an IntegerPolynomial to a power in place, keeping only the coefficients of $x^i$ for $i$ less than len.

$$ p \gets p^e \bmod x^n. $$

The polynomial need not already be truncated: this is the power of its image modulo $x^n$, so only its first len coefficients are read. The zeroth power of every polynomial is 1, truncated to 0 when len is 0. The power is computed by repeated truncated squaring and multiplication.

§Worst-case complexity

$T(n, m) = O(n(m + \log n) \log (nm) \log\log (nm))$

$M(n, m) = O(n(m + \log n) \log (nm))$

where $T$ is time, $M$ is additional memory, $n$ is len, and $m$ is exp times the largest number of significant bits of any of the first len coefficients of the polynomial.

§Examples
use core::str::FromStr;
use malachite_base::polynomial::PowTruncatedAssign;
use malachite_nz::integer_polynomial::IntegerPolynomial;

let mut p = IntegerPolynomial::from_str("x+1").unwrap();
p.pow_truncated_assign(5, 3);
assert_eq!(p.to_string(), "10*x^2+5*x+1");

// The power is a multiple of x^4.
let mut p = IntegerPolynomial::from_str("x^2+x").unwrap();
p.pow_truncated_assign(4, 4);
assert_eq!(p.to_string(), "0");

This is equivalent to fmpz_poly_pow_trunc from fmpz_poly/pow_trunc.c, FLINT 3.6.0, except that a factor of $x^k$ is removed before powering, and that the intermediate powers are kept at their own lengths rather than padded to len.

Source§

impl PrimitivePart for IntegerPolynomial

Source§

fn primitive_part(self) -> Self

Computes the primitive part of an IntegerPolynomial, taking the polynomial by value.

This is the polynomial divided by its content, with the sign chosen so that the leading coefficient is non-negative. The sign matters: when the leading coefficient is negative, the content times the primitive part is the negation of the polynomial, and the identity needs the sign of the leading coefficient $\operatorname{lc}(p)$.

$$ p = \operatorname{sgn}(\operatorname{lc}(p)) \operatorname{cont}(p) \operatorname{pp}(p). $$

The primitive part of the zero polynomial is zero.

§Worst-case complexity

$T(n) = O(n (\log n)^2 \log\log n)$

$M(n) = O(1)$

where $T$ is time, $M$ is additional memory, and $n$ is the total number of bits of the coefficients.

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

let p = IntegerPolynomial::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!(
    IntegerPolynomial::ZERO.primitive_part(),
    IntegerPolynomial::ZERO
);

This is equivalent to fmpz_poly_primitive_part from fmpz_poly/primitive_part.c, FLINT 3.6.0.

Source§

type Output = IntegerPolynomial

The type of the primitive part.
Source§

impl PrimitivePart for &IntegerPolynomial

Source§

fn primitive_part(self) -> IntegerPolynomial

Computes the primitive part of an IntegerPolynomial, taking the polynomial by reference.

This is the polynomial divided by its content, with the sign chosen so that the leading coefficient is non-negative. The sign matters: when the leading coefficient is negative, the content times the primitive part is the negation of the polynomial, and the identity needs the sign of the leading coefficient $\operatorname{lc}(p)$.

$$ p = \operatorname{sgn}(\operatorname{lc}(p)) \operatorname{cont}(p) \operatorname{pp}(p). $$

The primitive part of the zero polynomial is zero.

§Worst-case complexity

$T(n) = O(n (\log n)^2 \log\log n)$

$M(n) = O(n)$

where $T$ is time, $M$ is additional memory, and $n$ is the total number of bits of the coefficients.

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

let p = IntegerPolynomial::from_str("-6*x^2+4*x-10").unwrap();
assert_eq!((&p).primitive_part().to_string(), "3*x^2-2*x+5");
assert_eq!(
    (&IntegerPolynomial::ZERO).primitive_part(),
    IntegerPolynomial::ZERO
);

This is equivalent to fmpz_poly_primitive_part from fmpz_poly/primitive_part.c, FLINT 3.6.0.

Source§

type Output = IntegerPolynomial

The type of the primitive part.
Source§

impl PrimitivePartAssign for IntegerPolynomial

Source§

fn primitive_part_assign(&mut self)

Replaces an IntegerPolynomial with its primitive part.

See primitive_part.

§Worst-case complexity

$T(n) = O(n (\log n)^2 \log\log n)$

$M(n) = O(1)$

where $T$ is time, $M$ is additional memory, and $n$ is the total number of bits of the coefficients.

§Examples
use core::str::FromStr;
use malachite_base::polynomial::PrimitivePartAssign;
use malachite_nz::integer_polynomial::IntegerPolynomial;

let mut p = IntegerPolynomial::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<'a> Rem<&'a Integer> for IntegerPolynomial

Source§

fn rem(self, m: &'a Integer) -> Self

Divides every coefficient of an IntegerPolynomial by an Integer, keeping the remainders, taking the polynomial by value and the modulus by reference.

See the documentation for the Rem implementation on IntegerPolynomial that takes both arguments by value for details, including the signs of the remainders and how reducing can lower the degree.

§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 total number of bits in the polynomial’s coefficients.

§Panics

Panics if m is zero.

§Examples
use core::str::FromStr;
use malachite_nz::integer::Integer;
use malachite_nz::integer_polynomial::IntegerPolynomial;

// Every coefficient is taken modulo 3, keeping its sign.
let p = IntegerPolynomial::from_str("x^2-4*x-5").unwrap();
assert_eq!((p.clone() % &Integer::from(3)).to_string(), "x^2-x-2");

// The sign of the modulus makes no difference, and reducing the leading coefficient to zero
// lowers the degree.
let p = IntegerPolynomial::from_str("-6*x^2+3*x-1").unwrap();
assert_eq!((p % &Integer::from(-3)).to_string(), "-1");
Source§

type Output = IntegerPolynomial

The resulting type after applying the % operator.
Source§

impl<'a> Rem<&'a Integer> for &IntegerPolynomial

Source§

fn rem(self, m: &'a Integer) -> IntegerPolynomial

Divides every coefficient of an IntegerPolynomial by an Integer, keeping the remainders, taking the polynomial by reference and the modulus by reference.

See the documentation for the Rem implementation on IntegerPolynomial that takes both arguments by value for details, including the signs of the remainders and how reducing can lower the degree.

§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 total number of bits in the polynomial’s coefficients.

§Panics

Panics if m is zero.

§Examples
use core::str::FromStr;
use malachite_nz::integer::Integer;
use malachite_nz::integer_polynomial::IntegerPolynomial;

// Every coefficient is taken modulo 3, keeping its sign.
let p = IntegerPolynomial::from_str("x^2-4*x-5").unwrap();
assert_eq!((&p % &Integer::from(3)).to_string(), "x^2-x-2");

// The sign of the modulus makes no difference, and reducing the leading coefficient to zero
// lowers the degree.
let p = IntegerPolynomial::from_str("-6*x^2+3*x-1").unwrap();
assert_eq!((&p % &Integer::from(-3)).to_string(), "-1");
// The polynomial is left alone.
assert_eq!(p.to_string(), "-6*x^2+3*x-1");
Source§

type Output = IntegerPolynomial

The resulting type after applying the % operator.
Source§

impl Rem<Integer> for IntegerPolynomial

Source§

fn rem(self, m: Integer) -> Self

Divides every coefficient of an IntegerPolynomial by an Integer, keeping the remainders, taking the polynomial by value and the modulus by value.

Each remainder has the sign of its coefficient and a smaller absolute value than $m$, as with Rem for Integers, so the sign of $m$ makes no difference. This is the remainder of truncating division: with the coefficient-wise quotient $q_i = \operatorname{ sgn}(p_im)\lfloor |p_i/m| \rfloor$, $p = mq + r$ holds exactly. For a remainder that is always non-negative, and a NaturalPolynomial result, use Mod.

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 $-6x^2 + 3x - 1$ modulo $3$ is the constant $-1$.

$$ f(p, m) = r, \quad \text{where} \quad r_i = p_i - m \operatorname{sgn}(p_im) \left \lfloor \left | \frac{p_i}{m} \right | \right \rfloor. $$

§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 total number of bits in the polynomial’s coefficients.

§Panics

Panics if m is zero.

§Examples
use core::str::FromStr;
use malachite_nz::integer::Integer;
use malachite_nz::integer_polynomial::IntegerPolynomial;

// Every coefficient is taken modulo 3, keeping its sign.
let p = IntegerPolynomial::from_str("x^2-4*x-5").unwrap();
assert_eq!((p.clone() % Integer::from(3)).to_string(), "x^2-x-2");

// The sign of the modulus makes no difference, and reducing the leading coefficient to zero
// lowers the degree.
let p = IntegerPolynomial::from_str("-6*x^2+3*x-1").unwrap();
assert_eq!((p % Integer::from(-3)).to_string(), "-1");
Source§

type Output = IntegerPolynomial

The resulting type after applying the % operator.
Source§

impl Rem<Integer> for &IntegerPolynomial

Source§

fn rem(self, m: Integer) -> IntegerPolynomial

Divides every coefficient of an IntegerPolynomial by an Integer, keeping the remainders, taking the polynomial by reference and the modulus by value.

See the documentation for the Rem implementation on IntegerPolynomial that takes both arguments by value for details, including the signs of the remainders and how reducing can lower the degree.

§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 total number of bits in the polynomial’s coefficients.

§Panics

Panics if m is zero.

§Examples
use core::str::FromStr;
use malachite_nz::integer::Integer;
use malachite_nz::integer_polynomial::IntegerPolynomial;

// Every coefficient is taken modulo 3, keeping its sign.
let p = IntegerPolynomial::from_str("x^2-4*x-5").unwrap();
assert_eq!((&p % Integer::from(3)).to_string(), "x^2-x-2");

// The sign of the modulus makes no difference, and reducing the leading coefficient to zero
// lowers the degree.
let p = IntegerPolynomial::from_str("-6*x^2+3*x-1").unwrap();
assert_eq!((&p % Integer::from(-3)).to_string(), "-1");
// The polynomial is left alone.
assert_eq!(p.to_string(), "-6*x^2+3*x-1");
Source§

type Output = IntegerPolynomial

The resulting type after applying the % operator.
Source§

impl<'a> RemAssign<&'a Integer> for IntegerPolynomial

Source§

fn rem_assign(&mut self, m: &'a Integer)

Divides every coefficient of an IntegerPolynomial by an Integer, replacing the polynomial by the one whose coefficients are the remainders, taking the modulus by reference.

See the documentation for the Rem implementation on IntegerPolynomial that takes both arguments by value for details, including the signs of the remainders and how reducing can lower the degree.

§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 total number of bits in the polynomial’s coefficients.

§Panics

Panics if m is zero.

§Examples
use core::str::FromStr;
use malachite_nz::integer::Integer;
use malachite_nz::integer_polynomial::IntegerPolynomial;

let mut p = IntegerPolynomial::from_str("x^2-4*x-5").unwrap();
p %= &Integer::from(3);
assert_eq!(p.to_string(), "x^2-x-2");

let mut p = IntegerPolynomial::from_str("-6*x^2+3*x-1").unwrap();
p %= &Integer::from(-3);
assert_eq!(p.to_string(), "-1");
Source§

impl RemAssign<Integer> for IntegerPolynomial

Source§

fn rem_assign(&mut self, m: Integer)

Divides every coefficient of an IntegerPolynomial by an Integer, replacing the polynomial by the one whose coefficients are the remainders, taking the modulus by value.

See the documentation for the Rem implementation on IntegerPolynomial that takes both arguments by value for details, including the signs of the remainders and how reducing can lower the degree.

§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 total number of bits in the polynomial’s coefficients.

§Panics

Panics if m is zero.

§Examples
use core::str::FromStr;
use malachite_nz::integer::Integer;
use malachite_nz::integer_polynomial::IntegerPolynomial;

let mut p = IntegerPolynomial::from_str("x^2-4*x-5").unwrap();
p %= Integer::from(3);
assert_eq!(p.to_string(), "x^2-x-2");

let mut p = IntegerPolynomial::from_str("-6*x^2+3*x-1").unwrap();
p %= Integer::from(-3);
assert_eq!(p.to_string(), "-1");
Source§

impl RemPowerOf2 for IntegerPolynomial

Source§

fn rem_power_of_2(self, pow: u64) -> Self

Divides every coefficient of an IntegerPolynomial by $2^k$, keeping the remainders, taking the polynomial by value.

Each remainder has the sign of its coefficient and a smaller absolute value than $2^k$, as with RemPowerOf2 for Integers. This is the remainder of truncating division, and the result stays an IntegerPolynomial; for a remainder that is always non-negative, and a NaturalPolynomial result, use ModPowerOf2.

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$.

$$ f(p, k) = r, \quad \text{where} \quad r_i = p_i - 2^k \operatorname{sgn}(p_i) \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 total number of bits of the coefficients.

§Examples
use core::str::FromStr;
use malachite_base::num::arithmetic::traits::RemPowerOf2;
use malachite_nz::integer_polynomial::IntegerPolynomial;

// Every coefficient is taken modulo 4, keeping its sign.
assert_eq!(
    IntegerPolynomial::from_str("x^2-7*x-2")
        .unwrap()
        .rem_power_of_2(2)
        .to_string(),
    "x^2-3*x-2"
);

// Reducing the leading coefficient to zero lowers the degree.
assert_eq!(
    IntegerPolynomial::from_str("-4*x^2-3")
        .unwrap()
        .rem_power_of_2(2)
        .to_string(),
    "-3"
);
Source§

type Output = IntegerPolynomial

Source§

impl RemPowerOf2 for &IntegerPolynomial

Source§

fn rem_power_of_2(self, pow: u64) -> IntegerPolynomial

Divides every coefficient of an IntegerPolynomial by $2^k$, keeping the remainders, taking the polynomial by reference.

See the documentation for the RemPowerOf2 implementation on IntegerPolynomial for details, including the signs of the remainders and 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 total number of bits of the coefficients.

§Examples
use core::str::FromStr;
use malachite_base::num::arithmetic::traits::RemPowerOf2;
use malachite_nz::integer_polynomial::IntegerPolynomial;

// Every coefficient is taken modulo 4, keeping its sign.
assert_eq!(
    (&IntegerPolynomial::from_str("x^2-7*x-2").unwrap())
        .rem_power_of_2(2)
        .to_string(),
    "x^2-3*x-2"
);

// Reducing the leading coefficient to zero lowers the degree.
assert_eq!(
    (&IntegerPolynomial::from_str("-4*x^2-3").unwrap())
        .rem_power_of_2(2)
        .to_string(),
    "-3"
);
Source§

type Output = IntegerPolynomial

Source§

impl RemPowerOf2Assign for IntegerPolynomial

Source§

fn rem_power_of_2_assign(&mut self, pow: u64)

Divides every coefficient of an IntegerPolynomial by $2^k$, replacing the polynomial by the one whose coefficients are the remainders.

See the documentation for the RemPowerOf2 implementation on IntegerPolynomial for details, including the signs of the remainders and 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 total number of bits of the coefficients.

§Examples
use core::str::FromStr;
use malachite_base::num::arithmetic::traits::RemPowerOf2Assign;
use malachite_nz::integer_polynomial::IntegerPolynomial;

let mut p = IntegerPolynomial::from_str("x^2-7*x-2").unwrap();
p.rem_power_of_2_assign(2);
assert_eq!(p.to_string(), "x^2-3*x-2");

let mut p = IntegerPolynomial::from_str("-4*x^2-3").unwrap();
p.rem_power_of_2_assign(2);
assert_eq!(p.to_string(), "-3");
Source§

impl Shl<u8> for IntegerPolynomial

Source§

fn shl(self, bits: u8) -> IntegerPolynomial

Left-shifts an IntegerPolynomial (multiplies it by a power of 2), taking it by value. Every coefficient is shifted.

$f(p, k) = 2^kp$.

§Worst-case complexity

$T(n, m, k) = O(n + km)$

$M(n, m, k) = O(n + km)$

where $T$ is time, $M$ is additional memory, $n$ is the total number of bits of the coefficients, $m$ is bits, and $k$ is self.len().

§Examples

See here.

Source§

type Output = IntegerPolynomial

The resulting type after applying the << operator.
Source§

impl Shl<u8> for &IntegerPolynomial

Source§

fn shl(self, bits: u8) -> IntegerPolynomial

Left-shifts an IntegerPolynomial (multiplies it by a power of 2), taking it by reference. Every coefficient is shifted.

$f(p, k) = 2^kp$.

§Worst-case complexity

$T(n, m, k) = O(n + km)$

$M(n, m, k) = O(n + km)$

where $T$ is time, $M$ is additional memory, $n$ is the total number of bits of the coefficients, $m$ is bits, and $k$ is self.len().

§Examples

See here.

Source§

type Output = IntegerPolynomial

The resulting type after applying the << operator.
Source§

impl Shl<u16> for IntegerPolynomial

Source§

fn shl(self, bits: u16) -> IntegerPolynomial

Left-shifts an IntegerPolynomial (multiplies it by a power of 2), taking it by value. Every coefficient is shifted.

$f(p, k) = 2^kp$.

§Worst-case complexity

$T(n, m, k) = O(n + km)$

$M(n, m, k) = O(n + km)$

where $T$ is time, $M$ is additional memory, $n$ is the total number of bits of the coefficients, $m$ is bits, and $k$ is self.len().

§Examples

See here.

Source§

type Output = IntegerPolynomial

The resulting type after applying the << operator.
Source§

impl Shl<u16> for &IntegerPolynomial

Source§

fn shl(self, bits: u16) -> IntegerPolynomial

Left-shifts an IntegerPolynomial (multiplies it by a power of 2), taking it by reference. Every coefficient is shifted.

$f(p, k) = 2^kp$.

§Worst-case complexity

$T(n, m, k) = O(n + km)$

$M(n, m, k) = O(n + km)$

where $T$ is time, $M$ is additional memory, $n$ is the total number of bits of the coefficients, $m$ is bits, and $k$ is self.len().

§Examples

See here.

Source§

type Output = IntegerPolynomial

The resulting type after applying the << operator.
Source§

impl Shl<u32> for IntegerPolynomial

Source§

fn shl(self, bits: u32) -> IntegerPolynomial

Left-shifts an IntegerPolynomial (multiplies it by a power of 2), taking it by value. Every coefficient is shifted.

$f(p, k) = 2^kp$.

§Worst-case complexity

$T(n, m, k) = O(n + km)$

$M(n, m, k) = O(n + km)$

where $T$ is time, $M$ is additional memory, $n$ is the total number of bits of the coefficients, $m$ is bits, and $k$ is self.len().

§Examples

See here.

Source§

type Output = IntegerPolynomial

The resulting type after applying the << operator.
Source§

impl Shl<u32> for &IntegerPolynomial

Source§

fn shl(self, bits: u32) -> IntegerPolynomial

Left-shifts an IntegerPolynomial (multiplies it by a power of 2), taking it by reference. Every coefficient is shifted.

$f(p, k) = 2^kp$.

§Worst-case complexity

$T(n, m, k) = O(n + km)$

$M(n, m, k) = O(n + km)$

where $T$ is time, $M$ is additional memory, $n$ is the total number of bits of the coefficients, $m$ is bits, and $k$ is self.len().

§Examples

See here.

Source§

type Output = IntegerPolynomial

The resulting type after applying the << operator.
Source§

impl Shl<u64> for IntegerPolynomial

Source§

fn shl(self, bits: u64) -> IntegerPolynomial

Left-shifts an IntegerPolynomial (multiplies it by a power of 2), taking it by value. Every coefficient is shifted.

$f(p, k) = 2^kp$.

§Worst-case complexity

$T(n, m, k) = O(n + km)$

$M(n, m, k) = O(n + km)$

where $T$ is time, $M$ is additional memory, $n$ is the total number of bits of the coefficients, $m$ is bits, and $k$ is self.len().

§Examples

See here.

Source§

type Output = IntegerPolynomial

The resulting type after applying the << operator.
Source§

impl Shl<u64> for &IntegerPolynomial

Source§

fn shl(self, bits: u64) -> IntegerPolynomial

Left-shifts an IntegerPolynomial (multiplies it by a power of 2), taking it by reference. Every coefficient is shifted.

$f(p, k) = 2^kp$.

§Worst-case complexity

$T(n, m, k) = O(n + km)$

$M(n, m, k) = O(n + km)$

where $T$ is time, $M$ is additional memory, $n$ is the total number of bits of the coefficients, $m$ is bits, and $k$ is self.len().

§Examples

See here.

Source§

type Output = IntegerPolynomial

The resulting type after applying the << operator.
Source§

impl Shl<u128> for IntegerPolynomial

Source§

fn shl(self, bits: u128) -> IntegerPolynomial

Left-shifts an IntegerPolynomial (multiplies it by a power of 2), taking it by value. Every coefficient is shifted.

$f(p, k) = 2^kp$.

§Worst-case complexity

$T(n, m, k) = O(n + km)$

$M(n, m, k) = O(n + km)$

where $T$ is time, $M$ is additional memory, $n$ is the total number of bits of the coefficients, $m$ is bits, and $k$ is self.len().

§Examples

See here.

Source§

type Output = IntegerPolynomial

The resulting type after applying the << operator.
Source§

impl Shl<u128> for &IntegerPolynomial

Source§

fn shl(self, bits: u128) -> IntegerPolynomial

Left-shifts an IntegerPolynomial (multiplies it by a power of 2), taking it by reference. Every coefficient is shifted.

$f(p, k) = 2^kp$.

§Worst-case complexity

$T(n, m, k) = O(n + km)$

$M(n, m, k) = O(n + km)$

where $T$ is time, $M$ is additional memory, $n$ is the total number of bits of the coefficients, $m$ is bits, and $k$ is self.len().

§Examples

See here.

Source§

type Output = IntegerPolynomial

The resulting type after applying the << operator.
Source§

impl Shl<usize> for IntegerPolynomial

Source§

fn shl(self, bits: usize) -> IntegerPolynomial

Left-shifts an IntegerPolynomial (multiplies it by a power of 2), taking it by value. Every coefficient is shifted.

$f(p, k) = 2^kp$.

§Worst-case complexity

$T(n, m, k) = O(n + km)$

$M(n, m, k) = O(n + km)$

where $T$ is time, $M$ is additional memory, $n$ is the total number of bits of the coefficients, $m$ is bits, and $k$ is self.len().

§Examples

See here.

Source§

type Output = IntegerPolynomial

The resulting type after applying the << operator.
Source§

impl Shl<usize> for &IntegerPolynomial

Source§

fn shl(self, bits: usize) -> IntegerPolynomial

Left-shifts an IntegerPolynomial (multiplies it by a power of 2), taking it by reference. Every coefficient is shifted.

$f(p, k) = 2^kp$.

§Worst-case complexity

$T(n, m, k) = O(n + km)$

$M(n, m, k) = O(n + km)$

where $T$ is time, $M$ is additional memory, $n$ is the total number of bits of the coefficients, $m$ is bits, and $k$ is self.len().

§Examples

See here.

Source§

type Output = IntegerPolynomial

The resulting type after applying the << operator.
Source§

impl ShlAssign<u8> for IntegerPolynomial

Source§

fn shl_assign(&mut self, bits: u8)

Left-shifts an IntegerPolynomial (multiplies it by a power of 2), in place. Every coefficient is shifted.

$p \gets 2^kp$.

§Worst-case complexity

$T(n, m, k) = O(n + km)$

$M(n, m, k) = O(n + km)$

where $T$ is time, $M$ is additional memory, $n$ is the total number of bits of the coefficients, $m$ is bits, and $k$ is self.len().

§Examples

See here.

Source§

impl ShlAssign<u16> for IntegerPolynomial

Source§

fn shl_assign(&mut self, bits: u16)

Left-shifts an IntegerPolynomial (multiplies it by a power of 2), in place. Every coefficient is shifted.

$p \gets 2^kp$.

§Worst-case complexity

$T(n, m, k) = O(n + km)$

$M(n, m, k) = O(n + km)$

where $T$ is time, $M$ is additional memory, $n$ is the total number of bits of the coefficients, $m$ is bits, and $k$ is self.len().

§Examples

See here.

Source§

impl ShlAssign<u32> for IntegerPolynomial

Source§

fn shl_assign(&mut self, bits: u32)

Left-shifts an IntegerPolynomial (multiplies it by a power of 2), in place. Every coefficient is shifted.

$p \gets 2^kp$.

§Worst-case complexity

$T(n, m, k) = O(n + km)$

$M(n, m, k) = O(n + km)$

where $T$ is time, $M$ is additional memory, $n$ is the total number of bits of the coefficients, $m$ is bits, and $k$ is self.len().

§Examples

See here.

Source§

impl ShlAssign<u64> for IntegerPolynomial

Source§

fn shl_assign(&mut self, bits: u64)

Left-shifts an IntegerPolynomial (multiplies it by a power of 2), in place. Every coefficient is shifted.

$p \gets 2^kp$.

§Worst-case complexity

$T(n, m, k) = O(n + km)$

$M(n, m, k) = O(n + km)$

where $T$ is time, $M$ is additional memory, $n$ is the total number of bits of the coefficients, $m$ is bits, and $k$ is self.len().

§Examples

See here.

Source§

impl ShlAssign<u128> for IntegerPolynomial

Source§

fn shl_assign(&mut self, bits: u128)

Left-shifts an IntegerPolynomial (multiplies it by a power of 2), in place. Every coefficient is shifted.

$p \gets 2^kp$.

§Worst-case complexity

$T(n, m, k) = O(n + km)$

$M(n, m, k) = O(n + km)$

where $T$ is time, $M$ is additional memory, $n$ is the total number of bits of the coefficients, $m$ is bits, and $k$ is self.len().

§Examples

See here.

Source§

impl ShlAssign<usize> for IntegerPolynomial

Source§

fn shl_assign(&mut self, bits: usize)

Left-shifts an IntegerPolynomial (multiplies it by a power of 2), in place. Every coefficient is shifted.

$p \gets 2^kp$.

§Worst-case complexity

$T(n, m, k) = O(n + km)$

$M(n, m, k) = O(n + km)$

where $T$ is time, $M$ is additional memory, $n$ is the total number of bits of the coefficients, $m$ is bits, and $k$ is self.len().

§Examples

See here.

Source§

impl Square for IntegerPolynomial

Source§

fn square(self) -> Self

Squares an IntegerPolynomial, taking it by value.

$$ f(p) = p^2. $$

Squaring takes roughly half the coefficient multiplications of multiplying two different polynomials of the same length.

§Worst-case complexity

$T(n, m) = O(n(m + \log n) \log (nm) \log\log (nm))$

$M(n, m) = O(n(m + \log n) \log (nm))$

where $T$ is time, $M$ is additional memory, $n$ is the length of the polynomial, and $m$ is the largest number of significant bits of any of its coefficients.

§Examples
use core::str::FromStr;
use malachite_base::num::arithmetic::traits::Square;
use malachite_nz::integer_polynomial::IntegerPolynomial;

assert_eq!(
    (IntegerPolynomial::from_str("x^2-3*x+2").unwrap())
        .square()
        .to_string(),
    "x^4-6*x^3+13*x^2-12*x+4"
);
assert_eq!(
    (IntegerPolynomial::from_str("-x+1").unwrap())
        .square()
        .to_string(),
    "x^2-2*x+1"
);

This is equivalent to fmpz_poly_sqr from fmpz_poly/sqr.c, FLINT 3.6.0.

Source§

type Output = IntegerPolynomial

Source§

impl Square for &IntegerPolynomial

Source§

fn square(self) -> IntegerPolynomial

Squares an IntegerPolynomial, taking it by reference.

$$ f(p) = p^2. $$

Squaring takes roughly half the coefficient multiplications of multiplying two different polynomials of the same length.

§Worst-case complexity

$T(n, m) = O(n(m + \log n) \log (nm) \log\log (nm))$

$M(n, m) = O(n(m + \log n) \log (nm))$

where $T$ is time, $M$ is additional memory, $n$ is the length of the polynomial, and $m$ is the largest number of significant bits of any of its coefficients.

§Examples
use core::str::FromStr;
use malachite_base::num::arithmetic::traits::Square;
use malachite_nz::integer_polynomial::IntegerPolynomial;

assert_eq!(
    (&IntegerPolynomial::from_str("x^2-3*x+2").unwrap())
        .square()
        .to_string(),
    "x^4-6*x^3+13*x^2-12*x+4"
);
assert_eq!(
    (&IntegerPolynomial::from_str("-x+1").unwrap())
        .square()
        .to_string(),
    "x^2-2*x+1"
);

This is equivalent to fmpz_poly_sqr from fmpz_poly/sqr.c, FLINT 3.6.0.

Source§

type Output = IntegerPolynomial

Source§

impl SquareAssign for IntegerPolynomial

Source§

fn square_assign(&mut self)

Squares an IntegerPolynomial in place.

$$ p \gets p^2. $$

§Worst-case complexity

$T(n, m) = O(n(m + \log n) \log (nm) \log\log (nm))$

$M(n, m) = O(n(m + \log n) \log (nm))$

where $T$ is time, $M$ is additional memory, $n$ is the length of the polynomial, and $m$ is the largest number of significant bits of any of its coefficients.

§Examples
use core::str::FromStr;
use malachite_base::num::arithmetic::traits::SquareAssign;
use malachite_nz::integer_polynomial::IntegerPolynomial;

let mut p = IntegerPolynomial::from_str("x^2-3*x+2").unwrap();
p.square_assign();
assert_eq!(p.to_string(), "x^4-6*x^3+13*x^2-12*x+4");

This is equivalent to fmpz_poly_sqr from fmpz_poly/sqr.c, FLINT 3.6.0.

Source§

impl SquareTruncated for IntegerPolynomial

Source§

fn square_truncated(self, len: u64) -> Self

Squares an IntegerPolynomial, keeping only the coefficients of $x^i$ for $i$ less than len, taking it by value.

$$ f(p, n) = p^2 \bmod x^n. $$

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, m) = O(n(m + \log n) \log (nm) \log\log (nm))$

$M(n, m) = O(n(m + \log n) \log (nm))$

where $T$ is time, $M$ is additional memory, $n$ is len, and $m$ is the largest number of significant bits of any of the first len coefficients of the polynomial.

§Examples
use core::str::FromStr;
use malachite_base::polynomial::SquareTruncated;
use malachite_nz::integer_polynomial::IntegerPolynomial;

assert_eq!(
    (IntegerPolynomial::from_str("x^2-3*x+2").unwrap())
        .square_truncated(3)
        .to_string(),
    "13*x^2-12*x+4"
);
// The cross terms combine with the square of the linear coefficient.
assert_eq!(
    (IntegerPolynomial::from_str("x^2+x-1").unwrap())
        .square_truncated(3)
        .to_string(),
    "-x^2-2*x+1"
);

This is equivalent to fmpz_poly_sqrlow from fmpz_poly/sqrlow.c, FLINT 3.6.0.

Source§

type Output = IntegerPolynomial

Source§

impl SquareTruncated for &IntegerPolynomial

Source§

fn square_truncated(self, len: u64) -> IntegerPolynomial

Squares an IntegerPolynomial, keeping only the coefficients of $x^i$ for $i$ less than len, taking it by reference.

$$ f(p, n) = p^2 \bmod x^n. $$

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, m) = O(n(m + \log n) \log (nm) \log\log (nm))$

$M(n, m) = O(n(m + \log n) \log (nm))$

where $T$ is time, $M$ is additional memory, $n$ is len, and $m$ is the largest number of significant bits of any of the first len coefficients of the polynomial.

§Examples
use core::str::FromStr;
use malachite_base::polynomial::SquareTruncated;
use malachite_nz::integer_polynomial::IntegerPolynomial;

assert_eq!(
    (&IntegerPolynomial::from_str("x^2-3*x+2").unwrap())
        .square_truncated(3)
        .to_string(),
    "13*x^2-12*x+4"
);
// The cross terms combine with the square of the linear coefficient.
assert_eq!(
    (&IntegerPolynomial::from_str("x^2+x-1").unwrap())
        .square_truncated(3)
        .to_string(),
    "-x^2-2*x+1"
);

This is equivalent to fmpz_poly_sqrlow from fmpz_poly/sqrlow.c, FLINT 3.6.0.

Source§

type Output = IntegerPolynomial

Source§

impl SquareTruncatedAssign for IntegerPolynomial

Source§

fn square_truncated_assign(&mut self, len: u64)

Squares an IntegerPolynomial in place, keeping only the coefficients of $x^i$ for $i$ less than len.

$$ p \gets p^2 \bmod x^n. $$

§Worst-case complexity

$T(n, m) = O(n(m + \log n) \log (nm) \log\log (nm))$

$M(n, m) = O(n(m + \log n) \log (nm))$

where $T$ is time, $M$ is additional memory, $n$ is len, and $m$ is the largest number of significant bits of any of the first len coefficients of the polynomial.

§Examples
use core::str::FromStr;
use malachite_base::polynomial::SquareTruncatedAssign;
use malachite_nz::integer_polynomial::IntegerPolynomial;

let mut p = IntegerPolynomial::from_str("x^2-3*x+2").unwrap();
p.square_truncated_assign(3);
assert_eq!(p.to_string(), "13*x^2-12*x+4");

This is equivalent to fmpz_poly_sqrlow from fmpz_poly/sqrlow.c, FLINT 3.6.0.

Source§

impl StructuralPartialEq for IntegerPolynomial

Source§

impl Sub for IntegerPolynomial

Source§

fn sub(self, other: Self) -> Self

Subtracts two IntegerPolynomials, taking both by value.

$$ f(p, q) = p - q. $$

When the two polynomials have the same degree, their leading coefficients can cancel, 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 total number of bits of the coefficients of both polynomials.

§Examples
use core::str::FromStr;
use malachite_nz::integer_polynomial::IntegerPolynomial;

assert_eq!(
    (IntegerPolynomial::from_str("x^2+x").unwrap()
        - IntegerPolynomial::from_str("x^2-1").unwrap())
    .to_string(),
    "x+1"
);
// A longer subtrahend is negated.
assert_eq!(
    (IntegerPolynomial::from_str("3*x+1").unwrap()
        - IntegerPolynomial::from_str("x^2").unwrap())
    .to_string(),
    "-x^2+3*x+1"
);

This is equivalent to fmpz_poly_sub from fmpz_poly/sub.c, FLINT 3.6.0.

Source§

type Output = IntegerPolynomial

The resulting type after applying the - operator.
Source§

impl Sub<&IntegerPolynomial> for IntegerPolynomial

Source§

fn sub(self, other: &Self) -> Self

Subtracts two IntegerPolynomials, taking the first by value and the second by reference.

$$ f(p, q) = p - q. $$

When the two polynomials have the same degree, their leading coefficients can cancel, 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 total number of bits of the coefficients of both polynomials.

§Examples
use core::str::FromStr;
use malachite_nz::integer_polynomial::IntegerPolynomial;

assert_eq!(
    (IntegerPolynomial::from_str("x^2+x").unwrap()
        - &IntegerPolynomial::from_str("x^2-1").unwrap())
        .to_string(),
    "x+1"
);
// A longer subtrahend is negated.
assert_eq!(
    (IntegerPolynomial::from_str("3*x+1").unwrap()
        - &IntegerPolynomial::from_str("x^2").unwrap())
        .to_string(),
    "-x^2+3*x+1"
);

This is equivalent to fmpz_poly_sub from fmpz_poly/sub.c, FLINT 3.6.0.

Source§

type Output = IntegerPolynomial

The resulting type after applying the - operator.
Source§

impl Sub<&IntegerPolynomial> for &IntegerPolynomial

Source§

fn sub(self, other: &IntegerPolynomial) -> IntegerPolynomial

Subtracts two IntegerPolynomials, taking both by reference.

$$ f(p, q) = p - q. $$

When the two polynomials have the same degree, their leading coefficients can cancel, 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 total number of bits of the coefficients of both polynomials.

§Examples
use core::str::FromStr;
use malachite_nz::integer_polynomial::IntegerPolynomial;

assert_eq!(
    (&IntegerPolynomial::from_str("x^2+x").unwrap()
        - &IntegerPolynomial::from_str("x^2-1").unwrap())
        .to_string(),
    "x+1"
);
// A longer subtrahend is negated.
assert_eq!(
    (&IntegerPolynomial::from_str("3*x+1").unwrap()
        - &IntegerPolynomial::from_str("x^2").unwrap())
        .to_string(),
    "-x^2+3*x+1"
);

This is equivalent to fmpz_poly_sub from fmpz_poly/sub.c, FLINT 3.6.0.

Source§

type Output = IntegerPolynomial

The resulting type after applying the - operator.
Source§

impl Sub<IntegerPolynomial> for &IntegerPolynomial

Source§

fn sub(self, other: IntegerPolynomial) -> IntegerPolynomial

Subtracts two IntegerPolynomials, taking the first by reference and the second by value.

$$ f(p, q) = p - q. $$

When the two polynomials have the same degree, their leading coefficients can cancel, 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 total number of bits of the coefficients of both polynomials.

§Examples
use core::str::FromStr;
use malachite_nz::integer_polynomial::IntegerPolynomial;

assert_eq!(
    (&IntegerPolynomial::from_str("x^2+x").unwrap()
        - IntegerPolynomial::from_str("x^2-1").unwrap())
    .to_string(),
    "x+1"
);
// A longer subtrahend is negated.
assert_eq!(
    (&IntegerPolynomial::from_str("3*x+1").unwrap()
        - IntegerPolynomial::from_str("x^2").unwrap())
    .to_string(),
    "-x^2+3*x+1"
);

This is equivalent to fmpz_poly_sub from fmpz_poly/sub.c, FLINT 3.6.0.

Source§

type Output = IntegerPolynomial

The resulting type after applying the - operator.
Source§

impl SubAssign for IntegerPolynomial

Source§

fn sub_assign(&mut self, other: Self)

Subtracts another IntegerPolynomial from an IntegerPolynomial in place, taking the right-hand side by value.

$$ p \gets p - q. $$

§Worst-case complexity

$T(n) = O(n)$

$M(n) = O(n)$

where $T$ is time, $M$ is additional memory, and $n$ is the total number of bits of the coefficients of both polynomials.

§Examples
use core::str::FromStr;
use malachite_nz::integer_polynomial::IntegerPolynomial;

let mut p = IntegerPolynomial::from_str("x^2+x").unwrap();
p -= IntegerPolynomial::from_str("x^2-1").unwrap();
assert_eq!(p.to_string(), "x+1");
Source§

impl SubAssign<&IntegerPolynomial> for IntegerPolynomial

Source§

fn sub_assign(&mut self, other: &Self)

Subtracts another IntegerPolynomial from an IntegerPolynomial in place, taking the right-hand side by reference.

$$ p \gets p - q. $$

§Worst-case complexity

$T(n) = O(n)$

$M(n) = O(n)$

where $T$ is time, $M$ is additional memory, and $n$ is the total number of bits of the coefficients of both polynomials.

§Examples
use core::str::FromStr;
use malachite_nz::integer_polynomial::IntegerPolynomial;

let mut p = IntegerPolynomial::from_str("x^2+x").unwrap();
p -= &IntegerPolynomial::from_str("x^2-1").unwrap();
assert_eq!(p.to_string(), "x+1");
Source§

impl SubTruncated for IntegerPolynomial

Source§

fn sub_truncated(self, other: Self, len: u64) -> Self

Subtracts one IntegerPolynomial from another, keeping only the coefficients of $x^i$ for $i$ less than len, taking both by value.

$$ f(p, q, n) = (p - q) \bmod x^n. $$

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. The difference is trimmed, so when coefficients cancel 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 total number of bits of the first len coefficients of both polynomials.

§Examples
use core::str::FromStr;
use malachite_base::polynomial::SubTruncated;
use malachite_nz::integer_polynomial::IntegerPolynomial;

assert_eq!(
    IntegerPolynomial::from_str("x^3+2*x^2-x+5")
        .unwrap()
        .sub_truncated(IntegerPolynomial::from_str("4*x^2+x-2").unwrap(), 3)
        .to_string(),
    "-2*x^2-2*x+7"
);
// The quadratic and linear coefficients cancel.
assert_eq!(
    IntegerPolynomial::from_str("x^3+2*x^2-x+5")
        .unwrap()
        .sub_truncated(IntegerPolynomial::from_str("2*x^2-x+3").unwrap(), 3)
        .to_string(),
    "2"
);

This is equivalent to fmpz_poly_sub_series from fmpz_poly/sub_series.c, FLINT 3.6.0.

Source§

type Output = IntegerPolynomial

Source§

impl SubTruncated<&IntegerPolynomial> for IntegerPolynomial

Source§

fn sub_truncated(self, other: &Self, len: u64) -> Self

Subtracts one IntegerPolynomial from another, keeping only the coefficients of $x^i$ for $i$ less than len, taking the first by value and the second by reference.

$$ f(p, q, n) = (p - q) \bmod x^n. $$

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. The difference is trimmed, so when coefficients cancel 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 total number of bits of the first len coefficients of both polynomials.

§Examples
use core::str::FromStr;
use malachite_base::polynomial::SubTruncated;
use malachite_nz::integer_polynomial::IntegerPolynomial;

assert_eq!(
    IntegerPolynomial::from_str("x^3+2*x^2-x+5")
        .unwrap()
        .sub_truncated(&IntegerPolynomial::from_str("4*x^2+x-2").unwrap(), 3)
        .to_string(),
    "-2*x^2-2*x+7"
);
// The quadratic and linear coefficients cancel.
assert_eq!(
    IntegerPolynomial::from_str("x^3+2*x^2-x+5")
        .unwrap()
        .sub_truncated(&IntegerPolynomial::from_str("2*x^2-x+3").unwrap(), 3)
        .to_string(),
    "2"
);

This is equivalent to fmpz_poly_sub_series from fmpz_poly/sub_series.c, FLINT 3.6.0.

Source§

type Output = IntegerPolynomial

Source§

impl SubTruncated<&IntegerPolynomial> for &IntegerPolynomial

Source§

fn sub_truncated(self, other: &IntegerPolynomial, len: u64) -> IntegerPolynomial

Subtracts one IntegerPolynomial from another, keeping only the coefficients of $x^i$ for $i$ less than len, taking both by reference.

$$ f(p, q, n) = (p - q) \bmod x^n. $$

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. The difference is trimmed, so when coefficients cancel 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 total number of bits of the first len coefficients of both polynomials.

§Examples
use core::str::FromStr;
use malachite_base::polynomial::SubTruncated;
use malachite_nz::integer_polynomial::IntegerPolynomial;

assert_eq!(
    (&IntegerPolynomial::from_str("x^3+2*x^2-x+5").unwrap())
        .sub_truncated(&IntegerPolynomial::from_str("4*x^2+x-2").unwrap(), 3)
        .to_string(),
    "-2*x^2-2*x+7"
);
// The quadratic and linear coefficients cancel.
assert_eq!(
    (&IntegerPolynomial::from_str("x^3+2*x^2-x+5").unwrap())
        .sub_truncated(&IntegerPolynomial::from_str("2*x^2-x+3").unwrap(), 3)
        .to_string(),
    "2"
);

This is equivalent to fmpz_poly_sub_series from fmpz_poly/sub_series.c, FLINT 3.6.0.

Source§

type Output = IntegerPolynomial

Source§

impl SubTruncated<IntegerPolynomial> for &IntegerPolynomial

Source§

fn sub_truncated(self, other: IntegerPolynomial, len: u64) -> IntegerPolynomial

Subtracts one IntegerPolynomial from another, keeping only the coefficients of $x^i$ for $i$ less than len, taking the first by reference and the second by value.

$$ f(p, q, n) = (p - q) \bmod x^n. $$

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. The difference is trimmed, so when coefficients cancel 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 total number of bits of the first len coefficients of both polynomials.

§Examples
use core::str::FromStr;
use malachite_base::polynomial::SubTruncated;
use malachite_nz::integer_polynomial::IntegerPolynomial;

assert_eq!(
    (&IntegerPolynomial::from_str("x^3+2*x^2-x+5").unwrap())
        .sub_truncated(IntegerPolynomial::from_str("4*x^2+x-2").unwrap(), 3)
        .to_string(),
    "-2*x^2-2*x+7"
);
// The quadratic and linear coefficients cancel.
assert_eq!(
    (&IntegerPolynomial::from_str("x^3+2*x^2-x+5").unwrap())
        .sub_truncated(IntegerPolynomial::from_str("2*x^2-x+3").unwrap(), 3)
        .to_string(),
    "2"
);

This is equivalent to fmpz_poly_sub_series from fmpz_poly/sub_series.c, FLINT 3.6.0.

Source§

type Output = IntegerPolynomial

Source§

impl SubTruncatedAssign for IntegerPolynomial

Source§

fn sub_truncated_assign(&mut self, other: Self, len: u64)

Subtracts an IntegerPolynomial from an IntegerPolynomial in place, keeping only the coefficients of $x^i$ for $i$ less than len, taking the second polynomial by value.

$$ p \gets (p - q) \bmod x^n. $$

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. The difference is trimmed, so when coefficients cancel 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 total number of bits of the first len coefficients of both polynomials.

§Examples
use core::str::FromStr;
use malachite_base::polynomial::SubTruncatedAssign;
use malachite_nz::integer_polynomial::IntegerPolynomial;

let mut p = IntegerPolynomial::from_str("x^3+2*x^2-x+5").unwrap();
p.sub_truncated_assign(IntegerPolynomial::from_str("4*x^2+x-2").unwrap(), 3);
assert_eq!(p.to_string(), "-2*x^2-2*x+7");

// The quadratic and linear coefficients cancel.
let mut p = IntegerPolynomial::from_str("x^3+2*x^2-x+5").unwrap();
p.sub_truncated_assign(IntegerPolynomial::from_str("2*x^2-x+3").unwrap(), 3);
assert_eq!(p.to_string(), "2");

This is equivalent to fmpz_poly_sub_series from fmpz_poly/sub_series.c, FLINT 3.6.0.

Source§

impl SubTruncatedAssign<&IntegerPolynomial> for IntegerPolynomial

Source§

fn sub_truncated_assign(&mut self, other: &Self, len: u64)

Subtracts an IntegerPolynomial from an IntegerPolynomial in place, keeping only the coefficients of $x^i$ for $i$ less than len, taking the second polynomial by reference.

$$ p \gets (p - q) \bmod x^n. $$

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. The difference is trimmed, so when coefficients cancel 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 total number of bits of the first len coefficients of both polynomials.

§Examples
use core::str::FromStr;
use malachite_base::polynomial::SubTruncatedAssign;
use malachite_nz::integer_polynomial::IntegerPolynomial;

let mut p = IntegerPolynomial::from_str("x^3+2*x^2-x+5").unwrap();
p.sub_truncated_assign(&IntegerPolynomial::from_str("4*x^2+x-2").unwrap(), 3);
assert_eq!(p.to_string(), "-2*x^2-2*x+7");

// The quadratic and linear coefficients cancel.
let mut p = IntegerPolynomial::from_str("x^3+2*x^2-x+5").unwrap();
p.sub_truncated_assign(&IntegerPolynomial::from_str("2*x^2-x+3").unwrap(), 3);
assert_eq!(p.to_string(), "2");

This is equivalent to fmpz_poly_sub_series from fmpz_poly/sub_series.c, FLINT 3.6.0.

Source§

impl ToLatex for IntegerPolynomial

Source§

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

Writes an IntegerPolynomial 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.

A negative term joins the one before it with its own - rather than with a +, and a coefficient of -1 leaves only that sign behind. 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_nz::integer_polynomial::IntegerPolynomial;

assert_eq!(
    IntegerPolynomial::from_str("x^2+3*x+2")
        .unwrap()
        .to_latex_string(),
    "x^2+3x+2"
);
assert_eq!(
    IntegerPolynomial::from_str("0").unwrap().to_latex_string(),
    "0"
);
assert_eq!(
    IntegerPolynomial::from_str("5").unwrap().to_latex_string(),
    "5"
);
assert_eq!(
    IntegerPolynomial::from_str("x").unwrap().to_latex_string(),
    "x"
);
assert_eq!(
    IntegerPolynomial::from_str("2*x^3")
        .unwrap()
        .to_latex_string(),
    "2x^3"
);

// An exponent of more than one digit is braced.
assert_eq!(
    IntegerPolynomial::from_str("x^12+x^2")
        .unwrap()
        .to_latex_string(),
    "x^{12}+x^2"
);

The value column holds each polynomial as Display writes it.

valuefragmentrenders as
x^2+3*x+2x^2+3x+2$x^2+3x+2$
00$0$
55$5$
xx$x$
2*x^32x^3$2x^3$
x^12+x^2x^{12}+x^2$x^{12}+x^2$
Source§

fn to_latex(&self) -> LatexWrapper<'_, Self>
where Self: Sized,

Converts a value to a LaTeX math-mode fragment. Read more
Source§

fn to_latex_string(&self) -> String
where Self: Sized,

Converts a value to a LaTeX math-mode fragment, as a String. Read more
Source§

impl ToTypst for IntegerPolynomial

Source§

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

Writes an IntegerPolynomial 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.

A negative term joins the one before it with its own - rather than with a +, and a coefficient of -1 leaves only that sign behind. 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_nz::integer_polynomial::IntegerPolynomial;

assert_eq!(
    IntegerPolynomial::from_str("x^2+3*x+2")
        .unwrap()
        .to_typst_string(),
    "x^2+3x+2"
);
assert_eq!(
    IntegerPolynomial::from_str("0").unwrap().to_typst_string(),
    "0"
);
assert_eq!(
    IntegerPolynomial::from_str("5").unwrap().to_typst_string(),
    "5"
);
assert_eq!(
    IntegerPolynomial::from_str("x").unwrap().to_typst_string(),
    "x"
);
assert_eq!(
    IntegerPolynomial::from_str("2*x^3")
        .unwrap()
        .to_typst_string(),
    "2x^3"
);

// An exponent of more than one digit is parenthesized.
assert_eq!(
    IntegerPolynomial::from_str("x^12+x^2")
        .unwrap()
        .to_typst_string(),
    "x^(12)+x^2"
);

The value column holds each polynomial as Display writes it.

valuefragment
x^2+3*x+2x^2+3x+2
00
55
xx
2*x^32x^3
x^12+x^2x^(12)+x^2
Source§

fn to_typst(&self) -> TypstWrapper<'_, Self>
where Self: Sized,

Converts a value to a Typst math-mode fragment. Read more
Source§

fn to_typst_string(&self) -> String
where Self: Sized,

Converts a value to a Typst math-mode fragment, as a String. Read more
Source§

impl TryFrom<&IntegerPolynomial> for NaturalPolynomial

Source§

fn try_from(p: &IntegerPolynomial) -> Result<Self, Self::Error>

Converts an IntegerPolynomial to a NaturalPolynomial, taking the IntegerPolynomial by reference and returning an error if any coefficient is negative.

A successful conversion keeps 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 total number of bits in the coefficients.

§Examples

See here.

Source§

type Error = NaturalPolynomialFromIntegerPolynomialError

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

impl<T: PrimitiveUnsigned + for<'a> TryFrom<&'a Integer>> TryFrom<&IntegerPolynomial> for UnsignedPolynomial<T>

Source§

fn try_from(p: &IntegerPolynomial) -> Result<Self, Self::Error>

Converts an IntegerPolynomial to an UnsignedPolynomial, taking the IntegerPolynomial by reference and returning an error if any coefficient is negative or too large for T.

No coefficient is ever wrapped. A successful conversion keeps 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

See here.

Source§

type Error = UnsignedPolynomialFromIntegerPolynomialError

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

impl TryFrom<IntegerPolynomial> for NaturalPolynomial

Source§

fn try_from(p: IntegerPolynomial) -> Result<Self, Self::Error>

Converts an IntegerPolynomial to a NaturalPolynomial, taking the IntegerPolynomial by value and returning an error if any coefficient is negative.

Each coefficient’s limbs are reused rather than copied. A successful conversion keeps 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

See here.

Source§

type Error = NaturalPolynomialFromIntegerPolynomialError

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

impl<T: PrimitiveUnsigned + for<'a> TryFrom<&'a Integer>> TryFrom<IntegerPolynomial> for UnsignedPolynomial<T>

Source§

fn try_from(p: IntegerPolynomial) -> Result<Self, Self::Error>

Converts an IntegerPolynomial to an UnsignedPolynomial, taking the IntegerPolynomial by value and returning an error if any coefficient is negative or too large for T.

Taking the polynomial by value saves nothing, since the coefficients are copied into new storage either way; this is here so that a conversion can be written without a borrow.

§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

See here.

Source§

type Error = UnsignedPolynomialFromIntegerPolynomialError

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

impl Zero for IntegerPolynomial

The constant 0.

Source§

const ZERO: Self

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

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

Source§

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

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

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

Source§

fn exact_from(value: T) -> U

Source§

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

Source§

fn exact_into(self) -> U

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

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

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T, U> OverflowingInto<U> for T
where U: OverflowingFrom<T>,

Source§

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

Source§

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

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

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

Source§

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

Source§

fn to_debug_string(&self) -> String

Returns the String produced by Ts Debug implementation.

§Examples
use malachite_base::strings::ToDebugString;

assert_eq!([1, 2, 3].to_debug_string(), "[1, 2, 3]");
assert_eq!(
    [vec![2, 3], vec![], vec![4]].to_debug_string(),
    "[[2, 3], [], [4]]"
);
assert_eq!(Some(5).to_debug_string(), "Some(5)");
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

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

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

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

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

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

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

Source§

fn wrapping_into(self) -> U