Live data from Hacker News

Learn Physics by Programming in Haskell [pdf]

arxiv.org

31–40 of 56 posts

Re: Learn Physics by Programming in Haskell [pdf]

#31
post #13
post #8

"One obvious use of types in physics that we have not explored in this work is the expression of physical dimensions (length, mass, time) and units (meter, kilogram, second). ...This is not trivial to do with Haskell’s type system because one wants multiplication to “multiply the units” as well as the numbers." F# supports units: https://msdn.microsoft.com/en-us/library/dd233243.aspx

And note that there is no way to resolve this without some fundamental changes as Haskell requires that the two operands and the resultant type share a type. (Otherwise you could do some tricks with recursive types to accomplish this)

>Haskell requires that the two operands and the resultant type share a type.

Most physical unit libraries simply describe a "unit-ed" multiplication/division/etc operator, so you write code like

    let v = (5 ~* meter) / (1 *~ second)

This division operator would replace the standard one.

This requires using Haskell extensions that support dependent types, but the libraries certainly exist.

I've used "Dimensional" before.

Re: Learn Physics by Programming in Haskell [pdf]

#32
The thing is from my experience, most computational individuals would be strongly opposed to FP. They may not have been raised on for loops, but once they learn about for, good luck on having them warm up to the idea of map and reduce.

I think the only way you'd succeed is by snatching their young before they go down that path. I don't really see many people warming up to new things aimed at them like Julia or even not-so-new stuff like numpy/matplotlib and friends. If it isn't Fortran or C or matlab, it doesn't ring well with them. Of course, the new kids who don't know programming (or physics yet, perhaps) are ripe for indoctrination of your religion as opposed to theirs.

Re: Learn Physics by Programming in Haskell [pdf]

#33

The thing is from my experience, most computational individuals would be strongly opposed to FP. They may not have been raised on for loops, but once they learn about for, good luck on having them warm up to the idea of map and reduce. I think the only way you'd succeed is by snatching their young before they go down that path. I don't really see many people warming up to new things aimed at them like Julia or even n…

I'm not sure this is a bad thing. The criticism of C and its counterparts is valid in some respects, but I think the dogmatic views of FP proponents overstep the bounds of what is justified in many situations. Often a more procedural solution maps better to the problem at hand than a recursive or functional one would.

Just to clarify: I'm not anti-FP in any way. I've implemented some fairly large projects in OCaml and like the language a lot, however, I don't think FP supersedes more traditional programming styles in all (or even many) cases.

I expect some people to disagree with me and I'd love to hear why! I put my viewpoints forward not to say that they're the absolute truth but more to get responses from other people. I'd be more than happy to chance my opinions if given compelling evidence.

Re: Learn Physics by Programming in Haskell [pdf]

#34
post #27

I'm a physics sophomore, and I would be very glad to see more programming, especially FP, integrated to physics courses. During my studies, I've programmed some simulations related to the physics courses I've taken. My main purpose has been to gain a deeper, more practical insight on the subject which would've otherwise remained quite theoretical and distant. For example, I made a little rollercoaster simulation to d…

Have a look at the Matter & Interactions textbook by Chabay and Sherwood. It's a really cool concept for a first-year physics course, and it incorporates a lot of programming (and even just programming-inspired perspectives). (The authors use the "VPython" programming package for easy creation of 3D simulations.)

I'll second this. I took a course using this textbook and it was one of my favorites.

Re: Learn Physics by Programming in Haskell [pdf]

#35
I think the problem with this sort of thing is it doesn't capture the beauty and elegance of either Haskell or physics. Take the first line

  data Vec = Vec { xComp :: Double
    , yComp :: Double
    , zComp :: Double }
The author has just defined a 3d vector. But there is no "3" in the above because Vec is hardcoded to be three dimensional. The physics student is probably interested in what aspects of physics are special to 3 dimensions, and which generalize to higher dimensions. I think geometric/Clifford algebra somewhat answers this, but my knowledge is limited. Anyway, functional programming is still at the stage when the things that it can express about mathematics, are actually pretty obvious already. I have high hopes for the future (e.g HoTT), but for now functional programming is much more exciting for programmers than physicists or mathematicians (who aren't logicians or category theorists).

Re: Learn Physics by Programming in Haskell [pdf]

#36
post #2

If you're into physics I'd recommend solving some problems using whatever language, but especially functional languages (i.e. Lisps, Haskell, etc.) because you have some big "A-ha!" moments as to what the math really means. Like when you program an integral from scratch for a mechanics problem and you go "Oh that's why we use an integral here!" There are also many problems (i.e. n-body orbital dynamics) where brute-f…

One thing that somewhat turned me away about SICM is that it relies almost entirely on a specific Scheme implementation and Emacs setup.

Edwin (the text editor that comes with MIT-Scheme) is not quite emacs, but when I used it for SICP I kind of liked it...once I figured out the debugger. (edit: that sounded sarcastic, I actually liked Edwin)

Apparently there's an important library for the course called scmutils that the Racket people gave up on porting a while back: http://lists.racket-lang.org/users/archive/2005-October/0099...

Re: Learn Physics by Programming in Haskell [pdf]

#37

Earlier quoted context omitted.

The authors are really onto something with programming as a means to learn other subjects. I think this is because of the precision that programming demands. You have to really nail down every edge case, and think about things down to their essence. This is one reason why programmers can succeed in jumping the fence to work in their customer's jobs, even when it's an unrelated field. (I've seen many programmers make…

I think it's actually as much to do with having to turn syntax and abstraction into something actionable that describes the solution. That is, in programming you learn a small set of abstractions (programming language syntax), and the actual coursework in applying that is in how they combine, how to fit them to problems. In math, you learn a large number of abstractions (notation), that can vary and have new ones acr…

Alternatively, you could just note that your example reduces to 100*(100+1)/2. This simplification decreases cognitive load even more substantially! Taking a strictly programmatic view of a problem allows you to be lazy, and I believe that you lose a lot in the process. There is importance (numerically, even!) in thinking about things in a more formalized, mathematical way.

Re: Learn Physics by Programming in Haskell [pdf]

#38
post #36

Earlier quoted context omitted.

One thing that somewhat turned me away about SICM is that it relies almost entirely on a specific Scheme implementation and Emacs setup.

Edwin (the text editor that comes with MIT-Scheme) is not quite emacs, but when I used it for SICP I kind of liked it...once I figured out the debugger. (edit: that sounded sarcastic, I actually liked Edwin) Apparently there's an important library for the course called scmutils that the Racket people gave up on porting a while back: http://lists.racket-lang.org/users/archive/2005-October/0099...

There is also a port to Guile: http://www.cs.rochester.edu/~gildea/guile-scmutils/

Re: Learn Physics by Programming in Haskell [pdf]

#39
post #24
post #17

Man, do I feel old. Back in undergraduate school, we were taught to learn programming (FORTRAN) through physics, not the other way around. The idea that the process could be turned around really hammers home how much things have changed due to the access to computers at a young age that most kids have nowadays.

I learned programming independently, but I've done a Master's in physics. I really think that you want the curriculum to go in this order: (1) teach a high-schooler to program via games; (2) leverage that programming knowledge to build up some abstract mathematics and love of patterns; (3) start into Newton's equations with a programming background. Haskell is actually a pretty good choice for this process because it…

that sounds so fun. I would love to take a class (or classes) like that :)

Re: Learn Physics by Programming in Haskell [pdf]

#40

Earlier quoted context omitted.

The authors are really onto something with programming as a means to learn other subjects. I think this is because of the precision that programming demands. You have to really nail down every edge case, and think about things down to their essence. This is one reason why programmers can succeed in jumping the fence to work in their customer's jobs, even when it's an unrelated field. (I've seen many programmers make…

I think it's actually as much to do with having to turn syntax and abstraction into something actionable that describes the solution. That is, in programming you learn a small set of abstractions (programming language syntax), and the actual coursework in applying that is in how they combine, how to fit them to problems. In math, you learn a large number of abstractions (notation), that can vary and have new ones acr…

But your second code snippet is almost a verbatim transliteration of the image URL, so in what sense is it easier to understand?

(verbatim transliteration would be

    sum (map (\i -> i)) [1..100]

)
Post reply on HN