
Learn Physics by Programming in Haskell - jxub
https://arxiv.org/abs/1412.4880
======
alew1
Bootstrap is working on a high school physics curriculum for ninth graders,
which integrates functional programming as a fundamental component. They only
have a landing page up at the moment [0], but I attended a very cool workshop
they gave this summer. They’ve designed the programming language to avoid any
“incidental complexity”—Physics teachers only have to teach the CS that’s
absolutely necessary for the physics education goals they’re trying to
achieve.

[0]
[http://www.bootstrapworld.org/materials/spring2018/courses/p...](http://www.bootstrapworld.org/materials/spring2018/courses/physics/)

~~~
nikofeyn
as a note for others, the programming language they developed and use is
pyret.

[https://www.pyret.org](https://www.pyret.org)

------
amelius
Related: [https://mitpress.mit.edu/books/functional-differential-
geome...](https://mitpress.mit.edu/books/functional-differential-geometry)

~~~
privong
There's also this one, "Structure and Interpretation of Classical Mechanics"
(by the same authors): [https://mitpress.mit.edu/books/structure-and-
interpretation-...](https://mitpress.mit.edu/books/structure-and-
interpretation-classical-mechanics-0)

~~~
wirrbel
I had ordered one of those books (don't really remember which of them), and it
is to this day the only book I sent back to amazon for a refund.

~~~
tntn
ok?

This comment doesn't really tell us much. Was the book missing its cover? Did
you not realize what the book was about? Did you dislike the presentation
style?

~~~
wirrbel
okay, I dug up my amazon review again. It was "Functional Differential
Geometry" and my main complaint was, that they claim to replace a fuzzy
mathematical notation with a Scheme DSL which would make things more clear. In
the end, it all felt like they replaced mathematical notation with one that
THEY were just more familiar.

I am a scheme/lisp/clojure fan by heart, so it definitely wasn't the parens.

------
kuwze
There is also the sequel “Learn Quantum Mechanics with Haskell”[0].

[0]: [https://arxiv.org/abs/1611.09471](https://arxiv.org/abs/1611.09471)

------
privong
The haskell library is here: [https://github.com/walck/learn-
physics](https://github.com/walck/learn-physics)
[https://hackage.haskell.org/package/learn-
physics](https://hackage.haskell.org/package/learn-physics)

~~~
ivan_ah
Wow this is beautiful! The "main" equation for the physics of projectile
motion is less than 10 lines of code: [https://github.com/walck/learn-
physics/blob/master/examples/...](https://github.com/walck/learn-
physics/blob/master/examples/src/Projectile.hs#L25)

The "state" of the system St is defined here [https://github.com/walck/learn-
physics/blob/f6ce9bbaece24f48...](https://github.com/walck/learn-
physics/blob/f6ce9bbaece24f481f170bb72b8c6b10500ee383/src/Physics/Learn/Mechanics.hs#L110)
It's amazing to see code and implementation details that match the physics
language.

I wonder if this codebase is ELM-able? i.e. does it use any specific features
from Haskell that are not in ELM? I'd love to see this in the browser. Weekend
project anyone?

~~~
efnx
Typeclasses - thought you could use that whole dictionary work around, or
write namespaced variants.

------
JoshMnem
"Learn <subject> by Programming in <language>" would be a popular series of
books. I hope someone writes them.

~~~
GuiA
I recommend “Music for geeks and nerds”, which is an intro to music
theory/composition with python

[https://pedrokroger.net/mfgan/](https://pedrokroger.net/mfgan/)

~~~
JoshMnem
Looks interesting. Music theory and harmony would be good topics to approach
with computers.

I think that there could be books on poetry (analyze meters, language, cross-
references, symbolism, poet connections), literature, biology, math,
psychology, sociology, economics, ecology, chemistry, etc. through
programming.

Some of those exist, but there should be more.

------
77pt77
So the Haskell version of [1] (in scheme)

[1]
[https://en.wikipedia.org/wiki/Structure_and_Interpretation_o...](https://en.wikipedia.org/wiki/Structure_and_Interpretation_of_Classical_Mechanics)

[Free book]
[https://mitpress.mit.edu/sites/default/files/titles/content/...](https://mitpress.mit.edu/sites/default/files/titles/content/sicm_edition_2/book.html)

~~~
bringtheaction
Never heard of that book. I enjoyed SICP a lot so if this is anything like
SICP was then I would be very happy.

~~~
tchow
Can you share your experience with sicp? I'm self taught in JavaScript, go,
python, ruby and taken Coursera for algorithms and read up on the operating
system. Will sicp help me?

~~~
emmelaich
One odd thing for me was that example problems seem to taken from physics and
engineering. Which is natural for the authors and the time -- computer science
departments typically started out as part of the Physics or Engineering
departments.

One of the first examples is Newton's method for approximation. Which many
beginning programmers have never encountered.

~~~
Jtsummers
In particular CS at MIT ~was~is in the EECS department. MIT also begins with
calculus (18.01), not algebra or pre-calculus or anything else. Newton's
method, at least in my undergrad (Georgia Tech, not MIT), did introduce
Newton's method at some point (I cannot remember the context, but I do
remember it in my first or second calculus course). Since SICP students would
have taken or be taking Calculus at the same time, it wouldn't be a stretch
for them to have seen those sorts of problems already.

~~~
nikofeyn
cs at mit _is_ in the eecs department.

~~~
Jtsummers
Oops, yeah. That wasn't supposed to be past tense.

~~~
nikofeyn
haha. no worries. :)

------
pducks32
As a physicist I really really enjoyed this. Really cool. I have a swift
library (using Foundation’s Measurement API) that I use for so much of my
calculations and the one really important thing that has helped me solve
problems is the type system. Units are types and I see a lot of young
physicists students make mistakes where if they just looked at the units
they’d have gotten it right. Physics is some sense just dimensional analysis.
This library would be great if it were able to add unit types to really ensure
that people understand _why_ a formula is the way it is.

------
huntie
Somewhat related, does anyone have a reccomendation for learning Newtonian
Physics? I took a semester as an undergrad, but I didn't understand it as well
as I would like.

~~~
mhh__
Feynman lectures -> Landau Lifshitz, when you can make the jump.

This will show you how to do the physics, then (Landau Lifshitz) show you how
to reformulate this physics (again, it is actually in the feynman lectures
too) in the terms we use in modern physics (Variational methods etc.)

~~~
contact_fusion
Feynman lectures are excellent for physical intuition but if someone doesn't
have a few years of practice with physics it will be difficult to get much out
of it. Feynman also doesn't have a lot in the way of problem solving, even
with the companion problem solving book.

With that in mind, Landau/Lifshitz is an entirely different class. I'm a
practicing astrophysical theorist and I would never claim to have grokked
these volumes in anything nearing completeness. A serious post-PhD program of
study can be undertaken to understand to the finer points of those books; this
is a pursuit that would challenge any practitioner. (I place _Physics of Shock
Waves and High Temperature Hydrodynamic Phenomena_ by Zel'dovich and Razier in
the same category of extremely information dense Soviet tracts on physics.)
They are incredibly valuable, although I do think there is a bit of an element
of "if you don't know L/L, you aren't a _real_ theorist."

I think that recommending these texts is great for someone down the road, but
if someone hasn't even had a full year of intro physics recommending these is
not appropriate. Intro-level textbooks exist for a reason - not all of them
are cheap, watered down versions of the "real stuff." (Some are, of course.)
There are also some texts I've found (but don't remember, unfortunately) in
the computer vision community that introduce some physics that would be great
for someone with a computer science/engineering background.

edit: "cheap" as in "cheap feeling" not inexpensive, as most of those intro
texts are more expensive than the graduate level

~~~
mhh__
The first L&L book is what I'm thinking of: It's actually pretty manageable.
I'm talking out of my ass beyond here in the series, I don't have any others
in physical form so I've read bits of QM and _The classical theory of fields_

The downside to them is that they don't come into contact with the
"mathematical" physics side e.g. Treatment of Lagrangian/Hamiltonian formalism
through differential geometry.

------
voidmain
Matter and Interactions [1] is a great introductory physics course that (among
other innovations) makes extensive use of simple simulations (by students).

Here [2] is an example of a program, complete with 3D graphics.

[1] [https://matterandinteractions.org/](https://matterandinteractions.org/)

[2]
[http://www.glowscript.org/#/user/GlowScriptDemos/folder/Exam...](http://www.glowscript.org/#/user/GlowScriptDemos/folder/Examples/program/BinaryStar-
VPython/edit)

------
nickpsecurity
" In electromagnetic theory, the type signatures of functions that calculate
electric and magnetic fields clearly express the functional dependency on the
charge and current distributions that produce the fields"

Maybe a student learning this will go on to make a HDL for analog circuits in
Haskell that are easier to get correct or simulate for being in Haskell. Prior
work includes using Haskell for digital design (i.e. Bluespec) and non-Haskell
HDL's for analog components. There's definitely more possibilities for
developing or modelling electronics in Haskell. :)

------
Maro
I've seen this before and it's terrible. Haskell's type system is terrible for
this, ie. instead of plain vanilla operator overloading they have (^+^)... I
once played around with a way to automatically track units when writing code
like this, and I gave up on Haskell, doing it in C++ was much easier/sane.

[https://github.com/mtrencseni/physcode](https://github.com/mtrencseni/physcode)

~~~
runeks
> Haskell's type system is terrible for this, ie. instead of plain vanilla
> operator overloading they have (^+^)...

Haskell’s type system does not prevent you from overloading the + operator.
It’s the standard library (“Prelude”) that defines + to only work on numbers,
and not on vectors, but with Haskell’s type system allows you to define + to
do anything you want.

~~~
tome
Yes indeed. Not only is it possible to overload + but Haskell's _type system_
has absolutely nothing to say on the matter.

~~~
Maro
Yes but if you want to use libs, and they don't do it this way, you're f--ked.
This is one of the things I ran into.

~~~
dllthomas
Well, no, you're not "f--ked", there's just a pile of boilerplate. Not fun -
and likely not worth it for the marginal benefit of being able to reuse + that
way - but plenty possible.

And for what it's worth, I certainly agree that the way Num is structured is a
wart in Haskell, and I think the previous two commenters agree. It's just that
we should be clear about where the blame lies - and that's not the type
system.

------
jonjacky
This 1994 paper (using Scheme) might be pertinent:

Fields in Physics are like Curried Functions or Physics for Functional
Programmers:
[http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.49.1...](http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.49.1181)

------
mhh__
I find this is more of a distraction than abstraction at the moment, to be
honest.

How would this approach generalize to more modern physics?

------
anonytrary
Haskell seems to be the language to learn if you're into physics, math and
blockchains. I feel exactly like I did right before I became a web developer.
I felt it was a no-brainer to learn Javascript. Is Haskell a no-brainer for
2025?

------
pankajdoharey
Very interesting Paper, though i would really want to see if games like
Besiege could actually be used to teach classical Physics.

------
garfieldnate
Are the lecture notes for the class available anywhere?

