I recently came across a very funny math thing, which has to do with the volume of spheres in N dimensions. Sure, not really meaningful from a physical point of view, but still very funny to think about it.

**The volume of an N-dimensional sphere goes to zero (!) as the number of dimensions increases. In other terms, balls are empty in very high dimensional spaces.** That’s sooo weird.

To be more precise, one should really say that the ratio between the volume of a sphere and that of a cube goes to zero. Imagine putting a circle inside a square in 2D: the area of the square is , while the area of the circle is . What’s left (“the corners”) have area . In 2D, there’s more area in the circle than in the corners. It turns out that if you crank up the number of dimensions, *all* of the volume is contained in the corners!

Of course, I couldn’t believe this and had to convince myself with both maths and “experiments”.

## Maths…

So, let’s calculate the volume of a sphere in N dimensions. There are many ways to carry out this proof; this is a simple one taken from the source of all knowledge. We expect the volume to scale with the radius as . We want to find the constant of proportionality as a function of N.

We deal with numbers , which are really arrays of reals. We need a function and, for simplicity, let’s just take a Gaussian

The idea is to integrate this function in two different sets of coordinates and compare the result. First, let’s integrate in cartesian coordinates:

Each of those piece is a single-dimensional gaussian, and we know that a gaussians integrate to . We have N of them, so that gives you .

Now, let’s do the same thing in spherical coordinate. The distance from the origin is . We divide into shells of dimension N-1 and then integrate radially, i.e.

The term in brakets is the surface of a N-1 dimensional sphere, which is expected to scale as , i.e.

So, the integral above becomes (substitute )

The last thing is a Gamma function, which is *defined* by the integral above, so not much to say there. It basically the generalization of factorials to non-integer numbers.

Now we can equate the integrals computed with both sets of coordinates to obtain

We thus have the surface area of the (N-1)dimensional sphere

The N-volume is now obtained by integrating the surface along (easy! it’s a polinomial!)

where at the end we used the Gamma function property .

So, this is the final result:

The N-dimensional volume scale as the inverse of a Gamma function. So, it goes to zero, and it goes to zero really fast! Faster than an exponential, actually. This is because as (this thing is called Stirling formula).

## Code…

That’s hard to believe, so I had to do an experiment, which for me really means putting this thing into a computer. Here is the simple python code I wrote to compute the N-dimensional volume

It’s a Monte-Carlo strategy, and it’s actually very simple. We throw a large number of random points in the N-dimensional cube and select those that are inside the sphere. The volume of the sphere is the volume of the cube times the fraction of accepted points

.

We do this for many dimensions D up to 30 and check the volumes we find against the exact solution we proved above. If you run that code, this is what you get:

D=2 N=10000000 N_in=7854391 V=3.14176 Sol=3.14159 diff=0.00005 t=0.63s D=3 N=10000000 N_in=5236198 V=4.18896 Sol=4.18879 diff=0.00004 t=0.92s D=4 N=10000000 N_in=3084039 V=4.93446 Sol=4.93480 diff=0.00007 t=1.16s D=5 N=10000000 N_in=1645407 V=5.26530 Sol=5.26379 diff=0.00029 t=1.35s D=6 N=10000000 N_in=808056 V=5.17156 Sol=5.16771 diff=0.00074 t=1.74s D=7 N=10000000 N_in=370005 V=4.73606 Sol=4.72477 diff=0.00239 t=1.89s D=8 N=10000000 N_in=158915 V=4.06822 Sol=4.05871 diff=0.00234 t=2.08s D=9 N=10000000 N_in=064144 V=3.28417 Sol=3.29851 diff=0.00435 t=2.50s D=10 N=10000000 N_in=025101 V=2.57034 Sol=2.55016 diff=0.00791 t=3.78s D=11 N=10000000 N_in=009097 V=1.86307 Sol=1.88410 diff=0.01117 t=3.54s D=12 N=10000000 N_in=003223 V=1.32014 Sol=1.33526 diff=0.01133 t=3.11s D=13 N=10000000 N_in=001055 V=0.86426 Sol=0.91063 diff=0.05092 t=3.27s D=14 N=10000000 N_in=000382 V=0.62587 Sol=0.59926 diff=0.04439 t=3.41s D=15 N=10000000 N_in=000114 V=0.37356 Sol=0.38144 diff=0.02068 t=3.62s D=16 N=10000000 N_in=000026 V=0.17039 Sol=0.23533 diff=0.27594 t=3.65s D=17 N=10000000 N_in=000012 V=0.15729 Sol=0.14098 diff=0.11566 t=3.80s D=18 N=10000000 N_in=000002 V=0.05243 Sol=0.08215 diff=0.36176 t=4.06s D=19 N=10000000 N_in=000001 V=0.05243 Sol=0.04662 diff=0.12456 t=4.54s D=20 N=10000000 N_in=000001 V=0.10486 Sol=0.02581 diff=3.06316 t=4.47s D=21 N=10000000 N_in=000000 V=0.00000 Sol=0.01395 diff=1.00000 t=5.10s D=22 N=10000000 N_in=000000 V=0.00000 Sol=0.00737 diff=1.00000 t=5.42s D=23 N=10000000 N_in=000000 V=0.00000 Sol=0.00381 diff=1.00000 t=5.27s D=24 N=10000000 N_in=000000 V=0.00000 Sol=0.00193 diff=1.00000 t=5.68s D=25 N=10000000 N_in=000000 V=0.00000 Sol=0.00096 diff=1.00000 t=6.46s D=26 N=10000000 N_in=000000 V=0.00000 Sol=0.00047 diff=1.00000 t=6.16s D=27 N=10000000 N_in=000000 V=0.00000 Sol=0.00022 diff=1.00000 t=6.51s D=28 N=10000000 N_in=000000 V=0.00000 Sol=0.00010 diff=1.00000 t=6.99s D=29 N=10000000 N_in=000000 V=0.00000 Sol=0.00005 diff=1.00000 t=6.91s D=30 N=10000000 N_in=000000 V=0.00000 Sol=0.00002 diff=1.00000 t=7.29s

For D=2 we get 3.14… which is . The volume then goes up till D=5. That’s the number of dimensions in which a sphere is “maximally filling”. After that, it decreases like crazy. This code is really good up only up to D=15 or so. After that, the sphere is so small that the number of points is basically zero and the error made on the predictions is close to 100%. This is the same information in a plot. The two solutions seem to agree on that scale, but if you look at the errors (bottom plot), that becomes huge.

BTW, I still think it’s weird. What happens if you pour water is a N-dimensional spherical ball? Can’t fit any water in. Wait. What’s N-dimensional water?

That was fun, for me at least. Hope you had fun too.

ps. I lead a discussion on this in the 2018 TAPIR Postdoc lunch at Caltech. Thanks to everybody that was there!