The Complete Magazine on Open Source

Introduction to SageMath

, / 8990 0


Sage is wonderful open source software as it covers almost all areas of mathematics, with varying levels of sophistication. It has all the built-in objects and functions for expressing mathematical concepts and calculations. Besides a command line and programming library interface, it also has a dynamic self-hosted website.

Many of us are unaware of some of the best software that helps make our tasks easier. This article intends to introduce SageMath to open source users interested in mathematics, and also to beginners who wish to explore open source projects and contribute to them.
Here goes the mission statement of SageMath: “Create a viable, free, open source alternative to Magma, Maple, Mathematica and Matlab.”
SageMath is a free open source mathematics software system written in Python and Cython. It integrates over 90 open source mathematics software packages. William A. Stein is the lead developer of SageMath. It has a Web based graphical interface, and the user interface is a notebook in a Web browser or the command line. SageMath can be used in various areas of mathematics like basic algebra, linear algebra, numerical computation, graph theory, cryptography and much more. And since it is used in areas like Calculus, linear algebra, abstract algebra, etc, it is helpful in preparing curriculum for undergraduate students. Many standard textbooks for undergraduates include solutions to their exercises using Sage, which we can refer to in the following link:

Figure 1

Figure 1: Installation prerequisites

The first version of Sage was released on February 24, 2015. The present stable version is Sage 6.8.
To install Sage on Linux (Ubuntu/Debian), your system should have the C/C++ compiler, make, m4, Perl, ar and ranlib (which can be obtained as part of GNU binutils) and tar (Figure 1).
To install Sage, type:

sudo apt-get install gcc make m4 perl binutils tar

To download the source code for Sage, go to; you will see a list of mirrors. Select one and download it. This might take time. I downloaded the developer version. This is a tar file containing the source code for Sage.
We can also do this from the command line using the wget command, as shown below:

wget -c

You can select a download server of your convenience; I selected the one given above and hence downloaded sage-6.8.rc1.tar.gz.

Extracting the tar file
My tar file is of the .tar.gz format, so I used the following command to extract it:

tar -xvzf sage-6.8.rc1.tar.gz
cd sage-6.8.rc1

The ls command will list the files and folders inside the Sage directory. Please go through the README.txt for further information.

Figure 2

Figure 2: Files and folders inside Sage directory

Figure 3

Figure 3: Buiding Sage

The build process
You need to give the make command for the build process to happen; however, it does take some time.
When the build gets over, to start using Sage, type the following command from Sage’s home directory:


Figures 6 and 7 illustrate a few examples where Sage has been used to get solutions to mathematical problems.
You can use the Sage reference manual to look at more such examples.

Figure 4

Figure 4: Successful completion of Sage build

Figure 5

Figure 5: Constructing a matrix

SageMath can be used in research, teaching, to learn various courses, etc. Everyone can download and use it. You can take a demo from a class and publish it, so that students can look at it after the class. Mathematica has the ‘Player’ application but with SageMath, students can easily alter the demo for themselves — something that isn’t possible with the former. Since many users will be familiar with Python, Sage encourages students to discover bugs, and to try and fix them.
SageMath allows network transparency. For instance, if SageMath is running on a fast machine, you will get the benefit of that machine even while accessing Sage from somewhere else. Since Mathematica’s support for Linux is not very good, SageMath is a true open source alternative to it.

Figure 6

Figure 6: Drawing a unit circle with 0,0 as centre

Figure 7

Figure 7: Command

Contributing to Sage
Many people, including high school students, undergraduates, graduate students, mathematicians, scientists and software engineers contribute to the Sage project. Sage has a very welcoming developer community with a lot of options for contributing to it, like finding a bug and reporting it, fixing a bug, implementing a new function or creating a new class. If you are not familiar with programming, you can still contribute to Sage by writing technical tutorials for a mathematical topic, translating existing documentation to a new language, etc.
You can ask questions about contributing to Sage in its IRC channel #sagemath on and in its mailing lists (!forum/sage-devel).