8 ms·
Learn Physics by Programming in Haskell
- amelius 9y agoRelated: https://mitpress.mit.edu/books/functional-differential-geometry https://mitpress.mit.edu/books/functional-differential-geome...
- privong 9y agoThere's also this one, "Structure and Interpretation of Classical Mechanics" (by the same authors): https://mitpress.mit.edu/books/structure-and-interpretation-classical-mechanics-0 https://mitpress.mit.edu/books/structure-and-interpretation-...
- hnarayanan 9y agoAnd here are some source files and setup notes for the underlying SICM scheme library pertinent to macOS: https://github.com/hnarayanan/sicm https://github.com/hnarayanan/sicm
- wirrbel 9y agoI 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 9y agook? 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?
- abecedarius 9y agoI actually did the same with SICM, because it arrived with some of the pages stuck together. In the chapter on rigid body dynamics, as it happens. (This really did occur, but it was just glue.)
- wirrbel 9y agookay, 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.
- BaryonBundle 9y agoAnd the previous HN discussion on this exact topic had some good notes: https://news.ycombinator.com/item?id=9003898 https://news.ycombinator.com/item?id=9003898
- sitkack 9y agoA great book that walks the reader through simulations to learn Physics is, "From Newton to Mandelbrot". [0] [0] https://www.amazon.com/Newton-Mandelbrot-Theoretical-Physics-Graduate/dp/3662536838 https://www.amazon.com/Newton-Mandelbrot-Theoretical-Physics...
- privong 9y agoThe 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 9y agoWow 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/src/Projectile.hs#L25 https://github.com/walck/learn-physics/blob/master/examples/... The "state" of the system St is defined here https://github.com/walck/learn-physics/blob/f6ce9bbaece24f481f170bb72b8c6b10500ee383/src/Physics/Learn/Mechanics.hs#L110 https://github.com/walck/learn-physics/blob/f6ce9bbaece24f48... 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?
- huntie 9y agoSomewhat 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.
- lymitshn 9y agoYou can take a look at Feynman lecture notes at caltech.edu.
- Disolation 9y agoIf you want a good textbook, try David Morin's "Introduction to Classical Mechanics: With Problems and Solutions". Rather rigorous book with a good writing style and a lot of exercises.
- sitkack 9y agoMentioned in another branch of this discussion, but I really liked "From Newton to Mandelbrot" for a computational take on learning Physics.
- mhh__ 9y agoFeynman 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 9y agoFeynman 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
- Maro 9y agoI'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
- thepratt 9y agoThere isn't operator overloading as other languages have it, but you can write instances for your types. It seems you're just complaining about using vector addition operator (^+^) instead of a different addition operator (+); if it bothered you that much an instance would create a link defining + as ^+^.
- marcosdumay 9y ago> but you can write instances for your types Yes, as long as they have the structure your classes demand. It's not exactly Haskell's type system that is bad, it's the numeric classes that are a bit of a mess. Math has a much cleaner structure that, for example, does not demand that you can convert any integral value into an instance of your numbers. Haskell tried to simplify it, but wasn't successful.
- KirinDave 9y agoYou say it's terrible to use an alternative operator but then don't really say why Why is that bad? In Haskell, + is reserved for Num, which require some other properties that you can't guarantee for vectors. It'd be pretty bad to run afoul of that in a physics conversation. Haskell certainly can let the + operator mean multiple things in multiple contexts.
- runeks 9y ago> 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.
- kuwze 9y agoThere is also the sequel “Learn Quantum Mechanics with Haskell”[0]. [0]: https://arxiv.org/abs/1611.09471 https://arxiv.org/abs/1611.09471
- 77pt77 9y agoSo the Haskell version of [1] (in scheme) [1] https://en.wikipedia.org/wiki/Structure_and_Interpretation_of_Classical_Mechanics https://en.wikipedia.org/wiki/Structure_and_Interpretation_o... [Free book] https://mitpress.mit.edu/sites/default/files/titles/content/sicm_edition_2/book.html https://mitpress.mit.edu/sites/default/files/titles/content/...
- bringtheaction 9y agoNever heard of that book. I enjoyed SICP a lot so if this is anything like SICP was then I would be very happy.
- tchow 9y agoCan 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?
- professor_plum 9y agoYou might in fact love it. You'll get a nice overview of how interpreters actually work, for one thing.
- fsloth 9y agoI would recommend anyone who has not implemented an interpreter to implement the scheme interpreter in sicp (in any language of their choosing). At heart sicp is not about scheme but about computation systems in general and at that it's the most elegant book I've come across.
- Buttons840 9y agoSICP lives up to the hype in my experience. The pacing is perfect. It will take awhile to work through though. I'd suggest planning to skip some exercises and pick them up on a second read. Don't let yourself get bogged down and lose motivation over one exercise.
- 9y ago
- alew1 9y agoBootstrap 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/physics/ http://www.bootstrapworld.org/materials/spring2018/courses/p...
- nikofeyn 9y agoas a note for others, the programming language they developed and use is pyret. https://www.pyret.org https://www.pyret.org
- nickpsecurity 9y ago" 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. :)
- JoshMnem 9y ago"Learn <subject> by Programming in <language>" would be a popular series of books. I hope someone writes them.
- GuiA 9y agoI 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 9y agoLooks 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.
- JoelMcCracken 9y agoWow, this sounds so good. Please someone, more like this.
- jonjacky 9y agoThis 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.1181 http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.49.1...
- pducks32 9y agoAs 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.
- mhh__ 9y agoI 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 9y agoHaskell 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?
- voidmain 9y agoMatter 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/Examples/program/BinaryStar-VPython/edit http://www.glowscript.org/#/user/GlowScriptDemos/folder/Exam...
- garfieldnate 9y agoAre the lecture notes for the class available anywhere?
- pankajdoharey 9y agoVery interesting Paper, though i would really want to see if games like Besiege could actually be used to teach classical Physics.