The onion constant is not 0.557
(This is Yan Sheng.)
In my mind, J. Kenji López-Alt is the greatest nerdsniper chef: he has made claims about cooking methods and techniques, based on experimental evidence, which have become the inspiration for later theoretical research. For instance, on the subject of grilling meat, he writes that "...flipping steak repeatedly during cooking can result in a cooking time about 30% faster than flipping only once"; this was confirmed by a model of Thiffeault (2022) (here are some slides from a talk).
Today's post, however, is about onions:
Question: What is the optimal way to cut an onion such that the size variation among the diced pieces is minimised?
After removing the ends and halving the onion, we can view it as approximately a half-cylinder with concentric layers. This reduces the dimension of the problem, so now we're cutting concentric semicircles:
(In the following diagrams, I'm viewing the arcs themselves as the layers, and not the spaces between the arcs. I will also only draw the right half of the above picture, due to symmetry.)
One traditional method is to make vertical cuts, but this would cause the lowest piece of each layer to be too large. An alternative is to cut radially, but this makes the inner pieces tiny.
To avoid both problems above, López-Alt has proposed in one of his cooking videos to cut radially towards a point $\approx0.6r$ below the centre:
Naturally, the question now is to find the constant $\approx0.6$ which determines the optimal "onion point". Dylan Poulsen has written a Medium article which does exactly that, evaluating the constant numerically to 1000 decimal places, starting $0.55730669\ldots$ López-Alt has cited Poulsen in a newer video and a New York Times article. Chefs everywhere can now sleep well at night, now that we know the optimal way to cut an onion.
Except that I think Poulsen was wrong, and the onion constant isn't 0.557. The rest of this post explains why.
Exercise (for the interested reader): Take this time to read Poulsen's article, and point out some weaknesses in his analysis.
First thoughts
The onion problem seems pretty hard, so let's ask an easy question first: can we cut the onion perfectly? In other words, what would it look like if we could get all the pieces to be exactly the same size?
Since the length of each layer is proportional to its radius, the number of pieces each layer needs to be cut into is also proportional to its radius:
Now if we attempt to line all of the cut points up, starting from the middle of the onion and going outwards, we find that they don't quite lie on straight lines:
It's not too hard to derive the polar equation for the curves that the cut points lie on: it turns out that these are segments of hyperbolic spirals, given by $r\theta=\text{const}$. In the real world, these curves are used to determine the starting positions for the 200m and 400m races on an athletics track, for exactly the same reason that they appeared in our problem: to ensure that the arc lengths on concentric circles stay constant when the radius varies.
Here's another way of looking at the same situation: imagine unrolling each semicircular layer into a straight line segment (just like in one of the proofs for the area of the circle). Now to get pieces of equal size, we just have to make even cuts perpendicular to the layers. Wrapping these back into the semicircle yields the hyperbolic spiral cuts on the original onion:
Okay, so we've solved the problem if we could cut arbitrary curves into our onion. Unfortunately, real knives aren't usually floppy, so this doesn't actually work in real life.
Far from home
Say we can only cut using straight line segments. Let's try the next easiest thing: the curve segments are mostly straight-ish, so why not just straighten them out? We'll do almost as well if we cut straight from the (evenly spaced) endpoints on the perimeter to the (evenly spaced) endpoints on the diameter:
Notice how the lines look like they converge to roughly the same point below the centre, so the intuition by López-Alt is largely sound. However, if we look at where they converge:
Exercise:
- Show that, if the quarter onion is the unit circle in the first quadrant centred at the origin, then the cut with $x$-intercept $t$ has $y$-intercept $-\dfrac{t\cos(\frac\pi2t)}{\sin(\frac\pi2t)-t}$.
- Show that the above quantity increases from $-\dfrac2{\pi-2}=-1.75\ldots$ at $t=0$ to $-\dfrac\pi2=-1.57\ldots$ at $t=1$.
That's pretty far from -0.557..., so what's the difference between what we just did and the Poulsen result?
A better model
Recall our statement of the onion problem:
Question: What is the optimal way to cut an onion such that the size variation among the diced pieces is minimised?
This is how Poulsen translated the above vague wording into a precise mathematical question, summarised in English:
The Poulsen Problem: Assuming that all cuts pass through a single "onion point" below the centre of the onion, find the choice of onion point that minimises the variance of the Jacobian of a certain coordinate system over the onion.
For those who are unfamiliar with the Jacobian (determinant), the core idea is that it is a scaling factor that captures the idea of "the size of a piece", in the limit as the number of onion layers and the number of cuts go to infinity. Oh, and of course we're making the simplifying assumption that the onion has infinitely many layers, and we're making infinitely many cuts.
I'm going to assume that Poulsen did solve his formulation of the onion problem correctly, and that 0.557... is in fact the correct onion constant for his formulation. (Mostly because I'm not going to check stuff like this:)
So there must be some subtlety in his formulation of the problem which causes it to fail to capture the fact that our naive attempt should be close to optimal. Further reflection leads us to isolate the following two issues:
Poulsen uses a coordinate system $(r,\theta)$ tailor-made for the problem: $r$ is the distance to the centre of the onion (so $r=\text{const}$ along layers of the onion), and $\theta$ is the angle measured from the onion point (so $\theta=\text{const}$ along cuts). The problem with taking the Jacobian relative to this coordinate system is that it introduces the artificial assumption that cuts are at regularly spaced angular increments from the onion point.
This property doesn't hold for the perfect cut! In order to cut even a single layer into equal parts, the angles of the cuts from the onion point have to become clustered closer and closer together as we go from the middle out towards the ends:
The Poulsen model lacks such a parametrisation of the $\theta$ variable. Note that this has little effect if the onion point is close to the centre of the onion, but the further (i.e., lower) the onion point goes, the bigger the disadvantage of restricting to constant angular speed.
The metric used in the Poulsen model (variance of the Jacobian) is not scale-invariant. Imagine if we have already diced our onion, but now we cut each of the pieces in half. Intuitively, this should not affect "the size variation among the diced pieces"; for instance, if the largest piece was 10 times larger than the smaller piece earlier, this will still be true now. However, the Jacobian has now dropped by a factor of 2 everywhere, so the variance of the Jacobian drops by a factor of 4.
Hence, with all else being equal, the Poulsen model prefers small pieces over large pieces. This also penalises onion points further from the centre, because of the constant angular velocity restriction: cutting at the same angle from further away yields larger pieces.
With these two effects combined, it is not surprising that the Poulsen onion constant 0.557... is much lower than our estimate of 1.6-1.7.
How should we modify Poulsen's formulation to better align with our intuitive idea of the onion problem, and avoid the two issues above?
- The solution to the second issue is easy: instead of minimising the variance of the Jacobian, we minimise the variance of the logarithm of the Jacobian.
- The solution to the first issue is easy to state: instead of using the Jacobian $|J_{r,\theta}|$ with the coordinate $\theta$, we should reparametrise using an arbitrary increasing function $\psi(\theta)$.
Hence our new formulation of the problem goes as follows:
New Onion Problem: Assuming that all cuts pass through a single "onion point" below the centre of the onion, find the choice of onion point and parametrisation $\psi(\theta)$ that minimises the variance of $\log|J_{r,\psi}|$ over the onion.
At first glance, this is horrible: instead of optimising over a single variable (the position of the onion point), we now also have to optimise over all choices of increasing functions $\psi$?? As we will see, this will turn out to actually not be so bad after all.
Technical note: There is another rather subtle choice in the Poulsen model which we will handle differently. The definition of "mean" is "average value", and the definition of "variance" is "average squared distance from the mean", and so one has to choose exactly how this averaging is to be performed. For example, imagine that half of our onion has been chopped into pieces of size $X$, and the other half has been chopped into pieces of size $2X$. The average size of the pieces by area is $3X/2$; on the other hand, there are twice as many small pieces as big pieces, so the average size of the pieces by count is $4X/3$. Poulsen's model effectively averages by count, since he averages over $dr\,d\theta$. We decide to average by area.
Reparametrisation
Let's hold off on the algebra for as long as we can, and see how far we can get purely by reasoning in English.
Suppose that reparametrising the angle increases the number of cuts near some angles $\theta_1$, but decreases it near some angles $\theta_2$:
What happens to the lengths of the pieces? Well, they get multiplied by some constant $<1$ near $\theta_1$, and some constant $>1$ near $\theta_2$. The key point is that they get multiplied by some function that only depends on $\theta$. So all the reparamatrisation is doing is to allow us to fudge $\log|J|$ by adding different constants along rays from the onion point. This strongly suggests that the correct coordinate system for this problem is polar coordinates from the onion point.
Now note that the minimisation problem has the following form: We have a bunch of numbers, grouped in different buckets, and we're allowed to add a different constant to each bucket. How do we minimise the variance among all the numbers? (Pause here if you want to think about how to formalise and solve this problem.)
Intuitively, we probably want to bring each bucket close "in aggregate" to the other buckets, maybe something like equating the means of each bucket. It turns out that this is exactly correct! In fact, the total variance is equal to the variance of the centroids of each bucket, plus the variance within each bucket; this is the parallel axis theorem, sometimes known as Leibniz's theorem for the special case of triangles:$$AP^2+BP^2+CP^2=AG^2+BG^2+CG^2+3PG^2.$$ Now we can get rid of the reparametrisation all together: for a fixed onion point, we compute $\log|J_{r,\theta}|$ inside the semicircle, de-mean along rays from the onion point, then find the variance. We can then vary the onion point and solve the one-variable minimisation problem to get the new onion constant. Nice!
I did the algebra so you don't have to
...but feel free to follow along! You can also safely skip to the next section.
Exercise: Given function $f$ and nonnegative weight $w$, show that the value of $I=\int w(f-C)^2$ is minimised over constants $C$ at $$C=\frac{\int wf}{\int f},\qquad I=\left(\int wf^2\right)-\frac{\left(\int wf\right)^2}{\int w},$$ whenever all integrals are absolutely convergent.
We will follow Poulsen's notation, so polar coordinates from the onion point are given by $(c,\theta)$:
Exercise: Recall that $\displaystyle|J_{u,v}|=\left\lvert\frac{\partial x}{\partial u}\frac{\partial y}{\partial v}-\frac{\partial x}{\partial v}\frac{\partial y}{\partial u}\right\rvert$. For any increasing $\psi(\theta)$, show that $\displaystyle|J_{r,\psi}|=\frac{|J_{r,\theta}|}{\psi'}$.
Exercise: Show that $|J_{r,\theta}|=-r\dfrac{\partial\varphi(r,\theta)}{\partial\theta}$. (This makes sense: $|J_{r,\theta}|$ should be the length of the onion piece between two cuts $d\theta$ apart, and that's exactly $r\,d\varphi$. The negative sign comes from the fact that $\theta$ increases clockwise instead of anticlockwise.)
Exercise: By staring at the following diagram and using the sine law, deduce that $|J_{r,\theta}|=-r\dfrac{\partial\varphi(r,\theta)}{\partial\theta}=\dfrac c{\sin(\theta+\varphi)}$:
Exercise: By applying the cosine law, deduce the following equivalent expressions for for the Jacobian: $$\begin{align*} |J_{r,\theta}|&=\frac{cr}{c-h\cos\theta}=\frac{2rc^2}{c^2+r^2-h^2}\\ &=\frac{r^2+h^2+2rh\sin\varphi}{r+h\sin\varphi}=\frac{c\sqrt{c^2+h^2-2ch\cos\theta}}{c-h\cos\theta}. \end{align*}$$
Remarks:
- Poulsen's expression for the Jacobian simplifies to the last expression above.
- It is possible to derive the Jacobian in other ways, but beware: the partial derivative $\dfrac{\partial f}{\partial r}$ means two different things depending on whether your coordinate system is $(r,\theta)$ or $(r,\varphi)$! Extra care needs to be taken to keep track of which variable is staying constant.
Exercise: Show that for fixed $h>0$ (i.e., fixed onion point), the minimum value over all parametrisations $\psi(\theta)$ for the area-normalised variance of $\log|J_{r,\psi}|$ over the onion is equal to$$\frac4\pi\left[\int_0^{\tan^{-1}(1/h)}\int_{c_1}^{c_2}\log^2|J_{r,\theta}|\,c\,dc\,d\theta-\int_0^{\tan^{-1}(1/h)}\frac2{c_2^2-c_1^2}\left(\int_{c_1}^{c_2}\log|J_{r,\theta}|\,c\,dc\right)^2\,d\theta\right],$$where$$\begin{align*}c_1&=h\sec\theta,\\c_2&=h\cos\theta+\sqrt{1-h^2\sin^2\theta}.\end{align*}$$ Now that's something we can throw into a Jupyter notebook to optimise. I've done that too! Here's Supplementary Material A for this blog post.
Results
Solving the optimisation problem, we get a new onion constant. Poulsen chose to denote his onion constant $ס=0.557\ldots$ with the Hebrew letter samekh, for its resemblance to the onion; in the same tradition of typographic obtuseness, we will denote the true onion constant with an actual onion:$$🧅=0.8283244\ldots$$(The value of the area-normalised variance is 0.0186, corresponding to a value of $\sim14\%$ for the typical variation of the size of the pieces.)
Here's what the cuts look like, superimposed on the hyperbolic spirals representing the perfect solution (left), Poulsen's solution (centre), and cuts at evenly spaced angles (right):
Wait, 0.828 is much lower than our initial estimate of 1.6-1.7. (At least it's larger than Poulsen's constant, like we expected.) What happened?
Let's investigate further. Here are some plots of the Jacobian over the onion with different choices of onion points:
The top row represents cuts with equal angles from the onion point (Poulsen's setup), where the bottom row represents the optimal parametrisation of the angle. From left to right, the onion points are chosen at 0.1, ס, 🧅, 1.65, and 10 radii below the onion centre, respectively. The Jacobian has been normalised such that $\log|J_{r,\theta}|$ has mean 0, i.e., the size of the pieces have geometric mean 1.
Immediately we see the two problematic effects mentioned at the start of this post:
- On the left, where we're making cuts almost towards the onion centre, pieces near the centre become so small that they're off the colour scale, rendering as white (which should be interpreted as very dark);
- On the right, where we're making almost vertical cuts, pieces near the bottom become so large that they're also off the colour scale, but in the other direction. All the choices of onion points in between involve a trade-off between these two opposing effects.
Zooming in onto the middle three plots in the bottom row:
It appears that between ס and 🧅 (left and centre), 🧅 is better because pieces are a more uniform size in a larger area in the middle, which offsets a small increase the number of large pieces in the lower area. Also, the problem with our initial estimate of ~1.65 (right) appears to be that there are too many large pieces in the lower area.
Okay, so now we've really solved the onion problem: cut towards the point 0.83 radii below the centre of the onion. Chefs everywhere can now really sleep well at night, now that we really know the optimal way to cut an onion.
Right?
How I actually cut onions
I'm not a professional chef; I have never needed to dice an industrial amount of onions at once. When I cut onions, I don't do it like J. Kenji López-Alt; I quarter (instead of halve) my onions, then just vertically slice the wedges:
(Again, this is just the right half of the full picture, due to symmetry. Of course, this picture is upside down relative to the orientation of the wedge when cutting in real life.)
How does this method fare relative to what we've discussed so far? Here are the Jacobian plots, for both evenly spaced and optimally parametrised vertical cuts, with the same colour scale as the previous plots:
These appear to have nearly equal or lower variance than the previous plots! Indeed, the area-normalised variance for the log Jacobians are 0.0148 on the left and 0.00424 on the right, corresponding to typical variations of ~12% and ~6.5% for the piece sizes.
In hindsight, this makes perfect sense: the layers of a quarter onion are less curved than those of a half onion, so the straightening operation we performed before is less drastic, so it's much easier to approximate the hyperbolic spirals with straight (or even vertical) cuts:
Another way of looking at it is that now the tangents to each pieces are far from being vertical, so that the problem of large pieces with vertical cuts goes away.
Here are the optimal parametrised vertical cuts, with the hyperbolic spirals. Look how close they are:
So it appears that I've done a whole lot of math to not change how I cut my onions, after all...
Further questions
- Calculate 🧅 to 1000 decimal places. This is of personal interest to me; I've done it before for a different constant. Poulsen could do it for his constant because he found a closed form for the derivative of the variance integral with respect to the onion point; it doesn't look so easy in our problem.
- Find the value of the onion constant for the quarter onion. It's probably much larger than 🧅, because vertical cuts already look pretty good.
- What are the optimal straight cuts for the half onion, if we no longer restrict the cuts to pass through a common onion point? The cuts will have to be parametrised in a different way, for example by specifying where the cut passing through each point on the diameter intersects the outermost layer.
- Real onions aren't cylinders; model and solve the onion problem in 3 dimensions.
- Find an optimisation problem in your own life. Come up with a mathematical model and find the optimal solution. What are the assumptions and limitations of the model, and how applicable are the results to real life?
Comments
Post a Comment