In one of his travel books, Bill Bryson claims that he could spend every evening of his life arriving in a new city. In a similar spirit, I think I could spend a lot of time exploring new mathematics software systems. I have discussed Maxima and Axiom in the past, but a newer system, and one which is fighting with them for my allegiance, is Sage.
Sage (originally SAGE: Software for Algebraic and Geometric Exploration) is the brainchild of William Stein, a mathematician at the University of Washington. His idea was not to write a new CAS from scratch, but rather to take the best offerings from current CAS software, and put them all together in one package, adding new functionality as required. The beauty of this approach is that even though Sage is very young (the first 0.1 release dates back only to 2005) it already shows astonishing maturity and functionality. Sage claims to be “about building the car, not reinventing the wheel”.
There are many aspects of Sage which set it apart from other CAS’s:
- It is based around the robust language Python. Thus rather than learning a language specific to your CAS, all programming in Sage can be done in Python. So Sage can access all the Python mathematical libraries: numpy, scipy and the rest.
- Its notebook interface runs in a web browser, using a client-server mechanism. This means that the worry “does the software run on my system?” is moot; once a notebook server is up and running, it can be accessed by pretty much any modern web browser. (Sage can also run locally in a linux console).
- This means you don’t even have to download and install Sage to use it – a public server is available at http://www.sagenb.org; all you have to do is create an account for yourself, and away you go.
- Sage’s support for number theory and algebra is probably the best offered by any modern system: it has state-of-the-art algorithms (some provided by their developers) which means that in many cases it is faster than Maple or Mathematica.
- Sage includes, within it, other open-source systems such as Maxima, GAP, and Pari/GP, as well as specialized libraries such as LAPACK, GMP-ECM and LinBox. This means even if there is no “native” Sage method for performing a particular task, the task can be done by interfacing to one of the included systems.
- Sage also provides support for interfaces to commercial and non-free systems such as Maple, Mathematica, Matlab, Magma. So if you have access to these systems, you can use them from within Sage.
- Sage’s support for cryptography is excellent – all the number theory you could want, as well as solid support for computations with finite fields and elliptic curves. There are even packages for classical cryptosystems such as the Vigenère or Hill systems.
So, why use Sage, when there are other respectable and venerable systems out there? Well, here are a few reasons:
- Python – see my first point above. This has the added advantage that if you use Sage for teaching, then your students are likely to pick up a smattering of Python, a language which they may well meet again.
- Open source. This is important for verifying mathematical correctness. If a proof depends on the results of computation, it is necessary that the computation be verified. But this can’t be done on a commercial system, because the source code can’t be examined.
- Ease of access – see points 2 and 3 above.
- Sage provides an object oriented structure which is particularly useful for dealing with mathematical structures.
The relative youth of Sage means that there has not been a huge “pick-up” as yet. However, mathematicians and educators are beginning to sit up and take notice; one fine example is A First Course in Linear Algebra, by Robert Beezer, a free online textbook which makes extensive use of Sage. Other Sage-based texts can be seen at Sage Books.
So, what can Sage do? The best way of answering this is to poke about the Sage website and in particular the Feature Tour. But here are a few little examples (all in console mode, for ease):
sage: x=var('x') sage: p=diff(exp(x^2),x,10)*exp(-x^2) sage: p.simplify_exp() 1024 x^10 + 23040 x^8 + 161280 x^6 + 403200 x^4 + 302400 x^2 + 30240
- Linear Algebra:
sage: M=matrix([[1,2,3],[4,5,6],[7,8,10]]) sage: c=random_matrix(ZZ,3,1);c [ 7 ] [-2 ] [-2 ] sage: b=M*c sage: M^-1*b [ 7 ] [-2 ] [-2 ]
- Number theory:
sage: p=next_prime(randint(2^49,2^50));p 1022095718672689 sage: r=primitive_root(p);r 7 sage: pl=log(mod(10^15,p),r);pl 1004868498084144 sage: mod(r,p)^pl 1000000000000000
- Finite Fields:
sage: F.<x>=GF(2) sage: G.<a>=GF(2^4,name='a',modulus=x^4+x+1) sage: a^2/(a^2+1) a^3 + a sage: a^100 a^2 + a + 1 sage: log(a^2,a^3+1) 13 sage: (a^3+1)^13 a^2
It must be understood that these little examples are by no means representative of the power, depth and breadth of Sage. And being open source, you can always add to it or extend it yourself!