8 ms·
SymPy makes math fun again
- okaleniuk 7y agoBy the way, there is SymPy online: https://live.sympy.org/ https://live.sympy.org/ You don't even have to install anything!
- okaleniuk 7y agoWell, the online version might fail on heavy computations to be honest, so it might be best to have it installed locally if you're planning to do some serious stuff. But for the first acquaintance, the online SymPy should be fine.
- williamstein 7y agoYou can also use SymPy on https://CoCalc.com https://CoCalc.com, and it will handle heavier computations. (Disclaimer: I created cocalc.)
- verdverm 7y agoreally glad for SymPy, used it in my PhD work: https://github.com/verdverm/pypge https://github.com/verdverm/pypge
- ktpsns 7y agohttps://dl.acm.org/citation.cfm?id=2463486 https://dl.acm.org/citation.cfm?id=2463486 -- awww, why don't you computer scientists (also) upload your work on preprint servers such as the ArXiV? http://arxiv.org/ http://arxiv.org/ Thus it keeps hidden behind the paywall forever.
- verdverm 7y agoThis was way before arxiv got popular. You can find the original one here: https://github.com/verdverm/go-pge/blob/master/pge_gecco2013.pdf https://github.com/verdverm/go-pge/blob/master/pge_gecco2013...
- symbolicanon 7y agoSymPy is pretty great, but some of its basic operations (e.g. subs() and evalf(), which substitute numeric values for symbolic variable names) can be exceedingly slow. There are workarounds like autowrap, which generates C code to do this orders of magnitude faster. There are also reimplementation efforts in C++ like symengine to address the performance issues.
- krastanov 7y ago`subs` and `evalf` is simply not the right tool for float/double precision arithmetics. `subs` in particular is a general tool for symbolic substitutions, and it is not fair to expect it to be fast for numerics (although improvements would always be great). `evalf` provides high precision arithmetics (your RAM is the limit), so again, it is inherently slower than float math. One can argue that this should be documented better or that the tool should be able to guess the intent of the user, but otherwise I would say of course `subs` and `evalf` are slow when you use them for float math.
- mhh__ 7y agoI find that mathematics gets less and less fun as I do more of it on a computer. Symbolic Algebra packages are very useful but nothing beats a pen, paper and time for fun.
- noobermin 7y agoI agree, but I'm not sure if it's a psychological thing or not. For example, I became known in my QFT classes for doing homework on TeXmacs. I think it might have very well to do with where you learned it first, for example, I never felt comfortable coding on paper and pen (although I did once in high school since I couldn't bring a laptop on the bus).
- mhh__ 7y agoI cannot work directly into TeX but I love fiddling around with it once I've done the work. When I'm slamming my head again a QFT textbook I feel like I need to work on paper so I don't lie to myself with the symbols (When I don't understand it yet) I plan my code on paper quite a lot, and actually quite enjoy talking about what I'm doing (Whiteboard or not) [I think some whiteboarding at interviews is a good thing]
- noobermin 7y agoOh don't misunderstand, I'm not that leet, texmacs is a TeX(like) wysiwyg with shortcuts inspired by TeX so it feels natural and is rather quick. One of the things apart from the familiarity I'm arguing is important is the symbols once on page looked more like what you'd see in a paper/book, so it was more immediately obvious when something looked "right" or didn't.
- jjoonathan 7y agoIf you like this, you'll love Mathematica. If you're at university and have a site license, that is :(
- jhbadger 7y agoThere's always Mathics, which is an open source implementation of (some) of Mathematica, using SymPy underneath: https://mathics.github.io/ https://mathics.github.io/
- noobermin 7y agoAny thoughts on Mathics? Have heard of it but haven't tried working with it in depth.
- jhbadger 7y ago1) If you use it, I'd recommend installing it locally (pretty easy with pip install mathics) 2) When doing something complex, it can be a bit slow (it relies on SymPy, which isn't a speed demon itself, plus it has to parse and interpret the Mathematica syntax, which adds overhead) 3) The subset of Mathematica that it supports is pretty much what SymPy does -- so pretty much classic mathematics and graphing rather than the knowledge based stuff like populations of countries and their GDPs or whatever that Mathematica has been adding over the last few versions.
- noobermin 7y agoHow are good like things like its simplifying algorithm? I've used Sage which uses sympy from what I understand and it didn't quite cut it. Is Mathics just an interface or does it tweak the algorithms?
- jhbadger 7y agoThe Mathematica/Wolfram language support of Mathics is good enough that some of the functionality is implemented in itself rather than a straight SymPy wrapper, but if Sage (a much bigger system than Mathics) can't simplify the expressions you want, probably Mathics can't either.
- iso-8859-1 7y agoNitpick: Reusing a name and shadowing and existing binding because the name is equivalent isn't "overloading". But I don't know if it should be called shadowing either because there is no function scoping in effect... Hmm
- okaleniuk 7y agoYes, indeed.
- TheRealPomax 7y agoSymPy turns "maths" into "programming", using python syntax instead of maths syntax, so if you already like programming, then you might just like SymPy... but as someone who likes maths, and likes programming: the programming maths parts is also the mind numbing part, and any line fewer I can write, I will take. So to me, this article just confronts me with the soul-destroying parts of modern maths, while claiming that those are apparently the fun bits. I have no idea how to reconcile those two things so I can pass that learning on to someone who might be getting interested in maths...
- jmwilson 7y agoThe times I have used CAS to help with algebraic simplification, I've found the same problem, regardless of using SymPy or the more feature-filled Mathematica: the package's rules for simplification often obscure useful forms that lead to insight. The CAS gives you the correct result, of course, but I end up having to apply significant post-processing to the result by forcing substitutions that can take almost as much time as doing the algebra by hand. As a simple example, consider the transfer function of a RLC circuit from basic electronics. It might contain a expression of the form: s^2 + (R/L) * s + 1/(LC). What's often helpful is to express this in terms of the unitless form 1 + s/(Q * w0) + (s/w0)^2, where w0 is the resonance frequency and Q is the quality factor. In a complicated example with more components, the value of w0 might be related to the simple form of 1/sqrt(LC) by some unitless factor, or there's some other helpful way to write things that neatly relate it to the basic case, but SymPy/Mathematica will drag its feet showing you that. I wish there was more done on improving the insight and meaningfulness of results from CAS to the experimenter.
- jacobolus 7y agoIt’s also very frustrating that they don’t know vector identities. Everything is done in terms of real numbers or complex numbers. I would love to see a CAS that knows identities of https://en.wikipedia.org/wiki/Geometric_algebra https://en.wikipedia.org/wiki/Geometric_algebra
- orbifold 7y agoThose exist and are in active use by physicists (in fact one of the first CAS called Schoonschip was developed by nobel price winner to be Veltman to carry out Feynman diagram calculations). However there remains a huge tome of high energy physics to be implemented in one common CAS (one of the things I sometimes dream about starting). The culture of theoretical physics is such that only the end results of calculations are ever shared with intermediate steps left as exercises to the reader. Graduate students are expected to develop a stash of identities and routines to go back to, which is their “competitive advantage”, especially in fields like model building.
- ska 7y ago
- bayesian_horse 7y agoI suspect that school and university math exams emphasize meticulous and flawless computation over intuition, understanding and problem solving. So to get good grades, it's not good enough to understand math, you also have to be able to focus enough to avoid mistakes. Between ADHD and the prefrontal cortex developing/maturing well past the age of 20, that's quite an ask.
- msla 7y agoEstimation should be taught as a respectable discipline and one worthy of serious study. Even aside from the fact no intelligent educator can claim with a straight face that most of their students will need to do arithmetic by hand in a real scenario, estimation is vital for getting an intuition about orders of magnitude and how quickly addition and multiplication increase a value.
- philipov 7y agoMy grandfather was a mathematician and he once admonished me that understanding math is as useful as understanding swimming. If you're drowning, you need to be able to DO swimming, not just understand it. Understanding will come from practice, but not the other way around.
- thrwayxyz 7y agoAbsolutely. People who understand math can't swim. They just board a ship going in the direction they want and get there without drowning.
- haberman 7y agoI'm an amateur at math: is what is being calculated in the article the same as a Taylor series?
- soVeryTired 7y agoNope - the Taylor series depends on a specific choice of point. Around that point, the truncated Taylor series is the "best" approximation of the function using a polynomial. In this case, the author has picked seven points on the sine curve (or its integral or its derivative), and used those seven pieces of information to find a unique polynomial. If I were to guess, I'd say that if the seven points were on the curve itself (not on its integral or derivative), and they were all very close to some point P, then the resulting polynomial would look a lot like the taylor series expansion around P. But that's just a guess :)
- okaleniuk 7y agoYes, that's correct! In fact, with sine modelling, Taylor series beats this approach with lower error. But with this you get to choose your properties so you might get more useful model instead. Say, if you want to conjoin two sine models got from Taylor series to have it on a full [0, 2pi], you will have derivative discontinuity - a bump - on the joint. But with this model you wouldn't since it's explicitly required to be the inverse number at 0 and at pi/2.
- okaleniuk 7y agoSymPy can expand series too, one line of code - and you're done. But that would be no fun. The idea here is: every differentiation or integration over a polynomial results in another polynomial, right? And a polynomial in a point is just a linear equation of its coefficients. You can shove them into a system and make SymPy solve it. So you can use differential and integral properties of some random function in some points, turn it into a linear system - and have a model of a function as a polynomial. That's it!
- atdt 7y ago> I disagree with “math is not for everyone”. Math is vast and diverse. Surely there is enough math for everyone. Are you the author? That's a great sentiment and you express it well. In fact, the whole article is engaging. Good job!
- lokedhs 7y agoAnother open source CAS one might want to look at is Maxima, which is based on Macsyma which was started in the 60's. Not many open source projects a history that long. The most popular frontend is wxMaxima which provides a nice user interface on top of Maxima: https://wxmaxima-developers.github.io/wxmaxima/ https://wxmaxima-developers.github.io/wxmaxima/ I have been working on a different frontend, that leverages CLIM, which happens to be a perfect toolkit for something like Maxima. I made a screencast showing the current state of development: https://peertube.mastodon.host/videos/watch/df751bd5-5a26-44da-90d5-f47624161649 https://peertube.mastodon.host/videos/watch/df751bd5-5a26-44...
- mruts 7y agoI would hardly call wxmaxima a “nice frontend” for maxima. It doesn’t even render equations nicely (in LaTeX), say. The emacs or LyX frontends are much nicer.
- lokedhs 7y agoI believe my renderer does a decent job though. You can see it in the video I posted. The equations in the documentation is renderered by the same code (which is not related to LaTeX, although since it's the reference implementation, I've tried to make my renderer be as similar as possible). I have a preview release available as an Appimage, but please note that it is not a completed product yet: https://github.com/lokedhs/docker-maxima-client/releases https://github.com/lokedhs/docker-maxima-client/releases
- tijss 7y agoI really like SymPy and support the hard working developers constantly improving it. This software is incredably complex and really needed. One day it will be a viable open source alternative for Matlab and Mathematica. That said, for my specific use case (modulo arithmetic / cyclic groups) I didn't get SymPy to work properly. While I was able to find guidelines on how to hack it together, I have not found a real solution. After 2 hrs of search, I retreated in shame to Mathematica. If anyone knows a solution or works with these structures, let me know!
- vog 7y agoI used to use a lot of SymPy, but finally switched to Sage. This is Python as well, but has some syntax extensions and sensible defaults that reduce many quirks of Python. For example, you can write 1/2 instead of of Rational(1,2) and a^b instead of ab. Moreover, Sage integrates lots of other libraries seamlessly. I remember doing lots of polynomial calculations and groebner basis stuff, and generating Singular script from Python seemed to be very elegant in the beginning. However, this quickly showed severe drawbacks. With Sage this all became easy and seamless again.
- mikorym 7y agoThere was a post about Sage not long ago that it is used commonly among cryptographers. As an aside, the statistical libraries and conveniences of R ("missing value" is a data type; every object is an array meaning you can call functions on arbitrary arrays) are the only reason that I still use R for some niche applications. I wonder whether pandas or something like Sage will actually take over this functionality. My impression is that the packages in R are so isolated (in a somewhat good sense) for a niche application that they are both difficult to emulate in Python and happen to keep on working long after they were written (and not necessarily maintained).