Sunday, February 08, 2015

The unreasonable effectiveness of mathematics

[With apologies to Eugene Wigner.]

I was noodling around with some graphics code the other day to try to produce some schematic representations of water waves for a book that I'm working on.  I wanted to produce a little animation of what happens when you throw a stone into a pond.  It didn't have to be very flashy, I just wanted it to be qualitatively correct, that is, I wanted to produce a drawing of a wave that spread out from a central source and decreased in amplitude with time and distance from the source.  So I started out with the venerable sin(x)/x function:
That's a good start, but now I wanted to animate it, so I changed it to sin(x+t)/(x+t) and varied the time t from zero up to some positive value.  The result was this:
That was kind of what I was after, but time seemed to be running backwards.  So I changed the sign on my time parameter, i.e. sin(x-t)/(x-t), which yielded this:
Now my waves were moving in the direction I wanted them to, but they weren't being damped out.  A bit of reflection revealed the reason: because I changed the sign of my time parameter in both the numerator and the denominator of my function, I had reversed the not only the time direction, but also the damping influence of time, which I had gotten right the first time.  So the function I wanted was (apparently) sin(x-t)/(x+t).  When I tried that, I got this as my first frame:
That looked promising.  The graph had flipped itself upside down, but that actually seemed closer to the Right Answer, because when you throw a stone into a pond the first thing it does it to make a "hole" in the water.  So I advanced the time a bit, and got this:
WTF?  Where did that spike come from?  I didn't want a spike.  Water doesn't do that.  Water is always nice and round, not pointy.  This couldn't be right.  And yet, the rest of the animation actually looked pretty reasonable:
I spent several hours fiddling with it trying to tweak the function so that it did the same thing but without that annoying spike.  I tried changing signs, using a cosine function instead of a sine, you name it.  Nothing looked right [1].  And then it occurred to me (duh!) to take another look at what water actually does when you drop something into it.


There, right in the center of an actual physical water wave, was my spike!  It didn't have a pointy end: surface tension had made the point shrink up into a sphere, but the spike was unmistakable.  It was as if the math was trying to take me by the throat and tell me, "No, water really does work this way."

In retrospect it is actually obvious why water has to work this way.  You drop a stone into a pond and the stone makes a hole in the water.  The stone keeps falling through the water (because the stone is denser), and as soon as it has moved out of the way, water rushes back in from all sides to fill the hole.  All that water rushing in meets at the center of the hole, and because of inertia and the fact that water is not compresible, it has to keep moving, so it has to go somewhere.  The only place left for it to go is up.

In 1960 Eugene Wigner published a famous paper entitled "The Unreasonable Effectiveness of Mathematics in the Natural Sciences" which first pointed out this phenomenon, that math often "takes you by the throat" and forces you towards the correct answer even if it sometimes takes people a while to realize that this is what is going on.  I thought it was cool to experience this phenomenon firsthand.


---
[1]  The reason the spike is there, mathematically speaking, is that the function sin(x-t)/(x+t) must be zero when x=t and t>0, but the limit of the function as x->t from above is -1.  So at t=0 it has to look like -sin(x)/x, but at t=epsilon it has to have two zero-crossings at x = +/- epsilon.  The only way to satisfy that condition, along with continuity constraints, is to have a spike.  It is might even be possible to prove that no mathematical function can possibly produce all the desired qualitative characteristics of water waves (damping, forward motion in time, conservation of mass) without a spike, but that's above my pay grade.

5 comments:

  1. > It is might even be possible to prove that no mathematical function can possibly produce all the desired qualitative characteristics of water waves (damping, forward motion in time, conservation of mass) without a spike, but that's above my pay grade.

    Simulating conservation laws is quite hard; doing so with fluids in computer graphics may not be a solved problem in any general sense. Have you heard of symplectic integrators? I believe that they work for some N-body problems. Have you investigated how quickly double-precision floating-point fails for a naive implementation of the 2-body problem?

    ReplyDelete
  2. Flailure is always an option

    This post is nicely consonant with the prior post on T.J. Radcliffe's blog.

    One of the parts I admired about his blog post is this:

    "I mention this because we rarely see what goes on behind the scientific curtain. There is always a lot of flailing around, a lot of trial and error. Young people in particular may not be aware of this and feel that their own flailings are uniquely embarrassing. They are not. Flailure is always an option, and often quite a good one."

    This jives with my own experience. You may have the overall structure of a program worked out, then you get hung up on one little unexpected piece -- and it takes you hours (or days) to resolve it.

    ReplyDelete
  3. Well I tried the water drop with sin(x^2+y^2)/(x^2+y^2)

    Looks similar

    ReplyDelete
  4. Yes, but that's one of the really interesting things about this: I ended up making an accurate prediction of physical behavior despite the fact that I had the math completely wrong!

    ReplyDelete