[HN Gopher] A rudimentary simulation of the three-body problem
       ___________________________________________________________________
        
       A rudimentary simulation of the three-body problem
        
       Author : achristmascarl
       Score  : 79 points
       Date   : 2024-04-02 18:23 UTC (4 hours ago)
        
 (HTM) web link (github.com)
 (TXT) w3m dump (github.com)
        
       | Gys wrote:
       | In this simulation the bodies also collide together. Luckily that
       | never happened in the book.
        
         | maelito wrote:
         | Should a collision conduct to a simulation of a 4 body problem
         | ?
        
         | achristmascarl wrote:
         | that might just be because of my low resolution gif ;)
        
         | SamBam wrote:
         | I was wondering about this too, but I think they're not
         | colliding. I think they're pulling towards each other and
         | getting tightly pulled around each other so they end up
         | slingshotting and flying back the way they came, in a way that
         | looks like a bounce.
         | 
         | You can see this in the very beginning of the simulation, with
         | the blue and green dot.
         | 
         | Can anyone say if this is actually accurate? It seems like an
         | unintuitive motion to me, but I'm often surprised by how these
         | things work.
        
           | achristmascarl wrote:
           | i believe you're correct, other (higher resolution)
           | visualizations of periodic orbits show that "wrapping"
           | behavior more clearly.
           | 
           | example from wikipedia: https://en.wikipedia.org/wiki/Three-
           | body_problem#/media/File...
        
         | CWuestefeld wrote:
         | The book is mis-named. Their system was not 3 bodies, but 4 (3
         | stars, plus a planet). And the system is so chaotic that even
         | that little planet will make a huge difference over time. And
         | even beyond that, the bodies themselves were transformed,
         | having the ability to tear atmosphere away from each other.
        
         | woooooo wrote:
         | Luckily??! Could have saved everyone a lot of trouble and kept
         | them in the proper number of dimensions.
        
       | at_compile_time wrote:
       | If you want to demonstrate why the three-body problem is chaotic,
       | you can set it up to run a couple hundred very similar
       | simulations in parallel. Just nudge each body by a tiny amount to
       | simulate uncertainty in the initial conditions and watch the
       | resulting configurations diverge as tiny differences become large
       | differences. Rather than points, you get lines of probability
       | that stretch out and wrap around each other. It's quite striking.
       | 
       | Edit: semantics
        
         | jovial_cavalier wrote:
         | This only demonstrates that the system is chaotic, not that
         | there is no closed form solution.
        
           | ncallaway wrote:
           | But the chaos is extremely critical, since we can't ever
           | perfectly measure the initial conditions.
           | 
           | So, even having a closed form solution isn't helpful when
           | computing real world situations.
        
             | zardo wrote:
             | It was really a math problem and not a physical one.
             | There's so much more going on ( GR, radiation pressure ),
             | that even if there were a solution it wouldn't be able to
             | predict Mercury's orbit.
        
             | constantcrying wrote:
             | The statements are independent. It having a closed form
             | solution and it being unstable don't contradict or confirm
             | one another.
             | 
             | In solutions to ODEs converge very often _exponentially_
             | from the true result. That the 3 Body problem for this
             | makes it characteristic, not special.
             | 
             | >So, even having a closed form solution isn't helpful when
             | computing real world situations.
             | 
             | Simply not true. It is helpful or not depending on your
             | problem. Often you are interested in short term behavior,
             | which can be studied by numerical methods or, if existing,
             | analytic solutions.
        
               | PaulHoule wrote:
               | Closed form solutions in general dynamic systems are
               | possible when systems are _integrable_ which means there
               | is a conserved quantity for every degree of freedom. The
               | solar system is _almost_ like that in the case that each
               | planet keeps going around with a constant angular
               | momentum so they go around like a set of clocks that run
               | at different speeds. Over long periods of time there is
               | angular momentum transferred by the planets so you get
               | chaos like this
               | 
               | https://www.aanda.org/articles/aa/full_html/2022/06/aa433
               | 27-...
               | 
               | Orbital mechanics is a tough case for perturbation theory
               | because each planet has three degrees of freedom (around,
               | in and out, up and down) and the periods are the same for
               | all of these motions and don't vary with the orbital
               | eccentricity or inclination. Contrast that to the generic
               | case where the periods are all different and vary with
               | the amplitude so with weak perturbations away from a
               | resonance the system behaves mostly like an integrable
               | system but if the ratio between two periods is close to
               | rational all hell breaks loose, see
               | 
               | https://en.wikipedia.org/wiki/Kolmogorov%E2%80%93Arnold%E
               | 2%8...
               | 
               | the harmonic oscillator has a similar problem because the
               | period doesn't change as a function of the amplitude.
               | Either way these two pedagogically important systems will
               | lead you completely wrong in terms of understanding
               | nonlinear dynamic, if you add, say, an ex^3 term to the
               | force in one of two coupled harmonic oscillators it is
               | meaningless that e is small, you have to realize that the
               | N=2 case of this integrable system
               | 
               | https://en.wikipedia.org/wiki/Toda_lattice
               | 
               | is the right place to start your perturbation from which
               | ends up explaining why the symmetry of the harmonic
               | oscillator breaks the way that it does. Funny though, the
               | harmonic oscillator is not weird at all in quantum
               | mechanics and is just fine to do perturbation theory
               | from.
        
               | why_at wrote:
               | Thanks for this. This is something that always bugged me
               | when I see explanations of the three-body problem.
               | They'll say something like "changing the initial
               | conditions just a tiny bit can dramatically change the
               | outcome!" as an explanation for why having no closed form
               | solution is significant.
               | 
               | But that never made sense to me, since plenty of things
               | with closed form solutions also do this.
        
           | nyrikki wrote:
           | This may be a bit pedantic, the nbody problem is not chaotic,
           | it is harder, having riddled basins.
           | 
           | > A riddled basin implies a kind of unpredictability, since
           | exact initial data are required in order to determine whether
           | the state of a system lies in such a basin, and hence to
           | determine the system's qualitative behavior as time increases
           | without bound. (Note this is different from "chaos," where
           | very precise initial data are required to determine finite-
           | time behavior.) What is more, any computation that determines
           | the long-term behavior of a system with riddled basins must
           | use the complete exact initial data, which generally cannot
           | be finitely expressed. Hence such computations are
           | intuitively impossible, even if the data are somehow
           | available.
           | 
           | http://philsci-archive.pitt.edu/13175/1/parker2003.pdf
           | 
           | The above post is a good 'example' of sensitivity to initial
           | conditions, and riddled basins do have a positive Lyapunov
           | exponent which is often the only criteria in popular
           | mathematics related to chaos. But while a positive Lyapunov
           | exponent is required for a system to be chaotic, it is not
           | sufficient to prove a system is chaotic.
           | 
           | If you look at the topologically transitive requirement,
           | where you work with the non-empty open sets U,V [?]
           | X....riddled basins have no open sets...only closed sets.
           | 
           | With riddled basins, no matter how small your e, it will
           | always contain the boundary set.
           | 
           | If you have 3 exit basins you can run into the Wada property,
           | which is also dependent on initial conditions but may have a
           | zero or even negative Lyapunov exponent and is where 3 or
           | more basins share the same boundary set...which is hard to
           | visualize, non-chaotic, and nondeterministic.
           | 
           | Add in strange non-chaotic attractors, which may be easier or
           | harder than strange chaotic attractors, and the story gets
           | more complicated.
           | 
           | Sensitivity to initial conditions is simply not sufficient to
           | show a system is chaotic in the formal meaning.
           | 
           | But the 3 body problem's issues do directly relate to
           | decidability and thus computability.
        
         | constantcrying wrote:
         | This is irrelevant to the unsolvability.
         | 
         | That the three body problem is unstable and that no analytic
         | solution exists are completely independent statements.
         | 
         | The upright pendulum is also an unstable ODE, yet it has an
         | analytical solution.
        
       | 7373737373 wrote:
       | There is this cool paper "Crash test for the restricted three-
       | body problem" [0], that plots where the third body eventually
       | ends up when dropped from any location. Looks very fractal-like
       | [1][2]
       | 
       | [0]
       | https://scholar.archive.org/work/wnwgyliq5fgtba45k535t5lb5e/...
       | 
       | [1] https://www.semanticscholar.org/paper/Crash-test-for-the-
       | res...
       | 
       | [2] https://www.semanticscholar.org/paper/Crash-test-for-the-
       | res...
        
         | jameshart wrote:
         | 'Strange attractors': https://en.wikipedia.org/wiki/Attractor
         | 
         | "An attractor is called strange if it has a fractal structure."
        
       | antognini wrote:
       | If anyone is interested in playing around with gravitational
       | dynamics I highly recommend the REBOUND library [1]. It has a
       | simple Python interface but under the hood it has a collection of
       | research grade integrators. It came out around the time I was
       | finishing up my PhD in gravitational dynamics, but if I were
       | still in the field it's what I'd be using.
       | 
       | If you're curious what would happen to the Solar System if you
       | made Jupiter 10 times more massive you can pip import the library
       | and find out for yourself in about five minutes.
       | 
       | [1]: https://github.com/hannorein/rebound
        
         | ricksunny wrote:
         | Looks awesome. I have a question that might be pedantic but I
         | think you could speak to. Coming from an engineering mindset, I
         | like the use of the term 'integrator' instead of 'solver'. In
         | MATLAB, 'solvers' are used to iterate states of ODE models. But
         | the term 'integrator' is more intuitive to me. Can you speak to
         | the use of one term vs another in the ephemeris community?
        
           | constantcrying wrote:
           | Solver is a general term, it is just an algorithm which
           | solves a certain problem. You have solvers for linear
           | systems, PDEs, optimization problems, graph problems, etc.
           | 
           | An integrator is an algorithm which allows the numerical
           | approximation of the solution to an ODE, given that the ODE
           | is written in a specific form where it is equivalent to
           | calculating the integral of multiple functions.
        
         | lucgommans wrote:
         | It's a hundred times less polished than rebound (that readme
         | looks seriously cool!), but in 2021 I also wanted to toy around
         | with orbital mechanics / gravity and couldn't find a quick and
         | easy simulator so I made this to run in a browser:
         | https://lucgommans.nl/p/badgravity/
         | 
         | Since it's so rough on the edges (especially on mobile,
         | initially I was surprised it works at all), here's the steps
         | for the mentioned example of making Jupiter 10x heavier:
         | 1. Open the scenarios on the left and click play on the inner
         | solar system to load that up         2. Click the plus on the
         | outer planets to add them in (if it looks like nothing
         | happened: zoom out. Space is big and this is to scale)
         | 3. Fold out the "bodies" section and alter the mass for
         | "J"upiter. The change is applied live.         4. Optionally
         | press Restart to restart with the current settings but back at
         | their initial positions and speeds
         | 
         | Making Jupiter 1000x heavier (and fast-forwarding the time in
         | the Simulator controls by 10x) makes it eject Mars from the
         | solar system within one minute, but interestingly Mercury and
         | Venus seem pretty stable around the sun in that configuration
         | 
         | The help/about page
         | (https://lucgommans.nl/p/badgravity/about.html) contains links
         | to all other orbit projects I could find. Seeing Rebound as
         | well as the OP, I should probably add a "libraries" section! Or
         | do you think that should just go with "Software to download"
         | alongside Stellarium and such?
        
       | JKCalhoun wrote:
       | And since A. K. Dewdney is fresh on my mind, he did a _Computer
       | Recreations_ article generally about this (about simulating
       | orbital mechanics) and the clever bit that I remember: you dial
       | the time slice way down as objects got close, you care little
       | when the objects are far apart.
       | 
       | Not a "solution" of course, but certainly an optimization if
       | you're just generally doing gravitational simulations.
        
         | PaulHoule wrote:
         | See https://en.wikipedia.org/wiki/Adaptive_step_size
        
       | lfmunoz4 wrote:
       | I sometimes feel like physicist are not completely honest to show
       | how grandiose they are. When you start actually studying this
       | stuff you realize this stuff is primitive, can barely answer
       | simple questions and a lot is on shaky footing at best.
        
         | acover wrote:
         | What in this post isn't honest?
        
           | lfmunoz4 wrote:
           | "not honest" might not be the right phrasing. What I was
           | trying to say is that when learning this stuff I felt like
           | they hid a lot of information from me which later surprised
           | me. But they hid it because they have no answers for it.
           | 
           | One simple example is what happens when you don't consider
           | these as points but instead spheres. Also what happens when
           | the spheres come close? The math starts breaking down, you
           | start seeing infinities. I.e, in reality spheres come close
           | and gravity doesn't go infinity.
        
             | mr_mitm wrote:
             | You are complaining that you study the simple cases or
             | simplified cases first before you study near unsolvable
             | systems?
             | 
             | Besides, very often the simplified case gets you
             | surprisingly far because the difference between idealized
             | situations and reality is often negligible or at least
             | easily describable - see perturbation theory. The
             | simplified cases are well worth studying.
        
               | sfink wrote:
               | If I understand correctly, or at least if I map it to my
               | own similar complaint: the problem is not that they have
               | you study simple or simplified cases, it's that the
               | ignored complexity is unacknowledged and sometimes even
               | denied. Which makes a lot of sense in primary school,
               | where even mentioning it might cause some kids to ignore
               | everything because "it's not really how it works" or
               | whatever. But by the time you've made it past the basics,
               | sweeping complexity under the rug is harmful. You still
               | want to be studying the simplified scenarios, but it
               | would be much better if you had some sense of the range
               | of things that meaningfully differ from realistic
               | scenarios. Not so you can take them into account in your
               | solutions, but so you have the appropriate level of
               | humility about what your solutions mean and the limits of
               | their applicability.
               | 
               | I guess I didn't do that much physics, because for me it
               | comes up more in other fields. In statistics, for
               | example, it is critically important to understand the
               | limitations of your results. For example, you might
               | assume that error is normally distributed. You don't want
               | to forget about that assumption, because it is very
               | commonly violated, and it can make a large difference in
               | your conclusions. Yet in school, it was almost always
               | handwaved aside with "Law of Large Numbers mumble mumble
               | mumble". Even when the law didn't apply, or the
               | definition of "Large" happened to be "way bigger than
               | your pathetic number of data points".
               | 
               | It's also why there's often such a gulf between academia
               | and industry. Academic results walk a tightrope of
               | assumptions and preconditions, and trying to put them
               | into practice always finds places where those don't hold.
               | Sometimes they even start out holding, but then everybody
               | takes advantage of it until competition drives everyone
               | into optimizing the residuals. If there's a space where
               | things make sense, competition will always drive you to
               | the edge of that space. Or beyond; competitive pressure
               | does not care about keeping your equations simple and
               | pure. Back to the point, you might study a field for
               | years and then land a job in exactly that field, only to
               | discover that everybody is looking at it completely
               | differently because they've exhausted the simplified
               | space and are deep in the land of heuristics, guesswork,
               | and approximation. The market for spherical steaks was
               | saturated years before.
        
         | petsfed wrote:
         | Maybe its because I made an honest effort of getting a PhD in
         | physics, but I absolutely do not understand this perspective.
         | 
         | Like yes, we have a really hard time talking about just about
         | anything as finite object with physical extent, but jokes about
         | frictionless spherical cows moving in simple harmonic motion
         | started in secondary school. The gaps and shortcomings should
         | not come as a surprise. But most of us also hold devices in our
         | pockets that leverage actual quantum phenomena to function at
         | all (diodes of any stripe only work because of quantum
         | transitions). So while its true that there are a variety of
         | unsolved and potentially unsolvable problems in physics, its a
         | gross misunderstanding to say that it can barely answer simple
         | questions.
         | 
         | I think about the Born-Oppenheimer approximation a lot, as its
         | so obviously a hack to even do the math at all, but it
         | undergirds basically all of solid state physics.
        
       | xyst wrote:
       | Netflix really going hard on pushing their IP. It's like guerilla
       | marketing on steroids.
       | 
       | I jest. Tbh, I didn't know this was an actual problem. Thanks for
       | sharing.
        
       | nonfamous wrote:
       | This account has been posting simulations of interesting 3-body
       | scenarios for quite a while. It used to be on Twitter but moved
       | to Mastodon. You can check out the archives and play the videos,
       | it's quite neat: https://botsin.space/@ThreeBodyBot
        
         | Hugsun wrote:
         | I love this bot, thanks for sharing!
        
       | rsynnott wrote:
       | Do you want ghost numbers counting down on your retinas? Because
       | this is how you get ghost numbers counting down on your retinas.
        
         | lagadu wrote:
         | It's ok, I'll just make sure never to measure the CMB for
         | variations.
        
       | joe_the_user wrote:
       | One of the first programs I ever wrote was a simulator for a
       | planet rotating a star with a naive difference equation
       | approximation to Newton's law. I was a bit disappointed to see
       | the planet reliably spiral into the sun.
       | 
       | The main thing is that something like Euler's method (naive
       | iterative approximation) doesn't guarantee conservation of
       | energy. I believe that this is why planetary dynamics are usually
       | handled with Lagrangian equations rather than the naive
       | approximation approach.
       | 
       | Edit: It would be nice to see what the author's system does for
       | two bodies as a sanity check. Three body system was indeed
       | chaotic but still conserve energy - would this system do that?
       | 
       | https://en.wikipedia.org/wiki/Lagrangian_mechanics
        
         | forgotpwd16 wrote:
         | Can convert Euler's method to a symplectic integrator utilizing
         | v_{n+1} when computing x_{n+1}. That said although such
         | integrators are widely used (usually of higher order than
         | Euler's) in celestial mechanics, one is not restricted to them.
         | For example Bulirsch-Stoer is also very used even if it isn't
         | symplectic because remains accurate (energy error very low)
         | even on long integrations.
        
         | FredFS456 wrote:
         | I think symplectic integrators are typically used, which are
         | derived from hamiltonian mechanics
         | 
         | https://en.wikipedia.org/wiki/Symplectic_integrator
        
         | zokier wrote:
         | It's true that Euler integration is about as crude as you can
         | get, but you don't need to reach to Lagrangians for
         | improvement; something like Verlet integration can already
         | bring dramatic gains with fairly small changes needed.
        
           | _0ffh wrote:
           | Yes, I think it's probably the simplest symplectic method,
           | which would be quite the improvement already.
        
         | dekhn wrote:
         | It wasn't the first program I wrote, or even a program I wrote,
         | but in middle school a friend wrote a 3-body integrator in
         | BASIC (sun, earth, moon). That single 20 line program shaped my
         | entire world view for a long time (decades), implying to me
         | that we could, if we had powerful enough computers, simulate
         | all sorts of things... even entire universes (which was also an
         | idea that I explored with cellular automata).
         | 
         | It's not a particularly helpful worldview and can often be
         | harmful if you're working with complex systems, or systems that
         | require more than o(n(log(n)) per step, or any number of other
         | real-world problems scientists face.
         | 
         | Many years later I was impressed at how well astronomy packages
         | work (IE, "it's time T at local L, what is the angle of the sun
         | in the sky?") and stumbled across this paper by Sussman:
         | https://web.mit.edu/wisdom/www/ss-chaos.pdf which shows some
         | pretty serious work on future prediction of solar system
         | objects.
        
           | forgotpwd16 wrote:
           | >simulate all sorts of things... even entire universes
           | 
           | You also assumed that chaos is a measurement problem. You
           | could simulate entire universe if you knew the initial
           | conditions sufficiently enough. There were two nice recent
           | papers[1][2] that showed in order to predict some orbits
           | you'll need an accuracy less of Planck length or else some
           | systems are fundamentally unpredictable.
           | 
           | [1]: https://arxiv.org/abs/2002.04029 [2]:
           | https://arxiv.org/abs/2311.07651
        
             | dekhn wrote:
             | I'd love to see convincing evidence that we could simulate
             | the universe using only standard physical laws. IIUC we
             | don't have a way to do that or reliably say whether it's
             | possible. It's also not that interesting a problem because
             | it's so impractical.
        
               | actionfromafar wrote:
               | But it would be interesting to see if we could simulate
               | _a_ universe and observe if it in any way resembled ours.
               | Even if the simulated universe was much  "smaller". (It
               | would of course have to be.)
        
               | dekhn wrote:
               | I think you'd need to be a few rungs up the Kardashev
               | scale to even contemplate this.
        
               | actionfromafar wrote:
               | That may be ... plus we don't really know what to make of
               | the observations around us, with dark matter and stuff.
        
         | PeterisP wrote:
         | Would it make sense to explicitly implement conservation of
         | energy?
         | 
         | I.e. do a simple method but calculate the total energy at the
         | beginning, and at each step adjust the speeds (e.g.
         | proportionally) so that the total energy matches the initial
         | value - you'll still always get _some_ difference due to
         | numerical accuracy issues, but that difference won 't be
         | growing over time.
        
       | danAtElodin wrote:
       | Nicely done! We were playing with this concept as well, in case
       | it's useful to compare notes together:
       | https://app.elodin.systems/sandbox/hn/three-body
        
       | zakhar wrote:
       | Hah, I did something similar at
       | https://ari.blumenthal.dev/!/-2/-1/three-body after reading the
       | book last year.
       | 
       | Source at
       | https://github.com/zkhr/blog/blob/main/static/js/three.js
        
       | yzydserd wrote:
       | Also see the source code for the popular ThreeBodyBot [0] as seen
       | on mastodon etc [1]
       | 
       | It contains a numerics tutorial [2] that I found very useful for
       | my use case.
       | 
       | [0] https://github.com/kirklong/ThreeBodyBot
       | 
       | [1] https://botsin.space/@ThreeBodyBot/112200106103679713
       | 
       | [2]
       | https://github.com/kirklong/ThreeBodyBot/blob/master/Numeric...
       | (ipynb)
        
       | PaulHoule wrote:
       | I noticed that paper they link to was the first one to find new
       | periodic orbits in the three body problem in a long time which
       | confirms what I've believed for a long time which is that
       | nonlinear mechanics is badly underresearched.
        
         | sameoldtune wrote:
         | There's a saying in mathematics circles which I'll butcher
         | here: "everything is either a linear system, reducible to
         | linear systems, or unapproachable."
         | 
         | Think about how bad we are at analytically solving "simple
         | looking" diff-eqs and the above statement starts to sound too
         | true.
        
           | PaulHoule wrote:
           | Exactly. Finding a few hundred periodic orbits is a lot of
           | hard work but you don't have the glory of having "solved"
           | something. Because of that kind of thinking there are many
           | unanswered questions which are ignored because they don't
           | seem to be part of some masterstroke.
        
       | nico wrote:
       | This is great! Thank you
       | 
       | In college, a long time ago, I wrote something like this, for n
       | bodies, but in c++ and OpenGL
       | 
       | More recently I've built something similar in python
       | 
       | For anyone interested in this, I recommend this Wired article
       | that goes from the 2 body problem to n, with simulations and code
       | that run on the browser: https://www.wired.com/2016/06/way-solve-
       | three-body-problem/
        
       | maxglute wrote:
       | Would be neat if there's planet level visualization in Space
       | Engine like in the show where you see the suns whizzing around
       | and enviroment freeze/burn.
        
         | adamredwoods wrote:
         | This isn't planet level, but shows surface:
         | https://universesandbox.com/
        
       | adamredwoods wrote:
       | Also check out: https://universesandbox.com/
       | 
       | https://twitter.com/UniverseSandbox/status/17709221751443007...
        
       ___________________________________________________________________
       (page generated 2024-04-02 23:00 UTC)