### Navigation

- index
- modules |
- next |
- previous |
- Polynomial Rings »
- Univariate Polynomials and Polynomial Rings »

# Dense univariate polynomials over \(\ZZ/n\ZZ\), implemented using FLINT.

Dense univariate polynomials over \(\ZZ/n\ZZ\), implemented using FLINT.

This module gives a fast implementation of \((\ZZ/n\ZZ)[x]\) whenever \(n\) is at most `sys.maxsize`. We use it by default in preference to NTL when the modulus is small, falling back to NTL if the modulus is too large, as in the example below.

EXAMPLES:

    sage: R.<a> = PolynomialRing(Integers(100))
    sage: type(a)
    <type 'sage.rings.polynomial.polynomial_zmod_flint.Polynomial_zmod_flint'>
    sage: R.<a> = PolynomialRing(Integers(5*2^64))
    sage: type(a)
    <type 'sage.rings.polynomial.polynomial_modn_dense_ntl.Polynomial_dense_modn_ntl_ZZ'>
    sage: R.<a> = PolynomialRing(Integers(5*2^64), implementation="FLINT")
    Traceback (most recent call last):
    ...
    ValueError: FLINT does not support modulus 92233720368547758080

AUTHORS:

- Burcin Erocal (2008-11) initial implementation
- Martin Albrecht (2009-01) another initial implementation

class `sage.rings.polynomial.polynomial_zmod_flint.``Polynomial_template`

  Bases: `sage.rings.polynomial.polynomial_element.Polynomial`

  Template for interfacing to external C / C++ libraries for implementations of polynomials.

  AUTHORS:

  - Robert Bradshaw (2008-10): original idea for templating
  - Martin Albrecht (2008-10): initial implementation

  This file implements a simple templating engine for linking univariate polynomials to their C/C++ library implementations. It requires a ‘linkage’ file which implements the `celement_` functions (see `sage.libs.ntl.ntl_GF2X_linkage` for an example). Both parts are then plugged together by inclusion of the linkage file when inheriting from this class. See `sage.rings.polynomial.polynomial_gf2x` for an example.

  We illustrate the generic glueing using univariate polynomials over \(\mathop{\mathrm{GF}}(2)\).

  Note

  Implementations using this template MUST implement coercion from base ring elements and `__getitem__`. See `Polynomial_GF2X` for an example.

  `degree`()

    EXAMPLE:

        sage: P.<x> = GF(2)[]
        sage: x.degree()
        1
        sage: P(1).degree()
        0
        sage: P(0).degree()
        -1

  `gcd`(other)

    Return the greatest common divisor of self and other.

    EXAMPLE:

        sage: P.<x> = GF(2)[]
        sage: f = x*(x+1)
        sage: f.gcd(x+1)
        x + 1
        sage: f.gcd(x^2)
        x

  `get_cparent`()
  `is_gen`()

    EXAMPLE:

        sage: P.<x> = GF(2)[]
        sage: x.is_gen()
        True
        sage: (x+1).is_gen()
        False

  `is_one`()

    EXAMPLE:

        sage: P.<x> = GF(2)[]
        sage: P(1).is_one()
        True

  `is_zero`()

    EXAMPLE:

        sage: P.<x> = GF(2)[]
        sage: x.is_zero()
        False

  `list`()

    EXAMPLE:

        sage: P.<x> = GF(2)[]
        sage: x.list()
        [0, 1]
        sage: list(x)
        [0, 1]

  `quo_rem`(right)

    EXAMPLE:

        sage: P.<x> = GF(2)[]
        sage: f = x^2 + x + 1
        sage: f.quo_rem(x + 1)
        (x, 1)

  `shift`(n)

    EXAMPLE:

        sage: P.<x> = GF(2)[]
        sage: f = x^3 + x^2 + 1
        sage: f.shift(1)
        x^4 + x^3 + x
        sage: f.shift(-1)
        x^2 + x

  `truncate`(n)

    Returns this polynomial mod \(x^n\).

    EXAMPLES:

        sage: R.<x> =GF(2)[]
        sage: f = sum(x^n for n in range(10)); f
        x^9 + x^8 + x^7 + x^6 + x^5 + x^4 + x^3 + x^2 + x + 1
        sage: f.truncate(6)
        x^5 + x^4 + x^3 + x^2 + x + 1

  `xgcd`(other)

    Computes extended gcd of self and other.

    EXAMPLE:

        sage: P.<x> = GF(7)[]
        sage: f = x*(x+1)
        sage: f.xgcd(x+1)
        (x + 1, 0, 1)
        sage: f.xgcd(x^2)
        (x, 1, 6)

class `sage.rings.polynomial.polynomial_zmod_flint.``Polynomial_zmod_flint`

  Bases: `sage.rings.polynomial.polynomial_zmod_flint.Polynomial_template`

  EXAMPLE:

      sage: P.<x> = GF(32003)[]
      sage: f = 24998*x^2 + 29761*x + 2252

  `factor`()

    Returns the factorization of the polynomial.

    EXAMPLES:

        sage: R.<x> = GF(5)[]
        sage: (x^2 + 1).factor()
        (x + 2) * (x + 3)

    TESTS:

        sage: (2*x^2 + 2).factor()
        (2) * (x + 2) * (x + 3)
        sage: P.<x> = Zmod(10)[]
        sage: (x^2).factor()
        Traceback (most recent call last):
        ...
        NotImplementedError: factorization of polynomials over rings with composite characteristic is not implemented

  `is_irreducible`()

    Return True if this polynomial is irreducible.

    EXAMPLES:

        sage: R.<x> = GF(5)[]
        sage: (x^2 + 1).is_irreducible()
        False
        sage: (x^3 + x + 1).is_irreducible()
        True

    TESTS:

        sage: R(0).is_irreducible()
        False
        sage: R(1).is_irreducible()
        False
        sage: R(2).is_irreducible()
        False

        sage: S.<s> = Zmod(10)[]
        sage: (s^2).is_irreducible()
        Traceback (most recent call last):
        ...
        NotImplementedError: checking irreducibility of polynomials over rings with composite characteristic is not implemented
        sage: S(1).is_irreducible()
        False
        sage: S(2).is_irreducible()
        Traceback (most recent call last):
        ...
        NotImplementedError: checking irreducibility of polynomials over rings with composite characteristic is not implemented

  `monic`()

    Return this polynomial divided by its leading coefficient.

    Raises ValueError if the leading cofficient is not invertible in the base ring.

    EXAMPLES:

        sage: R.<x> = GF(5)[]
        sage: (2*x^2+1).monic()
        x^2 + 3

    TESTS:

        sage: R.<x> = Zmod(10)[]
        sage: (5*x).monic()
        Traceback (most recent call last):
        ...
        ValueError: leading coefficient must be invertible

  `rational_reconstruct`(m, n_deg=0, d_deg=0)

    Construct a rational function n/d such that \(p*d\) is equivalent to \(n\) modulo \(m\) where \(p\) is this polynomial.

    EXAMPLES:

        sage: P.<x> = GF(5)[]
        sage: p = 4*x^5 + 3*x^4 + 2*x^3 + 2*x^2 + 4*x + 2
        sage: n, d = p.rational_reconstruct(x^9, 4, 4); n, d
        (3*x^4 + 2*x^3 + x^2 + 2*x, x^4 + 3*x^3 + x^2 + x)
        sage: (p*d % x^9) == n
        True

  `resultant`(other)

    Returns the resultant of self and other, which must lie in the same polynomial ring.

    INPUT:

    - other – a polynomial

    OUTPUT: an element of the base ring of the polynomial ring

    EXAMPLES:

        sage: R.<x> = GF(19)['x']
        sage: f = x^3 + x + 1;  g = x^3 - x - 1
        sage: r = f.resultant(g); r
        11
        sage: r.parent() is GF(19)
        True

    The following example shows that #11782 has been fixed:

        sage: R.<x> = ZZ.quo(9)['x']
        sage: f = 2*x^3 + x^2 + x;  g = 6*x^2 + 2*x + 1
        sage: f.resultant(g)
        5

  `reverse`(degree=None)

    Return a polynomial with the coefficients of this polynomial reversed.

    If an optional degree argument is given the coefficient list will be truncated or zero padded as necessary and the reverse polynomial will have the specified degree.

    EXAMPLES:

        sage: R.<x> = GF(5)[]
        sage: p = R([1,2,3,4]); p
        4*x^3 + 3*x^2 + 2*x + 1
        sage: p.reverse()
        x^3 + 2*x^2 + 3*x + 4
        sage: p.reverse(degree=6)
        x^6 + 2*x^5 + 3*x^4 + 4*x^3
        sage: p.reverse(degree=2)
        x^2 + 2*x + 3

        sage: R.<x> = GF(101)[]
        sage: f = x^3 - x + 2; f
        x^3 + 100*x + 2
        sage: f.reverse()
        2*x^3 + 100*x^2 + 1
        sage: f.reverse() == f(1/x) * x^f.degree()
        True

    Note that if \(f\) has zero constant coefficient, its reverse will have lower degree.

        sage: f = x^3 + 2*x
        sage: f.reverse()
        2*x^2 + 1

    In this case, reverse is not an involution unless we explicitly specify a degree.

        sage: f
        x^3 + 2*x
        sage: f.reverse().reverse()
        x^2 + 2
        sage: f.reverse(5).reverse(5)
        x^3 + 2*x

    TESTS:

        sage: p.reverse(degree=1.5r)
        Traceback (most recent call last):
        ...
        ValueError: degree argument must be a non-negative integer, got 1.5

  `revert_series`(n)

    Return a polynomial \(f\) such that \(f(self(x)) = self(f(x)) = x mod x^n\).

    EXAMPLES:

        sage: R.<t> =  GF(5)[]
        sage: f = t + 2*t^2 - t^3 - 3*t^4
        sage: f.revert_series(5)
        3*t^4 + 4*t^3 + 3*t^2 + t

        sage: f.revert_series(-1)
        Traceback (most recent call last):
        ...
        ValueError: argument n must be a non-negative integer, got -1

        sage: g = - t^3 + t^5
        sage: g.revert_series(6)
        Traceback (most recent call last):
        ...
        ValueError: self must have constant coefficient 0 and a unit for coefficient t^1

        sage: g = t + 2*t^2 - t^3 -3*t^4 + t^5
        sage: g.revert_series(6)
        Traceback (most recent call last):
        ...
        ValueError: the integers 1 up to n=5 are required to be invertible over the base field

  `small_roots`(*args, **kwds)

    See `sage.rings.polynomial.polynomial_modn_dense_ntl.small_roots()` for the documentation of this function.

    EXAMPLE:

        sage: N = 10001
        sage: K = Zmod(10001)
        sage: P.<x> = PolynomialRing(K)
        sage: f = x^3 + 10*x^2 + 5000*x - 222
        sage: f.small_roots()
        [4]

  `squarefree_decomposition`()

    Returns the squarefree decomposition of this polynomial.

    EXAMPLES:

        sage: R.<x> = GF(5)[]
        sage: ((x+1)*(x^2+1)^2*x^3).squarefree_decomposition()
        (x + 1) * (x^2 + 1)^2 * x^3

    TESTS:

        sage: (2*x*(x+1)^2).squarefree_decomposition()
        (2) * x * (x + 1)^2
        sage: P.<x> = Zmod(10)[]
        sage: (x^2).squarefree_decomposition()
        Traceback (most recent call last):
        ...
        NotImplementedError: square free factorization of polynomials over rings with composite characteristic is not implemented

`sage.rings.polynomial.polynomial_zmod_flint.``make_element`(parent, args)

### Navigation

- index
- modules |
- next |
- previous |
- Polynomial Rings »
- Univariate Polynomials and Polynomial Rings »