Live data from Hacker News

SymPy: Symbolic Mathematics in Python

sympy.org

41–50 of 137 posts

Re: SymPy: Symbolic Mathematics in Python

#41
As an aside - I have a bunch of logical expressions and I need to see if they are mutually exclusive. As in, if one is true given some combination of the variables, none of the other expressions must be true for the same combination.

For example Country="US" and Type="Sales" is not exclusive with Type in ("Sales", "Purchase")

What would be an approach to solving this?

Re: SymPy: Symbolic Mathematics in Python

#43
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…

I've used SymPy in a very similar way, in my case it was some nasty derivatives that were needed for some orbital mechanics calculations.

First write down the equations, then let SymPy do the laborious math part and turn the output into C code.

I'm guessing this is why you don't see a lot of SymPy projects in the wild. It was used for some intermediate calculations, and the results were turned into the product's code and the symbolic code is thrown away.

Re: SymPy: Symbolic Mathematics in Python

#44

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…

You should check out Sage Manifolds [1]. It's built on top of Sage Math, but I think it can also use SymPy as computational engine.

[1] https://sagemanifolds.obspm.fr/

Re: SymPy: Symbolic Mathematics in Python

#46

There is a benchmark of Sympy vs Mathematica at https://www.12000.org/my_notes/CAS_integration_tests/reports... The results were Mathematica failed to solve 1,523 problems, Sympy failed to solve 48,529. So it has some catching up to do.

Do you know why there's such a big difference ? For example, is the way sympy does its job fundamentally flawed ?

Re: SymPy: Symbolic Mathematics in Python

#47
post #18

Is there any GUI for SymPy one could easily use to solve symbolic math like Maple/Maxima/Macsyma?

Not sure what you mean with GUI, but you can use it with Jupyter notebooks.

More like writing/clicking math (like in MS Word or some LaTeX editors) that is then converted to SymPy instead of writing stuff in Python directly.

Re: SymPy: Symbolic Mathematics in Python

#48
post #46

There is a benchmark of Sympy vs Mathematica at https://www.12000.org/my_notes/CAS_integration_tests/reports... The results were Mathematica failed to solve 1,523 problems, Sympy failed to solve 48,529. So it has some catching up to do.

Do you know why there's such a big difference ? For example, is the way sympy does its job fundamentally flawed ?

I doubt there's any sort of fundamental flaw in sympy. Getting more and more solutions is mostly about putting in lots of work to tweak the bag of tricks. There is no universal algorithm for solving integrals.

As an open source project depending on volunteers (or is it just the one major author?) I am impressed that sympy does as much as it does.

Re: SymPy: Symbolic Mathematics in Python

#49

SymPy is awesome indeed! I've been using it as a teaching tool for many years. IMHO, it's the best option as compared to Mathematica/Maple/etc. because the API functions match exactly the verbs students use when learning math (solve, expand, factor, etc.). Here is a little tutorial for anyone looking to get started: https://minireference.com/static/tutorials/sympy_tutorial.pd... Also available in runnable notebook fo…

The biggest drawback of SymPy is the need to pre-define all your symbols. That makes it more difficult to handle scenarios where you're taking formulas as input because you either need to parse the equation yourself to figure out what variables were used, or have the user manually supply the symbols.

Re: SymPy: Symbolic Mathematics in Python

#50

As an aside - I have a bunch of logical expressions and I need to see if they are mutually exclusive. As in, if one is true given some combination of the variables, none of the other expressions must be true for the same combination. For example Country="US" and Type="Sales" is not exclusive with Type in ("Sales", "Purchase") What would be an approach to solving this?

Maybe prolog (or other logic programming language) or z3 (or other SAT solver)?
Post reply on HN