Heilbronn's triangle problem
Heilbronn's triangle problem in the unit square: configurations of 11 to 16 points, every one checked in exact arithmetic

| 1 | #!/usr/bin/env python3 |
| 2 | """Exact smallest triangle of this route's C4 arrangement, with a = (3 - sqrt5)/12 and b = a + 1/3 = (7 - sqrt5)/12. |
| 3 | |
| 4 | Usage: exact.py (needs sympy) |
| 5 | |
| 6 | The 16 points are the four images under (x, y) -> (1 - y, x) of |
| 7 | (0, a), (1/3, 0), (a, b) and (b, 1/3) -- the orbits n16.txt holds in floating point. |
| 8 | All 560 signed areas are computed in Q(sqrt5); the script prints the smallest absolute area, its float value, |
| 9 | and how many triangles attain it. |
| 10 | """ |
| 11 | import itertools |
| 12 | |
| 13 | import sympy as sp |
| 14 | |
| 15 | r5 = sp.sqrt(5) |
| 16 | a, b, t = (3 - r5) / 12, (7 - r5) / 12, sp.Rational(1, 3) |
| 17 | reps = [(0, a), (t, 0), (a, b), (b, t)] |
| 18 | pts = [] |
| 19 | for x, y in reps: |
| 20 | for _ in range(4): |
| 21 | pts.append((sp.nsimplify(x), sp.nsimplify(y))) |
| 22 | x, y = 1 - y, x |
| 23 | areas = [] |
| 24 | for p, q, r in itertools.combinations(pts, 3): |
| 25 | s = sp.radsimp(sp.expand(((q[0] - p[0]) * (r[1] - p[1]) - (r[0] - p[0]) * (q[1] - p[1])) / 2)) |
| 26 | areas.append(sp.Abs(s)) |
| 27 | m = min(areas, key=lambda e: sp.N(e, 50)) |
| 28 | V = (5 - r5) / 144 |
| 29 | assert sp.simplify(m - V) == 0 |
| 30 | low = sum(1 for e in areas if sp.N(e - V, 60) < sp.Rational(1, 10**40)) |
| 31 | assert all(sp.N(e - V, 60) > -sp.Rational(1, 10**40) for e in areas) |
| 32 | print(f"smallest triangle = (5 - sqrt5)/144 = {sp.N(V, 20)}, attained by {low} of {len(areas)} triangles") |