Advantages to learning Sage?

This answer is something of a counterpoint to Samuel's enthusiastic answer. In short (and to directly answer your question), I would say that you are much better off just using Python (or other constituent programs) directly. Exactly which of these you might use depends very much on what you want to do.

While Sage relies on Python, it is not a simple Python library. It is a monolithic amalgam of many open source, mathematical tools. The tools are supposedly integrated via a single language but, in reality, the parts don't generally fit together very well. Here's a simple example that you can try on CoCalc or a SageCellServer:

n, t = var('n,t')
integrate(t^n, t)

Any reasonable computer algebra system should be able to deal with this problem. Sage simply returns a long string of errors. To be fair, there is a workaround: simply execute the command assume(n!=-1) before executing the integrate command. (Or, I guess, one could execute assume(n == -1) first; it's hard to say.) But this step is not necessary in maxima, the (very good) computer algebra system that Sage punts to for integrate and many other algebraic tasks. Thus, this example illustrates an important point: The various tools incorporated into Sage are tied together very poorly. As a result, we might say that Sage is much less than the sum of it's parts. Thus one wonders, why not just use the parts that one needs?

Again, you ask specifically about the use of Python and it sounds like you've already got a Python program to do exactly the kind of thing that it's good for. So, why mess with Sage? You're not going to use Sage's Python to execute your program - you'll probably use your system Python or some other (more manageable) Python distribution. Furthermore, there's a huge scientific ecosystem surrounding Python that's developed a large number of great mathematical libraries. Use what you need.

In fairness, there is quite a bit of mathematical code that's been developed specifically for Sage, particularly in number theory. If you happen to need exactly that stuff, then go for it. Also, the Sage group has been an important force in the open source movement for mathematical software. I'm fairly certain their server based notebook inspired the notebook we see in Jupyter now, for example. Having said that and admitting that I love to tinker with open source software, I really think that the advantage that open source software supposedly has in mathematics over closed source software is quite overblown.

Whatever you do, first and foremost - have fun with the math and the code!


Here are some advantages of Sage (also known as SageMath) relevant to your question.

Sage supports all fields of mathematics, including those you mentioned (groups, finite fields, combinatorics, permutation groups, linear algebra over finite fields, linear programming, integer programming).

Sage relies on Python.

  • it is a widespread, well-designed programming language;
  • learning it is useful beyond Sage;
  • you get all the strength of Python;
  • you can easily install and use lots of Python libraries.

Sage also lets you use Cython to speed up Python code.

Sage packages and uses a lot of free open-source packages and libraries.

Sage also has interfaces to non-free software, so that you can interact with Magma for instance, if you already have lots of Magma code.

In the long run using Sage directly and becoming independent of Magma could be a greater gain for you.

One big advantage of Sage for mathematics is its being open-source, so that

  • everything it does can be tracked and checked;
  • any bug you encounter can be documented and fixed;
  • you can share any code you write with others;
  • people you share your code with are likely to actually use it because they can freely install Sage;
  • you can contribute code to Sage.

Standards for proofs in mathematics are that one should be able to understand every step of the proof. For the computational parts, this is only possible with open-source software.

Sage has a friendly community of users and developers. User support and development discussion happens openly on the ask-sage forum and on public mailing lists such as sage-support and sage-devel. You can ask there when you encounter a difficulty, or if you find that Sage is slower than other software for certain computations.

Sage does linear programming and integer programming, with support for several libraries, including CBC, CPLEX, CVXOPT, GLPK, GUROBI, PPL. See linear programming documentation, integer programming documentation, this page by Nathann Cohen, and you can find more example code by searching the web.