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.
class sage.rings.number_field.number_field_element.CoordinateFunction
__call__()
__init__()
__repr__()
alpha()
class sage.rings.number_field.number_field_element.NumberFieldElement

An element of a number field.

EXAMPLES:

sage: k.<a> = NumberField(x^3 + x + 1)
sage: a^3
-a - 1
__abs__()

Return the numerical absolute value of this number field element with respect to the first archimedean embedding, to double precision.

This is the abs( ) Python function. If you want a different embedding or precision, use self.abs(...).

EXAMPLES:

sage: k.<a> = NumberField(x^3 - 2)
sage: abs(a)
1.25992104989
sage: abs(a)^3
2.0
sage: a.abs(prec=128)
1.2599210498948731647672106072782283506
__copy__()
__eq__()
x.__eq__(y) <==> x==y
__floordiv__()

Return the quotient of self and other. Since these are field elements the floor division is exactly the same as usual division.

EXAMPLES:

sage: m.<b> = NumberField(x^4 + x^2 + 2/3)
sage: c = (1+b) // (1-b); c
3/4*b^3 + 3/4*b^2 + 3/2*b + 1/2
sage: (1+b) / (1-b) == c
True
sage: c * (1-b)
b + 1
__ge__()
x.__ge__(y) <==> x>=y
__getitem__()

Return the n-th coefficient of this number field element, written as a polynomial in the generator.

Note that n must be between 0 and d-1, where d is the degree of the number field.

EXAMPLES:

sage: m.<b> = NumberField(x^4 - 1789)
sage: c = (2/3-4/5*b)^3; c
-64/125*b^3 + 32/25*b^2 - 16/15*b + 8/27
sage: c[0]
8/27
sage: c[2]
32/25
sage: c[3]
-64/125

We illustrate bounds checking:

sage: c[-1]
...
IndexError: index must be between 0 and degree minus 1.
sage: c[4]
...
IndexError: index must be between 0 and degree minus 1.

The list method implicitly calls __getitem__:

sage: list(c)
[8/27, -16/15, 32/25, -64/125]
sage: m(list(c)) == c
True
__gt__()
x.__gt__(y) <==> x>y
__hash__()
x.__hash__() <==> hash(x)
__init__()
x.__init__(...) initializes x; see x.__class__.__doc__ for signature
__int__()

Attempt to convert this number field element to a Python integer, if possible.

EXAMPLES:

sage: C.<I>=CyclotomicField(4)
sage: int(1/I)
...
TypeError: cannot coerce nonconstant polynomial to int
sage: int(I*I)
-1
sage: K.<a> = NumberField(x^10 - x - 1)
sage: int(a)
...
TypeError: cannot coerce nonconstant polynomial to int
sage: int(K(9390283))
9390283

The semantics are like in Python, so the value does not have to preserved.

sage: int(K(393/29))
13
__invert__()

Returns the multiplicative inverse of self in the number field.

EXAMPLES:

sage: C.<I>=CyclotomicField(4)
sage: ~I
-I
sage: (2*I).__invert__()
-1/2*I
__le__()
x.__le__(y) <==> x<=y
__long__()

Attempt to convert this number field element to a Python long, if possible.

EXAMPLES:

sage: K.<a> = NumberField(x^10 - x - 1)
sage: long(a)
...
TypeError: cannot coerce nonconstant polynomial to long
sage: long(K(1234))
1234L

The value does not have to be preserved, in the case of fractions.

sage: long(K(393/29))
13L
__lt__()
x.__lt__(y) <==> x<y
__ne__()
x.__ne__(y) <==> x!=y
static __new__()
T.__new__(S, ...) -> a new object with type S, a subtype of T
__nonzero__()
x.__nonzero__() <==> x != 0
__pow__()
x.__pow__(y[, z]) <==> pow(x, y[, z])
__reduce__()

Used in pickling number field elements.

EXAMPLES:

sage: k.<a> = NumberField(x^3 - 17*x^2 + 1)
sage: t = a.__reduce__(); t
(<built-in function __create__NumberFieldElement_version1>, (Number Field in a with defining polynomial x^3 - 17*x^2 + 1, <type 'sage.rings.number_field.number_field_element.NumberFieldElement_absolute'>, x))
sage: t[0](*t[1]) == a
True
__repr__()

String representation of this number field element, which is just a polynomial in the generator.

EXAMPLES:

sage: k.<a> = NumberField(x^2 + 2)
sage: b = (2/3)*a + 3/5
sage: b.__repr__()
'2/3*a + 3/5'
__rfloordiv__()
x.__rfloordiv__(y) <==> y//x
__rpow__()
y.__rpow__(x[, z]) <==> pow(x, y[, z])
_add_()
_coefficients()

Return the coefficients of the underlying polynomial corresponding to this number field element.

OUTPUT:

  • a list whose length corresponding to the degree of this element written in terms of a generator.

EXAMPLES:

_complex_double_()

EXAMPLES:

sage: k.<a> = NumberField(x^2 + 1)
sage: abs(CDF(a))
1.0
_div_()

Returns the quotient of self and other as elements of a number field.

EXAMPLES:

sage: C.<I>=CyclotomicField(4)
sage: 1/I
-I
sage: I/0
...
ZeroDivisionError: rational division by zero
sage: G.<a> = NumberField(x^3 + 2/3*x + 1)
sage: a/a
1
sage: 1/a
-a^2 - 2/3
sage: a/0
...
ZeroDivisionError: Number field element division by zero
_gap_init_()

Return gap string representation of self.

EXAMPLES:

sage: F=CyclotomicField(8)
sage: p=F.gen()^2+2*F.gen()-3
sage: p
zeta8^2 + 2*zeta8 - 3
sage: p._gap_init_() # The variable name $sage2 belongs to the gap(F) and is somehow random
'GeneratorsOfField($sage2)[1]^2 + 2*GeneratorsOfField($sage2)[1] - 3'
sage: gap(p._gap_init_())
(-3+2*zeta8+zeta8^2)
_im_gens_()

This is used in computing homomorphisms between number fields.

EXAMPLES:

sage: k.<a> = NumberField(x^2 - 2)
sage: m.<b> = NumberField(x^4 - 2)
sage: phi = k.hom([b^2])
sage: phi(a+1)
b^2 + 1
sage: (a+1)._im_gens_(m, [b^2])
b^2 + 1
_integer_()

Returns an integer if this element is actually an integer.

EXAMPLES:

sage: C.<I>=CyclotomicField(4)
sage: (~I)._integer_()
...
TypeError: Unable to coerce -I to an integer
sage: (2*I*I)._integer_()
-2
_latex_()

Returns the latex representation for this element.

EXAMPLES:

sage: C,zeta12=CyclotomicField(12).objgen()
sage: latex(zeta12^4-zeta12)
\zeta_{12}^{2} - \zeta_{12} - 1
_lift_cyclotomic_element()

Creates an element of the passed field from this field. This is specific to creating elements in a cyclotomic field from elements in another cyclotomic field, in the case that self.number_field()._n() divides new_parent()._n(). This function aims to make this common coercion extremely fast!

More general coercion (i.e. of zeta6 into CyclotomicField(3)) is implemented in the _coerce_from_other_cyclotomic_field method of a CyclotomicField.

EXAMPLES:

sage: C.<zeta5>=CyclotomicField(5)
sage: CyclotomicField(10)(zeta5+1)  # The function _lift_cyclotomic_element does the heavy lifting in the background
zeta10^2 + 1
sage: (zeta5+1)._lift_cyclotomic_element(CyclotomicField(10))  # There is rarely a purpose to call this function directly
zeta10^2 + 1
sage: cf4 = CyclotomicField(4)
sage: cf1 = CyclotomicField(1) ; one = cf1.0
sage: cf4(one)
1
sage: type(cf4(1))
<type 'sage.rings.number_field.number_field_element_quadratic.NumberFieldElement_quadratic'>
sage: cf33 = CyclotomicField(33) ; z33 = cf33.0
sage: cf66 = CyclotomicField(66) ; z66 = cf66.0
sage: z33._lift_cyclotomic_element(cf66)
zeta66^2
sage: z66._lift_cyclotomic_element(cf33)
...
TypeError: The zeta_order of the new field must be a multiple of the zeta_order of the original.
sage: cf33(z66)
-zeta33^17

AUTHORS:

  • Joel B. Mohler
  • Craig Citro (fixed behavior for different representation of quadratic field elements)
_matrix_over_base()

Return the matrix of self over the base field L.

EXAMPLES:

sage: K.<a> = NumberField(ZZ['x'].0^3-2, 'a')
sage: L.<b> = K.extension(ZZ['x'].0^2+3, 'b')
sage: L(a)._matrix_over_base(K) == L(a).matrix()
True
_matrix_over_base_morphism()

Return the matrix of self over a specified base, where phi gives a map from the specified base to self.parent().

EXAMPLES:

sage: F.<alpha> = NumberField(ZZ['x'].0^5-2)
sage: h = Hom(QQ,F)([1])
sage: alpha._matrix_over_base_morphism(h) == alpha.matrix()
True
sage: alpha._matrix_over_base_morphism(h) == alpha.matrix(QQ)
True
_mul_()

Returns the product of self and other as elements of a number field.

EXAMPLES:

sage: C.<zeta12>=CyclotomicField(12)
sage: zeta12*zeta12^11
1
sage: G.<a> = NumberField(x^3 + 2/3*x + 1)
sage: a^3
-2/3*a - 1
sage: a^3+a
1/3*a - 1
_neg_()
_number_field()
_pari_()
_pari_init_()

Return GP/PARI string representation of self. This is used for converting this number field element to GP/PARI. The returned string defines a pari Mod in the variable is var, which is by default ‘x’ - not the name of the generator of the number field.

INPUT:

  • var - (default: ‘x’) the variable of the pari Mod.

EXAMPLES:

sage: K.<a> = NumberField(x^5 - x - 1)
sage: ((1 + 1/3*a)^4)._pari_init_()
'Mod(1/81*x^4 + 4/27*x^3 + 2/3*x^2 + 4/3*x + 1, x^5 - x - 1)'
sage: ((1 + 1/3*a)^4)._pari_init_('a')
'Mod(1/81*a^4 + 4/27*a^3 + 2/3*a^2 + 4/3*a + 1, a^5 - a - 1)'

Note that _pari_init_ can fail because of reserved words in PARI, and since it actually works by obtaining the PARI representation of something.

sage: K.<theta> = NumberField(x^5 - x - 1)
sage: b = (1/2 - 2/3*theta)^3; b
-8/27*theta^3 + 2/3*theta^2 - 1/2*theta + 1/8
sage: b._pari_init_('theta')
...
PariError: unexpected character (2)

Fortunately pari_init returns everything in terms of x by default.

sage: pari(b)
Mod(-8/27*x^3 + 2/3*x^2 - 1/2*x + 1/8, x^5 - x - 1)
_rational_()

Returns a rational number if this element is actually a rational number.

EXAMPLES:

sage: C.<I>=CyclotomicField(4)
sage: (~I)._rational_()
...
TypeError: Unable to coerce -I to a rational
sage: (I*I/2)._rational_()
-1/2
_set_multiplicative_order()

Set the multiplicative order of this number field element.

Warning

Use with caution - only for internal use! End users should never call this unless they have a very good reason to do so.

EXAMPLES:

sage: K.<a> = NumberField(x^2 + x + 1)
sage: a._set_multiplicative_order(3)
sage: a.multiplicative_order()
3

You can be evil with this so be careful. That’s why the function name begins with an underscore.

sage: a._set_multiplicative_order(389)
sage: a.multiplicative_order()
389
_sub_()
_symbolic_()

If an embedding into CC is specified, then a representation of this element can be made in the symbolic ring (assuming roots of the minimal polynomial can be found symbolically).

EXAMPLES:

sage: K.<a> = QuadraticField(2)
sage: SR(a)
sqrt(2)
sage: SR(3*a-5)
3*sqrt(2) - 5
sage: K.<a> = QuadraticField(2, embedding=-1.4)
sage: SR(a)
-sqrt(2)
sage: K.<a> = NumberField(x^2 - 2)
sage: SR(a)
...
TypeError: An embedding into RR or CC must be specified.

Now a more complicated example:

sage: K.<a> = NumberField(x^3 + x - 1, embedding=0.68)
sage: b = SR(a); b
(1/18*sqrt(3)*sqrt(31) + 1/2)^(1/3) - 1/3/(1/18*sqrt(3)*sqrt(31) + 1/2)^(1/3)

sage: (b^3 + b - 1).simplify_radical()
0

Make sure we got the right one:

sage: CC(a)
0.682327803828019
sage: CC(b)
0.682327803828019

Special case for cyclotomic fields:

sage: K.<zeta> = CyclotomicField(19)
sage: SR(zeta)
e^(2/19*I*pi)
sage: CC(zeta)
0.945817241700635 + 0.324699469204683*I
sage: CC(SR(zeta))
0.945817241700635 + 0.324699469204683*I

sage: SR(zeta^5 + 2)
e^(10/19*I*pi) + 2

For degree greater than 5, sometimes Galois theory prevents a closed-form solution. In this case, a numerical approximation is used:

sage: K.<a> = NumberField(x^5-x+1, embedding=-1)
sage: SR(a)
-1.1673040153
sage: K.<a> = NumberField(x^6-x^3-1, embedding=1)
sage: SR(a)
1/2*(sqrt(5) + 1)^(1/3)*2^(2/3)
abs()

Return the absolute value of this element with respect to the i-th complex embedding of parent, to the given precision.

If prec is 53 (the default), then the complex double field is used; otherwise the arbitrary precision (but slow) complex field is used.

INPUT:

  • prec - (default: 53) integer bits of precision
  • i - (default: ) integer, which embedding to use

EXAMPLES:

sage: z = CyclotomicField(7).gen()
sage: abs(z)
1.0
sage: abs(z^2 + 17*z - 3)
16.06044268
sage: K.<a> = NumberField(x^3+17)
sage: abs(a)
2.57128159066
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.414213562373
sage: a.abs(i=1)
2.41421356237
abs_non_arch()

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]
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
charpoly()
complex_embedding()

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.629960524947 - 1.09112363597*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()

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.629960524947 - 1.09112363597*I, -0.629960524947 + 1.09112363597*I, 1.25992104989]
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. Currently, this is implemented for cyclotomic fields and quadratic extensions of Q. It seems likely that there are other number fields for which the idea of a conjugate would be easy to compute.

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
sage: K.<j,b> = QQ[sqrt(-1), sqrt(2)]
sage: j.conjugate()
...
NotImplementedError: complex conjugation is not implemented (or doesn't make sense).
sage: K.<b> = NumberField(x^3 - 2)
sage: b.conjugate()
...
NotImplementedError: complex conjugation is not implemented (or doesn't make sense).
coordinates_in_terms_of_powers()

Let \alpha be self. Return a Python function 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)
...
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: print a.denominator()
15
denominator_ideal()

Return the denominator ideal of this number field element.

Note

A ValueError will be raised if this function is called on 0.

Note

See also numerator_ideal()

OUTPUT:

(integral ideal) The denominator ideal D of this element, where for a non-zero number field element a, the principal ideal generated by a has the form N/D where N and D are coprime integral ideals. An error is raised if the element is zero.

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)

TESTS:

Undefined for 0:

sage: K(0).denominator_ideal()
...
ValueError: denominator ideal of 0 is not defined.
galois_conjugates()

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/84*a1^4 + 13/42*a1, -1/252*a1^4 - 55/126*a1, -1/126*a1^4 + 8/63*a1]
sage: c[0]^3
2
sage: parent(c[0])
Number Field in a1 with defining polynomial x^6 + 40*x^3 + 1372
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]
global_height()

Returns the absolute logarithmic height of this number field element.

INPUT:

  • prec (int) – desired floating point precision (defult: 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, with the contributions from the 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()
2.869222240687...
sage: b.global_height(prec=200)
2.8692222406879748488543678846959454765968722137813736080066

The global height of an algebraic number is absolute, i.e. it does not depend on th 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
global_height_arch()

Returns the total archimedean component of the height of self.

INPUT:

  • prec (int) – desired floating point precision (defult: 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()

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

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
list()
Return the list of coefficients of self written in terms of a power basis.
local_height()

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

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

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.

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

TESTS:

sage: F.<z> = CyclotomicField(5) ; t = 3*z**3 + 4*z**2 + 2
sage: t.matrix(F)
[3*z^3 + 4*z^2 + 2]
minpoly()

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

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

TESTS:

sage: F.<z> = CyclotomicField(5)
sage: t = 3*z**3 + 4*z**2 + 2
sage: t.norm(F)
3*z^3 + 4*z^2 + 2
nth_root()

Return an nth root of self in the given number field.

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.

Note

A ValueError will be raised if this function is called on 0.

Note

See also denominator_ideal()

OUTPUT:

(integral ideal) The numerator ideal N of this element, where for a non-zero number field element a, the principal ideal generated by a has the form N/D where N and D are coprime integral ideals. An error is raised if the element is zero.

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)

TESTS:

Undefined for 0:

sage: K(0).numerator_ideal()
...
ValueError: numerator ideal of 0 is not defined.
polynomial()

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

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

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

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]

TESTS:

It doesn’t make sense to factor the ideal (0):

sage: F(0).support()
...
ArithmeticError: Support of 0 is not defined.
trace()

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

TESTS:

sage: F.<z> = CyclotomicField(5) ; t = 3*z**3 + 4*z**2 + 2
sage: t.trace(F)
3*z^3 + 4*z^2 + 2
valuation()

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

INPUT:

  • P - a prime ideal of the parent of self

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: 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
static __new__()
T.__new__(S, ...) -> a new object with type S, a subtype of T
_magma_init_()

Return Magma version of this number field element.

INPUT:

  • magma - a Magma interpreter

OUTPUT: MagmaElement that has parent the Magma object corresponding to the parent number field.

EXAMPLES:

sage: K.<a> = NumberField(x^3 + 2)
sage: a._magma_init_(magma)            # optional - magma
'(_sage_[...]![0, 1, 0])'            
sage: magma((2/3)*a^2 - 17/3)          # optional - magma
1/3*(2*a^2 - 17)

An element of a cyclotomic field.

sage: K = CyclotomicField(9)
sage: K.gen()
zeta9
sage: K.gen()._magma_init_(magma)     # optional - magma
'(_sage_[...]![0, 1, 0, 0, 0, 0])'
sage: magma(K.gen())                  # optional - magma
zeta9
_pari_()

Return PARI C-library object corresponding to self.

EXAMPLES:

sage: k.<j> = QuadraticField(-1)
sage: j._pari_('j')
Mod(j, j^2 + 1)
sage: pari(j)
Mod(x, x^2 + 1)
sage: y = QQ['y'].gen()
sage: k.<j> = NumberField(y^3 - 2)
sage: pari(j)
Mod(x, x^3 - 2)

By default the variable name is ‘x’, since in PARI many variable names are reserved:

sage: theta = polygen(QQ, 'theta')
sage: M.<theta> = NumberField(theta^2 + 1)
sage: pari(theta)
Mod(x, x^2 + 1)

If you try do coerce a generator called I to PARI, hell may break loose:

sage: k.<I> = QuadraticField(-1)
sage: I._pari_('I')
...
PariError: forbidden (45)

Instead, request the variable be named different for the coercion:

sage: pari(I)
Mod(x, x^2 + 1)
sage: I._pari_('i')
Mod(i, i^2 + 1)
sage: I._pari_('II')
Mod(II, II^2 + 1)
absolute_charpoly()

Return the characteristic polynomial of this element over

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

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

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

TESTS:

sage: R = K.ring_of_integers()
sage: R(a).charpoly()
x^3 - 2
sage: R(a).charpoly().parent()
Univariate Polynomial Ring in x over Integer Ring

sage: R(a).charpoly(algorithm='pari') == R(a).charpoly(algorithm='sage')
True
inverse_mod()

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 TypeError is raised if I is non-integral, and a ValueError if the generators are all 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
list()

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

EXAMPLE:

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

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

TESTS:

sage: R = K.ring_of_integers()
sage: R(a).minpoly()
x^3 - 2
sage: R(a).minpoly().parent()
Univariate Polynomial Ring in x over Integer Ring

sage: R(a).minpoly(algorithm='pari') == R(a).minpoly(algorithm='sage')
True
class sage.rings.number_field.number_field_element.NumberFieldElement_relative

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.

__getitem__()

Return the n-th coefficient of this relative number field element, written as a polynomial in the generator.

Note that n must be between 0 and d-1, where d is the relative degree of the number field.

EXAMPLES:

sage: K.<a, b> = NumberField([x^3 - 5, x^2 + 3])
sage: c = (a + b)^3; c
3*b*a^2 - 9*a - 3*b + 5
sage: c[0]
-3*b + 5

We illustrate bounds checking:

sage: c[-1]
...
IndexError: index must be between 0 and the relative degree minus 1.
sage: c[4]
...
IndexError: index must be between 0 and the relative degree minus 1.

The list method implicitly calls __getitem__:

sage: list(c)
[-3*b + 5, -9, 3*b]
sage: K(list(c)) == c
True
__init__()
x.__init__(...) initializes x; see x.__class__.__doc__ for signature
static __new__()
T.__new__(S, ...) -> a new object with type S, a subtype of T
__repr__()
_latex_()

Returns the latex representation for this element.

EXAMPLES:

sage: C.<zeta> = CyclotomicField(12)
sage: PC.<x> = PolynomialRing(C)
sage: K.<alpha> = NumberField(x^2 - 7)
sage: latex((alpha + zeta)^4)
\left(4 \zeta_{12}^{3} + 28 \zeta_{12}\right) \alpha + 43 \zeta_{12}^{2} + 48
sage: PK.<y> = PolynomialRing(K)
sage: L.<beta> = NumberField(y^3 + y + alpha)
sage: latex((beta + zeta)^3)
3 \zeta_{12} \beta^{2} + \left(3 \zeta_{12}^{2} - 1\right) \beta - \alpha + \zeta_{12}^{3}
_pari_()

Return PARI C-library object corresponding to self.

EXAMPLES:

By default the variable name is ‘x’, since in PARI many variable names are reserved.

sage: y = QQ['y'].gen()
sage: k.<j> = NumberField([y^2 - 7, y^3 - 2])
sage: pari(j)
Mod(42/5515*x^5 - 9/11030*x^4 - 196/1103*x^3 + 273/5515*x^2 + 10281/5515*x + 4459/11030, x^6 - 21*x^4 + 4*x^3 + 147*x^2 + 84*x - 339)
sage: j^2
7
sage: pari(j)^2
Mod(7, x^6 - 21*x^4 + 4*x^3 + 147*x^2 + 84*x - 339)
sage: (j^2)._pari_('y')
Mod(7, y^6 - 21*y^4 + 4*y^3 + 147*y^2 + 84*y - 339)

sage: K.<a> = NumberField(x^2 + 2, 'a')
sage: K(1)._pari_()
Mod(1, x^2 + 2)
sage: K(1)._pari_('t')
Mod(1, t^2 + 2)

sage: K.gen()._pari_()
Mod(x, x^2 + 2)
sage: K.gen()._pari_('t')
Mod(t, t^2 + 2)

At this time all elements, even relative elements, are
represented as absolute polynomials:

sage: K.<a> = NumberField(x^2 + 2, 'a')
sage: L.<b> = NumberField(K['x'].0^2 + a, 'b')
sage: L(1)._pari_()
Mod(1, x^4 + 2)
sage: L(1)._pari_('t')
Mod(1, t^4 + 2)
sage: L.gen()._pari_()
Mod(x, x^4 + 2)
sage: L.gen()._pari_('t')
Mod(t, t^4 + 2)

sage: M.<c> = NumberField(L['x'].0^3 + b, 'c')
sage: M(1)._pari_()
Mod(1, x^12 + 2)
sage: M(1)._pari_('t')
Mod(1, t^12 + 2)
sage: M.gen()._pari_()
Mod(x, x^12 + 2)
sage: M.gen()._pari_('t')
Mod(t, t^12 + 2)
absolute_charpoly()

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

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

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

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

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
__init__()
x.__init__(...) initializes x; see x.__class__.__doc__ for signature
__invert__()

Implement inversion, checking that the return value has the right parent. See trac #4190.

EXAMPLE:

sage: K = NumberField(x^3 -x + 2, 'a')
sage: OK = K.ring_of_integers()
sage: a = OK(K.gen())
sage: (~a).parent() is K
True
sage: (~a) in OK
False
sage: a**(-1) in OK
False
static __new__()
T.__new__(S, ...) -> a new object with type S, a subtype of T
_div_()

Implement division, checking that the result has the right parent. It’s not so crucial what the parent actually is, but it is crucial that the returned value really is an element of its supposed parent! This fixes trac #4190.

EXAMPLES:

sage: K = NumberField(x^3 - 17, 'a')
sage: OK = K.ring_of_integers()
sage: a = OK(K.gen())
sage: (17/a) in OK
True
sage: (17/a).parent() is K
True
sage: (17/(2*a)).parent() is K
True
sage: (17/(2*a)) in OK
False
inverse_mod()

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 TypeError is raised if I is non-integral, and a ValueError if the generators are all zero. A ZeroDivisionError is raised if I + (x) != (1).

EXAMPLES:

sage: OE = NumberField(x^3 - x + 2, 'w').ring_of_integers()
sage: w = OE.ring_generators()[0]
sage: w.inverse_mod(13*OE)
-7*w^2 - 13*w + 7
sage: w * (w.inverse_mod(13)) - 1 in 13*OE
True
sage: w.inverse_mod(2*OE)
...
ZeroDivisionError: w is not invertible modulo Fractional ideal (2)
class sage.rings.number_field.number_field_element.OrderElement_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'>
__init__()
x.__init__(...) initializes x; see x.__class__.__doc__ for signature
__invert__()

Implement division, checking that the result has the right parent. See trac #4190.

EXAMPLES:

sage: K1.<a> = NumberField(x^3 - 17)
sage: R.<y> = K1[]
sage: K2 = K1.extension(y^2 - a, 'b')
sage: OK2 = K2.order(K2.gen()) # (not maximal)
sage: b = OK2.gens()[1]; b
b
sage: b.parent() is OK2
True
sage: (~b).parent() is K2
True
sage: (~b) in OK2 # not implemented (#4193)
False
sage: b**(-1) in OK2 # not implemented (#4193)
False
static __new__()
T.__new__(S, ...) -> a new object with type S, a subtype of T
_div_()

Implement division, checking that the result has the right parent. It’s not so crucial what the parent actually is, but it is crucial that the returned value really is an element of its supposed parent. This fixes trac #4190.

EXAMPLES:

sage: K1.<a> = NumberField(x^3 - 17)
sage: R.<y> = K1[]
sage: K2 = K1.extension(y^2 - a, 'b')
sage: OK2 = K2.order(K2.gen()) # (not maximal)
sage: b = OK2.gens()[1]; b
b
sage: (17/b).parent() is K2
True
sage: (17/b) in OK2 # not implemented (#4193)
True
sage: (17/b^7) in OK2
False
absolute_charpoly()

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

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

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

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 TypeError is raised if I is non-integral, and a ValueError if the generators are all 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
minpoly()

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

Used in unpickling elements of number fields.

EXAMPLES:

Since this is just used in unpickling, we unpickle.

sage: k.<a> = NumberField(x^3 - 2)
sage: loads(dumps(a+1)) == a + 1
True
sage.rings.number_field.number_field_element.__create__NumberFieldElement_version1()

Used in unpickling elements of number fields.

EXAMPLES:

Since this is just used in unpickling, we unpickle.

sage: k.<a> = NumberField(x^3 - 2)
sage: loads(dumps(a+1)) == a + 1
True

This also gets called for unpickling order elements; we check that #6462 is fixed:

sage: L = NumberField(x^3 - x - 1,'a'); OL = L.maximal_order(); w = OL.0
sage: loads(dumps(w)) == w
True
sage.rings.number_field.number_field_element._inverse_mod_generic()

Return an inverse of elt modulo the given ideal. This is a separate function called from each of the OrderElement_xxx classes, since otherwise we’d have to have the same code three times over (there is no OrderElement_generic class - no multiple inheritance). See trac 4190.

EXAMPLES:

sage: OE = NumberField(x^3 - x + 2, 'w').ring_of_integers()
sage: w = OE.ring_generators()[0]
sage: from sage.rings.number_field.number_field_element import _inverse_mod_generic
sage: _inverse_mod_generic(w, 13*OE)
-7*w^2 - 13*w + 7
sage.rings.number_field.number_field_element.is_NumberFieldElement()

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

Previous topic

Relative Number Fields

Next topic

Optimized Quadratic Number Field Elements

This Page