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

\usepackage{index}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{amsthm}
\usepackage[all]{xy}
\usepackage{sage}

\newcommand{\code}[1]{{\tt #1}}

\usepackage{xspace}  % to allow for text macros that don't eat space 
\newcommand{\SAGE}{{\sf SAGE}\xspace}
\newcommand{\sage}{\SAGE}


%\newcommand{\comment}[1]{}

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

%\newcommand{\edit}[1]{{\bf [[Todo: #1]]}}
\newcommand{\edit}[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]{{\bf [[TODO: #1]]}}
\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}{=}
\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{warning}[theorem]{Warning}
\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}\sf
}%
{\end{alg}}
\newenvironment{steps}%
{\begin{itemize}\setlength{\itemsep}{0.1ex}}{\end{itemize}}

\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 that
started as a series of notes for a graduate course at Harvard
University in 2004.  This book is meant to answer the question ``How
do {\em you} compute spaces of modular forms'', by both providing a
clear description of the specific algorithms that are used and
explaining how to apply them using \SAGE \cite{sage}.

I have spent many years trying to find good practical 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
as part of \SAGE.  Much of this work has involved turning formulas and
constructions burried in obscure research papers into precise
computational recipes, then testing these in many cases and
eliminating subtle inaccuracies (published theorems sometimes contain
small mistakes that appear magnified when implemented and run on a
computer).  The goal of this book is to explain some of 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.  The field is
not yet mature, and there are 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.  

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 (in practice!) 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,
$p$-adic modular forms, and modular abelian varieties, all of which
are topics for another book.

The reader is not assumed to have prior exposure to modular forms, but
should be familiar with abstract algebra, basic algebraic number
theory, Riemann surfaces, and complex analysis.


%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}.  Noam Elkies made many
remarks about chapters 1 and 2.  The students in the Harvard course
made helpful remark; in particular, Abhinav Kumar made observations
about computing widths of cusps, Thomas James Barnet-Lamb about how to
represent Dirichlet characters, and Tseno V. Tselkov, Jennifer
Balakrishnan and Jesse Kass made other remarks.

Parts of Chapter~\ref{ch:modform} follow
\cite[Ch.~VII]{serre:arithmetic} closely, though we adjust the
notation, definitions, and order of presentation to be consistent with
the rest of this book. (For example, Serre writes $2k$ for the weight
instead of~$k$.)

\vspace{2ex}
\noindent{\bf Grant Information.}
This material is based upon work supported by the National Science
Foundation under Grant No. 0400386.

%\section*{TODO}
%\begin{enumerate}
%\item Mention Denis Charles's work on analyzing algorithms,
%computing, etc.
%\end{enumerate}








%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%
%   NEW CHAPTER 
%
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%







\chapter{Modular Forms}\label{ch:modform}

\edit{Write an introduction.}

\section{Basic Definitions}
Modular forms are certain types of functions on
the {\em complex upper half plane}
$$
  \h = \{z \in \C : \Im(z) > 0\}.
$$
The group
$$
 \SL_2(\R) = 
\left\{ \mtwo{a}{b}{c}{d} : ad-bc=1,\text{ and } a,b,c,d\in\R\right\}
$$
acts on $\h$ via linear fractional transformations,
as follows.
If
$\gamma = \abcd{a}{b}{c}{d} \in \SL_2(\R)$ and $z\in\h$,
then (see \exref{ch:modform}{ex:upperhalfpres})
\begin{equation}\label{eqn:lft}
  \gamma(z) = \frac{az + b}{cz + d} \in \h.
\end{equation}

\begin{definition}[Modular Group]
The \defn{modular group} is 
the subgroup $\SL_2(\Z)$ of $\SL_2(\R)$ of matrices
with integer entries.  Thus $\SL_2(\Z)$ is the group of
all matrices $\abcd{a}{b}{c}{d}$ with $a,b,c,d\in\Z$
and $ad-bc=1$.
\end{definition}
For example, the
matrices 
\begin{equation}\label{eqn:ST}
S=\mtwo{0}{-1}{1}{\hfill 0}
\qquad\text{and} \qquad
T=\mtwo{1}{1}{0}{1}
\end{equation} 
are both elements of $\SL_2(\Z)$;
the matrix $S$ defines the function $z\mapsto -1/z$,
and~$T$ the function $z\mapsto z+1$.
\begin{theorem}
The group $\SL_2(\Z)$ is generated by $S$ and $T$.
\end{theorem}
\begin{proof}
  See e.g. \cite[\S{}VII.1]{serre:arithmetic}, which uses the
  fundamental domain~$\cF$ consisting of all elements of $\h$ that
  satisfy $|z|\geq 1$ and $\Re(z)\leq 1/2$.
\end{proof}

%begin_sage
In \sage we compute the group $\SL_2(\Z)$ and its generators as follows:
\begin{verbatim}
sage: G = SL(2,Z)
sage: print G
The modular group SL(2,Z)
sage: S, T = G.gens()
sage: S
[ 0 -1]
[ 1  0]
sage: T
[1 1]
[0 1]
\end{verbatim}
%end_sage

\begin{definition}[Holomorphic and Meromorphic]
  Let $R$ be an open subset of $\C$.  A function $f:R\to \C$ is
  \defn{holomorphic} if $f$ is complex differentiable at every point
  $z\in R$, i.e., for each $z\in R$ the limit $\lim_{h\to 0}
  (f(z+h)-f(z))/h$ exists, where~$h$ may approach~$0$ along any path.
  The function $f: R\to\C\cup \{\infty\}$ is \defn{meromorphic}
    if it is holomorphic except (possibly) at a discrete set $S$ of
    points in~$ R$, and at each $\alpha\in S$ there is a positive
    integer $n$ such that $(z-\alpha)^n f(z)$ is holomorphic at
    $\alpha$.
\end{definition}

The function $f(z) = e^z$ is a holomorphic function on~$\h$
(in fact on all of $\C$).  The function $1/(z-i)$ is meromorphic
on~$\h$, and fails to be analytic at~$i$.

Modular forms are holomorphic functions on $\h$ that transform in a
particular way under a subgroup of $\SL_2(\Z)$.  Before definining
general modular forms, we define modular forms of level $1$.

\section{Modular Forms of Level 1}\label{sec:modform1}


\begin{definition}[Weakly Modular Function]
A \defn{weakly modular function} of weight $k\in\Z$ is a meromorphic
function $f$ on $\h$ such that 
 for all $\gamma=\abcd{a}{b}{c}{d}\in\SL_2(\Z)$ and all $z\in\h$
we have
\begin{equation}\label{eqn:modfunc}
   f(z) = (cz+d)^{-k} f(\gamma(z)).
 \end{equation}
\end{definition}
The constant functions are weakly modular of weight $0$.
There are no nonzero weakly modular functions of odd weight
(see \exref{ch:modform}{ex:nomodformodd}), and it is by
no means obvious that there are any weakly modular functions
of even weight $k\geq 2$.
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$ 
(see \exref{ch:modform}{ex:wmfprod}),
so once we find some nonconstant weakly modular functions, we'll
find many of them.

When $k$ is even (\ref{eqn:modfunc}) has a possibly 
more conceptual interpretation; namely
 (\ref{eqn:modfunc}) is the same as
$$
  f(\gamma(z))d(\gamma(z))^{k/2} = f(z)dz^{k/2}.
$$
Thus (\ref{eqn:modfunc}) simply says that 
the weight~$k$ ``differential form'' $f(z)dz^{k/2}$
is fixed under the action of every element of
$\SL_2(\Z)$.  


Since $\SL_2(\Z)$ is generated by the matrices $S$ and $T$
of (\ref{eqn:ST}), to show
that a meromorphic function~$f$ on $\h$ is a 
weakly modular function all we have to do is show
that for all $z\in\h$ we have 
\begin{equation}\label{eqn:modfunc2}
  f(z+1) = f(z) \qquad\text{and}\qquad f(-1/z) = z^k f(z).
\end{equation}

Suppose that $f$ is a weakly modular function of some weight~$k$.
Then $f$ might have a \defn{Fourier expansion}, which we try to obtain
as follows.  Let $q=q(z)=e^{2\pi i z}$, which we view as a holomorphic
function $\C\union{\infty} \to D$, where $D$ is the closed unit disk.
Let $D'$ be the punctured unit disk, i.e., $D$ with the origin
removed, and note that $q:\C \to D'$.  By (\ref{eqn:modfunc2}) we have
$f(z+1)=f(z)$, so there is a set-theoretic map $F:D' \to \C$ such that
for every $z\in\h$ we have $F(q(z)) = f(z)$.  This function $F$ is
thus a complex-valued function on the open unit disk.  It may or
may not be well behaved at $0$.

Suppose that $F$ is well-behaved at $0$, namely that for some
$m\in\Z$ and all $q$ in a neighborhood of $0$ we have the equality
$$
 F(q) = \sum_{n=m}^{\infty} a_n q^n.
$$
If this is the case, we say that~$f$ is 
\defn{meromorphic at $\infty$}.  If, moreover,
$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$ (and level $1$) 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 for all $z\in \h$, 
\begin{equation}\label{eqn:qexp1}
f(z) = \sum_{n=0}^{\infty} a_n q^n = \sum_{n=0}^{\infty} a_n e^{2 \pi i n z}.
\end{equation}
\begin{proposition}
The above series converges for all $z\in\h$.
\end{proposition}
\begin{proof}n
The function $f(q)$ is holomorphic on $D$, so 
its Taylor series converges absolutely
in $D$.   See also \cite[\S{}VII.4]{serre:arithmetic}
for an explicit bound on the $|a_n|$.
\end{proof}
We set $f(\infty)=a_0$, since $q^{2\pi i z}\to 0$ as 
$z\to i \infty$, and the value of $f$ at $\infty$
should be the value of $F$ at $0$, which is $a_0$
from the power series. 

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


\section{Modular Forms of Any Level}\label{sec:modformN}
We next define spaces of modular forms of arbitrary level.  For
example, when $k=2$ these are closely related to elliptic curves and
abelian varieties.

A \defn{congruence subgroup} of
$\SL_2(\Z)$ is any subgroup that contains
$$\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$.
For example, 
$$
  \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\}
$$
and
$$
  \Gamma_0(N) = \left\{ \mtwo{a}{b}{c}{d} \in \SL_2(\Z) : 
                    \mtwo{a}{b}{c}{d}\con \mtwo{*}{*}{0}{*}\pmod{N}
                \right\}
$$
are congruence subgroups of level~$N$.

Let $k$ be an integer.
Define the \defn{weight~$k$ right action} of $\GL_2(\Q)$ on 
the set of functions~$f:\h\to\C$  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)).
$$
\begin{proposition}
The action $f\mapsto f|[\gamma]_k$ is a right action
of $\GL_2(\Z)$ on the set of all functions $f:\h\to\C$; in
particular, 
$$
  f|[\gamma_1\gamma_2]_k = (f|[\gamma_1]_k)|[\gamma_2]_k,
$$
\end{proposition}
\begin{proof}
See \exref{ch:modform}{ex:grpact}.
\end{proof}

\begin{definition}[Weakly Modular Function]
A \defn{weakly modular function} of weight $k$ for a
congruence subgroup $\Gamma$ is a meromorphic
function $f :\h \to \C$ such that 
$f|[\gamma]_k = f$ for all $\gamma \in \Gamma$.
\end{definition}

A central object in the theory of modular forms (and modular symbols)
is the set of all {\em cusps}
$$
  \P^1(\Q) = \Q \union \{\infty\}.
$$
The set of cusps for a congruence subgroup $\Gamma$ is the set
$C(\Gamma)$ of orbits of $\P^1(\Q)$ under the action of $\Gamma$.  (We
will often identify elements of $C(\Gamma)$ with a representative
element from the orbit.)  For example, if $\Gamma=\SL_2(\Z)$ there is
exactly one orbit.
\begin{lemma}\label{lem:sl2ztrans}
  For any cusps $\alpha, \beta\in\P^1(\Q)$ there exists
  $\gamma\in\SL_2(\Z)$ such that $\gamma(\alpha) = \beta$.
\end{lemma}
\begin{proof}
This is \exref{ch:modform}{ex:sl2ztrans}.
\end{proof}

\begin{proposition}
For any congruence subgroup $\Gamma$, the set $C(\Gamma)$
of cusps is finite. 
\end{proposition}

In order to define modular forms for general congruence subgroups we
need to make sense of what it means for a function to be holomorphic
on the \defn{extended upper halfplane}
$$
  \h^* = \h\union \P^1(\Q).
$$
In Section~\ref{sec:modform1} we considered a weakly modular
function~$f$ on $\SL_2(\Z)$
to be holomorphic at~$\infty$ if its $q$-expansion 
is of the form
$\sum_{n=0}^{\infty} a_n q^n$.

In order to make sense of holomorphicity of a weakly modular
function $f$  for $\Gamma$ at any $\alpha\in\Q$,
we first prove a lemma.
\begin{lemma}
If $f :\h\to\C$ is a weakly modular function of weight $k$
for a congruence subgroup $\Gamma$, and $\delta \in \SL_2(\Z)$,
then $f|[\delta]_k$ is a weakly modular function for
$\delta^{-1}\Gamma \delta$.
\end{lemma}
\begin{proof}
If $s = \delta^{-1} \gamma\delta \in \delta^{-1}\Gamma \delta$,
then 
$$ 
   (f|[\delta]_k)|[s]_k = f|[\delta s]_k
          = f|[\delta \delta^{-1}\gamma\delta]_k
          = f|[\gamma\delta]_k = f|[\delta]_k.
$$
\end{proof}

Fix a weight~$k$ weakly modular function~$f$ for some congruence
subgroup~$\Gamma$, and suppose $\alpha \in \Q$.  In
Section~\ref{sec:modform1} we constructed the $q$-expansion of $f$ by
using that $f(z) = f(z+1)$, which held since
$T=\mtwo{1}{1}{0}{1}\in\SL_2(\Z)$.  Unfortunately, there are
congruence subgroups $\Gamma$ such that $T\not\in\Gamma$.  Moreover,
even if we are interested only in modular forms for $\Gamma_1(N)$,
where we have $T\in\Gamma_1(N)$ for all~$N$, we have to consider
$q$-expansions at infinity for modular forms on groups $\delta^{-1}
\Gamma_1(N)\delta$, and these need not contain~$T$.  Fortunately, $T^N
= \mtwo{1}{N}{0}{1} \in \Gamma(N)$, so a congruence subgroup of level
$N$ contains $T^N$.  Thus for our $f$ we have $f(z+h) = f(z)$ for some
positive integer $h$, and again when~$f$ is meromorphic at infinity we
obtain a Fourier expansion
\begin{equation}\label{eqn:qser}
   f(z) = \sum_{n=m}^{\infty} a_n q^{n/N},
\end{equation}
but instead it is in powers of the function $q^{1/N} = e^{2 \pi i z
  /N}$.  We say that $f$ is holomorphic at $\infty$ if in
(\ref{eqn:qser}) we have $m\geq 0$.  

What about the other cusps $\alpha\in\P^1(\Q)$? By
Lemma~\ref{lem:sl2ztrans} there is a $\gamma\in\SL_2(\Z)$ such that
$\gamma(\infty)=\alpha$.  We declare~$f$ to be \defn{holomorphic at
  the cusp~$\alpha$} if the weakly modular function $f|[\gamma]_k$ is
holomorphic at $\infty$.

\begin{definition}[Modular Form]
A {\em modular form} of integer weight $k$ for a congruence subgroup
$\Gamma$ is a weakly modular function $f:\h^*\to \C$ that
is holomorphic on $\h^*$.
\end{definition}

\begin{proposition}
A weakly modular function $f$ of weight $k$ for $\Gamma$
is holomorphic at every element of $\P^1(\Q)$ if 
 is holomorphic at a set of representative elements
for $C(\Gamma)$.
\end{proposition}
\begin{proof}
Let $c_1,\ldots, c_n \in \P^1(\Q)$ be representatives
for the set of cusps for $\Gamma$.
If $\alpha \in \P^1(\Q)$ then there is $\gamma\in\Gamma$
such that $\alpha = \gamma(c_i)$ for some $i$.
By hypothesis $f$ is holomorphic at $c_i$, so if $\delta\in\SL_2(\Z)$
is such that $\delta(\infty) = c_i$, then $f|[\delta]_k$
is holomorphic at $\infty$.  Since $f$ is a weakly modular
function,
\begin{equation}\label{eqn:prop:holoall}
  f|[\delta]_k = (f|[\gamma]_k)|[\delta]_k = f|[\gamma\delta]_k.
\end{equation}
But $\gamma(\delta(\infty)) = \gamma(c_i) = \alpha$, so 
(\ref{eqn:prop:holoall}) implies that $f$ is holomorphic 
at~$\alpha$.
\end{proof}


\subsection{Computing Widths of Cusps}
Let $\Gamma$ be a congruence subgroup of level~$N$.  Suppose
$\alpha\in C(\Gamma)$ is a cusp, and choose $\gamma\in\SL_2(\Z)$ such
that $\gamma(\infty)=\alpha$.  The minimal $h$ such that
$\abcd{1}{h}{0}{1} \in \gamma^{-1}\Gamma\gamma$ is called the
\defn{width} of the cusp $\alpha$ for the group $\Gamma$.  In this
section we discuss how to compute~$h$.

\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$] Use the extended Euclidean algorithm
to find $\gamma\in\SL_2(\Z)$ such that $\gamma(\infty)=\alpha$,
as follows.
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{}[compute Conjugate Matrix] Compute the following matrix in $M_2(\Z[x])$:
$$
  \delta(x) \set \gamma \mtwo{1}{x}{0}{1} \gamma^{-1}.
$$
Note that the entries of $\delta(x)$ 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 (or enumeration) to find the smallest
  simultaneous positive solution $h$ to these four equations.
\end{steps}
\end{algorithm}

\begin{example}
\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 symmetrically $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 
coprimality from the other two congruences is automatic.
So there is one congruence to solve in the $\Gamma_0(N)$ case.
There are 2 congruences in the $\Gamma_1(N)$ case. 
\end{remark}




\section{Examples of Modular Forms of Level $1$}\label{sec:level_one_eisen}

In this section you will finally see some examples of modular forms of
level $1$!  We will first introduce the Eisenstein series, one of each
weight, then define $\Delta$, which is a cusp form of weight $12$.  In
Section~\ref{sec:struct1} we will prove the structure theorem,
which says that using addition and multiplication of these forms, we
can generate all modular forms of level $1$.

For an even integer $k\geq 4$, the \defn{non-normalized weight~$k$
  Eisenstein series} is
$$
  G_k(z) = \sum_{m,n\in\Z}^{*} \frac{1}{(mz+n)^k},
$$
where for a given $z$, 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$, i.e.,
 $ G_k \in M_k(\SL_2(\Z))$.
\end{proposition}
\begin{proof}
See \cite[\S{} VII.2.3]{serre:arithmetic} for a proof
that $G_k(z)$ defines a holomorphic function on $\h^*$.
To see that $G_k$ is modular, observe 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).
$$
\end{proof}

\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, 
$$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.$$


\subsection{The Cusp Form $\Delta$}
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{ ($k$ 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$.  
\begin{lemma}\label{lem:delnz}
The cusp form $\Delta$ has a $0$ only at $\infty$.
\end{lemma}
\begin{proof}
Let $\omega_1, \omega_2$ be as above.
Since~$E$ is an elliptic curve, $\Delta(\omega_1/\omega_2)\neq 0$.
\end{proof}

\subsection{Fourier Expansions of Eisenstein Series}
Recall from (\ref{eqn:qexp1}) that elements $f$ of $M_k(\SL_2(\Z))$ can be
expressed as formal power series in terms of $q(z)=e^{2\pi i z}$, and
that this expansion is called the Fourier expansion of $f$.
The following proposition gives the Fourier expansion of the
Eisenstein series $G_k(z)$.

\begin{proposition}\label{prop:qexpGk}
For every even integer $k\geq 4$, 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}
\begin{proof}
  See \cite[\S VII.4]{serre:arithmetic}, which uses a series of clever
  manipulations of 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).
$$
\end{proof}

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:modform}{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}

%begin_sage
Use the \code{bernoulli} command to compute Bernoulli
numbers in \sage. 
\begin{verbatim}
sage: bernoulli(12)
-691/2730
sage: bernoulli(50)
495057205241079648212477525/66
\end{verbatim}
%end_sage


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 even integer, then
$$
  \zeta(k) = -\frac{(2\pi i)^{k}}{2\cdot k!}\cdot B_k.
$$
\end{proposition}
\begin{proof}
The proof in \cite[\S VII.4]{serre:arithmetic} 
involves manipulating a power series expansion for $z \cot(z)$.
\end{proof}

\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}
It is thus now simple to explicitly write down Eisenstein series
(see \exref{ch:modform}{ex:expeis}).


\begin{warning} Our series $E_k$ is normalized so that the coefficient
  of~$q$ is~$1$, but often in the literature $E_k$ is normalized 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 is also 
  convenient when considering congruences between cusp forms and
  Eisenstein series.
\end{warning}

\section{Structure Theorem}\label{sec:struct1}
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$; this presentation will allow us to obtain an algorithm
to compute a basis for this space.

Let $\cF$ be the subset of $\h$ of numbers $z$ with $|z|\geq 1$ and
$\Re(z)\leq 1/2$.  This is the standard fundamental domain for
$\SL_2(\Z)$.

\begin{theorem}[Valence Formula]\label{thm:valence}
Suppose $f \in M_k(\SL_2(\Z))$ is nonzero.  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 $\ds \sum^*_{w \in D}$ is the sum over elements of $\cF$
other than~$i$ or~$\rho$.
\end{theorem}
\begin{proof}
Serre proves this theorem in \cite[\S{}VII.3]{serre:arithmetic} using
the residue theorem from complex analysis.
\end{proof}

Let $M_k=M_k(\SL_2(\Z))$ denote the complex vector space of modular
forms of weight~$k$ for $\SL_2(\Z)$, and let~$S_k=S_k(\SL_2(\Z))$
denote the subspace of weight~$k$ cusp forms for $\SL_2(\Z)$.  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 the Eisenstein series $G_k$ and
$G_k(\infty)=2\zeta(k)\neq 0$, so the map $M_k\to \C$ is surjective,
so the following sequence is exact:
$$
  0 \to S_k \to M_k \to \C  \to 0  \qquad\text{(when $k\geq 4$ is even)}
$$

Thus when $k\geq 4$ is even $\dim(S_k)=\dim(M_k)-1$ hence
$$
  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$ (this
also follows from Lemma~\ref{lem:delnz} above).
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 for $M_k$}\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.\edit{Look up what the {\em real} algorithm
for doing this is.}
\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$ follows from (\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{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 very closely follows \cite[Ch.~X,
Thm.~4.4]{lang:modular}, which is in turn follows 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 = -\frac{8}{B_4} \cdot E_4 = 1 + 240q + 2160q^2 + 6720q^3 + 17520q^4 + \cdots
$$ and 
$$
  F_6 = -\frac{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}

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$.
\edit{Argue: Is $G_k$ integral?}




\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{remark}
%(Elkies) 
%\begin{enumerate}
%\item 
If you wish to write $f \in M_k$ 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$.  

%\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}

\section{Hecke Operators}\label{sec:hecke_one}
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
  (by Proposition~\ref{prop:hecke_com} below), so it does not 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$, then 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$ 
transforms $\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.
$$

Since $f$ is holomorphic on $\h$, 
each $f|[\gamma]_k$ is holomorphic on $\h$.
A finite sum of holomorphic functions is holomorphic,
so $T_{n,k}(f)$ 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}\label{prop:hecke_com}
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$.  The
  lattice $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 left $\SL_2(\Z)$-equivalence (i.e., the left
action of $\SL_2(\Z)$).

  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 d\,\mid\, (n,m)} d^{k-1} a_{mn/d^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}\label{cor:tpres} 
 The Hecke operators preserve $M_k$ and $S_k$.
\end{corollary}
\begin{remark} 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$.
In fact for any $k$ one has that
$$
 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}
  By Corollary~\ref{cor:tpres}, the Hecke operators $T_n$ also
  preserve the subspace $S_k$ of $M_k$.  Since $S_{12}$ has dimension
  $1$ (spanned by $\Delta$), we see that~$\Delta$ is an
  eigenvector for every $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{Computing Hecke Operators}
In this section we describe a simple algorithm for computing matrices
of Hecke operators on $M_k$.

\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
once we have computed $T_n(f_i) \pmod{q^{d+1}}$,
since the basis of~$f_i$ are in reduced row echelon form,
so 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 right is
  the matrix whose columsn are the linear combinations found in the
  previous step, i.e., whose columns are the coefficients of $T_n(f_i)$.
\end{steps}
\end{algorithm}
\begin{proof}
  First note that we 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}$ is:
$$
\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.
\edit{Isn't there something from a recent Berkeley grad student.}

% \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}


\subsection{A Conjecture about Complexity}


Let\edit{Lead in about coefficients of elliptic curve
modform, etc.???}
\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]\label{conj:edixhoven}
There is an algorithm to compute $\tau(p)$, for prime $p$, that
is polynomial-time in $\log(p)$.
More generally, suppose $f=\sum a_n q^n$ is an eigenform in some space
$M_k(N,\eps)$, where $k\geq 2$.  Then there is an algorithm
to compute $a_p$, for $p$ prime, in time polynomial in $\log(p)$.
\end{conjecture}


Bas Edixhoven, Jean-Marc Couveignes and Robin de Jong have mostly
proved that $\tau(p)$ can be computed in polynomial time; their
approach involves sophisticated techniques from arithmetic geometry
(e.g., \'etale cohomology, motives, Arakelov theory). This is work in
progress and has not been written up completely yet.  The ideas
Edixhoven uses are inspired by the ones introduced by Schoof, Elkies
and Atkin for quickly counting points on elliptic curves over finite
fields (see \cite{MR1413578}).

More precisely, Edixhoven describes his strategy as follows:
\begin{enumerate}
\item We compute the mod $\ell$ Galois representations associated to
  $\Delta$.  In particular, we produce a polynomial $f$ such that
  $\Q[x]/(f)$ is the corresponding field. This is then used to obtain
  $\tau(p) \pmod{\ell}$ and do a Schoof like algorithm for computing
  $\tau(p)$.

\item We compute the field of definition of suitable points of
  order~$\ell$ on $J_1(\ell)$ to do part 1.

\item The method is to approximate the polynomial $f$ in some sense
  (e.g., over the complex numbers, or modulo many small primes $r$),
  and use an estimate from Arakelov theory to determine a
  precision that will suffice.
\end{enumerate}

The rest of this book is about methods for computing subspaces of
$M_k(\Gamma_1(N))$ for general $N$ and $k$.  These general methods are
much more complicated than the methods presented in this chapter,
since there are many more forms of small weight, and it can be
difficult to obtain them.  These forms of higher level have subtle and
deep connections with arithmetic geometric objects such as elliptic
curves, abelian varieties, and motives.

\begin{exercises}
\item\label{ex:upperhalfpres}
Suppose $\gamma = \abcd{a}{b}{c}{d}$ is a matrix with real entries
and positive determinant.  Prove that if $z\in\C$ is a complex
number with positive imaginary part, then the imaginary
part of $\gamma(z) = (az+b)/(cz+d)$ is also positive.

\item\label{ex:meromorphic}
\begin{enumerate}
\item Prove that a polynomial is an analytic function on $\C$.
\item Prove that a rational function (quotient of two polynomials)
is a meromorphic function on $\C$.
\end{enumerate}

\item \label{ex:wmfprod}
Suppose $f$ and $g$ are weakly modular functions with $f\neq 0$.
\begin{enumerate}
\item Prove that the product $fg$ is a weakly modular function.
\item Prove that $1/f$ is a weakly modular function.
\item If $f$ and $g$ are modular functions, show that $fg$
is a modular function.
\item If $f$ and $g$ are modular forms, show that $fg$
is a modular form.
\end{enumerate}

\item \label{ex:nomodformodd}
Suppose $f$ is a weakly modular function of odd weight $k$.
Show that $f=0$.

\item \label{ex:conggamma1}
\begin{enumerate}
\item Prove that $\Gamma_1(N)$ is a group.
\item Prove that $\Gamma_1(N)$ has finite index in $\SL_2(\Z)$
(Hint: it contains the kernel of the homomorphism
$\SL_2(\Z) \to \SL_2(\Z/N\Z)$.)
\end{enumerate}

\item \label{ex:grpact}
Let $k$ be an integer, and for any function
$f:\h^*\to \C$ and $\gamma=\abcd{a}{b}{c}{d}\in\GL_2(\Q)$,
set $f|[\gamma]_k(z) = (cz+d)^{-k} f(\gamma(z))$. 
Prove that if $\gamma_1, \gamma_2 \in \SL_2(\Z)$,
then for all $z\in \h^*$ we have 
$$
 f|[\gamma_1 \gamma_2]_k(z)  = ((f|[\gamma_1]_k)|[\gamma_2]_k)(z).
$$

\item \label{ex:sl2ztrans}
Prove that for any $\alpha, \beta\in\P^1(\Q)$, there exists
  $\gamma\in\SL_2(\Z)$ such that $\gamma(\alpha) = \beta$.

\item \label{ex:expeis} By hand use (\ref{eqn:ekexp}) write down the
  coefficients of $1$, $q$, $q^2$, and $q^3$ of the Eisenstein series
  $E_8$.

\item \label{ex:vm} Explicitly compute the Victor Miller basis for
$M_{28}(\SL_2(\Z))$.

\end{exercises}

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









%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%
%   NEW CHAPTER 
%
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%












\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{Decomposing Modular Forms Using Dirichlet Characters}
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}

%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.


\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}.


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}$.
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}
sage: kronecker(151,200)
1
sage: kronecker(101,200)
-1
sage: 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]\label{defn:conductordir}
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}










%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%
%   NEW CHAPTER 
%
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%












\chapter{Eisenstein Series}\label{ch:eisen}
We introduce generalized Bernoulli numbers attached to Dirichlet
characters, and give an algorithm to enumerate the Eisenstein series
in $M_k(N,\eps)$.  We will wait until Chapter~\ref{ch:modsym} for an
algorithm to compute all cusp forms in $M_k(N,\eps)$.


\edit{There is something called the Akiyama-Tanigawa algorithm
for computing Bernoulli numbers.  It's in a paper by
Kaneko, Masanobu from Electronic
Journal of Integer Sequences, Vol. (3) article 00.2.9, 2000.}


\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:modform}.

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))$.
%skip
\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}









%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%
%   NEW CHAPTER 
%
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%












\chapter{Dimensions Formulas}
\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
%skip
\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
%skip
\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
%skip
\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
%skip
\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
%skip
\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}








%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%
%   NEW CHAPTER 
%
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%












\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 Forms of Matrices}\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:
%skip
\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 
%skip
\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 
%skip
\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 
%skip
\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$.
%skip
\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.
%skip
\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
\url{http://magma.maths.usyd.edu.au/users/allan/gb/faugere_f4.ps.gz}
  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 Wiedemann's algorithm for computing
minimal polynomials (see Section~\ref{sec:wiedemann}), 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}.

\section{Decomposing Spaces}
\label{sec:decompmodsym}
\edit{Rewrite this intro to make sense given what we know
at this point in the book.  It doesn't now, because I just
moved this section.}
Fix a weight $k$, integer~$N$, and Dirichlet character $\eps$
modulo~$N$.  Let $$V=\sS_k(\Gamma_1(N),\eps)^{+\new}$$ be the new
subspace of the $+1$ quotient of cuspidal modular symbols, viewed as a
$K=\Q(\eps)$ vector space.  In this section we will describe an
algorithm to write $V$ as a direct sum of simple $\T$-submodules.  It
is a consequence of Atkin-Lehner-Li theory and the isomorphism between
cusp forms and certain modular symbols that $V$ is a direct sum of
distinct simple modules, and that the Hecke operators $T_n$ all act
diagonalizably on~$V$.

Let $R$ denote the image of $\T\tensor K$ in $\End(V)$, and let
$n=\dim(V)$.  Since~$R$ is semisimple and finite dimensional over
a field,~$R$ is a product $\prod K_i$ of number fields, so a
random Hecke operator~$T$ will, with high probability, generate~$R$ as
a $K$-algebra.  (The elements that don't generate lie in proper
$K$-subalgebras of~$R$, and those subalgebras are direct sums of
subsets of the $K_i$.)  If~$T$
generates $R$ as an algebra, then the minimal polynomial~$f$ of~$T$
has degree~$n$, so it equals the characteristic polynomial of~$T$.
Also since $T$ is diagonalizable, the minimal polynomial of~$T$ is
square free.  Thus we are led to the following problem:

\begin{problem}\label{prob:decomp}
Suppose $T$ is an $n\times n$ matrix with entries in~$K$
and that the minimal polynomial of~$T$ is square free and
has degree~$n$.  View $T$ as acting on $V=K^n$.
Find the (unique up to order) simple module decomposition 
$W_0 \oplus \cdots \oplus W_m$
of~$V$ as a direct sum of simple $K[T]$-modules.
Equivalently, find an invertible matrix~$A$ such that
$A^{-1} T A$ is a block direct sum of matrices 
$T_0, \ldots, T_m$ such that the minimal polynomial
of each $T_i$ is irreducible.
\end{problem}

\begin{remark}\label{rem:rjf}
A natural generalization of Problem~\ref{prob:decomp} 
to arbitrary matrices is to
find the \defn{rational Jordan form} of $T$.
% Also consider the
% \defn{Frobenius normal form}.  This is 
% the unique matrix that is similar to $T$,
% is defined over $K$ and is a block direct sum of
% matrices $C_{f_i}$, where $f_{i-1}\mid f_i$, and
% $C_f$ is the companion matrix of $f=\sum_{j=0}^r b_j x^j$
% is 
% $$
%   C_f = \left(\begin{matrix}
%   0 & 0 & \cdots & \cdots & -b_0 \\
%   1 & 0 &   0    & 0      & -b_1 \\
%     & 1 &        & 0      & \vdots \\
%     &            &        & \vdots \\
%     & 0  &      & 1      & -b_{r-1}
%   \end{matrix}
% \right).
% $$
This form is like the usual Jordan form, but the summands
corresponding to eigenvalues are replaced by certain 
matrices with minimal polynomials the minimal
polynomials of the eigenvalues.
The rational Jordan form was extensively
studied by Geisbrecht in his Ph.D. thesis and many successive papers,
where he carefully analyzes
the complexity of his algorithms in terms of bit operations, and
observes that the limiting step is factoring
 polynomials over~$K$.  The reason is that given a polynomial
$f\in K[x]$, one can easily write down a matrix $T$ such that
one can can read off the factorization of~$f$ from the rational
Jordan form of $T$.
See also Allan Steel's related paper ({\em A New Algorithm for
the Computation of Canonical Forms of Matrices over Fields},
J. Symbolic Computation (1997) {\bf 24}, 409--432).  
The author would also like to thank Allan Steel for discussions
related to this chapter. 
\end{remark}

\subsection{Wiedemann's Minimal Polynomial Algorithm}
\label{sec:wiedemann}
In this section we describe 
an algorithm due to Wiedemann for computing the
minimal polynomial of an $n\times n$ matrix $A$ over a field. 
%It is best when applied to a sparse matrix with entries in
%a finite field, though it is valid in general.

Choose a random vector $v$ and compute the iterates
$$
   v_0=v, \quad v_1 = A(v),\quad v_2 = A^2(v),\quad \ldots, \quad v_{2n-1} = A^{2n-1}(v).
$$
If $f=x^m + c_{m-1}x^{m-1} + \cdots + c_1 x + c_0 $ 
is the minimal polynomial of $A$, then 
$$
   A^m + c_{m-1} A^{m-1} + \cdots + c_0 I_n = 0,
$$
where $I_n$ is the $n\times n$ identity matrix. 
For any $k\geq 0$, by
multiplying both sides on the right by $A^kv$, we see that
$$
   A^{m+k} v + c_{m-1} A^{m-1+k}v + \cdots + c_0 A^k v = 0,
$$
hence
$$
   v_{m+k} + c_{m-1} v_{m-1+k} + \cdots + c_0 v_k = 0, \qquad \text{all $k\geq 0$}.
$$

Wiedemann's clever idea is to observe that any single component of the
vectors $v_0, \ldots, v_{2n-1}$ satisfies a linear recurrence with
coefficients $1, c_{m-1}, \ldots, c_0$.  There is an algorithm (see
Algorithm~\ref{alg:bm} below) called the Berlekamp-Massey algorithm
(which was introduced in the 1960s in the context of coding theory)
that finds the minimal polynomial of a linear recurrence sequence
$\{a_r\}$.  The minimal polynomial of this linear recurrence is by
definition the unique monic polynomial~$g$, such that if $\{a_r\}$
satisfies a linear recurrence $a_{j+k} + b_{j-1} a_{j-1+k} + \cdots +
b_0 a_k=0$ (for all $k\geq 0$), then $g$ divides the polynomial $x^j +
\sum_{i=0}^{j-1} b_i x^i$.  In particular, if we apply
Berlekamp-Massey to the top coordinates of the $v_i$, we obtain a
polynomial $g_0$, which divides $f$.  We then apply it to the second
to the top coordinates and find a polynomial $g_1$ that divides $f$,
etc., Taking the least common multiple of the first few $g_i$, we find
a divisor of the minimal polynomial of~$f$.  One can show that with
``high probability'' one quickly finds~$f$, instead of just a proper
divisor of~$f$.\edit{Reference.}

\begin{remark}
In the literature, techniques that involve iterating a vector are 
often called Krylov methods.  The subspace generated by the iterates
of a vector under a matrix is called a Krylov subspace.
\end{remark}

In the context of decomposing spaces of modular forms, we will start
with a matrix for which it is likely that the degree of the minimal
polynomial~$f$ equals the number of rows of~$A$.\edit{pointer}

Here's the Berlekamp-Massey algorithm. 
\begin{algorithm}{Berlekamp-Massey}\label{alg:bm}%
INPUT:  The first $2n$ terms $a_{0},\ldots , a_{2n-1}$ of a linear
sequence that satisfies a linear recurrence of degree at most $n$.\\
OUTPUT:  The minimal polynomial $f$ of the sequence.
\begin{enumerate}
\item Let $R_0 = x^{2n}$, $R_1 = \sum_{i=0}^{2n-1} a_i x^i$, 
$V_0 = 0$, $V_1 = 1$.
\item While $\deg(R_1) \geq n$ do the following:
\begin{enumerate}
\item Compute $Q$ and $R$ such that 
$R_0 = Q R_1 + R$.
\item Let $(V_0, V_1, R_0, R_1) = (V_1, V_0 - QV_1, R_1, R)$.
\end{enumerate}
\item Let $d = \max(\deg(V_1), 1+\deg(R_1))$ and set
$P = x^d V_1(1/x)$.  
\item Let $c$ be the leading coefficient of $P$ and output
      $f = P/c$.
\end{enumerate}
\end{algorithm}
For a fresh viewpoint on Berlekamp-Massey and some ideas
for improvement, see 
{\em The Berlekamp-Massey Algorithm revisited} by
Atti, Diaz-Toca, and Lombardi (see 
{\tt http://hlombardi.free.fr/publis/ABMAvar.html})
(Note: I essentially copied the above description of the
Berlekamp-Massey algorithm from loc.\  cit.; my point is only
to illustrate that the Berlekamp-Massey is basically just the Euclidean
algorithm, i.e., it's not something really complicated.)


Now suppose $T$ is an $n\times n$ matrix as in
Problem~\ref{prob:decomp}.  We find the minimal polynomial of~$T$ by 
computing the minimal polynomial of $T\pmod{\wp}$, using Wiedemann's algorithm,
 for many primes $\wp$ and using the
Chinese remainder theorem.  (One has to bound the number of primes
that must be considered; see, e.g., \cite{cohen:course_ant}.)  
%Alternatively,
%one can apply Wiedemann directly over~$K$.  (I don't know if
%this is practical, or if the coefficient explosion
%renders this useless.)

One can also compute the characteristic polynomial of~$T$ directly
from the Hessenberg form of~$T$, which can be computed in $O(n^4)$
field operations, as described in \cite{cohen:course_ant}.  This is
simple, but slow.  Also, the~$T$ we consider will often be sparse,
and Wiedemann is particularly good when~$T$ is sparse.


\begin{example}
We compute the minimal polynomial of the Hecke operator $A=T_2$
on $\sM_2(\Gamma_0(23))^+$ using Wiedemann's algorithm.
We have 
$$
A= \left(\begin{array}{ccc}
3&0&0\\
0&0&2\\
-1&1/2&-1
\end{array}\right)
$$
Let $v=(1,0,0)^t$.  Then 
\begin{align*}
  v&=(1,0,0)^t,\quad Av = (3,0,-1)^t,\quad A^2v = (9,-2,-2)^t, \\
  A^3v&=(27,-4,-8)^t, \quad A^4v=(81,-16,-21)^t, \quad A^5v=(243,-42,-68)^t.
\end{align*}
The linear recurrence sequence coming from the first entries is
$$
   1, 3, 9, 27, 81, 243.
$$
This sequence satisfies the linear recurrence
$$
    a_{k+1} -3 a_k = 0, \qquad\text{all $k>0$}
$$
so its minimal polynomial is $x-3$.  This implies that
$x-3$ divides the minimal polynomial of the matrix $A$.
Next we use the sequence of second coordinates of the 
iterates of $v$, which is
$$
  0, 0, -2, -4, -16, -42.
$$
The recurrence that this sequence satisfies is slightly 
less obvious, so we apply the Berlekamp-Massey algorithm
to find it, with $n=3$.
\begin{enumerate}
\item We have $R_0 = x^6$, 
$
 R_1 = -42x^5 - 16x^4 - 4x^3 - 2x^2,
$
$V_0 = 0, V_1 = 1$.

\item 
\begin{enumerate}
\item Dividing $R_0$ by $R_1$, we find
$$
  R_0 = R_1 \left(  -\frac{1}{42}x + \frac{4}{441}  \right) + 
    \left(\frac{22}{441}x^4 - \frac{5}{441}x^3 + \frac{8}{441}x^2 \right)
$$
\item The new $V_0, V_1, R_0, R_1$ are 
\begin{align*}
  V_0 &= 1\\
  V_1 &= \frac{1}{42}x - \frac{4}{441}\\
  R_0 &= -42x^5 - 16x^4 - 4x^3 - 2x^2 \\
  R_1 &= \frac{22}{441}x^4 - \frac{5}{441}x^3 + \frac{8}{441}x^2\\
\end{align*}
Since $\deg(R_1)\geq n=3$, we have to do the above three steps again.
\end{enumerate}

\item We repeat the preceeding three steps.
\begin{enumerate}
\item Dividing $R_0$ by $R_1$, we find
$$
  R_0 = R_1 \left(-\frac{9261}{11}x - \frac{123921}{242}\right) + 
    \left( \frac{1323}{242}x^3 + \frac{882}{121}x^2\right)
$$
\item The new $V_0, V_1, R_0, R_1$ are [I'm running out of
{\tt $\backslash$frac} steam.]
\begin{align*}
  V_0 &= 1/42x - 4/441\\
  V_1 &= 441/22x^2 + 2205/484x + 441/121\\
  R_0 &= 22/441x^4 - 5/441x^3 + 8/441x^2\\
  R_1 &= 1323/242x^3 + 882/121x^2\\
\end{align*}
\end{enumerate}

\item Unfortunately we have to repeat the steps yet again.
We get
\begin{align*}
 V_0 &= 441/22x^2 + 2205/484x + 441/121\\
 V_1 &= -242/1323x^3 +968/3969x^2 + 484/3969x -242/3969\\
 R_0 &=1323/242x^3 + 882/121x^2\\
 R_1 &=  484/3969x^2
\end{align*}

\item We have $d=3$, 
so $P = -242/3969 x^3 + 484/3969x^2 +968/3969x - 242/1323$.
\item Multiply through by $-3969/242$ and
output $$x^3 - 2x^2 - 4x + 3 = (x - 3)(x^2 + x - 1).$$
\end{enumerate}
The minimal polynomial of $T_2$ is $(x - 3)(x^2 + x - 1)$,
since the minimal polynomial has degree at most $3$
and is divisible by $(x - 3)(x^2 + x - 1)$.
\end{example}


\subsection{Polynomial Factorization}
There is a new algorithm due to Hoeij, which has been
refined by Belebas, Kl\"uners,
and Steel, for factoring polynomials over number fields (and
more general global fields).  It involves factoring
modulo many primes, lifting $p$-adically, and cleverly using
LLL to solve a certain ``knapsack problem'' that reduces
the number of subsets of factors that need to be considered.
We will say nothing more about it here, except that it is
rumored to be ``very fast'', and it is the algorithm to 
know about.  [After a quick reading of Belebas, Hoeij, Kl\"uners,
and Steel, the $O$ complexity is unclear to me.]

\subsection{Decomposition Using Kernels}
We now know enough to give an algorithm to solve 
Problem~\ref{prob:decomp}.
\begin{algorithm}{Decomposition Using Kernels}\label{alg:decomp}%
INPUT: An $n\times n$ matrix~$T$ over a field~$K$ as
in Problem~\ref{prob:decomp}.\\
OUTPUT: Decomposition of $V$ as a direct sum of 
simple $K[T]$ modules.
\begin{enumerate}
\item{}[Minimal Polynomial] Compute the minimal polynomial~$f$ of~$T$,
e.g., using the multi-modular Wiedemann algorithm.
\item{}[Factorization]\label{alg:decomp:factor} Factor~$f$ using the 
Belebas, Hoeij, Kl\"uners, and Steel algorithm.
\item{}[Compute Kernels]\label{alg:decomp:ker}
For each irreducible factor $g_i$ of $f$:
\begin{enumerate}
\item Compute the matrix $A_i = g_i(T)$.  (This is difficult,
and $A$ will have huge coefficients.)
\item Compute $W_i = \ker(A_i)$ using, e.g., a multi-modular
kernel algorithm.
\end{enumerate}
\item{}[Output Answer] Then $V=\oplus W_i$.
\end{enumerate}
\end{algorithm}

\begin{remark}
In the worst case, perhaps Step~\ref{alg:decomp:factor} is
 most difficult step.  In practice Step~\ref{alg:decomp:ker} is
very time consuming.  As mentioned in Remark~\ref{rem:rjf}, 
if one can compute such decompositions $V=\oplus W_i$, then
one can easily factor polynomials~$f$, hence the difficulty of
polynomial factorization
is a lower bound on the complexity of writing~$V$
as a direct sum of simples. 
\end{remark}


\subsection{Multi-Modular Decomposition Algorithm}

The following algorithm is a modification of Algorithm~\ref{alg:decomp}, 
which improves upon the difficult Step~\ref{alg:decomp:ker}.

\begin{algorithm}{Decomposition Algorithm II}\label{alg:decomp2}%
INPUT: An $n\times n$ matrix~$T$ over a field~$K$ as
in Problem~\ref{prob:decomp}.\\
OUTPUT: Decomposition of $V$ as a direct sum of 
simple $K[T]$ modules.
\begin{enumerate}
\item{}[Minimal Polynomial] Compute the minimal polynomial~$f$ of~$T$,
e.g., using the multi-modular Wiedemann algorithm.
\item{}[Factorization]\label{alg:decomp:factor} Factor~$f=\prod g_i$ 
using the  Belebas, Hoeij, Kl\"uners, and Steel algorithm.
\item{}[Cofactors] For each~$i$, let $h_i = f/g_i$.
\item{}[Find Kernels]
For several primes $\wp$ (how many?), compute reduced row echelon
forms for basis of all the kernels $\overline{W}_i = \ker(g_i(\overline{T}))$
as follows:
\begin{enumerate}
\item Choose a random vector $v \in \overline{V}$.
\item Compute the iterates 
$$v_0 = v,\quad  v_1 = \overline{T}v,\quad \ldots, \quad v_{n-1}= \overline{T}^{n-1}v.$$
\item For each $i$ do the following:
\begin{enumerate}
\item Compute $w = h_i(\overline{T})v \in \ker(g_i(\overline{T}))$
by taking the linear combination of the $v_i$ given
by the coefficients of $h_i$.
\item Generate a subspace of $\ker(g_i(\overline{T}))$ using
 $w, \overline{T}w, \ldots, \overline{T}^{i}w$, keeping the 
 subspace basis in Echelon form at each step.  If this subspace
 does not equal the full $\ker(g_i(\overline{T}))$, 
 repeat the above steps with another $v$, and add the
 resulting iterates of the new $w$ to this subspace.  Repeat
 this process until we obtain a basis for $\ker(g_i(\overline{T}))$,
 in reduced row echelon form.
\end{enumerate}
\end{enumerate}
\item{}[Lift] Using the Chinese remainder theorem and
 rational reconstruction, lift the $\overline{W}_i$ to
$K$-vector spaces $W_i$ such that $V=\oplus W_i$ is the desired decomposition.
(WARNING: It is probably necessary to throw away ``bad'' primes, just
as we did in the multi-modular echelon algorithm.)
\end{enumerate}
\end{algorithm}










%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%
%   NEW CHAPTER 
%
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%












\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.  It is
  crucial to add this, since this is something nontrivial that I have
  in my thesis, and it's very important to know when implementing.}



\section{The Pairing Between Modular Symbols and Modular Forms}%
\label{sec:pairing}%
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
\begin{equation}\label{eqn:lfunc_ms}
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.
   \end{equation}
   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}\label{thm:tequivar}
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).
$$

\section{Explicitly Computing $\sM_k(\Gamma_0(N)$}\label{sec:compg0n}
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$.\\
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$:
%skip
\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$:
%skip
\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$:
%skip
\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)$.
%skip
\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}.)
%skip
\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)$.
%skip
\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$:
%skip
\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)$.
%skip
\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}.
%skip
\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).
%skip
\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&1&0&0&0&-2&0&0&1&1&0&1&-2&0&0&0&1&0&0&0\\
0&0&0&1&0&-1&0&-1&0&3&0&0&1&-3&0&0&0&1&0&0\\
1&0&0&0&-1&0&0&-1&0&0&0&3&0&1&0&-3&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&-1&-1&0&0&3&0&0&0&-3&0&0&1&1&0&0&0\\
0&1&0&1&0&-4&0&0&0&6&0&0&0&-4&0&0&1&1&0&0\\
1&0&0&1&0&0&0&-4&0&0&0&6&0&0&0&-4&0&1&0&1\\
0&0&2&0&0&0&-4&0&0&0&6&0&0&0&-4&0&0&0&2&0\\
1&1&0&0&-4&0&0&0&6&0&0&0&-4&0&0&0&1&0&0&1
\end{array}\right)
$$}
The reduced row echelon form of the relations matrix,
with zero rows removed:
{\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&0&0&0&0&0&3/16&-3/16\\
0&0&0&0&0&1&0&0&0&0&0&0&0&0&0&0&0&0&-1/16&1/16\\
0&0&0&0&0&0&1&0&0&0&0&0&0&0&0&0&0&1/2&-5/16&-3/16\\
0&0&0&0&0&0&0&1&0&0&0&0&0&0&0&0&0&-1/2&3/16&5/16\\
0&0&0&0&0&0&0&0&1&0&0&0&0&0&0&0&0&-1/6&1/12&1/12\\
0&0&0&0&0&0&0&0&0&1&0&0&0&0&0&0&0&1/6&-1/12&-1/12\\
0&0&0&0&0&0&0&0&0&0&1&0&0&0&0&0&0&0&1/4&-1/4\\
0&0&0&0&0&0&0&0&0&0&0&1&0&0&0&0&0&0&-1/4&1/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&\!\!\!\!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&\!\!\!\!1&\!\!\!\!0&\!\!\!\!0&\!\!\!\!0&\!\!\!\!0&\!\!\!\!0&\!\!\!\!0&\!\!\!\!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&\!\!\!\!0&\!\!\!\!0&\!\!\!\!0&\!\!\!\!0&\!\!\!\!0&\!\!\!\!0&\!\!\!\!0&\!\!\!\!0&\!\!\!\!0\\
0&\!\!\!\!0&\!\!\!\!0&\!\!\!\!0&\!\!\!\!1&\!\!\!\!0&\!\!\!\!0&\!\!\!\!0&\!\!\!\!0&\!\!\!\!0&\!\!\!\!0&\!\!\!\!0&\!\!\!\!0&\!\!\!\!0&\!\!\!\!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&\!\!\!\!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&\!\!\!\!1&\!\!\!\!0&\!\!\!\!0&\!\!\!\!0&\!\!\!\!0&\!\!\!\!0&\!\!\!\!0&\!\!\!\!0&\!\!\!\!0&\!\!\!\!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&\!\!\!\!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&\!\!\!\!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&\!\!\!\!0&\!\!\!\!0&\!\!\!\!0&\!\!\!\!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&\!\!\!\!1&\!\!\!\!0&\!\!\!\!0&\!\!\!\!0&\!\!\!\!0&\!\!\!\!0&\!\!\!\!0&\!\!\!\!0&\!\!\!\!0&\!\!\!\!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&\!\!\!\!1&\!\!\!\!0&\!\!\!\!0&\!\!\!\!0&\!\!\!\!0&\!\!\!\!0&\!\!\!\!0&\!\!\!\!0&\!\!\!\!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\\
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&\!\!\!\!0&\!\!\!\!0&\!\!\!\!0&\!\!\!\!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&\!\!\!\!0&\!\!\!\!0&\!\!\!\!0&\!\!\!\!0&\!\!\!\!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&\!\!\!\!0&\!\!\!\!0&\!\!\!\!0&\!\!\!\!0&\!\!\!\!0\\
0&\!\!\!\!0&\!\!\!\!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&\!\!\!\!0&\!\!\!\!0&\!\!\!\!0&\!\!\!\!0&\!\!\!\!0&\!\!\!\!0&\!\!\!\!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&\!\!\!\!1&\!\!\!\!0&\!\!\!\!0&\!\!\!\!0&\!\!\!\!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&\!\!\!\!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&\!\!\!\!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&\!\!\!\!0&\!\!\!\!0&\!\!\!\!0&\!\!\!\!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&\!\!\!\!0&\!\!\!\!0&\!\!\!\!0&\!\!\!\!0&\!\!\!\!0&\!\!\!\!0&\!\!\!\!0&\!\!\!\!0&\!\!\!\!0&\!\!\!\!0&\!\!\!\!0&\!\!\!\!0&\!\!\!\!0&\!\!\!\!1&\!\!\!\!0&\!\!\!\!0&\!\!\!\!0&\!\!\!\!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&\!\!\!\!1&\!\!\!\!0&\!\!\!\!0&\!\!\!\!0&\!\!\!\!0&\!\!\!\!0&\!\!\!\!0&\!\!\!\!0&\!\!\!\!0&\!\!\!\!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&\!\!\!\!1&\!\!\!\!0&\!\!\!\!0&\!\!\!\!0&\!\!\!\!0&\!\!\!\!0&\!\!\!\!0&\!\!\!\!0&\!\!\!\!0&\!\!\!\!0&\!\!\!\!0&\!\!\!\!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&\!\!\!\!1&\!\!\!\!0&\!\!\!\!0&\!\!\!\!0&\!\!\!\!0&\!\!\!\!0&\!\!\!\!0&\!\!\!\!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&\!\!\!\!1&\!\!\!\!0&\!\!\!\!0&\!\!\!\!0&\!\!\!\!0&\!\!\!\!0&\!\!\!\!0&\!\!\!\!0&\!\!\!\!0&\!\!\!\!0&\!\!\!\!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&\!\!\!\!1&\!\!\!\!1&\!\!\!\!0&\!\!\!\!0&\!\!\!\!0&\!\!\!\!0&\!\!\!\!0\\
\hline
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&\!\!\!\!1\\
0&\!\!\!\!0&\!\!\!\!1&\!\!\!\!0&\!\!\!\!0&\!\!\!\!0&\!\!\!\!0&\!\!\!\!0&\!\!\!\!0&\!\!\!\!0&\!\!\!\!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&\!\!\!\!0&\!\!\!\!0&\!\!\!\!0&\!\!\!\!0&\!\!\!\!0&\!\!\!\!0&\!\!\!\!0&\!\!\!\!1&\!\!\!\!0\\
0&\!\!\!\!0&\!\!\!\!0&\!\!\!\!1&\!\!\!\!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&\!\!\!\!0&\!\!\!\!0&\!\!\!\!0&\!\!\!\!0&\!\!\!\!0&\!\!\!\!0\\
0&\!\!\!\!0&\!\!\!\!0&\!\!\!\!0&\!\!\!\!1&\!\!\!\!0&\!\!\!\!0&\!\!\!\!0&\!\!\!\!0&\!\!\!\!0&\!\!\!\!0&\!\!\!\!0&\!\!\!\!0&\!\!\!\!0&\!\!\!\!1&\!\!\!\!0&\!\!\!\!0&\!\!\!\!0&\!\!\!\!0&\!\!\!\!0&\!\!\!\!0&\!\!\!\!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&\!\!\!\!0&\!\!\!\!0&\!\!\!\!0&\!\!\!\!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&\!\!\!\!0&\!\!\!\!1&\!\!\!\!0&\!\!\!\!0&\!\!\!\!0&\!\!\!\!0&\!\!\!\!0&\!\!\!\!0&\!\!\!\!0&\!\!\!\!0&\!\!\!\!0&\!\!\!\!0&\!\!\!\!0\\
0&\!\!\!\!0&\!\!\!\!0&\!\!\!\!0&\!\!\!\!0&\!\!\!\!0&\!\!\!\!1&\!\!\!\!0&\!\!\!\!1&\!\!\!\!0&\!\!\!\!0&\!\!\!\!0&\!\!\!\!0&\!\!\!\!0&\!\!\!\!0&\!\!\!\!0&\!\!\!\!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&\!\!\!\!3&\!\!\!\!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&\!\!\!\!0&\!\!\!\!1&\!\!\!\!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&\!\!\!\!0&\!\!\!\!0&\!\!\!\!0&\!\!\!\!0&\!\!\!\!0&\!\!\!\!0&\!\!\!\!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&\!\!\!\!0&\!\!\!\!0&\!\!\!\!0&\!\!\!\!0&\!\!\!\!0&\!\!\!\!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&\!\!\!\!0&\!\!\!\!0&\!\!\!\!0&\!\!\!\!0&\!\!\!\!0&\!\!\!\!0&\!\!\!\!1&\!\!\!\!0&\!\!\!\!0&\!\!\!\!0&\!\!\!\!0&\!\!\!\!0&\!\!\!\!0&\!\!\!\!0&\!\!\!\!0&\!\!\!\!0&\!\!\!\!1&\!\!\!\!0&\!\!\!\!0&\!\!\!\!0\\
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&\!\!\!\!0&\!\!\!\!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&\!\!\!\!0&\!\!\!\!0&\!\!\!\!0&\!\!\!\!0&\!\!\!\!0&\!\!\!\!1&\!\!\!\!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&\!\!\!\!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&\!\!\!\!0&\!\!\!\!0&\!\!\!\!1&\!\!\!\!0&\!\!\!\!0&\!\!\!\!0&\!\!\!\!0&\!\!\!\!0&\!\!\!\!0&\!\!\!\!0&\!\!\!\!0&\!\!\!\!0&\!\!\!\!0&\!\!\!\!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&\!\!\!\!1&\!\!\!\!0&\!\!\!\!0&\!\!\!\!0&\!\!\!\!1&\!\!\!\!0&\!\!\!\!0&\!\!\!\!0&\!\!\!\!0&\!\!\!\!0&\!\!\!\!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&\!\!\!\!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.    
The dimension of $\sM_2(\Gamma_0(2004),\Q)^+$ is $331$.
\end{example}

\subsection{Refined Algorithm For Computing Presentation}
\begin{algorithm}{Compute Presentation}\label{alg:modsympresent}
This is an algorithm to compute $\sM_k(\Gamma_0(N),\Q)$ or 
$\sM_k(\Gamma_0(N),\Q)^{\pm}$, 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 two-term $S$ relations and if the $\pm $
quotient is desired, by the two-term $\eta$ relations.
(See Algorithm~\ref{alg:twoterm} below.)
       Let $[x_i]$ denote the
          class of $x_i$ after this quotienting process.
\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}

\begin{algorithm}{Quotient By 2-Term Relations}\label{alg:twoterm}
This algorithm performs sparse Gauss elimination on a matrix all of      
whose columns have at most 2 nonzero entries.
This algorithm is more subtle than just ``identify symbols in pairs'',
since complicated relations can cause generators to surprisingly
equal $0$.

%skip
\begin{verbatim}
    INPUT:
        rels -- set of pairs ((i,s), (j,t)).  The pair represents 
                the relation
                      s*x_i + t*x_j = 0.
        n -- int, the x_i are x_0, ..., x_{n-1}.
        F -- base field
    OUTPUT:
        mod -- list such that mod[i] = (j,s), which means that
                     x_i is equivalent to s*x_j,
               where the x_j are a basis for the quotient. 
    EXAMPLE:
    We quotient out by the relations
           3*x0 - x1 = 0,  x1 + x3 = 0,   x2 + x3 = 0,  x4 - x5 = 0
    to get
        >>> Q = rings.RationalField()
        >>> rels = set([((0,3), (1,-1)), ((1,1), (3,1)), ((2,1),(3,1)), ((4,1),(5,-1))])
        >>> n = 6
        >>> sparse_2term_quotient(rels, n, Q)
        [(3, -1/3), (3, -1), (3, -1), (3, 1), (5, 1), (5, 1)]
    """
    if not isinstance(rels, set):
        raise TypeError, "rels must be a set"
    if not isinstance(n, int):
        raise TypeError, "n must be an int"
    if not isinstance(F, rings.Ring):
        raise TypeError, "F must be a ring."
    
    tm = misc.verbose()
    free = range(n)
    ONE = F(1)
    ZERO = F(0)
    coef = [ONE for i in xrange(n)] 
    related_to_me = [[] for i in xrange(n)]
    for v0, v1 in rels:
        c0 = coef[v0[0]] * F(v0[1])
        c1 = coef[v1[0]] * F(v1[1])
        # Mod out by the relation 
        #    c1*x_free[t[0]] + c2*x_free[t[1]] = 0.
        die = None
        if c0 == ZERO and c1 == ZERO:
            pass
        elif c0 == ZERO and c1 != ZERO:  # free[t[1]] --> 0
            die = free[v1[0]]
        elif c1 == ZERO and c0 != ZERO:
            die = free[v0[0]]
        elif free[v0[0]] == free[v1[0]]:
            if c0+c1 != 0:
                # all xi equal to free[t[0]] must now equal to zero.
                die = free[v0[0]]
        else:  # x1 = -c1/c0 * x2.
            x = free[v0[0]]
            free[x] = free[v1[0]]
            coef[x] = -c1/c0
            for i in related_to_me[x]:
                free[i] = free[x]
                coef[i] *= coef[x]
                related_to_me[free[v1[0]]].append(i)
            related_to_me[free[v1[0]]].append(x)
        if die != None:
            for i in related_to_me[die]:
                free[i] = 0
                coef[i] = ZERO
            free[die] = 0
            coef[die] = ZERO
    mod = [(free[i], coef[i]) for i in xrange(len(free))]
    misc.verbose("finished",tm)
    return mod
\end{verbatim}
\end{algorithm}



\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.  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:findall}).  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}).  Martin's thesis \cite{martin: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.
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}








%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%
%   NEW CHAPTER 
%
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%












\chapter{Computing Spaces of Modular Forms}\label{ch:modform}
\section{Atkin-Lehner-Li Theory}\label{sec:qexps}

By Atkin-Lehner-Li theory
(see \cite{atkin-lehner, winnie:newforms}), we have
a decomposition
\begin{equation}\label{eqn:decomp}
  S_k(\Gamma_1(N)) = 
   \bigoplus_{M\mid N} \bigoplus_{d\mid N/M} \alpha_d(S_k(\Gamma_1(M))_{\new}).
\end{equation}
Here $\alpha_d : S_k(\Gamma_1(M)) \to S_k(\Gamma_1(N))$ is the degeneracy
map $f(q) \mapsto f(q^d)$, and $S_k(\Gamma_1(M))_{\new}$
is the largest $\T$-stable (or Petersson) complement of the image of all maps $\alpha_d$
from level properly dividing~$M$.  The analogue of (\ref{eqn:decomp})
with $\Gamma_1$ replaced by $\Gamma_0$ is true;
it is also true with character, as long as we omit the 
spaces $S_k(\Gamma_1(M),\eps)$
for which $M\nmid \cond(\eps)$.

\begin{example}
If $N$ is prime and $k\leq 11$, then 
$S_k(\Gamma_1(N))_{\new} = S_k(\Gamma_1(N))$,
since $S_k(\Gamma_1(1))=0$.   
\end{example}

One can prove using the Petersson inner product that the Hecke
operators $T_n$ on $S_k(\Gamma_1(N))$, with $(n,N)=1$, are
diagonalizable.  Another result of Atkin-Lehner-Li theory is that the
ring of endomorphism of $S_k(\Gamma_1(N))_{\new}$ generated by all
Hecke operators equals the ring generated by the Hecke operators $T_n$
with $(n,N)=1$.  This statement need {\em not} be true if we do not
restrict to the new subspace.
\begin{example}\label{ex:onlyold}
We have
$$
  S_2(\Gamma_0(22)) = S_2(\Gamma_0(11)) \oplus \alpha_2(S_2(\Gamma_0(11))),
$$
where each of the spaces $S_2(\Gamma_0(11))$ has dimension $1$.  Thus
$S_2(\Gamma_0(22))_{\new} = 0$.  The Hecke operator $T_2$ on 
$S_2(\Gamma_0(22))$ has characteristic polynomial $x^2+2x+2$,
which is irreducible.  Since $\alpha_2$ commutes with all Hecke 
operators $T_n$, with $\gcd(n,2)=1$, the subring $\T'$ of the Hecke
algebra generated by operators $T_n$ with~$n$ odd is isomorphic
to~$\Z$ (the $2\times 2$ scalar matrices).  Thus on the full space
$S_2(\Gamma_0(22))$, we do not have $\T'=\T$.  However, on the new subspace 
we do have this equality, since the new subspace has dimension~$0$.
\end{example}

\begin{example}
This example is similar to Example~\ref{ex:onlyold}, except that there
are newforms.
We have
$$
  S_2(\Gamma_0(55)) = S_2(\Gamma_0(11)) \oplus \alpha_5(S_2(\Gamma_0(11)))
                     \oplus S_2(\Gamma_0(55))_{\new},
$$
where $S_2(\Gamma_0(11))$ has dimension $1$ and
$S_2(\Gamma_0(55))_{\new}$ has dimension~$3$.
The Hecke operator $T_5$ on 
$S_2(\Gamma_0(55))_{\new}$ acts  via the matrix
$$
\mthree
{-2}{\hfill 2}{\hfill -1}
{-1}{\hfill 1}{-1}
{\hfill 1}{-2}{\hfill 0}
$$
with respect to some basis. This matrix has eigenvalues $1$ and $-1$.
Atkin-Lehner theory asserts that $T_5$ must be a
linear combination of Hecke operators $T_n$, with 
$\gcd(n,55)=1$.
Upon computing the matrix for $T_2$,
we find by simple linear algebra that $T_5 = 2T_2 - T_4$.
\end{example}

Before moving on, we pause to say something about how the
Atkin-Lehner-Li theorems are proved.  A key result is to prove that if
$f, g \in S_k(\Gamma_1(N))_{\new}$ and $a_n(f) = a_n(g)$ for all~$n$
with $\gcd(n,N)=1$, then $f=g$.  First, replace $f$ and $g$ by their
difference $h=f-g$, and observe that $a_n(h)=0$ for $\gcd(n,N)=1$.  Note
that such an $h$ ``looks like'' it is in the image of the maps
$\alpha_d$, for $d\mid N$.  In fact it is---one shows that~$h$ is in
the old subspace $S_k(\Gamma_1(N))_{\old}$ (this is the ``crucial''
Theorem~$2$ of \cite{winnie:newforms}).  But $h$ is also new, since it
is the difference of two newforms, so
$h=0$, hence $f=g$.  The details involve
introducing many maps between spaces of modular forms, and computing
what they do to $q$-expansions.


\begin{definition}[Newform]
A \defn{newform} is a $\T$-eigenform $f\in S_k(\Gamma_1(N))_{\new}$
that is normalized so that the coefficient of $q$ is $1$.
\end{definition}
We now motivate this definition by explaining why any eigenform
can be normalized so that the coefficient of $q$ is $1$, and how
such an eigenform has the convenient properties that its Fourier
coefficients are exactly the Hecke eigenvalues. 
\begin{proposition}\label{prop:eigncoeffs}
The coefficients of a normalized $\T$-eigenform are the
eigenvalues.
\end{proposition}
\begin{proof}
The Hecke algebra $\T_\Q$ on $S_k(\Gamma_1(N))$ contains the diamond
bracket operators $\dbd{d}$, 
since $T_{p^2} = T_p^2 - \dbd{p}p^{k-1}$,
so any $\T$-eigenform lies in a subspace
$S_k(\Gamma_1(N),\eps)$ for some Dirichlet character $\eps$.  The
Hecke operators $T_p$, for $p$ prime, act on $S_k(\Gamma_1(N),\eps)$
by 
$$
T_p\left(\sum_{n=1}^{\infty} a_n q^n\right) =
\sum_{n=1}^{\infty} \left( a_{np}q^n + \eps(p) p^{k-1}
  a_{n}q^{np}\right),
$$
and there is a similar formula for $T_m$ with $m$ composite.
If $f=\sum_{n=1}^{\infty} a_n q^n$ is an eigenform for all
$T_p$, with eigenvalues $\lambda_p$, then by the above formula 
\begin{equation}\label{eqn:eigenexp}
\lambda_p f = \lambda_p a_1 q + \lambda_p a_2 q^2 + \cdots = T_p(f) = a_{p} q +
\text{higher terms}.  
\end{equation}
Equating coefficients of $q$ we see that if
$a_1=0$, then $a_p=0$ for all~$p$, hence
$a_n=0$ for all~$n$, because of the multiplicativity of Fourier
coefficients and the recurrence $$a_{p^r} = a_{p^{r-1}} a_p - \eps(p)
p^{k-1} a_{p^{r-2}}.$$ 
This would mean that $f=0$, a contradiction.  Thus $a_1\neq 0$,
and it makes sense to normalize $f$ so that $a_1=1$.
With this normalization, (\ref{eqn:eigenexp}) implies that $\lambda_p = a_p$,
as desired.  
\end{proof}

\begin{remark}\label{rem:dbdinhecke}
We even have that the operators $\dbd{d}$ on $S_k(\Gamma_1(N))$ lie in
$\Z[\ldots,T_n,\ldots]$.
It is enough to show $\dbd{p}\in\Z[\ldots,T_n,\ldots]$ for
primes~$p$, since each $\dbd{d}$ can be written in terms of the
$\dbd{p}$. Since $p\nmid N$, we have that
\[
  T_{p^2} = T_p^2 - \dbd{p}p^{k-1},
\]
so $\dbd{p}p^{k-1} = T_p^2 - T_{p^2}$.
By Dirichlet's theorem on primes in arithmetic progression, 
there is another prime~$q$ congruent
to~$p$ mod $N$. Since $p^{k-1}$ and $q^{k-1}$ are relatively
prime, there exist integers~$a$ and~$b$ such that $a p^{k-1} + b
q^{k-1} = 1$. Then
\[
\dbd{p}=\dbd{p}(a p^{k-1} + b q^{k-1})
       = a({T_p}^2-T_{p^2}) + b({T_q}^2-T_{q^2})
       \in \Z[\ldots, T_n,\ldots].
\]
\end{remark}

\section{Computing Cuspforms Using\\Modular Symbols}
There is an isomorphism 
$$S_k(\Gamma_1(N),\eps)_{\new} \isom \sS_k(\Gamma_1(N),\eps,\C)^+_{\new}$$
of $\T$ modules.  Thus  finding the systems of $\T$-eigenvalues on
cuspforms is the same as finding the systems of $\T$-eigenvalues
on cuspidal modular symbols.

Our strategy to compute $S_k(\Gamma_1(N),\eps)$ is to first reduce to
computing spaces $S_k(\Gamma_1(N),\eps)_{\new}$ using the
Atkin-Lehner-Li decomposition (\ref{eqn:decomp}).  To compute
$S_k(\Gamma_1(N),\eps)_{\new}$ to a given precision, we compute the
systems of eigenvalues of the Hecke operators $T_p$ on 
$V=\sS_k(\Gamma_1(N),\eps,\C)^+_{\new}$.  Using
Proposition~\ref{prop:eigncoeffs}, we then recover a basis of
$q$-expansions for newforms.     Note that we only need to 
compute Hecke eigenvalues $T_p$, for $p$ prime, not the $T_n$ for
$n$ composite, since the $a_n$
can be quickly recovered in terms of the $a_p$ using multiplicativity
and the recurrence. 

For many problems, one is really interested in the newforms, not just
any basis for $S_k(\Gamma_1(N),\eps)$.  The are many other problems
where just having a basis is enough, and knowing the newforms is not
so important.  Merel's paper \cite{merel:1585} culminates with the
following algorithm to compute $S_k(\Gamma_1(N),\eps)$ without finding
any eigenspaces:  
\begin{algorithm}{Merel's Algorithm for Computing a Basis}\label{alg:merelqexp}
\begin{enumerate}
\item{}[Compute Modular Symbols] 
Using  Algorithm~\ref{alg:modsympresent},
compute a presentation for $V = \sS_k(\Gamma_1(N),\eps)^+\tensor \Q(\eps)$,
viewed as a $K=\Q(\eps)$ vector space,
along with an action of Hecke operators $T_n$.

\item{}[Basis for Linear Dual]
Write down a basis for $V^* = \Hom(V,\Q(\eps))$.  E.g., if we identify
$V$ with $K^n$ viewed as column vectors, then $V^*$ is the space
of row vectors of length $n$, and the pairing is the row $\times$ column product.

\item{}[Find Generator]
Find $x\in V$ such that
$\T{} x = V$ by choosing random~$x$ until we find
one that generates.  The set of~$x$ that fail
to generate lie in a union of a finite number of
proper subspace. (This can be seen by analyzing
the structure of $S_k(\Gamma_1(N),\eps)$ as a $\T$-module;
see, e.g., my 252 notes.)
\item{}[Compute Basis]  
The set of power series
$$
  f_i = \sum_{n=1}^{m} \psi_i(T_n(x)) q^n + O(q^{m+1})
$$
form a basis for $S_k(\Gamma_1(N),\eps)$ to precision $m$.
\end{enumerate}
\end{algorithm}


  
In practice my experience is that my implementations of
Algorithm~\ref{alg:merelqexp} are significantly slower than the
eigenspace algorithm that we will describe in the rest of this
chapter.  The theoretical complexity of Algorithm~\ref{alg:merelqexp}
{\em may} be better, because it is not necessary to factor any
polynomials. Polynomial factorization is difficult from the
analysis-of-complexity point of view, though usually fairly fast in
practice.  The eigenvalue algorithm only requires computing a few
images $T_p(x)$ for $p$ prime and $x$ a Manin symbol on which $T_p$
can easily be computed.  The Merel algorithm involves computing
$T_n(x)$ for all~$n$, and a fairly easy~$x$, which is potentially more work.
(By ``easy $x$'', I mean that computing $T_n(x)$ is easier on~$x$
than on a completely random element of $\sS_k(\Gamma_1(N),\eps)^+$,
e.g.,~$x$ could be a Manin symbol.)


\section{Computing Systems of Eigenvalues}
In this section we describe an algorithm for computing
the system of Hecke eigenvalues associated to a simple
subspace of a space of modular symbols.   This algorithm
is vastly better than naively doing linear algebra
over the number field generated by the eigenvalues.  It
only involves linear algebra over the base field, and also
yields a very compact representation for the answer, which
is much better than writing the eigenvalues in terms of
a power basis for a number field.

\subsection{Computing Projection Onto a Subspace}\label{sec:projection}
Suppose $V = \oplus W_i$ is the $\T$-simple decomposition
of $V$ and fix a factor $W_j$.
Then there is a unique $\T$-equivariant homomorphism
$$ 
 \pi_j : V \to W_j
$$
such that $\pi_j$ restricted to $W_j$ is the identity map.
We compute $\pi_j$ using the following algorithm.
\begin{algorithm}{Projection Matrix}\label{alg:proj}%
INPUT: Decomposition $V=\oplus W_i$.\\
OUTPUT: Matrix of Projection Onto a Factor $W_j$.
\begin{enumerate}
\item
 Let~$B$ be the matrix whose columns
are got by concatenating together a basis for the factors $W_i$. 
\item Compute $C=B^{-1}$ using, e.g., computation of the reduced
row echelon form of the augmented matrix $[B|I]$, which is $[I|C]$.
\item The projection matrix onto $W_j$ is the submatrix of~$C$ got from
the rows corresponding to $W_j$, i.e., if the basis vectors for $W_j$
appear as columns~$n$ through~$m$ of~$B$, then the projection matrix
is got from rows~$n$ through~$m$ of~$C$.  
\end{enumerate}
\end{algorithm}
The algorithm works because the
matrix of projection, written with respect to the basis of columns
for~$B$, is just given by an $m-n+1$ row slice~$P$ of a diagonal
matrix~$D$ with $1$'s in the $n$ through $m$ positions. Thus projection
with respect to the standard basis is given by $P C$, which is
just rows~$n$ through~$m$ of $B^{-1}$.

Note that we only have to do the work of inverting~$B$ once; we then
get all projection maps $\pi_i$ for all~$i$ by taking appropriate
submatrices of~$B$.


\subsection{Systems of Eigenvalues}
\begin{algorithm}{System of Eigenvalues}\label{alg:eigsys}%
INPUT: A $\T$-simple subspace $W\subset V$ of modular symbols.\\
OUTPUT:
Maps $\psi$ and $e$, where 
$
   \psi : \T_K \to W
$ 
is a $K$-linear map  and $e:W \isom L$ is an isomorphism of $W$ with a
number field $L$, such that $a_n = e (\psi(T_n))$ is
the eigenvalue of the $n$th Hecke operator acting on a fixed
$\T$-eigenvector in $W\tensor\Qbar$.  Thus 
$f = \sum_{n=1}^{\infty} i(\psi(T_n)) q^n$ is a cuspidal modular eigenform.
\begin{enumerate}


\item{}[Compute Projection] 
Using Algorithm~\ref{alg:proj},
compute the $\T$-equivariant
projection map $\pi: V \to W$.   
Remark: We can replace $\pi$ by any
$K$-vector space map $\vphi:V\to W'$ such that $\Ker(\pi) = \Ker(\vphi)$, 
where $W'$ is any vector space, and the rest of the algorithm works. For example,
one could find such a~$\vphi$ by finding the simple submodule
of $V^*=\Hom(V,K)$ that is isomorphic to~$W$, e.g., by applying
Algorithm~\ref{alg:decomp2} to $V^*$ with $T$ replaced by
the transpose of $T$.   This is what Cremona means in his book
when he talks about find ``left eigenvectors''.

\item{}[Choose $v$]\label{step:eig:v}
 Choose a nonzero element $v\in{}V$ such
that $\pi(v)\neq 0$ and computation of $T_n(v)$ is ``easy'', e.g., choose~$v$
to be a Manin symbol.

\item{}[Map From Hecke Ring] Let $\psi$ be the map $\T \to W$, given 
by $\psi(t) = \pi(t v)$.  Note that computation of $\psi$
is relatively easy, because $v$ was chosen so that
$tv$ is relatively easy to compute.  In particular, 
if $t=T_p$, we do not need to compute the full matrix
of $T_p$ on~$V$; instead we just compute $T_p(v)$.
(We can even often compute eigenvalues for {\em all}
the factors $W_i$ just by computing one evaluation
$T_p(v)$ for a single easy $v$!)


\item{}[Find Generator]\label{alg:ap:gen} 
Find a random $T \in \T$ such that the iterates 
$$\psi(T^0), \quad \psi(T), \quad \psi(T^2), \quad \ldots, \quad \psi(T^{d-1})$$
are a basis for~$W$, where $W$ has dimension~$d$. For example, the $T$
that was used to compute the decomposition $V=\oplus W_i$
earlier would work.  

\item{}[Characteristic Polynomial] Compute the characteristic polynomial 
$f$ of $T|_W$, and let $L=K[x]/(f)$
  be the number field generated by a root of $f$.  Because
  of how we chose $T$ in Step~\ref{alg:ap:gen}, the minimal
  and characteristic polynomials of $T|_W$ are equal, and
  both are irreducible, so~$L$ is an extension of~$K$ 
  of degree~$d=\dim(W)$. 
  If in Step~\ref{alg:ap:gen},
  we used the~$T$
  used to compute the decomposition $V=\oplus W_i$ earlier,
  then we already know~$f$.

\item{}[Field Structure] 
In this step we endow $W$ with a field structure.
Let $e:W\to L$ be the unique $K$-linear isomorphism such that 
$$
  e(\psi(T^i)) \con x^i \pmod{f}
$$
for $i = 0,1,2,...,\deg(f)-1$. 
The map $e$ is uniquely determined since the $\psi(T^i)$ are a 
basis for~$W$.  To compute $e$, we compute
the change of basis matrix from the standard basis for~$W$ 
to the basis $\{\psi(T^i)\}$.  
This change of basis matrix is the inverse
of the matrix whose rows are the $\psi(T^i)$ 
for $i=0,...,\deg(f)-1$.

\item{}[Hecke Eigenvalues] Finally note that we have
$$       
          a_n = e(\psi(T_n)) = e(\pi(T_n(v)))
$$        
for Hecke operators $T_n$, where the $a_n$ are eigenvalues.
Output the maps $\psi$ and $e$ and terminate. 
\end{enumerate}
\end{algorithm}

One reason we separate $\psi$ and~$e$ is that when $\dim(W)$ is large,
the values
$\psi(T_n)$ tend to take not too much space to store and are easier to
compute, whereas each one of the values $e(\psi(n))$ are {\bf huge}.
John Cremona initially suggested to me the idea of 
separating these two maps.   The function $e$ typically involves large
numbers if $\dim(W)$ is large,
since $e$ is got from the iterates of a single vector.
For many applications, e.g.,
databases, it is better to store a matrix that defines~$e$ 
and the images under $\psi$ of many $T_n$.

\begin{remark}          
How can we find a minimal collection of information from 
which we can compute the map $n\mapsto{} \psi(T_n)$?  Do we need 
the whole modular symbols presentation?  No, we need only the
image of each generating Manin symbol in $M$ under
projection.  The Hecke operators are then given by the
standard Manin symbols formulas, where we reduce all
resulting Manin symbols to their image in $M$.  
\end{remark}

% \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!}

\begin{example}
The space $S_2(\Gamma_0(23))$ of cusp forms has dimension~$2$,
and is spanned by two $\Gal(\Qbar/\Q)$-conjugate newforms, 
one of which is
$$
f = \sum q + aq^2 + (-2a - 1)q^3 + (-a - 1)q^4 + 2aq^5 + \cdots,
$$
where $a=(-1+\sqrt{5})/2$.
We will use Algorithm~\ref{alg:eigsys} to compute a few
of these coefficients.

The space $\sM_2(\Gamma_0(23))^+$ of modular symbols has dimension~$3$.
It has as basis the following basis of Manin symbols:
$$
[(0,0)],\quad [(1,0)], \quad [(0,1)],
$$
where we use square brackets to differentiate Manin symbols
from vectors. 
The Hecke operator 
$$
T_2 = \left(\begin{array}{ccc}
3&0&0\\
0&0&2\\
-1&1/2&-1
\end{array}\right)
$$ has characteristic polynomial 
$(x-3)(x^2 + x - 1)$.  The kernel of $T_2-3$ corresponds to the span of
the Eisenstein series of
level~$23$ and weight~$2$, and the kernel $V$ of $T_2^2+T_2-1$
corresponds to $S_2(\Gamma_0(23))$.  (We could also 
have computed~$V$ as the kernel of the boundary map 
$\sM_2(\Gamma_0(23))^+\to \sB_2(\Gamma_0(23))^+$.)
Each of the following steps corresponds to the same
step of Algorithm~\ref{alg:eigsys}.
\begin{enumerate}
\item{}[Compute Projection]
Using the Algorithm~\ref{alg:proj}, we compute projection
onto $V$.  The matrix whose first two columns are the echelon basis for $V$ and whose
last column is the echelon basis for the Eisenstein subspace is
$$
\left(\begin{array}{ccc}
0&0&1\\
1&0&-2/11\\
0&1&-3/11
\end{array}\right)
$$
and 
$$
 B^{-1} = \left(\begin{array}{ccc}
2/11&1&0\\
3/11&0&1\\
1&0&0
\end{array}\right),
$$
so projection onto $V$ is given by the first two rows:
$$
  \pi = \left(\begin{array}{ccc}
2/11&1&0\\
3/11&0&1
\end{array}\right).
$$


\item{}[Choose~$v$] Let $v=(0,1,0)^t$. Notice that $\pi(v)=(1,0)^t\neq 0$, 
and $v=[(1,0)]$ is a sum of
only one Manin symbol, so it is easier to compute Hecke operators on~$v$
using Heilbronn matrices.

\item{}[Map From Hecke Ring] 
This step is purely conceptual, since no actual work needs to be
done.  We illustrate it by computing $\psi(T_1)$ and $\psi(T_2)$. 
 We have
$$\psi(T_1) = \pi(v) = (1,0)^t,$$
and 
$$\psi(T_2) = \pi(T_2(v)) = \pi((0,0,1/2)^t) = (0,1/2)^t.$$

\item{}[Find Generator] We have 
$$\psi(T_2^0) = \psi(T_1) = (1,0)^t,$$
which is clearly independent from $\psi(T_2)=(0,1/2)^t$.  Thus we
find that the image of the powers of $T=T_2$ generate $V$.

\item{}[Characteristic Polynomial] It is easy to compute the
characteristic polynomial of a $2\times 2$ matrix.  The matrix
of $T_2|_V$  is $\abcd{0}{2}{1/2}{-1}$, which has characteristic
polynomial $f=x^2+x-1$.   Of course, we already knew this because
we computed $V$ as the kernel of $T_2^2+T_2-1$.

\item{}[Field Structure] We have 
$$\psi(T_2^0) = \pi(v) = (1,0)^t
\text{ and } 
\psi(T_2) = (0,1/2).$$
The matrix with rows the $\psi(T_2^i)$
is $\abcd{1}{0}{0}{1/2}$, which has inverse $e=\abcd{1}{0}{0}{2}$.
The matrix $e$ defines an isomorphism between $V$ and
the field $$L=\Q[x]/(f) = \Q((-1+\sqrt{5})/2).$$
For example, $e((1,0))=1$ and $e((0,1))=2x$, where $x=(-1+\sqrt{5})/2$.

\item{}[Hecke Eigenvalues] We have $a_n = e(\Psi(T_n))$.  For example,
\begin{align*}
  a_1 &= e(\Psi(T_1)) = e((1,0)) = 1\\
  a_2 &= e(\Psi(T_2)) = e((0,1/2)) = x\\
  a_3 &= e(\Psi(T_3)) = e(\pi(T_3(v))) = e(\pi((0,-1,-1)^t)) = e((-1,-1)^t) = -1-2x\\
  a_4 &= e(\Psi(T_4)) = e(\pi((0,-1,-1/2)^t)) = e((-1,-1/2)^t) = -1-x\\
  a_5 &= e(\Psi(T_5)) = e(\pi((0,0,1)^t)) = e((0,1)^t) = 2x\\
  a_{23} &=   e(\Psi(T_{23})) = e(\pi((0,1,0)^t)) = e((1,0)^t) = 1\\
  a_{97} &= e(\Psi(T_{23})) = e(\pi((0,14,3)^t)) = e((14,3)^t) = 14+6x\\\\
 \end{align*}
   
\end{enumerate}
\end{example}

It is difficult to appreciate this algorithm without seeing how big
the coefficients of the power series expansion of a newform typically
are, when the newform is defined over a large field. For such examples,
please browse \cite{mfd}.
 








%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%
%   NEW CHAPTER 
%
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%










\chapter{Periods and Special Values of $L$-functions}\label{ch:periods}
\label{sec:periods}

This chapter is about how to approximate the integration
pairing, and the induced period mapping from modular symbols
to a complex vector space.


Let $\Gamma$ be a subgroup of $\SL_2(\Z)$ that contains
$\Gamma_1(N)$ for some $N$, and 
suppose
$$
  f =\sum_{n\geq 1} a_n q^n\in S_k(\Gamma).
$$
is a newform.
In this chapter we describe how to approximately compute the complex
period mapping
$$
   \Phi_f : \sM_k(\Gamma) \to \C,
$$
given by 
$$
  \Phi_f(P\{\alpha,\beta\}) = \langle f,\, P\{\alpha,\beta\} \rangle
  = \int_{\alpha}^{\beta} f(z) P(z,1) d z,
$$
as in Section~\ref{sec:pairing}.  As an application, we approximate
the special values $L(f,j)$, for $j=1,2,\ldots, k-1$ using
(\ref{eqn:lfunc_ms}) from page~\pageref{eqn:lfunc_ms}.  We also
compute the period lattice attached to a modular abelian variety,
which is an important step, e.g., in enumeration of $\Q$-curves [cite
Gonzalez, Lario, etc.] or computation of a curve whose Jacobian is a
modular abelian variety $A_f$ [cite X.~Wang and Ph.D. thesis from
Essen].

The algorithms that we describe in this chapter are a generalization
of the ones in \cite{cremona:algs} to other congruence subgroups,
newforms of degree bigger than~$1$, and weight bigger than~$2$.

\section{The Period Mapping and Complex Torus Attached to a Newform}
Fix a newform $f\in S_k(\Gamma)$, where $\Gamma_1(N)\subset \Gamma$
for some~$N$.  Let $f_1,\ldots, f_d$ be the
$\Gal(\Qbar/\Q)$-conjugates of $f$, where $\Gal(\Qbar/\Q)$ acts via
its action on the Fourier coefficients, which are algebraic integers.
Let
$$
  V_f = \C f_1 \oplus \cdots \oplus \C f_d \subset S_k(\Gamma)
$$
be the subspace of cusp forms spanned by the 
$\Gal(\Qbar/\Q)$-conjugates of~$f$.  
The integration pairing induces a $\T$-equivariant homomorphism 
$$ 
  \Phi_f : \sM_k(\Gamma) \ra V_f^* = \Hom_\C(V_f,\C),
$$
from modular symbols to the $\C$-linear dual $V_f^*$ of $V_f$.
Here $\T$ acts on $V_f^*$ via $(\vphi.t)(x) = \vphi(tx)$,
and this homomorphism is $\T$-stable by Theorem~\ref{thm:tequivar}.
The \defn{complex torus attached to $f$} is the
quotient 
$$
  A_f(\C) = V_f^*/\Phi_f(\sS_k(\Gamma,\Z)).
$$
Note that $\sS_k(\Gamma,\Z)=\sS_k(\Gamma)$, and we include
the $\Z$ in the notation here just to emphasize that
these are integral modular symbols.

When $k=2$, we can also construct $A_f$ as a quotient
of the modular Jacobian $\Jac(X_\Gamma)$, so $A_f$ is an 
abelian variety canonically defined over~$\Q$.

In general, we have an exact sequence
$$
  0 \to \Ker(\Phi_f) \to  \sS_k(\Gamma) \to V_f^* \to A_f(\C) \to 0.
$$
When $k=2$, we have an exact sequence
$$
    0 \to B \to \Jac(X_\Gamma) \to A_f \to 0,
$$
where $X_\Gamma=\Gamma\backslash \h^*$ is the modular curve
associated to $\Gamma$ and $B$ is some abelian variety.
We have 
$$\H_1(\Jac(X_\Gamma),\Z)\isom \H_1(X_\Gamma,\Z)\isom \sS_2(\Gamma),$$
so the induced map on homology is 
$$
  0 \to \H_1(B,\Z) \to \sS_2(\Gamma) \to \H_1(A_f,\Z).
$$
Thus we can identify the homology of $A_f$ with a quotient
of modular symbols.  
\begin{remark}[Warnings] In the literature, the
notation $A_f$ is sometimes used for the abelian
subvariety of $C\subset \Jac(X_\Gamma)$ attached to~$f$.
Here $C$ is the abelian variety dual of our $A_f$.
Also, $f$ could be a newform for a different group
$\Gamma'$, and then the corresponding abelian variety
$A_f$ could be different, so $A_f$ depends on the
choice of $\Gamma$.  For example, any newform for $\Gamma_0(N)$
is also a newform for $\Gamma_1(N)$, but the corresponding
$A_f$'s need not be equal.
\end{remark}

\begin{remark}
  When $k>2$, it is my understanding that the complex torus $A_f(\C)$
  is an abelian variety over~$\C$.  This additional abelian variety
  structure comes somehow from the Petersson inner product.  I believe
  Shimura proves this in \cite{shimura:surles}.  \edit{I don't have
    his paper with me right now, so can't confirm this.  This would
  be a good student project.}
\end{remark}



\section{Extended Modular Symbols}\label{defn:extendedmodsyms}%
In this section, we extend the notion of modular
symbols to allows symbols of the form
$P\{w,z\}$ where~$w$ and~$z$ are
arbitrary elements of $\h^*=\h\union\P^1(\Q)$.  
\begin{definition}[Extended Modular Symbols]
  The abelian group $\esM_k$ of \defn{extended modular symbols of
    weight~$k$} is the $\Z$-span of symbols $P\{w,z\}$, with $P\in
  V_{k-2}$ a homogenous polynomial of degree $k-2$ with integer
  coefficients, modulo the relations $$P\cdot (\{w,y\} + \{y,z\} +
  \{z,w\}) = 0$$
  and modulo any torsion.
\end{definition}
%The space $\esM_k$ is of uncountable rank over $\Z$.

Fix a finite-index subgroup $\Gamma\subset \SL_2(\Z)$.
Just as for usual modular symbols, $\esM_k$ is equipped with
an action of $\Gamma$, and we
define the space of extended modular of weight~$k$
for $\Gamma$ to be the biggest quotient
$$
  \esM_k(\Gamma) = (\esM_k/\{\gamma x - x : \gamma\in\Gamma, x \in \esM_k\})/\tor
$$
of $\esM_k(\Gamma)$ that is torsion free and fixed by $\Gamma$.

The integration  pairing extends naturally to a pairing
\begin{equation}\label{eqn:extpair}
      \left(S_k(\Gamma) \oplus \overline{S}_k(\Gamma)\right) 
\times 
\esM_k(\Gamma) 
\to \C,
    \end{equation}
where we recall that  $\overline{S}_k(\Gamma)$ denotes 
the space of antiholomorphic cusp forms.
Moreover, if
$$
  \iota: \sM_k(\Gamma)\hookrightarrow \esM_k(\Gamma)
$$
is the natural embedding, then $\iota$
respects (\ref{eqn:extpair}) in the sense that
for all $f \in S_k(\Gamma) \oplus \overline{S}_k(\Gamma)$
and $x\in \sM_k(\Gamma)$, we have
$$
   \langle f, x\rangle = \langle f , \iota(x)\rangle.
$$
As we will see soon, it
is often useful to replace
$x\in\sM_k(\Gamma)$ first by $\iota(x)$, and then 
by an equivalent sum $\sum y_i$ of symbols 
$y_i\in \esM_k(N,\eps)$ such that
$\langle f, \sum y_i \rangle$ is easier to 
compute numerically than $\langle f, x\rangle$.

For any Dirichlet character $\eps$ modulo~$N$ we also define
$\esM_k(\Gamma_1(N),\eps)$ to be the quotient of $\esM_k(\Gamma_1(N),\Z[\eps])$
by the relations $\gamma(x) - \eps(\gamma) x$, for all 
$\gamma \in \Gamma_0(N)$, and modulo any torsion.  (Recall
that if $\gamma=\abcd{a}{b}{c}{d}$, then $\eps(\gamma)=\eps(d)$.)


\section{Numerically Approximating Period Integrals}
\label{sec:numper}
In this section we assume $\Gamma$ is a congruence subgroup
of $\SL_2(\Z)$ that contains $\Gamma_1(N)$ for some~$N$.
Suppose~$\alp\in \h$, so $\Im(\alpha)>0$ and $m$ is
an integer such that $0\leq m\leq k-2$,
and consider the extended modular symbol
$X^mY^{k-2-m}\{\alp,\infty\}$.
Given an arbitrary cusp form $f =\sum_{n=1}^{\infty} a_n q^n\in S_k(\Gamma)$,
we find that
\begin{align}
\Phi_f(X^mY^{k-2-m}\{\alpha,\infty\}) &=
\left\langle f, \, X^mY^{k-2-m}\{\alpha,\infty\}\right\rangle \\
&= \int_{\alpha}^{i\infty} f(z)z^m dz \\
&=  \sum_{n=1}^{\oo} a_n \int_{\alpha}^{i\infty} e^{2\pi i n z} z^m dz.
\label{eqn:intsum}
\end{align}
The reversal of summation and integration is justified because
the imaginary part of~$\alp$ is positive so that the sum
converges absolutely.  This is made explicit in the following
lemma, which one proves by repeated integration by parts.
\begin{lemma}\label{lem:intexp}
\begin{equation}\label{intexp}
\int_{\alpha}^{i\infty} e^{2\pi i n z} z^m dz
   \,\,=\,\, e^{2\pi i n \alpha} 
      \sum_{s=0}^m \left(
          \frac{(-1)^s \alpha^{m-s}}
              {(2\pi i n)^{s+1}}
         \prod_{j=(m+1)-s}^m j\right).
\end{equation}
\end{lemma}
% \begin{remark}
% The integers $m\in \{0,1,\ldots, k-2\}$ are
% sometimes called \defn{critical integers} for~$f$.
% \end{remark}

In practice we will be interested in computing the period map $\Phi_f$
when $f \in S_k(\Gamma)$ is a newform.  Since $f$ is a newform, there
is a Dirichlet character $\eps$ such that $f \in
S_k(\Gamma_1(N),\eps)$.  The period map $\Phi_f : \sM_k(\Gamma) \to
\C$ then factors through the quotient $\sM_k(\Gamma_1(N),\eps)$, so it
suffices to compute the period map on modular symbols in
$\sM_k(\Gamma_1(N),\eps)$.

The following proposition is a higher weight
analogue of \cite[Prop. 2.1.1(5)]{cremona:algs}.
\begin{proposition}\label{modsym-errorterm}
For any $\gamma\in \Gamma_0(N)$, $P\in V_{k-2}$ and $\alp\in\h^*$,
we have the following relation in $\esM_k(\Gamma_1(N),\eps)$:
\begin{eqnarray}
P\{\oo, \gamma(\oo)\}
  &=& P\{\alp,\gamma(\alp)\} + (P - \eps(\gamma)\gamma^{-1}P)\{\oo,\alp\}\\
  &=& \eps(\gamma)(\gamma^{-1}P)\{\alp, \oo\} - P\{\gamma(\alp),\oo\}.
\label{eqn:erroreqn}
\end{eqnarray}
\end{proposition}
\begin{proof}
By definition, if $x\in\sM_k(N,\eps)$ is a modular symbol 
and $\gamma\in\Gamma_0(N)$ then $\gamma{}x=\eps(\gamma)x$.
Thus $\eps(\gamma)\gamma^{-1}x=x$, so 
\begin{eqnarray*}
P\{\oo, \gamma(\oo)\}
  &=& P\{\oo,\alp\} + P\{\alp,\gamma(\alp)\} + P\{\gamma(\alp),\gamma(\oo)\}\\
  &=& P\{\oo,\alp\} + P\{\alp,\gamma(\alp)\} + \eps(\gamma)\gamma^{-1}(P\{\gamma(\alp),\gamma(\oo)\})\\
  &=& P\{\oo,\alp\} + P\{\alp,\gamma(\alp)\} + \eps(\gamma)(\gamma^{-1}P)\{\alp, \oo\}\\
  &=& P\{\alp,\gamma(\alp)\} + P\{\oo,\alp\}  - \eps(\gamma)(\gamma^{-1}P)\{\oo, \alp\}\\
  &=& P\{\alp,\gamma(\alp)\} + (P - \eps(\gamma)\gamma^{-1}P)\{\oo,\alp\}.
\end{eqnarray*}
The second equality in the statement of the proposition now follows easily.
\end{proof}
In the classical case of weight two and trivial character,
the ``error term'' $(P - \eps(\gamma)\gamma^{-1}P)\{\oo,\alp\}$ 
vanishes.  In general this term does 
not vanish.  However, we can suitably modify the formulas 
found in \cite[2.10]{cremona:algs}, and still obtain an algorithm
for computing period integrals.

\begin{algorithm}{Period Integrals}\vspace{-2ex}
INPUT: A matrix $\gamma\in\Gamma_0(N)$,  a polynomial $P\in V_{k-2}$ and 
a cuspidal modular form $f\in S_k(\Gamma_1(N),\eps)$ 
presented as a $q$-expansion to some precision.\\
OUTPUT: The period integral
$\langle g, \,P\{\oo, \gamma(\oo)\}\rangle$,
computed to some precision.
\begin{steps}
\item Write $\gamma=\abcd{\hfill a}{b}{cN}{d}\in\gzero$, with $a,b,c,d\in\Z$,
and set $\alpha = \frac{-d+i}{cN}$ in Proposition~\ref{modsym-errorterm}.
\item 
Replacing~$\gamma$ by $-\gamma$ if necessary,
we find that the imaginary parts of~$\alpha$ and 
$\gamma(\alpha)=\frac{a+i}{cN}$
are both equal to the positive number $\frac{1}{cN}$.
\item 
Use (\ref{eqn:intsum}) and Lemma~\ref{lem:intexp} to 
compute the period integrals of
Proposition~\ref{modsym-errorterm}.
\end{steps}
\end{algorithm}
\begin{remark}
I have not specified the precision of the output in terms of the
input, which is a {\em major} problem with this algorithm.  
\edit{Do this using a bound on Fourier coefficients, like
the one Andrei Jorza showed me.}
\end{remark}

It would be nice to know that the modular symbols
of the form $P\{\oo,\gamma(\oo)\}$, for $P\in V_{k-2}$ and
$\gamma\in \Gamma_0(N)$ generate a large subspace
of $\sM_k(\Gamma_1(N),\eps)\tensor\Q$.
When $k=2$ and $\eps=1$, 
Manin proved in~\cite{manin:parabolic},
that the map $\Gamma_0(N)\ra H_1(X_0(N),\Z)$ 
sending~$\gamma$ to $\{0,\gamma(0)\}$ is a surjective
group homomorphism.  When $k>2$, I have not found any similar
group-theoretic statement.  However, we have the following
theorem.

\begin{theorem}\label{onlyoo}
Any element of $\sS_k(\Gamma_1(N),\eps)$ can be written in the form
$$\sum_{i=1}^n P_{i}\{\infty,\gamma_i(\infty)\}$$
for some $P_i\in V_{k-2}$ and $\gamma_i\in\gzero.$
Moreover, $P_i$ and $\gamma_i$ can be chosen so that 
$\sum  P_i = \sum \eps(\gamma_i)\gamma_i^{-1}(P_i)$,
so the error term in (\ref{eqn:erroreqn}) vanishes.
\end{theorem}
\begin{figure}
\begin{center}
\begin{picture}(305,150)(0,0)
%\put(-20,10){\parbox[t][5mm][l]{2in}{
%$$I_1=\int_\infty^{\gamma \infty}P(z,1)f(z)dz
%+\int_{\gamma \infty}^{\beta \infty}Q(z,1)f(z)dz$$}
%}
%\put(-20,200){\parbox[t][5mm][l]{2in}{
%$$I_2=\int_\alpha^{\gamma \alpha}P(z,1)f(z)dz
%+\int_{\gamma \alpha}^{\beta \alpha}Q(z,1)f(z)dz$$}}
\put(-10,10){\line(1,0){200}}
\put(10,10){\circle*{3}}
\put(10,0){$\infty$}
\qbezier(10,10)(50,40)(75,10)
%thickening
%\qbezier(10,11)(50,41)(75,11)
%endthickening
\put(49,25){\vector(1,0){1}}
\put(45,28){$P$}
\put(75,10){\circle*{3}}
\put(75,0){$\gamma \infty$}
\qbezier(75,10)(130,50)(140,10)
\put(120,30){\vector(1,0){1}}
\put(115,34){$Q$}
\put(140,10){\circle*{3}}
\put(140,0){$\beta \infty$}
\put(20,90){\circle*{3}}
\put(17,96){$\alpha$}
\qbezier(20,90)(50,120)(55,60)
\put(40,100){\vector(1,0){1}}
\put(40,104){$P$}
\put(55,60){\circle*{3}}
\put(60,54){$\gamma \alpha$}
\qbezier(55,60)(70,180)(100,140)
\put(87,150){\vector(1,0){1}}
\put(85,154){$Q$}
\put(100,140){\circle*{3}}
\put(100,146){$\beta \alpha$}
\comment{
%first vertical wiggle
\qbezier(10,10)(-10,30)(10,50)
\qbezier(10,50)(40,70)(20,90)
\put(5,45){\vector(2,3){1}}
%2nd vertical wiggle
\qbezier(75,10)(90,30)(75,40)
\qbezier(75,40)(60,50)(55,60)
\put(69,45){\vector(1,-1){1}}
\put(80,35){\vector(-1,2){1}}
%3rd vertical wiggle
\qbezier(140,10)(160,30)(140,50)
\qbezier(140,50)(90,80)(110,90)
\qbezier(110,90)(130,100)(100,120)
\qbezier(100,120)(90,130)(100,140)
\put(110,90){\vector(-1,-1){1}}
}
%vertical arrows
\put(100,50){\vector(-1,4){10}}
\put(50,40){\vector(-1,4){10}}
\put(140,155){\parbox[t][4in][l]{2in}{
The modular symbol 
$$P\{\infty ,\gamma \infty \}+Q\{\gamma \infty ,\beta \infty \}$$
$$\hspace{2em}=P\{\infty ,\gamma \infty \}+Q\{\infty ,\beta \infty \}-Q\{\infty ,\gamma \infty \}$$
can be ``transported'' to 
$$P\{\alpha,\gamma \alpha\}+Q\{\gamma \alpha,\beta \alpha\},$$
provided that\\
$$P\,+\,Q\,-\,Q=\gamma ^{-1}P\,+\,\beta ^{-1}Q\,-\,\gamma ^{-1}Q.$$\\
%In this case, $I_1=I_2$.
}}
\end{picture}
\end{center}
\caption{``Transporting'' a transportable modular symbol.}
\label{fig:trans}
\end{figure}

The author and Helena Verrill prove this theorem 
in \cite{stein-verrill:transportable}.  See also [[what that 
Edixhoven student is writing up...]]  The condition
that the error term vanishes, means that one can replace
$\infty$ by any $\alpha$ in the expression for the modular symbol
and obtain an equivalent modular symbol.  For this reason,
we call such modular symbols \defn{transportable}, as illustrated
in Figure~\ref{fig:trans}.

Note that in general not every element of the form
$P\{\oo,\gamma(\oo)\}$ must lie in $\sS_k(N,\eps)$.  However, if
$\gamma P = P$ then $P\{\oo,\gamma(\oo)\}$ does lie in
$\sS_k(N,\eps)$.  It would be interesting to know under what
circumstances $\sS_k(N,\eps)$ is generated by symbols of the form
$P\{\oo,\gamma(\oo)\}$ with $\gamma P = P$.  This sometimes fails for
$k$ odd; for example, when $k=3$ the condition $\gamma P = P$ implies
that $\gamma\in\gzero$ has an eigenvector with eigenvalue~$1$, hence
is of finite order.  When~$k$ is even the author can see no
obstruction to generating $\sS_k(N,\eps)$ using such symbols.

\newpage
\mbox{}
\newpage
\section{Speeding Convergence Using the Atkin-Lehner Operator}\label{sec:wntrick}
%{\bf WARNING:} {\em Throughout this section we assume that~$k$ is even.}

Let $w_N = \abcd{0}{-1}{N}{\hfill 0} \in M_2(\Z)$.
Consider the Atkin-Lehner involution $W_N$ on $M_k(\Gamma_1(N))$,
which is defined by
\begin{align*}
   W_N(f) &= N^{(2-k)/2} \cdot f|_{[w_N]_k}\\
          &= N^{(2-k)/2} \cdot f\left(-\frac{1}{Nz}\right) \cdot N^{k-1} \cdot (Nz)^{-k}\\
          &= N^{-k/2} \cdot z^{-k} \cdot f\left(-\frac{1}{Nz}\right).
\end{align*}
Here we take the positive square root if $k$ is odd.
Then $W_N^2 = (-1)^k$ is an involution when $k$ is even.

There is an operator on modular symbols, which we also denote
$W_N$, which is given by
\begin{align*}
 W_N(P \{\alpha, \beta\}) &= N^{(2-k)/2} \cdot w_N(P) \{w_N(\alpha), w_N(\beta)\}\\
  &=N^{(2-k)/2} \cdot P(-Y,NX) \left\{-\frac{1}{\alpha N}, -\frac{1}{\beta N}\right\},
 \end{align*}
and one has that if $f \in S_k(\Gamma_1(N))$ and $x\in\sM_k(\Gamma_1(N))$, then
$$
  \langle W_N(f), x\rangle = \langle f, W_N(x) \rangle.
$$

If $\eps$ is a Dirichlet character mod~$N$, then
the operator $W_N$ sends $S_k(\Gamma_1(N),\eps)$ to
$S_k(\Gamma_1(N),\overline{\eps})$.  Thus if $\eps^2=1$,
then $W_N$ preserves $S_k(\Gamma_1(N),\eps)$.  In particular,
$W_N$ acts on $S_k(\Gamma_0(N))$. 

 
The follow proposition shows how to compute the pairing
$\langle f, P\{\oo,\gamma(\oo)\} \rangle$ under
certain restrictive assumptions. 
It generalizes a result of~\cite{cremona:periods} to 
higher weight.  %(Compare also~\cite{goldfeld:complexity}.)

\begin{proposition}\label{wntrick}
Let $f \in S_k(\Gamma_1(N),\eps)$ be a cusp form which is
an eigenform for the Atkin-Lehner operator~$W_N$ 
having eigenvalue $w\in \{\pm 1\}$ (thus $\eps^2=1$ and~$k$ is even). 
Then for any $\gamma\in\Gamma_0(N)$ and any 
$P\in V_{k-2}$, with the property that $\gamma P = \eps(\gamma)P$, we have 
the following formula, valid for any $\alpha\in\h$:
\begin{align*}
\langle g, P\{\oo,\gamma(\oo)\}\rangle &= 
 \Bigl\langle g, \quad w \frac{P(Y,-NX)}{N^{k/2-1}}\{w_N(\alp),\oo\}\\
      &\qquad\qquad  +
   \left(P - w \frac{P(Y,-NX)}{N^{k/2-1}} \right)\left\{i/\sqrt{N},\oo\right\} 
        -P\left\{\gamma(\alp),\oo\right\} \Bigr\rangle.
\end{align*}
Here $\ds w_N(\alpha) = -\frac{1}{N\alpha}$. 
\end{proposition}
\begin{proof}
By Proposition~\ref{modsym-errorterm} our condition on~$P$
implies that $P\{\oo,\gamma(\oo)\}= P\{\alp,\gamma(\alp)\}$. 
The steps of the following computation are described below.\vspace{1ex}\\
\begin{align*}
\Bigl\langle f,\quad &P\{\alp,\gamma(\alp)\}\Bigr\rangle \\
  &=\left\langle 
  f,\quad P\{\alp,i/\sqrt{N}\} + P\{i/\sqrt{N},W(\alp)\}+P\{W(\alp),\gamma(\alp)\}
           \right\rangle \\
  &=\left\langle f,\quad w \frac{W(P)}{N^{k/2-1}}
        \{W(\alp),i/\sqrt{N}\} + P\{i/\sqrt{N},W(\alp)\}+P\{W(\alp),\gamma(\alp)\}
           \right\rangle \\
  &=\left\langle f,\quad \left(w \frac{W(P)}{N^{k/2-1}}-P\right)
        \{W(\alp),i/\sqrt{N}\} +P\{W(\alp),\oo\} - P\{\gamma(\alp),\oo\}
           \right\rangle\\
  &= \left\langle f,\quad w \frac{W(P)}{N^{k/2-1}}\{W(\alp),\oo\}
        +\left(P - w \frac{W(P)}{N^{k/2-1}}\right)\{i/\sqrt{N},\oo\} 
        -P\{\gamma(\alp),\oo\} \right\rangle.\\
      \end{align*}
For the first step, we break the path into three paths.
In the second step, we apply the $W$-involution to the first
term, and use that the action of~$W$ is compatible with
the pairing $\langle \,,\, \rangle$ and that~$f$ is an eigenvector
with eigenvalue~$w$. The third step involves
combining the first two terms and breaking up the third.
In the final step, we replace $\{ W(\alp), i/\sqrt{N}\}$
by $\{W(\alp),\infty\}+\{\infty,i/\sqrt{N}\}$ and regroup.
\end{proof}

A good choice for~$\alp$ is 
$\alp=\gamma^{-1}\left(\frac{b}{d}+\frac{i}{d\sqrt{N}}\right)$,
so that $W(\alp) = \frac{c}{d}+\frac{i}{d\sqrt{N}}$.
This maximizes the minimum of the imaginary parts 
of~$\alp$ and~$W(\alp)$, which results in series that converge
more quickly.

Let $\gamma=\abcd{a}{b}{c}{d}\in \Gamma_0(N)$.  
The polynomial
$$P(X,Y) = (cX^2 + (d-a)XY - bY^2)^{\frac{k-2}{2}}$$
satisfies $\gamma(P)=P$. 
We obtained this formula by viewing $V_{k-2}$ as
the $(k-2)$th symmetric product of the two-dimensional
space on which $\gzero$ acts naturally.  For example,
observe that since $\det(\gamma)=1$
the symmetric product of two eigenvectors for~$\gamma$ is an eigenvector
in $V_{2}$ having eigenvalue~$1$. 
For the same reason, if $\eps(\gamma)\neq 1$, there need
not be a polynomial $P(X,Y)$ such that $\gamma(P)=\eps(\gamma) P$.
One remedy is to choose another~$\gamma$ so that $\eps(\gamma)=1$.

Since the imaginary parts of the terms
$i/\sqrt{N}$, $\alp$ and $W(\alp)$ in the proposition
are all relatively large, the sums appearing at
the beginning of Section~\ref{sec:numper} 
converge quickly if~$d$ is small.
It 
is {\bf extremely} important to choose~$\gamma$ 
in Proposition~\ref{wntrick} with~$d$ small, otherwise
the series will converge very slowly.

\begin{remark}
  There should be a generalization of Proposition~\ref{wntrick}
  without the restrictions that $\eps^2=1$ and $k$ is even.  I would
  love to include something like this in the final version of this
  book.  Student project?
\end{remark}

\subsection{Another Atkin-Lehner Trick}
  Suppose $E$ is an elliptic curve and let $L(E,s)$ be the
  corresponding $L$-function.  Let $\eps\in\{\pm 1\}$ be the root
  number of $E$, i.e., the sign of the functional equation for
  $L(E,s)$, so $\Lambda(E,s) = \eps\Lambda(E,2-s)$, where
  $\Lambda(E,s) = N^{s/2} (2\pi)^{-s} \Gamma(s) L(E,s)$.
Let $f=f_E$ be the modular form associated to~$E$.  
  If $W_N(f) = w f$, then $\eps = -w$ (see \exref{ch:periods}{ex:funceqn}).
  We have
\begin{align*}
   L(E,1) &= -2\pi \int_{0}^{i\infty} f(z)\, dz \\
          &= -2\pi i \, \left\langle f,\, \{0,\infty\}\right\rangle\\
    &=-2\pi i\, \left\langle f, \{0,i/\sqrt{N}\} + \{i/\sqrt{N}, \infty\}\right\rangle\\
    &=-2\pi i\, \left\langle wf, \{w_N(0), w_N(i/\sqrt{N})\} 
                    + \{i/\sqrt{N}, \infty\}\right\rangle\\
    &=-2\pi i\, \left\langle wf, \{\infty , i/\sqrt{N}\} 
                    + \{i/\sqrt{N}, \infty\}\right\rangle\\
    &=-2\pi i\, (w-1) \left\langle f, \{\infty , i/\sqrt{N}\} \right\rangle\\
\end{align*}
If $w=1$, then $L(E,1)=0$.  If $w= -1$, then 
\begin{equation}\label{eqn:lone}
 L(E,1) = 4\pi i \left\langle f, \{\infty , i/\sqrt{N}\} \right\rangle
    =  2 \sum_{n=1}^{\infty} \frac{a_n}{n} e^{-2\pi n/\sqrt{N}}.
  \end{equation}
  
For much more about computing 
with $L$-functions of elliptic curves, including a trick for
computing $\eps$ quickly without directly computing $W_N$, 
see \cite[\S7.5]{cohen:course_ant} and \cite[\S2.11]{cremona:algs}.
One can also find higher derivatives $L^{(r)}(E,1)$ by a
formula similar to (\ref{eqn:lone}) (see \cite[\S2.13]{cremona:algs}). 

\section{Computing the Period Mapping}\label{sec:computephi}%
\index{Period mapping!computation of}%
Fix a newform $f=\sum a_nq^n\in S_k(\Gamma)$, 
where $\Gamma_1(N)\subset \Gamma$
for some~$N$.
Let $I=I_f\subset \T$ be the kernel of the 
ring homomorphism $\T\ra K_f=\Q(a_2, \ldots)$ that sends~$T_n$ to~$a_n$. 
Let $\Theta_f$ be the \defn{rational period mapping}
associated to~$f$ and $\Phi_f$ the period mapping associated
to the $\Gal(\Qbar/\Q)$-conjugates of~$f$, so 
we have a commutative diagram
$$\xymatrix{
 {\sM_k(\Gamma)_\Q}\ar[dr]_{\Theta_f}\ar[rr]^{\Phi_f} 
   &          & \Hom_\C(S_k(\Gamma)[I],\C) \\
    &     {\displaystyle\frac{\sM_k(\Gamma)_\Q}{\Ker(\Phi_f)}}\ar@{^(->}[ur]^{i_f}
}
$$
Recall that the cokernel of $\Phi_f$ is the complex torus $A_f(\C)$.

The Hecke algebra $\T$ acts on the linear dual
$$\sM_k(\Gamma)^* = \Hom (\sM_k(\Gamma), \Q)$$
by $(t.\vphi)(x) = \vphi(tx)$.
Since $f$ is a newform, if
$\theta_1, \ldots, \theta_d$ is a basis
for $\sM_k(\Gamma)_\Q^*[I]$, then
$$
  \Ker(\Phi_f) = \Ker(\theta_1) \oplus \cdots \oplus \Ker(\theta_d).
$$
Thus we can 
compute $\Ker(\Phi_f)$, hence $\Theta_f$, so 
to compute $\Phi_f$ we only need to compute~$i_f$. 

Let $g_1,\ldots,g_d$ be a basis for the $\Q$-vector space 
$$S_k(\Gamma; \Q)[I] = S_k(\Gamma)\cap \Q[[q]],$$
i.e., the space of cusp forms with rational Fourier expansion.
We will compute $\Phi_f$ with respect to the basis of
$\Hom_\Q(S_k(\Gamma;\Q)[I],\C)$ dual to this basis. 
Choose elements $x_1,\ldots,x_d\in \sM_k(\Gamma)$
with the following properties:
\begin{enumerate}
\item Using Proposition~\ref{modsym-errorterm} or Proposition~\ref{wntrick}
it is possible to compute the period integrals 
$\langle g_i, x_j \rangle$, $i,j\in\{1,\ldots d\}$
efficiently.
\item The $2d$ elements $v+\eta(v)$ and $v-\eta(v)$ for $v=\Theta_f(x_1),\ldots,\Theta_f(x_d)$ 
span a space of dimension $2d$ (i.e., they span $\sM_k(\Gamma)/\Ker(\Phi_f)$).
\end{enumerate}
Given this data, we can compute
$$i_f (v+\eta(v)) = 
   2\Re(\langle g_1, x_i\rangle, \ldots, \langle g_d, x_i\rangle)$$
and
$$i_f(v-\eta(v)) = 
   2i\Im(\langle g_1, x_i\rangle, \ldots, \langle g_d, x_i\rangle).$$
We break the integrals into real and imaginary parts because this
increases the precision of our answers.
Since the vectors $v_n+\eta(v_n)$ and $v_n-\eta(v_n)$, $n=1,\ldots,d$ span 
$\sM_k(N,\eps)_\Q/\Ker(\Phi_f)$,  we have computed~$i_f$. 

\begin{remark}
We want to find symbols~$x_i$ satisfying the
conditions of Proposition~\ref{wntrick}.  This is usually possible
when~$d$ is very small, but in practice I have had problems doing
this when~$d$ is large. 
\end{remark}

\begin{remark}
The above strategy was motivated by
\cite[\S2.10]{cremona:algs}.
\end{remark}

\begin{remark}
The following idea just occured to me. 
We could use that $\langle T_n(g), x\rangle = \langle g, T_n(x)\rangle$
for any Hecke operator $T_n$, so that we only need to compute 
the period integrals $\langle g, x_i\rangle$.  Then we obtain all pairings
$\langle T_n(g), x_i \rangle = \langle g , T_n(x_i) \rangle$.
Since the $T_n(g)$ span the simple $\T$-module $S_k(\Gamma;\Q)[I]$,
this must give all pairings.   However, it requires computing
only $2d$ pairings instead of $2d^2$ pairings, which is potentially
a huge savings when $d$ is large.
\end{remark}

% for example with \text{\bf 131k2B}, 
%in which case the dimension is~$10$.

% \section{Computing $L(f,s)$ at Critical Integers}%
% \label{sec:compspecval}%
% \index{Special value $L(A,j)$!computing}%
% For $s = 1,\ldots,k-1$ we have
% \begin{eqnarray}\label{specialvalueformula}
%   L(f,s)   &=& 
%     \frac{(2\pi)^{s-1}i^{s-1}}{(s-1)!}\cdot 
%       \langle f, X^{s-1}Y^{k-1-s}\{0,\oo\}\rangle,\\
%   L(A_I,s) &=& \prod_{i=1}^d L(f_i,s).
% \end{eqnarray}
% Let
%         $$\e_i := X^{i-1}\{0,\oo\}$$
% denote the $i$th \defn{winding element}\index{Winding element|textit}. 
% In section~\ref{computephi} we computed the period 
% map\index{Period mapping}
% $\Phi_f$ with respect to a basis $g_1,\ldots,g_d$ 
% for $S_k(N,\eps;\Q)[I]$. 
% Upon writing~$f$ as a $K_f$-linear combination 
% $\alp_1 g_1+ \cdots+ \alp_d g_d$ we find that
% \begin{eqnarray*}
% \langle f, \e_i\rangle
%     &=& \langle \alp_1 g_1+ \cdots+ \alp_d g_d, \e_i\rangle\\
%     &=& \alp_1 \langle g_1, \e_i \rangle + \cdots
%         + \alp_d \langle g_d, \e_i \rangle\\
%     &=& \alp_1 \Phi_f(\e_i)_1 + \cdots
%         + \alp_d \Phi_f(\e_i)_d 
% \end{eqnarray*}
% Here $\Phi_f(\e_i)_j$ denotes the $j$th coordinate of $\Phi_f(\e_i)$.
% Finally using Equation~\ref{specialvalueformula} we compute the
% special value.


% \section{The Order of Vanishing of $L(f,s)$ at Integer Points}

\section{Computing Elliptic Curves of Given Conductor}\label{sec:findall}

\subsection{Using Modular Symbols}
Using modular symbols and the period map, we can compute all elliptic
curves over~$\Q$ of conductor~$N$, up to isogeny.  The algorithm in
this section gives all \defn{modular elliptic curves}, i.e., elliptic
curves attached to modular forms, of conductor~$N$.  Fortunately, it
is now known by \cite{wiles:fermat, breuil-conrad-diamond-taylor,
  taylor-wiles:fermat} that every elliptic curve over~$\Q$ is modular,
so the procedure described in this section gives all elliptic curves,
up to isogeny, of given conductor.  I think this algorithm was 
first introduced by Tingly (??), and later refined by Cremona \cite{cremona:algs}.

\begin{algorithm}{Elliptic Curves of Conductor~$N$}
INPUT: A positive integer~$N$.\\
OUTPUT: A list of Weierstrass equations for the 
elliptic curves of conductor~$N$, up to isogeny.
\begin{steps}
\item{}[Compute Modular Symbols] 
  Compute $\sM_2(\Gamma_0(N))$ using Section~\ref{sec:compg0n}.

\item{}[Find Rational Eigenspaces] \label{step:rateigen}
Find the two-dimensional eigenspaces $V$ in 
$\sM_2(\Gamma_0(N))_{\new}$ that correspond to elliptic curves.
Do {\em not} use the decomposition algorithms from 
Section~\ref{sec:decompmodsym}, which are too complicated,
and give way more information than we need.  Instead, for the first
few primes $p\nmid N$, compute all eigenspaces $\Ker(T_p - a)$, where
$a$ runs through integers with $-2\sqrt{p} < a  <  2\sqrt{p}$.
Intersect these eigenspaces to find the eigenspaces that 
correspond to elliptic curves.  To find just the new ones,
either compute the degeneracy maps to lower level, or find
all the rational eigenspaces of all levels that strictly
divide~$N$ and exclude them.

\item{}[Find Rational Newforms]\label{step:ratnew}
Using Algorithm~\ref{alg:eigsys},
find each rational newform $f=\sum_{n=1}^{\infty} a_n q^n \in \Z[[q]]$ associated
to each eigenspace $V$ found in Step~\ref{step:rateigen}.

\item{}[Find Each Curve] 
For each rational eigenvector~$f$ 
found in Step~\ref{step:ratnew}, do the following:

\begin{steps}
\item{}[Period Lattice] Compute the corresponding
period lattice $\Lambda=\Z\omega_1 + \Z\omega_2$ 
by computing the image of $\Phi_f$, 
as described in Section~\ref{sec:computephi}.

\item{}[Compute $\tau$]\label{step:tau}
Let $\tau=\omega_1/\omega_2$.  If $\Im(\tau)<0$, swap
$\omega_1$ and $\omega_2$, so $\Im(\tau)>0$.  
By successively applying generators of $\SL_2(\Z)$,
we find an $\SL_2(\Z)$ equivalent element $\tau'$
in the standard fundamental domain, so 
$|\Re(\tau')|\leq 1/2$ and $|\tau|\geq 1$.

\item{}[$c$-invariants] Compute the invariants $c_4$
and $c_6$ of the lattice~$\Lambda$ using the following 
rapidly convergent series:
\begin{align*}
c_4 &= \left(\frac{2\pi}{\omega_2}\right)^4 \cdot
      \left(1+240\sum_{n=1}^{\infty}\frac{n^3q^n}{1-q^n}\right)\\
c_6 &= \left(\frac{2\pi}{\omega_2}\right)^6 \cdot
      \left(1-504\sum_{n=1}^{\infty}\frac{n^5q^n}{1-q^n}\right),
    \end{align*}
where $q=e^{2\pi i \tau'}$, where $\tau'$ is as in Step~\ref{step:tau}.
A theorem of Edixhoven
(that the Manin constant is an integer) implies that
the invariants $c_4$ and $c_6$ of $\Lambda$ are integers,
so it is only necessary to compute $\Lambda$ to large
precision to determine them.

\item{}[Elliptic Curve] An elliptic curve with
invariants $c_4$ and $c_6$ is 
$$
E: \quad y^2 = x^3 -\frac{c_4}{48}x  -\frac{c_6}{864}.
$$

\item{}[Prove Correctness]\label{step:correct}  Compute the conductor of~$E$.
If the conductor of~$E$ is not~$N$, then recompute $c_4$ and
$c_6$ using a larger precision everywhere (e.g., more terms
of $f$, reals to larger precision, etc.)  If the conductor is~$N$, 
compute the coefficients $b_p$ of the modular form $g=g_E$
attached to the elliptic curve $E$, for $p\leq \#\P^1(\Z/N\Z)/6$.
Verify that $a_p = b_p$, where $a_p$ are the coefficients
of~$f$.   If this equality holds, then $E$ must be isogenous
to the elliptic curve attached to~$f$, by the Sturm
bound (Theorem~\ref{thm:sturm}) and Faltings's isogeny theorem.
If the equality fails for some~$p$, recompute $c_4$ and $c_6$
to larger precision.
\end{steps}
\end{steps}
\end{algorithm}
There are a couple of tricks to optimize the above algorithm.
For example, one can work separately with
 $\sM_k(\Gamma_0(N))_{\new}^+$
and 
$\sM_k(\Gamma_0(N))_{\new}^-$ and
get enough information to find $E$, up to isogeny
(see \cite{cremona:periods}).


Once we have one curve from each isogeny class of curves of
conductor~$N$, we can find each curve in each isogeny class, hence all
curves of conductor~$N$.  If $E/\Q$ is an elliptic curve,
then any curve isogenous to $E$ is isogenous via a chain
of isogenous of prime degree.  There is an {\em a priori} bound
on the degrees of these isogenous due to Mazur.  Also, there
are various methods for finding all isogenous from $E$ of
a given fixed degree.  See \cite[\S3.8]{cremona:algs} for
more details.


\subsection{Finding Curves by Finding $S$-Integral Points}
Cremona and others have recently been systematically developing an
alternative complementary approach to the problem of computing all
elliptic curves of given conductor (see \cite{cremona-lingham}).
Instead of computing all curves of given conductor, we instead
consider the seemingly more difficult problem of find all curves with
good reduction outside a finite set $S$ of primes.  Since one can
compute the conductor of a curve using Tate's algorithm
\cite[\S3.2]{tate:antwerpiv, cremona:algs}, if we know all curves with
good reduction outside~$S$, we can find all curves of conductor~$N$ by
letting $S$ be the set of prime divisors of~$N$.

There is a strategy for finding all curves with good reduction
outside~$S$.  It is not a provably-correct algorithm, in the sense
that it is always guarenteed to terminate (the modular symbols method
above {\em is} an algorithm), but in practice it often works, and
I think one conjectures that it always does.  Also,
this strategy makes sense over any number field, whereas the modular
symbols method does not, though there are generalizations of modular
symbols to other number fields.

Fix a finite set~$S$ of primes of a number field~$K$.  It is a theorem
of Shafarevich that there are only finitely many elliptic curves with
good reduction outside~$S$ (see \cite[\S IX.6]{silverman:aec}).  His
proof uses that the group of $S$-units in $K$ is finite, and Siegel's
theorem that there are only finitely many $S$-integral points on an
elliptic curve.  One can make all this explicit, and sometimes in
practice one can compute all these $S$-integral points.  

The problem of finding all elliptic curves with good reduction outside
of~$S$ can be broken into several subproblems, the main ones being:
\begin{enumerate}
\item Determine the following finite subgroup of $K^*/(K^*)^m$:
$$
  K(S,m) = \{x \in K^*/(K^*)^m \, : \, m \mid \ord_\p(x) \text{ all } \p\not\in S\}.
$$
\item Find all $S$-integral points on certain elliptic curves
$y^2=x^3 + k$.
\end{enumerate}

In \cite{cremona-lingham}, there is one example, where he finds all
curves of conductor $N=2^8\cdot 17^2 = 73984$ by finding all curves
with good reduction outside $\{2, 17\}$.  He finds $32$ curves of
conductor $73984$ that divide into $16$ isogeny classes.  He remarks
that $\dim S_2(\Gamma_0(N)) = 9577$, and his modular symbols program
was not able to find these curves at this high of level (presumably
due to memory constraints?).


\section{Examples}
\subsection{Jacobians of genus-two curves}%
\index{Jacobian!of genus-two curve}%
\index{Genus-two curves}%
\label{sec:analytic-empirical}%
The author is among the the six authors of~\cite{empirical}, who
gather empirical evidence for the BSD
conjecture for Jacobian of genus two curves.  Of the~$32$ Jacobians
considered, all but four are optimal quotients of $J_0(N)$ for
some~$N$.  The methods of this section can be used to compute
$\Omega_f^{+}$ for the Jacobians of these~$28$ curves.  Using explicit
models for the genus two curves, the authors of \cite{empirical}
computed the measure of~$A$ with respect to a basis for the N\'eron
differentials of~$A$. In all~$28$ cases our answers agreed to the
precision computed.  Thus in these cases we have numerically verified
that the Manin constant\index{Manin constant} equals~$1$.

The first example considered in \cite{empirical} is the Jacobian
$A=J_0(23)$ of the modular curve $X_0(23)$.  This curve has as a model
     $$y^2+(x^3+x+1)y = -2x^5-3x^2+2x-2$$
from which one can compute the BSD $\Omega_A = 2.7328...$. 
The following is an integral basis of cusp forms for $S_2(23)$.
\begin{eqnarray*}
 g_1 &=&   q - q^3 - q^4 - 2q^6 + 2q^7 + \cdots        \\
 g_2 &=& q^2 - 2q^3 - q^4 + 2q^5 + q^6 + 2q^7 +\cdots      
\end{eqnarray*}
The space $\sM_2(23;\Q)$ of modular symbols
 has dimension five and is spanned
by  $\{-1/19,0\}$, $\{-1/17,0\}$, $\{-1/15,0\}$, $\{-1/11,0\}$
and $\{\oo,0\}$.  The submodule $\sS_2(23;\Z)$ has rank four and 
has as basis the first four of the above five symbols. 
Choose $\gamma_1 = \abcd{8}{1}{23}{3}$ and  
$\gamma_2=\abcd{6}{1}{23}{4}$ and let 
$x_i = \{\oo,\gamma_i(\oo)\}$.
Using the $W_N$-trick (see Section~\ref{sec:wntrick}) we compute
the period integrals $\langle g_i, x_j\rangle $ using $97$ terms
of the $q$-expansions of $g_1$ and $g_2$, and obtain
$$\begin{array}{ll}
\langle g_1, x_1 \rangle \sim -1.3543+1.0838i,\qquad
      &\langle g_1, x_2 \rangle \sim -0.5915+ 1.6875i\\
\langle g_2, x_1 \rangle \sim -0.5915 - 0.4801i,\qquad
      &\langle g_2, x_2 \rangle \sim -0.7628 + 0.6037i
\end{array}$$
Using $97$ terms we already obtain about 14 decimal digits
of accuracy, but we do not reproduce them all here.
We next find that 
$$\langle g_1, x_1 + x_1^*\rangle \sim 2\Re(-1.3543+1.0838i) = 2.7086,$$
and so on.
Upon writing each generator of $\sS_2(23)$ in terms 
of $x_1 + x_1^*$, $x_1 - x_1^*$, $x_2 + x_2^*$ and $x_2 - x_2^*$
we discover that the period mapping with respect to the 
basis dual to $g_1$ and $g_2$ is (approximately)
$$\begin{array}{rcll}
\{-1/19,0\}&\mapsto&(\hspace{.8em}0.5915 - 1.6875i,&   \hspace{.8em}0.7628 - 0.6037i)\\
\{-1/17,0\}&\mapsto&(-0.5915 - 1.6875i,&  -0.7628 - 0.6037i)\\
\{-1/15,0\}&\mapsto&(-1.3543 - 1.0838i,&  -0.5915 + 0.4801i)\\
\{-1/11,0\}&\mapsto&(-1.5256,&             \hspace{.8em}0.3425)
\end{array}$$
Working in $\sS_2(23)$ we find $\sS_2(23)^+$ is spanned by
$\{-1/19,0\}-\{-1/17,0\}$ and $\{-1/11,0\}$. 
There is only one real component so 
$$\Omega_I^+ \sim
\left|\begin{array}{cc}
   1.1831 & 1.5256 \\
  -1.5256 & 0.3425
\end{array}\right| = 2.7327...$$
To greater precision we find that $\Omega_f^+\sim 2.7327505324965$.  
This agrees with the value in \cite{empirical}; since the Manin
constant\index{Manin constant}
is an integer, it must equal~$1$.

\subsection{Level one cusp forms}
In the following two sections we consider several specific examples
of tori attached to modular 
forms of weight greater than two.

Let $k\geq 12$ be an even integer.  Associated to each Galois 
conjugacy class of normalized eigenforms~$f$, there is a
torus $A_f$ over~$\R$. 
The real and minus volume\index{Real volume}
\index{Minus volume} of the first few of 
these tori are displayed in  
Table~\ref{table:vols}.   For weights~$24$ and~$28$ we 
give $\Omega^-/i$ so that the columns will line up nicely.
In each case, $97$ terms of the $q$-expansion were used.

\begin{table}
\begin{center}
\caption{Volumes associated to level one cusp forms.\label{table:vols}}
\index{Table of!volumes of level one cusp forms}%
\begin{tabular}{c}
\vspace{-2ex}\\
$\begin{array}{clll}
\hspace{2em}k\hspace{2em} & \hspace{4em}\Omega^+ \hspace{4em}&
    \hspace{4em}\Omega^-\hspace{4em}\\
\vspace{-2ex} & &\\
 12& 0.002281474899 & 0.000971088287i \\
 16 &0.003927981492 & 0.000566379403i \\
 18& 0.000286607497 & 0.023020042428i \\
 20& 0.008297636952 & 0.0005609325015i \\
 22& 0.002589288079 & 0.0020245743816i \\
 24 &0.000000002968& 0.0000000054322i& \\
 26 &0.003377464512 & 0.3910726132671i  \\
 28& 0.000000015627 & 0.0000000029272i&
\end{array}$
\vspace{-2ex}\\
\\
\end{tabular}\end{center}
\end{table}

The volumes appear to be {\em much} smaller than 
the volumes of weight two abelian varieties.
The dimension of each $A_f$ is~$1$, except for
weights $24$ and $28$ when the dimension is~$2$.


\subsection{CM elliptic curves of weight greater than two}
\label{cmellipticcurves}
Let~$f$ be a rational newform with ``complex multiplication'', in the
sense that ``half'' of the Fourier coefficients of~$f$ are zero.  For
our purposes, it is not necessary to define complex multiplication any
more precisely.  Experimentally, it appears that the associated
elliptic~$A_f$ has rational $j$-invariant.  As evidence for this we
present Table~\ref{table:cmcurves}, which includes the analytic data
about every rational CM form of weight four and level $\leq 197$.  The
computations of Table~\ref{table:cmcurves} were done using at
least~$97$ terms of the $q$-expansion of~$f$.  The rationality of~$j$
could probably be proved by observing that the CM forces $A_f$ to have
extra automorphisms.

\begin{table}
\begin{center}
\caption{CM elliptic curves of weight $>2$.\label{table:cmcurves}}%
\index{Table of!CM elliptic curves of weight $>2$}%
\begin{tabular}{c}
$\begin{array}{lcccrr} 
E                 &   j   &\Omega^+&\Omega^- &    c_4\hspace{2em}  & c_6 \hspace{2em}  \\
\vspace{-2ex}    & & &&&\\
\text{\bf 9k4A}  &   0 & 0.2095 & 0.1210i &         0.0000   & -56626421686.2951\\  
\text{\bf 32k4A} &1728 & 0.2283 & 0.2283i &  -3339814.8874   &            0.0000\\
\text{\bf 64k4D} &1728 & 0.1614 & 0.1614i&  53437038.1988   &        0.0000\\  
\text{\bf 108k4A} &   0 & 0.0440 & 0.0762i&    -14699.2655   &  24463608892439.7456\\
\text{\bf 108k4C}&   0 & 0.0554 & 0.0960i&      1608.7743   &   6115643810955.1724\\
\text{\bf 121k4A}&-2^{15}& 0.0116 & 0.0385i  &
85659519816.8841 & 25723073306989527.1216\\
\text{\bf 144k4E}&   0 & 0.0454 & 0.0262i&  81.1130&
-549788016394046.1396\\
\text{\bf 27k6A} &   0 & 0.0110 & 0.0191i&         0.0000   & 97856189971744203.7795\\
\text{\bf 32k6A} &1728 & 0.0199 & 0.0199i&   -58095643136.7658&8.0094\\
\end{array}$
\vspace{-2ex}\\
\\
\end{tabular}\end{center}
\end{table}

In these examples, the invariants $c_4$ and $c_6$ are mysterious (to me); 
in contrast, in weight~$2$ the invariants of an elliptic curve
are known to be integers (see \cite[2.14]{cremona:algs}).



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

% \section{Rational and Integral Period Mappings}\label{sec:ratpm}
% ...

\begin{exercises}
\item\label{ex:perp-stable} Let $f \in S_k(\Gamma_1(N))$ be a newform, and let 
$V_f$ be the subspace spanned by the $\Gal(\Qbar/\Q)$ conjugates
of $f$.  Let $V_f^{\perp}$ be the Petersson complement of 
$V_f$ in $S_k(\Gamma_1(N))$. 
\begin{enumerate} 
\item Show that Atkin-Lehner-Li theory and properties of the Petersson
  innner product imply that $V_f^{\perp}$ is stable under the full
  Hecke algebra $\T\subset S_k(\Gamma_1(N))$.
\item (*) Give an example of $f \in S_2(\Gamma_1(N))$ that
 shows that $V_f^{\perp}$ need not be $\T$-stable
if~$f$ is not a newform.   [Hint: Argue that if $V_f^{\perp}$ is
$\T$-stable for any $f$, then every element of $\T$ is diagonalizable.
An example of a space where $T_3$ is not diagonalizable is 
$S_2(\Gamma_1(81))$ (you may assume this).]
\end{enumerate}

\item \label{ex:funceqn} Suppose $f \in S_2(\Gamma_0(N))$ is a newform
and that $W_N(f) = w f$.  Let $\Lambda(E,s) = N^{s/2} (2\pi)^{-s} \Gamma(s) L(E,s)$.
Prove that $$\Lambda(E,s) = -w \Lambda(E,2-s).$$
[Hint: Show that $\Lambda(f,s) = \int_{0,\infty} f(iy/\sqrt{N})y^{s-1}\, dy$,
then substitute $1/y$ for $y$.  If you get completely stuck, see
any of many standard references, e.g., \cite[\S2.8]{cremona:algs}.]


\end{exercises}



% \chapter{Modular Curves and Modular 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}









%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%
%   NEW CHAPTER 
%
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%










\chapter{Congruences}\label{ch:serre}

\section{Congruences Between Modular Forms}
In this section we develop theory for determining when modular forms
are congruent, which is extremely import for computing with modular
forms.    

Let $\Gamma$ be an arbitrary congruence subgroup of $\SL_2(\Z)$,
and suppose $f\in M_k(\Gamma)$ is a modular form of integer weight~$k$
for $\Gamma$. Since $\abcd{1}{N}{0}{1}\in\Gamma$ for some integer~$N$,
the form $f$ has a Fourier expansion in
nonnegative powers of $q^{1/N}$.  For a rational
number $n$, let $a_n(f)$ be the coefficient of $q^n$ in
the Fourier expansion of~$f$.
Put
$$
  \ord_q(f) = \min\{n\in \Q : a_n \neq 0\},
$$
where by convention we take $\min \emptyset = +\infty$,
so $\ord_q(0)=+\infty$.

\subsection{The $j$-invariant}
Let
$$
  j = \frac{1}{q} + 744 + 196884 q + \cdots
$$
be the $j$-function, which is a weight~$0$ modular function
that is holomorphic except for a simple pole at $\infty$ and
has integer Fourier coefficients (see, e.g., 
\cite[\S VIII.3.3]{serre:arithmetic}).
\begin{lemma}\label{lem:jform}
Suppose $g$ is a weight~$0$ level~$1$
modular function that is holomorphic except possibly 
with a pole of order~$n$ at $\infty$.
Then $g$ is a polynomial in $j$ of degree at most~$n$.
Moreover, the coefficients of this polynomial lie in 
the ideal $I$ generated by the coefficients $a_m(g)$
with $m\leq  0$.
\end{lemma}
\begin{proof}
If $n=0$, then $g\in M_0(\SL_2(\Z))=\C$, so $g$ is constant with
constant term in~$I$, so the statement is true.  Next suppose $n>0$ and the lemma
has been proved for all functions with smaller order poles.
Let $\alpha = a_n(g)$, and note that
$$
  \ord_q(g - \alpha j^n) = 
  \ord_q\left(g - \alpha \cdot \left(\frac{1}{q} + 744 + 196884 q + \cdots \right)^n\right) > -n.
$$
Thus by induction $h=g - \alpha j^{n}$ is a polynomial in $j$
of degree $<n$ with coefficients in the ideal generated 
by the coefficients $a_m(g)$ with $m< 0$.  It follows
that $g=\alpha \cdot j^n - h$ satisfies the conclusion
of the lemma.
\end{proof}

\subsection{Congruences for Modular Forms}
If $\O$ is the ring of integers of a number field, $\m$
is a maximal ideal of~$\O$, and $f=\sum a_n q^n \in \O[[q^{1/N}]]$
for some integer~$N$,
let
$$
 \ord_\m(f) = \ord_q(f \!\!\mod{\m}) = \min\{n\in\Q : a_n \not\in \m\}.
$$
Note that $\ord_\m(fg) = \ord_\m(f) + \ord_\m(g)$.
The following theorem was first proved in \cite{sturm:cong},
and our proof is an expanded version of the one in \cite{sturm:cong}.

\begin{theorem}[Sturm]\label{thm:sturm}
  Let $\m$ be a prime ideal in the ring of integers $\O$ of a
  number field~$K$, and let $\Gamma$ be a congruence subgroup
of $\SL_2(\Z)$ of index~$m$ and level~$N$.
Suppose $f\in M_k(\Gamma,\O)$ is a modular form
and 
$$
  \ord_\m(f) > \frac{km}{12}
$$
or $f \in S_k(\Gamma,\O)$ is a cusp form
and 
$$
\ord_\m(f) > \frac{km}{12} - \frac{m-1}{N}.
$$
Then $f\con 0\pmod{\m}$.
\end{theorem}
\begin{proof}
\noindent{\bf Case 1: First we assume $\Gamma=\SL_2(\Z)$.}\\
Let 
$$
 \Delta  = q + 24q^2 + \cdots \in S_{12}(\SL_2(\Z),\Z)
$$
be the $\Delta$ function. 
Since $\ord_\m(f) > k/12$, we have $\ord_\m(f^{12}) > k$.
We have 
\begin{equation}\label{eqn:sturm1}
  \ord_q(f^{12}\cdot\Delta^{-k}) 
 = 12 \cdot \ord_q(f) - k\cdot \ord_q(\Delta) \geq -k,
\end{equation}
since $f$ is holomorphic at infinity and $\Delta$ has a zero of order~$1$.
Also
\begin{equation}\label{eqn:sturm2}
  \ord_\m(f^{12}\cdot \Delta^{-k}) =  \ord_\m(f^{12}) - k\cdot \ord_\m(\Delta)
          > k - k = 0.
\end{equation}
Combining (\ref{eqn:sturm1}) and (\ref{eqn:sturm2}), we see that
$$
  f^{12} \cdot \Delta^{-k} = \sum_{n\geq -k} b_n q^n,
$$
with $b_n \in \O$ and $b_n\in \m$ if $n\leq 0$. 

By Lemma~\ref{lem:jform}, 
$$
   f^{12} \cdot \Delta^{-k} \in \m[j]
$$
is a polynomial in~$j$ of degree at most~$k$ with coefficients
in $\m$.
Thus 
$$
  f^{12} \in \m[j]\cdot \Delta^k,
$$
so since the coefficients of $\Delta$ are integers, 
every coefficient of $f^{12}$ is in $\m$.
Thus
$
\ord_\m(f^{12}) = +\infty,
$
hence 
$\ord_\m(f) = +\infty$, so $f=0$, as claimed.

\vspace{2ex}
\noindent{\bf Case 2: $\Gamma$ Arbitrary}
\newcommand{\wM}{\mathfrak{M}}
% Since $f\con 0\pmod{\m}$ if and only
% if $f^{12} \con 0\pmod{\m}$, and 
% $\ord_\m(f^{12}) = 12\ord_\m(f)$, and
% $f^{12} \in M_{12k}(\Gamma)$, the theorem is true
% for $f$ if and only if it is true for $f^{12}$.
% We may thus replace~$f$ by $f^{12}$, and hence 
% assume that $12\mid k$.  We may also assume without
% loss that $f$ is nonconstant.

% The product $g = f \cdot \Delta^{-k/12}$ is a modular function
% of weight~$0$ that is holomorphic except possibly at~$\infty$.

Let $N$ be such that $\Gamma(N)\subset \Gamma$, so also
$f \in M_k(\Gamma(N))$.  
If $g\in M_k(\Gamma(N))$ is arbitrary, then
because $\Gamma(N)$ is a normal subgroup of $\SL_2(\Z)$,
we have that for any $\gamma \in\Gamma(N)$ and $\delta \in \SL_2(\Z)$,
that
$$
  (g|[\delta]_k)|[\gamma]_k = g|[\delta\gamma]_k
          = g|[\gamma'\delta]_k = g|[\gamma']_k|[\delta]_k
           = g|[\delta]_k,
$$
where $\delta'\in\SL_2(\Z)$.  Thus for any $\delta\in \SL_2(\Z)$,
we have that $g|[\delta]_k \in M_k(\Gamma(N))$, so $\SL_2(\Z)$
acts on $M_k(\Gamma(N))$.

It is a standard (but nontrivial) fact about modular forms, which
comes from the geometry of the modular curve $X(N)$ over $\Q(\zeta_N)$
and $\Z[\zeta_N]$, that $M_k(\Gamma(N))$ has a basis with Fourier
expansions in $\Z[\zeta_N][[q^{1/N}]]$, and that the action of
$\SL_2(\Z)$ on $M_k(\Gamma(N))$ preserves $$
M_k(\Gamma(N),\Q(\zeta_N)) = M_k(\Gamma(N)) \cap{}
(\Q(\zeta_N)[[q^{1/N}]]), $$
and the cuspidal subspace
$S_k(\Gamma(N),\Q(\zeta_N))$.  In particular, for any
$\gamma\in\SL_2(\Z)$, $$
f|[\gamma]_k \in M_k(\Gamma(N), K(\zeta_N)),
$$
Moreover, the denominators of $f|[\gamma]_k$ are bounded, since~$f$
is an $\O[\zeta_N]$-linear combination of a basis for
$M_k(\Gamma(N),\Z[\zeta_N])$, and the denominators of $f|[\gamma]_k$
divide the product of the denominators of the images of each of these
basis vectors under $[\gamma]_k$.
  
% Let $L$ be a finite extension of $K(\zeta_N)$ such that the ideal $\m
% \O_L$ is principal.  For example, if~$n$ is the order of the class
% of~$\m_0=\m\O_{K(\zeta_N)}$ in the class group of $K(\zeta_N)$, then
% $\m_0^n = (\alpha)$ is principal, and we can take $L = K(\zeta_N,
% \sqrt[n]{\alpha})$.  
Let $L=K(\zeta_N)$.
Let $\wM$ be a prime of $\O_L$ that divides
$\m \O_L$.   We will now show that for each $\gamma\in\SL_2(\Z)$, the
Chinese remainder theorem implies that there is an element $A_\gamma\in L^*$
such that
\begin{equation}\label{eqn:sturm_crt}
A_\gamma \cdot f|[\gamma]_k \in M_k(\Gamma(N), \O_L)
\qquad \text{and}
\qquad \ord_{\wM} (A_{\gamma} \cdot f|[\gamma]_k) < \infty.
\end{equation}
First find $A \in L^*$ such that 
$A\cdot f|[\gamma]_k$ has coefficients in $\O_L$.
Choose $\alpha\in \wM$ with $\alpha \not\in \wM^2$, and find a negative power
$\alpha^t$ such that $\alpha^t\cdot A\cdot f|[\gamma]_k$
has $\wM$-integral coefficients and finite valuation.  
This is possible because we assumed that $f$ is nonzero.
Use the Chinese remainder theorem to find $\beta\in \O_L$
such that $\beta\con 1\pmod{\wM}$ and $\beta\con 0\pmod{\wp}$
for each prime $\wp\neq \wM$ that divides $(\alpha)$.
Then for some $s$ we have 
$$
 \beta^s \cdot \alpha^t \cdot A\cdot f|[\gamma]_k  = A_\gamma \cdot f|[\gamma]_k
   \in M_k(\Gamma(N),\O_L),
$$
and $\ord_{\wM}(A_\gamma \cdot f|[\gamma]_k) < \infty$.



Write 
$$
 \SL_2(\Z) = \bigcup_{i=1}^m \Gamma{} \gamma_i
$$
with $\gamma_1 = \abcd{1}{0}{0}{1}$, and let
$$
  F = f \cdot \prod_{i=2}^m A_{\gamma_i} \cdot f|[\gamma_i]_k.
$$
Then 
$
  F \in M_{km}(\SL_2(\Z))
$
and since $\wM\cap \O_K = \m$, we have $\ord_{\wM}(f) = \ord_{\m}(f)$,
so
$$
 \ord_{\wM}(F) \geq \ord_{\wM}(f) = \ord_{\m}(f) > \frac{km}{12}.
$$
Thus we can apply case 1 to conclude that
$$
 \ord_{\wM}(F) = +\infty.
$$
Thus
\begin{equation}\label{eqn:sturm:ords}
  \infty = \ord_{\wM}(F) = \ord_\m(f) + \sum_{i=2}^m \ord_{\wM}(A_{\gamma_i} f|[\gamma]_k),
\end{equation}
so $\ord_\m(f)=+\infty$, because of (\ref{eqn:sturm_crt}).
    
We next obtain a better bound when~$f$ is a cusp form.
Since $|[\gamma]_k$ preserves
cusp forms, $\ord_{\wM}(A_{\gamma_i} f|[\gamma]_k) \geq \frac{1}{N}$
for each $i$.
Thus
$$
 \ord_{\wM}(F) \geq \ord_{\wM}(f)  + \frac{m-1}{N} = \ord_{\m}(f) + \frac{m-1}{N} > \frac{km}{12},
$$
since now we are merely assuming that 
$$
  \ord_{\m}(f) > \frac{km}{12} 
     - \frac{m - 1}{N}.
$$
Thus we again apply case 1 to conclude that
$
 \ord_{\wM}(F) = +\infty,
$
and using (\ref{eqn:sturm:ords}) conclude that
$\ord_\m(f)=+\infty$.


% Let $\cF_N$ be the field of all modular functions for $\Gamma(N)$.
% This is an extension of $\Q(j)$ such that 
% $\Gal(\cF_N/\Q(j)) \isom \GL_2(\Z)$
% and the $|[\gamma]_0$ action of $\SL_2(\Z)$
% on $\cF_N$ defines a homomorphism 
% $$
%  \SL_2(\Z) \to \Gal(\cF_N/\Q(j)).
% $$
% In particular, $\cF_N$ is preserved by the $[\gamma]_0$ action
% of $\SL_2(\Z)$.
% Alternatively, $\cF_N$ is the field of rational functions on
% the modular curve $X(\Gamma(N))$ over $\Q(\zeta_N)$.

% Since $\Delta^{-k/12}$ is a modular function of weight $-k$, 
% we have
% $$
%   g|[\gamma]_0 = f|[\gamma]_k \cdot \Delta^{-k/12}|[\gamma]_{-k}
%     = f|[\gamma]_k \cdot \Delta^{-k/12},
% $$
% so 
% $$
%  f|[\gamma]_k = g|[\gamma]_0 \cdot \Delta^{k/12}.
% $$
% It follows that for all $\gamma\in\SL_2(\Z)$, 
% $$f|_{[\gamma]_k} \in M_k(\Gamma(N),K(\zeta_N)),$$
% where $\zeta_N$ is a primitive $N$th root of unity.


\end{proof}

\begin{corollary}
  Let $\m$ be a prime ideal in the ring of integers $\O$ of a
  number field.  Suppose $f,g\in M_k(\Gamma,\O)$ are modular
  forms and 
$$
  a_n(f) \con  a_n(g) \pmod{\m}
$$
for all 
$$
  n\leq 
\begin{cases}
\ds\frac{km}{12} - \frac{m-1}{N} & \text{ if }f-g \in S_k(\Gamma,\O),\\
\ds\frac{km}{12} & \text{otherwise},
\end{cases}
$$
where $m=[\SL_2(\Z):\Gamma]$.
Then $f\con g\pmod{\m}$.
\end{corollary}

Buzzard proved the following corollary, which is extremely useful
in practical computations.
It asserts that the Sturm bound for modular forms with character
is the same as the Sturm bound for $\Gamma_0(N)$.
\begin{corollary}[Buzzard]
  Let~$\m$ be a prime ideal in the ring of integers~$\O$ of a
  number field.  
  Suppose $f,g\in M_k(\Gamma_1(N),\eps,\O)$ are modular
  forms with Dirichlet character~$\eps:(\Z/N\Z)^* \to \C^*$ and assume
that
  $$
  a_n(f) \con  a_n(g) \pmod{\m}
\qquad\text{for all}\qquad
  n \leq  \frac{km}{12},
$$
where 
$$m=[\SL_2(\Z):\Gamma_0(N)] = 
   \#\P^1(\Z/N\Z) = N \cdot \prod_{p|N}\left(1+{1\over p}\right).$$
Then $f\con g\pmod{\m}$.
\end{corollary}
\begin{proof}
Let $h=f-g$ and 
let $r=km/12$,
so $\ord_\m(h) > r$.  Let $s$ be the order of the
Dirichlet character $\eps$.  Then $h^s \in M_{ks}(\Gamma_0(N))$ 
and 
$$
\ord_\m(h^s) > sr = \frac{ksm}{12}.
$$
By Theorem~\ref{thm:sturm}, we have $\ord_\m(h^s) = \infty$,
so $\ord_\m(h) = \infty$.  It follows that $f\con g\pmod{\m}$.
\end{proof}

\subsection{Congruence for Newforms}
Sturm's paper \cite{sturm:cong} also applies some results of Asai on
$q$-expansions at various cusps to obtain a more refined result for
newforms.  

\begin{theorem}[Sturm]
Let $N$ be a square-free positive integer, and 
suppose~$f$ and~$g$ are two newforms in 
$S_k(\Gamma_1(N),\eps,\O)$,
where $\O$ is the ring of integers of a number field, 
and suppose that $\m$ is a maximal ideal of $\O$.
Let~$I$ be an arbitrary subset of the prime divisors of~$N$.
If 
$
 a_p(f) = a_p(g)
$
for all $p\in I$, and
$$
 a_p(f) \con a_p(g)\pmod{\m}
$$
for all primes 
$$
  p \leq \frac{k\cdot [\SL_2(\Z):\Gamma_0(N)]}{12 \cdot 2^{\#I}},
$$ 
then $f\con g\pmod{\m}$.
\end{theorem}


\cite{buzzard-stein:artin} also contains a result about congruences
between newforms, which does not require that the level be square
free.  Recall (see Definition~\ref{defn:conductordir}) that the conductor of
a Dirichlet character $\eps$ is the largest divisor~$c$ of $N$ such
that~$\eps$ factors through $(\Z/c\Z)^\times$.

\begin{theorem}
Let $N>4$ be any integer, and
suppose $f$ and $g$ are two normalized eigenforms in $S_k(\Gamma_1(N),\eps,\O)$,
where $\O$ is the ring of integers of a number field, 
and suppose that $\m$ is a maximal ideal of $\O$.
Let~$I$ be the set of prime divisors of $N$ that
do not divide~$\frac{N}{\cond(\eps)}$.
If 
$$
a_p(f) \con a_p(g)\pmod{\m}
$$
for all primes $p\in I$ and for all primes
$$
  p \leq \frac{k\cdot [\SL_2(\Z):\Gamma_0(N)]}{12 \cdot 2^{\#I}},
$$ 
then $f\con g\pmod{\m}$.
\end{theorem}
For the proof, see Lemma~1.4 and Corollary 1.7 in \cite[\S1.3]{buzzard-stein:artin}.




\section{Generating the Hecke Algebra as a $\Z$-module}

The following theorem appeared in \cite[Appendix]{lario-schoof}, except that
we give a better bound here.

\begin{theorem}\label{thm:heckegen}
Suppose $\Gamma$ is a congruence subgroup that contains
$\Gamma_1(N)$ and let 
\begin{equation}\label{eqn:perfectR}
  r=\frac{km}{12} - \frac{m - 1}{N},
\end{equation}
where $m=[\SL_2(\Z):\Gamma]$.
Then the Hecke algebra $\T=\Z[\ldots, T_n,\ldots] \subset \End(S_k(\Gamma))$
is generated as a $\Z$-module by the Hecke operators
$T_n$ for $n\leq r$.
\end{theorem}
\begin{proof}
  For any ring~$R$, let $S_k(N,R) = S_k(N,\Z)\otimes{}R$, where
  $S_k(N,\Z)\subset \Z[[q]]$ is the submodule of cusp forms with
  integer Fourier expansion at the cusp~$\infty$, and let $\T{}_R =
  \T{}\otimes_\Z R$.  For any ring~$R$, there is a perfect pairing 
$$S_k(N,R) \otimes_R \T{}_R \rightarrow R$$ 
given by $\langle f,T\rangle\mapsto a_1(T(f))$ (this is true
for~$R=\Z$, hence for any $R$).

  Let~$M$ be the submodule of $\T{}$ generated by
  $T_1,T_2,\ldots,T_r$, where~$r$ is the largest integer $\leq
  {{kN}\over{12}}\cdot [\SL_2(\Z):\Gamma]$.
  Consider the exact sequence of additive abelian groups
  $$0\rightarrow M \mathop{\rightarrow}\limits^{i}\ \T{}
  \rightarrow \T{}/M \rightarrow 0.$$
  Let~$p$ be a prime and use
  that tensor product is right exact to obtain an exact sequence
  $$M\otimes \F_p \mathop{\rightarrow}\limits^{\overline{i}}\ 
    \T \otimes\F_p \rightarrow (\T{}/M)\otimes\F_p\rightarrow 0.$$
  Suppose that $f\in S_k(N,\F_p)$ pairs to~$0$ with each of
  $T_1,\ldots, T_r$.  Then $$a_m(f)=a_1(T_m f)=\langle f, T_m\rangle =
  0$$ in $\F_p$ for each $m\leq r$.  By Theorem~\ref{thm:sturm}, it
  follows that $f = 0$. Thus the pairing restricted to the image of
  $M\otimes\F_p$ in $\T_{\F_p}$ is nondegenerate, so
because (\ref{eqn:perfectR}) is perfect, it follows that
  $$
  \dim_{\F_p} \overline{i}(M\otimes\F_p) =  \dim_{\F_p} S_k(N,\F_p).
  $$
  Thus $(\T{}/M) \tensor \F_p = 0$. 
  Repeating the argument for all primes~$p$ shows that $\T{}/M=0$, 
  as claimed.
\end{proof}


\begin{remark}
In general, the conclusion of 
Theorem~\ref{thm:heckegen} is not true if one considers only
 $T_n$ where~$n$ runs over the {\sl primes} less than the bound.
Consider, for example, $S_2(11)$, where the bound is~$1$ and
there are no primes $\leq 1$. 
However, the Hecke algebra is generated as an {\em algebra}
by operators $T_p$ with $p\leq r$.
\end{remark}

%\subsection{Examples}

% \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}



% \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{Serre's Conjectures}
% \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}


\bibliography{biblio}

\printindex


\end{document}
