If you’re a mathy type and want to get into some computer programming, or if you’re a computer person but want to learn what kinds of math you can do with code, a new book out from No Starch Press will help you achieve those goals. It’s also perfect for doing with your kids, or just diving into yourself.
Math Adventures With Python: An Illustrated Guide to Exploring Math With Code by Peter Farrell takes you through how to do both basic and more involved math using the Python language. This book sounded a bit intimidating to me at first since I knew no Python. I do have a decent math and programming background from college, but that was 25 years ago. And I was sure that Python was different from my old standbys, Pascal and C++. Could I learn Python using this book? Would I be lost? I needn’t have worried. I felt guided and supported from page 1.
Math Adventures With Python takes users through, step by step, how to install Python 3 on their machines and how to use the programming interface. You start by installing Python 3 itself (it’s called IDLE when you run it, after Eric Idle of Monty Python, of course), and also installing a processor application (called Processing) for graphics and interactivity. It sounds more complicated than it is. Just follow the instructions and you’ll be fine. I’m not sure what I was expecting in terms of an interface, but I thought it would be more graphics heavy. It looks just like a text editor, but it has extra capabilities built in, which appear as you start typing commands.
The lessons then start easy, having you just draw basic lines and create simple outputs, including using the LOGO-style turtle to draw shapes. After you learn how to use loops to draw a square, you jump right into creating your own functions. Then, after you’ve learned a few more things, the book challenges you to apply what you’ve learned so far to implement something new that you aren’t given explicit instructions for. It’s a great method for learning.
Complexity of topics and lessons ramps up slowly and logically, gradually covering such topics as:
- Drawing polygons
- Doing arithmetic with lists and loops
- Using conditionals
- Make similar shapes
- Trigonometry and triangles
- Taking user input
- Graphing equations
- Using colors
- Animating objects
- Learning data types such as integers, floats, strings, and Booleans
- Using a circle to draw sine waves
- Creating your own Spirograph
- Complex numbers
- Solving systems of equations with matrices (including Gaussian Elimination!)
- Building objects with classes
- Creating fractals, including with color, both with and without recursion
- Cellular automata
- Genetic algorithms
I especially enjoyed the fractals section, learning to create the Mandelbrot set, then the Julia set. I spent hours playing with Fractint as a teenager, so I enjoyed seeing the computations behind these fractals. Adding in recursion, the book also helps you create fractal-based trees, Koch snowflakes, the Sierpinski triangle, and more.
You then learn how to build your own sheep grazing simulation!
The book not only shows you how to implement math concepts in a coding environment, it also describes why we do or would want to do certain math tasks. As you go, it explains what all of the Python commands are and how to use them. It’s a very detailed and informative book, and will teach you how to implement sometimes complicated math concepts in Python by the time you’re done going through it. It’s easy to find your way around the book since it has two tables of contents: one for at-a-glance navigation, and one in more detail, which breaks the book down almost page by page. There is also an index.
Though having programming experience of any kind is helpful when working through the book since it makes the learning curve more gradual, anyone who can follow directions and think critically will be able to learn everything the book has to offer. Those users new to Python, though, will want to work through this book from front to back, since the lessons build on each other.
Even though this was my first real introduction to the Python language, my background in programming and math was helpful for me to understand what they were trying to accomplish. But that kind of background definitely isn’t necessary for understanding the book and following its detailed instructions; it breaks the projects down into small steps, helping those working through the book see almost instant results, including kids (though parents may need to do the program installation to get things started).
If you love math and have always wanted to dig deeper while using computer programs to implement some fun math-based projects, Math Adventures With Python is the perfect book for you. Though it does help a bit to have even a modest background in higher math (post-arithmetic) and computer programming basics, any patient student, probably high school age to adult, will feel like they have enough guidance to go from directing a turtle to draw a basic square, all the way to creating gorgeous, colorful fractals. This book steps you through everything you need to do and know, and it will empower you to create program variations and play around with your newfound toolset. I recommend it highly.
Note: I received a copy of this book for review purposes, but all nostalgia for my math and computer science days are all my own.