# Number Fields¶

AUTHORS:

• William Stein (2004, 2005): initial version
• Steven Sivek (2006-05-12): added support for relative extensions
• William Stein (2007-09-04): major rewrite and documentation
• Robert Bradshaw (2008-10): specified embeddings into ambient fields
• Simon King (2010-05): Improve coercion from GAP
• Jeroen Demeyer (2010-07, 2011-04): Upgrade PARI (#9343, #10430, #11130)
• Robert Harron (2012-08): added is_CM(), complex_conjugation(), and maximal_totally_real_subfield()
• Christian Stump (2012-11): added conversion to universal cyclotomic field
• Julian Rueth (2014-04-03): absolute number fields are unique parents

Note

Unlike in PARI/GP, class group computations in Sage do not by default assume the Generalized Riemann Hypothesis. To do class groups computations not provably correctly you must often pass the flag proof=False to functions or call the function proof.number_field(False). It can easily take 1000’s of times longer to do computations with proof=True (the default).

This example follows one in the Magma reference manual:

sage: K.<y> = NumberField(x^4 - 420*x^2 + 40000)
sage: z = y^5/11; z
420/11*y^3 - 40000/11*y
sage: R.<y> = PolynomialRing(K)
sage: f = y^2 + y + 1
sage: L.<a> = K.extension(f); L
Number Field in a with defining polynomial y^2 + y + 1 over its base field
sage: KL.<b> = NumberField([x^4 - 420*x^2 + 40000, x^2 + x + 1]); KL
Number Field in b0 with defining polynomial x^4 - 420*x^2 + 40000 over its base field


We do some arithmetic in a tower of relative number fields:

sage: K.<cuberoot2> = NumberField(x^3 - 2)
sage: L.<cuberoot3> = K.extension(x^3 - 3)
sage: S.<sqrt2> = L.extension(x^2 - 2)
sage: S
Number Field in sqrt2 with defining polynomial x^2 - 2 over its base field
sage: sqrt2 * cuberoot3
cuberoot3*sqrt2
sage: (sqrt2 + cuberoot3)^5
(20*cuberoot3^2 + 15*cuberoot3 + 4)*sqrt2 + 3*cuberoot3^2 + 20*cuberoot3 + 60
sage: cuberoot2 + cuberoot3
cuberoot3 + cuberoot2
sage: cuberoot2 + cuberoot3 + sqrt2
sqrt2 + cuberoot3 + cuberoot2
sage: (cuberoot2 + cuberoot3 + sqrt2)^2
(2*cuberoot3 + 2*cuberoot2)*sqrt2 + cuberoot3^2 + 2*cuberoot2*cuberoot3 + cuberoot2^2 + 2
sage: cuberoot2 + sqrt2
sqrt2 + cuberoot2
sage: a = S(cuberoot2); a
cuberoot2
sage: a.parent()
Number Field in sqrt2 with defining polynomial x^2 - 2 over its base field


Warning

Doing arithmetic in towers of relative fields that depends on canonical coercions is currently VERY SLOW. It is much better to explicitly coerce all elements into a common field, then do arithmetic with them there (which is quite fast).

class sage.rings.number_field.number_field.CyclotomicFieldFactory

Return the $$n$$-th cyclotomic field, where n is a positive integer, or the universal cyclotomic field if n==0.

For the documentation of the universal cyclotomic field, see UniversalCyclotomicField.

INPUT:

• n - a nonnegative integer, default:0
• names - name of generator (optional - defaults to zetan)
• bracket - Defines the brackets in the case of n==0, and is ignored otherwise. Can be any even length string, with "()" being the default.
• embedding - bool or n-th root of unity in an ambient field (default True)

EXAMPLES:

If called without a parameter, we get the universal cyclotomic field:

sage: CyclotomicField()
Universal Cyclotomic Field


We create the $$7$$th cyclotomic field $$\QQ(\zeta_7)$$ with the default generator name.

sage: k = CyclotomicField(7); k
Cyclotomic Field of order 7 and degree 6
sage: k.gen()
zeta7


The default embedding sends the generator to the complex primitive $$n^{th}$$ root of unity of least argument.

sage: CC(k.gen())
0.623489801858734 + 0.781831482468030*I


Cyclotomic fields are of a special type.

sage: type(k)
<class 'sage.rings.number_field.number_field.NumberField_cyclotomic_with_category'>


We can specify a different generator name as follows.

sage: k.<z7> = CyclotomicField(7); k
Cyclotomic Field of order 7 and degree 6
sage: k.gen()
z7


The $$n$$ must be an integer.

sage: CyclotomicField(3/2)
Traceback (most recent call last):
...
TypeError: no conversion of this rational to integer


The degree must be nonnegative.

sage: CyclotomicField(-1)
Traceback (most recent call last):
...
ValueError: n (=-1) must be a positive integer


The special case $$n=1$$ does not return the rational numbers:

sage: CyclotomicField(1)
Cyclotomic Field of order 1 and degree 1


Due to their default embedding into $$\CC$$, cyclotomic number fields are all compatible.

sage: cf30 = CyclotomicField(30)
sage: cf5 = CyclotomicField(5)
sage: cf3 = CyclotomicField(3)
sage: cf30.gen() + cf5.gen() + cf3.gen()
zeta30^6 + zeta30^5 + zeta30 - 1
sage: cf6 = CyclotomicField(6) ; z6 = cf6.0
sage: cf3 = CyclotomicField(3) ; z3 = cf3.0
sage: cf3(z6)
zeta3 + 1
sage: cf6(z3)
zeta6 - 1
sage: cf9 = CyclotomicField(9) ; z9 = cf9.0
sage: cf18 = CyclotomicField(18) ; z18 = cf18.0
sage: cf18(z9)
zeta18^2
sage: cf9(z18)
-zeta9^5
sage: cf18(z3)
zeta18^3 - 1
sage: cf18(z6)
zeta18^3
sage: cf18(z6)**2
zeta18^3 - 1
sage: cf9(z3)
zeta9^3

create_key(n=0, names=None, bracket='()', embedding=True)

Create the unique key for the cyclotomic field specified by the parameters.

TESTS:

sage: CyclotomicField.create_key()
(0, None, True, '()')

create_object(version, key, **extra_args)

Create the unique cyclotomic field defined by key.

TESTS:

sage: CyclotomicField.create_object(None, (0, None, True, '()'))
Universal Cyclotomic Field

sage.rings.number_field.number_field.NumberField(polynomial, name=None, check=True, names=None, embedding=None, latex_name=None, assume_disc_small=False, maximize_at_primes=None, structure=None)

Return the number field (or tower of number fields) defined by the irreducible polynomial.

INPUT:

• polynomial - a polynomial over $$\QQ$$ or a number field, or a list of such polynomials.
• name - a string or a list of strings, the names of the generators
• check - a boolean (default: True); do type checking and irreducibility checking.
• embedding - None, an element, or a list of elements, the images of the generators in an ambient field (default: None)
• latex_name - None, a string, or a list of strings (default: None), how the generators are printed for latex output
• assume_disc_small – a boolean (default: False); if True, assume that no square of a prime greater than PARI’s primelimit (which should be 500000); only applies for absolute fields at present.
• maximize_at_primesNone or a list of primes (default: None); if not None, then the maximal order is computed by maximizing only at the primes in this list, which completely avoids having to factor the discriminant, but of course can lead to wrong results; only applies for absolute fields at present.
• structureNone, a list or an instance of structure.NumberFieldStructure (default: None), internally used to pass in additional structural information, e.g., about the field from which this field is created as a subfield.

EXAMPLES:

sage: z = QQ['z'].0
sage: K = NumberField(z^2 - 2,'s'); K
Number Field in s with defining polynomial z^2 - 2
sage: s = K.0; s
s
sage: s*s
2
sage: s^2
2


Constructing a relative number field:

sage: K.<a> = NumberField(x^2 - 2)
sage: R.<t> = K[]
sage: L.<b> = K.extension(t^3+t+a); L
Number Field in b with defining polynomial t^3 + t + a over its base field
sage: L.absolute_field('c')
Number Field in c with defining polynomial x^6 + 2*x^4 + x^2 - 2
sage: a*b
a*b
sage: L(a)
a
sage: L.lift_to_base(b^3 + b)
-a


Constructing another number field:

sage: k.<i> = NumberField(x^2 + 1)
sage: R.<z> = k[]
sage: m.<j> = NumberField(z^3 + i*z + 3)
sage: m
Number Field in j with defining polynomial z^3 + i*z + 3 over its base field


Number fields are globally unique:

sage: K.<a> = NumberField(x^3 - 5)
sage: a^3
5
sage: L.<a> = NumberField(x^3 - 5)
sage: K is L
True


The variable name of the defining polynomial has no influence on equality of fields:

sage: x = polygen(QQ, 'x'); y = polygen(QQ, 'y')
sage: k.<a> = NumberField(x^2 + 3)
sage: m.<a> = NumberField(y^2 + 3)
sage: k
Number Field in a with defining polynomial x^2 + 3
sage: m
Number Field in a with defining polynomial y^2 + 3
sage: k == m
True


In case of conflict of the generator name with the name given by the preparser, the name given by the preparser takes precedence:

sage: K.<b> = NumberField(x^2 + 5, 'a'); K
Number Field in b with defining polynomial x^2 + 5


One can also define number fields with specified embeddings, may be used for arithmetic and deduce relations with other number fields which would not be valid for an abstract number field.

sage: K.<a> = NumberField(x^3-2, embedding=1.2)
sage: RR.coerce_map_from(K)
Composite map:
From: Number Field in a with defining polynomial x^3 - 2
To:   Real Field with 53 bits of precision
Defn:   Generic morphism:
From: Number Field in a with defining polynomial x^3 - 2
To:   Real Lazy Field
Defn: a -> 1.259921049894873?
then
Conversion via _mpfr_ method map:
From: Real Lazy Field
To:   Real Field with 53 bits of precision
sage: RR(a)
1.25992104989487
sage: 1.1 + a
2.35992104989487
sage: b = 1/(a+1); b
1/3*a^2 - 1/3*a + 1/3
sage: RR(b)
0.442493334024442
sage: L.<b> = NumberField(x^6-2, embedding=1.1)
sage: L(a)
b^2
sage: a + b
b^2 + b


Note that the image only needs to be specified to enough precision to distinguish roots, and is exactly computed to any needed precision:

sage: RealField(200)(a)
1.2599210498948731647672106072782283505702514647015079800820


One can embed into any other field:

sage: K.<a> = NumberField(x^3-2, embedding=CC.gen()-0.6)
sage: CC(a)
-0.629960524947436 + 1.09112363597172*I
sage: L = Qp(5)
sage: f = polygen(L)^3 - 2
sage: K.<a> = NumberField(x^3-2, embedding=f.roots()[0][0])
sage: a + L(1)
4 + 2*5^2 + 2*5^3 + 3*5^4 + 5^5 + 4*5^6 + 2*5^8 + 3*5^9 + 4*5^12 + 4*5^14 + 4*5^15 + 3*5^16 + 5^17 + 5^18 + 2*5^19 + O(5^20)
sage: L.<b> = NumberField(x^6-x^2+1/10, embedding=1)
sage: K.<a> = NumberField(x^3-x+1/10, embedding=b^2)
sage: a+b
b^2 + b
sage: CC(a) == CC(b)^2
True
sage: K.coerce_embedding()
Generic morphism:
From: Number Field in a with defining polynomial x^3 - x + 1/10
To:   Number Field in b with defining polynomial x^6 - x^2 + 1/10
Defn: a -> b^2


The QuadraticField and CyclotomicField constructors create an embedding by default unless otherwise specified:

sage: K.<zeta> = CyclotomicField(15)
sage: CC(zeta)
0.913545457642601 + 0.406736643075800*I
sage: K(sqrtn3)
2*zeta^5 + 1
sage: sqrtn3 + zeta
2*zeta^5 + zeta + 1


An example involving a variable name that defines a function in PARI:

sage: theta = polygen(QQ, 'theta')
sage: M.<z> = NumberField([theta^3 + 4, theta^2 + 3]); M
Number Field in z0 with defining polynomial theta^3 + 4 over its base field


TESTS:

sage: x = QQ['x'].gen()
sage: y = ZZ['y'].gen()
sage: K = NumberField(x^3 + x + 3, 'a'); K
Number Field in a with defining polynomial x^3 + x + 3
sage: K.defining_polynomial().parent()
Univariate Polynomial Ring in x over Rational Field

sage: L = NumberField(y^3 + y + 3, 'a'); L
Number Field in a with defining polynomial y^3 + y + 3
sage: L.defining_polynomial().parent()
Univariate Polynomial Ring in y over Rational Field

sage: W1 = NumberField(x^2+1,'a')
sage: K.<x> = CyclotomicField(5)[]
sage: W.<a> = NumberField(x^2 + 1); W
Number Field in a with defining polynomial x^2 + 1 over its base field


The following has been fixed in trac ticket #8800:

sage: P.<x> = QQ[]
sage: K.<a> = NumberField(x^3-5,embedding=0)
sage: L.<b> = K.extension(x^2+a)
sage: F, R = L.construction()
sage: F(R) == L    # indirect doctest
True


Check that trac ticket #11670 has been fixed:

sage: K.<a> = NumberField(x^2 - x - 1)
True
sage: K.<a> = NumberField(x^3 - x - 1)
True
sage: K.<a> = CyclotomicField(7)
True


Another problem that was found while working on trac ticket #11670, maximize_at_primes and assume_disc_small were lost when pickling:

sage: K.<a> = NumberField(x^3-2, assume_disc_small=True, maximize_at_primes=[2], latex_name='\\alpha', embedding=2^(1/3))
sage: L._assume_disc_small
True
sage: L._maximize_at_primes
(2,)


It is an error not to specify the generator:

sage: K = NumberField(x^2-2)
Traceback (most recent call last):
...
TypeError: You must specify the name of the generator.

class sage.rings.number_field.number_field.NumberFieldFactory

Factory for number fields.

This should usually not be called directly, use NumberField() instead.

INPUT:

• polynomial - a polynomial over $$\QQ$$ or a number field.
• name - a string (default: 'a'), the name of the generator
• check - a boolean (default: True); do type checking and irreducibility checking.
• embedding - None or an element, the images of the generator in an ambient field (default: None)
• latex_name - None or a string (default: None), how the generator is printed for latex output
• assume_disc_small – a boolean (default: False); if True, assume that no square of a prime greater than PARI’s primelimit (which should be 500000); only applies for absolute fields at present.
• maximize_at_primesNone or a list of primes (default: None); if not None, then the maximal order is computed by maximizing only at the primes in this list, which completely avoids having to factor the discriminant, but of course can lead to wrong results; only applies for absolute fields at present.
• structureNone or an instance of structure.NumberFieldStructure (default: None), internally used to pass in additional structural information, e.g., about the field from which this field is created as a subfield.

TESTS:

sage: from sage.rings.number_field.number_field import NumberFieldFactory
sage: nff = NumberFieldFactory("number_field_factory")
sage: R.<x> = QQ[]
sage: nff(x^2 + 1, name='a', check=False, embedding=None, latex_name=None, assume_disc_small=False, maximize_at_primes=None, structure=None)
Number Field in a with defining polynomial x^2 + 1


Pickling preserves the structure() of a number field:

sage: K.<a> = QuadraticField(2)
sage: L.<b> = K.change_names()
sage: M.structure()
(Isomorphism given by variable name change map:
From: Number Field in b with defining polynomial x^2 - 2
To:   Number Field in a with defining polynomial x^2 - 2,
Isomorphism given by variable name change map:
From: Number Field in a with defining polynomial x^2 - 2
To:   Number Field in b with defining polynomial x^2 - 2)

create_key_and_extra_args(polynomial, name, check, embedding, latex_name, assume_disc_small, maximize_at_primes, structure)

Create a unique key for the number field specified by the parameters.

TESTS:

sage: from sage.rings.number_field.number_field import NumberFieldFactory
sage: nff = NumberFieldFactory("number_field_factory")
sage: R.<x> = QQ[]
sage: nff.create_key_and_extra_args(x^2+1, name='a', check=False, embedding=None, latex_name=None, assume_disc_small=False, maximize_at_primes=None, structure=None)
((Rational Field, x^2 + 1, ('a',), None, None, None, False, None), {'check': False})

create_object(version, key, check)

Create the unique number field defined by key.

TESTS:

sage: from sage.rings.number_field.number_field import NumberFieldFactory
sage: nff = NumberFieldFactory("number_field_factory")
sage: R.<x> = QQ[]
sage: nff.create_object(None, (QQ, x^2 + 1, ('a',), None, None, None, False, None), check=False)
Number Field in a with defining polynomial x^2 + 1

sage.rings.number_field.number_field.NumberFieldTower(polynomials, names, check=True, embeddings=None, latex_names=None, assume_disc_small=False, maximize_at_primes=None, structures=None)

Create the tower of number fields defined by the polynomials in the list polynomials.

INPUT:

• polynomials - a list of polynomials. Each entry must be polynomial which is irreducible over the number field generated by the roots of the following entries.
• names - a list of strings or a string, the names of the generators of the relative number fields. If a single string, then names are generated from that string.
• check - a boolean (default: True), whether to check that the polynomials are irreducible
• embeddings - a list of elemenst or None (default: None), embeddings of the relative number fields in an ambient field.
• latex_names - a list of strings or None (default: None), names used to print the generators for latex output.
• assume_disc_small – a boolean (default: False); if True, assume that no square of a prime greater than PARI’s primelimit (which should be 500000); only applies for absolute fields at present.
• maximize_at_primesNone or a list of primes (default: None); if not None, then the maximal order is computed by maximizing only at the primes in this list, which completely avoids having to factor the discriminant, but of course can lead to wrong results; only applies for absolute fields at present.
• structuresNone or a list (default: None), internally used to provide additional information about the number field such as the field from which it was created.

OUTPUT:

Returns the relative number field generated by a root of the first entry of polynomials over the relative number field generated by root of the second entry of polynomials ... over the number field over which the last entry of polynomials is defined.

EXAMPLES:

sage: k.<a,b,c> = NumberField([x^2 + 1, x^2 + 3, x^2 + 5]); k # indirect doctest
Number Field in a with defining polynomial x^2 + 1 over its base field
sage: a^2
-1
sage: b^2
-3
sage: c^2
-5
sage: (a+b+c)^2
(2*b + 2*c)*a + 2*c*b - 9


The Galois group is a product of 3 groups of order 2:

sage: k.galois_group(type="pari")
Galois group PARI group [8, 1, 3, "E(8)=2[x]2[x]2"] of degree 8 of the Number Field in a with defining polynomial x^2 + 1 over its base field


Repeatedly calling base_field allows us to descend the internally constructed tower of fields:

sage: k.base_field()
Number Field in b with defining polynomial x^2 + 3 over its base field
sage: k.base_field().base_field()
Number Field in c with defining polynomial x^2 + 5
sage: k.base_field().base_field().base_field()
Rational Field


In the following example the second polynomial is reducible over the first, so we get an error:

sage: v = NumberField([x^3 - 2, x^3 - 2], names='a')
Traceback (most recent call last):
...
ValueError: defining polynomial (x^3 - 2) must be irreducible


We mix polynomial parent rings:

sage: k.<y> = QQ[]
sage: m = NumberField([y^3 - 3, x^2 + x + 1, y^3 + 2], 'beta')
sage: m
Number Field in beta0 with defining polynomial y^3 - 3 over its base field
sage: m.base_field ()
Number Field in beta1 with defining polynomial x^2 + x + 1 over its base field


sage: K.<a> = NumberField([x^2 + 3, x^2 + 2, x^2 + 1])
sage: K
Number Field in a0 with defining polynomial x^2 + 3 over its base field
sage: K.base_field()
Number Field in a1 with defining polynomial x^2 + 2 over its base field
sage: K.base_field().base_field()
Number Field in a2 with defining polynomial x^2 + 1


A bigger tower of quadratic fields:

sage: K.<a2,a3,a5,a7> = NumberField([x^2 + p for p in [2,3,5,7]]); K
Number Field in a2 with defining polynomial x^2 + 2 over its base field
sage: a2^2
-2
sage: a3^2
-3
sage: (a2+a3+a5+a7)^3
((6*a5 + 6*a7)*a3 + 6*a7*a5 - 47)*a2 + (6*a7*a5 - 45)*a3 - 41*a5 - 37*a7


The function can also be called by name:

sage: NumberFieldTower([x^2 + 1, x^2 + 2], ['a','b'])
Number Field in a with defining polynomial x^2 + 1 over its base field

class sage.rings.number_field.number_field.NumberField_absolute(polynomial, name, latex_name=None, check=True, embedding=None, assume_disc_small=False, maximize_at_primes=None, structure=None)

Function to initialize an absolute number field.

EXAMPLE:

sage: K = NumberField(x^17 + 3, 'a'); K
Number Field in a with defining polynomial x^17 + 3
sage: type(K)
<class 'sage.rings.number_field.number_field.NumberField_absolute_with_category'>
sage: TestSuite(K).run()

Minkowski_embedding(B=None, prec=None)

Return an nxn matrix over RDF whose columns are the images of the basis $$\{1, \alpha, \dots, \alpha^{n-1}\}$$ of self over $$\QQ$$ (as vector spaces), where here $$\alpha$$ is the generator of self over $$\QQ$$, i.e. self.gen(0). If B is not None, return the images of the vectors in B as the columns instead. If prec is not None, use RealField(prec) instead of RDF.

This embedding is the so-called “Minkowski embedding” of a number field in $$\RR^n$$: given the $$n$$ embeddings $$\sigma_1, \dots, \sigma_n$$ of self in $$\CC$$, write $$\sigma_1, \dots, \sigma_r$$ for the real embeddings, and $$\sigma_{r+1}, \dots, \sigma_{r+s}$$ for choices of one of each pair of complex conjugate embeddings (in our case, we simply choose the one where the image of $$\alpha$$ has positive real part). Here $$(r,s)$$ is the signature of self. Then the Minkowski embedding is given by

$x \mapsto ( \sigma_1(x), \dots, \sigma_r(x), \sqrt{2}\Re(\sigma_{r+1}(x)), \sqrt{2}\Im(\sigma_{r+1}(x)), \dots, \sqrt{2}\Re(\sigma_{r+s}(x)), \sqrt{2}\Im(\sigma_{r+s}(x)))$

Equivalently, this is an embedding of self in $$\RR^n$$ so that the usual norm on $$\RR^n$$ coincides with $$|x| = \sum_i |\sigma_i(x)|^2$$ on self.

TODO: This could be much improved by implementing homomorphisms over VectorSpaces.

EXAMPLES:

sage: F.<alpha> = NumberField(x^3+2)
sage: F.Minkowski_embedding()
[ 1.00000000000000 -1.25992104989487  1.58740105196820]
[ 1.41421356237... 0.8908987181... -1.12246204830...]
[0.000000000000000  1.54308184421...  1.94416129723...]
sage: F.Minkowski_embedding([1, alpha+2, alpha^2-alpha])
[ 1.00000000000000 0.740078950105127  2.84732210186307]
[ 1.41421356237...  3.7193258428... -2.01336076644...]
[0.000000000000000  1.54308184421... 0.40107945302...]
sage: F.Minkowski_embedding() * (alpha + 2).vector().column()
[0.740078950105127]
[ 3.7193258428...]
[ 1.54308184421...]

absolute_degree()

A synonym for degree.

EXAMPLES:

sage: K.<i> = NumberField(x^2 + 1)
sage: K.absolute_degree()
2

absolute_different()

A synonym for different.

EXAMPLES:

sage: K.<i> = NumberField(x^2 + 1)
sage: K.absolute_different()
Fractional ideal (2)

absolute_discriminant()

A synonym for discriminant.

EXAMPLES:

sage: K.<i> = NumberField(x^2 + 1)
sage: K.absolute_discriminant()
-4

absolute_generator()

An alias for sage.rings.number_field.number_field.NumberField_generic.gen(). This is provided for consistency with relative fields, where the element returned by sage.rings.number_field.number_field_rel.NumberField_relative.gen() only generates the field over its base field (not necessarily over $$\QQ$$).

EXAMPLE:

sage: K.<a> = NumberField(x^2 - 17)
sage: K.absolute_generator()
a

absolute_polynomial()

A synonym for polynomial.

EXAMPLES:

sage: K.<i> = NumberField(x^2 + 1)
sage: K.absolute_polynomial()
x^2 + 1

absolute_vector_space()

A synonym for vector_space.

EXAMPLES:

sage: K.<i> = NumberField(x^2 + 1)
sage: K.absolute_vector_space()
(Vector space of dimension 2 over Rational Field,
Isomorphism map:
From: Vector space of dimension 2 over Rational Field
To:   Number Field in i with defining polynomial x^2 + 1,
Isomorphism map:
From: Number Field in i with defining polynomial x^2 + 1
To:   Vector space of dimension 2 over Rational Field)

automorphisms()

Compute all Galois automorphisms of self.

This uses PARI’s nfgaloisconj and is much faster than root finding for many fields.

EXAMPLES:

sage: K.<a> = NumberField(x^2 + 10000)
sage: K.automorphisms()
[
Ring endomorphism of Number Field in a with defining polynomial x^2 + 10000
Defn: a |--> a,
Ring endomorphism of Number Field in a with defining polynomial x^2 + 10000
Defn: a |--> -a
]


Here’s a larger example, that would take some time if we found roots instead of using PARI’s specialized machinery:

sage: K = NumberField(x^6 - x^4 - 2*x^2 + 1, 'a')
sage: len(K.automorphisms())
2


$$L$$ is the Galois closure of $$K$$:

sage: L = NumberField(x^24 - 84*x^22 + 2814*x^20 - 15880*x^18 - 409563*x^16 - 8543892*x^14 + 25518202*x^12 + 32831026956*x^10 - 672691027218*x^8 - 4985379093428*x^6 + 320854419319140*x^4 + 817662865724712*x^2 + 513191437605441, 'a')
sage: len(L.automorphisms())
24

base_field()

Returns the base field of self, which is always QQ

EXAMPLES:

sage: K = CyclotomicField(5)
sage: K.base_field()
Rational Field

change_names(names)

Return number field isomorphic to self but with the given generator name.

INPUT:

• names - should be exactly one variable name.

Also, K.structure() returns from_K and to_K, where from_K is an isomorphism from K to self and to_K is an isomorphism from self to K.

EXAMPLES:

sage: K.<z> = NumberField(x^2 + 3); K
Number Field in z with defining polynomial x^2 + 3
sage: L.<ww> = K.change_names()
sage: L
Number Field in ww with defining polynomial x^2 + 3
sage: L.structure()[0]
Isomorphism given by variable name change map:
From: Number Field in ww with defining polynomial x^2 + 3
To:   Number Field in z with defining polynomial x^2 + 3
sage: L.structure()[0](ww + 5/3)
z + 5/3

elements_of_bounded_height(bound, precision=53, LLL=False)

Return an iterator over the elements of self with relative multiplicative height at most bound.

The algorithm requires floating point arithmetic, so the user is allowed to specify the precision for such calculations.

It might be helpful to work with an LLL-reduced system of fundamental units, so the user has the option to perform an LLL reduction for the fundamental units by setting LLL to True.

Certain computations may be faster assuming GRH, which may be done globally by using the number_field(True/False) switch.

For details: See [Doyle-Krumm].

INPUT:

• bound - a real number
• precision - (default: 53) a positive integer
• LLL - (default: False) a boolean value

OUTPUT:

• an iterator of number field elements

Warning

In the current implementation, the output of the algorithm cannot be guaranteed to be correct due to the necessity of floating point computations. In some cases, the default 53-bit precision is considerably lower than would be required for the algorithm to generate correct output.

Todo

Should implement a version of the algorithm that guarantees correct output. See Algorithm 4 in [Doyle-Krumm] for details of an implementation that takes precision issues into account.

EXAMPLES:

There are no elements in a number field with multiplicative height less than 1:

sage: K.<g> = NumberField(x^5 - x + 19)
sage: list(K.elements_of_bounded_height(0.9))
[]


The only elements in a number field of height 1 are 0 and the roots of unity:

sage: K.<a> = NumberField(x^2 + x + 1)
sage: list(K.elements_of_bounded_height(1))
[0, a + 1, a, -1, -a - 1, -a, 1]

sage: K.<a> = CyclotomicField(20)
sage: len(list(K.elements_of_bounded_height(1)))
21


The elements in the output iterator all have relative multiplicative height at most the input bound:

sage: K.<a> = NumberField(x^6 + 2)
sage: L = K.elements_of_bounded_height(5)
sage: for t in L:
....:     exp(6*t.global_height())
....:
1.00000000000000
1.00000000000000
1.00000000000000
2.00000000000000
2.00000000000000
2.00000000000000
2.00000000000000
4.00000000000000
4.00000000000000
4.00000000000000
4.00000000000000

sage: K.<a> = NumberField(x^2 - 71)
sage: L = K.elements_of_bounded_height(20)
sage: all(exp(2*t.global_height()) <= 20 for t in L) # long time (5 s)
True

sage: K.<a> = NumberField(x^2 + 17)
sage: L = K.elements_of_bounded_height(120)
sage: len(list(L))
9047

sage: K.<a> = NumberField(x^4 - 5)
sage: L = K.elements_of_bounded_height(50)
sage: len(list(L)) # long time (2 s)
2163

sage: K.<a> = CyclotomicField(13)
sage: L = K.elements_of_bounded_height(2)
sage: len(list(L)) # long time (3 s)
27

sage: K.<a> = NumberField(x^6 + 2)
sage: L = K.elements_of_bounded_height(60, precision=100)
sage: len(list(L)) # long time (5 s)
1899

sage: K.<a> = NumberField(x^4 - x^3 - 3*x^2 + x + 1)
sage: L = K.elements_of_bounded_height(10, LLL=true)
sage: len(list(L))
99


AUTHORS:

• John Doyle (2013)
• David Krumm (2013)

REFERENCES:

 [Doyle-Krumm] John R. Doyle and David Krumm, Computing algebraic numbers of bounded height, Arxiv 1111.4963 (2013).
embeddings(K)

Compute all field embeddings of self into the field K (which need not even be a number field, e.g., it could be the complex numbers). This will return an identical result when given K as input again.

If possible, the most natural embedding of self into K is put first in the list.

INPUT:

• K - a number field

EXAMPLES:

sage: K.<a> = NumberField(x^3 - 2)
sage: L.<a1> = K.galois_closure(); L
Number Field in a1 with defining polynomial x^6 + 108
sage: K.embeddings(L)[0]
Ring morphism:
From: Number Field in a with defining polynomial x^3 - 2
To:   Number Field in a1 with defining polynomial x^6 + 108
Defn: a |--> 1/18*a1^4
sage: K.embeddings(L) is K.embeddings(L)
True


We embed a quadratic field into a cyclotomic field:

sage: L.<a> = QuadraticField(-7)
sage: K = CyclotomicField(7)
sage: L.embeddings(K)
[
Ring morphism:
From: Number Field in a with defining polynomial x^2 + 7
To:   Cyclotomic Field of order 7 and degree 6
Defn: a |--> 2*zeta7^4 + 2*zeta7^2 + 2*zeta7 + 1,
Ring morphism:
From: Number Field in a with defining polynomial x^2 + 7
To:   Cyclotomic Field of order 7 and degree 6
Defn: a |--> -2*zeta7^4 - 2*zeta7^2 - 2*zeta7 - 1
]


We embed a cubic field in the complex numbers:

sage: K.<a> = NumberField(x^3 - 2)
sage: K.embeddings(CC)
[
Ring morphism:
From: Number Field in a with defining polynomial x^3 - 2
To:   Complex Field with 53 bits of precision
Defn: a |--> -0.62996052494743... - 1.09112363597172*I,
Ring morphism:
From: Number Field in a with defining polynomial x^3 - 2
To:   Complex Field with 53 bits of precision
Defn: a |--> -0.62996052494743... + 1.09112363597172*I,
Ring morphism:
From: Number Field in a with defining polynomial x^3 - 2
To:   Complex Field with 53 bits of precision
Defn: a |--> 1.25992104989487
]


Test that trac ticket #15053 is fixed:

sage: K = NumberField(x^3 - 2, 'a')
sage: K.embeddings(GF(3))
[]

galois_closure(names=None, map=False)

Return number field $$K$$ that is the Galois closure of self, i.e., is generated by all roots of the defining polynomial of self, and possibly an embedding of self into $$K$$.

INPUT:

• names - variable name for Galois closure
• map - (default: False) also return an embedding of self into $$K$$

EXAMPLES:

sage: K.<a> = NumberField(x^4 - 2)
sage: M = K.galois_closure('b'); M
Number Field in b with defining polynomial x^8 + 28*x^4 + 2500
sage: L.<a2> = K.galois_closure(); L
Number Field in a2 with defining polynomial x^8 + 28*x^4 + 2500
sage: K.galois_group(names=("a3")).order()
8

sage: phi = K.embeddings(L)[0]
sage: phi(K.0)
1/120*a2^5 + 19/60*a2
sage: phi(K.0).minpoly()
x^4 - 2

sage: L, phi = K.galois_closure('b', map=True)
sage: L
Number Field in b with defining polynomial x^8 + 28*x^4 + 2500
sage: phi
Ring morphism:
From: Number Field in a with defining polynomial x^4 - 2
To:   Number Field in b with defining polynomial x^8 + 28*x^4 + 2500
Defn: a |--> 1/240*b^5 - 41/120*b


A cyclotomic field is already Galois:

sage: K.<a> = NumberField(cyclotomic_polynomial(23))
sage: L.<z> = K.galois_closure()
sage: L
Number Field in z with defining polynomial x^22 + x^21 + x^20 + x^19 + x^18 + x^17 + x^16 + x^15 + x^14 + x^13 + x^12 + x^11 + x^10 + x^9 + x^8 + x^7 + x^6 + x^5 + x^4 + x^3 + x^2 + x + 1


TESTS:

Let’s make sure we’re renaming correctly:

sage: K.<a> = NumberField(x^4 - 2)
sage: L, phi = K.galois_closure('cc', map=True)
sage: L
Number Field in cc with defining polynomial x^8 + 28*x^4 + 2500
sage: phi
Ring morphism:
From: Number Field in a with defining polynomial x^4 - 2
To:   Number Field in cc with defining polynomial x^8 + 28*x^4 + 2500
Defn: a |--> 1/240*cc^5 - 41/120*cc

hilbert_conductor(a, b)

This is the product of all (finite) primes where the Hilbert symbol is -1. What is the same, this is the (reduced) discriminant of the quaternion algebra $$(a,b)$$ over a number field.

INPUT:

-a,b – elements of the number field $$self$$

OUTPUT:

• squarefree ideal of the ring of integers of $$self$$

EXAMPLES:

sage: F.<a> = NumberField(x^2-x-1)
sage: F.hilbert_conductor(2*a,F(-1))
Fractional ideal (2)
sage: K.<b> = NumberField(x^3-4*x+2)
sage: K.hilbert_conductor(K(2),K(-2))
Fractional ideal (1)
sage: K.hilbert_conductor(K(2*b),K(-2))
Fractional ideal (b^2 + b - 2)


AUTHOR:

• Aly Deines
hilbert_symbol(a, b, P=None)

Returns the Hilbert symbol $$(a,b)_P$$ for a prime P of self and non-zero elements a and b of self. If P is omitted, return the global Hilbert symbol $$(a,b)$$ instead.

INPUT:

• a, b – elements of self
• P – (default: None) If $$P$$ is None, compute the global symbol. Otherwise, $$P$$ should be either a prime ideal of self (which may also be given as a generator or set of generators) or a real or complex embedding.

OUTPUT:

If a or b is zero, returns 0.

If a and b are non-zero and P is specified, returns the Hilbert symbol $$(a,b)_P$$, which is 1 if the equation $$a x^2 + b y^2 = 1$$ has a solution in the completion of self at P, and is -1 otherwise.

If a and b are non-zero and P is unspecified, returns 1 if the equation has a solution in self and -1 otherwise.

EXAMPLES:

Some global examples:

sage: K.<a> = NumberField(x^2 - 23)
sage: K.hilbert_symbol(0, a+5)
0
sage: K.hilbert_symbol(a, 0)
0
sage: K.hilbert_symbol(-a, a+1)
1
sage: K.hilbert_symbol(-a, a+2)
-1
sage: K.hilbert_symbol(a, a+5)
-1


That the latter two are unsolvable should be visible in local obstructions. For the first, this is a prime ideal above 19. For the second, the ramified prime above 23:

sage: K.hilbert_symbol(-a, a+2, a+2)
-1
sage: K.hilbert_symbol(a, a+5, K.ideal(23).factor()[0][0])
-1


More local examples:

sage: K.hilbert_symbol(a, 0, K.ideal(5))
0
sage: K.hilbert_symbol(a, a+5, K.ideal(5))
1
sage: K.hilbert_symbol(a+1, 13, (a+6)*K.maximal_order())
-1
sage: [emb1, emb2] = K.embeddings(AA)
sage: K.hilbert_symbol(a, -1, emb1)
-1
sage: K.hilbert_symbol(a, -1, emb2)
1


Ideals P can be given by generators:

sage: K.<a> = NumberField(x^5 - 23)
sage: pi = 2*a^4 + 3*a^3 + 4*a^2 + 15*a + 11
sage: K.hilbert_symbol(a, a+5, pi)
1
sage: rho = 2*a^4 + 3*a^3 + 4*a^2 + 15*a + 11
sage: K.hilbert_symbol(a, a+5, rho)
1


This also works for non-principal ideals:

sage: K.<a> = QuadraticField(-5)
sage: P = K.ideal(3).factor()[0][0]
sage: P.gens_reduced()  # random, could be the other factor
(3, a + 1)
sage: K.hilbert_symbol(a, a+3, P)
1
sage: K.hilbert_symbol(a, a+3, [3, a+1])
1


Primes above 2:

sage: K.<a> = NumberField(x^5 - 23)
sage: O = K.maximal_order()
sage: p = [p[0] for p in (2*O).factor() if p[0].norm() == 16][0]
sage: K.hilbert_symbol(a, a+5, p)
1
sage: K.hilbert_symbol(a, 2, p)
1
sage: K.hilbert_symbol(-1, a-2, p)
-1


Various real fields are allowed:

sage: K.<a> = NumberField(x^3+x+1)
sage: K.hilbert_symbol(a/3, 1/2, K.embeddings(RDF)[0])
1
sage: K.hilbert_symbol(a/5, -1, K.embeddings(RR)[0])
-1
sage: [K.hilbert_symbol(a, -1, e) for e in K.embeddings(AA)]
[-1]


Real embeddings are not allowed to be disguised as complex embeddings:

sage: K.<a> = QuadraticField(5)
sage: K.hilbert_symbol(-1, -1, K.embeddings(CC)[0])
Traceback (most recent call last):
...
ValueError: Possibly real place (=Ring morphism:
From: Number Field in a with defining polynomial x^2 - 5
To:   Complex Field with 53 bits of precision
Defn: a |--> -2.23606797749979) given as complex embedding in hilbert_symbol. Is it real or complex?
sage: K.hilbert_symbol(-1, -1, K.embeddings(QQbar)[0])
Traceback (most recent call last):
...
ValueError: Possibly real place (=Ring morphism:
From: Number Field in a with defining polynomial x^2 - 5
To:   Algebraic Field
Defn: a |--> -2.236067977499790?) given as complex embedding in hilbert_symbol. Is it real or complex?
sage: K.hilbert_symbol(-1, -1, K.embeddings(CDF)[0])
1
sage: K.hilbert_symbol(-1, -1, K.embeddings(QQbar)[0])
1


a and b do not have to be integral or coprime:

sage: K.<i> = QuadraticField(-1)
sage: O = K.maximal_order()
sage: K.hilbert_symbol(1/2, 1/6, 3*O)
1
sage: p = 1+i
sage: K.hilbert_symbol(p, p, p)
1
sage: K.hilbert_symbol(p, 3*p, p)
-1
sage: K.hilbert_symbol(3, p, p)
-1
sage: K.hilbert_symbol(1/3, 1/5, 1+i)
1
sage: L.hilbert_symbol(-3, -1/2, 2)
1


Various other examples:

sage: K.<a> = NumberField(x^3+x+1)
sage: K.hilbert_symbol(-6912, 24, -a^2-a-2)
1
sage: K.<a> = NumberField(x^5-23)
sage: P = K.ideal(-1105*a^4 + 1541*a^3 - 795*a^2 - 2993*a + 11853)
sage: Q = K.ideal(-7*a^4 + 13*a^3 - 13*a^2 - 2*a + 50)
sage: b = -a+5
sage: K.hilbert_symbol(a,b,P)
1
sage: K.hilbert_symbol(a,b,Q)
1
sage: K.<a> = NumberField(x^5-23)
sage: P = K.ideal(-1105*a^4 + 1541*a^3 - 795*a^2 - 2993*a + 11853)
sage: K.hilbert_symbol(a, a+5, P)
1
sage: K.hilbert_symbol(a, 2, P)
1
sage: K.hilbert_symbol(a+5, 2, P)
-1
sage: K.<a> = NumberField(x^3 - 4*x + 2)
sage: K.hilbert_symbol(2, -2, K.primes_above(2)[0])
1


Check that the bug reported at trac ticket #16043 has been fixed:

sage: K.<a> = NumberField(x^2 + 5)
sage: p = K.primes_above(2)[0]; p
Fractional ideal (2, a + 1)
sage: K.hilbert_symbol(2*a, -1, p)
1
sage: K.hilbert_symbol(2*a, 2, p)
-1
sage: K.hilbert_symbol(2*a, -2, p)
-1


AUTHOR:

• Aly Deines (2010-08-19): part of the doctests
• Marco Streng (2010-12-06)
is_absolute()

Returns True since self is an absolute field.

EXAMPLES:

sage: K = CyclotomicField(5)
sage: K.is_absolute()
True

maximal_order(v=None)

Return the maximal order, i.e., the ring of integers, associated to this number field.

INPUT:

• v - (default: None) None, a prime, or a list of primes.
• if v is None, return the maximal order.
• if v is a prime, return an order that is $$p$$-maximal.
• if v is a list, return an order that is maximal at each prime in the list v.

EXAMPLES:

In this example, the maximal order cannot be generated by a single element:

sage: k.<a> = NumberField(x^3 + x^2 - 2*x+8)
sage: o = k.maximal_order()
sage: o
Maximal Order in Number Field in a with defining polynomial x^3 + x^2 - 2*x + 8


We compute $$p$$-maximal orders for several $$p$$. Note that computing a $$p$$-maximal order is much faster in general than computing the maximal order:

sage: p = next_prime(10^22); q = next_prime(10^23)
sage: K.<a> = NumberField(x^3 - p*q)
sage: K.maximal_order([3]).basis()
[1/3*a^2 + 1/3*a + 1/3, a, a^2]
sage: K.maximal_order([2]).basis()
[1, a, a^2]
sage: K.maximal_order([p]).basis()
[1, a, a^2]
sage: K.maximal_order([q]).basis()
[1, a, a^2]
sage: K.maximal_order([p,3]).basis()
[1/3*a^2 + 1/3*a + 1/3, a, a^2]


An example with bigger discriminant:

sage: p = next_prime(10^97); q = next_prime(10^99)
sage: K.<a> = NumberField(x^3 - p*q)
sage: K.maximal_order(prime_range(10000)).basis()
[1, a, a^2]

optimized_representation(names=None, both_maps=True)

Return a field isomorphic to self with a better defining polynomial if possible, along with field isomorphisms from the new field to self and from self to the new field.

EXAMPLES: We construct a compositum of 3 quadratic fields, then find an optimized representation and transform elements back and forth.

sage: K = NumberField([x^2 + p for p in [5, 3, 2]],'a').absolute_field('b'); K
Number Field in b with defining polynomial x^8 + 40*x^6 + 352*x^4 + 960*x^2 + 576
sage: L, from_L, to_L = K.optimized_representation()
Number Field in a14 with defining polynomial x^8 + 4*x^6 + 7*x^4 + 36*x^2 + 81
sage: to_L(K.0)   # random
4/189*a14^7 - 1/63*a14^6 + 1/27*a14^5 + 2/9*a14^4 - 5/27*a14^3 + 8/9*a14^2 + 3/7*a14 + 3/7
sage: from_L(L.0)   # random
1/1152*a1^7 + 1/192*a1^6 + 23/576*a1^5 + 17/96*a1^4 + 37/72*a1^3 + 5/6*a1^2 + 55/24*a1 + 3/4


The transformation maps are mutually inverse isomorphisms.

sage: from_L(to_L(K.0))
b
sage: to_L(from_L(L.0))     # random
a14

optimized_subfields(degree=0, name=None, both_maps=True)

Return optimized representations of many (but not necessarily all!) subfields of self of the given degree, or of all possible degrees if degree is 0.

EXAMPLES:

sage: K = NumberField([x^2 + p for p in [5, 3, 2]],'a').absolute_field('b'); K
Number Field in b with defining polynomial x^8 + 40*x^6 + 352*x^4 + 960*x^2 + 576
sage: L = K.optimized_subfields(name='b')
sage: L[0][0]
Number Field in b0 with defining polynomial x - 1
sage: L[1][0]
Number Field in b1 with defining polynomial x^2 - 3*x + 3
sage: [z[0] for z in L]          # random -- since algorithm is random
[Number Field in b0 with defining polynomial x - 1,
Number Field in b1 with defining polynomial x^2 - x + 1,
Number Field in b2 with defining polynomial x^4 - 5*x^2 + 25,
Number Field in b3 with defining polynomial x^4 - 2*x^2 + 4,
Number Field in b4 with defining polynomial x^8 + 4*x^6 + 7*x^4 + 36*x^2 + 81]


We examine one of the optimized subfields in more detail:

sage: M, from_M, to_M = L[2]
sage: M                             # random
Number Field in b2 with defining polynomial x^4 - 5*x^2 + 25
sage: from_M     # may be slightly random
Ring morphism:
From: Number Field in b2 with defining polynomial x^4 - 5*x^2 + 25
To:   Number Field in a1 with defining polynomial x^8 + 40*x^6 + 352*x^4 + 960*x^2 + 576
Defn: b2 |--> -5/1152*a1^7 + 1/96*a1^6 - 97/576*a1^5 + 17/48*a1^4 - 95/72*a1^3 + 17/12*a1^2 - 53/24*a1 - 1


The to_M map is None, since there is no map from K to M:

sage: to_M


We apply the from_M map to the generator of M, which gives a rather large element of $$K$$:

sage: from_M(M.0)          # random
-5/1152*a1^7 + 1/96*a1^6 - 97/576*a1^5 + 17/48*a1^4 - 95/72*a1^3 + 17/12*a1^2 - 53/24*a1 - 1


Nevertheless, that large-ish element lies in a degree 4 subfield:

sage: from_M(M.0).minpoly()   # random
x^4 - 5*x^2 + 25

order(*args, **kwds)

Return the order with given ring generators in the maximal order of this number field.

INPUT:

• gens - list of elements in this number field; if no generators are given, just returns the cardinality of this number field ($$\infty$$) for consistency.
• check_is_integral - bool (default: True), whether to check that each generator is integral.
• check_rank - bool (default: True), whether to check that the ring generated by gens is of full rank.
• allow_subfield - bool (default: False), if True and the generators do not generate an order, i.e., they generate a subring of smaller rank, instead of raising an error, return an order in a smaller number field.

EXAMPLES:

sage: k.<i> = NumberField(x^2 + 1)
sage: k.order(2*i)
Order in Number Field in i with defining polynomial x^2 + 1
sage: k.order(10*i)
Order in Number Field in i with defining polynomial x^2 + 1
sage: k.order(3)
Traceback (most recent call last):
...
ValueError: the rank of the span of gens is wrong
sage: k.order(i/2)
Traceback (most recent call last):
...
ValueError: each generator must be integral


Alternatively, an order can be constructed by adjoining elements to $$\ZZ$$:

sage: K.<a> = NumberField(x^3 - 2)
sage: ZZ[a]
Order in Number Field in a0 with defining polynomial x^3 - 2


TESTS:

We verify that trac ticket #2480 is fixed:

sage: K.<a> = NumberField(x^4 + 4*x^2 + 2)
sage: B = K.integral_basis()
sage: K.order(*B)
Order in Number Field in a with defining polynomial x^4 + 4*x^2 + 2
sage: K.order(B)
Order in Number Field in a with defining polynomial x^4 + 4*x^2 + 2
sage: K.order(gens=B)
Order in Number Field in a with defining polynomial x^4 + 4*x^2 + 2

places(all_complex=False, prec=None)

Return the collection of all infinite places of self.

By default, this returns the set of real places as homomorphisms into RIF first, followed by a choice of one of each pair of complex conjugate homomorphisms into CIF.

On the other hand, if prec is not None, we simply return places into RealField(prec) and ComplexField(prec) (or RDF, CDF if prec=53). One can also use prec=infinity, which returns embeddings into the field $$\overline{\QQ}$$ of algebraic numbers (or its subfield $$\mathbb{A}$$ of algebraic reals); this permits exact computatation, but can be extremely slow.

There is an optional flag all_complex, which defaults to False. If all_complex is True, then the real embeddings are returned as embeddings into CIF instead of RIF.

EXAMPLES:

sage: F.<alpha> = NumberField(x^3-100*x+1) ; F.places()
[Ring morphism:
From: Number Field in alpha with defining polynomial x^3 - 100*x + 1
To:   Real Field with 106 bits of precision
Defn: alpha |--> -10.00499625499181184573367219280,
Ring morphism:
From: Number Field in alpha with defining polynomial x^3 - 100*x + 1
To:   Real Field with 106 bits of precision
Defn: alpha |--> 0.01000001000003000012000055000273,
Ring morphism:
From: Number Field in alpha with defining polynomial x^3 - 100*x + 1
To:   Real Field with 106 bits of precision
Defn: alpha |--> 9.994996244991781845613530439509]

sage: F.<alpha> = NumberField(x^3+7) ; F.places()
[Ring morphism:
From: Number Field in alpha with defining polynomial x^3 + 7
To:   Real Field with 106 bits of precision
Defn: alpha |--> -1.912931182772389101199116839549,
Ring morphism:
From: Number Field in alpha with defining polynomial x^3 + 7
To:   Complex Field with 53 bits of precision
Defn: alpha |--> 0.956465591386195 + 1.65664699997230*I]

sage: F.<alpha> = NumberField(x^3+7) ; F.places(all_complex=True)
[Ring morphism:
From: Number Field in alpha with defining polynomial x^3 + 7
To:   Complex Field with 53 bits of precision
Defn: alpha |--> -1.91293118277239,
Ring morphism:
From: Number Field in alpha with defining polynomial x^3 + 7
To:   Complex Field with 53 bits of precision
Defn: alpha |--> 0.956465591386195 + 1.65664699997230*I]
sage: F.places(prec=10)
[Ring morphism:
From: Number Field in alpha with defining polynomial x^3 + 7
To:   Real Field with 10 bits of precision
Defn: alpha |--> -1.9,
Ring morphism:
From: Number Field in alpha with defining polynomial x^3 + 7
To:   Complex Field with 10 bits of precision
Defn: alpha |--> 0.96 + 1.7*I]

real_places(prec=None)

Return all real places of self as homomorphisms into RIF.

EXAMPLES:

sage: F.<alpha> = NumberField(x^4-7) ; F.real_places()
[Ring morphism:
From: Number Field in alpha with defining polynomial x^4 - 7
To:   Real Field with 106 bits of precision
Defn: alpha |--> -1.626576561697785743211232345494,
Ring morphism:
From: Number Field in alpha with defining polynomial x^4 - 7
To:   Real Field with 106 bits of precision
Defn: alpha |--> 1.626576561697785743211232345494]

relative_degree()

A synonym for degree.

EXAMPLES:

sage: K.<i> = NumberField(x^2 + 1)
sage: K.relative_degree()
2

relative_different()

A synonym for different.

EXAMPLES:

sage: K.<i> = NumberField(x^2 + 1)
sage: K.relative_different()
Fractional ideal (2)

relative_discriminant()

A synonym for discriminant.

EXAMPLES:

sage: K.<i> = NumberField(x^2 + 1)
sage: K.relative_discriminant()
-4

relative_polynomial()

A synonym for polynomial.

EXAMPLES:

sage: K.<i> = NumberField(x^2 + 1)
sage: K.relative_polynomial()
x^2 + 1

relative_vector_space()

A synonym for vector_space.

EXAMPLES:

sage: K.<i> = NumberField(x^2 + 1)
sage: K.relative_vector_space()
(Vector space of dimension 2 over Rational Field,
Isomorphism map:
From: Vector space of dimension 2 over Rational Field
To:   Number Field in i with defining polynomial x^2 + 1,
Isomorphism map:
From: Number Field in i with defining polynomial x^2 + 1
To:   Vector space of dimension 2 over Rational Field)

relativize(alpha, names, structure=None)

Given an element in self or an embedding of a subfield into self, return a relative number field $$K$$ isomorphic to self that is relative over the absolute field $$\QQ(\alpha)$$ or the domain of $$alpha$$, along with isomorphisms from $$K$$ to self and from self to $$K$$.

INPUT:

• alpha - an element of self or an embedding of a subfield into self
• names - 2-tuple of names of generator for output field K and the subfield QQ(alpha) names[0] generators K and names[1] QQ(alpha).
• structure – an instance of structure.NumberFieldStructure or None (default: None), if None, then the resulting field’s structure() will return isomorphisms from and to this field. Otherwise, the field will be equipped with structure.

OUTPUT:

K – relative number field

Also, K.structure() returns from_K and to_K, where from_K is an isomorphism from K to self and to_K is an isomorphism from self to K.

EXAMPLES:

sage: K.<a> = NumberField(x^10 - 2)
sage: L.<c,d> = K.relativize(a^4 + a^2 + 2); L
Number Field in c with defining polynomial x^2 - 1/5*d^4 + 8/5*d^3 - 23/5*d^2 + 7*d - 18/5 over its base field
sage: c.absolute_minpoly()
x^10 - 2
sage: d.absolute_minpoly()
x^5 - 10*x^4 + 40*x^3 - 90*x^2 + 110*x - 58
sage: (a^4 + a^2 + 2).minpoly()
x^5 - 10*x^4 + 40*x^3 - 90*x^2 + 110*x - 58
sage: from_L, to_L = L.structure()
sage: to_L(a)
c
sage: to_L(a^4 + a^2 + 2)
d
sage: from_L(to_L(a^4 + a^2 + 2))
a^4 + a^2 + 2


The following demonstrates distinct embeddings of a subfield into a larger field:

sage: K.<a> = NumberField(x^4 + 2*x^2 + 2)
sage: K0 = K.subfields(2)[0][0]; K0
Number Field in a0 with defining polynomial x^2 - 2*x + 2
sage: rho, tau = K0.embeddings(K)
sage: L0 = K.relativize(rho(K0.gen()), 'b'); L0
Number Field in b0 with defining polynomial x^2 - b1 + 2 over its base field
sage: L1 = K.relativize(rho, 'b'); L1
Number Field in b0 with defining polynomial x^2 - a0 + 2 over its base field
sage: L2 = K.relativize(tau, 'b'); L2
Number Field in b0 with defining polynomial x^2 + a0 over its base field
sage: L0.base_field() is K0
False
sage: L1.base_field() is K0
True
sage: L2.base_field() is K0
True


Here we see that with the different embeddings, the relative norms are different:

sage: a0 = K0.gen()
sage: L1_into_K, K_into_L1 = L1.structure()
sage: L2_into_K, K_into_L2 = L2.structure()
sage: len(K.factor(41))
4
sage: w1 = -a^2 + a + 1; P = K.ideal([w1])
sage: Pp = L1.ideal(K_into_L1(w1)).ideal_below(); Pp == K0.ideal([4*a0 + 1])
True
sage: Pp == w1.norm(rho)
True

sage: w2 = a^2 + a - 1; Q = K.ideal([w2])
sage: Qq = L2.ideal(K_into_L2(w2)).ideal_below(); Qq == K0.ideal([-4*a0 + 9])
True
sage: Qq == w2.norm(tau)
True

sage: Pp == Qq
False


TESTS:

We can relativize over the whole field:

sage: K.<a> = NumberField(x^4 + 2*x^2 + 2)
sage: K.relativize(K.gen(), 'a')
Number Field in a0 with defining polynomial x - a1 over its base field
sage: K.relativize(2*K.gen(), 'a')
Number Field in a0 with defining polynomial x - 1/2*a1 over its base field


We can relativize over the prime field:

sage: L = K.relativize(K(1), 'a'); L
Number Field in a0 with defining polynomial x^4 + 2*x^2 + 2 over its base field
sage: L.base_field()
Number Field in a1 with defining polynomial x - 1
sage: L.base_field().base_field()
Rational Field

sage: L = K.relativize(K(2), 'a'); L
Number Field in a0 with defining polynomial x^4 + 2*x^2 + 2 over its base field
sage: L.base_field()
Number Field in a1 with defining polynomial x - 2
sage: L.base_field().base_field()
Rational Field

sage: L = K.relativize(K(0), 'a'); L
Number Field in a0 with defining polynomial x^4 + 2*x^2 + 2 over its base field
sage: L.base_field()
Number Field in a1 with defining polynomial x
sage: L.base_field().base_field()
Rational Field


We can relativize over morphisms returned by self.subfields():

sage: L = NumberField(x^4 + 1, 'a')
sage: [L.relativize(h, 'c') for (f,h,i) in L.subfields()]
[Number Field in c0 with defining polynomial x^4 + 1 over its base field, Number Field in c0 with defining polynomial x^2 - 1/2*a1 over its base field, Number Field in c0 with defining polynomial x^2 - a2*x - 1 over its base field, Number Field in c0 with defining polynomial x^2 - a3*x + 1 over its base field, Number Field in c0 with defining polynomial x - a4 over its base field]


We can relativize over a relative field:

sage: K.<z> = CyclotomicField(16)
sage: L, L_into_K, _ = K.subfields(4)[0]; L
Number Field in z0 with defining polynomial x^4 + 16
sage: F, F_into_L, _ = L.subfields(2)[0]; F
Number Field in z0_0 with defining polynomial x^2 + 64

sage: L_over_F = L.relativize(F_into_L, 'c'); L_over_F
Number Field in c0 with defining polynomial x^2 - 1/2*z0_0 over its base field
sage: L_over_F_into_L, _ = L_over_F.structure()

sage: K_over_rel = K.relativize(L_into_K * L_over_F_into_L, 'a'); K_over_rel
Number Field in a0 with defining polynomial x^2 - 1/2*c0 over its base field
sage: K_over_rel.base_field() is L_over_F
True
sage: K_over_rel.structure()
(Relative number field morphism:
From: Number Field in a0 with defining polynomial x^2 - 1/2*c0 over its base field
To:   Cyclotomic Field of order 16 and degree 8
Defn: a0 |--> z
c0 |--> 2*z^2
z0_0 |--> 8*z^4, Ring morphism:
From: Cyclotomic Field of order 16 and degree 8
To:   Number Field in a0 with defining polynomial x^2 - 1/2*c0 over its base field
Defn: z |--> a0)


We can relativize over a really large field:

sage: K.<a> = CyclotomicField(3^3*2^3)
sage: R = K.relativize(a^(3^2), 't'); R
Number Field in t0 with defining polynomial x^9 - t1 over its base field
sage: R.structure()
(Relative number field morphism:
From: Number Field in t0 with defining polynomial x^9 - t1 over its base field
To:   Cyclotomic Field of order 216 and degree 72
Defn: t0 |--> a
t1 |--> a^9,
Ring morphism:
From: Cyclotomic Field of order 216 and degree 72
To:   Number Field in t0 with defining polynomial x^9 - t1 over its base field
Defn: a |--> t0)

subfields(degree=0, name=None)

Return all subfields of self of the given degree, or of all possible degrees if degree is 0. The subfields are returned as absolute fields together with an embedding into self. For the case of the field itself, the reverse isomorphism is also provided.

EXAMPLES:

sage: K.<a> = NumberField( [x^3 - 2, x^2 + x + 1] )
sage: K = K.absolute_field('b')
sage: S = K.subfields()
sage: len(S)
6
sage: [k[0].polynomial() for k in S]
[x - 3,
x^2 - 3*x + 9,
x^3 - 3*x^2 + 3*x + 1,
x^3 - 3*x^2 + 3*x + 1,
x^3 - 3*x^2 + 3*x - 17,
x^6 - 3*x^5 + 6*x^4 - 11*x^3 + 12*x^2 + 3*x + 1]
sage: R.<t> = QQ[]
sage: L = NumberField(t^3 - 3*t + 1, 'c')
sage: [k[1] for k in L.subfields()]
[Ring morphism:
From: Number Field in c0 with defining polynomial t
To:   Number Field in c with defining polynomial t^3 - 3*t + 1
Defn: 0 |--> 0,
Ring morphism:
From: Number Field in c1 with defining polynomial t^3 - 3*t + 1
To:   Number Field in c with defining polynomial t^3 - 3*t + 1
Defn: c1 |--> c]
sage: len(L.subfields(2))
0
sage: len(L.subfields(1))
1

vector_space()

Return a vector space V and isomorphisms self –> V and V –> self.

OUTPUT:

• V - a vector space over the rational numbers
• from_V - an isomorphism from V to self
• to_V - an isomorphism from self to V

EXAMPLES:

sage: k.<a> = NumberField(x^3 + 2)
sage: V, from_V, to_V  = k.vector_space()
sage: from_V(V([1,2,3]))
3*a^2 + 2*a + 1
sage: to_V(1 + 2*a + 3*a^2)
(1, 2, 3)
sage: V
Vector space of dimension 3 over Rational Field
sage: to_V
Isomorphism map:
From: Number Field in a with defining polynomial x^3 + 2
To:   Vector space of dimension 3 over Rational Field
sage: from_V(to_V(2/3*a - 5/8))
2/3*a - 5/8
sage: to_V(from_V(V([0,-1/7,0])))
(0, -1/7, 0)

sage.rings.number_field.number_field.NumberField_absolute_v1(poly, name, latex_name, canonical_embedding=None)

This is used in pickling generic number fields.

EXAMPLES:

sage: from sage.rings.number_field.number_field import NumberField_absolute_v1
sage: R.<x> = QQ[]
sage: NumberField_absolute_v1(x^2 + 1, 'i', 'i')
Number Field in i with defining polynomial x^2 + 1

class sage.rings.number_field.number_field.NumberField_cyclotomic(n, names, embedding=None, assume_disc_small=False, maximize_at_primes=None)

Create a cyclotomic extension of the rational field.

The command CyclotomicField(n) creates the n-th cyclotomic field, obtained by adjoining an n-th root of unity to the rational field.

EXAMPLES:

sage: CyclotomicField(3)
Cyclotomic Field of order 3 and degree 2
sage: CyclotomicField(18)
Cyclotomic Field of order 18 and degree 6
sage: z = CyclotomicField(6).gen(); z
zeta6
sage: z^3
-1
sage: (1+z)^3
6*zeta6 - 3

sage: K = CyclotomicField(197)
True
True

sage: cf12 = CyclotomicField( 12 )
sage: z12 = cf12.0
sage: cf6 = CyclotomicField( 6 )
sage: z6 = cf6.0
sage: FF = Frac( cf12['x'] )
sage: x = FF.0
sage: z6*x^3/(z6 + x)
zeta12^2*x^3/(x + zeta12^2)

sage: cf6 = CyclotomicField(6) ; z6 = cf6.gen(0)
sage: cf3 = CyclotomicField(3) ; z3 = cf3.gen(0)
sage: cf3(z6)
zeta3 + 1
sage: cf6(z3)
zeta6 - 1
sage: type(cf6(z3))
sage: cf1 = CyclotomicField(1) ; z1 = cf1.0
sage: cf3(z1)
1
sage: type(cf3(z1))

complex_embedding(prec=53)

Return the embedding of this cyclotomic field into the approximate complex field with precision prec obtained by sending the generator $$\zeta$$ of self to exp(2*pi*i/n), where $$n$$ is the multiplicative order of $$\zeta$$.

EXAMPLES:

sage: C = CyclotomicField(4)
sage: C.complex_embedding()
Ring morphism:
From: Cyclotomic Field of order 4 and degree 2
To:   Complex Field with 53 bits of precision
Defn: zeta4 |--> 6.12323399573677e-17 + 1.00000000000000*I


Note in the example above that the way zeta is computed (using sin and cosine in MPFR) means that only the prec bits of the number after the decimal point are valid.

sage: K = CyclotomicField(3)
sage: phi = K.complex_embedding(10)
sage: phi(K.0)
-0.50 + 0.87*I
sage: phi(K.0^3)
1.0
sage: phi(K.0^3 - 1)
0.00
sage: phi(K.0^3 + 7)
8.0

complex_embeddings(prec=53)

Return all embeddings of this cyclotomic field into the approximate complex field with precision prec.

If you want 53-bit double precision, which is faster but less reliable, then do self.embeddings(CDF).

EXAMPLES:

sage: CyclotomicField(5).complex_embeddings()
[
Ring morphism:
From: Cyclotomic Field of order 5 and degree 4
To:   Complex Field with 53 bits of precision
Defn: zeta5 |--> 0.309016994374947 + 0.951056516295154*I,
Ring morphism:
From: Cyclotomic Field of order 5 and degree 4
To:   Complex Field with 53 bits of precision
Defn: zeta5 |--> -0.809016994374947 + 0.587785252292473*I,
Ring morphism:
From: Cyclotomic Field of order 5 and degree 4
To:   Complex Field with 53 bits of precision
Defn: zeta5 |--> -0.809016994374947 - 0.587785252292473*I,
Ring morphism:
From: Cyclotomic Field of order 5 and degree 4
To:   Complex Field with 53 bits of precision
Defn: zeta5 |--> 0.309016994374947 - 0.951056516295154*I
]

construction()

x.__init__(...) initializes x; see help(type(x)) for signature

different()

Returns the different ideal of the cyclotomic field self.

EXAMPLES:

sage: C20 = CyclotomicField(20)
sage: C20.different()
Fractional ideal (10, 2*zeta20^6 - 4*zeta20^4 - 4*zeta20^2 + 2)
sage: C18 = CyclotomicField(18)
sage: D = C18.different().norm()
sage: D == C18.discriminant().abs()
True

discriminant(v=None)

Returns the discriminant of the ring of integers of the cyclotomic field self, or if v is specified, the determinant of the trace pairing on the elements of the list v.

Uses the formula for the discriminant of a prime power cyclotomic field and Hilbert Theorem 88 on the discriminant of composita.

INPUT:

• v (optional) - list of element of this number field

OUTPUT: Integer if v is omitted, and Rational otherwise.

EXAMPLES:

sage: CyclotomicField(20).discriminant()
4000000
sage: CyclotomicField(18).discriminant()
-19683

is_galois()

Return True since all cyclotomic fields are automatically Galois.

EXAMPLES:

sage: CyclotomicField(29).is_galois()
True

is_isomorphic(other)

Return True if the cyclotomic field self is isomorphic as a number field to other.

EXAMPLES:

sage: CyclotomicField(11).is_isomorphic(CyclotomicField(22))
True
sage: CyclotomicField(11).is_isomorphic(CyclotomicField(23))
False
sage: CyclotomicField(3).is_isomorphic(NumberField(x^2 + x +1, 'a'))
True
sage: CyclotomicField(18).is_isomorphic(CyclotomicField(9))
True
sage: CyclotomicField(10).is_isomorphic(NumberField(x^4 - x^3 + x^2 - x + 1, 'b'))
True


Check trac ticket #14300:

sage: K = CyclotomicField(4)
sage: N = K.extension(x^2-5, 'z')
sage: K.is_isomorphic(N)
False
sage: K.is_isomorphic(CyclotomicField(8))
False

next_split_prime(p=2)

Return the next prime integer $$p$$ that splits completely in this cyclotomic field (and does not ramify).

EXAMPLES:

sage: K.<z> = CyclotomicField(3)
sage: K.next_split_prime(7)
13

number_of_roots_of_unity()

Return number of roots of unity in this cyclotomic field.

EXAMPLES:

sage: K.<a> = CyclotomicField(21)
sage: K.number_of_roots_of_unity()
42

real_embeddings(prec=53)

Return all embeddings of this cyclotomic field into the approximate real field with precision prec.

Mostly, of course, there are no such embeddings.

EXAMPLES:

sage: CyclotomicField(4).real_embeddings()
[]
sage: CyclotomicField(2).real_embeddings()
[
Ring morphism:
From: Cyclotomic Field of order 2 and degree 1
To:   Real Field with 53 bits of precision
Defn: -1 |--> -1.00000000000000
]

roots_of_unity()

Return all the roots of unity in this cyclotomic field, primitive or not.

EXAMPLES:

sage: K.<a> = CyclotomicField(3)
sage: zs = K.roots_of_unity(); zs
[1, a, -a - 1, -1, -a, a + 1]
sage: [ z**K.number_of_roots_of_unity() for z in zs ]
[1, 1, 1, 1, 1, 1]

signature()

Return (r1, r2), where r1 and r2 are the number of real embeddings and pairs of complex embeddings of this cyclotomic field, respectively.

Trivial since, apart from QQ, cyclotomic fields are totally complex.

EXAMPLES:

sage: CyclotomicField(5).signature()
(0, 2)
sage: CyclotomicField(2).signature()
(1, 0)

zeta(n=None, all=False)

Returns an element of multiplicative order $$n$$ in this this cyclotomic field, if there is one. Raises a ValueError if there is not.

INPUT:

• n - integer (default: None, returns element of maximal order)
• all - bool (default: False) - whether to return a list of all n-th roots.

OUTPUT: root of unity or list

EXAMPLES:

sage: k = CyclotomicField(7)
sage: k.zeta()
zeta7
sage: k.zeta().multiplicative_order()
7
sage: k = CyclotomicField(49)
sage: k.zeta().multiplicative_order()
49
sage: k.zeta(7).multiplicative_order()
7
sage: k.zeta()
zeta49
sage: k.zeta(7)
zeta49^7

sage: K.<a> = CyclotomicField(7)
sage: K.zeta(14, all=True)
[-a^4, -a^5, a^5 + a^4 + a^3 + a^2 + a + 1, -a, -a^2, -a^3]
sage: K.<a> = CyclotomicField(10)
sage: K.zeta(20, all=True)
Traceback (most recent call last):
...
ValueError: n (=20) does not divide order of generator

sage: K.<a> = CyclotomicField(5)
sage: K.zeta(4)
Traceback (most recent call last):
...
ValueError: n (=4) does not divide order of generator
sage: v = K.zeta(5, all=True); v
[a, a^2, a^3, -a^3 - a^2 - a - 1]
sage: [b^5 for b in v]
[1, 1, 1, 1]

zeta_order()

Return the order of the maximal root of unity contained in this cyclotomic field.

EXAMPLES:

sage: CyclotomicField(1).zeta_order()
2
sage: CyclotomicField(4).zeta_order()
4
sage: CyclotomicField(5).zeta_order()
10
sage: CyclotomicField(5)._n()
5
sage: CyclotomicField(389).zeta_order()
778

sage.rings.number_field.number_field.NumberField_cyclotomic_v1(zeta_order, name, canonical_embedding=None)

This is used in pickling cyclotomic fields.

EXAMPLES:

sage: from sage.rings.number_field.number_field import NumberField_cyclotomic_v1
sage: NumberField_cyclotomic_v1(5,'a')
Cyclotomic Field of order 5 and degree 4
sage: NumberField_cyclotomic_v1(5,'a').variable_name()
'a'

class sage.rings.number_field.number_field.NumberField_generic(polynomial, name, latex_name=None, check=True, embedding=None, category=None, assume_disc_small=False, maximize_at_primes=None, structure=None)

Generic class for number fields defined by an irreducible polynomial over $$\QQ$$.

EXAMPLES:

sage: K.<a> = NumberField(x^3 - 2); K
Number Field in a with defining polynomial x^3 - 2
sage: TestSuite(K).run()

S_class_group(S, proof=None, names='c')

Returns the S-class group of this number field over its base field.

INPUT:

• S - a set of primes of the base field
• proof - if False, assume the GRH in computing the class group. Default is True. Call number_field_proof to change this default globally.
• names - names of the generators of this class group.

OUTPUT:

The S-class group of this number field.

EXAMPLE:

A well known example:

sage: K.<a> = QuadraticField(-5)
sage: K.S_class_group([])
S-class group of order 2 with structure C2 of Number Field in a with defining polynomial x^2 + 5


When we include the prime $$(2, a+1)$$, the S-class group becomes trivial:

sage: K.S_class_group([K.ideal(2,a+1)])
S-class group of order 1 of Number Field in a with defining polynomial x^2 + 5


TESTS:

sage: K.<a> = QuadraticField(-14)
sage: I = K.ideal(2,a)
sage: S = (I,)
sage: CS = K.S_class_group(S);CS
S-class group of order 2 with structure C2 of Number Field in a with defining polynomial x^2 + 14
sage: T = tuple([])
sage: CT = K.S_class_group(T);CT
S-class group of order 4 with structure C4 of Number Field in a with defining polynomial x^2 + 14
sage: K.class_group()
Class group of order 4 with structure C4 of Number Field in a with defining polynomial x^2 + 14

S_unit_group(proof=None, S=None)

Return the S-unit group (including torsion) of this number field.

ALGORITHM: Uses PARI’s bnfsunit command.

INPUT:

• proof (bool, default True) flag passed to pari.
• S - list or tuple of prime ideals, or an ideal, or a single ideal or element from which an ideal can be constructed, in which case the support is used. If None, the global unit group is constructed; otherwise, the S-unit group is constructed.

Note

The group is cached.

EXAMPLES:

sage: x = polygen(QQ)
sage: K.<a> = NumberField(x^4 - 10*x^3 + 20*5*x^2 - 15*5^2*x + 11*5^3)
sage: U = K.S_unit_group(S=a); U
S-unit group with structure C10 x Z x Z x Z of Number Field in a with defining polynomial x^4 - 10*x^3 + 100*x^2 - 375*x + 1375 with S = (Fractional ideal (5, 1/275*a^3 + 4/55*a^2 - 5/11*a + 5), Fractional ideal (11, 1/275*a^3 + 4/55*a^2 - 5/11*a + 9))
sage: U.gens()
(u0, u1, u2, u3)
sage: U.gens_values()
[-7/275*a^3 + 1/11*a^2 - 9/11*a - 1, 6/275*a^3 - 9/55*a^2 + 14/11*a - 2, 1/275*a^3 + 4/55*a^2 - 5/11*a + 5, -14/275*a^3 + 21/55*a^2 - 29/11*a + 6]
sage: U.invariants()
(10, 0, 0, 0)
sage: [u.multiplicative_order() for u in U.gens()]
[10, +Infinity, +Infinity, +Infinity]
sage: U.primes()
(Fractional ideal (5, 1/275*a^3 + 4/55*a^2 - 5/11*a + 5), Fractional ideal (11, 1/275*a^3 + 4/55*a^2 - 5/11*a + 9))


With the default value of $$S$$, the S-unit group is the same as the global unit group:

sage: x = polygen(QQ)
sage: K.<a> = NumberField(x^3 + 3)
sage: U = K.unit_group(proof=False)
sage: U == K.S_unit_group(proof=False)
True


The value of $$S$$ may be specified as a list of prime ideals, or an ideal, or an element of the field:

sage: K.<a> = NumberField(x^3 + 3)
sage: U = K.S_unit_group(proof=False, S=K.ideal(6).prime_factors()); U
S-unit group with structure C2 x Z x Z x Z x Z of Number Field in a with defining polynomial x^3 + 3 with S = (Fractional ideal (-a^2 + a - 1), Fractional ideal (a + 1), Fractional ideal (a))
sage: K.<a> = NumberField(x^3 + 3)
sage: U = K.S_unit_group(proof=False, S=K.ideal(6)); U
S-unit group with structure C2 x Z x Z x Z x Z of Number Field in a with defining polynomial x^3 + 3 with S = (Fractional ideal (-a^2 + a - 1), Fractional ideal (a + 1), Fractional ideal (a))
sage: K.<a> = NumberField(x^3 + 3)
sage: U = K.S_unit_group(proof=False, S=6); U
S-unit group with structure C2 x Z x Z x Z x Z of Number Field in a with defining polynomial x^3 + 3 with S = (Fractional ideal (-a^2 + a - 1), Fractional ideal (a + 1), Fractional ideal (a))

sage: U
S-unit group with structure C2 x Z x Z x Z x Z of Number Field in a with defining polynomial x^3 + 3 with S = (Fractional ideal (-a^2 + a - 1), Fractional ideal (a + 1), Fractional ideal (a))
sage: U.primes()
(Fractional ideal (-a^2 + a - 1),
Fractional ideal (a + 1),
Fractional ideal (a))
sage: U.gens()
(u0, u1, u2, u3, u4)
sage: U.gens_values()
[-1, a^2 - 2, -a^2 + a - 1, a + 1, a]


The exp and log methods can be used to create $$S$$-units from sequences of exponents, and recover the exponents:

sage: U.gens_orders()
(2, 0, 0, 0, 0)
sage: u = U.exp((3,1,4,1,5)); u
-6*a^2 + 18*a - 54
sage: u.norm().factor()
-1 * 2^9 * 3^5
sage: U.log(u)
(1, 1, 4, 1, 5)

S_units(S, proof=True)

Returns a list of generators of the S-units.

INPUT:

- S - a set of primes of the base field

• proof - if False, assume the GRH in computing the class group

OUTPUT:

A list of generators of the unit group.

Note

For more functionality see the S_unit_group() function.

EXAMPLE:

sage: K.<a> = QuadraticField(-3)
sage: K.unit_group()
Unit group with structure C6 of Number Field in a with defining polynomial x^2 + 3
sage: K.S_units([])
[-1/2*a + 1/2]
sage: K.S_units([])[0].multiplicative_order()
6


An example in a relative extension (see trac ticket #8722):

sage: L.<a,b> = NumberField([x^2 + 1, x^2 - 5])
sage: p = L.ideal((-1/2*b - 1/2)*a + 1/2*b - 1/2)
sage: W = L.S_units([p]); [x.norm() for x in W]
[9, 1, 1]


Our generators should have the correct parent (trac ticket #9367):

sage: _.<x> = QQ[]
sage: L.<alpha> = NumberField(x^3 + x + 1)
sage: p = L.S_units([ L.ideal(7) ])
sage: p[0].parent()
Number Field in alpha with defining polynomial x^3 + x + 1


TEST:

This checks that the multiple entries issue at trac ticket #9341 is fixed:

sage: _.<t> = QQ[]
sage: K.<T> = NumberField(t-1)
sage: I = K.ideal(2)
sage: K.S_units([I])
[2, -1]
sage: J = K.ideal(-2)
sage: K.S_units([I, J, I])
[2, -1]

absolute_degree()

Return the degree of self over $$\QQ$$.

EXAMPLES:

sage: NumberField(x^3 + x^2 + 997*x + 1, 'a').absolute_degree()
3
sage: NumberField(x + 1, 'a').absolute_degree()
1
sage: NumberField(x^997 + 17*x + 3, 'a', check=False).absolute_degree()
997

absolute_field(names)

Returns self as an absolute extension over QQ.

OUTPUT:

• K - this number field (since it is already absolute)

Also, K.structure() returns from_K and to_K, where from_K is an isomorphism from K to self and to_K is an isomorphism from self to K.

EXAMPLES:

sage: K = CyclotomicField(5)
sage: K.absolute_field('a')
Number Field in a with defining polynomial x^4 + x^3 + x^2 + x + 1

absolute_polynomial_ntl()

Alias for polynomial_ntl(). Mostly for internal use.

EXAMPLES:

sage: NumberField(x^2 + (2/3)*x - 9/17,'a').absolute_polynomial_ntl()
([-27 34 51], 51)

algebraic_closure()

Return the algebraic closure of self (which is QQbar).

EXAMPLES:

sage: K.<i> = QuadraticField(-1)
sage: K.algebraic_closure()
Algebraic Field
sage: K.<a> = NumberField(x^3-2)
sage: K.algebraic_closure()
Algebraic Field
sage: K = CyclotomicField(23)
sage: K.algebraic_closure()
Algebraic Field

change_generator(alpha, name=None, names=None)

Given the number field self, construct another isomorphic number field $$K$$ generated by the element alpha of self, along with isomorphisms from $$K$$ to self and from self to $$K$$.

EXAMPLES:

sage: L.<i> = NumberField(x^2 + 1); L
Number Field in i with defining polynomial x^2 + 1
sage: K, from_K, to_K = L.change_generator(i/2 + 3)
sage: K
Number Field in i0 with defining polynomial x^2 - 6*x + 37/4
sage: from_K
Ring morphism:
From: Number Field in i0 with defining polynomial x^2 - 6*x + 37/4
To:   Number Field in i with defining polynomial x^2 + 1
Defn: i0 |--> 1/2*i + 3
sage: to_K
Ring morphism:
From: Number Field in i with defining polynomial x^2 + 1
To:   Number Field in i0 with defining polynomial x^2 - 6*x + 37/4
Defn: i |--> 2*i0 - 6


We can also do

sage: K.<c>, from_K, to_K = L.change_generator(i/2 + 3); K
Number Field in c with defining polynomial x^2 - 6*x + 37/4


We compute the image of the generator $$\sqrt{-1}$$ of $$L$$.

sage: to_K(i)
2*c - 6


Note that the image is indeed a square root of -1.

sage: to_K(i)^2
-1
sage: from_K(to_K(i))
i
sage: to_K(from_K(c))
c

characteristic()

Return the characteristic of this number field, which is of course 0.

EXAMPLES:

sage: k.<a> = NumberField(x^99 + 2); k
Number Field in a with defining polynomial x^99 + 2
sage: k.characteristic()
0

class_group(proof=None, names='c')

Return the class group of the ring of integers of this number field.

INPUT:

• proof - if True then compute the class group provably correctly. Default is True. Call number_field_proof to change this default globally.
• names - names of the generators of this class group.

OUTPUT: The class group of this number field.

EXAMPLES:

sage: K.<a> = NumberField(x^2 + 23)
sage: G = K.class_group(); G
Class group of order 3 with structure C3 of Number Field in a with defining polynomial x^2 + 23
sage: G.0
Fractional ideal class (2, 1/2*a - 1/2)
sage: G.gens()
(Fractional ideal class (2, 1/2*a - 1/2),)

sage: G.number_field()
Number Field in a with defining polynomial x^2 + 23
sage: G is K.class_group()
True
sage: G is K.class_group(proof=False)
False
sage: G.gens()
(Fractional ideal class (2, 1/2*a - 1/2),)


There can be multiple generators:

sage: k.<a> = NumberField(x^2 + 20072)
sage: G = k.class_group(); G
Class group of order 76 with structure C38 x C2 of Number Field in a with defining polynomial x^2 + 20072
sage: G.0 # random
Fractional ideal class (41, a + 10)
sage: G.0^38
Trivial principal fractional ideal class
sage: G.1 # random
Fractional ideal class (2, -1/2*a)
sage: G.1^2
Trivial principal fractional ideal class


Class groups of Hecke polynomials tend to be very small:

sage: f = ModularForms(97, 2).T(2).charpoly()
sage: f.factor()
(x - 3) * (x^3 + 4*x^2 + 3*x - 1) * (x^4 - 3*x^3 - x^2 + 6*x - 1)
sage: [NumberField(g,'a').class_group().order() for g,_ in f.factor()]
[1, 1, 1]

class_number(proof=None)

Return the class number of this number field, as an integer.

INPUT:

• proof - bool (default: True unless you called number_field_proof)

EXAMPLES:

sage: NumberField(x^2 + 23, 'a').class_number()
3
sage: NumberField(x^2 + 163, 'a').class_number()
1
sage: NumberField(x^3 + x^2 + 997*x + 1, 'a').class_number(proof=False)
1539

completion(p, prec, extras={})

Returns the completion of self at $$p$$ to the specified precision. Only implemented at archimedean places, and then only if an embedding has been fixed.

EXAMPLES:

sage: K.<a> = QuadraticField(2)
sage: K.completion(infinity, 100)
Real Field with 100 bits of precision
sage: K.<zeta> = CyclotomicField(12)
sage: K.completion(infinity, 53, extras={'type': 'RDF'})
Complex Double Field
sage: zeta + 1.5                            # implicit test
2.36602540378444 + 0.500000000000000*I

complex_conjugation()

Return the complex conjugation of self.

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: QuadraticField(-1, 'I').complex_conjugation()
Ring endomorphism of Number Field in I with defining polynomial x^2 + 1
Defn: I |--> -I
sage: CyclotomicField(8).complex_conjugation()
Ring endomorphism of Cyclotomic Field of order 8 and degree 4
Defn: zeta8 |--> -zeta8^3
Identity endomorphism of Number Field in a with defining polynomial x^2 - 5
sage: F = NumberField(x^4 + x^3 - 3*x^2 - x + 1, 'a')
sage: F.is_totally_real()
True
sage: F.complex_conjugation()
Identity endomorphism of Number Field in a with defining polynomial x^4 + x^3 - 3*x^2 - x + 1
sage: F.<b> = NumberField(x^2 - 2)
sage: F.extension(x^2 + 1, 'a').complex_conjugation()
Relative number field endomorphism of Number Field in a with defining polynomial x^2 + 1 over its base field
Defn: a |--> -a
b |--> b
sage: F2.<b> = NumberField(x^2 + 2)
sage: K2.<a> = F2.extension(x^2 + 1)
sage: cc = K2.complex_conjugation()
sage: cc(a)
-a
sage: cc(b)
-b

complex_embeddings(prec=53)

Return all homomorphisms of this number field into the approximate complex field with precision prec.

This always embeds into an MPFR based complex field. If you want embeddings into the 53-bit double precision, which is faster, use self.embeddings(CDF).

EXAMPLES:

sage: k.<a> = NumberField(x^5 + x + 17)
sage: v = k.complex_embeddings()
sage: ls = [phi(k.0^2) for phi in v] ; ls # random order
[2.97572074038...,
-2.40889943716 + 1.90254105304*I,
-2.40889943716 - 1.90254105304*I,
0.921039066973 + 3.07553311885*I,
0.921039066973 - 3.07553311885*I]
sage: K.<a> = NumberField(x^3 + 2)
sage: ls = K.complex_embeddings() ; ls # random order
[
Ring morphism:
From: Number Field in a with defining polynomial x^3 + 2
To:   Complex Double Field
Defn: a |--> -1.25992104989...,
Ring morphism:
From: Number Field in a with defining polynomial x^3 + 2
To:   Complex Double Field
Defn: a |--> 0.629960524947 - 1.09112363597*I,
Ring morphism:
From: Number Field in a with defining polynomial x^3 + 2
To:   Complex Double Field
Defn: a |--> 0.629960524947 + 1.09112363597*I
]

composite_fields(other, names=None, both_maps=False, preserve_embedding=True)

List of all possible composite number fields formed from self and other, together with (optionally) embeddings into the compositum; see the documentation for both_maps below.

If preserve_embedding is True and if self and other both have embeddings into the same ambient field, or into fields which are contained in a common field, only the compositum respecting both embeddings is returned. If one (or both) of self or other does not have an embedding or preserve_embedding is False, all possible composite number fields are returned.

INPUT:

• other - a number field
• names - generator name for composite fields
• both_maps - (default: False) if True, return quadruples (F, self_into_F, other_into_F, k) such that self_into_F is an embedding of self in F, other_into_F is an embedding of in F, and k is an integer such that F.gen() equals other_into_F(other.gen()) + k*self_into_F(self.gen()) or has the value Infinity in which case F.gen() equals self_into_F(self.gen()), or is None (which happens when other is a relative number field). If both self and other have embeddings into an ambient field, then F will have an embedding with respect to which both self_into_F and other_into_F will be compatible with the ambient embeddings.
• preserve_embedding - (default: True) if self and other have ambient embeddings, then return only the compatible compositum.

OUTPUT:

• list - list of the composite fields, possibly with maps.

EXAMPLES:

sage: K.<a> = NumberField(x^4 - 2)
sage: K.composite_fields(K)
[Number Field in a with defining polynomial x^4 - 2,
Number Field in a0 with defining polynomial x^8 + 28*x^4 + 2500]


A particular compositum is selected, together with compatible maps into the compositum, if the fields are endowed with a real or complex embedding:

sage: K1 = NumberField(x^4 - 2, 'a', embedding=RR(2^(1/4)))
sage: K2 = NumberField(x^4 - 2, 'a', embedding=RR(-2^(1/4)))
sage: K1.composite_fields(K2)
[Number Field in a with defining polynomial x^4 - 2]
sage: [F, f, g, k], = K1.composite_fields(K2, both_maps=True); F
Number Field in a with defining polynomial x^4 - 2
sage: f(K1.0), g(K2.0)
(a, -a)


With preserve_embedding set to False, the embeddings are ignored:

sage: K1.composite_fields(K2, preserve_embedding=False)
[Number Field in a with defining polynomial x^4 - 2,
Number Field in a0 with defining polynomial x^8 + 28*x^4 + 2500]


Changing the embedding selects a different compositum:

sage: K3 = NumberField(x^4 - 2, 'a', embedding=CC(2^(1/4)*I))
sage: [F, f, g, k], = K1.composite_fields(K3, both_maps=True); F
Number Field in a0 with defining polynomial x^8 + 28*x^4 + 2500
sage: f(K1.0), g(K3.0)
(1/240*a0^5 - 41/120*a0, 1/120*a0^5 + 19/60*a0)


If no embeddings are specified, the maps into the composite are chosen arbitrarily:

sage: Q1.<a> = NumberField(x^4 + 10*x^2 + 1)
sage: Q2.<b> = NumberField(x^4 + 16*x^2 + 4)
sage: Q1.composite_fields(Q2, 'c')
[Number Field in c with defining polynomial x^8 + 64*x^6 + 904*x^4 + 3840*x^2 + 3600]
sage: F, Q1_into_F, Q2_into_F, k = Q1.composite_fields(Q2, 'c', both_maps=True)[0]
sage: Q1_into_F
Ring morphism:
From: Number Field in a with defining polynomial x^4 + 10*x^2 + 1
To:   Number Field in c with defining polynomial x^8 + 64*x^6 + 904*x^4 + 3840*x^2 + 3600
Defn: a |--> 19/14400*c^7 + 137/1800*c^5 + 2599/3600*c^3 + 8/15*c

This is just one of four embeddings of Q1 into F::
sage: Hom(Q1, F).order() 4

TESTS:

Let’s check that embeddings are being respected:

sage: x = polygen(ZZ)
sage: K0.<b> = CyclotomicField(7, 'a').subfields(3)[0][0].change_names()
sage: K1.<a1> = K0.extension(x^2 - 2*b^2, 'a1').absolute_field()
sage: K2.<a2> = K0.extension(x^2 - 3*b^2, 'a2').absolute_field()


We need embeddings, so we redefine:

sage: L1.<a1> = NumberField(K1.polynomial(), 'a1', embedding=CC.0)
sage: L2.<a2> = NumberField(K2.polynomial(), 'a2', embedding=CC.0)
sage: [CDF(a1), CDF(a2)]
[-0.6293842454258951, -0.7708351267200304]


and we get the same embeddings via the compositum:

sage: F, L1_into_F, L2_into_F, k = L1.composite_fields(L2, both_maps=True)[0]
sage: [CDF(L1_into_F(L1.gen())), CDF(L2_into_F(L2.gen()))]
[-0.6293842454258959, -0.7708351267200312]


Let’s check that if only one field has an embedding, the resulting fields do not have embeddings:

sage: L1.composite_fields(K2)[0].coerce_embedding() is None
True
sage: L2.composite_fields(K1)[0].coerce_embedding() is None
True


We check that other can be a relative number field:

sage: L.<a, b> = NumberField([x^3 - 5, x^2 + 3])
sage: CyclotomicField(3, 'w').composite_fields(L, both_maps=True)
[(Number Field in a with defining polynomial x^3 - 5 over its base field, Ring morphism:
From: Cyclotomic Field of order 3 and degree 2
To:   Number Field in a with defining polynomial x^3 - 5 over its base field
Defn: w |--> -1/2*b - 1/2, Relative number field endomorphism of Number Field in a with defining polynomial x^3 - 5 over its base field
Defn: a |--> a
b |--> b, None)]

construction()

Construction of self

EXAMPLE:

sage: K.<a>=NumberField(x^3+x^2+1,embedding=CC.gen())
sage: F,R = K.construction()
sage: F
AlgebraicExtensionFunctor
sage: R
Rational Field
sage: F(R) == K
True


Note that, if a number field is provided with an embedding, the construction functor applied to the rationals is not necessarily identic with the number field. The reason is that the construction functor uses a value for the embedding that is equivalent, but not necessarily equal, to the one provided in the definition of the number field:

sage: F(R) is K
False
sage: F.embeddings
[0.2327856159383841? + 0.7925519925154479?*I]


TEST:

sage: K.<a> = NumberField(x^3+x+1)
sage: R.<t> = ZZ[]
sage: a+t     # indirect doctest
t + a
sage: (a+t).parent()
Univariate Polynomial Ring in t over Number Field in a with defining polynomial x^3 + x + 1


The construction works for non-absolute number fields as well:

sage: K.<a,b,c>=NumberField([x^3+x^2+1,x^2+1,x^7+x+1])
sage: F,R = K.construction()
sage: F(R) == K
True

sage: P.<x> = QQ[]
sage: K.<a> = NumberField(x^3-5,embedding=0)
sage: L.<b> = K.extension(x^2+a)
sage: a*b
a*b

defining_polynomial()

Return the defining polynomial of this number field.

This is exactly the same as self.polynomal().

EXAMPLES:

sage: k5.<z> = CyclotomicField(5)
sage: k5.defining_polynomial()
x^4 + x^3 + x^2 + x + 1
sage: y = polygen(QQ,'y')
sage: k.<a> = NumberField(y^9 - 3*y + 5); k
Number Field in a with defining polynomial y^9 - 3*y + 5
sage: k.defining_polynomial()
y^9 - 3*y + 5

degree()

Return the degree of this number field.

EXAMPLES:

sage: NumberField(x^3 + x^2 + 997*x + 1, 'a').degree()
3
sage: NumberField(x + 1, 'a').degree()
1
sage: NumberField(x^997 + 17*x + 3, 'a', check=False).degree()
997

different()

Compute the different fractional ideal of this number field.

The codifferent is the fractional ideal of all $$x$$ in $$K$$ such that the the trace of $$xy$$ is an integer for all $$y \in O_K$$.

The different is the integral ideal which is the inverse of the codifferent.

EXAMPLES:

sage: k.<a> = NumberField(x^2 + 23)
sage: d = k.different()
sage: d
Fractional ideal (-a)
sage: d.norm()
23
sage: k.disc()
-23


The different is cached:

sage: d is k.different()
True


Another example:

sage: k.<b> = NumberField(x^2 - 123)
sage: d = k.different(); d
Fractional ideal (2*b)
sage: d.norm()
492
sage: k.disc()
492

disc(v=None)

Shortcut for self.discriminant.

EXAMPLES:

sage: k.<b> = NumberField(x^2 - 123)
sage: k.disc()
492

discriminant(v=None)

Returns the discriminant of the ring of integers of the number field, or if v is specified, the determinant of the trace pairing on the elements of the list v.

INPUT:

• v (optional) - list of element of this number field

OUTPUT: Integer if v is omitted, and Rational otherwise.

EXAMPLES:

sage: K.<t> = NumberField(x^3 + x^2 - 2*x + 8)
sage: K.disc()
-503
sage: K.disc([1, t, t^2])
-2012
sage: K.disc([1/7, (1/5)*t, (1/3)*t^2])
-2012/11025
sage: (5*7*3)^2
11025
sage: NumberField(x^2 - 1/2, 'a').discriminant()
8

elements_of_norm(n, proof=None)

Return a list of solutions modulo units of positive norm to $$Norm(a) = n$$, where a can be any integer in this number field.

INPUT:

• proof - default: True, unless you called number_field_proof and set it otherwise.

EXAMPLES:

sage: K.<a> = NumberField(x^2+1)
sage: K.elements_of_norm(3)
[]
sage: K.elements_of_norm(50)
[-7*a + 1, -5*a - 5, a - 7]

extension(poly, name=None, names=None, check=True, embedding=None, latex_name=None, structure=None)

Return the relative extension of this field by a given polynomial.

EXAMPLES:

sage: K.<a> = NumberField(x^3 - 2)
sage: R.<t> = K[]
sage: L.<b> = K.extension(t^2 + a); L
Number Field in b with defining polynomial t^2 + a over its base field


We create another extension:

sage: k.<a> = NumberField(x^2 + 1); k
Number Field in a with defining polynomial x^2 + 1
sage: y = var('y')
sage: m.<b> = k.extension(y^2 + 2); m
Number Field in b with defining polynomial y^2 + 2 over its base field


Note that b is a root of $$y^2 + 2$$:

sage: b.minpoly()
x^2 + 2
sage: b.minpoly('z')
z^2 + 2


A relative extension of a relative extension:

sage: k.<a> = NumberField([x^2 + 1, x^3 + x + 1])
sage: R.<z> = k[]
sage: L.<b> = NumberField(z^3 + 3 + a); L
Number Field in b with defining polynomial z^3 + a0 + 3 over its base field

factor(n)

Ideal factorization of the principal ideal generated by $$n$$.

EXAMPLES:

Here we show how to factor Gaussian integers (up to units). First we form a number field defined by $$x^2 + 1$$:

sage: K.<I> = NumberField(x^2 + 1); K
Number Field in I with defining polynomial x^2 + 1


Here are the factors:

sage: fi, fj = K.factor(17); fi,fj
((Fractional ideal (I + 4), 1), (Fractional ideal (I - 4), 1))


Now we extract the reduced form of the generators:

sage: zi = fi[0].gens_reduced()[0]; zi
I + 4
sage: zj = fj[0].gens_reduced()[0]; zj
I - 4


We recover the integer that was factored in $$\ZZ[i]$$ (up to a unit):

sage: zi*zj
-17


One can also factor elements or ideals of the number field:

sage: K.<a> = NumberField(x^2 + 1)
sage: K.factor(1/3)
(Fractional ideal (3))^-1
sage: K.factor(1+a)
Fractional ideal (a + 1)
sage: K.factor(1+a/5)
(Fractional ideal (a + 1)) * (Fractional ideal (-a - 2))^-1 * (Fractional ideal (2*a + 1))^-1 * (Fractional ideal (-3*a - 2))


An example over a relative number field:

sage: pari('setrand(2)')
sage: L.<b> = K.extension(x^2 - 7)
sage: f = L.factor(a + 1); f
(Fractional ideal (1/2*a*b - a + 1/2)) * (Fractional ideal (-1/2*a*b - a + 1/2))
sage: f.value() == a+1
True


It doesn’t make sense to factor the ideal (0), so this raises an error:

sage: L.factor(0)
Traceback (most recent call last):
...
AttributeError: 'NumberFieldIdeal' object has no attribute 'factor'


AUTHORS:

• Alex Clemesha (2006-05-20), Francis Clarke (2009-04-21): examples
fractional_ideal(*gens, **kwds)

Return the ideal in $$\mathcal{O}_K$$ generated by gens. This overrides the sage.rings.ring.Field method to use the sage.rings.ring.Ring one instead, since we’re not really concerned with ideals in a field but in its ring of integers.

INPUT:

• gens - a list of generators, or a number field ideal.

EXAMPLES:

sage: K.<a> = NumberField(x^3-2)
sage: K.fractional_ideal([1/a])
Fractional ideal (1/2*a^2)


One can also input a number field ideal itself, or, more usefully, for a tower of number fields an ideal in one of the fields lower down the tower.

sage: K.fractional_ideal(K.ideal(a))
Fractional ideal (a)
sage: L.<b> = K.extension(x^2 - 3, x^2 + 1)
sage: M.<c> = L.extension(x^2 + 1)
sage: L.ideal(K.ideal(2, a))
Fractional ideal (a)
sage: M.ideal(K.ideal(2, a)) == M.ideal(a*(b - c)/2)
True


The zero ideal is not a fractional ideal!

sage: K.fractional_ideal(0)
Traceback (most recent call last):
...
ValueError: gens must have a nonzero element (zero ideal is not a fractional ideal)

galois_group(type=None, algorithm='pari', names=None)

Return the Galois group of the Galois closure of this number field.

INPUT:

• type - none, gap, or pari. If None (the default), return an explicit group of automorphisms of self as a GaloisGroup_v2 object. Otherwise, return a GaloisGroup_v1 wrapper object based on a PARI or Gap transitive group object, which is quicker to compute, but rather less useful (in particular, it can’t be made to act on self). If type = ‘gap’, the database_gap package should be installed.
• algorithm - ‘pari’, ‘kash’, ‘magma’. (default: ‘pari’, except when the degree is >= 12 when ‘kash’ is tried.)
• name - a string giving a name for the generator of the Galois closure of self, when self is not Galois. This is ignored if type is not None.

Note that computing Galois groups as abstract groups is often much faster than computing them as explicit automorphism groups (but of course you get less information out!) For more (important!) documentation, so the documentation for Galois groups of polynomials over $$\QQ$$, e.g., by typing K.polynomial().galois_group?, where $$K$$ is a number field.

To obtain actual field homomorphisms from the number field to its splitting field, use type=None.

EXAMPLES:

With type None:

sage: k.<b> = NumberField(x^2 - 14) # a Galois extension
sage: G = k.galois_group(); G
Galois group of Number Field in b with defining polynomial x^2 - 14
sage: G.gen(0)
(1,2)
sage: G.gen(0)(b)
-b
sage: G.artin_symbol(k.primes_above(3)[0])
(1,2)

sage: k.<b> = NumberField(x^3 - x + 1) # not Galois
sage: G = k.galois_group(names='c'); G
Galois group of Galois closure in c of Number Field in b with defining polynomial x^3 - x + 1
sage: G.gen(0)
(1,2,3)(4,5,6)


With type 'pari':

sage: NumberField(x^3-2, 'a').galois_group(type="pari")
Galois group PARI group [6, -1, 2, "S3"] of degree 3 of the Number Field in a with defining polynomial x^3 - 2

sage: NumberField(x-1, 'a').galois_group(type="gap")    # optional - database_gap
Galois group Transitive group number 1 of degree 1 of the Number Field in a with defining polynomial x - 1
sage: NumberField(x^2+2, 'a').galois_group(type="gap")  # optional - database_gap
Galois group Transitive group number 1 of degree 2 of the Number Field in a with defining polynomial x^2 + 2
sage: NumberField(x^3-2, 'a').galois_group(type="gap")  # optional - database_gap
Galois group Transitive group number 2 of degree 3 of the Number Field in a with defining polynomial x^3 - 2

sage: x = polygen(QQ)
sage: NumberField(x^3 + 2*x + 1, 'a').galois_group(type='gap')    # optional - database_gap
Galois group Transitive group number 2 of degree 3 of the Number Field in a with defining polynomial x^3 + 2*x + 1
sage: NumberField(x^3 + 2*x + 1, 'a').galois_group(algorithm='magma')   # optional - magma, , database_gap
Galois group Transitive group number 2 of degree 3 of the Number Field in a with defining polynomial x^3 + 2*x + 1


EXPLICIT GALOIS GROUP: We compute the Galois group as an explicit group of automorphisms of the Galois closure of a field.

sage: K.<a> = NumberField(x^3 - 2)
sage: L.<b1> = K.galois_closure(); L
Number Field in b1 with defining polynomial x^6 + 108
sage: G = End(L); G
Automorphism group of Number Field in b1 with defining polynomial x^6 + 108
sage: G.list()
[
Ring endomorphism of Number Field in b1 with defining polynomial x^6 + 108
Defn: b1 |--> b1,
...
Ring endomorphism of Number Field in b1 with defining polynomial x^6 + 108
Defn: b1 |--> -1/12*b1^4 - 1/2*b1
]
sage: G[2](b1)
1/12*b1^4 + 1/2*b1

gen(n=0)

Return the generator for this number field.

INPUT:

• n - must be 0 (the default), or an exception is raised.

EXAMPLES:

sage: k.<theta> = NumberField(x^14 + 2); k
Number Field in theta with defining polynomial x^14 + 2
sage: k.gen()
theta
sage: k.gen(1)
Traceback (most recent call last):
...
IndexError: Only one generator.

gen_embedding()

If an embedding has been specified, return the image of the generator under that embedding. Otherwise return None.

EXAMPLES:

sage: QuadraticField(-7, 'a').gen_embedding()
2.645751311064591?*I
sage: NumberField(x^2+7, 'a').gen_embedding() # None

ideal(*gens, **kwds)

K.ideal() returns a fractional ideal of the field, except for the zero ideal which is not a fractional ideal.

EXAMPLES:

sage: K.<i>=NumberField(x^2+1)
sage: K.ideal(2)
Fractional ideal (2)
sage: K.ideal(2+i)
Fractional ideal (i + 2)
sage: K.ideal(0)
Ideal (0) of Number Field in i with defining polynomial x^2 + 1

ideals_of_bdd_norm(bound)

All integral ideals of bounded norm.

INPUT:

• bound - a positive integer

OUTPUT: A dict of all integral ideals I such that Norm(I) <= bound, keyed by norm.

EXAMPLE:

sage: K.<a> = NumberField(x^2 + 23)
sage: d = K.ideals_of_bdd_norm(10)
sage: for n in d:
....:     print n
....:     for I in d[n]:
....:         print I
1
Fractional ideal (1)
2
Fractional ideal (2, 1/2*a - 1/2)
Fractional ideal (2, 1/2*a + 1/2)
3
Fractional ideal (3, 1/2*a - 1/2)
Fractional ideal (3, 1/2*a + 1/2)
4
Fractional ideal (4, 1/2*a + 3/2)
Fractional ideal (2)
Fractional ideal (4, 1/2*a + 5/2)
5
6
Fractional ideal (1/2*a - 1/2)
Fractional ideal (6, 1/2*a + 5/2)
Fractional ideal (6, 1/2*a + 7/2)
Fractional ideal (1/2*a + 1/2)
7
8
Fractional ideal (1/2*a + 3/2)
Fractional ideal (4, a - 1)
Fractional ideal (4, a + 1)
Fractional ideal (1/2*a - 3/2)
9
Fractional ideal (9, 1/2*a + 11/2)
Fractional ideal (3)
Fractional ideal (9, 1/2*a + 7/2)
10

integral_basis(v=None)

Returns a list containing a ZZ-basis for the full ring of integers of this number field.

INPUT:

• v - None, a prime, or a list of primes. See the documentation for self.maximal_order.

EXAMPLES:

sage: K.<a> = NumberField(x^5 + 10*x + 1)
sage: K.integral_basis()
[1, a, a^2, a^3, a^4]


Next we compute the ring of integers of a cubic field in which 2 is an “essential discriminant divisor”, so the ring of integers is not generated by a single element.

sage: K.<a> = NumberField(x^3 + x^2 - 2*x + 8)
sage: K.integral_basis()
[1, 1/2*a^2 + 1/2*a, a^2]


ALGORITHM: Uses the pari library (via _pari_integral_basis).

is_CM()

Return True if self is a CM field (i.e. a totally imaginary quadratic extension of a totally real field).

EXAMPLES:

sage: Q.<a> = NumberField(x - 1)
sage: Q.is_CM()
False
sage: K.<i> = NumberField(x^2 + 1)
sage: K.is_CM()
True
sage: L.<zeta20> = CyclotomicField(20)
sage: L.is_CM()
True
sage: K.is_CM()
True
sage: L.is_CM()
False
sage: F.<a> = NumberField(x^3 - 2)
sage: F.is_CM()
False
sage: F.<a> = NumberField(x^4-x^3-3*x^2+x+1)
sage: F.is_CM()
False


The following are non-CM totally imaginary fields.

sage: F.<a> = NumberField(x^4 + x^3 - x^2 - x + 1)
sage: F.is_totally_imaginary()
True
sage: F.is_CM()
False
sage: F2.<a> = NumberField(x^12 - 5*x^11 + 8*x^10 - 5*x^9 - \
x^8 + 9*x^7 + 7*x^6 - 3*x^5 + 5*x^4 + \
7*x^3 - 4*x^2 - 7*x + 7)
sage: F2.is_totally_imaginary()
True
sage: F2.is_CM()
False


The following is a non-cyclotomic CM field.

sage: M.<a> = NumberField(x^4 - x^3 - x^2 - 2*x + 4)
sage: M.is_CM()
True


Now, we construct a totally imaginary quadratic extension of a totally real field (which is not cyclotomic).

sage: E_0.<a> = NumberField(x^7 - 4*x^6 - 4*x^5 + 10*x^4 + 4*x^3 - \
6*x^2 - x + 1)
sage: E_0.is_totally_real()
True
sage: E.<b> = E_0.extension(x^2 + 1)
sage: E.is_CM()
True


Finally, a CM field that is given as an extension that is not CM.

sage: E_0.<a> = NumberField(x^2 - 4*x + 16)
sage: y = polygen(E_0)
sage: E.<z> = E_0.extension(y^2 - E_0.gen() / 2)
sage: E.is_CM()
True
sage: E.is_CM_extension()
False

is_absolute()

Returns True if self is an absolute field.

This function will be implemented in the derived classes.

EXAMPLES:

sage: K = CyclotomicField(5)
sage: K.is_absolute()
True

is_field(proof=True)

Return True since a number field is a field.

EXAMPLES:

sage: NumberField(x^5 + x + 3, 'c').is_field()
True

is_galois()

Return True if this number field is a Galois extension of $$\QQ$$.

EXAMPLES:

sage: NumberField(x^2 + 1, 'i').is_galois()
True
sage: NumberField(x^3 + 2, 'a').is_galois()
False

is_isomorphic(other)

Return True if self is isomorphic as a number field to other.

EXAMPLES:

sage: k.<a> = NumberField(x^2 + 1)
sage: m.<b> = NumberField(x^2 + 4)
sage: k.is_isomorphic(m)
True
sage: m.<b> = NumberField(x^2 + 5)
sage: k.is_isomorphic (m)
False

sage: k = NumberField(x^3 + 2, 'a')
sage: k.is_isomorphic(NumberField((x+1/3)^3 + 2, 'b'))
True
sage: k.is_isomorphic(NumberField(x^3 + 4, 'b'))
True
sage: k.is_isomorphic(NumberField(x^3 + 5, 'b'))
False

is_relative()

EXAMPLES:

sage: K.<a> = NumberField(x^10 - 2)
sage: K.is_absolute()
True
sage: K.is_relative()
False

is_totally_imaginary()

Return True if self is totally imaginary, and False otherwise.

Totally imaginary means that no isomorphic embedding of self into the complex numbers has image contained in the real numbers.

EXAMPLES:

sage: NumberField(x^2+2, 'alpha').is_totally_imaginary()
True
sage: NumberField(x^2-2, 'alpha').is_totally_imaginary()
False
sage: NumberField(x^4-2, 'alpha').is_totally_imaginary()
False

is_totally_real()

Return True if self is totally real, and False otherwise.

Totally real means that every isomorphic embedding of self into the complex numbers has image contained in the real numbers.

EXAMPLES:

sage: NumberField(x^2+2, 'alpha').is_totally_real()
False
sage: NumberField(x^2-2, 'alpha').is_totally_real()
True
sage: NumberField(x^4-2, 'alpha').is_totally_real()
False

latex_variable_name(name=None)

Return the latex representation of the variable name for this number field.

EXAMPLES:

sage: NumberField(x^2 + 3, 'a').latex_variable_name()
'a'
sage: NumberField(x^3 + 3, 'theta3').latex_variable_name()
'\theta_{3}'
sage: CyclotomicField(5).latex_variable_name()
'\zeta_{5}'

maximal_totally_real_subfield()

Return the maximal totally real subfield of self together with an embedding of it into self.

EXAMPLES:

sage: F.<a> = QuadraticField(11)
sage: F.maximal_totally_real_subfield()
[Number Field in a with defining polynomial x^2 - 11, Identity endomorphism of Number Field in a with defining polynomial x^2 - 11]
sage: F.maximal_totally_real_subfield()
[Rational Field, Natural morphism:
From: Rational Field
To:   Number Field in a with defining polynomial x^2 + 15]
sage: F.<a> = CyclotomicField(29)
sage: F.maximal_totally_real_subfield()
(Number Field in a0 with defining polynomial x^14 + x^13 - 13*x^12 - 12*x^11 + 66*x^10 + 55*x^9 - 165*x^8 - 120*x^7 + 210*x^6 + 126*x^5 - 126*x^4 - 56*x^3 + 28*x^2 + 7*x - 1, Ring morphism:
From: Number Field in a0 with defining polynomial x^14 + x^13 - 13*x^12 - 12*x^11 + 66*x^10 + 55*x^9 - 165*x^8 - 120*x^7 + 210*x^6 + 126*x^5 - 126*x^4 - 56*x^3 + 28*x^2 + 7*x - 1
To:   Cyclotomic Field of order 29 and degree 28
Defn: a0 |--> -a^27 - a^26 - a^25 - a^24 - a^23 - a^22 - a^21 - a^20 - a^19 - a^18 - a^17 - a^16 - a^15 - a^14 - a^13 - a^12 - a^11 - a^10 - a^9 - a^8 - a^7 - a^6 - a^5 - a^4 - a^3 - a^2 - 1)
sage: F.<a> = NumberField(x^3 - 2)
sage: F.maximal_totally_real_subfield()
[Rational Field, Conversion map:
From: Rational Field
To:   Number Field in a with defining polynomial x^3 - 2]
sage: F.<a> = NumberField(x^4 - x^3 - x^2 + x + 1)
sage: F.maximal_totally_real_subfield()
[Rational Field, Conversion map:
From: Rational Field
To:   Number Field in a with defining polynomial x^4 - x^3 - x^2 + x + 1]
sage: F.<a> = NumberField(x^4 - x^3 + 2*x^2 + x + 1)
sage: F.maximal_totally_real_subfield()
[Number Field in a1 with defining polynomial x^2 - x - 1, Ring morphism:
From: Number Field in a1 with defining polynomial x^2 - x - 1
To:   Number Field in a with defining polynomial x^4 - x^3 + 2*x^2 + x + 1
Defn: a1 |--> -1/2*a^3 - 1/2]
sage: F.<a> = NumberField(x^4-4*x^2-x+1)
sage: F.maximal_totally_real_subfield()
[Number Field in a with defining polynomial x^4 - 4*x^2 - x + 1, Identity endomorphism of Number Field in a with defining polynomial x^4 - 4*x^2 - x + 1]


An example of a relative extension where the base field is not the maximal totally real subfield.

sage: E_0.<a> = NumberField(x^2 - 4*x + 16)
sage: y = polygen(E_0)
sage: E.<z> = E_0.extension(y^2 - E_0.gen() / 2)
sage: E.maximal_totally_real_subfield()
[Number Field in z2 with defining polynomial x^2 - 6, Composite map:
From: Number Field in z2 with defining polynomial x^2 - 6
To:   Number Field in z with defining polynomial x^2 - 1/2*a over its base field
Defn:   Ring morphism:
From: Number Field in z2 with defining polynomial x^2 - 6
To:   Number Field in z with defining polynomial x^4 - 2*x^2 + 4
Defn: z2 |--> -1/2*z^3 + 2*z
then
Isomorphism map:
From: Number Field in z with defining polynomial x^4 - 2*x^2 + 4
To:   Number Field in z with defining polynomial x^2 - 1/2*a over its base field]

narrow_class_group(proof=None)

Return the narrow class group of this field.

INPUT:

• proof - default: None (use the global proof setting, which defaults to True).

EXAMPLES:

sage: NumberField(x^3+x+9, 'a').narrow_class_group()
Multiplicative Abelian group isomorphic to C2

ngens()

Return the number of generators of this number field (always 1).

OUTPUT: the python integer 1.

EXAMPLES:

sage: NumberField(x^2 + 17,'a').ngens()
1
sage: NumberField(x + 3,'a').ngens()
1
sage: k.<a> = NumberField(x + 3)
sage: k.ngens()
1
sage: k.0
-3

number_of_roots_of_unity()

Return the number of roots of unity in this field.

Note

We do not create the full unit group since that can be expensive, but we do use it if it is already known.

EXAMPLES:

sage: F.<alpha> = NumberField(x**22+3)
sage: F.zeta_order()
6
sage: F.<alpha> = NumberField(x**2-7)
sage: F.zeta_order()
2

order()

Return the order of this number field (always +infinity).

OUTPUT: always positive infinity

EXAMPLES:

sage: NumberField(x^2 + 19,'a').order()
+Infinity

pari_bnf(proof=None, units=True)

PARI big number field corresponding to this field.

INPUT:

• proof – If False, assume GRH. If True, run PARI’s bnfcertify() to make sure that the results are correct.
• units – (default: True) If True, insist on having fundamental units. If False, the units may or may not be computed.

OUTPUT:

The PARI bnf structure of this number field.

Warning

Even with proof=True, I wouldn’t trust this to mean that everything computed involving this number field is actually correct.

EXAMPLES:

sage: k.<a> = NumberField(x^2 + 1); k
Number Field in a with defining polynomial x^2 + 1
sage: len(k.pari_bnf())
10
sage: k.pari_bnf()[:4]
[[;], matrix(0,3), [;], ...]
sage: len(k.pari_nf())
9
sage: k.<a> = NumberField(x^7 + 7); k
Number Field in a with defining polynomial x^7 + 7
sage: dummy = k.pari_bnf(proof=True)

pari_nf(important=True)

PARI number field corresponding to this field.

This is the number field constructed using nfinit(). This is the same as the number field got by doing pari(self) or gp(self).

INPUT:

• important – (default: True) bool. If False, raise a RuntimeError if we need to do a difficult discriminant factorization. Useful when the PARI nf structure is useful but not strictly required, such as for factoring polynomials over this number field.

EXAMPLES:

sage: k.<a> = NumberField(x^4 - 3*x + 7); k
Number Field in a with defining polynomial x^4 - 3*x + 7
sage: k.pari_nf()[:4]
[y^4 - 3*y + 7, [0, 2], 85621, 1]
sage: pari(k)[:4]
[y^4 - 3*y + 7, [0, 2], 85621, 1]

sage: k.<a> = NumberField(x^4 - 3/2*x + 5/3); k
Number Field in a with defining polynomial x^4 - 3/2*x + 5/3
sage: k.pari_nf()
Traceback (most recent call last):
...
TypeError: Unable to coerce number field defined by non-integral polynomial to PARI.
sage: pari(k)
Traceback (most recent call last):
...
TypeError: Unable to coerce number field defined by non-integral polynomial to PARI.
sage: gp(k)
Traceback (most recent call last):
...
TypeError: Unable to coerce number field defined by non-integral polynomial to PARI.


With important=False, we simply bail out if we cannot easily factor the discriminant:

sage: p = next_prime(10^40); q = next_prime(10^41)
sage: K.<a> = NumberField(x^2 - p*q)
sage: K.pari_nf(important=False)
Traceback (most recent call last):
...
RuntimeError: Unable to factor discriminant with trial division


Next, we illustrate the maximize_at_primes and assume_disc_small parameters of the NumberField contructor. The following would take a very long time without the maximize_at_primes option:

sage: K.<a> = NumberField(x^2 - p*q, maximize_at_primes=[p])
sage: K.pari_nf()
[y^2 - 100000000000000000000...]


Since the discriminant is square-free, this also works:

sage: K.<a> = NumberField(x^2 - p*q, assume_disc_small=True)
sage: K.pari_nf()
[y^2 - 100000000000000000000...]

pari_polynomial(name='x')

PARI polynomial with integer coefficients corresponding to the polynomial that defines this number field.

By default, this is a polynomial in the variable “x”. PARI prefers integral polynomials, so we clear the denominator. Therefore, this is NOT the same as simply converting the defining polynomial to PARI.

EXAMPLES:

sage: y = polygen(QQ)
sage: k.<a> = NumberField(y^2 - 3/2*y + 5/3)
sage: k.pari_polynomial()
6*x^2 - 9*x + 10
sage: k.polynomial()._pari_()
x^2 - 3/2*x + 5/3
sage: k.pari_polynomial('a')
6*a^2 - 9*a + 10


This fails with arguments which are not a valid PARI variable name:

sage: k = QuadraticField(-1)
sage: k.pari_polynomial('I')
Traceback (most recent call last):
...
PariError: I already exists with incompatible valence
sage: k.pari_polynomial('i')
i^2 + 1
sage: k.pari_polynomial('theta')
Traceback (most recent call last):
...
PariError: theta already exists with incompatible valence

pari_rnfnorm_data(L, proof=True)

Return the PARI rnfisnorminit() data corresponding to the extension L/self.

EXAMPLES:

sage: x = polygen(QQ)
sage: K = NumberField(x^2 - 2, 'alpha')
sage: L = K.extension(x^2 + 5, 'gamma')
sage: ls = K.pari_rnfnorm_data(L) ; len(ls)
8

sage: K.<a> = NumberField(x^2 + x + 1)
sage: P.<X> = K[]
sage: L.<b> = NumberField(X^3 + a)
sage: ls = K.pari_rnfnorm_data(L); len(ls)
8

pari_zk()

Integral basis of the PARI number field corresponding to this field.

This is the same as pari_nf().getattr(‘zk’), but much faster.

EXAMPLES:

sage: k.<a> = NumberField(x^3 - 17)
sage: k.pari_zk()
[1, 1/3*y^2 - 1/3*y + 1/3, y]
sage: k.pari_nf().getattr('zk')
[1, 1/3*y^2 - 1/3*y + 1/3, y]

polynomial()

Return the defining polynomial of this number field.

This is exactly the same as self.defining_polynomal().

EXAMPLES:

sage: NumberField(x^2 + (2/3)*x - 9/17,'a').polynomial()
x^2 + 2/3*x - 9/17

polynomial_ntl()

Return defining polynomial of this number field as a pair, an ntl polynomial and a denominator.

This is used mainly to implement some internal arithmetic.

EXAMPLES:

sage: NumberField(x^2 + (2/3)*x - 9/17,'a').polynomial_ntl()
([-27 34 51], 51)

polynomial_quotient_ring()

Return the polynomial quotient ring isomorphic to this number field.

EXAMPLES:

sage: K = NumberField(x^3 + 2*x - 5, 'alpha')
sage: K.polynomial_quotient_ring()
Univariate Quotient Polynomial Ring in alpha over Rational Field with modulus x^3 + 2*x - 5

polynomial_ring()

Return the polynomial ring that we view this number field as being a quotient of (by a principal ideal).

EXAMPLES: An example with an absolute field:

sage: k.<a> = NumberField(x^2 + 3)
sage: y = polygen(QQ, 'y')
sage: k.<a> = NumberField(y^2 + 3)
sage: k.polynomial_ring()
Univariate Polynomial Ring in y over Rational Field


An example with a relative field:

sage: y = polygen(QQ, 'y')
sage: M.<a> = NumberField([y^3 + 97, y^2 + 1]); M
Number Field in a0 with defining polynomial y^3 + 97 over its base field
sage: M.polynomial_ring()
Univariate Polynomial Ring in y over Number Field in a1 with defining polynomial y^2 + 1

power_basis()

Return a power basis for this number field over its base field.

If this number field is represented as $$k[t]/f(t)$$, then the basis returned is $$1, t, t^2, \ldots, t^{d-1}$$ where $$d$$ is the degree of this number field over its base field.

EXAMPLES:

sage: K.<a> = NumberField(x^5 + 10*x + 1)
sage: K.power_basis()
[1, a, a^2, a^3, a^4]

sage: L.<b> = K.extension(x^2 - 2)
sage: L.power_basis()
[1, b]
sage: L.absolute_field('c').power_basis()
[1, c, c^2, c^3, c^4, c^5, c^6, c^7, c^8, c^9]

sage: M = CyclotomicField(15)
sage: M.power_basis()
[1, zeta15, zeta15^2, zeta15^3, zeta15^4, zeta15^5, zeta15^6, zeta15^7]

prime_above(x, degree=None)

Return a prime ideal of self lying over x.

INPUT:

• x: usually an element or ideal of self. It should be such that self.ideal(x) is sensible. This excludes x=0.
• degree (default: None): None or an integer. If one, find a prime above x of any degree. If an integer, find a prime above x such that the resulting residue field has exactly this degree.

OUTPUT: A prime ideal of self lying over x. If degree is specified and no such ideal exists, raises a ValueError.

EXAMPLES:

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

sage: P2 = F.prime_above(2)
sage: P2 # random
Fractional ideal (-t)
sage: 2 in P2
True
sage: P2.is_prime()
True
sage: P2.norm()
2

sage: P3 = F.prime_above(3)
sage: P3 # random
Fractional ideal (t + 1)
sage: 3 in P3
True
sage: P3.is_prime()
True
sage: P3.norm()
3


The ideal (3) is totally ramified in F, so there is no degree 2 prime above 3:

sage: F.prime_above(3, degree=2)
Traceback (most recent call last):
...
ValueError: No prime of degree 2 above Fractional ideal (3)
sage: [ id.residue_class_degree() for id, _ in F.ideal(3).factor() ]
[1]


Asking for a specific degree works:

sage: P5_1 = F.prime_above(5, degree=1)
sage: P5_1 # random
Fractional ideal (-t^2 - 1)
sage: P5_1.residue_class_degree()
1

sage: P5_2 = F.prime_above(5, degree=2)
sage: P5_2 # random
Fractional ideal (t^2 - 2*t - 1)
sage: P5_2.residue_class_degree()
2


Relative number fields are ok:

sage: G = F.extension(x^2 - 11, 'b')
sage: G.prime_above(7)
Fractional ideal (b + 2)


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

sage: F.prime_above(0)
Traceback (most recent call last):
...
AttributeError: 'NumberFieldIdeal' object has no attribute 'prime_factors'

prime_factors(x)

Return a list of the prime ideals of self which divide the ideal generated by $$x$$.

OUTPUT: list of prime ideals (a new list is returned each time this function is called)

EXAMPLES:

sage: K.<w> = NumberField(x^2 + 23)
sage: K.prime_factors(w + 1)
[Fractional ideal (2, 1/2*w - 1/2), Fractional ideal (2, 1/2*w + 1/2), Fractional ideal (3, 1/2*w + 1/2)]

primes_above(x, degree=None)

Return prime ideals of self lying over x.

INPUT:

• x: usually an element or ideal of self. It should be such that self.ideal(x) is sensible. This excludes x=0.
• degree (default: None): None or an integer. If None, find all primes above x of any degree. If an integer, find all primes above x such that the resulting residue field has exactly this degree.

OUTPUT: A list of prime ideals of self lying over x. If degree is specified and no such ideal exists, returns the empty list. The output is sorted by residue degree first, then by underlying prime (or equivalently, by norm).

EXAMPLES:

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

sage: P2s = F.primes_above(2)
sage: P2s # random
[Fractional ideal (-t)]
sage: all(2 in P2 for P2 in P2s)
True
sage: all(P2.is_prime() for P2 in P2s)
True
sage: [ P2.norm() for P2 in P2s ]
[2]

sage: P3s = F.primes_above(3)
sage: P3s # random
[Fractional ideal (t + 1)]
sage: all(3 in P3 for P3 in P3s)
True
sage: all(P3.is_prime() for P3 in P3s)
True
sage: [ P3.norm() for P3 in P3s ]
[3]


The ideal (3) is totally ramified in F, so there is no degree 2 prime above 3:

sage: F.primes_above(3, degree=2)
[]
sage: [ id.residue_class_degree() for id, _ in F.ideal(3).factor() ]
[1]


Asking for a specific degree works:

sage: P5_1s = F.primes_above(5, degree=1)
sage: P5_1s # random
[Fractional ideal (-t^2 - 1)]
sage: P5_1 = P5_1s[0]; P5_1.residue_class_degree()
1

sage: P5_2s = F.primes_above(5, degree=2)
sage: P5_2s # random
[Fractional ideal (t^2 - 2*t - 1)]
sage: P5_2 = P5_2s[0]; P5_2.residue_class_degree()
2


Works in relative extensions too:

sage: PQ.<X> = QQ[]
sage: F.<a, b> = NumberField([X^2 - 2, X^2 - 3])
sage: PF.<Y> = F[]
sage: K.<c> = F.extension(Y^2 - (1 + a)*(a + b)*a*b)
sage: I = F.ideal(a + 2*b)
sage: P, Q = K.primes_above(I)
sage: K.ideal(I) == P^4*Q
True
sage: K.primes_above(I, degree=1) == [P]
True
sage: K.primes_above(I, degree=4) == [Q]
True


It doesn’t make sense to factor the ideal (0), so this raises an error:

sage: F.prime_above(0)
Traceback (most recent call last):
...
AttributeError: 'NumberFieldIdeal' object has no attribute 'prime_factors'

primes_of_bounded_norm_iter(B)

Iterator yielding all prime ideals with norm at most $$B$$.

INPUT:

• B – a positive integer; upper bound on the norms of the primes generated.

OUTPUT:

An iterator over all prime ideals of this number field of norm at most $$B$$.

Note

The output is not sorted by norm, but by size of the underlying rational prime.

EXAMPLES:

sage: K.<i> = QuadraticField(-1)
sage: it = K.primes_of_bounded_norm_iter(10)
sage: list(it)
[Fractional ideal (i + 1),
Fractional ideal (3),
Fractional ideal (-i - 2),
Fractional ideal (2*i + 1)]
sage: list(K.primes_of_bounded_norm_iter(1))
[]

primes_of_degree_one_iter(num_integer_primes=10000, max_iterations=100)

Return an iterator yielding prime ideals of absolute degree one and small norm.

Warning

It is possible that there are no primes of $$K$$ of absolute degree one of small prime norm, and it possible that this algorithm will not find any primes of small norm.

See module sage.rings.number_field.small_primes_of_degree_one for details.

INPUT:

• num_integer_primes (default: 10000) - an integer. We try to find primes of absolute norm no greater than the num_integer_primes-th prime number. For example, if num_integer_primes is 2, the largest norm found will be 3, since the second prime is 3.
• max_iterations (default: 100) - an integer. We test max_iterations integers to find small primes before raising StopIteration.

EXAMPLES:

sage: K.<z> = CyclotomicField(10)
sage: it = K.primes_of_degree_one_iter()
sage: Ps = [ it.next() for i in range(3) ]
sage: Ps # random
[Fractional ideal (z^3 + z + 1), Fractional ideal (3*z^3 - z^2 + z - 1), Fractional ideal (2*z^3 - 3*z^2 + z - 2)]
sage: [ P.norm() for P in Ps ] # random
[11, 31, 41]
sage: [ P.residue_class_degree() for P in Ps ]
[1, 1, 1]

primes_of_degree_one_list(n, num_integer_primes=10000, max_iterations=100)

Return a list of n prime ideals of absolute degree one and small norm.

Warning

It is possible that there are no primes of $$K$$ of absolute degree one of small prime norm, and it possible that this algorithm will not find any primes of small norm.

See module sage.rings.number_field.small_primes_of_degree_one for details.

INPUT:

• num_integer_primes (default: 10000) - an integer. We try to find primes of absolute norm no greater than the num_integer_primes-th prime number. For example, if num_integer_primes is 2, the largest norm found will be 3, since the second prime is 3.
• max_iterations (default: 100) - an integer. We test max_iterations integers to find small primes before raising StopIteration.

EXAMPLES:

sage: K.<z> = CyclotomicField(10)
sage: Ps = K.primes_of_degree_one_list(3)
sage: Ps  # random output
[Fractional ideal (-z^3 - z^2 + 1), Fractional ideal (2*z^3 - 2*z^2 + 2*z - 3), Fractional ideal (2*z^3 - 3*z^2 + z - 2)]
sage: [ P.norm() for P in Ps ]
[11, 31, 41]
sage: [ P.residue_class_degree() for P in Ps ]
[1, 1, 1]

primitive_element()

Return a primitive element for this field, i.e., an element that generates it over $$\QQ$$.

EXAMPLES:

sage: K.<a> = NumberField(x^3 + 2)
sage: K.primitive_element()
a
sage: K.<a,b,c> = NumberField([x^2-2,x^2-3,x^2-5])
sage: K.primitive_element()
a - b + c
sage: alpha = K.primitive_element(); alpha
a - b + c
sage: alpha.minpoly()
x^2 + (2*b - 2*c)*x - 2*c*b + 6
sage: alpha.absolute_minpoly()
x^8 - 40*x^6 + 352*x^4 - 960*x^2 + 576

primitive_root_of_unity()

Return a generator of the roots of unity in this field.

OUTPUT: a primitive root of unity. No guarantee is made about which primitive root of unity this returns, not even for cyclotomic fields.

Note

We do not create the full unit group since that can be expensive, but we do use it if it is already known.

ALGORITHM:

We use the PARI function nfrootsof1 in all cases. This is required (even for cyclotomic fields) in order to be consistent with the full unit group, which is also computed by PARI.

EXAMPLES:

sage: K.<i> = NumberField(x^2+1)
sage: z = K.primitive_root_of_unity(); z
i
sage: z.multiplicative_order()
4

sage: K.<a> = NumberField(x^2+x+1)
sage: z = K.primitive_root_of_unity(); z
a + 1
sage: z.multiplicative_order()
6

sage: x = polygen(QQ)
sage: F.<a,b> = NumberField([x^2 - 2, x^2 - 3])
sage: y = polygen(F)
sage: K.<c> = F.extension(y^2 - (1 + a)*(a + b)*a*b)
sage: K.primitive_root_of_unity()
-1


We do not special-case cyclotomic fields, so we do not always get the most obvious primitive root of unity:

sage: K.<a> = CyclotomicField(3)
sage: z = K.primitive_root_of_unity(); z
a + 1
sage: z.multiplicative_order()
6

sage: K = CyclotomicField(3)
sage: z = K.primitive_root_of_unity(); z
zeta3 + 1
sage: z.multiplicative_order()
6


TESTS:

Check for trac ticket #15027. We use a new variable name:

sage: K.<f> = QuadraticField(-3)
sage: K.primitive_root_of_unity()
-1/2*f + 1/2
sage: UK = K.unit_group()
sage: K.primitive_root_of_unity()
-1/2*f + 1/2

random_element(num_bound=None, den_bound=None, integral_coefficients=False, distribution=None)

Return a random element of this number field.

INPUT:

• num_bound - Bound on numerator of the coefficients of

the resulting element

• den_bound - Bound on denominators of the coefficients

of the resulting element

• integral_coefficients (default: False) - If True, then

the resulting element will have integral coefficients. This option overrides any value of $$den_bound$$.

• distribution - Distribution to use for the coefficients

of the resulting element

OUTPUT:

• Element of this number field

EXAMPLES:

sage: K.<j> = NumberField(x^8+1)
sage: K.random_element()
1/2*j^7 - j^6 - 12*j^5 + 1/2*j^4 - 1/95*j^3 - 1/2*j^2 - 4

sage: K.<a,b,c> = NumberField([x^2-2,x^2-3,x^2-5])
sage: K.random_element()
((6136*c - 7489/3)*b + 5825/3*c - 71422/3)*a + (-4849/3*c + 58918/3)*b - 45718/3*c + 75409/12

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


TESTS:

sage: K.<a> = NumberField(x^5-2)
sage: K.random_element(-1)
Traceback (most recent call last):
...
TypeError: x must be < y
sage: K.random_element(5,0)
Traceback (most recent call last):
...
TypeError: x must be < y
sage: QQ[I].random_element(0)
Traceback (most recent call last):
...
TypeError: x must be > 0

real_embeddings(prec=53)

Return all homomorphisms of this number field into the approximate real field with precision prec.

If prec is 53 (the default), then the real double field is used; otherwise the arbitrary precision (but slow) real field is used. If you want embeddings into the 53-bit double precision, which is faster, use self.embeddings(RDF).

Note

This function uses finite precision real numbers. In functions that should output proven results, one could use self.embeddings(AA) instead.

EXAMPLES:

sage: K.<a> = NumberField(x^3 + 2)
sage: K.real_embeddings()
[
Ring morphism:
From: Number Field in a with defining polynomial x^3 + 2
To:   Real Field with 53 bits of precision
Defn: a |--> -1.25992104989487
]
sage: K.real_embeddings(16)
[
Ring morphism:
From: Number Field in a with defining polynomial x^3 + 2
To:   Real Field with 16 bits of precision
Defn: a |--> -1.260
]
sage: K.real_embeddings(100)
[
Ring morphism:
From: Number Field in a with defining polynomial x^3 + 2
To:   Real Field with 100 bits of precision
Defn: a |--> -1.2599210498948731647672106073
]


As this is a numerical function, the number of embeddings may be incorrect if the precision is too low:

sage: K = NumberField(x^2+2*10^1000*x + 10^2000+1, 'a')
sage: len(K.real_embeddings())
2
sage: len(K.real_embeddings(100))
2
sage: len(K.real_embeddings(10000))
0
sage: len(K.embeddings(AA))
0

reduced_basis(prec=None)

This function returns an LLL-reduced basis for the Minkowski-embedding of the maximal order of a number field.

INPUT:

• self - number field, the base field
• prec (default: None) - the precision with which to compute the Minkowski embedding.

OUTPUT:

An LLL-reduced basis for the Minkowski-embedding of the maximal order of a number field, given by a sequence of (integral) elements from the field.

Note

In the non-totally-real case, the LLL routine we call is currently PARI’s qflll(), which works with floating point approximations, and so the result is only as good as the precision promised by PARI. The matrix returned will always be integral; however, it may only be only “almost” LLL-reduced when the precision is not sufficiently high.

EXAMPLES:

sage: F.<t> = NumberField(x^6-7*x^4-x^3+11*x^2+x-1)
sage: F.maximal_order().basis()
[1/2*t^5 + 1/2*t^4 + 1/2*t^2 + 1/2, t, t^2, t^3, t^4, t^5]
sage: F.reduced_basis()
[-1, -1/2*t^5 + 1/2*t^4 + 3*t^3 - 3/2*t^2 - 4*t - 1/2, t, 1/2*t^5 + 1/2*t^4 - 4*t^3 - 5/2*t^2 + 7*t + 1/2, 1/2*t^5 - 1/2*t^4 - 2*t^3 + 3/2*t^2 - 1/2, 1/2*t^5 - 1/2*t^4 - 3*t^3 + 5/2*t^2 + 4*t - 5/2]
sage: CyclotomicField(12).reduced_basis()
[1, zeta12^2, zeta12, zeta12^3]

reduced_gram_matrix(prec=None)

This function returns the Gram matrix of an LLL-reduced basis for the Minkowski embedding of the maximal order of a number field.

INPUT:

• self - number field, the base field
• prec (default: None) - the precision with which to calculate the Minkowski embedding. (See NOTE below.)

OUTPUT: The Gram matrix $$[\langle x_i,x_j \rangle]$$ of an LLL reduced basis for the maximal order of self, where the integral basis for self is given by $$\{x_0, \dots, x_{n-1}\}$$. Here $$\langle , \rangle$$ is the usual inner product on $$\RR^n$$, and self is embedded in $$\RR^n$$ by the Minkowski embedding. See the docstring for NumberField_absolute.Minkowski_embedding() for more information.

Note

In the non-totally-real case, the LLL routine we call is currently PARI’s qflll(), which works with floating point approximations, and so the result is only as good as the precision promised by PARI. In particular, in this case, the returned matrix will not be integral, and may not have enough precision to recover the correct gram matrix (which is known to be integral for theoretical reasons). Thus the need for the prec flag above.

If the following run-time error occurs: “PariError: not a definite matrix in lllgram (42)” try increasing the prec parameter,

EXAMPLES:

sage: F.<t> = NumberField(x^6-7*x^4-x^3+11*x^2+x-1)
sage: F.reduced_gram_matrix()
[ 6  3  0  2  0  1]
[ 3  9  0  1  0 -2]
[ 0  0 14  6 -2  3]
[ 2  1  6 16 -3  3]
[ 0  0 -2 -3 16  6]
[ 1 -2  3  3  6 19]
sage: Matrix(6, [(x*y).trace() for x in F.integral_basis() for y in F.integral_basis()])
[2550  133  259  664 1368 3421]
[ 133   14    3   54   30  233]
[ 259    3   54   30  233  217]
[ 664   54   30  233  217 1078]
[1368   30  233  217 1078 1371]
[3421  233  217 1078 1371 5224]

sage: var('x')
x
sage: F.<alpha> = NumberField(x^4+x^2+712312*x+131001238)
sage: F.reduced_gram_matrix(prec=128)
[   4.0000000000000000000000000000000000000   0.00000000000000000000000000000000000000 -2.1369320000000000000000000000000000000e6 -3.3122478000000000000000000000000000000e7]
[  0.00000000000000000000000000000000000000    46721.539331563218381658483353092335550 -2.2467769057394530109094755223395819322e7 -3.4807276041138450473611629088647496430e8]
[-2.1369320000000000000000000000000000000e6 -2.2467769057394530109094755223395819322e7 7.0704243186034907491782135494859351061e12 1.1256636615786237006027526953641297995e14]
[-3.3122478000000000000000000000000000000e7 -3.4807276041138450473611629088647496430e8 1.1256636615786237006027526953641297995e14 1.7923838231014970520503146603069479547e15]

regulator(proof=None)

Return the regulator of this number field.

Note that PARI computes the regulator to higher precision than the Sage default.

INPUT:

• proof - default: True, unless you set it otherwise.

EXAMPLES:

sage: NumberField(x^2-2, 'a').regulator()
0.881373587019543
sage: NumberField(x^4+x^3+x^2+x+1, 'a').regulator()
0.962423650119207

residue_field(prime, names=None, check=True)

Return the residue field of this number field at a given prime, ie $$O_K / p O_K$$.

INPUT:

• prime - a prime ideal of the maximal order in this number field, or an element of the field which generates a principal prime ideal.
• names - the name of the variable in the residue field
• check - whether or not to check the primality of prime.

OUTPUT: The residue field at this prime.

EXAMPLES:

sage: R.<x> = QQ[]
sage: K.<a> = NumberField(x^4+3*x^2-17)
sage: P = K.ideal(61).factor()[0][0]
sage: K.residue_field(P)
Residue field in abar of Fractional ideal (61, a^2 + 30)

sage: K.<i> = NumberField(x^2 + 1)
sage: K.residue_field(1+i)
Residue field of Fractional ideal (i + 1)


TESTS:

sage: L.<b> = NumberField(x^2 + 5)
sage: L.residue_field(P)
Traceback (most recent call last):
...
ValueError: Fractional ideal (61, a^2 + 30) is not an ideal of Number Field in b with defining polynomial x^2 + 5
sage: L.residue_field(2)
Traceback (most recent call last):
...
ValueError: Fractional ideal (2) is not a prime ideal

sage: L.residue_field(L.prime_above(5)^2)
Traceback (most recent call last):
...
ValueError: Fractional ideal (5) is not a prime ideal

roots_of_unity()

Return all the roots of unity in this field, primitive or not.

EXAMPLES:

sage: K.<b> = NumberField(x^2+1)
sage: zs = K.roots_of_unity(); zs
[b, -1, -b, 1]
sage: [ z**K.number_of_roots_of_unity() for z in zs ]
[1, 1, 1, 1]

selmer_group(S, m, proof=True, orders=False)

Compute the group $$K(S,m)$$.

INPUT:

• S – a set of primes of self
• m – a positive integer
• proof – if False, assume the GRH in computing the class group
• orders (default False) – if True, output two lists, the generators and their orders

OUTPUT:

A list of generators of $$K(S,m)$$, and (optionally) their orders as elements of $$K^\times/(K^\times)^m$$. This is the subgroup of $$K^\times/(K^\times)^m$$ consisting of elements $$a$$ such that the valuation of $$a$$ is divisible by $$m$$ at all primes not in $$S$$. It fits in an exact sequence between the units modulo $$m$$-th powers and the $$m$$-torsion in the $$S$$-class group:

$1 \longrightarrow O_{K,S}^\times / (O_{K,S}^\times)^m \longrightarrow K(S,m) \longrightarrow \operatorname{Cl}_{K,S}[m] \longrightarrow 0.$

The group $$K(S,m)$$ contains the subgroup of those $$a$$ such that $$K(\sqrt[m]{a})/K$$ is unramified at all primes of $$K$$ outside of $$S$$, but may contain it properly when not all primes dividing $$m$$ are in $$S$$.

EXAMPLES:

sage: K.<a> = QuadraticField(-5)
sage: K.selmer_group((), 2)
[-1, 2]


The previous example shows that the group generated by the output may be strictly larger than the ‘true’ Selmer group of elements giving extensions unramified outside $$S$$, since that has order just 2, generated by $$-1$$:

sage: K.class_number()
2
sage: K.hilbert_class_field('b')
Number Field in b with defining polynomial x^2 + 1 over its base field


When $$m$$ is prime all the orders are equal to $$m$$, but in general they are only divisors of $$m$$:

sage: K.<a> = QuadraticField(-5)
sage: P2 = K.ideal(2, -a+1)
sage: P3 = K.ideal(3, a+1)
sage: K.selmer_group((), 2, orders=True)
([-1, 2], [2, 2])
sage: K.selmer_group((), 4, orders=True)
([-1, 4], [2, 2])
sage: K.selmer_group([P2], 2)
[2, -1]
sage: K.selmer_group((P2,P3), 4)
[2, a + 1, -1]
sage: K.selmer_group((P2,P3), 4, orders=True)
([2, a + 1, -1], [4, 4, 2])
sage: K.selmer_group([P2], 3)
[2]
sage: K.selmer_group([P2, P3], 3)
[2, a + 1]
sage: K.selmer_group([P2, P3, K.ideal(a)], 3)  # random signs
[2, a + 1, a]


Example over $$\QQ$$ (as a number field):

sage: K.<a> = NumberField(polygen(QQ))
sage: K.selmer_group([],5)
[]
sage: K.selmer_group([K.prime_above(p) for p in [2,3,5]],2)
[2, 3, 5, -1]
sage: K.selmer_group([K.prime_above(p) for p in [2,3,5]],6, orders=True)
([2, 3, 5, -1], [6, 6, 6, 2])


TESTS:

sage: K.<a> = QuadraticField(-5)
sage: P2 = K.ideal(2, -a+1)
sage: P3 = K.ideal(3, a+1)
sage: P5 = K.ideal(a)
sage: S = K.selmer_group([P2, P3, P5], 3)
sage: S == [2, a + 1, a] or S == [2, a + 1, -a]
True


Verify that trac ticket #14489 is fixed:

sage: K.<a> = NumberField(x^3 - 381 * x + 127)
sage: K.selmer_group(K.primes_above(13), 2)
[-7/13*a^2 - 140/13*a + 36/13, 14/13*a^2 + 267/13*a - 85/13, 7/13*a^2 + 127/13*a - 49/13, -1, 1/13*a^2 - 19/13*a + 6/13, 1/13*a^2 - 19/13*a - 7/13, 2/13*a^2 + 53/13*a - 92/13, 10/13*a^2 + 44/13*a - 4555/13]


Verify that trac ticket #16708 is fixed:

sage: K.<a> = QuadraticField(-5)
sage: p = K.primes_above(2)[0]
sage: S = K.selmer_group((), 4)
sage: all(4.divides(x.valuation(p)) for x in S)
True

selmer_group_iterator(S, m, proof=True)

Return an iterator through elements of the finite group $$K(S,m)$$.

INPUT:

• S – a set of primes of self
• m – a positive integer
• proof – if False, assume the GRH in computing the class group

OUTPUT:

An iterator yielding the distinct elements of $$K(S,m)$$. See the docstring for NumberField_generic.selmer_group() for more information.

EXAMPLES:

sage: K.<a> = QuadraticField(-5)
sage: list(K.selmer_group_iterator((), 2))
[1, 2, -1, -2]
sage: list(K.selmer_group_iterator((), 4))
[1, 4, -1, -4]
sage: list(K.selmer_group_iterator([K.ideal(2, -a+1)], 2))
[1, -1, 2, -2]
sage: list(K.selmer_group_iterator([K.ideal(2, -a+1), K.ideal(3, a+1)], 2))
[1, -1, a + 1, -a - 1, 2, -2, 2*a + 2, -2*a - 2]


Examples over $$\QQ$$ (as a number field):

sage: K.<a> = NumberField(polygen(QQ))
sage: list(K.selmer_group_iterator([], 5))
[1]
sage: list(K.selmer_group_iterator([], 4))
[1, -1]
sage: list(K.selmer_group_iterator([K.prime_above(p) for p in [11,13]],2))
[1, -1, 13, -13, 11, -11, 143, -143]

signature()

Return (r1, r2), where r1 and r2 are the number of real embeddings and pairs of complex embeddings of this field, respectively.

EXAMPLES:

sage: NumberField(x^2+1, 'a').signature()
(0, 1)
sage: NumberField(x^3-2, 'a').signature()
(1, 1)

specified_complex_embedding()

Returns the embedding of this field into the complex numbers which has been specified.

Fields created with the QuadraticField or CyclotomicField constructors come with an implicit embedding. To get one of these fields without the embedding, use the generic NumberField constructor.

EXAMPLES:

sage: QuadraticField(-1, 'I').specified_complex_embedding()
Generic morphism:
From: Number Field in I with defining polynomial x^2 + 1
To:   Complex Lazy Field
Defn: I -> 1*I

sage: QuadraticField(3, 'a').specified_complex_embedding()
Generic morphism:
From: Number Field in a with defining polynomial x^2 - 3
To:   Real Lazy Field
Defn: a -> 1.732050807568878?

sage: CyclotomicField(13).specified_complex_embedding()
Generic morphism:
From: Cyclotomic Field of order 13 and degree 12
To:   Complex Lazy Field
Defn: zeta13 -> 0.885456025653210? + 0.464723172043769?*I


Most fields don’t implicitly have embeddings unless explicitly specified:

sage: NumberField(x^2-2, 'a').specified_complex_embedding() is None
True
sage: NumberField(x^3-x+5, 'a').specified_complex_embedding() is None
True
sage: NumberField(x^3-x+5, 'a', embedding=2).specified_complex_embedding()
Generic morphism:
From: Number Field in a with defining polynomial x^3 - x + 5
To:   Real Lazy Field
Defn: a -> -1.904160859134921?
sage: NumberField(x^3-x+5, 'a', embedding=CDF.0).specified_complex_embedding()
Generic morphism:
From: Number Field in a with defining polynomial x^3 - x + 5
To:   Complex Lazy Field
Defn: a -> 0.952080429567461? + 1.311248044077123?*I


This function only returns complex embeddings:

sage: K.<a> = NumberField(x^2-2, embedding=Qp(7)(2).sqrt())
sage: K.specified_complex_embedding() is None
True
sage: K.gen_embedding()
3 + 7 + 2*7^2 + 6*7^3 + 7^4 + 2*7^5 + 7^6 + 2*7^7 + 4*7^8 + 6*7^9 + 6*7^10 + 2*7^11 + 7^12 + 7^13 + 2*7^15 + 7^16 + 7^17 + 4*7^18 + 6*7^19 + O(7^20)
sage: K.coerce_embedding()
Generic morphism:
From: Number Field in a with defining polynomial x^2 - 2
To:   7-adic Field with capped relative precision 20
Defn: a -> 3 + 7 + 2*7^2 + 6*7^3 + 7^4 + 2*7^5 + 7^6 + 2*7^7 + 4*7^8 + 6*7^9 + 6*7^10 + 2*7^11 + 7^12 + 7^13 + 2*7^15 + 7^16 + 7^17 + 4*7^18 + 6*7^19 + O(7^20)

structure()

Return fixed isomorphism or embedding structure on self.

This is used to record various isomorphisms or embeddings that arise naturally in other constructions.

EXAMPLES:

sage: K.<z> = NumberField(x^2 + 3)
sage: L.<a> = K.absolute_field(); L
Number Field in a with defining polynomial x^2 + 3
sage: L.structure()
(Isomorphism given by variable name change map:
From: Number Field in a with defining polynomial x^2 + 3
To:   Number Field in z with defining polynomial x^2 + 3,
Isomorphism given by variable name change map:
From: Number Field in z with defining polynomial x^2 + 3
To:   Number Field in a with defining polynomial x^2 + 3)

sage: R.<y> = K[]
sage: D.<x0> = K.extension(y)
sage: D_abs.<y0> = D.absolute_field()
sage: D_abs.structure()[0](y0)
-a

subfield(alpha, name=None, names=None)

Return a number field $$K$$ isomorphic to $$\QQ(\alpha)$$ (if this is an absolute number field) or $$L(\alpha)$$ (if this is a relative extension $$M/L$$) and a map from K to self that sends the generator of K to alpha.

INPUT:

• alpha - an element of self, or something that coerces to an element of self.

OUTPUT:

• K - a number field
• from_K - a homomorphism from K to self that sends the generator of K to alpha.

EXAMPLES:

sage: K.<a> = NumberField(x^4 - 3); K
Number Field in a with defining polynomial x^4 - 3
sage: H.<b>, from_H = K.subfield(a^2)
sage: H
Number Field in b with defining polynomial x^2 - 3
sage: from_H(b)
a^2
sage: from_H
Ring morphism:
From: Number Field in b with defining polynomial x^2 - 3
To:   Number Field in a with defining polynomial x^4 - 3
Defn: b |--> a^2


A relative example. Note that the result returned is the subfield generated by $$\alpha$$ over self.base_field(), not over $$\QQ$$ (see trac ticket #5392):

sage: L.<a> = NumberField(x^2 - 3)
sage: M.<b> = L.extension(x^4 + 1)
sage: K, phi = M.subfield(b^2)
sage: K.base_field() is L
True


Subfields inherit embeddings:

sage: K.<z> = CyclotomicField(5)
sage: L, K_from_L = K.subfield(z-z^2-z^3+z^4)
sage: L
Number Field in z0 with defining polynomial x^2 - 5
sage: CLF_from_K = K.coerce_embedding(); CLF_from_K
Generic morphism:
From: Cyclotomic Field of order 5 and degree 4
To:   Complex Lazy Field
Defn: z -> 0.309016994374948? + 0.951056516295154?*I
sage: CLF_from_L = L.coerce_embedding(); CLF_from_L
Generic morphism:
From: Number Field in z0 with defining polynomial x^2 - 5
To:   Complex Lazy Field
Defn: z0 -> 2.23606797749979? + 0.?e-14*I


Check transitivity:

sage: CLF_from_L(L.gen())
2.23606797749979? + 0.?e-14*I
sage: CLF_from_K(K_from_L(L.gen()))
2.23606797749979? + 0.?e-14*I


If $$self$$ has no specified embedding, then $$K$$ comes with an embedding in $$self$$:

sage: K.<a> = NumberField(x^6 - 6*x^4 + 8*x^2 - 1)
sage: L.<b>, from_L = K.subfield(a^2)
sage: L
Number Field in b with defining polynomial x^3 - 6*x^2 + 8*x - 1
sage: L.gen_embedding()
a^2


You can also view a number field as having a different generator by just choosing the input to generate the whole field; for that it is better to use self.change_generator, which gives isomorphisms in both directions.

trace_dual_basis(b)

Compute the dual basis of a basis of self with respect to the trace pairing.

EXAMPLES:

sage: K.<a> = NumberField(x^3 + x + 1)
sage: b = [1, 2*a, 3*a^2]
sage: T = K.trace_dual_basis(b); T
[4/31*a^2 - 6/31*a + 13/31, -9/62*a^2 - 1/31*a - 3/31, 2/31*a^2 - 3/31*a + 4/93]
sage: [(b[i]*T[j]).trace() for i in xrange(3) for j in xrange(3)]
[1, 0, 0, 0, 1, 0, 0, 0, 1]

trace_pairing(v)

Return the matrix of the trace pairing on the elements of the list $$v$$.

EXAMPLES:

sage: K.<zeta3> = NumberField(x^2 + 3)
sage: K.trace_pairing([1,zeta3])
[ 2  0]
[ 0 -6]

uniformizer(P, others='positive')

Returns an element of self with valuation 1 at the prime ideal P.

INPUT:

• self - a number field
• P - a prime ideal of self
• others - either “positive” (default), in which case the element will have non-negative valuation at all other primes of self, or “negative”, in which case the element will have non-positive valuation at all other primes of self.

Note

When P is principal (e.g. always when self has class number one) the result may or may not be a generator of P!

EXAMPLES:

sage: K.<a> = NumberField(x^2 + 5); K
Number Field in a with defining polynomial x^2 + 5
sage: P,Q = K.ideal(3).prime_factors()
sage: P
Fractional ideal (3, a + 1)
sage: pi = K.uniformizer(P); pi
a + 1
sage: K.ideal(pi).factor()
(Fractional ideal (2, a + 1)) * (Fractional ideal (3, a + 1))
sage: pi = K.uniformizer(P,'negative'); pi
1/2*a + 1/2
sage: K.ideal(pi).factor()
(Fractional ideal (2, a + 1))^-1 * (Fractional ideal (3, a + 1))

sage: K = CyclotomicField(9)
sage: Plist=K.ideal(17).prime_factors()
sage: pilist = [K.uniformizer(P) for P in Plist]
sage: [pi.is_integral() for pi in pilist]
[True, True, True]
sage: [pi.valuation(P) for pi,P in zip(pilist,Plist)]
[1, 1, 1]
sage: [ pilist[i] in Plist[i] for i in range(len(Plist)) ]
[True, True, True]

sage: K.<t> = NumberField(x^4 - x^3 - 3*x^2 - x + 1)
sage: [K.uniformizer(P) for P,e in factor(K.ideal(2))]
[2]
sage: [K.uniformizer(P) for P,e in factor(K.ideal(3))]
[t - 1]
sage: [K.uniformizer(P) for P,e in factor(K.ideal(5))]
[t^2 - t + 1, t + 2, t - 2]
sage: [K.uniformizer(P) for P,e in factor(K.ideal(7))]
[t^2 + 3*t + 1]
sage: [K.uniformizer(P) for P,e in factor(K.ideal(67))]
[t + 23, t + 26, t - 32, t - 18]


ALGORITHM:

Use PARI. More precisely, use the second component of idealprimedec in the “positive” case. Use $$idealappr$$ with exponent of -1 and invert the result in the “negative” case.
unit_group(proof=None)

Return the unit group (including torsion) of this number field.

ALGORITHM: Uses PARI’s bnfunit command.

INPUT:

• proof (bool, default True) flag passed to pari.

Note

The group is cached.

EXAMPLES:

sage: x = QQ['x'].0
sage: A = x^4 - 10*x^3 + 20*5*x^2 - 15*5^2*x + 11*5^3
sage: K = NumberField(A, 'a')
sage: U = K.unit_group(); U
Unit group with structure C10 x Z of Number Field in a with defining polynomial x^4 - 10*x^3 + 100*x^2 - 375*x + 1375
sage: U.gens()
(u0, u1)
sage: U.gens_values()
[-7/275*a^3 + 1/11*a^2 - 9/11*a - 1, 6/275*a^3 - 9/55*a^2 + 14/11*a - 2]
sage: U.invariants()
(10, 0)
sage: [u.multiplicative_order() for u in U.gens()]
[10, +Infinity]


For big number fields, provably computing the unit group can take a very long time. In this case, one can ask for the conjectural unit group (correct if the Generalized Riemann Hypothesis is true):

sage: K = NumberField(x^17 + 3, 'a')
sage: K.unit_group(proof=True)  # takes forever, not tested
...
sage: U = K.unit_group(proof=False)
sage: U
Unit group with structure C2 x Z x Z x Z x Z x Z x Z x Z x Z of Number Field in a with defining polynomial x^17 + 3
sage: U.gens()
(u0, u1, u2, u3, u4, u5, u6, u7, u8)
sage: U.gens_values()  # result not independently verified
[-1, a^9 + a - 1, a^15 - a^12 + a^10 - a^9 - 2*a^8 + 3*a^7 + a^6 - 3*a^5 + a^4 + 4*a^3 - 3*a^2 - 2*a + 2, a^16 - a^15 + a^14 - a^12 + a^11 - a^10 - a^8 + a^7 - 2*a^6 + a^4 - 3*a^3 + 2*a^2 - 2*a + 1, 2*a^16 - a^14 - a^13 + 3*a^12 - 2*a^10 + a^9 + 3*a^8 - 3*a^6 + 3*a^5 + 3*a^4 - 2*a^3 - 2*a^2 + 3*a + 4, 2*a^16 - 3*a^15 + 3*a^14 - 3*a^13 + 3*a^12 - a^11 + a^9 - 3*a^8 + 4*a^7 - 5*a^6 + 6*a^5 - 4*a^4 + 3*a^3 - 2*a^2 - 2*a + 4, a^16 - a^15 - 3*a^14 - 4*a^13 - 4*a^12 - 3*a^11 - a^10 + 2*a^9 + 4*a^8 + 5*a^7 + 4*a^6 + 2*a^5 - 2*a^4 - 6*a^3 - 9*a^2 - 9*a - 7, a^15 + a^14 + 2*a^11 + a^10 - a^9 + a^8 + 2*a^7 - a^5 + 2*a^3 - a^2 - 3*a + 1, 5*a^16 - 6*a^14 + a^13 + 7*a^12 - 2*a^11 - 7*a^10 + 4*a^9 + 7*a^8 - 6*a^7 - 7*a^6 + 8*a^5 + 6*a^4 - 11*a^3 - 5*a^2 + 13*a + 4]

units(proof=None)

Return generators for the unit group modulo torsion.

INPUT:

• proof (bool, default True) flag passed to pari.

Note

For more functionality see the unit_group() function.

ALGORITHM: Uses PARI’s bnfunit command.

EXAMPLES:

sage: x = polygen(QQ)
sage: A = x^4 - 10*x^3 + 20*5*x^2 - 15*5^2*x + 11*5^3
sage: K = NumberField(A, 'a')
sage: K.units()
(6/275*a^3 - 9/55*a^2 + 14/11*a - 2,)


For big number fields, provably computing the unit group can take a very long time. In this case, one can ask for the conjectural unit group (correct if the Generalized Riemann Hypothesis is true):

sage: K = NumberField(x^17 + 3, 'a')
sage: K.units(proof=True)  # takes forever, not tested
...
sage: K.units(proof=False)  # result not independently verified
(a^9 + a - 1,
a^15 - a^12 + a^10 - a^9 - 2*a^8 + 3*a^7 + a^6 - 3*a^5 + a^4 + 4*a^3 - 3*a^2 - 2*a + 2,
a^16 - a^15 + a^14 - a^12 + a^11 - a^10 - a^8 + a^7 - 2*a^6 + a^4 - 3*a^3 + 2*a^2 - 2*a + 1,
2*a^16 - a^14 - a^13 + 3*a^12 - 2*a^10 + a^9 + 3*a^8 - 3*a^6 + 3*a^5 + 3*a^4 - 2*a^3 - 2*a^2 + 3*a + 4,
2*a^16 - 3*a^15 + 3*a^14 - 3*a^13 + 3*a^12 - a^11 + a^9 - 3*a^8 + 4*a^7 - 5*a^6 + 6*a^5 - 4*a^4 + 3*a^3 - 2*a^2 - 2*a + 4,
a^16 - a^15 - 3*a^14 - 4*a^13 - 4*a^12 - 3*a^11 - a^10 + 2*a^9 + 4*a^8 + 5*a^7 + 4*a^6 + 2*a^5 - 2*a^4 - 6*a^3 - 9*a^2 - 9*a - 7,
a^15 + a^14 + 2*a^11 + a^10 - a^9 + a^8 + 2*a^7 - a^5 + 2*a^3 - a^2 - 3*a + 1,
5*a^16 - 6*a^14 + a^13 + 7*a^12 - 2*a^11 - 7*a^10 + 4*a^9 + 7*a^8 - 6*a^7 - 7*a^6 + 8*a^5 + 6*a^4 - 11*a^3 - 5*a^2 + 13*a + 4)

zeta(n=2, all=False)

Return one, or a list of all, primitive n-th root of unity in this field.

INPUT:

• n - positive integer
• all - bool. If False (default), return a primitive $$n$$-th root of unity in this field, or raise a ValueError exception if there are none. If True, return a list of all primitive $$n$$-th roots of unity in this field (possibly empty).

Note

To obtain the maximal order of a root of unity in this field, use self.number_of_roots_of_unity().

Note

We do not create the full unit group since that can be expensive, but we do use it if it is already known.

EXAMPLES:

sage: K.<z> = NumberField(x^2 + 3)
sage: K.zeta(1)
1
sage: K.zeta(2)
-1
sage: K.zeta(2, all=True)
[-1]
sage: K.zeta(3)
-1/2*z - 1/2
sage: K.zeta(3, all=True)
[-1/2*z - 1/2, 1/2*z - 1/2]
sage: K.zeta(4)
Traceback (most recent call last):
...
ValueError: There are no 4th roots of unity in self.

sage: r.<x> = QQ[]
sage: K.<b> = NumberField(x^2+1)
sage: K.zeta(4)
b
sage: K.zeta(4,all=True)
[b, -b]
sage: K.zeta(3)
Traceback (most recent call last):
...
ValueError: There are no 3rd roots of unity in self.
sage: K.zeta(3,all=True)
[]

zeta_coefficients(n)

Compute the first n coefficients of the Dedekind zeta function of this field as a Dirichlet series.

EXAMPLE:

sage: x = QQ['x'].0
sage: NumberField(x^2+1, 'a').zeta_coefficients(10)
[1, 1, 0, 1, 2, 0, 0, 1, 1, 2]

zeta_function(prec=53, max_imaginary_part=0, max_asymp_coeffs=40)

Return the Zeta function of this number field.

This actually returns an interface to Tim Dokchitser’s program for computing with the Dedekind zeta function zeta_F(s) of the number field F.

INPUT:

• prec - integer (bits precision)
• max_imaginary_part - real number
• max_asymp_coeffs - integer

OUTPUT: The zeta function of this number field.

EXAMPLES:

sage: K.<a> = NumberField(ZZ['x'].0^2+ZZ['x'].0-1)
sage: Z = K.zeta_function()
sage: Z
Zeta function associated to Number Field in a with defining polynomial x^2 + x - 1
sage: Z(-1)
0.0333333333333333
sage: L.<a, b, c> = NumberField([x^2 - 5, x^2 + 3, x^2 + 1])
sage: Z = L.zeta_function()
sage: Z(5)
1.00199015670185

zeta_order()

Return the number of roots of unity in this field.

Note

We do not create the full unit group since that can be expensive, but we do use it if it is already known.

EXAMPLES:

sage: F.<alpha> = NumberField(x**22+3)
sage: F.zeta_order()
6
sage: F.<alpha> = NumberField(x**2-7)
sage: F.zeta_order()
2

sage.rings.number_field.number_field.NumberField_generic_v1(poly, name, latex_name, canonical_embedding=None)

This is used in pickling generic number fields.

EXAMPLES:

sage: from sage.rings.number_field.number_field import NumberField_absolute_v1
sage: R.<x> = QQ[]
sage: NumberField_absolute_v1(x^2 + 1, 'i', 'i')
Number Field in i with defining polynomial x^2 + 1

class sage.rings.number_field.number_field.NumberField_quadratic(polynomial, name=None, latex_name=None, check=True, embedding=None, assume_disc_small=False, maximize_at_primes=None, structure=None)

Create a quadratic extension of the rational field.

The command QuadraticField(a) creates the field $$\QQ(\sqrt{a})$$.

EXAMPLES:

sage: QuadraticField(3, 'a')
Number Field in a with defining polynomial x^2 - 3
Number Field in b with defining polynomial x^2 + 4

class_number(proof=None)

Return the size of the class group of self.

If proof = False (not the default!) and the discriminant of the field is negative, then the following warning from the PARI manual applies:

Warning

For $$D<0$$, this function may give incorrect results when the class group has a low exponent (has many cyclic factors), because implementing Shank’s method in full generality slows it down immensely.

EXAMPLES:

sage: QuadraticField(-23,'a').class_number()
3


These are all the primes so that the class number of $$\QQ(\sqrt{-p})$$ is $$1$$:

sage: [d for d in prime_range(2,300) if not is_square(d) and QuadraticField(-d,'a').class_number() == 1]
[2, 3, 7, 11, 19, 43, 67, 163]


It is an open problem to prove that there are infinity many positive square-free $$d$$ such that $$\QQ(\sqrt{d})$$ has class number $$1$$:

sage: len([d for d in range(2,200) if not is_square(d) and QuadraticField(d,'a').class_number() == 1])
121


TESTS:

sage: type(QuadraticField(-23,'a').class_number())
<type 'sage.rings.integer.Integer'>
sage: type(NumberField(x^3 + 23, 'a').class_number())
<type 'sage.rings.integer.Integer'>
sage: type(NumberField(x^3 + 23, 'a').extension(x^2 + 5, 'b').class_number())
<type 'sage.rings.integer.Integer'>
sage: type(CyclotomicField(10).class_number())
<type 'sage.rings.integer.Integer'>

discriminant(v=None)

Returns the discriminant of the ring of integers of the number field, or if v is specified, the determinant of the trace pairing on the elements of the list v.

INPUT:

• v (optional) - list of element of this number field

OUTPUT: Integer if v is omitted, and Rational otherwise.

EXAMPLES:

sage: K.<i> = NumberField(x^2+1)
sage: K.discriminant()
-4
sage: K.<a> = NumberField(x^2+5)
sage: K.discriminant()
-20
sage: K.<a> = NumberField(x^2-5)
sage: K.discriminant()
5

hilbert_class_field(names)

Returns the Hilbert class field of this quadratic field as a relative extension of this field.

Note

For the polynomial that defines this field as a relative extension, see the hilbert_class_field_defining_polynomial command, which is vastly faster than this command, since it doesn’t construct a relative extension.

EXAMPLES:

sage: K.<a> = NumberField(x^2 + 23)
sage: L = K.hilbert_class_field('b'); L
Number Field in b with defining polynomial x^3 - x^2 + 1 over its base field
sage: L.absolute_field('c')
Number Field in c with defining polynomial x^6 - 2*x^5 + 70*x^4 - 90*x^3 + 1631*x^2 - 1196*x + 12743
sage: K.hilbert_class_field_defining_polynomial()
x^3 - x^2 + 1

hilbert_class_field_defining_polynomial(name='x')

Returns a polynomial over $$\QQ$$ whose roots generate the Hilbert class field of this quadratic field as an extension of this quadratic field.

Note

Computed using PARI via Schertz’s method. This implementation is quite fast.

EXAMPLES:

sage: K.<b> = QuadraticField(-23)
sage: K.hilbert_class_field_defining_polynomial()
x^3 - x^2 + 1


Note that this polynomial is not the actual Hilbert class polynomial: see hilbert_class_polynomial:

sage: K.hilbert_class_polynomial()
x^3 + 3491750*x^2 - 5151296875*x + 12771880859375

sage: K.<a> = QuadraticField(-431)
sage: K.class_number()
21
sage: K.hilbert_class_field_defining_polynomial(name='z')
z^21 + 6*z^20 + 9*z^19 - 4*z^18 + 33*z^17 + 140*z^16 + 220*z^15 + 243*z^14 + 297*z^13 + 461*z^12 + 658*z^11 + 743*z^10 + 722*z^9 + 681*z^8 + 619*z^7 + 522*z^6 + 405*z^5 + 261*z^4 + 119*z^3 + 35*z^2 + 7*z + 1

hilbert_class_polynomial(name='x')

Compute the Hilbert class polynomial of this quadratic field.

Right now, this is only implemented for imaginary quadratic fields.

EXAMPLES:

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

sage: K.hilbert_class_polynomial(name='z')
z^3 + 39491307*z^2 - 58682638134*z + 1566028350940383

is_galois()

Return True since all quadratic fields are automatically Galois.

EXAMPLES:

sage: QuadraticField(1234,'d').is_galois()
True


This is used in pickling quadratic fields.

EXAMPLES:

sage: from sage.rings.number_field.number_field import NumberField_quadratic_v1
sage: R.<x> = QQ[]
Number Field in d with defining polynomial x^2 - 2

sage.rings.number_field.number_field.QuadraticField(D, name='a', check=True, embedding=True, latex_name='sqrt', **args)

Return a quadratic field obtained by adjoining a square root of $$D$$ to the rational numbers, where $$D$$ is not a perfect square.

INPUT:

• D - a rational number
• name - variable name (default: ‘a’)
• check - bool (default: True)
• embedding - bool or square root of D in an ambient field (default: True)
• latex_name - latex variable name (default: sqrt{D})

OUTPUT: A number field defined by a quadratic polynomial. Unless otherwise specified, it has an embedding into $$\RR$$ or $$\CC$$ by sending the generator to the positive or upper-half-plane root.

EXAMPLES:

sage: QuadraticField(3, 'a')
Number Field in a with defining polynomial x^2 - 3
Number Field in theta with defining polynomial x^2 - 3
sage: RR(theta)
1.73205080756888
Traceback (most recent call last):
...
ValueError: D must not be a perfect square.
Number Field in a with defining polynomial x^2 - 9


Quadratic number fields derive from general number fields.

sage: from sage.rings.number_field.number_field import is_NumberField
sage: type(K)
sage: is_NumberField(K)
True


sage: QuadraticField(-11, 'a') is QuadraticField(-11, 'a')
True


By default, quadratic fields come with a nice latex representation:

sage: K.<a> = QuadraticField(-7)
sage: latex(K)
\Bold{Q}(\sqrt{-7})
sage: latex(a)
\sqrt{-7}
sage: latex(1/(1+a))
-\frac{1}{8} \sqrt{-7} + \frac{1}{8}
sage: K.latex_variable_name()
'\\sqrt{-7}'


We can provide our own name as well:

sage: K.<a> = QuadraticField(next_prime(10^10), latex_name=r'\sqrt{D}')
sage: 1+a
a + 1
sage: latex(1+a)
\sqrt{D} + 1
a


The name of the generator does not interfere with Sage preparser, see #1135:

sage: K1 = QuadraticField(5, 'x')
sage: K1 is K2
True
sage: K1 is K3
True
sage: K1
Number Field in x with defining polynomial x^2 - 5


Note that, in presence of two different names for the generator, the name given by the preparser takes precedence:

sage: K4.<y> = QuadraticField(5, 'x'); K4
Number Field in y with defining polynomial x^2 - 5
sage: K1 == K4
False


TESTS:

sage: QuadraticField(-11, 'a') is QuadraticField(-11, 'a', latex_name='Z')
False
False

sage.rings.number_field.number_field.is_AbsoluteNumberField(x)

Return True if x is an absolute number field.

EXAMPLES:

sage: from sage.rings.number_field.number_field import is_AbsoluteNumberField
sage: is_AbsoluteNumberField(NumberField(x^2+1,'a'))
True
sage: is_AbsoluteNumberField(NumberField([x^3 + 17, x^2+1],'a'))
False


The rationals are a number field, but they’re not of the absolute number field class.

sage: is_AbsoluteNumberField(QQ)
False

sage.rings.number_field.number_field.is_CyclotomicField(x)

Return True if x is a cyclotomic field, i.e., of the special cyclotomic field class. This function does not return True for a number field that just happens to be isomorphic to a cyclotomic field.

EXAMPLES:

sage: from sage.rings.number_field.number_field import is_CyclotomicField
sage: is_CyclotomicField(NumberField(x^2 + 1,'zeta4'))
False
sage: is_CyclotomicField(CyclotomicField(4))
True
sage: is_CyclotomicField(CyclotomicField(1))
True
sage: is_CyclotomicField(QQ)
False
sage: is_CyclotomicField(7)
False

sage.rings.number_field.number_field.is_NumberFieldHomsetCodomain(codomain)

Returns whether codomain is a valid codomain for a number field homset. This is used by NumberField._Hom_ to determine whether the created homsets should be a sage.rings.number_field.morphism.NumberFieldHomset.

EXAMPLES:

This currently accepts any parent (CC, RR, ...) in Fields:

sage: from sage.rings.number_field.number_field import is_NumberFieldHomsetCodomain
sage: is_NumberFieldHomsetCodomain(QQ)
True
sage: is_NumberFieldHomsetCodomain(NumberField(x^2 + 1, 'x'))
True
sage: is_NumberFieldHomsetCodomain(ZZ)
False
sage: is_NumberFieldHomsetCodomain(3)
False
sage: is_NumberFieldHomsetCodomain(MatrixSpace(QQ, 2))
False
sage: is_NumberFieldHomsetCodomain(InfinityRing)
False


Question: should, for example, QQ-algebras be accepted as well?

Caveat: Gap objects are not (yet) in Fields, and therefore not accepted as number field homset codomains:

sage: is_NumberFieldHomsetCodomain(gap.Rationals)
False


Return True if x is of the quadratic number field type.

EXAMPLES:

sage: from sage.rings.number_field.number_field import is_QuadraticField
True
True
False


A quadratic field specially refers to a number field, not a finite field:

sage: is_QuadraticField(GF(9,'a'))
False

sage.rings.number_field.number_field.is_fundamental_discriminant(D)

Return True if the integer $$D$$ is a fundamental discriminant, i.e., if $$D \cong 0,1\pmod{4}$$, and $$D\neq 0, 1$$ and either (1) $$D$$ is square free or (2) we have $$D\cong 0\pmod{4}$$ with $$D/4 \cong 2,3\pmod{4}$$ and $$D/4$$ square free. These are exactly the discriminants of quadratic fields.

EXAMPLES:

sage: [D for D in range(-15,15) if is_fundamental_discriminant(D)]
[-15, -11, -8, -7, -4, -3, 5, 8, 12, 13]
sage: [D for D in range(-15,15) if not is_square(D) and QuadraticField(D,'a').disc() == D]
[-15, -11, -8, -7, -4, -3, 5, 8, 12, 13]

sage.rings.number_field.number_field.proof_flag(t)

Used for easily determining the correct proof flag to use.

Returns t if t is not None, otherwise returns the system-wide proof-flag for number fields (default: True).

EXAMPLES:

sage: from sage.rings.number_field.number_field import proof_flag
sage: proof_flag(True)
True
sage: proof_flag(False)
False
sage: proof_flag(None)
True
sage: proof_flag("banana")
'banana'

sage.rings.number_field.number_field.put_natural_embedding_first(v)

Helper function for embeddings() functions for number fields.

INPUT: a list of embeddings of a number field

OUTPUT: None. The list is altered in-place, so that, if possible, the first embedding has been switched with one of the others, so that if there is an embedding which preserves the generator names then it appears first.

EXAMPLES:

sage: K.<a> = CyclotomicField(7)
sage: embs = K.embeddings(K)
sage: [e(a) for e in embs] # random - there is no natural sort order
[a, a^2, a^3, a^4, a^5, -a^5 - a^4 - a^3 - a^2 - a - 1]
sage: id = [ e for e in embs if e(a) == a ][0]; id
Ring endomorphism of Cyclotomic Field of order 7 and degree 6
Defn: a |--> a
sage: permuted_embs = list(embs); permuted_embs.remove(id); permuted_embs.append(id)
sage: [e(a) for e in permuted_embs] # random - but natural map is not first
[a^2, a^3, a^4, a^5, -a^5 - a^4 - a^3 - a^2 - a - 1, a]
sage: permuted_embs[0] != a
True
sage: from sage.rings.number_field.number_field import put_natural_embedding_first
sage: put_natural_embedding_first(permuted_embs)
sage: [e(a) for e in permuted_embs] # random - but natural map is first
[a, a^3, a^4, a^5, -a^5 - a^4 - a^3 - a^2 - a - 1, a^2]
sage: permuted_embs[0] == id
True

sage.rings.number_field.number_field.refine_embedding(e, prec=None)

Given an embedding from a number field to either $$\RR$$ or $$\CC$$, returns an equivalent embedding with higher precision.

INPUT:

• e - an embedding of a number field into either RR or CC (with some precision)

• prec - (default None) the desired precision; if None,

current precision is doubled; if Infinity, the equivalent embedding into either QQbar or AA is returned.

EXAMPLES:

sage: from sage.rings.number_field.number_field import refine_embedding
sage: K = CyclotomicField(3)
sage: e10 = K.complex_embedding(10)
sage: e10.codomain().precision()
10
sage: e25 = refine_embedding(e10, prec=25)
sage: e25.codomain().precision()
25


An example where we extend a real embedding into AA:

sage: K.<a> = NumberField(x^3-2)
sage: K.signature()
(1, 1)
sage: e = K.embeddings(RR)[0]; e
Ring morphism:
From: Number Field in a with defining polynomial x^3 - 2
To:   Real Field with 53 bits of precision
Defn: a |--> 1.25992104989487
sage: e = refine_embedding(e,Infinity); e
Ring morphism:
From: Number Field in a with defining polynomial x^3 - 2
To:   Algebraic Real Field
Defn: a |--> 1.259921049894873?


Now we can obtain arbitrary precision values with no trouble:

sage: RealField(150)(e(a))
1.2599210498948731647672106072782283505702515
sage: _^3
2.0000000000000000000000000000000000000000000
sage: RealField(200)(e(a^2-3*a+7))
4.8076379022835799804500738174376232086807389337953290695624


Complex embeddings can be extended into QQbar:

sage: e = K.embeddings(CC)[0]; e
Ring morphism:
From: Number Field in a with defining polynomial x^3 - 2
To:   Complex Field with 53 bits of precision
Defn: a |--> -0.62996052494743... - 1.09112363597172*I
sage: e = refine_embedding(e,Infinity); e
Ring morphism:
From: Number Field in a with defining polynomial x^3 - 2
To:   Algebraic Field
Defn: a |--> -0.6299605249474365? - 1.091123635971722?*I
sage: ComplexField(200)(e(a))
-0.62996052494743658238360530363911417528512573235075399004099 - 1.0911236359717214035600726141898088813258733387403009407036*I
sage: e(a)^3
2


Embeddings into lazy fields work:

sage: L = CyclotomicField(7)
sage: x = L.specified_complex_embedding(); x
Generic morphism:
From: Cyclotomic Field of order 7 and degree 6
To:   Complex Lazy Field
Defn: zeta7 -> 0.623489801858734? + 0.781831482468030?*I
sage: refine_embedding(x, 300)
Ring morphism:
From: Cyclotomic Field of order 7 and degree 6
To:   Complex Field with 300 bits of precision
Defn: zeta7 |--> 0.623489801858733530525004884004239810632274730896402105365549439096853652456487284575942507 + 0.781831482468029808708444526674057750232334518708687528980634958045091731633936441700868007*I
sage: refine_embedding(x, infinity)
Ring morphism:
From: Cyclotomic Field of order 7 and degree 6
To:   Algebraic Field
Defn: zeta7 |--> 0.6234898018587335? + 0.7818314824680299?*I


#### Previous topic

Base class for all number fields

#### Next topic

Relative Number Fields