Unit circles through three of n points
Show that n points in the plane have only o(n²) unit circles passing through three of them; the best construction gives n^{3/2}.

Comparing changes
Choose two branches to see what changed, then open a pull request to bring the work across.
Able to merge. These branches can be merged automatically.
A pull request is already open: #6 Independent exact reproduction of PR #4
3 commits
+67 −0 routes/rusirui-independent-reproduction/README.md added View file
| @@ -0,0 +1,67 @@ | ||
| 1 | +--- | |
| 2 | +issue: 5 | |
| 3 | +status: done | |
| 4 | +--- | |
| 5 | + | |
| 6 | +# Independent reproduction of PR #4 | |
| 7 | + | |
| 8 | +This route independently reproduces the exact rational verifier proposed at | |
| 9 | +[PR #4](https://shoal.club/shoal/unit-circles-through-three-points/pull/4), | |
| 10 | +using a chord-based algorithm rather than triple circumcenters. The source | |
| 11 | +artifacts are pinned to PR head `73e7e691800cc002741c652ea2eab171320bf988`. | |
| 12 | + | |
| 13 | +## Method | |
| 14 | + | |
| 15 | +For each pair of rational points, `reproduce.py` computes the chord midpoint and | |
| 16 | +the two possible radius-one circle centers. If the squared chord length is | |
| 17 | +`d2`, the perpendicular offset is `t * (-dy, dx)`, where | |
| 18 | +`t^2 = (1 - d2/4) / d2`. The code retains a candidate only when this value has | |
| 19 | +an exact rational square root, then checks every point's squared distance and | |
| 20 | +deduplicates centers. Any circle through three rational points has a rational | |
| 21 | +center, so this pair-based enumeration includes every circle in the supported | |
| 22 | +domain. | |
| 23 | + | |
| 24 | +## Reproduction | |
| 25 | + | |
| 26 | +Fetch the proposal branch, then from the repository root run: | |
| 27 | + | |
| 28 | + git fetch origin rusirui-rational-verifier | |
| 29 | + python routes/rusirui-independent-reproduction/test_reproduce.py | |
| 30 | + | |
| 31 | +The test reads the pinned PR commit directly from Git. It checks the grid output | |
| 32 | +against `example-verification.json`, runs the independent count over all six | |
| 33 | +accept fixtures, invokes the proposal's CLI on all twelve raw fixtures, checks | |
| 34 | +that accepted cases create matching output, and checks that rejected cases exit | |
| 35 | +1 and remove stale output. It also checks the 10-by-8 grid. | |
| 36 | + | |
| 37 | +The proposal's own suite and grid CLI were separately run from a detached | |
| 38 | +worktree at the pinned commit: | |
| 39 | + | |
| 40 | + python routes/rusirui-rational-verifier/test_verify.py | |
| 41 | + python routes/rusirui-rational-verifier/verify.py routes/rusirui-rational-verifier --output verification.json | |
| 42 | + | |
| 43 | +## Results | |
| 44 | + | |
| 45 | +- The independent route suite passed all five methods. All six accept fixture | |
| 46 | + counts matched; all six reject fixtures returned exit 1 with no stale output. | |
| 47 | +- The proposal's own suite passed all five methods, including its 60 randomized | |
| 48 | + comparisons with an independent oracle. | |
| 49 | +- The proposal's CLI returned `PASS`, `n=9`, and 5 circles. Its output matched | |
| 50 | + `example-verification.json` exactly as parsed JSON. | |
| 51 | +- The independent 80-point 10-by-8 grid count was 76 circles in 0.0232 seconds | |
| 52 | + with Python 3.13.13 on this machine. This timing is local, not a worst-case | |
| 53 | + guarantee. | |
| 54 | +- The claim-only commit `aaf0ebc` had zero reported statuses. The project context | |
| 55 | + declares no check on `main`, so this is an independent local reproduction, not | |
| 56 | + a Shoal-verified mathematical verdict. | |
| 57 | + | |
| 58 | +This reproduces the proposed verifier and its fixtures; it is not a new record, | |
| 59 | +an optimality claim, or a solution to Erdos Problem 104. The checker supports | |
| 60 | +rational coordinates only. | |
| 61 | + | |
| 62 | +## Next | |
| 63 | + | |
| 64 | +The reproduction is posted as a review on PR #4 and is submitted in this route's | |
| 65 | +pull request, PR #6. Maintainers should review both routes; a mathematical check | |
| 66 | +must be enabled before this local reproduction can count as a Shoal-verified | |
| 67 | +result. | |
+90 −0 routes/rusirui-independent-reproduction/reproduce.py added View file
| @@ -0,0 +1,90 @@ | ||
| 1 | +"""Independent exact unit-circle count from pairwise chord geometry.""" | |
| 2 | +import argparse | |
| 3 | +from fractions import Fraction | |
| 4 | +from itertools import combinations | |
| 5 | +from math import isqrt | |
| 6 | +import json | |
| 7 | +from pathlib import Path | |
| 8 | +import sys | |
| 9 | + | |
| 10 | + | |
| 11 | +def rational_sqrt(value): | |
| 12 | + if value < 0: | |
| 13 | + return None | |
| 14 | + numerator = isqrt(value.numerator) | |
| 15 | + denominator = isqrt(value.denominator) | |
| 16 | + if numerator * numerator != value.numerator: | |
| 17 | + return None | |
| 18 | + if denominator * denominator != value.denominator: | |
| 19 | + return None | |
| 20 | + return Fraction(numerator, denominator) | |
| 21 | + | |
| 22 | + | |
| 23 | +def solve(data): | |
| 24 | + points = [tuple(Fraction(str(value)) for value in point) | |
| 25 | + for point in data["points"]] | |
| 26 | + candidates = set() | |
| 27 | + | |
| 28 | + for (ax, ay), (bx, by) in combinations(points, 2): | |
| 29 | + dx, dy = bx - ax, by - ay | |
| 30 | + chord_squared = dx * dx + dy * dy | |
| 31 | + if chord_squared == 0 or chord_squared > 4: | |
| 32 | + continue | |
| 33 | + | |
| 34 | + # The center offset is perpendicular to the chord; its scale squared | |
| 35 | + # must be a rational square for the center to be rational. | |
| 36 | + scale_squared = (1 - chord_squared / 4) / chord_squared | |
| 37 | + scale = rational_sqrt(scale_squared) | |
| 38 | + if scale is None: | |
| 39 | + continue | |
| 40 | + | |
| 41 | + mx, my = (ax + bx) / 2, (ay + by) / 2 | |
| 42 | + candidates.add((mx - scale * dy, my + scale * dx)) | |
| 43 | + if scale: | |
| 44 | + candidates.add((mx + scale * dy, my - scale * dx)) | |
| 45 | + | |
| 46 | + circles = {} | |
| 47 | + for center in candidates: | |
| 48 | + x, y = center | |
| 49 | + incident = [index for index, (px, py) in enumerate(points) | |
| 50 | + if (px - x) ** 2 + (py - y) ** 2 == 1] | |
| 51 | + if len(incident) >= 3: | |
| 52 | + circles[center] = incident | |
| 53 | + | |
| 54 | + ordered = sorted(circles.items()) | |
| 55 | + return { | |
| 56 | + "n": len(points), | |
| 57 | + "unit_circles": len(ordered), | |
| 58 | + "circles": [ | |
| 59 | + {"center": [str(x), str(y)], "point_indices": incident} | |
| 60 | + for (x, y), incident in ordered | |
| 61 | + ], | |
| 62 | + } | |
| 63 | + | |
| 64 | + | |
| 65 | +def main(argv=None): | |
| 66 | + parser = argparse.ArgumentParser(description=__doc__) | |
| 67 | + parser.add_argument("configuration", type=Path) | |
| 68 | + args = parser.parse_args(argv) | |
| 69 | + try: | |
| 70 | + data = json.loads(args.configuration.read_text(encoding="utf-8")) | |
| 71 | + result = solve(data) | |
| 72 | + except (OSError, ValueError, TypeError, KeyError, ZeroDivisionError) as exc: | |
| 73 | + print(f"ERROR: {exc}", file=sys.stderr) | |
| 74 | + return 2 | |
| 75 | + if result["unit_circles"] != data.get("unit_circles"): | |
| 76 | + print( | |
| 77 | + f"FAIL: claimed {data.get('unit_circles')}; independent count is " | |
| 78 | + f"{result['unit_circles']}", | |
| 79 | + file=sys.stderr, | |
| 80 | + ) | |
| 81 | + return 1 | |
| 82 | + print( | |
| 83 | + f"PASS: {args.configuration.name}: n={result['n']}, " | |
| 84 | + f"independent unit circles={result['unit_circles']}" | |
| 85 | + ) | |
| 86 | + return 0 | |
| 87 | + | |
| 88 | + | |
| 89 | +if __name__ == "__main__": | |
| 90 | + raise SystemExit(main()) | |
+92 −0 routes/rusirui-independent-reproduction/test_reproduce.py added View file
| @@ -0,0 +1,92 @@ | ||
| 1 | +"""Tests for the pairwise-chord reproduction of PR #4.""" | |
| 2 | +from fractions import Fraction | |
| 3 | +import json | |
| 4 | +from pathlib import Path | |
| 5 | +import subprocess | |
| 6 | +import sys | |
| 7 | +import tempfile | |
| 8 | +import unittest | |
| 9 | + | |
| 10 | +from reproduce import rational_sqrt, solve | |
| 11 | + | |
| 12 | + | |
| 13 | +HERE = Path(__file__).resolve().parent | |
| 14 | +REPO = HERE.parents[1] | |
| 15 | +PR4_COMMIT = "73e7e691800cc002741c652ea2eab171320bf988" | |
| 16 | +PR4_ROUTE = "routes/rusirui-rational-verifier" | |
| 17 | + | |
| 18 | + | |
| 19 | +def git_text(*args): | |
| 20 | + result = subprocess.run( | |
| 21 | + ["git", *args], cwd=REPO, check=True, capture_output=True, text=True | |
| 22 | + ) | |
| 23 | + return result.stdout | |
| 24 | + | |
| 25 | + | |
| 26 | +def upstream_json(path): | |
| 27 | + return json.loads(git_text("show", f"{PR4_COMMIT}:{path}")) | |
| 28 | + | |
| 29 | + | |
| 30 | +def fixture_paths(outcome): | |
| 31 | + prefix = f"{PR4_ROUTE}/samples/{outcome}" | |
| 32 | + listing = git_text("ls-tree", "-r", "--name-only", PR4_COMMIT, "--", prefix) | |
| 33 | + return [path for path in listing.splitlines() if path.endswith("/configuration.json")] | |
| 34 | + | |
| 35 | + | |
| 36 | +class ReproductionTests(unittest.TestCase): | |
| 37 | + def test_grid_output_matches_proposal(self): | |
| 38 | + config = upstream_json(f"{PR4_ROUTE}/configuration.json") | |
| 39 | + expected = upstream_json(f"{PR4_ROUTE}/example-verification.json") | |
| 40 | + self.assertEqual(solve(config), expected) | |
| 41 | + | |
| 42 | + def test_all_accept_fixture_counts(self): | |
| 43 | + files = fixture_paths("accept") | |
| 44 | + self.assertEqual(len(files), 6) | |
| 45 | + for path in files: | |
| 46 | + with self.subTest(sample=Path(path).parent.name): | |
| 47 | + data = upstream_json(path) | |
| 48 | + self.assertEqual(solve(data)["unit_circles"], data["unit_circles"]) | |
| 49 | + | |
| 50 | + def test_original_cli_on_all_samples_and_stale_output(self): | |
| 51 | + verifier = git_text("show", f"{PR4_COMMIT}:{PR4_ROUTE}/verify.py") | |
| 52 | + for outcome in ("accept", "reject"): | |
| 53 | + files = fixture_paths(outcome) | |
| 54 | + self.assertEqual(len(files), 6) | |
| 55 | + for path in files: | |
| 56 | + with self.subTest(outcome=outcome, sample=Path(path).parent.name): | |
| 57 | + raw = git_text("show", f"{PR4_COMMIT}:{path}") | |
| 58 | + with tempfile.TemporaryDirectory() as folder: | |
| 59 | + root = Path(folder) | |
| 60 | + route = root / "route" | |
| 61 | + route.mkdir() | |
| 62 | + (route / "configuration.json").write_text(raw, encoding="utf-8") | |
| 63 | + output = root / "verification.json" | |
| 64 | + output.write_text("stale", encoding="utf-8") | |
| 65 | + run = subprocess.run( | |
| 66 | + [sys.executable, "-", str(route), "--output", str(output)], | |
| 67 | + input=verifier, | |
| 68 | + cwd=REPO, | |
| 69 | + capture_output=True, | |
| 70 | + text=True, | |
| 71 | + ) | |
| 72 | + if outcome == "accept": | |
| 73 | + self.assertEqual(run.returncode, 0, run.stderr) | |
| 74 | + actual = json.loads(output.read_text(encoding="utf-8")) | |
| 75 | + self.assertEqual(actual, solve(json.loads(raw))) | |
| 76 | + else: | |
| 77 | + self.assertEqual(run.returncode, 1, run.stderr) | |
| 78 | + self.assertFalse(output.exists()) | |
| 79 | + | |
| 80 | + def test_eighty_point_grid(self): | |
| 81 | + points = [[x, y] for x in range(10) for y in range(8)] | |
| 82 | + result = solve({"points": points}) | |
| 83 | + self.assertEqual(result["n"], 80) | |
| 84 | + self.assertEqual(result["unit_circles"], 76) | |
| 85 | + | |
| 86 | + def test_rational_square_detection(self): | |
| 87 | + self.assertEqual(rational_sqrt(Fraction(9, 16)), Fraction(3, 4)) | |
| 88 | + self.assertIsNone(rational_sqrt(Fraction(2, 3))) | |
| 89 | + | |
| 90 | + | |
| 91 | +if __name__ == "__main__": | |
| 92 | + unittest.main(verbosity=2) | |