I’ve come to be somewhat known as a “math guy” in creative coding. It’s one of my impostor syndrome items because I’m really not any kind of expert in the field. I took Algebra and some Precalculus in high school banged my head on a formal Calculus course, but never made it through. Most of what I know has been self-taught and pretty seat-of-the-pants.
I’m pretty good at fumbling my way through things, figuring out intuitively how things work to the point where I can use them pretty expertly to do what I need to do with them, but I could not hold my own in a conversation with anyone who has a real math background. For a while now I’ve wanted to shore up that shaky wall of knowledge.
Recently I stumbled upon this book, A Programmer’s Introduction to Mathematics at https://pimbook.org/. There you can read a chunk of the first part of the book, buy a hard copy or an ebook version. If you go for the ebook, you can pay what you want. I paid $0 for a copy in order to evaluate it. But before I even got through Chapter 1, I went back and paid a decent amount for another copy in order to support the author.
As the title implies, the book is targeted towards programmers who do not have an academic math background. One thing that resonated with me right off is that the author talks about the language of mathematics as an analogy to the language of programming, and how when you were starting to code, everything was confusing, but you probably stuck with it and now it makes sense. Math is the same way, but for some reason, a lot of programmers tend have less patience when studying math.
He also discusses the fact that the language of mathematics is looser than programming in a lot of ways. In code, things have to be expressed a very exact way or they just don’t compile. Variables and functions have to be fully and explicitly defined if you expect the computer to run them. But in math, there’s a lot of tacit agreement and assumptions that go on. Lots of shortcuts and conventions. So if you’re not steeped in that culture, it all looks like black magic to you. This is exactly what I’ve experienced over the years. The text will talk vaguely about an idea and then there will be a formula with all kinds of Greek letters, and no explanation of what those symbols mean. If you aren’t already familiar with them, you don’t stand a chance.
Some of the topics covered in the book:
- Calculus with one variable
- Linear algebra
- Eigenvectors and Eigenvalues
- Multivariable calculus
Chapter 1 talks about polynomials and how formulate a polynomial that will pass through a series of points. The author goes through the concepts and definitions and the strategy on how to solve it, ending up with a few proofs. And you get to the following formula:
By the time I got there, I actually fully understood that formula! This felt really good. From there, the chapter went into a code example (all written in Python). But I felt so confident, I went straight in and coded up my own example in Golang. I defined a set of points, generated the polynomial for that set of points and then drew the curve based on that polynomial, and what do you know? It went through all the points, just as expected.
I was even able to animate it!
After finishing Chapter 1, I was checking into a subject that I’ve been aware of since the 90’s but had never actually tried to code: Lyapunov fractals. Heading to wikipedia’s page on the subject – https://en.wikipedia.org/wiki/Lyapunov_fractal – I came across this formula:
This looked pretty daunting. In the past I would have looked at that and glazed over. But this time I was able to read the formula and understand what was going on there. It wasn’t bad at all. I wrote the code solely based on what you see above (and a related function r in the same article) and was able to create this:
It took a while to get the coloring algorithm down, but the formula worked perfectly on first compile.
I’m on to chapter 2 now, which is all about sets. Lots of definitions so far, but it’s all making sense. I’m really looking forward to getting through the rest of the book and giving myself a more solid foundation in math.
If you don’t have a formal mathematics education, or need to brush up on what you do have, I highly recommend this book.