Separating hyperplanes: a line between two convex sets
The question
Four pairs of convex polygons. For which pairs can one straight line keep the two shapes on opposite sides?
Draw the line yourself; the page checks every corner.
- 1 SeeDraw a line between two shapes.
- 2 TryFind closest points; make two predictions.
- 3 ProveBuild the line from the closest point.
- 4 ApplyProblems to check yourself.
Before you start · 3 quick checks on the dot product, the two sides of a line and mixing two points, about 3 min
Two ideas before you start
2 ideasA line splits the plane in two
Figure: the line x + 2y = 6, the side where x + 2y is less than 6 shaded, and the points P = (1, 1), Q = (2, 2) and R = (4, 3). It needs JavaScript.
x + 2y at P = 1 + 2 · 1 = 3 3 < 6 P is on the shaded side.
Put a point into x + 2y and compare with 6: less, and it is on one side of the line x + 2y = 6; more, and it is on the other; equal, and it is on the line.
Exact definition
Hyperplanes and half-spaces. For a vector \(a \ne 0\) in \(\mathbb{R}^n\) and a number \(c\), the set \(H = \{x : a\cdot x = c\}\) is a hyperplane: a line when \(n = 2\), a plane when \(n = 3\). It splits \(\mathbb{R}^n\) into the two closed half-spaces \(\{x : a\cdot x \le c\}\) and \(\{x : a\cdot x \ge c\}\), which share \(H\), and the two open half-spaces where the inequalities are strict. The vector \(a\) is perpendicular to \(H\) and points into the side where \(a\cdot x \gt c\).
A line \(y = k + mx\) is the hyperplane \(a\cdot x = c\) with \(a = (-m, 1)\) and \(c = k\), so the points above it are those with \(a\cdot x \gt c\). The dot product is the one from the lesson on the dot product and the closest point on a line.
Separate: each set on its own side
Figure: a triangle A at the lower left, a triangle B at the upper right, and a dashed line between them. It needs JavaScript.
Strict: every corner of A is strictly below the line and every corner of B strictly above it. The line touches neither set.
A line separates two sets when each lies on its own closed side. If neither set touches the line, the separation is strict; if a set touches it, the separation is only weak.
Exact definition
Separation. A hyperplane \(a\cdot x = c\) with \(a \ne 0\) separates two sets \(A\) and \(B\) when \(a\cdot x \le c \le a\cdot y\) for every \(x \in A\) and every \(y \in B\), or the same with \(A\) and \(B\) swapped: each set lies in its own closed half-space. It separates them strictly when \(a\cdot x \lt c \lt a\cdot y\) for every \(x \in A\) and every \(y \in B\) (or swapped): neither set meets the hyperplane. On this page a weak separation is a separation that is not strict.
A set \(C\) is convex when it contains the point \((1 - t)u + tv\) for every \(u, v \in C\) and every \(t\) with \(0 \le t \le 1\), as in the lesson on convex sets and convex functions. Filled convex polygons, disks and half-spaces are convex sets.
Fine print: closed, bounded, and other names
A set is closed when it contains the limit of every convergent sequence of its points, and bounded when it fits inside some disk (in \(\mathbb{R}^n\), some ball). A filled polygon with its edges is closed and bounded; a half-plane \(\{(x, y) : y \le 0\}\) is closed but not bounded.
Some books reserve the name strong separation for a hyperplane with a positive gap: \(a\cdot x \le c - \varepsilon\) and \(a\cdot y \ge c + \varepsilon\) for some \(\varepsilon \gt 0\). For two nonempty, closed and bounded sets, strict and strong separation are the same thing, because \(a\cdot x\) then reaches its largest value on one set and its smallest on the other.
Draw a line between two shapes
- Drag the two round handles up or down to move the ends of your line, or focus a handle and use the arrow keys.
- Press Check my line when you think your line keeps A and B on opposite sides.
- Think no line can do it? Press No line separates them.
How the page decides
Your line runs from \(x = 0\) to \(x = 10\); each handle sets its height at one end, in steps of 0.1 from 0 to 7. The page checks the corners. Each side of a line is convex, and every point of a convex polygon is a weighted average of its corners, with nonnegative weights that add up to 1. So a polygon lies on one closed side of the line exactly when all its corners do, and strictly on one side exactly when all its corners do. Every corner has coordinates in halves, so the comparisons are exact.
A check that fails leaves the round open. A line that separates, or the button, ends the round. There are four rounds; after the last one a table compares your answers with the best possible ones. Start over clears everything.
| Round | Your answer | Best possible | Match |
|---|
One point and one convex set
A prediction first. The explorer below it opens once it is answered.
The explorer and its goals open after you answer the prediction.
Explorer: move the point b
Move \(b\) with the two sliders. The page finds the point \(p\) of \(C\) closest to \(b\), puts \(a = b - p\), and draws the line \(a\cdot x = c\) with \(c = a\cdot(p + b)/2\), halfway between \(p\) and \(b\).
Goals
How the page finds p
If \(b\) is in \(C\), then \(p = b\). Otherwise the page finds, on each edge from \(u\) to \(v\), the point \(u + s(v - u)\) with \[s = \frac{(b - u)\cdot(v - u)}{|v - u|^2},\] moved to the nearer end when \(s\) falls outside \([0, 1]\), and keeps the one nearest to \(b\). The values in the tiles are exact fractions, rounded to three decimals where they are written with ≈.
Two sets that do not meet
Why a closest point gives a separating line
Assumptions. \(n \ge 1\), \(C\) is a nonempty, closed, convex subset of \(\mathbb{R}^n\), and \(b\) is a point of \(\mathbb{R}^n\) that is not in \(C\).
Conclusion. There are a vector \(a \ne 0\) and a number \(c\) with \(a\cdot x \lt c \lt a\cdot b\) for every \(x \in C\): the hyperplane \(a\cdot x = c\) separates \(b\) from \(C\) strictly.
Facts the proof uses.
- a closest point exists: there is \(p \in C\) with \(|b - p| \le |b - x|\) for every \(x \in C\) (see below);
- convexity: \((1 - t)p + tx \in C\) for \(p, x \in C\) and \(0 \le t \le 1\);
- dot product algebra: \(|u|^2 = u\cdot u\), positive for \(u \ne 0\), and \[\begin{aligned} &|u - v|^2 \\ &= |u|^2 - 2u\cdot v + |v|^2. \end{aligned}\]
Setup. Fix a closest point \(p\) and put \(a = b - p\). Since \(p\) is in \(C\) and \(b\) is not, \(a \ne 0\).
Why a closest point exists
Pick any \(x_0 \in C\) and let \(K\) be the set of points of \(C\) at distance at most \(|b - x_0|\) from \(b\). \(K\) is closed (both conditions survive limits), bounded and nonempty, and the distance \(x \mapsto |b - x|\) is continuous, so it reaches a smallest value on \(K\) at some \(p\). Every point of \(C\) outside \(K\) is farther from \(b\) than \(x_0\), so \(p\) is a closest point of all of \(C\). Convexity also makes \(p\) unique (the last item under "What else follows", after the proof), but the proof does not need that.
Each option is one step about \(C\), \(b\), \(p\) and \(a\) of the theorem. Pick the one that is true for every set and point the theorem covers. A step that says "for every \(x \in C\)" must hold for every point of \(C\), the point \(p\) itself included.
- Two sets with a gap. Let \(A\) and \(B\) be nonempty, closed, convex sets in \(\mathbb{R}^n\) with no common point, and let \(A\) also be bounded. The set \(D = \{x - y : x \in A,\ y \in B\}\) is convex, and 0 is not in it. It is also closed, because \(A\) is closed and bounded; that step needs a limit argument and is taken here without proof. The theorem with \(C = D\) and \(b = 0\) gives \(a \ne 0\) and \(c \lt 0\) with \(a\cdot x - a\cdot y \lt c\) for every \(x \in A\) and \(y \in B\). With \(s\) the largest value of \(a\cdot x\) on \(A\), the hyperplane \(a\cdot z = s - c/2\) has \(A\) strictly on one side and \(B\) strictly on the other, with room \(|c|/2\) on each side. Round 1 and round 4 of stage 1 are of this kind.
- Sets that touch. Let \(A\) and \(B\) be nonempty convex sets in \(\mathbb{R}^n\), \(A\) with an interior point, and suppose no interior point of \(A\) lies in \(B\). Then some hyperplane separates them, perhaps only weakly. This theorem needs a limit argument and is stated here without proof; round 2 of stage 1 is an example.
- Supporting lines. Line 3 says \(a\cdot x \le a\cdot p\) for every \(x \in C\): the hyperplane \(a\cdot x = a\cdot p\) touches \(C\) at \(p\) and has all of \(C\) on one side. So the linear objective \(a\cdot x\) reaches its largest value on \(C\) at \(p\). In general, a linear objective \(f\cdot x\) with \(f \ne 0\) is largest on \(C\) at a point \(q\) of \(C\) exactly when the hyperplane \(f\cdot x = f\cdot q\) has all of \(C\) on the side \(f\cdot x \le f\cdot q\). The lesson on Lagrange multipliers finds optima on a constraint curve from a related picture: the level curve of the objective touches the constraint.
- A test for the closest point, and uniqueness. A point \(p\) of \(C\) is the closest point of \(C\) to \(b\) exactly when \((x - p)\cdot(b - p) \le 0\) for every \(x \in C\). Line 3 is one direction. For the other, write \(b - x = (b - p) - (x - p)\) and multiply out: \[\begin{aligned} &|b - x|^2 \\ &= |b - p|^2 + |x - p|^2 \\ &\quad {} - 2(x - p)\cdot(b - p). \end{aligned}\] When \((x - p)\cdot(b - p) \le 0\), this is at least \(|b - p|^2 + |x - p|^2\). So every point \(x \ne p\) of \(C\) is strictly farther from \(b\) than \(p\): the closest point is unique.
Problems
Each problem has hints and a full solution. Exact answers can be typed as a decimal or a fraction.
Related lessons: the dot product and the closest point on a line finds the closest point when \(C\) is a line through 0, where \(b - p\) is perpendicular to the whole line. Critical points finds optima where the gradient is zero; on a convex feasible set an optimum of a differentiable objective can also sit on the boundary. There, when the gradient is not zero, the line through the optimum perpendicular to the gradient has the whole set on one side, a supporting line like the one in stage 3. Lagrange multipliers treats optima on a constraint curve.
Further reading
- S. Boyd and L. Vandenberghe, Convex Optimization, section 2.5, “Separating and supporting hyperplanes.”
- R. T. Rockafellar, Convex Analysis, section 11, “Separation theorems.”