Welcome to the MAGMA Computer Algebra System

William Stein

               http://modular.fas.harvard.edu

December 3, 2001

Contents

1 Introduction 1 2 MAGMA 1 3 Resources for Learning MAGMA 2 4 MAGMA Categories 3 5 Some Rings 3 6 Finite Fields 4 7 Commutative Algebra and Geometry 4 8 Unique Flexibility 5 9 Some Frequently Asked Questions 6

1 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. Acknowledgement: Allan Steel, Kevin Buzzard, Helena Verrill, and John Cannon provided helpful comments on these notes.

2 MAGMA

What is MAGMA, “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^{1}, in the sense that all the money from Magma licenses and grants goes towards basic maintenance and flying mathematicians (like me) there.

1Cost recover is the technical term.

What is MAGMA, “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.

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 fundamental difference between Magma and the other systems is that every object in Magma belongs to a category; this is analogous to how variables in C must have a type. Thus there are literally hundreds of entirely different and incompatible notions of “1” in Magma.

3 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 abel.math.harvard.edu. (Caveat: If you wish to do very resource-intensive computations, get an account on modular.fas.harvard.edu from me.) Type 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

                  http://modular.fas.harvard.edu/docs/.

• first.dvi (16 pages): First few steps in Magma. Gets you going.

• tutorial.dvi (11 pages): A 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.

• overv27.dvi (64 pages): An overview of the domains of mathematics Magma treats. This is humbling.

• examples.dvi (200 pages): A short book of sophisticated examples.

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

• intro.dvi (800 pages): A book about how to program in Magma, with sophisticated examples.

• william stein.human: I have lots of experience with Magma, and I’m human hence more interactive than the above resources.

4 MAGMA Categories

A first glance at Magma reveals nothing too out of the ordinary:

> a := 2;
> a;
2
> a + 3*a^2;
14

However,

> f := x^2+1;
>> f := x^2+1;
        ^
User error: Identifier 'x' has not been declared or assigned
>

Here Magma doesn’t know what x is, and it doesn’t assume it does. The fix is to tell Magma what x is:

> // 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

Everything in Magma is an object in a certain category and has a parent.

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

5 Some Rings

Arithmetic in many standard rings is supported in Magma:

ℤ, ℤ/Nℤ, 𝔽_{q}, ℤ_{p}, and R[[q]].

> 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)

6 Finite Fields

Support for basic arithmetic over finite fields is a dream because a choice of \overline{𝔽}_{p} is built in. There is a fixed compatible choice of maps 𝔽_{p^{n}} ↪ 𝔽_{p^{nm}} for all n, m ≥ 1.

> 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)

7 Commutative Algebra and Geometry

It is easy and natural to work with quotients of polynomial rings and ideals in MAGMA.

> // 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)>;

The quotient L = R/I contains three generic points on the elliptic curve y^{2} = x^{3}+ax+b.

> 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

8 Unique Flexibility

This is a short example which demonstrates the flexibility of the system.

> 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>
]

9 Some Frequently Asked Questions

Question 9.1. Is there an equivalent to a .magmarc where initial commands can be loaded? (e.g., setting vi or emacs mode)

Yes. Set the environment variable MAGMA STARTUP FILE to the file you want Magma to execute at startup. Also, you should learn about spec files. Check out

  http://modular.fas.harvard.edu/docs/magma/htmlhelp/text122.html#247

Question 9.2. When running magma I tend to have a separate window with the documentation available, but also sometimes type ?X for some 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?

I never use ?X for help. Use the HTML help, which comes with Magma. You can also use it by viewing:

  http://modular.fas.harvard.edu/docs/magma/htmlhelp/MAGMA.html

This HTML help is generated from exactly the same TEX source files as the ? help, but by using the index it is easier to view.

Question 9.3. How can one refer to the output of the most recent command?

$ and $1, $2, $3.

Question 9.4. What are the easy ways for storing output in a file?

Here’s an example.

> file := Open("testfile","w");
> fprintf file, "hello world";
> Flush(file);
> r := Open("testfile","r");
> Gets(r);
hello world

You can read about file I/O commands at

   http://modular.fas.harvard.edu/docs/magma/htmlhelp/text130.html#363

Question 9.5. Is there a simple way to take an polynomial in x and replace x by some other expression?

No, because that doesn’t make Magmamatically 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 hom construction. Here is an example:

> R<x> := PolynomialRing(RationalField());
> phi := hom< R -> RationalField() | 4>;
> phi(x^2+1);
17