# Elements lying in extension of rings#

AUTHOR:

• Xavier Caruso (2019)

class sage.rings.ring_extension_element.RingExtensionElement[source]#

Generic class for elements lying in ring extensions.

Return the additive order of this element.

EXAMPLES:

sage: K.<a> = GF(5^4).over(GF(5^2))                                         # needs sage.rings.finite_rings
5

>>> from sage.all import *
>>> K = GF(Integer(5)**Integer(4)).over(GF(Integer(5)**Integer(2)), names=('a',)); (a,) = K._first_ngens(1)# needs sage.rings.finite_rings
5

backend(force=False)[source]#

Return the backend of this element.

INPUT:

• force – a boolean (default: False); if False, raise an error if the backend is not exposed

EXAMPLES:

sage: # needs sage.rings.finite_rings
sage: F = GF(5^2)
sage: K.<z> = GF(5^4).over(F)
sage: x = z^10
sage: x
(z2 + 2) + (3*z2 + 1)*z
sage: y = x.backend()
sage: y
4*z4^3 + 2*z4^2 + 4*z4 + 4
sage: y.parent()
Finite Field in z4 of size 5^4

>>> from sage.all import *
>>> # needs sage.rings.finite_rings
>>> F = GF(Integer(5)**Integer(2))
>>> K = GF(Integer(5)**Integer(4)).over(F, names=('z',)); (z,) = K._first_ngens(1)
>>> x = z**Integer(10)
>>> x
(z2 + 2) + (3*z2 + 1)*z
>>> y = x.backend()
>>> y
4*z4^3 + 2*z4^2 + 4*z4 + 4
>>> y.parent()
Finite Field in z4 of size 5^4

in_base()[source]#

Return this element as an element of the base.

EXAMPLES:

sage: # needs sage.rings.finite_rings
sage: F = GF(5^2)
sage: K.<z> = GF(5^4).over(F)
sage: x = z^3 + z^2 + z + 4
sage: y = x.in_base()
sage: y
z2 + 1
sage: y.parent()
Finite Field in z2 of size 5^2

>>> from sage.all import *
>>> # needs sage.rings.finite_rings
>>> F = GF(Integer(5)**Integer(2))
>>> K = GF(Integer(5)**Integer(4)).over(F, names=('z',)); (z,) = K._first_ngens(1)
>>> x = z**Integer(3) + z**Integer(2) + z + Integer(4)
>>> y = x.in_base()
>>> y
z2 + 1
>>> y.parent()
Finite Field in z2 of size 5^2


When the element is not in the base, an error is raised:

sage: z.in_base()                                                           # needs sage.rings.finite_rings
Traceback (most recent call last):
...
ValueError: z is not in the base

>>> from sage.all import *
>>> z.in_base()                                                           # needs sage.rings.finite_rings
Traceback (most recent call last):
...
ValueError: z is not in the base

sage: # needs sage.rings.finite_rings
sage: S.<X> = F[]
sage: E = S.over(F)
sage: f = E(1)
sage: g = f.in_base(); g
1
sage: g.parent()
Finite Field in z2 of size 5^2

>>> from sage.all import *
>>> # needs sage.rings.finite_rings
>>> S = F['X']; (X,) = S._first_ngens(1)
>>> E = S.over(F)
>>> f = E(Integer(1))
>>> g = f.in_base(); g
1
>>> g.parent()
Finite Field in z2 of size 5^2

is_nilpotent()[source]#

Return whether if this element is nilpotent in this ring.

EXAMPLES:

sage: A.<x> = PolynomialRing(QQ)
sage: E = A.over(QQ)
sage: E(0).is_nilpotent()
True
sage: E(x).is_nilpotent()
False

>>> from sage.all import *
>>> A = PolynomialRing(QQ, names=('x',)); (x,) = A._first_ngens(1)
>>> E = A.over(QQ)
>>> E(Integer(0)).is_nilpotent()
True
>>> E(x).is_nilpotent()
False

is_prime()[source]#

Return whether this element is a prime element in this ring.

EXAMPLES:

sage: A.<x> = PolynomialRing(QQ)
sage: E = A.over(QQ)
sage: E(x^2 + 1).is_prime()                                                 # needs sage.libs.pari
True
sage: E(x^2 - 1).is_prime()                                                 # needs sage.libs.pari
False

>>> from sage.all import *
>>> A = PolynomialRing(QQ, names=('x',)); (x,) = A._first_ngens(1)
>>> E = A.over(QQ)
>>> E(x**Integer(2) + Integer(1)).is_prime()                                                 # needs sage.libs.pari
True
>>> E(x**Integer(2) - Integer(1)).is_prime()                                                 # needs sage.libs.pari
False

is_square(root=False)[source]#

Return whether this element is a square in this ring.

INPUT:

• root – a boolean (default: False); if True, return also a square root

EXAMPLES:

sage: # needs sage.rings.finite_rings
sage: K.<a> = GF(5^3).over()
sage: a.is_square()
False
sage: a.is_square(root=True)
(False, None)
sage: b = a + 1
sage: b.is_square()
True
sage: b.is_square(root=True)
(True, 2 + 3*a + a^2)

>>> from sage.all import *
>>> # needs sage.rings.finite_rings
>>> K = GF(Integer(5)**Integer(3)).over(names=('a',)); (a,) = K._first_ngens(1)
>>> a.is_square()
False
>>> a.is_square(root=True)
(False, None)
>>> b = a + Integer(1)
>>> b.is_square()
True
>>> b.is_square(root=True)
(True, 2 + 3*a + a^2)

is_unit()[source]#

Return whether if this element is a unit in this ring.

EXAMPLES:

sage: A.<x> = PolynomialRing(QQ)
sage: E = A.over(QQ)
sage: E(4).is_unit()
True
sage: E(x).is_unit()
False

>>> from sage.all import *
>>> A = PolynomialRing(QQ, names=('x',)); (x,) = A._first_ngens(1)
>>> E = A.over(QQ)
>>> E(Integer(4)).is_unit()
True
>>> E(x).is_unit()
False

multiplicative_order()[source]#

Return the multiplicite order of this element.

EXAMPLES:

sage: K.<a> = GF(5^4).over(GF(5^2))                                         # needs sage.rings.finite_rings
sage: a.multiplicative_order()                                              # needs sage.rings.finite_rings
624

>>> from sage.all import *
>>> K = GF(Integer(5)**Integer(4)).over(GF(Integer(5)**Integer(2)), names=('a',)); (a,) = K._first_ngens(1)# needs sage.rings.finite_rings
>>> a.multiplicative_order()                                              # needs sage.rings.finite_rings
624

sqrt(extend=True, all=False, name=None)[source]#

Return a square root or all square roots of this element.

INPUT:

• extend – a boolean (default: True); if “True”, return a square root in an extension ring, if necessary. Otherwise, raise a ValueError if the root is not in the ring

• all – a boolean (default: False); if True, return all square roots of this element, instead of just one.

• name – Required when extend=True and self is not a square. This will be the name of the generator extension.

Note

The option extend=True is often not implemented.

EXAMPLES:

sage: # needs sage.rings.finite_rings
sage: K.<a> = GF(5^3).over()
sage: b = a + 1
sage: b.sqrt()
2 + 3*a + a^2
sage: b.sqrt(all=True)
[2 + 3*a + a^2, 3 + 2*a - a^2]

>>> from sage.all import *
>>> # needs sage.rings.finite_rings
>>> K = GF(Integer(5)**Integer(3)).over(names=('a',)); (a,) = K._first_ngens(1)
>>> b = a + Integer(1)
>>> b.sqrt()
2 + 3*a + a^2
>>> b.sqrt(all=True)
[2 + 3*a + a^2, 3 + 2*a - a^2]

class sage.rings.ring_extension_element.RingExtensionFractionFieldElement[source]#

A class for elements lying in fraction fields of ring extensions.

denominator()[source]#

Return the denominator of this element.

EXAMPLES:

sage: # needs sage.rings.number_field
sage: R.<x> = ZZ[]
sage: A.<a> = ZZ.extension(x^2 - 2)
sage: OK = A.over()  # over ZZ
sage: K = OK.fraction_field(); K
Fraction Field of
Maximal Order generated by a in Number Field in a
with defining polynomial x^2 - 2 over its base
sage: x = K(1/a); x
a/2
sage: denom = x.denominator(); denom
2

>>> from sage.all import *
>>> # needs sage.rings.number_field
>>> R = ZZ['x']; (x,) = R._first_ngens(1)
>>> A = ZZ.extension(x**Integer(2) - Integer(2), names=('a',)); (a,) = A._first_ngens(1)
>>> OK = A.over()  # over ZZ
>>> K = OK.fraction_field(); K
Fraction Field of
Maximal Order generated by a in Number Field in a
with defining polynomial x^2 - 2 over its base
>>> x = K(Integer(1)/a); x
a/2
>>> denom = x.denominator(); denom
2


The denominator is an element of the ring which was used to construct the fraction field:

sage: denom.parent()                                                        # needs sage.rings.number_field
Maximal Order generated by a in Number Field in a with defining polynomial x^2 - 2 over its base
sage: denom.parent() is OK                                                  # needs sage.rings.number_field
True

>>> from sage.all import *
>>> denom.parent()                                                        # needs sage.rings.number_field
Maximal Order generated by a in Number Field in a with defining polynomial x^2 - 2 over its base
>>> denom.parent() is OK                                                  # needs sage.rings.number_field
True

numerator()[source]#

Return the numerator of this element.

EXAMPLES:

sage: # needs sage.rings.number_field
sage: x = polygen(ZZ, 'x')
sage: A.<a> = ZZ.extension(x^2 - 2)
sage: OK = A.over()  # over ZZ
sage: K = OK.fraction_field(); K
Fraction Field of Maximal Order generated by a in Number Field in a
with defining polynomial x^2 - 2 over its base
sage: x = K(1/a); x
a/2
sage: num = x.numerator(); num
a

>>> from sage.all import *
>>> # needs sage.rings.number_field
>>> x = polygen(ZZ, 'x')
>>> A = ZZ.extension(x**Integer(2) - Integer(2), names=('a',)); (a,) = A._first_ngens(1)
>>> OK = A.over()  # over ZZ
>>> K = OK.fraction_field(); K
Fraction Field of Maximal Order generated by a in Number Field in a
with defining polynomial x^2 - 2 over its base
>>> x = K(Integer(1)/a); x
a/2
>>> num = x.numerator(); num
a


The numerator is an element of the ring which was used to construct the fraction field:

sage: num.parent()                                                          # needs sage.rings.number_field
Maximal Order generated by a in Number Field in a
with defining polynomial x^2 - 2 over its base
sage: num.parent() is OK                                                    # needs sage.rings.number_field
True

>>> from sage.all import *
>>> num.parent()                                                          # needs sage.rings.number_field
Maximal Order generated by a in Number Field in a
with defining polynomial x^2 - 2 over its base
>>> num.parent() is OK                                                    # needs sage.rings.number_field
True

class sage.rings.ring_extension_element.RingExtensionWithBasisElement[source]#

A class for elements lying in finite free extensions.

charpoly(base=None, var='x')[source]#

Return the characteristic polynomial of this element over base.

INPUT:

• base – a commutative ring (which might be itself an extension) or None

EXAMPLES:

sage: # needs sage.rings.finite_rings
sage: F = GF(5)
sage: K.<a> = GF(5^3).over(F)
sage: L.<b> = GF(5^6).over(K)
sage: u = a/(1+b)
sage: chi = u.charpoly(K); chi
x^2 + (1 + 2*a + 3*a^2)*x + 3 + 2*a^2

>>> from sage.all import *
>>> # needs sage.rings.finite_rings
>>> F = GF(Integer(5))
>>> K = GF(Integer(5)**Integer(3)).over(F, names=('a',)); (a,) = K._first_ngens(1)
>>> L = GF(Integer(5)**Integer(6)).over(K, names=('b',)); (b,) = L._first_ngens(1)
>>> u = a/(Integer(1)+b)
>>> chi = u.charpoly(K); chi
x^2 + (1 + 2*a + 3*a^2)*x + 3 + 2*a^2


We check that the charpoly has coefficients in the base ring:

sage: chi.base_ring()                                                       # needs sage.rings.finite_rings
Field in a with defining polynomial x^3 + 3*x + 3 over its base
sage: chi.base_ring() is K                                                  # needs sage.rings.finite_rings
True

>>> from sage.all import *
>>> chi.base_ring()                                                       # needs sage.rings.finite_rings
Field in a with defining polynomial x^3 + 3*x + 3 over its base
>>> chi.base_ring() is K                                                  # needs sage.rings.finite_rings
True


and that it annihilates u:

sage: chi(u)                                                                # needs sage.rings.finite_rings
0

>>> from sage.all import *
>>> chi(u)                                                                # needs sage.rings.finite_rings
0


Similarly, one can compute the characteristic polynomial over F:

sage: u.charpoly(F)                                                         # needs sage.rings.finite_rings
x^6 + x^4 + 2*x^3 + 3*x + 4

>>> from sage.all import *
>>> u.charpoly(F)                                                         # needs sage.rings.finite_rings
x^6 + x^4 + 2*x^3 + 3*x + 4


A different variable name can be specified:

sage: u.charpoly(F, var='t')                                                # needs sage.rings.finite_rings
t^6 + t^4 + 2*t^3 + 3*t + 4

>>> from sage.all import *
>>> u.charpoly(F, var='t')                                                # needs sage.rings.finite_rings
t^6 + t^4 + 2*t^3 + 3*t + 4


If base is omitted, it is set to its default which is the base of the extension:

sage: u.charpoly()                                                          # needs sage.rings.finite_rings
x^2 + (1 + 2*a + 3*a^2)*x + 3 + 2*a^2

>>> from sage.all import *
>>> u.charpoly()                                                          # needs sage.rings.finite_rings
x^2 + (1 + 2*a + 3*a^2)*x + 3 + 2*a^2


Note that base must be an explicit base over which the extension has been defined (as listed by the method bases()):

sage: u.charpoly(GF(5^2))                                                   # needs sage.rings.finite_rings
Traceback (most recent call last):
...
ValueError: not (explicitly) defined over Finite Field in z2 of size 5^2

>>> from sage.all import *
>>> u.charpoly(GF(Integer(5)**Integer(2)))                                                   # needs sage.rings.finite_rings
Traceback (most recent call last):
...
ValueError: not (explicitly) defined over Finite Field in z2 of size 5^2

matrix(base=None)[source]#

Return the matrix of the multiplication by this element (in the basis output by basis_over()).

INPUT:

• base – a commutative ring (which might be itself an extension) or None

EXAMPLES:

sage: # needs sage.rings.finite_rings
sage: K.<a> = GF(5^3).over()  # over GF(5)
sage: L.<b> = GF(5^6).over(K)
sage: u = a/(1+b)
sage: u
(2 + a + 3*a^2) + (3 + 3*a + a^2)*b
sage: b*u
(3 + 2*a^2) + (2 + 2*a - a^2)*b
sage: u.matrix(K)
[2 + a + 3*a^2 3 + 3*a + a^2]
[    3 + 2*a^2 2 + 2*a - a^2]
sage: u.matrix(GF(5))
[2 1 3 3 3 1]
[1 3 1 2 0 3]
[2 3 3 1 3 0]
[3 0 2 2 2 4]
[4 2 0 3 0 2]
[0 4 2 4 2 0]

>>> from sage.all import *
>>> # needs sage.rings.finite_rings
>>> K = GF(Integer(5)**Integer(3)).over(names=('a',)); (a,) = K._first_ngens(1)# over GF(5)
>>> L = GF(Integer(5)**Integer(6)).over(K, names=('b',)); (b,) = L._first_ngens(1)
>>> u = a/(Integer(1)+b)
>>> u
(2 + a + 3*a^2) + (3 + 3*a + a^2)*b
>>> b*u
(3 + 2*a^2) + (2 + 2*a - a^2)*b
>>> u.matrix(K)
[2 + a + 3*a^2 3 + 3*a + a^2]
[    3 + 2*a^2 2 + 2*a - a^2]
>>> u.matrix(GF(Integer(5)))
[2 1 3 3 3 1]
[1 3 1 2 0 3]
[2 3 3 1 3 0]
[3 0 2 2 2 4]
[4 2 0 3 0 2]
[0 4 2 4 2 0]


If base is omitted, it is set to its default which is the base of the extension:

sage: u.matrix()                                                            # needs sage.rings.finite_rings
[2 + a + 3*a^2 3 + 3*a + a^2]
[    3 + 2*a^2 2 + 2*a - a^2]

>>> from sage.all import *
>>> u.matrix()                                                            # needs sage.rings.finite_rings
[2 + a + 3*a^2 3 + 3*a + a^2]
[    3 + 2*a^2 2 + 2*a - a^2]


Note that base must be an explicit base over which the extension has been defined (as listed by the method bases()):

sage: u.matrix(GF(5^2))                                                     # needs sage.rings.finite_rings
Traceback (most recent call last):
...
ValueError: not (explicitly) defined over Finite Field in z2 of size 5^2

>>> from sage.all import *
>>> u.matrix(GF(Integer(5)**Integer(2)))                                                     # needs sage.rings.finite_rings
Traceback (most recent call last):
...
ValueError: not (explicitly) defined over Finite Field in z2 of size 5^2

minpoly(base=None, var='x')[source]#

Return the minimal polynomial of this element over base.

INPUT:

• base – a commutative ring (which might be itself an extension) or None

EXAMPLES:

sage: # needs sage.rings.finite_rings
sage: F = GF(5)
sage: K.<a> = GF(5^3).over(F)
sage: L.<b> = GF(5^6).over(K)
sage: u = 1 / (a+b)
sage: chi = u.minpoly(K); chi
x^2 + (2*a + a^2)*x - 1 + a

>>> from sage.all import *
>>> # needs sage.rings.finite_rings
>>> F = GF(Integer(5))
>>> K = GF(Integer(5)**Integer(3)).over(F, names=('a',)); (a,) = K._first_ngens(1)
>>> L = GF(Integer(5)**Integer(6)).over(K, names=('b',)); (b,) = L._first_ngens(1)
>>> u = Integer(1) / (a+b)
>>> chi = u.minpoly(K); chi
x^2 + (2*a + a^2)*x - 1 + a


We check that the minimal polynomial has coefficients in the base ring:

sage: chi.base_ring()                                                       # needs sage.rings.finite_rings
Field in a with defining polynomial x^3 + 3*x + 3 over its base
sage: chi.base_ring() is K                                                  # needs sage.rings.finite_rings
True

>>> from sage.all import *
>>> chi.base_ring()                                                       # needs sage.rings.finite_rings
Field in a with defining polynomial x^3 + 3*x + 3 over its base
>>> chi.base_ring() is K                                                  # needs sage.rings.finite_rings
True


and that it annihilates u:

sage: chi(u)                                                                # needs sage.rings.finite_rings
0

>>> from sage.all import *
>>> chi(u)                                                                # needs sage.rings.finite_rings
0


Similarly, one can compute the minimal polynomial over F:

sage: u.minpoly(F)                                                          # needs sage.rings.finite_rings
x^6 + 4*x^5 + x^4 + 2*x^2 + 3

>>> from sage.all import *
>>> u.minpoly(F)                                                          # needs sage.rings.finite_rings
x^6 + 4*x^5 + x^4 + 2*x^2 + 3


A different variable name can be specified:

sage: u.minpoly(F, var='t')                                                 # needs sage.rings.finite_rings
t^6 + 4*t^5 + t^4 + 2*t^2 + 3

>>> from sage.all import *
>>> u.minpoly(F, var='t')                                                 # needs sage.rings.finite_rings
t^6 + 4*t^5 + t^4 + 2*t^2 + 3


If base is omitted, it is set to its default which is the base of the extension:

sage: u.minpoly()                                                           # needs sage.rings.finite_rings
x^2 + (2*a + a^2)*x - 1 + a

>>> from sage.all import *
>>> u.minpoly()                                                           # needs sage.rings.finite_rings
x^2 + (2*a + a^2)*x - 1 + a


Note that base must be an explicit base over which the extension has been defined (as listed by the method bases()):

sage: u.minpoly(GF(5^2))                                                    # needs sage.rings.finite_rings
Traceback (most recent call last):
...
ValueError: not (explicitly) defined over Finite Field in z2 of size 5^2

>>> from sage.all import *
>>> u.minpoly(GF(Integer(5)**Integer(2)))                                                    # needs sage.rings.finite_rings
Traceback (most recent call last):
...
ValueError: not (explicitly) defined over Finite Field in z2 of size 5^2

norm(base=None)[source]#

Return the norm of this element over base.

INPUT:

• base – a commutative ring (which might be itself an extension) or None

EXAMPLES:

sage: # needs sage.rings.finite_rings
sage: F = GF(5)
sage: K.<a> = GF(5^3).over(F)
sage: L.<b> = GF(5^6).over(K)
sage: u = a/(1+b)
sage: nr = u.norm(K); nr
3 + 2*a^2

>>> from sage.all import *
>>> # needs sage.rings.finite_rings
>>> F = GF(Integer(5))
>>> K = GF(Integer(5)**Integer(3)).over(F, names=('a',)); (a,) = K._first_ngens(1)
>>> L = GF(Integer(5)**Integer(6)).over(K, names=('b',)); (b,) = L._first_ngens(1)
>>> u = a/(Integer(1)+b)
>>> nr = u.norm(K); nr
3 + 2*a^2


We check that the norm lives in the base ring:

sage: nr.parent()                                                           # needs sage.rings.finite_rings
Field in a with defining polynomial x^3 + 3*x + 3 over its base
sage: nr.parent() is K                                                      # needs sage.rings.finite_rings
True

>>> from sage.all import *
>>> nr.parent()                                                           # needs sage.rings.finite_rings
Field in a with defining polynomial x^3 + 3*x + 3 over its base
>>> nr.parent() is K                                                      # needs sage.rings.finite_rings
True


Similarly, one can compute the norm over F:

sage: u.norm(F)                                                             # needs sage.rings.finite_rings
4

>>> from sage.all import *
>>> u.norm(F)                                                             # needs sage.rings.finite_rings
4


We check the transitivity of the norm:

sage: u.norm(F) == nr.norm(F)                                               # needs sage.rings.finite_rings
True

>>> from sage.all import *
>>> u.norm(F) == nr.norm(F)                                               # needs sage.rings.finite_rings
True


If base is omitted, it is set to its default which is the base of the extension:

sage: u.norm()                                                              # needs sage.rings.finite_rings
3 + 2*a^2

>>> from sage.all import *
>>> u.norm()                                                              # needs sage.rings.finite_rings
3 + 2*a^2


Note that base must be an explicit base over which the extension has been defined (as listed by the method bases()):

sage: u.norm(GF(5^2))                                                       # needs sage.rings.finite_rings
Traceback (most recent call last):
...
ValueError: not (explicitly) defined over Finite Field in z2 of size 5^2

>>> from sage.all import *
>>> u.norm(GF(Integer(5)**Integer(2)))                                                       # needs sage.rings.finite_rings
Traceback (most recent call last):
...
ValueError: not (explicitly) defined over Finite Field in z2 of size 5^2

polynomial(base=None, var='x')[source]#

Return a polynomial (in one or more variables) over base whose evaluation at the generators of the parent equals this element.

INPUT:

• base – a commutative ring (which might be itself an extension) or None

EXAMPLES:

sage: # needs sage.rings.finite_rings
sage: F.<a> = GF(5^2).over()  # over GF(5)
sage: K.<b> = GF(5^4).over(F)
sage: L.<c> = GF(5^12).over(K)
sage: u = 1/(a + b + c); u
(2 + (-1 - a)*b) + ((2 + 3*a) + (1 - a)*b)*c + ((-1 - a) - a*b)*c^2
sage: P = u.polynomial(K); P
((-1 - a) - a*b)*x^2 + ((2 + 3*a) + (1 - a)*b)*x + 2 + (-1 - a)*b
sage: P.base_ring() is K
True
sage: P(c) == u
True

>>> from sage.all import *
>>> # needs sage.rings.finite_rings
>>> F = GF(Integer(5)**Integer(2)).over(names=('a',)); (a,) = F._first_ngens(1)# over GF(5)
>>> K = GF(Integer(5)**Integer(4)).over(F, names=('b',)); (b,) = K._first_ngens(1)
>>> L = GF(Integer(5)**Integer(12)).over(K, names=('c',)); (c,) = L._first_ngens(1)
>>> u = Integer(1)/(a + b + c); u
(2 + (-1 - a)*b) + ((2 + 3*a) + (1 - a)*b)*c + ((-1 - a) - a*b)*c^2
>>> P = u.polynomial(K); P
((-1 - a) - a*b)*x^2 + ((2 + 3*a) + (1 - a)*b)*x + 2 + (-1 - a)*b
>>> P.base_ring() is K
True
>>> P(c) == u
True


When the base is $$F$$, we obtain a bivariate polynomial:

sage: P = u.polynomial(F); P                                                # needs sage.rings.finite_rings
(-a)*x0^2*x1 + (-1 - a)*x0^2 + (1 - a)*x0*x1 + (2 + 3*a)*x0 + (-1 - a)*x1 + 2

>>> from sage.all import *
>>> P = u.polynomial(F); P                                                # needs sage.rings.finite_rings
(-a)*x0^2*x1 + (-1 - a)*x0^2 + (1 - a)*x0*x1 + (2 + 3*a)*x0 + (-1 - a)*x1 + 2


We check that its value at the generators is the element we started with:

sage: L.gens(F)                                                             # needs sage.rings.finite_rings
(c, b)
sage: P(c, b) == u                                                          # needs sage.rings.finite_rings
True

>>> from sage.all import *
>>> L.gens(F)                                                             # needs sage.rings.finite_rings
(c, b)
>>> P(c, b) == u                                                          # needs sage.rings.finite_rings
True


Similarly, when the base is GF(5), we get a trivariate polynomial:

sage: P = u.polynomial(GF(5)); P # needs sage.rings.finite_rings -x0^2*x1*x2 - x0^2*x2 - x0*x1*x2 - x0^2 + x0*x1 - 2*x0*x2 - x1*x2 + 2*x0 - x1 + 2 sage: P(c, b, a) == u # needs sage.rings.finite_rings True

Different variable names can be specified:

sage: u.polynomial(GF(5), var='y')                                          # needs sage.rings.finite_rings
-y0^2*y1*y2 - y0^2*y2 - y0*y1*y2 - y0^2 + y0*y1 - 2*y0*y2 - y1*y2 + 2*y0 - y1 + 2
sage: u.polynomial(GF(5), var=['x','y','z'])                                # needs sage.rings.finite_rings
-x^2*y*z - x^2*z - x*y*z - x^2 + x*y - 2*x*z - y*z + 2*x - y + 2

>>> from sage.all import *
>>> u.polynomial(GF(Integer(5)), var='y')                                          # needs sage.rings.finite_rings
-y0^2*y1*y2 - y0^2*y2 - y0*y1*y2 - y0^2 + y0*y1 - 2*y0*y2 - y1*y2 + 2*y0 - y1 + 2
>>> u.polynomial(GF(Integer(5)), var=['x','y','z'])                                # needs sage.rings.finite_rings
-x^2*y*z - x^2*z - x*y*z - x^2 + x*y - 2*x*z - y*z + 2*x - y + 2


If base is omitted, it is set to its default which is the base of the extension:

sage: u.polynomial()                                                        # needs sage.rings.finite_rings
((-1 - a) - a*b)*x^2 + ((2 + 3*a) + (1 - a)*b)*x + 2 + (-1 - a)*b

>>> from sage.all import *
>>> u.polynomial()                                                        # needs sage.rings.finite_rings
((-1 - a) - a*b)*x^2 + ((2 + 3*a) + (1 - a)*b)*x + 2 + (-1 - a)*b


Note that base must be an explicit base over which the extension has been defined (as listed by the method bases()):

sage: u.polynomial(GF(5^3))                                                 # needs sage.rings.finite_rings
Traceback (most recent call last):
...
ValueError: not (explicitly) defined over Finite Field in z3 of size 5^3

>>> from sage.all import *
>>> u.polynomial(GF(Integer(5)**Integer(3)))                                                 # needs sage.rings.finite_rings
Traceback (most recent call last):
...
ValueError: not (explicitly) defined over Finite Field in z3 of size 5^3

trace(base=None)[source]#

Return the trace of this element over base.

INPUT:

• base – a commutative ring (which might be itself an extension) or None

EXAMPLES:

sage: # needs sage.rings.finite_rings
sage: F = GF(5)
sage: K.<a> = GF(5^3).over(F)
sage: L.<b> = GF(5^6).over(K)
sage: u = a/(1+b)
sage: tr = u.trace(K); tr
-1 + 3*a + 2*a^2

>>> from sage.all import *
>>> # needs sage.rings.finite_rings
>>> F = GF(Integer(5))
>>> K = GF(Integer(5)**Integer(3)).over(F, names=('a',)); (a,) = K._first_ngens(1)
>>> L = GF(Integer(5)**Integer(6)).over(K, names=('b',)); (b,) = L._first_ngens(1)
>>> u = a/(Integer(1)+b)
>>> tr = u.trace(K); tr
-1 + 3*a + 2*a^2


We check that the trace lives in the base ring:

sage: tr.parent()                                                           # needs sage.rings.finite_rings
Field in a with defining polynomial x^3 + 3*x + 3 over its base
sage: tr.parent() is K                                                      # needs sage.rings.finite_rings
True

>>> from sage.all import *
>>> tr.parent()                                                           # needs sage.rings.finite_rings
Field in a with defining polynomial x^3 + 3*x + 3 over its base
>>> tr.parent() is K                                                      # needs sage.rings.finite_rings
True


Similarly, one can compute the trace over F:

sage: u.trace(F)                                                            # needs sage.rings.finite_rings
0

>>> from sage.all import *
>>> u.trace(F)                                                            # needs sage.rings.finite_rings
0


We check the transitivity of the trace:

sage: u.trace(F) == tr.trace(F)                                             # needs sage.rings.finite_rings
True

>>> from sage.all import *
>>> u.trace(F) == tr.trace(F)                                             # needs sage.rings.finite_rings
True


If base is omitted, it is set to its default which is the base of the extension:

sage: u.trace()                                                             # needs sage.rings.finite_rings
-1 + 3*a + 2*a^2

>>> from sage.all import *
>>> u.trace()                                                             # needs sage.rings.finite_rings
-1 + 3*a + 2*a^2


Note that base must be an explicit base over which the extension has been defined (as listed by the method bases()):

sage: u.trace(GF(5^2))                                                      # needs sage.rings.finite_rings
Traceback (most recent call last):
...
ValueError: not (explicitly) defined over Finite Field in z2 of size 5^2

>>> from sage.all import *
>>> u.trace(GF(Integer(5)**Integer(2)))                                                      # needs sage.rings.finite_rings
Traceback (most recent call last):
...
ValueError: not (explicitly) defined over Finite Field in z2 of size 5^2

vector(base=None)[source]#

Return the vector of coordinates of this element over base (in the basis output by the method basis_over()).

INPUT:

• base – a commutative ring (which might be itself an extension) or None

EXAMPLES:

sage: # needs sage.rings.finite_rings
sage: F = GF(5)
sage: K.<a> = GF(5^2).over()  # over F
sage: L.<b> = GF(5^6).over(K)
sage: x = (a+b)^4; x
(-1 + a) + (3 + a)*b + (1 - a)*b^2
sage: x.vector(K)                   # basis is (1, b, b^2)
(-1 + a, 3 + a, 1 - a)
sage: x.vector(F)                   # basis is (1, a, b, a*b, b^2, a*b^2)
(4, 1, 3, 1, 1, 4)

>>> from sage.all import *
>>> # needs sage.rings.finite_rings
>>> F = GF(Integer(5))
>>> K = GF(Integer(5)**Integer(2)).over(names=('a',)); (a,) = K._first_ngens(1)# over F
>>> L = GF(Integer(5)**Integer(6)).over(K, names=('b',)); (b,) = L._first_ngens(1)
>>> x = (a+b)**Integer(4); x
(-1 + a) + (3 + a)*b + (1 - a)*b^2
>>> x.vector(K)                   # basis is (1, b, b^2)
(-1 + a, 3 + a, 1 - a)
>>> x.vector(F)                   # basis is (1, a, b, a*b, b^2, a*b^2)
(4, 1, 3, 1, 1, 4)


If base is omitted, it is set to its default which is the base of the extension:

sage: x.vector()                                                            # needs sage.rings.finite_rings
(-1 + a, 3 + a, 1 - a)

>>> from sage.all import *
>>> x.vector()                                                            # needs sage.rings.finite_rings
(-1 + a, 3 + a, 1 - a)


Note that base must be an explicit base over which the extension has been defined (as listed by the method bases()):

sage: x.vector(GF(5^3))                                                     # needs sage.rings.finite_rings
Traceback (most recent call last):
...
ValueError: not (explicitly) defined over Finite Field in z3 of size 5^3

>>> from sage.all import *
>>> x.vector(GF(Integer(5)**Integer(3)))                                                     # needs sage.rings.finite_rings
Traceback (most recent call last):
...
ValueError: not (explicitly) defined over Finite Field in z3 of size 5^3