# Elements of number fields (implemented using NTL)#

AUTHORS:

• William Stein: initial version

• Joel B. Mohler (2007-03-09): reimplemented in Cython

• William Stein (2007-09-04): added doctests

• Robert Bradshaw (2007-09-15): specialized classes for relative and absolute elements

• John Cremona (2009-05-15): added support for local and global logarithmic heights

• Robert Harron (2012-08): conjugate() now works for all fields contained in CM fields

class sage.rings.number_field.number_field_element.CoordinateFunction(alpha, W, to_V)[source]#

Bases: object

This class provides a callable object which expresses elements in terms of powers of a fixed field generator $$\alpha$$.

EXAMPLES:

sage: x = polygen(ZZ, 'x')
sage: K.<a> = NumberField(x^2 + x + 3)
sage: f = (a + 1).coordinates_in_terms_of_powers(); f
Coordinate function that writes elements in terms of the powers of a + 1
sage: f.__class__
<class 'sage.rings.number_field.number_field_element.CoordinateFunction'>
sage: f(a)
[-1, 1]
True

>>> from sage.all import *
>>> x = polygen(ZZ, 'x')
>>> K = NumberField(x**Integer(2) + x + Integer(3), names=('a',)); (a,) = K._first_ngens(1)
>>> f = (a + Integer(1)).coordinates_in_terms_of_powers(); f
Coordinate function that writes elements in terms of the powers of a + 1
>>> f.__class__
<class 'sage.rings.number_field.number_field_element.CoordinateFunction'>
>>> f(a)
[-1, 1]
True

alpha()[source]#

EXAMPLES:

sage: x = polygen(ZZ, 'x')
sage: K.<a> = NumberField(x^3 + 2)
sage: (a + 2).coordinates_in_terms_of_powers().alpha()
a + 2

>>> from sage.all import *
>>> x = polygen(ZZ, 'x')
>>> K = NumberField(x**Integer(3) + Integer(2), names=('a',)); (a,) = K._first_ngens(1)
>>> (a + Integer(2)).coordinates_in_terms_of_powers().alpha()
a + 2

class sage.rings.number_field.number_field_element.NumberFieldElement[source]#

Bases: NumberFieldElement_base

An element of a number field.

EXAMPLES:

sage: x = polygen(ZZ, 'x')
sage: k.<a> = NumberField(x^3 + x + 1)
sage: a^3
-a - 1

>>> from sage.all import *
>>> x = polygen(ZZ, 'x')
>>> k = NumberField(x**Integer(3) + x + Integer(1), names=('a',)); (a,) = k._first_ngens(1)
>>> a**Integer(3)
-a - 1

abs(prec=None, i=None)[source]#

Return the absolute value of this element.

If i is provided, then the absolute value of the $$i$$-th embedding is given.

Otherwise, if the number field has a coercion embedding into $$\RR$$, the corresponding absolute value is returned as an element of the same field (unless prec is given). Otherwise, if it has a coercion embedding into $$\CC$$, then the corresponding absolute value is returned. Finally, if there is no coercion embedding, $$i$$ defaults to 0.

For the computation, the complex field with prec bits of precision is used, defaulting to 53 bits of precision if prec is not provided. The result is in the corresponding real field.

INPUT:

• prec – (default: None) integer bits of precision

• i – (default: None) integer, which embedding to use

EXAMPLES:

sage: z = CyclotomicField(7).gen()
sage: abs(z)
1.00000000000000
sage: abs(z^2 + 17*z - 3)
16.0604426799931
sage: x = polygen(ZZ, 'x')
sage: K.<a> = NumberField(x^3 + 17)
sage: abs(a)
2.57128159065824
sage: a.abs(prec=100)
2.5712815906582353554531872087
sage: a.abs(prec=100, i=1)
2.5712815906582353554531872087
sage: a.abs(100, 2)
2.5712815906582353554531872087

>>> from sage.all import *
>>> z = CyclotomicField(Integer(7)).gen()
>>> abs(z)
1.00000000000000
>>> abs(z**Integer(2) + Integer(17)*z - Integer(3))
16.0604426799931
>>> x = polygen(ZZ, 'x')
>>> K = NumberField(x**Integer(3) + Integer(17), names=('a',)); (a,) = K._first_ngens(1)
>>> abs(a)
2.57128159065824
>>> a.abs(prec=Integer(100))
2.5712815906582353554531872087
>>> a.abs(prec=Integer(100), i=Integer(1))
2.5712815906582353554531872087
>>> a.abs(Integer(100), Integer(2))
2.5712815906582353554531872087


Here’s one where the absolute value depends on the embedding:

sage: K.<b> = NumberField(x^2 - 2)
sage: a = 1 + b
sage: a.abs(i=0)
0.414213562373095
sage: a.abs(i=1)
2.41421356237309

>>> from sage.all import *
>>> K = NumberField(x**Integer(2) - Integer(2), names=('b',)); (b,) = K._first_ngens(1)
>>> a = Integer(1) + b
>>> a.abs(i=Integer(0))
0.414213562373095
>>> a.abs(i=Integer(1))
2.41421356237309


Check that Issue #16147 is fixed:

sage: x = polygen(ZZ)
sage: f = x^3 - x - 1
sage: beta = f.complex_roots()[0]; beta
1.32471795724475
sage: K.<b> = NumberField(f, embedding=beta)
sage: b.abs()
1.32471795724475

>>> from sage.all import *
>>> x = polygen(ZZ)
>>> f = x**Integer(3) - x - Integer(1)
>>> beta = f.complex_roots()[Integer(0)]; beta
1.32471795724475
>>> K = NumberField(f, embedding=beta, names=('b',)); (b,) = K._first_ngens(1)
>>> b.abs()
1.32471795724475


Check that for fields with real coercion embeddings, absolute values are in the same field (Issue #21105):

sage: x = polygen(ZZ)
sage: f = x^3 - x - 1
sage: K.<b> = NumberField(f, embedding=1.3)
sage: b.abs()
b

>>> from sage.all import *
>>> x = polygen(ZZ)
>>> f = x**Integer(3) - x - Integer(1)
>>> K = NumberField(f, embedding=RealNumber('1.3'), names=('b',)); (b,) = K._first_ngens(1)
>>> b.abs()
b


However, if a specific embedding is requested, the behavior reverts to that of number fields without a coercion embedding into $$\RR$$:

sage: b.abs(i=2)
1.32471795724475

>>> from sage.all import *
>>> b.abs(i=Integer(2))
1.32471795724475


Also, if a precision is requested explicitly, the behavior reverts to that of number fields without a coercion embedding into $$\RR$$:

sage: b.abs(prec=53)
1.32471795724475

>>> from sage.all import *
>>> b.abs(prec=Integer(53))
1.32471795724475

abs_non_arch(P, prec=None)[source]#

Return the non-archimedean absolute value of this element with respect to the prime $$P$$, to the given precision.

INPUT:

• P – a prime ideal of the parent of self

• prec (int) – desired floating point precision (default: default RealField precision).

OUTPUT:

(real) the non-archimedean absolute value of this element with respect to the prime $$P$$, to the given precision. This is the normalised absolute value, so that the underlying prime number $$p$$ has absolute value $$1/p$$.

EXAMPLES:

sage: x = polygen(ZZ, 'x')
sage: K.<a> = NumberField(x^2 + 5)
sage: [1/K(2).abs_non_arch(P) for P in K.primes_above(2)]
[2.00000000000000]
sage: [1/K(3).abs_non_arch(P) for P in K.primes_above(3)]
[3.00000000000000, 3.00000000000000]
sage: [1/K(5).abs_non_arch(P) for P in K.primes_above(5)]
[5.00000000000000]

>>> from sage.all import *
>>> x = polygen(ZZ, 'x')
>>> K = NumberField(x**Integer(2) + Integer(5), names=('a',)); (a,) = K._first_ngens(1)
>>> [Integer(1)/K(Integer(2)).abs_non_arch(P) for P in K.primes_above(Integer(2))]
[2.00000000000000]
>>> [Integer(1)/K(Integer(3)).abs_non_arch(P) for P in K.primes_above(Integer(3))]
[3.00000000000000, 3.00000000000000]
>>> [Integer(1)/K(Integer(5)).abs_non_arch(P) for P in K.primes_above(Integer(5))]
[5.00000000000000]


A relative example:

sage: L.<b> = K.extension(x^2 - 5)
sage: [b.abs_non_arch(P) for P in L.primes_above(b)]
[0.447213595499958, 0.447213595499958]

>>> from sage.all import *
>>> L = K.extension(x**Integer(2) - Integer(5), names=('b',)); (b,) = L._first_ngens(1)
>>> [b.abs_non_arch(P) for P in L.primes_above(b)]
[0.447213595499958, 0.447213595499958]

absolute_different()[source]#

Return the absolute different of this element.

This means the different with respect to the base field $$\QQ$$.

EXAMPLES:

sage: x = polygen(ZZ, 'x')
sage: K.<a> = NumberFieldTower([x^2 - 17, x^3 - 2])
sage: a.absolute_different()
0

>>> from sage.all import *
>>> x = polygen(ZZ, 'x')
>>> K = NumberFieldTower([x**Integer(2) - Integer(17), x**Integer(3) - Integer(2)], names=('a',)); (a,) = K._first_ngens(1)
>>> a.absolute_different()
0

absolute_norm()[source]#

Return the absolute norm of this number field element.

EXAMPLES:

sage: K1.<a1> = CyclotomicField(11)
sage: x = polygen(ZZ, 'x')
sage: K2.<a2> = K1.extension(x^2 - 3)
sage: K3.<a3> = K2.extension(x^2 + 1)
sage: (a1 + a2 + a3).absolute_norm()
1353244757701

sage: QQ(7/5).absolute_norm()
7/5

>>> from sage.all import *
>>> K1 = CyclotomicField(Integer(11), names=('a1',)); (a1,) = K1._first_ngens(1)
>>> x = polygen(ZZ, 'x')
>>> K2 = K1.extension(x**Integer(2) - Integer(3), names=('a2',)); (a2,) = K2._first_ngens(1)
>>> K3 = K2.extension(x**Integer(2) + Integer(1), names=('a3',)); (a3,) = K3._first_ngens(1)
>>> (a1 + a2 + a3).absolute_norm()
1353244757701

>>> QQ(Integer(7)/Integer(5)).absolute_norm()
7/5


Return the additive order of this element (i.e., infinity if self != 0 and 1 if self == 0)

EXAMPLES:

sage: x = polygen(ZZ, 'x')
sage: K.<u> = NumberField(x^4 - 3*x^2 + 3)
+Infinity
1
sage: K.ring_of_integers().characteristic()  # implicit doctest
0

>>> from sage.all import *
>>> x = polygen(ZZ, 'x')
>>> K = NumberField(x**Integer(4) - Integer(3)*x**Integer(2) + Integer(3), names=('u',)); (u,) = K._first_ngens(1)
+Infinity
1
>>> K.ring_of_integers().characteristic()  # implicit doctest
0

ceil()[source]#

Return the ceiling of this number field element.

EXAMPLES:

sage: x = polygen(ZZ)
sage: p = x**7 - 5*x**2 + x + 1
sage: a_AA = AA.polynomial_root(p, RIF(1,2))
sage: K.<a> = NumberField(p, embedding=a_AA)
sage: b = a**5 + a/2 - 1/7
sage: RR(b)
4.13444473767055
sage: b.ceil()
5

>>> from sage.all import *
>>> x = polygen(ZZ)
>>> p = x**Integer(7) - Integer(5)*x**Integer(2) + x + Integer(1)
>>> a_AA = AA.polynomial_root(p, RIF(Integer(1),Integer(2)))
>>> K = NumberField(p, embedding=a_AA, names=('a',)); (a,) = K._first_ngens(1)
>>> b = a**Integer(5) + a/Integer(2) - Integer(1)/Integer(7)
>>> RR(b)
4.13444473767055
>>> b.ceil()
5


This function always succeeds even if a tremendous precision is needed:

sage: c = b - 5065701199253/1225243417356 + 2
sage: c.ceil()
3
sage: RIF(c).unique_ceil()
Traceback (most recent call last):
...
ValueError: interval does not have a unique ceil

>>> from sage.all import *
>>> c = b - Integer(5065701199253)/Integer(1225243417356) + Integer(2)
>>> c.ceil()
3
>>> RIF(c).unique_ceil()
Traceback (most recent call last):
...
ValueError: interval does not have a unique ceil


If the number field is not embedded, this function is valid only if the element is rational:

sage: p = x**5 - 3
sage: K.<a> = NumberField(p)
sage: K(2/3).ceil()
1
sage: a.ceil()
Traceback (most recent call last):
...
TypeError: ceil not uniquely defined since no real embedding is specified

>>> from sage.all import *
>>> p = x**Integer(5) - Integer(3)
>>> K = NumberField(p, names=('a',)); (a,) = K._first_ngens(1)
>>> K(Integer(2)/Integer(3)).ceil()
1
>>> a.ceil()
Traceback (most recent call last):
...
TypeError: ceil not uniquely defined since no real embedding is specified

charpoly(var='x')[source]#

Return the characteristic polynomial of this number field element.

EXAMPLES:

sage: x = polygen(ZZ, 'x')
sage: K.<a> = NumberField(x^3 + 7)
sage: a.charpoly()
x^3 + 7
sage: K(1).charpoly()
x^3 - 3*x^2 + 3*x - 1

>>> from sage.all import *
>>> x = polygen(ZZ, 'x')
>>> K = NumberField(x**Integer(3) + Integer(7), names=('a',)); (a,) = K._first_ngens(1)
>>> a.charpoly()
x^3 + 7
>>> K(Integer(1)).charpoly()
x^3 - 3*x^2 + 3*x - 1

complex_embedding(prec=53, i=0)[source]#

Return the $$i$$-th embedding of self in the complex numbers, to the given precision.

EXAMPLES:

sage: x = polygen(ZZ, 'x')
sage: k.<a> = NumberField(x^3 - 2)
sage: a.complex_embedding()
-0.629960524947437 - 1.09112363597172*I
sage: a.complex_embedding(10)
-0.63 - 1.1*I
sage: a.complex_embedding(100)
-0.62996052494743658238360530364 - 1.0911236359717214035600726142*I
sage: a.complex_embedding(20, 1)
-0.62996 + 1.0911*I
sage: a.complex_embedding(20, 2)
1.2599

>>> from sage.all import *
>>> x = polygen(ZZ, 'x')
>>> k = NumberField(x**Integer(3) - Integer(2), names=('a',)); (a,) = k._first_ngens(1)
>>> a.complex_embedding()
-0.629960524947437 - 1.09112363597172*I
>>> a.complex_embedding(Integer(10))
-0.63 - 1.1*I
>>> a.complex_embedding(Integer(100))
-0.62996052494743658238360530364 - 1.0911236359717214035600726142*I
>>> a.complex_embedding(Integer(20), Integer(1))
-0.62996 + 1.0911*I
>>> a.complex_embedding(Integer(20), Integer(2))
1.2599

complex_embeddings(prec=53)[source]#

Return the images of this element in the floating point complex numbers, to the given bits of precision.

INPUT:

• prec – integer (default: 53) bits of precision

EXAMPLES:

sage: x = polygen(ZZ, 'x')
sage: k.<a> = NumberField(x^3 - 2)
sage: a.complex_embeddings()
[-0.629960524947437 - 1.09112363597172*I,
-0.629960524947437 + 1.09112363597172*I,
1.25992104989487]
sage: a.complex_embeddings(10)
[-0.63 - 1.1*I, -0.63 + 1.1*I, 1.3]
sage: a.complex_embeddings(100)
[-0.62996052494743658238360530364 - 1.0911236359717214035600726142*I,
-0.62996052494743658238360530364 + 1.0911236359717214035600726142*I,
1.2599210498948731647672106073]

>>> from sage.all import *
>>> x = polygen(ZZ, 'x')
>>> k = NumberField(x**Integer(3) - Integer(2), names=('a',)); (a,) = k._first_ngens(1)
>>> a.complex_embeddings()
[-0.629960524947437 - 1.09112363597172*I,
-0.629960524947437 + 1.09112363597172*I,
1.25992104989487]
>>> a.complex_embeddings(Integer(10))
[-0.63 - 1.1*I, -0.63 + 1.1*I, 1.3]
>>> a.complex_embeddings(Integer(100))
[-0.62996052494743658238360530364 - 1.0911236359717214035600726142*I,
-0.62996052494743658238360530364 + 1.0911236359717214035600726142*I,
1.2599210498948731647672106073]

conjugate()[source]#

Return the complex conjugate of the number field element.

This is only well-defined for fields contained in CM fields (i.e. for totally real fields and CM fields). Recall that a CM field is a totally imaginary quadratic extension of a totally real field. For other fields, a ValueError is raised.

EXAMPLES:

sage: k.<I> = QuadraticField(-1)
sage: I.conjugate()
-I
sage: (I/(1+I)).conjugate()
-1/2*I + 1/2
sage: z6 = CyclotomicField(6).gen(0)
sage: (2*z6).conjugate()
-2*zeta6 + 2

>>> from sage.all import *
>>> k = QuadraticField(-Integer(1), names=('I',)); (I,) = k._first_ngens(1)
>>> I.conjugate()
-I
>>> (I/(Integer(1)+I)).conjugate()
-1/2*I + 1/2
>>> z6 = CyclotomicField(Integer(6)).gen(Integer(0))
>>> (Integer(2)*z6).conjugate()
-2*zeta6 + 2


The following example now works.

sage: x = polygen(ZZ, 'x')
sage: F.<b> = NumberField(x^2 - 2)
sage: K.<j> = F.extension(x^2 + 1)
sage: j.conjugate()
-j

>>> from sage.all import *
>>> x = polygen(ZZ, 'x')
>>> F = NumberField(x**Integer(2) - Integer(2), names=('b',)); (b,) = F._first_ngens(1)
>>> K = F.extension(x**Integer(2) + Integer(1), names=('j',)); (j,) = K._first_ngens(1)
>>> j.conjugate()
-j


Raise a ValueError if the field is not contained in a CM field.

sage: K.<b> = NumberField(x^3 - 2)
sage: b.conjugate()
Traceback (most recent call last):
...
ValueError: Complex conjugation is only well-defined
for fields contained in CM fields.

>>> from sage.all import *
>>> K = NumberField(x**Integer(3) - Integer(2), names=('b',)); (b,) = K._first_ngens(1)
>>> b.conjugate()
Traceback (most recent call last):
...
ValueError: Complex conjugation is only well-defined
for fields contained in CM fields.


An example of a non-quadratic totally real field.

sage: F.<a> = NumberField(x^4 + x^3 - 3*x^2 - x + 1)
sage: a.conjugate()
a

>>> from sage.all import *
>>> F = NumberField(x**Integer(4) + x**Integer(3) - Integer(3)*x**Integer(2) - x + Integer(1), names=('a',)); (a,) = F._first_ngens(1)
>>> a.conjugate()
a


An example of a non-cyclotomic CM field.

sage: K.<a> = NumberField(x^4 - x^3 + 2*x^2 + x + 1)
sage: a.conjugate()
-1/2*a^3 - a - 1/2
sage: (2*a^2 - 1).conjugate()
a^3 - 2*a^2 - 2

>>> from sage.all import *
>>> K = NumberField(x**Integer(4) - x**Integer(3) + Integer(2)*x**Integer(2) + x + Integer(1), names=('a',)); (a,) = K._first_ngens(1)
>>> a.conjugate()
-1/2*a^3 - a - 1/2
>>> (Integer(2)*a**Integer(2) - Integer(1)).conjugate()
a^3 - 2*a^2 - 2

coordinates_in_terms_of_powers()[source]#

Let $$\alpha$$ be self. Return a callable object (of type CoordinateFunction) that takes any element of the parent of self in $$\QQ(\alpha)$$ and writes it in terms of the powers of $$\alpha$$: $$1, \alpha, \alpha^2, ...$$.

(NOT CACHED).

EXAMPLES:

This function allows us to write elements of a number field in terms of a different generator without having to construct a whole separate number field.

sage: y = polygen(QQ,'y'); K.<beta> = NumberField(y^3 - 2); K
Number Field in beta with defining polynomial y^3 - 2
sage: alpha = beta^2 + beta + 1
sage: c = alpha.coordinates_in_terms_of_powers(); c
Coordinate function that writes elements in terms of the powers of beta^2 + beta + 1
sage: c(beta)
[-2, -3, 1]
sage: c(alpha)
[0, 1, 0]
sage: c((1+beta)^5)
[3, 3, 3]
sage: c((1+beta)^10)
[54, 162, 189]

>>> from sage.all import *
>>> y = polygen(QQ,'y'); K = NumberField(y**Integer(3) - Integer(2), names=('beta',)); (beta,) = K._first_ngens(1); K
Number Field in beta with defining polynomial y^3 - 2
>>> alpha = beta**Integer(2) + beta + Integer(1)
>>> c = alpha.coordinates_in_terms_of_powers(); c
Coordinate function that writes elements in terms of the powers of beta^2 + beta + 1
>>> c(beta)
[-2, -3, 1]
>>> c(alpha)
[0, 1, 0]
>>> c((Integer(1)+beta)**Integer(5))
[3, 3, 3]
>>> c((Integer(1)+beta)**Integer(10))
[54, 162, 189]


This function works even if self only generates a subfield of this number field.

sage: x = polygen(ZZ, 'x')
sage: k.<a> = NumberField(x^6 - 5)
sage: alpha = a^3
sage: c = alpha.coordinates_in_terms_of_powers()
sage: c((2/3)*a^3 - 5/3)
[-5/3, 2/3]
sage: c
Coordinate function that writes elements in terms of the powers of a^3
sage: c(a)
Traceback (most recent call last):
...
ArithmeticError: vector is not in free module

>>> from sage.all import *
>>> x = polygen(ZZ, 'x')
>>> k = NumberField(x**Integer(6) - Integer(5), names=('a',)); (a,) = k._first_ngens(1)
>>> alpha = a**Integer(3)
>>> c = alpha.coordinates_in_terms_of_powers()
>>> c((Integer(2)/Integer(3))*a**Integer(3) - Integer(5)/Integer(3))
[-5/3, 2/3]
>>> c
Coordinate function that writes elements in terms of the powers of a^3
>>> c(a)
Traceback (most recent call last):
...
ArithmeticError: vector is not in free module

denominator()[source]#

Return the denominator of this element, which is by definition the denominator of the corresponding polynomial representation. I.e., elements of number fields are represented as a polynomial (in reduced form) modulo the modulus of the number field, and the denominator is the denominator of this polynomial.

EXAMPLES:

sage: K.<z> = CyclotomicField(3)
sage: a = 1/3 + (1/5)*z
sage: a.denominator()
15

>>> from sage.all import *
>>> K = CyclotomicField(Integer(3), names=('z',)); (z,) = K._first_ngens(1)
>>> a = Integer(1)/Integer(3) + (Integer(1)/Integer(5))*z
>>> a.denominator()
15

denominator_ideal()[source]#

Return the denominator ideal of this number field element.

The denominator ideal of a number field element $$a$$ is the integral ideal consisting of all elements of the ring of integers $$R$$ whose product with $$a$$ is also in $$R$$.

EXAMPLES:

sage: x = polygen(ZZ, 'x')
sage: K.<a> = NumberField(x^2 + 5)
sage: b = (1+a)/2
sage: b.norm()
3/2
sage: D = b.denominator_ideal(); D
Fractional ideal (2, a + 1)
sage: D.norm()
2
sage: (1/b).denominator_ideal()
Fractional ideal (3, a + 1)
sage: K(0).denominator_ideal()
Fractional ideal (1)

>>> from sage.all import *
>>> x = polygen(ZZ, 'x')
>>> K = NumberField(x**Integer(2) + Integer(5), names=('a',)); (a,) = K._first_ngens(1)
>>> b = (Integer(1)+a)/Integer(2)
>>> b.norm()
3/2
>>> D = b.denominator_ideal(); D
Fractional ideal (2, a + 1)
>>> D.norm()
2
>>> (Integer(1)/b).denominator_ideal()
Fractional ideal (3, a + 1)
>>> K(Integer(0)).denominator_ideal()
Fractional ideal (1)

descend_mod_power(K='QQ', d=2)[source]#

Return a list of elements of the subfield $$K$$ equal to self modulo $$d$$’th powers.

INPUT:

• K (number field, default $$\QQ$$) – a subfield of the parent number field $$L$$ of self

• d (positive integer, default 2) – an integer at least 2

OUTPUT:

A list, possibly empty, of elements of $$K$$ equal to self modulo $$d$$’th powers, i.e. the preimages of self under the map $$K^*/(K^*)^d \rightarrow L^*/(L^*)^d$$ where $$L$$ is the parent of self. A ValueError is raised if $$K$$ does not embed into $$L$$.

ALGORITHM:

All preimages must lie in the Selmer group $$K(S,d)$$ for a suitable finite set of primes $$S$$, which reduces the question to a finite set of possibilities. We may take $$S$$ to be the set of primes which ramify in $$L$$ together with those for which the valuation of self is not divisible by $$d$$.

EXAMPLES:

A relative example:

sage: Qi.<i> = QuadraticField(-1)
sage: K.<zeta> = CyclotomicField(8)
sage: f = Qi.embeddings(K)[0]
sage: a = f(2+3*i) * (2-zeta)^2
sage: a.descend_mod_power(Qi,2)
[-2*i + 3, 3*i + 2]

>>> from sage.all import *
>>> Qi = QuadraticField(-Integer(1), names=('i',)); (i,) = Qi._first_ngens(1)
>>> K = CyclotomicField(Integer(8), names=('zeta',)); (zeta,) = K._first_ngens(1)
>>> f = Qi.embeddings(K)[Integer(0)]
>>> a = f(Integer(2)+Integer(3)*i) * (Integer(2)-zeta)**Integer(2)
>>> a.descend_mod_power(Qi,Integer(2))
[-2*i + 3, 3*i + 2]


An absolute example:

sage: K.<zeta> = CyclotomicField(8)
sage: K(1).descend_mod_power(QQ,2)
[1, 2, -1, -2]
sage: a = 17 * K._random_nonzero_element()^2
sage: a.descend_mod_power(QQ,2)
[17, 34, -17, -34]

>>> from sage.all import *
>>> K = CyclotomicField(Integer(8), names=('zeta',)); (zeta,) = K._first_ngens(1)
>>> K(Integer(1)).descend_mod_power(QQ,Integer(2))
[1, 2, -1, -2]
>>> a = Integer(17) * K._random_nonzero_element()**Integer(2)
>>> a.descend_mod_power(QQ,Integer(2))
[17, 34, -17, -34]

different(K=None)[source]#

Return the different of this element with respect to the given base field.

The different of an element $$a$$ in an extension of number fields $$L/K$$ is defined as $$\mathrm{Diff}_{L/K}(a) = f'(a)$$ where $$f$$ is the characteristic polynomial of $$a$$ over $$K$$.

INPUT:

• K – a subfield (embedding of a subfield) of the parent number field of self. Default: None, which will amount to self.parent().base_field().

EXAMPLES:

sage: x = polygen(ZZ, 'x')
sage: K.<a> = NumberField(x^3 - 2)
sage: a.different()
3*a^2
sage: a.different(K=K)
1

>>> from sage.all import *
>>> x = polygen(ZZ, 'x')
>>> K = NumberField(x**Integer(3) - Integer(2), names=('a',)); (a,) = K._first_ngens(1)
>>> a.different()
3*a^2
>>> a.different(K=K)
1


The optional argument K can be an embedding of a subfield:

sage: K.<b> = NumberField(x^4 - 2)
sage: (b^2).different()
0
sage: phi = K.base_field().embeddings(K)[0]
sage: b.different(K=phi)
4*b^3

>>> from sage.all import *
>>> K = NumberField(x**Integer(4) - Integer(2), names=('b',)); (b,) = K._first_ngens(1)
>>> (b**Integer(2)).different()
0
>>> phi = K.base_field().embeddings(K)[Integer(0)]
>>> b.different(K=phi)
4*b^3


Compare the relative different and the absolute different for an element in a relative number field:

sage: K.<a> = NumberFieldTower([x^2 - 17, x^3 - 2])
sage: a.different()
2*a0
sage: a.different(K=QQ)
0
sage: a.absolute_different()
0

>>> from sage.all import *
>>> K = NumberFieldTower([x**Integer(2) - Integer(17), x**Integer(3) - Integer(2)], names=('a',)); (a,) = K._first_ngens(1)
>>> a.different()
2*a0
>>> a.different(K=QQ)
0
>>> a.absolute_different()
0


Observe that for the field extension $$\QQ(i)/\QQ$$, the different of the field extension is the ideal generated by the different of $$i$$:

sage: K.<c> = NumberField(x^2 + 1)
sage: K.different() == K.ideal(c.different())
True

>>> from sage.all import *
>>> K = NumberField(x**Integer(2) + Integer(1), names=('c',)); (c,) = K._first_ngens(1)
>>> K.different() == K.ideal(c.different())
True

factor()[source]#

Return factorization of this element into prime elements and a unit.

OUTPUT:

(Factorization) If all the prime ideals in the support are principal, the output is a Factorization as a product of prime elements raised to appropriate powers, with an appropriate unit factor.

Raise ValueError if the factorization of the ideal (self) contains a non-principal prime ideal.

EXAMPLES:

sage: x = polygen(ZZ, 'x')
sage: K.<i> = NumberField(x^2 + 1)
sage: (6*i + 6).factor()
(-i) * (i + 1)^3 * 3

>>> from sage.all import *
>>> x = polygen(ZZ, 'x')
>>> K = NumberField(x**Integer(2) + Integer(1), names=('i',)); (i,) = K._first_ngens(1)
>>> (Integer(6)*i + Integer(6)).factor()
(-i) * (i + 1)^3 * 3


In the following example, the class number is 2. If a factorization in prime elements exists, we will find it:

sage: K.<a> = NumberField(x^2 - 10)
sage: factor(169*a + 531)
(-6*a - 19) * (-3*a - 1) * (-2*a + 9)
sage: factor(K(3))
Traceback (most recent call last):
...
ArithmeticError: non-principal ideal in factorization

>>> from sage.all import *
>>> K = NumberField(x**Integer(2) - Integer(10), names=('a',)); (a,) = K._first_ngens(1)
>>> factor(Integer(169)*a + Integer(531))
(-6*a - 19) * (-3*a - 1) * (-2*a + 9)
>>> factor(K(Integer(3)))
Traceback (most recent call last):
...
ArithmeticError: non-principal ideal in factorization


Factorization of 0 is not allowed:

sage: K.<i> = QuadraticField(-1)
sage: K(0).factor()
Traceback (most recent call last):
...
ArithmeticError: factorization of 0 is not defined

>>> from sage.all import *
>>> K = QuadraticField(-Integer(1), names=('i',)); (i,) = K._first_ngens(1)
>>> K(Integer(0)).factor()
Traceback (most recent call last):
...
ArithmeticError: factorization of 0 is not defined

floor()[source]#

Return the floor of this number field element.

EXAMPLES:

sage: x = polygen(ZZ)
sage: p = x**7 - 5*x**2 + x + 1
sage: a_AA = AA.polynomial_root(p, RIF(1,2))
sage: K.<a> = NumberField(p, embedding=a_AA)
sage: b = a**5 + a/2 - 1/7
sage: RR(b)
4.13444473767055
sage: b.floor()
4

sage: K(125/7).floor()
17

>>> from sage.all import *
>>> x = polygen(ZZ)
>>> p = x**Integer(7) - Integer(5)*x**Integer(2) + x + Integer(1)
>>> a_AA = AA.polynomial_root(p, RIF(Integer(1),Integer(2)))
>>> K = NumberField(p, embedding=a_AA, names=('a',)); (a,) = K._first_ngens(1)
>>> b = a**Integer(5) + a/Integer(2) - Integer(1)/Integer(7)
>>> RR(b)
4.13444473767055
>>> b.floor()
4

>>> K(Integer(125)/Integer(7)).floor()
17


This function always succeeds even if a tremendous precision is needed:

sage: c = b - 4772404052447/1154303505127 + 2
sage: c.floor()
1
sage: RIF(c).unique_floor()
Traceback (most recent call last):
...
ValueError: interval does not have a unique floor

>>> from sage.all import *
>>> c = b - Integer(4772404052447)/Integer(1154303505127) + Integer(2)
>>> c.floor()
1
>>> RIF(c).unique_floor()
Traceback (most recent call last):
...
ValueError: interval does not have a unique floor


If the number field is not embedded, this function is valid only if the element is rational:

sage: p = x**5 - 3
sage: K.<a> = NumberField(p)
sage: K(2/3).floor()
0
sage: a.floor()
Traceback (most recent call last):
...
TypeError: floor not uniquely defined since no real embedding is specified

>>> from sage.all import *
>>> p = x**Integer(5) - Integer(3)
>>> K = NumberField(p, names=('a',)); (a,) = K._first_ngens(1)
>>> K(Integer(2)/Integer(3)).floor()
0
>>> a.floor()
Traceback (most recent call last):
...
TypeError: floor not uniquely defined since no real embedding is specified

galois_conjugates(K)[source]#

Return all Gal(Qbar/Q)-conjugates of this number field element in the field $$K$$.

EXAMPLES:

In the first example the conjugates are obvious:

sage: x = polygen(ZZ, 'x')
sage: K.<a> = NumberField(x^2 - 2)
sage: a.galois_conjugates(K)
[a, -a]
sage: K(3).galois_conjugates(K)
[3]

>>> from sage.all import *
>>> x = polygen(ZZ, 'x')
>>> K = NumberField(x**Integer(2) - Integer(2), names=('a',)); (a,) = K._first_ngens(1)
>>> a.galois_conjugates(K)
[a, -a]
>>> K(Integer(3)).galois_conjugates(K)
[3]


In this example the field is not Galois, so we have to pass to an extension to obtain the Galois conjugates.

sage: K.<a> = NumberField(x^3 - 2)
sage: c = a.galois_conjugates(K); c
[a]
sage: K.<a> = NumberField(x^3 - 2)
sage: c = a.galois_conjugates(K.galois_closure('a1')); c                    # needs sage.groups
[1/18*a1^4, -1/36*a1^4 + 1/2*a1, -1/36*a1^4 - 1/2*a1]
sage: c[0]^3
2
sage: parent(c[0])
Number Field in a1 with defining polynomial x^6 + 108
sage: parent(c[0]).is_galois()                                              # needs sage.groups
True

>>> from sage.all import *
>>> K = NumberField(x**Integer(3) - Integer(2), names=('a',)); (a,) = K._first_ngens(1)
>>> c = a.galois_conjugates(K); c
[a]
>>> K = NumberField(x**Integer(3) - Integer(2), names=('a',)); (a,) = K._first_ngens(1)
>>> c = a.galois_conjugates(K.galois_closure('a1')); c                    # needs sage.groups
[1/18*a1^4, -1/36*a1^4 + 1/2*a1, -1/36*a1^4 - 1/2*a1]
>>> c[Integer(0)]**Integer(3)
2
>>> parent(c[Integer(0)])
Number Field in a1 with defining polynomial x^6 + 108
>>> parent(c[Integer(0)]).is_galois()                                              # needs sage.groups
True


There is only one Galois conjugate of $$\sqrt[3]{2}$$ in $$\QQ(\sqrt[3]{2})$$.

sage: a.galois_conjugates(K)
[a]

>>> from sage.all import *
>>> a.galois_conjugates(K)
[a]


Galois conjugates of $$\sqrt[3]{2}$$ in the field $$\QQ(\zeta_3,\sqrt[3]{2})$$:

sage: L.<a> = CyclotomicField(3).extension(x^3 - 2)
sage: a.galois_conjugates(L)
[a, (-zeta3 - 1)*a, zeta3*a]

>>> from sage.all import *
>>> L = CyclotomicField(Integer(3)).extension(x**Integer(3) - Integer(2), names=('a',)); (a,) = L._first_ngens(1)
>>> a.galois_conjugates(L)
[a, (-zeta3 - 1)*a, zeta3*a]

gcd(other)[source]#

Return the greatest common divisor of self and other.

INPUT:

• self, other – elements of a number field or maximal order.

OUTPUT:

• A generator of the ideal (self, other). If the parent is a number field, this always returns 0 or 1. For maximal orders, this raises ArithmeticError if the ideal is not principal.

EXAMPLES:

sage: K.<i> = QuadraticField(-1)
sage: (i+1).gcd(2)
1
sage: K(1).gcd(0)
1
sage: K(0).gcd(0)
0
sage: R = K.maximal_order()
sage: R(i+1).gcd(2)
i + 1
sage: R = K.order(2*i)
sage: R(1).gcd(R(4*i))
1

>>> from sage.all import *
>>> K = QuadraticField(-Integer(1), names=('i',)); (i,) = K._first_ngens(1)
>>> (i+Integer(1)).gcd(Integer(2))
1
>>> K(Integer(1)).gcd(Integer(0))
1
>>> K(Integer(0)).gcd(Integer(0))
0
>>> R = K.maximal_order()
>>> R(i+Integer(1)).gcd(Integer(2))
i + 1
>>> R = K.order(Integer(2)*i)
>>> R(Integer(1)).gcd(R(Integer(4)*i))
1


The following field has class number 3, but if the ideal (self, other) happens to be principal, this still works:

sage: x = polygen(ZZ, 'x')
sage: K.<a> = NumberField(x^3 - 7)
sage: K.class_number()
3
sage: a.gcd(7)
1
sage: R = K.maximal_order()
sage: R(a).gcd(7)
a
sage: R(a+1).gcd(2)
Traceback (most recent call last):
...
ArithmeticError: ideal (a + 1, 2) is not principal, gcd is not defined
sage: R(2*a - a^2).gcd(0)
a
sage: R(a).gcd(R(2*a)).parent()
Maximal Order generated by a in Number Field in a with defining polynomial x^3 - 7

>>> from sage.all import *
>>> x = polygen(ZZ, 'x')
>>> K = NumberField(x**Integer(3) - Integer(7), names=('a',)); (a,) = K._first_ngens(1)
>>> K.class_number()
3
>>> a.gcd(Integer(7))
1
>>> R = K.maximal_order()
>>> R(a).gcd(Integer(7))
a
>>> R(a+Integer(1)).gcd(Integer(2))
Traceback (most recent call last):
...
ArithmeticError: ideal (a + 1, 2) is not principal, gcd is not defined
>>> R(Integer(2)*a - a**Integer(2)).gcd(Integer(0))
a
>>> R(a).gcd(R(Integer(2)*a)).parent()
Maximal Order generated by a in Number Field in a with defining polynomial x^3 - 7

global_height(prec=None)[source]#

Returns the absolute logarithmic height of this number field element.

INPUT:

• prec (int) – desired floating point precision (default: default RealField precision).

OUTPUT:

(real) The absolute logarithmic height of this number field element; that is, the sum of the local heights at all finite and infinite places, scaled by the degree to make the result independent of the parent field.

EXAMPLES:

sage: R.<x> = QQ[]
sage: K.<a> = NumberField(x^4 + 3*x^2 - 17)
sage: b = a/2
sage: b.global_height()
0.789780699008...
sage: b.global_height(prec=200)
0.78978069900813892060267152032141577237037181070060784564457

>>> from sage.all import *
>>> R = QQ['x']; (x,) = R._first_ngens(1)
>>> K = NumberField(x**Integer(4) + Integer(3)*x**Integer(2) - Integer(17), names=('a',)); (a,) = K._first_ngens(1)
>>> b = a/Integer(2)
>>> b.global_height()
0.789780699008...
>>> b.global_height(prec=Integer(200))
0.78978069900813892060267152032141577237037181070060784564457


The global height of an algebraic number is absolute, i.e. it does not depend on the parent field:

sage: QQ(6).global_height()
1.79175946922805
sage: K(6).global_height()
1.79175946922805

sage: L.<b> = NumberField((a^2).minpoly())
sage: L.degree()
2
sage: b.global_height() # element of L (degree 2 field)
1.41660667202811
sage: (a^2).global_height() # element of K (degree 4 field)
1.41660667202811

>>> from sage.all import *
>>> QQ(Integer(6)).global_height()
1.79175946922805
>>> K(Integer(6)).global_height()
1.79175946922805

>>> L = NumberField((a**Integer(2)).minpoly(), names=('b',)); (b,) = L._first_ngens(1)
>>> L.degree()
2
>>> b.global_height() # element of L (degree 2 field)
1.41660667202811
>>> (a**Integer(2)).global_height() # element of K (degree 4 field)
1.41660667202811


And of course every element has the same height as it’s inverse:

sage: K.<s> = QuadraticField(2)
sage: s.global_height()
0.346573590279973
sage: (1/s).global_height()   #make sure that 11758 is fixed
0.346573590279973

>>> from sage.all import *
>>> K = QuadraticField(Integer(2), names=('s',)); (s,) = K._first_ngens(1)
>>> s.global_height()
0.346573590279973
>>> (Integer(1)/s).global_height()   #make sure that 11758 is fixed
0.346573590279973

global_height_arch(prec=None)[source]#

Returns the total archimedean component of the height of self.

INPUT:

• prec (int) – desired floating point precision (default: default RealField precision).

OUTPUT:

(real) The total archimedean component of the height of this number field element; that is, the sum of the local heights at all infinite places.

EXAMPLES:

sage: R.<x> = QQ[]
sage: K.<a> = NumberField(x^4 + 3*x^2 - 17)
sage: b = a/2
sage: b.global_height_arch()
0.38653407379277...

>>> from sage.all import *
>>> R = QQ['x']; (x,) = R._first_ngens(1)
>>> K = NumberField(x**Integer(4) + Integer(3)*x**Integer(2) - Integer(17), names=('a',)); (a,) = K._first_ngens(1)
>>> b = a/Integer(2)
>>> b.global_height_arch()
0.38653407379277...

global_height_non_arch(prec=None)[source]#

Return the total non-archimedean component of the height of self.

INPUT:

• prec (int) – desired floating point precision (default: default RealField precision).

OUTPUT:

(real) The total non-archimedean component of the height of this number field element; that is, the sum of the local heights at all finite places, weighted by the local degrees.

ALGORITHM:

An alternative formula is $$\log(d)$$ where $$d$$ is the norm of the denominator ideal; this is used to avoid factorization.

EXAMPLES:

sage: R.<x> = QQ[]
sage: K.<a> = NumberField(x^4 + 3*x^2 - 17)
sage: b = a/6
sage: b.global_height_non_arch()
7.16703787691222

>>> from sage.all import *
>>> R = QQ['x']; (x,) = R._first_ngens(1)
>>> K = NumberField(x**Integer(4) + Integer(3)*x**Integer(2) - Integer(17), names=('a',)); (a,) = K._first_ngens(1)
>>> b = a/Integer(6)
>>> b.global_height_non_arch()
7.16703787691222


Check that this is equal to the sum of the non-archimedean local heights:

sage: [b.local_height(P) for P in b.support()]
[0.000000000000000, 0.693147180559945, 1.09861228866811, 1.09861228866811]
sage: [b.local_height(P, weighted=True) for P in b.support()]
[0.000000000000000, 2.77258872223978, 2.19722457733622, 2.19722457733622]
sage: sum([b.local_height(P,weighted=True) for P in b.support()])
7.16703787691222

>>> from sage.all import *
>>> [b.local_height(P) for P in b.support()]
[0.000000000000000, 0.693147180559945, 1.09861228866811, 1.09861228866811]
>>> [b.local_height(P, weighted=True) for P in b.support()]
[0.000000000000000, 2.77258872223978, 2.19722457733622, 2.19722457733622]
>>> sum([b.local_height(P,weighted=True) for P in b.support()])
7.16703787691222


A relative example:

sage: PK.<y> = K[]
sage: L.<c> = NumberField(y^2 + a)
sage: (c/10).global_height_non_arch()
18.4206807439524

>>> from sage.all import *
>>> PK = K['y']; (y,) = PK._first_ngens(1)
>>> L = NumberField(y**Integer(2) + a, names=('c',)); (c,) = L._first_ngens(1)
>>> (c/Integer(10)).global_height_non_arch()
18.4206807439524

inverse_mod(I)[source]#

Returns the inverse of self mod the integral ideal $$I$$.

INPUT:

• I – may be an ideal of self.parent(), or an element or list of elements of self.parent() generating a nonzero ideal. A ValueError is raised if $$I$$ is non-integral or zero. A ZeroDivisionError is raised if $$I + (x) \neq (1)$$.

Note

It’s not implemented yet for non-integral elements.

EXAMPLES:

sage: x = polygen(ZZ, 'x')
sage: k.<a> = NumberField(x^2 + 23)
sage: N = k.ideal(3)
sage: d = 3*a + 1
sage: d.inverse_mod(N)
1

>>> from sage.all import *
>>> x = polygen(ZZ, 'x')
>>> k = NumberField(x**Integer(2) + Integer(23), names=('a',)); (a,) = k._first_ngens(1)
>>> N = k.ideal(Integer(3))
>>> d = Integer(3)*a + Integer(1)
>>> d.inverse_mod(N)
1

sage: k.<a> = NumberField(x^3 + 11)
sage: d = a + 13
sage: d.inverse_mod(a^2)*d - 1 in k.ideal(a^2)
True
sage: d.inverse_mod((5, a + 1))*d - 1 in k.ideal(5, a + 1)
True
sage: K.<b> = k.extension(x^2 + 3)
sage: b.inverse_mod([37, a - b])
7
sage: 7*b - 1 in K.ideal(37, a - b)
True
sage: b.inverse_mod([37, a - b]).parent() == K
True

>>> from sage.all import *
>>> k = NumberField(x**Integer(3) + Integer(11), names=('a',)); (a,) = k._first_ngens(1)
>>> d = a + Integer(13)
>>> d.inverse_mod(a**Integer(2))*d - Integer(1) in k.ideal(a**Integer(2))
True
>>> d.inverse_mod((Integer(5), a + Integer(1)))*d - Integer(1) in k.ideal(Integer(5), a + Integer(1))
True
>>> K = k.extension(x**Integer(2) + Integer(3), names=('b',)); (b,) = K._first_ngens(1)
>>> b.inverse_mod([Integer(37), a - b])
7
>>> Integer(7)*b - Integer(1) in K.ideal(Integer(37), a - b)
True
>>> b.inverse_mod([Integer(37), a - b]).parent() == K
True

is_integer()[source]#

Test whether this number field element is an integer.

EXAMPLES:

sage: x = polygen(ZZ, 'x')
sage: K.<cbrt3> = NumberField(x^3 - 3)
sage: cbrt3.is_integer()
False
sage: (cbrt3**2 - cbrt3 + 2).is_integer()
False
sage: K(-12).is_integer()
True
sage: K(0).is_integer()
True
sage: K(1/2).is_integer()
False

>>> from sage.all import *
>>> x = polygen(ZZ, 'x')
>>> K = NumberField(x**Integer(3) - Integer(3), names=('cbrt3',)); (cbrt3,) = K._first_ngens(1)
>>> cbrt3.is_integer()
False
>>> (cbrt3**Integer(2) - cbrt3 + Integer(2)).is_integer()
False
>>> K(-Integer(12)).is_integer()
True
>>> K(Integer(0)).is_integer()
True
>>> K(Integer(1)/Integer(2)).is_integer()
False

is_integral()[source]#

Determine if a number is in the ring of integers of this number field.

EXAMPLES:

sage: x = polygen(ZZ, 'x')
sage: K.<a> = NumberField(x^2 + 23)
sage: a.is_integral()
True
sage: t = (1+a)/2
sage: t.is_integral()
True
sage: t.minpoly()
x^2 - x + 6
sage: t = a/2
sage: t.is_integral()
False
sage: t.minpoly()
x^2 + 23/4

>>> from sage.all import *
>>> x = polygen(ZZ, 'x')
>>> K = NumberField(x**Integer(2) + Integer(23), names=('a',)); (a,) = K._first_ngens(1)
>>> a.is_integral()
True
>>> t = (Integer(1)+a)/Integer(2)
>>> t.is_integral()
True
>>> t.minpoly()
x^2 - x + 6
>>> t = a/Integer(2)
>>> t.is_integral()
False
>>> t.minpoly()
x^2 + 23/4


An example in a relative extension:

sage: K.<a,b> = NumberField([x^2 + 1, x^2 + 3])
sage: (a + b).is_integral()
True
sage: ((a-b)/2).is_integral()
False

>>> from sage.all import *
>>> K = NumberField([x**Integer(2) + Integer(1), x**Integer(2) + Integer(3)], names=('a', 'b',)); (a, b,) = K._first_ngens(2)
>>> (a + b).is_integral()
True
>>> ((a-b)/Integer(2)).is_integral()
False

is_norm(L, element=False, proof=True)[source]#

Determine whether self is the relative norm of an element of $$L/K$$, where $$K$$ is self.parent().

INPUT:

• L – a number field containing $$K$$ = self.parent().

• elementTrue or False, whether to also output an element of which self is a norm.

• proof – If True, then the output is correct unconditionally. If False, then the output is correct under GRH.

OUTPUT:

If element is False, then the output is a boolean $$B$$, which is True if and only if self is the relative norm of an element of $$L$$ to $$K$$.

If element is True, then the output is a pair $$(B, x)$$, where $$B$$ is as above. If $$B$$ is True, then $$x$$ is an element of $$L$$ such that self == x.norm(K). Otherwise, $$x$$ is None.

ALGORITHM:

Uses PARI’s pari:rnfisnorm. See _rnfisnorm().

EXAMPLES:

sage: x = polygen(ZZ, 'x')
sage: K.<beta> = NumberField(x^3 + 5)
sage: Q.<X> = K[]
sage: L = K.extension(X^2 + X + beta, 'gamma')
sage: (beta/2).is_norm(L)
False
sage: beta.is_norm(L)
True

>>> from sage.all import *
>>> x = polygen(ZZ, 'x')
>>> K = NumberField(x**Integer(3) + Integer(5), names=('beta',)); (beta,) = K._first_ngens(1)
>>> Q = K['X']; (X,) = Q._first_ngens(1)
>>> L = K.extension(X**Integer(2) + X + beta, 'gamma')
>>> (beta/Integer(2)).is_norm(L)
False
>>> beta.is_norm(L)
True


With a relative base field:

sage: K.<a, b> = NumberField([x^2 - 2, x^2 - 3])
sage: L.<c> = K.extension(x^2 - 5)
sage: (2*a*b).is_norm(L)
True
sage: _, v = (2*b*a).is_norm(L, element=True)
sage: v.norm(K) == 2*a*b
True

>>> from sage.all import *
>>> K = NumberField([x**Integer(2) - Integer(2), x**Integer(2) - Integer(3)], names=('a', 'b',)); (a, b,) = K._first_ngens(2)
>>> L = K.extension(x**Integer(2) - Integer(5), names=('c',)); (c,) = L._first_ngens(1)
>>> (Integer(2)*a*b).is_norm(L)
True
>>> _, v = (Integer(2)*b*a).is_norm(L, element=True)
>>> v.norm(K) == Integer(2)*a*b
True


Non-Galois number fields:

sage: K.<a> = NumberField(x^2 + x + 1)
sage: Q.<X> = K[]
sage: L.<b> = NumberField(X^4 + a + 2)
sage: (a/4).is_norm(L)
True
sage: (a/2).is_norm(L)                                                      # needs sage.groups
Traceback (most recent call last):
...
NotImplementedError: is_norm is not implemented unconditionally
for norms from non-Galois number fields
sage: (a/2).is_norm(L, proof=False)                                         # needs sage.groups
False

sage: K.<a> = NumberField(x^3 + x + 1)
sage: Q.<X> = K[]
sage: L.<b> = NumberField(X^4 + a)
sage: t, u = (-a).is_norm(L, element=True); u  # random (not unique)
b^3 + 1
sage: t and u.norm(K) == -a
True

>>> from sage.all import *
>>> K = NumberField(x**Integer(2) + x + Integer(1), names=('a',)); (a,) = K._first_ngens(1)
>>> Q = K['X']; (X,) = Q._first_ngens(1)
>>> L = NumberField(X**Integer(4) + a + Integer(2), names=('b',)); (b,) = L._first_ngens(1)
>>> (a/Integer(4)).is_norm(L)
True
>>> (a/Integer(2)).is_norm(L)                                                      # needs sage.groups
Traceback (most recent call last):
...
NotImplementedError: is_norm is not implemented unconditionally
for norms from non-Galois number fields
>>> (a/Integer(2)).is_norm(L, proof=False)                                         # needs sage.groups
False

>>> K = NumberField(x**Integer(3) + x + Integer(1), names=('a',)); (a,) = K._first_ngens(1)
>>> Q = K['X']; (X,) = Q._first_ngens(1)
>>> L = NumberField(X**Integer(4) + a, names=('b',)); (b,) = L._first_ngens(1)
>>> t, u = (-a).is_norm(L, element=True); u  # random (not unique)
b^3 + 1
>>> t and u.norm(K) == -a
True


Verify that Issue #27469 has been fixed:

sage: L.<z24> = CyclotomicField(24); L
Cyclotomic Field of order 24 and degree 8
sage: K = L.subfield(z24^3, 'z8')[0]; K
Number Field in z8 with defining polynomial x^4 + 1
with z8 = 0.7071067811865475? + 0.7071067811865475?*I
sage: flag, c = K(-7).is_norm(K, element=True); flag
True
sage: c.norm(K)
-7
sage: c in L
True

>>> from sage.all import *
>>> L = CyclotomicField(Integer(24), names=('z24',)); (z24,) = L._first_ngens(1); L
Cyclotomic Field of order 24 and degree 8
>>> K = L.subfield(z24**Integer(3), 'z8')[Integer(0)]; K
Number Field in z8 with defining polynomial x^4 + 1
with z8 = 0.7071067811865475? + 0.7071067811865475?*I
>>> flag, c = K(-Integer(7)).is_norm(K, element=True); flag
True
>>> c.norm(K)
-7
>>> c in L
True


AUTHORS:

• Craig Citro (2008-04-05)

• Marco Streng (2010-12-03)

is_nth_power(n)[source]#

Return True if self is an $$n$$’th power in its parent $$K$$.

EXAMPLES:

sage: x = polygen(ZZ, 'x')
sage: K.<a> = NumberField(x^4 - 7)
sage: K(7).is_nth_power(2)
True
sage: K(7).is_nth_power(4)
True
sage: K(7).is_nth_power(8)
False
sage: K((a-3)^5).is_nth_power(5)
True

>>> from sage.all import *
>>> x = polygen(ZZ, 'x')
>>> K = NumberField(x**Integer(4) - Integer(7), names=('a',)); (a,) = K._first_ngens(1)
>>> K(Integer(7)).is_nth_power(Integer(2))
True
>>> K(Integer(7)).is_nth_power(Integer(4))
True
>>> K(Integer(7)).is_nth_power(Integer(8))
False
>>> K((a-Integer(3))**Integer(5)).is_nth_power(Integer(5))
True


ALGORITHM: Use PARI to factor $$x^n$$ - self in $$K$$.

is_one()[source]#

Test whether this number field element is $$1$$.

EXAMPLES:

sage: x = polygen(ZZ, 'x')
sage: K.<a> = NumberField(x^3 + 3)
sage: K(1).is_one()
True
sage: K(0).is_one()
False
sage: K(-1).is_one()
False
sage: K(1/2).is_one()
False
sage: a.is_one()
False

>>> from sage.all import *
>>> x = polygen(ZZ, 'x')
>>> K = NumberField(x**Integer(3) + Integer(3), names=('a',)); (a,) = K._first_ngens(1)
>>> K(Integer(1)).is_one()
True
>>> K(Integer(0)).is_one()
False
>>> K(-Integer(1)).is_one()
False
>>> K(Integer(1)/Integer(2)).is_one()
False
>>> a.is_one()
False


Return if self is a square in the completion at the prime $$P$$.

INPUT:

• P – a prime ideal

• check – (default: True); check if $$P$$ is prime

EXAMPLES:

sage: x = polygen(ZZ, 'x')
sage: K.<a> = NumberField(x^2 + 2)
sage: p = K.primes_above(2)[0]
False

>>> from sage.all import *
>>> x = polygen(ZZ, 'x')
>>> K = NumberField(x**Integer(2) + Integer(2), names=('a',)); (a,) = K._first_ngens(1)
>>> p = K.primes_above(Integer(2))[Integer(0)]
False

is_prime()[source]#

Test whether this number-field element is prime as an algebraic integer.

Note that the behavior of this method differs from the behavior of is_prime() in a general ring, according to which (number) fields would have no nonzero prime elements.

EXAMPLES:

sage: x = polygen(ZZ, 'x')
sage: K.<i> = NumberField(x^2 + 1)
sage: (1 + i).is_prime()
True
sage: ((1+i)/2).is_prime()
False

>>> from sage.all import *
>>> x = polygen(ZZ, 'x')
>>> K = NumberField(x**Integer(2) + Integer(1), names=('i',)); (i,) = K._first_ngens(1)
>>> (Integer(1) + i).is_prime()
True
>>> ((Integer(1)+i)/Integer(2)).is_prime()
False

is_rational()[source]#

Test whether this number field element is a rational number.

EXAMPLES:

sage: x = polygen(ZZ, 'x')
sage: K.<cbrt3> = NumberField(x^3 - 3)
sage: cbrt3.is_rational()
False
sage: (cbrt3**2 - cbrt3 + 1/2).is_rational()
False
sage: K(-12).is_rational()
True
sage: K(0).is_rational()
True
sage: K(1/2).is_rational()
True

>>> from sage.all import *
>>> x = polygen(ZZ, 'x')
>>> K = NumberField(x**Integer(3) - Integer(3), names=('cbrt3',)); (cbrt3,) = K._first_ngens(1)
>>> cbrt3.is_rational()
False
>>> (cbrt3**Integer(2) - cbrt3 + Integer(1)/Integer(2)).is_rational()
False
>>> K(-Integer(12)).is_rational()
True
>>> K(Integer(0)).is_rational()
True
>>> K(Integer(1)/Integer(2)).is_rational()
True

is_square(root=False)[source]#

Return True if self is a square in its parent number field and otherwise return False.

INPUT:

• root – if True, also return a square root (or None if self is not a perfect square)

EXAMPLES:

sage: x = polygen(ZZ, 'x')
sage: m.<b> = NumberField(x^4 - 1789)
sage: b.is_square()
False
sage: c = (2/3*b + 5)^2; c
4/9*b^2 + 20/3*b + 25
sage: c.is_square()
True
sage: c.is_square(True)
(True, 2/3*b + 5)

>>> from sage.all import *
>>> x = polygen(ZZ, 'x')
>>> m = NumberField(x**Integer(4) - Integer(1789), names=('b',)); (b,) = m._first_ngens(1)
>>> b.is_square()
False
>>> c = (Integer(2)/Integer(3)*b + Integer(5))**Integer(2); c
4/9*b^2 + 20/3*b + 25
>>> c.is_square()
True
>>> c.is_square(True)
(True, 2/3*b + 5)


We also test the functional notation.

sage: is_square(c, True)
(True, 2/3*b + 5)
sage: is_square(c)
True
sage: is_square(c + 1)
False

>>> from sage.all import *
>>> is_square(c, True)
(True, 2/3*b + 5)
>>> is_square(c)
True
>>> is_square(c + Integer(1))
False

is_totally_positive()[source]#

Return True if self is positive for all real embeddings of its parent number field. We do nothing at complex places, so e.g. any element of a totally complex number field will return True.

EXAMPLES:

sage: x = polygen(ZZ, 'x')
sage: F.<b> = NumberField(x^3 - 3*x - 1)
sage: b.is_totally_positive()
False
sage: (b^2).is_totally_positive()
True

>>> from sage.all import *
>>> x = polygen(ZZ, 'x')
>>> F = NumberField(x**Integer(3) - Integer(3)*x - Integer(1), names=('b',)); (b,) = F._first_ngens(1)
>>> b.is_totally_positive()
False
>>> (b**Integer(2)).is_totally_positive()
True

is_unit()[source]#

Return True if self is a unit in the ring where it is defined.

EXAMPLES:

sage: x = polygen(ZZ, 'x')
sage: K.<a> = NumberField(x^2 - x - 1)
sage: OK = K.ring_of_integers()
sage: OK(a).is_unit()
True
sage: OK(13).is_unit()
False
sage: K(13).is_unit()
True

>>> from sage.all import *
>>> x = polygen(ZZ, 'x')
>>> K = NumberField(x**Integer(2) - x - Integer(1), names=('a',)); (a,) = K._first_ngens(1)
>>> OK = K.ring_of_integers()
>>> OK(a).is_unit()
True
>>> OK(Integer(13)).is_unit()
False
>>> K(Integer(13)).is_unit()
True


It also works for relative fields and orders:

sage: K.<a,b> = NumberField([x^2 - 3, x^4 + x^3 + x^2 + x + 1])
sage: OK = K.ring_of_integers()
sage: OK(b).is_unit()
True
sage: OK(a).is_unit()
False
sage: a.is_unit()
True

>>> from sage.all import *
>>> K = NumberField([x**Integer(2) - Integer(3), x**Integer(4) + x**Integer(3) + x**Integer(2) + x + Integer(1)], names=('a', 'b',)); (a, b,) = K._first_ngens(2)
>>> OK = K.ring_of_integers()
>>> OK(b).is_unit()
True
>>> OK(a).is_unit()
False
>>> a.is_unit()
True

list()[source]#

Return the list of coefficients of self written in terms of a power basis.

EXAMPLES:

sage: x = polygen(ZZ, 'x')
sage: K.<a> = NumberField(x^3 - x + 2); ((a + 1)/(a + 2)).list()
[1/4, 1/2, -1/4]
sage: K.<a, b> = NumberField([x^3 - x + 2, x^2 + 23]); ((a + b)/(a + 2)).list()
[3/4*b - 1/2, -1/2*b + 1, 1/4*b - 1/2]

>>> from sage.all import *
>>> x = polygen(ZZ, 'x')
>>> K = NumberField(x**Integer(3) - x + Integer(2), names=('a',)); (a,) = K._first_ngens(1); ((a + Integer(1))/(a + Integer(2))).list()
[1/4, 1/2, -1/4]
>>> K = NumberField([x**Integer(3) - x + Integer(2), x**Integer(2) + Integer(23)], names=('a', 'b',)); (a, b,) = K._first_ngens(2); ((a + b)/(a + Integer(2))).list()
[3/4*b - 1/2, -1/2*b + 1, 1/4*b - 1/2]

local_height(P, prec=None, weighted=False)[source]#

Returns the local height of self at a given prime ideal $$P$$.

INPUT:

• P – a prime ideal of the parent of self

• prec (int) – desired floating point precision (default: default RealField precision).

• weighted (bool, default False) – if True, apply local degree weighting.

OUTPUT:

(real) The local height of this number field element at the place $$P$$. If weighted is True, this is multiplied by the local degree (as required for global heights).

EXAMPLES:

sage: R.<x> = QQ[]
sage: K.<a> = NumberField(x^4 + 3*x^2 - 17)
sage: P = K.ideal(61).factor()[0][0]
sage: b = 1/(a^2 + 30)
sage: b.local_height(P)
4.11087386417331
sage: b.local_height(P, weighted=True)
8.22174772834662
sage: b.local_height(P, 200)
4.1108738641733112487513891034256147463156817430812610629374
sage: (b^2).local_height(P)
8.22174772834662
sage: (b^-1).local_height(P)
0.000000000000000

>>> from sage.all import *
>>> R = QQ['x']; (x,) = R._first_ngens(1)
>>> K = NumberField(x**Integer(4) + Integer(3)*x**Integer(2) - Integer(17), names=('a',)); (a,) = K._first_ngens(1)
>>> P = K.ideal(Integer(61)).factor()[Integer(0)][Integer(0)]
>>> b = Integer(1)/(a**Integer(2) + Integer(30))
>>> b.local_height(P)
4.11087386417331
>>> b.local_height(P, weighted=True)
8.22174772834662
>>> b.local_height(P, Integer(200))
4.1108738641733112487513891034256147463156817430812610629374
>>> (b**Integer(2)).local_height(P)
8.22174772834662
>>> (b**-Integer(1)).local_height(P)
0.000000000000000


A relative example:

sage: PK.<y> = K[]
sage: L.<c> = NumberField(y^2 + a)
sage: L(1/4).local_height(L.ideal(2, c - a + 1))
1.38629436111989

>>> from sage.all import *
>>> PK = K['y']; (y,) = PK._first_ngens(1)
>>> L = NumberField(y**Integer(2) + a, names=('c',)); (c,) = L._first_ngens(1)
>>> L(Integer(1)/Integer(4)).local_height(L.ideal(Integer(2), c - a + Integer(1)))
1.38629436111989

local_height_arch(i, prec=None, weighted=False)[source]#

Returns the local height of self at the $$i$$’th infinite place.

INPUT:

• i (int) – an integer in range(r+s) where $$(r,s)$$ is the signature of the parent field (so $$n=r+2s$$ is the degree).

• prec (int) – desired floating point precision (default: default RealField precision).

• weighted (bool, default False) – if True, apply local degree weighting, i.e. double the value for complex places.

OUTPUT:

(real) The archimedean local height of this number field element at the $$i$$’th infinite place. If weighted is True, this is multiplied by the local degree (as required for global heights), i.e. 1 for real places and 2 for complex places.

EXAMPLES:

sage: R.<x> = QQ[]
sage: K.<a> = NumberField(x^4 + 3*x^2 - 17)
sage: [p.codomain() for p in K.places()]
[Real Field with 106 bits of precision,
Real Field with 106 bits of precision,
Complex Field with 53 bits of precision]
sage: [a.local_height_arch(i) for i in range(3)]
[0.5301924545717755083366563897519,
0.5301924545717755083366563897519,
0.886414217456333]
sage: [a.local_height_arch(i, weighted=True) for i in range(3)]
[0.5301924545717755083366563897519,
0.5301924545717755083366563897519,
1.77282843491267]

>>> from sage.all import *
>>> R = QQ['x']; (x,) = R._first_ngens(1)
>>> K = NumberField(x**Integer(4) + Integer(3)*x**Integer(2) - Integer(17), names=('a',)); (a,) = K._first_ngens(1)
>>> [p.codomain() for p in K.places()]
[Real Field with 106 bits of precision,
Real Field with 106 bits of precision,
Complex Field with 53 bits of precision]
>>> [a.local_height_arch(i) for i in range(Integer(3))]
[0.5301924545717755083366563897519,
0.5301924545717755083366563897519,
0.886414217456333]
>>> [a.local_height_arch(i, weighted=True) for i in range(Integer(3))]
[0.5301924545717755083366563897519,
0.5301924545717755083366563897519,
1.77282843491267]


A relative example:

sage: L.<b, c> = NumberFieldTower([x^2 - 5, x^3 + x + 3])
sage: [(b + c).local_height_arch(i) for i in range(4)]
[1.238223390757884911842206617439,
0.02240347229957875780769746914391,
0.780028961749618,
1.16048938497298]

>>> from sage.all import *
>>> L = NumberFieldTower([x**Integer(2) - Integer(5), x**Integer(3) + x + Integer(3)], names=('b', 'c',)); (b, c,) = L._first_ngens(2)
>>> [(b + c).local_height_arch(i) for i in range(Integer(4))]
[1.238223390757884911842206617439,
0.02240347229957875780769746914391,
0.780028961749618,
1.16048938497298]

matrix(base=None)[source]#

If base is None, return the matrix of right multiplication by the element on the power basis $$1, x, x^2, \ldots, x^{d-1}$$ for the number field. Thus the rows of this matrix give the images of each of the $$x^i$$.

If base is not None, then base must be either a field that embeds in the parent of self or a morphism to the parent of self, in which case this function returns the matrix of multiplication by self on the power basis, where we view the parent field as a field over base.

Specifying base as the base field over which the parent of self is a relative extension is equivalent to base being None.

INPUT:

• base – field or morphism

EXAMPLES:

Regular number field:

sage: K.<a> = NumberField(QQ['x'].0^3 - 5)
sage: M = a.matrix(); M
[0 1 0]
[0 0 1]
[5 0 0]
sage: M.base_ring() is QQ
True

>>> from sage.all import *
>>> K = NumberField(QQ['x'].gen(0)**Integer(3) - Integer(5), names=('a',)); (a,) = K._first_ngens(1)
>>> M = a.matrix(); M
[0 1 0]
[0 0 1]
[5 0 0]
>>> M.base_ring() is QQ
True


Relative number field:

sage: L.<b> = K.extension(K['x'].0^2 - 2)
sage: M = b.matrix(); M
[0 1]
[2 0]
sage: M.base_ring() is K
True

>>> from sage.all import *
>>> L = K.extension(K['x'].gen(0)**Integer(2) - Integer(2), names=('b',)); (b,) = L._first_ngens(1)
>>> M = b.matrix(); M
[0 1]
[2 0]
>>> M.base_ring() is K
True


Absolute number field:

sage: M = L.absolute_field('c').gen().matrix(); M
[  0   1   0   0   0   0]
[  0   0   1   0   0   0]
[  0   0   0   1   0   0]
[  0   0   0   0   1   0]
[  0   0   0   0   0   1]
[-17 -60 -12 -10   6   0]
sage: M.base_ring() is QQ
True

>>> from sage.all import *
>>> M = L.absolute_field('c').gen().matrix(); M
[  0   1   0   0   0   0]
[  0   0   1   0   0   0]
[  0   0   0   1   0   0]
[  0   0   0   0   1   0]
[  0   0   0   0   0   1]
[-17 -60 -12 -10   6   0]
>>> M.base_ring() is QQ
True


More complicated relative number field:

sage: L.<b> = K.extension(K['x'].0^2 - a); L
Number Field in b with defining polynomial x^2 - a over its base field
sage: M = b.matrix(); M
[0 1]
[a 0]
sage: M.base_ring() is K
True

>>> from sage.all import *
>>> L = K.extension(K['x'].gen(0)**Integer(2) - a, names=('b',)); (b,) = L._first_ngens(1); L
Number Field in b with defining polynomial x^2 - a over its base field
>>> M = b.matrix(); M
[0 1]
[a 0]
>>> M.base_ring() is K
True


An example where we explicitly give the subfield or the embedding:

sage: x = polygen(ZZ, 'x')
sage: K.<a> = NumberField(x^4 + 1); L.<a2> = NumberField(x^2 + 1)
sage: a.matrix(L)
[ 0  1]
[a2  0]

>>> from sage.all import *
>>> x = polygen(ZZ, 'x')
>>> K = NumberField(x**Integer(4) + Integer(1), names=('a',)); (a,) = K._first_ngens(1); L = NumberField(x**Integer(2) + Integer(1), names=('a2',)); (a2,) = L._first_ngens(1)
>>> a.matrix(L)
[ 0  1]
[a2  0]


Notice that if we compute all embeddings and choose a different one, then the matrix is changed as it should be:

sage: v = L.embeddings(K)
sage: a.matrix(v[1])
[  0   1]
[-a2   0]

>>> from sage.all import *
>>> v = L.embeddings(K)
>>> a.matrix(v[Integer(1)])
[  0   1]
[-a2   0]


The norm is also changed:

sage: a.norm(v[1])
a2
sage: a.norm(v[0])
-a2

>>> from sage.all import *
>>> a.norm(v[Integer(1)])
a2
>>> a.norm(v[Integer(0)])
-a2

minpoly(var='x')[source]#

Return the minimal polynomial of this number field element.

EXAMPLES:

sage: x = polygen(ZZ, 'x')
sage: K.<a> = NumberField(x^2 + 3)
sage: a.minpoly('x')
x^2 + 3
sage: R.<X> = K['X']
sage: L.<b> = K.extension(X^2 - (22 + a))
sage: b.minpoly('t')
t^2 - a - 22
sage: b.absolute_minpoly('t')
t^4 - 44*t^2 + 487
sage: b^2 - (22+a)
0

>>> from sage.all import *
>>> x = polygen(ZZ, 'x')
>>> K = NumberField(x**Integer(2) + Integer(3), names=('a',)); (a,) = K._first_ngens(1)
>>> a.minpoly('x')
x^2 + 3
>>> R = K['X']; (X,) = R._first_ngens(1)
>>> L = K.extension(X**Integer(2) - (Integer(22) + a), names=('b',)); (b,) = L._first_ngens(1)
>>> b.minpoly('t')
t^2 - a - 22
>>> b.absolute_minpoly('t')
t^4 - 44*t^2 + 487
>>> b**Integer(2) - (Integer(22)+a)
0

multiplicative_order()[source]#

Return the multiplicative order of this number field element.

EXAMPLES:

sage: K.<z> = CyclotomicField(5)
sage: z.multiplicative_order()
5
sage: (-z).multiplicative_order()
10
sage: (1+z).multiplicative_order()
+Infinity

sage: x = polygen(QQ)
sage: K.<a> = NumberField(x^40 - x^20 + 4)
sage: u = 1/4*a^30 + 1/4*a^10 + 1/2
sage: u.multiplicative_order()
6
sage: a.multiplicative_order()
+Infinity

>>> from sage.all import *
>>> K = CyclotomicField(Integer(5), names=('z',)); (z,) = K._first_ngens(1)
>>> z.multiplicative_order()
5
>>> (-z).multiplicative_order()
10
>>> (Integer(1)+z).multiplicative_order()
+Infinity

>>> x = polygen(QQ)
>>> K = NumberField(x**Integer(40) - x**Integer(20) + Integer(4), names=('a',)); (a,) = K._first_ngens(1)
>>> u = Integer(1)/Integer(4)*a**Integer(30) + Integer(1)/Integer(4)*a**Integer(10) + Integer(1)/Integer(2)
>>> u.multiplicative_order()
6
>>> a.multiplicative_order()
+Infinity


An example in a relative extension:

sage: K.<a, b> = NumberField([x^2 + x + 1, x^2 - 3])
sage: z = (a - 1)*b/3
sage: z.multiplicative_order()
12
sage: z^12==1 and z^6!=1 and z^4!=1
True

>>> from sage.all import *
>>> K = NumberField([x**Integer(2) + x + Integer(1), x**Integer(2) - Integer(3)], names=('a', 'b',)); (a, b,) = K._first_ngens(2)
>>> z = (a - Integer(1))*b/Integer(3)
>>> z.multiplicative_order()
12
>>> z**Integer(12)==Integer(1) and z**Integer(6)!=Integer(1) and z**Integer(4)!=Integer(1)
True

norm(K=None)[source]#

Return the absolute or relative norm of this number field element.

If $$K$$ is given, then $$K$$ must be a subfield of the parent $$L$$ of self, in which case the norm is the relative norm from $$L$$ to $$K$$. In all other cases, the norm is the absolute norm down to $$\QQ$$.

EXAMPLES:

sage: x = polygen(ZZ, 'x')
sage: K.<a> = NumberField(x^3 + x^2 + x - 132/7); K
Number Field in a with defining polynomial x^3 + x^2 + x - 132/7
sage: a.norm()
132/7
sage: factor(a.norm())
2^2 * 3 * 7^-1 * 11
sage: K(0).norm()
0

>>> from sage.all import *
>>> x = polygen(ZZ, 'x')
>>> K = NumberField(x**Integer(3) + x**Integer(2) + x - Integer(132)/Integer(7), names=('a',)); (a,) = K._first_ngens(1); K
Number Field in a with defining polynomial x^3 + x^2 + x - 132/7
>>> a.norm()
132/7
>>> factor(a.norm())
2^2 * 3 * 7^-1 * 11
>>> K(Integer(0)).norm()
0


Some complicated relatives norms in a tower of number fields.

sage: K.<a,b,c> = NumberField([x^2 + 1, x^2 + 3, x^2 + 5])
sage: L = K.base_field(); M = L.base_field()
sage: a.norm()
1
sage: a.norm(L)
1
sage: a.norm(M)
1
sage: a
a
sage: (a + b + c).norm()
121
sage: (a + b + c).norm(L)
2*c*b - 7
sage: (a + b + c).norm(M)
-11

>>> from sage.all import *
>>> K = NumberField([x**Integer(2) + Integer(1), x**Integer(2) + Integer(3), x**Integer(2) + Integer(5)], names=('a', 'b', 'c',)); (a, b, c,) = K._first_ngens(3)
>>> L = K.base_field(); M = L.base_field()
>>> a.norm()
1
>>> a.norm(L)
1
>>> a.norm(M)
1
>>> a
a
>>> (a + b + c).norm()
121
>>> (a + b + c).norm(L)
2*c*b - 7
>>> (a + b + c).norm(M)
-11


We illustrate that norm is compatible with towers:

sage: z = (a + b + c).norm(L); z.norm(M)
-11

>>> from sage.all import *
>>> z = (a + b + c).norm(L); z.norm(M)
-11


If we are in an order, the norm is an integer:

sage: K.<a> = NumberField(x^3 - 2)
sage: a.norm().parent()
Rational Field
sage: R = K.ring_of_integers()
sage: R(a).norm().parent()
Integer Ring

>>> from sage.all import *
>>> K = NumberField(x**Integer(3) - Integer(2), names=('a',)); (a,) = K._first_ngens(1)
>>> a.norm().parent()
Rational Field
>>> R = K.ring_of_integers()
>>> R(a).norm().parent()
Integer Ring


When the base field is given by an embedding:

sage: K.<a> = NumberField(x^4 + 1)
sage: L.<a2> = NumberField(x^2 + 1)
sage: v = L.embeddings(K)
sage: a.norm(v[1])
a2
sage: a.norm(v[0])
-a2

>>> from sage.all import *
>>> K = NumberField(x**Integer(4) + Integer(1), names=('a',)); (a,) = K._first_ngens(1)
>>> L = NumberField(x**Integer(2) + Integer(1), names=('a2',)); (a2,) = L._first_ngens(1)
>>> v = L.embeddings(K)
>>> a.norm(v[Integer(1)])
a2
>>> a.norm(v[Integer(0)])
-a2

nth_root(n, all=False)[source]#

Return an $$n$$’th root of self in its parent $$K$$.

EXAMPLES:

sage: x = polygen(ZZ, 'x')
sage: K.<a> = NumberField(x^4 - 7)
sage: K(7).nth_root(2)
a^2
sage: K((a-3)^5).nth_root(5)
a - 3

>>> from sage.all import *
>>> x = polygen(ZZ, 'x')
>>> K = NumberField(x**Integer(4) - Integer(7), names=('a',)); (a,) = K._first_ngens(1)
>>> K(Integer(7)).nth_root(Integer(2))
a^2
>>> K((a-Integer(3))**Integer(5)).nth_root(Integer(5))
a - 3


ALGORITHM: Use PARI to factor $$x^n$$ - self in $$K$$.

numerator_ideal()[source]#

Return the numerator ideal of this number field element.

The numerator ideal of a number field element $$a$$ is the ideal of the ring of integers $$R$$ obtained by intersecting $$aR$$ with $$R$$.

EXAMPLES:

sage: x = polygen(ZZ, 'x')
sage: K.<a> = NumberField(x^2 + 5)
sage: b = (1+a)/2
sage: b.norm()
3/2
sage: N = b.numerator_ideal(); N
Fractional ideal (3, a + 1)
sage: N.norm()
3
sage: (1/b).numerator_ideal()
Fractional ideal (2, a + 1)
sage: K(0).numerator_ideal()
Ideal (0) of Number Field in a with defining polynomial x^2 + 5

>>> from sage.all import *
>>> x = polygen(ZZ, 'x')
>>> K = NumberField(x**Integer(2) + Integer(5), names=('a',)); (a,) = K._first_ngens(1)
>>> b = (Integer(1)+a)/Integer(2)
>>> b.norm()
3/2
>>> N = b.numerator_ideal(); N
Fractional ideal (3, a + 1)
>>> N.norm()
3
>>> (Integer(1)/b).numerator_ideal()
Fractional ideal (2, a + 1)
>>> K(Integer(0)).numerator_ideal()
Ideal (0) of Number Field in a with defining polynomial x^2 + 5

ord(P)[source]#

Return the valuation of self at a given prime ideal $$P$$.

INPUT:

• P – a prime ideal of the parent of self

Note

The method ord() is an alias for valuation().

EXAMPLES:

sage: R.<x> = QQ[]
sage: K.<a> = NumberField(x^4 + 3*x^2 - 17)
sage: P = K.ideal(61).factor()[0][0]
sage: b = a^2 + 30
sage: b.valuation(P)
1
sage: b.ord(P)
1
sage: type(b.valuation(P))
<class 'sage.rings.integer.Integer'>

>>> from sage.all import *
>>> R = QQ['x']; (x,) = R._first_ngens(1)
>>> K = NumberField(x**Integer(4) + Integer(3)*x**Integer(2) - Integer(17), names=('a',)); (a,) = K._first_ngens(1)
>>> P = K.ideal(Integer(61)).factor()[Integer(0)][Integer(0)]
>>> b = a**Integer(2) + Integer(30)
>>> b.valuation(P)
1
>>> b.ord(P)
1
>>> type(b.valuation(P))
<class 'sage.rings.integer.Integer'>


The function can be applied to elements in relative number fields:

sage: L.<b> = K.extension(x^2 - 3)
sage: [L(6).valuation(P) for P in L.primes_above(2)]
[4]
sage: [L(6).valuation(P) for P in L.primes_above(3)]
[2, 2]

>>> from sage.all import *
>>> L = K.extension(x**Integer(2) - Integer(3), names=('b',)); (b,) = L._first_ngens(1)
>>> [L(Integer(6)).valuation(P) for P in L.primes_above(Integer(2))]
[4]
>>> [L(Integer(6)).valuation(P) for P in L.primes_above(Integer(3))]
[2, 2]

polynomial(var='x')[source]#

Return the underlying polynomial corresponding to this number field element.

The resulting polynomial is currently not cached.

EXAMPLES:

sage: x = polygen(ZZ, 'x')
sage: K.<a> = NumberField(x^5 - x - 1)
sage: f = (-2/3 + 1/3*a)^4; f
1/81*a^4 - 8/81*a^3 + 8/27*a^2 - 32/81*a + 16/81
sage: g = f.polynomial(); g
1/81*x^4 - 8/81*x^3 + 8/27*x^2 - 32/81*x + 16/81
sage: parent(g)
Univariate Polynomial Ring in x over Rational Field

>>> from sage.all import *
>>> x = polygen(ZZ, 'x')
>>> K = NumberField(x**Integer(5) - x - Integer(1), names=('a',)); (a,) = K._first_ngens(1)
>>> f = (-Integer(2)/Integer(3) + Integer(1)/Integer(3)*a)**Integer(4); f
1/81*a^4 - 8/81*a^3 + 8/27*a^2 - 32/81*a + 16/81
>>> g = f.polynomial(); g
1/81*x^4 - 8/81*x^3 + 8/27*x^2 - 32/81*x + 16/81
>>> parent(g)
Univariate Polynomial Ring in x over Rational Field


Note that the result of this function is not cached (should this be changed?):

sage: g is f.polynomial()
False

>>> from sage.all import *
>>> g is f.polynomial()
False


Note that in relative number fields, this produces the polynomial of the internal representation of this element:

sage: R.<y> = K[]
sage: L.<b> = K.extension(y^2 - a)
sage: b.polynomial()
x

>>> from sage.all import *
>>> R = K['y']; (y,) = R._first_ngens(1)
>>> L = K.extension(y**Integer(2) - a, names=('b',)); (b,) = L._first_ngens(1)
>>> b.polynomial()
x


In some cases this might not be what you are looking for:

sage: K.<a> = NumberField(x^2 + x + 1)
sage: R.<y> = K[]
sage: L.<b> = K.extension(y^2 + y + 2)
sage: b.polynomial()
1/2*x^3 + 3*x - 1/2
sage: R(list(b))
y

>>> from sage.all import *
>>> K = NumberField(x**Integer(2) + x + Integer(1), names=('a',)); (a,) = K._first_ngens(1)
>>> R = K['y']; (y,) = R._first_ngens(1)
>>> L = K.extension(y**Integer(2) + y + Integer(2), names=('b',)); (b,) = L._first_ngens(1)
>>> b.polynomial()
1/2*x^3 + 3*x - 1/2
>>> R(list(b))
y

relative_norm()[source]#

Return the relative norm of this number field element over the next field down in some tower of number fields.

EXAMPLES:

sage: K1.<a1> = CyclotomicField(11)
sage: x = polygen(ZZ, 'x')
sage: K2.<a2> = K1.extension(x^2 - 3)
sage: (a1 + a2).relative_norm()
a1^2 - 3
sage: (a1 + a2).relative_norm().relative_norm() == (a1 + a2).absolute_norm()
True

sage: K.<x,y,z> = NumberField([x^2 + 1, x^3 - 3, x^2 - 5])
sage: (x + y + z).relative_norm()
y^2 + 2*z*y + 6

>>> from sage.all import *
>>> K1 = CyclotomicField(Integer(11), names=('a1',)); (a1,) = K1._first_ngens(1)
>>> x = polygen(ZZ, 'x')
>>> K2 = K1.extension(x**Integer(2) - Integer(3), names=('a2',)); (a2,) = K2._first_ngens(1)
>>> (a1 + a2).relative_norm()
a1^2 - 3
>>> (a1 + a2).relative_norm().relative_norm() == (a1 + a2).absolute_norm()
True

>>> K = NumberField([x**Integer(2) + Integer(1), x**Integer(3) - Integer(3), x**Integer(2) - Integer(5)], names=('x', 'y', 'z',)); (x, y, z,) = K._first_ngens(3)
>>> (x + y + z).relative_norm()
y^2 + 2*z*y + 6

residue_symbol(P, m, check=True)[source]#

The $$m$$-th power residue symbol for an element self and proper ideal $$P$$.

$\left(\frac{\alpha}{\mathbf{P}}\right) \equiv \alpha^{\frac{N(\mathbf{P})-1}{m}} \operatorname{mod} \mathbf{P}$

Note

accepts $$m=1$$, in which case returns 1

Note

can also be called for an ideal from sage.rings.number_field_ideal.residue_symbol

Note

self is coerced into the number field of the ideal P

Note

if $$m=2$$, self is an integer, and $$P$$ is an ideal of a number field of absolute degree 1 (i.e. it is a copy of the rationals), then this calls kronecker_symbol(), which is implemented using GMP.

INPUT:

• P – proper ideal of the number field (or an extension)

• m – positive integer

OUTPUT:

• an $$m$$-th root of unity in the number field

EXAMPLES:

Quadratic Residue (11 is not a square modulo 17):

sage: x = polygen(ZZ, 'x')
sage: K.<a> = NumberField(x - 1)
sage: K(11).residue_symbol(K.ideal(17),2)
-1
sage: kronecker_symbol(11, 17)
-1

>>> from sage.all import *
>>> x = polygen(ZZ, 'x')
>>> K = NumberField(x - Integer(1), names=('a',)); (a,) = K._first_ngens(1)
>>> K(Integer(11)).residue_symbol(K.ideal(Integer(17)),Integer(2))
-1
>>> kronecker_symbol(Integer(11), Integer(17))
-1


The result depends on the number field of the ideal:

sage: K.<a> = NumberField(x - 1)
sage: L.<b> = K.extension(x^2 + 1)
sage: K(7).residue_symbol(K.ideal(11),2)
-1
sage: K(7).residue_symbol(L.ideal(11),2)                                    # needs sage.libs.gap
1

>>> from sage.all import *
>>> K = NumberField(x - Integer(1), names=('a',)); (a,) = K._first_ngens(1)
>>> L = K.extension(x**Integer(2) + Integer(1), names=('b',)); (b,) = L._first_ngens(1)
>>> K(Integer(7)).residue_symbol(K.ideal(Integer(11)),Integer(2))
-1
>>> K(Integer(7)).residue_symbol(L.ideal(Integer(11)),Integer(2))                                    # needs sage.libs.gap
1


Cubic Residue:

sage: K.<w> = NumberField(x^2 - x + 1)
sage: (w^2 + 3).residue_symbol(K.ideal(17),3)
-w

>>> from sage.all import *
>>> K = NumberField(x**Integer(2) - x + Integer(1), names=('w',)); (w,) = K._first_ngens(1)
>>> (w**Integer(2) + Integer(3)).residue_symbol(K.ideal(Integer(17)),Integer(3))
-w


The field must contain the m-th roots of unity:

sage: K.<w> = NumberField(x^2 - x + 1)
sage: (w^2 + 3).residue_symbol(K.ideal(17),5)
Traceback (most recent call last):
...
ValueError: The residue symbol to that power is not defined for the number field

>>> from sage.all import *
>>> K = NumberField(x**Integer(2) - x + Integer(1), names=('w',)); (w,) = K._first_ngens(1)
>>> (w**Integer(2) + Integer(3)).residue_symbol(K.ideal(Integer(17)),Integer(5))
Traceback (most recent call last):
...
ValueError: The residue symbol to that power is not defined for the number field

round()[source]#

Return the round (nearest integer) of this number field element. In case of ties, this relies on the default rounding for rational numbers.

EXAMPLES:

sage: x = polygen(ZZ)
sage: p = x**7 - 5*x**2 + x + 1
sage: a_AA = AA.polynomial_root(p, RIF(1,2))
sage: K.<a> = NumberField(p, embedding=a_AA)
sage: b = a**5 + a/2 - 1/7
sage: RR(b)
4.13444473767055
sage: b.round()
4
sage: (-b).round()
-4
sage: (b + 1/2).round()
5
sage: (-b - 1/2).round()
-5

>>> from sage.all import *
>>> x = polygen(ZZ)
>>> p = x**Integer(7) - Integer(5)*x**Integer(2) + x + Integer(1)
>>> a_AA = AA.polynomial_root(p, RIF(Integer(1),Integer(2)))
>>> K = NumberField(p, embedding=a_AA, names=('a',)); (a,) = K._first_ngens(1)
>>> b = a**Integer(5) + a/Integer(2) - Integer(1)/Integer(7)
>>> RR(b)
4.13444473767055
>>> b.round()
4
>>> (-b).round()
-4
>>> (b + Integer(1)/Integer(2)).round()
5
>>> (-b - Integer(1)/Integer(2)).round()
-5


This function always succeeds even if a tremendous precision is needed:

sage: c = b - 5678322907931/1225243417356 + 3
sage: c.round()
3
sage: RIF(c).unique_round()
Traceback (most recent call last):
...
ValueError: interval does not have a unique round (nearest integer)

>>> from sage.all import *
>>> c = b - Integer(5678322907931)/Integer(1225243417356) + Integer(3)
>>> c.round()
3
>>> RIF(c).unique_round()
Traceback (most recent call last):
...
ValueError: interval does not have a unique round (nearest integer)


If the number field is not embedded, this function is valid only if the element is rational:

sage: p = x**5 - 3
sage: K.<a> = NumberField(p)
sage: [K(k/3).round() for k in range(-3,4)]
[-1, -1, 0, 0, 0, 1, 1]
sage: a.round()
Traceback (most recent call last):
...
TypeError: floor not uniquely defined since no real embedding is specified

>>> from sage.all import *
>>> p = x**Integer(5) - Integer(3)
>>> K = NumberField(p, names=('a',)); (a,) = K._first_ngens(1)
>>> [K(k/Integer(3)).round() for k in range(-Integer(3),Integer(4))]
[-1, -1, 0, 0, 0, 1, 1]
>>> a.round()
Traceback (most recent call last):
...
TypeError: floor not uniquely defined since no real embedding is specified

sign()[source]#

Return the sign of this algebraic number (if a real embedding is well defined)

EXAMPLES:

sage: x = polygen(ZZ, 'x')
sage: K.<a> = NumberField(x^3 - 2, embedding=AA(2)**(1/3))
sage: K.zero().sign()
0
sage: K.one().sign()
1
sage: (-K.one()).sign()
-1
sage: a.sign()
1
sage: (a - 234917380309015/186454048314072).sign()
1
sage: (a - 3741049304830488/2969272800976409).sign()
-1

>>> from sage.all import *
>>> x = polygen(ZZ, 'x')
>>> K = NumberField(x**Integer(3) - Integer(2), embedding=AA(Integer(2))**(Integer(1)/Integer(3)), names=('a',)); (a,) = K._first_ngens(1)
>>> K.zero().sign()
0
>>> K.one().sign()
1
>>> (-K.one()).sign()
-1
>>> a.sign()
1
>>> (a - Integer(234917380309015)/Integer(186454048314072)).sign()
1
>>> (a - Integer(3741049304830488)/Integer(2969272800976409)).sign()
-1


If the field is not embedded in real numbers, this method will only work for rational elements:

sage: L.<b> = NumberField(x^4 - x - 1)
sage: b.sign()
Traceback (most recent call last):
...
TypeError: sign not well defined since no real embedding is
specified
sage: L(-33/125).sign()
-1
sage: L.zero().sign()
0

>>> from sage.all import *
>>> L = NumberField(x**Integer(4) - x - Integer(1), names=('b',)); (b,) = L._first_ngens(1)
>>> b.sign()
Traceback (most recent call last):
...
TypeError: sign not well defined since no real embedding is
specified
>>> L(-Integer(33)/Integer(125)).sign()
-1
>>> L.zero().sign()
0

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

Return the square root of this number in the given number field.

INPUT:

• all – optional boolean (default False); whether to return both square roots

• extend – optional boolean (default True); whether to extend the field by adding the square roots if needed

EXAMPLES:

sage: x = polygen(ZZ, 'x')
sage: K.<a> = NumberField(x^2 - 3)
sage: K(3).sqrt()
a
sage: K(3).sqrt(all=True)
[a, -a]
sage: K(a^10).sqrt()
9*a
sage: K(49).sqrt()
7
sage: K(1+a).sqrt(extend=False)
Traceback (most recent call last):
...
ValueError: a + 1 not a square in Number Field in a with defining polynomial x^2 - 3
sage: K(0).sqrt()
0
sage: K((7+a)^2).sqrt(all=True)
[a + 7, -a - 7]

>>> from sage.all import *
>>> x = polygen(ZZ, 'x')
>>> K = NumberField(x**Integer(2) - Integer(3), names=('a',)); (a,) = K._first_ngens(1)
>>> K(Integer(3)).sqrt()
a
>>> K(Integer(3)).sqrt(all=True)
[a, -a]
>>> K(a**Integer(10)).sqrt()
9*a
>>> K(Integer(49)).sqrt()
7
>>> K(Integer(1)+a).sqrt(extend=False)
Traceback (most recent call last):
...
ValueError: a + 1 not a square in Number Field in a with defining polynomial x^2 - 3
>>> K(Integer(0)).sqrt()
0
>>> K((Integer(7)+a)**Integer(2)).sqrt(all=True)
[a + 7, -a - 7]

sage: K.<a> = CyclotomicField(7)
sage: a.sqrt()
a^4

>>> from sage.all import *
>>> K = CyclotomicField(Integer(7), names=('a',)); (a,) = K._first_ngens(1)
>>> a.sqrt()
a^4

sage: K.<a> = NumberField(x^5 - x + 1)
sage: (a^4 + a^2 - 3*a + 2).sqrt()
a^3 - a^2

>>> from sage.all import *
>>> K = NumberField(x**Integer(5) - x + Integer(1), names=('a',)); (a,) = K._first_ngens(1)
>>> (a**Integer(4) + a**Integer(2) - Integer(3)*a + Integer(2)).sqrt()
a^3 - a^2


Using the extend keyword:

sage: K = QuadraticField(-5)
sage: z = K(-7).sqrt(extend=True); z                                        # needs sage.symbolic
sqrt(-7)
sage: CyclotomicField(4)(4).sqrt(extend=False)
2

>>> from sage.all import *
>>> z = K(-Integer(7)).sqrt(extend=True); z                                        # needs sage.symbolic
sqrt(-7)
>>> CyclotomicField(Integer(4))(Integer(4)).sqrt(extend=False)
2


If extend=False an error is raised, if self is not a square:

sage: K = QuadraticField(-5)
sage: K(-7).sqrt(extend=False)
Traceback (most recent call last):
...
ValueError: -7 not a square in Number Field in a
with defining polynomial x^2 + 5 with a = 2.236067977499790?*I

>>> from sage.all import *
>>> K(-Integer(7)).sqrt(extend=False)
Traceback (most recent call last):
...
ValueError: -7 not a square in Number Field in a
with defining polynomial x^2 + 5 with a = 2.236067977499790?*I


ALGORITHM: Use PARI to factor $$x^2$$ $$-$$ self in $$K$$.

support()[source]#

Return the support of this number field element.

OUTPUT: A sorted list of the prime ideals at which this number field element has nonzero valuation. An error is raised if the element is zero.

EXAMPLES:

sage: x = ZZ['x'].gen()
sage: F.<t> = NumberField(x^3 - 2)

>>> from sage.all import *
>>> x = ZZ['x'].gen()
>>> F = NumberField(x**Integer(3) - Integer(2), names=('t',)); (t,) = F._first_ngens(1)

sage: P5s = F(5).support()
sage: P5s
[Fractional ideal (-t^2 - 1), Fractional ideal (t^2 - 2*t - 1)]
sage: all(5 in P5 for P5 in P5s)
True
sage: all(P5.is_prime() for P5 in P5s)
True
sage: [ P5.norm() for P5 in P5s ]
[5, 25]

>>> from sage.all import *
>>> P5s = F(Integer(5)).support()
>>> P5s
[Fractional ideal (-t^2 - 1), Fractional ideal (t^2 - 2*t - 1)]
>>> all(Integer(5) in P5 for P5 in P5s)
True
>>> all(P5.is_prime() for P5 in P5s)
True
>>> [ P5.norm() for P5 in P5s ]
[5, 25]

trace(K=None)[source]#

Return the absolute or relative trace of this number field element.

If $$K$$ is given, then $$K$$ must be a subfield of the parent $$L$$ of self, in which case the trace is the relative trace from $$L$$ to $$K$$. In all other cases, the trace is the absolute trace down to $$\QQ$$.

EXAMPLES:

sage: x = polygen(ZZ, 'x')
sage: K.<a> = NumberField(x^3 - 132/7*x^2 + x + 1); K
Number Field in a with defining polynomial x^3 - 132/7*x^2 + x + 1
sage: a.trace()
132/7
sage: (a + 1).trace() == a.trace() + 3
True

>>> from sage.all import *
>>> x = polygen(ZZ, 'x')
>>> K = NumberField(x**Integer(3) - Integer(132)/Integer(7)*x**Integer(2) + x + Integer(1), names=('a',)); (a,) = K._first_ngens(1); K
Number Field in a with defining polynomial x^3 - 132/7*x^2 + x + 1
>>> a.trace()
132/7
>>> (a + Integer(1)).trace() == a.trace() + Integer(3)
True


If we are in an order, the trace is an integer:

sage: K.<zeta> = CyclotomicField(17)
sage: R = K.ring_of_integers()
sage: R(zeta).trace().parent()
Integer Ring

>>> from sage.all import *
>>> K = CyclotomicField(Integer(17), names=('zeta',)); (zeta,) = K._first_ngens(1)
>>> R = K.ring_of_integers()
>>> R(zeta).trace().parent()
Integer Ring

valuation(P)[source]#

Return the valuation of self at a given prime ideal $$P$$.

INPUT:

• P – a prime ideal of the parent of self

Note

The method ord() is an alias for valuation().

EXAMPLES:

sage: R.<x> = QQ[]
sage: K.<a> = NumberField(x^4 + 3*x^2 - 17)
sage: P = K.ideal(61).factor()[0][0]
sage: b = a^2 + 30
sage: b.valuation(P)
1
sage: b.ord(P)
1
sage: type(b.valuation(P))
<class 'sage.rings.integer.Integer'>

>>> from sage.all import *
>>> R = QQ['x']; (x,) = R._first_ngens(1)
>>> K = NumberField(x**Integer(4) + Integer(3)*x**Integer(2) - Integer(17), names=('a',)); (a,) = K._first_ngens(1)
>>> P = K.ideal(Integer(61)).factor()[Integer(0)][Integer(0)]
>>> b = a**Integer(2) + Integer(30)
>>> b.valuation(P)
1
>>> b.ord(P)
1
>>> type(b.valuation(P))
<class 'sage.rings.integer.Integer'>


The function can be applied to elements in relative number fields:

sage: L.<b> = K.extension(x^2 - 3)
sage: [L(6).valuation(P) for P in L.primes_above(2)]
[4]
sage: [L(6).valuation(P) for P in L.primes_above(3)]
[2, 2]

>>> from sage.all import *
>>> L = K.extension(x**Integer(2) - Integer(3), names=('b',)); (b,) = L._first_ngens(1)
>>> [L(Integer(6)).valuation(P) for P in L.primes_above(Integer(2))]
[4]
>>> [L(Integer(6)).valuation(P) for P in L.primes_above(Integer(3))]
[2, 2]

vector()[source]#

Return vector representation of self in terms of the basis for the ambient number field.

EXAMPLES:

sage: x = polygen(ZZ, 'x')
sage: K.<a> = NumberField(x^2 + 1)
sage: (2/3*a - 5/6).vector()
(-5/6, 2/3)
sage: (-5/6, 2/3)
(-5/6, 2/3)
sage: O = K.order(2*a)
sage: (O.1).vector()
(0, 2)
sage: K.<a,b> = NumberField([x^2 + 1, x^2 - 3])
sage: (a + b).vector()
(b, 1)
sage: O = K.order([a,b])
sage: (O.1).vector()
(-b, 1)
sage: (O.2).vector()
(1, -b)

>>> from sage.all import *
>>> x = polygen(ZZ, 'x')
>>> K = NumberField(x**Integer(2) + Integer(1), names=('a',)); (a,) = K._first_ngens(1)
>>> (Integer(2)/Integer(3)*a - Integer(5)/Integer(6)).vector()
(-5/6, 2/3)
>>> (-Integer(5)/Integer(6), Integer(2)/Integer(3))
(-5/6, 2/3)
>>> O = K.order(Integer(2)*a)
>>> (O.gen(1)).vector()
(0, 2)
>>> K = NumberField([x**Integer(2) + Integer(1), x**Integer(2) - Integer(3)], names=('a', 'b',)); (a, b,) = K._first_ngens(2)
>>> (a + b).vector()
(b, 1)
>>> O = K.order([a,b])
>>> (O.gen(1)).vector()
(-b, 1)
>>> (O.gen(2)).vector()
(1, -b)

class sage.rings.number_field.number_field_element.NumberFieldElement_absolute[source]#
absolute_charpoly(var='x', algorithm=None)[source]#

Return the characteristic polynomial of this element over $$\QQ$$.

For the meaning of the optional argument algorithm, see charpoly().

EXAMPLES:

sage: x = ZZ['x'].0
sage: K.<a> = NumberField(x^4 + 2, 'a')
sage: a.absolute_charpoly()
x^4 + 2
sage: a.absolute_charpoly('y')
y^4 + 2
sage: (-a^2).absolute_charpoly()
x^4 + 4*x^2 + 4
sage: (-a^2).absolute_minpoly()
x^2 + 2

sage: a.absolute_charpoly(algorithm='pari') == a.absolute_charpoly(algorithm='sage')
True

>>> from sage.all import *
>>> x = ZZ['x'].gen(0)
>>> K = NumberField(x**Integer(4) + Integer(2), 'a', names=('a',)); (a,) = K._first_ngens(1)
>>> a.absolute_charpoly()
x^4 + 2
>>> a.absolute_charpoly('y')
y^4 + 2
>>> (-a**Integer(2)).absolute_charpoly()
x^4 + 4*x^2 + 4
>>> (-a**Integer(2)).absolute_minpoly()
x^2 + 2

>>> a.absolute_charpoly(algorithm='pari') == a.absolute_charpoly(algorithm='sage')
True

absolute_minpoly(var='x', algorithm=None)[source]#

Return the minimal polynomial of this element over $$\QQ$$.

For the meaning of the optional argument algorithm, see charpoly().

EXAMPLES:

sage: x = ZZ['x'].0
sage: f = (x^10 - 5*x^9 + 15*x^8 - 68*x^7 + 81*x^6 - 221*x^5
....:       + 141*x^4 - 242*x^3 - 13*x^2 - 33*x - 135)
sage: K.<a> = NumberField(f, 'a')
sage: a.absolute_charpoly()
x^10 - 5*x^9 + 15*x^8 - 68*x^7 + 81*x^6 - 221*x^5
+ 141*x^4 - 242*x^3 - 13*x^2 - 33*x - 135
sage: a.absolute_charpoly('y')
y^10 - 5*y^9 + 15*y^8 - 68*y^7 + 81*y^6 - 221*y^5
+ 141*y^4 - 242*y^3 - 13*y^2 - 33*y - 135
sage: b = (-79/9995*a^9 + 52/9995*a^8 + 271/9995*a^7 + 1663/9995*a^6
....:       + 13204/9995*a^5 + 5573/9995*a^4 + 8435/1999*a^3
....:       - 3116/9995*a^2 + 7734/1999*a + 1620/1999)
sage: b.absolute_charpoly()
x^10 + 10*x^9 + 25*x^8 - 80*x^7 - 438*x^6 + 80*x^5
+ 2950*x^4 + 1520*x^3 - 10439*x^2 - 5130*x + 18225
sage: b.absolute_minpoly()
x^5 + 5*x^4 - 40*x^2 - 19*x + 135

sage: b.absolute_minpoly(algorithm='pari') == b.absolute_minpoly(algorithm='sage')      # needs sage.libs.pari
True

>>> from sage.all import *
>>> x = ZZ['x'].gen(0)
>>> f = (x**Integer(10) - Integer(5)*x**Integer(9) + Integer(15)*x**Integer(8) - Integer(68)*x**Integer(7) + Integer(81)*x**Integer(6) - Integer(221)*x**Integer(5)
...       + Integer(141)*x**Integer(4) - Integer(242)*x**Integer(3) - Integer(13)*x**Integer(2) - Integer(33)*x - Integer(135))
>>> K = NumberField(f, 'a', names=('a',)); (a,) = K._first_ngens(1)
>>> a.absolute_charpoly()
x^10 - 5*x^9 + 15*x^8 - 68*x^7 + 81*x^6 - 221*x^5
+ 141*x^4 - 242*x^3 - 13*x^2 - 33*x - 135
>>> a.absolute_charpoly('y')
y^10 - 5*y^9 + 15*y^8 - 68*y^7 + 81*y^6 - 221*y^5
+ 141*y^4 - 242*y^3 - 13*y^2 - 33*y - 135
>>> b = (-Integer(79)/Integer(9995)*a**Integer(9) + Integer(52)/Integer(9995)*a**Integer(8) + Integer(271)/Integer(9995)*a**Integer(7) + Integer(1663)/Integer(9995)*a**Integer(6)
...       + Integer(13204)/Integer(9995)*a**Integer(5) + Integer(5573)/Integer(9995)*a**Integer(4) + Integer(8435)/Integer(1999)*a**Integer(3)
...       - Integer(3116)/Integer(9995)*a**Integer(2) + Integer(7734)/Integer(1999)*a + Integer(1620)/Integer(1999))
>>> b.absolute_charpoly()
x^10 + 10*x^9 + 25*x^8 - 80*x^7 - 438*x^6 + 80*x^5
+ 2950*x^4 + 1520*x^3 - 10439*x^2 - 5130*x + 18225
>>> b.absolute_minpoly()
x^5 + 5*x^4 - 40*x^2 - 19*x + 135

>>> b.absolute_minpoly(algorithm='pari') == b.absolute_minpoly(algorithm='sage')      # needs sage.libs.pari
True

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

The characteristic polynomial of this element, over $$\QQ$$ if self is an element of a field, and over $$\ZZ$$ is self is an element of an order.

This is the same as absolute_charpoly() since this is an element of an absolute extension.

The optional argument algorithm controls how the characteristic polynomial is computed: 'pari' uses PARI, 'sage' uses charpoly for Sage matrices. The default value None means that 'pari' is used for small degrees (up to the value of the constant TUNE_CHARPOLY_NF, currently at 25), otherwise 'sage' is used. The constant TUNE_CHARPOLY_NF should give reasonable performance on all architectures; however, if you feel the need to customize it to your own machine, see Issue #5213 for a tuning script.

EXAMPLES:

We compute the characteristic polynomial of the cube root of $$2$$.

sage: R.<x> = QQ[]
sage: K.<a> = NumberField(x^3 - 2)
sage: a.charpoly('x')
x^3 - 2
sage: a.charpoly('y').parent()
Univariate Polynomial Ring in y over Rational Field

>>> from sage.all import *
>>> R = QQ['x']; (x,) = R._first_ngens(1)
>>> K = NumberField(x**Integer(3) - Integer(2), names=('a',)); (a,) = K._first_ngens(1)
>>> a.charpoly('x')
x^3 - 2
>>> a.charpoly('y').parent()
Univariate Polynomial Ring in y over Rational Field

is_real_positive(min_prec=53)[source]#

Using the n method of approximation, return True if self is a real positive number and False otherwise. This method is completely dependent of the embedding used by the n method.

The algorithm first checks that self is not a strictly complex number. Then if self is not zero, by approximation more and more precise, the method answers True if the number is positive. Using RealInterval, the result is guaranteed to be correct.

For CyclotomicField, the embedding is the natural one sending zetan on $$\cos(2*\pi/n)$$.

EXAMPLES:

sage: K.<a> = CyclotomicField(3)
sage: (a + a^2).is_real_positive()
False
sage: (-a - a^2).is_real_positive()
True
sage: K.<a> = CyclotomicField(1000)
sage: (a + a^(-1)).is_real_positive()
True
sage: K.<a> = CyclotomicField(1009)
sage: d = a^252
sage: (d + d.conjugate()).is_real_positive()
True
sage: d = a^253
sage: (d + d.conjugate()).is_real_positive()
False
sage: a.is_real_positive()
True
sage: a.is_real_positive()
False
sage: (a - a).is_real_positive()
False

>>> from sage.all import *
>>> K = CyclotomicField(Integer(3), names=('a',)); (a,) = K._first_ngens(1)
>>> (a + a**Integer(2)).is_real_positive()
False
>>> (-a - a**Integer(2)).is_real_positive()
True
>>> K = CyclotomicField(Integer(1000), names=('a',)); (a,) = K._first_ngens(1)
>>> (a + a**(-Integer(1))).is_real_positive()
True
>>> K = CyclotomicField(Integer(1009), names=('a',)); (a,) = K._first_ngens(1)
>>> d = a**Integer(252)
>>> (d + d.conjugate()).is_real_positive()
True
>>> d = a**Integer(253)
>>> (d + d.conjugate()).is_real_positive()
False
>>> K = QuadraticField(Integer(3), names=('a',)); (a,) = K._first_ngens(1)
>>> a.is_real_positive()
True
>>> K = QuadraticField(-Integer(3), names=('a',)); (a,) = K._first_ngens(1)
>>> a.is_real_positive()
False
>>> (a - a).is_real_positive()
False

lift(var='x')[source]#

Return an element of $$\QQ[x]$$, where this number field element lives in $$\QQ[x]/(f(x))$$.

EXAMPLES:

sage: K.<a> = QuadraticField(-3)
sage: a.lift()
x

>>> from sage.all import *
>>> K = QuadraticField(-Integer(3), names=('a',)); (a,) = K._first_ngens(1)
>>> a.lift()
x

list()[source]#

Return the list of coefficients of self written in terms of a power basis.

EXAMPLES:

sage: K.<z> = CyclotomicField(3)
sage: (2 + 3/5*z).list()
[2, 3/5]
sage: (5*z).list()
[0, 5]
sage: K(3).list()
[3, 0]

>>> from sage.all import *
>>> K = CyclotomicField(Integer(3), names=('z',)); (z,) = K._first_ngens(1)
>>> (Integer(2) + Integer(3)/Integer(5)*z).list()
[2, 3/5]
>>> (Integer(5)*z).list()
[0, 5]
>>> K(Integer(3)).list()
[3, 0]

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

Return the minimal polynomial of this number field element.

For the meaning of the optional argument algorithm, see charpoly().

EXAMPLES:

We compute the characteristic polynomial of cube root of $$2$$.

sage: R.<x> = QQ[]
sage: K.<a> = NumberField(x^3 - 2)
sage: a.minpoly('x')
x^3 - 2
sage: a.minpoly('y').parent()
Univariate Polynomial Ring in y over Rational Field

>>> from sage.all import *
>>> R = QQ['x']; (x,) = R._first_ngens(1)
>>> K = NumberField(x**Integer(3) - Integer(2), names=('a',)); (a,) = K._first_ngens(1)
>>> a.minpoly('x')
x^3 - 2
>>> a.minpoly('y').parent()
Univariate Polynomial Ring in y over Rational Field

class sage.rings.number_field.number_field_element.NumberFieldElement_relative[source]#

The current relative number field element implementation does everything in terms of absolute polynomials.

All conversions from relative polynomials, lists, vectors, etc should happen in the parent.

absolute_charpoly(var='x', algorithm=None)[source]#

The characteristic polynomial of this element over $$\QQ$$.

We construct a relative extension and find the characteristic polynomial over $$\QQ$$.

The optional argument algorithm controls how the characteristic polynomial is computed: 'pari' uses PARI, 'sage' uses charpoly for Sage matrices. The default value None means that 'pari' is used for small degrees (up to the value of the constant TUNE_CHARPOLY_NF, currently at 25), otherwise 'sage' is used. The constant TUNE_CHARPOLY_NF should give reasonable performance on all architectures; however, if you feel the need to customize it to your own machine, see Issue #5213 for a tuning script.

EXAMPLES:

sage: R.<x> = QQ[]
sage: K.<a> = NumberField(x^3-2)
sage: S.<X> = K[]
sage: L.<b> = NumberField(X^3 + 17); L
Number Field in b with defining polynomial X^3 + 17 over its base field
sage: b.absolute_charpoly()
x^9 + 51*x^6 + 867*x^3 + 4913
sage: b.charpoly()(b)
0
sage: a = L.0; a
b
sage: a.absolute_charpoly('x')
x^9 + 51*x^6 + 867*x^3 + 4913
sage: a.absolute_charpoly('y')
y^9 + 51*y^6 + 867*y^3 + 4913

sage: a.absolute_charpoly(algorithm='pari') == a.absolute_charpoly(algorithm='sage')    # needs sage.libs.pari
True

>>> from sage.all import *
>>> R = QQ['x']; (x,) = R._first_ngens(1)
>>> K = NumberField(x**Integer(3)-Integer(2), names=('a',)); (a,) = K._first_ngens(1)
>>> S = K['X']; (X,) = S._first_ngens(1)
>>> L = NumberField(X**Integer(3) + Integer(17), names=('b',)); (b,) = L._first_ngens(1); L
Number Field in b with defining polynomial X^3 + 17 over its base field
>>> b.absolute_charpoly()
x^9 + 51*x^6 + 867*x^3 + 4913
>>> b.charpoly()(b)
0
>>> a = L.gen(0); a
b
>>> a.absolute_charpoly('x')
x^9 + 51*x^6 + 867*x^3 + 4913
>>> a.absolute_charpoly('y')
y^9 + 51*y^6 + 867*y^3 + 4913

>>> a.absolute_charpoly(algorithm='pari') == a.absolute_charpoly(algorithm='sage')    # needs sage.libs.pari
True

absolute_minpoly(var='x', algorithm=None)[source]#

Return the minimal polynomial over $$\QQ$$ of this element.

For the meaning of the optional argument algorithm, see absolute_charpoly().

EXAMPLES:

sage: x = polygen(ZZ, 'x')
sage: K.<a, b> = NumberField([x^2 + 2, x^2 + 1000*x + 1])
sage: y = K['y'].0
sage: L.<c> = K.extension(y^2 + a*y + b)
sage: c.absolute_charpoly()
x^8 - 1996*x^6 + 996006*x^4 + 1997996*x^2 + 1
sage: c.absolute_minpoly()
x^8 - 1996*x^6 + 996006*x^4 + 1997996*x^2 + 1
sage: L(a).absolute_charpoly()
x^8 + 8*x^6 + 24*x^4 + 32*x^2 + 16
sage: L(a).absolute_minpoly()
x^2 + 2
sage: L(b).absolute_charpoly()
x^8 + 4000*x^7 + 6000004*x^6 + 4000012000*x^5 + 1000012000006*x^4
+ 4000012000*x^3 + 6000004*x^2 + 4000*x + 1
sage: L(b).absolute_minpoly()
x^2 + 1000*x + 1

>>> from sage.all import *
>>> x = polygen(ZZ, 'x')
>>> K = NumberField([x**Integer(2) + Integer(2), x**Integer(2) + Integer(1000)*x + Integer(1)], names=('a', 'b',)); (a, b,) = K._first_ngens(2)
>>> y = K['y'].gen(0)
>>> L = K.extension(y**Integer(2) + a*y + b, names=('c',)); (c,) = L._first_ngens(1)
>>> c.absolute_charpoly()
x^8 - 1996*x^6 + 996006*x^4 + 1997996*x^2 + 1
>>> c.absolute_minpoly()
x^8 - 1996*x^6 + 996006*x^4 + 1997996*x^2 + 1
>>> L(a).absolute_charpoly()
x^8 + 8*x^6 + 24*x^4 + 32*x^2 + 16
>>> L(a).absolute_minpoly()
x^2 + 2
>>> L(b).absolute_charpoly()
x^8 + 4000*x^7 + 6000004*x^6 + 4000012000*x^5 + 1000012000006*x^4
+ 4000012000*x^3 + 6000004*x^2 + 4000*x + 1
>>> L(b).absolute_minpoly()
x^2 + 1000*x + 1

charpoly(var='x')[source]#

The characteristic polynomial of this element over its base field.

EXAMPLES:

sage: x = ZZ['x'].0
sage: K.<a, b> = QQ.extension([x^2 + 2, x^5 + 400*x^4 + 11*x^2 + 2])
sage: a.charpoly()
x^2 + 2
sage: b.charpoly()
x^2 - 2*b*x + b^2
sage: b.minpoly()
x - b

sage: K.<a, b> = NumberField([x^2 + 2, x^2 + 1000*x + 1])
sage: y = K['y'].0
sage: L.<c> = K.extension(y^2 + a*y + b)
sage: c.charpoly()
x^2 + a*x + b
sage: c.minpoly()
x^2 + a*x + b
sage: L(a).charpoly()
x^2 - 2*a*x - 2
sage: L(a).minpoly()
x - a
sage: L(b).charpoly()
x^2 - 2*b*x - 1000*b - 1
sage: L(b).minpoly()
x - b

>>> from sage.all import *
>>> x = ZZ['x'].gen(0)
>>> K = QQ.extension([x**Integer(2) + Integer(2), x**Integer(5) + Integer(400)*x**Integer(4) + Integer(11)*x**Integer(2) + Integer(2)], names=('a', 'b',)); (a, b,) = K._first_ngens(2)
>>> a.charpoly()
x^2 + 2
>>> b.charpoly()
x^2 - 2*b*x + b^2
>>> b.minpoly()
x - b

>>> K = NumberField([x**Integer(2) + Integer(2), x**Integer(2) + Integer(1000)*x + Integer(1)], names=('a', 'b',)); (a, b,) = K._first_ngens(2)
>>> y = K['y'].gen(0)
>>> L = K.extension(y**Integer(2) + a*y + b, names=('c',)); (c,) = L._first_ngens(1)
>>> c.charpoly()
x^2 + a*x + b
>>> c.minpoly()
x^2 + a*x + b
>>> L(a).charpoly()
x^2 - 2*a*x - 2
>>> L(a).minpoly()
x - a
>>> L(b).charpoly()
x^2 - 2*b*x - 1000*b - 1
>>> L(b).minpoly()
x - b

lift(var='x')[source]#

Return an element of $$K[x]$$, where this number field element lives in the relative number field $$K[x]/(f(x))$$.

EXAMPLES:

sage: K.<a> = QuadraticField(-3)
sage: x = polygen(K)
sage: L.<b> = K.extension(x^7 + 5)
sage: u = L(1/2*a + 1/2 + b + (a-9)*b^5)
sage: u.lift()
(a - 9)*x^5 + x + 1/2*a + 1/2

>>> from sage.all import *
>>> K = QuadraticField(-Integer(3), names=('a',)); (a,) = K._first_ngens(1)
>>> x = polygen(K)
>>> L = K.extension(x**Integer(7) + Integer(5), names=('b',)); (b,) = L._first_ngens(1)
>>> u = L(Integer(1)/Integer(2)*a + Integer(1)/Integer(2) + b + (a-Integer(9))*b**Integer(5))
>>> u.lift()
(a - 9)*x^5 + x + 1/2*a + 1/2

list()[source]#

Return the list of coefficients of self written in terms of a power basis.

EXAMPLES:

sage: x = polygen(ZZ, 'x')
sage: K.<a,b> = NumberField([x^3 + 2, x^2 + 1])
sage: a.list()
[0, 1, 0]
sage: v = (K.base_field().0 + a)^2; v
a^2 + 2*b*a - 1
sage: v.list()
[-1, 2*b, 1]

>>> from sage.all import *
>>> x = polygen(ZZ, 'x')
>>> K = NumberField([x**Integer(3) + Integer(2), x**Integer(2) + Integer(1)], names=('a', 'b',)); (a, b,) = K._first_ngens(2)
>>> a.list()
[0, 1, 0]
>>> v = (K.base_field().gen(0) + a)**Integer(2); v
a^2 + 2*b*a - 1
>>> v.list()
[-1, 2*b, 1]

valuation(P)[source]#

Return the valuation of self at a given prime ideal $$P$$.

INPUT:

• P – a prime ideal of relative number field which is the parent of self

EXAMPLES:

sage: x = polygen(ZZ, 'x')
sage: K.<a, b, c> = NumberField([x^2 - 2, x^2 - 3, x^2 - 5])
sage: P = K.prime_factors(5)[1]
sage: (2*a + b - c).valuation(P)
1

>>> from sage.all import *
>>> x = polygen(ZZ, 'x')
>>> K = NumberField([x**Integer(2) - Integer(2), x**Integer(2) - Integer(3), x**Integer(2) - Integer(5)], names=('a', 'b', 'c',)); (a, b, c,) = K._first_ngens(3)
>>> P = K.prime_factors(Integer(5))[Integer(1)]
>>> (Integer(2)*a + b - c).valuation(P)
1

class sage.rings.number_field.number_field_element.OrderElement_absolute[source]#

Element of an order in an absolute number field.

EXAMPLES:

sage: x = polygen(ZZ, 'x')
sage: K.<a> = NumberField(x^2 + 1)
sage: O2 = K.order(2*a)
sage: w = O2.1; w
2*a
sage: parent(w)
Order of conductor 2 generated by 2*a in Number Field in a with defining polynomial x^2 + 1

sage: w.absolute_charpoly()
x^2 + 4
sage: w.absolute_charpoly().parent()
Univariate Polynomial Ring in x over Integer Ring
sage: w.absolute_minpoly()
x^2 + 4
sage: w.absolute_minpoly().parent()
Univariate Polynomial Ring in x over Integer Ring

>>> from sage.all import *
>>> x = polygen(ZZ, 'x')
>>> K = NumberField(x**Integer(2) + Integer(1), names=('a',)); (a,) = K._first_ngens(1)
>>> O2 = K.order(Integer(2)*a)
>>> w = O2.gen(1); w
2*a
>>> parent(w)
Order of conductor 2 generated by 2*a in Number Field in a with defining polynomial x^2 + 1

>>> w.absolute_charpoly()
x^2 + 4
>>> w.absolute_charpoly().parent()
Univariate Polynomial Ring in x over Integer Ring
>>> w.absolute_minpoly()
x^2 + 4
>>> w.absolute_minpoly().parent()
Univariate Polynomial Ring in x over Integer Ring

inverse_mod(I)[source]#

Return an inverse of self modulo the given ideal.

INPUT:

• I – may be an ideal of self.parent(), or an element or list of elements of self.parent() generating a nonzero ideal. A ValueError is raised if $$I$$ is non-integral or is zero. A ZeroDivisionError is raised if $$I + (x) \neq (1)$$.

EXAMPLES:

sage: x = polygen(ZZ, 'x')
sage: OE.<w> = EquationOrder(x^3 - x + 2)
sage: w.inverse_mod(13)
6*w^2 - 6
sage: w * (w.inverse_mod(13)) - 1 in 13*OE.number_field()
True
sage: w.inverse_mod(13).parent() == OE
True
sage: w.inverse_mod(2)
Traceback (most recent call last):
...
ZeroDivisionError: w is not invertible modulo Fractional ideal (2)

>>> from sage.all import *
>>> x = polygen(ZZ, 'x')
>>> OE = EquationOrder(x**Integer(3) - x + Integer(2), names=('w',)); (w,) = OE._first_ngens(1)
>>> w.inverse_mod(Integer(13))
6*w^2 - 6
>>> w * (w.inverse_mod(Integer(13))) - Integer(1) in Integer(13)*OE.number_field()
True
>>> w.inverse_mod(Integer(13)).parent() == OE
True
>>> w.inverse_mod(Integer(2))
Traceback (most recent call last):
...
ZeroDivisionError: w is not invertible modulo Fractional ideal (2)

class sage.rings.number_field.number_field_element.OrderElement_relative[source]#

Element of an order in a relative number field.

EXAMPLES:

sage: x = polygen(ZZ, 'x')
sage: O = EquationOrder([x^2 + x + 1, x^3 - 2], 'a,b')
sage: c = O.1; c
(-2*b^2 - 2)*a - 2*b^2 - b
sage: type(c)
<class 'sage.rings.number_field.number_field_element.OrderElement_relative'>

>>> from sage.all import *
>>> x = polygen(ZZ, 'x')
>>> O = EquationOrder([x**Integer(2) + x + Integer(1), x**Integer(3) - Integer(2)], 'a,b')
>>> c = O.gen(1); c
(-2*b^2 - 2)*a - 2*b^2 - b
>>> type(c)
<class 'sage.rings.number_field.number_field_element.OrderElement_relative'>

absolute_charpoly(var='x')[source]#

The absolute characteristic polynomial of this order element over $$\ZZ$$.

EXAMPLES:

sage: x = ZZ['x'].0
sage: K.<a,b> = NumberField([x^2 + 1, x^2 - 3])
sage: OK = K.maximal_order()
sage: _, u, _, v = OK.basis()
sage: t = 2*u - v; t
-b
sage: t.absolute_charpoly()
x^4 - 6*x^2 + 9
sage: t.absolute_minpoly()
x^2 - 3
sage: t.absolute_charpoly().parent()
Univariate Polynomial Ring in x over Integer Ring

>>> from sage.all import *
>>> x = ZZ['x'].gen(0)
>>> K = NumberField([x**Integer(2) + Integer(1), x**Integer(2) - Integer(3)], names=('a', 'b',)); (a, b,) = K._first_ngens(2)
>>> OK = K.maximal_order()
>>> _, u, _, v = OK.basis()
>>> t = Integer(2)*u - v; t
-b
>>> t.absolute_charpoly()
x^4 - 6*x^2 + 9
>>> t.absolute_minpoly()
x^2 - 3
>>> t.absolute_charpoly().parent()
Univariate Polynomial Ring in x over Integer Ring

absolute_minpoly(var='x')[source]#

The absolute minimal polynomial of this order element over $$\ZZ$$.

EXAMPLES:

sage: x = ZZ['x'].0
sage: K.<a,b> = NumberField([x^2 + 1, x^2 - 3])
sage: OK = K.maximal_order()
sage: _, u, _, v = OK.basis()
sage: t = 2*u - v; t
-b
sage: t.absolute_charpoly()
x^4 - 6*x^2 + 9
sage: t.absolute_minpoly()
x^2 - 3
sage: t.absolute_minpoly().parent()
Univariate Polynomial Ring in x over Integer Ring

>>> from sage.all import *
>>> x = ZZ['x'].gen(0)
>>> K = NumberField([x**Integer(2) + Integer(1), x**Integer(2) - Integer(3)], names=('a', 'b',)); (a, b,) = K._first_ngens(2)
>>> OK = K.maximal_order()
>>> _, u, _, v = OK.basis()
>>> t = Integer(2)*u - v; t
-b
>>> t.absolute_charpoly()
x^4 - 6*x^2 + 9
>>> t.absolute_minpoly()
x^2 - 3
>>> t.absolute_minpoly().parent()
Univariate Polynomial Ring in x over Integer Ring

charpoly(var='x')[source]#

The characteristic polynomial of this order element over its base ring.

This special implementation works around Issue #4738. At this time the base ring of relative order elements is $$\ZZ$$; it should be the ring of integers of the base field.

EXAMPLES:

sage: x = ZZ['x'].0
sage: K.<a,b> = NumberField([x^2 + 1, x^2 - 3])
sage: OK = K.maximal_order(); OK.basis()
[1, 1/2*a - 1/2*b, -1/2*b*a + 1/2, a]
sage: charpoly(OK.1)
x^2 + b*x + 1
sage: charpoly(OK.1).parent()
Univariate Polynomial Ring in x over Maximal Order generated by b
in Number Field in b with defining polynomial x^2 - 3
sage: [ charpoly(t) for t in OK.basis() ]
[x^2 - 2*x + 1, x^2 + b*x + 1, x^2 - x + 1, x^2 + 1]

>>> from sage.all import *
>>> x = ZZ['x'].gen(0)
>>> K = NumberField([x**Integer(2) + Integer(1), x**Integer(2) - Integer(3)], names=('a', 'b',)); (a, b,) = K._first_ngens(2)
>>> OK = K.maximal_order(); OK.basis()
[1, 1/2*a - 1/2*b, -1/2*b*a + 1/2, a]
>>> charpoly(OK.gen(1))
x^2 + b*x + 1
>>> charpoly(OK.gen(1)).parent()
Univariate Polynomial Ring in x over Maximal Order generated by b
in Number Field in b with defining polynomial x^2 - 3
>>> [ charpoly(t) for t in OK.basis() ]
[x^2 - 2*x + 1, x^2 + b*x + 1, x^2 - x + 1, x^2 + 1]

inverse_mod(I)[source]#

Return an inverse of self modulo the given ideal.

INPUT:

• I – may be an ideal of self.parent(), or an element or list of elements of self.parent() generating a nonzero ideal. A ValueError is raised if $$I$$ is non-integral or is zero. A ZeroDivisionError is raised if $$I + (x) \neq (1)$$.

EXAMPLES:

sage: x = polygen(ZZ, 'x')
sage: E.<a,b> = NumberField([x^2 - x + 2, x^2 + 1])
sage: OE = E.ring_of_integers()
sage: t = OE(b - a).inverse_mod(17*b)
sage: t*(b - a) - 1 in E.ideal(17*b)
True
sage: t.parent() == OE
True

>>> from sage.all import *
>>> x = polygen(ZZ, 'x')
>>> E = NumberField([x**Integer(2) - x + Integer(2), x**Integer(2) + Integer(1)], names=('a', 'b',)); (a, b,) = E._first_ngens(2)
>>> OE = E.ring_of_integers()
>>> t = OE(b - a).inverse_mod(Integer(17)*b)
>>> t*(b - a) - Integer(1) in E.ideal(Integer(17)*b)
True
>>> t.parent() == OE
True

minpoly(var='x')[source]#

The minimal polynomial of this order element over its base ring.

This special implementation works around Issue #4738. At this time the base ring of relative order elements is $$\ZZ$$; it should be the ring of integers of the base field.

EXAMPLES:

sage: x = ZZ['x'].0
sage: K.<a,b> = NumberField([x^2 + 1, x^2 - 3])
sage: OK = K.maximal_order(); OK.basis()
[1, 1/2*a - 1/2*b, -1/2*b*a + 1/2, a]
sage: minpoly(OK.1)
x^2 + b*x + 1
sage: charpoly(OK.1).parent()
Univariate Polynomial Ring in x over Maximal Order generated by b
in Number Field in b with defining polynomial x^2 - 3
sage: _, u, _, v = OK.basis()
sage: t = 2*u - v; t
-b
sage: t.charpoly()
x^2 + 2*b*x + 3
sage: t.minpoly()
x + b

sage: t.absolute_charpoly()
x^4 - 6*x^2 + 9
sage: t.absolute_minpoly()
x^2 - 3

>>> from sage.all import *
>>> x = ZZ['x'].gen(0)
>>> K = NumberField([x**Integer(2) + Integer(1), x**Integer(2) - Integer(3)], names=('a', 'b',)); (a, b,) = K._first_ngens(2)
>>> OK = K.maximal_order(); OK.basis()
[1, 1/2*a - 1/2*b, -1/2*b*a + 1/2, a]
>>> minpoly(OK.gen(1))
x^2 + b*x + 1
>>> charpoly(OK.gen(1)).parent()
Univariate Polynomial Ring in x over Maximal Order generated by b
in Number Field in b with defining polynomial x^2 - 3
>>> _, u, _, v = OK.basis()
>>> t = Integer(2)*u - v; t
-b
>>> t.charpoly()
x^2 + 2*b*x + 3
>>> t.minpoly()
x + b

>>> t.absolute_charpoly()
x^4 - 6*x^2 + 9
>>> t.absolute_minpoly()
x^2 - 3

sage.rings.number_field.number_field_element.is_NumberFieldElement(x)[source]#

Return True if $$x$$ is of type NumberFieldElement, i.e., an element of a number field.

EXAMPLES:

sage: from sage.rings.number_field.number_field_element import is_NumberFieldElement
sage: is_NumberFieldElement(2)
doctest:warning...
DeprecationWarning: is_NumberFieldElement is deprecated;
See https://github.com/sagemath/sage/issues/34931 for details.
False
sage: x = polygen(ZZ, 'x')
sage: k.<a> = NumberField(x^7 + 17*x + 1)
sage: is_NumberFieldElement(a+1)
True

>>> from sage.all import *
>>> from sage.rings.number_field.number_field_element import is_NumberFieldElement
>>> is_NumberFieldElement(Integer(2))
doctest:warning...
DeprecationWarning: is_NumberFieldElement is deprecated;