\documentclass[12pt]{article}
\usepackage[active]{srcltx}
\usepackage{graphicx}
\input{macros}
\hoffset=-0.05\textwidth
\textwidth=1.1\textwidth
\voffset=-0.08\textheight
\textheight=1.16\textheight

\title{Math 129: Algebraic Number Theory\\
{\bf Lecture 5}}
\author{William Stein}
\date{Thursday, February 19, 2004}
\begin{document}
\maketitle

\section{Dedekind Domains}
First we complete the proof begun on Tuesday that the set of nonzero
fractional ideals of $\O_K$ is a group.  Recall that a fractional
ideal~$I$ is an $\O_K$-submodule of~$K$ that is finitely generated.
We proved on Tuesday that if $\p$ is a prime ideal of $I$,
then there is a fractional ideal
$$
  \p^{-1} = \{a \in \K : a\p \subset \O_K\}
$$ such that $\p \p^{-1} = (1) = \O_K$, i.e., every prime ideal has an
inverse.  We proved this by noting that either $\p \p^{-1}=\O_K$ or
$\p\p^{-1}=\p$.  Using the fact that $\O_K$ is Noetherian and
integrally closed, we deduced that $\p\p^{-1}=\p$ leads to a
contradiction.  It remains to prove that every fractional ideal has an
inverse, which we do now.

\begin{proof}[Completion of proof]
So far we have proved that if $\p$ is a prime ideal of $\O_K$, then
$\p^{-1} = \{a \in \K : a\p \subset \O_K\}$ is the inverse of $\p$ in
the monoid of nonzero fractional ideals of $\O_K$.  As mentioned after
Definition~\ref{def:fracideal} [on Tuesday], every nonzero fractional
ideal is of the form $aI$ for $a\in K$ and $I$ an integral ideal, so
since $(a)$ has inverse $(1/a)$, it suffices to show that every
integral ideal~$I$ has an inverse.  If not, then there is a nonzero
integral ideal~$I$ that is maximal among all nonzero integral ideals
that do not have an inverse.  Every ideal is contained in a maximal
ideal, so there is a nonzero prime ideal $\p$ such that $I\subset \p$.
Multiplying both sides of this inclusion by $\p^{-1}$ and using that
$\O_K\subset \p^{-1}$, we see that $I \subset \p^{-1} I \subset \O_K$.
If $I = \p^{-1} I$, then arguing as in the proof that $\p^{-1}$ is the
inverse of $\p$, we see that each element of $\p^{-1}$ preserves the
finitely generated $\Z$-module~$I$ and is hence integral.  But then
$\p^{-1}\subset \O_K$, which implies that $\O_K = \p \p^{-1} \subset
\p$, a contradiction.  Thus $I \neq \p^{-1} I$.  Because $I$ is
maximal among ideals that do not have an inverse, the ideal $\p^{-1}
I$ does have an inverse, call it~$J$.  Then $\p{}J$ is the inverse of
$I$, since $\O_K = (\p{}J)(\p^{-1}I) = JI$.
\end{proof}

We are now ready to deduce the crucial Theorem~\ref{thm:intuniqfac},
which asserts that any nonzero ideal of a Dedekind domain can be
expressed uniquely as a product of primes (up to order).  Thus unique
factorization holds for ideals in a Dedekind domain, and it is this
unique factorization that initially motivated the introduction of
rings of integers of number fields over a century ago.

\begin{theorem}\label{thm:uniqfac}
Suppose $I$ is an integral ideal of $\O_K$.  Then $I$ can
be written as a product 
$$
  I = \p_1\cdots \p_n
$$ of prime ideals of $\O_K$, and this representation is unique up to
order.  (Exception: If $I=0$, then the representation is not unique.)
\end{theorem}
\begin{proof}
Suppose $I$ is an ideal that is maximal among the set of all ideals in
$\O_K$ that can not be written as a product of primes.  Every ideal is
contained in a maximal ideal, so $I$ is contained in a nonzero prime
ideal $\p$.  If $I\p^{-1} = I$, then by Theorem~\ref{thm:ddabgrp}
[that the fractional ideals form an abelian group] we can cancel $I$
from both sides of this equation to see that $\p^{-1}=\O_K$, a
contradiction.  Thus $I$ is strictly contained in $I\p^{-1}$, so by
our maximality assumption on $I$ there are maximal ideals
$\p_1,\ldots, \p_n$ such that $I\p^{-1} = \p_1\cdots \p_n$.  Then
$I=\p\cdot \p_1\cdots \p_n$, a contradiction.  Thus every ideal can be
written as a product of primes.

Suppose $\p_1\cdots \p_n=\q_1\cdots \q_m$. If no $\q_i$ is contained in
$\p_1$, then for each $i$ there is an $a_i\in \q_i$ such that
$a_i\not\in\p_1$.  But the product of the $a_i$ is in the $\p_1\cdots
\p_n$, which is a subset of $\p_1$, which contradicts the fact that
$\p_1$ is a prime ideal.  Thus $\q_i=\p_1$ for some~$i$.  We can thus
cancel $\q_i$ and $\p_1$ from both sides of the equation.  Repeating
this argument finishes the proof of uniqueness.
\end{proof}

\begin{corollary}\label{thm:intuniqfac}
If $I$ is a fractional ideal of $\O_K$ then there exists 
prime ideals $\p_1,\ldots, \p_n$ and $\q_1,\ldots, \q_m$,
unique up to order, such that 
$$
  I = (\p_1\cdots \p_n)(\q_1\cdots \q_m)^{-1}.
$$
\end{corollary}
\begin{proof}
We have $I=(a/b)J$ for some $a,b\in\O_K$ and integral ideal $J$.
Applying Theorem~\ref{thm:intuniqfac} to $(a)$, $(b)$, and $J$ gives
an expression as claimed.  For uniqueness, if one has two such product
expressions, multiply through by the denominators and use the
uniqueness part of Theorem~\ref{thm:intuniqfac}
\end{proof}

\comment{\begin{example}
Consider the ring $R=\Z[\sqrt{5}]$, which is {\em not} the full ring 
of integers of $K=\Q(\sqrt{5})$.  
Then $4$ does not factor uniquely as a product of irreducible elements, since
$$
   4 = 2 \cdot 2 = (1+\sqrt{5})(-1+\sqrt{5})
$$
and $2$ and $\pm 1 + \sqrt{5}$ are both irreducible, and
their quotient is $(1+\sqrt{5})/2$, which is not in $R$ (though it is
in $\O_K$, so in $\O_K$ this is not an example of failure of unique factorization). 
To check that~$2$ is irreducible it suffices to prove that $(2)$ in $R$
is a prime ideal.  We have $\Z[x]/(x^2-x-1)\isom R$, where the isomorphism
sends~$x$ to $(1+\sqrt{5})/2$.  Then $\O_K/(2)$ is isomorphic to 
$\Z[x]/(x^2-x-1,2)$, which is isomorphic to 
$\F_2[x]/(x^2-x-1)$, which is a field, since $x^2-x-1$
is irreducible mod~$2$ (since it has no roots in $\F_2$).
Also note that $2$ and $1+\sqrt{5}$ don't just differ
by a unit, since $(1+\sqrt{5})/2$
We clearly have in $\O_K$ that 
$$
  (4) = (2)^2
$$
is the decomposition of $(4)$ as a product of primes.  
\end{example}
}
\begin{example}
The ring of integers of $K=\Q(\sqrt{-6})$ is $\O_K=\Z[\sqrt{-6}]$.
In $\O_K$, we have
$$
  6 = -\sqrt{-6}\sqrt{-6} = 2 \cdot 3.
$$ If $ab=\sqrt{-6}$, with $a,b\in \O_K$ and neither a unit, then
$\Norm(a)\Norm(b) = 6$, so without loss $\Norm(a)=2$ and
$\Norm(b)=3$. If $a=c + d\sqrt{-6}$, then $\Norm(a) = c^2 + 6d^2$;
since the equation $c^2 + 6d^2 = 2$ has no solution with $c,d\in\Z$,
there is no element in $\O_K$ with norm~$2$, so $\sqrt{-6}$ is
irreducible.  Also, $\sqrt{-6}$ is not a unit times~$2$ or times $3$,
since again the norms would not match up.  Thus $6$ can not be written
uniquely as a product of irreducibles in $\O_K$.
Theorem~\ref{thm:uniqfac}, however, implies that the principal
ideal $(6)$ can, however, be
written uniquely as a product of prime ideals.  Using MAGMA
we find such a decomposition:
\begin{verbatim}
> R<x> := PolynomialRing(RationalField());
> K := NumberField(x^2+6);
> OK := MaximalOrder(K);
> [K!b : b in Basis(OK)];
[
    1,
    K.1    // this is sqrt(-6)
]   
> Factorization(6*OK);
[
    <Prime Ideal of OK
    Two element generators:
        [2, 0]
        [2, 1], 2>,
    <Prime Ideal of OK
    Two element generators:
        [3, 0]
        [3, 1], 2>
]
\end{verbatim}
The output means that
$$
(6) = (2, 2+\sqrt{-6})^2 \cdot (3,3+\sqrt{-6})^2,
$$ where each of the ideals $(2, 2+\sqrt{-6})$ and $(3, 3+\sqrt{-6})$
is prime.  I will discuss algorithms for computing such a
decomposition in detail, probably next week.  The first idea is to
write $(6)=(2)(3)$, and hence reduce to the case of writing the $(p)$,
for $p\in\Z$ prime, as a product of primes. Next one decomposes the
Artinian ring $\O_K\tensor \F_p$ as a product of local Artinian rings.
\end{example}

\section{Algorithms for Algebraic Number Theory}
The best overall reference for algorithms for doing basic algebraic
number theory computations is Henri Cohen's book {\em A Course in
Computational Algebraic Number Theory}, Springer, GTM 138.

Our main long-term algorithmic goals for this course are to understand
good algorithms for solving the following problems in particular
cases:
\begin{itemize}
\item {\bf Ring of integers:} Given a number field $K$ (by giving a
polynomial), compute the full ring $\O_K$ of integers.
\item  {\bf Decomposition of primes:} Given a prime number 
$p\in\Z$, find the decomposition of the ideal $p\O_K$ as a product 
of prime ideals of $\O_K$.
\item {\bf  Class group:} Compute the group of equivalence classes
of nonzero ideals of $\O_K$, where $I$ and $J$
are equivalent if there exists $\alpha \in \O_K$
such that $IJ^{-1}=(\alpha)$.
\item  {\bf Units:} Compute generators for the group of 
units of $\O_K$.
\end{itemize}

As we will see, somewhat surprisingly it turns out that
algorithmically by far the most time-consuming step in computing the
ring of integers $\O_K$ seems to be to factor the discriminant of a
polynomial whose root generates the field~$K$.  The algorithm(s) for
computing $\O_K$ are quite complicated to describe, but the first step
is to factor this discriminant, and it takes much longer in practice
than all the other complicated steps.

\section{Using MAGMA}
This section is a first introduction to MAGMA for algebraic number
theory.  MAGMA is probably the best general purpose program for doing
algebraic number theory computations.  You can use it via the web page
\verb|http://modular.fas.harvard.edu/calc|.  MAGMA is not free, but if
you would like a copy for your personal computer, send me an email,
and I can arrange for you to obtain a legal copy for free. 

\begin{center}
Five minute tour of the MAGMA web page and documentation.
\end{center}

The following examples illustrate what we've done so far in the course
using MAGMA, and a little of where we are going.  Feel free to ask
questions as we go. 

\subsection{Smith Normal Form}
On the first day of class we learned about Smith normal forms
of matrices.  
\begin{verbatim}
> A := Matrix(2,2,[1,2,3,4]);
> A;
[1 2]
[3 4]
> SmithForm(A);
[1 0]
[0 2]

[ 1  0]
[-1  1]

[-1  2]
[ 1 -1]
\end{verbatim}
As you can see, MAGMA computed the Smith form, which is 
$\mtwo{1}{0}{0}{2}$.  What are the other two matrices
it output?  To see what any MAGMA command does, type
the command by itself with no arguments followed by a
semicolon.
\begin{verbatim}
> SmithForm;
Intrinsic 'SmithForm'

Signatures:

    (<Mtrx> X) -> Mtrx, AlgMatElt, AlgMatElt
    [
        k: RngIntElt, 
        NormType: MonStgElt, 
        Partial: BoolElt, 
        RightInverse: BoolElt
    ]

        The smith form S of X, together with unimodular matrices 
        P and Q such that P * X * Q = S.
\end{verbatim}
As you can see, {\tt SmithForm} returns three arguments, a matrix and
matrices $P$ and $Q$ that transform the input matrix to Smith normal
form.  The syntax to ``receive'' three return arguments is natural,
but uncommon in other programming languages:
\begin{verbatim}
> S, P, Q := SmithForm(A);
> S;
[1 0]
[0 2]
> P;
[ 1  0]
[-1  1]
> Q;
[-1  2]
[ 1 -1]
> P*A*Q;
[1 0]
[0 2]
\end{verbatim}
Next, let's test the limits.  We make a $10\times 10$ 
integer matrix with entries between $0$ and $99$,
and compute its Smith normal form.
\begin{verbatim}
> A := Matrix(10,10,[Random(100) : i in [1..100]]);
> time B := SmithForm(A);  
Time: 0.000
\end{verbatim}
Let's print the first row of $A$, the first and last
row of $B$, and the diagonal of $B$:
\begin{verbatim}
> A[1];
( 4 48 84  3 58 61 53 26  9  5)
> B[1];
(1 0 0 0 0 0 0 0 0 0)
> B[10];
(0 0 0 0 0 0 0 0 0 51805501538039733)
> [B[i,i] : i in [1..10]];
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 51805501538039733 ]
\end{verbatim}
Let's see how big we have to make~$A$ in order
to slow down MAGMA.  These timings below are on
a 1.6Ghz Pentium 4-M laptop running Magma V2.11 under 
VMware Linux.  I tried exactly the same computation
running Magma V2.17 natively under Windows XP on
the same machine, and it takes {\em twice} as long
to do each computation, which is strange.
\begin{verbatim}
> n := 50; A := Matrix(n,n,[Random(100) : i in [1..n^2]]);
> time B := SmithForm(A);  
Time: 0.050
> n := 100; A := Matrix(n,n,[Random(100) : i in [1..n^2]]);
> time B := SmithForm(A);  
Time: 0.800
> n := 150; A := Matrix(n,n,[Random(100) : i in [1..n^2]]);
> time B := SmithForm(A);  
Time: 4.900
> n := 200; A := Matrix(n,n,[Random(100) : i in [1..n^2]]);
> time B := SmithForm(A);  
Time: 19.160
\end{verbatim}

MAGMA can also work with finitely generated abelian groups.
\begin{verbatim}
> G := AbelianGroup([3,5,18]);
> G;
Abelian Group isomorphic to Z/3 + Z/90
Defined on 3 generators
Relations:
    3*G.1 = 0
    5*G.2 = 0
    18*G.3 = 0
> #G;
270
> H := sub<G | [G.1+G.2]>;
> #H;
15
> G/H;
Abelian Group isomorphic to Z/18
Defined on 1 generator
Relations:
    18*$.1 = 0
\end{verbatim}

\subsection{$\Qbar$ and Number Fields}
MAGMA has many commands for doing basic arithmetic with
$\Qbar$.
\begin{verbatim}
> Qbar := AlgebraicClosure(RationalField());
> Qbar;
> S<x> := PolynomialRing(Qbar);
> r := Roots(x^3-2);
> r;
[
    <r1, 1>,
    <r2, 1>,
    <r3, 1>
]
> a := r[1][1];
> MinimalPolynomial(a);
x^3 - 2
> s := Roots(x^2-7);
> b := s[1][1];
> MinimalPolynomial(b);
x^2 - 7
> a+b;
r4 + r1
> MinimalPolynomial(a+b);
x^6 - 21*x^4 - 4*x^3 + 147*x^2 - 84*x - 339
> Trace(a+b);
0
> Norm(a+b);
-339
\end{verbatim}
There are few commands for general algebraic number fields,
so usually we work in specific finitely generated subfields:
\begin{verbatim}
> MinimalPolynomial(a+b);
x^6 - 21*x^4 - 4*x^3 + 147*x^2 - 84*x - 339
> K := NumberField($1) ;  // $1 = result of previous computation.
> K;
Number Field with defining polynomial x^6 - 21*x^4 - 4*x^3 + 
    147*x^2 - 84*x - 339 over the Rational Field
\end{verbatim}
We can also define relative extensions of number fields
and pass to the corresponding absolute extension. 
\begin{verbatim}
> R<x> := PolynomialRing(RationalField());
> K<a> := NumberField(x^3-2);   // a is the image of x in Q[x]/(x^3-2)
> a;
a
> a^3;
2
> S<y> := PolynomialRing(K);
> L<b> := NumberField(y^2-a);
> L;
Number Field with defining polynomial y^2 - a over K
> b^2;
a
> b^6;
2
> AbsoluteField(L);
Number Field with defining polynomial x^6 - 2 over the Rational 
Field
\end{verbatim}

\subsection{Rings of integers}
MAGMA computes rings of integers of number fields.
\begin{verbatim}
> RingOfIntegers(K);
Maximal Equation Order with defining polynomial x^3 - 2 over ZZ
> RingOfIntegers(L);
Maximal Equation Order with defining polynomial x^2 + [0, -1, 0] 
over its ground order
\end{verbatim}
Sometimes the ring of integers of $\Q(a)$ isn't just $\Z[a]$.
First a simple example, then a more complicated one:
\begin{verbatim}
> K<a> := NumberField(2*x^2-3);   // doesn't have to be monic
> 2*a^2 - 3;
0
> K;
Number Field with defining polynomial x^2 - 3/2 over the Rational
Field
> O := RingOfIntegers(K);
> O;
Maximal Order of Equation Order with defining polynomial 2*x^2 - 
    3 over ZZ
> Basis(O);
[
    O.1,
    O.2
]
> [K!x : x in Basis(O)];
[
    1,
    2*a       // this is Sqrt(3)
]
\end{verbatim}
Here's are some more examples:
\begin{verbatim}
> procedure ints(f)   // (procedures don't return anything; functions do)
      K<a> := NumberField(f);
      O := MaximalOrder(K);
      print [K!z : z in Basis(O)];
  end procedure;
> ints(x^2-5);
[
    1,
    1/2*(a + 1)
]
> ints(x^2+5);
[
    1,
    a
]
> ints(x^3-17);
[
    1,
    a,
    1/3*(a^2 + 2*a + 1)
]
> ints(CyclotomicPolynomial(7));  
[
    1,
    a,
    a^2,
    a^3,
    a^4,
    a^5
]
> ints(x^5+&+[Random(10)*x^i : i in [0..4]]);  // RANDOM
[
    1,
    a,
    a^2,
    a^3,
    a^4
]
> ints(x^5+&+[Random(10)*x^i : i in [0..4]]);  // RANDOM
[
    1,
    a,
    a^2,
    1/2*(a^3 + a),
    1/16*(a^4 + 7*a^3 + 11*a^2 + 7*a + 14)
]
\end{verbatim}
Lets find out how high of a degree MAGMA can easily deal with.
\begin{verbatim}
> d := 10; time ints(x^10+&+[Random(10)*x^i : i in [0..d-1]]); 
[
    1, a, a^2, a^3, a^4, a^5, a^6, a^7, a^8, a^9
]
Time: 0.030
> d := 15; time ints(x^10+&+[Random(10)*x^i : i in [0..d-1]]); 
[
    1,
    7*a,
    7*a^2 + 4*a,
    7*a^3 + 4*a^2 + 4*a,
    7*a^4 + 4*a^3 + 4*a^2 + a,
    7*a^5 + 4*a^4 + 4*a^3 + a^2 + a,
    7*a^6 + 4*a^5 + 4*a^4 + a^3 + a^2 + 4*a,
    7*a^7 + 4*a^6 + 4*a^5 + a^4 + a^3 + 4*a^2,
    7*a^8 + 4*a^7 + 4*a^6 + a^5 + a^4 + 4*a^3 + 4*a,
    7*a^9 + 4*a^8 + 4*a^7 + a^6 + a^5 + 4*a^4 + 4*a^2 + 5*a,
    7*a^10 + 4*a^9 + 4*a^8 + a^7 + a^6 + 4*a^5 + 4*a^3 + 5*a^2 +  4*a,
  ...
]
Time: 0.480
> d := 20; time ints(x^10+&+[Random(10)*x^i : i in [0..d-1]]); 
[
    1,
    2*a,
    4*a^2,
    8*a^3,
    8*a^4 + 2*a^2 + a,
    8*a^5 + 2*a^3 + 3*a^2,
 ...]
Time: 3.940
> d := 25; time ints(x^10+&+[Random(10)*x^i : i in [0..d-1]]); 
... I stopped it after a few minutes...
\end{verbatim}

We can also define orders in rings of integers.
\begin{verbatim}
> R<x> := PolynomialRing(RationalField());
> K<a> := NumberField(x^3-2);
> O := Order([2*a]);
> O;
Transformation of Order over 
Equation Order with defining polynomial x^3 - 2 over ZZ
Transformation Matrix:
[1 0 0]
[0 2 0]
[0 0 4]
> OK := MaximalOrder(K);
> Index(OK,O);
8
> Discriminant(O);
-6912
> Discriminant(OK);
-108
> 6912/108;
64    // perfect square...
\end{verbatim}

\subsection{Ideals}
\begin{verbatim}
> R<x> := PolynomialRing(RationalField());
> K<a> := NumberField(x^3-2);
> O := Order([2*a]);
> O;
Transformation of Order over 
Equation Order with defining polynomial x^3 - 2 over ZZ
Transformation Matrix:
[1 0 0]
[0 2 0]
[0 0 4]
> OK := MaximalOrder(K);
> Index(OK,O);
8
> Discriminant(O);
-6912
> Discriminant(OK);
-108
> 6912/108;
64    // perfect square...
> R<x> := PolynomialRing(RationalField());
> K<a> := NumberField(x^2-7);
> K<a> := NumberField(x^2-5);
> Discriminant(K);
20   // ????????? Yuck!
> OK := MaximalOrder(K);
> Discriminant(OK);
5    // better
> Discriminant(NumberField(x^2-20));
80
> I := 7*OK;
> I;
Principal Ideal of OK
Generator:
    [7, 0]
> J := (OK!a)*OK;    // the ! computes the natural image of a in OK
> J;
Principal Ideal of OK
Generator:
    [-1, 2]
> I*J;
Principal Ideal of OK
Generator:
    [-7, 14]
> J*I;
Principal Ideal of OK
Generator:
    [-7, 14]
> I+J;
Principal Ideal of OK
Generator:
    [1, 0]
> 
> Factorization(I);
[
    <Principal Prime Ideal of OK
    Generator:
        [7, 0], 1>
]
> Factorization(3*OK);
[
    <Principal Prime Ideal of OK
    Generator:
        [3, 0], 1>
]
> Factorization(5*OK);
[
    <Prime Ideal of OK
    Two element generators:
        [5, 0]
        [4, 2], 2>
]
> Factorization(11*OK);
[
    <Prime Ideal of OK
    Two element generators:
        [11, 0]
        [14, 2], 1>,
    <Prime Ideal of OK
    Two element generators:
        [11, 0]
        [17, 2], 1>
]
\end{verbatim}
We can even work with fractional ideals in MAGMA.
\begin{verbatim}
> K<a> := NumberField(x^2-5);
> OK := MaximalOrder(K);
> I := 7*OK;
> J := (OK!a)*OK;
> M := I/J;
> M;
Fractional Principal Ideal of OK
Generator:
    -7/5*OK.1 + 14/5*OK.2
> Factorization(M);
[
    <Prime Ideal of OK
    Two element generators:
        [5, 0]
        [4, 2], -1>,
    <Principal Prime Ideal of OK
    Generator:
        [7, 0], 1>
]
\end{verbatim}


\subsection{Next time}
On Tuesday I will talk about discriminants and describe an
algorithm for ``factoring primes'', that is writing an
ideal $p\O_K$ as a product of prime ideals of $\O_K$.


\end{document}