As you may have alreay guessed, much of elementary number theoretic aspects are implemented in SAGE. For example, the prime factorisation, primality test etc. Given a number N, SAGE can for example find the next probable prime.
{{{id=1| A = next_probable_prime(10^250) /// }}} {{{id=4| A /// 10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001227 }}} {{{id=5| A.is_prime() /// True }}} {{{id=6| timeit('A.is_prime()') /// ^CTraceback (most recent call last): File "Let us now do some Galois theory. Let us work out the Galois correspondence for a number field.
{{{id=19| K.If the number field is not normal, we may compute the Galois closure:
{{{id=28| M. = NumberField(x^3 - 2); M.galois_closure(names='b') /// Number Field in b with defining polynomial x^6 + 108 }}}However, if I now ask for the Galois group, SAGE returns the Galois group of the Galois closure. (SAGE (the world in general?) does not know how to compute the Galois group of an extension that is not normal.)
{{{id=30| G = M.galois_group(names='b'); G.group_generators() /// Family ((1,2,3)(4,5,6), (1,4)(2,6)(3,5)) }}} {{{id=31| G[1].as_hom() /// Ring endomorphism of Number Field in b with defining polynomial x^6 + 108 Defn: b |--> 1/12*b^4 - 1/2*b }}} {{{id=32| K. = NumberField([x^2 + 5, x^2 - 2]) L.Recall the notion of a different of a number field. For a lattice $L$ in a number field $K$, we may define its dual using the trace $\operatorname{Tr}_{K/\mathbf{Q}}$:
\[L^\vee = \{\alpha \in K: \operatorname{Tr}_{K/\mathbf{Q}}(\alpha L) \in \mathbf{Z}\}.\]
It is easy to verify that a fractional ideal $\mathfrak{a}$ gives a lattice in $K$; it turns out that $\mathfrak{a}^\vee$ is also a fractional ideal and satisfies:
\[\mathfrak{a}^\vee = \mathfrak{a}^{-1}\mathcal{O}_K^\vee.\]
The ideal $\mathcal{O}_K$ is a full sublattice of $K$ and $\mathcal{O}_K^\vee \subseteq \mathcal{O}_K$. Thus, the dual lattice gives us an interesting fractional ideal: the dual $\mathcal{O}_K^\vee$ is the largest fractional ideal whose all elements have integer trace. The inverse $(\mathcal{O}_K^\vee)^{-1}$, therefore an integral ideal, is called the different of the number field $K$.
{{{id=59| I = M.different(); I /// Fractional ideal (d) }}} {{{id=61| I.norm() /// 20072 }}} {{{id=62| #can factor principal ideals in a number field M.factor(18) /// (Fractional ideal (2, 1/2*d))^2 * (Fractional ideal (3, 1/2*d + 1))^2 * (Fractional ideal (3, 1/2*d + 2))^2 }}} {{{id=63| #you can factor elements of a number field N.