Elements of Laurent polynomial rings

class sage.rings.polynomial.laurent_polynomial.LaurentPolynomial[source]

Bases: CommutativeAlgebraElement

Base class for Laurent polynomials.

change_ring(R)[source]

Return a copy of this Laurent polynomial, with coefficients in R.

EXAMPLES:

sage: R.<x> = LaurentPolynomialRing(QQ)
sage: a = x^2 + 3*x^3 + 5*x^-1
sage: a.change_ring(GF(3))
2*x^-1 + x^2
>>> from sage.all import *
>>> R = LaurentPolynomialRing(QQ, names=('x',)); (x,) = R._first_ngens(1)
>>> a = x**Integer(2) + Integer(3)*x**Integer(3) + Integer(5)*x**-Integer(1)
>>> a.change_ring(GF(Integer(3)))
2*x^-1 + x^2
R.<x> = LaurentPolynomialRing(QQ)
a = x^2 + 3*x^3 + 5*x^-1
a.change_ring(GF(3))

Check that Issue #22277 is fixed:

sage: # needs sage.modules
sage: R.<x, y> = LaurentPolynomialRing(QQ)
sage: a = 2*x^2 + 3*x^3 + 4*x^-1
sage: a.change_ring(GF(3))
-x^2 + x^-1
>>> from sage.all import *
>>> # needs sage.modules
>>> R = LaurentPolynomialRing(QQ, names=('x', 'y',)); (x, y,) = R._first_ngens(2)
>>> a = Integer(2)*x**Integer(2) + Integer(3)*x**Integer(3) + Integer(4)*x**-Integer(1)
>>> a.change_ring(GF(Integer(3)))
-x^2 + x^-1
# needs sage.modules
R.<x, y> = LaurentPolynomialRing(QQ)
a = 2*x^2 + 3*x^3 + 4*x^-1
a.change_ring(GF(3))
dict()[source]

Abstract dict method.

EXAMPLES:

sage: R.<x> = LaurentPolynomialRing(ZZ)
sage: from sage.rings.polynomial.laurent_polynomial import LaurentPolynomial
sage: LaurentPolynomial.monomial_coefficients(x)
Traceback (most recent call last):
...
NotImplementedError
>>> from sage.all import *
>>> R = LaurentPolynomialRing(ZZ, names=('x',)); (x,) = R._first_ngens(1)
>>> from sage.rings.polynomial.laurent_polynomial import LaurentPolynomial
>>> LaurentPolynomial.monomial_coefficients(x)
Traceback (most recent call last):
...
NotImplementedError
R.<x> = LaurentPolynomialRing(ZZ)
from sage.rings.polynomial.laurent_polynomial import LaurentPolynomial
LaurentPolynomial.monomial_coefficients(x)
hamming_weight()[source]

Return the hamming weight of self.

The hamming weight is number of nonzero coefficients and also known as the weight or sparsity.

EXAMPLES:

sage: R.<x> = LaurentPolynomialRing(ZZ)
sage: f = x^3 - 1
sage: f.hamming_weight()
2
>>> from sage.all import *
>>> R = LaurentPolynomialRing(ZZ, names=('x',)); (x,) = R._first_ngens(1)
>>> f = x**Integer(3) - Integer(1)
>>> f.hamming_weight()
2
R.<x> = LaurentPolynomialRing(ZZ)
f = x^3 - 1
f.hamming_weight()
map_coefficients(f, new_base_ring=None)[source]

Apply f to the coefficients of self.

If f is a sage.categories.map.Map, then the resulting polynomial will be defined over the codomain of f. Otherwise, the resulting polynomial will be over the same ring as self. Set new_base_ring to override this behavior.

INPUT:

  • f – a callable that will be applied to the coefficients of self

  • new_base_ring – (optional) if given, the resulting polynomial will be defined over this ring

EXAMPLES:

sage: # needs sage.rings.finite_rings
sage: k.<a> = GF(9)
sage: R.<x> = LaurentPolynomialRing(k)
sage: f = x*a + a
sage: f.map_coefficients(lambda a: a + 1)
(a + 1) + (a + 1)*x
sage: R.<x,y> = LaurentPolynomialRing(k, 2)                                 # needs sage.modules
sage: f = x*a + 2*x^3*y*a + a                                               # needs sage.modules
sage: f.map_coefficients(lambda a: a + 1)                                   # needs sage.modules
(2*a + 1)*x^3*y + (a + 1)*x + a + 1
>>> from sage.all import *
>>> # needs sage.rings.finite_rings
>>> k = GF(Integer(9), names=('a',)); (a,) = k._first_ngens(1)
>>> R = LaurentPolynomialRing(k, names=('x',)); (x,) = R._first_ngens(1)
>>> f = x*a + a
>>> f.map_coefficients(lambda a: a + Integer(1))
(a + 1) + (a + 1)*x
>>> R = LaurentPolynomialRing(k, Integer(2), names=('x', 'y',)); (x, y,) = R._first_ngens(2)# needs sage.modules
>>> f = x*a + Integer(2)*x**Integer(3)*y*a + a                                               # needs sage.modules
>>> f.map_coefficients(lambda a: a + Integer(1))                                   # needs sage.modules
(2*a + 1)*x^3*y + (a + 1)*x + a + 1
# needs sage.rings.finite_rings
k.<a> = GF(9)
R.<x> = LaurentPolynomialRing(k)
f = x*a + a
f.map_coefficients(lambda a: a + 1)
R.<x,y> = LaurentPolynomialRing(k, 2)                                 # needs sage.modules
f = x*a + 2*x^3*y*a + a                                               # needs sage.modules
f.map_coefficients(lambda a: a + 1)                                   # needs sage.modules

Examples with different base ring:

sage: # needs sage.modules sage.rings.finite_rings
sage: R.<r> = GF(9); S.<s> = GF(81)
sage: h = Hom(R, S)[0]; h
Ring morphism:
  From: Finite Field in r of size 3^2
  To:   Finite Field in s of size 3^4
  Defn: r |--> 2*s^3 + 2*s^2 + 1
sage: T.<X,Y> = LaurentPolynomialRing(R, 2)
sage: f = r*X + Y
sage: g = f.map_coefficients(h); g
(2*s^3 + 2*s^2 + 1)*X + Y
sage: g.parent()
Multivariate Laurent Polynomial Ring in X, Y
 over Finite Field in s of size 3^4
sage: h = lambda x: x.trace()
sage: g = f.map_coefficients(h); g
X - Y
sage: g.parent()
Multivariate Laurent Polynomial Ring in X, Y
 over Finite Field in r of size 3^2
sage: g = f.map_coefficients(h, new_base_ring=GF(3)); g
X - Y
sage: g.parent()
Multivariate Laurent Polynomial Ring in X, Y over Finite Field of size 3
>>> from sage.all import *
>>> # needs sage.modules sage.rings.finite_rings
>>> R = GF(Integer(9), names=('r',)); (r,) = R._first_ngens(1); S = GF(Integer(81), names=('s',)); (s,) = S._first_ngens(1)
>>> h = Hom(R, S)[Integer(0)]; h
Ring morphism:
  From: Finite Field in r of size 3^2
  To:   Finite Field in s of size 3^4
  Defn: r |--> 2*s^3 + 2*s^2 + 1
>>> T = LaurentPolynomialRing(R, Integer(2), names=('X', 'Y',)); (X, Y,) = T._first_ngens(2)
>>> f = r*X + Y
>>> g = f.map_coefficients(h); g
(2*s^3 + 2*s^2 + 1)*X + Y
>>> g.parent()
Multivariate Laurent Polynomial Ring in X, Y
 over Finite Field in s of size 3^4
>>> h = lambda x: x.trace()
>>> g = f.map_coefficients(h); g
X - Y
>>> g.parent()
Multivariate Laurent Polynomial Ring in X, Y
 over Finite Field in r of size 3^2
>>> g = f.map_coefficients(h, new_base_ring=GF(Integer(3))); g
X - Y
>>> g.parent()
Multivariate Laurent Polynomial Ring in X, Y over Finite Field of size 3
# needs sage.modules sage.rings.finite_rings
R.<r> = GF(9); S.<s> = GF(81)
h = Hom(R, S)[0]; h
T.<X,Y> = LaurentPolynomialRing(R, 2)
f = r*X + Y
g = f.map_coefficients(h); g
g.parent()
h = lambda x: x.trace()
g = f.map_coefficients(h); g
g.parent()
g = f.map_coefficients(h, new_base_ring=GF(3)); g
g.parent()
monomial_coefficients()[source]

Abstract dict method.

EXAMPLES:

sage: R.<x> = LaurentPolynomialRing(ZZ)
sage: from sage.rings.polynomial.laurent_polynomial import LaurentPolynomial
sage: LaurentPolynomial.monomial_coefficients(x)
Traceback (most recent call last):
...
NotImplementedError
>>> from sage.all import *
>>> R = LaurentPolynomialRing(ZZ, names=('x',)); (x,) = R._first_ngens(1)
>>> from sage.rings.polynomial.laurent_polynomial import LaurentPolynomial
>>> LaurentPolynomial.monomial_coefficients(x)
Traceback (most recent call last):
...
NotImplementedError
R.<x> = LaurentPolynomialRing(ZZ)
from sage.rings.polynomial.laurent_polynomial import LaurentPolynomial
LaurentPolynomial.monomial_coefficients(x)
number_of_terms()[source]

Abstract method for number of terms

EXAMPLES:

sage: R.<x> = LaurentPolynomialRing(ZZ)
sage: from sage.rings.polynomial.laurent_polynomial import LaurentPolynomial
sage: LaurentPolynomial.number_of_terms(x)
Traceback (most recent call last):
...
NotImplementedError
>>> from sage.all import *
>>> R = LaurentPolynomialRing(ZZ, names=('x',)); (x,) = R._first_ngens(1)
>>> from sage.rings.polynomial.laurent_polynomial import LaurentPolynomial
>>> LaurentPolynomial.number_of_terms(x)
Traceback (most recent call last):
...
NotImplementedError
R.<x> = LaurentPolynomialRing(ZZ)
from sage.rings.polynomial.laurent_polynomial import LaurentPolynomial
LaurentPolynomial.number_of_terms(x)
class sage.rings.polynomial.laurent_polynomial.LaurentPolynomial_univariate[source]

Bases: LaurentPolynomial

A univariate Laurent polynomial in the form of \(t^n \cdot f\) where \(f\) is a polynomial in \(t\).

INPUT:

  • parent – a Laurent polynomial ring

  • f – a polynomial (or something that can be coerced to one)

  • n – integer (default: 0)

AUTHORS:

  • Tom Boothby (2011) copied this class almost verbatim from laurent_series_ring_element.pyx, so most of the credit goes to William Stein, David Joyner, and Robert Bradshaw

  • Travis Scrimshaw (09-2013): Cleaned-up and added a few extra methods

coefficients()[source]

Return the nonzero coefficients of self.

EXAMPLES:

sage: R.<t> = LaurentPolynomialRing(QQ)
sage: f = -5/t^(2) + t + t^2 - 10/3*t^3
sage: f.coefficients()
[-5, 1, 1, -10/3]
>>> from sage.all import *
>>> R = LaurentPolynomialRing(QQ, names=('t',)); (t,) = R._first_ngens(1)
>>> f = -Integer(5)/t**(Integer(2)) + t + t**Integer(2) - Integer(10)/Integer(3)*t**Integer(3)
>>> f.coefficients()
[-5, 1, 1, -10/3]
R.<t> = LaurentPolynomialRing(QQ)
f = -5/t^(2) + t + t^2 - 10/3*t^3
f.coefficients()
constant_coefficient()[source]

Return the coefficient of the constant term of self.

EXAMPLES:

sage: R.<t> = LaurentPolynomialRing(QQ)
sage: f = 3*t^-2 - t^-1 + 3 + t^2
sage: f.constant_coefficient()
3
sage: g = -2*t^-2 + t^-1 + 3*t
sage: g.constant_coefficient()
0
>>> from sage.all import *
>>> R = LaurentPolynomialRing(QQ, names=('t',)); (t,) = R._first_ngens(1)
>>> f = Integer(3)*t**-Integer(2) - t**-Integer(1) + Integer(3) + t**Integer(2)
>>> f.constant_coefficient()
3
>>> g = -Integer(2)*t**-Integer(2) + t**-Integer(1) + Integer(3)*t
>>> g.constant_coefficient()
0
R.<t> = LaurentPolynomialRing(QQ)
f = 3*t^-2 - t^-1 + 3 + t^2
f.constant_coefficient()
g = -2*t^-2 + t^-1 + 3*t
g.constant_coefficient()
degree()[source]

Return the degree of self.

EXAMPLES:

sage: R.<x> = LaurentPolynomialRing(ZZ)
sage: g = x^2 - x^4
sage: g.degree()
4
sage: g = -10/x^5 + x^2 - x^7
sage: g.degree()
7
>>> from sage.all import *
>>> R = LaurentPolynomialRing(ZZ, names=('x',)); (x,) = R._first_ngens(1)
>>> g = x**Integer(2) - x**Integer(4)
>>> g.degree()
4
>>> g = -Integer(10)/x**Integer(5) + x**Integer(2) - x**Integer(7)
>>> g.degree()
7
R.<x> = LaurentPolynomialRing(ZZ)
g = x^2 - x^4
g.degree()
g = -10/x^5 + x^2 - x^7
g.degree()

The zero polynomial is defined to have degree \(-\infty\):

sage: R.<x> = LaurentPolynomialRing(ZZ)
sage: R.zero().degree()
-Infinity
>>> from sage.all import *
>>> R = LaurentPolynomialRing(ZZ, names=('x',)); (x,) = R._first_ngens(1)
>>> R.zero().degree()
-Infinity
R.<x> = LaurentPolynomialRing(ZZ)
R.zero().degree()
derivative(*args)[source]

The formal derivative of this Laurent polynomial, with respect to variables supplied in args.

Multiple variables and iteration counts may be supplied. See documentation for the global derivative() function for more details.

See also

_derivative()

EXAMPLES:

sage: R.<x> = LaurentPolynomialRing(QQ)
sage: g = 1/x^10 - x + x^2 - x^4
sage: g.derivative()
-10*x^-11 - 1 + 2*x - 4*x^3
sage: g.derivative(x)
-10*x^-11 - 1 + 2*x - 4*x^3
>>> from sage.all import *
>>> R = LaurentPolynomialRing(QQ, names=('x',)); (x,) = R._first_ngens(1)
>>> g = Integer(1)/x**Integer(10) - x + x**Integer(2) - x**Integer(4)
>>> g.derivative()
-10*x^-11 - 1 + 2*x - 4*x^3
>>> g.derivative(x)
-10*x^-11 - 1 + 2*x - 4*x^3
R.<x> = LaurentPolynomialRing(QQ)
g = 1/x^10 - x + x^2 - x^4
g.derivative()
g.derivative(x)

sage: R.<t> = PolynomialRing(ZZ)
sage: S.<x> = LaurentPolynomialRing(R)
sage: f = 2*t/x + (3*t^2 + 6*t)*x
sage: f.derivative()
-2*t*x^-2 + (3*t^2 + 6*t)
sage: f.derivative(x)
-2*t*x^-2 + (3*t^2 + 6*t)
sage: f.derivative(t)
2*x^-1 + (6*t + 6)*x
>>> from sage.all import *
>>> R = PolynomialRing(ZZ, names=('t',)); (t,) = R._first_ngens(1)
>>> S = LaurentPolynomialRing(R, names=('x',)); (x,) = S._first_ngens(1)
>>> f = Integer(2)*t/x + (Integer(3)*t**Integer(2) + Integer(6)*t)*x
>>> f.derivative()
-2*t*x^-2 + (3*t^2 + 6*t)
>>> f.derivative(x)
-2*t*x^-2 + (3*t^2 + 6*t)
>>> f.derivative(t)
2*x^-1 + (6*t + 6)*x
R.<t> = PolynomialRing(ZZ)
S.<x> = LaurentPolynomialRing(R)
f = 2*t/x + (3*t^2 + 6*t)*x
f.derivative()
f.derivative(x)
f.derivative(t)
dict()[source]

Return a dictionary representing self.

EXAMPLES:

sage: R.<x,y> = ZZ[]
sage: Q.<t> = LaurentPolynomialRing(R)
sage: f = (x^3 + y/t^3)^3 + t^2; f
y^3*t^-9 + 3*x^3*y^2*t^-6 + 3*x^6*y*t^-3 + x^9 + t^2
sage: f.monomial_coefficients()
{-9: y^3, -6: 3*x^3*y^2, -3: 3*x^6*y, 0: x^9, 2: 1}
>>> from sage.all import *
>>> R = ZZ['x, y']; (x, y,) = R._first_ngens(2)
>>> Q = LaurentPolynomialRing(R, names=('t',)); (t,) = Q._first_ngens(1)
>>> f = (x**Integer(3) + y/t**Integer(3))**Integer(3) + t**Integer(2); f
y^3*t^-9 + 3*x^3*y^2*t^-6 + 3*x^6*y*t^-3 + x^9 + t^2
>>> f.monomial_coefficients()
{-9: y^3, -6: 3*x^3*y^2, -3: 3*x^6*y, 0: x^9, 2: 1}
R.<x,y> = ZZ[]
Q.<t> = LaurentPolynomialRing(R)
f = (x^3 + y/t^3)^3 + t^2; f
f.monomial_coefficients()

dict is an alias:

sage: f.dict()
{-9: y^3, -6: 3*x^3*y^2, -3: 3*x^6*y, 0: x^9, 2: 1}
>>> from sage.all import *
>>> f.dict()
{-9: y^3, -6: 3*x^3*y^2, -3: 3*x^6*y, 0: x^9, 2: 1}
f.dict()
divides(other)[source]

Return True if self divides other.

EXAMPLES:

sage: R.<x> = LaurentPolynomialRing(ZZ)
sage: (2*x**-1 + 1).divides(4*x**-2 - 1)
True
sage: (2*x + 1).divides(4*x**2 + 1)
False
sage: (2*x + x**-1).divides(R(0))
True
sage: R(0).divides(2*x ** -1 + 1)
False
sage: R(0).divides(R(0))
True
sage: R.<x> = LaurentPolynomialRing(Zmod(6))
sage: p = 4*x + 3*x^-1
sage: q = 5*x^2 + x + 2*x^-2
sage: p.divides(q)
False

sage: R.<x,y> = GF(2)[]
sage: S.<z> = LaurentPolynomialRing(R)
sage: p = (x+y+1) * z**-1 + x*y
sage: q = (y^2-x^2) * z**-2 + z + x-y
sage: p.divides(q), p.divides(p*q)                                          # needs sage.libs.singular
(False, True)
>>> from sage.all import *
>>> R = LaurentPolynomialRing(ZZ, names=('x',)); (x,) = R._first_ngens(1)
>>> (Integer(2)*x**-Integer(1) + Integer(1)).divides(Integer(4)*x**-Integer(2) - Integer(1))
True
>>> (Integer(2)*x + Integer(1)).divides(Integer(4)*x**Integer(2) + Integer(1))
False
>>> (Integer(2)*x + x**-Integer(1)).divides(R(Integer(0)))
True
>>> R(Integer(0)).divides(Integer(2)*x ** -Integer(1) + Integer(1))
False
>>> R(Integer(0)).divides(R(Integer(0)))
True
>>> R = LaurentPolynomialRing(Zmod(Integer(6)), names=('x',)); (x,) = R._first_ngens(1)
>>> p = Integer(4)*x + Integer(3)*x**-Integer(1)
>>> q = Integer(5)*x**Integer(2) + x + Integer(2)*x**-Integer(2)
>>> p.divides(q)
False

>>> R = GF(Integer(2))['x, y']; (x, y,) = R._first_ngens(2)
>>> S = LaurentPolynomialRing(R, names=('z',)); (z,) = S._first_ngens(1)
>>> p = (x+y+Integer(1)) * z**-Integer(1) + x*y
>>> q = (y**Integer(2)-x**Integer(2)) * z**-Integer(2) + z + x-y
>>> p.divides(q), p.divides(p*q)                                          # needs sage.libs.singular
(False, True)
R.<x> = LaurentPolynomialRing(ZZ)
(2*x**-1 + 1).divides(4*x**-2 - 1)
(2*x + 1).divides(4*x**2 + 1)
(2*x + x**-1).divides(R(0))
R(0).divides(2*x ** -1 + 1)
R(0).divides(R(0))
R.<x> = LaurentPolynomialRing(Zmod(6))
p = 4*x + 3*x^-1
q = 5*x^2 + x + 2*x^-2
p.divides(q)
R.<x,y> = GF(2)[]
S.<z> = LaurentPolynomialRing(R)
p = (x+y+1) * z**-1 + x*y
q = (y^2-x^2) * z**-2 + z + x-y
p.divides(q), p.divides(p*q)                                          # needs sage.libs.singular
euclidean_degree()[source]

Return the degree of self as an element of an Euclidean domain.

This is the Euclidean degree of the underlying polynomial.

EXAMPLES:

sage: R.<x> = LaurentPolynomialRing(QQ)
sage: (x^-5 + x^2).euclidean_degree()
7

sage: R.<x> = LaurentPolynomialRing(ZZ)
sage: (x^-5 + x^2).euclidean_degree()
Traceback (most recent call last):
...
NotImplementedError
>>> from sage.all import *
>>> R = LaurentPolynomialRing(QQ, names=('x',)); (x,) = R._first_ngens(1)
>>> (x**-Integer(5) + x**Integer(2)).euclidean_degree()
7

>>> R = LaurentPolynomialRing(ZZ, names=('x',)); (x,) = R._first_ngens(1)
>>> (x**-Integer(5) + x**Integer(2)).euclidean_degree()
Traceback (most recent call last):
...
NotImplementedError
R.<x> = LaurentPolynomialRing(QQ)
(x^-5 + x^2).euclidean_degree()
R.<x> = LaurentPolynomialRing(ZZ)
(x^-5 + x^2).euclidean_degree()
exponents()[source]

Return the exponents appearing in self with nonzero coefficients.

EXAMPLES:

sage: R.<t> = LaurentPolynomialRing(QQ)
sage: f = -5/t^(2) + t + t^2 - 10/3*t^3
sage: f.exponents()
[-2, 1, 2, 3]
>>> from sage.all import *
>>> R = LaurentPolynomialRing(QQ, names=('t',)); (t,) = R._first_ngens(1)
>>> f = -Integer(5)/t**(Integer(2)) + t + t**Integer(2) - Integer(10)/Integer(3)*t**Integer(3)
>>> f.exponents()
[-2, 1, 2, 3]
R.<t> = LaurentPolynomialRing(QQ)
f = -5/t^(2) + t + t^2 - 10/3*t^3
f.exponents()
factor()[source]

Return a Laurent monomial (the unit part of the factorization) and a factored polynomial.

EXAMPLES:

sage: R.<t> = LaurentPolynomialRing(ZZ)
sage: f = 4*t^-7 + 3*t^3 + 2*t^4 + t^-6
sage: f.factor()                                                            # needs sage.libs.pari
(t^-7) * (4 + t + 3*t^10 + 2*t^11)
>>> from sage.all import *
>>> R = LaurentPolynomialRing(ZZ, names=('t',)); (t,) = R._first_ngens(1)
>>> f = Integer(4)*t**-Integer(7) + Integer(3)*t**Integer(3) + Integer(2)*t**Integer(4) + t**-Integer(6)
>>> f.factor()                                                            # needs sage.libs.pari
(t^-7) * (4 + t + 3*t^10 + 2*t^11)
R.<t> = LaurentPolynomialRing(ZZ)
f = 4*t^-7 + 3*t^3 + 2*t^4 + t^-6
f.factor()                                                            # needs sage.libs.pari
gcd(right)[source]

Return the gcd of self with right where the common divisor d makes both self and right into polynomials with the lowest possible degree.

EXAMPLES:

sage: R.<t> = LaurentPolynomialRing(QQ)
sage: t.gcd(2)
1
sage: gcd(t^-2 + 1, t^-4 + 3*t^-1)
t^-4
sage: gcd((t^-2 + t)*(t + t^-1), (t^5 + t^8)*(1 + t^-2))
t^-3 + t^-1 + 1 + t^2
>>> from sage.all import *
>>> R = LaurentPolynomialRing(QQ, names=('t',)); (t,) = R._first_ngens(1)
>>> t.gcd(Integer(2))
1
>>> gcd(t**-Integer(2) + Integer(1), t**-Integer(4) + Integer(3)*t**-Integer(1))
t^-4
>>> gcd((t**-Integer(2) + t)*(t + t**-Integer(1)), (t**Integer(5) + t**Integer(8))*(Integer(1) + t**-Integer(2)))
t^-3 + t^-1 + 1 + t^2
R.<t> = LaurentPolynomialRing(QQ)
t.gcd(2)
gcd(t^-2 + 1, t^-4 + 3*t^-1)
gcd((t^-2 + t)*(t + t^-1), (t^5 + t^8)*(1 + t^-2))
integral()[source]

The formal integral of this Laurent series with 0 constant term.

EXAMPLES:

The integral may or may not be defined if the base ring is not a field.

sage: t = LaurentPolynomialRing(ZZ, 't').0
sage: f = 2*t^-3 + 3*t^2
sage: f.integral()
-t^-2 + t^3
>>> from sage.all import *
>>> t = LaurentPolynomialRing(ZZ, 't').gen(0)
>>> f = Integer(2)*t**-Integer(3) + Integer(3)*t**Integer(2)
>>> f.integral()
-t^-2 + t^3
t = LaurentPolynomialRing(ZZ, 't').0
f = 2*t^-3 + 3*t^2
f.integral()

sage: f = t^3
sage: f.integral()
Traceback (most recent call last):
...
ArithmeticError: coefficients of integral cannot be coerced into the base ring
>>> from sage.all import *
>>> f = t**Integer(3)
>>> f.integral()
Traceback (most recent call last):
...
ArithmeticError: coefficients of integral cannot be coerced into the base ring
f = t^3
f.integral()

The integral of \(1/t\) is \(\log(t)\), which is not given by a Laurent polynomial:

sage: t = LaurentPolynomialRing(ZZ,'t').0
sage: f = -1/t^3 - 31/t
sage: f.integral()
Traceback (most recent call last):
...
ArithmeticError: the integral of is not a Laurent polynomial, since t^-1 has nonzero coefficient
>>> from sage.all import *
>>> t = LaurentPolynomialRing(ZZ,'t').gen(0)
>>> f = -Integer(1)/t**Integer(3) - Integer(31)/t
>>> f.integral()
Traceback (most recent call last):
...
ArithmeticError: the integral of is not a Laurent polynomial, since t^-1 has nonzero coefficient
t = LaurentPolynomialRing(ZZ,'t').0
f = -1/t^3 - 31/t
f.integral()

Another example with just one negative coefficient:

sage: A.<t> = LaurentPolynomialRing(QQ)
sage: f = -2*t^(-4)
sage: f.integral()
2/3*t^-3
sage: f.integral().derivative() == f
True
>>> from sage.all import *
>>> A = LaurentPolynomialRing(QQ, names=('t',)); (t,) = A._first_ngens(1)
>>> f = -Integer(2)*t**(-Integer(4))
>>> f.integral()
2/3*t^-3
>>> f.integral().derivative() == f
True
A.<t> = LaurentPolynomialRing(QQ)
f = -2*t^(-4)
f.integral()
f.integral().derivative() == f
inverse_mod(a, m)[source]

Invert the polynomial a with respect to m, or raise a ValueError if no such inverse exists.

The parameter m may be either a single polynomial or an ideal (for consistency with inverse_mod() in other rings).

ALGORITHM: Solve the system \(as + mt = 1\), returning \(s\) as the inverse of \(a\) mod \(m\).

EXAMPLES:

sage: S.<t> = LaurentPolynomialRing(QQ)
sage: f = inverse_mod(t^-2 + 1, t^-3 + 1); f
1/2*t^2 - 1/2*t^3 - 1/2*t^4
sage: f * (t^-2 + 1) + (1/2*t^4 + 1/2*t^3) * (t^-3 + 1)
1
>>> from sage.all import *
>>> S = LaurentPolynomialRing(QQ, names=('t',)); (t,) = S._first_ngens(1)
>>> f = inverse_mod(t**-Integer(2) + Integer(1), t**-Integer(3) + Integer(1)); f
1/2*t^2 - 1/2*t^3 - 1/2*t^4
>>> f * (t**-Integer(2) + Integer(1)) + (Integer(1)/Integer(2)*t**Integer(4) + Integer(1)/Integer(2)*t**Integer(3)) * (t**-Integer(3) + Integer(1))
1
S.<t> = LaurentPolynomialRing(QQ)
f = inverse_mod(t^-2 + 1, t^-3 + 1); f
f * (t^-2 + 1) + (1/2*t^4 + 1/2*t^3) * (t^-3 + 1)
inverse_of_unit()[source]

Return the inverse of self if a unit.

EXAMPLES:

sage: R.<t> = LaurentPolynomialRing(QQ)
sage: (t^-2).inverse_of_unit()
t^2
sage: (t + 2).inverse_of_unit()
Traceback (most recent call last):
...
ArithmeticError: element is not a unit
>>> from sage.all import *
>>> R = LaurentPolynomialRing(QQ, names=('t',)); (t,) = R._first_ngens(1)
>>> (t**-Integer(2)).inverse_of_unit()
t^2
>>> (t + Integer(2)).inverse_of_unit()
Traceback (most recent call last):
...
ArithmeticError: element is not a unit
R.<t> = LaurentPolynomialRing(QQ)
(t^-2).inverse_of_unit()
(t + 2).inverse_of_unit()
is_constant()[source]

Return whether this Laurent polynomial is constant.

EXAMPLES:

sage: R.<x> = LaurentPolynomialRing(QQ)
sage: x.is_constant()
False
sage: R.one().is_constant()
True
sage: (x^-2).is_constant()
False
sage: (x^2).is_constant()
False
sage: (x^-2 + 2).is_constant()
False
sage: R(0).is_constant()
True
sage: R(42).is_constant()
True
sage: x.is_constant()
False
sage: (1/x).is_constant()
False
>>> from sage.all import *
>>> R = LaurentPolynomialRing(QQ, names=('x',)); (x,) = R._first_ngens(1)
>>> x.is_constant()
False
>>> R.one().is_constant()
True
>>> (x**-Integer(2)).is_constant()
False
>>> (x**Integer(2)).is_constant()
False
>>> (x**-Integer(2) + Integer(2)).is_constant()
False
>>> R(Integer(0)).is_constant()
True
>>> R(Integer(42)).is_constant()
True
>>> x.is_constant()
False
>>> (Integer(1)/x).is_constant()
False
R.<x> = LaurentPolynomialRing(QQ)
x.is_constant()
R.one().is_constant()
(x^-2).is_constant()
(x^2).is_constant()
(x^-2 + 2).is_constant()
R(0).is_constant()
R(42).is_constant()
x.is_constant()
(1/x).is_constant()
is_monomial()[source]

Return True if self is a monomial; that is, if self is \(x^n\) for some integer \(n\).

EXAMPLES:

sage: k.<z> = LaurentPolynomialRing(QQ)
sage: z.is_monomial()
True
sage: k(1).is_monomial()
True
sage: (z+1).is_monomial()
False
sage: (z^-2909).is_monomial()
True
sage: (38*z^-2909).is_monomial()
False
>>> from sage.all import *
>>> k = LaurentPolynomialRing(QQ, names=('z',)); (z,) = k._first_ngens(1)
>>> z.is_monomial()
True
>>> k(Integer(1)).is_monomial()
True
>>> (z+Integer(1)).is_monomial()
False
>>> (z**-Integer(2909)).is_monomial()
True
>>> (Integer(38)*z**-Integer(2909)).is_monomial()
False
k.<z> = LaurentPolynomialRing(QQ)
z.is_monomial()
k(1).is_monomial()
(z+1).is_monomial()
(z^-2909).is_monomial()
(38*z^-2909).is_monomial()
is_square(root=False)[source]

Return whether this Laurent polynomial is a square.

If root is set to True then return a pair made of the boolean answer together with None or a square root.

EXAMPLES:

sage: R.<t> = LaurentPolynomialRing(QQ)

sage: R.one().is_square()
True
sage: R(2).is_square()
False

sage: t.is_square()
False
sage: (t**-2).is_square()
True
>>> from sage.all import *
>>> R = LaurentPolynomialRing(QQ, names=('t',)); (t,) = R._first_ngens(1)

>>> R.one().is_square()
True
>>> R(Integer(2)).is_square()
False

>>> t.is_square()
False
>>> (t**-Integer(2)).is_square()
True
R.<t> = LaurentPolynomialRing(QQ)
R.one().is_square()
R(2).is_square()
t.is_square()
(t**-2).is_square()

Usage of the root option:

sage: p = (1 + t^-1 - 2*t^3)
sage: p.is_square(root=True)
(False, None)
sage: (p**2).is_square(root=True)
(True, -t^-1 - 1 + 2*t^3)
>>> from sage.all import *
>>> p = (Integer(1) + t**-Integer(1) - Integer(2)*t**Integer(3))
>>> p.is_square(root=True)
(False, None)
>>> (p**Integer(2)).is_square(root=True)
(True, -t^-1 - 1 + 2*t^3)
p = (1 + t^-1 - 2*t^3)
p.is_square(root=True)
(p**2).is_square(root=True)

The answer is dependent of the base ring:

sage: # needs sage.rings.number_field
sage: S.<u> = LaurentPolynomialRing(QQbar)
sage: (2 + 4*t + 2*t^2).is_square()
False
sage: (2 + 4*u + 2*u^2).is_square()
True
>>> from sage.all import *
>>> # needs sage.rings.number_field
>>> S = LaurentPolynomialRing(QQbar, names=('u',)); (u,) = S._first_ngens(1)
>>> (Integer(2) + Integer(4)*t + Integer(2)*t**Integer(2)).is_square()
False
>>> (Integer(2) + Integer(4)*u + Integer(2)*u**Integer(2)).is_square()
True
# needs sage.rings.number_field
S.<u> = LaurentPolynomialRing(QQbar)
(2 + 4*t + 2*t^2).is_square()
(2 + 4*u + 2*u^2).is_square()
is_unit()[source]

Return True if this Laurent polynomial is a unit in this ring.

EXAMPLES:

sage: R.<t> = LaurentPolynomialRing(QQ)
sage: (2 + t).is_unit()
False
sage: f = 2*t
sage: f.is_unit()
True
sage: 1/f
1/2*t^-1
sage: R(0).is_unit()
False
sage: R.<s> = LaurentPolynomialRing(ZZ)
sage: g = 2*s
sage: g.is_unit()
False
sage: 1/g
1/2*s^-1
>>> from sage.all import *
>>> R = LaurentPolynomialRing(QQ, names=('t',)); (t,) = R._first_ngens(1)
>>> (Integer(2) + t).is_unit()
False
>>> f = Integer(2)*t
>>> f.is_unit()
True
>>> Integer(1)/f
1/2*t^-1
>>> R(Integer(0)).is_unit()
False
>>> R = LaurentPolynomialRing(ZZ, names=('s',)); (s,) = R._first_ngens(1)
>>> g = Integer(2)*s
>>> g.is_unit()
False
>>> Integer(1)/g
1/2*s^-1
R.<t> = LaurentPolynomialRing(QQ)
(2 + t).is_unit()
f = 2*t
f.is_unit()
1/f
R(0).is_unit()
R.<s> = LaurentPolynomialRing(ZZ)
g = 2*s
g.is_unit()
1/g

ALGORITHM: A Laurent polynomial is a unit if and only if its “unit part” is a unit.

is_zero()[source]

Return 1 if self is 0, else return 0.

EXAMPLES:

sage: R.<x> = LaurentPolynomialRing(QQ)
sage: f = 1/x + x + x^2 + 3*x^4
sage: f.is_zero()
0
sage: z = 0*f
sage: z.is_zero()
1
>>> from sage.all import *
>>> R = LaurentPolynomialRing(QQ, names=('x',)); (x,) = R._first_ngens(1)
>>> f = Integer(1)/x + x + x**Integer(2) + Integer(3)*x**Integer(4)
>>> f.is_zero()
0
>>> z = Integer(0)*f
>>> z.is_zero()
1
R.<x> = LaurentPolynomialRing(QQ)
f = 1/x + x + x^2 + 3*x^4
f.is_zero()
z = 0*f
z.is_zero()
monomial_coefficients()[source]

Return a dictionary representing self.

EXAMPLES:

sage: R.<x,y> = ZZ[]
sage: Q.<t> = LaurentPolynomialRing(R)
sage: f = (x^3 + y/t^3)^3 + t^2; f
y^3*t^-9 + 3*x^3*y^2*t^-6 + 3*x^6*y*t^-3 + x^9 + t^2
sage: f.monomial_coefficients()
{-9: y^3, -6: 3*x^3*y^2, -3: 3*x^6*y, 0: x^9, 2: 1}
>>> from sage.all import *
>>> R = ZZ['x, y']; (x, y,) = R._first_ngens(2)
>>> Q = LaurentPolynomialRing(R, names=('t',)); (t,) = Q._first_ngens(1)
>>> f = (x**Integer(3) + y/t**Integer(3))**Integer(3) + t**Integer(2); f
y^3*t^-9 + 3*x^3*y^2*t^-6 + 3*x^6*y*t^-3 + x^9 + t^2
>>> f.monomial_coefficients()
{-9: y^3, -6: 3*x^3*y^2, -3: 3*x^6*y, 0: x^9, 2: 1}
R.<x,y> = ZZ[]
Q.<t> = LaurentPolynomialRing(R)
f = (x^3 + y/t^3)^3 + t^2; f
f.monomial_coefficients()

dict is an alias:

sage: f.dict()
{-9: y^3, -6: 3*x^3*y^2, -3: 3*x^6*y, 0: x^9, 2: 1}
>>> from sage.all import *
>>> f.dict()
{-9: y^3, -6: 3*x^3*y^2, -3: 3*x^6*y, 0: x^9, 2: 1}
f.dict()
monomial_reduction()[source]

Return the decomposition as a polynomial and a power of the variable. Constructed for compatibility with the multivariate case.

OUTPUT:

A tuple (u, t^n) where u is the underlying polynomial and n is the power of the exponent shift.

EXAMPLES:

sage: R.<x> = LaurentPolynomialRing(QQ)
sage: f = 1/x + x^2 + 3*x^4
sage: f.monomial_reduction()
(3*x^5 + x^3 + 1, x^-1)
>>> from sage.all import *
>>> R = LaurentPolynomialRing(QQ, names=('x',)); (x,) = R._first_ngens(1)
>>> f = Integer(1)/x + x**Integer(2) + Integer(3)*x**Integer(4)
>>> f.monomial_reduction()
(3*x^5 + x^3 + 1, x^-1)
R.<x> = LaurentPolynomialRing(QQ)
f = 1/x + x^2 + 3*x^4
f.monomial_reduction()
number_of_terms()[source]

Return the number of nonzero coefficients of self.

Also called weight, hamming weight or sparsity.

EXAMPLES:

sage: R.<x> = LaurentPolynomialRing(ZZ)
sage: f = x^3 - 1
sage: f.number_of_terms()
2
sage: R(0).number_of_terms()
0
sage: f = (x+1)^100
sage: f.number_of_terms()
101
>>> from sage.all import *
>>> R = LaurentPolynomialRing(ZZ, names=('x',)); (x,) = R._first_ngens(1)
>>> f = x**Integer(3) - Integer(1)
>>> f.number_of_terms()
2
>>> R(Integer(0)).number_of_terms()
0
>>> f = (x+Integer(1))**Integer(100)
>>> f.number_of_terms()
101
R.<x> = LaurentPolynomialRing(ZZ)
f = x^3 - 1
f.number_of_terms()
R(0).number_of_terms()
f = (x+1)^100
f.number_of_terms()

The method hamming_weight() is an alias:

sage: f.hamming_weight()
101
>>> from sage.all import *
>>> f.hamming_weight()
101
f.hamming_weight()
polynomial_construction()[source]

Return the polynomial and the shift in power used to construct the Laurent polynomial \(t^n u\).

OUTPUT:

A tuple (u, n) where u is the underlying polynomial and n is the power of the exponent shift.

EXAMPLES:

sage: R.<x> = LaurentPolynomialRing(QQ)
sage: f = 1/x + x^2 + 3*x^4
sage: f.polynomial_construction()
(3*x^5 + x^3 + 1, -1)
>>> from sage.all import *
>>> R = LaurentPolynomialRing(QQ, names=('x',)); (x,) = R._first_ngens(1)
>>> f = Integer(1)/x + x**Integer(2) + Integer(3)*x**Integer(4)
>>> f.polynomial_construction()
(3*x^5 + x^3 + 1, -1)
R.<x> = LaurentPolynomialRing(QQ)
f = 1/x + x^2 + 3*x^4
f.polynomial_construction()
quo_rem(other)[source]

Divide self by other and return a quotient q and a remainder r such that self == q * other + r.

EXAMPLES:

sage: R.<t> = LaurentPolynomialRing(QQ)
sage: (t^-3 - t^3).quo_rem(t^-1 - t)
(t^-2 + 1 + t^2, 0)
sage: (t^-2 + 3 + t).quo_rem(t^-4)
(t^2 + 3*t^4 + t^5, 0)

sage: num = t^-2 + t
sage: den = t^-2 + 1
sage: q, r = num.quo_rem(den)
sage: num == q * den + r
True
>>> from sage.all import *
>>> R = LaurentPolynomialRing(QQ, names=('t',)); (t,) = R._first_ngens(1)
>>> (t**-Integer(3) - t**Integer(3)).quo_rem(t**-Integer(1) - t)
(t^-2 + 1 + t^2, 0)
>>> (t**-Integer(2) + Integer(3) + t).quo_rem(t**-Integer(4))
(t^2 + 3*t^4 + t^5, 0)

>>> num = t**-Integer(2) + t
>>> den = t**-Integer(2) + Integer(1)
>>> q, r = num.quo_rem(den)
>>> num == q * den + r
True
R.<t> = LaurentPolynomialRing(QQ)
(t^-3 - t^3).quo_rem(t^-1 - t)
(t^-2 + 3 + t).quo_rem(t^-4)
num = t^-2 + t
den = t^-2 + 1
q, r = num.quo_rem(den)
num == q * den + r
residue()[source]

Return the residue of self.

The residue is the coefficient of \(t^-1\).

EXAMPLES:

sage: R.<t> = LaurentPolynomialRing(QQ)
sage: f = 3*t^-2 - t^-1 + 3 + t^2
sage: f.residue()
-1
sage: g = -2*t^-2 + 4 + 3*t
sage: g.residue()
0
sage: f.residue().parent()
Rational Field
>>> from sage.all import *
>>> R = LaurentPolynomialRing(QQ, names=('t',)); (t,) = R._first_ngens(1)
>>> f = Integer(3)*t**-Integer(2) - t**-Integer(1) + Integer(3) + t**Integer(2)
>>> f.residue()
-1
>>> g = -Integer(2)*t**-Integer(2) + Integer(4) + Integer(3)*t
>>> g.residue()
0
>>> f.residue().parent()
Rational Field
R.<t> = LaurentPolynomialRing(QQ)
f = 3*t^-2 - t^-1 + 3 + t^2
f.residue()
g = -2*t^-2 + 4 + 3*t
g.residue()
f.residue().parent()
shift(k)[source]

Return this Laurent polynomial multiplied by the power \(t^n\). Does not change this polynomial.

EXAMPLES:

sage: R.<t> = LaurentPolynomialRing(QQ['y'])
sage: f = (t+t^-1)^4; f
t^-4 + 4*t^-2 + 6 + 4*t^2 + t^4
sage: f.shift(10)
t^6 + 4*t^8 + 6*t^10 + 4*t^12 + t^14
sage: f >> 10
t^-14 + 4*t^-12 + 6*t^-10 + 4*t^-8 + t^-6
sage: f << 4
1 + 4*t^2 + 6*t^4 + 4*t^6 + t^8
>>> from sage.all import *
>>> R = LaurentPolynomialRing(QQ['y'], names=('t',)); (t,) = R._first_ngens(1)
>>> f = (t+t**-Integer(1))**Integer(4); f
t^-4 + 4*t^-2 + 6 + 4*t^2 + t^4
>>> f.shift(Integer(10))
t^6 + 4*t^8 + 6*t^10 + 4*t^12 + t^14
>>> f >> Integer(10)
t^-14 + 4*t^-12 + 6*t^-10 + 4*t^-8 + t^-6
>>> f << Integer(4)
1 + 4*t^2 + 6*t^4 + 4*t^6 + t^8
R.<t> = LaurentPolynomialRing(QQ['y'])
f = (t+t^-1)^4; f
f.shift(10)
f >> 10
f << 4
truncate(n)[source]

Return a polynomial with degree at most \(n-1\) whose \(j\)-th coefficients agree with self for all \(j < n\).

EXAMPLES:

sage: R.<x> = LaurentPolynomialRing(QQ)
sage: f = 1/x^12 + x^3 + x^5 + x^9
sage: f.truncate(10)
x^-12 + x^3 + x^5 + x^9
sage: f.truncate(5)
x^-12 + x^3
sage: f.truncate(-16)
0
>>> from sage.all import *
>>> R = LaurentPolynomialRing(QQ, names=('x',)); (x,) = R._first_ngens(1)
>>> f = Integer(1)/x**Integer(12) + x**Integer(3) + x**Integer(5) + x**Integer(9)
>>> f.truncate(Integer(10))
x^-12 + x^3 + x^5 + x^9
>>> f.truncate(Integer(5))
x^-12 + x^3
>>> f.truncate(-Integer(16))
0
R.<x> = LaurentPolynomialRing(QQ)
f = 1/x^12 + x^3 + x^5 + x^9
f.truncate(10)
f.truncate(5)
f.truncate(-16)
valuation(p=None)[source]

Return the valuation of self.

The valuation of a Laurent polynomial \(t^n u\) is \(n\) plus the valuation of \(u\).

EXAMPLES:

sage: R.<x> = LaurentPolynomialRing(ZZ)
sage: f = 1/x + x^2 + 3*x^4
sage: g = 1 - x + x^2 - x^4
sage: f.valuation()
-1
sage: g.valuation()
0
>>> from sage.all import *
>>> R = LaurentPolynomialRing(ZZ, names=('x',)); (x,) = R._first_ngens(1)
>>> f = Integer(1)/x + x**Integer(2) + Integer(3)*x**Integer(4)
>>> g = Integer(1) - x + x**Integer(2) - x**Integer(4)
>>> f.valuation()
-1
>>> g.valuation()
0
R.<x> = LaurentPolynomialRing(ZZ)
f = 1/x + x^2 + 3*x^4
g = 1 - x + x^2 - x^4
f.valuation()
g.valuation()
variable_name()[source]

Return the name of variable of self as a string.

EXAMPLES:

sage: R.<x> = LaurentPolynomialRing(QQ)
sage: f = 1/x + x^2 + 3*x^4
sage: f.variable_name()
'x'
>>> from sage.all import *
>>> R = LaurentPolynomialRing(QQ, names=('x',)); (x,) = R._first_ngens(1)
>>> f = Integer(1)/x + x**Integer(2) + Integer(3)*x**Integer(4)
>>> f.variable_name()
'x'
R.<x> = LaurentPolynomialRing(QQ)
f = 1/x + x^2 + 3*x^4
f.variable_name()
variables()[source]

Return the tuple of variables occurring in this Laurent polynomial.

EXAMPLES:

sage: R.<x> = LaurentPolynomialRing(QQ)
sage: f = 1/x + x^2 + 3*x^4
sage: f.variables()
(x,)
sage: R.one().variables()
()
>>> from sage.all import *
>>> R = LaurentPolynomialRing(QQ, names=('x',)); (x,) = R._first_ngens(1)
>>> f = Integer(1)/x + x**Integer(2) + Integer(3)*x**Integer(4)
>>> f.variables()
(x,)
>>> R.one().variables()
()
R.<x> = LaurentPolynomialRing(QQ)
f = 1/x + x^2 + 3*x^4
f.variables()
R.one().variables()
xgcd(other)[source]

Extended gcd() for univariate Laurent polynomial rings over a field.

OUTPUT:

A triple (g, p, q) such that g is the gcd() of self (\(= a\)) and other (\(= b\)), and p and q are cofactors satisfying the Bezout identity

\[g = p \cdot a + q \cdot b.\]

EXAMPLES:

sage: S.<t> = LaurentPolynomialRing(QQ)
sage: a = t^-2 + 1
sage: b = t^-3 + 1
sage: g, p, q = a.xgcd(b); (g, p, q)
(t^-3, 1/2*t^-1 - 1/2 - 1/2*t, 1/2 + 1/2*t)
sage: g == p * a + q * b
True
sage: g == a.gcd(b)
True
sage: t.xgcd(t)
(t, 0, 1)
sage: t.xgcd(5)
(1, 0, 1/5)
>>> from sage.all import *
>>> S = LaurentPolynomialRing(QQ, names=('t',)); (t,) = S._first_ngens(1)
>>> a = t**-Integer(2) + Integer(1)
>>> b = t**-Integer(3) + Integer(1)
>>> g, p, q = a.xgcd(b); (g, p, q)
(t^-3, 1/2*t^-1 - 1/2 - 1/2*t, 1/2 + 1/2*t)
>>> g == p * a + q * b
True
>>> g == a.gcd(b)
True
>>> t.xgcd(t)
(t, 0, 1)
>>> t.xgcd(Integer(5))
(1, 0, 1/5)
S.<t> = LaurentPolynomialRing(QQ)
a = t^-2 + 1
b = t^-3 + 1
g, p, q = a.xgcd(b); (g, p, q)
g == p * a + q * b
g == a.gcd(b)
t.xgcd(t)
t.xgcd(5)