Live data from Hacker News

Learn Physics by Programming in Haskell [pdf]

arxiv.org

41–50 of 56 posts

Re: Learn Physics by Programming in Haskell [pdf]

#41
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.

Eh, I think the approach we (as in, that's how I learned programming, too) learned with is the correct one, really. Computational physics is less about programming and more about the constant tension between the demands of efficiency and accuracy and the inherent imperfections of the methods (e.g. difference models) and underlying machine representation of numbers. Physics isn't just about punching numbers into a com…

If you're doing really advanced computational physics, sure, but that doesn't mean you can't start on an easier path and learn about those challenges later.

It's no different to practical work – you start off by focusing on the concepts, not worrying about budgeting and time constraints, even though those things are important in the real world too.

In our undergrad course we used C and it was completely the wrong tool for the job. No one learned more about numerical challenges than they could've with Python, and fighting with semicolons just puts people off.

Re: Learn Physics by Programming in Haskell [pdf]

#42

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…

most computational individuals would be strongly opposed to FP

There's ample evidence for and against. The most famous counterpoint I know of is Dijkstra, whose Ph.D. was in theoretical physics. What does a theoretical physicist do? They calculate, of course. On reams and reams of paper.

Dijkstra famously warned against the brain damage that comes with learning BASIC. I understand it to mean that one could be so caught up with the details of shuffling bits and bytes that a bigger picture is no longer conceivable to the poor fellow.

Because the poor fellow has fallen into the trap of premature optimization. For loop all the things, higher abstractions be damned.

Re: Learn Physics by Programming in Haskell [pdf]

#43
The linked paper doesn't address the elephant in the room - numerical integration is a finicky process to work with in many systems. Students who are still working to understand the underlying concepts are not going to be helped by things like non-energy conserving integrals. [1]

The lack of units in the type system also means the error-preventing properties of static typing are somewhat limited here; it's possible to write code that assumes F=a/m without any complaint from the compiler.

[1] http://en.wikipedia.org/wiki/Energy_drift

Re: Learn Physics by Programming in Haskell [pdf]

#44
post #43

The linked paper doesn't address the elephant in the room - numerical integration is a finicky process to work with in many systems. Students who are still working to understand the underlying concepts are not going to be helped by things like non-energy conserving integrals. [1] The lack of units in the type system also means the error-preventing properties of static typing are somewhat limited here; it's possible t…

https://wiki.haskell.org/Physical_units

Re: Learn Physics by Programming in Haskell [pdf]

#45
post #38
post #36

Earlier quoted context omitted.

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/

Oh sweet a guile port.. thanks for posting that!

Re: Learn Physics by Programming in Haskell [pdf]

#46
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.

I'm working on a port to Clojure: https://github.com/littleredcomputer/math .

(The name is a little vague, I haven't decided what to call it; "scmutils" doesn't convey much).

Having it in Clojure means it could be integrated with lots of other things; I'm considering graphics, at some point, or some kind of integration with javascript.

I'm a daily reader of HN, but not much of a contributor (sadly): do you think this might be worth a Show HN when it was more mature?

Re: Learn Physics by Programming in Haskell [pdf]

#47
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)

I think that this is true only if you want to be an instance of `Num`, which makes sense: the collection of, say, lengths is not such an instance, because you cannot multiply two lengths and get a length. Nothing stops us from defining (simplified)

    data Unit a = Unit a [String]

    (*) (Unit a as) (Unit b bs) = Unit (a Main.* b) (as ++ bs)
Of course, we will then have to disambiguate `` when we use it in the code. Another option would be to give it another name, like `unit` (or something less awful).

Re: Learn Physics by Programming in Haskell [pdf]

#48
post #46

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.

I'm working on a port to Clojure: https://github.com/littleredcomputer/math . (The name is a little vague, I haven't decided what to call it; "scmutils" doesn't convey much). Having it in Clojure means it could be integrated with lots of other things; I'm considering graphics, at some point, or some kind of integration with javascript. I'm a daily reader of HN, but not much of a contributor (sadly): do you think this…

I've been putting off the SICM course and thus scmutils but the idea of a Clojure port makes me a little giddy. 2 good things I see: the possibility of using it in bigger projects (sorry, Scheme) or just not dealing with context switching from Emacs/Clojure to Edwin/Scheme.

Either way - really cool, wish I could help but I don't really know how.

Re: Learn Physics by Programming in Haskell [pdf]

#49
post #42

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…

most computational individuals would be strongly opposed to FP There's ample evidence for and against. The most famous counterpoint I know of is Dijkstra, whose Ph.D. was in theoretical physics. What does a theoretical physicist do? They calculate, of course. On reams and reams of paper. Dijkstra famously warned against the brain damage that comes with learning BASIC. I understand it to mean that one could be so caug…

A couple of random bits of trivia:

* Dijkstra's Ph.D. was in theoretical physics, but I don't believe he ever actually did much. Instead, he was working on computing systems. Famously, when he was getting married, the Amsterdam official recording the marriage wouldn't accept "programmer" as a job, so his marriage certificate says "theoretical physicist."

* Dijkstra was not a wildly big fan of functional programming. Admittedly, he was less a fan of other things, and I've had this sneaking suspicion that his was simply another allergic reaction to recursion, but still...his guarded command notation was essentially imperative.

Re: Learn Physics by Programming in Haskell [pdf]

#50

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...

Actually I wonder how much Curry took from mathematics tendency to parametrize abstractions, leaving variables for later, in his work.
Post reply on HN