Live data from Hacker News

SymPy: Symbolic Mathematics in Python

sympy.org

21–30 of 137 posts

Re: SymPy: Symbolic Mathematics in Python

#21
post #11

Working in the field of robotics, I often have to write big vectors ( usually computed as the result of 3D transformations ) and then compute their Jacobian ( their derivative with respect to several state-variables ), which quickly becomes very nasty equations. I use sympy to (i) compute these big vectors, expressed in a very declarative way, (ii) compute the jacobian and (iii) export the results in C-code, immediat…

Why are you calculating the Jacobian symbolically? AFAIK, for complex cases, the numerical Jacobian is often faster / more numerically stable.

Re: SymPy: Symbolic Mathematics in Python

#22
post #4

Sympy is amazing, but i kinda fail to see whats news about it as its oldest commit is 14 years ago.

Oldest commit was from today: https://github.com/sympy/sympy Where are you getting 14 years from?

That's the newest commit. The oldest commit on GitHub is from 2007: https://github.com/sympy/sympy/commit/99b21ff58ad2e2ba831725...

Re: SymPy: Symbolic Mathematics in Python

#23
post #7

Earlier quoted context omitted.

Stephen Wolfram notwithstanding, Mathematica is still far ahead of most alternatives as a CAS. Maple is good on some integrals. Their downsides are that their languages are not very well suited as general purpose languages, many times the algebraic manipulations you have to perform aren't that complicated and you'd rather work in a "real" language. Yet another case where python isn't the best in class but still worka…

"Python isn't the best tool for anything, but it's the second best tool for most things."

I thought the role of "second best tool for most things" belonged to Excel

Re: SymPy: Symbolic Mathematics in Python

#24
sympy works really well in jupyter. my own demo notebooks for sympy are

https://nbviewer.org/url/canonical.org/~kragen/sw/dev3/sympy... (solving a multivariate quadratic with math pretty-printing)

https://nbviewer.org/url/canonical.org/~kragen/sw/dev3/tiny-... (my cheatsheet of quick-and-dirty numpy/pylab plots, including some sympy examples)

https://nbviewer.org/url/canonical.org/~kragen/sw/dev3/secan... (using sympy to symbolically differentiate an existing python function, which is something you can't usually do, in order to find its minimum in closed form)

https://nbviewer.org/url/canonical.org/~kragen/sw/dev3/max-p... (some basic circuit analysis with basic calculus with sympy)

https://nbviewer.org/url/canonical.org/~kragen/sw/dev3/latex... (various fiddling around with mathjax formatting and sympy, including some analysis of minsky's circle algorithm from hakmem)

Re: SymPy: Symbolic Mathematics in Python

#25
post #10
post #7

Earlier quoted context omitted.

Stephen Wolfram notwithstanding, Mathematica is still far ahead of most alternatives as a CAS. Maple is good on some integrals. Their downsides are that their languages are not very well suited as general purpose languages, many times the algebraic manipulations you have to perform aren't that complicated and you'd rather work in a "real" language. Yet another case where python isn't the best in class but still worka…

Sagemath is a python library that has more capabilities than Mathematica. If you want to do real symbolic computation in python Sagemath is the only way to do it. That said sympy is quite a cool little library for learning.

Sagemath isn't a python library, it's a collection of packages (of which sympy is one) under a common interface. It is indeed what you would use if you wanted to do real symbolic computation in python, but it's not at the level of Mathematica or Maple.

Look, we all love open source, but we aren't doing anybody any favors by pretending the open source alternative is better when it isn't. I would encourage anyone whose needs are satisfied by sympy/sagemath to opt for the open alternative, but the question was whether or not Mathematica as of now, early 2024, is better. The unfortunate reality is that it is.

Re: SymPy: Symbolic Mathematics in Python

#26
post #21
post #11

Working in the field of robotics, I often have to write big vectors ( usually computed as the result of 3D transformations ) and then compute their Jacobian ( their derivative with respect to several state-variables ), which quickly becomes very nasty equations. I use sympy to (i) compute these big vectors, expressed in a very declarative way, (ii) compute the jacobian and (iii) export the results in C-code, immediat…

Why are you calculating the Jacobian symbolically? AFAIK, for complex cases, the numerical Jacobian is often faster / more numerically stable.

Well, the symbolic computation is only used to generate C code. The generated code then evaluates jacobians numerically. And we use several methods for numerical stability on top of that.

Re: SymPy: Symbolic Mathematics in Python

#29
post #25
post #10

Earlier quoted context omitted.

Sagemath is a python library that has more capabilities than Mathematica. If you want to do real symbolic computation in python Sagemath is the only way to do it. That said sympy is quite a cool little library for learning.

Sagemath isn't a python library, it's a collection of packages (of which sympy is one) under a common interface. It is indeed what you would use if you wanted to do real symbolic computation in python, but it's not at the level of Mathematica or Maple. Look, we all love open source, but we aren't doing anybody any favors by pretending the open source alternative is better when it isn't. I would encourage anyone whose…

I'm old enough to have had people tell me the same thing about the Linux kernel vs the Windows kernel.

I can do an import sage as the top of any python script.

It's a library.

And since I get all of python for free it's better than Mathematica.

Re: SymPy: Symbolic Mathematics in Python

#30
A decade ago when I was interested in General Relativity I wanted to write a simple program to handle symbolic calculations for Einstein field equations (Starting with metric and calculated affine connections, ricci tensor …etc.). Sympy was an option (better because python was the only language I know well) but I found it hard and actually couldn't make it work. I used mathematica which was new for me but did it in a couple of hours. I expanded it later and used it to calculate a lot of things in a black hole paper I published later.

I checked now, and it seems that on this front a lot of development in sympy made it possible that we know how very good libraries built on top of it [1] [2]. There is even now a Jupyter notebook example on schwarzschild metric [3].

[1] https://docs.einsteinpy.org

[2]https://github.com/spacetimeengineer/spacetimeengine

[3] https://github.com/sympy/sympy/blob/master/examples/intermed...

Post reply on HN