4 ms·
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 varia
by abdullahkhalids 4y ago
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.
- 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.
- abdullahkhalids 4y agoVariable names are not arbitrary. They have meaning. Single-letter lower-case variables hardly cover all possible names. Mathematica, just like, real mathematics, allows you to have variable names with subscripts/superscripts/greek-letters etc. E.g. a_g is distinct from a_f (which are both rendered in rich text) My recommendation is not that everyone buy Mathematica, but that sympy figures out a way to allow every sequence of letters and numbers (that start with a letter) to automatically become a variable without declaration.
- loa_in_ 4y agoIt's possible to get the same result in sympy with some metaprogramming, and it does absolutely support longer names for variables!
- geysersam 4y agoSubscripts on symbols you can do in sympy as well. Also multiple subscripts. In your formulas you can have Greek letters in sympy. But you'll have to give the symbols valid python names.
- anigbrowl 4y agoYour points are valid and the workaround is indeed easy, but it is strangely clumsy and inelegant. I put up with it because I like SymPy a lot, while not needing to use it so often that the awkwardness really chafes. But if I was doing more serious math work or doing it professionally I'd probably spring for the Mathematica license despite finding Wolfram personally annoying.
- whyever 4y agoYou can leave out the assignment, `var` already injects the variables into the local scope. IIRC, the commas are redundant.
- jwilk 4y agoInto global scope.
- rav 4y agoYou 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
- anigbrowl 4y agoUnderrated suggestion - thanks a lot.
- schoen 4y agoThis 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