Everything I do regularly in Mathematica can be done in Python. Even though Mathematica has a mind-boggling amount of functionality, I only use a tiny proportion of it. I skimmed through some of my Mathematica files to see what functions I use and then looked for Python counterparts. I found I use less of Mathematica than I imagined.

The core mathematical functions I need are in SciPy. The plotting features are in matplotlib. The SymPy library appears to have the symbolic functionality I need, though I’m as not sure about this one.

As I’ve blogged about before, I’d like to consolidate my tools. I started using Emacs again because I was frustrated with using a different editor for every kind of file. One of the things I find promising about Python is that I may be able to do more in Python and reduce the number of programming languages I use regularly.

**Update** (2017):

I wrote this post years ago when I was just starting to move to the Python stack. Since that time I have used Python as my default programming environment. The number and quality of Python libraries for applied mathematics has increased greatly over that time.

Python has numerous advantages over Mathematica. It is open source, and so it is more transparent. When something goes wrong, you can dig in and debug it. It is of course free, so you don’t have to buy software licenses, saving not only money but administrative hassle. And perhaps more importantly, *other people* that you want to share code with don’t have to buy licenses; you might find a Mathematica license a good investment for your company, but you can’t expect everyone you work with to necessarily come to the same conclusion.

The disadvantage to Python relative to Mathematica is that it is less consistent, less integrated. The Python stack for applied math—SciPy, NumPy, Pandas, Matplotlib, etc.—is better integrated than it used to be, but it still remains a collection of separate libraries.

If you’d like help moving from Mathematica to the Python stack, please call or email to discuss your particular company’s needs.

There is the little fact that these commercial tools (Mathematica, Maple, Matlab) tend to do some vendor lock-in. The more you invest in one particular tool, the more you have an incentive to continue. That’s a risky proposition on the long run.

I have promoted Python as an alternative to Matlab for a long time now. I had not realized we could use it as an alternative to Mathematica, but why not?

While it is slightly off-topic, Maxima is an excellent open source symbolic tool: http://maxima.sourceforge.net/

I have used Maxima, for serious work, in two research papers. Once in 2002 and once this year. I had maxima crunching polynomials for days a few months ago. It works well. It is not as smart as Mathematica or Maple, but good enough for my needs. There is a nice GUI which is very Maple-like.

Another open source symbolics package is GiNaC. This is actually a C++ library but there are Python bindings available via the PyGiNaC package.

Lets not forget Sage: a full-blown Python-based Computer Algebra System.

Daniel: I’ve felt the vendor lock-in. I’ve used Mathematica off and on for two decades. It’s a great piece of software. How could I ever learn something else as well? But it looks like it’s not as hard as I thought.

…and if you use Sage (http://www.sagemath.org) you get an amazingly powerful CAS which is based on Python, so all your Python knowledge gets carried across. Sage actually contains Maxima (as well as lots of other open-source mathematical software) within it.

Alasdair: I’ve heard good things about SAGE. However, you can’t install it on Windows, and I’ve heard people say you can hardly install it on Linux: the best thing is to download a virtual machine with SAGE installed.

When I looked briefly at Maxima, the syntax looked awkward compared to Mathematica. Maybe it’s just a matter of familiarity. I’m sure Maxima is quite powerful.

@Alasdair, you beat me to the punch. Additionally, though I haven’t used it, I know that you can access Mathematica from within Sage, if for some reason there were a Mathematica function you needed or preferred.

+1 for Sage. Though you need to run it in a VM on Windows, I’ve found it trivial to install on Ubuntu 9 and 10 as well as Mac OS X 10.6.

The nice thing about Mathematica is that it Just Works, and that all the tools from different fields are consolidated into one program, with consistent naming conventions. Not so for Python scientific tools; I wish they will move in this direction too.

If I understand correctly, Sage is trying to do it too, but I think that their disregard for normal, non-technical people is their big problem. I spoke to them and they pretty much said that they care mostly about Linux users because most of the developers of Sage are on Linux. I personally hate this attitude… There are so many scientists on Windows and in my opinion anyone who ignores Windows will end up in obscurity.

Lately I stopped using mathematica because of the vendor lockin and because mathematica took too much control of the problem solution. And replaced it with C++ and libraries usable from C++ for numerical work, for the symbolic part I realized that in general I needed it less that I though.

I see Sage has been mentioned. There is also the Enthought distribution of Python which is specifically aimed at computational science needs. A second option is the Python(x,y) distribution. It is a huge set of tools for Python (though you can customize it as needed) and comes with the Spyder terminal (used to be pydee). Spyder gives an interactive terminal much like MatLab.

I played around with Sage but it’s way too powerful for most everything I do. And I have never learned Python – I know Perl, R and Ruby.

I’ve used Maxima but found it hard to use until I got the wxMaxima GUI version. But for general numerical computing, I’m perfectly happy with R.

I really like NumPy/SciPy, etc. But regarding SymPy, are you sure it’s good enough? I know I looked at it some months ago and ruled it out for what I was trying to do (or maybe I just couldn’t do what I needed due to unfamiliarity).

I’ve compiled various versions of Sage on my Linux box over the years. It wasn’t at all difficult – however it does take hours to compile.

As for their disregard for Windows, perhaps they were careless in phrasing. They probably meant that their developers are Linux developers, and don’t know much about Windows. Likely they want a Windows version, but need developers familiar with Windows, and few/none have signed up. That’s a common problem with many open source projects (and it’s not their fault).

Also, knowing how Sage is built, it’d be a *major* challenge to get it running on Windows. It basically has custom versions of many large Linux projects within it. Some distributions don’t like it for that reason (redundancy). So to get it working on Windows, you have to port those other projects to Windows as well.

So, it’s been almost half a year, what’s the verdict?

Yaroslav: I still use Mathematica regularly, especially for symbolic computation. But I do use Python for more tasks than I used to.

I like that Mathematica’s syntax is very memorable. I can just fire it up and get down to business without having to look anything up. It’s convenient for quick calculations. If I needed to do extensive programming, I’d rather use Python.

For symbolic computation you might take a glance at Racket, which is a dialect of Lisp. (It grew out of a very mature implementation of Scheme.)

http://racket-lang.org/

As far as the syntax differences go, it really depends on how you used Mathematica. I tended to tackle problems from a functional perspective and so my Mathematica expressions were reminiscent of the Lisp style – the only differences being that function application looked like F[…] instead of (F …).

Hi, I just came across this posting of yours. I would like to ask a question about SymPy (perhaps you have more experience with it now?). Does SymPy, or Python itself, has the “patterns” feature of Mathematica? Certainly there are some “pattern” feature in Python. Moreover it can incorporate Perl codes in it. But how good is it compared to Mathematica?

I ask because I do not have the time yet to learn about Python (I mean, I can program in Python, but I have not learn NumPy and SymPy yet). If it is not better than Mathematica in this part, I would choose to stay with Mathematica.

Moreover, now Mathematica has built-in support of parallel and GPU computing interface. If you want to have complicated and fully optimized parallel/GPU programs, this is not enough. But this saves a huge amount of program developing time if the computation is straight forward.

Im trying to program a simple python GUI alternative to Euler Math Toolbox. The goal is to have a simple cell-based layout (like Mathematica/wxMaxima/Euler), and send raw input from the cells into Pythons scientific librarys , and print the result under the input cell.

It should have dedicated mathematical calculation-cells an text cells with LaTeX support.

I have tried to use Tkinter, but I only manage to make a simple text editor. Do you have any tips on how to proceed to get the Mathematica/Euler GUI?

I have been using Mathematica for a while not and just started using SymPy. Guess I am now where you were when you write this article. I find that the symbolic solvers like linsolve are extremely slow when compared to Mathematica’s Solve[] function no matter how much you try to speed it up. Did anyone else notice the same? Did you get around to finding a fix?

I don’t do much symbolic computing. I find SymPy much harder to use than Mathematica, but I don’t do symbolic computing often enough to justify buying a Mathematica license. (You can get Mathematica free on a Raspberry Pi, but only for personal use. I’d need a commercial license.)