# Elements lying in extension of rings¶

AUTHOR:

• Xavier Caruso (2019)

class sage.rings.ring_extension_element.RingExtensionElement

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))
5

is_nilpotent()

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

is_prime()

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()
True
sage: E(x^2-1).is_prime()
False

is_square(root=False)

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: 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)

is_unit()

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

multiplicative_order()

Return the multiplicite order of this element.

EXAMPLES:

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

sqrt(extend=True, all=False, name=None)

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: 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]

class sage.rings.ring_extension_element.RingExtensionFractionFieldElement

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

denominator()

Return the denominator of this element.

EXAMPLES:

sage: R.<x> = ZZ[]
sage: A.<a> = ZZ.extension(x^2 - 2)
sage: OK = A.over()  # over ZZ
sage: K = OK.fraction_field()
sage: K
Fraction Field of Order 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


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

sage: denom.parent()
Order in Number Field in a with defining polynomial x^2 - 2 over its base
sage: denom.parent() is OK
True

numerator()

Return the numerator of this element.

EXAMPLES:

sage: A.<a> = ZZ.extension(x^2 - 2)
sage: OK = A.over()  # over ZZ
sage: K = OK.fraction_field()
sage: K
Fraction Field of Order 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


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

sage: num.parent()
Order in Number Field in a with defining polynomial x^2 - 2 over its base
sage: num.parent() is OK
True

class sage.rings.ring_extension_element.RingExtensionWithBasisElement

A class for elements lying in finite free extensions.

charpoly(base=None, var='x')

Return the characteristic polynomial of this element over base.

INPUT:

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

EXAMPLES:

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


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

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


and that it annihilates u:

sage: chi(u)
0


Similarly, one can compute the characteristic polynomial over F:

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


A different variable name can be specified:

sage: u.charpoly(F, var='t')
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()
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))
Traceback (most recent call last):
...
ValueError: not (explicitly) defined over Finite Field in z2 of size 5^2

matrix(base=None)

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: 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]


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

sage: u.matrix()
[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))
Traceback (most recent call last):
...
ValueError: not (explicitly) defined over Finite Field in z2 of size 5^2

minpoly(base=None, var='x')

Return the minimal polynomial of this element over base.

INPUT:

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

EXAMPLES:

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


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

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


and that it annihilates u:

sage: chi(u)
0


Similarly, one can compute the minimal polynomial over F:

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


A different variable name can be specified:

sage: u.minpoly(F, var='t')
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()
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))
Traceback (most recent call last):
...
ValueError: not (explicitly) defined over Finite Field in z2 of size 5^2

norm(base=None)

Return the norm of this element over base.

INPUT:

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

EXAMPLES:

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


We check that the norm lives in the base ring:

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


Similarly, one can compute the norm over F:

sage: u.norm(F)
4


We check the transitivity of the norm:

sage: u.norm(F) == nr.norm(F)
True


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

sage: u.norm()
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))
Traceback (most recent call last):
...
ValueError: not (explicitly) defined over Finite Field in z2 of size 5^2

polynomial(base=None, var='x')

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: 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


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

sage: P = u.polynomial(F); P
(-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)
(c, b)
sage: P(c, b) == u
True


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

sage: P = u.polynomial(GF(5)); P -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 True

Different variable names can be specified:

sage: u.polynomial(GF(5), var='y')
-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'])
-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()
((-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))
Traceback (most recent call last):
...
ValueError: not (explicitly) defined over Finite Field in z3 of size 5^3

trace(base=None)

Return the trace of this element over base.

INPUT:

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

EXAMPLES:

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


We check that the trace lives in the base ring:

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


Similarly, one can compute the trace over F:

sage: u.trace(F)
0


We check the transitivity of the trace:

sage: u.trace(F) == tr.trace(F)
True


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

sage: u.trace()
-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))
Traceback (most recent call last):
...
ValueError: not (explicitly) defined over Finite Field in z2 of size 5^2

vector(base=None)

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: 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)


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

sage: x.vector()
(-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))
Traceback (most recent call last):
...
ValueError: not (explicitly) defined over Finite Field in z3 of size 5^3