# Computations in the ring of integers of a number field

Suppose I have some number field $K$, with its ring of integers $O_K$ = K.ring_of_integers(). If $I$ is an ideal of $O_K$ (or, if $I$ is a fractional ideal of $K$), I'd like to be able to compute with the ring $O_K/I$. For example, I'd like to be able to ask how big that ring is.

K.<omega> = NumberField(x^2+x+1)
OK = K.ring_of_integers()
R.<a,b> = OK.quo(OK.ideal(9))
R.cardinality()


gives a NotImplementedError. (Even though cardinality shows up as one of the supported methods if I type R.??).

Or, again for example, I'd like to be able to determine the ring structure of $R$, or the structure of its group of units, but none of these methods seem to actually be supported.

The type of R is sage.rings.quotient_ring.QuotientRing_generic_with_category.

What am I missing?

edit retag close merge delete

Methods that appear in tab completion are not always implemented.

Sort by » oldest newest most voted

Note that in this particular case, OK can be defined directly:

sage: E = EisensteinIntegers()
sage: E
Eisenstein Integers in Number Field in omega with defining polynomial x^2 + x + 1
sage: E.gens()
(1, omega)


If needed, define the generator:

sage: omega = E.gen(1)
sage: omega
omega
sage: omega^2
-omega - 1


(We don't need it for what follows.)

Since the goal is to get information about an ideal, give it a name:

sage: J = E.ideal(9)
sage: J
sage: J
Fractional ideal (9)


Indeed, we can use the <TAB> key and type:

sage: J.<TAB>


to see all the methods that exist for J. Then it's a matter of trying out some of these methods with promising names, seeing what results we get, and reading their documentation.

Apply Euler phi to the ideal:

sage: J.euler_phi()
54


Get the documentation for euler_phi:

sage: J.euler_phi?
Signature:      J.euler_phi()
Docstring:
Returns the Euler varphi-function of this integral ideal.

This is the order of the multiplicative group of the quotient
modulo the ideal.

An error is raised if the ideal is not integral.

EXAMPLES:

sage: K.<i>=NumberField(x^2+1)
sage: I = K.ideal(2+i)
sage: [r for r in I.residues() if I.is_coprime(r)]
[-2*i, -i, i, 2*i]
sage: I.euler_phi()
4
sage: J = I^3
sage: J.euler_phi()
100
sage: len([r for r in J.residues() if J.is_coprime(r)])
100
sage: J = K.ideal(3-2*i)
sage: I.is_coprime(J)
True
sage: I.euler_phi()*J.euler_phi() == (I*J).euler_phi()
True
sage: L.<b> = K.extension(x^2 - 7)
sage: L.ideal(3).euler_phi()
64
Init docstring: Initialize self.  See help(type(self)) for accurate signature.
File:           /opt/s/sage/local/lib/python3.7/site-packages/sage/rings/number_field/number_field_ideal.py
Type:           method


The following may also be of interest:

sage: J.idealstar()
Multiplicative Abelian group isomorphic to C6 x C3 x C3
sage: J.idealstar?
...

sage: J.residues()
...
sage: list(J.residues())
...
sage: len(J.residues())
81

sage: J.invertible_residues()
...
sage: list(J.invertible_residues())
...
sage: len(J.invertible_residues())
54


One take-away from this is that a lot of the information about the quotient modulo this ideal can be accessed using methods defined on the ideal, rather than on the quotient. Note how in all the above we never defined the quotient!

more