Solving Problems With Magma PDF
Solving Problems With Magma PDF
Wieb Bosma
John Cannon
Catherine Playoust
Allan Steel
Typeset by computer using Donald Knuth’s TEX, and the document preparation
system LATEX developed by Leslie Lamport.
Introduction
This book is neither an introductory manual nor a reference manual for Magma. Those needs are
met by the books An Introduction to Magma and Handbook of Magma Functions. Even the most
keen inductive learners will not learn all there is to know about Magma from the present work.
What Solving Problems with Magma does offer is a large collection of real-world algebraic problems,
solved using the Magma language and intrinsics. It is hoped that by studying these examples,
especially those in your specialty, you will gain a practical understanding of how to express math-
ematical problems in Magma terms. Most of the examples have arisen from genuine research
questions, some of which the other computer algebra systems on the market cannot handle well,
and a few which stretch Magma to its limit too. If you are trying the examples on your own
Magma, be warned that some of the examples require significant CPU time and/or storage space
to complete their execution.
We thank all those who have contributed examples. Some are older problems, solved with
Magma’s predecessor Cayley. Others are new ones that exploit Magma’s ability to straddle
all aspects of algebra. We welcome comments on this book and submissions of new approaches
that you think might advantage other mathematicians.
iii
Contents
Introduction iii
1 Language 1
1.1 Puzzle-solving . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
1.1.1 Dog Daze . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
1.1.2 Letters standing for digits . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
1.2 Sets, sequences and functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
1.2.1 Farey sequence . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
1.2.2 The knapsack problem . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
1.2.3 Simulation of a cellular automaton . . . . . . . . . . . . . . . . . . . . . . . 7
2 The Integers 11
2.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
2.2 Arithmetic and Arithmetic Functions . . . . . . . . . . . . . . . . . . . . . . . . . . 11
2.2.1 Example: Amicable numbers . . . . . . . . . . . . . . . . . . . . . . . . . . 11
2.3 Factorization and Primality Proving . . . . . . . . . . . . . . . . . . . . . . . . . . 12
2.3.1 Example: Cunningham Factorization . . . . . . . . . . . . . . . . . . . . . . 12
2.3.2 Example: Sums of Squares . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
4 Finite Fields 21
4.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21
4.2 Finite Fields . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21
4.2.1 Example: Lattice of Finite Fields . . . . . . . . . . . . . . . . . . . . . . . . 22
v
vi CONTENTS
5 Number Fields 25
5.1 Features . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25
5.1.1 Example: Imprimitive degree 9 fields . . . . . . . . . . . . . . . . . . . . . . 25
5.1.2 Example: Galois Group and its Action . . . . . . . . . . . . . . . . . . . . . 28
7 Function Fields 49
7.1 General Function Fields . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49
7.2 Algebraic Function Fields . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49
7.2.1 Example: Invariants . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 50
12 Permutation Groups 79
12.1 Contruction and Actions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 79
12.1.1 Shuffle Groups . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 79
12.1.2 Construction of the Design Associated with M24 . . . . . . . . . . . . . . . 80
12.2 Subgroup Structure of Permutation Groups . . . . . . . . . . . . . . . . . . . . . . 82
12.2.1 Chief Series of Rubik’s 4 × 4 × 4 cube . . . . . . . . . . . . . . . . . . . . . 82
12.2.2 Subgroup lattice . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 83
12.3 Representations and Cohomology . . . . . . . . . . . . . . . . . . . . . . . . . . . 84
13 Matrix Groups 85
13.1 Constructions of Matrix Groups . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 85
13.1.1 Random generation of matrix group elements . . . . . . . . . . . . . . . . . 85
viii CONTENTS
14 Coxeter Groups 91
14.1 Summary of Facilities . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 91
14.2 Constructing the split octonions . . . . . . . . . . . . . . . . . . . . . . . . . . . . 91
14.2.1 The Lie algebra of type D4 . . . . . . . . . . . . . . . . . . . . . . . . . . . 92
14.2.2 The Lie algebra of type G2 . . . . . . . . . . . . . . . . . . . . . . . . . . . 93
14.2.3 The octonion algebra . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 95
18 Lattices 119
18.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 119
18.2 Construction and Operations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 119
18.2.1 Example: Constructing the Barnes-Wall Lattice . . . . . . . . . . . . . . . 120
18.3 Properties . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 120
18.3.1 Example: Gosset Lattice . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 121
18.3.2 Example: Voronoi Cells of a Perfect Lattice . . . . . . . . . . . . . . . . . . 122
18.4 Reduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 123
18.4.1 Example: Knapsack Problem . . . . . . . . . . . . . . . . . . . . . . . . . . 124
CONTENTS ix
19 Algebras 129
19.1 Finite Dimensional Algebras . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 129
19.1.1 A Jordan algebra . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 129
19.1.2 The real Cayley algebra . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 130
19.2 Group Algebras . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 131
19.2.1 Diameter of the Cayley graph . . . . . . . . . . . . . . . . . . . . . . . . . . 131
19.2.2 Random distribution of words . . . . . . . . . . . . . . . . . . . . . . . . . . 132
19.3 Matrix Algebras . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 133
19.3.1 Jordan forms of matrices over a finite field . . . . . . . . . . . . . . . . . . . 133
19.3.2 Jordan forms of matrices over the rationals . . . . . . . . . . . . . . . . . . 135
19.3.3 Matrix algebra over a polynomial ring . . . . . . . . . . . . . . . . . . . . . 137
19.3.4 Orders of a unit in a matrix ring . . . . . . . . . . . . . . . . . . . . . . . . 137
19.4 Lie Algebras . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 138
19.5 Finitely presented algebras . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 139
19.5.1 Hecke algebra . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 139
23 Graphs 165
23.1 Construction and Properties of Graphs . . . . . . . . . . . . . . . . . . . . . . . . 165
23.1.1 Construction of Tutte’s 8-cage . . . . . . . . . . . . . . . . . . . . . . . . . 165
23.1.2 Construction of the Grötzch Graph . . . . . . . . . . . . . . . . . . . . . . . 166
23.2 Automorphism Groups . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 166
23.2.1 Automorphism Group of the 8-dimensional Cube Graph . . . . . . . . . . . 167
33 Miscellaneous 227
33.1 NTRU . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 227
33.2 Rijndael’s linear diffusion matrix . . . . . . . . . . . . . . . . . . . . . . . . . . . . 230
Chapter 1
Language
1.1 Puzzle-solving
The problem ‘DOG DAZE’ was taken from a May 1994 edition of the magazine published with
the Weekend Australian newspaper. It is not difficult to solve by hand, but the following code, by
Greg Gamble, indicates a way of solving it using Magma.
The Problem:
Devious Dan, the dogcatcher, found the five local dog owners most helpful, yet he still couldn’t
work out who Ms Green was, her dog’s name, or even the kind of dog she had. Ms Brown’s dog,
Loopsie or Mooksie, was not the terrier. Woopsie, the poodle, did not belong to Mary. Marion’s
setter was not Loopsie. Margie’s basset was called Smooksie or Mooksie. Myrtle, who was not Ms
Grey, owned Poopsie or Smooksie. Martha Black didn’t own the great dane. Ms Grey didn’t own
Poopsie, but Mooksie belonged to Ms White, who was not Marion.
The Solution:
> S := { a : a in C |
> implies(sn eq "Brown", (dn in {"Loopsie","Mooksie"})) and
> implies(sn eq "Brown", (db ne "terrier")) and
> iff(dn eq "Woopsie", db eq "poodle") and
> implies(dn eq "Woopsie", fn ne "Mary") and
> iff(fn eq "Marion", db eq "setter") and
1
2 CHAPTER 1. LANGUAGE
At this stage, the function needed to solve the problem can be defined. It returns the set of all
possible solutions.
A solution of the problem is a subset of the set S consisting of five 4-tuples, such that each
firstname etc. occurs precisely once. Observe that if <fn,sn,db,dn> is a member of a solution
then there exist four 4-tuples among the set of 4-tuples in S not having firstname equal to fn etc.
such that firstname etc. occurs precisely once. In this way the problem is reduced (recursively) to
problems involving successively fewer 4-tuples.
The solution can be read from the output. Note that it is unique.
The problem ‘How many are whole?’, by Susan Denham, was taken from New Scientist No. 1998
(7 Oct 1995), in the Enigma problem section on p. 63. It was brought to the attention of the
1.1. PUZZLE-SOLVING 3
The Problem:
In what follows, digits have been consistently replaced by letters, with different letters being used
for different digits:
In the list ONE TWO THREE FOUR just the first and one other are perfect squares.
In the list ONE + 1 TWO + 1 THREE + 1 FOUR + 1 just one is a perfect square.
In the list ONE + 2 TWO + 2 THREE + 2 FOUR + 2 just one is a perfect square.
Assuming that there are no leading zeros in ONE, TWO, THREE, FOUR, we know that none of
O, T, F is zero. Since ONE is a perfect square and is greater than 100, it follows that ONE+1
and ONE+2 cannot be squares, so they can be put aside from the second and third conditions.
Since TWO is greater than 100, at most one of TWO, TWO+1, TWO+2 can be a square, and
similarly for THREE and FOUR. There are three conditions involving TWO, THREE, FOUR, so
it follows that x, y + 1, z + 2 must all be perfect squares, for some permutation (x, y, z) of (TWO,
THREE, FOUR). Therefore the conditions can be rephrased as shown below:
We construct all the possibilities for ONE explicitly, by finding those squares in the range 100 to 999
whose digits are distinct. The numbers with squares in this range are between Ceiling(Sqrt(100))
= 10 and Floor(Sqrt(999)) = 31. The following constructor builds the set of possibilities. Note
that the intrinsic Intseq(n, b) converts the integer n to a base-b representation of it as a sequence
starting with the units digit.
ONEoptions has size 13, so there are 13 possibilities for ONE. Let a particular choice from
ONEoptions be ONEchoice.
At this stage, the solution splits into two: one slower algorithm, that is relatively easy to write;
and one much faster algorithm, that takes some care in crafting.
Slower Algorithm: The digits TFoptions for {T, F} will be chosen as a subset of size 2 from
the set of non-zero digits with ONEchoice removed (this set has size 6). The digits WHRUoptions
4 CHAPTER 1. LANGUAGE
for {W, H, R, U} will be chosen as a subset of size 4 from the set of all digits with the digits for
ONEchoice and TFchoice removed (this set has size 5). Finally, the ordered choice TFchoice for
T, F will be made by permuting TFoptions, and similarly for WHRUchoice. Note that the total
number of choices of digits considered under this scheme is
Now we can construct the solutions, in a single assignment. Note that in the second and third
lines, the effect is to construct the permutations of WHRUoptions and TFoptions. The function
Subsets(T, k) returns the sequence of all subsets of set T of size k.
It emerges that the solution is unique. We check that it satisfies the conditions:
Finally, we calculate FORTUNE, as the question asked. The result matches the published answer:
> 1000000*F+100000*O+10000*R+1000*T+100*U+10*N+E;
3701284
1.2. SETS, SEQUENCES AND FUNCTIONS 5
Faster Algorithm: The reason that the above algorithm is slow is that it constructs all possible
choices of digits such that ONE works, and then tests everything. It would be improved if the
choice for TWO were tested before digits were allocated to THREE and FOUR, and similarly
if the choice for THREE were be tested before digits were allocated to FOUR. (Testing FOUR
as well makes little practical difference, since there are only a few options at that stage.) This
method is followed in the version below:
The answer is the same as before, but the execution time is much less.
The Farey series Fn of degree n consists of all rational numbers with denominator less than or
equal to n, in order of magnitude. Since we will need the Numerator and Denominator functions
often, we first define abbreviations for them.
> D := Denominator;
> N := Numerator;
We present three ways to obtain the Farey series Fn of degree n. The CPU time taken to calculate
F100 will be measured for each version, in order to compare the algorithms.
6 CHAPTER 1. LANGUAGE
The first method calculates the entries in order. It uses the fact that for any three consecutive
0 00
Farey fractions pq , pq0 , pq00 of degree n:
q+n 0 q+n 0
p00 = b cp − p, q 00 = b cq − q.
q0 q0
The second method calculates the Farey series recursively. It uses the property that Fn may
0
be obtained from Fn−1 by inserting a new fraction (namely p+p
q+q 0 ) between any two consecutive
p p0
rationals q and q0 in Fn−1 for which q + q 0 equals n.
The third method uses Setseq to convert a set into a sequence and Sort to put the terms of the
sequence in ascending order:
The third method was fastest, followed by the first method. The recursive method was much
slower, but note that it effectively calculates all the Farey sequences up to the given n.
1.2. SETS, SEQUENCES AND FUNCTIONS 7
The knapsack problem is concerned with the task of selecting items to be packed into a knapsack.
The items are chosen from a large number of objects with different volumes. One can choose
as many items of whatever volume to go into the knapsack as one likes, provided that the total
volume of the knapsack is filled. This problem is in the class of NP-complete problems.
Here we present a Magma function that produces a solution to the knapsack problem. It operates
on the pseudo-non-deterministic principle of choosing some object to go into the knapsack and
trying to pack the rest of the knapsack, recursively. The volume of the knapsack is t, and the list
of volumes of the objects is contained in the sequence Q. The aim is to find some entries of Q
whose sum is t.
We use this function to find some distinct primes less than 100 whose sum is 151:
This problem has been adapted from a Mathematica example discussed by Richard Gaylord.1 The
Magma program was developed by Graham Matthews. Thanks also to Richard J. Fateman for
his assistance.
Introduction: Turbulent cascading has been suggested as the underlying cause of a wide variety
of phenomena, including geological upheavals (such as volcanic eruptions and earthquakes), species
1 Richard J. Gaylord and Paul R. Wellin, Computer Simulations with Mathematica: Explorations in Complex
Physical and Biological Systems (Santa Clara, CA: Springer-Verlag TELOS, 1995), 147–149.
8 CHAPTER 1. LANGUAGE
extinction during evolution, and fluid turbulence. A simple one-dimensional probabilistic cellular
automaton (CA), known as the forest fire model, displays this behaviour.
The Forest Fire CA System: The forest fire CA employs a one-dimensional lattice of length n,
with periodic boundary conditions. Lattice sites may have a value of 0, 1 or 2, where 0 represents
an empty site (or ‘hole’), 1 represents a healthy tree (or ‘tree’), and 2 represents a burning tree.
A forest is a set of contiguous sites (i.e., a connected segment) with value 1 or 2. A forest preserve
consists of forests separated by gaps (or ‘deserts’) consisting of clusters of connected holes. The
system evolves in a specified number of time steps, in each of which entire forests of trees can
catch fire and burn down and trees can sprout on individual empty sites.
(Note: having all of the trees in a forest burn down in a single time step while trees grows
independently of one another provides a separation between the time scales for the processes of
deforestation and reforestation).
The Algorithm:
(1) A forest preserve of length n, consisting of empty sites and tree sites, is created.
All of the sites in the forest preserve are updated in each time step, according to the following
sequence of steps:
(2a) Trees catch fire with probability f and empty sites sprout trees with probability p.
(2b) All tree sites adjacent to an ignited tree site (i.e., trees in the same forest) ignite.
The sequence of steps 2a-c can be combined and applied to any forest preserve configuration.
>
> return [ i eq 1 select InitialPreserve else
> destroy(forestIgnite(treeGrowIgnite(Self(i-1)))) : i in [1..m]];
> end function;
We can call the function for a forest of 25 trees, with a probability of catching fire of 0.2 and a
probability of empty sites sprouting trees of 0.4, over 200 iterations:
Now the sequence F contains the history of the preserve. By printing some values of F we can
see how the forest changes over the iterations.
2.1 Introduction
Magma contains a purpose-written fast integer arithmetic package. Both Karatsuba and FFT
algorithms are used for integer multiplication while the Weber accelerated GCD algorithm is
used for GCD calculation. Assembler macros are used for critical operations and 64-bit hardware
instructions are used on DEC-Alpha machines.
A pair of positive integers (m, n) is called amicable if n is equal to the sum of the proper divisors
of m (that is, the divisors excluding m itself), and vice versa. The following code finds such pairs.
Note that it also finds perfect numbers, that is, amicable pairs of the form (m, m).
11
12 CHAPTER 2. THE INTEGERS
28 28
220 284
284 220
496 496
1184 1210
1210 1184
2620 2924
2924 2620
5020 5564
5564 5020
6232 6368
6368 6232
8128 8128
Magma contains a database of factorizations of 199,044 integers of the form an ± 1. This database
includes the factorizations of integers of the form an ± 1, a ≤ 12, produced by Sam Wagstaff and
collaborators. In addition, it includes factorizations of integers of the form pn ± 1, for primes
13 ≤ p ≤ 1000 as tabulated by Richard Brent and collaborators. Given an integer of the form
an ± 1 that lies in the scope of the tables, Magma empolys an algorithm due to Richard Brent
that derives its factorization using a combination of table lookup, Aurifeuillian factorization and
algebraic factorization. We demonstrate the process by factoring 3429 + 1, an integer having 205
decimal digits.
For each integer n in the range 1020 ≤ n ≤ 1020 + 100, we determine whether n can be written as
the sum of two perfect squares. The function NormEquation is used for the computation.
> b := 10^20;
> for n in [b .. b + 100] do
> s, x, y := NormEquation(1, n);
> if s then
> printf "%o = %o^2 + %o^2\n", n, x, y;
> end if;
> end for;
100000000000000000000 = 10000000000^2 + 0^2
100000000000000000001 = 10000000000^2 + 1^2
100000000000000000004 = 10000000000^2 + 2^2
100000000000000000009 = 9551166965^2 + 2962298028^2
100000000000000000016 = 10000000000^2 + 4^2
100000000000000000025 = 8429062912^2 + 5380603909^2
100000000000000000036 = 9694446870^2 + 2453100056^2
100000000000000000045 = 8337268941^2 + 5521770242^2
100000000000000000049 = 9969472985^2 + 780774232^2
100000000000000000053 = 9421472622^2 + 3351992487^2
100000000000000000058 = 8964092203^2 + 4432273793^2
100000000000000000064 = 10000000000^2 + 8^2
100000000000000000072 = 9727676814^2 + 2317823074^2
100000000000000000080 = 8585762712^2 + 5126858556^2
14 CHAPTER 2. THE INTEGERS
3.1 Introduction
A polynomial ring may be formed over any commutative ring, including a polynomial ring. Since
computational methods for univariate polynomial rings are often much simpler and more efficient
than those for multivariate rings (especially over a field), we discuss the two cases separately. In
this section, the symbol K, appearing as a coefficient ring, will denote a field.
15
16 CHAPTER 3. UNIVARIATE POLYNOMIAL RINGS
The resultant of two polynomials tells whether they have a non-trivial GCD. We take two poly-
nomials in ZZ[x] which are coprime and using the resultant we find the primes modulo which the
polynomials have a common factor.
For each prime divisor p of the resultant r we note the GCD of the polynomials modulo p.
> PrimeDivisors(r);
[ 2, 3, 71, 704807, 1584901, 865534777 ]
> for p in PrimeDivisors(r) do
for> PP<y> := PolynomialRing(GF(p));
for> printf "p = %o, GCD = %o\n", p, GCD(PP ! f, PP ! g);
for> end for;
p = 2, GCD = y^2 + y + 1
p = 3, GCD = y + 1
p = 71, GCD = y + 40
p = 704807, GCD = y + 476610
p = 1584901, GCD = y + 297038
p = 865534777, GCD = y + 337462522
For all other primes not dividing the resultant, the GCD is trivial. We check that this is the case
for the primes up to 23.
We give a Magma language implementation of the modular algorithm for computing the GCD of
two monic polynomials with integer coefficients. [A description of the algorithm may be found
in J.H. Davenport, Y. Siret and E. Tournier, Computer Algebra, Academic Press, London, 1988.]
(Magma has an intrinsic GCD to compute this value; the example is for illustrative purposes). The
GCD function, ModGCD, calls the function Chinese to perform the Chinese Remainder Algorithm
on the polynomials a modulo m and b modulo p. Chinese, in turn, calls the Magma intrinsic
Solution(u, v, m), where u, v and m are pairs of integers, to solve the congruences
u1 x = v1 (mod m1 ), u 2 x = v2 (mod m2 ),
The polynomial a and the polynomial returned by Chinese are equal when both are coerced into
the ring of polynomials over ResidueClassRing(m), and similarly for b and p.
For each successive prime, the function ModGCD creates Fp [u] together with the natural homomor-
phisms φ : ZZ[x] → Fp [u] and ρ : Fp [u] → ZZ[x]. The GCD of the images of polynomials f and g in
Fp [u] is found by calling the intrinsic function GCD.
We also try our function on a much larger example. The method is quite powerful even for very
large examples.
> f := (x+1)^100;
> g := (x+2)^100;
> gcd := ModGCD(f*g, f*(g+1));
> time gcd := ModGCD(f*g, f*(g+1));
Time: 1.799
> gcd eq f;
true
> Degree(f);
100
> Max(Coefficients(f));
100891344545564193334812497256 51
• Factorization over GF(q): Small field Berlekamp, large field Berlekamp, Cantor-Zassenhaus algo-
rithms
• Factorization over Z
Z and Q: Collins-Encarnacion algorithm
• Factorization over Q p : Ford-Zassenhaus algorithm
• Factorization over Q(α): Trager algorithm
The key algorithms for univariate polynomials are GCD and factorization. Greatest common
divisors for polynomials over ZZ are computed using either a modular algorithm or the GCD-HEU
method, while for polynomials over a number field, a modular method is used. The factorization
of polynomials over ZZ uses single factor bounds, parallel Hensel lifting and other recent ideas of
Collins and Encarnacion. Magma factors the first challenge polynomial of Zimmermann (degree
156, 78 digit coefficients over ZZ) in 6 seconds.
We first factorize the polynomial x100 + x + 1 over the finite field of cardinality 2.
We now factorize the same polynomial over the finite field of cardinality 214 and notice that the
degree 14 factor above splits into linear factors.
We factorization a polynomial of degree 40 over the cyclotomic field K = Q(ζ5 ) of order 5. Notice
that the polynomial has rational coefficients but splits over K into polynomials whose coefficients
are not rational.
4.1 Introduction
The finite field module uses different representations of finite field elements depending upon the size
of the field. Thus, in the case of small to medium sized fields, the Zech logarithm representation is
used. For a large degree extension K of a (small) prime field, K is represented as an extension of
an intermediate field F whenever possible. The intermediate field F is chosen to be small enough
so that the fast Zech logarithm representation may be used. Thus, Magma supports finite fields
ranging from GF(2n ), where the degree n may be a thousand or more, to fields GF(p), where the
characteristic p may be a thousand-bit integer.
21
22 CHAPTER 4. FINITE FIELDS
We create GF(536 ) and its full subfield-lattice and then experiment with the relationships. We
start by creating F 36 with generator w36 as GF(536 ) and note the defining polynomial of F 36
(the minimal polynomial of w36).
Note that the defining polynomial of F 12 is not the same as the Conway polynomial for GF(512 ).
So set G with generator g to be the finite field whose defining polynomial is the Conway polynomial.
> F12 ! g;
4*w12^11 + w12^10 + 2*w12^7 + 2*w12^6 + 3*w12^5 + 3*w12^4 + 3*w12^3 + 3*w12^2 +
4*w12 + 1
4.2. FINITE FIELDS 23
Check that the minimal polynomial of g over F 6 is quadratic (note that F 6 is automatically a
subfield of G by transitivity).
Since g is primitive (root of a Conway polynomial), setting h to the following power will obtain
an element whose minimal polynomial has degree 6, i.e. h generates a field of degree 6.
Since all fields of the same degree are equal, h must be in F 6. Set h6 to the element in F 6 equal
to h.
> h in F6;
true
> h6 := F6 ! h;
> h6;
w6^3281
Now lift h into F 36 in two different ways and check that the “diagram” commutes. Lifting h6 via
F 18 gives the same answer as lifting h directly into F 36.
Note that elements in two different fields (w18 in F 18 and g in G) can be compared, combined
etc. because there is an automatic cover for them.
> w18 + g;
w36^35 + 2*w36^34 + 2*w36^33 + w36^32 + 2*w36^31 + w36^30 + w36^29 + w36^27 +
24 CHAPTER 4. FINITE FIELDS
Let z be w18 + g (which will reside in F 36). We can calculate the order of z and the factorization
of the order of z easily.
> z := w18 + g;
> Order(z);
1818989403545856475830078
> FactoredOrder(z);
[ <2, 1>, <3, 3>, <7, 1>, <13, 1>, <19, 1>, <31, 1>, <37, 1>, <601, 1>, <829,
1>, <5167, 1>, <6597973, 1> ]
However, z is not primitive, which can also be seen from the factorization of 536 − 1.
> IsPrimitive(z);
false
> Factorization(5^36-1);
[ <2, 4>, <3, 3>, <7, 1>, <13, 1>, <19, 1>, <31, 1>, <37, 1>, <601, 1>, <829,
1>, <5167, 1>, <6597973, 1> ]
Clearly z is the 8-th power of a primitive element. Let y be the 8-th root of z. Then y is primitive.
2 3
Finally, we test whether y is normal over F 4, i.e. whether [y, y q , y q , y q , . . .] are independent over
F 4 where q = #F 4 = 54 .
5.1 Features
• Simple and relative extensions
• Maximal order, integral basis (Round 2 and Round 4 algorithms)
• Quotient orders, suborders, extension orders
• Construction of integral and fractional ideals
• Ideal arithmetic: product, quotient, gcd, lcm
• Determination of whether an ideal is: integral, prime, principal
• Factorization of an ideal; Decomposition of primes
• Residue field of an order modulo a prime ideal
• Class group, ray class group
• Unit group, exceptional units, S-units, regulator
• Solution of: norm equations, relative norm equations
• Solution of: Thue equations, unit equations, index form equations, Mordell equations
• Determination of subfields
• Automorphism group of a normal extension
• Isomorphism of number fields
• Galois group of a polynomial (for degrees less than 12)
In this example we illustrate how to construct some of the fields that are the subject of study in
a certain paper, and show how to verify some of the results mentioned there. The paper is: F.
Diaz y Diaz, M. Olivier, Imprimitive ninth-degree number fields with small discriminants, Math.
Comp. 64 (1995), 305–321.
We begin with two special fields of signature (9, 0): first the maximal real subfield of the cyclotomic
field Q(ζ19 ).
25
26 CHAPTER 5. NUMBER FIELDS
As expected, only the prime 19 ramifies in the field, and indeed it is totally ramified:
The next field is the composite field of k = Q(α) where α3 = −α2 + 2α + 1, and l = Q(γ) where
γ 3 = 3γ + 1. Note that we create a relative extension by a rational polynomial. The field contains
two other non-isomorphic cubic subfields.
The field L is one of 3 imprimitive degree 9 fields given in Diaz y Diaz and Olivier for which the
class group is C3 × C3 . We find its class group. We also find the cubic subfield; we show that it
is isomorphic to k above and create the explicit isomorphism.
> C, m := ClassGroup(L);
> C;
Abelian Group isomorphic to Z/3 + Z/3
Defined on 2 generators
Relations:
3*C.1 = 0
3*C.2 = 0
> Norm( m(C.1) ), Norm( m(C.2) );
7 27
> S := Subfields(L);
> S[2][1];
Number Field with defining polynomial x^3 - 22*x^2 + 159*x - 377
over the Rational Field
> H<h> := S[2][1]; g := S[2][2];
> fl, f := IsIsomorphic(k, H);
> fl;
true
> f(k.1);
h^2 - 14*h + 47
> m<y> := MinimalPolynomial(g(f(k.1))); m;
y^3 + y^2 - 2*y - 1
In Diaz y Diaz and Olivier’s paper, 4 non-isomorphic fields are constructed that are all relative
cubic extensions of discriminant −2045563163 of the cubic field k of discriminant 49 defined above.
We construct the 4 fields, using the given cubic polynomials, as relative and absolute extensions.
We check the discriminants; note that the computation of the discriminant triggers the determi-
nation of the ring of integers.
By just looking at the decomposition of the primes 11, 17 and 19 (as suggested by the authors)
we see that the fields are non-isomorphic.
Number Field with defining polynomial x^9 - 4*x^8 + 14*x^7 - 39*x^6 + 72*x^5 -
110*x^4 + 128*x^3 - 78*x^2 + 16*x - 1 over the Rational Field
-2045563163
If it is possible to obtain the full factorization of an integer polynomial over its splitting field, the
Galois action of the group of the splitting field can be made entirely explicit. In this example
we show how it can be done in Magma, and how to find the Galois correspondence (between
subgroups and subfields). Although there exists a polynomial-time algorithm for the factorization
of polynomials over number fields, in practice this is the bottleneck for our approach to Galois
theory. Only in small examples we will be able to construct the splitting field as below.
We begin with a cubic polynomial f and determine its Galois group using the intrinsic function
GaloisGroup(f). This will be a degree-3 representation.
Next, we find the Galois group in two degree-6 representations. Firstly, we construct it bare-
handed. We start by obtaining the splitting field for f as a two-step extension of Q.
5.1. FEATURES 29
We factorize f over the splitting field, and obtain all its roots from the linear factors.
Each of the roots is an algebraic conjugate of the primitive element a of the field. The elements
of the Galois group of A over Q are obtained by sending a to one of its conjugates. Thus the
action on A of such an element of the Galois group is determined by the polynomial (with rational
coefficients) expressing the conjugate in a. These polynomials are stored in P below. We (again)
determine the Galois group: by numbering the algebraic conjugates ci and finding all images of ci
under a given Pj , we obtain the permutation associated with Pj . The Galois group H consists of
these permutations on 6 letters.
Lastly, we find the Galois group G using the intrinsic function once more, but in terms of the
degree-6 defining polynomial of the splitting field. It will be conjugate to H: a simple renumbering
of roots makes them equal. As we see, we only need to cyclically permute three roots.
> G := GaloisGroup(DefiningPolynomial(A));
> fl, el := IsConjugate(Sym(6), G, H);
> fl, el;
true (3, 4, 5)
Since we have the explicit action of the Galois group, we can now find the quadratic subfield of A
corresponding to the subgroup K of H of order 3. We create the sequence of automorphisms of A
contained in K and see that the trace of a3 generates the required quadratic field.
> S := Subgroups(H);
> S;
Conjugacy classes of subgroups
------------------------------
√ √
Therefore the quadratic subfield is Q( −207) = Q( −23).
Chapter 6
Multivariate Polynomial Rings
6.1 Introduction
Multivariate polynomial rings in any number of variables may be formed over any coefficient
ring, including a polynomial ring. Multivariate polynomials are represented in distributive form,
using ordered linked lists of coefficient-monomial pairs. Different orderings are allowed on the
monomials; these become significant in the construction of Gröbner bases of ideals. Computations
with ideals are currently allowable over fields only.
This examples shows how one can construct different polynomial rings with different orders.
> Z := IntegerRing();
> // Construct polynomial ring with block elimination and a > d > b > c
> P<a,b,c,d> := PolynomialRing(Z, 4, "elim", [1, 4], [2, 3]);
> a + b + c + d;
a + d + b + c
> a + d^10 + b + c^10;
d^10 + a + c^10 + b
> a + d^10 + b + c;
d^10 + a + b + c
> // Construct polynomial ring with weight order and x > y > z
> P<x,y,z> := PolynomialRing(Z, 3, "weight", [100,10,1, 1,10,100, 1,1,1]);
33
34 CHAPTER 6. MULTIVARIATE POLYNOMIAL RINGS
> x + y + z;
x + y + z
> (x+y^2+z^3)^4;
x^4 + 4*x^3*y^2 + 4*x^3*z^3 + 6*x^2*y^4 + 12*x^2*y^2*z^3 + 6*x^2*z^6 + 4*x*y^6 +
12*x*y^4*z^3 + 12*x*y^2*z^6 + 4*x*z^9 + y^8 + 4*y^6*z^3 + 6*y^4*z^6 +
4*y^2*z^9 + z^12
• Monomial orders: lexicographical, graded lexicographical, graded reverse lexicographical, block elim-
ination, general weight vectors
• Arithmetic with elements
• Recursive coefficient, monomial, term, and degree access
• Determination of whether an element is: a unit, a zero-divisor, nilpotent
• Differentiation, integration, evaluation and interpolation
• S-polynomial of two polynomials
We let P = Q[x, y, z], and give an example of interpolation. We find a polynomial which, when
evaluated in the first variable x at the rational points 1, 2, 3, yields y, z, y + z respectively. We
check the result by evaluating.
> Q := RationalField();
> P<x, y, z> := PolynomialRing(Q, 3);
> f := Interpolation([Q | 1, 2, 3], [y, z, y + z], 1);
> f;
x^2*y - 1/2*x^2*z - 4*x*y + 5/2*x*z + 4*y - 2*z
> [ Evaluate(f, 1, v) : v in [1, 2, 3] ];
[
y,
z,
y + z
]
We illustrate in this example how resultants can be used to perform various operations in algebraic
number fields.
6.4. POLYNOMIAL RINGS: GCD AND RESULTANT 35
Let K be the number field Q(α) where α12 + α + 1 = 0 and let L be the extension field K(β) of
K where β 5 − β 3 − α = 0. For this example we let f and g be the corresponding polynomials in
Q[a, b].
Suppose we wish to the compute the minimal polynomial of β over Q. There are many ways to
do this, but using resultants we only need compute Resa (f, g); the squarefree part of this is the
minimal polynomial we desire, which is the resultant itself in this example.
To the compute the minimal polynomial of α + β over Q, we compute Resa (f, h) where h(a, b) =
g(a, b − a).
Notice that the lexicographical Gröbner basis (with a > b) of the ideal generated by f and g
contains f and the minimal polynomial of β (written in b).
6.5 Factorization
• Factorization over GF(q), ZZ, Q (EEZ algorithm), Q(α) (Trager algorithm) and R(x1 , . . . , xn ) where
R is any of the previous rings
We create a polynomial f in the polynomial ring in three indeterminates over the ring of integers
by multiplying together various trinomials. The resulting product f has 461 terms and total degree
15. We then factorize f to recover the trionomials.
We factorize a polynomial lying in K[x, y, z], where K is the cyclotomic field Q(ζ5 ) of order 5.
Notice that the polynomial has rational coefficients and is irreducible over Q but factors non-
trivially over K.
Magma computes the lex order Gröbner basis for the Katsura-5 problem in 4.5 seconds and
the lex order Gröbner basis for the cyclic 6-th roots problem in 3.9 seconds. Taking a much
more difficult example, Magma computes the grevlex order Gröbner basis for the cyclic 7-th
roots problem in 780 seconds and transforms to the lex order Gröbner basis (using the FGLM
algorithm) in a further 8563 seconds.
We compute the Gröbner basis of the “Cyclic-6” ideal with respect to the lexicographical order.
The ideal is an ideal of the polynomial ring Q(x, y, z, t, u, v). We also note that the last polynomial
in the Gröbner basis is univariate (since, in fact, the ideal is zero-dimensional and the monomial
order is lexicographical) and observe that it has a nice factorization. Note especially that in this
example, homogenizing at first and keeping the Gröbner basis reduced makes this computation very
fast; without using these features (i.e., if the parameters Homogenize := false or ReduceByNew
:= false are given), the computation is much more expensive (takes hundreds of seconds on the
same computer).
38 CHAPTER 6. MULTIVARIATE POLYNOMIAL RINGS
> Q := RationalField();
> P<x,y,z,t,u,v> := PolynomialRing(Q, 6);
> I := ideal<P |
> x + y + z + t + u + v,
> x*y + y*z + z*t + t*u + u*v + v*x,
> x*y*z + y*z*t + z*t*u + t*u*v + u*v*x + v*x*y,
> x*y*z*t + y*z*t*u + z*t*u*v + t*u*v*x + u*v*x*y + v*x*y*z,
> x*y*z*t*u + y*z*t*u*v + z*t*u*v*x + t*u*v*x*y + u*v*x*y*z + v*x*y*z*t,
> x*y*z*t*u*v - 1>;
> time B := GroebnerBasis(I);
Time: 3.870
> #B;
17
> B[17];
v^48 - 2554*v^42 - 399710*v^36 - 499722*v^30 + 499722*v^18 + 399710*v^12 +
2554*v^6 - 1
> Factorization(B[17]);
[
<v - 1, 1>,
<v + 1, 1>,
<v^2 + 1, 1>,
<v^2 - 4*v + 1, 1>,
<v^2 - v + 1, 1>,
<v^2 + v + 1, 1>,
<v^2 + 4*v + 1, 1>,
<v^4 - v^2 + 1, 1>,
<v^4 - 4*v^3 + 15*v^2 - 4*v + 1, 1>,
<v^4 + 4*v^3 + 15*v^2 + 4*v + 1, 1>,
<v^8 + 4*v^6 - 6*v^4 + 4*v^2 + 1, 1>,
<v^8 - 6*v^7 + 16*v^6 - 24*v^5 + 27*v^4 - 24*v^3 +
16*v^2 - 6*v + 1, 1>,
<v^8 + 6*v^7 + 16*v^6 + 24*v^5 + 27*v^4 + 24*v^3 +
16*v^2 + 6*v + 1, 1>
]
• Radical of an ideal
• Syzygy modules
We create a certain symmetrical ideal I of the multivariate polynomial ring Q[x, y, z]. The mono-
mial order is the lexicographical order. We then examine the structure of the ideal and its variety
by computing the primary decomposition and radical.
We next compute the radical R of I. Notice that R properly contains I (so I is not radical).
40 CHAPTER 6. MULTIVARIATE POLYNOMIAL RINGS
> I subset R;
true
> R subset I;
false
> IsRadical(I);
false
y^4,
z - 1
],
Ideal of Polynomial ring of rank 3 over Rational Field
Lexicographical Order
Variables: x, y, z
Dimension 0, Non-radical, Primary, Non-prime
Size of variety over algebraically closed field: 1
Groebner basis:
[
x + z,
y - 1,
z^4
],
Ideal of Polynomial ring of rank 3 over Rational Field
Lexicographical Order
Variables: x, y, z
Dimension 0, Non-radical, Primary, Non-prime
Size of variety over algebraically closed field: 1
Groebner basis:
[
x - 1,
y + z,
z^4
],
Ideal of Polynomial ring of rank 3 over Rational Field
Lexicographical Order
Variables: x, y, z
Dimension 0, Radical, Prime
Size of variety over algebraically closed field: 24
Groebner basis:
[
x + y + 61112/64995*z^11 + 9482/4333*z^10 + 74792/21665*z^9 +
79192/9285*z^8 + 322716/21665*z^7 - 208232/21665*z^6 -
230586/21665*z^5 + 5587/3095*z^4 + 84806/21665*z^3 -
198367/43330*z^2 + 116852/21665*z - 2951/6190,
y^2 + 61112/64995*y*z^11 + 9482/4333*y*z^10 + 74792/21665*y*z^9 +
79192/9285*y*z^8 + 322716/21665*y*z^7 - 208232/21665*y*z^6 -
230586/21665*y*z^5 + 5587/3095*y*z^4 + 84806/21665*y*z^3 -
198367/43330*y*z^2 + 116852/21665*y*z - 2951/6190*y +
53057/64995*z^11 + 27833/12999*z^10 + 257296/64995*z^9 +
616304/64995*z^8 + 377451/21665*z^7 + 14838/21665*z^6 -
79997/43330*z^5 + 70123/43330*z^4 + 143529/86660*z^3 -
373089/86660*z^2 + 301193/86660*z - 114169/86660,
z^12 + 2*z^11 + 3*z^10 + 8*z^9 + 13*z^8 - 15*z^7 - 15/2*z^6 + 3*z^5 +
9/4*z^4 - 6*z^3 + 15/2*z^2 - 3*z + 3/4
]
]
> P[1 .. 3];
[
Ideal of Polynomial ring of rank 3 over Rational Field
Lexicographical Order
Variables: x, y, z
Dimension 0, Radical, Prime
42 CHAPTER 6. MULTIVARIATE POLYNOMIAL RINGS
There are thus 4 families of solutions to the set of equations implied by I. The first 3 families
yield the solutions (1, 0, 0), (0, 1, 0) and (0, 0, 1). These solutions were obvious from the original
basis of the ideal I. The last family (the variety of P [4]) yields a set of 24 solutions, lying in an
algebraic number field of degree 24.
We construct an ideal I of the polynomial ring GF(2)[x, y, z], and discover that the ideal is the
full polynomial ring. Suppose we then wish to write 1 ∈ I as an (algebraic) expression in terms of
our original generators of the ideal. We use RelationIdeal to find that expression.
Variables: x, y, z
Groebner basis:
[
1
]
> Q<a, b> := PolynomialRing(GF(2), 2);
> R := RelationIdeal(S, Q);
> R;
Ideal of Polynomial ring of rank 2 over GF(2)
Lexicographical Order
Variables: a, b
Basis:
[
a^6 + a + b^2 + 1
]
> // Check the expression:
> S[1]^6 + S[1] + S[2]^2;
1
We illustrate a subalgorithm of the Invariant Theory module of Magma which uses the Hilbert-
driven Buchberger Algorithm.
Let R be the invariant ring of the (permutation) cyclic group G of order 4 over the field K = GF(2).
Suppose we have a sequence L of 4 homogeneous invariants of degrees 1, 2, 2, and 4 respectively.
We wish to determine efficiently whether the polynomials of L constitute primary invariants for R.
To check this, the ideal generated by L must be zero-dimensional and the elements of L must be
algebraically independent. This is equivalent to the condition that the weighted numerator of the
Hilbert series of the ideal is the product (1 − t)(1 − t2 )2 (1 − t4 ). If that is not the correct weighted
numerator, it will be less than the correct weighted numerator so the algorithm will return true if
and only if the polynomials L do constitute primary invariants for R.
> K := GF(2);
> P<a,b,c,d> := PolynomialRing(K, 4);
> L := [
> a + b + c + d,
> a*b + a*d + b*c + c*d,
> a*c + b*d,
> a*b*c*d
44 CHAPTER 6. MULTIVARIATE POLYNOMIAL RINGS
> ];
> // Form potential Hilbert series weighted numerator
> T<t> := PolynomialRing(IntegerRing());
> N := &*[1 - t^TotalDegree(f): f in L];
> N;
t^9 - t^8 - 2*t^7 + 2*t^6 + 2*t^3 - 2*t^2 - t + 1
> time l, B := HilbertGroebnerBasis(L, N);
> l;
true
Since HilbertGroebnerBasis returns true, the elements of L are algebraically independent (which
is a well-known fact anyway since these elements are the elementary symmetric polynomials). The
sequence B also has the Gröbner basis of the ideal generated by L.
Let K be a field, R = K[x1 , . . . , xn ] a polynomial ring over K and I an ideal of R. The quotient
ring A = R/I is called an affine algebra.
Modules over a multivariate polynomial ring K[x1 , . . . , xn ] (K a field) and quotient rings of such
(affine algebras) form a special category in Magma. Multivariate polynomial rings are not principal
ideal rings in general, so the standard matrix echelonization algorithms are not applicable. Magma
allows computations in modules over such rings by adding a column field to each monomial of a
polynomial and then by using the ideal machinery based on Gröbner bases. This method is much
more efficient than introducing new variables to represent the columns since the number of columns
does not affect the total number of variables.
We construct simple generic free modules over Q[x, y, z]. The first module has default weights 0
on its columns, while the second has weights 1, 2, and 3 respectively on its columns.
Given any field K and indeterminates x1 , . . . , xn , the user may form the field of rational functions
K(x1 , . . . , xn ) as the localization of the polynomial ring K[x1 , . . . , xn ] at the prime ideal hxi. At
present only arithmetic and elementary operations are available in general function fields.
A function field is a finite algebraic extension K(x, α) of the field of rational functions K(x), where
K is either Fq , Q or a number field.
• Genus
• Basis reduction for finite orders (Pohst-Schörnig method) for global fields
49
50 CHAPTER 7. FUNCTION FIELDS
The development of this module is a joint project with the KANT group. Work is under way on
developing algorithms for computing the divisor class group.
We create the rational function field F16 (x) and extend it by a root of the polynomial y 4 + y + x5 .
Thus, the exact constant field is K. We now construct the equation order at infinity, the maximal
order at infinity and finally the ideals corresponding to pairwise distinct places lying over the
infinite place of F.
> E := EquationOrderInfinite(F);
> E;
Infinite order over Finite field of size 2^4 defined by
y^4 + 1/x^6*y + 1/x^3
> Decomposition(Oinf);
[ Ideal of Oinf
Basis:
7.2. ALGEBRAIC FUNCTION FIELDS 51
[ 1/x 0 0 0]
[ 0 1 0 0]
[ 0 0 1 0]
[ 0 0 0 1] ]
Thus there is only one ideal lying over the infinite place.
Chapter 8
Algebraically Closed Fields
8.1 Introduction
Algebraically Closed Fields are finite algebraic extensions of Q which automatically extend when-
ever there is a need. The technique is similar to the D5 method of D. Duval et al.
Any function in Magma which works generically over a field works automatically over these fields
(including matrix and polynomial algorithms). The computation of roots and the factorization of
polynomials over these fields also work automatically (such polynomials always split into linear
factors of course). The Gröbner basis machinery works well over these fields also, allowing the
computation of the full algebraic variety of ideals.
Factorization is delayed and there is an elaborate system whereby if a factor is found, the field
automatically changes itself and reduces its elements to take advantage of the new information.
• Creation
• Minimal Polynomials
• Conjugates
• Roots and factorization of polynomials
• Simplification of conjugates
• Computation of absolute field
• Conversion to standard field
We compute the complete Jordan form of an 8 × 8 matrix with rational entries. The resulting
canonical form has entries in the algebraic closure A of Q.
> A := AlgebraicClosure();
> P<x> := PolynomialRing(A);
53
54 CHAPTER 8. ALGEBRAICALLY CLOSED FIELDS
> X;
[ 0 0 1 0 0 0 0 0]
[-1 1 1 0 -1 0 -1 1]
[ 1 0 1 0 0 0 0 0]
[ 0 0 -1 1 -1 1 0 0]
[ 0 0 1 0 -1 0 -2 1]
[ 0 1 1 -2 0 -1 2 0]
[ 0 1 -1 0 0 0 2 -1]
[-1 2 0 0 -1 0 0 0]
Next we compute the Jordan form J of X, the transformation matrix T such that T XT −1 = J,
and the primary invariant factors F of X. Notice that J is a true Jordan form with linear Jordan
blocks.
We now print out A which shows the algebraic relations (minimal polynomials) which the inde-
terminates satisfy.
> A;
Algebraically closed field with 4 indeterminates
Relations:
[
r4 + r3,
r3^2 + 1,
r2 + r1 - 1,
r1^2 - r1 - 1
]
> T;
[1 -r1 -1 0 1 0 1 -1]
8.3. ALGEBRAICALLY CLOSED FIELDS: VARIETIES 55
> T*X*T^-1 eq J;
true
> F;
[
<x - r1, 1>,
<x - r1, 2>,
<x + r1 - 1, 1>,
<x + r1 - 1, 2>,
<x - r3, 1>,
<x + r3, 1>
]
In this example we compute the full algebraic variety of the Cyclic-5 Roots ideal. We first note
the Gröbner basis of the ideal I.
> Q := RationalField();
> P<x,y,z,t,u> := PolynomialRing(Q, 5);
> I := ideal<P |
> x + y + z + t + u,
> x*y + y*z + z*t + t*u + u*x,
> x*y*z + y*z*t + z*t*u + t*u*x + u*x*y,
> x*y*z*t + y*z*t*u + z*t*u*x + t*u*x*y +
> u*x*y*z, x*y*z*t*u - 1>;
> GroebnerBasis(I);
[
x + y + z + t + u,
y^2 + 3*y*u + 2*t^6*u + 6*t^5*u^2 + t^4*u^3 - 2*t^3*u^4 + t^2 -
566/275*t*u^11 - 6273/25*t*u^6 + 69019/275*t*u - 1467/275*u^12 -
16271/25*u^7 + 179073/275*u^2,
y*z - y*u + z^2 + 2*z*u - 6/5*t^6*u - 19/5*t^5*u^2 - t^4*u^3 + t^3*u^4 -
56 CHAPTER 8. ALGEBRAICALLY CLOSED FIELDS
Now we compute the variety of I over the algebraic closure A of Q. Each 5-tuple represents a
solution to the original set of polynomials. There are 70 solutions in all.
> A := AlgebraicClosure();
> time v := Variety(I, A);
Time: 1.529
> #v;
70
> v;
[
<1, 1, 1, -r1 - 3, r1>,
<1, 1, 1, r1, -r1 - 3>,
<1, 1, -r1 - 3, r1, 1>,
<1, 1, r1, -r1 - 3, 1>,
<1, -r1 - 3, r1, 1, 1>,
<1, r1, -r1 - 3, 1, 1>,
<1, r3, r3^2, r3^3, -r3^3 - r3^2 - r3 - 1>,
<1, -r3^3 - r3^2 - r3 - 1, r3^3, r3^2, r3>,
<1, r3^3, r3, -r3^3 - r3^2 - r3 - 1, r3^2>,
<1, r3^2, -r3^3 - r3^2 - r3 - 1, r3, r3^3>,
<-r1 - 3, 1, 1, 1, r1>,
<-r1 - 3, r1, 1, 1, 1>,
<r1, 1, 1, 1, -r1 - 3>,
<r1, -r1 - 3, 1, 1, 1>,
<r3, r3, -r3^2 - 2*r3 - 1, r3^2 - r3 + 1, r3>,
<r3, r3, r3^2 - r3 + 1, -r3^2 - 2*r3 - 1, r3>,
<r3, -r3^2 - 2*r3 - 1, r3^2 - r3 + 1, r3, r3>,
<r3, r3^2, r3^3, -r3^3 - r3^2 - r3 - 1, 1>,
<r3, r3^2 - r3 + 1, -r3^2 - 2*r3 - 1, r3, r3>,
<r3, r3^3, 1, r3^2, -r3^3 - r3^2 - r3 - 1>,
<-r3^2 - 2*r3 - 1, r3, r3, r3, r3^2 - r3 + 1>,
8.3. ALGEBRAICALLY CLOSED FIELDS: VARIETIES 57
<r7, r7*r3^3 + r7*r3^2 - r7, r7*r3^3 + r7*r3^2 - r7, r7*r3^3 + r7*r3^2 - r7,
-3*r7*r3^3 - 3*r7*r3^2 + 2*r7>,
<-3*r7*r3^3 - 3*r7*r3^2 + 2*r7, r7*r3^3 + r7*r3^2 - r7, r7*r3^3 + r7*r3^2 -
r7, r7*r3^3 + r7*r3^2 - r7, r7>,
<-r7*r3^3 - r7*r3^2 + r7 + r3^3 + r3^2, -r7*r3^3 - r7*r3^2 + r7 + r3^3 +
r3^2, -r7*r3^3 - r7*r3^2 + r7 + r3^3 + r3^2, -r7 - r3^3 - r3^2 - 1,
3*r7*r3^3 + 3*r7*r3^2 - 2*r7 - 2*r3^3 - 2*r3^2 + 1>,
<-r7*r3^3 - r7*r3^2 + r7 + r3^3 + r3^2, -r7*r3^3 - r7*r3^2 + r7 + r3^3 +
r3^2, -r7*r3^3 - r7*r3^2 + r7 + r3^3 + r3^2, 3*r7*r3^3 + 3*r7*r3^2 -
2*r7 - 2*r3^3 - 2*r3^2 + 1, -r7 - r3^3 - r3^2 - 1>,
<r7*r3^3 + r7*r3^2 - r7, r7*r3^3 + r7*r3^2 - r7, r7*r3^3 + r7*r3^2 - r7, r7,
-3*r7*r3^3 - 3*r7*r3^2 + 2*r7>,
<r7*r3^3 + r7*r3^2 - r7, r7*r3^3 + r7*r3^2 - r7, r7*r3^3 + r7*r3^2 - r7,
-3*r7*r3^3 - 3*r7*r3^2 + 2*r7, r7>,
<3*r7*r3^3 + 3*r7*r3^2 - 2*r7 - 2*r3^3 - 2*r3^2 + 1, -r7*r3^3 - r7*r3^2 + r7
+ r3^3 + r3^2, -r7*r3^3 - r7*r3^2 + r7 + r3^3 + r3^2, -r7*r3^3 - r7*r3^2
+ r7 + r3^3 + r3^2, -r7 - r3^3 - r3^2 - 1>
]
We finally print out A so we can see the defining relations for r1, r3 and r7.
Factorizations of intermediate defining polynomials have been found along the way so the other
roots of the defining polynomials have been expressed in terms of r1, r3 and r7.
> A;
Algebraic closure of Q
Defining relations:
[
r10 - r3^3 - 2*r3^2 - 2*r3 - 1,
r9 + r7 + r3^3 + r3^2 + 1,
r8 + r3^2 + 2*r3 + 1,
r7^2 + r7*r3^3 + r7*r3^2 + r7 +
3*r3^3 + 3*r3^2 + 5,
r6 - r3^3,
r5 - r3^2,
r4 + r3^3 + r3^2 + r3 + 1,
r3^4 + r3^3 + r3^2 + r3 + 1,
r2 + r1 + 3,
r1^2 + 3*r1 + 1
]
Chapter 9
The Real and Complex Fields
9.1 Introduction
Two different models of the real and complex field are available in Magma. The default version is
based on semantics developed by Henri Cohen for PARI. In this model, the precision of a real or
complex number is determined by the accuracy of the operands and the operation. Whenever a real
or complex number is known exactly, it is kept in exact form and only converted to real/complex
form when it has to be used as an argument in some operation. Thus, during a calculation, real or
complex numbers will appear with varying precisions, where the precision for a particular number
is chosen in such a way that all digits should be meaningful. This is achieved through use of a
form of interval arithmetic. We call this model of the real or complex field, the free model. Magma
implements its free model using a modified version of the PARI code. The PARI code achieves its
speed by using assembler for a small number of critical operations and by careful organization.
59
60 CHAPTER 9. THE REAL AND COMPLEX FIELDS
• Riemann-ζ function
The standard elliptic and modular functions are available in two forms. Firstly, their Fourier
expansions may be calculated (i.e., power series in q = e2πis ). Secondly, their value may be
obtained at any point in the upper-half of the complex plane.
• Dedekind η function
• Jacobi sine theta-function and its k-th derivative
• Modular j-function
• Weber’s f -function, Weber’s f2 -function
• Weierstrass ρ function
Chapter 10
Finitely Presented Groups
10.1 Introduction
Given an fp-group about which nothing is known, the immediate problems are to determine
whether it is trivial, finite, infinite, free etc and to determine its finite homomorphic images,
finite index subgroups and so on. The central strategy for analyzing an fp-group is to attempt
to construct non-trivial homomorphisms, which may be onto an abelian group, p-group, nilpotent
group, soluble group, permutation group (the Todd-Coxeter algorithm) or matrix group (vector
enumeration).
The Todd-Coxeter procedure is the fundamental tool for investigating finitely presented groups.
Magma contains the recent version developed by George Havas. The following example is a
19-generator presentation for the group 3M(24) constructed by Richard Weiss. The calculations
presented below (made available by Gernot Stroth) were part of the process of verifying correctness.
> G<a,b,c,wa,wb,wc,h,d,e,w,z,f,ab,bc,bbc,abc,abbc,aabbc,u> :=
> Group<a,b,c,wa,wb,wc,h,d,e,w,z,f,ab,bc,bbc,abc,abbc,aabbc,u|
> ab*(a,b)^-1, bc*(b^wc)^-1, bbc*((b,c)*bc)^-1, abc*(bc^wa)^-1,
> abbc*(abc^wb)^-1, aabbc*(bbc^wa)^-1, u*(z*w)^-1,
> a^2, b^2, c^2, z^2, w^2, u^2, d^2, wa^2, wb^2, wc^2, e^2, f^2,
> z*(a,b^h)*ab^(h^-1), w*(a,b^(h^-1))*ab^h,
61
62 CHAPTER 10. FINITELY PRESENTED GROUPS
Having set up a presentation for the group G and generators for a subgroup H, we try to construct
the right coset space V for H in G.
We were successful! The coset space has cardinality 920 808. From this we construct the permu-
tation representation f onto P of G afforded by this coset space.
> f, P := CosetAction(V);
We use the random Schreier-Sims algorithm for a quick estimate of the order of the permutation
group P .
> RandomSchreier(P);
> Order(P);
3765617127571985163878400
> FactoredOrder(P);
[ <2, 21>, <3, 17>, <5, 2>, <7, 3>, <11, 1>, <13, 1>, <17, 1>, <23, 1>,
<29, 1> ]
This is the correct order for 3M(24). If desired we could run a verification procedure and prove
that this is the correct order for P .
A subgroup of a finitely presented group may be represented by its coset table. This representation
allows us to compute various functions of the subgroup as shown in the following list:
• Membership,
• Core, intersection normalizer, normal closure
• Transversal
• Whether conjugate, maximal, normal, etc
10.3. OPERATIONS ON SUBGROUPS OF FINITE INDEX 63
> c;
Finitely presented group C on 17 generators
Index in group p4g is 32 = 2^5
Generators as words in group p4g
C.1 = s^4
C.2 = r * s^4 * r
C.3 = (s * r)^4
C.4 = (s * r * s^-1 * r)^2
C.5 = (s^-1 * r * s * r)^2
C.6 = (s^-1 * r)^4
C.7 = s * r * s^2 * r * s^-1 * r * s^-2 * r
C.8 = s * r * s^4 * r * s^-1
C.9 = s^2 * r * s * r * s^-2 * r * s^-1 * r
C.10 = s^2 * r * s^-1 * r * s^-2 * r * s * r
C.11 = s^-1 * r * s^2 * r * s * r * s^-2 * r
C.12 = s^-1 * r * s^4 * r * s
C.13 = r * s * r * s^4 * r * s^-1 * r
C.14 = r * s^-1 * r * s^4 * r * s * r
C.15 = s^2 * r * s^2 * r * s^-2 * r * s^-2 * r
C.16 = s^2 * r * s^4 * r * s^-2
C.17 = r * s^2 * r * s^4 * r * s^-2 * r
We use the p-quotient algorithm to construct the largest finite 2-generator group having exponent
5.
> F := FreeGroup(2);
> q := pQuotient (F, 5, 14: Print := 1, Exponent := 5);
Lower exponent-5 central series for F
Group: F to lower exponent-5 central class 1 has order 5^2
Group: F to lower exponent-5 central class 2 has order 5^3
Group: F to lower exponent-5 central class 3 has order 5^5
Group: F to lower exponent-5 central class 4 has order 5^8
Group: F to lower exponent-5 central class 5 has order 5^10
Group: F to lower exponent-5 central class 6 has order 5^14
Group: F to lower exponent-5 central class 7 has order 5^18
Group: F to lower exponent-5 central class 8 has order 5^22
Group: F to lower exponent-5 central class 9 has order 5^28
Group: F to lower exponent-5 central class 10 has order 5^31
Group: F to lower exponent-5 central class 11 has order 5^33
Group: F to lower exponent-5 central class 12 has order 5^34
Group completed. Lower exponent-5 central class = 12, order = 5^34
10.5. CONSTRUCTION AND PRESENTATION OF SUBGROUPS 65
• Tietze transformations
This example shows how the low index subgroup machinery may be used to prove that a group is
infinite. The original solution is due to Mike Slattery.
The finiteness of the last of the Fibonacci groups, F (9), was settled in 1988 by M.F. Newman
using the following result:
Theorem. Let G be a group with a finite presentation on b generators and r relations, and
suppose p is an odd prime. Let d denote the rank of the elementary abelian group G1 = [G, G]Gp
and let e denote the rank of G2 = [G1 , G]Gp . If
r − b < d2 /2 − d/2 − d − e
or
r − b ≤ d2 /2 − d/2 − d − e + (e + d/2 − d2 /4)d/2,
then G has arbitrary large quotients of p-power order.
We present a proof that F (9) is infinite using this result. The proof involves constructing presen-
tations for subgroups (function Rewrite) and p-quotient calculations (function pQuotient).
Thus the nilpotent quotient of F is divisible by 2 and 19. We examine the 2- and 19-quotients of
F.
Thus the nilpotent residual of F has index 152. We try to locate this subgroup. We first take a
2-generator presentation for F .
> G := Simplify(F);
> G;
Finitely presented group G on 2 generators
Generators as words in group F
G.1 = x1
G.2 = x2
Relations
G.2 * G.1 * G.2 * G.1 * G.2^2 * G.1 * G.2^2 * G.1^-1 * G.2 * G.1^-2 * G.2 *
G.1^-2 = Id(G)
G.1 * G.2^2 * G.1 * G.2 * G.1^2 * G.2^-1 * G.1^2 * G.2^-1 * G.1 * G.2^-1 *
G.1^2 * G.2^-1 * G.1 * G.2^-1 = Id(G)
> H := ncl< G | (G.1, G.2) >;
> H;
Finitely presented group H
Index in group G is 76 = 2^2 * 19
Subgroup of group G defined by coset table
We have it now.
> AbelianQuotientInvariants(H);
[ 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5 ]
The nilpotent H residual has a 5-quotient. We construct a presentation for H and then calculate
d and e for its 5-quotient.
Since Left is greater than Right, this presentation for H doesn’t work so we start eliminating
generators.
Got it! By Newman’s theorem, H has an infinite 5-quotient and so F must be infinite.
Chapter 11
Finite Soluble Groups
11.1 Introduction
For computational purposes it is most effective to represent a soluble group by means of a polycyclic
presentation.
We verify an easy example from a paper of Hawkes and Cossey. The paper shows that the largest
size of a conjugacy class in an abelian by nilpotent finite group is at least as large as the product
of the largest class sizes for the sylow subgroups. The paper gives an example of a group having
derived length 3 in which this result is fal se. Mike Slattery wrote the following Magma code to
verify their example:
69
70 CHAPTER 11. FINITE SOLUBLE GROUPS
> E := DihedralGroup(GrpPC,5);
> A := CyclicGroup(GrpPC,8);
> QH := SylowSubgroup(H,2);
> m1 := TrivialModule(QH,FiniteField(5));
> m2 := Induction(m1, H);
> G := Extension(m2,H);
> G;
GrpPC : G of order 250000 = 2^4 * 5^6
PC-Relations:
G.1^2 = Id(G),
G.2^5 = Id(G),
G.3^2 = G.4,
G.4^2 = G.5,
G.5^2 = Id(G),
G.6^5 = Id(G),
G.7^5 = Id(G),
G.8^5 = Id(G),
G.9^5 = Id(G),
G.10^5 = Id(G),
G.2^G.1 = G.2^4,
G.3^G.1 = G.3 * G.4 * G.5,
G.4^G.1 = G.4 * G.5,
G.6^G.2 = G.10,
G.7^G.1 = G.10,
G.7^G.2 = G.6,
G.8^G.1 = G.9,
G.8^G.2 = G.7,
G.9^G.1 = G.8,
G.9^G.2 = G.8,
G.10^G.1 = G.7,
G.10^G.2 = G.9
> DerivedLength(G);
3
> P := SylowSubgroup(G,5);
> Q := SylowSubgroup(G,2);
> time Maximum({x[2] : x in Classes(G)});
1250
Time: 30.019
> time Maximum({x[2] : x in Classes(P)});
625
Time: 0.090
> time Maximum({x[2] : x in Classes(Q)});
4
Time: 0.009
The following example concerns a soluble permutation group H of order 48. An abstract descrip-
tion of its structure was found by John Cannon and Mike Newman in response to a question raised
by Brendan McKay. While it does not yet seem possible to automate such analysis completely,
this example shows how mathematical insight supported by calculation may led to a satisfactory
description of a group in a few minutes.
> H := PermutationGroup< 24 |
> (2,3)(5,6)(7,8)(9,10)(11,12)(14,15)(16,17)(18,19)(20,21)(23,24),
> (1,2,7,18,8,9)(3,22,10,20,19,21)(4,6,23,17,24,14)(5,13,15,11,16,12),
> (1,4)(2,14)(3,15)(5,10)(6,9)(7,24)(8,23)(11,21)(12,20)(13,22)(16,19)(17,18)>;
> Order(H);
48
Since the order is 48, the group H is soluble/polycyclic, and it may be helpful to have a polycyclic
presentation G:
> G := PCGroup(H);
> G;
GrpPC : G of order 48 = 2^4 * 3
PC-Relations:
G.1^2 = Id(G),
G.2^2 = Id(G),
G.3^2 = Id(G),
G.4^2 = Id(G),
G.5^3 = Id(G),
G.3^G.2 = G.3 * G.4,
G.5^G.1 = G.5^2,
G.5^G.3 = G.5^2
One can read off: the commutator subgroup is hG.4, G.5i, and it is abelian and has order 6 –
thus cyclic; the commutator quotient is elementary abelian of order 8. Also hG.1, G.2, G.3, G.4i
is a Sylow 2-subgroup; hG.2, G.3, G.4i is dihedral of order 8. Furthermore, hG.5i is the Sylow
3-subgroup, and its centralizer has order 24. We find this centralizer C.
> C;
GrpPC : C of order 24 = 2^3 * 3
PC-Relations:
C.1^2 = Id(C),
C.2^2 = Id(C),
C.3^3 = Id(C),
C.4^2 = Id(C),
C.2^C.1 = C.2 * C.4
Thus C has a direct decomposition into hC.3i which is cyclic of order 3 and B = hC.1, C.2, C.4i
which is dihedral of order 8. Hence both these subgroups are characteristic in C and normal in
G. Furthermore, B has hC.3, G.5i as a complement which is normal and non-abelian of order 6.
So G has a direct decomposition into a dihedral subgroup of order 8 and a non-abelian subgroup
of order 6.
We find B, and get all the complements of B in G. The function Complements(G, B) actually
returns conjugacy class representatives for these complements. Finally, we test to see which
complements are normal in G.
We load a definition of the Burnside group B(2, 6) from a Magma database solgps containing
definitions of various interesting soluble groups. B(2, 6) is a two-generator group, the unique group
of order 228 · 325 and exponent 6.
11.3. SUBGROUP STRUCTURE, AUTOMORPHISMS AND REPRESENTATIONS 73
> G := B26();
> ds := DerivedSeries(G);
> [ FactoredOrder(x) : x in ds ];
[
[ <2, 28>, <3, 25> ],
[ <2, 26>, <3, 23> ],
[ <2, 18>, <3, 13> ],
[]
]
> cs := ChiefSeries(G);
> [ FactoredOrder(x) : x in cs ];
[
[ <2, 28>, <3, 25> ],
[ <2, 27>, <3, 25> ],
[ <2, 26>, <3, 25> ],
[ <2, 26>, <3, 24> ],
[ <2, 26>, <3, 23> ],
[ <2, 26>, <3, 22> ],
[ <2, 26>, <3, 21> ],
[ <2, 26>, <3, 20> ],
[ <2, 26>, <3, 19> ],
[ <2, 26>, <3, 18> ],
[ <2, 26>, <3, 17> ],
[ <2, 26>, <3, 16> ],
[ <2, 26>, <3, 15> ],
[ <2, 26>, <3, 14> ],
[ <2, 26>, <3, 13> ],
[ <2, 26>, <3, 12> ],
[ <2, 26>, <3, 11> ],
[ <2, 26>, <3, 10> ],
[ <2, 26>, <3, 9> ],
[ <2, 26>, <3, 8> ],
[ <2, 26>, <3, 7> ],
[ <2, 26>, <3, 6> ],
[ <2, 26>, <3, 5> ],
74 CHAPTER 11. FINITE SOLUBLE GROUPS
So we see there are 35 proper maximal subgroups of G and that the smallest has index 64.
We analyze the structure of a polycyclic group. The group arose in the context of an investigation
of groups of deficiency zero (by Havas, Newman and O’Brien). The group is visibly an extension
of a 2-group by a 3-group. The 3-group is known, from earlier work, to be a group of order 35 and
class 3.
The analysis below is a sanitised version of an analysis first done by Alice Niemeyer and Mike
Newman. Some polishing is due to Allan Steel.
> G<a,b,c,d,e,f,g,h,i,j,k,l,m,n> :=
> PolycyclicGroup < a,b,c,d,e,f,g,h,i,j,k,l,m,n |
> a^3 = d, b^3 = d^2*e, c^3, d^3, e^3,
> f^2 = l, g^2 = l, h^2 = l*m, i^2 = l*m, j^2 = l*n, k^2 = l*n, l^2, m^2, n^2,
> b^a=b*c, c^a=c*d*e, d^a=d, e^a=e, f^a=j*k, g^a=j, h^a=g, i^a=f*g,
> j^a=i, k^a=h*i, l^a=l*n, m^a=n, n^a=m*n,
> c^b=c*d, d^b=d, e^b=e, f^b=j*k, g^b=j, h^b=f, i^b=g, j^b=h,
> k^b=i, l^b=l*n, m^b=n, n^b=m*n,
> d^c=d, e^c=e, f^c=f, g^c=g, h^c=i, i^c=h*i, j^c=j*k, k^c=j, l^c=l, m^c=m,
> n^c=n, e^d=e, f^d=g, g^d=f*g, h^d=i, i^d=h*i, j^d=k, k^d=j*k, l^d=l,
> m^d=m, n^d=n, f^e=f, g^e=g, h^e=h, i^e=i, j^e=j, k^e=k, l^e=l, m^e=m,
> n^e=n, g^f=g*l, h^f=h, i^f=i, j^f=j, k^f=k, l^f=l, m^f=m, n^f=n,
> h^g=h, i^g=i, j^g=j, k^g=k, l^g=l, m^g=m, n^g=n,
> i^h=i*l*m, j^h=j, k^h=k, l^h=l, m^h=m, n^h=n,
> j^i=j, k^i=k, l^i=l, m^i=m, n^i=n,
11.3. SUBGROUP STRUCTURE, AUTOMORPHISMS AND REPRESENTATIONS 75
One can read off that the Sylow 2-subgroup has lower 2-central class 2. The next few lines confirm
this.
The action of the Sylow 3-subgroup on S2/D is a 3-subgroup of GL(6, 2) and so a subgroup of the
wreath product C3 o C3 .
> Order(Centre(G));
6
The 3-part of the centre has order 3, so the faithful action on S2/D is C3 o C3 and S2/D must be
irreducible. The next step confirms that.
This module will reduce under the action of at least one of the maximal subgroups. Finding this
reduction helps the analysis. Since the Sylow 3-subgroup can be generated by 2 elements it has 4
maximal subgroups.
> M3 := MaximalSubgroups(S3);
We test what happens. Note that for each group A in M3 we need to create H = hS2, Ai. It is
not possible to use GModule(A, S2, D), since the second argument would not be a subgroup of
the first one.
> else
> print "subgroup", i, "acts irreducibly";
> end if;
> end for;
subgroup 1 acts irreducibly
subgroup 2 acts irreducibly
subgroup 3 acts reducibly
We have found a subgroup A (the third maximal subgroup) that acts reducibly.
Next, we look for ‘small’ normal subgroups of H in S2. The idea is to take a non-zero element of
a minimal H-submodule of S2/D, pull it back into S2 and calculate the A-admissible subgroup
T1 generated by it. Unfortunately not all the A-admissibles have the same order. In this case one
gets orders 8 and 16. So we take the first of order 8. Because there is randomness in one of the
routines involved in MinimalSubmodules, it is not predictable when this will occur. This explains
why the output may vary from run to run.
> T2 := T1 ^ a;
> T3 := T2 ^ a;
> Order(sub<G | T1, T2, T3>);
512
The conjugates of T1 under a span S2 . So S2 is the direct sum of three copies of the quaternions.
Now explore the action of A on the Ti more closely. First compute a centraliser.
> C23;
GrpPC : C23 of order 9 = 3^2
PC-Relations:
C23.1^3 = C23.2
>
> Order(Centraliser(C23, T1));
3
Thus this centraliser is cyclic of order 9. Together with T1 it generates U1 which is a split extension
of the quaternions by a cyclic group of order 9 acting as an automorphism of order 3. So the group
is an extension of a central subgroup of order 3 by SL(2, 3).
Thus the conjugates of U1 span H (which has index 3 in G). In fact H is a central product of
these conjugates.
Thus G can be viewed as built from conjugates of U1 under a with a3 in H but not the centre of
H.
Chapter 12
Permutation Groups
Magma contains a large amount of machinery for dealing with permutation groups of finite degree.
The following list summarises various constructions of these groups available in Magma.
• Permutation representations for classical groups, e.g. PGL(n, q), PSp(n, q), PSU(n, q 2 ), P Ω(n, q)
• Construction of wreath products with both types of action
• Orbits on points, sets of points, and sequences of points
• Systems of imprimitivity
• Induced actions on G-sets
• Base and strong generating set: Sims-Schreier algorithm, random Schreier algorithm, Todd-Coxeter
Schreier algorithm, Brownie-Cannon-Sims verification
• Stabilizer of a point, set of points, sequence of points, partition
• Automorphism groups of graphs, codes and designs
• Homomorphisms induced by actions on orbits and systems of imprimitivity
• Random element generation: Holt-Leedham-Green-O’Brien algorithm
• Databases: Transitive groups up to degree 15 (Butler), primitive groups up to degree 50 (Sims),
irreducible soluble subgroups of GL(n, p) for pn < 256 (Short), simple groups up to order a million
(Campbell and Robertson), sporadic simple groups
Consider a pack of 3n cards, which is shuffled as follows: The pack is divided into three piles each
containing n cards and the piles are placed in a row in the order they are removed from the deck.
Now the three piles are permuted among themselves, and finally the deck is reassembled by taking
the first card from the first pile, the second card from the second pile, and so on. We wish to
know if such a shuffle is fair in the sense that any card may appear in any position after a finite
number of such shuffles.
For further details, see Steve Medvedoff, Kent Morrison, Groups of Perfect Shuffles, Mathematics
Magazine 60 no. 1 (Feb 1987), 3–14, and also a paper cited by it: P. Diaconis, R.L. Graham,
W.M. Kantor, The mathematics of perfect shuffles, Adv. Appl. Math. 4 (1983), 175–196.
We give a function ShuffleGroup which produces generators for the group of permutations of the
cards defined by this shuffle, and returns this group.
79
80 CHAPTER 12. PERMUTATION GROUPS
ShuffleGroup := function(n)
m := 3 * n;
G := SymmetricGroup(m);
end function;
We now determine the degrees of those shuffle groups which do not correspond to perfect shuffles,
for n in the range 1 to 120.
Starting with generators for the Mathieu group M24 , we construct the associated 5-(24, 5, 1) block
design.
GSet{ 3 },
GSet{ 4 },
GSet{ 5 },
GSet{ 6, 7, 9, 10, 12, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24 },
GSet{ 8, 11, 13 }
]
The five fixed points together with the orbit of length 3 form a block of a 5-(24, 8, 1) design. By
computing the orbit of this block under M24 , we obtain all the blocks of the design.
> CompositionFactors(SB);
G
| Alternating(8)
*
| Cyclic(2)
*
| Cyclic(2)
*
| Cyclic(2)
*
| Cyclic(2)
1
82 CHAPTER 12. PERMUTATION GROUPS
The key concept for representing a permutation group is that of a base and strong generating set
(BSGS). Brownie, Cannon and Sims (1991) showed that it is practical, in some cases at least,
to construct a BSGS for short-base groups having degree up to several million. The ability to
construct a BSGS, coupled with the use of algorithms that make heavy use of the classification
theorem for finite simple groups, opened up the possibility of analyzing the structure (e.g. deter-
mining the composition factors) for short base groups of degree up to a million.
| Alternating(24)
*
| Cyclic(2)
*
| Alternating(24)
*
| Alternating(8)
*
| Cyclic(3) (7 copies)
1
We find that the chief factors of the group are as shown above. The fifth term of the chief series
itself is the normal subgroup of G isomorphic to an elementary abelian group of order 37 extended
by A8 .
> cs[5];
Permutation group acting on a set of cardinality 72
Order = 44089920 = 2^6 * 3^9 * 5 * 7
(67, 69, 68)(70, 71, 72)
(64, 67, 70)(65, 69, 72)(66, 68, 71)
(61, 64, 70)(62, 66, 71)(63, 65, 72)
(58, 61, 72)(59, 63, 71)(60, 62, 70)
(55, 58, 70)(56, 59, 72)(57, 60, 71)
(52, 72, 59, 56, 54, 71, 60, 57, 53, 70, 58, 55)(64, 69, 66, 67, 65, 68)
(49, 60, 57, 53, 51, 59, 56, 54, 50, 58, 55, 52)(61, 68, 63, 67, 62, 69)
This group represents the possible tranformations on the corners of the cube. In terms of posi-
tioning the corner cubes every even permutation of them is possible. Each corner cube can be
oriented three ways. The orientation of seven of the corner cubes may be chosen freely, and this
will determine the orientation of the eighth corner.
We create the subgroup lattice of AΓL(1, 8) and locate the Fitting subgroup in the lattice.
Subgroup Lattice
----------------
[ 1] Order 1 Length 1
Maximal Subgroups:
---
[ 2] Order 2 Length 7
Maximal Subgroups: 1
[ 3] Order 3 Length 28
Maximal Subgroups: 1
[ 4] Order 7 Length 8
84 CHAPTER 12. PERMUTATION GROUPS
Maximal Subgroups: 1
---
[ 5] Order 4 Length 7
Maximal Subgroups: 2
[ 6] Order 6 Length 28
Maximal Subgroups: 2 3
[ 7] Order 21 Length 8
Maximal Subgroups: 3 4
---
[ 8] Order 8 Length 1
Maximal Subgroups: 5
[ 9] Order 12 Length 7
Maximal Subgroups: 3 5
---
[10] Order 24 Length 7
Maximal Subgroups: 6 8 9
[11] Order 56 Length 1
Maximal Subgroups: 4 8
---
[12] Order 168 Length 1
Maximal Subgroups: 7 10 11
> F := FittingSubgroup(G);
> F;
Permutation group F acting on a set of cardinality 8
Order = 8 = 2^3
(1, 2)(3, 6)(4, 8)(5, 7)
(1, 6)(2, 3)(4, 7)(5, 8)
(1, 5)(2, 7)(3, 4)(6, 8)
> L ! F;
8
We now construct a chain from the bottom to the top of the lattice.
> H := Bottom(L);
> Chain := [H];
> while H ne Top(L) do
> H := Representative(MinimalOvergroups(H));
> Chain := Append(Chain, H);
> end while;
> Chain;
[ 1, 2, 5, 8, 10, 12 ]
Below are listed some of the constructions and elementary operations on matrix groups available
in Magma.
We use the RandomProcess function to sample the orders of elements in the group GL(20, 16).
85
86 CHAPTER 13. MATRIX GROUPS
[ <3, 2>, <5, 1>, <7, 1>, <13, 1>, <17, 1>, <37, 1>, <73, 1>, <109, 1>,
<241, 1>, <433, 1>, <38737, 1> ],
[ <3, 1>, <5, 2>, <11, 1>, <17, 1>, <31, 1>, <41, 1>, <257, 1> ],
[ <3, 2>, <5, 2>, <7, 1>, <11, 1>, <13, 1>, <17, 1>, <31, 1>, <41, 1>, <257,
1>, <65537, 1> ],
[ <3, 2>, <5, 1>, <7, 1>, <13, 1>, <17, 1>, <19, 1>, <37, 1>, <73, 1>, <109,
1>, <241, 1>, <433, 1>, <38737, 1> ],
[ <3, 2>, <5, 1>, <7, 1>, <13, 1>, <17, 1>, <29, 1>, <43, 1>, <113, 1>,
<127, 1>, <241, 1> ],
[ <3, 1>, <5, 1>, <7, 1>, <13, 1>, <17, 1>, <257, 1>, <65537, 1> ],
[ <5, 1>, <11, 1>, <17, 1>, <31, 1>, <41, 1>, <257, 1>, <61681, 1>,
<4278255361, 1> ],
[ <3, 2>, <5, 1>, <7, 1>, <11, 1>, <13, 1>, <17, 1>, <31, 1>, <41, 1>,
<61681, 1> ],
[ <3, 3>, <5, 1>, <7, 1>, <13, 1>, <17, 1>, <19, 1>, <29, 1>, <37, 1>, <43,
1>, <73, 1>, <109, 1>, <113, 1>, <127, 1>, <257, 1> ]
]
The matrix group facilities are mainly restricted to finite groups since there are, as yet, few
algorithms of general interest known for infinite groups. Techniques for working with finite matrix
groups divide into methods for groups of small degree and methods for groups of large degree. Our
initial concern is the development of a module for dealing with finite matrix groups of small degree.
In practice, this means degrees up to 30 or so, over small rings. However, this case is important,
since algorithms for dealing with larger degree groups defined over finite fields will ultimately
reduce down to this case. The small degree technique involves looking for some sequences of
objects (subspaces and vectors) in the underlying vector space that defines a stabilizer chain
which has the property that the basic orbits are not excessively large. Thus, we have a concept
of a base and strong generating set (BSGS) similar to that employed in the case of permutation
groups. Once such a BSGS is available, analogues of the permutation group backtrack searches
for centralizer, normalizer etc may be described.
• Homomorphism induced by action of a reducible group on G-invariant submodule and its quotient
module
• Homomorphisms induced by actions on orbits of vectors and subspaces
• Homomorphism induced by action on the cosets of a subgroup
• Construction of subgroups, quotient groups
• Abelian quotient, soluble quotient
• Composition series, composition factors, chief series, chief factors
• Characteristic series: Derived, upper central, lower central, elementary abelian, p-central, Jennings
• Characteristic subgroups: Centre, derived subgroup, Fitting subgroup, Op (G), radical, solvable
residual
• Subgroup constructions: Centralizer, intersection, normal closure, core
• Sylow p-subgroup
• Testing elements for conjugacy
• Conjugacy classes of elements
• Presentation on given generators (for groups of moderate order)
13.2. STRUCTURE OF A MATRIX GROUP 87
• Character table
• Molien series
• Ring of invariants
In this example we compute the Bravais subgroups of the finite integral matrix group W (E6 ).
[ 1 1 1 1 1 0]
[ 0 0 -1 -1 -1 0]
[ 0 -1 0 0 0 0]
[ 0 1 1 0 0 0]
[ 0 0 0 1 0 0]
[-1 -1 -2 -1 0 -1]
[ 1 0 0 0 0 0]
[ 0 1 0 0 0 0]
[ 0 0 1 0 0 0]
[ 0 0 0 1 0 0]
[ 0 0 0 0 1 0]
[-1 -2 -3 -2 -1 -1]
We now find the subgroups of G. Currently, the subgroup function only works for permutation
groups. In general the next line does not yield a faithful action it does, though, for irreducible
representations
Time: 127.949
> print "Computed", #Sub, "subgroups";
Computed 1503 subgroups
> Bravais := [];
> t := Cputime();
> for S in Sub do
> U := S‘subgroup @@ phi;
> A := BravaisGroup(U);
> if Order(A) eq Order(U) then
> Append(~Bravais, U);
> end if;
> end for;
> print "\nFound", #Bravais, "Bravais subgroups";
[-1 0 0 0 0 0]
[ 0 -1 0 0 0 0]
[ 0 0 -1 0 0 0]
[ 0 0 0 -1 0 0]
[ 0 0 0 0 -1 0]
[ 0 0 0 0 0 -1]
[ 0 -1 -1 0 0 -1]
[ 0 1 0 0 0 0]
[ 0 0 1 0 0 0]
[ 1 1 1 1 0 1]
[ 0 0 0 0 1 0]
[-1 -1 -1 0 0 0]
[ 0 -1 -1 -1 -1 0]
[ 0 1 0 0 0 0]
[ 0 0 1 0 0 0]
[ 0 0 0 1 0 0]
13.3. DECOMPOSITION OF MATRIX GROUPS OVER FINITE FIELDS 89
[-1 -1 -1 -1 0 0]
[ 1 1 1 1 1 1]
]
Consider a matrix group G acting on the finite dimensional KG-module V over a finite field K.
According to a theorem of Aschbacher (M. Aschbacher, On the maximal subgroups of the finite
classical groups, Invent. Math. 76 (1984) 469-514.), G falls into one of nine classes. The facilities
listed here attempt to decide into which such class a given group falls.
Finite Coxeter groups are implemented as a subclass of permutation groups so that they inherit all
the operations for permutation groups as well as having many specialized functions. This module
was implemented by Don Taylor. Frank Lübeck and the Chevie team provided helpful assistance.
The purpose of this example is to construct an 8-dimensional module for the Lie algebra of type
G2 and to define a multiplication on it which turns it into an alternative algebra. The algebra
will turn out to be the octonions and the elements of G2 will act as derivations. The example was
constructed by Don Taylor (University of Sydney).
91
92 CHAPTER 14. COXETER GROUPS
Let W be the Coxeter group of type E6 , let Φ be its root system and let ∆ = {α1 , α2 , . . . , α6 } be
the set of simple roots labelled according to the Dynkin Diagram
•3
•1 •2 •4 •5 •6
There are 36 positive roots and 24 of these lie outside the subsystem (of type D4 ) spanned by α2 ,
α3 , α4 and α5 . These 24 roots are partitioned into 3 subsets of size 8 according to the values of
their first and last coordinates. We label these sets X, Y and Z.
> W := CoxeterGroup("E",6);
> Phi := RootSystem(W);
> X := Reverse({@ x : x in Phi | x[1] eq 1 and x[6] eq 0 @});
> Y := Reverse({@ x : x in Phi | x[1] eq 0 and x[6] eq 1 @});
> Z := Reverse({@ x : x in Phi | x[1] eq 1 and x[6] eq 1 @});
> #X, #Y, #Z;
8 8 8
We have reversed the order of the roots so that, in each case, they are ordered from highest to
lowest.
Let Vy and Vz be the vector spaces with bases indexed by the roots in Y and Z respectively and
let d4eY, d4fY, d4eZ, d4fZ be the corresponding sequences of matrices representing the action of
the simple root vectors of D4 .
The Cartan subalgebra H of D4 has basis {h2 , h3 , h4 , h5 }, where hi = hαi , and its dual has basis
{α2 , α3 , α4 , α5 }. Moreover, for h ∈ H and α ∈ X we have [h eα ] = α(h)eα and so the weights of
the module Vx are simply the roots α ∈ X restricted to H.
The Cartan matrix of W has entries h αi , αj i and since the form h−, −i is linear in the first variable
the values of h α, αj i are given by the product of the row vector α by the matrix C.
> C := CartanMatrix(W);
14.2. CONSTRUCTING THE SPLIT OCTONIONS 93
> X[1];
(1 1 2 2 1 0)
> X[1]*C;
( 0 0 1 0 0 -1)
This shows that, as a D4 module, X has highest weight λ2 according to the following labelling of
the D4 Dynkin diagram, where λ1 , λ2 , λ3 and λ4 are the fundamental weights.
1•H
H• •4
©©3
2•
> Y[1];
(0 1 1 2 2 1)
> Y[1]*C;
(-1 0 0 0 1 0)
> Z[1];
(1 2 2 3 2 1)
> Z[1]*C;
(0 1 0 0 0 0)
The Lie algebra of type G2 may be regarded as the subalgebra of D4 generated by eA = eα2 +
eα3 + eα5 , eB = eα4 , e−A = e−α2 + e−α3 + e−α5 and e−B = e−α4 .
As D4 -modules the spaces Vx , Vy and Vz are not isomorphic. However they become isomorphic
when considered as G2 -modules. We note in passing that D4 has an automorphism of order 3
which permutes the modules Vx , Vy and Vz . It should be possible to obtain the “principle of local
triality” directly from this and then obtain the matrices P and Q (defined below).
> eX := [d4eX[1]+d4eX[2]+d4eX[4],d4eX[3]];
> fX := [d4fX[1]+d4fX[2]+d4fX[4],d4fX[3]];
> eY := [d4eY[1]+d4eY[2]+d4eY[4],d4eY[3]];
> fY := [d4fY[1]+d4fY[2]+d4fY[4],d4fY[3]];
>
> eZ := [d4eZ[1]+d4eZ[2]+d4eZ[4],d4eZ[3]];
> fZ := [d4fZ[1]+d4fZ[2]+d4fZ[4],d4fZ[3]];
94 CHAPTER 14. COXETER GROUPS
The modules Vx , Vy and Vz are reducible and split into the sum of an irreducible 7-dimensional
submodule and a 1-dimensional complement. From highest weight theory the 7-dimensional sub-
module has a basis consisting of vectors of the form eiβ11 · · · eiβmm v + , where v + is a maximal vector
and βi ∈ {−A, −B}. To set this up in Magmawe need a vector space of dimension 8.
> V := VectorSpace(RationalField(),8);
> B := Basis(V);
In each of Vx , Vy and Vz the highest weight vector is the first basis element. Thus to describe a
basis for the 7-dimensional submodule it is enough to give a sequence of root elements with the
property that the (i + 1)-st basis element is obtained by applying the i-th root element to the i-th
basis element.
We see directly from the forms of fX[1] and fX[2] that for Vx we may take
> ss := [1,2,1,1,2,1];
> Bx := [i eq 0 select B[1] else Self(i)*fX[ss[i]] : i in [0..6]];
> Bx;
[
V: (1 0 0 0 0 0 0 0),
V: (0 -1 0 0 0 0 0 0),
V: (0 0 1 0 0 0 0 0),
V: (0 0 0 -1 1 0 0 0),
V: (0 0 0 0 0 -2 0 0),
V: (0 0 0 0 0 0 -2 0),
V: (0 0 0 0 0 0 0 -2)
]
Writing x1 , . . . , x8 to denote the basis vectors of Vx (similarly for Vy and Vz ), the 1-dimensional
G2 -submodule of Vx is spanned by x4 +x5 = (0, 0, 0, 1, 1, 0, 0, 0) and that of Vy (resp. Vz ) is spanned
14.2. CONSTRUCTING THE SPLIT OCTONIONS 95
u ? v = [uϕ v ψ ]
turns Vz into an alternative algebra. The identity element must be a multiple of z4 − z5 and we
have (z4 − z5 )ϕ = λ(x4 + x5 ) and (z4 − z5 )ψ = µ(y4 − y5 ).
> for i := 1 to 8 do
for> c4 := LieStructureConstant(W,X[4],Y[i]);
for> c5 := LieStructureConstant(W,X[5],Y[i]);
for> z4 := c4 eq 0 select 0 else X[4]+Y[i];
for> z5 := c5 eq 0 select 0 else X[5]+Y[i];
for> <i,c4,c5,z4,z5>;
for> end for;
<1, 0, 1, 0, (1 2 2 3 2 1)>
<2, 1, 0, (1 1 2 3 2 1), 0>
<3, 1, 0, (1 1 2 2 2 1), 0>
<4, 0, 1, 0, (1 1 2 2 1 1)>
<5, 1, 0, (1 1 1 2 2 1), 0>
<6, 0, 1, 0, (1 1 1 2 1 1)>
<7, 0, 1, 0, (1 1 1 1 1 1)>
<8, 1, 0, (1 0 1 1 1 1), 0>
Hence for ξ(z4 − z5 ) to be an identity element (on the left) we must have µ = −1 and ξλ = 1.
And now ξ(z4 − z5 ) ? zi = zi for all i.
> for i := 1 to 8 do
for> c4 := LieStructureConstant(W,X[i],Y[4]);
for> c5 := LieStructureConstant(W,X[i],Y[5]);
for> z4 := c4 eq 0 select 0 else X[i]+Y[4];
for> z5 := c5 eq 0 select 0 else X[i]+Y[5];
for> <i,c4,c5,z4,z5>;
for> end for;
<1, 0, 1, 0, (1 2 2 3 2 1)>
<2, -1, 0, (1 1 2 3 2 1), 0>
<3, -1, 0, (1 1 2 2 2 1), 0>
<4, 0, 1, 0, (1 1 1 2 2 1)>
<5, 1, 0, (1 1 2 2 1 1), 0>
<6, 0, -1, 0, (1 1 1 2 1 1)>
<7, 0, 1, 0, (1 1 1 1 1 1)>
<8, 1, 0, (1 0 1 1 1 1), 0>
Thus
1 1
z4 ∗ ξ(z4 − z5 ) = (λ + 1)z4 − (λ − 1)z5
2 2
and so λ = ξ = 1.
> M := MatrixRing(RationalField(),8);
> P := M!1;
> P[5,5] := -1;
> P[6,6] := -1;
> P[8,8] := -1;
> Q := M!1;
> Q[4,4] := 0;
> Q[4,5] := 1;
> Q[5,4] := 1;
> Q[5,5] := 0;
The Lie algebra G2 acts on E6 as derivations and this carries over to its action on the algebra
V . In order to check this we use the following code, utilising the variables V, B, coeff and ndx
already defined
The structure constants of this algebra are all integers and so the Z-span O(Z) of the basis z1 ,
. . . , z8 is an algebra. Then for any field F the vector space O(F) = F ⊗Z O(Z) is the algebra of
split octonions over F. Our construction shows that it admits the Chevalley group G2 (F) as a
group of automorphisms.
Chapter 15
Invariant Rings of Finite Groups
A module for constructing both characteristic zero and modular invariants of finite groups has
been developed by Gregor Kemper and Allan Steel. This includes a new algorithm for computing
primary invariants that guarantees that the degrees of the invariants constructed are optimal (with
respect to their product and then sum). Magma allows computation in invariant rings over ground
fields of arbitrary characteristic. Of particular interest is the modular case, i.e., the case where
the characteristic of the ground field divides the order of the group.
In this example we let R be the invariant ring of the degree-6 permutation representation of the
dihedral group of order 12 and with coefficient field the rational field Q.
We first compute primary invariants and secondary invariants of R easily. The secondary invariants
are quite large and messy so we only print their degrees.
> G := DihedralGroup(6);
> G;
Permutation group G acting on a set of cardinality 6
Order = 12 = 2^2 * 3
(1, 2, 3, 4, 5, 6)
(1, 6)(2, 5)(3, 4)
99
100 CHAPTER 15. INVARIANT RINGS OF FINITE GROUPS
In this example we define a 4-dimensional reflection group G of order 92160 and “manually” find
primary invariants for the ring of invariants of G. The function PrimaryInvariants would do all
this automatically for us of course.
15.1. CONSTRUCTING INVARIANTS 101
We start by constructing the Molien series of G, both as a rational function and as a power
series; from this, it emerges that possible primary invariants have degrees 8, 24, 24, and 40. Next,
we construct linearly independent invariants of these degrees. We then use the Hilbert-driven
Buchberger algorithm to show that the ideal generated by these invariants is zero-dimensional,
since the numerator of the Hilbert Series of the ideal is (1−t8 )(1−t24 )(1−t24 )(1−t40 ) as expected.
Since the ideal is zero-dimensional, the four invariants must be primary invariants for G.
We create the cyclotomic field K = Q(ζ8 ), and a matrix group G over K generated by 4 matrices:
> Order(G);
92160
> FactoredOrder(G);
[ <2, 11>, <3, 2>, <5, 1> ]
The Molien series calculation needs the conjugacy classes of G. We call the Classes function,
specifying that the classes C are to be found as orbits under conjugation action. We do this since
the default method would be much slower for this group.
Once the conjugacy classes of G have been found, they will be remembered for subsequent calcu-
lations.
We are now in a position to compute the Molien series of G, initially as a rational function and
then as a power series:
where d is the degree of the matrix representation. Therefore we undertake a partial factorization
of the denominator D as the product of polynomials of the form (1 − xk ) for various k. We
determine each k by taking the degree of the first non-constant term of D and then dividing out
by (1 − xk ).
1 + t32
.
(1 − t8 )(1 − t24 )(1 − t24 )(1 − t40 )
Therefore the degrees 8, 24, 24 and 40 should be tried to find primary invariants.
We now proceed to form linearly independent invariants with these degrees. The first invariant
can be computed with the function ReynoldsOperator, and the others can be constructed using
InvariantsOfDegree: which successively calls ReynoldsOperator efficiently to obtain linearly
independent invariants of the desired degree.
(The output above has been heavily edited, since the polynomials have many terms.)
Finally, we show that the ideal is zero-dimensional by checking that the Hilbert-driven Buchberger
algorithm succeeds:
This indicates that the ideal is zero-dimensional, so L must contain primary invariants for G.
Let R be the invariant ring of the group generated by the degree-5 Jordan block over GF(2). We
first note that R is not Cohen-Macaulay. We then construct a minimal free resolution F of R and
verify that the homological dimension of R is 2 so the depth of R is 3.
> K:=GF(2);
> G := MatrixGroup<5,K | [1,0,0,0,0, 1,1,0,0,0, 0,1,1,0,0,
> 0,0,1,1,0, 0,0,0,1,1]>;
> Order(G);
8
> G;
MatrixGroup(5, GF(2)) of order 2^3
Generators:
[1 0 0 0 0]
[1 1 0 0 0]
[0 1 1 0 0]
[0 0 1 1 0]
[0 0 0 1 1]
> R := InvariantRing(G);
We now compute the primary and secondary invariants and list their degrees.
> IsCohenMacaulay(R);
false
> HilbertSeries(R);
(-t^6 + t^4 - t^3 - 2*t^2 + 2*t - 1)/(t^13 - 3*t^12 + 2*t^11 +
2*t^10 - 3*t^9 + t^8 - t^5 + 3*t^4 - 2*t^3 - 2*t^2 + 3*t - 1)
We take a subgroup of order 16 of GL7 (2) and compute its invariant ring.
> K:=GF(2);
> G:=MatrixGroup<7,K |
> [1,0,0,0,1,0,0, 0,1,0,0,0,0,0, 0,0,1,0,0,0,0, 0,0,0,1,0,0,0,
> 0,0,0,0,1,0,0, 0,0,0,0,0,1,0, 0,0,0,0,0,0,1],
> [1,0,0,0,0,0,0, 0,1,0,0,0,1,0, 0,0,1,0,0,0,0, 0,0,0,1,0,0,0,
> 0,0,0,0,1,0,0, 0,0,0,0,0,1,0, 0,0,0,0,0,0,1],
> [1,0,0,0,0,0,0, 0,1,0,0,0,0,0, 0,0,1,0,0,0,1, 0,0,0,1,0,0,0,
> 0,0,0,0,1,0,0, 0,0,0,0,0,1,0, 0,0,0,0,0,0,1],
> [1,0,0,0,0,0,0, 0,1,0,0,0,0,0, 0,0,1,0,0,0,0, 0,0,0,1,1,1,1,
> 0,0,0,0,1,0,0, 0,0,0,0,0,1,0, 0,0,0,0,0,0,1] >;
> #G;
16
> R:=InvariantRing(G);
> time SecondaryInvariants(R);
[
1
]
> IsCohenMacaulay(R);
true
Time: 0.270
Since R has only one secondary invariant, it is (isomorphic to) a polynomial ring and thus Cohen-
Macaulay.
16.1 Introduction
The four fundamental algorithms for computational module theory are echelonization, the spinning
algorithm, the Meataxe algorithm and an algorithm for Hom(U, V ). For the important case of tuple
modules over finite fields, different representations of vector arithmetic, depending upon the field,
have been implemented. The Magma algorithm for splitting modules (the Meataxe algorithm) is
a deterministic version of the Holt-Rees algorithm and is capable of splitting modules over GF(2)
having dimension up to at least 20 000. While the Magma Meataxe currently works over finite
fields, it is being extended to modules defined over Q, or small degree extensions of Q. Magma
also includes a new algorithm for the construction of Hom(U, V ) where U and V are KG-modules
which is applicable to modules having dimension several hundred.
• Arithmetic
• Extension and restriction of the field of scalars
• Direct sum, tensor product, symmetric square, exterior square
• Submodules, via the spinning algorithm
• Membership of a submodule
• Basis operations
• Sum and intersection of submodules
• Quotient modules
• Splitting a reducible module (Holt-Rees Meataxe)
• Testing a module for irreducibility, absolute irreducibility
• Centralizing algebra of an irreducible module
• Composition series, composition factors, constituents
• Maximal and minimal submodules, Jacobson radical, socle
• Socle series
• Construction of Hom(U, V ), End(U )
• Testing modules for isomorphism
• Complement of a direct summand
• Testing modules for indecomposability; indecomposable components
• Submodule lattice (modules over a finite field)
107
108 CHAPTER 16. VECTOR SPACES AND KG-MODULES
16.1.2 KG-Modules
• As for modules over a field
• Dual
• Construction of a permutation module
• Induction and restriction
We load the simple Lie group G(2, 5), represented as a permutation group of degree 3096, from
the standard Magma library of algebraic structures. Then we find the composition factors of a
composition series of the permutation module of G:
> G := PermutationGroup<20 |
> (1, 6, 11, 16)(2, 7, 12, 17)(3, 8, 13, 18)(4, 9, 14, 19)(5, 10, 15, 20),
> (1, 6)(2, 7)(3, 8)(4, 9)(5, 10),
> (1, 2, 3, 4, 5),
> (1, 5)(2, 4)
> >;
[
GModule of dimension 1 with base ring GF(7),
GModule of dimension 3 with base ring GF(7),
GModule of dimension 16 with base ring GF(7)
]
Classify the modules up to isomorphism and select one module from each isomorphism class.
> Constituents(T);
[
GModule of dimension 1 with base ring GF(7),
GModule of dimension 3 with base ring GF(7),
GModule of dimension 4 with base ring GF(7),
GModule of dimension 16 with base ring GF(7),
GModule of dimension 48 with base ring GF(7),
GModule of dimension 48 with base ring GF(7),
GModule of dimension 48 with base ring GF(7)
]
This example is due to Jon Carlson (Athens, GA, USA). The idea is to test a technique for
constructing endo-trivial modules. An endo-trivial module is one with the property that
is the direct sum of a trivial module and a projective (free, in this case) module.
110 CHAPTER 16. VECTOR SPACES AND KG-MODULES
0 → δx → x → k → 0
where k is the trivial f 3[g]-module and x is a permutation module whose point stabilizer is a
noncentral cyclic subgroup.
Now we want to decompose the tensor product of δx with itself. One of the summands should be
an endo-trivial module. Note that the dimension of an endo-trivial module cannot be divisible by
the prime 3, since the square of the dimension must be 1 plus a multiple of 27 (the order of the
group g). The function IsDecomposable tests whether its argument is decomposable, and if this
is the case then it also provides a decomposition as the second and third return values.
We want to check what the pieces are. We suspect that the module of dimension 9 is just a copy
of our permutation module, and the check below confirms that. Then we proceed with the other
piece.
We suspect this time that the module of dimension 27 is a free module. We use the theorem that
the free module is the only module with the property that it is generated by a single element and
has dimension equal to the order of the group. So we try a couple of times to see if it can be
generated by a single element.
> IsDecomposable(m4);
false
So the dimension is 1 more than a multiple (29) of the order of g (27), as expected.
We know that the tensor product of m4 with its dual has a direct summand isomorphic to the
trivial module. If it is endo-trivial then the tensor of it with its dual must be one copy of the
trivial module plus (Dim(et) − 1)/27 = 29 copies of the free module. So the action of the group
algebra must have exactly 29 + 1 = 30 fixed points. We check:
> Fix(et);
GModule of dimension 30 over GF(3)
Actually at this point we can be certain that m4 is an endo-trivial module. But just to be sure
we factor out projective modules to see if we get down to the trivial module. We are using here
the fact that the group ring is self-injective and hence any free submodule (module of dimension
27 generated by one element) is a direct summand.
112 CHAPTER 16. VECTOR SPACES AND KG-MODULES
> ww := et;
> Dim := Dimension; // shorthand
> repeat
> sum := rep{s : i in [1..100] | Dim(s) eq 27
> where s is sub< ww | Random(ww) >};
> qq := quo< ww | sum >;
> print (Dim(et) - Dim(qq)) / #g, Dim(qq);
> ww := qq;
> until Dim(qq) eq 1;
1 757
2 730
3 703
4 676
[ etc ]
26 82
27 55
28 28
29 1
Finally we want to check that the module m4 is not one of the known endo-trivial modules. It is
enough to see that it doesn’t have the same restriction to all of the maximal elementary abelian
subgroups. So we calculate all the maximal elementary abelian 3-subgroups. and then check the
dimension of the fixed point set on each.
> cc := Centre(g);
> max1:= sub< g | g.1, cc >;
> max2:= sub< g | g.2, cc >;
> max3:= sub< g | g.1*g.2, cc >;
> max4:= sub< g | g.1*g.2^2, cc >;
> [ Fix(Restriction(m4, x)) : x in [max1, max2, max3, max4] ];
[
GModule of dimension 6 over GF(3),
GModule of dimension 4 over GF(3),
GModule of dimension 4 over GF(3),
GModule of dimension 4 over GF(3)
]
Notice that the single fixed-point space of dimension 6 corresponds to the restriction of m4 to the
maximal subgroup containing the subgroup h with which we started.
Chapter 17
Homomorphisms of Modules
17.1 Introduction
Magma provides many facilities for computing in modules of (rectangular) matrices. These often
arise as the modules Hom(U, V ) for tuple modules U and V .
We construct two homomorphism modules H1 and H2 over Q and then the homomorphism module
H = Hom(H1 , H2 ) with right matrix action.
113
114 CHAPTER 17. HOMOMORPHISMS OF MODULES
> Q := RationalField();
> H1 := sub<RMatrixSpace(Q, 2, 3) | [1,2,3, 4,5,6], [0,0,1, 1,3,3]>;
> H2 := sub<RMatrixSpace(Q, 2, 4) | [6,5,7,1, 15,14,16,4], [0,0,0,0, 1,2,3,4]>;
> H := Hom(H1, H2, "right");
> H: Maximal;
KMatrixSpace of 3 by 4 matrices and dimension 1 over Rational Field
Echelonized basis:
[ 1 2 3 4]
[-1/2 -1 -3/2 -2]
[ 0 0 0 0]
[ 1 2 6]
[ 7 14 15]
[1 0]
[1 1]
[0 1]
> Image(H.1);
KMatrixSpace of 3 by 3 matrices and dimension 1 over Rational Field
> Kernel(H.1);
KMatrixSpace of 2 by 3 matrices and dimension 0 over Rational Field
> HS := PermutationGroup<100 |
> (2, 3)(6, 9)(8, 13)(10, 14)(11, 17)(12, 19)(15, 27)(16, 24)(18, 26)(20,
> 32)(21, 28)(25, 35)(29, 40)(30, 37)(31, 39)(36, 41)(38, 44)(42, 47)(45,
> 48)(46, 56)(49, 60)(50, 54)(51, 63)(53, 64)(55, 66)(57, 67)(58, 68)(59,
> 70)(61, 73)(62, 72)(65, 76)(69, 81)(74, 83)(75, 79)(78, 80)(89, 92)(91,
> 95)(94, 97)(96, 98)(99, 100),
> (3, 4)(5, 6)(7, 10)(8, 11)(12, 18)(13, 21)(16, 24)(17, 28)(19, 31)(20,
> 33)(22, 27)(23, 35)(26, 39)(29, 36)(30, 41)(37, 40)(38, 46)(42, 49)(43,
> 51)(44, 53)(45, 55)(47, 58)(48, 59)(50, 61)(52, 57)(54, 62)(56, 64)(60,
> 68)(66, 70)(69, 71)(72, 73)(75, 79)(76, 85)(77, 80)(83, 87)(86, 89)(88,
> 91)(94, 96)(97, 99)(98, 100),
> (4, 5)(6, 9)(10, 16)(11, 17)(12, 20)(14, 24)(15, 28)(18, 30)(19, 32)(21,
> 27)(22, 34)(25, 38)(26, 37)(29, 40)(31, 42)(33, 43)(35, 44)(36, 45)(39,
> 47)(41, 48)(46, 57)(50, 54)(51, 59)(53, 65)(55, 58)(56, 67)(61, 74)(63,
> 70)(64, 76)(66, 68)(69, 79)(73, 83)(75, 81)(77, 86)(78, 80)(84, 88)(87,
> 90)(91, 94)(95, 97)(99, 100),
> (5, 8)(6, 11)(7, 12)(9, 15)(10, 18)(13, 22)(14, 25)(16, 29)(17, 28)(19,
> 23)(21, 27)(24, 36)(26, 39)(30, 40)(31, 35)(37, 41)(38, 45)(42, 50)(43,
> 52)(44, 54)(46, 55)(47, 48)(49, 61)(51, 57)(53, 62)(56, 60)(58, 59)(64,
> 68)(66, 73)(69, 71)(70, 72)(76, 83)(77, 80)(78, 84)(81, 82)(85, 87)(86,
> 88)(89, 91)(97, 98)(99, 100),
> (1, 2)(6, 10)(9, 16)(11, 18)(13, 23)(14, 24)(15, 29)(17, 30)(19, 22)(21,
> 27)(25, 36)(26, 37)(28, 40)(31, 35)(32, 34)(38, 45)(39, 41)(42, 44)(46,
> 59)(47, 48)(50, 54)(51, 57)(55, 58)(56, 69)(60, 71)(63, 75)(64, 77)(66,
> 78)(67, 79)(68, 80)(70, 81)(72, 82)(73, 84)(76, 86)(83, 88)(85, 89)(87,
> 91)(90, 94)(93, 96)(99, 100)
> >;
Construct the orbital graph G with 100 vertices, and set A to be the 100 by 100 adjacency matrix
of graph G:
> &+Eltseq(A);
7700
Of course, one can calculate the determinant also using the Smith algorithm:
116 CHAPTER 17. HOMOMORPHISMS OF MODULES
(2) Compute the abelian-quotient invariants of a normal subgroup of G(7, 8) using the Smith
algorithm.
Apply the Smith algorithm to the relevant matrix with 1081 rows and 2657 columns.
(3) Calculating the Smith form or determinant of arbitrary matrices is easy too:
[ 9 11 13 15 17 19 21 23 25 27]
[10 12 14 16 18 20 22 24 26 28]
[11 13 15 17 19 21 23 25 27 29]
[12 14 16 18 20 22 24 26 28 30]
> V - s in K;
true
Chapter 18
Lattices
18.1 Introduction
119
120 CHAPTER 18. LATTICES
• Arithmetic on lattices: sum, intersection, direct sum, tensor product, exterior square, sym-
metric square
• Conversion between lattices and Z-modules and Q-modules.
The 16-dimensional Barnes-Wall lattice Λ16 can be constructed from the first order Reed-Muller
code of length 16 using construction ‘B’. Note that the inner product matrix is the identity matrix
divided by 2 so that the Gram matrix is integral and primitive.
18.3 Properties
• Rank, determinant, basis, basis matrix, inner product matrix, Gram matrix, centre density,
testing for integrality and evenness, index in a superlattice
• Minimum of a lattice (which can also be asserted)
• Kissing number of a lattice
• Theta series of a lattice
• Enumeration of all short vectors of a lattice having norm in a given range
• Enumeration of all shortest vectors of a lattice
• Enumeration of all vectors of a lattice having squared distance from a vector (possibly)
outside the lattice in a given range
18.3. PROPERTIES 121
• Enumeration of all vectors of a lattice closest to a vector (possibly) outside the lattice
• Process to enumerate short or close vectors of a lattice thereby allowing manual looping over
short vectors having norm in a given range or close vectors having squared distance in a
given range
Magma includes a highly optimized algorithm for enumerating all vectors of a lattice of a given
norm. This algorithm is used for computing the minimum, the shortest vectors, short vectors in
a given range, and vectors close to or closest to a given vector (possibly) outside the lattice.
We create the Gosset lattice L = E8 and find the shortest vectors of L. There are 120 normalized
vectors so the kissing number is 240, and the minimum is 2.
We note that the rank of the space generated by the shortest vectors is 8 so that the successive
minima of L are [2, 2, 2, 2, 2, 2, 2, 2].
> Rank(ShortestVectorsMatrix(L));
8
We next find the vectors in L which are closest to a certain vector in the Q-span of L. The vector
is actually a hole of L and the square of its distance from L is 8/9.
> w := RSpace(RationalField(), 8) !
> [ -1/6, 1/6, -1/2, -1/6, 1/6, -1/2, 1/6, -1/2 ];
> C, d := ClosestVectors(L, w);
> C;
122 CHAPTER 18. LATTICES
[
(-1/2 -1/2 -1/2 -1/2 1/2 -1/2 1/2 -1/2),
(-1/2 1/2 -1/2 -1/2 -1/2 -1/2 1/2 -1/2),
(-1/2 1/2 -1/2 -1/2 1/2 -1/2 -1/2 -1/2),
(-1/2 1/2 -1/2 1/2 1/2 -1/2 1/2 -1/2),
( 1/2 1/2 -1/2 -1/2 1/2 -1/2 1/2 -1/2),
( 0 0 -1 0 0 -1 0 0),
( 0 0 -1 0 0 0 0 -1),
( 0 0 0 0 0 -1 0 -1),
(0 0 0 0 0 0 0 0)
]
> d;
8/9
> { Norm(v): v in C };
{ 0, 2 }
We finally notice that these closest vectors are in fact amongst the shortest vectors of the lattice
(together with the zero vector).
The Voronoi cell has 782 vertices, but only 28 of these are of maximal norm 5/2 and therefore
deep holes. We now compute the norms and cardinalities for the shallow holes.
18.4. REDUCTION 123
So there are 126 holes of norm 17/9, 16 holes of norm 2, etc. We now investigate the Voronoi cell
as a polyhedron.
The polyhedron which is the convex closure of the holes has 782 vertices, 4074 edges and 104 faces.
The faces are defined by vectors of length up to 6 and all such vectors are relevant (since there
are only 104). We finally look at the graph defined by the vertices and edges of the Voronoi cell.
> G := VoronoiGraph(L);
> IsConnected(G);
true
> Diameter(G);
8
> Maxdeg(G);
20 ( -1 0 1/2 1/2 1/2 0)
> v := RSpace(Rationals(), 6) ! [ -1, 0, 1/2, 1/2, 1/2, 0 ]; (v*M, v);
5/2
The graph is (of course) connected, its diameter is 8 and the vertices of maximal degree 20 are
exactly the deep holes.
18.4 Reduction
• LLL reduction of lattices, basis matrices and Gram matrices (with numerous parameters)
• Seysen reduction of lattices, basis matrices and Gram matrices (for reducing a lattice and
its dual simultaneously)
• Pairwise reduction of lattices, basis matrices and Gram matrices
• Orthogonalization and orthonormalization (Cholesky decomposition) of a lattice
• Testing matrices for positive or negative (semi-)definiteness
The LLL algorithm can operate on either a basis matrix or a Gram matrix (and will use the
Gram method even if given a basis matrix and it is deemed appropriate) and can be controlled by
many parameters (δ constant, exact de Weger integral method or Schnorr-Euchner floating point
method, step and time limits, selection of methods, etc.). The LLL algorithm can reduce matrices
with very large entries as well as matrices having large sizes (e.g., number of rows well over 500).
124 CHAPTER 18. LATTICES
b1 = (2, 0, . . . , 0, na1 , 0)
b2 = (0, 2, . . . , 0, na2 , 0)
..
.
bn = (0, 0, . . . , 2, nan , 0)
bn+1 = (1, 1, . . . , 1, ns, 1).
Then every vector v = (v1 , . . . , vn+2 ) ∈ L such that the norm of v is n + 1 and
yields the solution xi = |vi − vn+2 |/2 for i = 1, . . . , n to the original equation.
We first write a function KnapsackLattice which, given the sequence Q and sum s, creates a
matrix X representing the above basis and returns the lattice generated by the rows of X. Note
that the Lattice creation function will automatically LLL-reduce the matrix X as it creates the
lattice.
We next write a function Solutions which uses the function ShortVectors to enumerate all
vectors of the lattice L having norm exactly n + 1 and thus to find all solutions to the Knapsack
problem associated with L. (Note that the minimum of the lattice may be less than n + 1.) The
function returns each solution as a sequence of indices for Q.
We now apply our functions to a sequence Q of 12 integers each less than 1000 and the sum 2676.
There are actually 4 solutions. We verify that each gives the original sum.
> Q := [ 52, 218, 755, 221, 574, 593, 172, 771, 183, 810, 437, 137 ];
> s := 2676;
> L := KnapsackLattice(Q, s);
> L;
Lattice of rank 13 and degree 14
Basis:
( 0 0 0 0 2 0 0 0 0 0 -2 -2 0 0)
( 1 1 1 1 -1 -1 -1 -1 1 1 1 -1 0 -1)
( 1 1 -1 -1 -1 1 -1 -1 -1 1 1 1 0 1)
( 0 2 0 0 0 0 -2 0 -2 0 0 2 0 0)
( 2 0 0 2 0 -2 0 0 2 0 0 2 0 0)
( 0 0 2 0 0 -2 2 -2 0 0 2 0 0 0)
( 3 -1 1 1 -1 1 -1 -1 -1 -1 1 1 0 1)
( 1 1 1 -1 -1 1 1 -1 1 -1 -1 3 0 1)
( 1 -1 -1 3 -1 -1 1 1 -1 1 -1 -1 0 1)
( 1 -1 -1 1 1 1 1 -1 -3 1 1 -1 0 -1)
( 1 3 -3 1 -1 1 1 1 1 -1 1 1 0 1)
( 1 1 1 -3 1 -1 3 1 1 -1 -1 -1 0 -1)
( 1 -1 -1 1 -1 1 1 1 -1 -1 1 -1 -12 1)
> S := KnapsackSolutions(L);
> S;
[
[ 2, 3, 4, 5, 8, 12 ],
[ 3, 4, 5, 7, 8, 9 ],
[ 3, 4, 7, 8, 9, 11, 12 ],
[ 1, 2, 3, 4, 9, 10, 11 ]
]
> [&+[Q[i]: i in s]: s in S];
[ 2676, 2676, 2676, 2676 ]
Finally, we apply our method to a larger example. We let Q be a sequence consisting of 50 random
integers in the range [1, 21000 ]. We let I be a random subset of {1 . . . 50} and let s be the sum of
the elements of Q indexed by I. We then solve the Knapsack problem with input (Q, s) and this
time obtain I as the only answer.
> b := 1000;
> n := 50;
> SetSeed(1);
> Q := [Random(1, 2^b): i in [1 .. n]];
> I := {};
> while #I lt n div 2 do
> Include(~I, Random(1, n));
> end while;
> I := Sort(Setseq(I)); I;
126 CHAPTER 18. LATTICES
[ 1, 4, 5, 8, 9, 10, 13, 16, 19, 23, 24, 26, 29, 30, 31, 32, 33, 34,
35, 37, 38, 40, 42, 47, 48 ]
> s := &+[Q[i]: i in I]; Ilog2(s);
1003
> time L := KnapsackLattice(Q, s);
Time: 25.930
> [Ilog2(Norm(b)): b in Basis(L)];
[ 5, 45, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46,
46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46,
46, 46, 46, 46, 46, 46, 46, 46, 46, 47, 47, 47, 47, 47, 47, 47, 47 ]
> time KnapsackSolutions(L);
[
[ 1, 4, 5, 8, 9, 10, 13, 16, 19, 23, 24, 26, 29, 30, 31, 32, 33,
34, 35, 37, 38, 40, 42, 47, 48 ]
]
Time: 1.579
• Determination of whether two lattices are isometric in such a way that specified bilinear
forms are fixed
• Invariant lattice of a rational matrix group and the associated action (thus yielding an
integral representation of the group)
• Endomorphism ring
• Dimension of the space of invariant bilinear forms, the endomorphism algebra or its centre
using a modular algorithm
The computation of the automorphism group of a lattice and the testing of lattices for isometry is
performed using the AUTO and ISOM programs of Bernd Souvignier. The automorphism group
Co0 of the 24-dimensional Leech lattice Λ24 is found in 175 seconds.
18.5. AUTOMORPHISMS AND G-LATTICES 127
We compute the automorphism group of the root lattice E8 and manually transform the action
on the coordinates into an action on the lattice vectors.
[1 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 1 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 1]
[0 0 0 0 0 0 1 0]
> [ #Orbit(A, b) : b in Basis(L) ];
[ 2160, 240, 240, 240, 240, 240, 240, 240 ]
Chapter 19
Algebras
This is a good start, as one of the defining properties of Jordan algebras is that they are commu-
tative. The other property is that the identity (x2 ∗ y) ∗ x = x2 ∗ (y ∗ x) holds for all x, y ∈ A. We
check this on a random pair.
So the algebra is in fact a Jordan algebra (which was clear by construction). We finally have a
look at the structure constants.
129
130 CHAPTER 19. ALGEBRAS
> BasisProducts(A);
[
[ (1 0 0 0), (0 2 0 0), (0 0 2 0), (0 0 0 0) ],
[ (0 2 0 0), (0 0 0 0), (2 0 0 2), (0 2 0 0) ],
[ (0 0 2 0), (2 0 0 2), (0 0 0 0), (0 0 2 0) ],
[ (0 0 0 0), (0 2 0 0), (0 0 2 0), (0 0 0 1) ]
]
We construct the real Cayley algebra, which is a non-associative algebra of dimension 8, containing
7 quaternion algebras. If the basis elements are labelled 1, . . . , 8 and 1 corresponds to the identity,
these quaternion algebras are spanned by {1, (n+1) mod 7+2, (n+2) mod 7+2, (n+4) mod 7+4},
where 0 ≤ n ≤ 6. We first define a function, which, given three indices i, j, k constructs a sequence
with the structure constants for the quaternion algebra spanned by 1, i, j, k in the quadruple
notation.
> quat := func<i,j,k | [<1,1,1, 1>, <i,i,1, -1>, <j,j,1, -1>, <k,k,1, -1>,
> <1,i,i, 1>, <i,1,i, 1>, <1,j,j, 1>, <j,1,j, 1>, <1,k,k, 1>, <k,1,k, 1>,
> <i,j,k, 1>, <j,i,k, -1>, <j,k,i, 1>, <k,j,i, -1>, <k,i,j, 1>, <i,k,j, -1>]>;
We now define the sequence of non-zero structure constants for the Cayley algebra using the
function quat. Some structure constants are defined more than once and we have to get rid of
these when defining the algebra.
> con := &cat[quat((n+1) mod 7 +2, (n+2) mod 7 +2, (n+4) mod 7 +2):n in [0..6]];
> C := Algebra< Rationals(), 8 | Setseq(Set(con)) >;
> C;
Algebra of dimension 8 with base ring Rational Field
> IsAssociative(C);
false
> IsAssociative( sub< C | C.1, C.2, C.3, C.5 > );
true
The integral elements in this algebra are those where either all coefficients are integral or exactly
4 coefficients lie in 1/2 + Z in positions i1 , i2 , i3 , i4 , such that i1 , i2 , i3 , i4 are a basis of one of the
7 quaternion algebras or a complement of such a basis. These elements are called the integral
Cayley numbers and form a Z-algebra. The units in this algebra are the elements with either one
entry ±1 and the others 0 or with 4 entries ±1/2 and 4 entries 0, where the non-zero entries√are
in the positions as described above. This gives 240 units and they form (after rescaling with 2)
the roots in the root lattice of type E8 .
$.1^2 + 1/2
Tensoring the integral Cayley algebra with a finite field gives a finite Cayley algebra. As the
Z-algebra generated by the chosen basis for C has index 24 in the full integral Cayley algebra,
we can get the finite Cayley algebras by applying the ChangeRing function for finite fields of odd
characteristic. The Cayley algebra over GF (q) has the simple group G2 (q) as its automorphism
group. Since the identity has to be fixed, every automorphism is determined by its image on the
remaining 7 basis elements. Each of these has minimal polynomial x2 + 1, hence one obtains a
permutation representation of G2 (q) on the elements with this minimal polynomial. As ±-pairs
have to be preserved, this number can be divided by 2.
In the case of the Cayley algebra over GF (3) we obtain a permutation representation of degree
351, which is in fact the smallest possible degree (corresponding to the representation on the cosets
of the largest maximal subgroup U3 (3) : 2). Over GF (5), the permutation representation is of
degree 7875, corresponding to the maximal subgroup L3 (5) : 2, the smallest possible degree being
3906.
We use the group algebra to determine the diameter of the Cayley graph of a group.
> G := Alt(6);
> QG := GroupAlgebra( Rationals(), G );
> e := QG!1 + &+[ QG!g : g in Generators(G) ];
> e;
Id(G) + (1, 2)(3, 4, 5, 6) + (1, 2, 3)
132 CHAPTER 19. ALGEBRAS
The group elements that can be expressed as words of length at most n in the generators of G
have non-zero coefficient in en . The following function returns for a group algebra element e a
sequence with the cardinalities of the supports of en and breaks when the group order is reached.
> wordcount( e );
[ 3, 7, 14, 26, 47, 83, 140, 219, 293, 345, 360 ]
Thus, every element in A6 can be expressed as a word of length at most 11 in the generators
(1, 2)(3, 4, 5, 6) and (1, 2, 3). A better 2-generator set is for example (1, 2, 3, 4, 5) and (1, 5, 3, 6, 4),
where all elements can be expressed as words of length at most 10 and this is in fact optimal. A
worst 2-generator set is given by (1, 2)(3, 4) and (1, 5, 3, 2)(4, 6).
The group algebra can also be used to investigate the random distribution of words of a certain
length in the generators of the group.
For growing n, the words of length n in the generators of M11 converge towards a random distri-
bution iff en converges towards eta. We look at the quadratic differences of the coefficients of
en −eta for n = 10, 20, 30, 40, 50.
19.3. MATRIX ALGEBRAS 133
Calculate the characteristic polynomial c of A and factorize c—note that there are quadratic
irreducible factors.
Calculate the primary invariant factors of A which give the structure of the blocks in the (gener-
alized) Jordan form of A.
> PrimaryInvariantFactors(A);
[
<x + 1, 1>,
<x + 1, 1>,
<x + 1, 1>,
<x + 1, 1>,
<x + 2, 1>,
<x + 2, 1>,
<x + 2, 1>,
<x + 2, 1>,
<x + 2, 1>,
<x + 2, 1>,
<x^2 + 1, 1>,
<x^2 + 1, 1>,
<x^2 + 1, 1>,
<x^2 + x + 2, 1>,
<x^2 + x + 2, 1>,
<x^2 + x + 2, 1>,
<x^2 + 2*x + 2, 1>,
<x^2 + 2*x + 2, 1>,
<x^2 + 2*x + 2, 1>
]
Now we let AF be the matrix A but with entries in F and then let cF be the characteristic
polynomial of AF. Note that cF now splits completely.
> cF;
y^28 + y^27 + 2*y^25 + 2*y^24 + 2*y^4 + 2*y^3 + y + 1
> Factorization(cF);
[
<y + 1, 4>,
<y + w, 3>,
<y + w^2, 3>,
<y + w^3, 3>,
<y + 2, 6>,
<y + w^5, 3>,
<y + w^6, 3>,
<y + w^7, 3>
]
> JordanForm(AF);
[2 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0]
[0 2 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0]
[0 0 2 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0]
[0 0 0 2 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0]
[0 0 0 0 w^5 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0]
[0 0 0 0 0 w^5 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0]
[0 0 0 0 0 0 w^5 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0]
[0 0 0 0 0 0 0 w^6 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0]
[0 0 0 0 0 0 0 0 w^6 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0]
[0 0 0 0 0 0 0 0 0 w^6 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0]
[0 0 0 0 0 0 0 0 0 0 w^7 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0]
[0 0 0 0 0 0 0 0 0 0 0 w^7 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0]
[0 0 0 0 0 0 0 0 0 0 0 0 w^7 0 0 0 0 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 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 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 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 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 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 w 0 0 0 0 0 0 0 0]
[0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 w 0 0 0 0 0 0 0]
[0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 w 0 0 0 0 0 0]
[0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 w^2 0 0 0 0 0]
[0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 w^2 0 0 0 0]
[0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 w^2 0 0 0]
[0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 w^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 w^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 w^3]
> A := M ! [i * j : i, j in [1 .. 10]];
> A;
[ 1 2 3 4 5 6 7 8 9 10]
[ 2 4 6 8 10 12 14 16 18 20]
[ 3 6 9 12 15 18 21 24 27 30]
[ 4 8 12 16 20 24 28 32 36 40]
[ 5 10 15 20 25 30 35 40 45 50]
[ 6 12 18 24 30 36 42 48 54 60]
[ 7 14 21 28 35 42 49 56 63 70]
[ 8 16 24 32 40 48 56 64 72 80]
[ 9 18 27 36 45 54 63 72 81 90]
[ 10 20 30 40 50 60 70 80 90 100]
Find the Jordan form J, with the transformation matrix T , and the primary invariant factors F .
> J, T, F := JordanForm(A);
> J;
[385 0 0 0 0 0 0 0 0 0]
[ 0 0 0 0 0 0 0 0 0 0]
[ 0 0 0 0 0 0 0 0 0 0]
[ 0 0 0 0 0 0 0 0 0 0]
[ 0 0 0 0 0 0 0 0 0 0]
[ 0 0 0 0 0 0 0 0 0 0]
[ 0 0 0 0 0 0 0 0 0 0]
[ 0 0 0 0 0 0 0 0 0 0]
[ 0 0 0 0 0 0 0 0 0 0]
[ 0 0 0 0 0 0 0 0 0 0]
> T;
[ 1 2 3 4 5 6 7 8 9 10]
[ 1 2 3 4 5 6 7 8 9 -57/2]
[ 1 2 3 4 5 6 7 8 -304/9 10]
[ 1 2 3 4 5 6 7 -321/8 9 10]
[ 1 2 3 4 5 6 -48 8 9 10]
[ 1 2 3 4 5 -349/6 7 8 9 10]
[ 1 2 3 4 -72 6 7 8 9 10]
[ 1 2 3 -369/4 5 6 7 8 9 10]
[ 1 2 -376/3 4 5 6 7 8 9 10]
[ -384 2 3 4 5 6 7 8 9 10]
> F;
19.3. MATRIX ALGEBRAS 137
[
<x - 385, 1>,
<x, 1>,
<x, 1>,
<x, 1>,
<x, 1>,
<x, 1>,
<x, 1>,
<x, 1>,
<x, 1>,
<x, 1>
]
> J eq T * A * T^-1;
true
We consider the algebra M5 (P ), where P is the polynomial ring in indeterminate x over the field
GF(5). We take the matrix having xi + xj in its (i, j)-th position.
> K := GaloisField(5);
> P<x> := PolynomialAlgebra(K);
> M := MatrixAlgebra(P, 5);
> a := M ! [x^i + x^j: i, j in [1..5]];
> a;
[ 2*x x^2 + x x^3 + x x^4 + x x^5 + x]
[ x^2 + x 2*x^2 x^3 + x^2 x^4 + x^2 x^5 + x^2]
[ x^3 + x x^3 + x^2 2*x^3 x^4 + x^3 x^5 + x^3]
[ x^4 + x x^4 + x^2 x^4 + x^3 2*x^4 x^5 + x^4]
[ x^5 + x x^5 + x^2 x^5 + x^3 x^5 + x^4 2*x^5]
> ElementaryDivisors(a);
[
x,
x^3 + 3*x^2 + x
]
We calculate the order and factored order of a random matrix over a finite field.
[21 13 4 13 17 0 0 21 3 0 13 13 0 1 17 9 9 18 11 21]
[14 5 20 20 22 4 5 21 0 3 7 14 1 0 12 19 5 18 0 20]
[19 9 14 19 4 5 20 8 22 8 12 9 9 22 9 16 10 14 8 5]
[21 11 12 6 11 19 12 9 8 9 7 0 10 0 3 16 21 2 19 9]
[14 9 9 16 22 5 0 14 6 4 2 11 20 17 7 10 7 7 13 10]
[22 21 2 22 11 18 7 3 19 7 2 18 11 3 10 18 10 8 1 19]
[ 5 17 10 17 1 22 8 3 19 13 22 20 8 12 17 14 3 15 12 4]
[ 0 16 6 7 19 19 10 3 15 21 3 22 13 19 22 6 19 1 12 12]
[18 19 18 0 15 5 19 22 6 9 22 20 16 17 12 2 5 2 22 16]
[21 1 22 6 18 14 2 7 8 15 9 20 11 15 20 7 16 3 5 8]
[ 8 19 18 3 7 5 7 19 22 13 4 13 7 4 11 21 3 14 8 3]
[ 5 11 15 15 19 0 1 12 0 8 0 1 18 10 8 0 5 0 15 11]
[21 7 18 2 5 22 21 8 6 5 18 17 22 15 12 13 2 7 6 4]
[ 3 7 13 12 19 3 10 16 18 20 10 21 11 21 2 19 11 6 13 8]
[15 20 18 15 12 7 18 2 3 16 18 4 7 14 17 16 0 22 15 1]
[15 11 21 12 9 2 0 12 12 21 12 10 11 20 8 2 10 17 13 21]
[15 10 17 0 19 13 21 21 16 10 13 0 10 12 13 21 3 10 20 7]
[ 3 21 11 12 16 13 2 17 21 12 16 11 14 9 7 10 19 10 0 7]
>
> Order(A);
216138319375440
> FactoredOrder(A);
[ <2, 4>, <3, 1>, <5, 1>, <7, 1>, <11, 1>, <19, 1>, <79, 1>, <7792003, 1> ]
We create the Lie algebra sl3 (Q) as a structure constant algebra. First, we construct gl3 (Q) from
the full matrix algebra M3 (Q) and get sl3 (Q) as the derived algebra of gl3 (Q).
Since it acts diagonally, this element lies in a Cartan subalgebra. The next candidate seems to be
the fifth basis element.
19.5. FINITELY PRESENTED ALGEBRAS 139
This also acts diagonally and commutes with sl3.1, hence we have luckily found a full Cartan
algebra in sl3 (Q). We can now easily work out the root system. Obviously the root spaces
correspond to the pairs (sl3.2, sl3.4), (sl3.3, sl3.7) and (sl3.6, sl3.8). The product of
a positive root with its negative should lie in the Cartan algebra.
> sl3.2*sl3.4;
( 1 0 0 0 -1 0 0 0)
> sl3.3*sl3.7;
(1 0 0 0 0 0 0 0)
> sl3.6*sl3.8;
(0 0 0 0 1 0 0 0)
Clearly some choices have to be made and we fix sl3.3 as the element eα corresponding to the
first fundamental root α, sl3.7 as e−α and get sl3.1 as hα = eα ∗e−α . For the other fundamental
root β we have to find an element eβ such that eα ∗ eβ is non-zero.
> sl3.3*sl3.2;
(0 0 0 0 0 0 0 0)
> sl3.3*sl3.4;
( 0 0 0 0 0 -1 0 0)
> sl3.3*sl3.6;
(0 0 0 0 0 0 0 0)
> sl3.3*sl3.8;
(0 1 0 0 0 0 0 0)
We choose sl3.8 as eβ , sl3.6 as e−β and consequently -sl3.5 as hβ . This now determines eα+β
to be sl3.2 and e−α−β to be sl3.4.
Each Coxeter group has associated with it a Hecke algebra generated by elements corresponding
to a set of fundamental roots for the group. Although the Hecke algebra is normally defined over
the ring of Laurent polynomials Z[q, q −1 ], we may construct a presentation by extending to Q and
setting q equal to a primitive root of unity. The following Magma code constructs a presentation
140 CHAPTER 19. ALGEBRAS
for the Hecke algebra of type E6 . Linton’s vector enumerator1 is then applied to construct a
27-dimensional representation over the field Q(ω), where ω is a fifth root of unity.
1 S.A.Linton, “Generalizations of the Todd-Coxeter Algorithm”, in: Wieb Bosma, Alf van der Poorten (eds),
Computational Algebra and Number Theory, Sydney 1992, Dordrecht: Kluwer, to appear, 1995; and S.A. Linton,
“Constructing Matrix Representations of Finitely Presented Groups”, J. Symbolic Comput. 12 (1991), 427–438.
Chapter 20
Plane Curves
• Newton Polygons
Curves in the plane are defined as the vanishing of a polynomial, y − x2 = 0 defining a parabola
for instance. But before making a curve in Magma, one must make the plane, its ambient space.
I make an affine plane over the rationals with coordinates x, y as follows.
> k := Rationals();
> A<x,y> := AffineSpace(k,2);
> A;
Affine space of dimension 2 with coordinates x,y
Of course, one can create other affine spaces: maybe the intersection points of two curves will have
coordinates in some extension of the rationals and a new plane with these extended coefficients
will be needed to find them.
One defines points in affine spaces using Magma’s usual coercion operator ! to reinterpret se-
quences of coordinates.
> p := A ! [1,0];
> p;
[ 1, 0 ]
141
142 CHAPTER 20. PLANE CURVES
The ambient space records the base√ field over which all points, curves and other schemes lying in
it must be defined. So the point [ 2, 0] could not have been coerced into this ambient space.
One creates curves using a reference to a 2-dimensional ambient space and a polynomial defined
on it.
This curve is contained in A and will stay that way: if you want to change it, by a base extension
or change of coordinates say, you will have to create a new curve.
> Ambient(C) eq A;
true
> BaseRing(C);
Rational Field
> IsNonSingular(C);
false
> SingularPoints(C);
[
[0, 0]
]
> q := SingularPoints(C)[1];
> T := TangentCone(C,q);
> T;
Affine scheme defined by [ x^2 ]
> IsReduced(T);
false
Notice that the tangent cone is embedded as a scheme in the same ambient space as C itself. The
code above could be the basis of a routine to check whether a given plane curve has only ordinary
singularities.
The function Blowup() returns the two standard affine plane curve patches on the blowup at the
origin.
> Blowup(C);
Affine plane curve defined by x*y^3 + 1
Affine plane curve defined by x^2 + y
In this case a single blowup resolves C — indeed, I can see that both patches are nonsingular.
For more complicated singularities more blowups will be needed. In a later version, Magma will
include functions to carry out the complete resolution of C expressing the data in a variety of
ways.
> Genus(C);
0
Since its equation has only two terms one can easily spot a parametrisation.
Maps from one projective space to another are defined by a sequence of homogeneous polynomials
of equal degree. I choose such a sequence out of the blue; later on I give some justification for my
choice.
The map φ is a birational embedding of the projective plane into projective 3-space. Its image,
strictly speaking, the closure of the image of the regular part of φ, is the singular quadric cone
b2 = ac.
I really want to calculate the image of C under this map. That is harder to do, but I can at least
calculate the equations of the image in any chosen degree. Of course, these might not be enough
to cut out C precisely, but a finite number of such equations will be.
That’s good — we certainly expect C to lie in the quadric cone since that’s the image of the plane
which C started out in — but we clearly need to find more equations.
So I have expressed the image of C as the nonsingular intersection of a conic and a cubic in
projective 3-space; compare with Hartshorne, Algebraic Geometry, GTM 52, Springer (1977),
section IV example (5.2.2) where one sees that any nonhyperelliptic curve of genus 4 admits such
a description.
To understand the choice of map in the previous paragraph, I analyse C by blowing up its singular
point a couple of times. I use some knowledge of curve singularities and their adjoints.
So I see that C has a single double point at (0 : 0 : 1). Blowing that up produces another double
point, a cusp, which is resolved by one more blowup. The expected genus of a degree 5 plane
curve is 21 (5 − 1)(5 − 2) = 6. Standard results in the resolution of curve singularities show that the
genus of this curve is 6 − 1 − 1 = 4 as was calculated earlier. Moreover, the (canonical) adjoints to
C are those plane curves of degree 2 passing through both the double point and the double point
after the blowup. I calculate these using linear systems.
Given the system of all curves of degree 2, I first restrict to those curves passing through the double
point, and then to those having a specified tangent at the double point, a condition equivalent to
the blowup condition.
> L := LinearSystem(P,2);
> L;
The complete linear system of degree 2
> p := SingularPoints(C)[1];
> L1 := Subsystem(L,p);
> L1;
The linear system defined by [ x^2, x*y, x*z, y^2, y*z ]
The system L1 is clearly too big: I’m essentially calculating a basis of sections of the canonical
class of the resolution of C, and the genus is by definition the size of such a basis.
20.3. BIRATIONAL MAPS OF THE PROJECTIVE PLANE 145
> T := ProjectivePlaneCurveType(Reduced(TangentCone(C,p)));
> L2 := Subsystem(L,p,T);
> L2;
The linear system defined by [ x^2, x*y, y^2, y*z ]
It is these functions that I used to define a map from the projective plane to projective 3-space
above.
Automorphisms of the projective plane are always linear. However, there are lots of maps which
are not everywhere defined, but which are bijections on an open subset of the plane. These are
the so-called birational automorphisms, often called cremona transformations. The archetype is
the following, called the standard quadratic transformation.
Notice that the map is normalised by multiplying up the denominators. I say that f has function
degree 2 since it can be defined using quadratic polynomials with no common factors. A cremona
transformation of the plane is a genuine automorphism if and only if it has function degree 1.
At the end of the last century, Max Nöther and others showed that any cremona transformation
can be composed (up to linear automorphisms) with the standard quadratic transformation to
produce a cremona transformation of lower function degree. (In fact, there are cases when this
doesn’t work, but after a sequence of such compositions it always does.) By making a string
of such compositions, he showed that any cremona transformation factorises as a composition of
linear automorphisms and standard quadratic transformations. Consider an example.
How do you begin? The trick is to find three points in the plane where g is not defined, move
them to the standard coordinate points and make a quadratic transformation. (The existence of
such points in a generalised setting and then the correct choice of a subset of them is determined
by the Nöther–Fano inequalities. However, I don’t do that here, rather I get ignorantly lucky.)
> Support(BaseLocus(g));
[ [ 0, 0, 1 ], [ -3/2, -1, 1 ], [ 3/4, -1, 1 ], [ 0, 1, 0 ], [ 1, 0, 0 ] ]
> std_quad := QuadraticTransformation(P);
> g1 := Composition(g,std_quad);
> FunctionDegree(g1);
2
146 CHAPTER 20. PLANE CURVES
The function degree has dropped which is the thing directing the induction. So I continue.
> Support(BaseLocus(g1));
[ [ -2/3, 0, 1 ], [ -2/3, -1, 1 ], [ 4/3, -1, 1 ] ]
> tr := Translation(P,$1);
> quad := Composition(tr,std_quad);
> g2 := Composition(g1,quad);
> FunctionDegree(g2);
1
So I’m done: the function g2 is a linear automorphism. To check the factorisation I compose the
maps appearing in the algorithm in the reverse order and recover g; note that standard quadratic
transformations are selfinverse.
> f1 := Composition(Inverse(tr),std_quad);
> f2 := Composition(std_quad,f1);
> f3 := Composition(g2,f2);
> f3 eq g;
true
I don’t explain the theory of divisors here except to say that one can think of them as being formal
sums of points of a curve; in particular, they form a group.
Notice that in this example the curve E is elliptic and in Weierstraß form. This is currently a
requirement of the functions below.
Given a point on E, one considers it as a divisor by coercing it into the divisor group.
> p := P ! [3,2,1];
> d := D ! p;
> d;
[ < [ 3, 2, 1 ], 1 > ]
The trailing 1 is the coefficient of the formal sum 1 · p. A line in the plane can be used to create a
principal divisor, the divisor of zeros and poles of the rational function `/z where ` is the equation
of the line.
> L := Divisor(D,p,p);
> L;
[ < [ 3, 2, 1 ], 2 >, < [ 0, 4, 1 ], 1 >, < [ 0, 1, 0 ], -3 > ]
20.4. LINEAR EQUIVALENCE OF DIVISORS 147
Notice the coefficient −3 coming from the pole of the flex z = 0 to E at infinity.
In the case of genus 1 curves like E one can always add a number of divisors of this form to a
given divisor to reduce it to a normal form having only a single positive component other than the
point at infinity (0 : 1 : 0). See what I mean in an example: the normal form is mostly supported
on the point (0 : 1 : 0).
> 3*d;
[ < [ 3, 2, 1 ], 3 > ]
> NormalForm(3*d);
[ < [ 1, 2, 1 ], 1 >, < [ 0, 1, 0 ], 2 > ]
Two divisors are said to be linearly equivalent if their difference is the divisor of zeros and poles
of some rational function, or equivalently, if their normal forms are identical.
> AreLinearlyEquivalent(3*d,$1);
true
($.1^2 + 4*$.1*$.2 + $.1*$.3 + 3*$.2*$.3 + 3*$.3^2)/
($.1*$.3 + 3*$.2*$.3 + 3*$.3^2)
Notice that a rational function is also returned. (Names for the generators of the rational func-
tions are not known, so the $.i notation is used.) This rational function corresponds to the
difference of the two arguments. It is unique up to a scalar multiple. The algorithm to calculate
it is straightforward: choose particular divisors arising from lines to add to or subtract from the
difference of the arguments — simply aim to eliminate points not at infinity by cancellation; each
of these generates a quotient of linear polynomials whose product is the required function.
Chapter 21
Elliptic Curves
Elliptic curves may be created over any field supported in Magma. The use of generic code
enables basic arithmetic of points to be performed regardless of the base field. The following
general operations are available:
• Division polynomials
We construct a generic point on an elliptic curve, by base extending the curve to its function field.
149
150 CHAPTER 21. ELLIPTIC CURVES
Now we can construct a generic point, and show that doubling the point results in the usual
expression for the double of a point.
The formulas for multiplication by n, and even for the addition law can be “discovered” in this
way.
Magma allows the formation of subgroups and subschemes of elliptic curves. Subgroups are de-
fined by a univariate polynomial; the rational points of the curve which are roots of this polynomial
are exactly the x-coordinates of points in the subgroup. General subschemes need not be closed
under the group law, and are specified by an ideal of a bivariate polynomial ring. Subgroups arise
naturally as the kernels of isogenies as covered in the next section.
One of the unique features of Magma is its facility for constructing maps between elliptic curves.
Four types of maps are supported, isogenies, isomorphisms, translations, and rational maps. Fea-
tures include:
• Isomorphisms, isogenies and rational maps between curves, translation maps on a curve
• Arithmetic of isomorphisms and isogenies: inverses, composition
• Degree of an isogeny;
• Kernel of an isogeny as a subgroup;
• Decide if curves are isomorphic;
21.3. MAPS BETWEEN ELLIPTIC CURVES 151
• Given a subgroup of an elliptic curve, construction of a separable isogeny with kernel that
subgroup;
We show to to construct an isogeny with given kernel, and then calculate its dual.
First we construct a separable isogeny whose kernel is the set of 3-torsion points on the curve E.
We know the composite of the isogeny and its dual will have kernel the group of n-torsion points,
where n is the degree of I. We construct this subgroup and push it through the isogeny:
Note that E2 is not equal to E - they are different models of the same curve. We have to multiply
J by the isomorphism between E2 and E to get the dual of I.
And check:
> pt := Random(E);
> Idual(I(pt)) eq deg*pt;
true
Magma contains an extensive package of functions for computing with elliptic curves over the
rationals. It incorporates code for computing the Mordell-Weil rank and group of an elliptic curve
based on John Cremona’s mwrank program. There are also facilities for computing heights of
points, rational points on curves, and a database of curves with conductor less than 5077.
• Invariants for integral curves: conductor, regulator, Mordell-Weil rank, Tamagawa numbers;
• Kodaira symbols;
• Database of curves with conductor less than 5077, with tables of properties.
We define an elliptic curve E over the rational field, then calculate its global minimal model M
and the torsion points of E and M .
21.4. ELLIPTIC CURVES OVER THE RATIONAL NUMBERS 153
> G, h := TorsionSubgroup(E);
> torsion_pts_E := [ h(g) : g in G ];
> torsion_pts_E;
[ (0, 1, 0), (-21, 216, 1), (51, -432, 1), (51, 432, 1),
(-21, -216, 1) ]
Since M is the minimal model of E, the two curves are isomorphic. We check this, assigning the
isomorphism M → E to the identifier iso. We next show that iso gives the expected correspondence
between the two sets of torsion points.
We calculate the integral points on the elliptic curve F defined by y 2 = x3 + 17 over the rational
field. Firstly, we calculate a basis a, b for the integral points, by mapping the generators of the
full Mordell-Weil group of F back to F . We then calculate ia + jb for small values of i and j, in
order to find other integral points.
This agrees with Silverman, [J. H. Silverman, The Arithmetic of Elliptic Curves (New York:
Springer-Verlag, 1986), 60.], who reports 16 integral points on F .
Magma contains several special functions for computing with elliptic curves defined over a finite
field. The most elaborate of these is an implementation of the Schoof-Elkies-Atkin algorithm for
calculating the order of a curve over a field of large characteristic. Lercier’s extension of the algo-
rithm is also implemented to enable calculation of the order of a curve over a field of characteristic
two. In intermediate characteristic, the algorithm of Atkin carries out the calculation.
• Trace of Frobenius
• Supersingular testing
• Random points
• Quadratic twist
This example computes the endomorphism ring of an elliptic curve over a finite field.
There is no square factor, so the ring generated by the Frobenius map is maximal. Since the curve
is ordinary, this equals the full endomorphism ring.
The discriminant contains a square factor, so the endomorphism ring may or may not be that
generated by the Frobenius. To find out we look at the 7-isogenies.
> Factorization(f);
[
<x + 27, 1>,
<x + 64, 1>,
<x + 210, 1>,
<x^7 + 93*x^6 + 76*x^5 + 113*x^4 + 93*x^3 + 217*x^2 + 175*x + 35, 1>,
<x^7 + 134*x^6 + 141*x^5 + 82*x^4 + 93*x^3 + 121*x^2 + 202, 1>,
<x^7 + 189*x^6 + 30*x^5 + 157*x^4 + 93*x^3 + 68*x^2 + 115*x + 222, 1>
]
Only one. A kernel polynomial for an isogeny of prime degree ` has degree (` − 1)/2, so in this
case a kernel is defined by a degree three polynomial, which can only come from the product of
the three linear factors. We can now conclude that the endomorphism ring is non-maximal at 7,
so is generated by the Frobenius endomorphism. Let’s find the isogeny:
> #E1;
156 CHAPTER 21. ELLIPTIC CURVES
235
> #E;
235
> IsIsomorphic(E1,E);
false
> Factorization(DivisionPolynomial(E1,7));
[
<x + 10, 1>,
<x + 12, 1>,
<x + 13, 1>,
<x + 14, 1>,
<x + 19, 1>,
<x + 32, 1>,
<x + 35, 1>,
<x + 43, 1>,
<x + 46, 1>,
<x + 65, 1>,
<x + 66, 1>,
<x + 84, 1>,
<x + 89, 1>,
<x + 102, 1>,
<x + 120, 1>,
<x + 138, 1>,
<x + 151, 1>,
<x + 156, 1>,
<x + 162, 1>,
<x + 192, 1>,
<x + 198, 1>,
<x + 208, 1>,
<x + 211, 1>,
<x + 224, 1>
]
All eight of them are rational! (Moreover each of the eight kernel polynomials of degree three splits
into linear factors.) One isogeny is the dual of I, the other seven will lead to different curves. We
now know that E1 has the largest possible endomorphism ring, of discriminant −19. Indeed, this
discriminant has class number one, so its j-invariant is defined over the integers:
The isogeny which generates the endomorphism ring will be the multiplication-by-5 map.
21.6. DATABASES FOR ELLIPTIC CURVES 157
We have to decide which of the pairwise groupings of linear factors define kernel polynomials.
> #E1;
235
> P := (235 div 5)*Random(E1);
> { P, 2*P };
{ (13, 82, 1), (35, 219, 1) }
So one kernel polynomial disappears on 13 and 35; the third and fourth factors of the division
polynomial. The first and second form the other pair.
J is a generator of the endomophism ring of E1, which satifies either the minimal polynomial
J 2 − J + 5, or J 2 + J + 5 of discriminant −19.
> F := FrobeniusMap(E1);
> P := Random(E1); P; F(P) eq P;
(40, 117, 1)
true
> J(J(P)) - J(P) + 5*P;
(115, 146, 1)
> J(J(P)) + J(P) + 5*P;
(0, 1, 0)
For the convenience of users, Magma comes with a copy of John Cremona’s elliptic curve database
already installed. This database contains minimal models of all the elliptic curves over the rationals
with conductor less than 5300, as well as a set of invariants for each. The database can be searched
by the user, enabling quick selection of appropriate examples and counter-examples.
Magma contains a database of modular equations calculated by Oliver Atkin. These equations
play a central role in the point-counting algorithms for elliptic curves over finite fields, and are also
directly available to the user. The database contains all modular equations for integers between
23 and 700, with the exception of those for 37 and 43. A supplementary database of canonical
modular equations to replace the missing equations in the database is also available on request.
Chapter 22
Enumerative Combinatorics
In addition to algebraic structures such as power series rings, Magma has the following facilities
for enumeration.
• Factorial
• Binomial, multinomial coefficients
• Stirling numbers of the first and second kind
• Fibonacci numbers, Bernoulli numbers, Harmonic numbers, and Eulerian numbers
• Number of partitions of n
• Enumeration of restricted and unrestricted partitions
• Sets of subsets, multisets, and subsequences of sets
• Permutations of sets (as sequences)
How can we make change for sixty cents using five, ten, twenty and fifty cent coins? The
RestrictedPartitions function will construct the ways for us.
159
160 CHAPTER 22. ENUMERATIVE COMBINATORICS
If we wish to know the number of different ways we can make change for varying amounts of
money we can use the well-known generating function solution.
We check that there are 18 ways to make change for sixty cents and find out that there are 49
ways to change a dollar with these coins.
Balanced strings of left and right parentheses may be generated using the grammar
S → (S)S | eps.
The procedure below, by Don Taylor, generates balanced strings from the grammar. The proba-
3
bility of (S)S being chosen rather than eps has been set to 10 .
produce := procedure();
seq := ["S"];
rhs := ["(", "S", ")", "S"];
i := 1;
repeat
if Random(1, 10) gt 7 then
Insert(~seq, i, i, rhs);
else
Remove(~seq, i);
end if;
print #seq gt 0 select &*seq else "eps";
i := Position(seq, "S");
until i eq 0;
print "Length:", #seq;
end procedure;
> produce();
22.1. THE ENUMERATION FUNCTIONS 161
(S)S
()S
()(S)S
()((S)S)S
()(()S)S
()(())S
()(())(S)S
()(())()S
()(())()
Length: 8
> produce();
eps
Length: 0
> produce();
(S)S
((S)S)S
(()S)S
(())S
(())
Length: 4
To find out how many strings of length n this grammar produces we consider the ordinary gen-
erating function f (x) of strings by length. Since the grammar is unambiguous we can read from
the grammar that this power series satifies
f (x) = x2 f (x)2 + 1.
We find that the grammar produces 132 different strings of length 12. We easily identify the
sequence of coefficients as the Catalan numbers.
162 CHAPTER 22. ENUMERATIVE COMBINATORICS
In this example we show how Magma can compute the Bernoulli number B10000 . The computation
depends on a new asymptotically fast polynomial division algorithm of Daniel Ford, coupled with
FFT methods for integer and polynomial multiplication. The whole computation takes about 14
hours on a 250MHz Ultrasparc.
This means that the i-th Bernoulli number Bi is i! times the coefficient of xi in E(x). The Bernoulli
numbers B0 , . . . , Bn for any n can thus be calculated by computing the above power series and
scaling the coefficients.
First we illustrate the method for a small number of coefficients (printing out the computed power
series at each stage).
For the small example, we first set the final precision p we desire to be 14. We then create the
denominator D = ex − 1 of the exponential generating function to precision p + 1 (we need p + 1
since we lose precision when we divide by the denominator and the valuation changes).
> p := 14;
> S<x> := PowerSeriesRing(RationalField());
> D := Exp(x + O(x^(p + 2))) - 1;
> D;
x + 1/2*x^2 + 1/6*x^3 + 1/24*x^4 + 1/120*x^5 + 1/720*x^6 + 1/5040*x^7 +
1/40320*x^8 + 1/362880*x^9 + 1/3628800*x^10 + 1/39916800*x^11 +
1/479001600*x^12 + 1/6227020800*x^13 + 1/87178291200*x^14 +
1/1307674368000*x^15 + O(x^16)
We then form the quotient E = x/D which gives the exponential generating function.
> E := x / D;
> E;
1 - 1/2*x + 1/12*x^2 - 1/720*x^4 + 1/30240*x^6 - 1/1209600*x^8 + 1/47900160*x^10
- 691/1307674368000*x^12 + 1/74724249600*x^14 + O(x^15)
We finally compute the Laplace transform of E (which multiplies the coefficient of xn by n!) to
yield the generating function of the Bernoulli numbers to precision p. Thus the coefficient of x14
here is B14 .
> B := Laplace(E);
> B;
1 - 1/2*x + 1/6*x^2 - 1/30*x^4 + 1/42*x^6 - 1/30*x^8 + 5/66*x^10 - 691/2730*x^12
+ 7/6*x^14 + O(x^15)
Now for the giant computation! We do the exactly the same but with p = 10000. First, computing
ex − 1 to precision p + 1 involves computing n! for n = 0, . . . 10001 which is a fairly small part of
the whole computation!
22.2. COMPUTING THE BERNOULLI NUMBER B10000 163
> p := 10000;
> S<x> := PowerSeriesRing(RationalField());
> time D := Exp(x + O(x^(p + 2))) - 1;
Time: 10.129
Forming the quotient E = x/D is where the bulk of the effort for the computation is spent. This
uses the fast division algorithm, coupled with the FFT multiplication methods. Without these
methods (i.e., using classical quadratic-complexity methods), the computation would probably
take weeks.
> time E := x / D;
Time: 45209.089
As before, we compute the Laplace transform of E to yield the generating function B. This takes
a while because the denominators of the coefficients of E are large and GCDs must be taken of
these with the appropriate factorials.
Printing the resulting generating function B takes about 70MB (900000 lines) of output, so we
will not include the output here! The printing actually takes about 5000 seconds because of all
the necessary base conversion from binary to decimal when printing the coefficients.
Xm µ ¶
m+1
Bj = 0.
j=0
j
This recurrence relation is commonly used to define the Bernoulli numbers; one could use it to
compute B10000 (with rational arithmetic) but this would be incredibly slow and the point of the
example is to use a better method!
We check our result by evaluating the left-hand side of the recurrence relation, with all compu-
tations done modulo a large prime p (which is the smallest prime greater than 1030 )—the result
should be zero modulo p.
164 CHAPTER 22. ENUMERATIVE COMBINATORICS
Finally, we make some comments on the actual run of Magma which was used to generate this
example.
The largest amount of time taken for the computation was the forming of the product of two
polynomials with integer coefficients, each of degree 5000. The coefficients of both polynomials
were each about 15000–20000 decimal digits on average! (This product arose within the recursive
division algorithm.)
To form the product, each polynomial was transformed using the FFT algorithm into a vector of
length 16384 whose points were each integer blocks of 131072 bits each. Each FFT transform took
about 96 seconds and the space taken by each vector was about 270MB of memory.
The vectors were then multiplied pointwise (placing the result back into the first vector to save
memory). This involved 16384 products of pairs of integers, each of which was 131072 bits (about
40000 decimal digits) long. These products were in turn done by the Schönhage-Strassen FFT
integer multiplication algorithm (so the FFT method was genuinely called recursively)! Each
integer product took 0.085 seconds, giving a total time of 1390 seconds for the 16384 products.
Finally, the inverse FFT was applied to the resulting product vector to obtain the product of the
original polynomials. This FFT transform took 94 seconds, and, adding in the time for a few
trivial house-keeping operations, the total time for the polynomial product was 1700 seconds.
Chapter 23
Graphs
Graphs may be directed or undirected. In addition, their vertices and/or their edges may be
labelled.
The following construction of Tutte’s 8-cage uses the technique described in P. Lorimer, J. of
Graph Theory, 13, 5 (1989), 553–557. The graph is constructed so that it has G = P ΓL(2, 9) in
its representation of degree 30 as its automorphism group. The vertices of the graph correspond
to the points on which G acts. The neighbours of vertex 1 are the points lying in the unique orbit
N1 of length 3 of the stabilizer of 1. The edges for vertex i are precisely the points N1g where g is
an element of G such that 1g = i.
> G := PermutationGroup< 30 |
> (1, 2)(3, 4)(5, 7)(6, 8)(9, 13)(10, 12)(11, 15)(14, 19)(16, 23)
> (17, 22)(18, 21)(20, 27)(24, 29)(25, 28)(26, 30),
> (1, 24, 28, 8)(2, 9, 17, 22)(3, 29, 19, 15)(4, 5, 21, 25)
> (6, 18, 7, 16)(10, 13, 30, 11)(12, 14)(20, 23)(26, 27) >;
> N1 := rep{ o : o in Orbits(Stabilizer(G, 1)) | #o eq 3 };
> tutte := Graph< 30 | <1, N1>^G >;
165
166 CHAPTER 23. GRAPHS
The Grötzch graph may be built by taking the complete graph K5, choosing a cycle of length 5
(say, 1-3-5-2-4), inserting a vertex of degree two on each chord of this cycle, and finally connecting
each of these vertices to a new vertex.
> G := CompleteGraph(5);
> E := EdgeSet(G);
> H := InsertVertex({ E | { 1, 3 }, { 1, 4 }, { 2, 4 }, { 2, 5 }, { 3, 5 } });
> L,V := Union(H, CompleteGraph(1));
> L := L + { { V.11, V.6 }, { V.11, V.7 }, { V.11, V.8 }, { V.11, V.9 },
> { V.11, V.10 } };
> L;
Graph
Vertex Neighbours
1 2 5 6 7 ;
2 1 3 8 10 ;
3 2 4 6 9 ;
4 3 5 7 8 ;
5 1 4 9 10 ;
6 1 3 11 ;
7 1 4 11 ;
8 2 4 11 ;
9 3 5 11 ;
10 2 5 11 ;
11 6 7 8 9 10 ;
Brendan McKay’s automorphism program (nauty) is used for computing automorphism groups.In
accordance with the Magma philosophy, a graph may be studied under the action of an automor-
phism group. Using the G-set mechanism an automorphism group can be made to act on any
desired set of objects derived from the graph.
We illustrate the use of some of the automorphism group functions on the graph of the 8-
dimensional cube.
> g := KCubeGraph(8);
> aut := AutomorphismGroup(g);
> Order(aut), FactoredOrder(aut);
10321920 [ <2, 15>, <3, 2>, <5, 1>, <7, 1> ]
> CompositionFactors(aut);
G
| Cyclic(2)
*
| Cyclic(2)
*
| Alternating(8)
*
| Cyclic(2)
*
| Cyclic(2)
*
| Cyclic(2)
*
| Cyclic(2)
*
| Cyclic(2)
*
| Cyclic(2)
*
| Cyclic(2)
1
> IsVertexTransitive(g);
true
> IsEdgeTransitive(g);
true
> IsSymmetric(g);
true
> IsDistanceTransitive(g);
true
> IntersectionArray(g);
[ 8, 7, 6, 5, 4, 3, 2, 1, 1, 2, 3, 4, 5, 6, 7, 8 ]
Chapter 24
Incidence Structures and Designs
General incidence structures provide a universe in which families of incidence structures satisfying
stronger conditions (linear spaces, t-designs, etc) reside.
Tools are provided for constructing designs from difference sets, Hadamard matrices, codes and
other designs. The standard families of difference sets are incorporated. A major feature is the
ability to compute automorphism groups and to test pairs of incidence structures for isomorphism.
We construct the Witt design D on 12 points, together with its point-set P and block-set B.
> D, P, B := WittDesign(12);
> D;
5-(12, 6, 1) Design with 132 blocks
This design has a resolution; i.e. the block-set of D can be partitioned into parallel classes. In
this example, the automorphism group A acts transitively on the classes of the resolution. Hence
we can get the resolution of D by taking the orbit of a single parallel class under A. To construct
the initial class, we select one of the blocks of points and then find the block consisting of the
remaining points.
169
170 CHAPTER 24. INCIDENCE STRUCTURES AND DESIGNS
We construct the automorphism group of the block design corresponding to the projective plane
PG(2, 2).
> B1 := { 1, 2, 4 };
> B2 := { 2, 3, 5 };
> B3 := { 3, 4, 6 };
> B4 := { 4, 5, 7 };
> B5 := { 5, 6, 1 };
> B6 := { 6, 7, 2 };
> B7 := { 7, 1, 3 };
> D := Design< 2, 7 | B1, B2, B3, B4, B5, B6, B7 >;
> D;
2-(7, 3, 1) Design with 7 blocks
> A, PP, BB := AutomorphismGroup(D);
> A;
Permutation group A acting on a set of cardinality 7
Order = 168 = 2^3 * 3 * 7
(1, 2)(3, 5, 6, 7)
(2, 5, 3)(4, 6, 7)
(2, 4)(3, 5, 7, 6)
(3, 6)(5, 7)
(3, 5)(6, 7)
> PP;
GSet{ 1, 2, 3, 4, 5, 6, 7 }
> BB;
GSet{ {1, 2, 4}, {2, 3, 5}, {3, 4, 6}, {4, 5, 7}, {1, 5, 6},
{2, 6, 7}, {1, 3, 7} }
The returned values PP and BB are A-sets corresponding to the action of the automophism group
on the points and blocks of D respectively. Using them, we can determine the stabilizer of the
24.2. AUTOMORPHISM GROUPS 171
block B1 in two ways—first, by regarding B1 as a set of points to be stabilized under the action
of A on the points; and second, by regarding B1 as a block to be fixed under the action of A on
the blocks.
The function DifferenceSet given below may be used to construct the design corresponding to
a given set S of integers forming a perfect difference set modulo n.
We use this function to construct a (19, 9, 4)-design and then proceed to compute its automorphism
group.
> IsPrimitive(A);
true
> IsFrobenius(A);
true
Thus the group is a Frobenius group and the normal subgroup of order 19 must be the Frobenius
kernel.
Chapter 25
Finite Planes
Although finite planes correspond to particular families of designs, separate categories are provided
for both projective and affine planes in order to exploit the rich structure possessed by these
objects.
Apart from elementary invariants, a reasonably fast method is available for testing whether a
plane is desarguesian. Among special configurations of interest, a search procedure for k-arcs
is provided. A specialized algorithm developed by Jeff Leon is used to compute the collineation
group of a projective plane while the affine case is handled by the incidence structure method. The
collineation group (order 23 38 ) of a “random” projective plane of order 81 supplied by Gordon
Royle was found in 1 202 seconds. As with graphs and designs the G-set mechanism gives the
action of the collineation group on any appropriate set.
This example is partly derived from J. D. Key’s paper “Some applications of Magma in designs
and codes: oval designs, hermitian unitals and generalized Reed-Muller codes” (1995, unpublished
173
174 CHAPTER 25. FINITE PLANES
manuscr ipt). A unital (or unitary) design is a Steiner 2-design with parameters 2-(m3 +1, m+1, 1).
In the context of the desarguesian plane of square order q 2 , the set of absolute points and non-
absolute lines of a unitary polarity forms a unital known as the hermitian unital.
Given a prime p and an integer m, the function below returns two values: the hermitian unital
xq+1 + y q+1 + z q+1 = 0 in PG(2, q 2 ), where q = pm ; and the design whose blocks are those
intersections of lines of the plane with the unital which have cardinality q + 1.
HUnital := function(p, m)
q := p^m;
P, V, L := ProjectivePlane(q ^ 2);
hu := { pt : pt in V |
IsZero(pt[1]^(q+1) + pt[2]^(q+1) + pt[3]^(q+1)) };
blks := [blk : lin in L | #blk eq (q+1) where blk is lin meet hu];
return hu, Design< 2, SetToIndexedSet(hu) | blks >;
end function;
We now evaluate the function for the case p = 2, m = 2, and compute the automorphism group
for the resulting design:
We construct the collineation group PGL(3, q) in its action on the points of PG(2, q), for the case
where q = 16.
We begin by creating the projective plane PP from the finite field with 16 elements, along with
the point-set and line-set of the plane. Then the collineation group G is formed.
> q := 16;
> F<w> := FiniteField(q);
> PP, Pts, Lns := ProjectivePlane(F);
25.2. CONSTRUCTION OF AN AFFINE PLANE BY DERIVATION 175
> PP;
The projective plane PG(2, 16)
> #Pts, #Lns;
273 273
We next define a certain Hall oval, and print its points. We choose points P and Q on the oval
and find the line P Q that contains P and Q. Then we choose a point X not on the line P Q: this
is done by choosing another point on the oval.
> P := Rep(oval);
> Q := Rep(Exclude(oval, P));
> P, Q;
( 1 : 0 : 0 ) ( 0 : 1 : 0 )
> PQ := Lns![P, Q];
> PQ;
< 0 : 0 : 1 >
Now we construct: the group H1 of central collineations with axis P Q; the group H2 of elations
with centre P and axis P Q; the group H3 of homologies with centre P and axis XQ; and the
group H4 of central collineations with centre P and axis through Q.
We construct the set afflines containing the lines of the new plane. They are: the translates of
oval (excluding P and Q) under the central collineations: the lines of PG(2, F ) (excluding P Q)
176 CHAPTER 25. FINITE PLANES
incident with P ; and the lines of PG(2, F ) (excluding P Q) incident with Q. Then we can construct
the affine plane itself.
Finally, we check that the plane is desarguesian by calculating the p-rank, which equals the
dimension of the corresponding linear code:
Currently, the coding theory module is designed for linear codes over finite fields though this will
be extended to linear codes over finite rings in the near future.
A large number of standard constructions are supported together with the determination of all
the standard invariants.
177
178 CHAPTER 26. ERROR-CORRECTING CODES
We construct a Goppa code of length 31 over GF(2) with generator polynomial G(z) = z 3 + z + 1.
> q := 2^5;
> K<w> := FiniteField(q);
> P<z> := PolynomialRing(K);
> G := z^3 + z + 1;
> L := [w^i : i in [0 .. q - 2]];
> C := GoppaCode(L, G);
> C;
[31, 16, 7] Goppa code (r = 3) over GF(2)
Generator matrix:
[1 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 1 0 0 1 0 0 1 0 1 1 0 0 0 0 1]
[0 1 0 0 0 0 0 0 0 0 0 0 0 1 0 0 1 0 0 1 1 1 1 0 0 1 0 1 1 0 1]
[0 0 1 0 0 0 0 0 0 0 0 0 0 1 0 0 1 0 0 0 1 0 0 1 0 1 0 0 0 0 1]
[0 0 0 1 0 0 0 0 0 0 0 0 0 1 1 0 0 0 0 1 1 1 0 1 0 1 0 1 0 1 1]
[0 0 0 0 1 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 1 1 0 1 1 0 1 1 1 1 1]
[0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 1 0 0 1 0 0 1 0 1 0 0 1 0 1 0]
[0 0 0 0 0 0 1 0 0 0 0 0 0 1 0 0 1 0 0 0 1 0 1 0 0 1 1 1 0 1 0]
[0 0 0 0 0 0 0 1 0 0 0 0 0 0 1 0 0 0 0 0 0 1 1 0 1 0 1 0 0 1 1]
[0 0 0 0 0 0 0 0 1 0 0 0 0 1 1 0 1 0 0 0 0 0 1 0 1 0 1 0 1 0 0]
[0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 1 1 1 1 0 1 1 1 1 0 1 0]
[0 0 0 0 0 0 0 0 0 0 1 0 0 0 1 0 1 0 0 0 0 0 1 1 1 1 0 1 1 1 1]
[0 0 0 0 0 0 0 0 0 0 0 1 0 1 1 0 0 0 0 1 1 1 1 0 0 0 1 0 1 1 1]
[0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 1 0 0 1 0 1 0 1 1 0 0 1 1 1 1]
[0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 0 0 1 1 1 0 1 0 0 1 1 0 1 0]
[0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 1 1 0 1 0 0 0 1 1 0 0 1]
[0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 1 0 0 1 0 1 0 1 1 1 1]
Algorithms are provided for computing the minimum weight and weight distribution. For example,
computation of the minimum weight (15) of a [79, 40, 15] quadratic-residue code takes 23 seconds;
computation of the weight distribution of the [64, 22, 16] Reed-Muller code (r = 2, m = 6) takes
2.9 seconds.
We determine the weight distribution and weight enumerator for the the second-order binary
Reed-Muller code of length 128 and its dual.
We construct a Hamming code C, encode an information word using C, introduce one error, and
then decode by calculating the syndrome of the “received” vector and applying the CosetLeaders
map to the syndrome to recover the original vector.
First we set C to be the third-order Hamming code over the finite field with two elements.
Then we set L to be the set of coset leaders of C in its ambient space V and f to be the map
which maps the syndrome of a vector in V to its coset leader in L.
> L, f := CosetLeaders(C);
> L;
{@
(0 0 0 0 0 0 0),
(1 0 0 0 0 0 0),
(0 1 0 0 0 0 0),
(0 0 1 0 0 0 0),
(0 0 0 1 0 0 0),
(0 0 0 0 1 0 0),
(0 0 0 0 0 1 0),
(0 0 0 0 0 0 1)
@}
> I := InformationSpace(C);
> I;
Full Vector space of degree 4 over GF(2)
> i := I ! [1, 0, 1, 1];
> w := i * GeneratorMatrix(C);
> w;
(1 0 1 1 0 1 0)
Now we set r to be the same as w but with an error in the 7th coordinate (so r is the “received
vector”).
> r := w;
> r[7] := 1;
26.4. AUTOMORPHISM GROUP 181
> r;
(1 0 1 1 0 1 1)
Finally we let s be the syndrome of r with respect to C, apply f to s to get the coset leader l,
and subtract l from r to get the corrected vector v. Finding the coordinates of v with respect to
the basis of C (the rows of the generator matrix of C) gives the original information vector.
We compute the automorphism group of the second-order Reed-Muller code of length 64.
In 1988, Cheng and Sloane discovered a binary [32, 17, 8] code having twice as many codewords
as the [32, 16, 8] extended quadratic residue code. The code can be constructed as a submodule of
the permutation module over GF(2) of the automorphism group of the 4-dimensional cube acting
on edges. We construct the code and compute its weight enumerator and automorphism group.
Thus, the module M has 373 submodules. We now proceed to find all codes of minimum weight
8 that arise as 17-dimensional submodules of L.
> codes := { C : N in L |
> Dimension(N) eq 17 and MinimumWeight(C) eq 8
> where C is LinearCode(Morphism(N)) };
> print #codes;
1
Therefore, there is only one such code, the one discovered by Cheng and Sloane. We compute its
weight enumerator and automorphism group.
> C := Rep(codes);
> Wt<x> := WeightEnumerator(C); print Wt;
x^32 + 908*x^24 + 3328*x^22 + 14784*x^20 + 27392*x^18 + 38246*x^16
+ 27392*x^14 + 14784*x^12 + 3328*x^10 + 908*x^8 + 1
> A := AutomorphismGroup(C); print A;
Permutation group A acting on a set of cardinality 32
Order = 384 = 2^7 * 3
(1, 29, 2, 22)(3, 25, 4, 23)(5, 28, 18, 8)(6, 7, 17, 32)
(9, 26, 14, 13)(10, 11, 12, 30)(15, 21, 16, 20)(19, 27, 24, 31)
(1, 2)(3, 16)(4, 15)(5, 14)(6, 12)(7, 30)(8, 26)(9, 18)(10, 17)
(11, 32)(13, 28)(19, 24)(20, 25)(21, 23)(22, 29)(27, 31)
(1, 31)(2, 27)(3, 16)(4, 15)(5, 8)(6, 7)(9, 13)(10, 11)(12, 30)
(14, 26)(17, 32)(18, 28)(19, 22)(20, 23)(21, 25)(24, 29)
(5, 17)(6, 18)(7, 28)(8, 32)(9, 12)(10, 14)(11, 26)(13, 30)
(19, 24)(20, 21)(22, 29)(23, 25)
(2, 3)(6, 7)(9, 19)(10, 20)(11, 23)(12, 24)(13, 22)(14, 21)
(16, 27)(18, 28)(25, 26)(29, 30)
(3, 15)(4, 16)(5, 9)(6, 10)(7, 11)(8, 13)(12, 17)(14, 18)(20, 23)
(21, 25)(26, 28)(30, 32)
Not unexpectedly, the automorphism group A of our code is isomorphic to our initial group, G!
26.4. AUTOMORPHISM GROUP 183
V. Pless (1972) constructed 5-designs from the codewords of minimum weight in a symmetry code.
The function Paley(q) below returns a (q + 1) by (q + 1) Paley matrix, i.e., a conference matrix
of the form
0 1 1 ··· 1
±1
..
. Q
±1
where Q is a q by q matrix of the form returned by Qmat(q):
Z := IntegerRing();
ConstZMat := func< n, r, c |
RMatrixSpace(Z, r, c) ! [ n : i in [1..r*c]] >;
We create a ternary [36, 18] symmetry code from the generator matrix (I | C), where C is a Paley
matrix with q = 17.
> q := 17;
> C := Paley(q);
> M := MatrixRing(GF(3), q+1);
> gen := HorizontalJoin(Identity(M), M ! C);
> LC := LinearCode(gen);
> LC : Minimal;
[36, 18] Linear Code over GF(3)
> #LC;
387420489
> LC eq Dual(LC);
true
184 CHAPTER 26. ERROR-CORRECTING CODES
We now construct a design from the supports of the words wds. Note that codewords c and 2c
have the same support, and thus contribute one block between them.
> BlockDegree(D);
12
> ReplicationNumber(D);
7140
27.1 Introduction
Magma contains most of the necessary tools to implement algorithms like RSA, Diffie-Hellman,
Rabin’s scheme, DSA, and similar cryptographic protocols based on modular arithmetic. We say
‘most’ of the tools since it currently does not implement any hash functions, but later versions
will. Magma is highly optimised for modular arithmetic in terms of both algorithms and imple-
mentation. When primes are requested, Magma will actually prove that the numbers are prime
using elliptic curve primality proving, unless the option Proof := false is used. In the latter
case, the strong pseudo prime1 probabilistic primality test is used with 20 random bases. The
number of bases can be changed when using the IsProbablePrime function.
Cyrptographers will find Magma’s efficient implementation of the following functions quite useful:
The following example illustrates how easy it is to implement cryptographic protocols based on
modular arithmetic within Magma. The example first selects a 160−bit prime q and then a 1024-
bit prime p such that p − 1 is divisible by q. We then create a base element g that has order q
modulo p. This completes the parameter generation.
185
186 CHAPTER 27. CRYPTOSYSTEMS BASED ON MODULAR ARITHMETIC
1337515134874490020173357215531009450590829772871
> Ilog2 (q);
159
> repeat
repeat> got_it, p := RandomPrime (1024, 1, q, 1000 : Proof := false);
repeat> until got_it;
> p;
9580857313574454467613060923425440574687571992321592085613767541323518556424063\
6870999714979396504020106523189126646490023404689751268797973287943112748468858\
5112188583029439178782333909341452456713751676055272435838466600707466469768637\
02436886400028700931402807964952723748913904077302288212634086165312979
> Ilog2 (p);
1023
> tmp := Random(p);
> exp := (p - 1) div q;
> g := Modexp (tmp, exp, p);
> g;
9099434663087419685135561467286690325533565050389764304406879818429098710086127\
5056323837603364481555882010692591443031542806508304253422643971354617261015205\
9526110036982281836121915695320198181107494957048326450851398389718852451553377\
71985882768398204953603166823927758384246426448586848858743868508080769
> Modexp (g, q, p);
1
The RandomPrime function above is used in two different ways. The first time, we asked for a
random prime which was up to 160−bits in length, and it returned the value q which happened
to be exactly 160−bits (which is equivalent to blog2 qc = 159). The second time, we asked for a
1024−bit prime that was congruent to 1 modulo q (so that p − 1 would be divisible by q). The
fourth argument, ‘1000’, was the number of iterations to attempt finding this prime before giving
up. Since there is a possibility of failure (for example, the user could possibly choose parameters
for which no prime exists of the form being requested), using RandomPrime in this form returns
two values: the first value is a boolean telling if it succeeded, and if it succeeded, the second value
is the prime. We put the second RandomPrime call in a loop to be sure we found such a prime.
Now that the parameters are set up, we are able to do a pseudo-implementation of the protocol.
First, Alice and Bob choose private keys and compute their corresponding public keys.
Alice and Bob now use each others public keys to compute the shared secret.
true
> /* the secret is... */
> A_sec;
8109416952960290247477174360527800613930603221801200765371022080190000393736445\
0307159060302439497132285938077980828986940582351118805711533307729202563454652\
9815387864793079894434226833555249730103795361582588274893664683809421885227721\
95753093058897768884456335283105474598964427905020684463746295562330487
Magma has the tools to implement and experiment with several attacks on public key cryptosys-
tems. Below is a simple example - Hastad’s broadcast attack on RSA when proper padding is
not used. In the simplest form of Hastad’s attack, it is possible to recover a message M if it is
encrypted and sent to three different people each having public exponent 3. The idea is to use
the Chinese remainder theorem to reconstruct M 3 modulo the product of each person’s modulus,
and that value is the same as the integer M 3 . Hence, M is retrieved by taking the cube root of
the result.
The first step is to generate three 1024-bit RSA moduli that each allow public exponent 3. The
RSAModulus command can be used to do this.
We will choose a random number between 1 and min(N 1, N 2, N 3) as the message to encrypt.
> N1 lt N2;
false
> N2 lt N3;
false
> M := Random (N3);
> M;
3440529232586722292829328861136561346736442600934839677157093901605167985958993\
3857060123042308889835795824523475956543160826810781254171877604928791186169070\
188 CHAPTER 27. CRYPTOSYSTEMS BASED ON MODULAR ARITHMETIC
3621537193780357046864912714525854536054067346404487840196055878389798209407065\
80974439526610180907344476555877076126103632612344115951050221575128623
The value of C 0 = M 3 can be computed using the Chinese remainder theorem. This is done below.
As mentioned earlier, Magma provides the option of proving primality, and in fact, it can even
return a readble proof to you. The function PrimalityCertificate runs Morain’s ECPP and
returns a certificate, and then the function PrimalityCertificate can be used to convert that
certificate into a readable proof. The option Trust indicates the point below which you are
prepared to take primes on trust (i.e. not display a formal proof).
Let us illustrate with the value q that was used in section 27.2. Since the proof takes up a few
pages, we only show part of it here.
> q := 1337515134874490020173357215531009450590829772871;
> pc := PrimalityCertificate (q);
> IsPrimeCertificate (pc : ShowCertificate := true, Trust := 10^6);
Statement: N = 14200079 is prime
----------
Theorem 1:
Let N - 1 = m*p where p is an odd prime such that 2*p+1 > sqrt(N).
If there exists an integer a such that
1. a^((N - 1)/2) = -1 mod N, and
2. a^(m/2) <> -1 mod N
then N is prime.
Here:
N - 1 = 106 * 133963
It was already proved that p=133963 is a prime.
2*p+1 = 267927 > sqrt(N) = 3768.299218480400874016954855
Let a := 11
Then:
Theorem 1:
Let N - 1 = m*p where p is an odd prime such that 2*p+1 > sqrt(N).
If there exists an integer a such that
1. a^((N - 1)/2) = -1 mod N, and
2. a^(m/2) <> -1 mod N
then N is prime.
Here:
190 CHAPTER 27. CRYPTOSYSTEMS BASED ON MODULAR ARITHMETIC
N - 1 = 2 * 14200079
It was already proved that p=14200079 is a prime.
2*p+1 = 28400159 > sqrt(N) = 5329.179955677984045909398984
Let a := 7
Then:
Theorem 4:
Let N be an integer greater than 1 and prime to 6. Let E be an
elliptic curve over Z/NZ, m and s two integers such that s divides
m. Suppose we have found a point P on E that satisfies mP = O_E, and
that for each prime factor q of s, we have verified that (m/q)P <> O_E.
If s > (sqrt[4](N)+1)^2, then N is prime.
Here:
E : Y^2 = X^3 + 0 * X + 13537256947685289 .
P = (9328326001824128606101878404779919459976,
5229592904990638368428645153905898717896, 1) .
m * P = 55028159614939147721070141849703 * P = (0, 1, 0) .
m := c*s where c = 1 and s = 55028159614939147721070141849703.
It was already proved that q = 55028159614939147721070141849703 is a prime.
(m/q)*P = (9328326001824128606101878404779919459976,
5229592904990638368428645153905898717896, 1) .
s > (sqrt[4](N)+1)^2 = 99784151379379952272.45348058 .
Therefore, N is prime.
Theorem 1:
Let N - 1 = m*p where p is an odd prime such that 2*p+1 > sqrt(N).
If there exists an integer a such that
1. a^((N - 1)/2) = -1 mod N, and
2. a^(m/2) <> -1 mod N
then N is prime.
Here:
27.5. INTEGER FACTORISATION 191
N - 1 = 134330790 * 9956876862515957958509417055695194307953
It was already proved that p=9956876862515957958509417055695194307953 is a
prime.
2*p+1 = 19913753725031915917018834111390388615907 > sqrt(N) =
1156509893980371453775462.441
Let a := 3
Then:
true
Magma’s highly optimised factorisation routines can be quite useful in numerous applications.
The examples below illustrates for three numbers. The timings were done on a 333 Mhz Sun
Workstation.
28.1 Introduction
Magma conatins an extensive library for working with elliptic curves over many different types of
fields. Here we restrict our examples to the basic functions which can be used to implement elliptic
curve cryptography (ECC). For a more in-depth discussion of Magma’s elliptic curve functionality,
please refer to the documents Alebraic Geometry in Magma and An Overview of Magma.
This example is small enough that one can verify the computations by hand. In the first step, we
create the elliptic curve y 2 = x3 + 16x + 11 over GF(19) by specifying the two coefficients 16 and
11. We then list all the points, which are given in projective form. Next, we select two points (P
and Q) and do some simple arithmetic operations.
193
194 CHAPTER 28. ELLIPTIC CURVE CRYPTOGRAPHY
> i := 0;
> repeat
repeat> i := i + 1;
repeat> until (IsIdentity(i*P));
> i;
9
> 9*P;
(0, 1, 0)
> Order(P);
9
The use of randomly generated curves for ECC is often suggested, since some people fear that spe-
cially chosen curves may not be as secure. Unfortunately, the difficulty of efficient implementation
of point counting algorithms prevent many people from having this option. However, Magma
does quite well, as the following example illustrates. These computations were done on a 333 MHz
Sun workstation.
+ w^52 + w^51 + w^49 + w^48 + w^46 + w^43 + w^41 + w^39 + w^37 + w^36 + w^34
+ w^31 + w^28 + w^25 + w^22 + w^19 + w^18 + w^17 + w^11 + w^9 + w^8 + w^7 +
w^4 + w^3 + w)*x^2 + (w^162 + w^159 + w^158 + w^157 + w^156 + w^155 + w^154
+ w^152 + w^151 + w^150 + w^148 + w^146 + w^145 + w^143 + w^142 + w^140 +
w^139 + w^132 + w^131 + w^130 + w^127 + w^125 + w^119 + w^117 + w^116 +
w^114 + w^112 + w^111 + w^110 + w^108 + w^107 + w^106 + w^102 + w^101 +
w^100 + w^95 + w^92 + w^91 + w^90 + w^87 + w^86 + w^81 + w^80 + w^79 + w^76
+ w^75 + w^73 + w^72 + w^71 + w^69 + w^68 + w^66 + w^61 + w^60 + w^57 + w^56
+ w^55 + w^54 + w^46 + w^43 + w^39 + w^38 + w^37 + w^36 + w^31 + w^29 + w^28
+ w^26 + w^23 + w^22 + w^19 + w^16 + w^15 + w^14 + w^12 + w^11 + w^10 + w^8
+ w^7 + w^6 + w^5 + w^2 + w) over GF(2^163)
> time Order(E);
11692013098647223345629477395231649124606825548932
Time: 43.810
Counting the points took just short of 44 seconds! To convince ourself that the result is correct,
we select a random point and multiply it by the order:
As any cryptographer knows, computing discrete logs on elliptic curves can be a very difficult task.
However, if the curve was not chosen securely, the computation may be feasible. Magma contains
a fast implementation of the Pohlig-Hellman and the van Oorschot-Wiener parallel collision search
algorithms. In the example below, the largest prime factor of the order of the curve is 50-bits.
> K := GF(RandomPrime(97));
196 CHAPTER 28. ELLIPTIC CURVE CRYPTOGRAPHY
> n;
1690793370222126531882026190457535410772343917
> P := Random(E) * (Order(E) div n);
> P;
(790453240443123790554571249483379206427271956600,
325843289698143222404459068215716111970272227044, 1)
> Order(P) eq n;
true
The private key d is chosen as a random integer mod n, and from that the public key Q is computed
as d times the base point P .
> d := Random(n);
> Q := d*P;
> Q;
(920519926385924148398458711152818574128596774502,
553865768004097214761917304328882406025468089306, 1)
> M := Random(n);
> M;
1654636034743999889619171508648168266181438360
To sign M , we first select a random number k and compute the point k∗P . The x-coordinate of the
result is extracted, and that value modulo n is taken to be r. Note that this x−coordinate is a finite
field element which must be coerced to an integer. Then s is computed to be k −1 (M + dr) mod n
and the pair (r, s) is the signature for M .
> k := Random(n);
> kp_seq := ElementToSequence (k*P);
> kp_seq;
[ 700008528872903877813195484185896175850306338609,
582253421118186060369191301935795359994090876503, 1 ]
> r := (IntegerRing()!kp_seq[1]) mod n;
> r;
20073600943493614036641336476515790555956971
> s := (Modinv (k, n) * (M + d*r)) mod n;
> s;
1107972919999368435492883456055569826752602919
To verify the signature, we first check that r and s are in the range of [1, n − 1]. If that passes, set
u1 to M ∗ s−1 mod n, u2 to r ∗ s−1 mod n, and let v be the x-coordinate modulo n of the point
u1 ∗ P + u2 ∗ Q. The signature is valid if and only if v equals r.
> r in [1..n-1];
198 CHAPTER 28. ELLIPTIC CURVE CRYPTOGRAPHY
true
> s in [1..n-1];
true
> w := Modinv (s, n);
> u1 := M*w mod n; u2 := r*w mod n;
> temp := u1*P + u2*Q;
> temp;
(700008528872903877813195484185896175850306338609,
582253421118186060369191301935795359994090876503, 1)
> temp_seq := ElementToSequence (temp);
> v := (IntegerRing()!temp_seq[1]) mod n;
> v;
20073600943493614036641336476515790555956971
> v eq r;
true
Several cryptographic papers have showed the speed advantages of specially chosen curves, such
as anamolous binary curves. This section illustrates some of the Magma tools for experimenting
with these ideas by implementing the algorithms from Jerome Solinas’ Crypto ’97 paper entitled
“An Improved Algorithm for Arithmetic on a Family of Elliptic Curves”2 .
We start by using a curve from Solinas’ paper of order equal to twice a prime r.
> q := 2;
> m := 163;
> K<z> := GF(q^m);
> Esub := EllipticCurve([GF(q)| 1, 1, 0, 0, 1]);
> E := BaseExtend(Esub, K);
> E;
Elliptic Curve defined by y^2 + x*y = x^3 + x^2 + 1 over GF(2^163)
> FactoredOrder (E);
[ <2, 1>, <5846006549323611672814741753598448348329118574063, 1> ]
> r := $1[2][1];
> Trace(Esub);
1
Due to space constraints, we were unable to include his algorithm in this document.
28.6. EXAMPLE: SCALAR MULTIPLY USING THE FROBENIUS MAP 199
Next, we choose a point of order r on the curve, and select a random integer k to be used for the
scalar multiply.
We now want to write the scalar k in terms of τ so that the scalar multiply can be done quickly.
By using the NAF encoding method, the expected density (i.e. number of nonzero coefficients) is
one third the encoding length. To make the encoding length small, reduction of k modulo τ m − 1
is performed and the result is represented as a linear combination of 1 and τ . Fortunately, we
can do this computation with much less code in Magma than what was given in Solinas’ paper,
because Magma provides a mod function3 for the maximal order R, and because τ is an element
of the integral basis. The code below performs the reduction, and then obtains a τ -adic NAF
encoding of the result.
Before doing the scalar multiply, let’s check that the encoding actually worked:
> s := #S;
> sum := R!0;
> for i in [s..1 by -1] do
for> sum := tau*sum + S[i];
for> end for;
> sum;
-991956120863437853224788 + 589253799488616101896173*tau
> k_mod_modulus;
-991956120863437853224788 + 589253799488616101896173*tau
> sum eq k_mod_modulus;
true
z^87 + z^86 + z^81 + z^79 + z^78 + z^74 + z^68 + z^67 + z^65 + z^63 + z^61 +
z^57 + z^53 + z^52 + z^51 + z^50 + z^49 + z^48 + z^47 + z^45 + z^44 + z^43 +
z^39 + z^38 + z^36 + z^31 + z^30 + z^27 + z^25 + z^16 + z^15 + z^12 + z^11 +
z^9 + z^7 + z^4 + z^3 + z + 1, 1)
> kP := k*P;
> print "expected to get: ", kP;
expected to get: (z^156 + z^155 + z^153 + z^151 + z^148 + z^147 + z^146 + z^145
+ z^141 + z^140 + z^139 + z^138 + z^136 + z^134 + z^132 + z^131 + z^129 +
z^125 + z^122 + z^119 + z^116 + z^115 + z^113 + z^112 + z^109 + z^108 +
z^104 + z^103 + z^98 + z^97 + z^96 + z^94 + z^93 + z^91 + z^90 + z^86 + z^82
+ z^80 + z^79 + z^78 + z^77 + z^76 + z^73 + z^72 + z^71 + z^69 + z^67 + z^66
+ z^62 + z^57 + z^55 + z^52 + z^51 + z^49 + z^47 + z^44 + z^41 + z^40 + z^39
+ z^37 + z^35 + z^34 + z^33 + z^30 + z^27 + z^24 + z^19 + z^17 + z^16 + z^15
+ z^13 + z^11 + z^7 + z^6 + z^5 + z^3 + z^2 + 1, z^162 + z^160 + z^157 +
z^156 + z^153 + z^151 + z^143 + z^141 + z^140 + z^137 + z^136 + z^131 +
z^130 + z^128 + z^127 + z^126 + z^122 + z^121 + z^120 + z^119 + z^115 +
z^114 + z^112 + z^108 + z^107 + z^105 + z^101 + z^98 + z^95 + z^93 + z^92 +
z^88 + z^87 + z^86 + z^81 + z^79 + z^78 + z^74 + z^68 + z^67 + z^65 + z^63 +
z^61 + z^57 + z^53 + z^52 + z^51 + z^50 + z^49 + z^48 + z^47 + z^45 + z^44 +
z^43 + z^39 + z^38 + z^36 + z^31 + z^30 + z^27 + z^25 + z^16 + z^15 + z^12 +
z^11 + z^9 + z^7 + z^4 + z^3 + z + 1, 1)
> R eq kP;
true
Chapter 29
LLL and Lattice Based Ciphers
29.1 Introduction
The LLL lattice reduction algorithm has proven itself to be a very important tool in cryptography.
Magma has a highly optimised implementation based on the FP-LLL algorithm of Schnorr and
Euchner and the de Weger integral algorithm. For more details on Magma’s lattice machinery,
refer to the document Module Theory in Magma by Allan Steel.
In this chapter we demonstrate how effective Magma’s LLL can be for cryptanalytic applications
by implementing and cryptanalyzing the Merkle-Hellman knapsack cryptosystem.
Our implementation of the Merkle-Hellman Knapsack scheme is based upon the description given
in The Rise and Fall of Knapsack Cryptosystems by Andrew Odlyzko. Let n be the number of
elements in the knapsack. Then we create Pa superincreasing knapsack b1 , . . . , bn with b1 ≈ 2n and
n
bn ≈ 22n . We then choose a value M > j=1 bj and an integer W such that gcd(M, W ) = 1.
Let π be a random permutation of the integers 1, . . . , n. The public weights are created by
aj = bπ(j) W mod M . The trapdoor private information is the bj , M , W , and π. The Magma
code below is one way of performing this parameter generation.
max_increment := 2^n;
/* generate b_1 : the first element of the vector */
b_i := 2^n + Random (1, max_increment);
b_vec := [b_i];
sum := b_i;
for i in [2..n] do
b_i := sum + Random (1, max_increment);
sum +:= b_i;
Append (~b_vec, b_i);
end for;
M := NextPrime (sum);
W := Random (1, M);
203
204 CHAPTER 29. LLL AND LATTICE BASED CIPHERS
pi := Random(Sym(n));
To encrypt a stream of n bits, we simply add the aj ’s together where the corresponding input bit
is a 1.
n := #bit_stream;
if n ne #a_vec then
print "ERROR: bit_stream must be same length as a_vec";
return 0;
end if;
/* assume bit_stream was entered properly (contains only 1’s and 0’s) */
return &+[a_vec[i]*bit_stream[i] : i in [1..n]];
end function;
Decryption is done with the trapdoor information. By multiplying the sum s by W −1 mod M ,
we are able to find the original bit stream using the superincreasing property of the bj and the
permutation π.
n := #b_vec;
pi_inv := pi^-1;
bit_stream := [0 : i in [1..n]];
return bit_stream;
end function;
Here is a small example, using a knapsack of length 50 and a randomly generated bit stream.
29.3. CRYPTANALYSIS WITH LLL 205
> n := 50;
> a_vec, b_vec, M, W, pi := KnapsackParamGeneration (n);
> a_vec;
[ 1386915547668324532996071313267, 480859449341809389615925150721,
396831847319158859761380910988, 1100492193377271901625809282566,
602163238313232210355415916295, 225743102342246789252109786635,
178027020140160005094859199390, 779220245900000096190424559705,
1119144046051117135238533914655, 1418686951088432878615983998936,
899299012420785534489933598742, 565071352129143828482957948937,
53957821466545320161917709457, 313904821458716880518680856652,
519241475289568336576750859767, 1289665342941505668365298399433,
238900603596419042941537807273, 536259692176238414925018681313,
933360455834373612992698096458, 77420254874942454508653944008,
1357247585805657102274983154542, 265062672662096748950202024392,
1463546371870460613421683901684, 780541407523099261353546130279,
409719664966522686344206604523, 313884181857775522859495247905,
1435444384474192324157952546261, 753326465780188459888065768459,
424115371126362588790544114246, 1000154808549905130987323691901,
80674888369062544661414074351, 32851776062654913119621352433,
1591423709902385491737044525729, 1164573295123181605738862740531,
1166866106328683648615938806544, 508385025612481068258268255595,
1009324978486724871710849690549, 1588353352827906714598130028095,
800259809134539255416029873707, 768702586293351853940869658594,
63200795057489971649383667562, 798217142168267708536649714137,
1052381564098338275979264812466, 994288605478880536515871422188,
289608215198805540201911271638, 179259316982728917034735283463,
821652935065312755697389840491, 22024370738243911810448800424,
66736060857289293708802287026, 145362079149720553476747758142 ]
> bit_stream := [Random(0,1): i in [1..n]];
> bit_stream;
[ 0, 1, 0, 0, 0, 1, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 1, 0, 1, 1, 0, 1, 0, 1, 1, 0,
1, 0, 1, 1, 1, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 1, 1, 0, 1, 1, 1 ]
> s := KnapsackEncrypt (bit_stream, a_vec);
> s;
12548424973953989357522773357968
LLL has aided cryptologists in breaking many of the variants of knapsack cryptosystems. Below is
a simple Magma program written by Allan Steel which can be used to break the Merkle-Hellman
knapsack scheme. The general idea of this attack is due to Schnorr and Euchner.
b2 = (2, . . . , 0, na2 , 0)
..
.
bn = (0, . . . , 2, nan , 0)
bn+1 = (1, . . . , 1, ns, 1).
The code repeatedly applies LLL with parameter 0.9991 until a solution is found. It is possible
to use other reduction algorithms that Magma provides to possibly speed up the process, but we
didn’t find the need for these other tools for this application.
function SolveKnapsack(Q, s)
n := #Q;
X := RMatrixSpace(IntegerRing(), n + 1, n + 2) ! 0;
for i := 1 to n do
X[i][i] := 2;
X[i][n + 1] := n * Q[i];
X[n + 1][i] := 1;
end for;
X[n + 1][n + 1] := n * s;
X[n + 1][n + 2] := 1;
c := 0;
while true do
c +:= 1;
"LLL number", c;
X := LLL(X: Delta := 0.999);
v := X[1];
"Norm:", Norm(v);
Using this code, the knapsack was broken in less than a second:
But this was an easy example! We used the same code to break a knapsack of length 100. It
finished in 258 iterations and took only 2.5 minutes!
Chapter 30
McEliece Cryptosystem
30.1 Introduction
We demonstrate how these functions can be useful to the cryptographer by implementing the
McEliece public key cryptosystem, and showing an attack on the system when certain precautions
are not taken. The attack comes from Tom Berson’s Crypto ’97 paper Failure of the McEliece
Public-Key Cryptosystem Under Message-Resend and Related-Message Attack.
Below is the Magma code for implementing this cryptosystem. This code was written by Damien
Fisher, however some small style changes were made.
The first function generates a random Goppa code using the minimal polynomial of a random
element from a degree 50 extension of GF(210 ). The generator matrix for this code will have
524 rows, 1024 columns, and will be able to correct up to 50 errors. These are the parameters
originally suggested by McEliece.
209
210 CHAPTER 30. MCELIECE CRYPTOSYSTEM
function RandomCode()
q := 2^10;
K<w> := FiniteField(q);
Kext := ext<K | 50: Optimize := false>;
repeat
g := MinimalPolynomial (Random(Kext),K);
until Degree(g) eq 50;
L := [x: x in K];
The function below creates the private and public keys using the RandomCode function. The private
key consists of the tuple < C, S, P > where C is the Goppa code, S is an invertible 524 by 524
scrambler matrix, and P is a 1024 by 1024 permutation matrix over GF(2). The public key G is
a 524 by 1024 matrix over GF (2).
function McElieceKey()
// Magically pick C.
C := RandomCode ();
n := Length (C);
k := Dimension (C);
G := S * GeneratorMatrix (C);
I_n := MatrixRing (GF(2), n)!1;
P := Parent (I_n) ! [I_n[j] ^ perm : j in [1 .. n]];
G := G * P;
Next, we give the functions to encrypt and decrypt. Encryption of a 1024-bit message m is done
by multiplying m (treated as a vector over GF(2)) by G and then adding a random error vector
e having t 1’s in it. Decryption is done by first multiplying the ciphertext by P −1 , then decoding
the Goppa code, and finally multiplying by S −1 .
count := 0;
repeat
30.1. INTRODUCTION 211
return m * G + V!e;
end function;
And now, we test it. This example uses an error of weight t = 10, which is not large enough for
true cryptographic applications, but good enough for illustrative purposes.
1 1 1 1 1 0 0 0 0 0 1 0 1 1 0 1 1 1 0 1 1 0 0 1 1 1 1 1 0 0 1 0 0 0 0 1 0 1
0 1 1 1 0 1 1 0 1 0 0 1 1 1 0 0 1 1 1 0 0 1 0 0 1 1 0 0 0 0 0 0 0 1 1 0 1 0
0 1 1 0 0 1 0 1 1 1 1 0 1 1 1 1 0 0 1 0 1 1 1 0 0 1 1 1 1 1 0 0 1 1 1 1 1 1
0 1 1 0 1 0 1 1 0 0 0 1 0 0 0 1 1 1 0 0 0 0 0 1 0 0 0 1 0 0 0 0 1 0 0 0 0 0
1 1 1 0 1 0 1 1 0 0 1 0 0 0 1 0 1 1 0 1 1 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 1
0 1 1 0 0 1 0 0 0 0 0 1 1 1 1 0 1 1 1 1 0 0 0 0 0 0 1 1 0 0 1 0 0 1 0 1 1 1
1 0 0 0 1 1 1 0 1 1 1 0 0 0 1 1 0 0 1 1 0 0 0 1 1 1 0 0 0 0 1 1 1 0 0 0 1 0
1 1 1 1 1 0 0 1 0 1 0 0 0 1 1 1 0 0 0 0 1 1 0 0 0 1 0 1 0 1 1 0 1 1 1 1 0 0
0 0 0 1 0 0 0 0 1 1 0 0 0 1 0 0 1 0 1 1 0 1 1 0 0 0 0 1 1 1 1 0 1 1 1 0 1 0
1 0 1 0 0 1 0 1 1 1 0 1 0 0 0 0 1 0 0 1 1 0 1 0 0 0 0 1 1 0 1 0 0 0 0 1 1 1
0 1 0 1 1 1 0 0 1 1 0 1 0 0 0 1 1 0 0 0 0 1 1 0 0 1 1 1 0 0 1 0 1 0 1 0 0 0
0 0 1 0 1 0 0 1 1 0 0 0 1 0 0 1 1 1 0 1 1 0 0 0 1 1 0 1 1 0 0 1 0 0 1 0 0 1
1 1 0 1 1 1 1 1 0 1 0 1 0 1 0 0 0 1 0 0 0 0 1 0 1 1 1 0 1 0 1 1 0 1 1 1 1 1
0 1 0 1 0 0 0 0 0 1 0 0 0 1 1 0 1 0 0 1 0 0 0 1 1 0 1 0 1 0 1 0 1 1 1 0 1 0
0 0 0 1 1 0 1 0 1 0 0 0 1 1 1 1 0 0 0 1 1 0 1 0 1 0 0 1 0 0 0 1 1 1 0 0 0 0
0 1 0 0 1 1 1 0 0 1 1 1 1 1 0 0 0 0 1 0 1 1 1 0 0 0 0 1 1 1 1 1 0 1 1 1 1 1
1 1 0 0 0 0 0 1 0 0 1 1 0 0 0 1 0 0 0 0 0 0 0 1 1 1 0 1 0 1 1 1 1 0 0 0 1 0
1 0 0 1 0 1 1 0 1 1 0 1 0 1 1 0 1 0 0 0 0 1 1 1 0 1 0 1 0 0 1 1 0 0 1 1 1 1
0 0 1 1 1 1 1 1 1 0 0 0 1 0 1 1 1 1 1 0 1 0 1 0 1 0 1 1 1 0 1 1 1 0 1 0 1 1
0 0 0 0 1 0 0 1 0 0 0 0 0 0 1 1 0 1 0 0 0 1 0 1 1 0 0 1 0 0 1 0 1 1)
> mprime := McElieceDecrypt (c, priv);
> mprime;
(0 1 0 0 0 1 1 1 0 1 0 1 0 0 1 1 1 0 0 0 0 1 1 0 1 0 1 0 0 0 0 1 0 0 0 1 1 0 0 1
1 0 1 1 1 0 1 0 0 1 0 1 1 1 1 0 0 0 0 0 1 0 0 0 0 0 1 0 0 0 0 0 1 0 0 0 1 0
1 0 0 1 0 1 0 0 1 1 0 1 1 1 0 1 1 0 0 1 0 1 0 1 1 0 0 1 0 1 1 1 1 0 1 0 1 1
0 0 0 0 0 1 1 1 0 0 1 0 0 1 0 1 1 0 1 0 0 0 0 0 0 1 1 0 1 1 1 1 0 1 1 1 0 0
1 1 0 0 1 1 1 1 1 1 1 0 1 0 1 1 0 1 0 0 1 0 1 0 0 0 0 0 0 1 0 0 1 1 0 1 1 0
0 1 0 0 0 1 1 0 0 0 1 0 0 1 0 1 1 0 0 1 0 0 1 0 0 1 1 0 1 1 0 0 1 0 1 1 0 1
0 1 0 1 1 1 1 1 1 0 1 0 1 1 1 0 1 1 1 0 1 1 0 1 1 0 0 0 0 0 0 0 0 1 0 0 1 0
1 1 0 1 0 1 1 0 0 0 0 1 1 1 0 1 0 1 0 0 1 0 1 0 1 1 1 0 1 1 0 0 0 0 0 1 1 0
0 0 0 1 1 0 0 0 1 0 0 1 1 0 0 0 0 0 0 1 0 0 1 1 0 1 0 1 0 1 1 1 1 0 0 0 1 1
1 0 0 1 0 1 0 0 0 1 1 1 1 0 1 1 1 0 1 0 1 0 1 0 1 1 0 1 1 0 0 0 0 0 0 1 0 0
1 0 1 0 1 0 1 0 1 1 0 1 1 1 1 0 0 0 1 0 0 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 1
1 1 0 0 0 0 1 0 1 0 0 0 1 0 1 1 0 1 0 1 0 1 1 1 0 0 0 1 0 1 0 1 1 1 0 0 0 0
1 1 0 1 1 0 1 1 1 1 0 0 1 1 0 1 0 0 1 1 1 1 0 0 1 0 1 1 0 1 1 0 0 0 0 1 1 0
0 0 1 1 0 0 0 0 0 1 1 1 0 1 0 0 1 0 0 0 0 0 0 1 0 1 1 1)
> m eq mprime;
true
Following Tom Berson’s article, we explain how to attack the McEliece system when not properly
implemented. The general idea is that if we could guess 524 locations where the product m × G
is not changed by the error vector e, then we can look at those corresponding 524 columns of G
to get a relation that doesn’t involve any error between the ciphertext and the plaintext. If these
columns are linearly independent, then square matrix associated with them can be inverted, and
consequently m can be retrieved.
It takes too much expected work to guess 524 correct columns if nothing is known about where
the errors are. However, if the same message is encrypted twice using different random vectors,
then the exclusive-or of the ciphertexts equals the exclusive-or of the error vectors, hence revealing
30.2. ATTACKING MCELIECE USING MESSAGE RESEND 213
where most of the errors are. The only errors which are not revealed are those that occur in the
same place for both encryptions. Berson showed that for t = 50, you expect to find around 95.1 of
the 100 errors, and then the probability of correctly guessing 524 good values is very reasonable
(i.e. 5 or 12 attempts is often enough).
Since in our example we are only allowing t = 10, we expect to find approximately 19.8 errors. In
fact, most of the time we will find 20, and this simplifies our code slightly because we usually only
need one attempt.
procedure MessageResend()
priv, pub := McElieceKey();
n := 1024;
k := 524;
if m ne m1prime then
print "deciphering failed.";
else
print "deciphered message is: ";
print m1prime;
end if;
end procedure;
> MessageResend();
original message is:
(0 0 1 1 0 0 1 0 1 1 1 1 1 0 0 0 0 0 1 1 1 1 0 0 1 0 0 1 0 1 1 1 1 0 0 1 1 1 1 0
0 1 1 1 0 1 0 1 0 0 1 0 1 1 0 1 1 1 1 1 1 1 1 0 1 0 1 0 0 1 0 0 1 1 0 1 0 0
1 1 1 0 1 0 0 1 0 0 0 1 1 0 0 1 0 0 0 1 0 1 1 1 0 0 0 0 1 0 0 1 1 0 0 0 0 0
0 1 0 0 0 1 1 1 0 1 1 0 1 1 1 1 1 1 1 1 0 0 0 0 0 1 1 1 0 0 1 1 0 1 1 1 0 0
1 0 0 1 1 1 1 0 0 0 0 1 0 1 0 0 0 1 1 0 0 1 1 1 1 0 0 1 1 1 1 1 1 0 1 0 1 0
0 0 0 0 1 1 0 0 0 1 1 0 0 0 0 1 0 0 0 0 0 1 0 1 1 1 1 1 1 0 1 1 0 1 0 0 1 0
0 1 0 0 0 0 0 0 0 1 0 0 0 1 0 0 1 0 1 1 1 0 0 0 1 0 0 1 1 1 0 1 0 1 0 1 1 0
0 0 0 1 1 0 1 1 1 1 1 1 0 1 0 0 1 0 0 0 0 0 0 1 0 0 0 1 0 0 0 1 0 1 0 0 1 0
1 1 1 1 1 0 1 1 1 1 0 0 1 0 0 1 1 0 0 0 0 1 0 1 1 0 0 0 0 0 0 0 0 0 1 0 1 0
1 0 1 0 1 1 1 0 1 0 1 1 0 1 1 0 0 0 0 1 0 0 1 1 0 1 1 1 0 0 1 1 1 0 0 1 0 0
0 1 1 0 0 0 0 1 0 0 0 0 1 1 0 0 0 0 1 0 0 0 1 0 1 0 0 0 0 0 1 0 1 1 1 0 0 0
0 1 1 0 1 1 0 1 0 0 0 1 1 0 0 0 0 1 1 0 0 0 0 0 1 1 1 1 0 1 1 1 0 0 1 1 0 1
0 0 0 0 1 0 1 1 0 1 0 1 1 0 1 0 1 0 1 0 0 0 1 0 1 0 0 1 1 0 0 1 1 1 0 1 1 0
0 0 1 0 0 0 0 0 1 1 1 0 1 0 1 0 0 0 1 1 0 0 1 0 0 0 1 0)
Sum of two ciphertexts is:
(0 0 0 0 0 0 0 0 0 0 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 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 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 0 0 0 0 0 0 0 0 0 0 0
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 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 1 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 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 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 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 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
30.2. ATTACKING MCELIECE USING MESSAGE RESEND 215
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 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 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 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 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 0 0 0 0 0 0 0 0 0 0 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 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 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 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0)
deciphered message is:
(0 0 1 1 0 0 1 0 1 1 1 1 1 0 0 0 0 0 1 1 1 1 0 0 1 0 0 1 0 1 1 1 1 0 0 1 1 1 1 0
0 1 1 1 0 1 0 1 0 0 1 0 1 1 0 1 1 1 1 1 1 1 1 0 1 0 1 0 0 1 0 0 1 1 0 1 0 0
1 1 1 0 1 0 0 1 0 0 0 1 1 0 0 1 0 0 0 1 0 1 1 1 0 0 0 0 1 0 0 1 1 0 0 0 0 0
0 1 0 0 0 1 1 1 0 1 1 0 1 1 1 1 1 1 1 1 0 0 0 0 0 1 1 1 0 0 1 1 0 1 1 1 0 0
1 0 0 1 1 1 1 0 0 0 0 1 0 1 0 0 0 1 1 0 0 1 1 1 1 0 0 1 1 1 1 1 1 0 1 0 1 0
0 0 0 0 1 1 0 0 0 1 1 0 0 0 0 1 0 0 0 0 0 1 0 1 1 1 1 1 1 0 1 1 0 1 0 0 1 0
0 1 0 0 0 0 0 0 0 1 0 0 0 1 0 0 1 0 1 1 1 0 0 0 1 0 0 1 1 1 0 1 0 1 0 1 1 0
0 0 0 1 1 0 1 1 1 1 1 1 0 1 0 0 1 0 0 0 0 0 0 1 0 0 0 1 0 0 0 1 0 1 0 0 1 0
1 1 1 1 1 0 1 1 1 1 0 0 1 0 0 1 1 0 0 0 0 1 0 1 1 0 0 0 0 0 0 0 0 0 1 0 1 0
1 0 1 0 1 1 1 0 1 0 1 1 0 1 1 0 0 0 0 1 0 0 1 1 0 1 1 1 0 0 1 1 1 0 0 1 0 0
0 1 1 0 0 0 0 1 0 0 0 0 1 1 0 0 0 0 1 0 0 0 1 0 1 0 0 0 0 0 1 0 1 1 1 0 0 0
0 1 1 0 1 1 0 1 0 0 0 1 1 0 0 0 0 1 1 0 0 0 0 0 1 1 1 1 0 1 1 1 0 0 1 1 0 1
0 0 0 0 1 0 1 1 0 1 0 1 1 0 1 0 1 0 1 0 0 0 1 0 1 0 0 1 1 0 0 1 1 1 0 1 1 0
0 0 1 0 0 0 0 0 1 1 1 0 1 0 1 0 0 0 1 1 0 0 1 0 0 0 1 0)
Notice that the sum of the two ciphertexts had exactly twenty 1’s in it (as expected).
Chapter 31
Pseudo Random Bit Sequences
31.1 Introduction
Magma has some useful tools for analyzing and generating bit sequences, including:
• LFSR simulation
• Berlekamp-Massey algorithm
• Autocorrelation and Crosscorrelation functions
• Sequence decimation
• Shrinking generator
• Blum-Blum-Shub and RSA pseudo-random bit generators
Bits are represented by Magma as elements over GF(2). However not all of these functions are
restricted to this finite field.
For a linear feedback shift register (LFSR) of length L, initial state s0 , . . . , sL−1 ∈ GF(q), and
connection polynomial C(D) = 1 + c1 D + c2 D2 + . . . + cL DL (also over GF(q)), the j’th element
PL
of the sequence is computed as sj = − i=1 ci sj−i for j ≥ L. Magma includes the functions
LFSRStep and LFSRSequence to simulate linear feedback shift registers. The former will advance
a sequence one step to the next state of the LFSR. The latter will return a sequence of values that
result from the output of the corresponding LFSR.
We illustrate with an example from The Handbook of Applied Cryptography on page 196. First a
sequence of length 15 is generated using the primitive polynomial, and next we show the states of
the LFSR as it advances the first three steps.
> K := GF(2);
> P<D> := PolynomialRing (K);
> P;
Univariate Polynomial Ring in D over Finite field of size 2
> C := 1 + D + D^4;
> S := [K| 0,1,1,0];
217
218 CHAPTER 31. PSEUDO RANDOM BIT SEQUENCES
Using these functions, it is possible to create your own functions to simulate stream ciphers
like nonlinear combination generators, summation generators, nonlinear filter generators, etc....
Another common stream cipher is the shrinking generator, however this one is already programmed
within Magma (command: ShrinkingGenerator).
The Berlekamp-Massey algorithm can be used to compute the smallest LFSR connection polyno-
mial that generates a sequence of finite field elements. In the example below, we start with 10
randomly chosen elements from the field GF(132 ), and compute a connection polynomial that gen-
erates that sequence. The BerlekampMassey function returns a minimal connection polynomial,
and also the length L which tells the number of elements necessary to regenerate the sequence
(this is necessary since the connection polynomial may be singular). Using this information, we
regenerate the initial sequence using its first L elements.
Decimation of the sequence S by a value a value d means to create a new sequence by taking
every d’th element of S with wrap-around such that the new sequence is the same length as the
original. Given a primitive polynomial over GF(q), one can obtain another primitive polynomial
by decimating an LFSR sequence obtained from the initial polynomial. This is demonstrated in
the code below.
31.5. OTHER BIT GENERATORS 219
> K := GF(7);
> C<D> := PrimitivePolynomial(K, 2);
> C;
D^2 + 6*D + 3
In order to generate an LFSR sequence, we must first multiply this polynomial by a suitable
constant so that the trailing coefficient becomes 1.
> C := C * Coefficient(C,0)^-1;
> C;
5*D^2 + 2*D + 1
We are now able to generate an LFSR sequence of length 72 − 1. The initial state can be anything
other than [0, 0].
In addition to the pseudo-random bit generators mentioned above, one can also use the Blum-
Blum-Shub or RSA random bit generators. In the example below, we generate a 1024-bit Blum-
Blum-Shub modulus N , and then count the number of 1’s in a sequence of 1000 bits generated
from the Blum-Blum-Shub algorithm using modulus N and a randomly chosen initial seed.
> N := BlumBlumShubModulus(1024);
> &+[IntegerRing()!b: b in BlumBlumShub (N, Random(N), 1000)];
489
Chapter 32
Finite Fields
32.1 Introduction
Several sections of this book give examples of Magma’s functionality with finite fields. However,
the topic is important enough in cryptography that it deserves its own chapter.
• Construction of GF(q) for any prime power, and arithmetic in that field
• Construction of towers of extensions
• Trace and norm of an element
• Order of an element
• Characteristic and minimum polynomials
• Square root (Tonelli-Shanks method for GF(p)), n-th root
• Construction of primitive and normal elements, testing for primitivity and normality
• Enumeration of irreducible polynomials
• Polhig-Hellman, baby-step giant-step, linear sieve, and Gaussian integer sieve discrete logarithm
algorithms
• Factorisation of polynomials over finite fields
• Creating splitting fields
• Factorisation over splitting fields
The ability to efficiently factor polynomials over finite fields can be very handy. Below we give a
simple example, where we find all fifth roots of an element modulo a prime p.
221
222 CHAPTER 32. FINITE FIELDS
> m := Random(K) ^ 5;
> m;
881494904
> /* we know m is a fifth power. Now find all of its fifth roots */
> P<x> := PolynomialRing (K);
> f := x^5 - m;
> Factorisation (f);
[
<x + 98800491, 1>,
<x + 180305718, 1>,
<x + 351879082, 1>,
<x + 469153538, 1>,
<x + 1002212893, 1>
]
> fact := $1;
> for i := 1 to 5 do
for> z := -Evaluate (fact[i][1], 0);
for> print z, "^5 -", m, "=", z^5 - m;
for> end for;
952375370 ^5 - 881494904 = 0
870870143 ^5 - 881494904 = 0
699296779 ^5 - 881494904 = 0
582022323 ^5 - 881494904 = 0
48962968 ^5 - 881494904 = 0
In the next example, we create a random degree 5 monic polynomial over GF(220 ). It factors into
a linear factor and a fourth degree polynomial. We verify that factorisation is correct, and then
factor it over the splitting field.
z^39 + z^38 + z^37 + z^35 + z^34 + z^30 + z^24 + z^22 + z^21 + z^19 +
z^9 + z^8 + z^7 + z^2 + z + 1, 1>,
<Y + z^78 + z^77 + z^76 + z^75 + z^74 + z^71 + z^70 + z^69 + z^68 + z^63 +
z^60 + z^58 + z^55 + z^52 + z^41 + z^39 + z^37 + z^31 + z^29 + z^28 +
z^26 + z^24 + z^22 + z^21 + z^20 + z^19 + z^17 + z^16 + z^15 + z^13 +
z^11 + z^10 + z^8 + z^6 + z^5 + z^4 + z^3 + z, 1>,
<Y + z^79 + z^74 + z^73 + z^72 + z^71 + z^70 + z^68 + z^67 + z^66 + z^65 +
z^64 + z^62 + z^59 + z^58 + z^57 + z^53 + z^51 + z^50 + z^48 + z^47 +
z^43 + z^41 + z^40 + z^39 + z^38 + z^36 + z^33 + z^32 + z^31 + z^29 +
z^27 + z^26 + z^23 + z^18 + z^17 + z^15 + z^14 + z^9 + z^6 + z^5 + z^3 +
z + 1, 1>,
<Y + z^79 + z^78 + z^75 + z^74 + z^73 + z^72 + z^71 + z^70 + z^69 + z^65 +
z^63 + z^53 + z^52 + z^51 + z^50 + z^48 + z^47 + z^45 + z^42 + z^41 +
z^40 + z^37 + z^35 + z^34 + z^33 + z^32 + z^31 + z^22 + z^21 + z^20 +
z^16 + z^15 + z^13 + z^12 + z^10 + z^9 + z^8 + z^5 + z^4 + z^3 + z^2 +
1, 1>,
<Y + z^79 + z^74 + z^73 + z^72 + z^71 + z^70 + z^69 + z^65 + z^64 + z^63 +
z^60 + z^58 + z^57 + z^55 + z^54 + z^50 + z^49 + z^48 + z^46 + z^45 +
z^43 + z^41 + z^39 + z^38 + z^37 + z^34 + z^32 + z^31 + z^29 + z^28 +
z^27 + z^26 + z^24 + z^23 + z^20 + z^18 + z^15 + z^14 + z^13 + z^9 + z^7
+ z^5 + z^4, 1>
]
Finite field of size 2^80
> fact2 := $1;
> prod := fact2[1][1];
> for i := 2 to 5 do
for> prod := prod * fact2[i][1];
for> end for;
> prod;
Y^5 + (z^79 + z^78 + z^77 + z^75 + z^70 + z^69 + z^67 + z^60 + z^58 + z^56 +
z^55 + z^52 + z^50 + z^49 + z^47 + z^46 + z^43 + z^38 + z^36 + z^34 + z^32 +
z^30 + z^29 + z^26 + z^24 + z^22 + z^21 + z^20 + z^13 + z^12 + z^11 + z^8 +
z^4 + z^3 + z + 1)*Y^4 + (z^79 + z^78 + z^77 + z^73 + z^69 + z^68 + z^67 +
z^66 + z^65 + z^62 + z^61 + z^58 + z^57 + z^56 + z^54 + z^53 + z^51 + z^49 +
z^47 + z^44 + z^42 + z^41 + z^40 + z^39 + z^38 + z^37 + z^34 + z^33 + z^32 +
z^31 + z^29 + z^26 + z^25 + z^21 + z^20 + z^19 + z^15 + z^14 + z^13 + z^11 +
z^10 + z^9 + z^4 + z^3 + z)*Y^3 + (z^78 + z^76 + z^74 + z^73 + z^69 + z^68 +
z^67 + z^59 + z^58 + z^57 + z^52 + z^51 + z^48 + z^44 + z^42 + z^35 + z^34 +
z^31 + z^30 + z^29 + z^27 + z^26 + z^25 + z^23 + z^22 + z^21 + z^17 + z^16 +
z^15 + z^14 + z^10 + z^9 + z^8 + z^5 + z^2)*Y^2 + (z^79 + z^78 + z^76 + z^75
+ z^74 + z^70 + z^69 + z^68 + z^66 + z^65 + z^63 + z^62 + z^61 + z^60 + z^55
+ z^52 + z^48 + z^44 + z^42 + z^41 + z^40 + z^39 + z^37 + z^36 + z^32 + z^30
+ z^26 + z^25 + z^24 + z^23 + z^21 + z^20 + z^17 + z^15 + z^14 + z^13 + z^8
+ z)*Y + z^79 + z^78 + z^77 + z^76 + z^73 + z^70 + z^67 + z^66 + z^65 + z^63
+ z^62 + z^61 + z^58 + z^56 + z^53 + z^50 + z^45 + z^43 + z^41 + z^39 + z^37
+ z^35 + z^34 + z^29 + z^27 + z^21 + z^19 + z^16 + z^12 + z^11 + z^9 + z^8 +
z^5 + z^2 + 1
The result was given as a polynomial over GF(2). To get it as a polynomial over K, we can do
the following:
> P!prod;
X^5 + w^516299*X^4 + w^885970*X^3 + w^628673*X^2 + w^453256*X + w^639090
224 CHAPTER 32. FINITE FIELDS
Remark: you may have noticed that the fields GF(220 ) and GF(280 ) are represented differently
within Magma. For GF(220 ), the element w is a generator of the multiplicative group. Magma
is able to use such a representation for small fields because the factorisation of the order of the
multiplicative group can quickly be obtained, and therefore a multiplicative generator can be found
quickly. For larger fields, Magma does not attempt this computation.
Our next example shows Magma’s ability to compute discrete logarithms efficiently in prime
fields. We generate an 100-bit prime p, and notice that the factorisation of p − 1 would make it
nearly impossible to perform a Pohlig-Hellman discrete logarithm because the largest prime factor
is 27-digits. Thus, Magma internally uses an index calculus discrete logarithm algorithm, which
will either be the Gaussian integer sieve or the linear sieve, both due to Coppersmith, Odlyzko,
and Schroeppel. In most cases, Magma will choose the Gaussian integer sieve, since it is more
efficient in practice.
The logarithm took less than 17 seconds! But subsequent logarithms will in fact go much faster,
since certain data does not need to be recomputed. For example, on the second call to the Log
function, the result is computed in about 1 second:
> b^m - t;
0
In Shamir’s t out of n threshold scheme, a set of n people each hold shares of a secret S, and any t
of them can get together to compute S. However, less than t people can get no information about
it.
The scheme is based upon polynomial interpolation in a finite field. Let K be a finite field. Initially
we choose the secret randomly from K along with t − 1 other random values from K. These values
are used to create a polynomial f of degree t − 1 over K such that f (0) = S. Below we do this
for t = 3 and n = 5.
> t := 3;
> n := 5;
> p := RandomPrime (160);
> p;
831683565424322358470119661658063377313329498701
> Ilog2(p);
159
> K := GF(p);
> S := Random (K);
> S;
388005396389914678062277072148817245612709240026
> a_vec := [S];
> for i in [1..t-1] do
for> Append (~a_vec, Random(K));
for> end for;
> P<x> := PolynomialRing(K);
> f := P!a_vec;
> f;
570810940281561956797303947735945134707953478833*x^2 +
339162245841631570546880748441891441159716340186*x +
388005396389914678062277072148817245612709240026
The next step is to compute shares of the secret. For persons i ∈ [1..n], we let their share be f (i).
Reconstructing the secret is done by polynomial interpolation. First, we choose 3 people at random
to reconstruct S.
> p := [];
> s := [];
> for i in [1..t] do
for> repeat
for|repeat> person := K!Random (1, n);
for|repeat> until person notin p;
for> Append (~p, person);
for> /* store this person’s share */
for> Append (~s, shares[IntegerRing()!person]);
for> end for;
>
> p;
[ 1, 3, 4 ]
> s;
[ 466295017088785846936342106668590444167049560344,
721005638478610491587817215491554140270133079174,
65743073745241608895107628136681260505546778985 ]
33.1 NTRU
Arithmetic will be done in R = Z [X] with reduction modulo X N − 1 for N = 11. We will also
need to reduce modulo p = 3 and q = 32. Thus, we create rings Rp = Z [X] /p and Rq = Z [X] /q.
> N := 11;
> q := 32;
> p := 3;
> R<X> := PolynomialRing( Integers() );
> Rp := PolynomialRing( GF(p) );
> Rq := PolynomialRing( ResidueClassRing( q ) );
We will need to compute inverses in the ring of truncated polynomials modulo p and q. Algorithms
for doing this are given at http://www.ntru.com/tech.technical.htm. Below is an implementation
of the algorithms within Magma:
function InverseModPrime( R, a, p, N )
X := R.1;
Rp := PolynomialRing( GF(p) );
k := 0; b := R!1; c := R!0;
f := a; g := X^N - 1;
while true do
f0 := Evaluate(f, 0);
while f0 eq 0 do
f := f div X; c := c * X; k +:= 1;
f0 := Evaluate(f, 0);
end while;
if Degree(f) eq 0 then
b := R!Rp!(b * Modinv( f0, p ));
227
228 CHAPTER 33. MISCELLANEOUS
f0 := Evaluate(f, 0);
g0 := Evaluate(g, 0);
u := (Modinv( g0, p ) * f0) mod p;
f := R!Rp!(f - u*g);
b := R!Rp!(b - u*c);
end while;
return ans;
end function;
b := InverseModPrime( R, a, p, N );
q := p;
X := R.1;
while q lt prime_power do
q := q*p;
Rq := PolynomialRing( ResidueClassRing( q ) );
b := R!Rq!( (b * (2 - a * b)) mod (X^N - 1) );
end while;
return b;
end function;
We take the example polynomials f (X) and g(X) from the web site, and compute
The results are coerced back to polynomials in Z [X]. It is easy to check that the inverses are
correct. The values of F p, p and g(X) are used to compute the public key h(X).
> f := -1+X+X^2-X^4+X^6+X^9-X^10;
> g := -1+X^2+X^3+X^5-X^8-X^10;
> Fp := InverseModPrimePower( R, f, p, N );
33.1. NTRU 229
> Fq := InverseModPrimePower( R, f, q, N );
> Fp;
2*X^9 + X^8 + 2*X^7 + X^5 + 2*X^4 + 2*X^3 + 2*X + 1
> Fq;
30*X^10 + 18*X^9 + 20*X^8 + 22*X^7 + 16*X^6 + 15*X^5 + 4*X^4 + 16*X^3 + 6*X^2 +
9*X + 5
> R!Rp!(f*Fp mod (X^N - 1));
1
> R!Rq!(f*Fq mod (X^N - 1));
1
> h := R!Rq!(p*Fq*g mod (X^N - 1));
> h;
16*X^10 + 19*X^9 + 12*X^8 + 19*X^7 + 15*X^6 + 24*X^5 + 12*X^4 + 20*X^3 + 22*X^2
+ 25*X + 8
> m := -1+X^3-X^4-X^8+X^9+X^10;
> r := -1+X^2+X^3+X^4-X^5-X^7;
> e := R!Rq!((r*h + m) mod (X^N - 1));
> e;
19*X^10 + 6*X^9 + 25*X^8 + 7*X^7 + 30*X^6 + 16*X^5 + 14*X^4 + 24*X^3 + 26*X^2 +
11*X + 14
Decryption will require adjusting polynomials so that the coefficients are between −p/2 and +p/2
or −q/2 and +q/2. The following function performs the adjustment.
function AdjustPolynomial( R, a, q )
coeffs := Eltseq( a );
qdiv2 := q div 2;
for i in [1..#coeffs] do
if coeffs[i] gt qdiv2 then
coeffs[i] -:= q;
end if;
end for;
return R!coeffs;
end function;
Finally we can perform the decryption steps and verify that the solution is correct.
> a;
-7*X^10 - 3*X^9 + 5*X^8 + 7*X^7 + 6*X^6 + 7*X^5 + 10*X^4 - 11*X^3 - 10*X^2 - 7*X
+ 3
> b := AdjustPolynomial( R, R!Rp!a, p);
> c := AdjustPolynomial( R, R!Rp!(Fp*b mod (X^N - 1)), p);
> c;
X^10 + X^9 - X^8 - X^4 + X^3 - 1
> c eq m;
true
In the paper “New Observations on Rijndael” by Sean Murphy and Matt Robshaw, several unusual
properties of the block cipher Rijndael (Advanced Encryption Standard candidate finalist) are
identified. In particular, they show that the constant c which is added on to each byte can be
relocated into the key schedule, and then the linear diffusion layer that remains can be represented
by a 128 by 128 bit matrix. A very surprising property of this matrix is that it has exponent 16.
In other words, any 128-bit input vector is mapped to itself after at most 16 iterations of the linear
diffusion layer.
Below we outline Magma computations which verify the correctness of their observations. To do
this, we create matrices which correspond to ByteSub, ShiftRow, and MixColumn transformations
of Rijndael. Upon multiplying the three matrices together, we get the same linear diffusion
matrix that Murphy and Robshaw obtained. We finish by computing the minimal polynomial and
verifying that it is a divisor of x16 + 1 in GF(2) [x].
When building the matrices corresponding to the three transformations, it will sometimes be
convenient for us to first work at the byte level, and then using the byte level matrices to build
the corresponding bit level matrices. An input byte matrix of the form
a11 a12 a13 a14
a21 a22 a23 a24
a31 a32 a33 a34
a41 a42 a43 a44
[a11 , a21 , a31 , a41 , a12 , a22 , a32 , a42 , a13 , a23 , a33 , a43 , a14 , a24 , a34 , a44 ] .
At the bit level, we expand the above vector so that each byte is replaced by 8 bits with the most
significant bits coming first.
Let us begin with the ByteSub transform. It is straightfoward to create the 8 by 8 matrix which
performs the byte substitution. That matrix is given in the Rijndael specifications.
> seq := [
> 1,1,1,1,1,0,0,0,
> 0,1,1,1,1,1,0,0,
> 0,0,1,1,1,1,1,0,
> 0,0,0,1,1,1,1,1,
> 1,0,0,0,1,1,1,1,
> 1,1,0,0,0,1,1,1,
33.2. RIJNDAEL’S LINEAR DIFFUSION MATRIX 231
> 1,1,1,0,0,0,1,1,
> 1,1,1,1,0,0,0,1
> ];
> L := Matrix(GF(2),8,8,seq);
To create the 128 by 128 bit matrix which acts as ByteSub on all 16 bytes, we can simply do:
We build the matrix corresponding to the ShiftRow transformation first at the byte level: the
matrix M will send the vector
[a11 , a21 , a31 , a41 , a12 , a22 , a32 , a42 , a13 , a23 , a33 , a43 , a14 , a24 , a34 , a44 ]
to
[a11 , a22 , a33 , a44 , a12 , a23 , a34 , a41 , a13 , a24 , a31 , a42 , a14 , a21 , a32 , a43 ] .
There are of course many ways to build this matrix within Magma. We choose to do it by
swapping rows of the identity matrix.
Creating the corresponding bit level matrix can be done by expanding this matrix out and inserting
the 8 by 8 identity wherever the 1’s are.
232 CHAPTER 33. MISCELLANEOUS
We now form the matrix which corresponds to first doing ByteSub and then ShiftRow:
The final step is the MixColumn transformation (refered to the matrix D in the Murphy/Robshaw
paper). MixColumn is a function which treats 4 bytes of data (one column of data of the state) as
an element of GF(28 ) [x], and multiplies this element by a fixed GF(28 ) polynomial c(x) modulo
x4 + 1. In Rijndael, GF(28 ) is represented by GF(2)[t]/m(t) where m(t) is t8 + t4 + t3 + t + 1. The
polynomial c(x) is (t + 1)x3 + x2 + x + t. Thus, we have to be able to multiply elements in GF(28 )
by only the following fixed polynomials: 1, t, t + 1 . We first create the matrices corresponding to
this mutliplication. Note that i8 (already created) corresponds to multiplying by 1.
Let us first create a 32 by 32 matrix which represents multiplying one column of the state by
c(x) mod x4 + 1. Recall from the Rijndael specifications that this is equivalent to multiplying the
an input column by the matrix
t t+1 1 1
1 t t+1 1
.
1 1 t t+1
t+1 1 1 t
By inserting the above 32 by 32 matrix in 4 positions along the diaganol of a 128 by 128 ma-
trix, we obatin the MixColumn matrix which corresponds to applying the finite field polynomial
multiplication to all four columns of the state.
We can now check that linear diffusion layer is the same matrix that Murphy and Robshaw
obtained. Due to space limitations, we do not print it out again here. The computations of the
minimal and characteristic polynomial are done below. It is clear that the exponent of the linear
diffusion layer matrix is 16 because the minimal polynomial m(x) times x + 1 is equal to x16 + 1.