Live data from Hacker News

SymPy makes math fun again

wordsandbuttons.online

51–60 of 96 posts

Re: SymPy makes math fun again

#51
post #16

The fact that you have to declare every single variable makes it a non-starter for me. In Mathematica, I have written calculations that involve dozens of variables. In sympy that will be very annoying.

You can start a REPL with `isympy -I`, which is an IPython REPL but with some preprocessing magic that wraps any unknown variable into a sympy symbol and any integer into a sympy integer, which makes it closer to Mathematica: In [1]: 22/7*foobar Out[1]: 22⋅fo̅o ────── 7

This is totally great.

  In [1]: (foo + 1) ** 7                                                          
  Out[1]: 
           7
  (foo + 1) 
  
  In [2]: expand(_)                                                               
  Out[2]: 
     7        6         5         4         3         2            
  foo  + 7⋅foo  + 21⋅foo  + 35⋅foo  + 35⋅foo  + 21⋅foo  + 7⋅foo + 1
  
  In [3]: diff(_)                                                                 
  Out[3]: 
       6         5          4          3          2             
  7⋅foo  + 42⋅foo  + 105⋅foo  + 140⋅foo  + 105⋅foo  + 42⋅foo + 7
    
  In [4]: expand((cats+dogs)**5)                                                  
  Out[4]: 
      5         4               3     2          2     3              4       5
  cats  + 5⋅cats ⋅dogs + 10⋅cats ⋅dogs  + 10⋅cats ⋅dogs  + 5⋅cats⋅dogs  + dogs
  
  In [5]: hip + hip + hooray                                                      
  Out[5]: 2⋅hip + hooray

Re: SymPy makes math fun again

#52
post #50
post #12

Nice article. I totally agree about SymPy making math fun. I used Mathematica a lot in college, but stopped once it wasn’t free to me anymore. Here’s a blog post I made recently showing some fun SymPy calculations. https://www.swied.com/posts/make-a-ringtone-sound/make-a-rin...

Wolfram Engine + VS Code (notebook plugin), anyone?

Yes, this discussion sent me down a rabbit hole learning about the free (for non production use) Wolfram Engine, WolframScript, and Wolfram Language kernel for Jupyter!

Re: SymPy makes math fun again

#54

I like sagemath. They have integration with sympy, and they also have many features making python simpler when you want to do mathematical things. There's latex display feature when in notebook. It looks good, can even have symbolical matrices and display them as you would've expected. It's on par with Wolfram notebook, but you get to program in python instead of some propietary language. If you got some really long…

As someone who does research with computer algebra systems (mainly Wolfram Mathematica) many hours a day, I think that SymPy is still far behind Mathematica. The fundamental design of Mathematica based on replacement rules and a style of functional programming is quite difficult to beat in terms of ease of use. A few weeks ago I gave SymPy another try, and tried to implement a nested sum of the type 1 <= a_1 < ... <…

Wouldnt the following work in basic python:

  for a_k in 1 to n:
    for a_(k-1) in 1 to a_k:
    ....
I'm a heavy user of Mma but there are better examples. Automating the rewriting of formulas to make them more concise is a big one. (But also not as straightforward as it could be, tradeoffs between conciseness, ease of reading and speed of implementation need to be triaged, similar to Lisp/APL. Maybe sympy still has a chance to be more like math/TCS)

Re: SymPy makes math fun again

#56
What I like most about SymPy is how straightforwardly it maps onto how you actually do math by hand. The domain objects are things like variables, expressions, equations, and the operations are things like "differentiate", "set equal", "solve for X". It feels like it just automates the stuff I would already do: a bicycle for doing algebra.

Most other CASes seem to have a more "magic calculator" interface, where you plop down some crazy integral and it spits out a closed form. This is useful of course, but it has nothing really to do with doing math.

I'm sure both styles are possible in either one, that's just the spirit I feel like each one has.

Re: SymPy makes math fun again

#57

I like sagemath. They have integration with sympy, and they also have many features making python simpler when you want to do mathematical things. There's latex display feature when in notebook. It looks good, can even have symbolical matrices and display them as you would've expected. It's on par with Wolfram notebook, but you get to program in python instead of some propietary language. If you got some really long…

As someone who does research with computer algebra systems (mainly Wolfram Mathematica) many hours a day, I think that SymPy is still far behind Mathematica. The fundamental design of Mathematica based on replacement rules and a style of functional programming is quite difficult to beat in terms of ease of use. A few weeks ago I gave SymPy another try, and tried to implement a nested sum of the type 1 <= a_1 < ... <…

That's true, Mathematica is more advanced. But it's not cheap and it brings in a whole new world with it. You do have to learn to use it explicitly while with SymPy, you can start after a 5 minute introduction. I would say, Mathematica a good professional instrument while SymPy is a good hobbyist tool.

A note to a bypassing reader, if you want to try Mathematica, and not sure if you would stay with it, don't go for a desktop license. Get a Raspberry Pi instead. Mathematica comes free for Raspberry!

Re: SymPy makes math fun again

#58
post #14

The fact that you have to declare every single variable makes it a non-starter for me. In Mathematica, I have written calculations that involve dozens of variables. In sympy that will be very annoying.

Just write: a, b, c, d, f, g, h, i, j, k, l, m, n, p, q, r, s, t, u, v, w, x, y, z = var('a, b, c, d, f, g, h, i, j, k, l, m, n, p, q, r, s, t, u, v, w, x, y, z') At the top of your Jupyter notebook, right after your import lines, and copy and paste it everywhere else. It's really not a big deal! You can always redefine these variables to other things later, if you need to. Mathematica costs $387 for the "home deskto…

You can leave out the assignment, `var` already injects the variables into the local scope. IIRC, the commas are redundant.

Re: SymPy makes math fun again

#59
post #17

As a mathematician, the least fun I have is when interacting with a CAS. The degree to which one needs to do this tends to be field specific, but the tedium of calculations seen is most undergraduate courses is negligible.

In my experience, undergrad courses in theoretical physics can be extremely tedious, and a CAS can be quite helpful to double check your results.

Re: SymPy makes math fun again

#60

I like sagemath. They have integration with sympy, and they also have many features making python simpler when you want to do mathematical things. There's latex display feature when in notebook. It looks good, can even have symbolical matrices and display them as you would've expected. It's on par with Wolfram notebook, but you get to program in python instead of some propietary language. If you got some really long…

As someone who does research with computer algebra systems (mainly Wolfram Mathematica) many hours a day, I think that SymPy is still far behind Mathematica. The fundamental design of Mathematica based on replacement rules and a style of functional programming is quite difficult to beat in terms of ease of use. A few weeks ago I gave SymPy another try, and tried to implement a nested sum of the type 1 <= a_1 < ... <…

Do you have some reference on how to use the rewrite rules? I've meant to use them a few times but I've never seen a good tutorial or textbook.
Post reply on HN