Muxiao Liu. login
~ $ open mooncakes-in-6-dimensions.md
WORKSHOP

Why Never to Sell Mooncakes in 6 Dimensions

planted oct 15, 2026 · v1.0.1
v1.0.1 oct 15 planted

A journey to find the “surface area” and “volume” of n-dimensional spheres.

Back in 2023, a standard was put into force in China to prevent mooncake over-packaging. The issue was that they put mooncakes in huge boxes, with giant gaps between the packaging and the actual mooncake. After this short read, you will be able to get back at these vendors with a confident and articulate denunciation:

You should go and sell your mooncakes in 6-dimensional space (or above)!!

DISCLAIMER

Use with caution. This is considered offensive in some cultures.

OK, guys, this is exciting. Let’s get ready…

A circle is πR2\pi R^2, a sphere is 43πR3\frac{4}{3}\pi R^3. Not the most surprising results. What about higher dimensions? Can we try to get the “volume” of higher dimensional spheres?

Boring Prerequisites: Edgy and Round

A single integral is the area under the curve.

∫x=0x=bdx=b\int_{x=0}^{x=b}dx=b

Consider generalizing this image to the “volume” between the “surface” of the function and the “plane” formed by the axes we are integrating over.

∫x=0x=b∫y=0y=hdxdy=∫x=0x=bdx⋅y∣y=0y=h=∫x=0x=bhdx=hb\int_{x=0}^{x=b}\int_{y=0}^{y=h}dxdy=\int_{x=0}^{x=b}\Biggr. dx\cdot y\Biggr|^{y=h}_{y=0}=\int_{x=0}^{x=b}hdx=hb

Note that when calculating, order of the terms inside the integrals doesn’t matter, as long as the variables stay inside their corresponding integrals.

This is the area of a h×bh \times b rectangle, however, conceptually, it is more accurate to think of it as the volume of a h×b×1h \times b \times 1 slab. Because this allows us to use non-constant functions, and the double integral gives the total volume under the surface (or equivalently, the accumulated value of the 2D domain that is integrated over. We can always translate the 3D image with uniform “density” to a 2D image with variable values everywhere, depending on what makes most sense in context).

∫x=0x=b∫y=0y=hx2y3dxdy=b33h44\int_{x=0}^{x=b}\int_{y=0}^{y=h}x^2y^3dxdy= \frac{b^3}{3}\frac{h^4}{4}

We can also vary the bounds of integrals.

∫x=0x=b∫y=0y=−hbx+hdxdy=−hbb22+hb=hb2\int_{x=0}^{x=b}\int_{y=0}^{y=-\frac{h}{b}x+h}dxdy=\frac{-h}{b}\frac{b^2}{2}+hb=\frac{hb}{2}

This is the area of a triangle.

Integrating in the Polar Coordinate

Now that we moved into integrating a 2 dimensional plane, we are naturally allowed to use polar coordinates instead of the edgy one. In Cartesian, each dxdydxdy is an infinitesimal rectangle. In polar, we are integrating over a fan-shape thingy, which makes it slightly more complicated (but as we will see, extremely helpful at times).

A=∫r=0r=Rdr∫θ=−πθ=πrdθA=\int_{r=0}^{r=R}dr\int_{\theta=-\pi}^{\theta=\pi}rd\theta

The fan shape has height drdr and the arc length is rdθrd\theta, we can approximate the area with simply rdrdθrdrd\theta since it is infinitesimally small. Notice how the arc length depends on rr, since the further away from the origin, the longer the arc length will be with a given dθd\theta.
Unit check: rdrdθrdrd\theta is distance2×rad\text{distance}^2\times\text{rad}.

Polar in 3D

Let’s try to generalize our results to 3D.
The easiest way is to use a cylindrical coordinate, where each point is identified by a radius, a height, and an angle. We can translate from cartesian by:

r=x2+y2,θ=tan⁡−1(yx),z=z\begin{gathered}r=\sqrt{x^2+y^2},\\[0.4em] \theta = \tan^{-1}(\frac{y}{x}),\\[0.4em]z=z\end{gathered}

Or back:

x=rcos⁡θ,y=rsin⁡θ,z=z\begin{gathered}x=r\cos\theta,\\[0.4em]y=r\sin\theta,\\[0.4em]z=z\end{gathered}

Note that θ\theta is always from positive xx, and represents the angle on the x-y plane. This is essentially what we had before, integrating over a height zz.

∫z=z1z=z2dz∫r=r1r=r2dr∫θ=θ1θ=θ2rdθ\int_{z=z_1}^{z=z_2}dz\int_{r=r_1}^{r=r_2}dr\int_{\theta=\theta_1}^{\theta=\theta_2}rd\theta

The metric for volume is dzdr(rdθ)dz dr (rd\theta).

Now, let’s try the spherical coordinate, where each point is identified with 2 angles and a radius.

r=x2+y2+z2,ϕ=tan⁡−1(yx),θ=cos⁡−1(zr)\begin{gathered}r=\sqrt{x^2+y^2+z^2},\\[0.4em]\phi=\tan^{-1}(\frac{y}{x}),\\[0.4em]\theta=\cos^{-1}(\frac{z}{r})\end{gathered}

Note on notation: For some reason we switch the angle on the x-y plane that used to be θ\theta to ϕ\phi…

Back to Cartesian:

z=rcos⁡θ,y=rsin⁡θsin⁡ϕ,x=rsin⁡θcos⁡ϕ\begin{gathered}z=r\cos\theta,\\[0.4em]y=r\sin\theta \sin \phi,\\[0.4em] x = r\sin\theta\cos\phi\end{gathered}

To make a bit of sense out of this: θ\theta is the angle between rr and zz. The projection of r on the x-y plane is rsin⁡θr\sin\theta, which makes angle ϕ\phi with x.
Conventionally, θ\theta goes from 00 to π\pi, and ϕ\phi goes from 00 to 2π2\pi. This is the same as how we locate on the Earth, where we use the whole circle for longitude and only half of the circle for latitude.
The metric for volume now would be dr,rdθ,rsin⁡θdϕdr, rd\theta, r\sin\theta d\phi.

Let’s use this to calculate the surface area of a sphere.

A=∫θ=0θ=πRdθ∫ϕ=0ϕ=2πRsin⁡θdϕ=4πR2A=\int_{\theta=0}^{\theta=\pi}Rd\theta\int_{\phi=0}^{\phi=2\pi}R\sin\theta d\phi=4\pi R^2

Integrate over rr for volume.

V=∫r=0r=Rdr∫θ=0θ=πrdθ∫ϕ=0ϕ=2πrsin⁡θdϕ=∫r=0r=R4πr2dr=43πR3V=\int_{r=0}^{r=R}dr\int_{\theta=0}^{\theta=\pi}rd\theta\int_{\phi=0}^{\phi=2\pi}r\sin\theta d\phi=\int_{r=0}^{r=R}4\pi r^2dr=\frac{4}{3}\pi R^3

We often find ways to use mathematics to generalize something that works in only a limited circumstance to a bigger world. The simple example is us defining ii such that the square root, which only worked for non-negative numbers, now works for all real numbers. Now, this new tool gives us a method to obtain surface area and volume of “spheres” of any dimension! We can already see that they generalize to lower dimensions:

  • On 2D (I am using A and V here for consistency, but in this context they mean circumference and area):
A=∫θ=−πθ=πRdθ=2πRA=\int_{\theta=-\pi}^{\theta=\pi}Rd\theta=2\pi R V=∫r=0r=Rdr∫θ=−πθ=πrdθ=πR2V=\int_{r=0}^{r=R}dr\int_{\theta=-\pi}^{\theta=\pi}rd\theta=\pi R^2
  • 1D (We don’t really have a good formula for the “surface area” anymore, but we can obtain it in reverse, by taking the derivative with respect to the radius. Consider how we interpret these results. A 1D sphere is really just a line segment of length 2R2R, volume here means length. What about “surface area”? Points?):
V=∫r=−Rr=Rdr=2RV=\int_{r=-R}^{r=R}dr=2R A=dVdr=2A=\frac{dV}{dr}=2

Can we similarly calculate the surface area and volume of higher dimensional spheres, whatever that means? That is not so easy! We will need two little detours into something seemingly irrelevant, but even cooler (a little teaser, they both start with a capital “G”! OK, maybe that wasn’t so informative). Soon you will see how they come together…

The Gaussian Integral: 大方无隅 (“The Great Square Has No Corners”)

Now, here is the juicy bit… Why do we need a different coordinate system? Well, other than when we may need definite integrals over a less edgy domain (like the spheres), here is a beautiful result that requires it. This is the Gaussian Integral:

I=∫x=−∞x=∞e−x2dxI=\int_{x=-\infty}^{x=\infty}e^{-x^2}dx

It represents the area under the curve of a bell curve. It looks simple, but isn’t easy to solve at all… For instance, try the obvious u-substitution:

u=x2,du=2xdxu=x^2,du=2xdx

Ah-oh. That xx there is not friendly…
How can we solve this important and simple looking integral? Clever mathematicians, I believe Poisson, figured out a way.

I=∫x=−∞x=∞e−x2dx=∫y=−∞y=∞e−y2dyI=\int_{x=-\infty}^{x=\infty}e^{-x^2}dx=\int_{y=-\infty}^{y=\infty}e^{-y^2}dy

Nothing fancy, just did the same thing with a different name.

I2=∫y=−∞y=∞e−y2dy∫x=−∞x=∞e−x2dx=∫y=−∞y=∞∫x=−∞x=∞e−(x2+y2)dxdyI^2=\int_{y=-\infty}^{y=\infty}e^{-y^2}dy\int_{x=-\infty}^{x=\infty}e^{-x^2}dx=\int_{y=-\infty}^{y=\infty}\int_{x=-\infty}^{x=\infty}e^{-(x^2+y^2)}dxdy

Now we see why we are choosing a different name. Note how x2+y2x^2+y^2 is nothing other than r2r^2 in polar coordinates. Now, since we are integrating both xx and yy from positive to negative infinity, that is essentially the whole plane. It makes no difference which way we are integrating, edgy or not. Let’s turn the integrals polar, leaving the function untouched:

I2=∫r=0r=∞∫θ=−πθ=πe−r2rdrdθI^2=\int_{r=0}^{r=\infty}\int_{\theta=-\pi}^{\theta=\pi}e^{-r^2}rdrd\theta

Something very significant has quietly occurred. Remember that unfriendly xx in Cartesian? We now get to tackle it. Note how the function inside the integrals is now re−r2re^{-r^2}, which looks exactly like the original function, just with rr in place of xx (which doesn’t make a difference to the function itself) and with an additional rr coming from the property of the arc length.
We can now do it the peaceful way:

u=r2,du=2rdru=r^2,du=2rdr I2=12∫u=0u=∞∫θ=−πθ=πe−ududθ=πI^2=\frac{1}{2}\int_{u=0}^{u=\infty}\int_{\theta=-\pi}^{\theta=\pi}e^{-u}dud\theta=\pi I=πI=\sqrt{\pi}

How pretty! This result will be used as our first component for n-dimensional spheres, although they don’t look akin at the moment. Note that although we were able to find II, this method can no longer be used if we are looking at finite limits, since then the domain of I2I^2 becomes a square and we can no longer use polar integration.

The Gamma Function: Halfway Between 1 and 1

0!0! is 1. 1!1! is also 1. If you happen to be 22-year-old Euler in 1729, you would ask: what is one-half factorial? The answer was surprising. It isn’t 1, it has a π\pi in it. That’s what sent him looking for an integral that gives the factorial, and his integral, rewritten a little, is the Gamma function (https://arxiv.org/pdf/1908.01571).

For Re(x)>0\text{Re} (x) >0:

Γ(x)=∫t=0t=∞tx−1e−tdt\Gamma(x)=\int_{t=0}^{t=\infty}t^{x-1}e^{-t}dt

First, note that this function has a certain property. Consider Γ(x+1)\Gamma(x+1), use integration by parts:

Γ(x+1)=∫t=0t=∞txe−tdt=[−txe−t]t=0t=∞+∫t=0t=∞e−txtx−1dt=0+x∫t=0t=∞tx−1e−tdt=xΓ(x)\begin{align*} \Gamma(x+1)&= \int_{t=0}^{t=\infty}t^{x}e^{-t}dt \\ &= \bigg[-t^x e^{-t}\bigg]_{t=0}^{t=\infty}+\int_{t=0}^{t=\infty}e^{-t}xt^{x-1}dt \\ &=0+x\int_{t=0}^{t=\infty}t^{x-1}e^{-t}dt \\ &= x\Gamma(x) \end{align*}

Remember how we mentioned how mathematics can allow us to generalize an operation limited to a certain circumstance? When we see this property of this function, it feels like we can use it to generalize the factorial function, since it also satisfies f(x+1)=xf(x)f(x+1)=xf(x) like the factorial (more precisely, (x−1)!(x-1)!), but can be applied to more than just natural numbers!

Γ(1)=∫t=0t=∞t0e−tdt=0−(−1)=1\Gamma(1)=\int_{t=0}^{t=\infty}t^{0}e^{-t}dt=0-(-1)=1

By induction, Γ(n+1)=n!\Gamma(n+1)=n!.
There, we showed that the Gamma function can be used in place of factorial for natural numbers, but why don’t we generalize further?

Γ(12)=∫t=0t=∞t−12e−tdt\Gamma(\frac{1}{2})=\int_{t=0}^{t=\infty}t^{-\frac{1}{2}}e^{-t}dt

Let t=u2,dt=2udut=u^2, dt = 2udu, and get ready for some grand reveal…

Γ(12)=∫u=0u=∞u−1e−u22udu=2∫u=0u=∞e−u2du\begin{align*} \Gamma(\frac{1}{2})&= \int_{u=0}^{u=\infty}u^{-1}e^{-u^2}2udu \\ &= 2\int_{u=0}^{u=\infty}e^{-u^2}du \end{align*}

Whaaaaaat?! Is this not our beloved… Gaussian Integral?
Well, almost our Gaussian Integral, this one is from u=0u=0 to u=∞u=\infty instead from −∞-\infty, but that can’t stop us. The function inside the Gaussian Integral is an even function, that means:

∫x=−∞x=∞e−x2dx=2∫x=0x=∞e−x2dx\int_{x=-\infty}^{x=\infty}e^{-x^2}dx=2\int_{x=0}^{x=\infty}e^{-x^2}dx

Or, if you don’t buy this, we can integrate from 00 to π2\frac{\pi}{2} on this step instead of from −π-\pi to π\pi, since we are covering the same domain (after we squared it we only look at the first quadrant).

(I′)2=∫r=0r=∞∫θ=0θ=π2e−r2rdrdθ=π4(I')^2=\int_{r=0}^{r=\infty}\int_{\theta=0}^{\theta=\frac{\pi}{2}}e^{-r^2}rdrd\theta=\frac{\pi}{4} Γ(12)=2I′=π\Gamma(\frac{1}{2})=2I'=\sqrt{\pi}

With Γ(12)\Gamma(\frac{1}{2}) and the fact that Γ(x+1)=xΓ(x)\Gamma(x+1)=x\Gamma(x), it is easy to obtain:

xxΓ(x)\Gamma(x)
……
72\frac{7}{2}158π\frac{15}{8}\sqrt\pi
52\frac{5}{2}34π\frac{3}{4}\sqrt\pi
32\frac{3}{2}12π\frac{1}{2}\sqrt{\pi}
12\frac{1}{2}π\sqrt{\pi}
−12-\frac{1}{2}−2π-2\sqrt\pi
−32-\frac{3}{2}43π\frac{4}{3}\sqrt\pi
−52-\frac{5}{2}−815π-\frac{8}{15}\sqrt\pi
−72-\frac{7}{2}16105π\frac{16}{105}\sqrt\pi
……

Note that from Γ(1)=1\Gamma(1) = 1 and Γ(x+1)=xΓ(x)\Gamma(x+1)=x\Gamma(x), Γ(0)=10\Gamma(0)=\frac{1}{0} which is undefined, so are, therefore, all negative integers.

The Balls

We are now finally ready to make all these weird functions come together for the “surface areas” and “volumes” of the spheres.
First, let’s expand our II to more dimensions.

In=(π)n=∫x=−∞x=∞dx∫y=−∞y=∞dy…e−(x2+y2+… )I^n=(\sqrt{\pi})^n=\int_{x=-\infty}^{x=\infty}dx\int_{y=-\infty}^{y=\infty}dy\dots e^{-(x^2+y^2+\dots)}

Let’s go to a “spherical” coordinate for nn dimensions! Note that it is still true that r2=x2+y2+…r^2=x^2+y^2+\dots the entire integral is “spherically” symmetrical, which means that we can still use an integral over rr to find the volume with surface area.

But what is that surface area? Well, we know from unit checking and the fact that it is a n−1n-1 dimensional surface in a nn dimensional space, that it must be in the form of An(R)=snRn−1A_n(R)=s_nR^{n-1}, where sns_n is some constant.
Think of this geometrically. What we did before is to integrate each ∫θ=−πθ=πe−r2rdθ\int_{\theta=-\pi}^{\theta=\pi}e^{-r^2}rd\theta over each drdr, but we don’t need to deal with all that, since we know that it would just be the surface area of a “sphere”, let’s replace it:

In=∫r=0r=∞e−r2snrn−1drI^n=\int_{r=0}^{r=\infty}e^{-r^2}s_nr^{n-1}dr

Let t=r2,dt=2rdrt=r^2, dt = 2rdr.

∫r=0r=∞e−r2snrn−1dr=12∫t=0t=∞e−tsntn−22dt=sn2∫t=0t=∞tn2−1e−tdt\begin{align*} \int_{r=0}^{r=\infty}e^{-r^2}s_nr^{n-1}dr &= \frac{1}{2}\int_{t=0}^{t=\infty}e^{-t}s_nt^{\frac{n-2}{2}}dt\\ &= \frac{s_n}{2}\int_{t=0}^{t=\infty}t^{\frac{n}{2}-1}e^{-t}dt \end{align*}

[Giant noise in wonder and celebration] Does this now remind you of something?

In=sn2Γ(n2)I^n=\frac{s_n}{2}\Gamma(\frac{n}{2})

The best part is, we already know what InI^n is, it is (π)n(\sqrt{\pi})^n!

(π)n=sn2Γ(n2)(\sqrt{\pi})^n=\frac{s_n}{2}\Gamma(\frac{n}{2}) sn=2(π)nΓ(n2)=2πn2Γ(n2)s_n=\frac{2(\sqrt{\pi})^n}{\Gamma(\frac{n}{2})}=\frac{2\pi^{\frac{n}{2}}}{\Gamma(\frac{n}{2})}

My friends, this is a big moment! Through n-dimensional Gaussian Integral, and the Gamma Function, we have obtained a formula for the surface area of an n-dimensional sphere!!

An(R)=2πn2Γ(n2)Rn−1A_n(R)=\frac{2\pi^{\frac{n}{2}}}{\Gamma(\frac{n}{2})}R^{n-1}

Which means the volume is:

∫r=0r=RAn(r)dr=2πn2Γ(n2)∫r=0r=Rrn−1dr=2πn2Γ(n2)1nRn=2nπn2Γ(n2)Rn=πn2n2Γ(n2)Rn=πn2Γ(n2+1)Rn\begin{align*} \int_{r=0}^{r=R}A_n(r)dr &= \frac{2\pi^{\frac{n}{2}}}{\Gamma(\frac{n}{2})}\int_{r=0}^{r=R}r^{n-1}dr \\ &= \frac{2\pi^{\frac{n}{2}}}{\Gamma(\frac{n}{2})}\frac{1}{n}R^n \\ &= \frac{2}{n}\frac{\pi^{\frac{n}{2}}}{\Gamma(\frac{n}{2})}R^n \\ &= \frac{\pi^{\frac{n}{2}}}{\frac{n}{2}\Gamma(\frac{n}{2})}R^n \\ &= \frac{\pi^{\frac{n}{2}}}{\Gamma(\frac{n}{2}+1)}R^n \end{align*}

Or just:

Vn(R)=An(R)nRV_n(R)=\frac{A_n(R)}{n}R
nnAn(R)A_n(R)Vn(R)V_n(R)
1222R2R
22πR2\pi RπR2\pi R^2
34πR24\pi R^243πR3\frac{4}{3}\pi R^3
42π2R32\pi^2 R^312π2R4\frac{1}{2}\pi^2 R^4
583π2R4\frac{8}{3}\pi^2 R^4815π2R5\frac{8}{15}\pi^2 R^5
6π3R5\pi^3 R^516π3R6\frac{1}{6}\pi^3 R^6
71615π3R6\frac{16}{15}\pi^3 R^616105π3R7\frac{16}{105}\pi^3 R^7
………

2023 Is a Bad Year for High Dimensional Mooncake Vendors

Let’s pack a (oddly spherical) mooncake of radius RR into the smallest box that fits it: a cube with side 2R2R. The volume of the box in nn dimensions is

(2R)n=2nRn(2R)^n=2^nR^n

So the fraction of the box that is actually mooncake is

Vn(R)(2R)n=πn2Γ(n2+1)Rn2nRn=πn22n Γ(n2+1)\begin{align*} \frac{V_n(R)}{(2R)^n} &= \frac{\frac{\pi^{\frac{n}{2}}}{\Gamma(\frac{n}{2}+1)}R^n}{2^nR^n} \\ &= \frac{\pi^{\frac{n}{2}}}{2^n\,\Gamma(\frac{n}{2}+1)} \end{align*}

n=1n=1:

π122 Γ(32)=π2⋅12π=1\frac{\pi^{\frac{1}{2}}}{2\,\Gamma(\frac{3}{2})}=\frac{\sqrt{\pi}}{2\cdot\frac{1}{2}\sqrt{\pi}}=1

n=2n=2:

π4 Γ(2)=π4≈0.785\frac{\pi}{4\,\Gamma(2)}=\frac{\pi}{4}\approx 0.785

n=3n=3:

π328 Γ(52)=π328⋅34π=π6≈0.524\frac{\pi^{\frac{3}{2}}}{8\,\Gamma(\frac{5}{2})}=\frac{\pi^{\frac{3}{2}}}{8\cdot\frac{3}{4}\sqrt{\pi}}=\frac{\pi}{6}\approx 0.524

n=10n=10:

π5210 Γ(6)=π51024⋅5!=π5122880≈0.0025\frac{\pi^{5}}{2^{10}\,\Gamma(6)}=\frac{\pi^5}{1024\cdot 5!}=\frac{\pi^5}{122880}\approx 0.0025

n=100n=100:

π502100 Γ(51)=π502100⋅50!≈1.9×10−70\frac{\pi^{50}}{2^{100}\,\Gamma(51)}=\frac{\pi^{50}}{2^{100}\cdot 50!}\approx 1.9\times10^{-70}

Where did all the space go? To the corners. A corner of the box is at (R,R,…,R)(R, R, \dots, R), so its distance from the center is

R2+R2+⋯+R2=nR2=Rn\sqrt{R^2+R^2+\dots+R^2}=\sqrt{nR^2}=R\sqrt{n}

In 100 dimensions, the corners are 10R10R away from the center, while the mooncake only reaches RR. Even the tightest box is basically all gap.

From n=6n=6 on, even the tightest possible box is over 12 times the mooncake, more than China’s standard allows (around 10 times). Thanks to this, no evil 6-dimensional mooncake box could ever pass the standard.

Acknowledgement

Professor Noah Graham supplied most of the information in this page in his lectures and problem sets.

~ $ cat comments  # 0 — muxiao reads these
nothing yet — the prompt below is listening.
rm
~ $