# Ham sandwich theorem

In mathematical measure theory, for every positive integer n the ham sandwich theorem states that given n measurable "objects" in n-dimensional Euclidean space, it is possible to divide each one of them in half (with respect to their measure, e.g. volume) with a single (n − 1)-dimensional hyperplane. This is possible even if the objects overlap.
It was proposed by Hugo Steinhaus and proved by Stefan Banach (explicitly in dimension 3, without stating the theorem in the n-dimensional case), and also years later called the Stone–Tukey theorem after Arthur H. Stone and John Tukey.

## Naming

The ham sandwich theorem takes its name from the case when n = 3 and the three objects to be bisected are the ingredients of a ham sandwich. Sources differ on whether these three ingredients are two slices of bread and a piece of ham (Peters 1981), bread and cheese and ham (Cairns 1963), or bread and butter and ham (Dubins & Spanier 1961). In two dimensions, the theorem is known as the pancake theorem to refer to the flat nature of the two objects to be bisected by a line (Cairns 1963).

## History

According to Beyer & Zardecki (2004), the earliest known paper about the ham sandwich theorem, specifically the n = 3 case of bisecting three solids with a plane, is a 1938 note in a Polish mathematics journal (Editors 1938). Beyer and Zardecki's paper includes a translation of this note, which attributes the posing of the problem to Hugo Steinhaus, and credits Stefan Banach as the first to solve the problem, by a reduction to the Borsuk–Ulam theorem. The note poses the problem in two ways: first, formally, as "Is it always possible to bisect three solids, arbitrarily located, with the aid of an appropriate plane?" and second, informally, as "Can we place a piece of ham under a meat cutter so that meat, bone, and fat are cut in halves?" The note then offers a proof of the theorem.
A more modern reference is Stone & Tukey (1942), which is the basis of the name "Stone–Tukey theorem". This paper proves the n-dimensional version of the theorem in a more general setting involving measures. The paper attributes the n = 3 case to Stanislaw Ulam, based on information from a referee; but Beyer & Zardecki (2004) claim that this is incorrect, given the note mentioned above, although "Ulam did make a fundamental contribution in proposing" the Borsuk–Ulam theorem.

## Two-dimensional variant: proof using a rotating-knife

The two-dimensional variant of the theorem (also known as the pancake theorem) can be proved by an argument which appears in the fair cake-cutting literature (see e.g. Robertson–Webb rotating-knife procedure).
For each angle $\alpha \in [0,180^{\circ }]$, a straight line ("knife") of angle $\alpha$ can bisect pancake #1. To see this, translate along its normal a straight line of angle $\alpha$ from $-\infty$ to $\infty$; the fraction of pancake #1 covered by the line changes continuously from 0 to 1, so by the intermediate value theorem it must be equal to 1/2 somewhere along the way. It is possible that an entire range of translations of our line yield a fraction of 1/2; in this case, it is a canonical choice to pick the middle one of all such translations.
When the knife is at angle 0, it also cuts pancake #2, but the pieces are probably unequal (if we are lucky and the pieces are equal, we are done). Define the 'positive' side of the knife as the side in which the fraction of pancake #2 is larger. We now turn the knife, and translate it as described above. When the angle is $\alpha$, define $p(\alpha )$ as the fraction of pancake #2 at the positive side of the knife. Initially $p(0)>1/2$. The function $p$ is continuous, since small changes in the angle lead to small changes in the position of the knife.
When the knife is at angle 180, the knife is upside-down, so $p(180)<1/2$. By the intermediate value theorem, there must be an angle in which $p(\alpha )=1/2$. Cutting at that angle bisects both pancakes simultaneously.

## n-dimensional variant: proof using the Borsuk–Ulam theorem

The ham sandwich theorem can be proved as follows using the Borsuk–Ulam theorem. This proof follows the one described by Steinhaus and others (1938), attributed there to Stefan Banach, for the n = 3 case. In the field of Equivariant topology, this proof would fall under the configuration-space/tests-map paradigm.
Let A$_1$, A$_2$, ..., A$_n$ denote the n compact (or more genreral: bounded and Lebesgue-measurable) subsets of $\mathbb {R} ^{n}$ that we wish to simultaneously bisect. Let $S=\{v=(v_{1},\ldots ,v_{n})\in \mathbb {R} ^{n}\colon v_{1}^{2}+\ldots +v_{n}^{2}=1\}$ be the unit (n − 1)-sphere in $\mathbb {R} ^{n}$. For each point v on S, we can define a continuum $(E_{v,c})_{c\in \mathbb {R} }$ of affine hyperplanes with normal vector v: $E_{v,c}=\{x\in \mathbb {R} ^{n}\colon x_{1}v_{1}+\ldots +x_{n}v_{n}=c\}$ for $c\in \mathbb {R}$. For each $c\in \mathbb {R}$, we call the space $E_{v,c}^{+}=\{x\in \mathbb {R} ^{n}\colon x_{1}v_{1}+\ldots +x_{n}v_{n}>c\}$ the "positive side" of $E_{v,c}$, which is the side pointed to by the vector v. By the intermediate value theorem, every family of such hyperplanes contains at least one hyperplane that bisects the bounded set A$_n$: at one extreme translation, no volume of A$_n$ is on the positive side, and at the other extreme translation, all of A$_n$'s volume is on the positive side, so in between there must be a closed interval I$_v$ of possible values of $c\in \mathbb {R}$, for which $E_{v,c}$ bisects the volume of A$_n$. If A$_n$ has volume zero, we pick $c=0$ for all $v\in S$. Otherwise, the interval I$_v$ is compact and we can canonically pick $c={\frac {1}{2}}(\inf I_{v}+\sup I_{v})$ as its midpoint for each $v\in S$. Thus we obtain a continuous function $\alpha \colon S\to \mathbb {R}$ such that for each point v on the sphere S the hyperplane $E_{v,\alpha (v)}$ bisects A$_n$. Note further that we have $I_{-v}=-I_{v}$ and thus $\alpha (-v)=-\alpha (v)$ for all $v\in S$.
Now we define a function $f\colon S\to \mathbb {R} ^{n-1}$ as follows:
    $f(v)=(vol(A_{1}\cap E_{v,\alpha (v)}^{+}),\ldots ,vol(A_{n-1}\cap E_{v,\alpha (v)}^{+}))$.
This function f is continuous (which can be proven with the dominated convergence theorem). By the Borsuk–Ulam theorem, there are antipodal points $v$ and $-v$ on the sphere S such that $f(v)=f(-v)$. Antipodal points correspond to hyperplanes $E_{v,\alpha (v)}$ and $E_{-v,\alpha (-v)}=E_{-v,-\alpha (v)}$ that are equal except that they have opposite positive sides. Thus, $f(v)=f(-v)$ means that the volume of A$_i$ is the same on the positive and negative side of $E_{v,\alpha (v)}$, for $i=1,\ldots ,n$. Thus, $E_{v,\alpha (v)}$ is the desired ham sandwich cut that simultaneously bisects the volumes of A$_1$, ..., A$_n$.

## Measure theoretic versions

In measure theory, Stone & Tukey (1942) proved two more general forms of the ham sandwich theorem. Both versions concern the bisection of n subsets X$_1$, X$_2$, ..., X$_n$ of a common set X, where X has a Carathéodory outer measure and each X$_i$ has finite outer measure.
Their first general formulation is as follows: for any continuous real function $f\colon S^{n}\times X\to \mathbb {R}$, there is a point p of the n-sphere S$^n$ and a real number s$_0$ such that the surface f(p,x) = s$_0$ divides X into f(p,x) < s$_0$ and f(p,x) > s$_0$ of equal measure and simultaneously bisects the outer measure of X$_1$, X$_2$, ..., X$_n$. The proof is again a reduction to the Borsuk-Ulam theorem. This theorem generalizes the standard ham sandwich theorem by letting f(s,x) = s$_1$x$_1$ + ... + s$_n$x$_n$.
Their second formulation is as follows: for any n + 1 measurable functions f$_0$, f$_1$, ..., f$_n$ over X that are linearly independent over any subset of X of positive measure, there is a linear combination f = a$_0$f$_0$ + a$_1$f$_1$ + ... + a$_n$f$_n$ such that the surface f(x) = 0, dividing X into f(x) < 0 and f(x) > 0, simultaneously bisects the outer measure of X$_1$, X$_2$, ..., X$_n$. This theorem generalizes the standard ham sandwich theorem by letting f$_0$(x) = 1 and letting f$_i$(x), for i > 0, be the i-th coordinate of x.

## Discrete and computational geometry versions

In discrete geometry and computational geometry, the ham sandwich theorem usually refers to the special case in which each of the sets being divided is a finite set of points. Here the relevant measure is the counting measure, which simply counts the number of points on either side of the hyperplane. In two dimensions, the theorem can be stated as follows:
    For a finite set of points in the plane, each colored "red" or "blue", there is a line that simultaneously bisects the red points and bisects the blue points, that is, the number of red points on either side of the line is equal and the number of blue points on either side of the line is equal.
There is an exceptional case when points lie on the line. In this situation, we count each of these points as either being on one side, on the other, or on neither side of the line (possibly depending on the point), i.e. "bisecting" in fact means that each side contains less than half of the total number of points. This exceptional case is actually required for the theorem to hold, of course when the number of red points or the number of blue is odd, but also in specific configurations with even numbers of points, for instance when all the points lie on the same line and the two colors are separated from each other (i.e. colors don't alternate along the line). A situation where the numbers of points on each side cannot match each other is provided by adding an extra point out of the line in the previous configuration.
In computational geometry, this ham sandwich theorem leads to a computational problem, the ham sandwich problem. In two dimensions, the problem is this: given a finite set of n points in the plane, each colored "red" or "blue", find a ham sandwich cut for them. First, Megiddo (1985) described an algorithm for the special, separated case. Here all red points are on one side of some line and all blue points are on the other side, a situation where there is a unique ham sandwich cut, which Megiddo could find in linear time. Later, Edelsbrunner & Waupotitsch (1986) gave an algorithm for the general two-dimensional case; the running time of their algorithm is O(n log n), where the symbol O indicates the use of Big O notation. Finally, Lo & Steiger (1990) found an optimal O(n)-time algorithm. This algorithm was extended to higher dimensions by Lo, Matoušek & Steiger (1994) where the running time is $o(n^{d-1})$. Given d sets of points in general position in d-dimensional space, the algorithm computes a (d−1)-dimensional hyperplane that has an equal number of points of each of the sets in both of its half-spaces, i.e., a ham-sandwich cut for the given points. If d is a part of the input, then no polynomial time algorithm is expected to exist, as if the points are on a moment curve, the problem becomes equivalent to necklace splitting, which is PPA-complete.
A linear-time algorithm that area-bisects two disjoint convex polygons is described by Stojmenovíc (1991).

## Generalizations

The original theorem works for at most n collections, where n is the number of dimensions. To bisect a larger number of collections without going to higher dimensions, one can use, instead of a hyperplane, an algebraic surface of degree k, i.e., an (n−1)–dimensional surface defined by a polynomial function of degree k:
Given ${\binom {k+n}{n}}-1$ measures in an n–dimensional space, there exists an algebraic surface of degree k which bisects them all. (Smith & Wormald (1998)).
This generalization is proved by mapping the n–dimensional plane into a ${\binom {k+n}{n}}-1$ dimensional plane, and then applying the original theorem. For example, for n = 2 and k = 2, the 2–dimensional plane is mapped to a 5–dimensional plane via:
    (x, y) → (x, y, x$^2$, y$^2$, xy).