In 1933, Esther Klein noticed that any 5 points in the plane — no three collinear — must contain 4 that form a convex quadrilateral. Paul Erdős named the resulting theorem the Happy Ending Problem, because it led to the marriage of Esther Klein and George Szekeres. This tool lets you watch the proof run live.
Erdős–Szekeres (1935): For every integer k ≥ 3, there is a smallest number ES(k) such that any set of ES(k) or more points in general position in the plane must contain k points in convex position.
Known values: ES(3) = 3, ES(4) = 5, ES(5) = 9, ES(6) = 17 (conjectured). The general conjecture is ES(k) = 2k−2 + 1.
ES(k) ≤ C(2k−4, k−2) + 1 (Erdős–Szekeres bound)
The proof works by finding long cups (∪-shaped, left-turning sequences) and caps (∩-shaped, right-turning) among your points. When either reaches length k, those k points are in convex position — guaranteed.
Every ordered triple (i, j, k) of your points is fed through a single TurnGate that computes the 2-D cross product:
cross = (pj − pi) × (pk − pi)
cross > 0 → RIGHT (clockwise in screen space)
cross < 0 → LEFT (counter-clockwise)
A SequenceGate then runs dynamic programming over those turn labels to find the longest monotone cup and cap. No global search — just local gates composing.
The ObstructionGate computes which positions in the plane are "safe" for an additional point. When no safe zone remains, no arrangement can avoid closure.
Click either canvas to place points manually. Watch the gate fire one triple at a time with Step, or animate the full computation with Run.
Use Both Random to generate two independent arrangements at the same N and compare them side by side — same gate, different topology, both close.
The Batch Runner sweeps N from min to max and plots the probability that a random arrangement contains a convex k-gon. Watch the threshold emerge.
Set k = 4 or k = 5 in the controls to change which convex polygon you're hunting.
Single-Input, Single-Output: each gate reads one event stream and emits targeted updates. The DOM is the source of truth; no gate touches another gate's elements.
This architecture mirrors the mathematical argument itself — local rules (cross products) compose into global structure (convex position) without any gate ever "knowing" the global answer.
The same framework applies to Collatz (which closes) and explains why Goldbach cannot close — primality has no local gate.