11 ms·
Learn Physics with Functional Programming
- daft_pink 3y agoI'd love a book like this written in Python. Just feedback. I clicked the link and was about to purchase this. The idea of learning physics sounds great. The idea of spending time learning a new programming language that I'm unlikely to use for anything else sounds terrible.
- tobinfricke 3y agoI had the opposite reaction. I already know physics, but I want to learn Haskell.
- daft_pink 3y agoMaybe I will take the plunge. Is there any real value to learning Haskell? There are so many different things I’d love to study.
- michaelsbradley 3y ago[flagged]
- nequo 3y agoThis is a very valid consideration. At the least, Haskell is much faster than Python, the language itself is not that complicated (learning a whole new ecosystem is a different story), FP might lend itself better to translating physics into code, and some elements of it carry over to other languages, for example, type classes and Rust’s traits.
- petemir 3y ago> and some elements of it carry over to other languages, for example, type classes and Rust’s traits. Add react to the list
- acchow 3y ago> the language itself is not that complicated I find Haskell quite complicated, involving abstract concepts you would likely not consciously encounter in other languages (lenses, monad transformers, free monads, etc).
- nequo 3y agoLenses and monad transformers are libraries, not part of the language. It doesn't look like the book uses them, so you don't need to understand them in order to follow it: https://nostarch.com/learn-physics-functional-programming https://nostarch.com/learn-physics-functional-programming
- deleted 3y ago[deleted]
- itishappy 3y agoIt doesn't need to be. You can do so much with just data declarations and typeclasses. https://www.simplehaskell.org/ https://www.simplehaskell.org/ (disclaimer: not a huge fan of the sight design, but I fully support the concept)
- weatherlight 3y agoI get your reluctance to dive into a new language just for one project. But here's the deal: Haskell's strong type system and emphasis on pure functions can actually make you a better programmer in any language. Its lazy evaluation is a unique feature that optimizes performance, and it's built with concurrency in mind. Plus, in Haskell, you really can't cheat your way out of functional programming. The language enforces it, so the code you write will be functional, unlike in Python where you can mix paradigms. Even if you're a Python devotee, the principles you'll learn from Haskell can offer a new lens for problem-solving. It's not just about learning a new language; it's about broadening your skill set.
- 7thaccount 3y agoThere's always some value in learning a new paradigm, but Haskell always felt less useful to me than learning other tools and esoteric technologies. That's a personal belief though and it's subjective. Some people love Haskell and get a lot of power from it. Python mostly hits an optimal point for my needs though and I didn't have to read 50 articles trying to explain what a Monad was. Scripting languages just click a lot better for me (less ceremony). There are some weird languages I like such as APL. APL is also very mathy, but there's essentially no ceremony (just some funny symbols that are easy enough to learn).
- chowells 3y agoAh. You found Haskell hard because you were trying to learn it out of order. Demanding to understand what a monad is before learning how higher-order functions and higher-kinded polymorphism work in Haskell is like demanding to know what an Iterator is before learning what a variable is in Java. The thing about "Monad" is that it's an absolutely trivial interface. You'll know you actually understand it properly when you go "oh, that's all." Is it hard to describe? Not when you understand the underlying concepts. But if you demand to skip them, you're only going to confuse yourself.
- appleaday1 3y agohttps://bartoszmilewski.com/2021/02/16/functorio/ https://bartoszmilewski.com/2021/02/16/functorio/
- 7thaccount 3y agoNo, but a good assumption. I read several books and dozens of tutorials including parts of the 1000 page one that couple did like 6 years ago. Function application and so on definitely came before IO and the likes. It all just seemed like enormous mental effort for the simplest of things. That was my experience at least. It's possible I just don't have the best kind of brain for FP. Your mileage will vary of course. This was just my experience. I know Haskell is powerful, but it wasn't right for me. I haven't met a scripting language I didn't like yet though, so perhaps my neurons are just wired for that now. I do enjoy the random APL or Forth problem though and I'm decent at SQL after using it often for a decade.
- adamddev1 3y agoYes, I benefited greatly from learning Haskell. Found myself writing beautiful new abstractions in TypeScript based on what I learned. I suggest going through https://haskell.mooc.fi/ https://haskell.mooc.fi/ to learn. Beyond the practical value you'll also discover the delightful beauty with which you can express things in Haskell, and these sparks of joy could give you a new motivation to grow and appreciate deeper, beautiful ways of coding and thinking.
- forgotpwd16 3y agoAnother win if Python was used will be showing how functional programming is done in Python. That said I'm fine with it being based on Haskell. Presenting a specific programming language doesn't seem to be the main point. Also someone can follow book with Python and typing/mypy as exercise.
- greenie_beans 3y agolearning another programming language that you will never use still has value. it makes you a better python programmer.
- wrycoder 3y agoYou can learn Scheme in two hours. Haskell, not so much. Stick to SICM.
- jmhimara 3y agoI'd be willing to bet there are already books like this for python. Or at least online tutorials. I know for a fact there are python books dedicated to scientific programming, but they probably assume some knowledge of science and focus more on the codding aspect.
- deleted 3y ago[deleted]
- i_don_t_know 3y agoI’m working my way through a German book that explores Physics with Python: https://pyph.de/1/2/index.php?name=intro https://pyph.de/1/2/index.php?name=intro
- MissingAFew 3y agoFunny, I was thinking of doing just this exact thing to learn haskell.
- footy 3y agoThis is an incredibly cool concept and I would have loved to have this book when I was in undergrad (for Physics).
- noelwelsh 3y agoSounds similar to https://tgvaughan.github.io/sicm/toc.html https://tgvaughan.github.io/sicm/toc.html Should be fun if you're physics inclined.
- tobinfricke 3y agoOfficial version: https://mitp-content-server.mit.edu/books/content/sectbyfn/books_pres_0/9579/sicm_edition_2.zip/book.html https://mitp-content-server.mit.edu/books/content/sectbyfn/b... I'd really like to see a "spiritual successor" to Structure and Interpretation of Classical Mechanics--something that can take off and achieve a life of its own. SICM is open-source, and many people have implemented their own versions of parts of it, but I would love to see a vibrant and active community develop around such a beautiful computer algebra / computer-physics system. SICM goes far beyond simple Newtonian mechanics, implementing calculus, Lagrangian and Hamiltonian mechanics, and differential geometry, and probably a whole lot more that you just have to spelunk into the source code to discover. (Here's a book about the differential geometry implementation in scmutils: https://mitpress.mit.edu/9780262019347/functional-differential-geometry/ https://mitpress.mit.edu/9780262019347/functional-differenti... as seen in HN: https://news.ycombinator.com/item?id=7884551 https://news.ycombinator.com/item?id=7884551 )
- lrc 3y agoHave a look at Emmy: https://emmy.mentat.org https://emmy.mentat.org
- lvk 3y agoAre there any other systems that can render programmatic equations to LaTeX?
- nequo 3y agoSymPy[1] and Mathematica[2] can both render expressions in LaTeX, if this is what you mean. [1] https://docs.sympy.org/latest/tutorials/intro-tutorial/printing.html https://docs.sympy.org/latest/tutorials/intro-tutorial/print... [2] https://reference.wolfram.com/language/ref/TeXForm.html https://reference.wolfram.com/language/ref/TeXForm.html
- archarios 3y agoCalculus makes a lot more sense to me as code so this seems promising :D
- tobinfricke 3y agoDoes this implement symbolic algebra/calculus, or is it entirely numerical?
- tikhonj 3y agoNo idea if this book does it, but this seems like a perfect fit for automatic differentiation. You can get a simple implementation of automatic differentiation for one dimension in a small amount of surprisingly clear code, without needing to pull in any dependencies or extraneous concepts.
- tobinfricke 3y agoThat is along the lines of the motivation for my question. Automatic differentiation is such a natural fit with Haskell...
- lagrange77 3y ago> this seems like a perfect fit for automatic differentiation. Why?
- tikhonj 3y agoIt would let you represent physical systems as normal Haskell functions and get accurate derivatives "for free". At least in the one-dimensional case it's probably simpler than numeric differentiation while also letting you worry far less about accuracy and stability. I've never worked this through to a full conclusion, but you could even write it in a way that would let you get symbolic differentiation out of it too.
- lagrange77 3y agoMakes sense. I initially thought, that automatic differentiation would be mostly useful for long derivative chains, but of course even for single derivatives it does have advantages.
- sritchie 3y ago
- galp76 3y agoI have been looking for a excuse to try again to learn Haskell. Also looking for some interesting book to learn material in order to try to get my son interested in science. Thanks for this.
- Pet_Ant 3y agoI wish the title said "Haskell" instead of "Function Programming". I mean the two aren't interchangeable. Was actually hoping for Clojure personally.
- deleted 3y ago[deleted]
- ogogmad 3y agoExpressing physics with more rigorous mathematical or computational formalism might be good: For instance, a force is a triple (sending object, receiving object, force vector). Newton's third law says that whenever there is a force (S,R,F), then there is another force (R,S,-F). Also, this makes clear that Newton's 2nd law is not a definition of force, because it misses out on two of the three components of a force triple (-- by the way, is there a formal term for what I'm calling a force triple?)
- lagrange77 3y agoYes and it could help with a shortcoming of traditional representations of physical phenomena: defining cause and effect.
- alex_lav 3y agoHow much of either do I need to know to find value out of this book?
- tobinfricke 3y agoIt appears to be an elementary introduction to both. It appears that no prior physics knowledge is needed.
- latenightcoding 3y agoStructure and Interpretation of Classical Mechanics published in 2001 uses Scheme (There is a second edition released more recently)
- hcarvalhoalves 3y agoSee also: https://nextjournal.com/try/samritchie/sicmutils https://nextjournal.com/try/samritchie/sicmutils
- deleted 3y ago[deleted]
- deleted 3y ago[deleted]
- bumbledraven 3y agoI would like to see Learn Physics with APL.
- trenchgun 3y agoAbsolutely! I did find this. "Working with APL for Physics Research - Kostas Blekos - Dyalog '17" https://www.youtube.com/watch?v=pWtvRlCdX00 https://www.youtube.com/watch?v=pWtvRlCdX00 Would be interested in reading a more detailed account.
- bowsamic 3y agoI feel like the screenshots don’t make the book seem particularly novel or interesting
- hatmatrix 3y agoJulia might have been more practical - also has a type system, symbolic computing, automatic differentiation, etc. And maybe just functional enough.
- jalino23 3y agoexcept its not 0 index!
- hatmatrix 3y agoFor translating mathematics to code, in most (but not all cases) more relevant to have 1-indexing.
- george_____t 3y agoWhat's impractical about Haskell?
- roguas 3y agomoonads
- poulpy123 3y agoDoes it really teach physics or does it teach Haskell through the way of physics equations?
- zare_st 3y agoOrdered from Amazon, thx.
- ngcc_hk 3y agoI am actually studying special relativity and found Jupyter Notebook plus some simple plot helps a lot. I did search Common Lisp as reading python code is hard. A mess for the one doing Lorentz trnasformation. End up I have to do it myself. This is different I suspect if it is in common lisp as it usually can be read, understood and use. Sadly for simple realization for example the twin paradox without acceleration (3 astronauts handing over clock info instead of using acelearation). It is not there. And doing graphic … and simple wedge. Sadly. May be someone here can highlight some sites for this and that. For chapter 14 I wonder whether a Jupiter notebook (which can do Tex if using Matplotlib … have not tested it as I used texshop and screen capture from Matplotlib instead).
- 1-6 3y agoAfter learning Physics with FP, you can help with Modelica!
- nyrikki 3y agoIs there an effective way of dealing with anti-commutative algebras like the geometric product in a functional model? Obviously total functional programming is a problem. But the GP greatly simplifies electrodynamics and removing the need to track handedness in your basis is very helpful in my experience.