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.
Sympy is a sufficiently advanced technology, indistinguishable from magic. If you love python and are interested in math, give it a try and you will be astonished of what it can do.
No one is a complete beginner I suppose. If you did some geometry in school, maybe some basic algebra, if you know what a function is (and I think every programmer knows what a function is) - you're good to go.
Even if the book is called Geometry for Programmers, I was trying really hard to make it self-sufficient. E. g. if you want to get deep into fascinating stuff like NURBS, you need to know a little calculus. So there is a chapter on calculus. It is shallow by itself but it opens the door for power series, polynomial interpolation, and then Bezier, rational Bezier, and finally NURBS.
Just like that, before introducing homogeneous coordinates and projective matrices, I put a chapter on linear equations. In any other geometry book it would have been completely redundant, but it explains so much about 4 point transformations, I just had to put it there.
TL&DR I sure hope so! This was my intention and if the book isn't appropriate for a beginner, I failed miserably as an author.
I 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.
I 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.
I 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.
As someone who does research with computer algebra systems (mainly Wolfram Mathematica) many hours a day, I think that SymPy is still far behind Mathematica. The fundamental design of Mathematica based on replacement rules and a style of functional programming is quite difficult to beat in terms of ease of use. A few weeks ago I gave SymPy another try, and tried to implement a nested sum of the type 1 <= a_1 < ... < a_k <= n over a complicated summand f(a_1, ... ,a_k), where k and n are integer arguments, and it took me ages to figure out how to implement this in SymPy, whereas I in Mathematica I can write this in a minute.
That's true, Mathematica is more advanced. But it's not cheap and it brings in a whole new world with it. You do have to learn to use it explicitly while with SymPy, you can start after a 5 minute introduction. I would say, Mathematica a good professional instrument while SymPy is a good hobbyist tool.
A note to a bypassing reader, if you want to try Mathematica, and not sure if you would stay with it, don't go for a desktop license. Get a Raspberry Pi instead. Mathematica comes free for Raspberry!
SymPy is a great tool but there isn't a dedicated team of mathematicians and programmers working on it full time. I believe it has potential to compete with Mathematica someday.
I'm a heavy user of Mma but there are better examples. Automating the rewriting of formulas to make them more concise is a big one. (But also not as straightforward as it could be, tradeoffs between conciseness, ease of reading and speed of implementation need to be triaged, similar to Lisp/APL. Maybe sympy still has a chance to be more like math/TCS)
No. In Mathematica important operations like mapping functions over sets (arrays/tensors) at various depths have simple operators such as (/@, @, @@, @@@). You can do functional composition using @*, etc. You don't need to define your variables and functions before being able to write them in expressions. Often you want to have intermediate terms that have some temporary name, and which get substituted later on. The replacement rules in Mathematica are very powerful for this.
As another example, I googled some project Euler solutions in Mathematica and (pure Python) and found this: https://www.nayuki.io/page/project-euler-solutions. Compared to the pure Python solutions, the Mathematica code is typically much smaller. Of course this is not Sympy, but a lot of the Python syntax carries over to SymPy as well.
I don't have experience with SageMath, but if they are really running on Python, then they are surely giving up on some of the nice rewriting that Mathematica is based on, as I would expect then a library call is needed instead in Python.
> As someone who does research […] mainly Wolfram Mathematica […] it took me ages to figure out how to implement this in SymPy, whereas I in Mathematica I can write this in a minute.
Hardly surprising, is it? As someone with more experience in Python, it would likely be the opposite for me.
You are replying to somebody talking about sage (rather than sympy), which in many fields (not all) is very far ahead of Mathematica.
I do quite like the programming language of Mathematica, but an advantage of sage (and of sympy) is that you have the whole python standard library at your disposal. For your example you could e.g. use itertools.product.
> 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?
> 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:
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.
> They have other things to smooth out the parts of python
I should add that this is an interesting chunk of Python code, and we've always planned to separate it out from Sage as a separate library than could be used with Sympy, etc.
It does a surprising number of little clever things we realized would be a good idea over years, and it has some neat ideas from various Python PEP's like [1..10] that were rejected from Python, but are very useful when expressing mathematics. It's also annoying when you just want to format your code using prettier (say), and you can't because Sage isn't Python. :-(
In case anyone is interested to learn more about SymPy, check out this printable tutorial: https://minireference.com/static/tutorials/sympy_tutorial.pd... It covers basic fundamentals (high school math like solving equations), calculus, mechanics, and linear algebra.
I 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.
No 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.
Yes, this discussion sent me down a rabbit hole learning about the free (for non production use) Wolfram Engine, WolframScript, and Wolfram Language kernel for Jupyter!
SymPy 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.
What 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.
The 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
Symbolics.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
Learning 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.
Well, 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.
You 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:
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.
Variable 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.
Your 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.
I'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 :-)
This 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.
My 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:
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/
Some 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.
SymPy 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 .
Shoutout to Mathics (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.
As 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.
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