Number Field Elements

AUTHORS:

  • William Stein: version before it got Cython’d

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

  • William Stein (2007-09-04): add 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)

Bases: object

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

EXAMPLES:

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]
sage: f == loads(dumps(f))
True
alpha()

EXAMPLES:

sage: K.<a> = NumberField(x^3 + 2)
sage: (a + 2).coordinates_in_terms_of_powers().alpha()
a + 2
class sage.rings.number_field.number_field_element.NumberFieldElement

Bases: sage.structure.element.FieldElement

An element of a number field.

EXAMPLES:

sage: k.<a> = NumberField(x^3 + x + 1)
sage: a^3
-a - 1
abs(prec=None, i=None)

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

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

Check that trac ticket #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

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

sage: x = polygen(ZZ)
sage: f = x^3 - x - 1
sage: K.<b> = NumberField(f, embedding=1.3)
sage: 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

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
abs_non_arch(P, prec=None)

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

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]
absolute_different()

Return the absolute different of this element.

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

EXAMPLES:

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

See also

different()

absolute_norm()

Return the absolute norm of this number field element.

EXAMPLES:

sage: K1.<a1> = CyclotomicField(11)
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
additive_order()

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

EXAMPLES:

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

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

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

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
charpoly(var='x')

Return the characteristic polynomial of this number field element.

EXAMPLES:

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
complex_embedding(prec=53, i=0)

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

EXAMPLES:

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
complex_embeddings(prec=53)

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: 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]
conjugate()

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

The following example now works.

sage: F.<b> = NumberField(x^2 - 2)
sage: K.<j> = F.extension(x^2 + 1)
sage: 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.

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

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
coordinates_in_terms_of_powers()

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]

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

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
denominator()

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
denominator_ideal()

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: 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)
descend_mod_power(K='QQ', d=2)

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)
[-3*i - 2, -2*i + 3]

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_element()^2
sage: a.descend_mod_power(QQ,2)
[17, 34, -17, -34]
different(K=None)

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: K.<a> = NumberField(x^3 - 2)
sage: a.different()
3*a^2
sage: 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

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

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
factor()

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: K.<i> = NumberField(x^2+1)
sage: (6*i + 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

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
floor()

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

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

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
galois_conjugates(K)

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: K.<a> = NumberField(x^2 - 2)
sage: a.galois_conjugates(K)
[a, -a]
sage: K(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
[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()
True

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

sage: 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]
gcd(other)

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

Non-maximal orders are not supported:

sage: R = K.order(2*i)
sage: R(1).gcd(R(4*i))
Traceback (most recent call last):
...
NotImplementedError: gcd() for Order in Number Field in i with defining polynomial x^2 + 1 with i = 1*I is not implemented

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

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 in Number Field in a with defining polynomial x^3 - 7
global_height(prec=None)

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

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

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
global_height_arch(prec=None)

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...
global_height_non_arch(prec=None)

Returns 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

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

A relative example:

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

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) != (1).

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

EXAMPLES:

sage: k.<a> = NumberField(x^2 + 23)
sage: N = k.ideal(3)
sage: d = 3*a + 1
sage: 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
is_integer()

Test whether this number field element is an integer

See also

EXAMPLES:

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
is_integral()

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

EXAMPLES:

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

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
is_norm(L, element=False, proof=True)

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

  • element – True 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 False, 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 rnfisnorm. See self._rnfisnorm().

EXAMPLES:

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

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

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

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

Verify that trac ticket #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)
sage: flag
True
sage: c.norm(K)
-7
sage: c in L
True

AUTHORS:

  • Craig Citro (2008-04-05)

  • Marco Streng (2010-12-03)

is_nth_power(n)

Return True if self is an \(n\)’th power in its parent \(K\).

EXAMPLES:

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

ALGORITHM: Use PARI to factor \(x^n\) - self in \(K\).

is_one()

Test whether this number field element is \(1\).

EXAMPLES:

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
is_padic_square(P, check=True)

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: K.<a> = NumberField(x^2 + 2)
sage: p = K.primes_above(2)[0]
sage: K(5).is_padic_square(p)
False
is_rational()

Test whether this number field element is a rational number

See also

EXAMPLES:

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
is_square(root=False)

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

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
is_totally_positive()

Returns 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: F.<b> = NumberField(x^3-3*x-1)
sage: b.is_totally_positive()
False
sage: (b^2).is_totally_positive()
True
is_unit()

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

EXAMPLES:

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

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
list()

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

EXAMPLES:

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]
local_height(P, prec=None, weighted=False)

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

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
local_height_arch(i, prec=None, weighted=False)

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]

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]
matrix(base=None)

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

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

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

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

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

sage: K.<a> = NumberField(x^4 + 1); L.<a2> = NumberField(x^2 + 1)
sage: 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]

The norm is also changed:

sage: a.norm(v[1])
a2
sage: a.norm(v[0])
-a2
minpoly(var='x')

Return the minimal polynomial of this number field element.

EXAMPLES:

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
multiplicative_order()

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

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
norm(K=None)

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

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

We illustrate that norm is compatible with towers:

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

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
nth_root(n, all=False)

Return an \(n\)’th root of self in its parent \(K\).

EXAMPLES:

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

ALGORITHM: Use PARI to factor \(x^n\) - self in \(K\).

numerator_ideal()

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: 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
ord(P)

Returns the valuation of self at a given prime ideal P.

INPUT:

  • P - a prime ideal of the parent of self

Note

The function 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))
<type '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]
polynomial(var='x')

Return the underlying polynomial corresponding to this number field element.

The resulting polynomial is currently not cached.

EXAMPLES:

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

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

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

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
relative_norm()

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: 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
residue_symbol(P, m, check=True)

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: K.<a> = NumberField(x - 1)
sage: K(11).residue_symbol(K.ideal(17),2)
-1
sage: kronecker_symbol(11,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)
1

Cubic Residue:

sage: K.<w> = NumberField(x^2 - x + 1)
sage: (w^2 + 3).residue_symbol(K.ideal(17),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
round()

Return the round (nearest integer) 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.round()
4
sage: (-b).round()
-4
sage: (b+1/2).round()
5
sage: (-b-1/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)

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
sign()

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

EXAMPLES:

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

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
sqrt(all=False, extend=True)

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: 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]
sage: K.<a> = CyclotomicField(7)
sage: 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

Using the extend keyword:

sage: K = QuadraticField(-5)
sage: z = K(-7).sqrt(extend=True); z
sqrt(-7)
sage: CyclotomicField(4)(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

ALGORITHM: Use PARI to factor \(x^2\) - self in \(K\).

support()

Return the support of this number field element.

OUTPUT: A sorted list of the primes 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)
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]
trace(K=None)

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

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
valuation(P)

Returns the valuation of self at a given prime ideal P.

INPUT:

  • P - a prime ideal of the parent of self

Note

The function 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))
<type '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]
vector()

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

EXAMPLES:

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)
class sage.rings.number_field.number_field_element.NumberFieldElement_absolute

Bases: sage.rings.number_field.number_field_element.NumberFieldElement

absolute_charpoly(var='x', algorithm=None)

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
absolute_minpoly(var='x', algorithm=None)

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')
True
charpoly(var='x', algorithm=None)

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 self.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 trac ticket #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
is_real_positive(min_prec=53)

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: K.<a> = QuadraticField(3)
sage: a.is_real_positive()
True
sage: K.<a> = QuadraticField(-3)
sage: a.is_real_positive()
False
sage: (a-a).is_real_positive()
False
lift(var='x')

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
list()

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]
minpoly(var='x', algorithm=None)

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
class sage.rings.number_field.number_field_element.NumberFieldElement_relative

Bases: sage.rings.number_field.number_field_element.NumberFieldElement

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)

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 trac ticket #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')
True
absolute_minpoly(var='x', algorithm=None)

Return the minimal polynomial over \(\QQ\) of this element.

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

EXAMPLES:

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
charpoly(var='x')

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
lift(var='x')

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
list()

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

EXAMPLES:

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]
valuation(P)

Returns 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: K.<a, b, c> = NumberField([x^2 - 2, x^2 - 3, x^2 - 5])
sage: P = K.prime_factors(5)[0]
sage: (2*a + b - c).valuation(P)
1
class sage.rings.number_field.number_field_element.OrderElement_absolute

Bases: sage.rings.number_field.number_field_element.NumberFieldElement_absolute

Element of an order in an absolute number field.

EXAMPLES:

sage: K.<a> = NumberField(x^2 + 1)
sage: O2 = K.order(2*a)
sage: w = O2.1; w
2*a
sage: parent(w)
Order 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
inverse_mod(I)

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) != (1).

EXAMPLES:

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

Bases: sage.rings.number_field.number_field_element.NumberFieldElement_relative

Element of an order in a relative number field.

EXAMPLES:

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)
<type 'sage.rings.number_field.number_field_element.OrderElement_relative'>
absolute_charpoly(var='x')

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
absolute_minpoly(var='x')

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
charpoly(var='x')

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

This special implementation works around bug #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 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]
inverse_mod(I)

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) != (1).

EXAMPLES:

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
minpoly(var='x')

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

This special implementation works around bug #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 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
sage.rings.number_field.number_field_element.is_NumberFieldElement(x)

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)
False
sage: k.<a> = NumberField(x^7 + 17*x + 1)
sage: is_NumberFieldElement(a+1)
True