"""goldcps.py -- the golden fixed sets read as cut-and-project sets. QUESTION. Each of the 22 survivors x of [0, delta_4] at L = 40 (goldroot's SURV), delta' = R(phi^2/3) among them, has a fixed set A_inf, B_inf of points in (1/d)Z[phi]. Is each one coset's points in a window times a conjugate interval (a cut-and-project set, CPS, with interval windows)? And is the 181-state closed subgame that delta_1's scale-1 translates leave in delta''s game structure, or what any compact source of its sizes closes? DESIGN (frozen before this engine). A point v = (a + b phi)/d is held as the integer pair (a, b); v* = (a + b - b phi)/d. L_A is the Z-span of A's differences, the least lattice whose coset holds A, kept as a basis (e, f), (0, g); H is the box of A's real and conjugate ranges. Any interval windows holding A hold H, and any lattice holding A's differences holds L_A, so A is a CPS with interval windows over some lattice of Q(phi) iff the coset a0 + L_A has |A| points in H (the box count). The convex count is the coset's points in the convex hull of the plane points (v, v*); box >= convex >= |A|. Signs of x + y phi are decided in integers (2x + y + y sqrt5). The null: 200 draws, seed 2169, of a source made of the 5 target-A points nearest a uniformly drawn target-A point and the 11 target-B points nearest a drawn target-B point (Euclidean in (v, v*)); its scale-1 translates into delta''s fixed set, their unions, and the largest closed subgame inside, as goldroot's (F). PREDICTIONS (frozen before the engine). C0 (TRANSPLANT, goldfix's print over Z[phi]) at delta_2, delta_3, delta_4, L_A has index 1, so the box counts reprint 53, 422, 3074. C1 (a guess) no survivor with |A_inf| >= 31 is a box CPS on A, and none of delta_2 .. delta_4 is lattice-convex on A. C2 (a guess) A_inf(delta') is no box CPS. C3 (a guess) the 181 is no outlier. KILL of the aim's reading: "box CPS on A: n of 22", n < 22. KILL of the 181's structure: "null: k of 200 draws close >= 181 A states"; structure iff k < 10. Controls: (a) the real source reprints goldroot's 85 t_A, 122 t_B, closed 181; (b) K_k (goldfix's window) at k = 2, 3, 4 a CPS on both counts, |K_k| = 4, 12, 33; (c) K_k less a point that is no hull vertex, k = 3, 4, read "not CPS" on both; (d) delta_2 .. delta_4 over Z^2 reprint 53, 422, 3074. Arms added after the first run (frozen before their code): W1 (a pattern guess) L_A is the fractional ideal Z[phi] + x Z[phi] at all 22; W2 r, the runs of members among the box's coset points sorted by v*, is the least number of intervals of a conjugate window W* with A = coset in (real hull) x W* (r' likewise sorted by v), guessed to grow with |A|; KILL of the finite-window reading: max r over the 22 above 8. FINDINGS (copied from the print). Controls held: (b) K_k at k = 2, 3, 4: |K| 4, 12, 33, index 1, box and convex counts equal, one window interval each way; (c) K_3, K_4 less a non-vertex point: box and convex 12, 33 against 11, 32, two conj intervals; (d) delta_2 .. delta_4 over Z^2: 53, 422, 3074, goldfix's; (a) delta_1's source (|A| 5, |B| 11): 85 t_A, 122 t_B, closed 181. C0 held: L_A has index 1 at delta_2 .. delta_4. KILL of the aim's reading FIRED: "box CPS on A: 2 of 22; lattice-convex on A: 2 of 22", delta_0's point and delta_1's five; on B 1 of 22 on both. C1 held from |A| = 18 up, every survivor's box and convex counts above |A| (phi/2: 23, 21 against 18; (-12 + 14phi)/11: 1840, 1503 against 659). C2 held: delta' (301; box 752, convex 727). W1, frozen at all 22, fails at delta_0 alone (the print's None), its one point spanning {0}: L_A = Z[phi] + x Z[phi] at 21 of 21 rank-2 survivors (index d at the ten with d > 1 whose numerator's norm d divides, (-2 + 4phi)/5, (-13 + 11phi)/5 and every d = 11, 19, 29; index 1 at the other eleven, 3phi/5 among them), and A_inf, B_inf lie in the ideal itself at 22 of 22: a pattern for the equality; the inclusion follows from every end of A_n, B_n being alpha + beta delta, alpha and beta in Z[phi] (goldsurv's cells). W2: finite-window reading KILLED, max r 540 ((-4 + 20phi)/29, |A| 1326). Off the chain r is a fraction of |A| (phi/2: 4 of 18; (-11 + 8phi)/2: 390 of 875); along the chain delta_2, delta_3, delta_4 it is 6, 20, 56 of 31, 211, 1437 (r' 16, 111, 770). r does not grow with |A|: 168 at |A| 419, 162 at 559. C3 KILLED, the 181 beats this null: "0 of 200 draws close >= 181 A states; median 89" (max 166; 55 draws whose union holds no closed subgame). A nearest-point source is no CPS, and its B side is the 11 B points nearest a drawn one, so neither a CPS source nor a free B side is read here. RUN RECORD. 4 of 4, 59.7 s, peak 219.0 MB under a 2048 MB cap. Changes to what was frozen: W1 and W2 came after the first run; the window-run counter's control (r = 1 on K_k, 2 with the plant) and W1's inclusion in the ideal itself were added with them; W1's equality is read at the rank-2 survivors only, delta_0 named above. The load-bearing FINDINGS figures are now checks (8 of 8, 64.8 s); printed only: W1's index list, (b)'s index 1, (c)'s 12, 33 against 11, 32, the per-survivor box and convex counts (phi/2's 23, 21; 1840, 1503), W2's r at phi/2, (-11 + 8phi)/2, |A| 419 and 559. Run: python goldcps.py """ from fractions import Fraction as Fr from functools import cmp_to_key from math import gcd, floor, ceil import os import random import sys import time os.environ.setdefault("OPENBLAS_NUM_THREADS", "1") HERE = os.path.dirname(os.path.abspath(__file__)) sys.path.insert(0, HERE) import goldroot as gr # noqa PHI = (1 + 5 ** .5) / 2 S5 = 5 ** .5 CHECKS = [] def check(name, ok, detail=""): CHECKS.append(bool(ok)) print(f" [{'ok ' if ok else 'FAIL'}] {name}" + (f" -- {detail}" if detail else "")) # ------------------------------------------------------------ Z[phi] in ints def zs(x, y): """sign of x + y phi, x and y integers.""" p, r = 2 * x + y, y if p >= 0 and r >= 0: return 1 if p or r else 0 if p <= 0 and r <= 0: return -1 s = p * p - 5 * r * r return (1 if s > 0 else -1) if p > 0 else (1 if s < 0 else -1) def zmul(u, v): return (u[0] * v[0] + u[1] * v[1], u[0] * v[1] + u[1] * v[0] + u[1] * v[1]) def re_(p): return p # (a, b): a + b phi def co_(p): return (p[0] + p[1], -p[1]) # conjugate: a + b - b phi def zcmp(u, v): return zs(u[0] - v[0], u[1] - v[1]) def zfl(u): return u[0] + u[1] * PHI def to_int(S, d): out = [] for x, y in S: a, b = x * d, y * d assert a.denominator == 1 and b.denominator == 1, (x, y, d) out.append((int(a), int(b))) return out # ------------------------------------------------------------ the lattice class Lat: """Z-span of integer vectors, basis (e, f), (0, g), e >= 0, g >= 0.""" def __init__(self, vecs): self.e, self.f, self.g = 0, 0, 0 for x, y in vecs: self.add(x, y) def add(self, x, y): if x < 0: x, y = -x, -y if self.e == 0: if x == 0: self.g = gcd(self.g, y) else: self.e, self.f = x, y elif x != 0: e, f = self.e, self.f g0, s, t = egcd(e, x) nf = s * f + t * y ky = (x // g0) * f - (e // g0) * y # x-component 0 self.e, self.f = g0, nf self.g = gcd(self.g, ky) else: self.g = gcd(self.g, y) if self.g: self.f %= self.g def rank(self): return (self.e != 0) + (self.g != 0) def index(self): return self.e * self.g if self.rank() == 2 else None def has(self, x, y): if self.e == 0: if x != 0: return False return y == 0 if self.g == 0 else y % self.g == 0 if x % self.e: return False r = y - (x // self.e) * self.f return r == 0 if self.g == 0 else r % self.g == 0 def egcd(a, b): if b == 0: return (a, 1, 0) g, s, t = egcd(b, a % b) return (g, t, s - (a // b) * t) # ------------------------------------------------------------ the counts def box_points(P, lat): """coset points P[0] + lat inside the box of P's real and conj ranges.""" a0 = P[0] R = [re_(p) for p in P] C = [co_(p) for p in P] lo = min(R, key=cmp_to_key(zcmp)) hi = max(R, key=cmp_to_key(zcmp)) clo = min(C, key=cmp_to_key(zcmp)) chi = max(C, key=cmp_to_key(zcmp)) flo, fhi, fclo, fchi = zfl(lo), zfl(hi), zfl(clo), zfl(chi) out = [] for b in range(floor((flo - fchi) / S5) - 1, ceil((fhi - fclo) / S5) + 2): amin = max(flo - b * PHI, fclo - b + b * PHI) amax = min(fhi - b * PHI, fchi - b + b * PHI) for a in range(ceil(amin) - 1, floor(amax) + 2): if not lat.has(a - a0[0], b - a0[1]): continue p, c = (a, b), (a + b, -b) if (zcmp(p, lo) >= 0 and zcmp(p, hi) <= 0 and zcmp(c, clo) >= 0 and zcmp(c, chi) <= 0): out.append(p) return out def orient(p, q, r): """sign of (q - p) x (r - p) in the plane (v, v*), exact.""" pr, pc = re_(p), co_(p) qx = (q[0] - pr[0], q[1] - pr[1]) qc = co_(q) qy = (qc[0] - pc[0], qc[1] - pc[1]) rx = (r[0] - pr[0], r[1] - pr[1]) rc = co_(r) ry = (rc[0] - pc[0], rc[1] - pc[1]) fv = zfl(qx) * zfl(ry) - zfl(qy) * zfl(rx) if abs(fv) > 1e-6 * (1 + abs(zfl(qx)) + abs(zfl(qy))) * ( 1 + abs(zfl(rx)) + abs(zfl(ry))): return 1 if fv > 0 else -1 u, v = zmul(qx, ry), zmul(qy, rx) return zs(u[0] - v[0], u[1] - v[1]) def hull(P): pts = sorted(set(P), key=cmp_to_key(lambda u, v: zcmp(u, v))) if len(pts) <= 2: return pts lower, upper = [], [] for p in pts: while len(lower) >= 2 and orient(lower[-2], lower[-1], p) <= 0: lower.pop() lower.append(p) for p in reversed(pts): while len(upper) >= 2 and orient(upper[-2], upper[-1], p) <= 0: upper.pop() upper.append(p) return lower[:-1] + upper[:-1] def in_hull(h, p): if len(h) == 1: return p == h[0] if len(h) == 2: return orient(h[0], h[1], p) == 0 # p already in the box return all(orient(h[i], h[(i + 1) % len(h)], p) >= 0 for i in range(len(h))) def runs_along(P, lat, conj): """members' runs among the box's coset points sorted by v* (conj) or by v: the least number of intervals of that coordinate's window.""" bx = box_points(P, lat) key = co_ if conj else re_ bx.sort(key=cmp_to_key(lambda u, v: zcmp(key(u), key(v)))) S = set(P) r, prev = 0, False for p in bx: m = p in S r += m and not prev prev = m return r def ideal(x, d): """Z-span of d, d phi, d x, d x phi in ints over d (x = (a + b phi)/d).""" a, b = x return Lat([(d, 0), (0, d), (a, b), zmul((a, b), (0, 1))]) def counts(P, lat=None): """(|P|, rank, index, box count, convex count, hull size).""" if lat is None: lat = Lat((p[0] - P[0][0], p[1] - P[0][1]) for p in P) bx = box_points(P, lat) h = hull(P) cv = [p for p in bx if in_hull(h, p)] return len(P), lat.rank(), lat.index(), len(bx), len(cv), len(h) # ------------------------------------------------------------ K_k def kwin(k): """goldfix's K_k: v in Z[phi], v in I, v* in I* (v = a + b phi).""" eps = gr.phipow(-2 * k) N = gr.phipow(2 * k) lo = gr.add(gr.mul(gr.q(-1), gr.phipow(-2)), eps) hi = gr.sub(gr.mul(gr.q(2), gr.phipow(-1)), gr.mul(gr.PHI, eps)) clo, chi = gr.q(0), gr.sub(N, gr.phipow(2)) out = [] flo, fhi, fclo, fchi = (gr.fl(x) for x in (lo, hi, clo, chi)) for b in range(floor((flo - fchi) / S5) - 1, ceil((fhi - fclo) / S5) + 2): for a in range(ceil(max(flo - b * PHI, fclo - b + b * PHI)) - 1, floor(min(fhi - b * PHI, fchi - b + b * PHI)) + 2): v, c = gr.q(a, b), gr.q(a + b, -b) if (gr.cmp(v, lo) >= 0 and gr.cmp(v, hi) <= 0 and gr.cmp(c, clo) >= 0 and gr.cmp(c, chi) <= 0): out.append((a, b)) return out # ------------------------------------------------------------ the null def emb(v): x, y = float(v[0]), float(v[1]) return (x + y * PHI, x + y - y * PHI) def nearest(S, i, n): c = emb(S[i]) E = [emb(w) for w in S] order = sorted(range(len(S)), key=lambda j: (E[j][0] - c[0]) ** 2 + (E[j][1] - c[1]) ** 2) return [S[j] for j in sorted(order[:n], key=lambda j: gr.fl(S[j]))] def closed_at_one(src, A, B, mA, mB, ixA, ixB): hs = [h for h in gr.search(src, (A, B), grid=range(0, 1)) if h[0] == 1] if not hs: return 0, 0, 0 _, _, tA, tB = hs[0] iA = {ixA[gr.add(v, t)] for t in tA for v in src[0]} iB = {ixB[gr.add(u, t)] for t in tB for u in src[1]} return len(tA), len(tB), len(gr.closed(mA, mB, iA, iB)[0]) # ------------------------------------------------------------ main def main(): t0 = time.time() print("== (b), (c) the positive control: goldfix's window K_k") want = {2: 4, 3: 12, 4: 33} okb, okc = True, True for k in (2, 3, 4): K = kwin(k) n, rk, ix, bx, cv, hs = counts(K) print(f" K_{k}: |K| {n}, rank {rk}, index {ix}, box {bx}, convex " f"{cv}, hull vertices {hs}") lk = Lat((p[0] - K[0][0], p[1] - K[0][1]) for p in K) rk2 = (runs_along(K, lk, True), runs_along(K, lk, False)) print(f" window intervals (conj, real) {rk2}") okb &= n == want[k] and bx == n and cv == n and rk2 == (1, 1) if k >= 3: h = set(hull(K)) inner = [p for p in K if p not in h] Kp = [p for p in K if p != inner[0]] lat = Lat((p[0] - Kp[0][0], p[1] - Kp[0][1]) for p in Kp) n2, _, _, bx2, cv2, _ = counts(Kp, lat) print(f" less {inner[0]}: |K| {n2}, box {bx2}, convex {cv2}") rc = runs_along(Kp, lat, True) print(f" conj-window intervals {rc}") okc &= bx2 > n2 and cv2 > n2 and rc == 2 check("(b) K_k a CPS on both counts, |K_k| = 4, 12, 33, one window " "interval each way", okb) check("(c) K_k less a non-vertex point read not CPS on both, two conj " "intervals", okc) print("== the survivors' fixed sets") runs = {} for x in gr.SURV: runs[x] = gr.run(gr.spt(*x))["d"] G = gr.run(gr.DP)["d"] rows = [] for x in gr.SURV + [("delta'", (-2, 3, 3))]: if x[0] == "delta'": name, d, H = "delta' = (-2 + 3phi)/3", 3, G else: name, d, H = gr.show(gr.pt_q(gr.spt(*x))), x[2], runs[x] FA, FB = (gr.pts(S) for S in gr.fixed(H)) PA, PB = to_int(FA, d), to_int(FB, d) cA, cB = counts(PA), counts(PB) rows.append((x, name, cA, cB)) print(f" {name:24s} d {d:2d} A: |A| {cA[0]:5d} rank {cA[1]} index " f"{cA[2]} box {cA[3]:6d} convex {cA[4]:6d} hull {cA[5]:3d} | " f"B: |B| {cB[0]:5d} index {cB[2]} box {cB[3]:6d} convex " f"{cB[4]:6d}") sv = rows[:22] boxA = sum(r[2][3] == r[2][0] for r in sv) cvA = sum(r[2][4] == r[2][0] for r in sv) boxB = sum(r[3][3] == r[3][0] for r in sv) cvB = sum(r[3][4] == r[3][0] for r in sv) print(f" box CPS on A: {boxA} of 22; lattice-convex on A: {cvA} of 22") print(f" box CPS on B: {boxB} of 22; lattice-convex on B: {cvB} of 22") dp = rows[22] print(f" delta': box CPS on A {dp[2][3] == dp[2][0]}, convex " f"{dp[2][4] == dp[2][0]}") big = [r for r in sv if r[2][0] >= 18] check("the kill fired: box CPS on A 2 of 22, lattice-convex 2 of 22 " "(delta_0, delta_1), on B 1 of 22 on both; C1 from |A| = 18 up, " "every box and convex count above |A|; C2, delta' 301, box 752, " "convex 727", (boxA, cvA, boxB, cvB) == (2, 2, 1, 1) and {r[0] for r in sv if r[2][3] == r[2][0]} == set(gr.SURV[:2]) and all(r[2][3] > r[2][0] and r[2][4] > r[2][0] for r in big) and dp[2][0] == 301 and (dp[2][3], dp[2][4]) == (752, 727)) print("== W1 L_A against the ideal Z[phi] + x Z[phi]; W2 the windows' " "intervals") w1, w1in, rs, rows_w = 0, 0, [], [] for x, name, cA, cB in rows: xx = (-2, 3, 3) if x[0] == "delta'" else x d = xx[2] H = G if x[0] == "delta'" else runs[x] PA = to_int(gr.pts(gr.fixed(H)[0]), d) PB = to_int(gr.pts(gr.fixed(H)[1]), d) la = Lat((p[0] - PA[0][0], p[1] - PA[0][1]) for p in PA) lb = Lat((p[0] - PB[0][0], p[1] - PB[0][1]) for p in PB) idl = ideal(xx[:2], d) same = ((la.e, la.f, la.g) == (idl.e, idl.f, idl.g) if la.rank() == 2 else None) sameB = ((lb.e, lb.f, lb.g) == (idl.e, idl.f, idl.g) if lb.rank() == 2 else None) inA = all(idl.has(*p) for p in PA + PB) if x[0] != "delta'": w1 += bool(same) w1in += inA r = runs_along(PA, la, True) if la.rank() == 2 else 1 rp = runs_along(PA, la, False) if la.rank() == 2 else 1 rb = runs_along(PB, lb, True) if lb.rank() == 2 else 1 if x[0] != "delta'": rs.append(r) rows_w.append((x, cA[0], r, rp, same)) print(f" {name:24s} |A| {cA[0]:5d}: L_A = ideal {same}, L_B = " f"ideal {sameB}; conj-window intervals A {r}, B {rb}; real-" f"window intervals A {rp}") print(f" W1: L_A = Z[phi] + x Z[phi] at {w1} of " f"{sum(r[2][1] == 2 for r in sv)} rank-2 survivors; A_inf and " f"B_inf inside the ideal itself at {w1in} of 22") print(f" W2: max conj-window intervals over the 22 on A: {max(rs)}; " f"finite-window reading {'survives' if max(rs) <= 8 else 'KILLED'}") rk2 = [r for r in sv if r[2][1] == 2] chain = {w[0]: w for w in rows_w} check("W1 at 21 of 21 rank-2 survivors, delta_0 the one of rank 0, " "the sets inside the ideal at 22 of 22; W2 killed, max r 540 at " "|A| 1326; along delta_2 .. delta_4 r 6, 20, 56, r' 16, 111, 770", w1 == 21 and len(rk2) == 21 and w1in == 22 and [w[4] for w in rows_w][0] is None and max(rs) == 540 and [w[1] for w in rows_w if w[2] == 540] == [1326] and [chain[x][2] for x in gr.SURV[2:5]] == [6, 20, 56] and [chain[x][3] for x in gr.SURV[2:5]] == [16, 111, 770]) print("== (d) the instrument against goldfix's print, over Z^2") full = Lat([(1, 0), (0, 1)]) got = [] for x in gr.SURV[2:5]: PA = to_int(gr.pts(gr.fixed(runs[x])[0]), x[2]) got.append(len(box_points(PA, full))) check("(d) delta_2 .. delta_4 over Z^2: 53, 422, 3074", got == [53, 422, 3074], f"{got}") c0 = [r[2][2] for r in sv[2:5]] print(f" C0: index of L_A at delta_2 .. delta_4 {c0}; " f"{'held' if c0 == [1, 1, 1] else 'KILLED'}") check("C0 held: L_A has index 1 at delta_2 .. delta_4", c0 == [1, 1, 1]) print("== (a) the 181 and its null") FA, FB = (gr.pts(S) for S in gr.fixed(G)) dpq = gr.pt_q(gr.DP) mA, mB = gr.moves(dpq, FA, FB) ixA = {w: i for i, w in enumerate(FA)} ixB = {w: i for i, w in enumerate(FB)} src = tuple(gr.pts(S) for S in gr.fixed(runs[(-1, 1, 1)])) real = closed_at_one(src, FA, FB, mA, mB, ixA, ixB) print(f" delta_1's source |A| {len(src[0])}, |B| {len(src[1])}: " f"{real[0]} t_A, {real[1]} t_B, closed {real[2]}") check("(a) the real source reprints 85 t_A, 122 t_B, closed 181", real == (85, 122, 181)) rng = random.Random(2169) nA, nB = len(src[0]), len(src[1]) vals = [] for _ in range(200): s = (nearest(FA, rng.randrange(len(FA)), nA), nearest(FB, rng.randrange(len(FB)), nB)) vals.append(closed_at_one(s, FA, FB, mA, mB, ixA, ixB)[2]) vals.sort() k = sum(v >= real[2] for v in vals) print(f" null closed sizes: min {vals[0]}, quartiles {vals[50]}, " f"{vals[100]}, {vals[150]}, max {vals[-1]}; zero in " f"{sum(v == 0 for v in vals)}") print(f" null: {k} of 200 draws close >= {real[2]} A states; median " f"{vals[100]}") print(f" the 181: {'beats this null' if k < 10 else 'no outlier'}") check("C3 killed, the 181 beats this null: 0 of 200 draws close >= 181; " "median 89, max 166, 55 draws closing nothing", k == 0 and vals[100] == 89 and vals[-1] == 166 and sum(v == 0 for v in vals) == 55) print(f"\n{sum(CHECKS)} of {len(CHECKS)} checks, {time.time() - t0:.1f} s") return 0 if all(CHECKS) else 1 if __name__ == "__main__": sys.exit(main())