What is the difference between SymPy and Sage?

18,300

(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.

Share:
18,300

Related videos on Youtube

Faouzi FJTech
Author by

Faouzi FJTech

Updated on April 19, 2020

Comments

  • Faouzi FJTech
    Faouzi FJTech about 4 years

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

    • Krastanov
      Krastanov almost 11 years
      This question will probably get closed (SO policy), but for what is worth: Sage is gigantic mixture of glued together programs and is great for serious mathematicians that need access to many tools that would be considered arcane academic magic by engineers that just need an integral or an equation to be solved without understanding the math. On the other hand, if you are not a mathematician or if you are a mathematician that needs a small and lean tool for experiments you will find SymPy quite nice. Frankly the only way to do justice to both projects is to spend a week learning each.
    • Ali
      Ali almost 11 years
      @Krastanov As an engineer, I resent your statement "engineers that just need an integral or an equation to be solved without understanding the math."
    • DSM
      DSM almost 11 years
      @Ali: could this be a language issue? In English, saying ".. that would be X by Y [that/which] just need Z" does not mean that there are no Y who may have other needs. Unless you're suggesting that every engineer understands, or needs to understand, every math tool used to the level of a professional mathematician. [This is getting borderline off-topic-- the only relevance is that Krastanov is right that one's needs will determine the appropriate tool.]
    • asmeurer
      asmeurer almost 11 years
      I'll write up a full answer later, but for now, read docs.sympy.org/0.7.3/tutorial/intro.html#why-sympy.
    • asmeurer
      asmeurer almost 11 years
      Yes, unfortunately, due to SO policy, if you ask a question like "Is SymPy better than Sage?" it will get closed, but if you ask "What is the difference between SymPy and Sage?" it will remain open.
    • Faouzi FJTech
      Faouzi FJTech almost 11 years
      Thanks Guys, I changed the title, the link by @asmeurer is really good thanks for it, now we need one from a neutral point of view, of course this one was written by sympa, so it still needs some reviews.
    • asmeurer
      asmeurer almost 11 years
      I tried to be as neutral as possible in my answer, but I am biased (and also, probably more importantly, I know perhaps too little about some of the specifics of Sage to give it a fair bout). But hey, that's what SO is for. Let other people answer as well.
    • asmeurer
      asmeurer almost 11 years
      By the way, if you do want specifics about certain mathematical capabilities, you should mention which things you care about.
    • Krastanov
      Krastanov almost 11 years
      @Ali, the majority of engineers care about calculus, not about topological invariants, Riemannian geometry or knot theory. I am not saying that one is easier than the other (which you seem to have assumed), rather that the math that most engineers use is very different from the math used by research mathematicians, and this is important to take into account when choosing between Sage/Magma or SymPy/Maple/Mathematica. Obviously such a generalization has its exceptions.
    • Geremia
      Geremia almost 7 years
  • Faouzi FJTech
    Faouzi FJTech almost 11 years
    Thanks alot @asmeurer , I wanna tell you that you did an excellent job with sympy, I spent the last 24 hours trying to discover some of its features. From what you described, including the BSD license, it would be the best choice for me. Actually I will need it to make a physics problem solver, so I would need pretty much everything from algebra to calculus. But the most important feature I'm looking for is a feautre that could solve for unknowns in equations : For example I have : x = a/b Can it solve for b and give : b = a/x ?
  • Faouzi FJTech
    Faouzi FJTech almost 11 years
    Nevermind, Got it, the solve module does it perfectly, thanks for coming up with such a great project !
  • asmeurer
    asmeurer almost 11 years
    SymPy was not written by me. I'm just the lead developer. There are over 200 people who have contributed to make SymPy what it is.
  • Faouzi FJTech
    Faouzi FJTech almost 11 years
    Thanks to all people contributing to it, its really some great project, people like you guys are making our lives so much easier, and make us build up on such great projects to make incredible ones.
  • asmeurer
    asmeurer almost 11 years
    I completely forgot that we have a writeup of the difference between SymPy and Sage on the SymPy wiki: github.com/sympy/sympy/wiki/SymPy-vs.-Sage. There are also pages for SymPy vs. other CASs there too.
  • Matthew
    Matthew about 10 years
    Sage does not define variables automatically. x is defined as a variable on startup; if you want to use y or z, you have to use y, z = var('y, z'). If you don't, you get a NameError. Sympy is not the default algorithm for integration in Sage, but using the keyword argument algorithm = 'sympy' forces it to use sympy. Another minor point for Sympy: it has an ascii-art pretty printer for rendering symbolic equations. I've imported Sympy into Sage's command line many times just for this feature.
  • Stefan Smith
    Stefan Smith almost 10 years
    @asmeurer : are these differences also valid: (i) Sage doesn't have a real Windows version; one must use it in a VirtualBox, manage files using unix commands, and jump through a few hoops to transfer files between the VirtualBox and one's Windows directories/Dropbox/e-mail/etc. SymPy, like Python, is not so unfriendly to Windows users; (ii) Using SymPy, one can see results output on the screen in "pretty" math symbols as in Maple, for example (SymPy uses LaTeX to do this), but in Sage one can't (?).
  • asmeurer
    asmeurer almost 10 years
    That's a good point. SymPy can be run anywhere that Python can. You can even run it on your phone.
  • jjcale
    jjcale over 7 years
    Is it possible to translate the sage-code of Peter Mueller in mathoverflow.net/questions/259197/… to SymPy ?
  • asmeurer
    asmeurer over 7 years
    @jjcale it looks like it should work. As far as I can tell it is only using basic polynomial manipulations. It straightforward to do the same thing with sympy.Poly.