Live data from Hacker News

Doing Symbolic Math with SymPy

lwn.net

71–80 of 81 posts

Re: Doing Symbolic Math with SymPy

#71

I want to encourage people to think of sympy not just as a competitor to Mathematica but additionally as an incredibly valuable library that can be used _inside_ of other projects. Sometimes, you just want to compute an antiderivative, or you want user-supplied functions that you can manipulate easily, or you want to do some actual algebra. Think of it less as a Mathematica replacement (like "Linux on the Desktop") a…

This may be a stretch, but can you point to any examples or articles about using SymPy outside of a strictly mathematical context?

I would bet it can be useful in physics engines

Re: Doing Symbolic Math with SymPy

#72
post #70

Earlier quoted context omitted.

Not at all. I've worked on numerical stuff myself; unlike the symbolic bugs, I have little sympathy for these particular numerical errors. It would be far more reasonable if it was convoluted composition of functions, or some kind of bizarre numerical edge case. However: (a) Univariate quadratics are extremely well-understood and extremely important. For example, the convergences of optimization algorithms (this is r…

It's been a while since I did root finding in SciPy, but in principle I do not agree, and it doesn't seem like you're proposing an actual solution. You can make the case that that root finding algorithm shouldn't be the default (if it is). You can argue for a warning, as mentioned in the bug, but what else? I personally prefer less magic in the algorithms (e.g. detect if it is a quadratic and pick a suitable algorith…

As I see it less magic in the algorithms" makes sense when the user specifies an algorithm. When they haven't, it literally means: "I really don't care how you solve this, just give me the best solution you can however you want, and stop making excuses."

And for the record I could propose better solutions but clearly you don't want them because that's too much "magic". In fact, one bit you might find fun: try plugging in the proposed solution as a new guess and see how well the algorithm had even converged. You're literally advocating for an algorithm that produces wrong solutions it doesn't even claim to converge on. It it even possible to be more wrong than this on such a basic problem?!

Lastly: I've found far milder bugs in Mathematica that I didn't expect them to fix, and they actually fixed them. So I think, moving forward, this is probably going to be my exhibit A for why expecting open source software to achieve the quality of commercial solutions might be fundamentally just expecting too much. When you don't have customer money to tell you your wrong solutions are wrong, people will jump to the defense of the most insane behavior, telling you you're "not fundamentally right" to expect programs to have even the most trivial sanity checks to prevent wildly wrong outputs for the most basic problems.

Re: Doing Symbolic Math with SymPy

#73

Earlier quoted context omitted.

That's not really a bug, it's just behavior explained by numerical analysis. A very small change in the initial guess can be the difference between success and a blowup for numerical algorithms; particularly rootfinding algorithms. Sometimes this is implementation specific, and is numerical instability. Sometimes this is endemic to the algorithm regardless of implementation, like Runge's phenomenon. Often there is no…

I know how numerical stuff works, but no, this is pretty inexcusable. See my other comment: https://news.ycombinator.com/item?id=25689916

You say you know how numerical stuff works, but you're demanding a solution that doesn't really exist. Numerical rootfinding algorithms are prone to this. The same thing happens in e.g. Mathematica, they just have better warning messages and documentation.

Re: Doing Symbolic Math with SymPy

#74
post #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.

https://github.com/jupyter/qtconsole

> The Qtconsole is a very lightweight application that largely feels like a terminal, but provides a number of enhancements only possible in a GUI, such as inline figures, proper multiline editing with syntax highlighting, graphical calltips, and more.

Re: Doing Symbolic Math with SymPy

#75
post #70

Earlier quoted context omitted.

It's been a while since I did root finding in SciPy, but in principle I do not agree, and it doesn't seem like you're proposing an actual solution. You can make the case that that root finding algorithm shouldn't be the default (if it is). You can argue for a warning, as mentioned in the bug, but what else? I personally prefer less magic in the algorithms (e.g. detect if it is a quadratic and pick a suitable algorith…

As I see it less magic in the algorithms" makes sense when the user specifies an algorithm. When they haven't, it literally means: "I really don't care how you solve this, just give me the best solution you can however you want, and stop making excuses." And for the record I could propose better solutions but clearly you don't want them because that's too much "magic". In fact, one bit you might find fun: try pluggin…

The root-finding problem is not solvable in general. In exact real arithmetic, there cannot exist an algorithm that will find an $x$ such that $f(x) = 0$ even if such an $x$ exists and $f$ is computable. At least not unless you make some further assumptions about $f$ and $x$.

Of course, I'm talking about the worst case. Your example is easier.

Re: Doing Symbolic Math with SymPy

#76
post #48

The trouble with SymPy is it's, well, buggy. I tried it a few years ago, and as soon as I got serious, I quite quickly ran into problems that I reported, some of which I now see they apparently still haven't gotten around to addressing. [1] [2] Symbolic math is hard ; they have my sympathies. I don't think I could do better. But as long as bugs like these exist, it's going to be hard to convince people to switch away…

Yikes those are bad. As a non-user interested in it, I must confess that seeing those issues (especially the 2nd one) makes me not want to use it! I do get that it is a hard problem, but I would then recommend they not have an option for "real" if they can't get it right. Users will expect it to work (unless the docs point out it is unreliable).

I don’t think there is a general-purpose symbolic math program that doesn’t have some bugs. Mathematica was getting some definite integrals wrong for some years. Anyone who uses these knows to check the results.

Re: Doing Symbolic Math with SymPy

#77
post #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.

My first mention of qtconsole in the article is a link to an official page that has detailed installation information.

Re: Doing Symbolic Math with SymPy

#78

Earlier quoted context omitted.

I know how numerical stuff works, but no, this is pretty inexcusable. See my other comment: https://news.ycombinator.com/item?id=25689916

You say you know how numerical stuff works, but you're demanding a solution that doesn't really exist. Numerical rootfinding algorithms are prone to this. The same thing happens in e.g. Mathematica, they just have better warning messages and documentation.

> The same thing happens in e.g. Mathematica, they just have better warning messages

They "just" produce "better" warning messages? You say that as if scipy is producing any warning messages? There's an absolutely colossal difference between failing with a poor error description and producing a completely wrong answer with 100% confidence.

> but you're demanding a solution that doesn't really exist

Doesn't exist?! Have you even tried the other algorithms on there before writing this? Broyden1, anderson, etc. handle this just fine. Even the default hybrid algorithm itself would handle this just fine if they even cared to run that very algorithm a couple more times to get convergence. Is there an algorithm that solves every equation in the world? No. Does it need to? No. Does it need to be able to handle the most basic cases? Yeah.

Re: Doing Symbolic Math with SymPy

#79
post #75

Earlier quoted context omitted.

As I see it less magic in the algorithms" makes sense when the user specifies an algorithm. When they haven't, it literally means: "I really don't care how you solve this, just give me the best solution you can however you want, and stop making excuses." And for the record I could propose better solutions but clearly you don't want them because that's too much "magic". In fact, one bit you might find fun: try pluggin…

The root-finding problem is not solvable in general. In exact real arithmetic, there cannot exist an algorithm that will find an $x$ such that $f(x) = 0$ even if such an $x$ exists and $f$ is computable. At least not unless you make some further assumptions about $f$ and $x$. Of course, I'm talking about the worst case. Your example is easier.

> The root-finding problem is not solvable in general.

Great, because nobody was asking for that either.

> Of course, I'm talking about the worst case. Your example is easier.

Which has been my entire point this whole time, which I already explained to you but which you conveniently prefer to totally ignore. The case I gave is not merely "easier"... it's utterly trivial. I literally even explained how they could solve it with the current algorithm too: by running multiple iterations of that exact algorithm to at least try to get some kind of convergence. Did I ever demand or expect it to solve arbitrary transcendentals? No, nobody was demanding it to magically solve everything. But producing flatly wrong outputs for even the simplest quadratics without any attempt to improve it, sanity check it, or issue a warning is just plain inexcusable and embarrassing.

Re: Doing Symbolic Math with SymPy

#80
post #75

Earlier quoted context omitted.

The root-finding problem is not solvable in general. In exact real arithmetic, there cannot exist an algorithm that will find an $x$ such that $f(x) = 0$ even if such an $x$ exists and $f$ is computable. At least not unless you make some further assumptions about $f$ and $x$. Of course, I'm talking about the worst case. Your example is easier.

> The root-finding problem is not solvable in general. Great, because nobody was asking for that either. > Of course, I'm talking about the worst case. Your example is easier. Which has been my entire point this whole time , which I already explained to you but which you conveniently prefer to totally ignore. The case I gave is not merely "easier"... it's utterly trivial . I literally even explained how they could so…

[deleted]
Post reply on HN