Hacker News new | past | comments | ask | show | jobs | submit login
SymPy - Python library for symbolic mathematics (sympy.org)
105 points by gregnavis on Sept 1, 2012 | hide | past | favorite | 24 comments



This would be useful for teaching math or prototyping. From their FAQ it sounds like performance is way too slow for problems where speed is an issue.

If you're looking for a fast symbolic math library for python, check out Theano. On CPU, it can take advantage of whatever BLAS you use, and on GPU, it will convert your code to optimized C++ and compile via nvidia's cuda sdk.

SymPy does seem a lot more feature rich than theano, which relies on numpy


Looking at Theano, they seem pretty different.

Theano seems to be a beefed-up numpy (with compilation, symbolic differentiation, stability, and GPU use), while Sympy is a CAS framework.

That said, Theano looks really really really cool.

I wish I'd seen Theano before trying to force Sympy to do pretty much what Theano does (through Sympy's codegen).


Theano has an interesting description of the lay of the land as they see it, where they position themselves as a hybrid of numpy/MATLAB type numerical-computational tools and sympy/Mathematica-style CAS tools: http://deeplearning.net/software/theano/introduction.html#wh...


From the link, they mention this:

The closest Python package to Theano is sympy. Theano focuses more on tensor expressions than Sympy, and has more machinery for compilation. Sympy has more sophisticated algebra rules and can handle a wider variety of mathematical operations (such as series, limits, and integrals).


Generally when I'm doing symbolic math, it's as a supplement to computation, not as a replacement. In such cases, speed doesn't matter so much.

To take a specific example, think about solving a set of differential equations. The Sundials suite provides an excellent, fast numerical implementation of the popular BDF algorithm. So why would you ever want to do a slower symbolic manipulation of the problem?

First, to get insight into how the BDF solver works when applied to a class of problems, you might express the problem symbolically, apply the algorithm symbolically, and play around with the resulting expressions. This might help you choose tolerances, decide how to express your problem (e.g., to avoid catastrophic roundoff errors), or design a new algorithm geared to your particular problem.

Second, you might use symbolic algebra to derive the Jacobian matrix of derivatives for your problem, then code that Jacobian up for Sundials to use during numerical solution. This would speed up the numerics by giving it a faster, more accurate way to find the Jacobian than doing so numerically.

In both cases, symbolic algebra is not used to find a particular numerical result, but to improve the use of numerical code for solving particular problems.


Really? I think you're getting things confused

"If you're looking for a fast symbolic math library" you are doing it wrong

In none of the symbolic math Sw I used speed was an issue. But rather, capabilities. (Maple, Mathcad). Of course speed is good when evaluating a numeric problem

If you're talking about numeric math, which is what Theano does, then you're right about it.


Maybe?

But doesn't most of the sw we're talking about do both? For example, you mentioned Maple, which says right on its website it does both: http://www.maplesoft.com/products/maple/features/feature_det... Theano also does both. But maybe I'm using the terminology wrong? Or maybe it doesn't matter?

Either way, Theano is fast and is similar to (but not exactly!) SymPy.


Yes, most do both.

Some are more geared towards Symbolic Math (like Maple), some others are focused on numeric computations and even if they do symbolic math are severely limited.

You're right, Theano does symbolic differentiations, but this looks like it's in support of its main purpose (multi-dimensional problems)

TL;DR: If you want to calculate a triple integral symbolically go for Maple (or maybe SymPy), if you want to calculate its value go for NumPy or Theano


Also check out Maxima [1], the GPL'ed version of the venerable computer algebra system DOE Macsyyma, which made the jump to PCs rather late and was therefore overtaken by Maple and Mathematica. Maxima is still under active development, has an community around it, and is available on Linux, Windows and Macs.

[1] http://maxima.sourceforge.net/


If you're going to mention Maxima, you should be aware that an actively developed open-source program collection called Sage (http://www.sagemath.org/) uses Maxima as well as many other open-source packages to create a rich mathematical environment that's becoming increasingly popular.

Sage uses Maxima internally to generate symbolic results, but Sage also has many other integrated math tools, and has a Web 2.0 interface -- a server-enabled front end.

My Sage tutorial: http://arachnoid.com/sage


This is cool. However, NumPy, SciPy, SymPy, Maxima and a whole lot of other tools are included in Sage, which is a competitor to Mathematica, Matlab, and Maple. It's free and open-source. You can try it here: http://www.sagenb.org


Mathics (http://www.mathics.org/) is a pretty useful online algebra system (with MathJax display) for symbolic computing à la Mathematica, backed by SymPy for most tasks and Sage for advanced stuff. You can check gallery and docs at http://www.mathics.net/


and the guy who does that seems interesting and relying: http://www.poeschko.com/


sympy online interpreter : http://pythonsympy.appspot.com/


SymPy is great. I've used it and read through the code (available open source). Also, my online calculator Encalc.com uses SymPy on the backend. For example: http://www.encalc.com/#expr=integrate(sin(x))


Looks like the link cut off the closing parentheses.


This seems to be a ery cool and useful project. Code generation is a killer feature for me.

Also check out the Sympy Live Shell: http://docs.sympy.org/dev/modules/utilities/codegen.html


See also, OpenOpt and the FuncDesigner package.

http://openopt.org/Welcome


Looks like powerful numeric software but the site is so astoundingly bad. It looks like a throwback to Geocities.


Site will be moved to new engine as soon as we will got possibilities to make it done.


This also is worth a try: http://live.sympy.org/


It would be amazing to have one for ruby, tho I'm definatly going to use this for calculus at uni.


I know of two very early stage systems in ruby: https://github.com/jdleesmiller/rucas (which I wrote) and http://brainopia.github.com/symbolic/

I don't think either is really very useful at this stage (certainly mine isn't), but ruby does provide some very nice metaprogramming support for encoding and manipulating symbolic expressions.


Does your university not provide Mathematica? If not, I highly recommend purchasing Mathematica for students. I love open source software and particularly Python (yet I haven't tried Sage yet...), but Mathematica just strikes me as one of the "great pieces of software" with the likes of emacs, the Linux kernel, and etc.




Consider applying for YC's Spring batch! Applications are open till Feb 11.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: