\documentclass{article}
\voffset=-0.05\textheight
\textheight=1.10\textheight

\hoffset=-0.05\textwidth
\textwidth=1.1\textwidth
\include{macros}
\title{Welcome to the MAGMA Computer Algebra System}
\date{December 3, 2001}
\author{William Stein\\
{\tt http://modular.fas.harvard.edu}}
\begin{document}
\maketitle
\tableofcontents

\section{Introduction}
\magma{} is a sophisticated mathematics calculator that is
significantly different than Maple, Mathematica, and PARI/GP.  In this
talk, which is directed at number theorists interested in modular
forms, I will introduce \magma{}, and give you a brief tour of some
aspects of \magma{}.

\vspace{1ex}
\noindent{\bf Acknowledgement:} Allan Steel, Kevin Buzzard, Helena Verrill,
and John Cannon provided helpful comments on these notes.

\section{MAGMA}
\mbox{}\indent{\bf What is M{\small AGMA}, ``the group''?}  \magma{} is
produced/headed by Professor John Cannon of the University of Sydney,
along with two handfulls of Ph.D. students, postdocs, and ``some
well-groomed professional top-notch elite C programmers/hackers''.
They are nonprofit\footnote{Cost recover is the technical term.}, 
in the sense that all the money from \magma{}
licenses and grants goes towards basic maintenance and flying
mathematicians (like me) there.
%\magma{} resembles several German groups like LiDIA or KANT, except
%that \magma{} is not free and Cannon wears the good manager hat as
%well as the mathematician one.

{\bf What is M{\small AGMA}, ``the program''?}  Unlike Maple and
Mathematica, which target college teachers, calculus students, engineers, 
and scientists, \magma{} is aimed squarely at 
research mathematicians (and intelligence agencies). 
My TI-89 pocket calculator is much better at
calculus than \magma{}, but \magma{} comes standard with a package by
Michael Stoll for arithmetic in Jacobians of Hyperelliptic curves and
my package for computing with modular forms.

{\bf \magma{} differs from PARI} in that its scope is vastly greater,
and \magma{} provides more powerful tools for suporting very large
projects.  Highly optimized implementation of algebraic number theory
algorithms is the reason for existence of PARI.  Also, PARI's
``philosophy'' is to assume standard conjectures (e.g., Riemann
Hypothesis) in order to speed up computations, but \magma{} typically
does not.

A {\bf fundamental difference} between \magma{} and the other systems
is that every object in \magma{} {\bf belongs to a category}; this is
analogous to how variables in {\tt C} must have a type.  Thus there
are literally hundreds of entirely different and incompatible notions
of ``$1$'' in \magma{}. 


\section{Resources for Learning MAGMA}
If you want to really learn \magma{} (or anything!)  it's absolutely
essential to try it!  \magma{} will soon be
available for everyone's use on {\tt abel.math.harvard.edu}.  (Caveat:
If you wish to do very resource-intensive computations, get an account
on {\tt modular.fas.harvard.edu} from me.)  Type {\tt magma} at
the command prompt and try it out!  There are many resources to get
you going and stay headed in the right direction.  See
\begin{center}
        {\tt http://modular.fas.harvard.edu/docs/.}
\end{center}


\begin{itemize}
\item {\tt first.dvi} (16 pages):  First few steps in \magma.  Gets you going.
\item {\tt tutorial.dvi} (11 pages): 
A {\em Modular Symbols Tutorial} by Kevin Buzzard and 
myself. Spend 1 hour with this and you'll be able to do many computations
with modular symbols in \magma.
\item {\tt overv27.dvi} (64 pages): An overview of the domains of mathematics
      \magma{} treats.  This is humbling. 
\item {\tt examples.dvi} (200 pages): A short book of sophisticated examples.
\item {\tt hb[1--8].dvi} (thousands of pages): Reference manual for all 
functions of \magma{} (also available in HTML).  If you want to know what a \magma{}
function really does, look here.  I wrote the chapters about modular
symbols and modular forms, which contain nontrivial examples and some
open problems.
\item {\tt intro.dvi} (800 pages): A book about how to program in \magma,
with sophisticated examples.
\item {\tt william\_stein.human}:  I have lots of experience with \magma,
and I'm human hence more interactive than the above resources.

\end{itemize}

\section{MAGMA Categories}
A first glance at \magma{} reveals nothing too out of the ordinary:
\begin{verbatim}
> a := 2;
> a;
2
> a + 3*a^2;
14
\end{verbatim}
However,
\begin{verbatim}
> f := x^2+1;

>> f := x^2+1;
        ^
User error: Identifier 'x' has not been declared or assigned
> 
\end{verbatim}
Here \magma{} doesn't know what~$x$ is, and it doesn't
{\em assume it does}.   The fix is to tell \magma{} what~$x$ 
is:
\begin{verbatim}
> // This is a comment, just like in C++.  "//" means comment.
> Z := Integers();    
> Z;                  // Shortcut for Print(Z);
Integer Ring
> R<x> := PolynomialRing(Z);        // R is Z[x]
> R;
Univariate Polynomial Ring in x over Integer Ring
> f := x^2 + 1;      // OK now
> f;
x^2 + 1             
\end{verbatim}
Everything in \magma{} is an object in a certain category
and has a parent.
\begin{verbatim}
> Category(Z);
RngInt            // one object category
> Category(R);    
RngUPol           // the category of univariate polynomial rings
> Category(f);
RngUPolElt        // the category of elements of univariate polynomial rings
> Parent(f);
Univariate Polynomial Ring in x over Integer Ring      // That's R.
\end{verbatim}

\section{Some Rings}
Arithmetic in many {\bf standard rings}  
is supported in \magma:
$$\Z, \quad \Z/N\Z, \quad \F_{q},\quad \Z_p, \text{ and } R[[q]].$$
\begin{verbatim}
> S := IntegerRing(12);           // make Z/12Z
> S;
Residue class ring of integers modulo 12
> Set(S);                         // the forgetful functor to SetEnum
{ 0, 11, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }
> W<q> := PowerSeriesRing(S);      // W is S[[q]]
> W;
Power series ring in q over IntegerRing(12)
> 1/(1+q);                         // arithmetic in S[[q]].
1 + 11*q + q^2 + 11*q^3 + q^4 + 11*q^5 + O(q^6)
\end{verbatim}

\section{Finite Fields}
Support for basic arithmetic over finite fields is a dream because
a choice of $\Fbar_p$ is built in.  There is a fixed compatible
choice of maps $\F_{p^n}\hookrightarrow \F_{p^{nm}}$ for all $n,m\geq 1$.

\begin{verbatim}
> K<a> := GF(3^2);   
> MinimalPolynomial(a);
$.1^2 + 2*$.1 + 2
> // The $.1 means "the first unnamed generator".  $.2 would be the second, etc.
> L<b> := GF(3^6);   // b generates L^*
> L!a;      // image of a in L.
b^91        // sweet.
> A := MatrixAlgebra(L,2)![b,2,0,1];
> A;
[    b     2]
[    0     1]
> V := VectorSpace(L,2);
> v := V.1;
> v;
(    1     0)
> v*A;       // WARNING: In Australia, matrices act ON THE RIGHT!
(    b     2)
\end{verbatim}
%> G := GeneralLinearGroup(2,K);     // build structures upon structures
%> #G;
%5760
%> Generators(G);
%{
%[  2   1]
%[  2   0],
%
%[  a   0]
%[  0   1]
%}

\section{Commutative Algebra and Geometry}
It is easy and natural to work with quotients of polynomial rings 
and ideals in MAGMA. 

\begin{verbatim}
> // The field K = Q(a,b,x0,x1,x2)
> K<a,b,x0,x1,x2> := FieldOfFractions(PolynomialRing(Rationals(),5));
Rational function field of rank 5 over Rational Field
Variables: a, b, x0, x1, x2
> // The polynomial ring R = K[y0,y1,y2]
> R<y0,y1,y2> := PolynomialRing(K,3);
Polynomial ring of rank 3 over 
Rational function field of rank 5 over Rational Field [...]
> // A maximal ideal of R.
> I := ideal<R | y0^2 - (x0^3+a*x0+b), 
                 y1^2 - (x1^3+a*x1+b), 
                 y2^2 - (x2^3+a*x2+b)>;
\end{verbatim}
The quotient $L = R/I$ contains three generic points
on the elliptic curve $y^2 = x^3 + ax + b$.
\begin{verbatim}
> L  := quo<R|I>;
Affine Algebra of rank 3 over [...]
> E  := EllipticCurve([L| a,b]); 
Elliptic Curve defined by y^2 = x^3 + a*x + b over Affine Algebra of rank 3 over 
Rational function field of rank 5 over Rational Field
Variables: a, b, x0, x1, x2
> P0 := E![L|x0,y0]; P1 := E![L|x1,y1]; P2 := E![L|x2,y2];
> P0 + P1;
(-2/(x0^2 - 2*x0*x1 + x1^2)*y0*y1 + ...
> // left and right are huge -- you probably don't want to print them out.
> left := (P0 + P1) + P2;  right := P0 + (P1 + P2);
> left eq right;
true
\end{verbatim}




\section{Unique Flexibility}
This is a short example which demonstrates the flexibility of the
system.
\begin{verbatim}
> R<x> := PolynomialRing(Integers());
> f := x^3+1;
> Factorization(f);
[
<x + 1, 1>,
<x^2 - x + 1, 1>
]
> S<x> := PolynomialRing(pAdicField(7));
> Factorization(S!f);
[
<x + 1, 1>,
<(1 + O(7^20))*x - 22143577275619761 + O(7^20), 1>,
<(1 + O(7^20))*x + 22143577275619760 + O(7^20), 1>
]
> W<x> := PolynomialRing(GF(7));
> Factorization(W!f);
[
<x + 1, 1>,
<x + 2, 1>,
<x + 4, 1>
]
> F<a> := GF(5^2);
> R5<x> := PolynomialRing(F);
> Factorization(R5!f);
[
<x + 1, 1>,
<x + a^8, 1>,
<x + a^16, 1>
]
\end{verbatim}



\section{Some Frequently Asked Questions}
\begin{question}
Is there an equivalent to a {\tt .magmarc} where initial commands can be
loaded?  (e.g., setting {\tt vi} or {\tt emacs} mode)
\end{question}

Yes.  Set the environment variable {\tt MAGMA\_STARTUP\_FILE} to the
file you want \magma{} to execute at startup.  Also, you should learn
about {\tt spec} files.  Check out
\begin{verbatim}
  http://modular.fas.harvard.edu/docs/magma/htmlhelp/text122.html#247
\end{verbatim}


\begin{question}
When running magma I tend to have a separate window with the
documentation available, but also sometimes type {\tt ?X} for some
{\tt X}; sometimes the output of available options is more than a
screen long; is there a way to make a paginator (e.g., less) do this
automatically, a page at a time?
\end{question}

I {\em never} 
use {\tt ?X} for help.  Use the HTML help, which comes with \magma{}.
You can also use it by viewing:
\begin{verbatim}
  http://modular.fas.harvard.edu/docs/magma/htmlhelp/MAGMA.html
\end{verbatim}
This HTML help is generated from exactly the same \TeX{} source files
as the {\tt ?} help, but by using the index it is easier to view. 

\begin{question}
How can one refer
to the output of the most recent command?  
\end{question}
\begin{verbatim}
$ and $1, $2, $3.
\end{verbatim}

\begin{question}
What are the easy ways for
storing output in a file? 
\end{question}

Here's an example.
\begin{verbatim}
> file := Open("testfile","w");
> fprintf file, "hello world";
> Flush(file); 
> r := Open("testfile","r");
> Gets(r);
hello world
\end{verbatim}
You can read about file I/O commands at
\begin{verbatim}
   http://modular.fas.harvard.edu/docs/magma/htmlhelp/text130.html#363
\end{verbatim}

\begin{question}
Is there a simple way to take an polynomial
in $x$ and replace $x$ by some other expression?
\end{question}

No, because that doesn't make \magma{}matically rigorous sense in
general.  However, in cases where what you want to do does make sense
(which should always be the case, I trust), you can use the {\tt hom}
construction.  Here is an example:
\begin{verbatim}
> R<x> := PolynomialRing(RationalField());
> phi := hom< R -> RationalField() | 4>;
> phi(x^2+1);
17
\end{verbatim}


\end{document}
