#!/usr/bin/env python3 """My own search inside the C4-symmetric family of 12-point configurations. Usage: c4search.py [SEED] [STARTS] > n12.txt A 12-point set invariant under the quarter turn R(x, y) = (1 - y, x) about the centre is three orbits of four points each (12 = 4*3), so the whole family has six free numbers: the three orbit representatives. This script optimizes those six by the same softmin continuation as search.py (chain rule through the orbit maps), from uniform random starts. No literature coordinates are used. The idea to search a rotation-restricted family is credited to the issue trail (cogito-claude's symmetric routes on n = 16; the symmetric constructions in the record table). The code, the parameterization and the runs are my own. """ import itertools import math import random import sys def triples_of(n): return list(itertools.combinations(range(n), 3)) def expand(reps): """The 12 points: each representative and its quarter-turn images.""" p = [] for rx, ry in reps: p.append((rx, ry)) p.append((1.0 - ry, rx)) p.append((1.0 - rx, 1.0 - ry)) p.append((ry, 1.0 - rx)) return p # d orbit point j / d (rx, ry), as linear maps: (dx/drx, dx/dry), (dy/drx, dy/dry) ORBIT_JAC = ( ((1.0, 0.0), (0.0, 1.0)), # (rx, ry) ((0.0, -1.0), (1.0, 0.0)), # (1-ry, rx) ((-1.0, 0.0), (0.0, -1.0)), # (1-rx, 1-ry) ((0.0, 1.0), (-1.0, 0.0)), # (ry, 1-rx) ) # which representative and orbit slot each of the 12 points came from SLOT = [(r, s) for r in range(3) for s in range(4)] def softmin_step(reps, tri, beta, step): """One gradient ascent step on the softmin over the C4 family; returns (S, true min A2).""" p = expand(reps) xs = [q[0] for q in p] ys = [q[1] for q in p] n = len(p) gx = [0.0] * n gy = [0.0] * n vals = [] for i, j, k in tri: ax, ay, bx, by, cx, cy = xs[i], ys[i], xs[j], ys[j], xs[k], ys[k] ux = bx - ax uy = by - ay vx = cx - ax vy = cy - ay cr = ux * vy - uy * vx a = cr if cr >= 0.0 else -cr vals.append([a, cr, i, j, k, ux, uy, vx, vy, 0.0]) m = min(v[0] for v in vals) z = 0.0 for v in vals: e = math.exp(-beta * (v[0] - m)) if beta * (v[0] - m) < 700.0 else 0.0 v[9] = e z += e s = m - math.log(z) / beta if z > 0.0 else m inv = 1.0 / z if z > 0.0 else 0.0 for v in vals: a, cr, i, j, k, ux, uy, vx, vy, e = v if e == 0.0: continue w = e * inv g = w if cr >= 0.0 else -w gx[i] += g * (uy - vy) gy[i] += g * (vx - ux) gx[j] += g * vy gy[j] += g * -vx gx[k] += g * -uy gy[k] += g * ux # pull the point gradients back through the orbit maps rx = [0.0] * 3 ry = [0.0] * 3 for t in range(n): r, slot = SLOT[t] j11, j12 = ORBIT_JAC[slot][0] j21, j22 = ORBIT_JAC[slot][1] rx[r] += j11 * gx[t] + j21 * gy[t] ry[r] += j12 * gx[t] + j22 * gy[t] for r in range(3): nx = reps[r][0] + step * rx[r] ny = reps[r][1] + step * ry[r] if nx < 0.0: nx = 0.0 elif nx > 1.0: nx = 1.0 if ny < 0.0: ny = 0.0 elif ny > 1.0: ny = 1.0 reps[r] = (nx, ny) return s, m / 2.0 def smallest(p): best = None xs = [q[0] for q in p] ys = [q[1] for q in p] for i, j, k in TRI: ax, ay, bx, by, cx, cy = xs[i], ys[i], xs[j], ys[j], xs[k], ys[k] cr = (bx - ax) * (cy - ay) - (cx - ax) * (by - ay) if cr < 0.0: cr = -cr if best is None or cr < best: best = cr return best / 2.0 def main(): global TRI args = [int(a) for a in sys.argv[1:4]] seed = args[0] if len(args) > 0 else 2026 starts = args[1] if len(args) > 1 else 300 rng = random.Random(seed) TRI = triples_of(12) stages = [(100.0, 0.05, 60), (400.0, 0.03, 60), (1500.0, 0.015, 60), (6000.0, 0.006, 50), (30000.0, 0.002, 50), (150000.0, 0.0006, 40), (800000.0, 0.0002, 40)] deep = [(2000000.0, 0.0001, 300), (10000000.0, 0.00003, 300), (50000000.0, 0.00001, 300), (200000000.0, 0.000003, 200)] pool = [] for t in range(starts): reps = [] while len(reps) < 3: rx, ry = rng.random(), rng.random() if abs(rx - ry) > 0.02: # x = y collapses the orbit reps.append((rx, ry)) p = expand(reps) if len(set(p)) < 12: continue best = smallest(p) for beta, step, iters in stages: for _ in range(iters): s, m = softmin_step(reps, TRI, beta, step) if m > best: best = m # the optimum of this family sits on the boundary: snap near-edge # coordinates exactly onto it reps = [(0.0 if rx < 0.002 else 1.0 if rx > 0.998 else rx, 0.0 if ry < 0.002 else 1.0 if ry > 0.998 else ry) for rx, ry in reps] best = max(best, smallest(expand(reps))) pool.append((best, reps)) pool.sort(reverse=True) pool = pool[:24] # deep polish and the tie polish only for the leading starts best_all, best_reps = None, None for best0, reps0 in pool: reps = reps0[:] best = max(best0, smallest(expand(reps))) for beta, step, iters in deep: for _ in range(iters): s, m = softmin_step(reps, TRI, beta, step) if m > best: best = m # final tie polish in rep space: ascend the mean gradient of the # triangles tied at the minimum (the hard-min subgradient there), # with the step decaying so the iterate settles instead of circling for it in range(14000): stp = 2e-6 * 0.9995 ** it p = expand(reps) xs = [q[0] for q in p] ys = [q[1] for q in p] vals = [] for i, j, k in TRI: ax, ay, bx, by, cx, cy = xs[i], ys[i], xs[j], ys[j], xs[k], ys[k] cr = (bx - ax) * (cy - ay) - (cx - ax) * (by - ay) vals.append(cr if cr >= 0.0 else -cr) m2 = min(vals) grx = [0.0] * 3 gry = [0.0] * 3 cnt = 0 for idx, (i, j, k) in enumerate(TRI): if vals[idx] - m2 > 1e-11: continue cnt += 1 ax, ay, bx, by, cx, cy = xs[i], ys[i], xs[j], ys[j], xs[k], ys[k] cr = (bx - ax) * (cy - ay) - (cx - ax) * (by - ay) g = 1.0 if cr >= 0.0 else -1.0 ux, uy, vx, vy = bx - ax, by - ay, cx - ax, cy - ay gx = [g * (uy - vy), g * vy, g * -uy] gy = [g * (vx - ux), g * -vx, g * ux] for t, pt in enumerate((i, j, k)): r, slot = SLOT[pt] j11, j12 = ORBIT_JAC[slot][0] j21, j22 = ORBIT_JAC[slot][1] grx[r] += j11 * gx[t] + j21 * gy[t] gry[r] += j12 * gx[t] + j22 * gy[t] w = 1.0 / cnt if cnt else 0.0 reps = [(min(1.0, max(0.0, q[0] + stp * w * grx[r])), min(1.0, max(0.0, q[1] + stp * w * gry[r]))) for r, q in enumerate(reps)] nm = smallest(expand(reps)) if nm > best: best = nm if best_all is None or best > best_all: best_all, best_reps = best, reps[:] best = best_all p = expand(best_reps) assert len(set(p)) == 12, "orbits collapsed" print(f"# n = 12: smallest triangle about {best_all:.10f} " f"(c4search.py {seed} {starts}: own search in the quarter-turn-symmetric family)", file=sys.stderr) for x, y in p: print(f"{x:.17f} {y:.17f}") if __name__ == "__main__": main()