[book] Learn Physics with Functional Programming

A book about learning physics with Haskell is on Hacker News front page today, the book appears to be from 2022. Has anyone read it? How is it?

HN link Learn Physics with Functional Programming | Hacker News

Book itself Learn Physics with Functional Programming | No Starch Press

15 Likes

I haven’t read it, but I have seen the author (Scott Walck) give a talk about it. I can say that he seems to have thought deeply about how to express various physics concepts as a typed DSL in a way that encodes/enforces relevant invariants. So the fact that it is in Haskell is really essential to the way the material is presented. I’m pretty sure Scott also actively uses this material in his own teaching.

4 Likes

Gone through most of the book. I think its a great book and am enjoying it. It’s based on the authors years of experience teaching computational physics. There’s something beautiful about using fp/haskell to express physics ideas. Note that the emphasis is on classical newtonian mechanics and electromagnetic theory, therefore the haskell used is quite simple. Gloss is used for simulation and visualization.

7 Likes

I read a draft of the book and talked with Scott a little bit while it was coming to publication. I think it’s an incredibly well written book and it was really fun to work through. He was partially inspired by Gerry Sussman and Jack Wisdom’s book Structure and Interpretation of Classical Mechanics, but obviously using Haskell over Scheme gives the benefits of types, and types are central to how he presents the material. SICM is also really great, I should say, but it’s aimed at a higher level (a second course, Lagrangian and Hamiltonian formulation of mechanics) instead of the “hopefully you’ve seen physics before but let’s work through it in a different way” style that Scott’s book uses. Unfortunately, the quantum mechanics sections didn’t make it into the book, but I think notes from his class on those sections still exist on his website.

Edit: See these two preprints:

Learn Physics by Programming in Haskell

Learn Quantum Mechanics with Haskell

8 Likes

Does the book treat physical quantities as categories and physical units as functors?

if someone is interested in this kinda books, i also want to recommend “Domain Specific Languages for Mathematician”. It’s used as a teaching material for second-year college student in chalmers. It also has accompanying youtube videos online.

3 Likes

@rubenmoor you can have a look at the related source code here : [GitHub - walck/learn-physics: A library of functions for vector calculus, calculation of electric field, electric flux, magnetic field, and other quantities in mechanics and electromagnetic theory.]

1 Like