7 ms·
SymPy makes math fun again
- Qem 4y agoFun, free and full. No need to fork hundreds of dollars for a Mathematica license.
- mr_mitm 4y agoDepends on your usecase. Mathematica is orders of magnitudes more powerful.
- deleted 4y ago[deleted]
- rsfern 4y agoThe interactive js visualizations are super cool, I didn’t know SymPy could do that Lately I’ve been using SymPy and Pluto.jl together, it’s been great for deriving results and making interactive visualizations for numerical code at the same time
- notpushkin 4y agoI think the visualization isn't made by SymPy, just the formulas for JS.
- rsfern 4y agoOh, so you have to hook it up to a js plotting library then? Still seems cool, I knew SymPy could emit LaTeX but I didn’t know it could do js too
- thatcherc 4y agoHave you checked out Symbolics.jl? It's a lot like SymPy.jl but with all the niceness of a implementation in native Julia instead of a python binding.
- rsfern 4y agoSymbolics.jl looks really cool, I haven’t used it much but I definitely want to I think I was looking into it at the start of this project, but it looks like it’s symbolic solver can still only handle linear equations, and I’m working with a mess of quadratic inequalities that I wanted to solve symbolically
- notpushkin 4y agoI've solved some Math assignments using SymPy on my sophomore year in uni. One time instead of writing them down to paper (the assignment was like “you have 24 hours to take these 20 integrals”), I've just shown the script I coded to my teacher and got an A. (And I have dropped out the very same year then :-)
- hgsgm 4y agoYou got an A for translating the problems into computer form? I'm glad you dropped out of that useless program.
- voz_ 4y agoThis is a surprisingly toxic take. The goal of a program is to teach you real world skills grounded in understanding theory. If someone understands how to take a complex math problem and turn it into a computer program, and knows to reach for sympy - that feels far more useful and implies a solid enough understanding of the problem at hand.
- xigoi 4y agoIt will bite you when you encounter a harder problem that can be solved using the same technique, but SymPy can't solve it.
- abdullahkhalids 4y agoThe 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.
- wging 4y agoIn some use cases you should be able to just use `var` for a simpler call pattern: https://docs.sympy.org/latest/modules/core.html#var https://docs.sympy.org/latest/modules/core.html#var (it puts things in the global namespace, but for the typical calculator use case that's probably fine) (Sage seems to work like this too - it may use sympy under the hood)
- chongli 4y agoJust 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 desktop" version, or $194/year for the online version. Pretty steep for anyone doing math as part of their hobby. Maybe it would be fine if math itself is your hobby, but even then I'd rather spend that on books. Of course this is all moot if you're an academic and your school pays for all the licenses to any software you need.
- paulpauper 4y agoWolfram Alpha is free alternative for most uses. Good enough for most people.
- kzrdude 4y agoSome more advanced sympy usage by the following guy on youtube (jupyter notebooks / code available). He describes these in videos, and not in writing, they were very useful as an introduction to equation solving in Sympy. See https://www.youtube.com/watch?v=SZdZeT93C1s https://www.youtube.com/watch?v=SZdZeT93C1s
- swied 4y agoNice 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-ringtone-sound.html https://www.swied.com/posts/make-a-ringtone-sound/make-a-rin...
- taeric 4y agoI do wonder how many have just never been exposed to Mathematica and Matlab. I don't think they were perfect, by any measure; but a lot of the things people find amazing about modern open source tooling were near table stakes for advanced tooling decades ago.
- musicale 4y agoNot entirely sure why you are downvoted; it seems to have taken decades to get to where we are with Jupyter/sympy/numpy/scipy and similar setups. I left matlab behind years ago, but I still use mathematica occasionally. Though I haven't made a serious effort to try out Maxima, Reduce, or Sagemath.
- analog31 4y agoNo disagreement. I'm sure many of those modern Python based tools started out with someone looking over at the commercial packages and saying, "why can't we have those things too?" Or, they were dabbling with expanding the functionality of Python as a toy project, and it snowballed. I think the free-ness of Python is a really big deal, because free means you use it for everything, and you use it for things that you expect to share. I don't know the present license terms of those programs, but it used to be that unless you worked for a really enlightened organization, if you had a seat of Mathematica, it meant you had exactly one seat, probably on the computer in your office, possibly the only seat in your department. If you also had computers in the lab, at home, etc., those computers were running something else, such as Python. If Python ever got good enough at something previously reserved for commercial software, even without being comprehensive at that thing, it triggered a decision on whether it was worth the headache of maintaining the commercial license and being chained down to a single computer. I don't do large math projects, and have been satisfied with Maxima. Where I'm beginning to use SymPy is to contain the derivations for formulas within the same Python code that uses those formulas. Mainly it's a readability and documentation play.
- machina_ex_deus 4y agoI 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 formula, it's easier to see you got it correctly by displaying it symbolically in latex. They have other things to smooth out the parts of python which are annoying in math, like exponentiation works with ^, and dividing integers returns a rational number instead of floating point or an integer.
- westurner 4y ago> They have other things to smooth out the parts of python which are annoying in math, like exponentiation works with ^, and dividing integers returns a rational number instead of floating point or an integer. SageMath also has a multivariate inequality solver IIRC. `*` is repeated multiplication (exponentiation) in Python. If you require preprocessing to translate ^ to *, you don't have valid Python code that'll run with any other interpreter. Is it easier to import SageMath from a plain Python script now; with conda repackaging? Type promotion in Python: from rational import Rational assert Rational(1, 4) / 2 == Rational(1, 8) Python 2 had a __future__ import to do floatdiv instead of floordiv: from __future__ import division assert 3 / 2 == 1.5 assert 3 // 2 == 1 assert 4 / 2 == 2.0 Python 3 returns floats from ints or decimals IIRC: assert 3 / 2 == 1.5 assert 3.0 / 2 == 1.5 assert 3 // 2 == 1 assert 4 / 2 == 2.0
- williamstein 4y ago> Is it easier to import SageMath from a plain Python script now; with conda repackaging? Yes, it's easy. It was always possible, since fortunately none of the Sage library implementation uses the Sage preprocessor. You could always do "sage -python" and you get the Python interpreter that Sage uses, and can import Sage via "import sage.all". Somebody asked me exactly this question at a colloquium talk I gave on Sage yesterday, and here's my answer/demo: https://youtu.be/dy792FEh1ns?t=1140 https://youtu.be/dy792FEh1ns?t=1140 In the demo, I use a Jupyter kernel that runs the Python included in Sage-9.8. Disclaimer: I created the Sage preparser long ago, in order to make Sage more palatable to mathematicians. In particular, it was inspired by audience feedback during a live demo I did at PyCon 2005.
- paulpauper 4y agoLearning how to derive the taylor series or memorizing the formulas with some rough understanding of how to derive them sounds easier than learning a programming language Regarding his low exam performance , this is why classes are sometimes graded on a curve. Intro calc. is pretty easy, and the author def. seems smart enough to do well. Likely his class was unusually hard. Sometimes that happens..luck of the draw.
- selimthegrim 4y agoSee my post on HN a few weeks back: https://news.ycombinator.com/item?id=34734412 https://news.ycombinator.com/item?id=34734412
- okaleniuk 4y agoWell, you have to understand how Taylor series work anyway. And then, of course, you have to understand differentiation. SymPy doesn't rob you of mathematical knowledge it just automates the grind. Of course, there is nothing wrong in doing symbolic computations by hand. But it's like walking vs. riding a bicycle. You're still getting from A to B but you save some time and energy with the machine.
- smohare 4y agoAs 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.
- brrrrrm 4y agowhat’s nice is that pyodide folks have gotten sympy compiled to web assembly, so it’s a viable browser library too!
- williamstein 4y ago+1 -- here's a link to quickly try that out in browser: https://jupyter.org/try-jupyter/lab https://jupyter.org/try-jupyter/lab Here's a completely separate Python in WebAssembly project I created, which also provides Sympy with "import sympy" being a little faster (1.7s v 1.16s on my laptop): https://cowasm.org/ https://cowasm.org/
- ivansavz 4y agoYes, the SymPy live shell is based on pyodide and the jupyterlite shell: https://live.sympy.org/ https://live.sympy.org/ (recommend desktop browser, but works on mobile too)
- l_theanine 4y agoShoutout to Mathics (https://mathics.org https://mathics.org), which is basically Mathematica, for Python, via SymPy. I'd like to say that I use it all the time, but I'm too old to be bothered by learn new things at this point. However, I think the Python ecosystem is getting better all the time, and things like SymPy and Mathics give me a lot of hope for the future of technical computing with Python.
- ivansavz 4y agoIn case anyone is interested to learn more about SymPy, check out this printable tutorial: https://minireference.com/static/tutorials/sympy_tutorial.pdf https://minireference.com/static/tutorials/sympy_tutorial.pd... It covers basic fundamentals (high school math like solving equations), calculus, mechanics, and linear algebra. The tutorial is also available in notebook form: https://github.com/minireference/sympytut_notebooks/tree/master/notebooks https://github.com/minireference/sympytut_notebooks/tree/mas... Binder link: https://mybinder.org/v2/gh/minireference/sympytut_notebooks/HEAD?labpath=notebooks%2FIntro.ipynb https://mybinder.org/v2/gh/minireference/sympytut_notebooks/...
- voz_ 4y agoSymPy is very powerful, and at times, a little infuriating, but that is probably my own noob-ishness. On the whole, I am extremely glad it exists, we've been using it inside the PyTorch compiler for dynamic shapes, and it has been an overall great time. I strongly encourage interested folks to pull it down and give it a spin. The printing/printer system, which the author touches on briefly with `jscode` is a brilliant way of converting sympy expressions into whatever you like. I found it a pretty smooth experience to write my own little printer.
- atan2 4y agoWhat a find. The other articles on this page are also very good!
- keithalewis 4y ago"There is no royal road to logic, and really valuable ideas can only be had at the price of close attention." -- Benjamin Franklin
- bofadeez 4y agoMath isn't supposed to be fun. It's supposed to work. What's with people trying to make everything fun?
- kalimanzaro 4y agoPreviously: 2019 267 pts 59 cmts https://news.ycombinator.com/item?id=20287486 https://news.ycombinator.com/item?id=20287486
- edflsafoiewq 4y agoWhat 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.
- genjii931 4y ago'again'?
- okaleniuk 4y agoHello, OP here. I wrote a whole book around the idea that mathematics is understanding first and symbolic computation second. In Geometry for Programmers, SymPy does the grind for you in every chapter (except chapter 2). Initially, I was even going to omit all the math notation altogether and turn all the formulas into Python snippets. But several reviewers said that this is too much, so now there are formulas you can see and snippets you can run. https://www.manning.com/books/geometry-for-programmers https://www.manning.com/books/geometry-for-programmers
- auggierose 4y agoI see that you don't use LaTeX for your formulas. Was that a choice of yours, or is it just not possible with Manning? I am asking because I would like to publish a book within the next year or so, and am wondering which route to go. It seems self-publishing gives you the most freedom.
- okaleniuk 4y agoI should have used LaTeX from the start, yes. Manning accept manuscripts in LaTeX, moreover, they prefer to work with LaTeX formulas, and even if you write in MS Word, there is a pugin for LaTeX that they encourage you to use... ...and I learned all of that after the manuscript was done. That's on me, I should have been more inquisitive. Also, I should have asked about their style guide and technical requirements for the graphics. The book was supposed to be ready for printing sometime this month but now the launch is delayed till June since they have to redo 300+ graphics from scratch. Self-publishing definitely gives you more freedom. But Manning also give you a development editor, a technical editor, a copy editor, a technical proofer, a copy proofer, plus a few dozen reviewers, and a whole production team. Writing for a publisher does feel like a deal with the devil, true, but it is not that bad of a deal. If you want, write me a line (ok@wordsandbuttons.online) and we'll chat about publishing with Manning. Or without. My first book was published on Leanpub, and the second is available from wordsandbuttons.online directly.
- samwestdev 4y agoYour book looks really interesting. Do you think it would be appropriate for a complete math/geometry beginner to read?
- idanp 4y agoI felt SymPy needed some adjustments for it to be fun and useful for my day-to-day calculations, so I wrote this: https://github.com/idanpa/calcpy https://github.com/idanpa/calcpy
- 6451937099 4y ago[dead]
- 6451937099 4y ago[dead]
- maCDzP 4y agoThis is the way. I use Wolframalpha for computation. I let my brain do the fun stuff.
- 6451937099 4y ago[dead]
- 6451937099 4y ago[dead]
- 29athrowaway 4y agoSagemath includes SymPy and other projects.
- edrx 4y agoMy main problem with SymPy is that I don't know where its community is! Maxima has a mailing list that is a really lovely place and an IRC channel that is (halfway between dead and) alive... what are the good places to ask questions about Sympy? Stackoverflow? Matrix? I just discovered that it has a group in Google Groups - that, ta-da! even has a recent message about the Gitter channel: https://groups.google.com/g/sympy/c/jisKFe_xsd0 https://groups.google.com/g/sympy/c/jisKFe_xsd0 "From what I've seen, for a while, it's mostly just been people asking questions, but no one has been on there who is actually able to answer them."
- create_sciency 4y agoSymPy definitely makes things easier. As a non trivial example I attempted to solve a recent (2022) IIT advanced maths paper with SymPy. This exam is usually considered to be hard, and is definitely non trivial. But with SymPy it was a cakewalk: https://youtu.be/O6UFVSm625k https://youtu.be/O6UFVSm625k .