The Erdős–Straus conjecture
Show that 4/n is a sum of three unit fractions with distinct denominators for every n > 2, or find a counterexample.

| 1 | """One case of the conjecture, found here: 4/7 written as 1/x + 1/y + 1/z with x < y < z. Drawn as fraction bars on one |
| 2 | whole (the faint frame): four sevenths above, the three unit fractions below, the same length exactly. Of all the |
| 3 | solutions for n = 7, this is the one whose smallest piece is largest, so every piece can be seen.""" |
| 4 | from fractions import Fraction as F |
| 5 | from pathlib import Path |
| 6 | |
| 7 | import kit |
| 8 | |
| 9 | n = 7 |
| 10 | |
| 11 | |
| 12 | def solutions(n): |
| 13 | """Every x < y < z with 4/n = 1/x + 1/y + 1/z: x is at most 3n/4, and then y at most 2/(4/n - 1/x).""" |
| 14 | for x in range(n // 4 + 1, 3 * n // 4 + 1): |
| 15 | r = F(4, n) - F(1, x) |
| 16 | for y in range(max(x + 1, int(1 / r) + 1), int(2 / r) + 1): |
| 17 | s = r - F(1, y) |
| 18 | if s > 0 and s.numerator == 1 and s.denominator > y: |
| 19 | yield x, y, s.denominator |
| 20 | |
| 21 | |
| 22 | x, y, z = min(solutions(n), key=lambda t: t[2]) |
| 23 | assert F(1, x) + F(1, y) + F(1, z) == F(4, n) and (x, y, z) == (3, 6, 14) |
| 24 | |
| 25 | x0, x1, h = 24, 616, 64 # the whole runs from x0 to x1 |
| 26 | X = lambda q: x0 + (x1 - x0) * float(q) |
| 27 | box = lambda a, b, top, cls, extra='': kit.polygon([(X(a), top), (X(b), top), (X(b), top + h), (X(a), top + h)], cls, extra) |
| 28 | body = ''.join(box(0, 1, top, 'faint-s', ' stroke-width="2" stroke-dasharray="3 7"') for top in (40, 150)) # the whole, twice |
| 29 | body += ''.join(box(F(k, n), F(k + 1, n), 40, 'ink-s', ' stroke-width="3"') for k in range(4)) # four sevenths |
| 30 | edges = [F(0), F(1, x), F(1, x) + F(1, y), F(4, n)] |
| 31 | for a, b in zip(edges, edges[1:]): # the three unit fractions |
| 32 | body += box(a, b, 150, 'f-soft') + box(a, b, 150, 'f-s', ' stroke-width="3"') |
| 33 | kit.write(__file__, 'mathematics', body, label=f'4/{n} = 1/{x} + 1/{y} + 1/{z}, three unit fractions') |