\documentclass{book}
\author{William Stein}
\title{Algorithms For Computing With Modular Forms}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% 
% 1. State every algorithm and theorem that I want to prove
%    and organize them in a way that makes sense.
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\usepackage{index}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{amsthm}
\usepackage[all]{xy}
%\usepackage{python}

\newcommand{\comment}[1]{}

%\usepackage[hyperindex,pdfmark]{hyperref}
\usepackage[hypertex]{hyperref}

\newcommand{\edit}[1]{{\bf [[Todo: #1]]}}
\newcommand{\examplesession}[1]{}
\newcommand{\gzero}{\Gamma_0(N)}
\newcommand{\esM}{\overline{\sM}}
\newcommand{\sM}{\mathbb{M}}
\newcommand{\sS}{\mathbb{S}}
\newcommand{\sB}{\mathbb{B}}
\newcommand{\eE}{\mathbf{E}}
\newcommand{\Adual}{A^{\vee}}
\newcommand{\Bdual}{B^{\vee}}

\newcommand{\defn}[1]{{\em \index*{#1}}}
\newcommand{\solution}[1]{\vspace{1em}\par\noindent{\bf Solution #1.} }
\newcommand{\todo}[1]{\noindent$\bullet$ {\small \textsf{#1}} $\bullet$\\}
\newcommand{\done}[1]{\noindent {\small \textsf{Done: #1}}\\}
\newcommand{\danger}[1]{\marginpar{\small \textsl{#1}}}
\renewcommand{\div}{\mbox{\rm div}}
\DeclareMathOperator{\chr}{char}
\DeclareMathOperator{\ind}{ind}
\DeclareMathOperator{\im}{im}
\DeclareMathOperator{\oo}{\infty}
\DeclareMathOperator{\abs}{abs}
\DeclareMathOperator{\lcm}{lcm}
\DeclareMathOperator{\cores}{cores}
\DeclareMathOperator{\coker}{coker}
\DeclareMathOperator{\image}{image}
\DeclareMathOperator{\prt}{part}
\DeclareMathOperator{\proj}{proj}
\DeclareMathOperator{\Br}{Br}
\DeclareMathOperator{\Ann}{Ann}
\DeclareMathOperator{\End}{End}
\DeclareMathOperator{\Tan}{Tan}
\DeclareMathOperator{\Eis}{Eis}
\newcommand{\unity}{\mathbf{1}}
\DeclareMathOperator{\Pic}{Pic}
\DeclareMathOperator{\Vol}{Vol}
\DeclareMathOperator{\Vis}{Vis}
\DeclareMathOperator{\Reg}{Reg}
%\DeclareMathOperator{\myRes}{Res}
%\newcommand{\Res}{\myRes}
\DeclareMathOperator{\Res}{Res}
\newcommand{\an}{{\rm an}}
\DeclareMathOperator{\rank}{rank}
\DeclareMathOperator{\Sel}{Sel}
\DeclareMathOperator{\Mat}{Mat}
\DeclareMathOperator{\BSD}{BSD}
\DeclareMathOperator{\id}{id}
%\DeclareMathOperator{\dz}{dz}
\newcommand{\dz}{dz}
%\DeclareMathOperator{\Re}{Re}
\renewcommand{\Re}{\mbox{\rm Re}}
%\DeclareMathOperator{\Im}{Im}
\DeclareMathOperator{\Selmer}{Selmer}
\newcommand{\pfSel}{\widehat{\Sel}}
\newcommand{\qe}{\stackrel{\mbox{\tiny ?}}{=}}
\newcommand{\isog}{\simeq}
\newcommand{\e}{\mathbf{e}}
\newcommand{\bN}{\mathbf{N}}

% ---- SHA ----
\DeclareFontEncoding{OT2}{}{} % to enable usage of cyrillic fonts
  \newcommand{\textcyr}[1]{%
    {\fontencoding{OT2}\fontfamily{wncyr}\fontseries{m}\fontshape{n}%
     \selectfont #1}}
\newcommand{\Sha}{{\mbox{\textcyr{Sh}}}}

%\font\cyr=wncyr10 scaled \magstep 1
%\font\cyr=wncyr10

%\newcommand{\Sha}{{\cyr X}}
\newcommand{\set}{\leftarrow}
\newcommand{\Shaan}{\Sha_{\mbox{\tiny \rm an}}}
\newcommand{\TS}{Shafarevich-Tate group}

\newcommand{\Gam}{\Gamma}
\renewcommand{\Im}{\text{Im}}
\newcommand{\X}{\mathcal{X}}
\newcommand{\cH}{\mathcal{H}}
\newcommand{\cA}{\mathcal{A}}
\newcommand{\cF}{\mathcal{F}}
\newcommand{\cG}{\mathcal{G}}
\newcommand{\cJ}{\mathcal{J}}
\newcommand{\cL}{\mathcal{L}}
\newcommand{\cV}{\mathcal{V}}
\newcommand{\cO}{\mathcal{O}}
\newcommand{\cQ}{\mathcal{Q}}
\newcommand{\cX}{\mathcal{X}}
\newcommand{\ds}{\displaystyle}
\newcommand{\M}{\mathcal{M}}
\newcommand{\B}{\mathcal{B}}
\newcommand{\E}{\mathcal{E}}
\renewcommand{\L}{\mathcal{L}}
\newcommand{\J}{\mathcal{J}}
\DeclareMathOperator{\new}{new}
\DeclareMathOperator{\Morph}{Morph}
\DeclareMathOperator{\old}{old}
\DeclareMathOperator{\Sym}{Sym}
\DeclareMathOperator{\Symb}{Symb}
%\newcommand{\Sym}{\mathcal{S}{\rm ym}}
\newcommand{\dw}{\delta(w)} 
\newcommand{\dwh}{\widehat{\delta(w)}}      
\newcommand{\dlwh}{\widehat{\delta_\l(w)}} 
\newcommand{\dash}{-\!\!\!\!-\!\!\!\!-\!\!\!\!-} 
\DeclareMathOperator{\tor}{tor}  
\newcommand{\Frobl}{\Frob_{\ell}}
\newcommand{\tE}{\tilde{E}}
\renewcommand{\l}{\ell}
\renewcommand{\t}{\tau}
\DeclareMathOperator{\cond}{cond}
\DeclareMathOperator{\Spec}{Spec}
\DeclareMathOperator{\Div}{Div}
\DeclareMathOperator{\Jac}{Jac}
\DeclareMathOperator{\res}{res}
\DeclareMathOperator{\Ker}{Ker}
\DeclareMathOperator{\Coker}{Coker}
\DeclareMathOperator{\sep}{sep}
\DeclareMathOperator{\sign}{sign}
\DeclareMathOperator{\unr}{unr}
\DeclareMathOperator{\Char}{char}
\newcommand{\N}{\mathcal{N}}
\newcommand{\U}{\mathcal{U}}
\newcommand{\Kbar}{\overline{K}}
\newcommand{\Lbar}{\overline{L}}
\newcommand{\gammabar}{\overline{\gamma}}
\newcommand{\q}{\mathbf{q}}
\renewcommand{\star}{\times}
\newcommand{\gM}{\mathfrak{M}}
\newcommand{\gA}{\mathfrak{A}}
\newcommand{\gP}{\mathfrak{P}}
\newcommand{\bmu}{\boldsymbol{\mu}}
\newcommand{\union}{\cup}
\newcommand{\Tl}{T_{\ell}}
\newcommand{\into}{\rightarrow}
\newcommand{\onto}{\rightarrow\!\!\!\!\rightarrow}
\newcommand{\intersect}{\cap}
\newcommand{\meet}{\cap}
\newcommand{\cross}{\times}
\DeclareMathOperator{\md}{mod}
\DeclareMathOperator{\toric}{toric}
\DeclareMathOperator{\tors}{tors}
\DeclareMathOperator{\Frac}{Frac}
\DeclareMathOperator{\corank}{corank}
\newcommand{\rb}{\overline{\rho}}
\newcommand{\ra}{\rightarrow}
\newcommand{\xra}[1]{\xrightarrow{#1}}
\newcommand{\hra}{\hookrightarrow}
\newcommand{\kr}[2]{\left(\frac{#1}{#2}\right)}
\newcommand{\la}{\leftarrow}
\newcommand{\lra}{\longrightarrow}
\newcommand{\riso}{\xrightarrow{\sim}}
\newcommand{\da}{\downarrow}
\newcommand{\ua}{\uparrow}
\newcommand{\con}{\equiv}
\newcommand{\Gm}{\mathbb{G}_m}
\newcommand{\pni}{\par\noindent}
\newcommand{\iv}{^{-1}}
\newcommand{\alp}{\alpha}
\newcommand{\bq}{\mathbf{q}}
\newcommand{\cpp}{{\tt C++}}
\newcommand{\tensor}{\otimes}
\newcommand{\bg}{{\tt BruceGenus}}
\newcommand{\abcd}[4]{\left(
        \begin{smallmatrix}#1&#2\\#3&#4\end{smallmatrix}\right)}
\newcommand{\mthree}[9]{\left(
        \begin{matrix}#1&#2&#3\\#4&#5&#6\\#7&#8&#9
        \end{matrix}\right)}
\newcommand{\mtwo}[4]{\left(
        \begin{matrix}#1&#2\\#3&#4
        \end{matrix}\right)}
\newcommand{\vtwo}[2]{\left(
        \begin{matrix}#1\\#2
        \end{matrix}\right)}
\newcommand{\smallmtwo}[4]{\left(
        \begin{smallmatrix}#1&#2\\#3&#4
        \end{smallmatrix}\right)}
\newcommand{\twopii}{2\pi{}i{}}  
\newcommand{\eps}{\varepsilon}
\newcommand{\vphi}{\varphi}
\newcommand{\gp}{\mathfrak{p}}
\newcommand{\W}{\mathcal{W}}
\newcommand{\oz}{\overline{z}}
\newcommand{\Zpstar}{\Zp^{\star}}
\newcommand{\Zhat}{\widehat{\Z}}
\newcommand{\Zbar}{\overline{\Z}}
\newcommand{\Zl}{\Z_{\ell}}
\newcommand{\Q}{\mathbb{Q}}
\newcommand{\GQ}{G_{\Q}}
\newcommand{\R}{\mathbb{R}}
\newcommand{\D}{{\mathbf D}}
\newcommand{\cC}{\mathcal{C}}
\newcommand{\cD}{\mathcal{D}}
\newcommand{\cP}{\mathcal{P}}
\newcommand{\cS}{\mathcal{S}}
\newcommand{\Sbar}{\overline{S}}
\newcommand{\K}{{\mathbf K}}
\newcommand{\C}{\mathbb{C}}
\newcommand{\Cp}{{\mathbf C}_p}
\newcommand{\Sets}{\mbox{\rm\bf Sets}}
\newcommand{\bcC}{\boldsymbol{\mathcal{C}}}
\renewcommand{\P}{\mathbb{P}}
\newcommand{\Qbar}{\overline{\Q}}
\newcommand{\kbar}{\overline{k}}
\newcommand{\dual}{\bot}
\newcommand{\T}{\mathbb{T}}
\newcommand{\calT}{\mathcal{T}}
\newcommand{\cT}{\mathcal{T}}
\newcommand{\cbT}{\mathbf{\mathcal{T}}}
\newcommand{\cU}{\mathcal{U}}
\newcommand{\Z}{\mathbb{Z}}
\newcommand{\F}{\mathbb{F}}
\newcommand{\Fl}{\F_{\ell}}
\newcommand{\Fell}{\Fl}
\newcommand{\Flbar}{\overline{\F}_{\ell}}
\newcommand{\Flnu}{\F_{\ell^{\nu}}}
\newcommand{\Fbar}{\overline{\F}}
\newcommand{\Fpbar}{\overline{\F}_p}
\newcommand{\fbar}{\overline{f}}
\newcommand{\Qp}{\Q_p}
\newcommand{\Ql}{\Q_{\ell}}
\newcommand{\Qell}{\Q_{\ell}}
\newcommand{\Qlbar}{\overline{\Q}_{\ell}}
\newcommand{\Qlnr}{\Q_{\ell}^{\text{nr}}}
\newcommand{\Qlur}{\Q_{\ell}^{\text{ur}}}
\newcommand{\Qltm}{\Q_{\ell}^{\text{tame}}}
\newcommand{\Qv}{\Q_v}
\newcommand{\Qpbar}{\Qbar_p}
\newcommand{\Zp}{\Z_p}
\newcommand{\Fp}{\F_p}
\newcommand{\Fq}{\F_q}
\newcommand{\Fqbar}{\overline{\F}_q}
\newcommand{\Ad}{Ad}
\newcommand{\adz}{\Ad^0}
\renewcommand{\O}{\mathcal{O}}
\newcommand{\A}{\mathcal{A}}
\newcommand{\Og}{O_{\gamma}}
\newcommand{\isom}{\cong}
\newcommand{\ncisom}{\approx}   % noncanonical isomorphism
\DeclareMathOperator{\ab}{ab}
\DeclareMathOperator{\Aut}{Aut}
\DeclareMathOperator{\Frob}{Frob}
\DeclareMathOperator{\Fr}{Fr}
\DeclareMathOperator{\Ver}{Ver}
\DeclareMathOperator{\Norm}{Norm}
\DeclareMathOperator{\norm}{norm}
\DeclareMathOperator{\disc}{disc}
\DeclareMathOperator{\ord}{ord}
\DeclareMathOperator{\GL}{GL}
\DeclareMathOperator{\PSL}{PSL}
\DeclareMathOperator{\PGL}{PGL}
\DeclareMathOperator{\Gal}{Gal}
\DeclareMathOperator{\SL}{SL}
\DeclareMathOperator{\SO}{SO}
\newcommand{\galq}{\Gal(\Qbar/\Q)}
\newcommand{\rhobar}{\overline{\rho}}
\newcommand{\cM}{\mathcal{M}}
\newcommand{\cB}{\mathcal{B}}
\newcommand{\cE}{\mathcal{E}}
\newcommand{\cR}{\mathcal{R}}
\newcommand{\et}{\text{\rm\'et}}

\newcommand{\sltwoz}{\SL_2(\Z)}
\newcommand{\sltwo}{\SL_2}
\newcommand{\gltwoz}{\GL_2(\Z)}
\newcommand{\mtwoz}{M_2(\Z)}
\newcommand{\gltwoq}{\GL_2(\Q)}
\newcommand{\gltwo}{\GL_2}
\newcommand{\gln}{\GL_n}
\newcommand{\psltwoz}{\PSL_2(\Z)}
\newcommand{\psltwo}{\PSL_2}
\newcommand{\h}{\mathfrak{h}}
\renewcommand{\a}{\mathfrak{a}}
\newcommand{\p}{\mathfrak{p}}
\newcommand{\m}{\mathfrak{m}}
\newcommand{\trho}{\tilde{\rho}}
\newcommand{\rhol}{\rho_{\ell}}
\newcommand{\rhoss}{\rho^{\text{ss}}}
\newcommand{\dbd}[1]{\langle #1 \rangle}
\DeclareMathOperator{\tr}{tr}
\DeclareMathOperator{\order}{order}
\DeclareMathOperator{\ur}{ur}
\DeclareMathOperator{\Tr}{Tr}
\DeclareMathOperator{\Hom}{Hom}
\DeclareMathOperator{\Mor}{Mor}
\DeclareMathOperator{\HH}{H}
\renewcommand{\H}{\HH}
\DeclareMathOperator{\Ext}{Ext}
\DeclareMathOperator{\Tor}{Tor}
\newcommand{\smallzero}{\left(\begin{smallmatrix}0&0\\0&0
                        \end{smallmatrix}\right)}
\newcommand{\smallone}{\left(\begin{smallmatrix}1&0\\0&1
                        \end{smallmatrix}\right)}

\newcommand{\pari}{{\sc Pari}\index{Pari}}
\newcommand{\python}{{\sc Python}\index{Python}}
\newcommand{\magma}{{\sc Magma}\index{Magma}}
\newcommand{\manin}{{\sc Manin}\index{Manin}}

\newcommand{\zbar}{\overline{z}}
\newcommand{\dzbar}{d\overline{z}}

%%%% Theoremstyles
\theoremstyle{plain}
\newtheorem{theorem}{Theorem}[section]
\newtheorem{proposition}[theorem]{Proposition}
\newtheorem{corollary}[theorem]{Corollary}
\newtheorem{claim}[theorem]{Claim}
\newtheorem{lemma}[theorem]{Lemma}
\newtheorem{conjecture}[theorem]{Conjecture}

\theoremstyle{definition}
\newtheorem{definition}[theorem]{Definition}
\newtheorem{alg}[theorem]{Algorithm}
\newtheorem{question}[theorem]{Question}
\newtheorem{problem}[theorem]{Problem}

%\theoremstyle{remark}
\newtheorem{goal}[theorem]{Goal}
\newtheorem{remark}[theorem]{Remark}
\newtheorem{remarks}[theorem]{Remarks}
\newtheorem{example}[theorem]{Example}
\newtheorem{exercise}[theorem]{Exercise}

\numberwithin{section}{chapter}
\numberwithin{equation}{section}
\numberwithin{figure}{section}
\numberwithin{table}{section}

\bibliographystyle{amsalpha}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Environments
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\newenvironment{algorithm}[1]{%
\begin{alg}[#1]\index{algorithm!#1}\mbox{}\\
}%
{\end{alg}}
\newenvironment{steps}%
{\begin{enumerate}\setlength{\itemsep}{0.1ex}}{\end{enumerate}}

\newcommand{\exref}[2]{Exercise~\ref{#1}.\ref{#2}}

\newenvironment{exercises}
{\section{Exercises}
 \renewcommand{\labelenumi}{\thechapter.\theenumi}
  \begin{enumerate}
}{\end{enumerate}}

\newcommand{\hd}[1]{\vspace{1ex}\noindent{\bf #1} }
\newcommand{\nf}[1]{\underline{#1}} 
\newcommand{\cbar}{\overline{c}}
\DeclareMathOperator{\rad}{rad}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%


\makeindex

\begin{document}
\maketitle


\hfill
\begin{center}
Copyright (c) 2004 William Stein\\
\end{center}
The author grants permission to copy, distribute and/or modify this
document under the terms of the GNU Free Documentation License,
Version 1.2 or any later version published by the Free Software
Foundation; with no Invariant Sections, no Front-Cover Texts, and no
Back-Cover Texts.  A copy of the license is included in the Appendix.

\hfill

\tableofcontents

\chapter*{Preface}
\addcontentsline{toc}{chapter}{\numberline{}Preface}

This is a book about algorithms for computing with modular forms.  I
am writing it for a Fall 2004 graduate course at Harvard University.
This book is meant to answer the question ``How do {\em you} compute
spaces $M_k(N,\eps)$ of modular forms'', which theoretical
mathematicians often ask me, and to provide a rigorous foundation for
the specific algorithms I use, some of which have until now never been
formally stated or proven to be correct, except in my head while I
typed them into a computer language.

I have spent several years trying to find the best ways to compute
with classical modular forms for congruence subgroups of $\SL_2(\Z)$,
and have implemented most of these algorithms several times, first in
C++ \cite{stein:hecke}, then in MAGMA \cite{magma}, and most recently
in Python/C++ (see Chapter~\ref{ch:manin}).  Much of this work has
involved turning formulas and constructions burried in books and
papers into precise computable recipes, then testing these in many
cases and eliminating subtle inaccuracies (published theorems often
contain very small mistakes that are greatly magnified when
implemented and run on a computer). The goal of this book is to
explain what I have learned along the way, and also describe unsolved
problems whose solution would move the theory forward.

The author is aware of no other books on computing with modular forms,
the closest work being Cremona's book \cite{cremona:algs}, which is
about computing with elliptic curves, and Cohen's book
\cite{cohen:course_ant} about algebraic number theory.  This field is
not mature, and there are some missing details and potential
improvements to many of the algorithms, which you the reader might
fill in, and which would be greatly appreciated by other
mathematicians.  Also, it seems that nobody has tried to analyze the
formal complexity of any of the algorithms in this book (the author
intends to do this as he writes the book) again this is somewhere
you might contribute.

This book focuses on how best to compute the spaces $M_k(N,\eps)$ of
modular forms, where $k\geq 2$ is an integer and~$\eps$ is a Dirichlet
character modulo~$N$.  I will spend the most effort explaining the
algorithms that appear so far to be the best for such computations.
I will not discuss computing half-integral weight forms,
weight one forms, forms for non-congruence subgroups or groups other
than $\GL_2$, Hilbert and Siegel modular forms, trace formulas, or
$p$-adic modular forms.  I will also write very little about computing
with modular abelian varieties.    These are topics for another book
or two.

The reader is not assumed to have prior exposure to modular forms, but
should have a firm grasp of abstract algebra, and be familiar with
algebraic number theory, geometry of curves, algebraic topology of
Riemann surfaces, and complex analysis.  For Chapter~\ref{ch:manin},
the reader should be familiar with the Python \cite{python}
programming language.

The text of this book is licensed under the GNU Free Documentation
License, Version 1.2, November 2002.  This means that you may freely
copy this book.  For the precise details, see the Appendix.

%\noindent{}{\bf Acknowledgement:} None yet.
% \mbox{}\vspace{2ex} 

% \noindent{}William Stein\\
% {\tt http://modular.fas.harvard.edu}\\
% {\tt was@math.harvard.edu}

\vspace{2ex}
\noindent{}{\bf Acknowledgement.} 
Kevin Buzzard made many helpful remarks which were helpful in finding
the algorithms in Chapter~\ref{ch:dirichlet}.
{\bf Noam Elkies:} Remarks throughout chapters 1 and 2.
The students in Math 257.
 
\begin{itemize}
\item Abhinav Kumar (abhinav@math.harvard.edu): Discussions about
  computing width of cusp.
 
\item Thomas James Barnet-Lamb (tbl@math.harvard.edu): About how to
  represent Dirichlet characters in the computer.

\item Tseno V. Tselkov (tselkov@fas.harvard.edu)

\item Jennifer Balakrishnan (jbalakr@fas.harvard.edu)

\item Jesse Kass (kass@math.harvard.edu)

\end{itemize}


\chapter{Modular Forms of Level One}\label{ch:levelone}
This chapter follows parts of \cite[Ch.~VII]{serre:arithmetic}
closely, though we adjust the notation, definitions, and order of
presentation to be more in line with what we will do in the rest of the
book.  Note that Serre writes $2k$ everywhere instead of~$k$, which
may seem like a good idea if one is only interested in modular
forms of level~$1$, since there are no nonzero level~$1$ forms of odd
weight.  

\section{Basic Definitions}
The complex upper half plane  $\h$ is equipped with
an action of 
$$
 \SL_2(\R) = \left\{ \abcd{a}{b}{c}{d} : ad-bc=1,\text{ and } a,b,c,d\in\R\right\}
$$
via linear fractional transformations.
The \defn{modular group} is 
the subgroup $\SL_2(\Z)$ of $\SL_2(\R)$ of matrices
with integer entries.  It acts on the upper half plane
and has as fundamental domain the 
set~$D$ of elements of $\h$ that satisfy $|z|\geq 1$
and $\Re(z)\leq 1/2$ (see \cite[\S{}VII.1]{serre:arithmetic}).
Using this fundamental domain, one sees that $\SL_2(\Z)$
is generated as a group by the matrices $S=\abcd{0}{-1}{1}{0}$
and $T=\abcd{1}{1}{0}{1}$.

\begin{definition}[Weakly Modular Function]
A \defn{weakly modular function} of weight $k$ is a meromorphic
function $f$ on $\h$ that satisfies
\begin{equation}\label{eqn:modfunc}
   f(z) = (cz+d)^{-k} f(\gamma(z))
 \end{equation}
 for all $\gamma=\abcd{a}{b}{c}{d}\in\SL_2(\Z)$.
\end{definition}
Note that there are no modular forms of odd weight, since 
(\ref{eqn:modfunc}) implies $f(z) = (-1)^k f(z)$.
When $k$ is even (\ref{eqn:modfunc}) is the same as
$$f(\gamma(z))d(\gamma(z))^{k/2} = f(z)dz^{k/2},
$$
so the weight~$k$ differential form $f(z)dz^{k/2}$
is fixed by $\SL_2(\Z)$.  Note also that the product
of two weakly modular functions of weights $k_1$
and $k_2$ is a weakly modular function of weight $k_1+k_2$.

Since $\SL_2(\Z)$ is generated by $S$ and $T$, we can show
that a meromorphic function $f$ is a weakly modular function
by checking that
\begin{equation}\label{eqn:modfunc2}
  f(z+1) = f(z) \qquad\text{and}\qquad f(-1/z) = z^k f(z).
\end{equation}


Let $q=e^{2\pi i z}$.  Since $f(z+1)=f(z)$, there is a set-theoretic
function $\tilde{f}(q)$ such that $\tilde{f}(q) = f(z)$.  If, moreover,
$$
 \tilde{f}(q) = \sum_{n=m}^{\infty} a_n q^n
$$
for
some $m\in\Z$ and all~$q$ in a neighborhood of~$0$, 
we say that~$f$ is \defn{meromorphic at $\infty$}.  If
also $m\geq 0$, then we say 
that~$f$ is \defn{holomorphic at  $\infty$}.

\begin{definition}[Modular Function]
A \defn{modular function} of weight~$k$ is a weakly modular function
of weight~$k$ that is meromorphic at $\infty$.
\end{definition}

\begin{definition}[Modular Form]
A \defn{modular form} of weight~$k$ is a modular function
of weight~$k$ that is holomorphic on $\h$ and at $\infty$.
\end{definition}

If $f$ is a modular form, then there are complex numbers $a_n$
such that 
$$
  f = \sum_{n=0}^{\infty} a_n q^n,
$$
and the above series converges for all $z\in\h$
(since $f(q)$ is holomorphic on the punctured open unit
disk, its Laurent series converges absolutely
in the punctured open unit;
see also \cite[\S{}VII.4]{serre:arithmetic}
for a bound on $|a_n|$).
Also we set $f(\infty)=a_0$, since $q^{2\pi i z}\to 0$ as 
$z\to\infty$.

\begin{definition}[Modular Form]
A \defn{modular form} (of level 1) of weight~$k$ is a modular function
of weight~$k$ that is holomorphic on $\h$ and at $\infty$.
\end{definition}

\begin{definition}[Cusp Form]
A \defn{cusp form} (of level 1) of weight~$k$ is a modular form of 
weight~$k$ such that $f(\infty)=0$, i.e., $a_0=0$.
\end{definition}

If $f$ is a nonzero meromorphic function on $\h$ 
and $w\in\h$, let
$\ord_w(f)$ be the largest integer~$n$ such that
$f/(w-z)^n$ is holomorphic at $w$.
If $f = \sum_{n=m}^{\infty} a_n q^n$ with $a_m\neq 0$,
let $\ord_{\infty}(f)=m$.  We will use the following
theorem to give a presentation for the vector space
of modular forms of weight~$k$, which will make it possible
to computable a basis for that space.

\begin{theorem}[Valence Formula]\label{thm:valence}
Suppose $f$ is a modular form.  Then
$$
  \ord_{\infty}(f) + \frac{1}{2}\ord_i(f) + \frac{1}{3} \ord_{\rho}(f)
   + \sum_{w\in D}^* \ord_w(f) = \frac{k}{12},
$$
where $\sum^*$ is the sum over elements of the fundamental
domain~$D$ other than~$i$ or~$\rho$.
\end{theorem}
Serre proves this theorem in \cite[\S{}VII.3]{serre:arithmetic} using
the residue theorem from complex analysis.  We will not prove it in
this book.

\section{Eisenstein Series and Delta}\label{sec:level_one_eisen}
For an even integer $k\geq 4$, define the (not-normalized) 
\defn{weight~$k$ Eisenstein series}
to be
$$
  G_k(z) = \sum_{m,n\in\Z}^{*} \frac{1}{(mz+n)^k},
$$
where the sum is over all $m,n\in\Z$ such that $mz+n\neq 0$.

\begin{proposition}
The function $G_k(z)$ is a modular form of weight~$k$.
\end{proposition}
See \cite[\S{} VII.2.3]{serre:arithmetic}, where he proves 
that $G_k(z)$ defines a holomorphic function on $\h\union\{\infty\}$.
To see that $G_k$ is modular, note that 
$$
  G_k(z+1) = \sum^* \frac{1}{(m(z+1)+n)^k} = \sum^* \frac{1}{(mz+(n+m))^k} = 
\sum^* \frac{1}{(mz+n)^k},
$$
and
$$
G_k(-1/z) = \sum^* \frac{1}{(-m/z+n)^k} = \sum^* \frac{z^k}{(-m+nz)^k}
  = z^k \sum^* \frac{1}{(mz+n)^k} = z^k G_k(z).
$$

\begin{proposition}
$G_k(\infty) = 2\zeta(k)$,
where $\zeta$ is the Riemann zeta function.
\end{proposition}
\begin{proof}
Taking the limit as $z\to i\infty$ in the definition 
of $G_k(z)$, we obtain $\sum^*_{n\in\Z} \frac{1}{n^k}$, since
the terms involving $z$ all go to $0$ as $z\mapsto i\infty$.  
This sum is twice $\zeta(k) = \sum_{n\geq 1} \frac{1}{n^k}$.
\end{proof}

For example, one can show that
$$G_4(\infty) = 2\zeta(4) = \frac{1}{3^2\cdot 5} \pi^4$$
and 
$$G_6(\infty) = 2\zeta(6) = \frac{2}{3^3\cdot 5\cdot 7} \pi^6.$$


Suppose $E=\C/\Lambda$ is an elliptic curve over $\C$, viewed as a quotient
of $\C$ by a lattice $\Lambda=\Z\omega_1+\Z\omega_2$, with $\omega_1/\omega_2\in\h$.
Then
$$
  \wp_{\Lambda}(u) = \frac{1}{u^2} + \sum_{k=4,\text{ even}}^{\infty} (k-1)
      G_k(\omega_1/\omega_2) u^{k-2},
$$
and 
$$
  (\wp')^2 = 4\wp^3 - 60 G_4(\omega_1/\omega_2) \wp - 140 G_6(\omega_1/\omega_2).
$$
The discriminant of the cubic $4x^3 - 60G_4(\omega_1/\omega_2) x - 
140 G_6(\omega_1/\omega_2)$ is $16\Delta(\omega_1/\omega_2)$, where
$$
 \Delta = (60 G_4)^3 - 27(140 G_6)^2
$$
is a cusp form of weight $12$.  
Since~$E$ is an elliptic curve, $\Delta(\omega_1/\omega_2)\neq 0$.

\begin{proposition}\label{prop:qexpGk}
For every even integer $k\geq 2$, we have
$$
  G_k(z) = 2\zeta(k) + 2\cdot \frac{(2\pi i)^{k}}{(k-1)!}\cdot
     \sum_{n=1}^{\infty} \sigma_{k-1}(n) q^n,
$$
where $\sigma_d(n)$ is the sum of the $d$th powers of the divisors
of~$n$.
\end{proposition}
For the proof, see \cite[\S VII.4]{serre:arithmetic}, which uses 
clever manipulations of various series, starting with the identity
$$
  \pi \cot(\pi z) = \frac{1}{z} + \sum_{m=1}^{\infty} 
     \left( \frac{1}{z+m} + \frac{1}{z-m}\right).
$$

From a computational point of view, the $q$-expansion for $G_k$ from
Proposition~\ref{prop:qexpGk} is unsatisfactory, because it involves
transcendental numbers.  To understand more clearly what is going on,
we introduce the \defn{Bernoulli numbers} $B_n$ for $n\geq 0$ 
{\em defined} by the following equality of formal power series:
\begin{equation}\label{eqn:def_bernoulli}
  \frac{x}{e^x - 1} = \sum_{n=0}^{\infty} B_n \frac{x^n}{n!}.
\end{equation}
Expanding the power series on the left we have $$
\frac{x}{e^x - 1} =
1 - \frac{x}{2} + \frac{x^2}{12} - \frac{x^4}{720} + \frac{x^6}{30240}
- \frac{x^8}{1209600} + \cdots $$
As this expansion suggests, the
Bernoulli numbers $B_n$ with $n>1$ odd are~$0$ (see
\exref{ch:levelone}{ex:odd_bernoulli}).
Expanding the series further, we obtain the following table:
\vspace{0.5ex}

\noindent{}$\ds B_{0}=1,\quad B_{1}=-\frac{1}{2},\quad B_{2}=\frac{1}{6},\quad
B_{4}=-\frac{1}{30},\quad B_{6}=\frac{1}{42},\quad
B_{8}=-\frac{1}{30},\quad $\vspace{1.5ex}

\noindent{}$\ds
B_{10}=\frac{5}{66},\quad
B_{12}=-\frac{691}{2730},\quad
B_{14}=\frac{7}{6},\quad
B_{16}=-\frac{3617}{510},\quad
B_{18}=\frac{43867}{798},\quad
$\vspace{1.5ex}

\noindent{}
$\ds{}\!\!B_{20}=-\frac{174611}{330},\quad
B_{22}=\frac{854513}{138},\quad
B_{24}=-\frac{236364091}{2730},\quad
B_{26}=\frac{8553103}{6}.
%B_{28}=-\frac{23749461029}{870},\quad
$\vspace{1ex}

For us the significance of the Bernoulli numbers is their connection with
values of $\zeta$ at positive even integers.
\begin{proposition}\label{prop:zeta_even}
If $k\geq 2$ is an {\bf even} integer, then
$$
  \zeta(k) = -\frac{(2\pi i)^{k}}{2\cdot k!}\cdot B_k.
$$
\end{proposition}
The proof involves manipulating a power series expansion for $z \cot(z)$
(see \cite[\S VII.4]{serre:arithmetic}).

\begin{definition}[Normalized Eisenstein Series]
The \defn{normalized Eisenstein series} of even weight~$k\geq 4$ is
$$
  E_k = \frac{(k-1)!}{2\cdot (2\pi i)^k}\cdot G_k 
$$
\end{definition} 
Combining Propositions~\ref{prop:qexpGk} and
\ref{prop:zeta_even} we see that
\begin{equation}\label{eqn:ekexp}
 E_k = -\frac{B_k}{2k} + q + \sum_{n=2}^{\infty} \sigma_{k-1}(n) q^n.
\end{equation}

\begin{remark} {\bf Warning: } Our series $E_k$ is normalized so that
  the coefficient of~$q$ is~$1$, but most books normalize $E_k$ so
  that the constant coefficient is~$1$.  We use the normalization with
  the coefficient of~$q$ equal to~$1$, because then the eigenvalue of
  the $n$th Hecke operator (see Section~\ref{sec:hecke_one}) 
  is the coefficient of~$q^n$.  Our
  normalization will also be convenient when we consider congruences
  between cusp forms and Eisenstein series.
\end{remark}

\section{Structure Theorem}
Let $M_k$ denote the complex vector space of modular forms of weight~$k$,
and let~$S_k$ denote the subspace of cusp forms.
We have an exact sequence
$$
  0 \to S_k \to M_k \to \C 
$$
that sends $f\in M_k$ to $f(\infty)$.  When $k\geq 4$ is even,
the space $M_k$ contains $G_k$ and $G_k(\infty)=2\zeta(k)\neq 0$,
so the map $M_k\to \C$ is surjective, and $\dim(S_k)=\dim(M_k)-1$,
so
$$
  M_k = S_k \oplus \C G_k.
$$

\begin{proposition}\label{prop:mk_vanish}
For $k<0$ and $k=2$, we have $M_k=0$.  
\end{proposition}
\begin{proof}
Suppose $f\in M_k$ is nonzero yet $k=2$ or $k<0$.  By 
Theorem~\ref{thm:valence}, 
$$
  \ord_{\infty}(f) + \frac{1}{2}\ord_i(f) + \frac{1}{3} \ord_{\rho}(f)
   + \sum_{w\in D}^* \ord_w(f) = \frac{k}{12}\leq 1/6.
$$
This is impossible because each quantity on the left-hand
side is nonnegative so whatever the sum is, it is too big
(or $0$, in which $k=0$).
\end{proof}

\begin{theorem}\label{thm:delta_iso}
Multiplication by $\Delta$ defines an isomorphism $M_{k-12}\to S_k$.
\end{theorem}
\begin{proof}
(We follow \cite[\S{}VII.3.2]{serre:arithmetic} closely.)
We apply Theorem~\ref{thm:valence} to $G_4$ and~$G_6$.
If $f=G_4$, then
$$
  \ord_{\infty}(f) + \frac{1}{2}\ord_i(f) + \frac{1}{3} \ord_{\rho}(f)
   + \sum_{w\in D}^* \ord_w(f) = \frac{4}{12} = \frac{1}{3},
$$
with the $\ord$s all nonnegative,
so $\ord_{\rho}(G_4) = 1$ and $\ord_w(G_4) = 0$ for all $w\neq \rho$.
Likewise $\ord_{i}(G_6) = 1$ and $\ord_w(G_6) = 0$ for all $w\neq i$.
Thus $\Delta(i)\neq 0$, so $\Delta$ is not identically~$0$ (we
also saw this above using the Weierstrass $\wp$ function).
Since $\Delta$ has weight~$12$ and $\ord_\infty(\Delta)\geq 1$,
Theorem~\ref{thm:valence} implies that~$\Delta$ has a simple
zero at $\infty$ and does not vanish on~$\h$.
Thus if $f\in S_k$ and we let $g=f/\Delta$, then $g$ is holomorphic
and satisfies the appropriate transformation formula, so~$g$
is a modular form of weight $k-12$.
\end{proof}

\begin{corollary}
  For $k=0,4,6,8,10,14$, the vector space $M_k$ has dimension~$1$, with
  basis $1$, $G_4$, $G_6$, $E_8$, $E_{10}$, and $E_{14}$, respectively, and
  $S_k=0$.
\end{corollary}
\begin{proof}
  Combining Proposition~\ref{prop:mk_vanish} with
  Theorem~\ref{thm:delta_iso} we see that the spaces $M_k$ for $k\leq
  10$ can not have dimension bigger than~$1$, since then $M_{k'}\neq
  0$ for some $k'<0$.  Also $M_{14}$ has dimension at most $1$, since
  $M_2$ has dimension $0$.  Each of the indicated spaces of weight
  $\geq 4$ contains the indicated Eisenstein series, so has
  dimension~$1$, as claimed.
\end{proof}

\begin{corollary}\label{cor:dim1}
$\dim M_k = \begin{cases}
   0 & \text{if }k\text{ is odd}, \\ 
   \lfloor{} k/12 \rfloor{} & \text{if } k\con 2\pmod{12},\\
   \lfloor{} k/12 \rfloor{}+1 & \text{if } k\not\con 2\pmod{12},
\end{cases}
$
where $\lfloor{}x \rfloor{}$ is the biggest integer $\leq x$.
\end{corollary}
\begin{proof}
As we have seen above, the formula is true when $k\leq 12$.
By Theorem~\ref{thm:delta_iso}, the dimension increases by $1$
when~$k$ is replaced by $k+12$.
\end{proof}

\begin{theorem}\label{thm:mk_one_basis}
The space $M_k$ has as basis the
modular forms $G_4^a G_6^b$, where $a,b$
are all pairs of nonnegative integers such that 
$4a+6b=k$.
\end{theorem}
\begin{proof}
We first prove by induction that the modular forms
$G_4^a G_6^b$ generate $M_k$, the cases $k\leq 12$
being clear (e.g., when $k=0$ we have $a=b=0$ and basis~$1$).
Choose some pair of integers $a,b$ such that $4a+6b=k$ 
(it is an elementary exercise to show these exist).
The form $g=G_4^a G_6^b$ is not a cusp form, since
it is nonzero at $\infty$.  Now suppose $f\in M_k$
is arbitrary.  Since $M_k = S_k \oplus \C G_k$, there
is $\alpha\in\C$ such that $f - \alpha g \in S_k$.
Then by Theorem~\ref{thm:delta_iso}, there is $h \in M_{k-12}$
such that $f - \alpha g = \Delta h$.  By induction,
$h$ is a polynomial in $G_4$ and $G_6$ of the required
type, and so is $\Delta$, so $f$ is as well.

Suppose there is a nontrivial linear relation between the $G_4^a
G_6^b$ for a given $k$.  By multiplying the linear relation by a
suitable power of $G_4$ and $G_6$, we may assume that that we have
such a nontrivial relation with $k\con 0\pmod{12}$.  Now divide the
linear relation by $G_6^{k/12}$ to see that $G_4^3/G_6^2$ satisfies a
polynomial with coefficients in $\C$.  Hence $G_4^3/G_6^2$ is a root
of a polynomial, hence a constant, which is a contradiction since the
$q$-expansion of $G_4^3/G_6^2$ is not constant.
\end{proof}

\begin{algorithm}{Basis}\label{alg:basis}
Given integers~$n$ and~$k$, this algorithm computes
a basis of $q$-expansions for the complex vector
space $M_k$ mod $q^n$.   The $q$-expansions output
by this algorithm have coefficients in $\Q$.
\begin{steps}
\item{}[Simple Case] If $k=0$ output the basis with
just $1$ in it, and terminate; otherwise if $k<4$ or~$k$ 
is odd, output the empty basis and terminate.
\item{}[Power Series] Compute $E_4$ and $E_6$ mod $q^n$
using the formula from (\ref{eqn:ekexp}) and
the definition (\ref{eqn:def_bernoulli}) of Bernoulli
numbers.
\item{}[Initialize] Set $b\set 0$.   
%Precompute the powers $E_4^2, E_4^3, \ldots E_4^m$ mod $q^n$,
%where $m=\lfloor{} k/4\rfloor{}$, and likewise for
%$E_6$, but with $m=\lfloor{} k/6\rfloor{}$.
\item{}[Enumerate Basis] For each integer~$b$ between~$0$ and
$\lfloor k/6\rfloor$, compute $a=(k-6b)/4$.
If~$a$ is an integer, compute and output the basis
element $E_4^a E_6^b \mod{q^n}$.  When we compute, e.g.,
$E_4^a$, do the computation by finding
$E_4^m\pmod{q^n}$ for each $m\leq a$, and save these
intermediate powers, so they can be reused later, and
likewise for powers of $E_6$.
\end{steps}
\end{algorithm}
\begin{proof}
This is simply a translation of Theorem~\ref{thm:mk_one_basis}
into an algorithm, since $E_k$ is a nonzero scalar multiple
of $G_k$.  That the $q$-expansions have coefficients
in $\Q$ is Equation~\ref{eqn:ekexp}.
\end{proof}

\begin{example}
We compute a basis for $M_{24}$, which is the space with
smallest weight whose dimension is bigger than $1$.
It has as basis $E_4^6$, $E_4^3 E_6^2$, and $E_6^4$, whose explicit
expansions are
\begin{align*}
  E_4^6 &= \frac{1}{191102976000000} +
   \frac{1}{132710400000}q + \frac{203}{44236800000}q^2 + \cdots\\
E_4^3 E_6^2 &= 
    \frac{1}{3511517184000} - \frac{1}{12192768000}q - \frac{377}{4064256000}q^2
  + \cdots \\
  E_6^4 &= \frac{1}{64524128256} - \frac{1}{32006016}q + 
    \frac{241}{10668672}q^2 +\cdots 
\end{align*}
\end{example}

In Section~\ref{sec:vmthesis}, we will discuss properties
of the reduced row echelon form of any basis for $M_k$, which
have better properties than the above basis.

\section{Hecke Operators}\label{sec:hecke_one}
Let $k$ be an integer.
Define the weight~$k$ right action of $\GL_2(\Q)$ on 
functions~$f$ on $\h$ as follows.  If $\gamma=\abcd{a}{b}{c}{d}\in\GL_2(\Q)$, let
$$
  f|[\gamma]_k = \det(\gamma)^{k-1} (cz+d)^{-k} f(\gamma(z)).
$$
One checks as an exercise that 
$$
  f|[\gamma_1\gamma_2]_k = (f|[\gamma_1]_k)|[\gamma_2]_k,
$$
i.e., that this is a right group action.
Also $f$ is a weakly modular function if $f$ is meromorphic
and $f|[\gamma]_k = f$ for all $\gamma\in\SL_2(\Z)$.

For any positive integer~$n$, let
$$
S_n = \left\{\mtwo{a}{b}{0}{d} \in M_2(\Z) \,\,:\,\,
a\geq 1,\,\, ad=n, \text{ and } 0\leq b <d\right\}.
$$
Note that the set $S_n$ is in bijection with the set of sublattices of
$\Z^2$ of index~$n$, where $\abcd{a}{b}{c}{d}$ corresponds to
$L=\Z\cdot (a,b) + \Z\cdot (0,d)$, as one can see, e.g., by using
Hermite normal form (the analogue of reduced row 
echelon form over~$\Z$).


\begin{definition}[Hecke Operator $T_{n,k}$]
The~$n$th Hecke operator $T_{n,k}$ of weight~$k$
is the operator on functions on $\h$ defined by
$$
T_{n,k}(f) = \sum_{\gamma \in S_n} 
f|[\gamma]_k.
$$
\end{definition}
\begin{remark}
  It would make more sense to write $T_{n,k}$ on the right, e.g.,
  $f|T_{n,k}$, since $T_{n,k}$ is defined using a right group action.
  However, if $n,m$ are integers, then $T_{n,k}$ and $T_{m,k}$
  commute, so it doesn't matter whether we consider the Hecke
  operators as acting on the right or left.
\end{remark}

\begin{proposition}\label{prop:tn_presweak}
If $f$ is a weakly modular function of weight~$k$,
so is $T_{n,k}(f)$, and if $f$ is also a modular
function, then so is $T_{n,k}(f)$.
\end{proposition}
\begin{proof}
Suppose $\gamma\in\SL_2(\Z)$.  Since~$\gamma$ 
induces an automorphism of $\Z^2$, the set 
$$S_n \cdot \gamma = \{ \delta \gamma : \delta\in S_n\}$$
is also in bijection with the sublattices
of $\Z^2$ of index~$n$.  
Then for each element $\delta\gamma \in S_n\cdot \gamma$, there
is $\sigma\in\SL_2(\Z)$ such that $\sigma\delta\gamma\in S_n$ (the
element $\sigma$
is the transformation of $\delta\gamma$ to Hermite normal form),
and the set of elements $\sigma\delta\gamma$ is equal to $S_n$.
Thus 
$$
 T_{n,k}(f) = \sum_{\sigma\delta\gamma\in S_n} f|[\sigma\delta\gamma]_k 
     = \sum_{\delta\in S_n} f|[\delta\gamma]_k
     = T_{n,k}(f)|[\gamma]_k.
$$

That $f$ being holomorphic on $\h$ implies $T_{n,k}(f)$ is holomorphic
on $\h$ follows because each $f|[\gamma]_k$ is holomorphic on $\h$,
and a finite sum of holomorphic functions is holomorphic.
\end{proof}

We will frequently drop $k$ from the notation in $T_{n,k}$, since
the weight $k$ is implicit in the modular function to which
we apply the Hecke operator.  Thus we henceforth make the
convention that if we write $T_{n}(f)$ and~$f$ is modular, 
then we mean $T_{n,k}(f)$, where~$k$ is the weight of~$f$.

\begin{proposition}
On weight $k$ modular functions we have
\begin{equation}\label{eqn:hecke_mul}
  T_{mn} = T_{n} T_{m} \qquad\qquad\qquad\qquad\quad
 \text{if }(n,m)=1,
\end{equation}
and
\begin{equation}\label{eqn:hecke_recur}
  T_{p^n} = T_{p^{n-1}} T_p\, -\, p^{k-1} T_{p^{n-2}}, \qquad\!\!
\text{if $p$ is prime}.
\end{equation}
\end{proposition}
\begin{proof}
  Let $L$ be a lattice of index $mn$.  The quotient $\Z^2/L$ is an
  abelian group of order $mn$, and $(m,n)=1$, so $\Z^2/L$ decomposes
  uniquely as a direct sum of a subgroup order~$m$ with a subgroup of
  order~$n$.  Thus there exists a unique lattice $L'$ such that
  $L\subset L'\subset \Z^2$, and $L'$ has index $m$ in $\Z^2$.  Thus
  $L'$ corresponds to an element of $S_m$, and the index~$n$ subgroup
  $L\subset L'$ corresponds to multiplying that element on the right by some
  uniquely determined element of $S_n$.  We thus have $$
  \SL_2(\Z) \cdot S_{m} \cdot
  S_n  = \SL_2(\Z) \cdot S_{mn} $$
  i.e., the set
  products of elements in $S_m$ with elements of $S_n$ equal the
  elements of $S_{mn}$, up to $\SL_2(\Z)$-equivalence.  It then
  follows from the definitions that for any $f$, we have $T_{mn}(f) =
  T_{n}(T_m(f))$.

  We will show that $T_{p^n} + p^{k-1} T_{p^{n-2}} = T_p T_{p^{n-1}}$.
  Suppose~$f$ is a weight~$k$ weakly modular function.  
Using that $f|[p]_k = (p^2)^{k-1}p^{-k} f = p^{k-2} f$, we have
$$
 \sum_{x\in S_{p^n}} f|[x]_k\,\, +\,\, p^{k-1}\!\!\! \sum_{x\in
      S_{p^{n-2}}} f|[x]_k
   =  \sum_{x\in S_{p^n}} f|[x]_k \,\,\,+\, p\!\!\!\! \sum_{x\in pS_{p^{n-2}}} f|[x]_k.
$$
  Also $$T_p T_{p^{n-1}}(f) = \sum_{y\in S_p} \sum_{x\in S_{p^{n-1}}}
  f|[x]_k|[y]_k = \sum_{x \in S_{p^{n-1}}\cdot S_p} f|[x]_k. $$
  Thus it suffices to show that $S_{p^n}$ union~$p$ copies of $p
  S_{p^{n-2}}$ is equal to $S_{p^{n-1}}\cdot S_p$, where we consider
  elements up to $\SL_2(\Z)$-equivalence.

  Suppose~$L$ is a sublattice of $\Z^2$ of index $p^n$, so~$L$
  corresponds to an element of $S_{p^n}$.  First suppose~$L$ is not
  contained in $p\Z^2$.  Then the image of~$L$ in $\Z^2/p\Z^2 =
  (\Z/p\Z)^2$ is of order~$p$, so if $L'=p\Z^2 + L$, then
  $[\Z^2:L']=p$ and $[L:L']=p^{n-1}$, and $L'$ is the only lattice
  with this property.  Second suppose that $L\subset p\Z^2$ if of
  index $p^n$, and that $x\in S_{p^n}$ corresponds to $L$.  Then every
  one of the $p+1$ lattices $L'\subset \Z^2$ of index~$p$
  contains~$L$. Thus there are $p+1$ chains $L\subset L'\subset \Z^2$
with $[\Z^2:L']=p$.

The chains $L\subset L'\subset\Z^2$ with $[\Z^2:L']=p$ and
$[\Z^2:L]=p^{n-1}$ are in bijection with the elements of
$S_{p^{n-1}}\cdot S_p$.  On the other hand the union of $S_{p^n}$ with
$p$ copies of $p S_{p^{n-2}}$ corresponds to the lattices~$L$ of index
$p^{n}$, but with those that contain $p\Z^2$ counted $p+1$ times. The
structure of the set of chains $L\subset L'\subset\Z^2$ that we
derived in the previous paragraph gives the result.
\end{proof}

\begin{corollary}
The Hecke operator $T_{p^n}$, for prime~$p$, is a polynomial in $T_p$.
If $n,m$ are any integers then $T_n T_m = T_m T_n$.
\end{corollary}
\begin{proof}
  The first statement is clear from (\ref{eqn:hecke_recur}), and this
  gives commutativity when $m$ and $n$ are both powers of $p$.  Combining
  this with (\ref{eqn:hecke_mul}) gives the second statement in general.
\end{proof}

\begin{remark}
Emmanuel Kowalski made the following remark on the number theory lists
in June 2004 when asked about the polynomials $f_n(X)$ such
that $T_{p^n} = f_n(T_p)$.
\begin{quote}
If you normalize the Hecke operators by considering
$$
        S_{n,k} = n^{-(k-1)/2} T_{n,k}
$$
then the recursion on the polynomials $P_r(X)$ such that 
$S_{p^r,k}=P_r(S_{p,k})$ becomes
$$
        X P_r  = P_{r+1} + P_{r-1},
$$
which is the recursion satisfied by the Chebychev polynomials $U_r$ such
that
$$
        U_r(2 \cos t) = \frac{\sin((r+1) t)}{ \sin(t)}.
$$
Alternatively, those give the characters of the symmetric powers of the
standard representation of $\SL_2(\R)$, evaluated on a rotation matrix
$$
\mtwo{\cos(t)}{-\sin(t)}{\sin(t)}{\hfill \cos(t)}.
$$
For references, see for instance \cite[p.~97]{iwaniec:topics}
or \cite[p.~78, p.~81]{serre:asymptotique}, and there are certainly many others.
\end{quote}
\end{remark}

\begin{proposition}\label{prop:qexpTn}
Suppose $f = \sum_{n\in\Z} a_n q^n$ is a modular function
of weight~$k$.
Then 
$$
   T_{n}(f)
     = \sum_{m\in\Z} 
\left(\sum_{1\leq c\,\mid\, (n,m)} c^{k-1} a_{mn/c^2}\right) q^m.
$$
In particular, if $n=p$ is prime, then
$$
  T_p(f) = \sum_{m\in \Z} \left(a_{mp} + p^{k-1} a_{m/p}\right) q^m,
$$
where $a_{m/p}=0$ if $m/p\not\in\Z$.
\end{proposition}
The proposition is not that difficult to prove (or at least the proof
is easy to follow), and is proved in \cite[\S
VII.5.3]{serre:arithmetic} by writing out $T_n(f)$ explicitly and
using that $\sum_{0\leq b<d} e^{2\pi i bm/d}$ is $d$ if $d\mid m$
and~$0$ otherwise.  A corollary of Proposition~\ref{prop:qexpTn} is
that $T_n$ preserves $M_k$ and $S_k$.
\begin{corollary} The Hecke operators preserve $M_k$ and $S_k$.
\end{corollary}
\begin{remark} (Elkies) We knew this already---for $M_k$ it's
  Proposition~\ref{prop:tn_presweak}, and for $S_k$ it's easy to show
  directly that if $f(i\infty)=0$ then $T_n f$ also vanishes at
  $i\infty$.
\end{remark}

\begin{example}
Recall that 
$$
E_4 = \frac{1}{240} + q + 9q^2 + 28q^3 + 73q^4 + 126q^5 + 252q^6 + 344q^7
+\cdots.
$$
Using the formula of Proposition~\ref{prop:qexpTn}, we see
that 
$$
T_2(E_4) = (1/240 + 2^3\cdot (1/240)) + 9q + (73 + 2^3\cdot 1) q^2 + \cdots \\
    = 9 E_4.
$$
Since $M_k$ has dimension $1$, and we have proved that $T_2$
preserves $M_k$, we know that $T_2$ acts as a scalar.  Thus
we know just from the constant coefficient of $T_2(E_4)$ that
$T_2(E_4) = 9 E_4$.
More generally, $T_p(E_4) = (1+p^3)E_4$, and even more generally
$$
 T_n(E_k) = \sigma_{k-1}(n) E_k,
$$
for any integer $n\geq 1$ and even weight $k\geq 4$.
\end{example}

\begin{example}
  The Hecke operators $T_n$ also preserve the subspace $S_k$ of $M_k$.
  Since $S_{12}$ has dimension $1$, this means that $\Delta$ is an
  eigenvector for all $T_n$.  Since the coefficient of $q$ in the
  $q$-expansion of $\Delta$ is~$1$, the eigenvalue of $T_n$ on
  $\Delta$ is the $n$th coefficient of $\Delta$.  Moreover the
  function $\tau(n)$ that gives the $n$th coefficient of $\Delta$ is a
  multiplicative function.  Likewise, one can show that the series
  $E_k$ are eigenvectors for all $T_n$, and because in this book we
  normalize $E_k$ so that the coefficient of $q$ is~$1$, the
  eigenvalue of $T_n$ on $E_k$ is the coefficient $\sigma_{k-1}(n)$
  of~$q^n$.
\end{example}


\section{The Victor Miller Basis}\label{sec:vmthesis}
\begin{lemma}[Victor Miller]\label{lem:vm}
The space $S_k$ has a basis $f_1,\ldots, f_{d}$ such
that if $a_i(f_j)$ is the $i$th coefficient of $f_j$, then
$a_i(f_j) = \delta_{i,j}$ for $i=1,\ldots, {d}$.  Moreover
the $f_j$ all lie in $\Z[[q]]$.
\end{lemma}
This is a straightforward construction involving $E_4$, $E_6$
and $\Delta$.  The following proof is copied almost verbatim
from \cite[Ch.~X, Thm.~4.4]{lang:modular}, which is in turn
presumably copied from the first lemma of Victor Miller's
thesis.
\begin{proof}
Let $d=\dim S_k$.
Since $B_4 = -1/30$ and $B_6=1/42$, we note that
$$
 F_4 = -8/B_4 \cdot E_4 = 1 + 240q + 2160q^2 + 6720q^3 + 17520q^4 + \cdots
$$ and 
$$
  F_6 = -12/B_6\cdot E_6 = 1 - 504q - 16632q^2 - 122976q^3 - 532728q^4
+\cdots 
$$
have $q$-expansions in $\Z[[q]]$ with leading
coefficient~$1$.
Choose integers $a,b\geq 0$ such that 
$$
  4a+6b\leq 14 \qquad\text{and}\qquad 4a + 6b \con k \pmod{12},
$$
with $a=b=0$ when $k\con 0\pmod{12}$, and
let 
$$
  g_j = \Delta^j F_6^{2(d-j)+a} F_4^b,\qquad\qquad \text{for } j=1,\ldots,d.
$$
Then
$$
 a_j(g_j) = 1, \qquad\text{and}\qquad a_i(g_j)=0\qquad\text{when}\qquad i<j.
$$
Hence the $g_j$ are linearly independent over $\C$, and thus form
a basis for $S_k$.  Since $F_4, F_6$, and $\Delta$ are all in $\Z[[q]]$,
so are the $g_j$.  The $f_i$ may then be constructed from the $g_j$
by Gauss elimination.  The coefficients of the resulting power series lie in 
$\Z$ because each time we clear a column we use the power series
$g_j$ whose leading coefficient is $1$ (so no denominators are introduced).
\end{proof}
\begin{remark}
The basis coming from Victor Miller's lemma is canonical, 
since it is just the reduced row echelon form of any basis.
Also the {\em integral} linear combinations are precisely
the modular forms of level $1$ with integral $q$-expansion.
\end{remark}

\begin{remark}
(Elkies) 
\begin{enumerate}
\item If you have just a single form $f$ in $M_k$ to write as a polynomial
  in $E_4$ and $E_6$, then it is wasteful to compute the Victor
Miller basis.
  Instead, use the upper triangular basis $\Delta^j F_6^{2(d-j)+a} F_4^b$,
  and match coefficients from $q^0$ to $q^d$.  (Or use ``my'' recursion
  if~$f$ happens to be the Eisenstein series.)
\item When $4\mid{}k$, the zeroth form $f_0$ in the Miller basis is also
  the theta function of an extremal self-dual even lattice
  of dimension $2k$ (if one exists).  More generally, if a lattice
  is with $c$ of extremality then its theta function differs from $f_0$
  by a linear combination of  $f_d, f_{d-1}, ..., f_{d+1-c}$.
\end{enumerate}
\end{remark}

We extend the Victor Miller basis to all $M_k$ by taking
a multiple of $G_k$ with constant term $1$, and subtracting
off the $f_i$ from the Victor Miller basis so that the
coefficients of $q, q^2, \ldots q^d$ of 
the resulting expansion are $0$.  We call the extra basis
element $f_0$.




\begin{example}
If $k=24$, then $d=2$.  Choose $a=b=0$, since $k\con 0\pmod{12}$.
Then 
$$g_1 = \Delta F_6^2 = 
q - 1032q^2 + 245196q^3 + 10965568q^4 + 60177390q^5 - \cdots
$$
and 
$$
g_2 = \Delta^2 = q^2 - 48q^3 + 1080q^4 - 15040q^5 + \cdots
$$
We let $f_2=g_2$ and 
$$ 
f_1 = g_1 + 1032 g_2
 = q + 195660q^3 + 12080128q^4 + 44656110q^5 - \cdots.
$$
\end{example}
\examplesession{
> n4 := Newforms(MF(1,4))[1][1];
> F4 := n4*240;
> F4;
1 + 240*q + 2160*q^2 + 6720*q^3 + 17520*q^4 + 30240*q^5 + 
60480*q^6 + 82560*q^7 + O(q^8)
> n6 := Newforms(MF(1,6))[1][1];
> n6
> ';

>> ';
     ^
User error: Unexpected newline in literal identifier
> n6;
-1/504 + q + 33*q^2 + 244*q^3 + 1057*q^4 + 3126*q^5 + 8052*q^6 + 
16808*q^7 + O(q^8)
> F6 := n6*(-504);
> F4;
1 + 240*q + 2160*q^2 + 6720*q^3 + 17520*q^4 + 30240*q^5 + 
60480*q^6 + 82560*q^7 + O(q^8)
> F6;
1 - 504*q - 16632*q^2 - 122976*q^3 - 532728*q^4 - 1575504*q^5 - 
4058208*q^6 - 8471232*q^7 + O(q^8)
> Delta := Newforms(CS(MF(1,12)))[1][1];
> Delta;
q - 24*q^2 + 252*q^3 - 1472*q^4 + 4830*q^5 - 6048*q^6 - 16744*q^7
+ O(q^8)
> Delta*F6^2;
q - 1032*q^2 + 245196*q^3 + 10965568*q^4 + 60177390*q^5 - 
1130921568*q^6 + 870123128*q^7 + O(q^8)
> Delta^2;
q^2 - 48*q^3 + 1080*q^4 - 15040*q^5 + 143820*q^6 - 985824*q^7 + 
O(q^8)
> 1032*Delta^2 + Delta*F6^2;
q + 195660*q^3 + 12080128*q^4 + 44656110*q^5 - 982499328*q^6 - 
147247240*q^7 + O(q^8)
> S := CS(MF(1,36));
> Basis(S);
[
    q + 57093088*q^4 + 37927345230*q^5 + 5681332472832*q^6 + 
    288978305864000*q^7 + O(q^8),
    q^2 + 194184*q^4 + 7442432*q^5 - 197264484*q^6 + 
    722386944*q^7 + O(q^8),
    q^3 - 72*q^4 + 2484*q^5 - 54528*q^6 + 852426*q^7 + O(q^8)
]
}

\begin{example}
When $k=36$, the Victor Miller basis, including $f_0$, is
\begin{align*}
f_0 &= 1 + \quad\,\,\, 6218175600q^4 + 15281788354560q^5 + \cdots\\
 f_1 &= \,\,\,\,\,\,  q + \quad\,\, 57093088q^4 + 37927345230q^5 +\cdots\\
 f_2 &=  \qquad q^2 +  \,\,\,\,194184q^4 + \quad\,\,\,\,\, 7442432q^5 + \cdots \\
 f_3 &=  \qquad\quad\,\, q^3 -\,\,\,\,\,\,\, 72q^4 +\qquad\quad\,\,  2484q^5 + \cdots
\end{align*}
\end{example}


\begin{algorithm}{Hecke Operator}
  This algorithm computes a matrix for the Hecke operator $T_n$ on the
 Victor Miller basis for $M_k$.
\begin{steps}
\item{}[Compute dimension] Set $d\set \dim(S_k)$, which we
  compute using Corollary~\ref{cor:dim1}.
\item{}[Compute basis] Using the algorithm
implicit in Lemma~\ref{lem:vm}, compute a
  basis $f_0,\ldots, f_d$ for $M_k$ modulo $q^{dn+1}$.
\item{}[Compute Hecke operator] Using the formula from
  Proposition~\ref{prop:qexpTn}, compute $T_n(f_i) \pmod{q^{d+1}}$ for
  each $i$.
\item{}[Write in terms of basis]\label{usevm} The elements 
$T_n(f_i) \pmod{q^{d+1}}$
  uniquely determine linear combinations of $f_0,f_1,\ldots, f_d
  \pmod{q^d}$.  These linear combinations are trivial to find,
since the basis of $f_i$ are in reduced row echelon form.
I.e., the combinations are just the first few coefficients 
of the power series $T_n(f_i)$.
\item{}[Write down matrix] The matrix of $T_n$ acting from the left is
  the matrix whose rows are the linear combinations found in the
  previous step, i.e., whose rows are the coefficients of $T_n(f_i)$.
\end{steps}
\end{algorithm}
\begin{proof}
  First note that we only have to compute a modular form~$f$ modulo
  $q^{dn+1}$ in order to compute $T_n(f)$ modulo $q^{d+1}$.  This
  follows from Proposition~\ref{prop:qexpTn}, since in the formula the
  $d$th coefficient of $T_n(f)$ involves only $a_{dn}$, and
  smaller-indexed coefficients of~$f$.
  The uniqueness assertion of Step~\ref{usevm}
 follows from Lemma~\ref{lem:vm} above.
\end{proof}



\begin{example}
This is the Hecke operator $T_2$ on $M_{36}$:
$$
\left(
\begin{matrix}
\hfill 34359738369&\hfill0&\hfill6218175600&\hfill9026867482214400\\
0&\hfill0&\hfill34416831456&\hfill5681332472832\\
0&\hfill1&\hfill194184&\hfill-197264484\\
0&\hfill0&\hfill-72&\hfill-54528\\
\end{matrix}\right)
$$
It has characteristic polynomial 
$$
(x - 34359738369) \cdot
(x^3 - 139656x^2 - 59208339456x - 1467625047588864),
$$
where the cubic factor is irreducible.
\end{example}

\begin{conjecture}[Maeda]
The characteristic polynomial of $T_2$ on $S_k$ is irreducible for any~$k$.
\end{conjecture}

Kevin Buzzard even observed that in many specific cases the Galois
group of the characteristic polynomial of $T_2$ is the full symmetric group
(see \cite{buzzard:t2}).  See also \cite{farmer-james:maeda} for more
evidence for Maeda's conjecture.

% \section{Computing Characteristic Polynomials}
% \begin{algorithm}{Characteristic Polynomial}
% This algorithm computes the characteristic
% polynomial of $T_p$ acting on $M_k(\SL_2(\Z))$.
% \end{algorithm}
% \section{Some Open Problems}
% \subsection{Maeda's Conjecture}
% \begin{conjecture}
% The characteristic polynomial of $T_2$ is irreducible.
% \end{conjecture}

\section{Can One Compute the Coefficients of $\Delta$ in Polynomial Time?}
Let 
\begin{align*}
\Delta &= \sum_{n=1}^{\infty} \tau(n) q^n \\
  & = q - 24q^2 + 252q^3 - 1472q^4 + 4830q^5 - 6048q^6 - 16744q^7\\
  &\qquad  + 84480q^8 - 113643q^9 - 115920q^{10} + 534612q^{11} - \\
  &\qquad  370944q^{12} - 577738q^{13} + 401856q^{14} + 1217160q^{15} + \\
  &\qquad  987136q^{16} - 6905934q^{17} + 2727432q^{18} + 10661420q^{19} + 
  \cdots 
\end{align*}
be the $\Delta$-function.
\begin{conjecture}[Edixhoven]
There is an algorithm to compute $\tau(p)$, for prime $p$, that
is polynomial-time in the number of digits of~$p$.
\end{conjecture}
Bas Edixhoven and his students have been working intensely for years
to apply sophisticated techniques from arithmetic geometry (e.g.,
\'etale cohomology, motives, Arakelov theory) in order to prove that
such an algorithm exists (among other things), and he believes they
are almost there.  There is evidently a significant gap between
proving {\em existence} of an algorithm that shold be polynomial time,
and actually writing down such an algorithm with explicitly bounded
running times.  The ideas Edixhoven uses are very similar to the ones
used for counting points on elliptic curves in polynomial time (the
algorithm of Schoof, with refinements by Atkins and Elkies).

%Remark: Edixhoven once told me that if you
%could compute $\tau(n)$ for {\em all} $n$, not just prime~$n$, in
%polynomial time, then you could factor integers in polynomial time.




% \subsection{The Gouvea-Mazur Conjecture}
% \edit{False in general, but .... (copy from last year).}


\chapter{Dirichlet Characters}\label{ch:dirichlet}

Fix an integral domain~$R$ and a root~$\zeta$ of unity in~$R$.
\begin{definition}[Dirichlet Character]
  A \defn{Dirichlet character} modulo~$N$ over~$R$ with given choice
  of $\zeta\in R$ is a map $\eps:\Z\to R$ such that there
is a homomorphism $f:(\Z/N\Z)^* \to \langle \zeta \rangle$ for which
$$
 \eps(a) = \begin{cases} 
       0 &\text{if }(a,N)>1,\\
     f\,(a\!\!\!\!\mod{N}) &\text{if }(a,N)=1.
   \end{cases}
$$
\end{definition}   
We denote the group of such Dirichlet characters by $D(N,R,\zeta)$, or
by just $D(N,R)$, when the choice of $\zeta$ is clear.  It follows
immediately from the definition that elements of
$D(N,R)$ are in bijection with  homomorphisms $(\Z/N\Z)^* \to
\langle \zeta \rangle$.

In this chapter we develop a systematic theory for computing
with Dirichlet characters.   These will be extremely important
everywhere in the rest of this book, when we compute with
spaces $M_k(\Gamma_1(N))$ of modular forms for 
$$
  \Gamma_1(N) = \left\{ \mtwo{a}{b}{c}{d} \in \SL_2(\Z) : 
                    \mtwo{a}{b}{c}{d}\con \mtwo{1}{*}{0}{1}\pmod{N}
                \right\}.
$$
For example, Eisenstein series in $M_k(\Gamma_1(N))$ are associated
to pairs of Dirichlet characters.  Also the complex vector space 
$M_k(\Gamma_1(N))$ with its structure as a module over the Hecke algebra
decomposes as a direct sum
$$
    M_k(\Gamma_1(N)) = \bigoplus_{\eps\in D(N,\C)} M_k(\Gamma_1(N))(\eps).
$$
Each space $M_k(\Gamma_1(N))(\eps)$ is frequently much easier
to compute with than the full $M_k(\Gamma_1(N))$.    
For example, $M_2(\Gamma_1(100))$ has dimension $370$, whereas
$M_2(\Gamma_1(100))(1)$ has dimension only $24$, and 
$M_2(\Gamma_1(389))$ has dimension $6499$, whereas
$M_2(\Gamma_1(389))(1)$ has dimension only $33$.

\begin{remark}
If 
$$
  \Gamma_0(N) = \left\{ \mtwo{a}{b}{c}{d} \in \SL_2(\Z) : 
                    \mtwo{a}{b}{c}{d}\con \mtwo{*}{*}{0}{*}\pmod{N}
                \right\},
$$
then $M_k(\Gamma_1(N))(1) = M_k(\Gamma_0(N))$.
\end{remark}

\section{Representation and Arithmetic}
\begin{lemma}\label{lem:dual}
  The groups $(\Z/N\Z)^*$ and $\Hom((\Z/N\Z)^*,\C^*)\isom D(N,\C^*)$
  are non-canonically isomorphic.
\end{lemma}
\begin{proof}
  This follows from the more general fact that for any abelian
  group~$G$, we have that $G\ncisom \Hom(G,\C^*)$.  To prove that this
  latter non-canonical isomorphism exists, first reduce to the case
  when~$G$ is cyclic of order~$n$, in which case the statement follows
  because $\zeta_n\in\C^*$, so $\Hom(G,\C^*)\isom \Hom(G,\langle
  \zeta_n\rangle)$ is also cyclic of order~$n$.
\end{proof}

\begin{corollary}\label{cor:dir_ord}
We have $\#D(N,R) \mid \vphi(N)$, with equality
if and only if the order of our choice of $\zeta\in R$
is a multiple of the exponent of the group $(\Z/N\Z)^*$.
\end{corollary}

\begin{example}
The group $D(5,\C)$ has elements 
$\{[1], [i], [-1], [-i]\}$,
so is cyclic of order $\vphi(5)=4$.
In contrast,  the group $D(5,\Q)$ has only the
two elements $[1]$ and $[-1]$ and order $2$.
\end{example}

Fix a positive integer~$N$, and write $N=\prod_{i=1}^{n} {p_i^{e_i}}$
where $p_1<p_2<\cdots < p_n$ are the prime divisors of~$N$.  By
\exref{ch:dirichlet}{ex:cyclic}, each factor $(\Z/p_i^{e_i}\Z)^*$ is a
cyclic group $C_i=\langle g_i \rangle$, except if $p_1=2$ and $e_1\geq
3$, in which case $(\Z/p_1^{e_1}\Z)^*$ is a product of the cyclic
subgroup $C_0 = \langle -1 \rangle$ of order $2$ with the cyclic
subgroup $C_1 = \langle 5\rangle$.  In all
cases we have $$
(\Z/N\Z)^* \isom \prod_{0\leq i\leq n} C_i = \prod_{0\leq i \leq n} \langle g_i \rangle.
$$
For~$i$ such that $p_i>2$, choose the generator $g_i$ of $C_i$ to be
the element of $\{2,3,\ldots, p_i^{e_i}-1\}$ that is smallest and
generates.  Finally, use the Chinese Remainder Theorem (see
\cite[\S1.3.3]{cohen:course_ant})) to lift each $g_i$ to an element in
$(\Z/N\Z)^*$, also denoted $g_i$, that is~$1$ modulo each $p_j^{e_j}$
for $j\neq i$.

\begin{algorithm}{Minimal generator for $(\Z/p^r\Z)^*$}\label{alg:mingens}
Given an odd prime power $p^r$, this algorithm computes
a minimal generator for $(\Z/p^r\Z)^*$.
\begin{steps}
\item{}[Factor Group Order] Factor $n=\phi(p^r) = p^{r-1}\cdot 2\cdot
  ((p-1)/2)$ as a product $\prod p_i^{e_i}$ of primes.  This is
  equivalent in difficulty to factoring $(p-1)/2$.  (See chapters 8
  and 10 of \cite{cohen:course_ant} for integer factorization
  algorithms.)
\item{}[Initialize]\label{step:gen_init} Set $g\set 2$.  
\item{}[Generator?] Using the binary powering algorithm (see
  \cite[\S1.2]{cohen:course_ant}), compute $g^{n/p_i}\pmod{p^r}$, for
  each prime divisor $p_i$ of~$n$.  If any of these powers are $1$,
  set $g\set g+1$ and go to Step~\ref{step:gen_init}. 
If no powers are $1$, output $g$ and terminate.
\end{steps}
\end{algorithm}
For the proof, see \exref{ch:dirichlet}{ex:orderalg}.

\begin{example}
A minimal generator for $(\Z/49\Z)^*$ is $3$.  
We have $n=\vphi(49)=42=2\cdot 3\cdot 7$, and 
$$
  2^{n/2} \con 1, \qquad 2^{n/3} \con 18, \qquad 2^{n/7} \con 15 \pmod{49}.
$$
so $2$ is not a generator for $(\Z/49\Z)^*$.  (We see
this just from $2^{n/2}\con 1\pmod{49}$.)  However 
$$
  3^{n/2} \con 48, \qquad 3^{n/3} \con 30, \qquad 3^{n/7} \con 43 \pmod{49}.
$$
\end{example}

\begin{example}\label{ex:mingens}
In this example
we compute minimal generators for $N=25$, $100$, and $200$:
\begin{enumerate}
\item
The minimal generator for $(\Z/25\Z)^*$ is $2$.

\item
Minimal generators for $(\Z/100\Z)^*$, lifted
to numbers modulo $100$, are $g_0=51$, $g_1=1$ and $g_2=77$.
Notice that $g_0\con -1\pmod{4}$ and $g_0\con 1\pmod{25}$, that $g_1=1$ since $2\mid N$, but
$8\nmid N$, and $g_2\con 2\pmod{25}$ is the minimal generator modulo~$25$.

\item
Minimal generators for $(\Z/200\Z)^*$, lifted
to numbers modulo $200$, are 
$g_0 = 151$, $g_1 = 101$, and $g_2=177$.  Note
that $g_0\con -1\pmod{4}$, that $g_1\con 5\pmod{8}$,
and $g_2\con 2\pmod{25}$.
\end{enumerate}
\end{example}

Fix an element~$\zeta$ of finite multiplicative order in a ring~$R$,
and let $D(N,R)$ denote the group of Dirichlet characters modulo~$N$
over~$R$, with image in $\langle \zeta\rangle \union \{0\}$.  We
specify an element $\eps\in D(N,R)$ by giving the list
\begin{equation}\label{eqn:epslist}
[\eps(g_0), \eps(g_1), \ldots, \eps(g_n)]
\end{equation}
of images of the generators of $(\Z/N\Z)^*$.  (Note if $N$ is even,
the number of elements of the list (\ref{eqn:epslist}) does {\em not}
depend on whether or not $8\mid N$---there are always two factors
corresponding to $2$.)  This representation completely
determines~$\eps$ and is convenient for arithmetic operations with
Dirichlet characters.  It is analogous to representing a linear
transformation by a matrix.  See Section~\ref{sec:alter_rep} for
a discussion of alternative ways to represent Dirichlet characters.


\begin{example}\label{ex:char}
If $N=200$, then $g_0=151$, $g_1=101$ and $g_2=177$, as
we saw in Example~\ref{ex:mingens}.  The
exponent of $(\Z/200\Z)^*$ is $20$, since that
is the least common multiple of the exponents of
$4=\#(\Z/8\Z)^*$ and $20=\#(\Z/25\Z)^*$.
The orders of $g_0$, $g_1$ and $g_2$ are $2$, $2$, and $20$.
Let $\zeta=\zeta_{20}$ be a primitive $20$th root of
unity in $\C$.  Then the following are generators
for $D(20,\C)$:
$$
  \eps_0 = [-1,1,1],\qquad
  \eps_1 = [1,-1,1],\qquad
  \eps_2 = [1,1,\zeta],
$$
and $\eps=[1,-1,\zeta^5]$ is an example element of order~$4$.
To evaluate $\eps(3)$, we write~$3$ in
terms of $g_0$, $g_1$, and $g_2$.
First, reducing $3$ modulo~$8$, we see that 
$3 \con g_0 \cdot g_1\pmod{8}$.  Next 
reducing $3$ modulo $25$, and trying powers of 
$g_2=2$, we find that $e\con g_2^7\pmod{25}$.  
Thus 
\begin{align*}
  \eps(3) &= \eps(g_0 \cdot g_1 \cdot g_2^7)\\
          &= \eps(g_0) \eps(g_1) \eps(g_2)^7\\
          &= 1 \cdot (-1) \cdot (\zeta^5)^7\\
          &= -\zeta^{35} = -\zeta^{15}.
\end{align*}
\end{example}

Example~\ref{ex:char} illustrates that if~$\eps$ is represented using
a list as described above, evaluation of~$\eps$ on an arbitrary
integer is inefficient without extra information; it requires solving
the discrete log problem in $(\Z/N\Z)^*$.  In fact, for a general
character~$\eps$ calculation of~$\eps$ will probably be at least as
hard as finding discrete logarithms no matter what representation we
use (quadratic characters are easier---see Algorithm~\ref{alg:kronecker}).
\begin{algorithm}{Evaluate $\eps$}\label{alg:eval_eps}
Given a Dirichlet character $\eps$ modulo~$N$, represented
by a list $[\eps(g_0), \eps(g_1), \ldots, \eps(g_n)]$,
and an integer~$a$, this algorithm computes~$\eps(a)$.
\begin{steps}
\item{}[GCD] Compute $g=\gcd(a,N)$.  If $g>1$, output~$0$ and terminate.
\item{}[Discrete Log]\label{step:eval_fb} For each $i$, write $a\pmod{p_i^{e_i}}$ as a
  power $m_i$ of $g_i$ using some algorithm for solving the discrete
  log problem (see below).  (If $p_i=2$, write
  $a\pmod{p_i^{e_i}}$ as $(-1)^{m_0}\cdot 5^{m_1}$.)  This step is
  analogous to writing a vector in terms of a basis.
\item{}[Multiply] Compute and output $\prod \eps(g_i)^{m_i}$ as an
  element of~$R$, and terminate.  This is analogous to multiplying a
  matrix times a vector.
\end{steps}
\end{algorithm}
By \exref{ch:dirichlet}{ex:dlogadd} we have an isomorphism
of groups
$$
(1+p^{n-1}(\Z/p^n\Z),\,\times) \isom (\Z/p\Z,\,+),
$$
so one sees by
induction that Step~\ref{step:eval_fb} is ``about as difficult'' as finding a
discrete log in $(\Z/p\Z)^*$.  There is an algorithm called
``baby-step giant-step'', which solves the discrete log problem in
$(\Z/p\Z)^*$ in time $O(\sqrt{\ell})$, 
where $\ell$ is the largest prime factor of $p-1=\#(\Z/p\Z)^*$
(note that the discrete log problem in $(\Z/p\Z)^*$ reduces
to a series of discrete log problems in each prime order cyclic
factor).
This is unfortunately still
exponential in the number of digits of~$\ell$.
\begin{algorithm}{Baby-Step Giant Step Discrete Log}
\label{alg:baby_giant_dlog}
Given a prime $p$, a generator $g$ of $(\Z/p\Z)^*$,
and an element $a\in (\Z/p\Z)^*$, this algorithm
finds an $n$ such that $g^n=a$.  
(Note that this algorithm works in any cyclic group,
not just $(\Z/p\Z)^*$.)
\begin{steps}
\item{}[Make Lists] 
Let $m=\lceil{} \sqrt{p}\rceil{}$ be the ceiling of $\sqrt{p}$,
and
construct two lists $$
g,\, g^m,\, \ldots, \,g^{(m-1)m}, g^{m^2}
\qquad\qquad\text{(giant steps)} $$
and 
$$
ag,\, ag^2,\, \ldots, \,
ag^{m-1}, ag^m \qquad\qquad\text{(baby steps)}.
$$
\item{}[Find Match]\label{step:find_match}
Sort the two lists and
find a match $g^{im} = a g^j$. Then $a = g^{im-j}$.
\end{steps}
\end{algorithm}
\begin{proof}
  We prove that there will always be a match. Since we know that $a=g^k$ for some $k$
  with $0\leq k\leq p-1$ and any such $k$ can be written in the form
  $im-j$ for $0\leq i,j\leq m-1$, we will find such a match.
\end{proof}

Algorithm~\ref{alg:baby_giant_dlog} uses nothing special about
$(\Z/p\Z)^*$, so it works in a generic group.  It is a theorem that
there is no faster algorithm to find discrete logs in a ``generic
group'' (see \cite{shoup:lower,nechaev:lower}).  Fortunately there are
much better subexponential algorithms for solving the discrete log
problem in $(\Z/p\Z)^*$, which use the special structure of this group.
They use the number field sieve (see e.g., \cite{gordon:dlog}), which
is also the best known algorithm for factoring integers.  This class
of algorithms has been very well studied by cryptographers; though
sub-exponential, solving discrete log problems when $p$ is large is
still extremely difficult.  For a more in-depth survey see
\cite{gordon:dlp}.

\begin{example}
  MAGMA contains an algorithm to compute discrete logarithms in
  $(\Z/p\Z)^*$ for small $p$.  Using a Pentium-M 1.8Ghz, I used MAGMA
  to compute a few discrete logs.  The commands below create $\Z/p\Z$
  in MAGMA, then let $U$ be the unit group $(\Z/p\Z)^*$, and finally
  find the power of the minimal generator that equals $100$.  The
  resulting timings below are horrible.  After a few seconds of
  discussion with Allan Steel of MAGMA, it emerged that the MAGMA code
  below causes MAGMA V2.11-8 to use an $O(p)$ check through all
  possibilities.  Presumably, this will be fixed soon.
%session
\begin{verbatim}
> G := Integers(NextPrime(10^5)); U,f := UnitGroup(G);
> time 100@@f;
54580*U.1
Time: 0.000
> G := Integers(NextPrime(10^6)); U,f := UnitGroup(G);
> time 100@@f;
584760*U.1
Time: 0.020
> G := Integers(NextPrime(10^7)); U,f := UnitGroup(G);
> time 100@@f;
9305132*U.1
Time: 0.320
> G := Integers(NextPrime(10^8)); U,f := UnitGroup(G);
> time 100@@f;
83605942*U.1
Time: 2.940
> G := Integers(NextPrime(10^9)); U,f := UnitGroup(G); 
> time 100@@f;
763676566*U.1
Time: 27.780
> G := Integers(NextPrime(10^10)); U,f := UnitGroup(G);
> time 100@@f;
8121975284*U.1
Time: 3150.470
\end{verbatim}
Currently the {\em right} way to request computation of a discrete
logarithm in MAGMA is to use the {\tt Log} command.  Using this
command we obtain the above logarithms much more quickly:
\begin{verbatim}
> p := NextPrime(10^5); k := GF(p); a := k!PrimitiveRoot(p);
> time Log(k!a, k!100);
54580
Time: 0.000
> p := NextPrime(10^8); k := GF(p); a := k!PrimitiveRoot(p);
> time Log(k!a, k!100);
83605942
Time: 0.000
> p := NextPrime(10^12); k := GF(p); a := k!PrimitiveRoot(p);
> time Log(k!a, k!100);
837165108486
Time: 0.000
> p := NextPrime(10^15); k := GF(p); a := k!PrimitiveRoot(p);
> time Log(k!a, k!100);
543584576740840
Time: 0.060
> p := NextPrime(10^20); k := GF(p); a := k!PrimitiveRoot(p);
> time Log(k!a, k!100);
55635183831704631320
Time: 0.210
> p := NextPrime(10^25); k := GF(p); a := k!PrimitiveRoot(p);
> time Log(k!a, k!100);
8669816947492932609764592
Time: 0.480
> p := NextPrime(10^35); k := GF(p); a := k!PrimitiveRoot(p);
> time Log(k!a, k!100);
28138566543929117345335749648530454
Time: 5.610
> Factorization(p-1);
[ <2, 2>, <3, 1>, <31, 1>, <59, 1>, <36289857533, 1>, 
                            <125550886981850531627, 1> ]
> p := NextPrime(p);
> Factorization(p-1);
[ <2, 1>, <72229, 1>, <692242727990142463553420371319, 1> ]
> k := GF(p); a := k!PrimitiveRoot(p);
> time Log(k!a, k!100);
23346611965343882546546326674895020
Time: 4.940
\end{verbatim}
Thus one can deal with primes having around $35$ digits in a few seconds.
Moral: Having an understanding of the theoretical complexity of
an algorithm, is much better than just some timing with an implementation,
becuause you might unwittingly misuse the implementation.
\end{example}


The specific applications of Dirichlet characters in this book involve
computing modular forms, and for these applications~$N$ will be fairly
small, e.g., $N<10^6$.  Also we will evaluate~$\eps$ on a {\em huge}
number of random elements, inside inner loops of algorithms.  Thus for
our purposes it will often be better to make a table of all values
of~$\eps$, so that evaluation of~$\eps$ is extremely fast.  The
following algorithm computes a table of all values of $\eps$, and it
does not require computing any discrete logs since we are computing
{\em all} values.

\begin{algorithm}{Values of $\eps$}
Given a Dirichlet character $\eps$ represented by the list
of values of $\eps$ on the minimal generators $g_i$ of $(\Z/N\Z)^*$, this algorithm
creates a list of all the values of $\eps$.
\begin{steps}
\item{}[Initialize] For each minimal generator $g_i$, set $a_i\set 0$.
  Let $n = \prod g_i^{a_i}$, and set $z\set 1$.  Create a list~$v$
  of~$N$ values, all initially set equal to $0$.  When this algorithm
  terminates the list~$v$ will have the property that 
  $$v\,\,[x
  \!\!\!\!\!\pmod{N}] = \eps(x).$$
  Notice that we index $v$ starting
  at $0$.
\item{}[Add Value to Table]\label{step:add_value} Set $v[n] \set z$.
\item{}[Finished?] If each $a_i$ is one less than the order of $g_i$, output~$v$ 
and terminate.
\item{}[Increment] Set $a_0\set a_0 + 1$, $n\set n\cdot g_0\pmod{N}$,
and $z\set z\cdot \eps(g_0)$.  If $a_0\geq \ord(g_0)$, set $a_0\to 0$,
then set $a_1\set a_1 + 1$, $n\set n\cdot g_1\pmod{N}$, and 
$z\set z\cdot \eps(g_1)$.  If $a_1\geq \ord(g_1)$, do what you just
did with $a_0$, but with all subscripts replaced by $1$.  Etc.
(Imagine a car odometer.)  Go to Step~\ref{step:add_value}.
\end{steps}
\end{algorithm}



% \begin{algorithm}{Unit Generators}
% Given an integer~$N$, this algorithm finds minimal generators for the
% cyclic factors of $(\Z/N\Z)^*$ corresponding to the prime powers that
% exactly divide~$N$.
% \end{algorithm}

% \begin{algorithm}{Generators}
%   Given an integer $N$ and a root of unity $\zeta\in R$, this
%   algorithm computes generators for the group of Dirichlet characters
%   modulo~$N$ with values in $\langle \zeta \rangle \union \{0 \}$.
% \end{algorithm}

Frequently people describe quadratic characters in terms of the
Kronecker symbol. The following algorithm gives a way to go between
the two representations.

\begin{algorithm}{Kronecker Symbol}\label{alg:kronecker}
  Given an integer~$N$, this algorithm computes a representation of
  the Kronecker symbol $\kr{a}{N}$ as a Dirichlet character.
\begin{steps}
\item Compute the minimal generators $g_i$ of $(\Z/N\Z)^*$
using Algorithm~\ref{alg:mingens}.
\item Compute $\kr{g_i}{N}$ for each $g_i$ using one
of the algorithms of \cite[\S1.1.4]{cohen:course_ant}.
\end{steps}
\end{algorithm}
\begin{remark}
  The algorithms in \cite[\S1.1.4]{cohen:course_ant} for computing the
  Kronecker symbol run in time quadratic in the number of digits of
  the input, so they do not require computing discrete logarithms.
(They use, e.g., that $\kr{a}{p} \con a^{(p-1)/2}\pmod{p}$, when
$p$ is an odd prime.)
  If~$N$ is very large and we are only interested in evaluating
  $\eps(a) = \kr{a}{N}$ for a few $a$, then viewing~$\eps$ as a
  Dirichlet character in the sense of this chapter leads to a less
  efficient way to compute with~$\eps$.  The algorithmic discussion of
  characters in this chapter is most useful for working with the full
  group of characters, and characters that cannot be expressed in
  terms of Kronecker characters.
\end{remark}

\begin{example}
We compute the Dirichlet character associated to the
Kronecker symbol $\kr{a}{200}$. Using PARI, we
find that $\kr{g_i}{200}$, for $i=0,1,2$, where the
$g_i$ are as in Example~\ref{ex:char}:
%session
\begin{verbatim}
? kronecker(151,200)
1
? kronecker(101,200)
-1
? kronecker(177,200)
1
\end{verbatim}
Thus the corresponding character is defined by $[1,-1,1]$.
\end{example}

\begin{remark}[Elkies]
  Jacobi reciprocity must be used to efficiently compute the Jacobi
  symbol $\kr{m}{n}$.  It's faster than computing $a^{(p-1)/2}$
  when~$p$ is prime, but more significantly it makes it possible to
  compute Jacobi symbols $\kr{m}{n}$ for all $m,n$ without knowing the
  factorization of~$n$---which of course would be a computation much
  longer than quadratic.
\end{remark}


\begin{example}
We compute the character associated to $\kr{a}{420}$.
We have $420=4\cdot 3\cdot 5\cdot 7$, and minimal generators
are 
$$
  g_0 = 211,\quad g_1=1, \quad g_2 = 281, \quad g_3=337, \quad g_4=241.
$$
We have $g_0\con -1\pmod{4}$, $g_2\con 2\pmod{3}$, $g_3\con 2\pmod{5}$
and $g_4\con 3\pmod{7}$.
Using PARI again we find $\kr{g_0}{420}=\kr{g_1}{420}=1$
and $\kr{g_2}{420}=\kr{g_3}{420}=\kr{g_4}{420}=-1$, so the
corresponding character is $[1,1,-1,-1,-1]$.
\end{example}

\section{Algorithms}

The following algorithm for computing the order of~$\eps$ reduces
the problem to computing the orders of powers of $\zeta$ in $R$.
\begin{algorithm}{Order of Character}\label{alg:dir_order}
  This algorithm computes the order of a Dirichlet
  character $\eps\in D(N,R)$.
\begin{steps}
\item Compute the order $r_i$ of each $\eps(g_i)$, for each minimal
  generator $g_i$ of $(\Z/N\Z)^*$.  Since the order of $\eps(g_i)$ is
  divisor of $n=\#(\Z/p_i^{e_i}\Z)^*$, we can compute its order by
  factoring~$n$ and considering the divisors of~$n$.
\item Compute and output the least commmon multiple of the integers
  $r_i$.
\end{steps}
\end{algorithm}
\begin{remark}
  Computing the order of $\eps(g_i) \in R$ is potentially difficult
  and tedious.  Using a different (simultaneous) representation of
  Dirichlet characters avoids having to compute the order of elements
  of $R$.  See Section~\ref{sec:alter_rep}.
\end{remark}


The next algorithm factors $\eps$ as a product of ``local'' characters,
one for each prime divisor of $N$.  It is useful for other algorithms,
and also for explicit computations with the Hijikita trace formula 
(see \cite{hijikata:trace}). This factorization is easy to compute
because of how we represent $\eps$.

\begin{algorithm}{Factorization of Character}\label{alg:dirfac}
Given a Dirichlet character $\eps\in D(N,R)$, with $N=\prod p_i^{e_i}$, 
this algorithm finds Dirichlet characters $\eps_i$ modulo $p_i^{e_i}$, such
that for all $a\in(\Z/N\Z)^*$, we have 
$\eps(a) = \prod \eps_i(a\!\!\pmod{p_i^{e_i}})$.
If $2\mid N$, the steps are as follows:
\begin{steps}
\item Let $g_i$ be the minimal generators of $(\Z/N\Z)^*$, so $\eps$
is given by a list $$[\eps(g_0),\ldots, \eps(g_n)].$$
\item\label{step:singletons} For $i=2,\ldots, n$, let $\eps_i$ be the element of $D(p_i^{e_i},R)$
defined by the singleton list $[\eps(g_i)]$.
\item\label{step:extra2} Let $\eps_1$ be the element of $D(2^{e_1},R)$ defined
by the list $[\eps(g_0), \eps(g_1)]$ of length~$2$.   Output the
$\eps_i$ and terminate.
\end{steps}
If $2\nmid N$, then omit Step~\ref{step:extra2}, and include
all $i$ in Step~\ref{step:singletons}.
\end{algorithm}
The factorization of Algorithm~\ref{alg:dirfac} is unique since each
$\eps_i$ is determined by the image of the canonical map
$(\Z/p_i^{e_i}\Z)^*$ in $(\Z/N\Z)^*$, which sends $a\pmod
{p_i^{e_i}}$ to the element of $(\Z/N\Z)^*$ that is
$a\pmod{p_i^{e_i}}$ and $1 \pmod{p_j^{e_j}}$ for $j\neq i$.

\begin{example}\label{ex:prodlocal}
If $\eps = [1,-1,\zeta^5] \in D(200,\C)$, then 
$\eps_1 = [1,-1]\in D(8,\C)$ and $\eps_2 = [\zeta^5]\in D(25,\C)$.
\end{example}



\begin{definition}[Conductor]
The \defn{conductor} of a Dirichlet character $\eps\in D(N,R)$
is the smallest positive divisor $c\mid N$ such that 
there is a character $\eps' \in D(c,R)$ for which 
$\eps(a) = \eps'(a)$ for all $a\in\Z$ with $(a,N)=1$.
A Dirichlet character is \defn{primitive} if its modulus equals
its conductor.  The character $\eps'$ associated to~$\eps$
with modulus equal to the conductor of~$\eps$ is called
the \defn{primitive character associated to}~$\eps$.
\end{definition}
We will be interested in conductors later, when computing new
subspaces of spaces of modular forms with character.  Also certain
formulas for special values of~$L$ functions are only valid for
primitive characters.

\begin{algorithm}{Conductor}\label{alg:conductor}
  This algorithm computes the conductor of a Dirichlet
  character~$\eps \in D(N,R)$.
\begin{steps}
\item{}[Factor Character]\label{step:factor_dir} Using Algorithm~\ref{alg:dirfac}, find
  characters~$\eps_i$ whose product is~$\eps$.
\item{}[Compute Orders] Using Algorithm~\ref{alg:dir_order}, compute
  the orders~$r_i$ of each~$\eps_i$.
\item{}[Conductors of Factors]\label{step:cond_fac}
For each $i$, either set $c_i\to 1$ if $\eps_i$
is the trivial character (i.e., of order $1$), or set $c_i \set
  p_i^{\ord_{p_i}(r_i)+1}$, where $\ord_{p}(n)$ is the largest power
  of $p$ that divides~$n$.
\item{}[Adjust at $2$?] If $p_1=2$ and $\eps_1(5)\neq 1$, set
$c_1\set 2c_1$.  
\item{}[Finished] Output $c = \prod c_i$ and terminate.
\end{steps}
\end{algorithm}
\begin{proof}
Let $\eps_i$ be the local factors of~$\eps$, as in Step~\ref{step:factor_dir}.
We first show that the product of the conductors $f_i$ of the $\eps_i$ is
the conductor~$f$ of~$\eps$.  Since $\eps_i$ factors through $(\Z/f_i\Z)^*$,
the product~$\eps$ of the $\eps_i$ factors through $(\Z/\prod f_i\Z)^*$,
so the conductor of~$\eps$ divides $\prod f_i$.  Conversely, if 
$\ord_{p_i}(f) < \ord_{p_i}(f_i)$ for some~$i$, then we could factor $\eps$
as a product of local (prime power) characters differently, which contradicts
that this factorization is unique.

It remains to prove that if~$\eps$ is a nontrivial character modulo
$p^n$, where~$p$ is a prime, and~$r$ is the order of~$\eps$, then the
conductor of~$\eps$ is $p^{\ord_p(r)+1}$, except possibly if $8\mid
p^n$.  Since the order and conductor of $\eps$ and of the associated
primitive character $\eps'$ are the same, we may assume $\eps$ is
primitive, i.e., that $p^n$ is the conductor of~$\eps$; note that that
$n>0$, since~$\eps$ is nontrivial.  

% If $m=\ord_p(r)$, so $p^m$ is the order
% of~$\eps$, then by Corollary~\ref{cor:dir_ord}, 
% $$
% p^m =
%   \ord(\eps) \mid \#D(p^n,R) \mid \#(\Z/p^n\Z)^* = p^{n-1}(p-1), $$
% so
% $m+1\leq n$.  It remains to show that $n\leq m+1$, except possibly
% when $8\mid p^n$, when $n\leq m+2$.   

First suppose $p$ is odd.
Then the abelian group $D(p^n,R)$ splits as a direct sum $D(p,R)\oplus D(p^n,R)'$,
where $D(p^n,R)'$ is the $p$-power torsion subgroup of $D(p^n,R)$.
Also $\eps$ has order $u\cdot p^m$, where $u$, which
is coprime to~$p$, is the order of the image of $\eps$
in $D(p,R)$ and $p^m$ is the order of the image in $D(p^n,R)'$.
If $m=0$, then the order of $\eps$ is coprime to $p$, so 
$\eps$ is in $D(p,R)$, which means that $n=1$,
so $n=m+1$, as required.  If $m>0$, then $\zeta\in R$ 
must have order divisible by $p$, so~$R$ has characteristic not
equal to~$p$.  The conductor of $\eps$ does not change if we
adjoin roots of unity to~$R$, so in light of Lemma~\ref{lem:dual}
we may assume that $D(N,R) \ncisom (\Z/N\Z)^*$.
It follows that for each $n'\leq n$, the $p$-power subgroup
$D(p^{n'},R)'$ of $D(p^{n'},R)$ is the $p^{n'-1}$-torsion
subgroup of $D(p^n,R)'$.   Thus $m=n-1$, since
$D(p^n,R)'$ is by assumption the smallest such group that 
contains the projection of~$\eps$.  This proves the 
formula of Step~\ref{step:cond_fac}.   We leave the argument
when $p=2$ as an exercise (see \exref{ch:dirichlet}{ex:cond2}).
\end{proof}

\begin{example}\label{ex:char_cond}
If $\eps = [1,-1,\zeta^5] \in D(200,\C)$, then
as we saw in Example~\ref{ex:prodlocal},~$\eps$ 
is the product of $\eps_1=[1,-1]$ and $\eps_2 = [\zeta^5]$.
Because $\eps_1(5)=-1$, the conductor of $\eps_1$ is $8$.
The order of $\eps_2$ is $4$ (since $\zeta$ is a $20$th
root of unity), so the conductor of $\eps_2$ is $5$.
Thus the conductor of~$\eps$ is $40=8\cdot 5$.
\end{example}

The following two algorithms restrict and extend characters to a
compatible modulus.  Using them it is easy to define multiplication of
two characters $\eps\in D(N,R)$ and $\eps'\in D(N',R')$, as long as
$R$ and $R'$ are subrings of a common ring.  To carry out the
multiplication, just extend bother characters to characters modulo
$\lcm(N,N')$, then multiply.

\begin{algorithm}{Restriction of Character}\label{alg:restrict}
Given a Dirichlet character $\eps\in D(N,R)$ and a divisor
$N'$ of $N$ that is a multiple of the conductor of $\eps$,
this algorithm finds a characters $\eps' \in D(N',R)$, such
that $\eps'(a) = \eps(a)$, for all $a\in\Z$ with $(a,N)=1$.
\begin{steps}
\item{}[Conductor] Compute the conductor of~$\eps$ using
  Algorithm~\ref{alg:conductor}, and verify that indeed $N'$ is
  divisible by the conductor and divides $N$.
\item{}[Minimal Generators] Compute the minimal generators $g_i$ for
  $(\Z/N'\Z)^*$.
\item{}[Values of Restriction]\label{step:addmod} For each $i$,
  compute $\eps'(g_i)$ as follows.  Find a multiple $aN'$ of $N'$ such
  that $(g_i+aN',\,N)=1$; then $\eps'(g_i) = \eps(g_i+aN')$.
\item{}[Output Character] Output the Dirichlet character modulo~$N'$
  defined by $[\eps'(g_0),\ldots, \eps'(g_n)]$.
\end{steps}
\end{algorithm}
\begin{proof}
The only part that is not clear is that in Step~\ref{step:addmod}
there is an $a$ such that $(g_i+aN', N)=1$.  If
we write $N=N_1\cdot N_2$, with $(N_1,N_2)=1$, and $N_1$ divisible
by all primes that divide $N'$, then $(g_i,N_1)=1$ since
$(g_i,N')=1$.  By the Chinese Remainder Theorem, 
there is an $x\in\Z$ such that $x\con g_i\pmod{N_1}$ and
$x\con 1\pmod{N_2}$. Then $x = g_i + b N_1 = g_i + (bN_1/N')\cdot N'$
and $(x,N)=1$, which completes the proof.
\end{proof}


\begin{algorithm}{Extension of Character}\label{alg:extend}
Given a Dirichlet character $\eps\in D(N,R)$ and a multiple
$N'$ of $N$,
this algorithm finds a characters $\eps' \in D(N',R)$, such
that $\eps'(a) = \eps(a)$, for all $a\in\Z$ with $(a,N')=1$.
\begin{steps}
\item{}[Minimal Generators] Compute the minimal generators $g_i$ for
  $(\Z/N'\Z)^*$.
\item{}[Evaluate] Compute $\eps(g_i)$ for each~$i$.  Since $(g_i,N')=1$,
we also have $(g_i,N)=1$.
\item{}[Output Character] Output the character defined by 
$[\eps(g_0),\ldots, \eps(g_n)]$.
\end{steps}
\end{algorithm}


We finish with an algorithm that computes the Galois orbit
of an element in $D(N,R)$.  This can be used to divide
$D(N,R)$ up into Galois orbits, which is useful for modular
forms computations, because, e.g., the spaces $M_k(\Gamma_1(N))(\eps)$
and $M_k(\Gamma_1(N))(\eps')$ are canonically isomorphic if $\eps$
and $\eps'$ are conjugate.
\begin{algorithm}{Galois Orbit}
Given a Dirichlet character $\eps\in D(N,R)$, this algorithm
computes the orbit of~$\eps$ under the action of $G=\Gal(\overline{F}/F)$,
where~$F$ is the prime subfield of $\Frac(R)$, so $F=\Fp$ or $\Q$.
\begin{steps}
\item{}[Order of $\zeta$] Let $n$ be the order of the chosen root $\zeta\in R$.
\item{}[Nontrivial Automorphisms]\label{step:nontriv_aut}
If $\Char(R)=0$, let
$$
 A = \{a : 2\leq a <n \text{ and }(a,n) = 1\}.
$$
If $\Char(R)=p>0$, compute the multiplicative order~$r$ of~$p$ modulo~$n$,
and let
$$
  A = \{p^m : 1\leq m < r\}.
$$
\item{}[Compute Orbit] Compute and output the {\em set} of unique elements $\eps^a$ 
for each $a\in A$ (there could be repeats, so we output unique elements only).
\end{steps}
\end{algorithm}
\begin{proof}
We prove that the nontrivial automorphisms of $\langle \zeta\rangle$ in characteristic~$p$
are as in Step~\ref{step:nontriv_aut}. 
It is well-known that every automorphism in characteristic~$p$ on 
$\zeta\in\Fpbar$ is of the form $x\mapsto x^{p^s}$, for some~$s$.
The images of $\zeta$ under such automorphisms are
$$
  \zeta, \zeta^p, \zeta^{p^2}, \ldots.
$$
Suppose $r>0$ is minimal such that $\zeta=\zeta^{p^r}$.  Then the
orbit of $\zeta$ is $\zeta,\ldots, \zeta^{p^{r-1}}$.
Also $p^r\con 1\pmod{n}$, where $n$ is the multiplicative order of~$\zeta$,
so~$r$ is the multiplicative order of~$p$ modulo~$n$, which completes
the proof.
\end{proof}

\begin{example}
The Galois orbits of characters in $D(20,\C^*)$ are as follows:
\begin{align*}
  G_0 &= \{ [1,1,1]\},\\
  G_1 &= \{[-1,1,1]\}, \\
  G_2 &= \{[1,1,\zeta_4],\,\, [1,1,-\zeta_4]\}\\
  G_3 &= \{[-1,1,\zeta_4],\,\, [-1,1,-\zeta_4]\}\\  
  G_4 &= \{[1,1,-1]\}, \\
  G_5 &= \{[-1,1,-1]\}
\end{align*}
The conductors of the characters in orbit $G_0$ are $1$, in
order $G_1$ are $4$, in orbit $G_2$ they are $5$, in
$G_3$ they are $20$, in $G_4$ the conductor is $5$, 
and in $G_5$ the conductor is $20$. (You should verify this.)
\end{example}

\section{Alternative Representations of Characters}\label{sec:alter_rep}
Let~$N$ be a positive integer and~$R$ an integral domain, with fixed
root of unity~$\zeta$ order~$n$, and let $D(N,R)=D(N,R,\zeta)$.  As in
the rest of this chapter, write $N=\prod p_i^{e_i}$, and let
$C_i=\langle g_i\rangle $ be the corresponding cyclic factors of
$(\Z/N\Z)^*$.  In this section we discuss other ways to represent
elements $\eps \in D(N,R)$.  Each representation has advantages and
disadvantages, and no single representation is best. 
It emerged while writing this chapter that simultaneously using
more than one representation of elements of $D(N,R)$ would be best.
It is easy to convert between them, and some algorithms are much
easier using one representation, than when using another.  
In this section we present two other representations, each which
has advantages and disadvantages.   But, we emphasize that there
is frequently no reason to restrict to only one representation!


We could represent $\eps$ by giving a list $[b_0,\ldots, b_n]$, where
each $b_i\in\Z/n\Z$ and $\eps(g_i) = \zeta^{b_i}$.  Then arithmetic in
$D(N,R)$ is arithmetic in $(\Z/n\Z)^{n+1}$, which is very efficient.
A drawback to this approach is that it is easy to accidently consider
sequences that do not actually correspond to elements of $D(N,R)$,
though it is not really any easier to do this than with the
representation we use elsewhere in this chapter.  Also the choice of
$\zeta$ is less clear, which can cause confusion.  Finally, the orders
of the local factors is more opaque, e.g., compare $[-1,\zeta_{40}]$
with $[20,1]$.  Overall this representation is not too bad, and is
more like representing a linear transformation by a matrix.
It has the {\bf advantage} over the representation discussed earlier
in this chapter that arithmetic in $D(N,R)$ is very efficient,
and doesn't require any operations in the ring $R$; such operations
could be quite slow, e.g., if $R$ were a large cyclotomic field.

Another way to represent~$\eps$ would be to give a list $[b_0,\ldots,
b_n]$ of integers, but this time with $b_i\in \Z/\gcd(s_i,n)\Z$, where
$s_i$ is the order of $g_i$.  Then $$\eps(g_i) = \zeta^{b_i \cdot
  n/(\gcd(s_i,n))},$$
which is already complicated enough to ring
warning bells.  With this representation we set up an identification
$$
D(N,R)\isom \bigoplus_i \Z/\gcd(s_i,n)\Z, $$
and arithmetic is
efficient.  This approach is seductive because every sequence of
integers determines a character, and the sizes of the integers in the
sequence nicely indicate the local orders of the character.  However,
giving analogues of many of the algorithms discussed in this chapter
that operate on characters represented this way is tricky.  For
example, the representation depends very much on the order of $\zeta$,
so it is difficult to correctly compute natural maps $D(N,R) \to
D(N,S)$, for $R\subset S$ rings, whereas for the representation
elsewhere in this chapter such maps are trivial to compute.  This was
the representation the author (Stein) implemented in MAGMA.

The PARI documentation says the following (where we have preserved
the incorrect typesetting):
\begin{quote}
  ``A {\em character} on the Abelian group $\oplus(\Z/N_i\Z)g_i$ is
  given by a row vector $\chi=[a_1,\ldots,a_n]$ such that $\chi(\prod
  g_i^{n_i}) = exp(2i \pi \sum a_i n_i/N_i)$.''
\end{quote}
This means that the abelian group has independent
generators $g_i$ of order $N_i$.  This definition says
that, e.g., the value
of the character on $g_1$ is 
$$
\chi(g_1) = (e^{2\pi i/N_1})^{a_1}.
$$
Thus the integers $a_i$ are integers modulo $N_i$, and this
representation is basically the same as the one we described
in the previous paragraph (and which the author does not like).




\begin{exercises}
\item\label{ex:cyclic}
This exercise is about the structure of the units of $\Z/p^n\Z$.
\begin{enumerate}
\item If~$p$ is odd and~$n$ is a positive integer,
prove that $(\Z/p^n\Z)^*$  is cyclic.
\item If $n\geq 3$ prove that $(\Z/2^n\Z)^*$ is a direct
sum of the cylclic subgroups $\langle -1 \rangle$
and $\langle 5 \rangle$, of orders 2 and $2^{n-2}$, 
respectively.
\end{enumerate}

\item \label{ex:orderalg}
Prove that Algorithm~\ref{alg:mingens} works, i.e., that 
if $g\in(\Z/p^r\Z)^*$ and $g^{n/p_i}\neq 1$ for all $p_i\mid n=\vphi(n)$,
then $g$ is a generator of $(\Z/p^r\Z)^*$.

\item \label{ex:dlogadd}
Let $p$ be an odd prime and $n\geq 2$ an integer, and prove
that
$$
  (1+p^{n-1}(\Z/p^n\Z),\,\times) \isom (\Z/p\Z,\,+).
$$
Use this to show that solving the discrete log problem
in $(\Z/p^n\Z)^*$ is ``not much harder'' than
solving the discrete log problem in $(\Z/p\Z)^*$.

\item \label{ex:cond2}
Suppose $\eps$ is a nontrivial Dirichlet character modulo $2^n$
of order~$r$ over the complex numbers $\C$.
Prove that the conductor of $\eps$ is
$$
  c = \begin{cases} 
       2^{\ord_2(r) + 1} & \text{if $\eps(5)=1$}\\
       2^{\ord_2(r) + 2} & \text{if $\eps(5)\neq 1$.}
     \end{cases}
$$

\item
\begin{enumerate}
\item Find an irreducible quadratic polynomial~$f$ over $\F_5$.
\item Then $\F_{25} = \F_5[x]/(f)$.  Find an element with multiplicative
order $5$ in $\F_{25}$.
\item Make a list of all Dirichlet characters in $D(25,\F_{25},\zeta)$.
\item Divide these characters up into orbits for the action
of $\Gal(\Fbar_5/\F_5)$.
\end{enumerate}


\end{exercises}



\chapter{Modular Forms and Eisenstein Series of\\Higher Level}\label{ch:eisen}
In this chapter, we define the space $M_k(N,\eps)$ modular forms of
arbitrary level and character and discuss generalized Bernoulli
numbers attached to Dirichlet characters.  Then we give an algorithm
to enumerate the Eisenstein series in $M_k(N,\eps)$.  We will have to
wait until Chapter~\ref{ch:modsym} for an algorithm to compute all
cusp forms in $M_k(N,\eps)$.

\section{Modular Forms of Higher Level}
In this section, we define the space $M_k(N,\eps)$ of modular forms
for $\Gamma_1(N)$ with character~$\eps$.  We begin with the definition
of $M_k(\Gamma_1(N))$.
\begin{definition}[Modular Forms]
Let $M_k(\Gamma_1(N))$ be the
complex vector space of holomorphic functions $f:\h^*\to \C$ such that
$f|[\gamma]_k = f$ for all $\gamma \in \Gamma_1(N)$.
\end{definition}
What it means for $f$ to be holomorphic at the elements of
$\Q\union\{i\infty\}$ is somewhat subtle.  We say $f$ is \defn{holomorphic}
at $i\infty$ if its $q$-expansion $\sum a_n q^n$ has no nonzero
coefficient $a_n$ for $n<0$.  To make sense of holomorphicity of $f$
at $\alpha\in\Q$, let $\gamma\in\SL_2(\Z)$ be such that
$\gamma(\infty)=\alpha$.  Then we say $f$ is holomorphic at $\alpha$
if $f|[\gamma]_k$ is holomorphic at infinity.  Note that formally $$f|[\gamma]_k
(\infty) = (cz+d)^{-k}f(\alpha),$$ where $(c,d)$ is the bottom row of
$\gamma$ and the factor $(cz+d)^{-k}$ does not affect holomorphicity
at $\alpha$.  Another subtlety hidden in this definition is that
$f|[\gamma]_k$ is a modular form for the conjugate group
$G=\gamma^{-1}\Gamma_1(N) \gamma$, which need not equal $\Gamma_1(N)$.
In particular, the matrix $\abcd{1}{1}{0}{1}$ need not be in $G$, so
$f|[\gamma]_k$ need not even have a power series expansion
$\sum_{n\in\Z} b_n q^n$ at infinity!  Fortunately (see
\exref{ch:eisen}{ex:has_width}) there is some positive integer~$h$ such
that $\abcd{1}{h}{0}{1} \in G$, so $f|[\gamma]_k$ has a power series
expansion $\sum_{n\in\Z} b_{n/h} q^{n/h}$ in powers of $q^{1/h}$, and we again say
$f|[\gamma]_k$ is holomorphic at infinity if $b_{n/h} = 0$ for all
$n<0$.  (The reason we obtain a power series in $q^{1/h}$ is that
$f|[\gamma]_k(hz)$ is invariant under $z\mapsto z+1$, so 
$f|[\gamma]_k(hz)$ has an expansion in powers of $q$.)

A \defn{congruence subgroup} is a subgroup $\Gamma$ of $\SL_2(\Z)$
that contains the kernel $\Gamma(N) = \ker(\SL_2(\Z)\to
\SL_2(\Z/N\Z))$ for some $N$.  The smallest such~$N$ is the
\defn{level} of $\Gamma$.

\begin{definition}[Width of Cusp]
  The minimal $h$ such that $\abcd{1}{h}{0}{1} \in
  \gamma^{-1}\Gamma\gamma$ is called the \defn{width of the cusp}
  $\gamma(\infty)$ for the group $\Gamma$.
\end{definition}


\begin{algorithm}{Width of Cusp}
  Given a congruence subgroup $\Gamma$ of level $N$ and a cusp
  $\alpha$ for $\Gamma$, this algorithm computes the width $h$ of
  $\alpha$.  We assume that $\Gamma$ is given by congruence conditions,
e.g., $\Gamma=\Gamma_0(N)$ or $\Gamma_1(N)$.
\begin{steps}
\item{}[Find $\gamma$] Using the extended Euclidean algorithm,
find $\gamma\in\SL_2(\Z)$ such that $\gamma(\infty)=\alpha$.
If $\alpha=\infty$ set $\gamma\set 1$; otherwise, write 
$\alpha=a/b$, find $c,d$ such that $ad-bc=1$, and set
$\gamma \set \abcd{a}{b}{c}{d}$.
\item{}[Generic Conjugate Matrix] Compute the following matrix in $M_2(\Z[x])$:
$$
  \delta(x) \set \gamma \mtwo{1}{x}{0}{1} \gamma^{-1}.
$$
Note that $\delta(x)$ matrix whose entries are constant or
linear in $x$.
\item{}[Solve] The congruence conditions that define $\Gamma$ give
rise to four linear congruence conditions on $x$.  
Use techniques from elementary number theory to find the smallest
simultaneous positive solution $h$ to these four equations.
\end{steps}
\end{algorithm}
% \begin{proof}
%   Let $N$ be the level of $\Gamma$, so $\Gamma$ contains $\Gamma(N)$.
%   Then $\abcd{1}{N}{0}{1} \in \Gamma(N) \subset \Gamma$, so $h$ is a
%   divisor of $N$.
% \end{proof}

\begin{example}\mbox{}\\
\begin{enumerate}
\item
Suppose $\alpha=0$ and $\Gamma=\Gamma_0(N)$ or $\Gamma_1(N)$.
Then $\gamma=\abcd{0}{1}{1}{0}$ has the property that $\gamma(\infty)=\alpha$.
Next, the congruence condition is 
$$\delta(x) = \gamma \mtwo{1}{x}{0}{1} \gamma^{-1} = \mtwo{1}{0}{x}{1} 
  \con \mtwo{1}{*}{0}{1}\pmod{N}.
$$
Thus the smallest positive solution is $h=N$, so the width of $0$
is~$N$.

\item Suppose $N=pq$ where $p,q$ are distinct primes, and let $\alpha=1/p$.
Then $\gamma=\abcd{1}{0}{p}{1}$ sends $\infty$ to $\alpha$.
The congruence condition for $\Gamma_0(pq)$ is 
$$
\delta(x) = \gamma \mtwo{1}{x}{0}{1} \gamma^{-1} = \mtwo{1-px}{x}{-p^2 x}{px+1}
  \con \mtwo{*}{*}{0}{*}\pmod{pq}.
$$
Since $p^2x \con 0\pmod{pq}$, we see that $x=q$ is the smallest solution.
Thus $1/p$ has width $q$, and likewise $1/q$ has width~$p$.
\end{enumerate}
\end{example}
\begin{remark}
For $\Gamma_0(N)$, once we enforce that the bottom 
left entry is $0\pmod{N}$, and use that the determinant is 1, the 
coprimeness that one gets from the other two congruences is automatic.
So there is one congruence to solve for $\Gamma_0(N)$.
There are 2 congruences in the $\Gamma_1(N)$ case (the 
bottom left entry and top left entry).
\end{remark}


The group $(\Z/N\Z)^*$ acts on $M_k(\Gamma_1(N))$ through the
\defn{diamond-bracket operators}~$\langle d \rangle$.
For $d\in(\Z/N\Z)^*$, define
$$
   f|\dbd{d} = f|[\abcd{a}{b}{c}{d'}]_k,
$$
where $\abcd{a}{b}{c}{d'} \in \SL_2(\Z)$ is congruent to
$\abcd{d^{-1}}{0}{0}{d}\pmod{N}$.  Note that the map
$\SL_2(\Z)\to \SL_2(\Z/N\Z)$ is surjective (see \exref{ch:eisen}{ex:surjred}),
so it makes sense to consider the matrix $\abcd{a}{b}{c}{d'}$.
To prove that $\dbd{d}$ preserves $M_k(\Gamma_1(N))$,
we prove the more general fact that $\Gamma_1(N)$ is normal
in 
$$  \Gamma_0(N) = \left\{ \mtwo{a}{b}{c}{d} \in \SL_2(\Z) : 
                    \mtwo{a}{b}{c}{d}\con \mtwo{*}{*}{0}{*}\pmod{N}
                \right\}.
$$
This will imply that $\dbd{d}$ preserves $M_k(\Gamma_1(N))$
since $\abcd{a}{b}{c}{d'} \in \Gamma_0(N)$.

\begin{lemma}
The group $\Gamma_1(N)$ is a normal subgroup of $\Gamma_0(N)$,
and the quotient $\Gamma_0(N)/\Gamma_1(N)$ is
isomorphic to $(\Z/N\Z)^*$.
\end{lemma}
\begin{proof}
Consider the surjective homomorphism $r:\SL_2(\Z)\to \SL_2(\Z/N\Z)$.
Then $\Gamma_1(N)$ is the exact inverse image of the subgroup $H$ of
matrices of the form $\abcd{1}{*}{0}{1}$ and $\Gamma_0(N)$
is the inverse image of the subroup $T$ of upper triangular matrices.
It thus suffices to observe that $H$ is normal in $T$, which is clear.
Finally, the quotient $T/H$ is isomorphic to the group of diagonal
matrices in $\SL_2(\Z/N\Z)^*$, which is isomorphic to $(\Z/N\Z)^*$.
\end{proof}

The diamond bracket action is simply the action of
$\Gamma_0(N)/\Gamma_1(N)\isom(\Z/N\Z)^*$ on $M_k(\Gamma_1(N))$. 
Since $M_k(\Gamma_1(N))$ is a vector space over $\C$,
the $\dbd{d}$ action breaks $M_k(\Gamma_1(N))$ up as a direct
sum of factors corresponding to the Dirichlet characters $D(N,C)$ of 
modulus~$N$.  
\begin{proposition}
We have
$$
  M_k(\Gamma_1(N)) = \bigoplus_{\eps \in D(N,\C)} M_k(N,\eps),
$$
where
$$
  M_k(N,\eps) = \bigl\{ f \in \M_k(\Gamma_1(N)) : f|\dbd{d} = \eps(d) f
                    \text{ all }d \in (\Z/N\Z)^*\bigr\}.
$$
\end{proposition}
\begin{proof}
  The linear transformations $\dbd{d}$, for the $d\in(\Z/N\Z)^*$, all
  commute, since $\dbd{d}$ acts through the abelian group
  $\Gamma_0(N)/\Gamma_1(N)$.  Also, if $e$ is the exponent of
  $(\Z/N\Z)^*$, then $\dbd{d}^e = \dbd{d^e} = \dbd{1} = 1$, so the
  matrix of $\dbd{d}$ is diagonalizable.  It is a standard fact from
  linear algebra that any commuting family of diagonalizable linear
  transformations is simultaneously diagonalizable (see
  \exref{ch:eisen}{ex:diag}), so there is a basis $f_1,\ldots, f_n$
  for $M_k(\Gamma_1(N))$ so that all $\dbd{d}$ act by diagonal
  matrices.  The eigenvalues of the action of $(\Z/N\Z)^*$ on a fixed
  $f_i$ defines a Dirichlet character, i.e., each $f_i$ has
  the property that $f_i |\dbd{d} = \eps_i(d)$, for all
  $d\in(\Z/N\Z)^*$ and some Dirichlet character $\eps_i$.  The $f_i$
  for a given $\eps$ then span $M_k(N,\eps)$, and taken together the
  $M_k(N,\eps)$ must span $M_k(\Gamma_1(N))$.
\end{proof}

\begin{definition}[Character of Modular Form]
If $f\in M_k(N,\eps)$, we say that $f$ \defn{has character} $\eps$.
\end{definition}
\begin{remark}
People also often write that $f$ has ``nebentypus character'' $\eps$.
I rarely hear anyone actually {\em say} nebentypus, and it's somewhat
redundant, so I will simply omit it in this book.
\end{remark}

% There is an inner product $\langle \, , \, \rangle $ on $M_k(Gamma_1(N))$
% called the \defn{Petersson inner product}.  It is nondegenerate and
% if $T_n$ is a Hecke operator, then $
The spaces $M_k(N,\eps)$ are a direct sum of subspaces
$S_k(N,\eps)$ and $E_k(N,\eps)$, where $S_k(N,\eps)$ is the
subspace of cusp forms, i.e., forms that vanish at {\em all}
cusps (elements of $\Q \union \{\infty\}$), and $E_k(N,\eps)$
is the subspace of Eisenstein series, which is the unique
subspace of $M_k(N,\eps)$ that is invariant under all Hecke
operators and is such that 
$M_k(N,\eps) = S_k(N,\eps) \oplus E_k(N,\eps)$.
The space $E_k(N,\eps)$ can also be defined as the space
spanned by all Eisenstein series of weight $k$ and level~$N$,
as defined below.  It can also be defined using the Petersson
inner product.

\begin{remark}
The notation $M_k(N)$ will not be used anywhere in this book
(except in this sentence).
\end{remark}

\section{Generalized Bernoulli Numbers}
Suppose $\eps$ is a Dirichlet character modulo~$N$ over~$\C$.
\begin{definition}[Generalized Bernoulli Number]
Define the \defn{generalized Bernoulli numbers} $B_{k,\eps}$
attached to~$\eps$ by the following 
identity of infinite series:
$$
\sum_{a=1}^{N-1} \frac{\eps(a) \cdot x \cdot e^{ax}}{e^{Nx}-1}
                \,\, = \,\, 
\sum_{k=0}^{\infty} B_{k,\eps} \cdot \frac{x^k}{k!}.
$$
\end{definition}
If $\eps$ is the trivial character of modulus $1$ and $B_k$
are as in Section~\ref{sec:level_one_eisen}, then
$B_{k,\eps} = B_k$, except when $k=1$, in which case
$B_{1,\eps} = -B_1 = 1/2$ (see \exref{ch:eisen}{ex:bern_triv}).

Let $\Q(\eps)$ denote the field generated by the values
of the character $\eps$, so $\Q(\eps)$ is the cyclotomic
extension $\Q(\zeta_n)$, where $n$ is the order of $\eps$.
\begin{algorithm}{Bernoulli Numbers}\label{alg:gen_bernoulli}
Given an integer $k\geq 0$ and any
Dirichlet character  $\eps$ with modulus~$N$, this algorithm computes
the generalized Bernoulli numbers $B_{j,\eps}$, for $j\leq k$.
\begin{steps}
\item{}\label{step:ber1} Compute $g \set x/(e^{Nx}-1) \in \Q[[x]]$ to
  precision $O(x^{k+1})$ by computing $e^{Nx}-1 = \sum_{n\geq 1} N^n x^n/n!$ 
to precision $O(x^{k+2})$, and computing the inverse
$x/(e^{Nx}-1)$.  For completeness, note that if 
$f = a_0 + a_1 x + a_2x^2 + \cdots$, then we have
the following recursive formula for the coefficients $b_n$ of the
expansion of $1/f$:
$$
 b_n \set - \frac{b_0}{a_0} \cdot (b_{n-1}a_1 + b_{n-2}a_2 + \cdots + b_0 a_n).
$$
\item{}\label{step:ber2} For each $a=1,\ldots, N$, compute $f_a \set g
  \cdot e^{ax}\in\Q[[x]]$, to precision $O(x^{k+1})$.  This requires
computing $e^{ax}=\sum_{n\geq 0} a^n x^n/n!$ to precision $O(x^{k+1})$.
(One can omit computation of $e^{Nx}$ if $N>1$.)

\item{}\label{step:ber4} Then for $j\leq k$, we have 
$$B_{j,\eps} \set j!\cdot 
  \sum_{a=1}^{N} \eps(a) \cdot c_j(f_a),
$$ where $c_j(f_a)$ is the
  coefficient of $x^j$ in~$f_a$.
\end{steps}
\end{algorithm}
Note that in Steps~\ref{step:ber1} and \ref{step:ber2} we compute the
power series doing arithmetic only in $\Q[[x]]$, not in
$\Q(\eps)[[x]]$, which could be much less efficient if $\eps$ has
large order.   One could also write down a recurrence formula
for $B_{j,\eps}$, but this would simply encode arithmetic
in power series rings and the definitions in a formula.

\begin{example}
Let $\eps$ be the nontrivial character with modulus~$4$. Thus~$\eps$ 
has order~$2$ and takes values in~$\Q$.  Then the Bernoulli
numbers $B_{k,\eps}$ for $k$ even are all $0$ and for $k$ odd
they are
\begin{align*}
B_{1,\eps} &= -1/2\\
B_{3,\eps} &= 3/2\\
B_{5,\eps} &= -25/2\\
B_{7,\eps} &= 427/2\\
B_{9,\eps} &= -12465/2\\
B_{11,\eps} &= 555731/2\\
B_{13,\eps} &= -35135945/2\\
B_{15,\eps} &= 2990414715/2\\
B_{17,\eps} &= -329655706465/2\\
B_{19,\eps} &= 45692713833379/2.
\end{align*}
%G = DirichletGroup(4)
%e = G._0
%[e.bernoulli(k) for k in range(20) if k%2==1]
%print "\n".join(['B_{%s,\\eps} &= %s\\\\'%(k,e.bernoulli(k)) for k in range(20) if k%2==1])
These Bernoulli numbers can be divisible by large primes.  For example,
$B_{17,\eps} = 5\cdot 17^2 \cdot 228135437 / 2$.
\end{example}

\begin{example}
  This examples illustrates that the generalized Bernoulli numbers
  need not be rational numbers.  Suppose~$\eps$ is the mod~$5$ character
such that $\eps(2) = i = \sqrt{-1}$.  Then  $B_{k,\eps}=0$ for $k$ even
and
\begin{align*}
B_{1,\eps} &= \frac{-i - 3}{5}\\
B_{3,\eps} &= \frac{6i + 12}{5}\\
B_{5,\eps} &= \frac{-86i - 148}{5}\\
B_{7,\eps} &= \frac{2366i + 3892}{5}\\
B_{9,\eps} &= \frac{-108846i - 176868}{5}\\
B_{11,\eps} &= \frac{7599526i + 12309572}{5}\\
B_{13,\eps} &= \frac{-751182406i - 1215768788}{5}\\
B_{15,\eps} &= \frac{99909993486i + 161668772052}{5}\\
B_{17,\eps} &= \frac{-17209733596766i - 27846408467908}{5}\\
%B_{19,\eps} &= \frac{3727215827984246i + 6030787602527332}{5}.
\end{align*}

% G = DirichletGroup(5)
% e = G.gen(0)
% s = "\n".join(['B_{%s,\\eps} &= \\frac{%s}{5}\\\\'%(k,5*e.bernoulli(k)) for k in range(20) if k%2==1]); s=s.replace("*zeta_4","i")
% print s

\end{example}


\begin{proposition}
If $\eps(-1) \neq (-1)^k$, then $B_{k,\eps}=0$.
\end{proposition}


\section{Explicit Basis for the Eisenstein Subspace}
Suppose $\chi$ and $\psi$ are primitive Dirichlet characters with
conductors $L$ and $M$, respectively.  
Let
\begin{equation}\label{eqn:eisen}
 E_{k,\chi,\psi}(q) = c_0 + \sum_{m \geq 1} \left(
                  \sum_{n|m} \psi(n) \cdot \chi(m/n) \cdot n^{k-1}\right) q^{m}
\in \Q(\chi, \psi)[[q]],
\end{equation}
where 
$$
c_0 = \begin{cases} 0 & \text{ if } L>1, \\
\ds- \frac{B_{k,\psi}}{2k} & \text{ if } L=1.
\end{cases}
$$
Note that when $\chi=\psi=1$ and $k\geq 4$, then $E_{k,\chi,\psi} = E_k$,
where $E_k$ is from Chapter~\ref{ch:levelone}.

Miyake proves statements that imply the following theorems in
\cite[Ch.~7]{miyake}.  We will not prove them in this book since
developing the theory needed to prove them would take us far afield
from our goal, which is to compute $M_k(N,\eps)$.
\begin{theorem}\label{thm:eisser}
Suppose $t$ is a positive integer and $\chi$, $\psi$ are as above,
and that~$k$ is a positive integer such that $\chi(-1)\psi(-1) = (-1)^k$.
Except when $k=2$ and $\chi=\psi=1$, the power series 
$E_{k,\chi,\psi}(q^t)$ defines an element of 
$M_k(MLt,\chi/\psi)$.
If $\chi=\psi=1$, $k=2$, $t>1$,  and $E_2 = E_{k,\chi,\psi}$, then 
$E_2(q) - t E_2(q^t)$ is a modular form in $M_2(\Gamma_0(t))$.
\end{theorem}

\begin{theorem}\label{thm:eisgen}
The Eisenstein series in $M_k(N, \eps)$ coming from Theorem~\ref{thm:eisser}
form a basis for the Eisenstein subspace $E_k(N,\eps)$.
\end{theorem}

\begin{theorem}\label{thm:eiseigen}
The Eisenstein series 
$E_{k,\chi,\psi}(q) \in M_k(ML)$ defined above
is an eigenvector for all Hecke operators $T_n$.  
Also $E_2(q) - t E_2(q^t)$, for $t>1$, is an eigenform.
\end{theorem}
Since $E_{k,\chi,\psi}(q)$ is normalizes so the coefficient
of~$q$ is $1$, the eigenvalue of $T_m$  is 
$$\sum_{n|m} \psi(n) \cdot \chi(m/n) \cdot n^{k-1}.$$
Also for $f = E_2(q) - t E_2(q^t)$ with $t>1$ prime, the coefficient of~$q$ 
is~$1$, and $T_m(f) = \sigma_{1}(m)\cdot f$ for $(m,t)=1$, and $T_t(f) = 
((t+1)-t)f = f$.

\begin{algorithm}{Enumerating Eisenstein Series}\label{alg:enum_eisen}
  Given a weight~$k$ and a Dirichlet character~$\eps$ of modulus~$N$,
  this algorithm computes a basis for the Eisenstein
  subspace $E_k(N,\eps)$ of $M_k(N,\eps)$ to precision $O(q^r)$.
\begin{steps}
\item{}[Weight 2 Trivial Character?] If $k=2$ and $\eps=1$, output the
  Eisenstein series $E_2(q) - tE_2(q^t)$, for each divisor $t\mid N$ with $t\neq
  1$, then terminate.
\item{}[Compute Dirichlet Group] Let $G\set D(N,\Q(\zeta_n))$ be the group of Dirichlet
characters with values in $\Q(\zeta_n)$, where~$n$ is the exponent
fo $(\Z/N\Z)^*$.
\item{}[Compute Conductors]\label{step:enum_eisen3}  Compute the conductor of every element of $G$ (which just
involves computing the orders of the local components of each character).
%View~$\eps$ as an element of~$G$, and compute
%the conductor $\cond(\eps)$ of~$\eps$.
\item{}[List Characters $\chi$]\label{step:enum_eisen4} Form a list $V$ all Dirichlet characters $\chi \in G$ 
such that $\cond(\chi)\cdot \cond(\chi/\eps)$ divides~$N$.
\item{}[Compute Eisenstein Series] For each character $\chi$ in $V$, let $\psi = \chi/\eps$, and
compute $E_{k,\chi,\psi}(q^t)\pmod{q^r}$ for each divisor~$t$ of 
$N/(\cond(\chi)\cdot \cond(\psi))$.  We compute $E_{k,\chi,\psi}(q^t) \pmod{q^r}$
using (\ref{eqn:eisen}) and Algorithm~\ref{alg:gen_bernoulli}.

\end{steps}
\end{algorithm}

\begin{remark}
Algorithm~\ref{alg:enum_eisen} is what I currently use in my programs.
It might be better to first reduce to the prime power case by writing
all characters as product of local characters and combine
Steps~\ref{step:enum_eisen3} and \ref{step:enum_eisen4} into a single
step that involves orders.  However, this might make things more
complicated and obscure.
\end{remark}

\begin{example}
The following is a basis of Eisenstein series 
$E_{2,\chi,\psi}$ for $E_2(\Gamma_1(13))$.
\begin{verbatim}
f1 = 1/2 + q + 3*q^2 + 4*q^3 + O(q^4)

f2 = (-7/13*zeta_12^2 - 11/13) + q + (2*zeta_12^2 + 1)*q^2 
                               + (-3*zeta_12^2 + 1)*q^3 + O(q^4)

f3 = q + (zeta_12^2 + 2)*q^2 + (-1*zeta_12^2 + 3)*q^3 + O(q^4)

f4 = (-1*zeta_12^2) + q + (2*zeta_12^2 - 1)*q^2 
                        + (3*zeta_12^2 - 2)*q^3 + O(q^4)

f5 = q + (zeta_12^2 + 1)*q^2 + (zeta_12^2 + 2)*q^3 + O(q^4)

f6 = (-1) + q + (-1)*q^2 + 4*q^3 + O(q^4)

f7 = q + q^2 + 4*q^3 + O(q^4)

f8 = (zeta_12^2 - 1) + q + (-2*zeta_12^2 + 1)*q^2 
                         + (-3*zeta_12^2 + 1)*q^3 + O(q^4)

f9 = q + (-1*zeta_12^2 + 2)*q^2 + (-1*zeta_12^2 + 3)*q^3 + O(q^4)

f10 = (7/13*zeta_12^2 - 18/13) + q + (-2*zeta_12^2 + 3)*q^2 
                                   + (3*zeta_12^2 - 2)*q^3 + O(q^4)

f11 = q + (-1*zeta_12^2 + 3)*q^2 + (zeta_12^2 + 2)*q^3 + O(q^4)
\end{verbatim}
\end{example}

\begin{exercises}
\item\label{ex:has_width} Suppose $\gamma\in\SL_2(\Z)$ and $N$
is a positive integer.  Prove that there is a positive integer~$h$
such that $\abcd{1}{h}{0}{1} \in \gamma^{-1}\Gamma_1(N)\gamma$.

\item\label{ex:surjred} Prove that the map $\SL_2(\Z)\to
  \SL_2(\Z/N\Z)$ is surjective.  (Hint: There is a proof of a more
  general result near the beginning of Shimura's book \cite{shimura:intro}.)

\item\label{ex:gamma0} Prove that $M_k(N,1) = M_k(\Gamma_0(N))$.

\item\label{ex:diag} Suppose $A$ and $B$ are diagonalizable 
linear transformations of a finite-dimensional vector space~$V$
and that both $A$ and $B$ are diagonalizable.  Prove there is a basis
for $V$ so that the matrices of $A$ and $B$ with respect to that
both are simultaneously diagonal.

\item\label{ex:bern_triv} If $\eps$ is the trivial character of
  modulus $1$ and $B_k$ are as in Section~\ref{sec:level_one_eisen},
  then $B_{k,\eps} = B_k$, except when $k=1$, in which case
  $B_{1,\eps} = -B_1 = 1/2$.

\item\label{ex:odd_bernoulli} 
Prove that if $n>1$ is odd, then the Bernoulli number $B_n$ is $0$.

\end{exercises}


\chapter{Computing Dimensions of Spaces of Modular Forms}
\label{ch:dim}

When computing with spaces of modular forms, it is helpful to have
easy-to-compute formulas for dimensions of these spaces, and certain
of their subspaces.  For example, they provide a double-check on the
output of the algorithms from Chapter~\ref{ch:modsym} that compute
explicit bases for spaces of modular forms.  Alternatively, dimension
formulas can be used to improve the efficiency of some of the
algorithms in Chapter~\ref{ch:modsym}, since we can use them to determine
the ranks of certain matrices without having to explicitly compute
them.  If we know the dimension of $M_k(N,\eps)$, and we have a
process for computing $q$-expansions of elements of $M_k(N,\eps)$,
e.g., multiplying together $q$-expansions of certain forms of smaller
weight or searching for $\theta$-series attached to quadratic forms,
then we can tell when we are done generating $M_k(N,\eps)$.

This chapter contains formulas the author knows for computing
dimensions of spaces of modular forms, along with some hints about how
to compute them, when this isn't obvious.  In several cases we give
dimension formulas for spaces that haven't yet been defined in this
book, so we define them in this chapter (e.g., we will discuss
newforms and oldforms further).  We also give many examples, which
were computed using the modular symbols algorithms from
Chapter~\ref{ch:modsym}.

Many of the dimension formulas and algorithms we give below grew out
of a program that Bruce Caskel wrote (around 1996) in PARI, which
Kevin Buzzard extended.  Their program codified dimension formulas
that Buzzard and Caskel found or extracted from the literature (mainly
\cite[\S2.6]{shimura:intro}).  The algorithm for dimensions of spaces
with nontrivial character are from~\cite{cohen-oesterle:dimensions},
with some slight refinements from Kevin Buzzard.

For the rest of this chapter,~$N$ denotes a positive integer and $k\geq
2$ is an integer.  We give {\bf no formulas} for dimensions of spaces
of weight $1$ modular forms, because it is an {\em open problem} to give
such formulas; the geometric methods used to derive the formulas below
do not apply in the case $k=1$.  If $k=0$, the only modular forms are
the constants, and for $k<0$ the dimension of $M_k(N,\eps)$ is $0$.

For a nonzero integer $N$ and a prime~$p$, let $v_p(N)$ be the
largest~$e$ such that $p^e \mid N$.  In the formulas below,~$p$ always
denotes a prime number.  Let $M_k(N,\eps)$ be the space of modular
forms of level~$N$ weight~$k$ and character~$\eps$, and $S_k(N,\eps)$
and $E_k(N,\eps)$ the cuspidal and Eisenstein subspaces.  

The dimension formulas below for $S_k(\Gamma_0(N))$,
$S_k(\Gamma_1(N))$, $E_k(\Gamma_0(N))$ and $E_k(\Gamma_1(N))$ below
are almost straight from \cite[\S2.6]{shimura:intro} (see also
\cite[\S2.5]{miyake}), and they are derived using the Riemann-Roch
Theorem applied to the covering $X_0(N)\to X_0(1)$ or $X_1(N)\to
X_1(1)$ and appropriately chosen divisors.  It would be natural to
give a sample argument along these lines at this point, but I will not
since it easy to find such arguments in  other books and survey
papers (see, e.g., \cite{diamond-im}).  So you will not learn much about how to
derive dimension formulas from this chapter.  What you will learn is
what is known about dimension formulas and what some of the obscure
references are.

\section{Modular Forms for $\Gamma_0(N)$}\label{sec:dimg0}
Define functions of a positive integer~$N$ by the following formulas:
\begin{align*}
\mu_0(N) &= \prod_{p\mid N} \left( p^{v_p(N)} + p^{v_p(N)-1} \right) \\
\mu_{0,2}(N) &= \begin{cases}
    0 & \text{if $4\mid N$,}\\
  \prod_{p\mid N} \left(1 + \kr{-4}{p}\right) & \text{otherwise.}
\end{cases}\\
\mu_{0,3}(N) &= \begin{cases}
    0 & \text{if $2\mid N$ or $9\mid N$,}\\
  \prod_{p\mid N} \left(1 + \kr{-3}{p}\right) & \text{otherwise.}
\end{cases}\\
c_0(N) &= \sum_{d\mid N} \vphi(\gcd(d,N/d)) \\
g_0(N) &= 1 + \frac{\mu_0(N)}{12} - \frac{\mu_{0,2}(N)}{4} - \
               \frac{\mu_{0,3}(N)}{3} - \frac{c_0(N)}{2}\\
\end{align*}
Note that $\mu_0(N)$ is the index of $\Gamma_0(N)$ in $\SL_2(\Z)$.
Also $g_0(N)$ is the genus of the modular curve $X_0(N)$, and $c_0(N)$
is the number of cusps of $X_0(N)$.

\begin{proposition}
We have $\dim S_2(\Gamma_0(N)) = g_0(N)$, and
for $k\geq 4$ even, 
\begin{align*}
\dim S_k(\Gamma_0(N)) &= 
 (k-1) \cdot (g_0(N) - 1) \,\,+ \,\,
\left( \frac{k}{2} - 1 \right) \cdot c_0(N) \,\, +  \\
  &\qquad\qquad  \mu_{0,2}(N)\cdot \left\lfloor\frac{k}{4}\right\rfloor \,\,+ \,\,
     \mu_{0,3}(N)\cdot \left\lfloor \frac{k}{3}\right\rfloor.
\end{align*}
The dimension of the Eisenstein subspace is as follows:
$$
  \dim E_k(\Gamma_0(N)) = 
\begin{cases}
c_0(N) & \text{if $k\neq 2$,}\\
c_0(N)-1 & \text{if $k=2$.}
\end{cases}
$$
\end{proposition}

The following table contains the dimension of $S_k(\Gamma_0(N))$
for some sample values of $N$ and $k$:
\begin{center}
\begin{tabular}{|l|llll|}\hline
$N$ & $\dim S_2(\Gamma_0(N))$ & $\dim S_4(\Gamma_0(N))$ & 
      $\dim S_6(\Gamma_0(N))$ & $\dim S_{24}(\Gamma_0(N))$\\\hline
1 & 0 & 0 & 0 & 2\\
10 & 0 & 3 & 5 & 33\\
11 & 1 & 2 & 4 & 22\\
100 & 7 & 36 & 66 & 336\\
389 & 32 & 97 & 161 & 747\\
1000 & 131 & 430 & 730 & 3430\\
2004 & 331 & 1002 & 1674 & 7722\\
100000 & 14801 & 44800 & 74800 & 344800\\\hline
\end{tabular}
\end{center}

\subsection{New and Old Subspaces}
For each divisor $N'$ of $N$, there are natural maps 
$$
\alpha_d :
M_k(\Gamma_0(N')) \to M_k(\Gamma_0(N)), 
$$
corresponding to the
divisors $d$ of $N/N'$, and maps 
$$
\beta_d: M_k(\Gamma_0(N)) \to
M_k(\Gamma_0(N')).  
$$
such that $\beta_d\circ \alpha_d$ is
multiplication by a nonzero scalar.  On $q$-expansions,
$\alpha_d(f(q)) = f(q^d)$, and the definition of $\beta_d$ is a
more complicated ``trace map'' (see, e.g., \cite{lang:modular}). 

The space $M_k(\Gamma_0(N))$ decomposes as a direct sum 
$$
M_k(\Gamma_0(N))  = M_k(\Gamma_0(N))^{\old} \oplus M_k(\Gamma_0(N))^{\new},
$$
where 
$M_k(\Gamma_0(N))^{\old}$ is the subspace generated by all images
$\alpha_d(M_k(\Gamma_0(N'))$ where $N'$ runs through proper divisors
of $N$ and $d$ runs through all divisors of $N/N'$.  
The new subspace $M_k(\Gamma_0(N))^{\new}$ can be defined as either
the intersection of the kernels of all maps $\beta_d$
to lower level, or the largest Hecke-stable complement of
$M_k(\Gamma_0(N))^{\old}$. 

Atkin and Lehner \cite{atkin-lehner} proved that
the space $S_k(\Gamma_0(N))$ is built out of new subspaces,
in the following sense.
\begin{theorem}[Atkin-Lehner]\label{thm:atkin-lehner}
We have an isomorphism
$$S_k(\Gamma_0(N)) = 
   \sum_{M\mid N} \sum_{d\mid N/M} \alpha_d(S_k(\Gamma_0(M))^{\new}).
$$
This is an isomorphism of $\T'$ modules, where $\T'$ is the
anemic Hecke algebra, i.e., the subring generated by Hecke
operators $T_n$ with $\gcd(n,N)=1$.
\end{theorem}
This theorem reduces the problem of computing $S_k(\Gamma_0(N))$ to
that of computing $S_k(\Gamma_0(M))^{\new}$ for divisors~$M$ of~$N$,
a fact that will be central later in this book.
Atkin and Lehner also prove that one can completely determine
$S_k(\Gamma_0(M))^{\new}$ just from the information of how the Hecke
operators act on it (their ``multiplicity one'' theory).  
Atkin and Lehner's work was generalized to fairly arbitrary congruence
subgroups of $\SL_2(\Z)$ by Winnie Li in her Berkeley Ph.D. thesis
under A. Ogg (see \cite{winnie:newforms}).

If $N''\mid N'\mid N$, then the maps $\alpha_d$ from
$M_k(\Gamma_0(N''))$ to $M_k(\Gamma_0(N))$ factor through
$M_k(\Gamma_0(N'))$.  Thus in the definition of
$M_k(\Gamma_0(N))^{\old}$ and $M_k(\Gamma_0(N))^{\new}$, it would
suffice to consider only proper divisors $N'$ of $N$ such that $N/N'$
is prime.  

\vspace{1ex}
\noindent{\bf Warning:} For a fixed $N'=N/p$, the images of $\alpha_1$ and $\alpha_p$
need {\em not} always be linearly independent (see
Example~\ref{ex:new_old} below).  However, the images of the new
subspace $S_k(\Gamma_0(N'))^{\new}$ are linearly independent, 
as asserted by Theorem~\ref{thm:atkin-lehner}.
 
\begin{proposition}\label{prop:newg0}
The dimension of the new subspace is
$$
 \dim S_k(\Gamma_0(N))^{\new} = \sum_{M\mid N} \overline{\mu}(N/M) 
   \cdot \dim S_k(\Gamma_0(M)),
$$
where the sum is over the positive divisors of $N$, and for an integer $R$,
$$
\overline{\mu}(R) = 
\begin{cases} 
 0 & \text{if $p^3\mid R$ for some $p$}\\
\ds \prod_{p\mid\mid R} -2 & \text{otherwise},
\end{cases}
$$
where the product is over primes that exactly divide $n$.
(Note that $\overline{\mu}$ is {\em not} the Moebius function, but
is similar to it.)
\end{proposition}\label{prop:dimg0}
Let $f(n) = \dim S_k(\Gamma_0(n))$ and
$g(n)=\dim S_k(\Gamma_0(n))^{\new}$.
Theorem~\ref{thm:atkin-lehner} implies that 
\begin{equation}\label{eqn:mumu}
  f(N) = \sum_{M\mid N} \sigma_0(N/M) g(M),
\end{equation}
where $\sigma_0(N/M)$ is the number of divisors of $N/M$.
Presumably there is an analogue of Moebius inversion,
but for functions with the property in (\ref{eqn:mumu}),
which involves the function $\overline{\mu}$. 




\begin{example}\label{ex:new_old}
The space $M_2(\Gamma_0(45))$ has dimension $10$ and basis
\begin{verbatim}
1 + 12*q^15 + O(q^20),
q + q^7 + 3*q^16 + 6*q^19 + O(q^20),
q^2 + 4*q^11 + 3*q^14 + q^17 + O(q^20),
q^3 + q^12 + q^15 + 3*q^18 + O(q^20),
q^4 + q^7 + 2*q^13 + 4*q^16 + 2*q^19 + O(q^20),
q^5 + O(q^20),
q^6 + 2*q^12 + 2*q^15 - q^18 + O(q^20),
q^8 + q^14 + q^17 + O(q^20),
q^9 - 2*q^15 + 3*q^18 + O(q^20),
q^10 + O(q^20)
\end{verbatim}
The new subspace is spanned by the single cusp form
\begin{verbatim}
q + q^2 - q^4 - q^5 - 3*q^8 - q^10 + 4*q^11 - 2*q^13 + O(q^14)
\end{verbatim}
First consider $N'=45/3=15$.  The space $M_2(\Gamma_0(15))$ has
basis
\begin{verbatim}
1 + 12*q^5 + O(q^8),
q + q^4 + q^5 + 3*q^6 + 2*q^7 + O(q^8),
q^2 + 2*q^4 + 2*q^5 - q^6 + 2*q^7 + O(q^8),
q^3 - 2*q^5 + 3*q^6 + O(q^8)
\end{verbatim}
There are two maps $\alpha_1$ and $\alpha_3$ from 
$M_2(\Gamma_0(15))$ to $M_2(\Gamma_0(45))$. 
The one dimension space $M_2(\Gamma_0(5))$ embeds
in $M_2(\Gamma_0(15))$ via $f(q)\mapsto f(q)$
and $f(q)\mapsto f(q^3)$.  We have a commutative diagram
$$
\xymatrix{
                          & {M_2(\Gamma_0(15))}\ar[rd]^{\alpha_3} \\
{M_2(\Gamma_0(5))}\ar[ur]^{\alpha_1}\ar[dr]^{\alpha_3} &  & {M_2(\Gamma_0(45)).}\\
                          & {M_2(\Gamma_0(15))}\ar[ur]^{\alpha_1}
}$$
This diagram illustrates that the intersection of the two images of 
$M_2(\Gamma_0(15))$ has dimension at least $1$.  In fact, the
sum of the images of the two maps from $M_2(\Gamma_0(15))$ is a 
$7$-dimensional subspace of $M_2(\Gamma_0(45))$.

Next consider $N'=45/5=9$, where the space $M_2(\Gamma_0(9))=E_2(\Gamma_0(9))$ has
as basis the three forms
\begin{verbatim}
1 + 12*q^3 + 36*q^6 + O(q^8),
q + 7*q^4 + 8*q^7 + O(q^8),
q^2 + 2*q^5 + O(q^8)
\end{verbatim}
There are two maps $\alpha_1$ and $\alpha_5$ from 
$M_2(\Gamma_0(9))$ to $M_2(\Gamma_0(45))$. 
The images of these two maps span a space of dimension $6$,
and this space intersects the span of the images of $M_2(\Gamma_0(15))$
in a space of dimension $4$.  Thus the old subspace
$M_2(\Gamma_0(45))^{\old}$ has dimension $9$, and the
new subspace has dimension $1$.  The new subspace
is spanned by the single cusp form
\begin{verbatim}
q + q^2 - q^4 - q^5 - 3*q^8 - q^10 + 4*q^11 + O(q^12)
\end{verbatim}
\end{example}

\begin{remark}
  Csirik, Wetherell, and Zieve prove in
  \cite{csirik-wetherell-zieve:g0} that a random positive integer has
  probability~$0$ of being a value of $g_0(N)=\dim S_2(\Gamma_0(N))$,
  and give bounds on the size of the set of values of $g_0(N)$ below
  some given~$x$.  For example, they show that $150, 180, 210, 286,
  304, 312, \ldots$ are the first few integers that are not of the
  form $g_0(N)$ for some~$N$.
\end{remark}


\section{Modular Forms for $\Gamma_1(N)$}
This section follows Section~\ref{sec:dimg0} closely, but with
suitable modifications with $\Gamma_0(N)$ replaced by $\Gamma_1(N)$.
The notion of new and old subspaces for $\Gamma_1(N)$ is exactly the
same as for $\Gamma_0(N)$; simply replace $\Gamma_0(N)$ by
$\Gamma_1(N)$ in the discussion of new and old forms in
Section~\ref{sec:dimg0}.

Define functions of a positive integer~$N$ by the following formulas:
\begin{align*}
\mu_1(N) &= 
\begin{cases}
\mu_0(N) & \text{if $N=1,2$,}\\
\ds\frac{\phi(N)\cdot \mu_0(N)}{2} & \text{otherwise.}
\end{cases} \\
\mu_{1,2}(N) &= \begin{cases}
    0 & \text{if $N\geq 4$,}\\
  \mu_{0,2}(N) & \text{otherwise.}
\end{cases}\\
\mu_{1,3}(N) &= \begin{cases}
    0 & \text{if $N\geq 4$,}\\
    \mu_{0,3}(N) & \text{otherwise.}
\end{cases}\\
c_1(N) &= 
\begin{cases}
  c_0(N) & \text{if $N=1,2$,}\\
  3      & \text{if $N=4$,}\\
  \ds \sum_{d \mid N} \frac{\phi(d)\phi(N/d)}{2} & \text{otherwise}.
\end{cases} \\
g_1(N) &= 1 + \frac{\mu_1(N)}{12} - \frac{\mu_{1,2}(N)}{4} - \frac{\mu_{1,3}(N)}{3}
            - \frac{c_1(N)}{2}
\end{align*}
Note that $g_1(N)$ is the genus of the modular curve $X_1(N)$, 
and $c_1(N)$ is the number of cusps of $X_1(N)$.
\todo{Make sure this is right for $N\leq 5$.}

\begin{proposition}
  We have $\dim S_2(\Gamma_1(N)) = g_1(N)$.  If $N\leq 2$, then $$\dim
  S_k(\Gamma_1(N)) = \dim S_k(\Gamma_0(N)),$$
  where $\dim
  S_k(\Gamma_0(N))$ is given by the formula of
  Proposition~\ref{prop:dimg0}.  If $k\geq 3$, let $$
  a = (k-1)(g_1(N)
  - 1) + \left(\frac{k}{2} -1\right)\cdot c_1(N).  $$
  Then for $N\geq
  3$, $$
  \dim S_k(\Gamma_1(N)) =
\begin{cases}
 a + 1/2 & \text{if $N=4$ and $2\nmid k$,}\\
 a + \lfloor{} k/3\rfloor{} & \text{if $N=3$,}\\
 a & \text{otherwise.}
\end{cases}
$$
The dimension of the Eisenstein subspace is as follows:
$$
  \dim E_k(\Gamma_1(N)) = 
\begin{cases}
c_1(N) & \text{if $k\neq 2$,}\\
c_1(N)-1 & \text{if $k=2$.}
\end{cases}
$$
The dimension of the new subspace of $M_k(\Gamma_1(N))$ is
$$
\dim S_k(\Gamma_1(N))^{\new} = 
     \sum_{M \mid N} \overline{\mu}(N/M) \cdot \dim S_k(\Gamma_1(M)),
$$
where $\overline{\mu}$ is as in the statement
of Proposition~\ref{prop:newg0}.
\end{proposition}
\begin{remark}
Since $M_k = S_k \oplus E_k$, the formulas above also give
a formula for the dimension of $M_k$.  
\end{remark}

The following table contains the dimension of $S_k(\Gamma_1(N))$
for some sample values of $N$ and $k$:
\begin{center}
\begin{tabular}{|l|llll|}\hline
$N$ & $\dim S_2(\Gamma_1(N))$ & $\dim S_3(\Gamma_1(N))$ & 
      $\dim S_4(\Gamma_1(N))$ & $\dim S_{24}(\Gamma_1(N))$\\\hline
1 & 0 & 0 & 0 & 2\\
10 & 0 & 2 & 5 & 65\\
11 & 1 & 5 & 10 & 110\\
100 & 231 & 530 & 830 & 6830\\
389 & 6112 & 12416 & 18721 & 144821\\
1000 & 28921 & 58920 & 88920 & 688920\\
2004 & 109893 & 221444 & 332996 & 2564036\\
100000 & 299792001 & 599792000 & 899792000 & 6899792000\\\hline
\end{tabular}
\end{center}


\section{Modular Forms with Character}
Fix a Dirichlet character~$\eps$ modulo~$N$,
and let $c$ be the conductor of~$\eps$ (we do {\em not}
assume that $\eps$ is primitive).
 Assume that $\eps \neq 1$, since otherwise
$M_k(N,\eps) = M_k(\Gamma_0(N))$ and the formulas of
Section~\ref{sec:dimg0} apply.  Also, assume that $\eps(-1)=(-1)^k$,
since otherwise $\dim M_k(\Gamma_0(N)) = 0$.  In this section we
discuss formulas for certain subspaces of $M_k(N,\eps)$.

In \cite{cohen-oesterle:dimensions}, Cohen and 
Oesterle assert (without proof, see Remark~\ref{rem:co} below) 
that for any $k\in\Z$ and $N$, $\eps$
as above, that
\begin{align*}
\dim S_k(N,\eps) &- \dim M_{2-k}(N,\eps)\\
  &= \frac{k-1}{12} \cdot \mu_0(N) \,\,-\,\,
         \frac{1}{2} \cdot \prod_{p\mid N} \lambda(p, N, v_p(c))\\
  &\qquad + \gamma_4(k) \cdot\!\! 
\sum_{x \in A_4(N)} \eps(x) \,\,\,+\,\,\, 
   \gamma_3(k) \cdot \!\! \sum_{x \in A_3(N)} \eps(x)
\end{align*}
where $\mu_0(N)$ is as in Section~\ref{sec:dimg0},
$A_4(N) = \{x \in \Z/N\Z : x^2 +1 = 0\}$ and
$A_3(N) = \{x \in \Z/N\Z : x^2 + x + 1 = 0 \}$,
and $\gamma_3, \gamma_4$ are:
\begin{align*}
\gamma_4(k) &= 
    \begin{cases}
     -1/4 & \text{if $k\con 2\pmod{4}$}\\
      1/4 & \text{if $k\con 0\pmod{4}$}\\
        0 & \text{if $k$ is odd}
     \end{cases}\\
\gamma_3(k) &= 
    \begin{cases}
     -1/3 & \text{if $k\con 2\pmod{3}$}\\
      1/3 & \text{if $k\con 0\pmod{3}$}\\
        0 & \text{if $k\con 1\pmod{3}$}
     \end{cases}
\end{align*}
It remains to define $\lambda$.  
Fix a prime divisor $p\mid N$ and let $r=v_p(N)$.
Then 
$$
\lambda(p,N,v_p(c)) = 
    \begin{cases}
      p^{\frac{r}{2}} + p^{\frac{r}{2} - 1} & \text{if $2\cdot v_p(c)\leq r$ and $2\mid r$,}\\
     2\cdot p^{\frac{r-1}{2}} & \text{if $2\cdot v_p(c)\leq r$ and $2\nmid r$,}\\
     2\cdot p^{r-v_p(c)} & \text{if $2\cdot v_p(c) > r$}
   \end{cases}
$$   

The formula can be used to compute $\dim M_k(N,\eps)$, 
$\dim S_k(N,\eps)$, and $\dim E_k(N,\eps)$ for any $N$, $\eps$, $k\neq 1$,
by using that
\begin{align*}
  \dim S_k(N,\eps) &= 0 \qquad \text{if $k\leq 0$}\\
  \dim M_k(N,\eps) &= 0 \qquad \text{if $k<0$}\\
  \dim M_0(N,\eps) &= 1 \qquad \text{if $k=0$}
\end{align*}

One thing that is not straightforward when implementing an algorithm
to compute the above dimension formulas is how to efficiently compute
the sets $A_4(N)$ and $A_6(N)$.  Kevin Buzzard suggested the
following two algorithms to the author.  Note that if~$k$
is odd, then $\gamma_4(k)=0$, so the sum over
$A_4(N)$ is only needed when $k$ is even.  
\begin{algorithm}{Compute Sum over $A_4(N)$}\label{alg:suma4}
INPUT: A positive integer $N$ and an even 
Dirichlet character $\eps$ modulo~$N$.\\
OUTPUT: The sum $\sum_{x \in A_4(N)} \eps(x)$.
\begin{steps}
\item{}[Factor $N$]  Compute the prime factorization 
$p_1^{e_1} \cdots p_n^{e_n}$ of $N$.
\item{}[Initialize] Set $t\set 1$ and $i\set 0$.
\item{}[Loop over prime divisors]\label{alg:sum1go} Set $i\set i+1$.
If $i>n$, return $t$.  Otherwise 
set $p\set p_i$ and $e\set e_i$.
\begin{steps}
\item\label{alg:a4_3a} If $p\con 3\pmod{4}$, return $0$.
\item\label{alg:a4_3b} If $p=2$ and $e>1$, return $0$.
\item If $p=2$ and $e=1$, go to Step~\ref{alg:sum1go}.
\item\label{alg:a4_3d} Compute a generator $a\in (\Z/p\Z)^*$ using
Algorithm~\ref{alg:mingens}.
\item Compute $\omega = a^{(p-1)/4}$.
\item Using the Chinese Remainder Theorem to find $x\in\Z/N\Z$
such that $x\con a\pmod{p}$ and $x\con 1\pmod{N/p^e}$.
\item\label{alg:a4_3g} Set $x \set x^{p^{r-1}}$.
\item\label{alg:a4_3h} Set $s\set \eps(x)$.
\item\label{alg:a4_3i} If $s=1$, set $t\set 2t$ and go to Step~\ref{alg:sum1go}.
\item\label{alg:a4_3j} If $s=-1$, set $t\set -2t$ and go to Step~\ref{alg:sum1go}.
\end{steps}
\end{steps}
\end{algorithm}
\begin{proof}
  Note that $\eps(-x)=\eps(x)$, since $\eps$ is even.  By the chinese
  remainder theorem, the set $A_4(N)$ is empty if and only if there is
  no square root of $-1$ modulo some prime power divisor of $p$.  If
  $A_4(N)$ is empty, the algorithm correctly detects this fact in
  steps \ref{alg:a4_3a}--\ref{alg:a4_3b}.  Thus assume $A_4(N)$ is
  non-empty.  For each prime power $p_i^{e_i}$ that exactly divides
  $N$, let $x_i \in Z/N\Z$ be such that $x_i^2 = -1$ and $x_i\con
  1\pmod{p_j^{e_j}}$ for $i \neq j$.  This is the value of $x$
  computed in steps \ref{alg:a4_3d}--\ref{alg:a4_3g} (as one can see
  using elementary number theory).

  The next key observation is that 
\begin{equation}\label{eqn:a4prodsum}
  \prod_i (\eps(x_i) + \eps(-x_i)) = 
    \sum_{x \in A_4(N)} \eps(x),
 \end{equation}
 since by the chinese remainder theorem the elements of $A_4(N)$ are
 in bijection with the choices for a square root of $-1$ modulo each
 prime power divisors of~$N$.  The observation (\ref{eqn:a4prodsum})
 is a huge gain from an efficiency point of view---if $N$ had $r$
 prime factors, then $A_4(N)$ would have size $2^r$, which could be
 prohibitive, where the product involves only $r$ factors.  To finish
 the proof, just note that Steps~\ref{alg:a4_3h}--\ref{alg:a4_3j}
 compute the local factors $\eps(x_i) + \eps(-x_i) = 2\eps(x_i)$,
 where again we use that $\eps$ is even.  (Note, e.g., that a solution
 of $x^2+1 \con 0\pmod{p}$ lifts uniquely to a solution mod $p^n$ for
 any~$n$, because the kernel of the natural homomorphism $(\Z/p^n\Z)^*
 \to (\Z/p\Z)^*$ is a group of $p$-power order.
\end{proof}

The algorithm for computing the sum over $A_3(N)$ is similar, but we
omit it.

The following table contains the dimension of $S_k(N,\eps)$
for some sample values of $N$ and $k$.  In each case, $\eps$
is the product of characters $\eps_p$ of maximal order
corresponding to the prime power factors of~$N$ (i.e.,
the product of the generators of $D(N,\C^*)$).
\begin{center}
\begin{tabular}{|l|llll|}\hline
$N$ & $\dim S_2(N,\eps)$ & $\dim S_3(N,\eps)$ & 
      $\dim S_4(N,\eps)$ & $\dim S_{24}(N,\eps)$\\\hline
1 & 0 & 0 & 0 & 2\\
10 & 0 & 1 & 0 & 0\\
11 & 0 & 1 & 0 & 0\\
100 & 13 & 0 & 43 & 343\\
389 & 0 & 64 & 0 & 0\\
1000 & 148 & 0 & 448 & 3448\\
2004 & 0 & 668 & 0 & 0\\\hline
\end{tabular}
\end{center}



\begin{remark}\label{rem:co}
  Cohen and Oesterle also give dimension formulas for spaces of
  half-integral weight modular forms, which we do not give in this
  chapter.  Also \cite{cohen-oesterle:dimensions} does not contain any
  {\em proofs} that their claimed formulas are correct, but instead
  say only that ``Les formules qui les donnent sont connues de
  beaucoup de gens et il existe plusieurs m\'ethodes permettant de les
  obtenir (th\'eor\`eme de Riemann-Roch, application des formules de
  trace donn\'ees par Shimura).''  (The formulas that we give here are
  well known and there exist many methods to prove them, e.g., the
  Riemann-Roch theorem and applications of the trace formula of
  Shimura.)
\end{remark}

 \begin{exercises}
\item Fill in the elementary number theory details of the 
proof of Algorithm~\ref{alg:suma4}.

\item Track this down the analogue of Moebius inversion for
  $\overline{\mu}$ and give a quick presentation on it.  

\item Implement in your favorite computer language an algorithm
to compute $\dim S_k(\Gamma_0(N))$.


% \item Presumably exactly the same formula as for $\dim
%   S_k(\Gamma_1(N))^{\new}$ should be true for $\dim
%   E_k(\Gamma_1(N))^{\new}$, but with $S_k$ replaced by $E_k$
%   everywhere.  Either prove that this is true, or show that it is not.
%   Also, the same statement with $\Gamma_1(N)$ replaced by $\Gamma_0(N)$.

\end{exercises}

\chapter{Linear Algebra}\label{ch:linalg}
This chapter is about exact matrix algebra with over the rational
numbers and cyclotomic fields.  Algorithms for linear algebra over
exact fields are necessary in order to implement the modular
symbols algorithms that we will describe in Chapter~\ref{ch:linalg}.


This chapter partly overlaps  with \cite[\S2.1--2.4]{cohen:course_ant}.

\section{Echelon Form}\label{sec:echelon_form}
\begin{definition}[Reduced Row Echelon Form]
A matrix is in \defn{row echelon form}
if each row in the matrix starts with more zeros
than the row above it.   A matrix is in \defn{reduced
row echelon form} if it is in row echelon form,
the first nonzero entry of any row is $1$, and
the first nonzero entry of any row is the only
nonzero value in its column.
\end{definition}
Given a matrix~$A$, there is another matrix~$B$ such that~$B$ is
obtained from~$A$ by left multiplication by an invertible matrix
and~$B$ is in reduced row echelon form.  This matrix~$B$ is called the
reduced row echelon form of~$A$.  It is unique.

A \defn{pivot column} of~$A$ is one such that the reduced row echelon
form of~$A$ contains a leading~$1$.

\begin{example}
The following matrix is in row echelon form, but
not reduced row echelon form:
\begin{verbatim}
 [ 14,  2,  7,  228, -224;
    0,  0,  3,   78,  -70;
    0,  0,  0, -405,  381]
\end{verbatim}
The reduced row echelon form of the above matrix is 
\begin{verbatim}
  [1, 1/7, 0, 0, -1174/945;
   0,   0, 1, 0,   152/135;
   0,   0, 0, 1,  -127/135]
\end{verbatim}
Notice that the entries of the reduced row echelon form
can easily be messy.  Another example is the simple
looking matrix 
\begin{verbatim}
  [ -9,  6,  7, 3, 1, 0, 0, 0;
   -10,  3,  8, 2, 0, 1, 0, 0;
     3, -6,  2, 8, 0, 0, 1, 0;
    -8, -6, -8, 6, 0, 0, 0, 1]
\end{verbatim}
whose echelon form is 
\begin{verbatim}
  [1, 0, 0, 0,  42/1025,  -92/1025,  1/25,  -9/205;
   0, 1, 0, 0, 716/3075, -641/3075, -2/75,  -7/615;
   0, 0, 1, 0, -83/1025,  133/1025,  1/25, -23/410;
   0, 0, 0, 1, 184/1025, -159/1025,  2/25,   9/410]
\end{verbatim}
\end{example}

One learns in a basic linear algebra course that two matrices~$A$
and~$B$ have the same reduced row echelon form if and only if there is
an invertible matrix~$E$ such that $EA = B$.  Also, many standard
operations in linear algebra, e.g., computation of the kernel of a
linear map, intersection of subspaces, membership checking, etc., can
be encoded as a question about computing the echelon form of a matrix.

% \begin{remark}
%   I've decided to change the format of the algorithms to the one in
%   Algorithm~\ref{alg:gauss}.  (I will go back and change the earlier
%   algorithms at some point.)  I've made this change for the following
%   reasons:
% \begin{enumerate}
% \item When showing the algorithms in the previous format to other people,
% e.g., Tate, the precise input and output was unclear.  The new format
% makes the input and output clear.  
% \item The format with separate steps and goto statements is 
% difficult to translate into a modern language; Knuth uses
% it in his books, because he is trying to represent programs
% that he has implemented using the MIX {\em assembly language},
% which lacks high level control structure.  I don't know
% why H. Cohen uses this format in his book.  It is much 
% easier to translate the pseudocode below into an actual program
% in a modern language.
% \item Most modern algorithm books use pseudocode, not steps with gotos.
% \end{enumerate}
% We will use a list of steps when that is best, and give Python-ish
% pseudocode when it is clearer.
% \end{remark}

The following is a naive algorithm for computing the echelon form of a
matrix.
\begin{algorithm}{Gauss Elimination}\label{alg:gauss}%
INPUT: An $m\times n$ matrix $A$ over a field.\\
OUTPUT: The reduced row echelon form of~$A$.\\
We write {\tt A[i,j]} for the $i,j$ entry of $A$,
where $0\leq i \leq m-1$ and $0\leq j \leq n-1$.
\begin{verbatim}
def echelon(A):
    start_row = 0
    nr = A.nrows        # The number of rows of A
    nc = A.ncols        # The number of columns of A
    for c in range(nc): # for c = 0, 1, 2, ..., nc-1
        for r in range(nr):
            a = A[r,c]
            # if a is nonzero
            if a != 0:  
                # Rescale row r of A by 1/a.
                A.scale_row(r, 1/a)
                # Swap row r with the start_row row.
                A.swap_rows(r, start_row)
                # Clear the c-th column
                for i in range(nr):
                    if i != start_row:
                        if A[i,c] != 0:
                            # Add -A[i,c] times start_row to the i-th row
                            # in order to clear the leading entry of 
                            # the i-th row.
                            A.add_multiple_of_row(start_row, -A[i,c], i)
                # Increment the start_row
                start_row = start_row + 1
                # The following break means that we skip the rest
                # of the for loop over r in range(nr), and
                # increase c and start a new for loop over r.
                break
\end{verbatim}
\end{algorithm}
This algorithm takes $O(mn^2)$ arithmetic operation in the base field,
where~$A$ is an $m\times n$ matrix.  If the base field is $\Q$, the
entries can become huge and arithmetic operations can be increasingly
expensive.  See Section~\ref{sec:modularmethod} for ways to mitigate
this problem.

To conclude this section we mention how to convert a few standard
problems into questions about reduced row echelon forms of matrices.
Note that one can also phrase some of these answers in terms of the
echelon form, which might be easier to compute, or an LUP
decomposition (lower triangular times upper triangular times
permutation matrix), which the numerical analysts use.
\begin{enumerate}
\item{} {\bf Kernel of $A$:} Since passing to the reduced row echelon form of
  $A$ is the same as multiplying on the left by an invertible matrix,
  the kernel of the reduce row echelon form is the same as the kernel
  of $A$.  Thus we may assume $A$ is in reduced row echelon form.  There is a
  basis vector of $\ker(A)$ that corresponds to each non-pivot column
  of $A$.  That vector has a $1$ at the non-pivot column, $0$'s at all
  other non-pivot columns, and for each pivot column, the negative of
  the entry of $A$ at the non-pivot column in the row with that pivot
  element.
\item{} {\bf Intersection of Subspaces:} Suppose $W_1$ and $W_2$ are
  subspace of a finite-dimensional vector space $V$.  Let $A_1$ and
  $A_2$ be matrices whose columns form a basis for $W_1$ and $W_2$,
  respectively.  Let $A=[A_1 | A_2]$ be the augmented matrix formed
  from $A_1$ and $A_2$.  Let $K$ be the kernel of the linear
  transformation defined by $A$.  Then K is isomorphic to the desired
  intersection.  To write down the intersection explicitly, suppose
  that $\dim(V) \leq \dim(W)$ and do the following: For each $b$ in a
  basis for $K$, write down the linear combination of a basis for $V$
  got by taking the first $\dim(V)$ entries of the vector $b$.  The
  fact that $b$ is in $\Ker(A)$ implies that the vector we just
  wrote down is also in $W$.  We took $V$ to have smaller dimension
  just so that the linear combinations in the intersection could be
  written down slightly more quickly.
\end{enumerate}


\section{Echelon Forms over $\Q$}\label{sec:modularmethod}
A major difficulty with computation of the echelon form of a dense
matrix over the rational numbers is that arithmetic with large
rational numbers is very time consuming, since each addition
potentially requires a $\gcd$ and numerous additions and
multiplications of integers.  Moreover, the entries of $A$ during
intermediate steps of Algorithm~\ref{alg:gauss} can be huge even
though the entries of $A$ and the answer are small.  For example,
suppose $A$ is an invertible square matrix.  Then the echelon form of
$A$ is the identity matrix, but during intermediate steps the entries
of $A$ could be quite large.  One technique for mitigating this
problem is to compute the echelon form using a multi-modular method.
The following is a sketch of such a multi-modular method (we will give
a more precise version; see Algorithm~\ref{alg:modech}):
\begin{enumerate}
\item By clearing denominators, we may assume that the entries of $A$
  are integers.
\item Compute the echelon forms $B_p$ of the reduction $A\pmod{p}$
  of~$A$ modulo several primes~$P = \{p, \ldots\}$, using some variant of
  Algorithm~\ref{alg:gauss}.
(Note that arithmetic modulo $p$ for a ``machine size'' prime $p$
is {\em very} fast.)
\item Use the Chinese Remainder Theorem to find a matrix $B$
with integer entries such that $B \con B_p \pmod{p}$ for all
$p\in P$.
\item Use rational reconstruction (see below) to find a matrix
$C$ whose coefficients are rational numbers $n/r$ such that
$|n|, r \leq \sqrt{m/2}$, where $m$ is the product of the
primes in $P$, and $C \con B_p \pmod{p}$ for each prime~$p$.
\item Use height bounds to verify that $C$ is the reduced
row echelon form of $A$.
\end{enumerate}

Rational reconstruction is a process that allows one to sometimes lift
an integer modulo~$m$ uniquely to a bounded rational number.

\begin{algorithm}{Rational Reconstruction}\label{alg:ratrecon}%
INPUT: An integer $a\geq 0$ and an integer $m\geq 1$.\\
OUTPUT: The numerator and denominator $n$, $d$ of the unique rational           
number $n/d$, if it exists, with  
$$
  |n|, d \leq \sqrt{\frac{m}{2}}
\qquad\text{and}\qquad n \con a d \pmod{m},
$$
or returns $n=d=0$, if no such rational number exists.
\begin{verbatim}
def rational_reconstruction(a, m):
    # Reduce a modulo m
    a = a % m           
    # Trivial special cases
    if a == 0: return (0,1)
    if a == 1: return (1,1)
    # Let bnd be the integer part of the square root of m/2.
    bnd = sqrt(m/2.0)    
    # Initialize Euclidean algorithm.
    u = m
    v = a
    # Perform the extended Euclidean algorithm, but terminate
    # when V[2] is <= bnd.
    U = (1,0,u)
    V = (0,1,v)
    while abs(V[2]) > bnd:
        q = U[2]//V[2]      # // means divide and take the integer part
        tmp = (U[0]-q*V[0], U[1]-q*V[1], U[2]-q*V[2])
        U = V
        V = tmp
    d = abs(V[1])
    n = V[2]
    if V[1] < 0:  n = n * (-1)
    if d <= bnd and gcd(n,d) == 1:
        return (n,d)
    return (0,0)
\end{verbatim}
\end{algorithm}

\begin{remark}[Technical Python Remarks]
In Python, use the {\tt sqrt} function from the {\tt gmpy} GMP
  library, not the one from {\tt math}.  
With Python integers, {\tt a/b} also means divide and
take the floor, i.e., what we denote by {\tt a//b} above.
Finally, {\tt gcd} is not included with Python.  Use, e.g.,
the {\tt gmpy.gcd} function.
\end{remark}

Algorithm~\ref{alg:ratrecon} for rational reconstruction is described
(with a complete nontrivial proof) in \cite[pg.656--657]{knuth2} as
the solution to exercise~51 on page 379.  See in particular the
paragraph right in the middle of page 657, which describes the
algorithm.  Knuth says this rational reconstruction algorithm is due
to Wang, Kornerup, and Gregory from around 1983.

We now give an indication of why Algorithm~\ref{alg:ratrecon} computes
the rational reconstruction of $a \pmod{m}$, leaving the precise
details and uniqueness to \cite[pg.656--657]{knuth2}.  At each
step in Algorithm~\ref{alg:ratrecon}, the $3$-tuple $V=(v_0, v_1,
v_2)$ satisfies
\begin{equation}\label{eqn:xgcdeqn}
   m \cdot v_0 + a\cdot v_1 = v_2,
 \end{equation}
and similarly for $U$.
When computing the usual extended $\gcd$, at the end $v_2=\gcd(a,m)$
and~$v_0$,~$v_1$ give a representation of the~$v_2$ as a $\Z$-linear
combination of~$m$ and~$a$.
In Algorithm~\ref{alg:ratrecon}, we are instead interested
in finding a rational number $n/d$ such that 
$n \con a\cdot d\pmod{m}$.  If we set $n=v_2$ and $d=v_1$
in (\ref{eqn:xgcdeqn}) and rearrange, we obtain
$$
  n  = a \cdot d + m \cdot v_0.
$$
Thus at {\em every} step of the algorithm we find a rational number
$n/d$ such that $n\con ad\pmod{m}$.  The problem at intermediate
steps is that, e.g., $v_0$ could be $0$, or $n$ or $d$
could be too large.  

% \begin{examples}
% We ``manufacture'' an integer that we know is the reduction of a rational
% number modulo $m=10000$, then recover that rational number
% using Algorithm~\ref{alg:ratrecon}.

% \end{examples}

If $A$ is a matrix with rational entries, let $H(A)$ 
be the \defn{height} of $A$, which is the maximum of the
absolute values of the numerators and denominators
of all entries of $A$.

\begin{algorithm}{Modular Algorithm for Computing Echelon Form}\label{alg:modech}%
INPUT: An $m\times n$ matrix $A$ with entries in $\Q$.\\
OUTPUT: The reduced row echelon form of~$A$.
\begin{steps}
\item Rescale the input matrix $A$ to have integer entries.  This does
  not change the echelon form and makes reduction modulo many primes
  easier.  Henceforth we assume $A$ has integer entries.

\item Let $c$ be a guess for the height of the echelon form. 

\item List successive primes $p_1, p_2, \ldots$
 such that the product of the $p_i$ is bigger than 
$n \cdot c \cdot H(A) + 1$, where $n$ is the number of columns of~$A$.

\item Compute the echelon forms $B_i$ of the reduction $A\pmod{p_i}$
using, e.g., Algorithm~\ref{alg:gauss} or something similar.

\item\label{step:discard} Discard any $B_i$ whose pivot column list is not maximal
  among pivot lists of all $B_j$ found so far.
(The pivot list associated to $B_i$
is the ordered list of integers $k$ such that the $k$th
column of $B_j$ is a pivot column.
We mean maximal with respect to the following ordering on
integer sequences: shorter integer sequences are smaller, and if two sequences
have the same length, then order in reverse lexicographic order.
Thus $[1,2]$ is smaller than $[1,2,3]$, and $[1,2,7]$ is smaller
than $[1,2,5]$.  Think of maximal as ``optimal'', i.e., best
possible pivot columns.)

\item Use the Chinese Remainder Theorem to find a matrix $B$
with integer entries such that $B \con B_i \pmod{p_i}$ for all
$p_i$.

\item Use rational reconstruction (Algorithm~\ref{alg:ratrecon})
to try to find a matrix~$C$ whose coefficients are rational 
numbers $n/r$ such that
$|n|, r \leq \sqrt{M/2}$, where $M=\prod p_i$, 
and $C \con B_i \pmod{p_i}$ for each prime~$p$.
If rational reconstruction fails,
compute a few more echelon forms mod the next few primes (using
the above steps),  and attempt rational reconstruction again.
Let $E$ be the matrix over~$\Q$ so obtained.

\item Compute the denominator $d$ of $E$, i.e., the smallest positive
  integer such that $dE$ has integer entries.  If 
\begin{equation}\label{eqn:modalgbound}
  H(dE) \cdot H(A)
  \cdot n \leq \prod p_i, 
\end{equation}
then $E$ is the reduced row echelon form of $A$.  If not,
repeat the above steps with a few more primes.  
\end{steps}
\end{algorithm}
\begin{proof}
  We prove that if the bound (\ref{eqn:modalgbound}) is satisfied,
  then the matrix~$E$ computed by the algorithm really is the reduced
  row echelon form~$R$ of~$A$.  The set of pivot columns of all
  matrices $B_i$ used to construct $E$ are the same, so the pivot
  columns of $E$ are the same as those of any $B_i$.  Thus $E$ is in
  reduced row echelon form.

  Recall from the end of Section~\ref{sec:echelon_form} that a matrix
  whose columns are a basis for the kernel of $A$ can be obtained from
  the reduced row echelon form of $R$.  Let $K$ be the matrix whose
  columns are the vectors in the kernel algorithm applied to $E$, 
so $EK=0$.  Since the reduced row echelon form is got by left
multiplying by an invertible matrix, for each $i$, there is 
an invertible matrices $C_i$ mod $p_i$ such that $A = C_i B_i$
so
$$
  A\cdot d K \con d C_i B_i K \con C_i \cdot dE \cdot K \con 0\pmod{p_i}.
$$
Since $d K$ and $A$ are integer matrices,
$$
 A \cdot dK \con 0\pmod{\prod{p_i}}.
$$
The integer entries of $A\cdot dK$ are all at most $H(A)\cdot{} H(dK)\cdot{} n$,
where $n$ is the number of columns of $A$.  Since $H(K) \leq H(E)$,
the bound (\ref{eqn:modalgbound}) implies that $A \cdot dK = 0$.  Thus
$A K = 0$, so $\Ker(E) \subset \Ker(A)$.  On the other hand,
the rank of~$E$ equals the rank of each $B_i$ (since the pivot columns
are the same), so $$\rank(E) = \rank(B_i) = \rank(A\!\!\!\pmod{p_i}) \leq
\rank(A).$$  Thus $\dim(\Ker(A)) \leq \dim(\Ker(E))$, and combining
this with the bound obtained above we see that 
$\Ker(E) = \Ker(A)$.   This implies that $E$ is the reduced row
echelon form of~$A$, since two matrices have the same kernel if
and only if they have the same reduced row echelon form 
(the echelon form is an invariant of the row space, and the
kernel is the orthogonal complement of the row space).

The reason for Step~\ref{step:discard} is that the matrices $B_i$ need
{\em not} be the reduction of $R$ modulo~$p_i$, and indeed this
reduction might not even be defined, e.g., if~$p_i$ divides the
denominator of some element of $R$, then this reduction makes no
sense.  For example, set $p=p_i$ and suppose $A=\abcd{p}{1}{0}{0}$.
Then $R=\abcd{1}{1/p}{0}{0}$, which has no reduction modulo~$p$; also,
the reduction of $A$ modulo~$B_i$ is $B_i = \abcd{0}{1}{0}{0}
\pmod{p}$, which is already in reduced row echelon form.  However if
we were to combine $B_i$ with the echelon form of $A$ modulo another
prime, the result could never be lifted using rational reconstruction.
Thus the reason we exclude all $B_i$ with non-maximal pivot column
sequence is so that a rational reconstruction will exist.  There are
only finitely many primes that divide denominators of entries of $R$,
so eventually all $B_i$ will have maximal pivot column sequences,
i.e., are the reduction of the true reduced row echelon form $R$, so
the algorithm terminates.
\end{proof}

\begin{remark}\mbox{}
\begin{enumerate}
\item
  I learned about rational reconstruction in the context of computing
  echelon forms from Allan Steel, who is one of the developers of
  \magma{}.  I learned from Allan that \magma{} does not use the above
  algorithm; instead it uses a Strassen ``divide and conquer'' echelon
  procedure that involves random permuting of rows, etc., and takes
  advantage of asymptotically fast matrix multiplication algorithms.
  The matrix multiplies are done using a modular CRT technique.  This
  is probably better in many cases, especially for dense matrices.

\item
  I have tested an implementation of Algorithm~\ref{alg:modech}
  against MAGMA V2.11-8.  For large square matrices over~$\Q$, e.g., over a hundred rows,
  (a case of importance when cutting out eigenspaces for Hecke
  operators), Algorithm~\ref{alg:modech} is much more efficient (both
  in time and memory usage) than MAGMA.  In contrast, for matrices
  with more columns than rows (an important case, e.g., when
  intersecting subspaces), MAGMA is often an order of magnitude faster.
  Thus an optimal package should probably implement both
  Algorithm~\ref{alg:modech} for square matrices and a divide and
  conquer echelon strategy for non-square matrices.

\item
  I have never seen Algorithm~\ref{alg:modech} anywhere else, and
  found the details and proof myself.  I have seen the idea of using a
  multi-modular method for linear algebra problems hinted out or
  explicitly suggested {\em many times}; I've just never seen a
  discussion of computing reduced row echelon forms this way.

\item
  There is also an iterative $p$-adic method for lifting solutions
  modulo~$p$ to an equation $Ax=v$ to characteristic $0$.  This is
  supposed to be faster for a single solution, but slower for lifting
  many solutions. See
\begin{verbatim}
http://magma.maths.usyd.edu.au/users/allan/gb/faugere_f4.ps.gz
\end{verbatim}
  for a discussion.

\item Algorithm~\ref{alg:modech}, with all matrices {\bf sparse},
  seems to work very well in practice.  A simple but helpful
  modification to Algorithm~\ref{alg:gauss} in the sparse case is to
  clear each column using a row with a minimal number of nonzero
  entries, so as to reduce the amount of ``fill in'' (denseness) of
  the matrix.  There are more sophisticated methods along these lines
  called ``intelligent Gauss elimination''.  (Cryptographers are
  interested in linear algebra with huge sparse linear, since they
  come up in factor basis attacks on the discrete log problem or
  integer factorization.)
\end{enumerate}
\end{remark}

One can likely adapt Algorithm~\ref{alg:modech} to computation of
reduced row echelon forms of matrices~$A$ over cyclotomic fields
$\Q(\zeta_n)$.  Assume~$A$ has denominator~$1$. Let~$p$ be a prime
that splits completely in $\Q(\zeta_n)$.  Compute the homomorphisms
$f_i : \Z_p[\zeta_n] \to \F_p$ by finding the elements of order~$n$ in
$\F_p^*$.  Then compute the mod~$p$ matrix $f_i(A)$ for each~$i$, and
find its reduced row echelon form.  Taken together, the maps $f_i$
together induce an isomorphism $\Psi:\F_p[X]/\Phi_n(X) \isom \F_p^d$,
where $\Phi_n(X)$ is the $n$th cyclotomic polynomial and $d$ is its
degree.  It's easy to compute $\Psi(f(x))$ by evaluating $f(x)$ at
each element of order~$n$ in $\F_p$.  To compute $\Psi^{-1}$ simply
use linear algebra over $\F_p$ to invert a matrix that represents
$\Psi$.  Use $\Psi^{-1}$ to compute the the reduced row echelon form
of $A\pmod{p}$, where~$(p)$ is the non-prime ideal in $\Z[\zeta_n]$
generated by~$p$.  Do this for several primes $p$, and use rational
reconstruction on each coefficient of each power of $\zeta_n$, to
recover the echelon form of~$A$.  
Problems: What is the analogue of (\ref{eqn:modalgbound})?


\section{Polynomials}

There are several linear algebra algorithms that involve polynomials
and are important to modular forms algorithms. 

Computation of characteristic polynomials of matrices is crucial to
modular forms computations.  There are many approaches to this
problems: compute $\det(xI-A)$ symbolically (bad), compute the traces
of the powers of $A$ (bad), or compute the Hessenberg form modulo many
primes and use CRT (not so bad, see \cite[\S2.2.4]{cohen:course_ant}).
Another more sophisticated method is to compute the rational canonical
form of $A$ using Giesbrecht's algorithms, which involve computing
Krylov subspaces (i.e., cyclic spaces spanned by a single vector), and
building up the whole space on which $A$ acts.  This latter method may
be viewed as a generalization of Weiedemann's algorithm for computing
characteristic polynomials, but with more structure.  The algorithm
used in \magma{} is similar to Giesbrecht's (probably independently
discovered).  PARI uses only Lagrange interpolation (?) and Hessenberg
form.


Factorization of polynomials in $\Z[X]$ is an important step in
computing an explicit basis of newforms for a space of modular forms.
The best algorithm is the van Hoeij method, which uses LLL in a
novel way to solve the sort of optimization problems that come up in
trying to lift factorizations mod~$p$ to~$\Z$.  It has aparently been
generalized to number fields and is included in new versions of PARI,
\magma{}, and NTL.  For more details, see van Hoeij's web page:
\url{http://www.math.fsu.edu/~hoeij/papers.html}.


\chapter{Modular Symbols}\label{ch:modsym}
Modular symbols are a formalism that make it
fairly easy and elementary to compute with homology or cohomology
related to certain Kuga-Sato varieties (these are $\cE\times_X \cdots
\times_X \cE$, where $X$ is a modular curve and $\cE$ is the univeral
elliptic curve over it).  It is not necessary to know anything about
these Kuga-Sato varieties in order to compute with modular symbols.

This chapter is about spaces of modular symbols and how to compute
with them.  It is by far the most important chapter in this book.  The
algorithms that build on the theory in this chapter are central to all
the computations we will do later in the book.  We will start with
the basics, in that the intended reader of
this chapter is not assumed to have ever seen a modular symbol before.

Much of this chapter follows Loic Merel's paper
\cite{merel:1585} very closely.  First we define modular symbols of
weight $k\geq 2$.  Then we define the corresponding Manin symbols, and
state a theorem of Merel-Shokurov, which gives all relations between
Manin symbols.  (The proof of the Merel-Shokurov theorem is beyond the
scope of this book.)  Next we describe how the Hecke operators act on
both modular and Manin symbols, and how to compute trace and inclusion
maps between spaces of modular symbols of different levels.  We close
the chapter with a discussion of computations with modular symbols
over finite fields.

In this book we will view modular symbols primarily as a formalism
that generates algorithms for computing with modular forms.  I.e.,
{\em we view modular symbols as modular forms for computers}.
However, modular symbols have also been used to prove theoretical
results about modular forms.  For example, certain technical
calculations with modular symbols are used in Loic Merel's proof of
the uniform boundedness conjecture for torsion points on elliptic
curves over number fields; modular symbols arise, e.g., in order to
understand linear independence of Hecke operators.  Another example is
Grigor Grigorov's in-progress Ph.D. thesis, which distills hypotheses
about Kato's Euler system in $K_2$ of modular curves to a simple
formula involving modular symbols (when the hypotheses are satisfied,
one obtains a lower bound on the Shafarevich-Tate group of an elliptic
curve).

\section{Modular Symbols}
We begin by defining a free abelian group $\sM$ of modular symbols,
which you should think of as the homology of the extended upper half
plane $\h^* = \h\union \P^1(\Q)$ relative to the cusps.  This is the
free abelian group on symbols $\{\alpha,\beta\}$ with 
$$\alpha, \beta \in \P^1(\Q) = \Q \union \{\infty\}$$
subject to the relations 
$$
  \{\alpha,\beta\} + \{\beta,\gamma\} + \{\gamma,\alpha\} = 0,
$$
for all $\alpha,\beta,\gamma\in\P^1(\Q)$.  
More precisely, $\sM =
(F/R)/(F/R)_{\tor}$, where $F$ is the free abelian group on all pairs
$(\alpha,\beta)$ and $R$ is the subgroup generated by all elements of
the form $(\alpha,\beta) + (\beta,\gamma) + (\gamma,\alpha)$.
Note that $\sM$ is a huge free abelian group of countable rank.

\begin{remark}[Warning!]
The $\{\alpha,\beta\}$ satisfy
the relations $\{\alpha,\beta\} = -\{\beta,\alpha\}$, since
$
  \{\alpha,\beta\} + \{\beta,\alpha\} + \{\alpha,\alpha\} = 0.
$
Thus the order matters.  The notation $\{\alpha,\beta\}$ looks
like the set containing two elements, which strongly (and incorrectly) suggests
that the order does not matter.  This is annoying, but it is the
standard notation, and we will stick with it.
\end{remark}

Now fix an integer $k\geq 2$.
Let $\Z_{k-2}[X,Y]$ be the abelian group of homogeneous polynomials of
degree $k-2$ in two variables $X,Y$ (so $\Z_{k-2}[X,Y]$ is isomorphic
to $\Sym^{k-2}(\Z)$ as a group, but certain natural actions are
different).  Set
$$
     \sM_k = \Z_{k-2}[X,Y] \tensor_\Z \sM,
$$
which is a torsion-free abelian group whose elements are
sums of expressions of the form $X^{i}Y^{k-2-i}\tensor \{\alpha,\beta\}$.
For example, 
$$
    X^3 \tensor \{0,1/2\} -17 XY^2 \tensor \{\infty,1/7\} \in \sM_{5}.
$$

Fix a finite index subgroup $G$ of $\SL_2(\Z)$. 
%If $k$ is odd, assume that $-1\not\in G$.
Define a \defn{left action of $G$} on $\Z_{k-2}[X,Y]$ as follows.  If
$g=\abcd{a}{b}{c}{d}\in G$ and $P(X,Y)\in \Z_{k-2}[X,Y]$, let
$$(g.P)(X,Y) = P(dX-bY, -cX+aY).$$
Note that if we think of $z=(X,Y)$
as a column vector, then $$(g.P)(z) = P(g^{-1}z),$$
since $g^{-1} =
\abcd{\hfill{}d}{-b}{-c}{\hfill{}a}$, since $\det(g)=1$.  The reason
for the inverse is so that this is a left action instead of a right
action, which is what function pre-composition always is.  
As further explanation, observe that if $g,h\in G$, then 
$$
((gh).P)(z) = P((gh)^{-1}z) = P(h^{-1}g^{-1}z) =
(h.P)(g^{-1}z) = (g.(h.P))(z).  
$$

Let $G$ act on the left on $\sM$ by 
$$
 g.\{\alpha, \beta\} = \{g(\alpha), g(\beta)\}.
$$
Here $G$ is acting via linear fractional transformations,
so if $g=\abcd{a}{b}{c}{d}$, then 
$$g(\alpha)=\frac{a\alpha + b}{c\alpha + d}.$$
For example, useful special cases to remember are that if $g=\abcd{a}{b}{c}{d}$ then
$$
g(0) = \frac{b}{d} \qquad\text{and}\qquad g(\infty) = \frac{a}{c}.
$$

We now combine these two actions to obtain a left action of $G$ on $\sM_{k-2}$, 
which is given by
$$
  g.(P \tensor \{\alpha, \beta\}) = (g.P) \tensor\{g(\alpha), g(\beta)\}.
$$
For example, 
\begin{align*}
  \mtwo{\hfill 1}{\hfill 2}{-2}{-3}.(X^3 \tensor \{0,1/2\}) &=  
     (-3X - 2Y)^3 \tensor\left\{-\frac{2}{3},  -\frac{5}{8}\right\} \\
  &\hspace{-2em}= (-27X^3 - 54X^2Y - 36XY^2 - 8Y^3)\tensor \left\{-\frac{2}{3},  -\frac{5}{8}\right\}.
\end{align*}

We will often write 
$P(X,Y)\{\alpha,\beta\}$ for $P(X,Y)\tensor\{\alpha,\beta\}$.

\begin{definition}[Modular Symbols]
Let $k\geq 2$ be an integer and let $G$ be a finite index subgroup of $\SL_2(\Z)$.
The space $\sM_k(G)$ of weight~$k$ modular symbols for $G$ is the quotient of
$\sM_k$ by all relations $g.x - x$ for $x \in \sM_k$ and by any torsion.
\end{definition}
Note that $\sM_k$ is a torsion free abelian group, and it is a
nontrivial fact that $\sM_k$ has finite rank.  We denote modular
symbols for $G$ in exactly the same way we denote elements of $\sM_k$,
but with surrounding text that hopefully makes the group~$G$ clear.
Thus $X^3\{0,1/2\}$ is an example element of $\sM_5(\Gamma_0(8))$,
because I say so.  In practice this does not cause confusion.

The space of \defn{modular symbols over a ring $R$} is
$$
  \sM_k(G,R) = \sM_k(G)\tensor_\Z R.
$$
In Section~\ref{sec:msff} we will discuss computing $\sM_k(G,R)$ when
$R$ is a finite field. 


\section{Manin Symbols}\label{sec:manin}
At this point you are probably wondering how one could possibly ever
program a computer to {\em compute} $\sM_k(G)$ for any specific $k$
and $G$.  As defined above, $\sM_k(G)$ is the quotient of one
infinitely generated abelian group by another one.  This section
is about Manin symbols, which are simply a distinguished subset
of the elements of $\sM_k(G)$ that lead to a finite presentation for
$\sM_k(G)$.  Also, it has emerged that formulas written in terms of
Manin symbols are frequently much easier to compute using a computer
than formulas in terms of modular symbols.

The \defn{Manin symbol} associated to $g\in \SL_2(\Z)$ and $P\in \Z_{k-2}[X,Y]$ is
$$
  [P,g] = g.(P\{0,\infty\}) \in \sM_k(G).
$$
Notice that if $Gg = Gh$, then $[P,g] = [P,h]$, since 
the symbol $g.(P\{0,\infty\})$ is invariant
by the action of $G$ on the left (by definition,
since it is a modular symbols for $G$).
Thus we can also write $[P, Gg]$, and since $G$ has finite index in $\SL_2(\Z)$,
the abelian group generated by Manin symbols is of finite rank, generated by
$$
 \bigl\{ [X^{k-2-i}Y^i, \, Gg_j] \, : \, i = 0,\ldots, k-2, \quad\text{and}\quad j = 0,\ldots, r \bigr\},
$$
where $g_0, \ldots, g_r$ run through representatives for the 
right cosets $G\backslash \SL_2(\Z)$.

The great thing about Manin symbols is that every modular symbols can be written as
a $\Z$-linear combination of them, so they generate all $\sM_k(G)$.  The proof
of this fact is known as ``Manin's trick''.
\begin{proposition}\label{prop:mangen}
The Manin symbols generate $\sM_k(G)$.
\end{proposition}
\begin{proof}
Suppose that we are given a modular
symbol $P\{\alpha,\beta\}$ and wish to represent it as a 
sum of Manin symbols.   Because 
    $$P\{a/b,c/d\} = P\{a/b,0\}+P\{0,c/d\},$$
it suffices to write $P\{0,a/b\}$ in
terms of Manin symbols. 
Let
$$0=\frac{p_{-2}}{q_{-2}} = \frac{0}{1},\,\,
\frac{p_{-1}}{q_{-1}}=\frac{1}{0},\,\,
\frac{p_0}{1}=\frac{p_0}{q_0},\,\,
\frac{p_1}{q_1},\,\,
\frac{p_2}{q_2},\,\ldots,\,\frac{p_r}{q_r}=\frac{a}{b}$$
denote the continued fraction convergents of the 
rational number $a/b$. 
Then
$$p_j q_{j-1} 
  - p_{j-1} q_j = (-1)^{j-1}\qquad \text{for }-1\leq j\leq r.$$
If we let
$g_j = \mtwo{(-1)^{j-1}p_j}{p_{j-1}}{(-1)^{j-1}q_j}{q_{j-1}}$,
then $g_j\in\sltwoz$ and 
\begin{align*}
  P\{0,a/b\}
 &=P\sum_{j=-1}^{r}\left\{\frac{p_{j-1}}{q_{j-1}},\frac{p_j}{q_j}\right\}\\
 &=\sum_{j=-1}^{r} g_j((g_j^{-1}P)\{0,\infty\})\\
 &=\sum_{j=-1}^{r} [g_j^{-1}P,\,\,g_j].
\end{align*}
Since $g_j\in\sltwoz$ and $P$ has integer coefficients, 
the polynomial $g_j^{-1}P$ also has integer coefficients,
so we introduce no denominators.
\end{proof}
As is well known, the continued
fraction expansion $[c_1,c_2,\ldots,c_n]$ of the rational number $a/b$
can be computed using the Euclidean algorithm.  The first term $c_1$
is the ``quotient'': $a = bc_1+r$, with $0\leq r < b$.  Let $a'=b$,
$b'=r$ and compute $c_2$ as $a'=b'c_2+r'$, etc., terminating when the
remainder is $0$.  For example, the expansion of $5/13$ is
$[0,2,1,1,2]$.  The numbers $$d_i=c_1+\frac{1}{\ds c_2+\frac{1}{\ds
    c_3+\cdots}}$$
will then be the (finite) convergents.  For example
if $a/b=5/13$, then the convergents are $$0/1,\,\, 1/0,\,\, d_1=0,\,\,
d_2=\frac{1}{2},\,\, d_3=\frac{1}{3},\,\, d_4=\frac{2}{5},\,\,
d_5=\frac{5}{13}.$$

\begin{remark}
  One can prove Proposition~\ref{prop:mangen} inductively without
  introducing continued fractions, but that proof is essentially the
  same one used to prove the existence of continued fractions of
  integers.  (I think I saw this in \cite{mtt}, but I can't seem to
  find the exact location in that paper right now.)
\end{remark}

Now that we know the Manin symbols generate $\sM_k(G)$, the next question
is what are the relations between Manin symbols.  Fortunately the answer
is fairly simple (though the proof is not).  Let
$$
\sigma = \mtwo{0}{-1}{1}{\hfill 0},\qquad
\tau = \mtwo{0}{-1}{1}{-1}, \qquad
J = \mtwo{-1}{\hfill 0}{0}{-1}.
$$
Define a {\em right action} of $\SL_2(\Z)$ on Manin symbols
as follows.  If $h \in \SL_2(\Z)$, let
$$
   [P, g].h = [h^{-1}.P, gh].
$$
This is a right action because $P.h = h^{-1}P$ is a right
action, and right multiplication $g\mapsto gh$ is also
a right action.
\begin{theorem}\label{thm:mansym}
If $x$ is a Manin symbol, then
\begin{align}
x + x.\sigma &= 0\\
x + x.\tau + x.\tau^{2} &= 0\\
x - x.J &= 0.
\end{align}
Moreover, these are all the relations between Manin symbols, in the
sense that the space $\sM_k(G)$ of modular symbols is isomorphic to
the quotient of the free abelian group on the finitely many symbols
$[X^{i}Y^{k-2-i},Gg]$ (for $i=0,\ldots, k-2$, and 
$Gg \in G\backslash \SL_2(\Z)$) by the above relations and any torsion.
\end{theorem}
\begin{proof}
  We will only prove the easy ``half'' of the theorem here. The proof
  of the difficult half, i.e., that the above relations are all the
  relations is more complicated.  Merel remarks in
  \cite[\S1.3]{merel:1585} that the quotient of Manin symbols by the
  above relations and torsion is isomorphic to a space of
  {\v{S}}okurov symbols, which is in turn isomorphic to $\sM_k(G)$.
  He cites \cite{sokurov:shimura} for most of the proof.  See
also
\cite{math252} for an exposition of Manin's proof from
\cite{manin:parabolic} when $k=2$, which
  involves triangulating the Riemann surface $G\backslash \h$.

For the proof of the easy half, i.e., that the expressions
above are in fact relations, we follow Merel's
proof from \cite[\S1.2]{merel:1585}.
Note that 
$$\sigma(0) = \sigma^2(\infty) = \infty
\qquad\text{and}\qquad
  \tau(1) = \tau^2(0) = \infty.
$$
Write $x=[P,g]$, we have 
\begin{align*}
[P,g] + [P,g].\sigma &= 
  [P,g]  + [\sigma^{-1}.P, g\sigma]\\
 &= g.(P\{0,\infty\}) + g\sigma. (\sigma^{-1}.P \{0,\infty\})\\
 &=
  (g.P) \{ g(0), g(\infty) \} + 
  (g\sigma).(\sigma^{-1}. P)\{ g\sigma(0), g\sigma(\infty)\} \\
  &=   (g.P) \{ g(0), g(\infty) \} + 
  (g.P)\{ g(\infty), g(0)\} \\ 
  &= (g.P)(\{ g(0), g(\infty) \} + \{ g(\infty), g(0)\})\\
  &= 0.
\end{align*}
Also, 
\begin{align*}
[P,g] &+ [P,g].\tau + [P,g].\tau^2 = 
  [P,g]  + [\tau^{-1}.P, g\tau] + [\tau^{-2}.P, g\tau^2]\\
  &= 
g.(P\{0,\infty\}) + 
   g\tau.(\tau^{-1}.P \{0,\infty\}) 
   + g\tau^2.(\tau^{-2}.P \{0,\infty\}) \\
&= (g.P) \{ g(0), g(\infty) \} + 
   (g.P) \{ g \tau(0),g\tau(\infty)\}) 
   + (g.P) \{ g\tau^2(0),\tau^2(\infty)\}) \\
&= (g.P) \{ g(0), g(\infty) \} + 
   (g.P) \{ g(1),g(0)\}) 
   + (g.P) \{ g(\infty), g(1)\}) \\
 &= (g.P)(\{ g(0), g(\infty)\} + 
\{ g(\infty), g(1)\} + \{ g(1),g(0)\}) \\
&= 0
\end{align*}
Finally, 
\begin{align*}
[P,g] + [P,g].J &= 
  g.(P\{0,\infty\}) - gJ.(J^{-1} P \{gJ(0), gJ(\infty)\}\\
  &= (g.P)\{g(0),g(\infty)\} - (g.P) \{g(0),g(\infty)\}\\
  &= 0,
\end{align*}
where we use that $J$ acts trivially via linear fractional
transformations.
\end{proof}


If $G$ is a finite-index subgroup and we have an algorithm to
enumerate the right cosets $G\backslash \SL_2(\Z)$, and to decide
which coset an arbitrary element of $\SL_2(\Z)$ belongs to, then
Theorem~\ref{thm:mansym} and the algorithms of Chapter~\ref{ch:linalg}
yield an algorithm to compute $\sM_k(G,\Q)$.  We will defer further
discussion about precise details of algorithms to compute modular
symbols until Chapter~\ref{ch:modsymcomp}).   Note that 
if $J\in G$, then the relation $x-x.J=0$ is automatic.  Also
note the matrices $\sigma$ and $\tau$ {\em do not commute},
so one can {\em not} first quotient out by the two-term $\sigma$
relations, then quotient out only the remaining free generators
by the $\tau$ relations, and get the right answer in general.


\subsection{Coset Representatives and Manin Symbols}

\begin{proposition}\label{prop:gamma1cosets}
The right cosets $\Gamma_1(N)\backslash \SL_2(\Z)$ are in bijection
with pairs $(c,d)$ where $c,d\in\Z/N\Z$ and $\gcd(c,d,N)=1$.
The coset containing
a matrix $\abcd{a}{b}{c}{d}$ corresponds $(c,d)$.
\end{proposition}
\begin{proof}
This proof is copied from \cite[pg.~203]{cremona:gammaone},
except in that paper Cremona works with
the analogue of $\Gamma_1(N)$ in $\PSL_2(\Z)$, so
his result is slightly different.
Suppose $\gamma_i = \abcd{a_i}{b_i}{c_i}{d_i} \in \SL_2(\Z)$,
for $i=1,2$.
We have
$$
 \gamma_1 \gamma_2^{-1} = 
  \mtwo{a_1}{b_1}{c_1}{d_1}
  \mtwo{\hfill{}d_2}{-b_2}{-c_2}{\hfill{}a_2}
  =\mtwo{a_1 d_2 - b_1 c_2}{*}{c_1 d_2 - d_1 c_2}{a_2 d_1 - b_2 c_1},$$
which is in $\Gamma_1(N)$ if and only if 
\begin{equation}\label{eqn:cos1a}
  c_1 d_2 - d_1 c_2 \con 0 \pmod{N}
\end{equation}
and 
\begin{equation}\label{eqn:cos1b}
  a_2 d_1 - b_2 c_1 \con a_1 d_2 - b_1 c_2 \con 1\pmod{N}.
\end{equation}
Since the $\gamma_i$ have determinant~$1$, if $(c_1,d_1)=(c_2,d_2)\pmod{N}$,
then the congruences (\ref{eqn:cos1a}--\ref{eqn:cos1b}) hold.
Conversely, if (\ref{eqn:cos1a}--\ref{eqn:cos1b}) hold, then 
\begin{align*}
 c_2 &\con a_2 d_1 c_2 - b_2  c_1 c_2 \\
    &\con a_2 d_2 c_1 - b_2 c_2 c_1 \quad\text{ since }d_1 c_2 \con d_2 c_1 \pmod{N}\\
    &\con c_1 \qquad\qquad\qquad\quad\,\text{since }a_2 d_2 - b_2 c_2 = 1,
  \end{align*}
and likewise 
$$
d_2 \con a_2 d_1 d_2 - b_2 c_1 d_2
   \con a_2 d_1 d_2 - b_2 d_1 c_2
   \con d_1\pmod{N}.
$$
\end{proof}

Thus we may view weight~$k$ Manin symbols for $\Gamma_1(N)$ as triples
of integers $(i,c,d)$, where $0\leq i\leq k-2$ and $c, d\in\Z/N\Z$
with $\gcd(c,d,N)=1$.  Here $(i,c,d)$ corresponds to the Manin symbol
$[X^iY^{k-2-i}, \abcd{a}{b}{c'}{d'}]$, where  $c'$ and 
$d'$ lift $c,d$.    The relations of Theorem~\ref{thm:mansym}
become
\begin{align*}
(i,\,c,d) + (-1)^i (k-2-i, \,d, -c) &= 0,\\
(i,\,c,d) \quad + \quad\,        (-1)^{k-2} \sum_{j=0}^{k-2-i}  (-1)^{j} \binom{k-2-i}{j} (j,\,d,-c-d)&\\
       \qquad\qquad + \quad
(-1)^{k-2-i} \sum_{j=0}^i (-1)^j \binom{i}{j} (k-2-i+j,\,-c-d,c)
 &=0,\\
(i,\,c,d) - (-1)^{k-2}(i,\,-c,-d) &= 0.
\end{align*}

There is a similar description of cosets for $\Gamma_0(N)$:
\begin{proposition}
  The right cosets $\Gamma_0(N)\backslash \SL_2(\Z)$ are in bijection
  with the elements of $\P^1(\Z/N\Z)$.  The coset containing a matrix
  $\abcd{a}{b}{c}{d}$ corresponds to the point $(c:d) \in
  \P^1(\Z/N\Z)$.
\end{proposition}
For a proof, see \cite[\S2.2]{cremona:algs}.

\subsection{Modular Symbols With Character}
Suppose now that $G=\Gamma_1(N)\subset \SL_2(\Z)$.
Merel defines an action of diamond bracket operators $\dbd{d}$,
with $\gcd(d,N)=1$, on modular and
Manin symbols.  On Manin symbols the action is given by
$$
\langle n \rangle ([P,(c,d)]) = \left[P,(nc, nd)\right].
$$

Let 
$$
  \eps : (\Z/N\Z)^* \to \Q(\zeta)^*
$$
be a Dirichlet character, where $\zeta$ is
an $n$th root of unity and~$n$ is the order of~$\eps$.  
Let $\sM_k(\Gamma_1(N),\eps)$ be the quotient of 
$\sM_k(\Gamma_1(N),\Z[\zeta])$ by the relations (given
in terms of Manin symbols)
$$
  \dbd{d}x - \eps(d)x = 0,
$$
for all $x\in \sM_k(\Gamma_1(N),\Z[\zeta])$,
and by any torsion.  Thus $\sM_k(\Gamma_1(N),\eps)$
is a torsion free $\Z[\eps]$-module.


% Since we define $\sM_k(\Gamma_1(N),\eps)$ as a quotient of
% $\sM_k(\Gamma_1(N),\Z[\zeta])$, it might appear that it would be more
% difficult to compute than $\sM_k(\Gamma_1(N),\Z[\zeta])$.  
% the following proposition asserts that this is not the case.
% \begin{proposition}
% The space
% $\sM_k(\Gamma_1(N),\eps)$ of modular symbols 
% is generated by Manin symbols
% $[X^{i}Y^{k-2-i},g]$, where $g$ runs through a set
% of coset representatives for  $\Gamma_0(N)\backslash \SL_2(\Z)$,
% and $i=0,\ldots,k-2$.  
% \end{proposition}
% \begin{proof}
% Let $g_0,\ldots, g_r$ be a set of representatives for
% $\Gamma_0(N)\backslash \SL_2(\Z)$.
% Suppose $[P,\gamma] \in \sM_k(\Gamma_1(N),\eps)$
% with $\gamma\in \SL_2(\Z)$.  Let $m$ be such that 
% $\Gamma_0(N)g_m = \Gamma_0(N) \gamma$, so there exists 
% $g\in \Gamma_0(N)$ with $g_m = g\gamma{}$.  By definition
% of $\sM_k(\Gamma_1(N),\eps)$, we have
% $$
%   \eps(g) [P,\gamma] = [P,g\gamma]
%    = [P,g_m],
% $$
% which, since $\eps(g)\neq 0$, shows 
% that $[P,\gamma]$ is in the span of the
% symbols $[P,g_m]$.
% \end{proof}

\begin{remark}
I do not know whether or not $\sM_k(\Gamma_1(N),\eps)$
is necessarily free as a $\Z[\eps]$-module.
\end{remark}

\section{Hecke Operators}
% \begin{algorithm}{Hecke Operator}
% Given a positive integer $n$ and a presentation
% for $\sM_k(N,\eps)$, this algorithm computes the $n$th 
% Hecke operator $T_n$ on $\sM_k(N,\eps)$.
% \end{algorithm}

Just as for modular forms, there is a \defn{Hecke algebra}
$\T=\Z[T_1,T_2, \ldots]$ of Hecke operators that act on
$\sM_k(\Gamma_0(N))$.  
Let 
$$
R_p = \left\{\mtwo{1}{r}{0}{p} : r = 0,1,\ldots, p-1 \right\} 
         \union \left\{ \mtwo{p}{0}{0}{1}\right\},
$$
where we omit $\abcd{p}{0}{0}{1}$ if $p\mid N$.  Then 
the \defn{Hecke operator} $T_p$ on $\sM_k(\Gamma_0(N))$
is given by
$$
  T_p(x) = \sum_{g \in R} g.x.
$$
Notice when $p\nmid N$, that $T_p$ is defined by summing over 
$p+1$ matrices that correspond to the $p+1$ sublattices of $\Z\times \Z$
if index~$p$.  This is exactly how we defined $T_p$ on modular forms.

You might think at this point that we've just formally defined a
computable abelian group, and defined operators formally on it that
look something like the usual Hecke operators, but perhaps there's no
real connection.  As it turns out, the ring generated by all the Hecke
operators on modular symbols is commutative, and
$\sM_k(\Gamma_1(N),\R)$ is non-canonically isomorphic as a $\T$-module
to $M_k(\Gamma_1(N))$.  Note that $\sM_k(\Gamma_1(N),\R)$ is a real
vector space and $M_k(\Gamma_1(N))$ is a complex vector space, so this
should be viewed also as an isomorphism of $\R$-vector spaces.  In
fact there is an extra conjugation structure on
$\sM_k(\Gamma_1(N),\R)$, which we will discuss later.

\subsection{General Definition of Hecke Operators}
Let $\Gamma$ be a finite index subgroup of $\SL_2(\Z)$ and suppose
$$
  \Delta\subset \GL_2(\Q)
$$
is a set such that $\Gamma\Delta = \Delta\Gamma = \Delta$ 
and $\Gamma \backslash \Delta$
is finite.  For example, $\Delta=\Gamma$ trivially 
satisfies this condition.  Also,
if $\Gamma=\Gamma_1(N)$, then for any positive integer $n$, the set 
$$
  \Delta_n = \left\{
\mtwo{a}{b}{c}{d}\in M_2(\Z) \,\,:\,\, ad-bc=n,\,\,\text{and}\,\,
\mtwo{a}{b}{c}{d}\con \mtwo{1}{*}{0}{n}\pmod{N}
   \right\}
$$
also satisfies this condition, as we will now prove.
\begin{lemma}\label{lem:deltan}
We have 
$$
  \Gamma_1(N)\cdot \Delta_n = \Delta_n \cdot \Gamma_1(N) = \Delta_n
$$
and
$$
 \Delta_n = \bigcup_{a,b} \Gamma_1(N) \cdot \sigma_a \mtwo{a}{b}{0}{n/a},
$$
where $\sigma_a \con \abcd{\hfill 1/a}{\,\, 0}{0}{ \hfill a}\pmod{N}$,
the union is disjoint and $1\leq a \leq n$ with $a\mid n$, $\gcd(a,N)=1$,
and $0\leq b < n/a$.  In particular, the set of cosets
$\Gamma_1(N)\backslash \Delta_n$ is finite.
\end{lemma}
\begin{proof}
If $\gamma\in\Gamma_1(N)$ and $\delta\in\Delta_n$, then
$$
\mtwo{1}{*}{0}{1} \cdot \mtwo{1}{*}{0}{n} \con 
\mtwo{1}{*}{0}{n} \cdot \mtwo{1}{*}{0}{1}
\con \mtwo{1}{*}{0}{n}\pmod{N}.
$$ 
Thus $\Gamma_1(N)\Delta_n \subset \Delta_n$, and since $\Gamma_1(N)$
is a group $\Gamma_1(N)\Delta_n = \Delta_n$; likewise 
$\Delta_n\Gamma_1(N) = \Delta_n$.

For the coset decomposition, we first prove the statement for $N=1$, i.e., for 
$\Gamma_1(N)=\SL_2(\Z)$.   If $A$ is an arbitrary element
of $M_2(\Z)$ with determinant $n$, then using row operators on the left
with determinant $1$, i.e., left multiplication by elements of $\SL_2(\Z)$,
we can transform $A$ into the form $\abcd{a}{b}{0}{n/a}$, with
$1\leq a\leq n$ and $0\leq b < n$.  (Just imagine applying the Euclidean
algorithm to the two entries in the first column of $A$.  Then $a$
is the $\gcd$ of the two entries in the first column, and the lower left
entry is $0$.  Next subtract $n/a$ from $b$ until $0\leq b < n/a$.)

Next suppose $N$ is arbitrary.  Let $g_1, \ldots, g_r$ be such
that $$g_1\Gamma_1(N) \union \cdots \union g_r \Gamma_1(N) = \SL_2(\Z)$$
is a disjoint union.  If $A \in \Delta_n$ is arbitrary, then 
as we showed above, there is some $\gamma\in\SL_2(\Z)$, so that
$\gamma\cdot A = \abcd{a}{b}{0}{n/a}$, with $1\leq a \leq n$ and 
$0\leq b < n/a$, and $a\mid n$.   Write $\gamma = g_i \cdot \alpha$, with $\alpha\in\Gamma_1(N)$.
Then 
$$
  \alpha\cdot A = g_i^{-1} \cdot \mtwo{a}{b}{0}{n/a} \con \mtwo{1}{*}{0}{n}\pmod{N}.
$$
It follows that 
$$
  g_i^{-1} \con \mtwo{1}{*}{0}{n} \cdot \mtwo{a}{b}{0}{n/a}^{-1} 
    \con \mtwo{1/a}{*}{0}{a}\pmod{N}.
$$
Since $\abcd{1}{1}{0}{1}\in \Gamma_1(N)$ and $\gcd(a,N)=1$,
there is $\gamma'\in\Gamma_1(N)$ such
that $$\gamma' g_i^{-1} \con \mtwo{1/a}{0}{0}{a}\pmod{N}.$$
We may then choose $\sigma_a = \gamma' g_i^{-1}$.
Thus every $A\in \Delta_n$ is of the form
$\gamma \sigma_a \abcd{a}{b}{0}{n/a}$,
with $\gamma\in\Gamma_1(N)$ and $a,b$ suitably bounded.  This
proves the second claim.
\end{proof}

Let any element $\delta=\abcd{a}{b}{c}{d}\in\GL_2(\Q)$
act on the left on modular symbols $\M_k$ by
$$
\delta(P\{\alpha,\beta\}) = P(dX-bY,-cX+aY) \{\delta(\alpha),\delta(\beta)\}.
$$
(Until now we had only defined an action of $\SL_2(\Z)$
on modular symbols.)
For $g=\abcd{a}{b}{c}{d}\in \GL_2(\Q)$, let
\begin{equation}\label{eqn:gtilde}
 \tilde{g} = \mtwo{\hfill{}d}{-b}{-c}{\hfill{}a}
           = \det(g)\cdot g^{-1}.
         \end{equation}
Note that $\tilde{\tilde{g}} = g$.  
Also, $\delta.P(X,Y)=(P\circ \tilde{g})(X,Y)$,
where we set $$\tilde{g}(X,Y) = (dX-bY,-cX+aY).$$


Suppose $\Gamma$ and $\Delta$ are as above.    Fix
a finite set $R$ of representatives for $\Gamma\backslash \Delta$.
Let
$$
 T_{\Delta} : \M_k(\Gamma) \to \M_k(\Gamma)
$$
be the linear map
$$
  T_{\Delta}(x) = \sum_{\delta\in R} \delta \cdot x,
$$

This map is well defined because 
if $\gamma\in\Gamma$ and $x\in \M_k(\Gamma)$,
then 
$$\sum_{\delta\in R} \delta \gamma \cdot x = 
\sum_{\text{certain $\delta'$}} \gamma \delta'\cdot x
 = \sum_{\text{certain $\delta'$}} \delta'\cdot x
 =\sum_{\delta\in R} \delta\cdot x,
$$
where we have used that $\Delta\Gamma = \Gamma\Delta$, and 
$\Gamma$ acts trivially on $\M_k(\Gamma)$.

Let $\Gamma=\Gamma_1(N)$ and $\Delta=\Delta_n$.  Then the $n$th
Hecke operator $T_n$ is $T_{\Delta_n}$, and by Lemma~\ref{lem:deltan},
$$
 T_n(x) = \sum_{a,b} \sigma_a \mtwo{a}{b}{0}{n/a} \cdot x,
$$
where $a,b$ are as in Lemma~\ref{lem:deltan}.

Given this definition, we can compute the Hecke operators
on $M_k(\Gamma_1(N))$ as follows.
Write $x$ as a modular symbol $P\{\alpha,\beta\}$, compute
$T_n(x)$ as a modular symbol, then convert back to Manin
symbols using (many!) continued fractions expansions. 
This is extremely inefficient, and fortunately Lo\"{i}c Merel
found a much better way, which we now describe 
(see also \cite{merel:1585} and also \cite{mazur:symboles}).


\subsection{Hecke Operators on Manin Symbols}
If $S$ is a subset of $\GL_2(\Q)$, 
let $$\tilde{S} = \{\tilde{g} : g \in  S\}.$$
Also, for any ring $R$ and any subset $S\subset M_2(\Z)$, 
let $R[S]$ denote the free $R$-module with basis the elements of $S$,
so the elements of $R[S]$ are the finite $R$-linear combinations
of the elements of $S$.

One of the main theorems of \cite{merel:1585} is that for any $\Gamma,\Delta$
as above, if one can find $\sum u_M M \in \C[M_2(\Z)]$ and a map
$$\phi: \tilde{\Delta} \SL_2(\Z) \to \SL_2(\Z)$$
that satisfies a
complicated list of conditions, then for any Manin symbol $[P,g] \in
\M_k(\Gamma)$, we have $$
T_\Delta([P,g]) = \sum_{gM\in
  \tilde{\Delta}\SL_2(\Z)\text{ with }M\in\SL_2(\Z)} u_M
[\tilde{M}\cdot P,\,\, \phi(gM)].  $$
Merel devotes substantial work
to giving examples of $\phi$ and $\sum u_M M \in \C[M_2(\Z)]$ that
satisfy all his conditions.
 
When $\Gamma=\Gamma_1(N)$, the complicated list of conditions becomes
simpler.    Let $M_2(\Z)_n$ be the set of $2\times 2$
matrices with determinant $n$.  
An element
$$
  h = \sum u_M [M] \in \C[M_2(\Z)_n]
$$
\defn{satisfies condition $C_n$}
if for every $K\in M_2(\Z)_n / \SL_2(\Z)$, we have that 
\begin{equation}\label{eqn:cn}
  \sum_{M \in K} u_M([M\infty] - [M 0 ]) = [\infty] - [0]
\in \C[P^1(\Q)].
\end{equation}
If $h$ satisfies condition $C_n$, then for any Manin symbol
$[P,g] \in M_k(\Gamma_1(N))$, Merel proves that
\begin{equation}\label{eqn:tnmanin}
  T_n([P,(u,v)]) = \sum_{M} u_M [P(aX+bY, \, cX+dY), (u,v)M].
\end{equation}
Here $(u,v)\in (\Z/N\Z)^2$ corresponds to a coset of $\Gamma_1(N)$
in $\SL_2(\Z)$, as in Proposition~\ref{prop:gamma1cosets}, and
if $(u',v')=(u,v)M \in (\Z/N\Z)^2$, and $\gcd(u',v',N)\neq 1$,
then we omit the corresponding summand.

For example, we will now check directly that the element
$$
 h_2 =  \left[\mtwo{2}{0}{0}{1}\right] + 
        \left[\mtwo{1}{0}{0}{2}\right] + 
        \left[\mtwo{2}{1}{0}{1}\right] + 
        \left[\mtwo{1}{0}{1}{2}\right]
$$
satisfies condition $C_2$. 
We have, as in the proof of Lemma~\ref{lem:deltan}, 
but using elementary column operations, that
\begin{align*}
  M_2(\Z)_2/\SL_2(\Z) &= \left\{
\mtwo{a}{0}{b}{2/a} \SL_2(\Z) : a=1,2\text{ and }0\leq b < 2/a
\right\} \\
&= \left\{ \mtwo{1}{0}{0}{2} \SL_2(\Z),\,\,\,\,
       \mtwo{1}{0}{1}{2} \SL_2(\Z),\,\,\,\,
      \mtwo{2}{0}{0}{1} \SL_2(\Z) \right\}.
  \end{align*}
To verify condition $C_2$, we consider each of the three
elements of $M_2(\Z)_2/\SL_2(\Z)$ and check that (\ref{eqn:cn})
holds.  We have that 
$$
\mtwo{1}{0}{0}{2} \in \mtwo{1}{0}{0}{2} \SL_2(\Z),
$$
$$
\mtwo{2}{1}{0}{1}, \mtwo{1}{0}{1}{2} \in \mtwo{1}{0}{1}{2} \SL_2(\Z),
$$
and
$$
\mtwo{2}{0}{0}{1}\in \mtwo{2}{0}{0}{1} \SL_2(\Z).
$$
Thus if $K = \abcd{1}{0}{0}{2}\SL_2(\Z)$, the left
sum of (\ref{eqn:cn}) is 
$[\abcd{1}{0}{0}{2}(\infty)] - [\abcd{1}{0}{0}{2}(0)]  = [\infty]-[0]$,
as required.  If $K=\abcd{1}{0}{1}{2} \SL_2(\Z)$, then
the left side of (\ref{eqn:cn}) is 
$$
[\abcd{2}{1}{0}{1}(\infty)] - [\abcd{2}{1}{0}{1}(0)] 
 + [\abcd{1}{0}{1}{2}(\infty)] - [\abcd{1}{0}{1}{2}(0)] 
  = [\infty] - [1] + [1] - [0] = [\infty] - [0].
$$
Finally, for $K = \abcd{2}{0}{0}{1}\SL_2(\Z)$
we also have
$[\abcd{2}{0}{0}{1}(\infty)] - [\abcd{2}{0}{0}{1}(0)]  = [\infty]-[0]$,
as required.
Thus by (\ref{eqn:tnmanin}) we can compute $T_2$ on {\em any} Manin
symbol, by summing over the action 
 of the four matrices
$\abcd{2}{0}{0}{1}, \abcd{1}{0}{0}{2}, 
\abcd{2}{1}{0}{1}, \abcd{1}{0}{1}{2}$.

\begin{proposition}[Merel]\label{prop:heilbronn}
The element
$$\sum_{\substack{a>b\geq 0\\d>c\geq 0\\ad-bc=n}}
\left[\mtwo{a}{b}{c}{d}\right] \in \Z[M_2(\Z)_n]
$$
satisfies condition $C_n$.
\end{proposition}
Merel's proof isn't too difficult, but takes two pages.

\begin{remark}
  In \cite[\S2.4]{cremona:algs}, Cremona discusses the work of Merel
  and Mazur on Heilbronn matrices in the special cases
  $\Gamma=\Gamma_0(N)$ and weight~$2$.  He gives a fairly simple proof
  that the action of $T_p$ on Manin symbols can be computed by summing
  the action of some set $R_p$ of matrices of determinant~$p$.  He
  then describes the set $R_p$, and gives an efficient continued
  fractions algorithm for computing it (but he does not seem to prove
  that his description of $R_p$ is correct).  (Note: My experience is
  that Cremona's set $R_p$ is significantly smaller than the sets
  appearing in Merel's paper, but when I've tried to use $R_p$ to do
  certain more general higher-weight computations that are correct using
  Merel's sets, they do not work.)
\end{remark}

\subsection{Remarks on Complexity}
Merel also gives another family $\mathcal{S}_n$ of matrices
that satisfy condition $C_n$, and he proves that
as $n\to \infty$,
$$\#\mathcal{S}_n \sim \frac{12 \log(2)}{\pi^2} \cdot 
  \sigma_1(n)\log(n),$$
where $\sigma_1(n)$ is the sum of the divisors of $n$.
Thus for a fixed space $M_k(\Gamma)$ of modular symbols,
one can compute the Hecke operator $T_n$ using
$O(\sigma_1(n)\log(n))$ arithmetic operations in the
base field.  Note that we've fixed $M_k(\Gamma)$, so we ignore 
the linear algebra involved in computation of a presentation; also, adding
elements takes a bounded number of field operations when the space
is fixed.  Thus using Manin symbols 
the complexity of computing $T_p$, for~$p$ prime, is $O((p+1)\log(p))$
field operations, which is {\em exponential} in the number of digits
of~$p$.   

There is a trick of Basmaji (see \cite{basmaji:thesis}) for computing
a matrix of $T_n$ on $\sM_k(\Gamma)$, when $n$ is very large, and it is more
efficient than one might naively expect.  Basmaji's trick doesn't
improve the big-oh complexity for a fixed space, but does improve the
complexity by a constant factor of the dimension of $\sM_k(\Gamma,\Q)$.
Suppose we are interested in computing the matrix for $T_n$ for some massive
integer~$n$, and that $\sM_k(\Gamma,\Q)$ as has fairly large dimension.
The trick is as follows.  Choose, a list 
$$x_1 =[P_1,g_1],\ldots,x_r = [P_r,g_r] \in V = \sM_k(\Gamma,\Q)$$ 
of Manin symbols  such that the
map $\Psi:\T \to V^r$
 given by $$t \mapsto (t x_1, \ldots, t x_r)$$
is injective.  In practice, it is often possible to do this with $r$ ``very
small''.
Also, we emphasize that $V^r$ is a $\Q$-vector space of dimension 
$r\cdot \dim(V)$.

Next find Hecke operators $T_i$, with $i$ small, 
whose images form a basis for the image of $\Psi$.
Now with the above data precomputed, which only required working with
Hecke operators $T_i$ for small $i$, we are ready to compute $T_n$
with $n$ huge.  Compute $y_i = T_n(x_i)$, for each $i=1,\ldots, r$,
which we can compute using Heilbronn matrices since each
$x_i=[P_i,g_i]$ is a Manin symbol.  We thus obtain $\Psi(T_n) \in V^r.$
Since we have precomputed Hecke operators $T_j$ such that
$\Psi(T_j)$ generate $V^r$, we can find $a_j$ such that
$\sum a_j \Psi(T_j) = \Psi(T_n)$.  Then since $\Psi$
is injective, we have $T_n = \sum a_j T_j$, which gives
the full matrix of $T_n$ on $M_k(\Gamma,\Q)$.



\section{Cuspidal Modular Symbols}
Let $\sB$ be the free abelian group on symbols $\{\alpha\}$,
for $\alpha\in\P^1(\Q)$, and set
$$
  \sB_k = \Z_{k-2}[X,Y]\tensor\sB.
$$
Define a left action of $\SL_2(\Z)$ on $\sB_k$ by
$$
  g . (P \{\alpha\}) = (g.P) \{g(\alpha)\},
$$
for $g\in \SL_2(\Z)$.
For any finite index subgroup $\Gamma\subset \SL_2(\Z)$,
let 
$\sB_k(\Gamma)$ be the quotient of $\sB_k$ by the relations
$x- g.x$ for all $g\in \Gamma$ and by any torsion.  Thus
$\sB_k(\Gamma)$ is a torsion free abelian group.

The \defn{boundary map} is the map
$$
  b:\sM_k(\Gamma) \to \sB_k(\Gamma)
$$
given by extending the map
$$
  b(P\{\alpha,\beta\}) = P\{\beta\} - P\{\alpha\}
$$
linearly.
The space $\sS_k(\Gamma)$ of \defn{cuspidal modular symbols}
is the kernel 
$$
  \sS_k(\Gamma) = \ker(\sM_k(\Gamma) \to \sB_k(\Gamma)),
$$
so we have an exact sequence
$$
  0 \to \sS_k(\Gamma) \to \sM_k(\Gamma) \to \sB_k(\Gamma).
$$
One can prove that when $k>2$ then this sequence is exact
on the right.   Also, there is a presentation of $\sB_k(\Gamma)$
in terms of ``boundary Manin symbols''.  [[TODO: Add this later to
the book, but discussing this is not necessary for Math
257.]]



\section{The Pairing Between Modular Symbols and Modular Forms}
In this section we define a pairing between modular symbols and
modular forms, and prove that the Hecke operators respect this
pairing.  We also define an involution on modular symbols, and study
its relationship with the pairing.  This pairing is crucial in much
that follows, because it gives rise to period maps from modular
symbols to certain complex vector spaces.

Fix an integer weight $k\geq 2$ and a finite-index subgroup
$\Gamma$ of $\SL_2(\Z)$.  Let $M_k(\Gamma)$ denote the space
of holomorphic modular forms of weight~$k$ for $\Gamma$,
and $S_k(\Gamma)$ its cuspidal subspace.
Following \cite[\S1.5]{merel:1585}, let 
$$
 \Sbar_k(\Gamma) = \{\overline{f} : f \in S_k(\Gamma)\}
$$
denote the space of \defn{antiholomorphic} cuspforms.  Here
$\overline{f}$ is the function on $\h^*$ given by
$\overline{f}(z) = \overline{f(z)}$.

Define a pairing
\begin{equation}\label{eqn:intpairing}
 (S_k(\Gamma) \oplus \Sbar_k(\Gamma)) 
   \times \sM_k(\Gamma) \to \C
 \end{equation}
 by 
$$
  \langle (f_1, f_2), P\{\alpha,\beta\} \rangle 
   = \int_{\alpha}^{\beta} f_1(z) P(z,1)\dz +
    \int_{\alpha}^{\beta} f_2(z) P(\zbar,1) \dzbar,
$$
and extending linearly.   Here the integral is a complex
path integral along a great circle (or vertical line) from~$\alpha$ 
to~$\beta$ (so, e.g., write $z(t)=x(t) + iy(t)$,
where $(x(t),y(t))$ traces out the path, and consider
two real integrals; see any introductory 
book on complex analysis for more details).

The integration pairing is well defined, which means that if we
replace $P\{\alpha,\beta\}$ by an equivalent modular symbols
(equivalent modulo the left action of $\Gamma$), then the integral
is the same.  This follows from the change of variables formulas
for integration and the fact that $f_1 \in S_k(\Gamma)$ and
$f_2 \in \Sbar_k(\Gamma)$.  For example, if $k=2$,
$g\in \Gamma$ and $f\in S_k(\Gamma)$, then
\begin{align*}
  \langle f, g\{\alpha,\beta\}\rangle
  &= \langle f, \{g(\alpha),g(\beta)\}\rangle \\
  &= \int_{g(\alpha)}^{g(\beta)} f(z)\dz \\
  &= \int_{\alpha}^{\beta} f(g(z))d g(z) \\
  &= \int_{\alpha}^{\beta} f(z)\dz  = 
\langle f, \{\alpha, \beta\}\rangle,
\end{align*}
where in the last step we use that $f$ is a weight~$2$ modular form.

\begin{remark}
The integration pairing is related to special values of
$L$-functions.  The $L$-function
attached to a cusp form $f=\sum a_n q^n \in S_k(\Gamma_1(N))$ is
\begin{equation}\label{eqn:lfs}
  L(f,s) = (2\pi)^{s}\Gamma(s)^{-1} \int_{0}^{\infty} f(i t)t^s \frac{dt}{t}
\end{equation}
Note that one can show that 
$L(f,s) =\sum_{n=1}^{\infty} \frac{a_n}{n^s}$
by switching the order of summation and integration,
which is justified using standard estimates on $|a_n|$
(see, e.g., \cite[\S VIII.5]{knapp:elliptic}).

For each integer $j$ with $1 \leq j \leq k-1$, we have
setting $s=j$ and making the change of variables $t\mapsto -it$
in (\ref{eqn:lfs}), that
$$
L(f,j) = \frac{(-2\pi i)^{j}}{(j-1)!}
              \cdot \left\langle f,\,\,
       X^{j-1}Y^{k-2-(j-1)} \{0,\infty\} \right\rangle.
$$
The integers $j$ as above are called \defn{critical integers}, and
when $f$ is an eigenform, they have deep conjectural significance.
We will discuss tricks to efficiently compute $L(f,j)$ later in 
this book.
\end{remark}

\begin{theorem}[Shokoruv]
The pairing $\langle \cdot\, , \, \cdot \rangle$ is
nondegenerate when restricted to cuspidal modular symbols:
$$
\langle \cdot\, , \, \cdot \rangle: (S_k(\Gamma) \oplus \Sbar_k(\Gamma)) 
   \times \sS_k(\Gamma) \to \C.
$$
\end{theorem}

The pairing is also compatible with Hecke operators.  Before proving
this, we define an action of \defn{Hecke operators} on $M_k(\Gamma_1(N))$ and
on $\Sbar_k(\Gamma_1(N))$.  The definition is very similar to the one
we gave in Section~\ref{sec:hecke_one} for modular forms of level~$1$.
For a positive integer~$n$, let $R_n$ be a set of coset
representatives for $\Gamma_1(N)\backslash \Delta_n$ from
Lemma~\ref{lem:deltan}.  For any $\gamma=\abcd{a}{b}{c}{d} \in \GL_2(\Q)$
and $f\in M_k(\Gamma_1(N))$ set
$$
  f|[\gamma]_k = \det(\gamma)^{k-1} (cz+d)^{-k} f(\gamma(z)).
$$
Also, for $f\in \Sbar_k(\Gamma_1(N))$, set
$$
  f|[\gamma]_k' = \det(\gamma)^{k-1} (c\zbar+d)^{-k} f(\gamma(z)).
$$
Then for $f\in M_k(\Gamma_1(N))$, 
$$
  T_n(f) = \sum_{\gamma\in R_n} f|[\gamma]_k
$$
and for $f\in \Sbar_k(\Gamma_1(N))$, 
$$
  T_n(f) = \sum_{\gamma\in R_n} f|[\gamma]_k'.
$$
This agrees with the definition  from \ref{sec:hecke_one}
when $N=1$.

\begin{remark}
If $\Gamma$ is an arbitrary finite index subgroup of $\SL_2(\Z)$,
then we can define operators $T_\Delta$ on $M_k(\Gamma)$
for any $\Delta$ with $\Delta\Gamma=\Gamma\Delta = \Delta$
and $\Gamma\backslash \Delta$ finite.   For concreteness we
do not do the general case here or in the theorem below, but
the proof is exactly the same (see \cite[\S1.5]{merel:1585}).
\end{remark}

Finally we prove the promised Hecke compatibility of the pairing.
This proof should convince you that the definition of modular symbols
is sensible, in that they are ``natural'' expressions to
integrate against modular forms.
\begin{theorem}
If $f=(f_1,f_2)\in S_k(\Gamma_1(N)) \oplus \Sbar_k(\Gamma_1(N))$ and
$x \in \sM_k(\Gamma_1(N))$, then for any $n$, 
$$
  \langle T_n(f), x \rangle = \langle f, T_n(x) \rangle.
$$
\end{theorem}
\begin{proof}
We exactly follow \cite[\S2.1]{merel:1585}, and
will only prove the theorem when $f=f_1\in S_k(\Gamma_1(N))$, 
the proof in the general case being the same.  

Let $\alpha, \beta \in \P^1(\Q)$, $P\in \Z_{k-2}[X,Y]$,
and for $g=\abcd{a}{b}{c}{d}\in\GL_2(\Q)$, set 
$j(g,z) = (cz+d)$.  Let $n$ be any positive integer,
and let $R_n$ be a set of coset
representatives for $\Gamma_1(N)\backslash \Delta_n$ from
Lemma~\ref{lem:deltan}.

We have
\begin{align*}
\langle T_n(f), P\{\alpha,\beta\}\rangle &= 
    \int_{\alpha}^{\beta} T_n(f) P(z,1) \dz\\
   &= \sum_{\delta\in R} \int_{\alpha}^{\beta}
            \det(\delta)^{k-1} f(\delta(z)) j(\delta,z)^{-k} P(z,1) \dz.
\end{align*}
Now for each summand corresponding to the $\delta\in R$,
make the change of variables $u=\delta z$.  Thus we 
make $\# R$ change of variables.  Also, recall the
notation from (\ref{eqn:gtilde}), which we will use below.
\begin{align*}
\langle T_n(f), P\{\alpha,\beta\}\rangle &= 
   \sum_{\delta \in R}\int_{\delta(\alpha)}^{\delta(\beta)}
             \det(\delta)^{k-1} f(u) j(\delta, \delta^{-1}(u))^{-k}
             P(\delta^{-1}(u), 1) d(\delta^{-1}(u)) \\
   &= 
   \sum_{\delta \in R}\int_{\delta(\alpha)}^{\delta(\beta)}
             \det(\delta)^{k-1} f(u) j(\tilde{\delta},u)^{k}
             \det(\delta)^{-k}
             P(\tilde{\delta}(u), 1) \frac{\det(\delta) du}
                                        {j(\tilde{\delta}, u)^2}\\
  &= \sum_{\delta \in R}\int_{\delta(\alpha)}^{\delta(\beta)}
             f(u) j(\tilde{\delta},u)^{k-2}
             P(\tilde{\delta}(u), 1) du\\
  &= \sum_{\delta \in R} \int_{\delta(\alpha)}^{\delta(\beta)}
           f(u) \cdot ((\delta.P)(u,1)) du\\
  &= \langle f, \, T_n(P\{\alpha,\beta\})\rangle.
\end{align*}
The second equality is the trickiest.
First, note that $\delta^{-1}(u) = \tilde{\delta}(u)$,
since a linear fractional transformation is unchanged
by a nonzero rescaling of a matrix that induces it.
Thus by the quotient rule, using that $\tilde{\delta}$
has determinant $\det(\delta)$, we see that
$$
   d(\delta^{-1}(u)) = \frac{\det(\delta) du}{j(\tilde{\delta},u)^2}.
$$
The other part of the second equality asserts that
\begin{equation}\label{eqn:bigstuff}
j(\delta, \delta^{-1}(u))^{-k} P(\delta^{-1}(u),1)
=
j(\tilde{\delta},u)^k \det(\delta)^{-k} P(\tilde{\delta}(u),1).
\end{equation}
From the definitions, and again using that $\delta^{-1}(u)=\tilde{\delta}(u)$, we see that
$$
  j(\delta, \delta^{-1}(u)) = \frac{\det(\delta)}{j(\tilde{\delta}, u)},
$$
which proves that (\ref{eqn:bigstuff}) holds.
In the third equality, we use that 
$$
  (\delta.P)(u,1) = j(\tilde{\delta}, u)^{k-2}
                    P(\tilde{\delta}(u), 1).
$$
To see this, note that $P(X,Y) = P(X/Y, 1)\cdot Y^{k-2}$.
Using this we see that
\begin{align*}
(\delta.P)(X,Y) &= (P\circ \tilde{\delta})(X,Y)\\
      &= P\left(\tilde{\delta}\left(\frac{X}{Y}\right),1\right) 
      \cdot \left(-c \cdot \frac{X}{Y} + a\right)^{k-2} \cdot Y^{k-2}.
\end{align*}
Now substituting $(u,1)$ for $(X,1)$, we see that
$$ (\delta.P)(u,1) = 
  P(\tilde{\delta}(u), 1) \cdot (-c u + a)^{k-2},$$
as required.
\end{proof}

\begin{remark}
The theorem is true more generally for any $\Gamma$ and
any operator $T_{\Delta}$, via the same proof.
\end{remark}


Suppose  that $\Gamma$ is finite index
subgroup of $\SL_2(\Z)$ such that 
if $\eta = \abcd{-1}{0}{\hfill 0}{1}$, then 
$$
 \eta \Gamma \eta = \Gamma.
$$
For example, $\Gamma=\Gamma_1(N)$ satisfies this condition.
There is an involution $\iota^*$ on $\sM_k(\Gamma)$ given by
\begin{equation}\label{eqn:star}
  \iota^*(P(X,Y)\{\alpha,\beta\})
    = -P(X,-Y)\{-\alpha,-\beta\},
\end{equation}
which we call the \defn{star involution}.  
On Manin symbols, $\iota^*$ it is 
$$
  \iota^*[P,(u,v)] = -[P(-X,Y), (-u,v)].
$$
Let $\sS_k(\Gamma)^+$ be the $+1$ eigenspace for
$\iota^*$ and $\sS_k(\Gamma)^-$ the $-1$ eigenspace.
There is also a map $\iota$ on modular forms, which
is adjoint to $\iota^*$.
\begin{remark}[WARNING]
  Notice the $-$ sign in front of $-P(X,-Y)\{-\alpha,-\beta\}$ in
  (\ref{eqn:star}).  This sign is missing in \cite{cremona:algs},
  which confused me.  Thus the $+1$ quotient in MAGMA is the quotient
  where $\eta$ acts as $-1$.  (This is a mistake.)
\end{remark}

We now state the final result about the pairing, which
explains how modular symbols and modular forms
are related.
\begin{theorem}
  The pairing $\langle \cdot\, , \, \cdot \rangle$ restricts to give
  nondegenerate Hecke compatible  bilinear pairings 
$$
 \sS_k(\Gamma)^+ \times S_k(\Gamma) \to \C
\qquad \text{and}\qquad
\sS_k(\Gamma)^- \times \Sbar_k(\Gamma) \to \C.
$$
\end{theorem}
In light of the Peterson inner product, the above theorem implies that
there is a canonical isomorphism of $\T'$-modules $$\sS_k(\Gamma,\C)^+
\isom S_k(\Gamma),$$
where $\T'$ is the anemic Hecke algebra, i.e.,
the subring of $\T$ generated by Hecke operators $T_n$ with
$\gcd(n,N)=1$.  In fact, one can prove, e.g., using Eichler-Shimura
cohomology, that there is a non-canonical isomorphism over the full Hecke algebra
$$
  \sM_k(\Gamma,\C) \isom M_k(\Gamma) \oplus \overline{S}_k(\Gamma).
$$

\newpage
\section{Explicitly Computing $\sM_k(\Gamma_0(N)$}
In this section we explicitly compute $\sM_k(\Gamma_0(N))$
for various $k$ and $N$.  We represent Manin symbols for
$\Gamma_0(N)$ as triples $(i, u,v)$, where
$(u,v)\in\P^1(\Z/N\Z)$, and $(i, u,v)$ corresponds
to $[X^i Y^{k-2-i}, (u,v)]$ in the usual notation.
Also, recall that $(u,v)$ corresponds to the right coset in 
$\Gamma_0(N) \backslash \SL_2(\Z)$ that contains a matrix
$\abcd{a}{b}{c}{d}$ with $(u,v)\con (c,d)$ as elements of
$\P^1(\Z/N\Z)$, i.e., up to rescaling by an element
of $(\Z/N\Z)^*$.  

\subsection{Computing $\P^1(\Z/N\Z)$}\label{sec:p1rep}
In this section we give an algorithm to compute a canonical
representative for each element of $\P^1(\Z/N\Z)$.  This algorithm is
extremely important because modular symbols implementations call a
huge number of times.  A more naive approach would be to store all
pairs $(u,v)\in (\Z/N\Z)^2$, and a fixed reduced representative, but
this wastes a huge amount of memory.  For example, if $N=10^5$,
we would have to store an array of
$$
  (10^5 \cdot 10^5) / 10^6 = 10000 \text{ million integers},
$$
which is many terabytes.

Another approach to enumerating $\P^1(\Z/N\Z)$ is described at the end
of \cite[\S2.2]{cremona:algs}. We use that it is easy to
test whether two pairs $(u_0,v_0), (u_1,v_1)$ define the same element
of $\P^1(\Z/N\Z)$; they do if and only if we have equality of cross
terms $u_0 v_1 = v_0 u_1\pmod{N}$ (see
\cite[Prop.~2.2.1]{cremona:algs}).  So we list elements $(1,a)$ for
$a=0,1,\ldots, N-1$, then elements $(d,a)$ for $d\mid N$ and
$a=1,\ldots, N-1$, but checking each time we add a new element to our
list whether we have already seen it.  Unfortunately, given a random
pair $(u,v)$, which is something we encounter {\em very frequently}
in practice, we have to compare $(u,v)$ with each element of the
list to find our chosen equivalent representative in $\P^1(\Z/N\Z)$.  This
is very expensive, since it requires a linear search through
the list, hence takes time at least $O(n)$, where $n$
is the number of elements of $\P^1(\Z/N\Z)$.  To get around this
Cremona says he ``used a simple 'hashing' system, so that
given any particular symbole $(c,d)$ we could quickly determine
to which symbol in our standard list it is equivalent.'' (He doesn't
say what hashing system he uses.)

Instead of either of the above methods, we use the following
algorithm, which finds a canonical representative for each element of
$\P^1(\Z/N\Z)$.  With this algorithm in hand, given an arbitrary
$(u,v)$, we first find the canonical equivalent elements $(u',v')$,
then search a sorted lists of all canonical pairs, which takes time
$O(\log(n))$, where $n=\#\P^1(\Z/N\Z)$.

\begin{algorithm}{Reduce}\sf\label{alg:p1list}\vspace{-1ex}\\%
INPUT: Integers $u$ and $v$, and a positive integer~$N$.\vspace{1ex}\\
OUTPUT: If possible, this algorithm outputs 
a pair $u_0, v_0$ such that $(u,v) \con (u_0,v_0)$ as
  elements of $\P^1(\Z/N\Z)$ and $s\in\Z$ such that $(u,v) = (su_0,
  sv_0) \pmod{\Z/n\Z}$.  Moreover, the element $(u_0,v_0)$ does not
  depend on the class of $(u,v)$, i.e., for any~$s$ with $\gcd(N,s)=1$
  the input $(su,sv)$ also outputs $(u_0,v_0)$.  
  If $(u,v)$ is not in $\P^1(\Z/N\Z)$, this algorithm
  outputs $(0,0), 0$.\vspace{1ex}\\
THE ALGORITHM:
In the following algorithm, {\tt a\%N} denotes the residue of~$a$
modulo~$N$ that satisfies $0 \leq a < N$.  
\begin{enumerate}
\item Reduce both $u$ and $v$ modulo~$N$:
\begin{verbatim}
    u = u % N;   v = v % N  
\end{verbatim} 
\item Deal with the easy special case when $u=0$,
using that $(0,v)\in \P^1(\Z/N\Z)$ if and only if
$\gcd(v,N)=1$:
\begin{verbatim}
    if u == 0:  
        u0 = 0
        if gcd(v,N) == 1:
            v0 = 1
        else:
            v0 = 0
        s = v
        return (u0,v0), s
\end{verbatim}
\item Compute $g=\gcd(u,N)$ and $s,t\in\Z$ such that $g=su+tN$:
\begin{verbatim}
    g, s, t = XGCD(u, N)
    s = s % N
\end{verbatim}
\item We have $\gcd(u,v,N)=\gcd(g,v)$, so if 
$\gcd(g,v)>1$, then $(u,v)\not\in\P^1(\Z/N\Z)$.
\begin{verbatim}
    if gcd(g, v) != 1:
        return (0,0), 0
\end{verbatim}
\item Now $g = su + tN$, so we may think of~$s$ as ``pseudo-inverse''
  of $u \pmod{N}$, in the sense that $su$ is as close as possible to
  being $1$ modulo~$N$. Note that since $g\mid u$, changing~$s$ modulo
  $N/g$ does not change $su\pmod{N}$.  We can adjust~$s$ modulo $N/g$
  so it is coprime to $N$.  (This is because $1 = s u/g + tN/g$, so
  $s$ is a unit mod $N/g$, and the map $(\Z/N\Z)^* \to (\Z/(N/g)\Z)^*$
 is surjective, e.g., as we saw in the proof of 
  Algorithm~\ref{alg:restrict}.)
\begin{verbatim}
    if g != 1:
        d = N/g
        while gcd(s,N) != 1:
            s = (s+d) % N
\end{verbatim}

\item Multiply $(u,v)$ by $s$, replacing  $(u,v)$  by the
equivalent element $(g,sv)$ of $\P^1(\Z/N\Z)$.
\begin{verbatim}
    u = g
    v = (s*v) % N
\end{verbatim}        
\item Next we find the unique pair $(g,v')$ equivalent to $(g,v)$ that
minimizes $v$.   To do this, we note that if $1\neq t\in(\Z/N\Z)^*$ and
$tg \con g\pmod{N}$, then $(t-1)g \con 0\pmod{N}$, so $t-1 = kN/g$
for some $k$ with $1\leq k \leq g-1$.   Then for $t=1+kN/g$ coprime to~$N$, 
we have $(gt, vt) = (g, v+kvN/g)$.  The following part of the algorithm
computes all $(g, v+kvN/g)$ pairs and picks out the one that minimizes the 
least nonnegative residue of $vt$ modulo~$N$:
\begin{verbatim}
    min_v = v; min_t = 1
    if g != 1:
        Ng = N/g
        vNg = (v*Ng) % N
        t = 1
        for k in xrange(1,g):     # for k satisfying 1<=k<g.
            v = (v + vNg) % N
            t = (t + Ng) % N
            if v < min_v and gcd(t,N) == 1:
                min_v = v; min_t = t
    s = s * min_t
\end{verbatim}
\item The $s$ that we have computed in the above steps multiples
the input $(u,v)$ to give the output $(u_0,v_0)$.  Thus we
have to invert it, since the output scalar is supposed to
multiply $(u_0,v_0)$ to give $(u,v)$.
\begin{verbatim}
    s = inverse_mod(s, N)
    return (u,min_v), s
\end{verbatim}
\end{enumerate}
\end{algorithm}
\begin{remark}
Allan Steel and the author jointly came up with Algorithm~\ref{alg:p1list}.
\end{remark}

\begin{remark}
There might be an even better algorithm that uses that
$$\P^1(\Z/N\Z)\isom \prod_{p\mid N} \P^1(\Z/p^{\nu_p}\Z).$$
This would also use that it is relatively easy to enumerate
the elements of $\P^1(\Z/p^n\Z)$ for a prime power $p^n$.
I have not thought this through.
\end{remark}

\begin{algorithm}{List $\P^1(\Z/N\Z)$}
This algorithm makes a sorted list of the distinct canonical
representatives of $\P^1(\Z/N\Z)$, as output by Algorithm~\ref{alg:p1list}.\\
INPUT: An integer~$N>1$.\vspace{1ex}\\
OUTPUT: Sorted list of canonical representatives for $\P^1(\Z/N\Z)$.
\begin{enumerate}
\item First we make a list of the canonical representatives
of enough pairs $(c,d)$ to fill up $\P^1(\Z/N\Z)$.  In
the following code, we name Algorithm~\ref{alg:p1list} 
 {\tt p1\_normalize}.
\begin{verbatim}
    lst = [(0,1), (1,0)]
    for c in range(1,N):          # iterate c such that 1 <= c < N:
        lst.append((1,c))
        g = gcd(c,N)
        if g > 1:
            u, v, s = p1_normalize(c, 1,   N)
            lst.append((u,v))
            if g == c:              # so c is a divisor
                for d in xrange(2,N):              # 2 <= d < N
                    if gcd(d,N) > 1 and gcd(d,c) == 1:
                        u,v,s = p1_normalize(c, d,   N)
                        lst.append((u,v))
\end{verbatim}
\item Next we sort the list of canonical pairs, then with one
pass through the list delete any duplicates (or use the following
Python code, which is slightly different).
\begin{verbatim}
    lst = list(set(lst))    # Python trick remove duplicates.
    lst.sort()
\end{verbatim}
\end{enumerate}

\end{algorithm}

\subsection{Examples of Computation of $\sM_k(\Gamma_0(N))$}
In this section, we compute $\sM_k(\Gamma_0(N))$ explicitly in a few cases.
\begin{example}\label{example:m4_1}
We compute $V=\sM_4(\Gamma_0(1))$.   Because $S_k(\Gamma_0(1))=0$,
and $M_k(\Gamma_0(1))=\C E_4$, we expect $V$ to have dimension~$1$,
and for the Hecke operator $T_n$ to have eigenvalues the
sum $\sigma_3(n)$ of the cubes of positive divisors of $n$.

The Manin symbols are 
$$
  x_0 = (0, 0, 0), \quad x_1 = (1, 0, 0), \quad x_2 = (2, 0, 0).
$$
The relation matrix is
$$
\left(\begin{matrix}
{}1&{}0&{}1\\
{}0&{}0&{}0\\
\hline
{}2&{}-2&{}2\\
{}1&{}-1&{}1\\
{}2&{}-2&{}2
\end{matrix}\right),
$$
where the first 2 rows correspond to $S$ relations and the second
two to $T$ relations.
Note that we don't include all $S$ relations, since it is obvious
that some are redundant, e.g., $x+xS=0$ and $(xS) + (xS)S=xS + x=0$
are the same since~$S$ has order~$2$.  (It's not clear to
me what is going on with $T$ relations when $k>2$, though in this 
example two of the three $T$ relations are redundant.)

The echelon form of the relation matrix is
$$
\left(\begin{matrix}
\hfill{}1&\hfill{}0&\hfill{}1\\
\hfill{}0&\hfill{}1&\hfill{}0\\
\end{matrix}\right),
$$
where we've deleted the zero rows from the bottom.
Thus we may replace the above complicated list
of relations with the following simpler list of relations:
\begin{align*}
   x_0 + x_2  &= 0\\
    x_1 &= 0
\end{align*}
from which we immediately read off that the second generator $x_1$ is
$0$ and $x_0=-x_2$.  Thus $\sM_4(\Gamma_0(1))$ has dimension~$1$, with
basis the equivalence class of $x_2$ (or of $x_0$).

Next we compute the Hecke operator $T_2$ on $\sM_4(\Gamma_0(1))$.
The Heilbronn matrices of determinant $2$ from Proposition~\ref{prop:heilbronn}
are
%M=MatrixSpace(Q,2) 
%h=HeilbronnMerel(2)
%print "\n".join(["h_%s="%i+M(h[i]).latex()+",\\quad{} " for i in range(len(h))])
$$
h_0=\left(\begin{matrix}
\hfill{}1&\hfill{}0\\
\hfill{}0&\hfill{}2
\end{matrix}\right),\quad{}
h_1=\left(\begin{matrix}
\hfill{}1&\hfill{}0\\
\hfill{}1&\hfill{}2
\end{matrix}\right),\quad{}
h_2=\left(\begin{matrix}
\hfill{}2&\hfill{}0\\
\hfill{}0&\hfill{}1
\end{matrix}\right),\quad{}
h_3=\left(\begin{matrix}
\hfill{}2&\hfill{}1\\
\hfill{}0&\hfill{}1
\end{matrix}\right),\quad{}
$$
To compute $T_2$, we apply each of these matrices to $x_0$,
then reduce modulo the relations.
We have
\begin{align*}
  x_2.\mtwo{1}{0}{0}{2} &= [X^2,(0,0)].\mtwo{1}{0}{0}{2}
         x_2\\
  x_2.\mtwo{1}{0}{1}{2} &= [X^2,(0,0)] = x_2\\
  x_2.\mtwo{2}{0}{0}{1} &= [(2X)^2,(0,0)] = 4x_2\\
  x_2.\mtwo{2}{1}{0}{1} &= [(2X+1)^2,(0,0)] = x_0 + 4x_1 + 4x_2
                                            \sim 3x_2
\end{align*}
Summing we see that $T_2(x_2) \sim 9x_2$ in $\sM_4(\Gamma_0(1))$.
Notice that 
$$9=1^3+2^3 = \sigma_3(2).$$

The Merel Heilbronn matrices of determinant $3$ from 
Proposition~\ref{prop:heilbronn} are
%print "\n".join(["h_%s="%i+M(h[i]).latex()+",\\quad{} " for i in range(len(h))])
\begin{align*}
h_0&=\left(\begin{matrix}
\hfill{}1&\hfill{}0\\
\hfill{}0&\hfill{}3
\end{matrix}\right),\quad{}
h_1=\left(\begin{matrix}
\hfill{}1&\hfill{}0\\
\hfill{}1&\hfill{}3
\end{matrix}\right),\quad{}
h_2=\left(\begin{matrix}
\hfill{}1&\hfill{}0\\
\hfill{}2&\hfill{}3
\end{matrix}\right),\quad{}
h_3=\left(\begin{matrix}
\hfill{}2&\hfill{}1\\
\hfill{}1&\hfill{}2
\end{matrix}\right),\quad{}\\
h_4&=\left(\begin{matrix}
\hfill{}3&\hfill{}0\\
\hfill{}0&\hfill{}1
\end{matrix}\right),\quad{}
h_5=\left(\begin{matrix}
\hfill{}3&\hfill{}1\\
\hfill{}0&\hfill{}1
\end{matrix}\right),\quad{}
h_6=\left(\begin{matrix}
\hfill{}3&\hfill{}2\\
\hfill{}0&\hfill{}1
\end{matrix}\right).
\end{align*}

We have
\begin{align*}
  x_2.\mtwo{1}{0}{0}{3} &= [X^2,(0,0)].\mtwo{1}{0}{0}{3} =
         x_2\\
  x_2.\mtwo{1}{0}{1}{3} &= [X^2,(0,0)] = x_2\\
  x_2.\mtwo{1}{0}{2}{3} &= [X^2,(0,0)] = x_2\\
  x_2.\mtwo{2}{1}{2}{2} &= [(2X+1)^2,(0,0)] = x_0 + 4x_1 + 4x_2
                                            \sim 3x_2\\
  x_2.\mtwo{3}{0}{0}{1} &= [(3X)^2,(0,0)] = 9x_2\\
  x_2.\mtwo{3}{1}{0}{1} &= [(3X+1)^2,(0,0)] = x_0 + 6x_1 + 9x_2 \sim 8x_2\\
  x_2.\mtwo{3}{2}{0}{1} &= [(3X+2)^2,(0,0)] = 4x_0 + 12x_1 + 9x_2 \sim 5x_2\\
\end{align*}
Summing we see that 
$$T_3(x_2) \sim x_2 + x_2 + x_2 + 3x_2 + 9x_2 + 8x_2 + 5x_2
           = 28 x_2.
$$
Notice that 
$$28=1^3+3^3 = \sigma_3(3).$$

\end{example}

\begin{example}
Next we compute $\sM_2(\Gamma_0(11))$ explicitly.
The Manin symbol generators are 
$$
x_0= (0, 1),\quad
x_1= (1, 0),\quad
x_2= (1, 1),\quad
x_3= (1, 2),\quad
x_4= (1, 3),\quad
x_5= (1, 4),\quad
$$
$$
x_6= (1, 5),\quad
x_7= (1, 6),\quad
x_8= (1, 7),\quad
x_9= (1, 8),\quad
x_{10}= (1, 9),\quad
x_{11}= (1, 10).
$$
The relation matrix is as follows, where the $S$
relations are above the line, and the $T$ relations
are below it.
$$
\left(\begin{array}{ccccccccccccc}
1&1&0&0&0&0&0&0&0&0&0&0\\
0&0&1&0&0&0&0&0&0&0&0&1\\
0&0&0&1&0&0&1&0&0&0&0&0\\
0&0&0&0&1&0&0&0&1&0&0&0\\
0&0&0&0&0&1&0&0&0&1&0&0\\
0&0&0&0&0&0&0&1&0&0&1&0\\
\hline
1&1&0&0&0&0&0&0&0&0&0&1\\
0&0&1&0&0&0&1&0&0&0&1&0\\
0&0&0&1&0&1&0&0&1&0&0&0\\
0&0&0&0&1&0&0&1&0&1&0&0
\end{array}\right)
$$
In weight $2$, two out of three $T$-relations are redundant, so we
do not include them.
The reduced row echelon form of the relation matrix is
$$
\left(\begin{array}{cccccccccccc}
1&1&0&0&0&0&0&0&0&0&0&0\\
0&0&1&0&0&0&0&0&0&0&0&0\\
0&0&0&1&0&0&0&0&0&0&-1&0\\
0&0&0&0&1&0&0&0&0&1&-1&0\\
0&0&0&0&0&1&0&0&0&1&0&0\\
0&0&0&0&0&0&1&0&0&0&1&0\\
0&0&0&0&0&0&0&1&0&0&1&0\\
0&0&0&0&0&0&0&0&1&-1&1&0\\
0&0&0&0&0&0&0&0&0&0&0&1\\
0&0&0&0&0&0&0&0&0&0&0&0
\end{array}\right)
$$
From the echelon form we immediaely see that every symbol
is equivalent to a combination of
$x_1=(1,0)$, $x_9=(1,8)$, and $x_{10}=(1,9)$.
(Notice that columns $1$, $9$, and $10$ are the pivot
columns, where we index columns starting at $0$.)
Explicitly, if $(a,b,c)$ is the $i$th row of the following
matrix, then  $x_i = a x_1 + b x_9 + c x_{10}$:
$$\left(\begin{array}{ccc}
-1&0&0\\
1&0&0\\
0&0&0\\
0&0&1\\
0&-1&1\\
0&-1&0\\
0&0&-1\\
0&0&-1\\
0&1&-1\\
0&1&0\\
0&0&1\\
0&0&0
\end{array}\right)$$

To compute $T_2$, we apply each of the Heilbronn
matrices of determinant~$2$ from Proposition~\ref{prop:heilbronn}
to $x_1$, then to $x_9$, and finally to $x_{10}$.
The matrices are as in Example~\ref{example:m4_1} above.
We have
$$
  T_2(x_1) = 3(1,0) + (1,6) \sim 3x_1 - x_{10}.
$$
Applying $T_2$ to $x_9=(1,8)$, we get
$$
 T_2(x_9) =  (1,3)  + (1,4) + (1,5) + (1,10) \sim -2x_9
$$
Applying $T_2$ to $x_{10}=(1,9)$, we get
$$
T_2(x_{10})= (1,4)+(1,5) + (1,7) + (1,10) \sim -x_1 - 2x_{10}.
$$
Thus the matrix of $T_2$ with respect to this basis is
$$
T_2 = 
\left(\begin{array}{ccc}
3&0&0\\
0&-2&0\\
-1&0&-2
\end{array}\right),
$$
where we write the matrix as an operator on the left on vectors
written in terms of $x_1$, $x_9$, and $x_{10}$.
The matrix $T_2$ has characteristic polynomial
$$
  (x-3) (x+2)^2.
$$
The $(x-3)$ factor corresponds to the weight $2$ Eisenstein
series, and the $x+2$ factor corresponds to the elliptic
curve $E=X_0(11)$, which has $$a_2 = -2 = 2+1 - \#E(\F_2).$$

We have
\begin{align*}
 T_3(x_1) &= 4 (1,0) + (1,4) + (1,6) + (1,8) \sim 4 x_1 - x_{10}\\
 T_3(x_9) &= (1,2)  + (1,3) + (1,4)+ (1,5) + (1,7) + 2(1,10) \sim -x_9\\
 T_3(x_{10}) &= (0,1) + (1,0) + (1,2) + (1,3) + (1,5) + (1,6) +(1,7)
    \sim -x_{10},
\end{align*}
so
$$
T_3 = 
\left(\begin{array}{ccc}
4&0&0\\
0&-1&0\\
-1&0&-1
\end{array}\right).
$$
The characteristic polynomial of $T_3$ is 
$(x-4)(x+1)^2$.
\end{example}


\begin{example}
In this example, we compute $\sM_6(\Gamma_0(3))$, 
which illustrates both big weight and nontrivial
level.  
We have the following generating Manin symbols:
\begin{align*}
x_{0} &= [XY^4,(0,1)],\qquad x_{1} = [XY^4,(1,0)]\\
x_{2} &= [XY^4,(1,1)], \qquad x_{3} = [XY^4,(1,2)]\\
x_{4} &= [XY^3,(0,1)], \qquad x_{5} = [XY^3,(1,0)]\\
x_{6} &= [XY^3,(1,1)], \qquad 
x_{7} = [XY^3,(1,2)]\\
x_{8} &= [X^2Y^2,(0,1)], \qquad 
\!\!x_{9} = [X^2Y^2,(1,0)]\\
x_{10} &= [X^2Y^2,(1,1)], \qquad 
\!\!\!\!x_{11} = [X^2Y^2,(1,2)]\\
x_{12} &= [X^3Y,(0,1)], \qquad 
x_{13} = [X^3Y,(1,0)]\\
x_{14} &= [X^3Y,(1,1)], \qquad 
x_{15} = [X^3Y,(1,2)]\\
x_{16} &= [X^4Y,(0,1)], \qquad 
x_{17} = [X^4Y,(1,0)]\\
x_{18} &= [X^4Y,(1,1)], \qquad 
x_{19} = [X^4Y,(1,2)]\\
\end{align*}
The relation matrix is already very large
for $\M_6(\Gamma_0(3))$ follows, where the $S$ relations
are before the line and the $T$ relations after it:
{\mbox{}\small
$$\hspace{-1em}
\left(\begin{array}{cccccccccccccccccccc}
1&0&0&0&0&0&0&0&0&0&0&0&0&0&0&0&0&1&0&0\\
0&1&0&0&0&0&0&0&0&0&0&0&0&0&0&0&1&0&0&0\\
0&0&1&0&0&0&0&0&0&0&0&0&0&0&0&0&0&0&0&1\\
0&0&0&1&0&0&0&0&0&0&0&0&0&0&0&0&0&0&1&0\\
0&0&0&0&1&0&0&0&0&0&0&0&0&-1&0&0&0&0&0&0\\
0&0&0&0&0&1&0&0&0&0&0&0&-1&0&0&0&0&0&0&0\\
0&0&0&0&0&0&1&0&0&0&0&0&0&0&0&-1&0&0&0&0\\
0&0&0&0&0&0&0&1&0&0&0&0&0&0&-1&0&0&0&0&0\\
0&0&0&0&0&0&0&0&1&1&0&0&0&0&0&0&0&0&0&0\\
0&0&0&0&0&0&0&0&0&0&1&1&0&0&0&0&0&0&0&0\\\hline
1&0&0&1&0&0&0&-4&0&0&0&6&0&0&0&-4&0&1&0&1\\
1&1&0&0&-4&0&0&0&6&0&0&0&-4&0&0&0&1&0&0&1\\
0&0&2&0&0&0&-4&0&0&0&6&0&0&0&-4&0&0&0&2&0\\
0&1&0&1&0&-4&0&0&0&6&0&0&0&-4&0&0&1&1&0&0\\
0&0&0&1&1&0&0&-3&0&0&0&3&0&-1&0&-1&0&1&0&0\\
1&0&0&0&-3&1&0&0&3&0&0&0&-1&0&0&-1&0&0&0&1\\
0&0&1&0&0&0&-2&0&0&0&3&0&0&0&-2&0&0&0&1&0\\
0&1&0&0&0&-3&0&1&0&3&0&0&-1&-1&0&0&1&0&0&0\\
0&0&0&1&0&0&0&-2&1&1&0&1&0&-2&0&0&0&1&0&0\\
1&0&0&0&-2&0&0&0&1&1&0&1&0&0&0&-2&0&0&0&1\\
0&0&1&0&0&0&-2&0&0&0&3&0&0&0&-2&0&0&0&1&0\\
0&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4\\
0&0&0&0&0&0&0&0&0&0&0&0&1&0&0&0&0&0&-1/16&1/16\\
0&0&0&0&0&0&0&0&0&0&0&0&0&1&0&0&0&0&3/16&-3/16\\
0&0&0&0&0&0&0&0&0&0&0&0&0&0&1&0&0&-1/2&3/16&5/16\\
0&0&0&0&0&0&0&0&0&0&0&0&0&0&0&1&0&1/2&-5/16&-3/16\\
\end{array}\right)
$$}
Since these relations are equivalent to the original
relations, we see quite clearly how
$x_0, \ldots, x_{15}$ can be expressed in 
terms of $x_{16}$, $x_{17}$, $x_{18}$, and $x_{19}$.
Thus $\sM_6(\Gamma_0(3))$ has dimension $4$.
For example, 
$$x_{15} \sim \frac{1}{2} x_{17} -\frac{5}{16}x_{18}
        - \frac{3}{16} x_{19}.
$$


Notice that the number of relations is already quite large. It is
perhaps surprisingy how complicated the presentation is for
$\sM_6(\Gamma_0(3))$.  Because there are denominators in the
relations, the above calculation is only a computation of
$\sM_6(\Gamma_0(3),\Q)$.  Computing $\sM_6(\Gamma_0(3),\Z)$ requires
computation of a $\Z$-basis for the kernel of the relation matrix,
which could be accomplished via, e.g., Hermite normal form or LLL
reduction.

As before, we find that with respect to the basis 
$x_{16}$, $x_{17}$, $x_{18}$, and $x_{19}$, that 
$$
T_2 = 
\left(\begin{array}{cccc}
33&0&0&0\\
3&6&12&12\\
-3/2&27/2&15/2&27/2\\
-3/2&27/2&27/2&15/2
\end{array}\right)
$$
Notice that there are denominators in the matrix for
$T_2$ with respect to this basis.  It is clear from
the definition of $T_2$ acting on Manin symbols that
$T_2$ preserves the $\Z$-module $\sM_6(\Gamma_0(3))$,
so there is some basis for $\sM_6(\Gamma_0(3))$
such that $T_2$ is given by an integer matrix.  Thus
the characteristic polynomial $f_2$ of $T_2$ will have integer
coefficients; indeed, 
$$
  f_2 = (x-33)^2 \cdot (x+6)^2.
$$
Note the factor of $33$, which comes from the two images
of the Eisenstein series $E_4$ of level~$1$.  The
factor $x+6$ comes from a cusp form 
$$
  g = q - 6q^2 + \cdots \in S_6(\Gamma_0(3)).
$$
By computing more Hecke operators $T_n$, we
can find more coefficients of~$g$.
For example, the charpoly of $T_3$ is 
$(x-1)(x-243)(x-9)^2$, and the matrix of $T_5$
is 
$$
T_5 = \left(\begin{array}{cccc}
3126&0&0&0\\
240&966&960&960\\
-120&1080&1086&1080\\
-120&1080&1080&1086
\end{array}\right),
$$
which has characteristic polynomial
$$
  f_5 = (x-3126)^2 (x-6)^2.
$$
The matrix of $T_7$ is 
$$T_7 = \left(\begin{array}{cccc}
16808&0&0&0\\
1296&5144&5184&5184\\
-648&5832&5792&5832\\
-648&5832&5832&5792
\end{array}\right),
$$
with characteristic polynomial
$$
 f_7 = (x -16808)^2 (x + 40)^2.
$$
One can put this information together to deduce that
$$
  g = q - 6q^2 + 9q^3 + 4q^4 + 6q^5 - 54q^6 - 40q^7 +\cdots.
$$
\end{example}

\begin{example}
The relation matrix for $\M_2(\Gamma_0(43))$ is 
{\tiny
\mbox{}
$$
\left(\begin{array}{cccccccccccccccccccccccccccccccccccccccccccc}
1&\!\!\!\!1&\!\!\!\!0&\!\!\!\!0&\!\!\!\!0&\!\!\!\!0&\!\!\!\!0&\!\!\!\!0&\!\!\!\!0&\!\!\!\!0&\!\!\!\!0&\!\!\!\!0&\!\!\!\!0&\!\!\!\!0&\!\!\!\!0&\!\!\!\!0&\!\!\!\!0&\!\!\!\!0&\!\!\!\!0&\!\!\!\!0&\!\!\!\!0&\!\!\!\!0&\!\!\!\!0&\!\!\!\!0&\!\!\!\!0&\!\!\!\!0&\!\!\!\!0&\!\!\!\!0&\!\!\!\!0&\!\!\!\!0&\!\!\!\!0&\!\!\!\!0&\!\!\!\!0&\!\!\!\!0&\!\!\!\!0&\!\!\!\!0&\!\!\!\!0&\!\!\!\!0&\!\!\!\!0&\!\!\!\!0&\!\!\!\!0&\!\!\!\!0&\!\!\!\!0&\!\!\!\!0\\
0&\!\!\!\!0&\!\!\!\!1&\!\!\!\!0&\!\!\!\!0&\!\!\!\!0&\!\!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\!\!\!\!0&\!\!\!\!0&\!\!\!\!0&\!\!\!\!0&\!\!\!\!1&\!\!\!\!0&\!\!\!\!0&\!\!\!\!0&\!\!\!\!0&\!\!\!\!0&\!\!\!\!0&\!\!\!\!0&\!\!\!\!0&\!\!\!\!1&\!\!\!\!0&\!\!\!\!1&\!\!\!\!0&\!\!\!\!0&\!\!\!\!0&\!\!\!\!0&\!\!\!\!0\\
0&\!\!\!\!0&\!\!\!\!0&\!\!\!\!0&\!\!\!\!0&\!\!\!\!0&\!\!\!\!0&\!\!\!\!0&\!\!\!\!0&\!\!\!\!0&\!\!\!\!0&\!\!\!\!0&\!\!\!\!0&\!\!\!\!0&\!\!\!\!0&\!\!\!\!0&\!\!\!\!0&\!\!\!\!0&\!\!\!\!0&\!\!\!\!0&\!\!\!\!0&\!\!\!\!0&\!\!\!\!0&\!\!\!\!0&\!\!\!\!0&\!\!\!\!0&\!\!\!\!0&\!\!\!\!0&\!\!\!\!0&\!\!\!\!0&\!\!\!\!0&\!\!\!\!0&\!\!\!\!0&\!\!\!\!0&\!\!\!\!0&\!\!\!\!0&\!\!\!\!0&\!\!\!\!3&\!\!\!\!0&\!\!\!\!0&\!\!\!\!0&\!\!\!\!0&\!\!\!\!0&\!\!\!\!0
\end{array}\right)
$$
}
Reducing, one computes a presentation for $\sM_2(\Gamma_0(43))$,
which has dimension $7$.  With respect to the symbols 
\begin{align*}
x_1&=(1,0),\quad x_{32}=(1,31),\quad
 x_{33} = (1,32),\\ 
x_{39} &= (1,38),\quad
 x_{40} = (1,39), \quad
x_{41} = (1,40),\quad
  x_{42} = (1,41),
\end{align*}
the matrix of $T_2$ is
$$
T_2=\left(\begin{array}{ccccccc}
3&0&0&0&0&0&0\\
0&-2&-1&-1&-1&0&0\\
0&1&1&0&0&-2&-1\\
0&0&1&-1&1&0&0\\
0&0&0&2&1&2&1\\
0&0&-1&-1&-1&-2&0\\
-1&0&0&1&1&1&-1
\end{array}\right),
$$
which has characteristic polynomial
$$
  (x-3)(x+2)^2 (x^2-2)^2.
$$
There is one Eisenstein series, and three cusp forms
with $a_2 = -2$ and $a_2 = \pm \sqrt{2}$.

\end{example}

\begin{example}
In this example we discuss computation of 
$\sM_2(\Gamma_0(2004),\Q)$, without explicitly writing
down the matrices, which are huge.    First we make
a list of the 
$$
4032 = (2^2 + 2) \cdot (3+1) \cdot (167 + 1)
$$
elements $(a,b)\in\P^1(\Z/2004\Z)$ using Algorithm~\ref{alg:p1list}.
This list looks like this:
$$
  x_0=(0, 1), (1, 0), (1, 1), (1, 2),
  \ldots,  (501, 7), (668, 1), (668, 3), (668, 5), x_{4032}=(1002, 1)
$$
For each of the symbols $x_i$, we consider the $S$ and $T$ relations.
Ignoring the redundant relations, we find $2016$ $S$-relations and
$1344$ $T$-relations.  It is simple to quotient out by the
$S$-relations, e.g., by identifying $x_i$ with $-x_i S = -x_j$ for some
$j$ (or setting $x_i=0$ if $x_i S = x_i$).  Once we've quotiented out
by the $S$ relations, we take the {\em image} of all of the $1344$ $T$
relations modulo the $S$-relations and quotient out by those
relations.  Because $S$ and $T$ do not commutate, we can not only
quotient out by $T$ relations $x_i + x_i T + x_i T^2 = 0$ where the
$x_i$ are the basis after quotienting out by the $S$ relations.
We find that the relation matrix has rank $3359$, so
$\sM_2(\Gamma_0(2004),\Q)$ has dimension $673$. 

If we instead compute the quotient $\sM_2(\Gamma_0(2004),\Q)^+$
of $\sM_2(\Gamma_0(2004),\Q)$ by the subspace of elements $x-\eta^*(x)$,
we include relations $x_i+x_iI=0$, where $I=\abcd{-1}{0}{0}{1}$.
There are now 2016 $S$ relations, 2024 $I$ relations,
and 1344 $T$ relations.  Again, it is almost trivial to quotient
out by the $S$ relations by identifying $x_i$ and $-x_i S$.
We then take the image of all $2024$ $I$ relations modulo the
$S$ relations, and again directly quotient out by the $I$-relations
by identifying $[x_i]$ with $-[x_iI]=-[x_j]$ for some $j$, where
by $[x_i]$ we mean the class of $x_i$ modulo the $S$ relations.
Finally, we quotient out by the $1344$ $T$ relations, which involves
sparse Gauss elimination on a matrix with ??? columns and $1344$ rows,
and at most $3$ nonzero entries per row.  Using Algorithm~\ref{},
we find ...   The dimension of $\sM_2(\Gamma_0(2004),\Q)^+$
is $331$.
\end{example}

\begin{algorithm}{Compute Presentation}
This is an algorithm to compute $\sM_k(\Gamma_0(N),\Q)$, which
only requires doing generic sparse linear algebra to deal
with the three term $T$-relations. 
\begin{enumerate}
\item Let $x_0,\ldots, x_n$ by a list of all Manin symbols.
\item Quotient out the $S$ relations by identifying $x_i$ with
      $-x_i S$, or by setting $x_i = 0$ if $x_i S = x_i$. 
       Let $[x_i]$ denote the
          class of $x_i$ after this quotienting process, so now
          every symbol $x_j$ can be written in terms of the 
          $[x_i]$, where the number of $[x_i]$ is about $n/2$.
\item Create a sparse matrix $A$ with $m$ columns, whose rows 
      encode the relations
$$
                 [x_i] + [x_iT] + [x_iT^2] = 0.
$$
          For example, there are about $n/3$ such rows
          (I'm unsure what the situation is for $k>2$).
          The number of nonzero entries per row is at most $3(k-1)$.
          Note that we must include rows for {\em all} $i$, since
          even if $[x_i] = [x_j]$, it need not be the case that
          $[x_i T] = [x_jT]$, since the matrices $S$ and $T$ do not commute.
          However, we have an a priori formula for the dimension
          of the quotient by all these relations, so we could omit
          many relations and just check that there are enough at the
          end---if there aren't, we add in more.

        \item Compute the reduced row echelon form of $A$ using the
          multi-modular (sparse) Gaussian elimination algorithm
          (Algorithm~\ref{alg:modech}).  For $k=2$, this is the
          echelon form of a matrix with size about $n/3 \times n/4$.

 \item Use what we have done above to read off a sparse matrix $R$
          that expresses each of the $n$ Manin symbols in terms of
          a basis of Manin symbols, modulo the relations. 
        \end{enumerate}
      \end{algorithm}

\begin{remark}
  There is rumored to be a ``geometric'' way to compute a presentation
  for $\sM_2(\Gamma_0(N))$ more directly, without resorting to general
  linear algebra techniques.  I am unaware of such a method having
  ever been published, but it was sketched to me independently by
  Georg Weber in 1999 and Robert Pollack in 2004. The computations we
  do after computing a presentation for $\sM_2(\Gamma_0(N))$ are
  usually significantly more time consuming than computation of a
  presentation in the first place, so it's unclear how useful this
  algorithm would be in practice.  (I have not heard of a method for
  directly obtaining a presentation for $\sM_k(\Gamma_0(N))$.)
\end{remark}


%\section{Trace and Inclusion Maps}\label{sec:degen}

% \begin{algorithm}{Increasing Level}
% Given [...] this algorithm computes the map
% $\alpha_t:\sM_k(N,\eps)\to \sM_k(N',\eps)$.
% \end{algorithm}

% \begin{algorithm}{Decreasing Level}
% Given [...] this algorithm computes the map
% $\beta_t:\sM_k(N',\eps)\to \sM_k(N,\eps)$.
% \end{algorithm}


%\section{Modular Symbols Over Finite Fields}\label{sec:msff}

% \section{The Intersection Pairing}
% \begin{algorithm}{The Intersection Pairing}
% This algorithm explicitly computes this intersection pairing 
% on $\H_1(X_0(N),\Z)$, presented in terms of cuspidal modular symbols.
% \end{algorithm}

% \edit{Applications?}

% \section{Open Problems}
% \begin{enumerate}
% \item What is the meaning of integral structure on higher-weight modular
% symbols?  
% \item Is it possible to compute $T_p$ in subexponential time?
% \end{enumerate}


\section{Applications}
\subsection{Later in this Book}
We now sketch some of the ways in which we will apply the
modular symbols algorithms of this chapter later in this book.

Cuspidal modular symbols are in Hecke-equivariant duality with
cuspidal modular forms, and as such we can compute modular forms by
computing systems of eigenvalues for the Hecke operators acting on
modular symbols.  By the Atkin-Lehner-Li theory of newforms (see,
e.g., \ref{thm:atkin-lehner}), we can construct $S_k(N,\eps)$ for
any~$N$, any $\eps$, and $k\geq 2$ using this method.  See
Chapter~\ref{ch:modform} for more details.

Once we can compute spaces of modular symbols, we move to computing
the corresponding modular forms.  In Section~\ref{sec:degen}, we
define inclusion and trace maps from modular symbols of one level $N$
to modular symbols of level a multiple or divisor of $N$.  Using these
we compute the quotient $V$ of the new subspace of cuspidal modular
symbols on which a ``star involution'' acts as $+1$.  The Hecke
operators act by diagonalizable commuting matrices on this space, and
computing the simultaneous systems of Hecke eigenvalues is equivalent
to computing corresponding newforms $\sum a_n q^n$.  In this way, we
obtain a list of {\em all} newforms (normalized eigenforms) in
$S_k(N,\eps)$ for any $N$, $\eps$, and $k\geq 2$.

In Chapter~\ref{sec:periods}, we compute with the period mapping from
modular symbols to $\C$ attached to a newform $f \in S_k(N,\eps)$.
When $k=2,\eps=1$ and~$f$ has rational Fourier coefficients, this
gives a method to compute the period lattice associated to a modular
elliptic curve attached to a newform (see
Section~\ref{sec:cremona_all}).  In general, computation of this map
is important when finding equations for modular $\Q$-curves, CM
curves, and curves with a given modular Jacobian.  It is also
important for computing special values of the $L$-function $L(f,s)$ at
integer points in the critical strip.

\subsection{Discussion of the Literature and Research}
Modular symbols were introduced by Birch \cite{birch:bsd} in
connection with computations in support of the Birch and
Swinnerton-Dyer conjecture.  Manin \cite{manin:parabolic} then made a
systematic study of weight~$2$ modular symbols and used them to prove
rationality results about special values of $L$-functions
(note that ``parabolic points'' in the title of Manin's paper means
``cusps'').  Merel's
paper \cite{merel:1585} builds on work of \v{S}okurov (mainly
\cite{sokurov:shimura}), which developed a higher-weight
generalization of Manin's work partly to understand rationality
properties of special values of modular $L$-functions (Shimura
simultaneously proved similar results via related cohomological
methods).  Cremona's book \cite{cremona:algs} discusses in detail how
to compute the space of weight~$2$ modular symbols for $\Gamma_0(N)$,
in connection with the problem of enumerating all elliptic curves of
given conductor, and his article \cite{cremona:gammaone} discusses the
$\Gamma_1(N)$ case and computation of modular symbols with character.

There have been several recent Ph.D. thesis about modular symbols.
Basmaji's thesis \cite{basmaji:thesis}, which is in German, contains a
tricks to efficiently compute Hecke operators $T_p$, with $p$ very
large, and also discusses how to compute spaces of half integral
weight modular forms building on what one can get from modular symbols
of integral weight. The author's Ph.D. thesis \cite{stein:phd}
contains two chapters about higher-weight modular symbols, and an
application to visibility of Shafarevich-Tate groups (see also
\cite{agashe:phd}).  Diderot's thesis \cite{diderot:thesis} is about
an attempt to study an analogue of modular symbols for weight~$1$.
Lemelin's thesis \cite{lemelin:dominic} discusses modular symbols for
quadratic imaginary fields in the context of $p$-adic analogues of the
Birch and Swinnerton-Dyer conjecture.  See also the survey paper
\cite{frey-muller}, which discusses computation with of weight~$2$
modular symbols in the context of computing with modular abelian
varieties.

There are analogues for modular symbols for groups besides
finite-index subgroups of $\SL_2(\Z)$, e.g., for groups of higher
degree, e.g., $\GL_3$.  There has also been 
work on computing Hilbert modular forms, e.g., by
Lassina Dembele \cite{dembele} (Hilbert modular forms
are like classical modular forms, but are functions on
a product of copies of $\h$, and $\SL_2(\Z)$ is replaced
by a group of matrices with entries in a totally real field).
I am {\em not} aware of any analogue of modular symbols for Siegel
modular forms (these are like classical modular forms, except the
upper half plane is replaced by a space of matrices).

Glenn Stevens (and recently Robert Pollack and Henri Darmon, see
\cite{darmon-pollack}) has been working for many years to develop an
analogue of modular symbols in a rigid analytic context, which should
be very helpful for questions about computing with over convergent
$p$-adic modular forms, or proving results about $p$-adic
$L$-functions.

Gabor Weise and Bas Edixhoven have been working on theory about
mod~$p$ modular symbols, and computation of weight~$1$ modular symbols
mod~$2$.


Finally we mention that Mazur uses the term ``modular symbol''
slightly differently in many of his papers to mean essentially what
we call the integral period mapping (see Section~\ref{sec:ratpm}).
This is a dual notion, which attaches a ``modular symbol'' to
a modular form or elliptic curve, and is really just an overloading
of the terminology.   See \cite{mtt} for an extensive discussion
of modular symbols from this point of view, where they are used to
construct $p$-adic $L$-functions.


\begin{exercises}
\item Compute $\sM_{3}(\Gamma_1(3))$ explicitly.  List
each Manin symbol, the relations they satisfy, compute
the quotient, etc.  Find the matrix of $T_2$.
(Check: The dimension of $\sM_{3}(\Gamma_1(3))$ is $2$, and
the characteristic polynomial of $T_2$ is $(x-3)(x+3)$.)
\item Prove that the pairing \ref{eqn:intpairing} is well defined.
\item 
\begin{enumerate}
\item Show that if $\eta = \abcd{-1}{0}{0}{1}$, then
$\eta \Gamma \eta = \Gamma$ for $\Gamma=\Gamma_0(N)$
and $\Gamma=\Gamma_1(N)$.  
\item (*) Give an example of a finite index
subgroup $\Gamma$ such that $\eta \Gamma \eta \neq \Gamma$.
\end{enumerate}

\item Suppose $M$ is an integer multiple of $N$.  Prove
that the natural map $(\Z/M\Z)^* \to (\Z/N\Z)^*$ is surjective.

\end{exercises}

% \chapter{Computing With Modular Symbols}
% \label{ch:modsymcomp}

\chapter{Using Modular Symbols to Compute 
Spaces of Modular Forms}\label{ch:modform}
\section{$q$-expansions of Newforms}\label{sec:qexps}
\edit{Atkin-Lehner Theory}
\begin{definition}[Newform]
A \defn{newform} is a cusp form~$f$ in the new
subspace of $S_k(N,\eps)$ that is a common eigenvector
for all Hecke operators $T_n$ and is normalized so
that $f = q + \cdots$.
\end{definition}

\begin{algorithm}{Systems of Cuspidal Eigenvalues}
  Given a weight~$k$ and a Dirichlet character~$\eps$ of
  modulus~$N$, this algorithm computes the system $a_p$ of
  eigenvalues of  each newform in $S_k(N,\eps)$.
\end{algorithm}

\edit{Mention the Schoof-Elkies-Atkin algorithm for
computing $a_p(f)$ in polynomial time when $f$ corresponds
to an elliptic curve.}

% \section{Basis of $q$-Expansions}
% \begin{algorithm}{Basis}
% Given an integer $N$, weight~$k$, a character $\eps$
% modulo~$N$, and an integer~$n$, this algorithm computes 
% a basis of $q$-expansions to precision $O(q^n)$ for 
% $S_k(N,\eps)$, with coefficients in $\Q(\eps)$.
% \end{algorithm}
% \edit{Give my newform algorithm.  Then mention Merel's
% algorithm from his universal Fourier expansions paper
% and explain that in practice it seems much slower,
% given a fast linear algebra package.  A formal analysis 
% would be interesting!}


\section{Congruences}
\begin{theorem}[Sturm]
Let $\lambda$ be a prime ideal in the ring of integers $\O_K$ 
of a number field~$K$.  Suppose $f\in M_k(\Gamma,\O_K)$
is a modular forms for a congruence subgroup $\Gamma$ and 
that $a_n(f)\con 0\pmod{\lambda}$ for 
$n\leq \frac{k}{12}[\SL_2(\Z):\Gamma]$.
Then $f\con 0\pmod{\lambda}$.
\end{theorem}

\begin{theorem}
Suppose $\Gamma$ is a congruence subgroup and let 
$$
  r=\left\lceil{} \frac{k}{12}\cdot [\SL_2(\Z):\Gamma] \right\rceil{}.
$$  
Then the Hecke algebra $\T_k(\Gamma) \subset \End(M_k(\Gamma))$
is generated as a $\Z$-module by the Hecke operators
$T_n$ for $n\leq r$.
\end{theorem}

% \begin{algorithm}{Discriminant of Hecke Algebra}
% Given a congruence subgroup~$\Gamma$ and a weight~$k$,
% this algorithm computes the discriminant of the Hecke
% algebra $\T_k(\Gamma) \subset \End(M_k(\Gamma))$.
% \end{algorithm}

% \subsection{The Calegari-Stein Conjectures}
% In this section we write $\T_k(N)$ for $\T_k(\Gamma_0(N))$.
% \edit{Define $\widetilde{\T_k(p)}$.}
% \begin{conjecture}
% Suppose $p\geq k-1$.  Then
%   $$
%   \ord_p([\widetilde{\T_k(p)} : \T_k(p)]) = 
%       \left\lfloor\frac{p}{12}\right\rfloor\cdot
%   \binom{m}{2} + a(p,m),
%   $$
%   where
%   $$
%   a(p,m) =
% \begin{cases}
%   0 & \text{if $p\con 1\pmod{12}$,}\\
%   3\cdot\ds\binom{\lceil \frac{m}{3}\rceil}{2} & \text{if $p\con 5\pmod{12}$,}
% \vspace{1ex}\\
%   2\cdot\ds\binom{\lceil \frac{m}{2}\rceil}{2} & \text{if $p\con 7\pmod{12}$,}
% \vspace{1ex}\\
%   a(5,m)+a(7,m) & \text{if $p\con 11\pmod{12}$.}
% \end{cases}
% $$
% \end{conjecture}
 

\chapter{Period Mappings Associated to Newforms}\label{sec:periods}
\section{Complex Period Mapping}
\begin{algorithm}{Complex Period Mapping}
Given a newform~$f$ in $S_k(N,\eps)$, this algorithm 
approximates the period map $M_k(N,\eps)\to \C$.
\end{algorithm}

\edit{Say something about bound on error, following the argument
that Andrei Jorza showed me.}

\section{Rational and Integral Period Mapping}\label{sec:ratpm}

\section{Special Values of $L$-Functions}
\begin{algorithm}{}
Given a newform~$f$ in $S_k(N,\eps)$
and an integer $j$ with $1\leq j \leq k-1$, this algorithm
approximates $L(f,j)$.
\end{algorithm}


\chapter{Modular Curves and Abelian Varieties}\label{ch:modabvar}
\section{Modular Curves}
 -- models for modular curves

 -- Baker-Poonen-Gonzalez  

\section{Modular Abelian Varieties}


\edit{Say something about computing $L(f,s)$ for arbitrary~$s$.}
\section{The Birch and Swinnerton-Dyer Conjecture}
\begin{algorithm}{The BSD Ratio}
Given a newform~$f$ in $S_2(\Gamma)$, with $\Gamma=\Gamma_0(N)$ or $\Gamma_1(N)$, 
vthis algorithm computes the rational number $L(A_f,1)/\Omega_{A_f}$.
\end{algorithm}

\section{How Cremona Computes all Elliptic Curves of Conductor~$N$}
\label{sec:cremona_all}


\chapter{Application: Serre's Conjecture}\label{ch:serre}

\section{Statement of the Conjecture}


\section{Determining Irreducibility}
\begin{algorithm}{Irreducible}
Given a newform $f\in S_k(N,\eps)$ and a maximal ideal $\lambda$ of $\O_f$,
this algorithm determines whether or not the mod~$\lambda$ representation
$\rhobar_{f,\lambda}$ is irreducible.
\end{algorithm}

\section{Computing the Serre Invariants}
\begin{algorithm}{Serre Weight}
Given a newform~$f$ and a maximal ideal~$\lambda$
of $\O_f$, this algorithm computes the Serre weight
of $\rho_{f,\lambda}$.
\end{algorithm}

\begin{algorithm}{Serre Level}
Given a newform~$f$ and a maximal ideal~$\lambda$
of $\O_f$, this algorithm computes the Serre level
of $\rho_{f,\lambda}$.
\end{algorithm}

\section{Finding the Newforms that Give Rise to a Representation}

\begin{algorithm}{Newforms Attached to a Representation}
Given a representation $\rhobar_{f,\lambda}$ and a space $S_k(N,\eps)$,
this algorithm finds all representations $\rhobar_{g,\mu}$
that are isomorphic to $f$, with $g\in S_k(N,\eps)$.
\end{algorithm}

% \chapter{The Method of Graphs}

% \begin{algorithm}{Method of Graphs}
%   This algorithm computes the action of the Hecke operators $T_2$,
%   $T_3$, $T_5$, and $T_7$ on the free abelian group on supersingular
%   $j$-invariants in $\F_{p^2}$.
% \end{algorithm}

% \section{Components Groups and Tamagawa Numbers 
%          of Modular Abelian Varieties}

% \section{Ideal Classes in Quaternion Algebras and Theta Series}

% \section{Open Problems}



\chapter{Software for Computing With Modular Forms}\label{ch:manin}

\section{MAGMA}

\section{Python / MANIN}

MANIN is a package for computing with modular forms that the author is
developing using the computer languages Python and C++.  
This chapter is about the structure and implementation of MANIN, and
its relation with the algorithms described elsewhere in this book.

MANIN is and will remain freely available, and all its components are
open source.  It's initial purpose is to provide a package for doing
computations with modular forms whose source code is easy to read,
modify, and understand.  It is usable from Python, which is an
extremely mature and well-designed modern language.  Being completely
free and open source makes it more suitable for citation in research
papers.  Speed is important but is {\em currently} of secondary
importance (the author's MAGMA packages are much faster in many
cases).

We begin with a sample MANIN session.
%session
\begin{verbatim}
>>> M = ModularSymbols(11)
>>> M.basis()
[(1,0), (1,8), (1,9)]
>>> t2 = M.hecke_operator(2); 
>>> t2
  [ 3,  0,  0;
    0, -2,  0;
   -1,  0, -2]
>>> charpoly(t2)
x^3 + x^2 - 8*x - 12
>>> t2.charpoly()             # call in more ``object-oriented'' way.
x^3 + x^2 - 8*x - 12
\end{verbatim}

\section{Cremona's mwrank}

\section{HECKE C++ Library}

\section{PARI/GP Package}


{\small
\chapter*{Appendix: GNU Free Documentation License}
\addcontentsline{toc}{chapter}{\numberline{}Appendix: GNU Free Documentation License}
 \begin{center}
       Version 1.2, November 2002

 Copyright \copyright 2000,2001,2002  Free Software Foundation, Inc.
 
     59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  
 
 Everyone is permitted to copy and distribute verbatim copies
 of this license document, but changing it is not allowed.
\end{center}


\begin{center}
{\bf\large Preamble}
\end{center}

The purpose of this License is to make a manual, textbook, or other
functional and useful document ``free'' in the sense of freedom: to
assure everyone the effective freedom to copy and redistribute it,
with or without modifying it, either commercially or noncommercially.
Secondarily, this License preserves for the author and publisher a way
to get credit for their work, while not being considered responsible
for modifications made by others.

This License is a kind of ``copyleft", which means that derivative
works of the document must themselves be free in the same sense.  It
complements the GNU General Public License, which is a copyleft
license designed for free software.

We have designed this License in order to use it for manuals for free
software, because free software needs free documentation: a free
program should come with manuals providing the same freedoms that the
software does.  But this License is not limited to software manuals;
it can be used for any textual work, regardless of subject matter or
whether it is published as a printed book.  We recommend this License
principally for works whose purpose is instruction or reference.


\begin{center}
{\Large\bf 1. APPLICABILITY AND DEFINITIONS}
%\addcontentsline{toc}{section}{1. APPLICABILITY AND DEFINITIONS}
\end{center}

This License applies to any manual or other work, in any medium, that
contains a notice placed by the copyright holder saying it can be
distributed under the terms of this License.  Such a notice grants a
world-wide, royalty-free license, unlimited in duration, to use that
work under the conditions stated herein.  The \textbf{``Document''}, below,
refers to any such manual or work.  Any member of the public is a
licensee, and is addressed as \textbf{``you''}.  You accept the license if you
copy, modify or distribute the work in a way requiring permission
under copyright law.

A \textbf{``Modified Version''} of the Document means any work containing the
Document or a portion of it, either copied verbatim, or with
modifications and/or translated into another language.

A \textbf{``Secondary Section''} is a named appendix or a front-matter section of
the Document that deals exclusively with the relationship of the
publishers or authors of the Document to the Document's overall subject
(or to related matters) and contains nothing that could fall directly
within that overall subject.  (Thus, if the Document is in part a
textbook of mathematics, a Secondary Section may not explain any
mathematics.)  The relationship could be a matter of historical
connection with the subject or with related matters, or of legal,
commercial, philosophical, ethical or political position regarding
them.

The \textbf{``Invariant Sections''} are certain Secondary Sections whose titles
are designated, as being those of Invariant Sections, in the notice
that says that the Document is released under this License.  If a
section does not fit the above definition of Secondary then it is not
allowed to be designated as Invariant.  The Document may contain zero
Invariant Sections.  If the Document does not identify any Invariant
Sections then there are none.

The \textbf{``Cover Texts''} are certain short passages of text that are listed,
as Front-Cover Texts or Back-Cover Texts, in the notice that says that
the Document is released under this License.  A Front-Cover Text may
be at most 5 words, and a Back-Cover Text may be at most 25 words.

A \textbf{``Transparent''} copy of the Document means a machine-readable copy,
represented in a format whose specification is available to the
general public, that is suitable for revising the document
straightforwardly with generic text editors or (for images composed of
pixels) generic paint programs or (for drawings) some widely available
vdrawing editor, and that is suitable for input to text formatters or
for automatic translation to a variety of formats suitable for input
to text formatters.  A copy made in an otherwise Transparent file
format whose markup, or absence of markup, has been arranged to thwart
or discourage subsequent modification by readers is not Transparent.
An image format is not Transparent if used for any substantial amount
of text.  A copy that is not ``Transparent'' is called \textbf{``Opaque''}.

Examples of suitable formats for Transparent copies include plain
ASCII without markup, Texinfo input format, LaTeX input format, SGML
or XML using a publicly available DTD, and standard-conforming simple
HTML, PostScript or PDF designed for human modification.  Examples of
transparent image formats include PNG, XCF and JPG.  Opaque formats
include proprietary formats that can be read and edited only by
proprietary word processors, SGML or XML for which the DTD and/or
processing tools are not generally available, and the
machine-generated HTML, PostScript or PDF produced by some word
processors for output purposes only.

The \textbf{``Title Page''} means, for a printed book, the title page itself,
plus such following pages as are needed to hold, legibly, the material
this License requires to appear in the title page.  For works in
formats which do not have any title page as such, ``Title Page'' means
the text near the most prominent appearance of the work's title,
preceding the beginning of the body of the text.

A section \textbf{``Entitled XYZ''} means a named subunit of the Document whose
title either is precisely XYZ or contains XYZ in parentheses following
text that translates XYZ in another language.  (Here XYZ stands for a
specific section name mentioned below, such as \textbf{``Acknowledgements''},
\textbf{``Dedications''}, \textbf{``Endorsements''}, or \textbf{``History''}.)  
To \textbf{``Preserve the Title''}
of such a section when you modify the Document means that it remains a
section ``Entitled XYZ'' according to this definition.

The Document may include Warranty Disclaimers next to the notice which
states that this License applies to the Document.  These Warranty
Disclaimers are considered to be included by reference in this
License, but only as regards disclaiming warranties: any other
implication that these Warranty Disclaimers may have is void and has
no effect on the meaning of this License.


\begin{center}
{\Large\bf 2. VERBATIM COPYING}
%\addcontentsline{toc}{section}{2. VERBATIM COPYING}
\end{center}

You may copy and distribute the Document in any medium, either
commercially or noncommercially, provided that this License, the
copyright notices, and the license notice saying this License applies
to the Document are reproduced in all copies, and that you add no other
conditions whatsoever to those of this License.  You may not use
technical measures to obstruct or control the reading or further
copying of the copies you make or distribute.  However, you may accept
compensation in exchange for copies.  If you distribute a large enough
number of copies you must also follow the conditions in section 3.

You may also lend copies, under the same conditions stated above, and
you may publicly display copies.


\begin{center}
{\Large\bf 3. COPYING IN QUANTITY}
%\addcontentsline{toc}{section}{3. COPYING IN QUANTITY}
\end{center}


If you publish printed copies (or copies in media that commonly have
printed covers) of the Document, numbering more than 100, and the
Document's license notice requires Cover Texts, you must enclose the
copies in covers that carry, clearly and legibly, all these Cover
Texts: Front-Cover Texts on the front cover, and Back-Cover Texts on
the back cover.  Both covers must also clearly and legibly identify
you as the publisher of these copies.  The front cover must present
the full title with all words of the title equally prominent and
visible.  You may add other material on the covers in addition.
Copying with changes limited to the covers, as long as they preserve
vthe title of the Document and satisfy these conditions, can be treated
as verbatim copying in other respects.

If the required texts for either cover are too voluminous to fit
legibly, you should put the first ones listed (as many as fit
reasonably) on the actual cover, and continue the rest onto adjacent
pages.

If you publish or distribute Opaque copies of the Document numbering
more than 100, you must either include a machine-readable Transparent
copy along with each Opaque copy, or state in or with each Opaque copy
a computer-network location from which the general network-using
public has access to download using public-standard network protocols
a complete Transparent copy of the Document, free of added material.
If you use the latter option, you must take reasonably prudent steps,
when you begin distribution of Opaque copies in quantity, to ensure
that this Transparent copy will remain thus accessible at the stated
location until at least one year after the last time you distribute an
Opaque copy (directly or through your agents or retailers) of that
edition to the public.

It is requested, but not required, that you contact the authors of the
Document well before redistributing any large number of copies, to give
them a chance to provide you with an updated version of the Document.


\begin{center}
{\Large\bf 4. MODIFICATIONS}
%\addcontentsline{toc}{section}{4. MODIFICATIONS}
\end{center}

You may copy and distribute a Modified Version of the Document under
the conditions of sections 2 and 3 above, provided that you release
the Modified Version under precisely this License, with the Modified
Version filling the role of the Document, thus licensing distribution
and modification of the Modified Version to whoever possesses a copy
of it.  In addition, you must do these things in the Modified Version:

\begin{itemize}
\item[A.] 
   Use in the Title Page (and on the covers, if any) a title distinct
   from that of the Document, and from those of previous versions
   (which should, if there were any, be listed in the History section
   of the Document).  You may use the same title as a previous version
   if the original publisher of that version gives permission.
   
\item[B.]
   List on the Title Page, as authors, one or more persons or entities
   responsible for authorship of the modifications in the Modified
   Version, together with at least five of the principal authors of the
   Document (all of its principal authors, if it has fewer than five),
   unless they release you from this requirement.
   
\item[C.]
   State on the Title page the name of the publisher of the
   Modified Version, as the publisher.
   
\item[D.]
   Preserve all the copyright notices of the Document.
   
\item[E.]
   Add an appropriate copyright notice for your modifications
   adjacent to the other copyright notices.
   
\item[F.]
   Include, immediately after the copyright notices, a license notice
   giving the public permission to use the Modified Version under the
   terms of this License, in the form shown in the Addendum below.
   
\item[G.]
   Preserve in that license notice the full lists of Invariant Sections
   and required Cover Texts given in the Document's license notice.
   
\item[H.]
   Include an unaltered copy of this License.
   
\item[I.]
   Preserve the section Entitled ``History", Preserve its Title, and add
   to it an item stating at least the title, year, new authors, and
   publisher of the Modified Version as given on the Title Page.  If
v   there is no section Entitled ``History'' in the Document, create one
   stating the title, year, authors, and publisher of the Document as
   given on its Title Page, then add an item describing the Modified
   Version as stated in the previous sentence.
   
\item[J.]
   Preserve the network location, if any, given in the Document for
   public access to a Transparent copy of the Document, and likewise
   the network locations given in the Document for previous versions
   it was based on.  These may be placed in the ``History'' section.
   You may omit a network location for a work that was published at
   least four years before the Document itself, or if the original
   publisher of the version it refers to gives permission.
   
\item[K.]
   For any section Entitled ``Acknowledgements'' or ``Dedications",
   Preserve the Title of the section, and preserve in the section all
   the substance and tone of each of the contributor acknowledgements
   and/or dedications given therein.
   
\item[L.]
   Preserve all the Invariant Sections of the Document,
   unaltered in their text and in their titles.  Section numbers
   or the equivalent are not considered part of the section titles.
   
\item[M.]
   Delete any section Entitled ``Endorsements".  Such a section
   may not be included in the Modified Version.
   
\item[N.]
   Do not retitle any existing section to be Entitled ``Endorsements"
   or to conflict in title with any Invariant Section.
   
\item[O.]
   Preserve any Warranty Disclaimers.
\end{itemize}

If the Modified Version includes new front-matter sections or
appendices that qualify as Secondary Sections and contain no material
copied from the Document, you may at your option designate some or all
of these sections as invariant.  To do this, add their titles to the
list of Invariant Sections in the Modified Version's license notice.
These titles must be distinct from any other section titles.

You may add a section Entitled ``Endorsements", provided it contains
nothing but endorsements of your Modified Version by various
parties--for example, statements of peer review or that the text has
been approved by an organization as the authoritative definition of a
standard.

You may add a passage of up to five words as a Front-Cover Text, and a
passage of up to 25 words as a Back-Cover Text, to the end of the list
of Cover Texts in the Modified Version.  Only one passage of
Front-Cover Text and one of Back-Cover Text may be added by (or
through arrangements made by) any one entity.  If the Document already
includes a cover text for the same cover, previously added by you or
by arrangement made by the same entity you are acting on behalf of,
you may not add another; but you may replace the old one, on explicit
permission from the previous publisher that added the old one.

The author(s) and publisher(s) of the Document do not by this License
give permission to use their names for publicity for or to assert or
imply endorsement of any Modified Version.


\begin{center}
{\Large\bf 5. COMBINING DOCUMENTS}
%\addcontentsline{toc}{section}{5. COMBINING DOCUMENTS}
\end{center}


You may combine the Document with other documents released under this
License, under the terms defined in section 4 above for modified
versions, provided that you include in the combination all of the
Invariant Sections of all of the original documents, unmodified, and
list them all as Invariant Sections of your combined work in its
license notice, and that you preserve all their Warranty Disclaimers.

The combined work need only contain one copy of this License, and
multiple identical Invariant Sections may be replaced with a single
copy.  If there are multiple Invariant Sections with the same name but
different contents, make the title of each such section unique by
adding at the end of it, in parentheses, the name of the original
author or publisher of that section if known, or else a unique number.
Make the same adjustment to the section titles in the list of
Invariant Sections in the license notice of the combined work.

In the combination, you must combine any sections Entitled ``History"
in the various original documents, forming one section Entitled
"History"; likewise combine any sections Entitled ``Acknowledgements",
and any sections Entitled ``Dedications".  You must delete all sections
Entitled ``Endorsements".

\begin{center}
{\Large\bf 6. COLLECTIONS OF DOCUMENTS}
%\addcontentsline{toc}{section}{6. COLLECTIONS OF DOCUMENTS}
\end{center}

You may make a collection consisting of the Document and other documents
released under this License, and replace the individual copies of this
License in the various documents with a single copy that is included in
the collection, provided that you follow the rules of this License for
verbatim copying of each of the documents in all other respects.

You may extract a single document from such a collection, and distribute
it individually under this License, provided you insert a copy of this
License into the extracted document, and follow this License in all
other respects regarding verbatim copying of that document.


\begin{center}
{\Large\bf 7. AGGREGATION WITH INDEPENDENT WORKS}
%\addcontentsline{toc}{section}{7. AGGREGATION WITH INDEPENDENT WORKS}
\end{center}


A compilation of the Document or its derivatives with other separate
and independent documents or works, in or on a volume of a storage or
distribution medium, is called an ``aggregate'' if the copyright
resulting from the compilation is not used to limit the legal rights
of the compilation's users beyond what the individual works permit.
When the Document is included in an aggregate, this License does not
apply to the other works in the aggregate which are not themselves
derivative works of the Document.

If the Cover Text requirement of section 3 is applicable to these
copies of the Document, then if the Document is less than one half of
the entire aggregate, the Document's Cover Texts may be placed on
covers that bracket the Document within the aggregate, or the
electronic equivalent of covers if the Document is in electronic form.
Otherwise they must appear on printed covers that bracket the whole
aggregate.


\begin{center}
{\Large\bf 8. TRANSLATION}
%\addcontentsline{toc}{section}{8. TRANSLATION}
\end{center}


Translation is considered a kind of modification, so you may
distribute translations of the Document under the terms of section 4.
Replacing Invariant Sections with translations requires special
permission from their copyright holders, but you may include
translations of some or all Invariant Sections in addition to the
original versions of these Invariant Sections.  You may include a
translation of this License, and all the license notices in the
Document, and any Warranty Disclaimers, provided that you also include
the original English version of this License and the original versions
of those notices and disclaimers.  In case of a disagreement between
the translation and the original version of this License or a notice
or disclaimer, the original version will prevail.

If a section in the Document is Entitled ``Acknowledgements",
"Dedications", or ``History", the requirement (section 4) to Preserve
its Title (section 1) will typically require changing the actual
title.


\begin{center}
{\Large\bf 9. TERMINATION}
%\addcontentsline{toc}{section}{9. TERMINATION}
\end{center}


You may not copy, modify, sublicense, or distribute the Document except
as expressly provided for under this License.  Any other attempt to
copy, modify, sublicense or distribute the Document is void, and will
automatically terminate your rights under this License.  However,
parties who have received copies, or rights, from you under this
License will not have their licenses terminated so long as such
parties remain in full compliance.


\begin{center}
{\Large\bf 10. FUTURE REVISIONS OF THIS LICENSE}
%\addcontentsline{toc}{section}{10. FUTURE REVISIONS OF THIS LICENSE}
\end{center}


The Free Software Foundation may publish new, revised versions
of the GNU Free Documentation License from time to time.  Such new
versions will be similar in spirit to the present version, but may
differ in detail to address new problems or concerns.  See
http://www.gnu.org/copyleft/.

Each version of the License is given a distinguishing version number.
If the Document specifies that a particular numbered version of this
License ``or any later version'' applies to it, you have the option of
following the terms and conditions either of that specified version or
of any later version that has been published (not as a draft) by the
Free Software Foundation.  If the Document does not specify a version
number of this License, you may choose any version ever published (not
as a draft) by the Free Software Foundation.
}

\bibliography{biblio}

\printindex


\end{document}
