Live data from Hacker News

Doing Symbolic Math with SymPy

lwn.net

31–40 of 81 posts

Re: Doing Symbolic Math with SymPy

#31

Earlier quoted context omitted.

Let's not pretend math notation has remained constant for millennia.

Exactly, it has been refined over millennia.

Right, and it's important to remember that mathematics is sharply optimized for human understanding, whereas programming languages strike a careful compromise between human understanding and efficient execution by machines. I don't think anyone could seriously argue that programming languages are "more expressive" than mathematical notation, which has the powers of ambiguity and hand-drawn graphics.

Re: Doing Symbolic Math with SymPy

#32
Worth noting that Julia's SymPy binding [1] is pretty pretty nice to work with too. If anyone's looking for big Julia project, I think a symbolic math package written fully in Julia would be a really exciting development. As far as I know, there isn't one yet. The better-known symbolic math packages for Julia still use bindings to C++ (SymEngine.jl [2]) or Python (SymPy.jl, Symata.jl [3]).

[1] - https://github.com/JuliaPy/SymPy.jl

[2] - https://github.com/symengine/SymEngine.jl

[3] - https://github.com/jlapeyre/Symata.jl

Re: Doing Symbolic Math with SymPy

#33

Earlier quoted context omitted.

It runs on a google colab tab that you can spin up pressing "ctrl-T" in any available computer.

Sure, but if you want fast easy math, it's hard to beat wolfram alpha, where you can just enter something like "solve x^2+5a=y for x" and get the answer right away.

It's really not. WA is good at getting natural language questions but gives you next to no control on the outputs.

Last time I used sympy I had a complicated function on many variables and wanted to plot certain specific 2D contours. I was distant from any computer with numerical/programming tools and needed to add them to a PPT deck last minute.

Re: Doing Symbolic Math with SymPy

#34

Worth noting that Julia's SymPy binding [1] is pretty pretty nice to work with too. If anyone's looking for big Julia project, I think a symbolic math package written fully in Julia would be a really exciting development. As far as I know, there isn't one yet. The better-known symbolic math packages for Julia still use bindings to C++ (SymEngine.jl [2]) or Python (SymPy.jl, Symata.jl [3]). [1] - https://github.com/Ju…

ModelingToolkit.jl is a symbolic math package written fully in Julia (with a bunch of extra symbolic-numerics features)

https://github.com/SciML/ModelingToolkit.jl

https://mtk.sciml.ai/dev/tutorials/symbolic_functions/

It's more like SymEngine in terms of completeness right now, though there's a good amount of simplification and equation solving built in. It's still growing, it's not at SymPy yet, but it's moving fast.

Re: Doing Symbolic Math with SymPy

#35
+100 this; SymPy is the best!

One of the coolest things about SymPy is the Live Shell, that let's you try basic calculations (without plotting) in the browser: https://live.sympy.org

There is even an option to send the entire session encoded as URL querystring which makes it tweetable, emailable, etc. e.g. https://live.sympy.org/?evaluate=factor(x**2%2B5*x%2B6)%0A%2... (to generate the session-as-querystring for your current live.sympy.org session, use the thumbtack button below the prompt)

I use this very often to send calculations and solutions—not only do you get the answer, but you see all the calculations.

Re: Doing Symbolic Math with SymPy

#36
I'd like to give an alternative perspective on SymPy. Whilst I'm not familiar with Mathematica, and therefore cannot draw parallels between the two, I've used SymPy for a number of years and found it to be really useful. I was initially introduced to it as part of a first year programming module in a Physics degree, and it was more than sufficient for that use-case; for that use-case, it absolutely wasn't worth paying for something like Mathematica. When combined with a graphical REPL (some may use Spyder, I personally use jupyter-qtconsole) or a Jupyter Notebook, it becomes really quite useful as it incorporates LaTeX rendering to make its outputs more readable and a little less daunting. Whilst the syntax may not be optimal for the mathematical way of working, for many problems like simple rearrangements, automatic simplification, checking equivalences, etc. it is almost always the first tool I reach for. The syntax is just cosmetic, and I use Python enough that the syntax doesn't even bother me, either. It does its job well, and it's helped me solve and verify solutions for a number of mathematical problems during my degree. Admittedly, I do run into the occasional problem here and there where there are obviously better tools available, but that's the same with any gratis vs paid solution. In most cases, SymPy does a sufficiently good job.

Re: Doing Symbolic Math with SymPy

#37

+100 this; SymPy is the best! One of the coolest things about SymPy is the Live Shell, that let's you try basic calculations (without plotting) in the browser: https://live.sympy.org There is even an option to send the entire session encoded as URL querystring which makes it tweetable, emailable, etc. e.g. https://live.sympy.org/?evaluate=factor(x**2%2B5*x%2B6)%0A%2... (to generate the session-as-querystring for your…

Here is a short tutorial of the SymPy APIs that are relevant for high school math (equations, algebra, functions, etc.) and first-year university (mechanics/calculus/linear algebra): https://minireference.com/static/tutorials/sympy_tutorial.pd...

Re: Doing Symbolic Math with SymPy

#38

SymPy's problem is that it is based on an object-oriented language. This results in SymPy (and friends) demanding that users abandon hundreds of years of math notation, to conform to the whims of a programming language. In SymPy you do M.diagonalize(), which makes no sense. The matrix M does not have a property diagonalize. Rather, you should apply a choosen diagonalization algorithm like Diagonalize(M) to produce a…

This is problem I have with Python in general; that even if you prefer to use it in a functional style, most libraries are written by real Python programmers, and using them will force you to grapple with the object-oriented inversion of common sense ( https://lee-phillips.org/pythonhate/ ). My favorite example is: ','.join(['a', 'b'])

Yeah, the Python language favors an imperative style due to the absence of features necessary for writing more functionally, like lambdas that can do more than return an expression, tail call optimization, and lexical scope. This last one, additionally, tends to make people use classes for essentially no other reason than that closures don't work natively.

> My favorite example is: ','.join(['a', 'b'])

I've always found the discrepancy between this example (instance method call), list(('a', 'b')) (technically a method call, but resembles a functional call), and str.lower('AB') (class method call) to be quite maddening.

Re: Doing Symbolic Math with SymPy

#39
post #25

Earlier quoted context omitted.

What's wrong with (','.join(['a', 'b']))? If it's the order of arguments, then I want to point out that the order has two big advantages: * partial application is actually useful: I've actually used (','.join) before, but (lambda sep: sep.join(['a', 'b'])) seems relatively useless. That's why Haskell also uses this order with (intercalate sep listOfStrings). * it accepts any iterable, rather than just lists.

What strikes me as weird about this is that our intent is to do something to the array of strings, so we are looking for a function that takes this array and transforms it into something else. But we are obligated to invert our intuition here, and write this as if we are doing something to the punctuation that we want to insert between the array elements. It’s backwards, and causes us (me, anyway) to keep forgetting…

> It could even be written in a way where the order of arguments didn’t matter

Well, 'hello'.join(', ') does not produce the same output as ', '.join('hello'), so the order of the arguments does matter.

Re: Doing Symbolic Math with SymPy

#40
The article mentions qtconsole interface. Does anyone know how to install and run this interface? I could not find such information either on the linked page or the SymPy docs.
Post reply on HN