Python for Mathematics Book

Over the weekend, I received my author copies of Python for Mathematics.

As I posted over on Mastodon:

I’m quite proud of this book. It’s the result of learning from the Python community and from years of working with first-year mathematics students.

The publisher was great and worked with me to ensure there’s an online version of the book, which you can find (in its current form) here: https://vknight.org/pfm/cover.html.
That version still needs a bit of updating — getting the print version ready took priority — but I’ll be sorting that out soon.

In the opening chapter (which isn’t yet updated online), I talk about how this book takes a different route than most programming texts. It essentially flips the usual order in which topics are introduced:

A traditional structure might look more like this:

  1. Using Notebooks
  2. Variables – covered in Chapter 10
  3. Conditionals – also in Chapter 10
  4. Loops – again, Chapter 10
  5. Functions – covered in Chapter 11
  6. Data structures – also in Chapter 11
  7. Recursion – Chapter 7
  8. Objects – Chapter 12
  9. SymPy – drawing on content from Chapters 2–4 and 9
  10. Combinatorics – Chapter 5
  11. Probability – Chapter 6
  12. Statistics – Chapter 8
  13. Command line – Chapter 13
  14. Modularisation – Chapter 14
  15. Documentation – Chapter 15
  16. Testing – Chapter 16

Instead, the book takes this different path on purpose:

“The choice to flip this structure and start with real use cases (and not code recipes) is deliberate.
The tools covered in Chapters 2 to 9 can be used with little to no programming knowledge — they mostly require just some maths.”

“After that, the programming basics in Chapters 10 to 12 help build on that experience,
and the topics in Chapters 13 to 16 give a taste of how modern research software is built.”

This structure reflects how my own approach to teaching programming has evolved. Rather than starting with the basics and asking students to believe that these abstract pieces will come together eventually, I try to start by showing what’s already possible — right now — using powerful, existing tools.

Another way to frame it might be: I’m not flipping the structure at all. I’m just starting with the bit that’s often missing.

And one more point about this book:

I don’t think universities should (ethically) be teaching commercial software —
I’ll write up more thoughts on that at some point.

But really, we don’t have to — at least not in my field (others may vary).
The tools in this book are freely available, easy to use, and just as powerful.
I don’t even go into some of the other incredible tools out there like SageMath,
or domain-specific libraries like Ciw for queuing processes.