3 ms·
I've always wanted to write a planetary simulator. I think clojure might be a decent language for it, as long as you avoid floating point as much as possible an
by ZitchDog 17y ago
I've always wanted to write a planetary simulator. I think clojure might be a decent language for it, as long as you avoid floating point as much as possible and use clojure's Ratios class instead.
user=> (type (/ 1 3))
clojure.lang.Ratio
user=> (* (/ 1 3) 3)
1
I'd really like to see an arithmetic macro for clojure to allow infix notation, constants, and lazy evaluation. Something like (arith 2m/s^2) would be crazy awesome.
- jackdawjack 17y agocheck out "the structure and interpretation of classical mechanics" by sussmann et al for a whole raft of things like this done in scheme. I don't see why would you want to stay away from floats, using rationals isn't going to magically fix the numerical errors from approximating derivatives and such. I believe they develop an automatic differentiation routine in SICM that will actually allow you to make a pretty good planetary motion simulator, i.e one that won't just go horribly wrong if you run it for a few thousand years. Of course if you're really interested/mathematically inclined one of the best ways to simulate Hamiltonian systems is via iterated maps, not unlike what was in the article. A good (but quite hard) ref to this is "simulating hamiltonian dynamics" by Leimkuhler and Reich.