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}.

Propose an exact rational unit-circle verifier with adversarial samples #4
Open
+2 −0 routes/rusirui-rational-verifier/.gitignore added View file
| @@ -0,0 +1,2 @@ | ||
| 1 | +__pycache__/ | |
| 2 | +verification.json | |
+121 −0 routes/rusirui-rational-verifier/README.md added View file
| @@ -0,0 +1,121 @@ | ||
| 1 | +--- | |
| 2 | +issue: 3 | |
| 3 | +status: done | |
| 4 | +--- | |
| 5 | + | |
| 6 | +# Exact verification of rational configurations | |
| 7 | + | |
| 8 | +This route proposes a dependency-free verifier for the number of distinct unit | |
| 9 | +circles through at least three points of a finite rational point set. It enumerates | |
| 10 | +noncollinear triples, computes their circumcenters with exact fractions, tests | |
| 11 | +squared radius equal to one, and deduplicates centers. It emits all centers and | |
| 12 | +their incident point indices. See [correctness.md](correctness.md). | |
| 13 | + | |
| 14 | +This is verification infrastructure, not a new bound, optimal configuration, or | |
| 15 | +solution of Erdos Problem 104. Only rational coordinates are supported; arbitrary | |
| 16 | +real/algebraic configurations are not covered. The bundled 3-by-3 integer grid | |
| 17 | +(9 points, 5 circles) is a test fixture, not a new OEIS term or record. | |
| 18 | + | |
| 19 | +## Files and input | |
| 20 | + | |
| 21 | +- verify.py: Python 3.12+ standard-library checker. | |
| 22 | +- configuration.json: the 9-point grid example. | |
| 23 | +- example-verification.json: locally generated circle list for the example. | |
| 24 | +- test_verify.py: regression tests and an independent exact geometric oracle. | |
| 25 | +- samples/accept/ and samples/reject/: six fixtures each. | |
| 26 | +- check.sbatch: proposed runner entry point. | |
| 27 | +- proposed-scienceslack.json: proposed root configuration preserving existing | |
| 28 | + metadata and adding one check whose code stays in this route. | |
| 29 | + | |
| 30 | +Each submission has one configuration.json object with exactly these keys: | |
| 31 | + | |
| 32 | + {"schema": 1, "points": [[1,0],[0,1],[-1,0]], "unit_circles": 1} | |
| 33 | + | |
| 34 | +Coordinates are JSON integers or strings such as "-3/5"; fractions have positive | |
| 35 | +denominators. Decimal numbers/strings, exponent notation and booleans are rejected. | |
| 36 | +Points must be distinct after reduction. The exact claimed count, including zero, | |
| 37 | +is mandatory. Limits: 3..80 points, 32 decimal digits per numerator/denominator, | |
| 38 | +and 128 KiB per file. Counts outside the elementary pair bound and duplicate | |
| 39 | +JSON keys are rejected. | |
| 40 | + | |
| 41 | +## Reproduce | |
| 42 | + | |
| 43 | +From the repository root: | |
| 44 | + | |
| 45 | + python routes/rusirui-rational-verifier/test_verify.py | |
| 46 | + python routes/rusirui-rational-verifier/verify.py routes/rusirui-rational-verifier --output routes/rusirui-rational-verifier/verification.json | |
| 47 | + | |
| 48 | +The second command prints PASS: configuration.json: n=9, exact unit circles=5. | |
| 49 | +Output uses reduced rational strings and zero-based point indices. A prior output | |
| 50 | +file is removed before checking, so rejection or skip cannot leave stale evidence. | |
| 51 | +Exit 0 means an exact match or explicit skip; 1 means invalid input or wrong count; | |
| 52 | +2 means an I/O/environment error. A missing artifact prints SKIP: no | |
| 53 | +configuration.json; no mathematical artifact judged, and emits no file. A | |
| 54 | +nonexistent route folder is an environment error. No score is proposed: counts | |
| 55 | +at different n are not directly comparable. | |
| 56 | + | |
| 57 | +## Local evidence and limitations | |
| 58 | + | |
| 59 | +On 2026-11-28, Python 3.13.13 passed all five test methods, including all 12 sample | |
| 60 | +fixtures, 60 deterministic randomized comparisons with an independent oracle, | |
| 61 | +rational rotations/translations, input validation, CLI exit codes and stale-output | |
| 62 | +removal. The oracle uses the side-length/area radius identity and a concyclicity | |
| 63 | +determinant; it does not reuse the checker circumcenter formula or deduplication. | |
| 64 | +An 80-point 10-by-8 integer-grid stress run counted 76 circles in about 0.90 seconds. | |
| 65 | +This is a local measurement, not a worst-case runtime guarantee. | |
| 66 | + | |
| 67 | +The shell wrapper passed the grid and rejected the overcount sample with Git's | |
| 68 | +POSIX shell, Python and core utilities on Windows. The first wrapper attempt | |
| 69 | +failed because dirname was absent from that shell's PATH; adding Git's utilities | |
| 70 | +resolved it. The proposed Linux image has not been tested on Shoal. | |
| 71 | + | |
| 72 | +Shoal reported zero statuses on implementation push 58cafb7. Its route wait | |
| 73 | +endpoint explicitly said there is no check that judges a push and no verdict will | |
| 74 | +come. These are author-run tests only: **the verifier and fixture count remain | |
| 75 | +unverified by a Shoal mathematical check**. A documentation review is not such a | |
| 76 | +check. | |
| 77 | + | |
| 78 | +## Maintainer activation | |
| 79 | + | |
| 80 | +All changes remain in this route as requested. The root configuration is unchanged; | |
| 81 | +this proposal does not activate a check or automatic ci/trial. After review: | |
| 82 | + | |
| 83 | +1. Incorporate checks.rational-circles from proposed-scienceslack.json into the | |
| 84 | + then-current root scienceslack.json, preserving other changes. | |
| 85 | +2. Copy the route's samples into root samples/accept/ and samples/reject/, where | |
| 86 | + Shoal's trial discovers them. | |
| 87 | +3. Run the sample trial in python:3.12-slim, confirm the entry point resolves the | |
| 88 | + approved verify.py beside its script, and approve the rules through the | |
| 89 | + maintainer workflow. Never execute a submitter-supplied verifier. | |
| 90 | + | |
| 91 | +The check reads $SS_INPUT/$SS_ROUTE_DIR/configuration.json and writes | |
| 92 | +verification.json in its job directory. It locates the trusted checker beside | |
| 93 | +its own $0 path; activation must confirm that the runner preserves that path. | |
| 94 | +No reject sample predated this route on main, so the documented automatic-approval | |
| 95 | +condition is not met: a person must approve the check. | |
| 96 | + | |
| 97 | +## Sources and scope | |
| 98 | + | |
| 99 | +Credit: T. F. Bloom, [Erdos Problem 104](https://www.erdosproblems.com/104), accessed | |
| 100 | +2026-11-28. Its page presents the conjecture, attributes the order-n^(3/2) | |
| 101 | +construction to Elekes, and lists no proof exposition or proof claim. | |
| 102 | +[OEIS A003829](https://oeis.org/A003829/internal), read on the same date, gives | |
| 103 | +1,4,4,8,12,16 for n=3..8. This route does not reproduce the optimal configurations | |
| 104 | +for n=4..8. | |
| 105 | + | |
| 106 | +The Elekes publisher record was also checked: G. Elekes, *n points in the plane | |
| 107 | +can determine n^(3/2) unit circles*, Combinatorica 4 (1984), 131, | |
| 108 | +[doi:10.1007/BF02579212](https://doi.org/10.1007/BF02579212). The related original | |
| 109 | +finite-configuration reference, linked by the source and OEIS, is H. Harborth and | |
| 110 | +I. Mengersen, *Point sets with many unit circles*, Discrete Mathematics 60 (1986), | |
| 111 | +193-197, doi:10.1016/0012-365X(86)90011-7. Neither paper was independently | |
| 112 | +reproduced here. The checker proof is elementary linear algebra; no literature | |
| 113 | +novelty is claimed. | |
| 114 | + | |
| 115 | +## Next | |
| 116 | + | |
| 117 | +A maintainer should review the proof and hostile samples, activate the proposed | |
| 118 | +check and sample trial using the steps above, and obtain a verdict on the actual | |
| 119 | +configuration. Extend the coordinate model to a specified algebraic number field | |
| 120 | +before attempting known irrational constructions. Finite counts alone do not | |
| 121 | +certify optimality or an asymptotic bound. | |
+9 −0 routes/rusirui-rational-verifier/check.sbatch added View file
| @@ -0,0 +1,9 @@ | ||
| 1 | +#!/bin/sh | |
| 2 | +#SBATCH --time=00:02:00 | |
| 3 | +#SBATCH --mem=256M | |
| 4 | +set -eu | |
| 5 | +: "${SS_INPUT:?missing input checkout}" | |
| 6 | +: "${SS_ROUTE_DIR:?missing route directory}" | |
| 7 | +# Read the verifier from this approved script's checkout, never from SS_INPUT. | |
| 8 | +CHECK_DIR=$(CDPATH= cd -- "$(dirname -- "$0")" && pwd) | |
| 9 | +exec python3 "$CHECK_DIR/verify.py" "$SS_INPUT/$SS_ROUTE_DIR" | |
+42 −0 routes/rusirui-rational-verifier/configuration.json added View file
| @@ -0,0 +1,42 @@ | ||
| 1 | +{ | |
| 2 | + "schema": 1, | |
| 3 | + "points": [ | |
| 4 | + [ | |
| 5 | + 0, | |
| 6 | + 0 | |
| 7 | + ], | |
| 8 | + [ | |
| 9 | + 0, | |
| 10 | + 1 | |
| 11 | + ], | |
| 12 | + [ | |
| 13 | + 0, | |
| 14 | + 2 | |
| 15 | + ], | |
| 16 | + [ | |
| 17 | + 1, | |
| 18 | + 0 | |
| 19 | + ], | |
| 20 | + [ | |
| 21 | + 1, | |
| 22 | + 1 | |
| 23 | + ], | |
| 24 | + [ | |
| 25 | + 1, | |
| 26 | + 2 | |
| 27 | + ], | |
| 28 | + [ | |
| 29 | + 2, | |
| 30 | + 0 | |
| 31 | + ], | |
| 32 | + [ | |
| 33 | + 2, | |
| 34 | + 1 | |
| 35 | + ], | |
| 36 | + [ | |
| 37 | + 2, | |
| 38 | + 2 | |
| 39 | + ] | |
| 40 | + ], | |
| 41 | + "unit_circles": 5 | |
| 42 | +} | |
+39 −0 routes/rusirui-rational-verifier/correctness.md added View file
| @@ -0,0 +1,39 @@ | ||
| 1 | +# Why the exact count is complete | |
| 2 | + | |
| 3 | +Let a,b,c be distinct noncollinear rational points. Put u=b-a, v=c-a, | |
| 4 | +D=u_x v_y-u_y v_x, U=u dot u and V=v dot v. The center a+d of their | |
| 5 | +circumcircle is characterized by | |
| 6 | + | |
| 7 | + 2 u dot d = U, 2 v dot d = V. | |
| 8 | + | |
| 9 | +Since D is nonzero, the unique solution is | |
| 10 | + | |
| 11 | + d_x = (U v_y - V u_y)/(2D), | |
| 12 | + d_y = (u_x V - v_x U)/(2D). | |
| 13 | + | |
| 14 | +Every operation is rational. The code computes these expressions with Fraction | |
| 15 | +and retains the center exactly when d_x^2+d_y^2=1. The equations imply that b | |
| 16 | +and c also have squared distance one from the center. Every retained center | |
| 17 | +therefore witnesses a genuine unit circle through three points (soundness). | |
| 18 | + | |
| 19 | +Conversely, any circle counted by the problem has three distinct input points. | |
| 20 | +They are noncollinear: a line meets a circle in at most two points. Their triple | |
| 21 | +is enumerated, its unique circumcenter is the desired center, and the exact | |
| 22 | +radius test passes (completeness). In particular, a circle through three rational | |
| 23 | +points has a rational center; rational arithmetic loses no circle of such an input. | |
| 24 | + | |
| 25 | +A unit circle is uniquely determined by its center. Reduced Fraction pairs have | |
| 26 | +exact equality and hashing. Storing centers in a set counts each circle once, | |
| 27 | +even with four or more incident points. The witness list checks every point | |
| 28 | +against each retained center using exact squared distance. | |
| 29 | + | |
| 30 | +Enumeration takes binomial(n,3) triples, followed by at most n(n-1)/3 centers | |
| 31 | +against n points: O(n^3) rational arithmetic operations, with bit cost depending | |
| 32 | +on input sizes. The input caps are operational limits. The pair bound used for | |
| 33 | +validation follows because each unordered point pair lies on at most two unit | |
| 34 | +circles, and each counted circle consumes at least three pair-circle incidences. | |
| 35 | + | |
| 36 | +This proves an enumeration method, not every implementation detail; the independent | |
| 37 | +oracle and hostile tests give additional implementation evidence. It proves no | |
| 38 | +maximum over configurations. Restricting submissions to rational coordinates | |
| 39 | +cannot resolve the stated problem for arbitrary real points. | |
+62 −0 routes/rusirui-rational-verifier/example-verification.json added View file
| @@ -0,0 +1,62 @@ | ||
| 1 | +{ | |
| 2 | + "n": 9, | |
| 3 | + "unit_circles": 5, | |
| 4 | + "circles": [ | |
| 5 | + { | |
| 6 | + "center": [ | |
| 7 | + "0", | |
| 8 | + "1" | |
| 9 | + ], | |
| 10 | + "point_indices": [ | |
| 11 | + 0, | |
| 12 | + 2, | |
| 13 | + 4 | |
| 14 | + ] | |
| 15 | + }, | |
| 16 | + { | |
| 17 | + "center": [ | |
| 18 | + "1", | |
| 19 | + "0" | |
| 20 | + ], | |
| 21 | + "point_indices": [ | |
| 22 | + 0, | |
| 23 | + 4, | |
| 24 | + 6 | |
| 25 | + ] | |
| 26 | + }, | |
| 27 | + { | |
| 28 | + "center": [ | |
| 29 | + "1", | |
| 30 | + "1" | |
| 31 | + ], | |
| 32 | + "point_indices": [ | |
| 33 | + 1, | |
| 34 | + 3, | |
| 35 | + 5, | |
| 36 | + 7 | |
| 37 | + ] | |
| 38 | + }, | |
| 39 | + { | |
| 40 | + "center": [ | |
| 41 | + "1", | |
| 42 | + "2" | |
| 43 | + ], | |
| 44 | + "point_indices": [ | |
| 45 | + 2, | |
| 46 | + 4, | |
| 47 | + 8 | |
| 48 | + ] | |
| 49 | + }, | |
| 50 | + { | |
| 51 | + "center": [ | |
| 52 | + "2", | |
| 53 | + "1" | |
| 54 | + ], | |
| 55 | + "point_indices": [ | |
| 56 | + 4, | |
| 57 | + 6, | |
| 58 | + 8 | |
| 59 | + ] | |
| 60 | + } | |
| 61 | + ] | |
| 62 | +} | |
+35 −0 routes/rusirui-rational-verifier/proposed-scienceslack.json added View file
| @@ -0,0 +1,35 @@ | ||
| 1 | +{ | |
| 2 | + "domain": "mathematics", | |
| 3 | + "topics": [ | |
| 4 | + "discrete-geometry", | |
| 5 | + "combinatorics" | |
| 6 | + ], | |
| 7 | + "type": "proof", | |
| 8 | + "also": [ | |
| 9 | + "construction" | |
| 10 | + ], | |
| 11 | + "cover": { | |
| 12 | + "file": "poster.webp" | |
| 13 | + }, | |
| 14 | + "source": { | |
| 15 | + "key": "erdos", | |
| 16 | + "name": "Erd艖s Problems", | |
| 17 | + "url": "https://www.erdosproblems.com/104", | |
| 18 | + "id": "104", | |
| 19 | + "curator": "Thomas Bloom", | |
| 20 | + "poser": "Paul Erd艖s", | |
| 21 | + "status": "open, $100 prize", | |
| 22 | + "as_of": "2026-10-20", | |
| 23 | + "prize": "$100", | |
| 24 | + "catalog": "0521c19bbd38" | |
| 25 | + }, | |
| 26 | + "review": true, | |
| 27 | + "approval": "first-time", | |
| 28 | + "checks": { | |
| 29 | + "rational-circles": { | |
| 30 | + "path": "routes/rusirui-rational-verifier/check.sbatch", | |
| 31 | + "method": "exact recomputation", | |
| 32 | + "image": "python:3.12-slim" | |
| 33 | + } | |
| 34 | + } | |
| 35 | +} | |
+18 −0 routes/rusirui-rational-verifier/samples/accept/collinear/configuration.json added View file
| @@ -0,0 +1,18 @@ | ||
| 1 | +{ | |
| 2 | + "schema": 1, | |
| 3 | + "points": [ | |
| 4 | + [ | |
| 5 | + 0, | |
| 6 | + 0 | |
| 7 | + ], | |
| 8 | + [ | |
| 9 | + 1, | |
| 10 | + 0 | |
| 11 | + ], | |
| 12 | + [ | |
| 13 | + 2, | |
| 14 | + 0 | |
| 15 | + ] | |
| 16 | + ], | |
| 17 | + "unit_circles": 0 | |
| 18 | +} | |
+26 −0 routes/rusirui-rational-verifier/samples/accept/dedup/configuration.json added View file
| @@ -0,0 +1,26 @@ | ||
| 1 | +{ | |
| 2 | + "schema": 1, | |
| 3 | + "points": [ | |
| 4 | + [ | |
| 5 | + 1, | |
| 6 | + 0 | |
| 7 | + ], | |
| 8 | + [ | |
| 9 | + 0, | |
| 10 | + 1 | |
| 11 | + ], | |
| 12 | + [ | |
| 13 | + -1, | |
| 14 | + 0 | |
| 15 | + ], | |
| 16 | + [ | |
| 17 | + 0, | |
| 18 | + -1 | |
| 19 | + ], | |
| 20 | + [ | |
| 21 | + "3/5", | |
| 22 | + "4/5" | |
| 23 | + ] | |
| 24 | + ], | |
| 25 | + "unit_circles": 1 | |
| 26 | +} | |
+42 −0 routes/rusirui-rational-verifier/samples/accept/grid/configuration.json added View file
| @@ -0,0 +1,42 @@ | ||
| 1 | +{ | |
| 2 | + "schema": 1, | |
| 3 | + "points": [ | |
| 4 | + [ | |
| 5 | + 0, | |
| 6 | + 0 | |
| 7 | + ], | |
| 8 | + [ | |
| 9 | + 0, | |
| 10 | + 1 | |
| 11 | + ], | |
| 12 | + [ | |
| 13 | + 0, | |
| 14 | + 2 | |
| 15 | + ], | |
| 16 | + [ | |
| 17 | + 1, | |
| 18 | + 0 | |
| 19 | + ], | |
| 20 | + [ | |
| 21 | + 1, | |
| 22 | + 1 | |
| 23 | + ], | |
| 24 | + [ | |
| 25 | + 1, | |
| 26 | + 2 | |
| 27 | + ], | |
| 28 | + [ | |
| 29 | + 2, | |
| 30 | + 0 | |
| 31 | + ], | |
| 32 | + [ | |
| 33 | + 2, | |
| 34 | + 1 | |
| 35 | + ], | |
| 36 | + [ | |
| 37 | + 2, | |
| 38 | + 2 | |
| 39 | + ] | |
| 40 | + ], | |
| 41 | + "unit_circles": 5 | |
| 42 | +} | |
+18 −0 routes/rusirui-rational-verifier/samples/accept/nonunit/configuration.json added View file
| @@ -0,0 +1,18 @@ | ||
| 1 | +{ | |
| 2 | + "schema": 1, | |
| 3 | + "points": [ | |
| 4 | + [ | |
| 5 | + 0, | |
| 6 | + 0 | |
| 7 | + ], | |
| 8 | + [ | |
| 9 | + 1, | |
| 10 | + 0 | |
| 11 | + ], | |
| 12 | + [ | |
| 13 | + 0, | |
| 14 | + 1 | |
| 15 | + ] | |
| 16 | + ], | |
| 17 | + "unit_circles": 0 | |
| 18 | +} | |
+18 −0 routes/rusirui-rational-verifier/samples/accept/rational-center/configuration.json added View file
| @@ -0,0 +1,18 @@ | ||
| 1 | +{ | |
| 2 | + "schema": 1, | |
| 3 | + "points": [ | |
| 4 | + [ | |
| 5 | + "4/3", | |
| 6 | + "2/7" | |
| 7 | + ], | |
| 8 | + [ | |
| 9 | + "1/3", | |
| 10 | + "9/7" | |
| 11 | + ], | |
| 12 | + [ | |
| 13 | + "-2/3", | |
| 14 | + "2/7" | |
| 15 | + ] | |
| 16 | + ], | |
| 17 | + "unit_circles": 1 | |
| 18 | +} | |
+18 −0 routes/rusirui-rational-verifier/samples/accept/three/configuration.json added View file
| @@ -0,0 +1,18 @@ | ||
| 1 | +{ | |
| 2 | + "schema": 1, | |
| 3 | + "points": [ | |
| 4 | + [ | |
| 5 | + 1, | |
| 6 | + 0 | |
| 7 | + ], | |
| 8 | + [ | |
| 9 | + 0, | |
| 10 | + 1 | |
| 11 | + ], | |
| 12 | + [ | |
| 13 | + -1, | |
| 14 | + 0 | |
| 15 | + ] | |
| 16 | + ], | |
| 17 | + "unit_circles": 1 | |
| 18 | +} | |
+18 −0 routes/rusirui-rational-verifier/samples/reject/collinear/configuration.json added View file
| @@ -0,0 +1,18 @@ | ||
| 1 | +{ | |
| 2 | + "schema": 1, | |
| 3 | + "points": [ | |
| 4 | + [ | |
| 5 | + 0, | |
| 6 | + 0 | |
| 7 | + ], | |
| 8 | + [ | |
| 9 | + 1, | |
| 10 | + 0 | |
| 11 | + ], | |
| 12 | + [ | |
| 13 | + 2, | |
| 14 | + 0 | |
| 15 | + ] | |
| 16 | + ], | |
| 17 | + "unit_circles": 1 | |
| 18 | +} | |
+18 −0 routes/rusirui-rational-verifier/samples/reject/duplicate/configuration.json added View file
| @@ -0,0 +1,18 @@ | ||
| 1 | +{ | |
| 2 | + "schema": 1, | |
| 3 | + "points": [ | |
| 4 | + [ | |
| 5 | + 1, | |
| 6 | + 0 | |
| 7 | + ], | |
| 8 | + [ | |
| 9 | + "2/2", | |
| 10 | + 0 | |
| 11 | + ], | |
| 12 | + [ | |
| 13 | + 0, | |
| 14 | + 1 | |
| 15 | + ] | |
| 16 | + ], | |
| 17 | + "unit_circles": 1 | |
| 18 | +} | |
+18 −0 routes/rusirui-rational-verifier/samples/reject/float/configuration.json added View file
| @@ -0,0 +1,18 @@ | ||
| 1 | +{ | |
| 2 | + "schema": 1, | |
| 3 | + "points": [ | |
| 4 | + [ | |
| 5 | + 1.0, | |
| 6 | + 0 | |
| 7 | + ], | |
| 8 | + [ | |
| 9 | + 0, | |
| 10 | + 1 | |
| 11 | + ], | |
| 12 | + [ | |
| 13 | + -1, | |
| 14 | + 0 | |
| 15 | + ] | |
| 16 | + ], | |
| 17 | + "unit_circles": 1 | |
| 18 | +} | |
+18 −0 routes/rusirui-rational-verifier/samples/reject/nearly-unit/configuration.json added View file
| @@ -0,0 +1,18 @@ | ||
| 1 | +{ | |
| 2 | + "schema": 1, | |
| 3 | + "points": [ | |
| 4 | + [ | |
| 5 | + 1, | |
| 6 | + 0 | |
| 7 | + ], | |
| 8 | + [ | |
| 9 | + 0, | |
| 10 | + "10000000000000001/10000000000000000" | |
| 11 | + ], | |
| 12 | + [ | |
| 13 | + -1, | |
| 14 | + 0 | |
| 15 | + ] | |
| 16 | + ], | |
| 17 | + "unit_circles": 1 | |
| 18 | +} | |
+22 −0 routes/rusirui-rational-verifier/samples/reject/overcount/configuration.json added View file
| @@ -0,0 +1,22 @@ | ||
| 1 | +{ | |
| 2 | + "schema": 1, | |
| 3 | + "points": [ | |
| 4 | + [ | |
| 5 | + 1, | |
| 6 | + 0 | |
| 7 | + ], | |
| 8 | + [ | |
| 9 | + 0, | |
| 10 | + 1 | |
| 11 | + ], | |
| 12 | + [ | |
| 13 | + -1, | |
| 14 | + 0 | |
| 15 | + ], | |
| 16 | + [ | |
| 17 | + 0, | |
| 18 | + -1 | |
| 19 | + ] | |
| 20 | + ], | |
| 21 | + "unit_circles": 4 | |
| 22 | +} | |
+18 −0 routes/rusirui-rational-verifier/samples/reject/undercount/configuration.json added View file
| @@ -0,0 +1,18 @@ | ||
| 1 | +{ | |
| 2 | + "schema": 1, | |
| 3 | + "points": [ | |
| 4 | + [ | |
| 5 | + 1, | |
| 6 | + 0 | |
| 7 | + ], | |
| 8 | + [ | |
| 9 | + 0, | |
| 10 | + 1 | |
| 11 | + ], | |
| 12 | + [ | |
| 13 | + -1, | |
| 14 | + 0 | |
| 15 | + ] | |
| 16 | + ], | |
| 17 | + "unit_circles": 0 | |
| 18 | +} | |
+115 −0 routes/rusirui-rational-verifier/test_verify.py added View file
| @@ -0,0 +1,115 @@ | ||
| 1 | +"""Run with python test_verify.py from any directory.""" | |
| 2 | +from fractions import Fraction as F | |
| 3 | +from itertools import combinations | |
| 4 | +import json | |
| 5 | +from pathlib import Path | |
| 6 | +import random | |
| 7 | +import subprocess | |
| 8 | +import sys | |
| 9 | +import tempfile | |
| 10 | +import unittest | |
| 11 | + | |
| 12 | +import verify | |
| 13 | + | |
| 14 | +HERE = Path(__file__).resolve().parent | |
| 15 | + | |
| 16 | + | |
| 17 | +def determinant(matrix): | |
| 18 | + if len(matrix) == 1: | |
| 19 | + return matrix[0][0] | |
| 20 | + return sum((-1)**j * matrix[0][j] * determinant( | |
| 21 | + [[row[k] for k in range(len(matrix)) if k != j] for row in matrix[1:]]) | |
| 22 | + for j in range(len(matrix))) | |
| 23 | + | |
| 24 | + | |
| 25 | +def independent_count(points): | |
| 26 | + # Radius identity: abc/(4 area) = 1. Deduplicate by complete incident | |
| 27 | + # point sets, using the 4x4 concyclicity determinant, not centers. | |
| 28 | + circles = set() | |
| 29 | + def dist(a, b): | |
| 30 | + return sum((x-y)**2 for x, y in zip(a, b)) | |
| 31 | + def row(p): | |
| 32 | + x, y = p | |
| 33 | + return [x*x+y*y, x, y, F(1)] | |
| 34 | + for a, b, c in combinations(points, 3): | |
| 35 | + cross = (b[0]-a[0])*(c[1]-a[1])-(b[1]-a[1])*(c[0]-a[0]) | |
| 36 | + if cross and dist(a,b)*dist(b,c)*dist(c,a) == 4*cross*cross: | |
| 37 | + circles.add(frozenset(i for i,p in enumerate(points) | |
| 38 | + if determinant([row(a),row(b),row(c),row(p)]) == 0)) | |
| 39 | + return len(circles) | |
| 40 | + | |
| 41 | + | |
| 42 | +class Tests(unittest.TestCase): | |
| 43 | + def test_samples(self): | |
| 44 | + for outcome in ('accept','reject'): | |
| 45 | + for file in sorted((HERE/'samples'/outcome).glob('*/configuration.json')): | |
| 46 | + with self.subTest(file=str(file)): | |
| 47 | + data = json.loads(file.read_text()) | |
| 48 | + if outcome == 'accept': | |
| 49 | + result = verify.verify(data) | |
| 50 | + self.assertEqual(result['unit_circles'], data['unit_circles']) | |
| 51 | + else: | |
| 52 | + with self.assertRaises(verify.Invalid): | |
| 53 | + verify.verify(data) | |
| 54 | + | |
| 55 | + def test_independent_oracle(self): | |
| 56 | + rng = random.Random(104) | |
| 57 | + grid = [(F(x),F(y)) for x in range(-2,3) for y in range(-2,3)] | |
| 58 | + pool = grid + [(F(3,5),F(4,5)),(F(-3,5),F(4,5))] | |
| 59 | + for trial in range(60): | |
| 60 | + points = rng.sample(pool, rng.randint(3,9)) | |
| 61 | + if trial % 3 == 0: | |
| 62 | + points = [(F(3,5)*x-F(4,5)*y+F(2,7), | |
| 63 | + F(4,5)*x+F(3,5)*y-F(5,11)) for x,y in points] | |
| 64 | + self.assertEqual(len(verify.unit_centers(points)), independent_count(points)) | |
| 65 | + | |
| 66 | + def test_symmetries_and_witnesses(self): | |
| 67 | + data = json.loads((HERE/'configuration.json').read_text()) | |
| 68 | + points, count = verify.parse(data) | |
| 69 | + for order in (points, list(reversed(points))): | |
| 70 | + moved = [(F(3,5)*x-F(4,5)*y+7,F(4,5)*x+F(3,5)*y-11) for x,y in order] | |
| 71 | + self.assertEqual(len(verify.unit_centers(moved)),count) | |
| 72 | + result = verify.verify(data) | |
| 73 | + for circle in result['circles']: | |
| 74 | + self.assertGreaterEqual(len(circle['point_indices']),3) | |
| 75 | + | |
| 76 | + def test_cli(self): | |
| 77 | + with tempfile.TemporaryDirectory() as folder: | |
| 78 | + tmp = Path(folder) | |
| 79 | + output = tmp/'result.json' | |
| 80 | + def run(route): | |
| 81 | + return subprocess.run([sys.executable,str(HERE/'verify.py'),str(route), | |
| 82 | + '--output',str(output)],capture_output=True,text=True) | |
| 83 | + good = run(HERE) | |
| 84 | + self.assertEqual(good.returncode,0,good.stderr) | |
| 85 | + self.assertIn('exact unit circles=5',good.stdout) | |
| 86 | + self.assertTrue(output.exists()) | |
| 87 | + bad = run(HERE/'samples/reject/overcount') | |
| 88 | + self.assertEqual(bad.returncode,1,bad.stderr) | |
| 89 | + self.assertFalse(output.exists()) | |
| 90 | + skipped = run(tmp) | |
| 91 | + self.assertEqual(skipped.returncode,0) | |
| 92 | + self.assertIn('no mathematical artifact judged',skipped.stdout) | |
| 93 | + self.assertEqual(run(tmp/'absent').returncode,2) | |
| 94 | + (tmp/'configuration.json').write_text('{"schema":1,"schema":1}') | |
| 95 | + self.assertEqual(run(tmp).returncode,1) | |
| 96 | + (tmp/'configuration.json').write_bytes(b' '*(verify.MAX_BYTES+1)) | |
| 97 | + self.assertEqual(run(tmp).returncode,1) | |
| 98 | + (tmp/'configuration.json').write_bytes(b'\xff') | |
| 99 | + self.assertEqual(run(tmp).returncode,1) | |
| 100 | + | |
| 101 | + def test_limits(self): | |
| 102 | + good = {'schema':1,'points':[[1,0],[0,1],[-1,0]],'unit_circles':1} | |
| 103 | + for value in (True, 1.0, '1.0','1/0','NaN', '1e0','9'*33): | |
| 104 | + bad = {**good,'points':[[value,0],[0,1],[-1,0]]} | |
| 105 | + with self.subTest(value=value), self.assertRaises(verify.Invalid): | |
| 106 | + verify.verify(bad) | |
| 107 | + for value in (True,1.0,-1): | |
| 108 | + with self.assertRaises(verify.Invalid): | |
| 109 | + verify.verify({**good,'unit_circles':value}) | |
| 110 | + with self.assertRaises(verify.Invalid): | |
| 111 | + verify.verify({**good,'points':[[i,0] for i in range(81)]}) | |
| 112 | + | |
| 113 | + | |
| 114 | +if __name__ == '__main__': | |
| 115 | + unittest.main(verbosity=2) | |
+125 −0 routes/rusirui-rational-verifier/verify.py added View file
| @@ -0,0 +1,125 @@ | ||
| 1 | +"""Exact finite counts for rational coordinates; Python 3.12+, no dependencies.""" | |
| 2 | +import argparse | |
| 3 | +from fractions import Fraction | |
| 4 | +from itertools import combinations | |
| 5 | +import json | |
| 6 | +from pathlib import Path | |
| 7 | +import re | |
| 8 | +import sys | |
| 9 | + | |
| 10 | +MAX_BYTES = 131072 | |
| 11 | +MAX_POINTS = 80 | |
| 12 | +RATIONAL = re.compile(r"-?[0-9]{1,32}(?:/[1-9][0-9]{0,31})?\Z") | |
| 13 | + | |
| 14 | + | |
| 15 | +class Invalid(ValueError): | |
| 16 | + pass | |
| 17 | + | |
| 18 | + | |
| 19 | +def rational(value): | |
| 20 | + if type(value) is int: | |
| 21 | + value = str(value) | |
| 22 | + if not isinstance(value, str) or not RATIONAL.fullmatch(value): | |
| 23 | + raise Invalid('coordinates must be integers or rational strings with <=32 digits per part') | |
| 24 | + return Fraction(value) | |
| 25 | + | |
| 26 | + | |
| 27 | +def unique_keys(pairs): | |
| 28 | + result = {} | |
| 29 | + for key, value in pairs: | |
| 30 | + if key in result: | |
| 31 | + raise Invalid('duplicate JSON key: ' + key) | |
| 32 | + result[key] = value | |
| 33 | + return result | |
| 34 | + | |
| 35 | + | |
| 36 | +def parse(data): | |
| 37 | + if not isinstance(data, dict) or set(data) != {'schema', 'points', 'unit_circles'}: | |
| 38 | + raise Invalid('expected exactly schema, points, unit_circles') | |
| 39 | + if type(data['schema']) is not int or data['schema'] != 1: | |
| 40 | + raise Invalid('schema must be integer 1') | |
| 41 | + raw = data['points'] | |
| 42 | + if not isinstance(raw, list) or not 3 <= len(raw) <= MAX_POINTS: | |
| 43 | + raise Invalid(f'expected 3..{MAX_POINTS} points') | |
| 44 | + points = [] | |
| 45 | + for point in raw: | |
| 46 | + if not isinstance(point, list) or len(point) != 2: | |
| 47 | + raise Invalid('each point must be [x,y]') | |
| 48 | + points.append(tuple(map(rational, point))) | |
| 49 | + if len(set(points)) != len(points): | |
| 50 | + raise Invalid('points must be distinct after rational reduction') | |
| 51 | + expected = data['unit_circles'] | |
| 52 | + if type(expected) is not int or not 0 <= expected <= len(points)*(len(points)-1)//3: | |
| 53 | + raise Invalid('unit_circles must be a nonnegative integer within the pair bound') | |
| 54 | + return points, expected | |
| 55 | + | |
| 56 | + | |
| 57 | +def unit_centers(points): | |
| 58 | + centers = set() | |
| 59 | + for a, b, c in combinations(points, 3): | |
| 60 | + ux, uy = b[0]-a[0], b[1]-a[1] | |
| 61 | + vx, vy = c[0]-a[0], c[1]-a[1] | |
| 62 | + det = ux*vy-uy*vx | |
| 63 | + if det == 0: | |
| 64 | + continue | |
| 65 | + u2, v2 = ux*ux+uy*uy, vx*vx+vy*vy | |
| 66 | + dx = (u2*vy-v2*uy)/(2*det) | |
| 67 | + dy = (ux*v2-vx*u2)/(2*det) | |
| 68 | + if dx*dx+dy*dy == 1: | |
| 69 | + centers.add((a[0]+dx, a[1]+dy)) | |
| 70 | + return centers | |
| 71 | + | |
| 72 | + | |
| 73 | +def verify(data): | |
| 74 | + points, expected = parse(data) | |
| 75 | + centers = unit_centers(points) | |
| 76 | + if len(centers) != expected: | |
| 77 | + raise Invalid(f'claimed {expected} unit circles; exact count is {len(centers)}') | |
| 78 | + circles = [] | |
| 79 | + for x, y in sorted(centers): | |
| 80 | + incident = [i for i, (px, py) in enumerate(points) if (px-x)**2+(py-y)**2 == 1] | |
| 81 | + circles.append({'center': [str(x), str(y)], 'point_indices': incident}) | |
| 82 | + return {'n': len(points), 'unit_circles': len(centers), 'circles': circles} | |
| 83 | + | |
| 84 | + | |
| 85 | +def main(): | |
| 86 | + parser = argparse.ArgumentParser(description=__doc__) | |
| 87 | + parser.add_argument('route', type=Path, help='folder containing configuration.json') | |
| 88 | + parser.add_argument('--output', type=Path, default=Path('verification.json')) | |
| 89 | + args = parser.parse_args() | |
| 90 | + path = args.route / 'configuration.json' | |
| 91 | + try: | |
| 92 | + if args.output.resolve() == path.resolve(): | |
| 93 | + print('ERROR: output must differ from input', file=sys.stderr) | |
| 94 | + return 2 | |
| 95 | + # Prevent a prior successful run from masquerading as this run. | |
| 96 | + args.output.unlink(missing_ok=True) | |
| 97 | + if not args.route.is_dir(): | |
| 98 | + print('ERROR: route folder does not exist', file=sys.stderr) | |
| 99 | + return 2 | |
| 100 | + if path.is_symlink(): | |
| 101 | + raise Invalid('configuration.json must not be a symlink') | |
| 102 | + if not path.exists(): | |
| 103 | + print('SKIP: no configuration.json; no mathematical artifact judged') | |
| 104 | + return 0 | |
| 105 | + if not path.is_file(): | |
| 106 | + raise Invalid('configuration.json must be a plain file') | |
| 107 | + with path.open('rb') as stream: | |
| 108 | + raw = stream.read(MAX_BYTES+1) | |
| 109 | + if len(raw) > MAX_BYTES: | |
| 110 | + raise Invalid('configuration.json exceeds 128 KiB') | |
| 111 | + data = json.loads(raw, object_pairs_hook=unique_keys) | |
| 112 | + result = verify(data) | |
| 113 | + args.output.write_text(json.dumps(result, indent=2)+'\n', encoding='utf-8') | |
| 114 | + print(f"PASS: configuration.json: n={result['n']}, exact unit circles={result['unit_circles']}") | |
| 115 | + return 0 | |
| 116 | + except (Invalid, ValueError, UnicodeError, RecursionError) as exc: | |
| 117 | + print('FAIL: '+str(exc), file=sys.stderr) | |
| 118 | + return 1 | |
| 119 | + except OSError as exc: | |
| 120 | + print('ERROR: '+str(exc), file=sys.stderr) | |
| 121 | + return 2 | |
| 122 | + | |
| 123 | + | |
| 124 | +if __name__ == '__main__': | |
| 125 | + sys.exit(main()) | |