Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.
Lecture 5 : Algebra
References:
Summary:
We start the lecture by recalling the useful sum
and prod
functions in Python, as well as more general iterators (in particular more fancy list comprehensions and tools for products of iterators). In the mathematical part, we begin by discussing (finite) groups and how to generate and identify them. Then we discuss polynomial rings and how to use them to study field extensions or ideals.
Python warmup : sum and prod
Two extremely useful constructions are the Python functions sum
and prod
for computing sums and products of elements in a list (or more general iterable). Here is the basic usage:
Combined with list comprehension:
We can in fact leave off the brackets above:
Apart from summing integers (or rational numbers, etc), we can in fact sum everything that has a +
operation. In some of these cases, we should specify by hand the "neutral element" that sum
should start with, which is given as a second argument (the default is the int 0
):
A more interesting application of this last point:
Exercise
The Euler-Mascheroni constant is defined as the limit
Compute its approximation for (alternatively: compute its first 4 digits) using the sum
function. Remark: If you are done early, try to find out if SageMath has this constant stored somewhere.
Solution (uncomment to see)
As you can imagine, the function prod
works much the same:
We can again take products of more general things. Here is an example: what do you think is the product of all elements in the symmetric group ?
The correct answer is: this depends on the order in which we multiply them! Just for fun, here is the set of all elements we can get like this (we'll see these constructions in more detail below and in the next lecture):
If you are interested in the question what elements you can get like this, have a look at the following answer to a question on math.stackexchange and the paper cited there.
Python warmup: more iterators
In this short section, we'll see a bunch of very useful constructions of iterators (used in for
-loops or the constructions of lists).
First is a more general version of list comprehension that we have seen before. As a reminder, here is the basic version:
More generally, we can have multiple for
in the list comprehension:
As you can see, the output is the list we would have obtained as follows:
In particular, the order of the for
-loops matters.
In addition we can have an if
-condition at the end of the list comprehension. Elements are only added to the list if this comprehension is satisfied:
Exercise
Create the list of
all integers between 100 and 200 satisfying
all entries of
Solution (uncomment to see)
In the exercise above, if we had wanted to compute the list , it would have required to write lots of for
statements by hand. Instead, we can use the function itertools.product
, which we need to import by hand as follows before using it:
The function product
takes iterables A, B, ...
and returns a generator that we would obtain from the code
Here is a first example:
Given a list N
of lists, the function product(*N)
essentially computes the cartesian product of these lists (hence the name):
Exercise
Consider the following list of integers:
A variant of the Subset sum problem asks: what are the ways of writing the number as a sum Find all such tuples.
Solution (uncomment to see)
Group theory
One of the fundamental objects in algebra are groups. These are abstractly defined as a tuple of a set and an operation satisfying certain axioms (associativity, existence of neutral and inverse elements).
While SageMath can work with some forms of infinite groups (in particular with finitely presented groups), we will mostly look at finite groups today. These are represented in SageMath as permutation groups, i.e. subgroups of some symmetric group generated by some elements.
The full symmetric group is created as follows:
Let's look at a random element of :
We see that it is represented in cycle notation. E.g. the element is the permutation sending If we want to create this particular element, this works as follows:
Alternatively, we use the following:
Now we can multiply, invert or raise elements to some power in the groups :
¡Careful!
In SageMath, the convention is that given permutations a,b
, the permutation a*b
is the permutation obtained by first applying a
and then applying b
. This is different from the standard notation standing for first applying and then . It leads to strange things as follows:
I must say that I find this a bit strange, but for many operations (computing inverses, subgroups generated by a subset, etc) this order does not really matter. You should just think of the SymmetricGroup(n)
acting on the set from the right.
Of course we can also create more general finite groups, some of which are given by pre-defined functions:
The phrase as a permutation group
already indicates that the elements of these groups are specified by certain permutations, indicating that they are naturally seen as subgroups of some . We can see this in an example by iterating through the group to look at its elements:
In many cases, it's sufficient to just have a look at the generators of the group, which we can obtain as follows:
Apart from the specific groups mentioned above, we can also create a group ourselves by generating it inside a symmetric group by a list of permutations:
Looking at a picture of a -gon, we see that these two permutations correspond to a rotation and a reflection at the -axis:
Thus we expect (and can confirm) that the group generated by them is equal to the dihedral group with elements:
Let's use this to try identifying a concrete group:
Exercise
Here is a beautiful hand-drawn picture of a cube:
Find a list of rotations which generate all symmetries of this cube in .
Compute the subgroup of generated by the permutations these rotations induce on the corners of the cube.
Find out what group it is and verify your answer with the
is_isomorphic
function.
Solution (uncomment to see)
Of course SageMath also knows about subgroups, their properties (like being normal) and quotient groups.
We can also list all subgroups of (possibly up to conjugation):
Exercise
An element is called a derangement if the permutation of has no fixed point, i.e. if for all . Denote by the number of derangements in , so that is the probability that a random permutation has no fixed points. Make some experiments and guess a formula for the limit of as .
Hint: Maybe look at some examples of .
Suggested sub-exercises (uncomment to see)
Solution (uncomment to see)
We can also do some computations with group homomorphisms (though I would say this is less well-developed). To specify such a homomorphism from to , we need to specify the images of the generators of . Let's try to construct a homomorphisms from to the cyclic group of order :
I claim that there exists a homomorphism sending to the neutral element, and sending to the element :
Now we can compute image and kernel of this morphism and verify the first isomorphism theorem:
Given a group homomorphism we have .
There are many more properties of groups and their elements which can be checked or computed using SageMath (e.g. whether a group is abelian or simple, the order of an element, etc). For most of these, you should be able to find them simply by guessing the name and using Tab
-completion, or by googling).
Finally, there are also libraries containing all isomorphism classes of groups of a given (small) order, in particular those of order at most 1023. This can be useful e.g. for checking a conjecture that you might have, or for trying to identify a given group. These libraries are implemented in the computer algebra system GAP, which SageMath uses in the background to do group theory computations.
When preparing this lecture, I found that there was not really a convenient way to access these databases, but based on this answer on math.stackexchange it is not so hard to write a function for this:
Exercise
The Feit-Thompson theorem states that every group of odd order is solvable. Check the theorem for orders at most 99.
Remark: A group is solvable if there exists a sequence of subgroups such that is normal in and such that the quotient is abelian for . However, you won't need to know this for solving the exercise ...
Solution (uncomment to see)
Just for fun, we finish with a nice picture: given a group with generating set , the Cayley graph of is the oriented graph which has one vertex for each element of the group, and an oriented edge from to for each .
For a fun application of group theory: this lecture explains how to solve a Rubik's cube using SageMath (in fact, the interface of SageMath to GAP).
Polynomial rings and field extensions
Given a base ring , we can create the polynomial ring over , where we can choose the variable names freely. Here is an example with the base ring :
Compared to symbolic expressions in the variables x,y
, the polynomials in S
have some additional functions (which don't make sense for general symbolic expressions):
Recall that an element of a ring is prime if and is not a unit and whenever divides for some then divides or divides .
Since is a unique factorization domain, an element which is not prime must be reducible:
The construction S.<x,y,...> = PolynomialRing(QQ)
automatically sets the variables x,y,...
to be generators of the new ring S
. We can also first create the ring abstractly, and then get our hands on the generators manually:
Exercise
Is the polynomial a prime element in
If not, specify a factorization.
Solution (uncomment to see)
Given a polynomial, we can get access to its coefficients as follows:
Using polynomials, we can now also play around with finite field extensions. Recall that given a field and an irreducible polynomial , the quotient is a field extension of of order .
Since in the ring we adjoined a root of the polynomial , it is no longer irreducible considered as an element of :
Exercise
Construct the following field extensions of : Check that and are Galois extensions (use Tab
-completion and the documentation via ?
to find the right commands). Also check that is not Galois. This is the classical example showing that it's not true that the composition of two Galois extensions is Galois.
Bonus exercise: Find an irreducible polynomial which has a root in but does not split as a product of linear factors.
Solution (uncomment to see)
Speaking of Galois extensions: we can of course also compute the Galois group of a field extension, and it naturally operates on elements of the larger field:
Finally, we can create ideals in polynomial rings:
In the background, SageMath computes a so-called Gröbner basis of the ideal . This is a particular set of generators of the ideal, such that there exist algorithms for answering questions like:
is a given element of the polynomial ring contained in the ideal,
are two ideals equal,
what is the intersection of two ideals, ...
In some cases, these can even be used to compute the solution set of a system of polynomial equations explicitly, in particular if this solution set is finite. Here is how we compute the solution set of the equations above, whose left-hand sides generate the ideal :
These are really interesting topics and algorithms, but since this lecture focuses primarily on applications, we will not go further into details here.
Assignments
Exercise
Compute the following:
the list of prime numbers between 100 and 200 which end in the digit '3'
the number of matrices in which are invertible
Solution (uncomment to see)
Exercise
For a subgroup of , denote by The numbers from the first exercise about derangements above are exactly . Last year, my friend Kaloyan Slavov (working at ETH Zurich) and Bjorn Poonen showed the following fun theorem.
Theorem (PS21)
If a subgroup satisfies , then .
Using clever arguments, they prove the theorem for , and for they use a computer program written in Magma. However, Magma is neither free nor open source! Show them that SageMath can also be used to prove their theorem for !
Hint: We already had an exercise about derangements above, so you might be able to recycle some of your code there!
Solution (uncomment to see)
Exercise
Compute the splitting field of the polynomial by iteratively adjoining roots of the polynomial to . What is the degree of the field extension ?
Solution (uncomment to see)