What is the difference between SymPy and Sage?

What is the difference between SymPy and Sage a.k.a. SageMath?


(Full disclosure: I am the lead developer of SymPy)

The first thing you should understand is that SymPy and Sage are not quite the same thing. SymPy is a pure Python library, that does computer algebra. Sage is a collection of open source mathematical software. Sage tries to gather together all the major open source mathematics software, and glue it together into a useful system. In fact, Sage includes SymPy as one of its systems.

Here is a short list of (biased) facts for each (I won't call them pros or cons, just facts):

SymPy

  • SymPy is completely standalone. It has no dependencies other than Python.
  • Despite being standalone, it is full featured as a computer algebra system. If you want to do numerics, you are encouraged to use other libraries in the scientific Python ecosystem.
  • SymPy is BSD licensed. For many people, this doesn't matter, but if you want to include SymPy in something else, it's nice to know that you can pretty much do whatever you want with the code.
  • SymPy does not try to change Python. SymPy takes the philosophy that Python is doing things well, so it should do things the Python way. For example, the operator for exponentiation is ** as it is in Python, not ^ as it is in many other systems.
  • SymPy can be used as a library. Since SymPy is just a Python module, you can just import it and use it in any place that uses Python. There are a lot of really cool apps and libraries out there that use SymPy in the background to do symbolics (in many cases, in places where you might not even realize that symbolics are being used).

Sage

  • Sage includes everything (including SymPy) from the open source world that you might want to do mathematics. This includes many libraries that are useful for numerics, like octave.
  • Sage is GPL. If you like the whole FSF software freedom shpel, then more power to you. You can't reuse the source code in your own application without licensing your application under the GPL as well.
  • Sage is hard to use as a library. On the other hand, it has a very nice notebook interface. If you want to do the same with SymPy, the recommended way is to use the IPython notebook and run from sympy import init_session; init_session() at the top (replace init_session with init_printing if you just want printing and not to import everything).
  • Sage includes a bit of a DSL on top of Python. For example, you can type 1/2 without wrapping the integer literals, and it will return a rational. x^2 gives x squared, not Xor(x, 2). I'm not sure if it automatically defines variables for you by default. This means that things that you do in an interactive Sage session might not translate directly to a Python script. On the other hand, this can be useful for interactive use (btw, SymPy also has isympy -I that does some similar things).

Maybe that's not what you were looking for. You probably wanted some actual mathematical features. But as I said, Sage includes SymPy, so by definition, every feature of SymPy will be a feature of Sage. In practice, this is not necessarily the case because Sage doesn't always use SymPy by default (I'm not sure what the current status of this is actually), so you may have to call to SymPy manually if you want to use it from within Sage.