Sage (see http://sagemath.org) is a comprehensive mathematical software system for computations in many areas of pure and applied mathematics. We program Sage using the mainstream programming language Python (see http://python.org), or its compiled variant Cython. It is also very easy to efficiently use code written in C/C++ from Sage.
The author of this article started the Sage project in 2005.
Sage is free and open source, meaning you can change any part of Sage and redistribute the result without having to pay any license fees, and Sage can also leverage the power of commercial mathematical software such as Magma and Mathematica, if you happen to have access to those closed source commercial systems.
This document assumes no prior knowledge of either Python or Sage. Our goal is to help number theorists do computations involving number fields and modular forms using Sage.
TODO: Overview of Article
As you read this article, please try every example in Sage, and make sure things works as I claim, and do all of the exercises. Moreover, you should experiment by typing in similar examples and checking that the output you get agrees with what you expect.
To use Sage, install it on your computer, and use either the command line or start the Sage notebook by typing notebook() at the command line.
We show Sage sessions as follows:
sage: factor(123456)
2^6 * 3 * 643
This means that if you type factor(123456) as input to Sage, then you’ll get 2^6 * 3 * 643 as output. If you’re using the Sage command line, you type factor(123456) and press enter; if you’re using the Sage notebook via your web browser, you type factor(123456) into an input cell and press shift-enter; in the output cell you’ll see 2^6 * 3 * 643.
After trying the factor command in the previous paragraph (do this now!), you should try factoring some other numbers.
Note
What happens if you factor a negative number? a rational number?
You can also draw both 2d and 3d pictures using Sage. For example, the following input plots the number of prime divisors of each positive integer up to .
sage: line([(n, len(factor(n))) for n in [1..500]])
And, this example draws a similar 3d plot:
sage: v = [[len(factor(n*m)) for n in [1..15]] for m in [1..15]]
sage: list_plot3d(v, interpolation_type='nn')