Lecture 1: Welcome!

In this first lecture we define computer algebra and sketch the organization of the course. The most important aspect of this lecture is to get started with the notebook interface in SageMath.

We can run SageMath in a terminal window, in the cell server, in a notebook, or in the cloud. Our running computation involves the symbol pi which SageMath recognizes as the mathematical constant \(\pi\). The lecture ends with finding out which system performs a particular calculation.

What is Computer Algebra?

Computer Algebra is the discipline that studies the algorithms for Symbolic Computation. In Symbolic Computation, one computes with symbols, rather than with numbers. In this course we are mostly concerned with the practical aspects of Symbolic Computation, in particular its implementation and its application to solve practical mathematical problems.

The lecture notes are organized in four parts:

  1. First steps with SageMath

  2. Polynomials and rational expressions

  3. Functions and Calculus

  4. More Advanced SageMath

  5. Some Components of SageMath

What is SageMath?

The original name Sage was short for Software for Algebra, Geometry, and Experimentation. Later, SAGE became Sage and now we refer to SageMath. Below are some important points about SageMath:

  • SageMath is released as free and open source software under the terms of the GNU General Public License.

  • As scripting language, SageMath uses Python. SageMath has a large, active developers community.

  • By design, SageMath does not reinvent the wheel, but bundles various powerful free and open source mathematical software systems, such as GAP, Maxima, R, Singular, sympy, numpy, scipy, etc. This design principle is visualized in Fig. 1. The figure is copied from [BS10].


    Fig. 1 The motto of SageMath: building the car instead of reinventing the wheel.

  • Try it without installing, via the SageMath Cell Server: https://sagecell.sagemath.org/, or with CoCalc: https://cocalc.com.

Running SageMath

There are two main modes to run SageMath:

  • In a terminal window, which is similar as using the command line interface to interactive software systems. This works fine for short calculations, when the right commands are knows in advance.

  • The notebook interface runs in a web browser. The help gives direct access to the reference manual and other documentation. The notebook interface is natural with cloud computing.

A terminal session with SageMath

sage: pi
sage: sin(pi)
sage: '%.14e' % pi
sage: type(_)
<type 'str'>
sage: type(pi)
<type 'sage.symbolic.expression.Expression'>
sage: p = plot(sin,(-pi,+pi))
sage: p

For a more interesting plot, consider the sine function with a decaying amplitude, as defined by exp(-x^2)*sin(8*x).

As a computer algebra system, Sage is mainly for symbolic computation. For its numerical computations, we are not limited to the hardware machine arithmetic. For example, to see the decimal expansion of \(\pi\) with 20 decimal places:

sage: pi20 = pi.n(digits=20)
sage: pi20
sage: sin(pi20)
sage: type(pi20)
<type 'sage.rings.real_mpfr.RealNumber'>

Unlike the exact value for \(\pi\), the value of sin(pi20) is no longer zero.

In the SageMath Cell Server to plot the sine function, we can enter:

plot(sin(x), (-pi, pi)).show()

When running the notebook interface, we can document our computations with text that follows the # symbol.

Which systems in SageMath are used?

Sage is built out of several systems. If you are curious to see which software package executed your calculation, you could proceed as follows:

sage: from sage.misc.citation import get_systems
sage: get_systems('Rational(0.75)')
sage: get_systems('RealField(10)(pi)')
['MPFR', 'ginac']
sage: import sage.misc.citation
sage: help(sage.misc.citation)
sage: sage.misc.citation.systems.keys()


  1. Go to http://www.sagemath.org/tour.html and take the Feature tour.

    After taking this tour, write a couple of sentences (one paragraph long) about what interests you most.

  2. Create an account on CoCalc, at https://cocalc.com, and make a notebook with calculations from this lecture.

  3. If there is sufficient disk space available on your home computer or laptop, consider installing SageMath from source. On Linux systems, you should not do this installation as root, but as an ordinary user.

  4. Which system executes the statement pi.n(digits=20)?



B. Erocal and W. Stein: The Sage project: Unifying free mathematical software to create a viable alternative to Magma, Maple, Mathematica, and MATLAB. In Mathematical Software - ICMS 2010, Springer-Verlag, 2010.