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

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: #17 Independently reproduce n = 15 at 0.0212105410 and certify its local maximum
7 commits
+44 −0 routes/hongdy22-codex-n15-search/CERTIFICATES.md added View file
| @@ -0,0 +1,44 @@ | ||
| 1 | +# Certificates for the n = 15 search | |
| 2 | + | |
| 3 | +## Refine and enclose the two best basins | |
| 4 | + | |
| 5 | +The independent result has six coordinates on the boundary and 25 tight triangles. The best deletion-seeded result has seven boundary coordinates and 24 tight triangles. After fixing those boundary coordinates at their exact values, `polish.py` sets the signed areas of the tight triangles to a common area `t` and solves the resulting square system with high-precision Newton steps. For the independent result the computed common area is approximately **0.02121054100549062829986481919051221720731723913024**. For the deletion-seeded result it is approximately **0.02110616858917234304196060158344921210040069411280**, agreeing with the record table's rounded value for the tightened historical configuration. [Record table](https://math.tejstead.com/heilbronn/square/15/) | |
| 6 | + | |
| 7 | +An exact comparison confirms the relationship between the arrangements. For the current record, rotate the independent Newton output by `(x, y) → (y, 1−x)` and read its points in the order `11, 12, 5, 8, 13, 9, 7, 3, 14, 10, 4, 2, 1, 6, 15`. The finite decimals equal the Newton output from the published current coordinates. For the older result, import Karpov's coordinates after the score line, refine once with `search.refine`, then run `polish.py`. Rotate the job's independently deletion-seeded Newton output by `(x, y) → (1−y, x)` and read its points in the order `14, 2, 9, 11, 6, 1, 13, 7, 8, 12, 10, 4, 15, 5, 3`. This gives identical decimals to the refined Karpov input. [Karpov's original coordinates](http://inversed.ru/Ascension/Heilbronn_S15.txt) | |
| 8 | + | |
| 9 | +Let `F(u)` be the equations for the oriented active areas minus `t`, `J` their Jacobian, and `A` a rational approximation to the inverse Jacobian at the stored center `u₀`. The script bounds the Jacobian change in the infinity norm by `6r` in the box of radius `r = 10⁻⁴²`. Each row has at most six coordinate derivatives that change by at most `r`. Exact rational arithmetic verifies | |
| 10 | + | |
| 11 | +```text | |
| 12 | +q = ||I − A J(u₀)||∞ + 6r ||A||∞ < 1 | |
| 13 | +||A F(u₀)||∞ + q r ≤ r. | |
| 14 | +``` | |
| 15 | + | |
| 16 | +Therefore `u ↦ u − A F(u)` is a contraction mapping the box to itself. It has a unique fixed point in the box, which solves the system because `A J(u₀)` and hence `A` are nonsingular. Bounds on the inactive triangle areas keep them above `t` throughout the box. The exact minimum of the exported finite decimals is also calculated separately. | |
| 17 | + | |
| 18 | +## Certify a strict local maximum | |
| 19 | + | |
| 20 | +At the enclosed root the last row of `−J⁻¹` gives weights on the tight triangles. The last column of `J` is all `−1`, so the weights sum to one. The weighted gradient vanishes in the free coordinates. A bound on `||J⁻¹ − A||∞` from the Neumann series yields strictly positive triangle weights and the correct strict signs of the weighted gradient on the boundary coordinates. Moving any boundary coordinate into the square decreases the weighted linearization. | |
| 21 | + | |
| 22 | +For a feasible displacement `d`, let `m` be the negative of the smallest directional derivative among the tight triangles. The sign constraints give `m ≥ 0`. If `w` is the lower bound on the smallest weight and `b` the lower bound on the boundary gradient margin, then the total magnitude of the boundary displacement is at most `m/b`. The weighted sum is nonpositive and the other derivatives are at least `−m`, so every active derivative has magnitude at most `m/w`. With `M` an upper bound on `||J⁻¹||∞` this gives | |
| 23 | + | |
| 24 | +```text | |
| 25 | +||d||∞ ≤ L m, where L = max(1/b, M(1/w + 1/(2b))). | |
| 26 | +``` | |
| 27 | + | |
| 28 | +The extra term `1/(2b)` bounds the boundary contribution to each area derivative. The remainder in an active area is at most `3||d||∞²`. For any nonzero displacement with `||d||∞ ≤ 1/(6L)`, at least one active area decreases. The script further caps the radius at one sixth of the certified lower area to preserve that triangle's orientation. The resulting radius exceeds **3.8×10⁻⁶** for the independent result and **4.1×10⁻⁶** for the deletion-seeded result. The radii refer to maximum absolute coordinate displacement from the enclosed configurations. | |
| 29 | + | |
| 30 | +## Exact checks on the deletion construction | |
| 31 | + | |
| 32 | +The fifth deletion removes the point on the left side at height `10/33` of Beyleveld's n = 16 arrangement. The local solve kept the y coordinates to working precision. Rounding the solver's coordinates to fractions of denominator at most 5000 changed each coordinate by at most 1.45e-15 and recovered a placement on the grid `(1/45)Z × (1/33)Z`. The result in `deletion-certificate.dat` has minimum area exactly `31/1485`, attained by 54 of its 455 triangles. | |
| 33 | + | |
| 34 | +For this placement, varying x alone with y and every triangle orientation fixed cannot exceed `31/1485`. The same holds for varying y alone with x and the orientations fixed. In each case the certificate forms a convex combination of signed areas of tight triangles. The combination is linear in the moving coordinates. Its maximum on the unit box is the sum of its positive coefficients, exactly `31/1485`. This bounds the minimum since it cannot exceed the weighted average. | |
| 35 | + | |
| 36 | +The two exact covering calculations find seven minimum six-point covers for the published arrangement at target `0.0212105411`, and two minimum seven-point covers for the deletion construction at target `0.0208754209`. Any original triangle below the target must lose at least one of its original points. The cover sizes are necessary conditions for reaching those targets while leaving the other points fixed. | |
| 37 | + | |
| 38 | +```sh | |
| 39 | +python3 "$route/verify_deletion.py" | |
| 40 | +python3 "$route/cover.py" "$route/reference15.dat" 0.0212105411 | |
| 41 | +python3 "$route/cover.py" "$route/deletion-certificate.dat" 0.0208754209 | |
| 42 | +``` | |
| 43 | + | |
| 44 | +Two spot checks were weaker. Clipping the forbidden strips with exact rational coordinates for [the n = 14 reproduction](https://shoal.club/bo/heilbronn-triangle/blob/912000d239bd284da691d6306f5a660e1e49b89c/routes/hongdy22-codex-n14/n14.txt) put the best fixed-parent insertion between 0.00728656 and 0.00728657. Refining all coordinates from cell centers at 99%, 90% and 80% of the numerical insertion limit reached 0.0182485810. Also, flipping one coordinate between every pair of points with distinct x and y and refining did not improve either seed. This tested 188 swaps for the deletion arrangement and 204 for the published record, taking unchanged scores within solver tolerance. | |
+60 −0 routes/hongdy22-codex-n15-search/README.md added View file
| @@ -0,0 +1,60 @@ | ||
| 1 | +--- | |
| 2 | +issue: 8 | |
| 3 | +status: done | |
| 4 | +tried: independent restarts, deletion-seeded search, and strip-cover relocation | |
| 5 | +conditions: n = 15 in the unit square | |
| 6 | +outcome: independent reproduction of 0.0212105410 with an exact local maximum certificate | |
| 7 | +evidence: job 101, job 102, job 105 | |
| 8 | +--- | |
| 9 | +# Independent reproduction of the n = 15 configuration | |
| 10 | + | |
| 11 | +The independent stream in [job 101](https://shoal.club/bo/heilbronn-triangle/jobs/101) rediscovered Nathan Sudermann-Merx's August 2026 arrangement. [Shoal's verifier](https://shoal.club/bo/heilbronn-triangle/jobs/102) reported **`n = 15: 0.0212105410`** on the [returned commit](https://shoal.club/bo/heilbronn-triangle/commit/4f09303ea7887ed1a473f6fc12b2abdc56e21836). It matches the published value and improves the prior project check of 0.0159343296. The candidate also meets issue #7's 95% threshold. Issue #8 seeks a larger checked value and remains open. [Published configuration](https://math.tejstead.com/heilbronn/square/15/) · [Previous project check](https://shoal.club/bo/heilbronn-triangle/jobs/84) | |
| 12 | + | |
| 13 | +The independent stream starts from stratified random coordinates and consumes neither literature configuration. Applying `(x, y) → (y, 1−x)` and assigning points by minimum total distance aligned the job's output to the published configuration with maximum point distance 1.65e-14. The two configurations give identical 60-decimal coordinates after Newton refinement, rotation and relabeling. The final `n15.txt` is the refinement of the job's independent coordinates. The exact verifier checks the finite decimals in that file. An additional rational certificate establishes a nearby strict local maximum. | |
| 14 | + | |
| 15 | +## Search and returned results | |
| 16 | + | |
| 17 | +`search.py` solves a max-min signed-area problem with SLSQP inside each starting triangle-orientation class. Starts change through stratified restarts, moves selected by clearance from lines through fixed pairs, and Gaussian perturbations. Three independent streams used NumPy 2.2.6, SciPy 1.15.3 and Python 3.12.16. Each had a 1,080-second wall budget. The workers were paused near the end to reduce local load and resumed after the cutoff to write their results. The batch completed after about 1,096 seconds of wall time. The project's earlier n = 13 search also used signed-area SLSQP. [Earlier search](https://shoal.club/bo/heilbronn-triangle/pull/15) | |
| 18 | + | |
| 19 | +| Stream | Starting coordinates | Seed | Completed attempts | Best attempt | Exact check, cut to ten decimals | | |
| 20 | +| --- | --- | ---: | ---: | ---: | ---: | | |
| 21 | +| Deletion | All single-point deletions of Beyleveld's n = 16 arrangement | 20261122 | 51,198 | 18,798 | 0.0211061685 | | |
| 22 | +| Independent | Random stratified starts with no literature seed | 20261123 | 43,584 | 26,322 | 0.0212105410 | | |
| 23 | +| Record control | Sudermann-Merx's published n = 15 arrangement | 20261124 | 51,580 | Start | 0.0212105410 | | |
| 24 | + | |
| 25 | +The deletion and control values in the table come from local runs of the unchanged verifier on the saved track outputs. The site judged the selected independent result. The returned coordinates, summaries and log were compared with the local files byte for byte before the result was fast-forwarded onto this route. The deletion stream independently found the tightened form of Peter Karpov's earlier arrangement, as established by the coordinate comparison in the certificates. The first smoke test, which removed the fifth listed n = 16 point, reached 31/1485 after rational reconstruction. [Beyleveld's n = 16 reference](https://math.tejstead.com/heilbronn/square/16/) | |
| 26 | + | |
| 27 | +## Reproduce | |
| 28 | + | |
| 29 | +From this repository's root, with Python 3.12.16, NumPy 2.2.6 and SciPy 1.15.3, replay the completed attempt counts. Choose an output directory separate from the checked files. | |
| 30 | + | |
| 31 | +```sh | |
| 32 | +route=routes/hongdy22-codex-n15-search | |
| 33 | +out=$(mktemp -d) | |
| 34 | +export OPENBLAS_NUM_THREADS=1 OMP_NUM_THREADS=1 VECLIB_MAXIMUM_THREADS=1 | |
| 35 | +python3 "$route/search.py" --attempts 51198 43584 51580 --seed 20261122 --output-dir "$out" | |
| 36 | +python3 verify.py "$out" | |
| 37 | +``` | |
| 38 | + | |
| 39 | +Floating solver trajectories may differ with the numerical stack. To use the exact byte-verified job output and reproduce the refinement without rerunning the search, start from the job commit. | |
| 40 | + | |
| 41 | +```sh | |
| 42 | +git fetch origin refs/jobs/101 | |
| 43 | +git show "4f09303ea7887ed1a473f6fc12b2abdc56e21836:$route/n15.txt" > "$out/raw.dat" | |
| 44 | +python3 "$route/polish.py" "$out/raw.dat" "$out/n15.txt" | |
| 45 | +python3 verify.py "$out" | |
| 46 | +``` | |
| 47 | + | |
| 48 | +For a shorter search replay, use `--attempts 16 26322 1` with the same seed and numerical stack to cover the independent stream through the first matching result. | |
| 49 | + | |
| 50 | +The three unpolished track outputs are also in `search-summary.json`. The proofs and limitations are described in [CERTIFICATES.md](CERTIFICATES.md). | |
| 51 | + | |
| 52 | +## Follow-up | |
| 53 | + | |
| 54 | +[Job 105](https://shoal.club/bo/heilbronn-triangle/jobs/105) tried strip clipping and coordinated relocations around the published record. It alternated smaller moves with moves that touch every currently tight triangle. The single low-priority process used 38.446 seconds of CPU over its 960-second wall budget. In 1,760 attempts with seed 20261142 it found no configuration that cleared the next checked digit, 0.0212105411. Its summary and log were fetched, checked byte for byte and fast-forwarded onto this route. The check on that job's result reran the already submitted independent configuration and reported 0.0212105410 again. The initial launch, job 104, was canceled after it registered without starting a local worker. Job 105 ran the same script in the foreground. | |
| 55 | + | |
| 56 | +Run the follow-up from the route directory with the same numerical stack using `bash search-strip.sbatch 960 20261142`. The script records the best observed candidate in `strip-summary.json` and writes new checked coordinates only if their exact area clears the target. Its fixed wall budget may allow different numbers of attempts on different machines. | |
| 57 | + | |
| 58 | +## Next | |
| 59 | + | |
| 60 | +Review [PR #17](https://shoal.club/bo/heilbronn-triangle/pull/17) for the independent reproduction and its local certificate. Further attempts at issue #8 should seek a different arrangement. The rational local bounds show which neighborhoods around the reproduced and deletion-seeded configurations are exhausted. | |
+45 −0 routes/hongdy22-codex-n15-search/cover.py added View file
| @@ -0,0 +1,45 @@ | ||
| 1 | +"""Count the fewest original points that must move to reach a target area.""" | |
| 2 | + | |
| 3 | +import argparse | |
| 4 | +from fractions import Fraction | |
| 5 | +from itertools import combinations | |
| 6 | +from pathlib import Path | |
| 7 | + | |
| 8 | + | |
| 9 | +def blocking_triangles(points, target): | |
| 10 | + masks = [] | |
| 11 | + for i, j, k in combinations(range(len(points)), 3): | |
| 12 | + (ax, ay), (bx, by), (cx, cy) = points[i], points[j], points[k] | |
| 13 | + area = abs((bx - ax) * (cy - ay) - (cx - ax) * (by - ay)) / 2 | |
| 14 | + if area < target: | |
| 15 | + masks.append((1 << i) | (1 << j) | (1 << k)) | |
| 16 | + return masks | |
| 17 | + | |
| 18 | + | |
| 19 | +def minimum_covers(n, masks): | |
| 20 | + for count in range(n + 1): | |
| 21 | + covers = [] | |
| 22 | + for moved in combinations(range(n), count): | |
| 23 | + cover = sum(1 << i for i in moved) | |
| 24 | + if all(cover & mask for mask in masks): | |
| 25 | + covers.append(tuple(i + 1 for i in moved)) | |
| 26 | + if covers: | |
| 27 | + return covers | |
| 28 | + raise ValueError("no cover") | |
| 29 | + | |
| 30 | + | |
| 31 | +def main(): | |
| 32 | + parser = argparse.ArgumentParser(description=__doc__) | |
| 33 | + parser.add_argument("coordinates", type=Path) | |
| 34 | + parser.add_argument("target", type=Fraction) | |
| 35 | + args = parser.parse_args() | |
| 36 | + points = [tuple(map(Fraction, line.split())) for line in args.coordinates.read_text().splitlines() | |
| 37 | + if line.strip() and not line.lstrip().startswith("#")] | |
| 38 | + masks = blocking_triangles(points, args.target) | |
| 39 | + covers = minimum_covers(len(points), masks) | |
| 40 | + print(f"{len(masks)} triangles below the target; at least {len(covers[0])} original points must move.") | |
| 41 | + print(f"{len(covers)} minimum covers, 1-based indices: {covers}") | |
| 42 | + | |
| 43 | + | |
| 44 | +if __name__ == "__main__": | |
| 45 | + main() | |
+15 −0 routes/hongdy22-codex-n15-search/deletion-certificate.dat added View file
| @@ -0,0 +1,15 @@ | ||
| 1 | +0 0 | |
| 2 | +43/45 1 | |
| 3 | +31/45 0 | |
| 4 | +4/15 1 | |
| 5 | +1 23/33 | |
| 6 | +43/45 2/33 | |
| 7 | +0 31/33 | |
| 8 | +2/9 4/11 | |
| 9 | +11/15 7/11 | |
| 10 | +4/15 2/33 | |
| 11 | +31/45 31/33 | |
| 12 | +29/45 10/33 | |
| 13 | +14/45 23/33 | |
| 14 | +41/45 4/11 | |
| 15 | +2/45 7/11 | |
+15 −0 routes/hongdy22-codex-n15-search/n15.txt added View file
| @@ -0,0 +1,15 @@ | ||
| 1 | +0.928052805577885694094141631581993814077296801345101456276517 0.279622023293142722116310681796180280839901495072293755989461 | |
| 2 | +0.320416388896403265297744346063029166524571647099223799076981 0.230810098495070172001722800068926771446288621755180580838907 | |
| 3 | +0.379551709488071625934944179825900735441750486713988714199590 0.633671022052187349641832950288180049729456652710511237835348 | |
| 4 | +0.608434806861250350483003263846047631504254425262218677110338 0.323994962889640986294307494149430350472889910245535092245934 | |
| 5 | +0.943125398309313836171440628750753884048307288363479281631781 0.951872981810379366659501748815266402512367908779296976096991 | |
| 6 | +0.062257753755641300733815413040107888397096879076627453788632 0.681378293497095479976557615053654283979296539989869084683909 | |
| 7 | +0.062257753755641300733815413040107888397096879076627453788632 0 | |
| 8 | +0 0.960911197707310419402068438448084324377548832958674190381171 | |
| 9 | +0.984886422028826287472906724303085578702538462882175733600479 0 | |
| 10 | +0.685143655788287916421946425670767672302968175144832524808276 0.721944962123044264418896325702526295595852983729995479624755 | |
| 11 | +0.629926189308287529637809924200253862407028234288028193945537 1 | |
| 12 | +1 0.674078936436826319997067159018038280865051695760360900558249 | |
| 13 | +0 0.275740355390538417139650092666230698959635224826555483245240 | |
| 14 | +0.666816613152246860936823217600853607490696374699601977532791 0.045978499768902282527035844727735685159151497327698834300169 | |
| 15 | +0.315241321288988879132442745416374307646736678188310423303581 0.912910898687075796512288991663865344407128532175161543690787 | |
+36 −0 routes/hongdy22-codex-n15-search/polish-report.json added View file
| @@ -0,0 +1,36 @@ | ||
| 1 | +{ | |
| 2 | + "independent": { | |
| 3 | + "free_coordinates": 24, | |
| 4 | + "active_triangles": 25, | |
| 5 | + "radius": "1e-42", | |
| 6 | + "contraction_factor_bound_approx": "6.310022485100213e-40", | |
| 7 | + "center_correction_approx": "4.9575747412095024e-61", | |
| 8 | + "minimum_active_weight_bound_approx": "0.0028252557368348263", | |
| 9 | + "minimum_boundary_sign_margin_approx": "0.008160269489055396", | |
| 10 | + "strict_local_maximum": true, | |
| 11 | + "local_maximum_radius_approx": "3.8167378496296045e-06", | |
| 12 | + "area_center": "0.021210541005490628299864819190512217207317239130240973954432", | |
| 13 | + "area_interval": [ | |
| 14 | + "165707351605395533592693899925876696932158118205007609019/7812500000000000000000000000000000000000000000000000000000", | |
| 15 | + "165707351605395533592693899925876696932173743205007609019/7812500000000000000000000000000000000000000000000000000000" | |
| 16 | + ], | |
| 17 | + "exact_minimum_of_decimal_export": "10605270502745314149932409595256108603658619565120486977215604981593695634175251304369615495551574654909774807112626641/500000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" | |
| 18 | + }, | |
| 19 | + "deletion": { | |
| 20 | + "free_coordinates": 23, | |
| 21 | + "active_triangles": 24, | |
| 22 | + "radius": "1e-42", | |
| 23 | + "contraction_factor_bound_approx": "1.066694111665804e-39", | |
| 24 | + "center_correction_approx": "4.7313299624939384e-61", | |
| 25 | + "minimum_active_weight_bound_approx": "0.006977044595420022", | |
| 26 | + "minimum_boundary_sign_margin_approx": "0.005927712623590355", | |
| 27 | + "strict_local_maximum": true, | |
| 28 | + "local_maximum_radius_approx": "4.117597719002515e-06", | |
| 29 | + "area_center": "0.021106168589172343041960601583449212100400694112804036672486", | |
| 30 | + "area_interval": [ | |
| 31 | + "10553084294586171520980300791724606050199847056402018336243/500000000000000000000000000000000000000000000000000000000000", | |
| 32 | + "10553084294586171520980300791724606050200847056402018336243/500000000000000000000000000000000000000000000000000000000000" | |
| 33 | + ], | |
| 34 | + "exact_minimum_of_decimal_export": "21106168589172343041960601583449212100400694112804036672485930679007510135522011669023032096817448941154579937534434451/1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" | |
| 35 | + } | |
| 36 | +} | |
+182 −0 routes/hongdy22-codex-n15-search/polish.py added View file
| @@ -0,0 +1,182 @@ | ||
| 1 | +"""Refine a 15-point basin and bound its nearby equal-area solution.""" | |
| 2 | + | |
| 3 | +import argparse | |
| 4 | +import json | |
| 5 | +from decimal import Decimal, localcontext | |
| 6 | +from fractions import Fraction | |
| 7 | +from itertools import combinations | |
| 8 | +from pathlib import Path | |
| 9 | + | |
| 10 | + | |
| 11 | +TRIPLES = tuple(combinations(range(15), 3)) | |
| 12 | +ACTIVE_TOLERANCE = Decimal("1e-9") | |
| 13 | +RADIUS = Fraction(1, 10**42) | |
| 14 | + | |
| 15 | + | |
| 16 | +def signed_area(points, triple): | |
| 17 | + (ax, ay), (bx, by), (cx, cy) = (points[index] for index in triple) | |
| 18 | + return ((bx - ax) * (cy - ay) - (cx - ax) * (by - ay)) / 2 | |
| 19 | + | |
| 20 | + | |
| 21 | +def derivatives(points, triple): | |
| 22 | + (ax, ay), (bx, by), (cx, cy) = (points[index] for index in triple) | |
| 23 | + return ((by - cy, cx - bx), (cy - ay, ax - cx), (ay - by, bx - ax)) | |
| 24 | + | |
| 25 | + | |
| 26 | +def solve(matrix, rhs): | |
| 27 | + rows = [list(a) + list(b) for a, b in zip(matrix, rhs)] | |
| 28 | + size = len(rows) | |
| 29 | + for col in range(size): | |
| 30 | + pivot = max(range(col, size), key=lambda row: abs(rows[row][col])) | |
| 31 | + rows[col], rows[pivot] = rows[pivot], rows[col] | |
| 32 | + if not rows[col][col]: | |
| 33 | + raise ValueError("singular system of critical triangles") | |
| 34 | + row = [value / rows[col][col] for value in rows[col]] | |
| 35 | + rows[col] = row | |
| 36 | + for i, other in enumerate(rows): | |
| 37 | + if i != col and other[col]: | |
| 38 | + rows[i] = [a - other[col] * b for a, b in zip(other, row)] | |
| 39 | + return [row[size:] for row in rows] | |
| 40 | + | |
| 41 | + | |
| 42 | +def coordinates(template, free, state): | |
| 43 | + points = [list(point) for point in template] | |
| 44 | + for (point, axis), value in zip(free, state): | |
| 45 | + points[point][axis] = value | |
| 46 | + return points | |
| 47 | + | |
| 48 | + | |
| 49 | +def evaluate(template, free, active, state): | |
| 50 | + points = coordinates(template, free, state) | |
| 51 | + by_coordinate = {key: i for i, key in enumerate(free)} | |
| 52 | + values, jacobian = [], [] | |
| 53 | + for triple, sign in active: | |
| 54 | + row = [0] * len(state) | |
| 55 | + row[-1] = -1 | |
| 56 | + for index, (dx, dy) in zip(triple, derivatives(points, triple)): | |
| 57 | + for axis, deriv in enumerate((dx, dy)): | |
| 58 | + position = by_coordinate.get((index, axis)) | |
| 59 | + if position is not None: | |
| 60 | + row[position] = sign * deriv / 2 | |
| 61 | + values.append(sign * signed_area(points, triple) - state[-1]) | |
| 62 | + jacobian.append(row) | |
| 63 | + return values, jacobian | |
| 64 | + | |
| 65 | + | |
| 66 | +def stationarity_margins(points, free, active, norm_inv, contraction, inverse): | |
| 67 | + # At the certified root the inverse differs from our approximate inverse | |
| 68 | + # by at most this amount in the induced infinity norm (Neumann series). | |
| 69 | + inverse_error = norm_inv * contraction / (1 - contraction) | |
| 70 | + weights = [-value for value in inverse[-1]] | |
| 71 | + weight_margin = min(weights) - inverse_error | |
| 72 | + gradient = [[Fraction(0), Fraction(0)] for _ in points] | |
| 73 | + for (triple, sign), weight in zip(active, weights): | |
| 74 | + for index, (dx, dy) in zip(triple, derivatives(points, triple)): | |
| 75 | + gradient[index][0] += weight * sign * dx / 2 | |
| 76 | + gradient[index][1] += weight * sign * dy / 2 | |
| 77 | + | |
| 78 | + # Every area derivative has magnitude at most 1/2 and changes by at most | |
| 79 | + # RADIUS. The exact positive weights sum to one by the last column of J. | |
| 80 | + error = inverse_error / 2 + RADIUS | |
| 81 | + free = set(free) | |
| 82 | + margins = [] | |
| 83 | + for index, point in enumerate(points): | |
| 84 | + for axis, value in enumerate(point): | |
| 85 | + if (index, axis) not in free: | |
| 86 | + coefficient = gradient[index][axis] | |
| 87 | + margins.append((coefficient if value == 1 else -coefficient) - error) | |
| 88 | + return weight_margin, min(margins, default=Fraction(1)), norm_inv + inverse_error | |
| 89 | + | |
| 90 | + | |
| 91 | +def certify(template, free, active, state, inverse): | |
| 92 | + """Use exact rational arithmetic for the residual and contraction bounds.""" | |
| 93 | + template = [[Fraction(value) for value in point] for point in template] | |
| 94 | + state = list(map(Fraction, state)) | |
| 95 | + values, jacobian = evaluate(template, free, active, state) | |
| 96 | + columns = list(zip(*jacobian)) | |
| 97 | + inverse = [[Fraction(value) for value in row] for row in inverse] | |
| 98 | + norm_inv = max(sum(map(abs, row)) for row in inverse) | |
| 99 | + residual = max( | |
| 100 | + sum(abs(int(i == j) - sum(a * b for a, b in zip(row, column))) | |
| 101 | + for j, column in enumerate(columns)) | |
| 102 | + for i, row in enumerate(inverse) | |
| 103 | + ) | |
| 104 | + correction = max(abs(sum(a * b for a, b in zip(row, values))) for row in inverse) | |
| 105 | + contraction = residual + 6 * RADIUS * norm_inv | |
| 106 | + if contraction >= 1 or correction + contraction * RADIUS > RADIUS: | |
| 107 | + raise ValueError("could not certify the contraction") | |
| 108 | + if any(not RADIUS < value < 1 - RADIUS for value in state[:-1]): | |
| 109 | + raise ValueError("certificate box would extend outside the square") | |
| 110 | + | |
| 111 | + points = coordinates(template, free, state) | |
| 112 | + critical = {triple for triple, _ in active} | |
| 113 | + inactive_min = min(abs(signed_area(points, triple)) for triple in TRIPLES if triple not in critical) | |
| 114 | + if inactive_min - 6 * RADIUS <= state[-1] + RADIUS or state[-1] <= RADIUS: | |
| 115 | + raise ValueError("could not separate inactive triangles from the common minimum") | |
| 116 | + weight_margin, boundary_margin, inverse_bound = stationarity_margins( | |
| 117 | + points, free, active, norm_inv, contraction, inverse | |
| 118 | + ) | |
| 119 | + local_radius = Fraction(0) | |
| 120 | + if weight_margin > 0 and boundary_margin > 0: | |
| 121 | + direction_bound = max(1 / boundary_margin, | |
| 122 | + inverse_bound * (1 / weight_margin + 1 / (2 * boundary_margin))) | |
| 123 | + local_radius = min(1 / (6 * direction_bound), (state[-1] - RADIUS) / 6) | |
| 124 | + return { | |
| 125 | + "free_coordinates": len(free), | |
| 126 | + "active_triangles": len(active), | |
| 127 | + "radius": "1e-42", | |
| 128 | + "contraction_factor_bound_approx": str(float(contraction)), | |
| 129 | + "center_correction_approx": str(float(correction)), | |
| 130 | + "minimum_active_weight_bound_approx": str(float(weight_margin)), | |
| 131 | + "minimum_boundary_sign_margin_approx": str(float(boundary_margin)), | |
| 132 | + "strict_local_maximum": local_radius > 0, | |
| 133 | + "local_maximum_radius_approx": str(float(local_radius)), | |
| 134 | + "area_center": str(Decimal(state[-1].numerator) / Decimal(state[-1].denominator)), | |
| 135 | + "area_interval": [str(state[-1] - RADIUS), str(state[-1] + RADIUS)], | |
| 136 | + "exact_minimum_of_decimal_export": str(min(abs(signed_area(points, triangle)) for triangle in TRIPLES)), | |
| 137 | + } | |
| 138 | + | |
| 139 | + | |
| 140 | +def main(): | |
| 141 | + parser = argparse.ArgumentParser(description=__doc__) | |
| 142 | + parser.add_argument("input", type=Path) | |
| 143 | + parser.add_argument("output", type=Path) | |
| 144 | + args = parser.parse_args() | |
| 145 | + with localcontext() as ctx: | |
| 146 | + ctx.prec = 90 | |
| 147 | + template = [list(map(Decimal, line.split())) for line in args.input.read_text().splitlines() | |
| 148 | + if line.strip() and not line.lstrip().startswith("#")] | |
| 149 | + if len(template) != 15: | |
| 150 | + raise ValueError("expected 15 points") | |
| 151 | + free = [] | |
| 152 | + for i, point in enumerate(template): | |
| 153 | + for axis, value in enumerate(point): | |
| 154 | + if abs(value) < ACTIVE_TOLERANCE: | |
| 155 | + point[axis] = Decimal(0) | |
| 156 | + elif abs(value - 1) < ACTIVE_TOLERANCE: | |
| 157 | + point[axis] = Decimal(1) | |
| 158 | + else: | |
| 159 | + free.append((i, axis)) | |
| 160 | + areas = [signed_area(template, triple) for triple in TRIPLES] | |
| 161 | + lowest = min(map(abs, areas)) | |
| 162 | + active = [(triple, 1 if area > 0 else -1) for triple, area in zip(TRIPLES, areas) | |
| 163 | + if abs(area) <= lowest + ACTIVE_TOLERANCE] | |
| 164 | + state = [template[i][axis] for i, axis in free] + [lowest] | |
| 165 | + if len(active) != len(state): | |
| 166 | + raise ValueError(f"{len(active)} active triangles for {len(state)} unknowns") | |
| 167 | + for _ in range(7): | |
| 168 | + values, jacobian = evaluate(template, free, active, state) | |
| 169 | + step = solve(jacobian, [[value] for value in values]) | |
| 170 | + state = [value - delta[0] for value, delta in zip(state, step)] | |
| 171 | + state = [Decimal(f"{value:.60f}") for value in state] | |
| 172 | + _, jacobian = evaluate(template, free, active, state) | |
| 173 | + identity = [[Decimal(i == j) for j in range(len(state))] for i in range(len(state))] | |
| 174 | + approximate_inverse = [[f"{value:.45f}" for value in row] for row in solve(jacobian, identity)] | |
| 175 | + report = certify(template, free, active, state, approximate_inverse) | |
| 176 | + points = coordinates(template, free, state) | |
| 177 | + args.output.write_text("".join(f"{x} {y}\n" for x, y in points)) | |
| 178 | + print(json.dumps(report, indent=2)) | |
| 179 | + | |
| 180 | + | |
| 181 | +if __name__ == "__main__": | |
| 182 | + main() | |
+21 −0 routes/hongdy22-codex-n15-search/reference15.dat added View file
| @@ -0,0 +1,21 @@ | ||
| 1 | +# Heilbronn square n=15 | |
| 2 | +# value (exact area implied by these coordinate literals): 0.0212105410054906282998648191905 | |
| 3 | +# domain: unit square [0,1]^2; value = min triangle area | |
| 4 | +# credit: found by Nathan Sudermann-Merx, August 2026 | |
| 5 | +# coordinates: Original full-precision coordinates of Nathan Sudermann-Merx's August 2026 record submissions (Fully asymmetric and rigid; replaced Karpov's 2011 entry. orbit-seeded searcher (LP relocation, min-norm ascent), finished by sign-fixed cell QCP and equal-critical-area continuation) | |
| 6 | +# via: https://math.tejstead.com/heilbronn/square/15/ | |
| 7 | +1 0.37007381069171247036219007579974613759297176571197180605446316077516480372083247773524540868295200430337459233077792406656302493603577335662255447547617779612329598672131962789833496656039607589269075 | |
| 8 | +0.67407893643682631999706715901803828086505169576036090055824859270631412466394449578059236003047794378204682466904480828515896092605515682552738187931703461851696741188451200048016745414366339421491831 0 | |
| 9 | +0.95187298181037936665950174881526640251236790877929697609699104212555465779158299738486724661915958411267469495443640722787757045933843856369379783637870447775848533626327647084609960933065821559196138 0.05687460169068616382855937124924611595169271163652071836821856293155970181385766824860236068429413672492771841096134008389360379924320427105453968992343865594821908037688264223043790498467122874229562 | |
| 10 | +0.96091119770731041940206843844808432437754883295867419038117101422485118470815733765391622905919556977934986439684291993764541139069039694538307380849762079487692658018721437816216228920310864118912253 1 | |
| 11 | +0.27574035539053841713965009266623069895963522482655548324524025940956335704285009613155139250917356546172579457906220393887281348833025707063216221097098690059666937121371077551883547982259799358436046 1 | |
| 12 | +0 0.01511357797117371252709327569691442129746153711782426639952050424252587904976300596767898365060264195684309437857085320706824159530847543627643152561710099157162743236993339820430346199783214935331211 | |
| 13 | +0 0.93774224624435869926618458695989211160290312092337254621136770567542037118164556071084789884244104096097976910829971970017359953980787741191477650760753403296445139093512539913024553392757081096949588 | |
| 14 | +0.63367102205218734964183295028818004972945665271051123783534757756669532141065808413907859877090724654794995427760283156918016186203665539508274421816810330609057373972166223244162706852699584067286338 0.62044829051192837406505582017409926455824951328601128580040963787986433915070493233721928182569444631499154024844394463070376848157334825429023201139537772513549728925694773447760767045366710060782574 | |
| 15 | +0.04597849976890228252703584472773568515915149732769883430016936670472030032617162935160721154996082575783842425566002716847942860661446463541626558893397401140610919930173623481077277400450975936348817 0.33318338684775313906317678239914639250930362530039802246720920466191129582112561046320423003238551286904062497231968228190320200431612834197800117772034542077207376936632986023412583837012868300511771 | |
| 16 | +0.72194496212304426441889632570252629559585298372999547962475538435940817928187246462068649013764735926746133155001523701226814387083485556981039211973207235826336461845728165306657805947058573390193332 0.31485634421171208357805357432923232769703182485516747519172433388696631152733795602867302575967845361607672516215949667585099097512953518459100142015432948601300242617610736386945208848648476938023637 | |
| 17 | +0.32399496288964098629430749414943035047288991024553509224593430024310525070496392267912308997117706923424896273765780762302613183268063209760598743956376928960415916060103629741515820577771456217962284 0.39156519313874964951699673615395236849574557473778132288966217260437620728083478791993563237097619180643987937912096564169980079104965329983479901715788652515582585111104462454243359448959173974692242 | |
| 18 | +0.23081009849507017200172280006892677144628862175518058083890686650359047365690988005712182637210920736094588705145156703480669085078276696790805608467388498856580075278863772519696216377253762059884219 0.67958361110359673470225565393697083347542835290077620092301934470489669177482192925415839724717848159177301043669270201628782009874716847297552130347023480575241271586380938493682978523847114003230978 | |
| 19 | +0.27962202329314272211631068179618028083990149507229375598946061947504341949344487237032935597336782245815764677393105675055371915171528075250987318942100446925866442046036219452535928865055287026448703 0.07194719442211430590585836841800618592270319865489854372348339337558523705852031062960254472225813126681364356904503612974492752764567817527818341720001186875973626907633303966891626538264975935817436 | |
| 20 | +0.68137829349709547997655761505365428397929653998986908468390938674062565411174161923764250052527140520462590234060770659636655862070027399566155517993475371225607294033596571133254778170893602250291431 0.93774224624435869926618458695989211160290312092337254621136770567542037118164556071084789884244104096097976910829971970017359953980787741191477650760753403296445139093512539913024553392757081096949588 | |
| 21 | +0.91291089868707579651228899166386534440712853217516154369078663391193160032288435804265963684051187850526651804923810311660511035303693963163232104991691233952747685363018426266763243464778777275212755 0.68475867871101112086755725458362569235326332181168957669641856779207516133016841278401529547367252549752308766971999678155382772559494656097289621738032985059966975886561860721534526650382104049283096 | |
+22 −0 routes/hongdy22-codex-n15-search/reference16.dat added View file
| @@ -0,0 +1,22 @@ | ||
| 1 | +# Heilbronn square n=16 | |
| 2 | +# value (exact area implied by these coordinate literals): 0.0205278592375366568914956011727 | |
| 3 | +# domain: unit square [0,1]^2; value = min triangle area | |
| 4 | +# credit: found by Mark Beyleveld, August 2006 | |
| 5 | +# coordinates: arXiv:2603.11107 (Beyleveld's all-rational configuration, value exactly 7/341) | |
| 6 | +# via: https://math.tejstead.com/heilbronn/square/16/ | |
| 7 | +0.064516129032258064516129032258 0 | |
| 8 | +0.935483870967741935483870967741 1 | |
| 9 | +0.741935483870967741935483870967 0 | |
| 10 | +0.258064516129032258064516129032 1 | |
| 11 | +0 0.30303030303030303030303030303 | |
| 12 | +1 0.696969696969696969696969696969 | |
| 13 | +1 0.060606060606060606060606060606 | |
| 14 | +0 0.939393939393939393939393939393 | |
| 15 | +0.258064516129032258064516129032 0.363636363636363636363636363636 | |
| 16 | +0.741935483870967741935483870967 0.636363636363636363636363636363 | |
| 17 | +0.32258064516129032258064516129 0.060606060606060606060606060606 | |
| 18 | +0.677419354838709677419354838709 0.939393939393939393939393939393 | |
| 19 | +0.677419354838709677419354838709 0.30303030303030303030303030303 | |
| 20 | +0.32258064516129032258064516129 0.696969696969696969696969696969 | |
| 21 | +0.935483870967741935483870967741 0.363636363636363636363636363636 | |
| 22 | +0.064516129032258064516129032258 0.636363636363636363636363636363 | |
+11 −0 routes/hongdy22-codex-n15-search/search-strip.sbatch added View file
| @@ -0,0 +1,11 @@ | ||
| 1 | +#!/bin/bash | |
| 2 | +#SBATCH --job-name=n15-throttled-strip-cover | |
| 3 | +#SBATCH --time=00:20:00 | |
| 4 | +#SBATCH --cpus-per-task=1 | |
| 5 | +#SBATCH --mem=512M | |
| 6 | +set -eu | |
| 7 | +export OPENBLAS_NUM_THREADS=1 OMP_NUM_THREADS=1 VECLIB_MAXIMUM_THREADS=1 | |
| 8 | +export PYTHONDONTWRITEBYTECODE=1 | |
| 9 | +python=${HEILBRONN_PYTHON:-python3} | |
| 10 | +nice -n 15 "$python" -u throttled_search.py "$1" "$2" | |
| 11 | +"$python" "${SS_INPUT:-../..}/verify.py" . | |
+92 −0 routes/hongdy22-codex-n15-search/search-summary.json added View file
| @@ -0,0 +1,92 @@ | ||
| 1 | +{ | |
| 2 | + "seed": 20261122, | |
| 3 | + "seconds_per_track": 1080.0, | |
| 4 | + "attempt_limits": null, | |
| 5 | + "selected": "independent", | |
| 6 | + "tracks": [ | |
| 7 | + { | |
| 8 | + "track": "deletion", | |
| 9 | + "seed": 20261122, | |
| 10 | + "seconds": 1095.349, | |
| 11 | + "attempts": 51198, | |
| 12 | + "accepted": 15324, | |
| 13 | + "improvements": 4, | |
| 14 | + "best_attempt": 18798, | |
| 15 | + "starting_area": 0.02052785923753664, | |
| 16 | + "best_area": 0.0211061685891722, | |
| 17 | + "coordinates": [ | |
| 18 | + "1.5052795889919334e-16 0.35103703891828075", | |
| 19 | + "0.30295226393788338 0.7128780543469182", | |
| 20 | + "0.39979209874597627 0", | |
| 21 | + "0.19239643062715076 0.99999999999999989", | |
| 22 | + "0.92496691084765981 1", | |
| 23 | + "0.63362260082880872 0.93337936948093558", | |
| 24 | + "2.3963988661505491e-16 0.93337936948093603", | |
| 25 | + "0.27253752450295449 0.41004828035247665", | |
| 26 | + "0.70137967919649846 0.65778974358498088", | |
| 27 | + "0.68426937775017327 0.10438755288979532", | |
| 28 | + "0.095655759909707067 0.036784269938867804", | |
| 29 | + "0.92820405359326852 0.39713027452448729", | |
| 30 | + "1 0.72244856765051446", | |
| 31 | + "0.99999999999999989 0.066200993265768657", | |
| 32 | + "0.61494550179503671 0.32930190459559067" | |
| 33 | + ] | |
| 34 | + }, | |
| 35 | + { | |
| 36 | + "track": "independent", | |
| 37 | + "seed": 20261123, | |
| 38 | + "seconds": 1095.348, | |
| 39 | + "attempts": 43584, | |
| 40 | + "accepted": 9512, | |
| 41 | + "improvements": 32, | |
| 42 | + "best_attempt": 26322, | |
| 43 | + "starting_area": 0.0001897783800414131, | |
| 44 | + "best_area": 0.021210541005487655, | |
| 45 | + "coordinates": [ | |
| 46 | + "0.92805280557787073 0.27962202329313779", | |
| 47 | + "0.32041638889639484 0.23081009849506337", | |
| 48 | + "0.37955170948806999 0.63367102205219306", | |
| 49 | + "0.60843480686123441 0.32399496288964513", | |
| 50 | + "0.9431253983093103 0.9518729818103786", | |
| 51 | + "0.062257753755640979 0.68137829349710732", | |
| 52 | + "0.062257753755640632 0", | |
| 53 | + "2.7339783905102941e-17 0.96091119770731537", | |
| 54 | + "0.98488642202881105 0", | |
| 55 | + "0.68514365578828096 0.7219449621230446", | |
| 56 | + "0.62992618930827959 1", | |
| 57 | + "1 0.67407893643682137", | |
| 58 | + "6.054893403508672e-18 0.27574035539055486", | |
| 59 | + "0.66681661315224094 0.045978499768900657", | |
| 60 | + "0.31524132128899268 0.9129108986870772" | |
| 61 | + ] | |
| 62 | + }, | |
| 63 | + { | |
| 64 | + "track": "record", | |
| 65 | + "seed": 20261124, | |
| 66 | + "seconds": 1095.348, | |
| 67 | + "attempts": 51580, | |
| 68 | + "accepted": 11480, | |
| 69 | + "improvements": 0, | |
| 70 | + "best_attempt": 0, | |
| 71 | + "starting_area": 0.02121054100549058, | |
| 72 | + "best_area": 0.021210541005490597, | |
| 73 | + "coordinates": [ | |
| 74 | + "1 0.37007381069171247", | |
| 75 | + "0.67407893643682637 0", | |
| 76 | + "0.95187298181037938 0.056874601690686165", | |
| 77 | + "0.96091119770731037 1", | |
| 78 | + "0.27574035539053843 1", | |
| 79 | + "0 0.015113577971173712", | |
| 80 | + "0 0.93774224624435865", | |
| 81 | + "0.63367102205218739 0.6204482905119284", | |
| 82 | + "0.045978499768902281 0.33318338684775312", | |
| 83 | + "0.72194496212304426 0.3148563442117121", | |
| 84 | + "0.32399496288964097 0.39156519313874966", | |
| 85 | + "0.23081009849507017 0.67958361110359677", | |
| 86 | + "0.27962202329314273 0.071947194422114308", | |
| 87 | + "0.68137829349709544 0.93774224624435865", | |
| 88 | + "0.91291089868707576 0.68475867871101115" | |
| 89 | + ] | |
| 90 | + } | |
| 91 | + ] | |
| 92 | +} | |
+235 −0 routes/hongdy22-codex-n15-search/search.py added View file
| @@ -0,0 +1,235 @@ | ||
| 1 | +"""Search 15-point configurations with point relocation and signed-area SLSQP.""" | |
| 2 | + | |
| 3 | +import argparse | |
| 4 | +import itertools | |
| 5 | +import json | |
| 6 | +import time | |
| 7 | +from concurrent.futures import FIRST_COMPLETED, ProcessPoolExecutor, wait | |
| 8 | +from fractions import Fraction | |
| 9 | +from pathlib import Path | |
| 10 | + | |
| 11 | +import numpy as np | |
| 12 | +import scipy | |
| 13 | +from scipy.optimize import minimize | |
| 14 | + | |
| 15 | + | |
| 16 | +N = 15 | |
| 17 | +TRACKS = ("deletion", "independent", "record") | |
| 18 | +TRIPLES = list(itertools.combinations(range(N), 3)) | |
| 19 | +I, J, K = np.array(TRIPLES).T | |
| 20 | +ROWS = np.arange(len(I)) | |
| 21 | +PAIR_I, PAIR_J = np.array(list(itertools.combinations(range(N - 1), 2))).T | |
| 22 | +BOUNDS = [(0.0, 1.0)] * (2 * N) + [(0.0, 0.5)] | |
| 23 | +OBJECTIVE_JAC = np.r_[np.zeros(2 * N), -1.0] | |
| 24 | +RECORD_NEXT_DIGIT = Fraction("0.0212105411") | |
| 25 | + | |
| 26 | + | |
| 27 | +def signed_area(points): | |
| 28 | + first = points[J] - points[I] | |
| 29 | + second = points[K] - points[I] | |
| 30 | + return (first[:, 0] * second[:, 1] - first[:, 1] * second[:, 0]) / 2 | |
| 31 | + | |
| 32 | + | |
| 33 | +def fitness(points): | |
| 34 | + return float(np.abs(signed_area(points)).min()) | |
| 35 | + | |
| 36 | + | |
| 37 | +def refine(points): | |
| 38 | + """Locally maximize the smallest area in the starting orientation class.""" | |
| 39 | + areas = signed_area(points) | |
| 40 | + signs = np.where(areas < 0, -1, 1) | |
| 41 | + signed_half = signs / 2 | |
| 42 | + initial = np.r_[points.ravel(), np.abs(areas).min()] | |
| 43 | + | |
| 44 | + def constraints(x): | |
| 45 | + return signs * signed_area(x[:-1].reshape(N, 2)) - x[-1] | |
| 46 | + | |
| 47 | + def jacobian(x): | |
| 48 | + p = x[:-1].reshape(N, 2) | |
| 49 | + ax, ay = p[I].T | |
| 50 | + bx, by = p[J].T | |
| 51 | + cx, cy = p[K].T | |
| 52 | + jac = np.zeros((len(I), 2 * N + 1)) | |
| 53 | + jac[ROWS, 2 * I] = signed_half * (by - cy) | |
| 54 | + jac[ROWS, 2 * I + 1] = signed_half * (cx - bx) | |
| 55 | + jac[ROWS, 2 * J] = signed_half * (cy - ay) | |
| 56 | + jac[ROWS, 2 * J + 1] = signed_half * (ax - cx) | |
| 57 | + jac[ROWS, 2 * K] = signed_half * (ay - by) | |
| 58 | + jac[ROWS, 2 * K + 1] = signed_half * (bx - ax) | |
| 59 | + jac[:, -1] = -1 | |
| 60 | + return jac | |
| 61 | + | |
| 62 | + solved = minimize( | |
| 63 | + lambda x: -x[-1], | |
| 64 | + initial, | |
| 65 | + jac=lambda x: OBJECTIVE_JAC, | |
| 66 | + bounds=BOUNDS, | |
| 67 | + constraints={"type": "ineq", "fun": constraints, "jac": jacobian}, | |
| 68 | + method="SLSQP", | |
| 69 | + options={"ftol": 2e-12, "maxiter": 70}, | |
| 70 | + ) | |
| 71 | + candidate = np.clip(solved.x[:-1].reshape(N, 2), 0, 1) | |
| 72 | + return max((points, candidate), key=fitness) | |
| 73 | + | |
| 74 | + | |
| 75 | +def stratified_start(rng): | |
| 76 | + """Sample one point in each x and y stratum and extend to the square.""" | |
| 77 | + points = (np.column_stack((rng.permutation(N), rng.permutation(N))) | |
| 78 | + + rng.random((N, 2))) / N | |
| 79 | + minimum = points.min(axis=0) | |
| 80 | + return (points - minimum) / (points.max(axis=0) - minimum) | |
| 81 | + | |
| 82 | + | |
| 83 | +def relocate(points, index, rng, probes=192): | |
| 84 | + """Sample alternate positions ranked by clearance from all fixed pair lines.""" | |
| 85 | + fixed = np.delete(points, index, axis=0) | |
| 86 | + first = fixed[PAIR_I] | |
| 87 | + dx, dy = (fixed[PAIR_J] - first).T | |
| 88 | + normals = np.column_stack((-dy, dx)) / 2 | |
| 89 | + offsets = np.einsum("ij,ij->i", normals, first) | |
| 90 | + trial_points = rng.random((probes, 2)) | |
| 91 | + trial_points[: probes // 2 : 2, 0] = rng.integers(2, size=probes // 4) | |
| 92 | + trial_points[1 : probes // 2 : 2, 1] = rng.integers(2, size=probes // 4) | |
| 93 | + trial_points = trial_points[np.linalg.norm(trial_points - points[index], axis=1) > 0.05] | |
| 94 | + if not len(trial_points): | |
| 95 | + return stratified_start(rng)[index] | |
| 96 | + signed = (trial_points[:, 0, None] * normals[:, 0] | |
| 97 | + + trial_points[:, 1, None] * normals[:, 1] - offsets) | |
| 98 | + clearance = np.abs(signed).min(axis=1) | |
| 99 | + return trial_points[np.argmax(clearance)] | |
| 100 | + | |
| 101 | + | |
| 102 | +def neighbor(points, rng, step): | |
| 103 | + new = points.copy() | |
| 104 | + if step % 3: | |
| 105 | + index = rng.integers(N) | |
| 106 | + new[index] = relocate(new, index, rng) | |
| 107 | + if step % 6 == 1: | |
| 108 | + index = rng.integers(N) | |
| 109 | + new[index] = relocate(new, index, rng) | |
| 110 | + else: | |
| 111 | + indices = rng.choice(N, size=1 + step % 4, replace=False) | |
| 112 | + scales = (0.018, 0.045, 0.09, 0.16) | |
| 113 | + new[indices] += rng.normal(0, scales[(step // 3) % len(scales)], (len(indices), 2)) | |
| 114 | + return np.clip(new, 0, 1) | |
| 115 | + | |
| 116 | + | |
| 117 | +def coordinates(points): | |
| 118 | + return [f"{x:.17g} {y:.17g}" for x, y in points] | |
| 119 | + | |
| 120 | + | |
| 121 | +def exact_fitness(lines): | |
| 122 | + points = [tuple(map(Fraction, line.split())) for line in lines] | |
| 123 | + return min(abs((bx - ax) * (cy - ay) - (cx - ax) * (by - ay)) / 2 | |
| 124 | + for (ax, ay), (bx, by), (cx, cy) in itertools.combinations(points, 3)) | |
| 125 | + | |
| 126 | + | |
| 127 | +def run_track(track, seed, seconds, attempts, inputs, move=neighbor): | |
| 128 | + rng = np.random.default_rng(seed) | |
| 129 | + start = time.monotonic() | |
| 130 | + deadline = start + seconds if seconds is not None else float("inf") | |
| 131 | + max_attempts = attempts if attempts is not None else float("inf") | |
| 132 | + n16, record = inputs | |
| 133 | + initial = { | |
| 134 | + "deletion": lambda: [np.delete(n16, i, axis=0) for i in range(len(n16))], | |
| 135 | + "independent": lambda: [stratified_start(rng)], | |
| 136 | + "record": lambda: [record], | |
| 137 | + }[track]() | |
| 138 | + first = max(initial, key=fitness) | |
| 139 | + first_value = fitness(first) | |
| 140 | + best, best_score = first, first_value | |
| 141 | + current, current_score = best, best_score | |
| 142 | + completed = accepted = best_attempt = improving = 0 | |
| 143 | + print(f"{track} seed={seed} starting_area={first_value:.13f}", flush=True) | |
| 144 | + | |
| 145 | + while completed < max_attempts and (completed == 0 or time.monotonic() < deadline): | |
| 146 | + if completed < len(initial): | |
| 147 | + start_points = initial[completed] | |
| 148 | + elif track == "independent" and completed % 12 == 0: | |
| 149 | + start_points = stratified_start(rng) | |
| 150 | + else: | |
| 151 | + start_points = move(current, rng, completed) | |
| 152 | + fitted = refine(start_points) | |
| 153 | + score = fitness(fitted) | |
| 154 | + completed += 1 | |
| 155 | + if score > best_score + 1e-13: | |
| 156 | + best, best_score, best_attempt = fitted, score, completed | |
| 157 | + improving += 1 | |
| 158 | + print(f"metric: {track}_area {score:.13f}", flush=True) | |
| 159 | + print(f"{track} improvement at attempt {completed}, area={score:.13f}", flush=True) | |
| 160 | + | |
| 161 | + phase = completed % 48 | |
| 162 | + temperature = 0.00012 + 0.00095 * (1 - phase / 48) | |
| 163 | + if phase == 0: | |
| 164 | + current, current_score = best, best_score | |
| 165 | + elif score >= current_score or rng.random() < np.exp((score - current_score) / temperature): | |
| 166 | + current, current_score = fitted, score | |
| 167 | + accepted += 1 | |
| 168 | + | |
| 169 | + lines = coordinates(best) | |
| 170 | + return { | |
| 171 | + "track": track, | |
| 172 | + "seed": seed, | |
| 173 | + "seconds": round(time.monotonic() - start, 3), | |
| 174 | + "attempts": completed, | |
| 175 | + "accepted": accepted, | |
| 176 | + "improvements": improving, | |
| 177 | + "best_attempt": best_attempt, | |
| 178 | + "starting_area": first_value, | |
| 179 | + "best_area": float(exact_fitness(lines)), | |
| 180 | + "coordinates": lines, | |
| 181 | + } | |
| 182 | + | |
| 183 | + | |
| 184 | +def main(): | |
| 185 | + parser = argparse.ArgumentParser(description=__doc__) | |
| 186 | + budget = parser.add_mutually_exclusive_group(required=True) | |
| 187 | + budget.add_argument("--seconds", type=float) | |
| 188 | + budget.add_argument("--attempts", type=int, nargs=3, metavar=("DELETION", "INDEPENDENT", "RECORD")) | |
| 189 | + parser.add_argument("--seed", type=int, required=True) | |
| 190 | + parser.add_argument("--output-dir", type=Path, required=True) | |
| 191 | + args = parser.parse_args() | |
| 192 | + if (args.seconds is not None and args.seconds <= 0) or (args.attempts and min(args.attempts) <= 0): | |
| 193 | + parser.error("the budget must be positive") | |
| 194 | + | |
| 195 | + route = Path(__file__).resolve().parent | |
| 196 | + inputs = tuple(np.loadtxt(route / f"reference{n}.dat") for n in (16, 15)) | |
| 197 | + limits = args.attempts or (None,) * len(TRACKS) | |
| 198 | + start = time.monotonic() | |
| 199 | + print(f"numpy={np.__version__} scipy={scipy.__version__} seed={args.seed}", flush=True) | |
| 200 | + with ProcessPoolExecutor(max_workers=len(TRACKS)) as pool: | |
| 201 | + futures = [ | |
| 202 | + pool.submit(run_track, track, args.seed + i, args.seconds, limits[i], inputs) | |
| 203 | + for i, track in enumerate(TRACKS) | |
| 204 | + ] | |
| 205 | + pending = set(futures) | |
| 206 | + while pending: | |
| 207 | + finished, pending = wait(pending, timeout=30, return_when=FIRST_COMPLETED) | |
| 208 | + for future in finished: | |
| 209 | + result = future.result() | |
| 210 | + print(f"{result['track']} completed {result['attempts']} attempts, " | |
| 211 | + f"best={result['best_area']:.13f}", flush=True) | |
| 212 | + if args.seconds is not None: | |
| 213 | + elapsed = time.monotonic() - start | |
| 214 | + pct = min(99, int(100 * elapsed / args.seconds)) if pending else 100 | |
| 215 | + print(f"progress: {pct}% elapsed={elapsed:.1f}s streams_complete={len(TRACKS) - len(pending)}", flush=True) | |
| 216 | + | |
| 217 | + results = [future.result() for future in futures] | |
| 218 | + eligible = [r for r in results if r["track"] != "record" | |
| 219 | + or exact_fitness(r["coordinates"]) >= RECORD_NEXT_DIGIT] | |
| 220 | + winner = max(eligible, key=lambda r: exact_fitness(r["coordinates"])) | |
| 221 | + args.output_dir.mkdir(parents=True, exist_ok=True) | |
| 222 | + (args.output_dir / "n15.txt").write_text("\n".join(winner["coordinates"]) + "\n") | |
| 223 | + summary = { | |
| 224 | + "seed": args.seed, | |
| 225 | + "seconds_per_track": args.seconds, | |
| 226 | + "attempt_limits": args.attempts, | |
| 227 | + "selected": winner["track"], | |
| 228 | + "tracks": results, | |
| 229 | + } | |
| 230 | + (args.output_dir / "search-summary.json").write_text(json.dumps(summary, indent=2) + "\n") | |
| 231 | + print(f"selected {winner['track']} area={winner['best_area']:.13f}", flush=True) | |
| 232 | + | |
| 233 | + | |
| 234 | +if __name__ == "__main__": | |
| 235 | + main() | |
+11 −0 routes/hongdy22-codex-n15-search/search.sbatch added View file
| @@ -0,0 +1,11 @@ | ||
| 1 | +#!/bin/bash | |
| 2 | +#SBATCH --job-name=n15-point-relocation | |
| 3 | +#SBATCH --time=00:44:00 | |
| 4 | +#SBATCH --cpus-per-task=3 | |
| 5 | +#SBATCH --mem=1G | |
| 6 | +set -eu | |
| 7 | +export OPENBLAS_NUM_THREADS=1 OMP_NUM_THREADS=1 VECLIB_MAXIMUM_THREADS=1 | |
| 8 | +export PYTHONDONTWRITEBYTECODE=1 | |
| 9 | +python=${HEILBRONN_PYTHON:-python3} | |
| 10 | +"$python" -u search.py --seconds "$1" --seed "$2" --output-dir . | |
| 11 | +"$python" "${SS_INPUT:-../..}/verify.py" . | |
+121 −0 routes/hongdy22-codex-n15-search/slurm-101.out added View file
| @@ -0,0 +1,121 @@ | ||
| 1 | +numpy=2.2.6 scipy=1.15.3 seed=20261122 | |
| 2 | +deletion seed=20261122 starting_area=0.0205278592375 | |
| 3 | +independent seed=20261123 starting_area=0.0001897783800 | |
| 4 | +record seed=20261124 starting_area=0.0212105410055 | |
| 5 | +metric: deletion_area 0.0206531944230 | |
| 6 | +deletion improvement at attempt 1, area=0.0206531944230 | |
| 7 | +metric: deletion_area 0.0207885304659 | |
| 8 | +deletion improvement at attempt 3, area=0.0207885304659 | |
| 9 | +metric: deletion_area 0.0208754208754 | |
| 10 | +deletion improvement at attempt 5, area=0.0208754208754 | |
| 11 | +metric: independent_area 0.0062811753631 | |
| 12 | +independent improvement at attempt 1, area=0.0062811753631 | |
| 13 | +metric: independent_area 0.0069882096215 | |
| 14 | +independent improvement at attempt 2, area=0.0069882096215 | |
| 15 | +metric: independent_area 0.0096110465225 | |
| 16 | +independent improvement at attempt 3, area=0.0096110465225 | |
| 17 | +metric: independent_area 0.0105530965690 | |
| 18 | +independent improvement at attempt 5, area=0.0105530965690 | |
| 19 | +metric: independent_area 0.0122232682380 | |
| 20 | +independent improvement at attempt 6, area=0.0122232682380 | |
| 21 | +metric: independent_area 0.0125332445487 | |
| 22 | +independent improvement at attempt 9, area=0.0125332445487 | |
| 23 | +metric: independent_area 0.0148605567025 | |
| 24 | +independent improvement at attempt 12, area=0.0148605567025 | |
| 25 | +metric: independent_area 0.0155472634127 | |
| 26 | +independent improvement at attempt 15, area=0.0155472634127 | |
| 27 | +metric: independent_area 0.0163876871739 | |
| 28 | +independent improvement at attempt 18, area=0.0163876871739 | |
| 29 | +metric: independent_area 0.0171164910360 | |
| 30 | +independent improvement at attempt 63, area=0.0171164910360 | |
| 31 | +metric: independent_area 0.0172528693256 | |
| 32 | +independent improvement at attempt 69, area=0.0172528693256 | |
| 33 | +metric: independent_area 0.0173218483652 | |
| 34 | +independent improvement at attempt 74, area=0.0173218483652 | |
| 35 | +metric: independent_area 0.0177249115228 | |
| 36 | +independent improvement at attempt 77, area=0.0177249115228 | |
| 37 | +metric: independent_area 0.0177926360076 | |
| 38 | +independent improvement at attempt 236, area=0.0177926360076 | |
| 39 | +metric: independent_area 0.0184397766420 | |
| 40 | +independent improvement at attempt 264, area=0.0184397766420 | |
| 41 | +metric: independent_area 0.0184397766421 | |
| 42 | +independent improvement at attempt 268, area=0.0184397766421 | |
| 43 | +metric: independent_area 0.0188862546102 | |
| 44 | +independent improvement at attempt 488, area=0.0188862546102 | |
| 45 | +metric: independent_area 0.0190957588888 | |
| 46 | +independent improvement at attempt 614, area=0.0190957588888 | |
| 47 | +metric: independent_area 0.0191142728294 | |
| 48 | +independent improvement at attempt 621, area=0.0191142728294 | |
| 49 | +metric: independent_area 0.0197951174766 | |
| 50 | +independent improvement at attempt 695, area=0.0197951174766 | |
| 51 | +metric: independent_area 0.0197951174769 | |
| 52 | +independent improvement at attempt 732, area=0.0197951174769 | |
| 53 | +metric: independent_area 0.0199803305495 | |
| 54 | +independent improvement at attempt 737, area=0.0199803305495 | |
| 55 | +metric: independent_area 0.0199803305498 | |
| 56 | +independent improvement at attempt 738, area=0.0199803305498 | |
| 57 | +progress: 2% elapsed=30.0s streams_complete=0 | |
| 58 | +progress: 5% elapsed=60.0s streams_complete=0 | |
| 59 | +metric: independent_area 0.0200677480867 | |
| 60 | +independent improvement at attempt 3089, area=0.0200677480867 | |
| 61 | +progress: 8% elapsed=90.0s streams_complete=0 | |
| 62 | +progress: 11% elapsed=120.0s streams_complete=0 | |
| 63 | +progress: 13% elapsed=150.0s streams_complete=0 | |
| 64 | +progress: 16% elapsed=180.0s streams_complete=0 | |
| 65 | +progress: 19% elapsed=210.0s streams_complete=0 | |
| 66 | +progress: 22% elapsed=240.0s streams_complete=0 | |
| 67 | +progress: 25% elapsed=270.0s streams_complete=0 | |
| 68 | +progress: 27% elapsed=300.0s streams_complete=0 | |
| 69 | +metric: deletion_area 0.0211061685892 | |
| 70 | +deletion improvement at attempt 18798, area=0.0211061685892 | |
| 71 | +progress: 30% elapsed=330.0s streams_complete=0 | |
| 72 | +progress: 33% elapsed=360.1s streams_complete=0 | |
| 73 | +progress: 36% elapsed=390.1s streams_complete=0 | |
| 74 | +progress: 38% elapsed=420.1s streams_complete=0 | |
| 75 | +progress: 41% elapsed=450.1s streams_complete=0 | |
| 76 | +metric: independent_area 0.0200683211569 | |
| 77 | +independent improvement at attempt 23468, area=0.0200683211569 | |
| 78 | +progress: 44% elapsed=480.1s streams_complete=0 | |
| 79 | +metric: independent_area 0.0203553208196 | |
| 80 | +independent improvement at attempt 25311, area=0.0203553208196 | |
| 81 | +metric: independent_area 0.0205325794259 | |
| 82 | +independent improvement at attempt 25413, area=0.0205325794259 | |
| 83 | +metric: independent_area 0.0205325794262 | |
| 84 | +independent improvement at attempt 25425, area=0.0205325794262 | |
| 85 | +metric: independent_area 0.0205420995109 | |
| 86 | +independent improvement at attempt 25485, area=0.0205420995109 | |
| 87 | +metric: independent_area 0.0205900998805 | |
| 88 | +independent improvement at attempt 25488, area=0.0205900998805 | |
| 89 | +metric: independent_area 0.0208418504369 | |
| 90 | +independent improvement at attempt 25539, area=0.0208418504369 | |
| 91 | +metric: independent_area 0.0212105410055 | |
| 92 | +independent improvement at attempt 26322, area=0.0212105410055 | |
| 93 | +progress: 47% elapsed=510.1s streams_complete=0 | |
| 94 | +progress: 50% elapsed=540.1s streams_complete=0 | |
| 95 | +progress: 52% elapsed=570.1s streams_complete=0 | |
| 96 | +progress: 55% elapsed=600.1s streams_complete=0 | |
| 97 | +progress: 58% elapsed=630.1s streams_complete=0 | |
| 98 | +progress: 61% elapsed=660.1s streams_complete=0 | |
| 99 | +progress: 63% elapsed=690.1s streams_complete=0 | |
| 100 | +progress: 66% elapsed=720.1s streams_complete=0 | |
| 101 | +progress: 69% elapsed=750.1s streams_complete=0 | |
| 102 | +progress: 72% elapsed=780.1s streams_complete=0 | |
| 103 | +progress: 75% elapsed=810.1s streams_complete=0 | |
| 104 | +progress: 77% elapsed=840.1s streams_complete=0 | |
| 105 | +progress: 80% elapsed=870.1s streams_complete=0 | |
| 106 | +progress: 83% elapsed=900.1s streams_complete=0 | |
| 107 | +progress: 86% elapsed=930.1s streams_complete=0 | |
| 108 | +progress: 88% elapsed=960.1s streams_complete=0 | |
| 109 | +progress: 91% elapsed=990.1s streams_complete=0 | |
| 110 | +progress: 94% elapsed=1020.1s streams_complete=0 | |
| 111 | +progress: 97% elapsed=1050.1s streams_complete=0 | |
| 112 | +progress: 99% elapsed=1080.1s streams_complete=0 | |
| 113 | +deletion completed 51198 attempts, best=0.0211061685892 | |
| 114 | +progress: 99% elapsed=1096.2s streams_complete=1 | |
| 115 | +independent completed 43584 attempts, best=0.0212105410055 | |
| 116 | +progress: 99% elapsed=1096.2s streams_complete=2 | |
| 117 | +record completed 51580 attempts, best=0.0212105410055 | |
| 118 | +progress: 100% elapsed=1096.2s streams_complete=3 | |
| 119 | +selected independent area=0.0212105410055 | |
| 120 | +n15.txt: 15 points in the unit square, smallest triangle 0.0212105410, on lines 4, 6 and 9 | |
| 121 | +n = 15: 0.0212105410 | |
+35 −0 routes/hongdy22-codex-n15-search/slurm-105.out added View file
| @@ -0,0 +1,35 @@ | ||
| 1 | +record seed=20261142 starting_area=0.0212105410055 | |
| 2 | +progress: 3% attempts=67 search_cpu=1.2s | |
| 3 | +progress: 6% attempts=140 search_cpu=2.5s | |
| 4 | +progress: 9% attempts=200 search_cpu=3.7s | |
| 5 | +progress: 12% attempts=261 search_cpu=4.9s | |
| 6 | +progress: 15% attempts=323 search_cpu=6.1s | |
| 7 | +progress: 19% attempts=380 search_cpu=7.3s | |
| 8 | +progress: 22% attempts=441 search_cpu=8.6s | |
| 9 | +progress: 25% attempts=497 search_cpu=9.8s | |
| 10 | +progress: 28% attempts=550 search_cpu=11.0s | |
| 11 | +progress: 31% attempts=609 search_cpu=12.2s | |
| 12 | +progress: 34% attempts=661 search_cpu=13.4s | |
| 13 | +progress: 38% attempts=717 search_cpu=14.7s | |
| 14 | +progress: 41% attempts=777 search_cpu=15.9s | |
| 15 | +progress: 44% attempts=824 search_cpu=17.1s | |
| 16 | +progress: 47% attempts=880 search_cpu=18.3s | |
| 17 | +progress: 50% attempts=930 search_cpu=19.5s | |
| 18 | +progress: 53% attempts=983 search_cpu=20.7s | |
| 19 | +progress: 57% attempts=1035 search_cpu=21.9s | |
| 20 | +progress: 60% attempts=1087 search_cpu=23.2s | |
| 21 | +progress: 63% attempts=1141 search_cpu=24.3s | |
| 22 | +progress: 66% attempts=1197 search_cpu=25.6s | |
| 23 | +progress: 69% attempts=1256 search_cpu=26.8s | |
| 24 | +progress: 72% attempts=1310 search_cpu=28.0s | |
| 25 | +progress: 75% attempts=1368 search_cpu=29.2s | |
| 26 | +progress: 79% attempts=1420 search_cpu=30.4s | |
| 27 | +progress: 82% attempts=1473 search_cpu=31.6s | |
| 28 | +progress: 85% attempts=1526 search_cpu=32.8s | |
| 29 | +progress: 88% attempts=1577 search_cpu=34.0s | |
| 30 | +progress: 91% attempts=1627 search_cpu=35.2s | |
| 31 | +progress: 94% attempts=1674 search_cpu=36.5s | |
| 32 | +progress: 98% attempts=1727 search_cpu=37.7s | |
| 33 | +progress: 100% attempts=1760 search_cpu=38.446s improved=False | |
| 34 | +n15.txt: 15 points in the unit square, smallest triangle 0.0212105410, on lines 4, 6 and 9 | |
| 35 | +n = 15: 0.0212105410 | |
+31 −0 routes/hongdy22-codex-n15-search/strip-summary.json added View file
| @@ -0,0 +1,31 @@ | ||
| 1 | +{ | |
| 2 | + "track": "record", | |
| 3 | + "seed": 20261142, | |
| 4 | + "seconds": 960.018, | |
| 5 | + "attempts": 1760, | |
| 6 | + "accepted": 752, | |
| 7 | + "improvements": 0, | |
| 8 | + "best_attempt": 0, | |
| 9 | + "starting_area": 0.02121054100549058, | |
| 10 | + "best_area": 0.021210541005490597, | |
| 11 | + "coordinates": [ | |
| 12 | + "1 0.37007381069171247", | |
| 13 | + "0.67407893643682637 0", | |
| 14 | + "0.95187298181037938 0.056874601690686165", | |
| 15 | + "0.96091119770731037 1", | |
| 16 | + "0.27574035539053843 1", | |
| 17 | + "0 0.015113577971173712", | |
| 18 | + "0 0.93774224624435865", | |
| 19 | + "0.63367102205218739 0.6204482905119284", | |
| 20 | + "0.045978499768902281 0.33318338684775312", | |
| 21 | + "0.72194496212304426 0.3148563442117121", | |
| 22 | + "0.32399496288964097 0.39156519313874966", | |
| 23 | + "0.23081009849507017 0.67958361110359677", | |
| 24 | + "0.27962202329314273 0.071947194422114308", | |
| 25 | + "0.68137829349709544 0.93774224624435865", | |
| 26 | + "0.91291089868707576 0.68475867871101115" | |
| 27 | + ], | |
| 28 | + "search_cpu_seconds": 38.446, | |
| 29 | + "wall_budget_seconds": 960.0, | |
| 30 | + "cleared_next_check_digit": false | |
| 31 | +} | |
+119 −0 routes/hongdy22-codex-n15-search/strip_moves.py added View file
| @@ -0,0 +1,119 @@ | ||
| 1 | +"""Reinsert several points by clipping away the forbidden strips.""" | |
| 2 | + | |
| 3 | +from itertools import combinations | |
| 4 | + | |
| 5 | +import numpy as np | |
| 6 | + | |
| 7 | +from search import N, TRIPLES, neighbor, signed_area | |
| 8 | + | |
| 9 | + | |
| 10 | +SQUARE = ((0.0, 0.0), (1.0, 0.0), (1.0, 1.0), (0.0, 1.0)) | |
| 11 | +TRIPLE_INDICES = np.array(TRIPLES) | |
| 12 | +CANDIDATE_MASKS = [ | |
| 13 | + np.array([sum(1 << node for node in members) for members in combinations(range(N), size)]) | |
| 14 | + for size in range(3, N + 1) | |
| 15 | +] | |
| 16 | + | |
| 17 | + | |
| 18 | +def minimum_cover(triples, rng): | |
| 19 | + """Choose a smallest set of at least three points meeting every triple.""" | |
| 20 | + edges = np.bitwise_or.reduce(1 << triples, axis=1) | |
| 21 | + for masks in CANDIDATE_MASKS: | |
| 22 | + valid = masks[np.all((masks[:, None] & edges) != 0, axis=1)] | |
| 23 | + if len(valid): | |
| 24 | + mask = int(rng.choice(valid)) | |
| 25 | + return rng.permutation([i for i in range(N) if mask & (1 << i)]) | |
| 26 | + raise ValueError("no cover of the tight triangles") | |
| 27 | + | |
| 28 | + | |
| 29 | +def pair_lines(points): | |
| 30 | + lines = [] | |
| 31 | + for (ax, ay), (bx, by) in combinations(points, 2): | |
| 32 | + nx, ny = (ay - by) / 2, (bx - ax) / 2 | |
| 33 | + lines.append((nx, ny, nx * ax + ny * ay)) | |
| 34 | + return sorted(lines, key=lambda line: line[0] ** 2 + line[1] ** 2) | |
| 35 | + | |
| 36 | + | |
| 37 | +def clip_half_plane(vertices, distances): | |
| 38 | + """Clip a convex polygon using signed distances to the clipping line.""" | |
| 39 | + output = [] | |
| 40 | + previous = vertices[-1] | |
| 41 | + old_distance = distances[-1] | |
| 42 | + for point, distance in zip(vertices, distances): | |
| 43 | + if (old_distance >= 0) != (distance >= 0): | |
| 44 | + scale = old_distance / (old_distance - distance) | |
| 45 | + output.append(tuple(a + scale * (b - a) for a, b in zip(previous, point))) | |
| 46 | + if distance >= 0: | |
| 47 | + output.append(point) | |
| 48 | + previous, old_distance = point, distance | |
| 49 | + return output | |
| 50 | + | |
| 51 | + | |
| 52 | +def feasible_cells(lines, target): | |
| 53 | + """Return cells of the square where every fixed-pair area is at least target.""" | |
| 54 | + cells = [SQUARE] | |
| 55 | + for nx, ny, offset in lines: | |
| 56 | + kept = [] | |
| 57 | + for vertices in cells: | |
| 58 | + values = [nx * x + ny * y - offset for x, y in vertices] | |
| 59 | + high, low = max(values), min(values) | |
| 60 | + if low >= target or high <= -target: | |
| 61 | + kept.append(vertices) | |
| 62 | + continue | |
| 63 | + if high > target: | |
| 64 | + kept.append(clip_half_plane(vertices, [value - target for value in values])) | |
| 65 | + if low < -target: | |
| 66 | + kept.append(clip_half_plane(vertices, [-value - target for value in values])) | |
| 67 | + if not kept: | |
| 68 | + return [] | |
| 69 | + cells = kept | |
| 70 | + return cells | |
| 71 | + | |
| 72 | + | |
| 73 | +def insertion(fixed, previous, quality, rng, ratios): | |
| 74 | + lines = pair_lines(fixed.tolist()) | |
| 75 | + nx, ny, offsets = np.array(lines).T | |
| 76 | + for ratio in ratios: | |
| 77 | + target = max(0.003, ratio * quality) | |
| 78 | + cells = feasible_cells(lines, target) | |
| 79 | + centers = np.array([np.mean(cell, axis=0) for cell in cells]) | |
| 80 | + if not len(centers): | |
| 81 | + continue | |
| 82 | + distances = np.linalg.norm(centers[:, None, :] - previous, axis=2).min(axis=1) | |
| 83 | + far_enough = distances > 0.035 | |
| 84 | + if far_enough.any(): | |
| 85 | + centers = centers[far_enough] | |
| 86 | + elif ratio != ratios[-1]: | |
| 87 | + continue | |
| 88 | + areas = np.abs(centers[:, 0, None] * nx + centers[:, 1, None] * ny - offsets) | |
| 89 | + best = np.argsort(areas.min(axis=1))[-5:] | |
| 90 | + return centers[rng.choice(best)] | |
| 91 | + return None | |
| 92 | + | |
| 93 | + | |
| 94 | +def strip_neighbor(points, rng, step): | |
| 95 | + # Interleave the cheap single-point and Gaussian moves as a control. | |
| 96 | + if step % 3 == 0 and step % 13 != 0: | |
| 97 | + return neighbor(points, rng, step) | |
| 98 | + | |
| 99 | + areas = np.abs(signed_area(points)) | |
| 100 | + quality = areas.min() | |
| 101 | + tight = TRIPLE_INDICES[areas <= quality + 0.0008] | |
| 102 | + weights = 1 + np.bincount(tight.ravel(), minlength=N) | |
| 103 | + probabilities = weights / weights.sum() if step % 2 else None | |
| 104 | + cover_move = step % 13 == 0 | |
| 105 | + if cover_move: | |
| 106 | + removed = minimum_cover(TRIPLE_INDICES[areas <= quality + 1e-8], rng) | |
| 107 | + else: | |
| 108 | + count = 3 if step % 5 == 0 else 2 | |
| 109 | + removed = rng.choice(N, size=count, replace=False, p=probabilities) | |
| 110 | + fixed = np.delete(points, removed, axis=0) | |
| 111 | + new = points.copy() | |
| 112 | + ratios = (0.93, 0.78, 0.62, 0.48, 0.33) if cover_move else (0.93, 0.78, 0.62) | |
| 113 | + for index in removed: | |
| 114 | + candidate = insertion(fixed, points[removed], quality, rng, ratios) | |
| 115 | + if candidate is None: | |
| 116 | + return neighbor(points, rng, step) | |
| 117 | + new[index] = candidate | |
| 118 | + fixed = np.vstack((fixed, candidate)) | |
| 119 | + return np.clip(new, 0, 1) | |
+63 −0 routes/hongdy22-codex-n15-search/throttled_search.py added View file
| @@ -0,0 +1,63 @@ | ||
| 1 | +"""Try strip-cover moves from the n = 15 record at a low local CPU duty cycle.""" | |
| 2 | + | |
| 3 | +import argparse | |
| 4 | +import json | |
| 5 | +import time | |
| 6 | +from pathlib import Path | |
| 7 | + | |
| 8 | +import numpy as np | |
| 9 | + | |
| 10 | +from search import RECORD_NEXT_DIGIT, exact_fitness, run_track | |
| 11 | +from strip_moves import strip_neighbor | |
| 12 | + | |
| 13 | + | |
| 14 | +CPU_FRACTION = 0.04 | |
| 15 | + | |
| 16 | + | |
| 17 | +class ThrottledMoves: | |
| 18 | + def __init__(self, seconds): | |
| 19 | + self.started = time.monotonic() | |
| 20 | + self.cpu_started = time.process_time() | |
| 21 | + self.seconds = seconds | |
| 22 | + self.reported_at = self.started | |
| 23 | + | |
| 24 | + def __call__(self, points, rng, step): | |
| 25 | + cpu_used = time.process_time() - self.cpu_started | |
| 26 | + now = time.monotonic() | |
| 27 | + elapsed = now - self.started | |
| 28 | + delay = min(self.seconds - elapsed, cpu_used / CPU_FRACTION - elapsed) | |
| 29 | + if delay > 0: | |
| 30 | + time.sleep(delay) | |
| 31 | + if now - self.reported_at >= 30: | |
| 32 | + print(f"progress: {min(99, int(100 * elapsed / self.seconds))}% " | |
| 33 | + f"attempts={step} search_cpu={cpu_used:.1f}s", flush=True) | |
| 34 | + self.reported_at = now | |
| 35 | + return strip_neighbor(points, rng, step) | |
| 36 | + | |
| 37 | + | |
| 38 | +def main(): | |
| 39 | + parser = argparse.ArgumentParser(description=__doc__) | |
| 40 | + parser.add_argument("seconds", type=float) | |
| 41 | + parser.add_argument("seed", type=int) | |
| 42 | + parser.add_argument("--output-dir", type=Path, default=Path(".")) | |
| 43 | + args = parser.parse_args() | |
| 44 | + if args.seconds <= 0: | |
| 45 | + parser.error("seconds must be positive") | |
| 46 | + route = Path(__file__).resolve().parent | |
| 47 | + baseline = np.loadtxt(route / "reference15.dat") | |
| 48 | + moves = ThrottledMoves(args.seconds) | |
| 49 | + result = run_track("record", args.seed, args.seconds, None, (None, baseline), move=moves) | |
| 50 | + improved = exact_fitness(result["coordinates"]) >= RECORD_NEXT_DIGIT | |
| 51 | + result["search_cpu_seconds"] = round(time.process_time() - moves.cpu_started, 3) | |
| 52 | + result["wall_budget_seconds"] = args.seconds | |
| 53 | + result["cleared_next_check_digit"] = improved | |
| 54 | + args.output_dir.mkdir(parents=True, exist_ok=True) | |
| 55 | + (args.output_dir / "strip-summary.json").write_text(json.dumps(result, indent=2) + "\n") | |
| 56 | + if improved: | |
| 57 | + (args.output_dir / "n15.txt").write_text("\n".join(result["coordinates"]) + "\n") | |
| 58 | + print(f"progress: 100% attempts={result['attempts']} " | |
| 59 | + f"search_cpu={result['search_cpu_seconds']:.3f}s improved={improved}", flush=True) | |
| 60 | + | |
| 61 | + | |
| 62 | +if __name__ == "__main__": | |
| 63 | + main() | |
+60 −0 routes/hongdy22-codex-n15-search/verify_deletion.py added View file
| @@ -0,0 +1,60 @@ | ||
| 1 | +"""Verify a rational n = 15 construction and two coordinate-wise upper bounds.""" | |
| 2 | + | |
| 3 | +from fractions import Fraction | |
| 4 | +from itertools import combinations | |
| 5 | +from pathlib import Path | |
| 6 | + | |
| 7 | + | |
| 8 | +TARGET = Fraction(31, 1485) | |
| 9 | +WEIGHTS = ( | |
| 10 | + { | |
| 11 | + (1, 7, 15): Fraction(8, 225), | |
| 12 | + (2, 7, 11): Fraction(31, 225), | |
| 13 | + (5, 9, 13): Fraction(31, 45), | |
| 14 | + (11, 13, 15): Fraction(31, 225), | |
| 15 | + }, | |
| 16 | + { | |
| 17 | + (1, 3, 10): Fraction(2, 33), | |
| 18 | + (4, 8, 10): Fraction(31, 33), | |
| 19 | + }, | |
| 20 | +) | |
| 21 | + | |
| 22 | + | |
| 23 | +def area(triangle): | |
| 24 | + (ax, ay), (bx, by), (cx, cy) = triangle | |
| 25 | + return abs((bx - ax) * (cy - ay) - (cx - ax) * (by - ay)) / 2 | |
| 26 | + | |
| 27 | + | |
| 28 | +def axis_bound(points, axis, weights): | |
| 29 | + """Bound the minimum for a fixed other axis and fixed triangle orientations.""" | |
| 30 | + assert sum(weights.values()) == 1 and min(weights.values()) > 0 | |
| 31 | + coefficients = [Fraction(0)] * len(points) | |
| 32 | + for triple, weight in weights.items(): | |
| 33 | + positions = [points[i - 1][axis] for i in triple] | |
| 34 | + fixed = [points[i - 1][1 - axis] for i in triple] | |
| 35 | + a, b, c = fixed | |
| 36 | + terms = ((b - c) / 2, (c - a) / 2, (a - b) / 2) | |
| 37 | + value = sum(t * x for t, x in zip(terms, positions)) | |
| 38 | + assert abs(value) == TARGET | |
| 39 | + sign = 1 if value > 0 else -1 | |
| 40 | + for index, term in zip(triple, terms): | |
| 41 | + coefficients[index - 1] += weight * sign * term | |
| 42 | + return sum(max(0, coefficient) for coefficient in coefficients) | |
| 43 | + | |
| 44 | + | |
| 45 | +def main(): | |
| 46 | + path = Path(__file__).with_name("deletion-certificate.dat") | |
| 47 | + points = [tuple(map(Fraction, line.split())) for line in path.read_text().splitlines()] | |
| 48 | + assert len(points) == len(set(points)) == 15 | |
| 49 | + assert all(0 <= value <= 1 for p in points for value in p) | |
| 50 | + areas = list(map(area, combinations(points, 3))) | |
| 51 | + assert min(areas) == TARGET | |
| 52 | + print(f"Exact minimum {TARGET} attained by {areas.count(TARGET)} of {len(areas)} triangles.") | |
| 53 | + for axis, label in enumerate("xy"): | |
| 54 | + bound = axis_bound(points, axis, WEIGHTS[axis]) | |
| 55 | + assert bound == TARGET | |
| 56 | + print(f"Vary {label} with the other axis and orientations fixed: upper bound {bound}.") | |
| 57 | + | |
| 58 | + | |
| 59 | +if __name__ == "__main__": | |
| 60 | + main() | |