"""goldshift.py -- the shift by 1/phi as six translation pairs, d in [1/phi, 1). Frozen before this engine, copied whole: QUESTION. On G_d, d in [1/phi, 1) (V = [1/phi - d, (1 + d)/phi], U = [-2, phi d - 1]; A: c, e in {0, 1}, v -> phi(c - v) in A, phi(e - v) in B; B: c' in {-1, 0, 1}, u -> phi(c' + d - phi - u) in A), does v in A_n and Z0 = [1/phi - d, d/phi - phi^-2] give v + 1/phi in A_n, and u in B_n and Z1 = [-2, phi d - 3] give u + 1/phi in B_n, at EVERY n (so on A_inf, B_inf)? DESIGN (by hand, before the engine). A pair (t, I) on A asserts v in A_n and I gives v + t in A_n. Same move algebra as the climb with the scale 1: from v the digit c lands at a = phi(c - v); from v + t the digit C lands at phi(C - v - t) = a + phi(C - c - t). So the reply translations are t' = phi(C - c - t) (A -> A), phi(E - e - t) (A -> B), phi(C' - c' - t) (B -> A), d cancelling. A family is CLOSED when each pair's window holds (I + t inside V, resp. U) and each played image, cut to its window, lies in the union of the intervals of pairs whose translation is a reply; (0, V) and (0, U) are always in it. Then by induction on n (base: the windows; step: v's moves give v + t's) every pair holds at every n. TRANSPLANT from the climb: that a finite interval family closes; re-derived here, not assumed. THE HAND CLOSURE, d in [1/phi, 1). J = [1/phi - d, phi d - 1] (= -phi Z0 and the c' = -1 image of Z1), K' = [phi - d, (1 + d)/phi] (the e = 1 zone), L = -phi J = [phi - phi^2 d, phi d - 1] split at phi d - phi into L_lo and L_hi, M' = -phi K' = [-1 - d, phi d - phi^2]. A: (1/phi, J), (-1, K'). B: (1/phi, Z1), (1/phi, L_lo), (-1, L_hi), (phi, M'). Z0 is inside J, so the A seed is (1/phi, J)'s. Windows: J + 1/phi in V iff d <= 1; K' - 1 in V (foot 1/phi - d exactly); L_lo + 1/phi top phi d - 1 exactly; L_hi - 1 foot phi d - phi^2 >= -2; M' + phi top phi d - 1 exactly; Z1 + 1/phi. Moves: (1/phi, J): c = 0 (Z0) -> J, C = 1, t' = 1/phi; c = 1 (from d >= phi/2) -> K = [2phi - phi^2 d, (1 + d)/phi] inside K', C = 1, t' = -1; e = 0 -> L, E = 1 (1/phi) on L_lo, E = 0 (-1) on L_hi; e = 1 never (J's top below phi - d iff d < 1). (-1, K'): c = 1 -> C = 0, t' = 0; c = 0 never; e = 0 -> M', E = 0, t' = phi; e = 1 -> E = 0, t' = 0. (1/phi, Z1): c' = -1 alone (d < 1) -> J, C' = 0, t' = 1/phi. (1/phi, L_lo): c' = -1 never; c' = 0 (d >= 3phi - 4) -> inside J (top phi d (1 + phi^2) - 2 phi^2 <= phi d - 1 iff d <= 1), C' = 1, t' = 1/phi; c' = 1 -> inside K', C' = 1, t' = -1. (-1, L_hi): c' = -1 never; c' = 0, 1 -> C' = c' - 1, t' = 0. (phi, M'): c' = -1 (d >= 2/phi^2) -> inside J, C' = 1, t' = 1/phi; c' = 0 -> K' exactly, C' = 1, t' = -1; c' = 1 never (top - (-1 + d/phi) = d - phi < 0). PREDICTIONS (frozen before the engine). Q1 the six pairs close on every leaf of [1/phi, 1). Q2 without any one of the five pairs other than (1/phi, Z1), closure fails on some leaf. Q3 (the theorem's prediction, exact interval sets) at every survivor y >= 1/phi of [0, delta_4] (goldroot's SURV, run to L = 40) and at 12 rational points of (1/phi, 1) off the survivors, run until A empties or L = 40: each pair's image (A_n and I) + t lies in A_n (B alike) at every level n, 0 failures. Q4 (a guess) the checker splits [1/phi, 1) only at roots among 2/phi^2, phi/2, 3phi - 4, 2/sqrt5. KILL (one print): "closure fails at N leaves of [1/phi, 1)"; the hand closure stands iff N = 0, and with it the SHIFT at every n; else the golden fixed sets close as a direction (reopen: a proof of the shift). Controls, read before the kill: (a) a known failure: the seeds alone ((1/phi, Z0), (1/phi, Z1)) fail, at c = 0 from Z0 (image J uncovered) and at e = 0 and c' = -1; (b) a known answer: Q3's level check at L = 40 recovers goldcopy's 4086 of 4086 and 6275 of 6275 (the c = 0 alone and c' = -1 alone points shifted into A_inf, B_inf); (c) plants: the checker with L_lo widened to all of L ((-1, L_hi) dropped) fails a B window; the level check at t = 1/phi + phi^-12 fails somewhere (read in the direction it pushes: more failures than at 1/phi). FINDINGS (copied from the print). Controls held: (a) the seeds alone fail at 2 of 2 leaves, at c = 0 and e = 0 from (1/phi, Z0) and c' = -1 from (1/phi, Z1) alone; (b) at the 21 survivors >= 1/phi, A_inf and Z0 shifted lies in A_inf at 4086 of 4086, B_inf and Z1 in B_inf at 6275 of 6275, goldcopy's numbers; (c) L_lo widened to L fails a B window at 8 of 8 leaves, and t + phi^-12 fails 1147 of 1315 level checks; (d) the bisecting inside agrees with goldroot's at 348 of 348. KILL MISSED, Q1 held: "closure fails at 0 leaves of [1/phi, 1)", 8 leaves (4 open), splits at 3phi - 4, phi/2 and 4 - 2phi = 2/phi^2, 8 to 12 plays a leaf. Q4 held: the splits lie among the four named, 2/sqrt5 (the climb's) not met. Q2 held: without (1/phi, J), (-1, K'), (-1, L_hi) or (phi, M') closure fails at 8 of 8 leaves, without (1/phi, L_lo) at 3 of 6. Q3 held: 0 failures of 1315 level checks at the 21 survivors (every level to the fixed one) and 0 of 378 at the 12 off points, whose A_n is empty at n = 4 to 9 (L* = 5 to 10). So the six pairs close at every d in [1/phi, 1): v in A_n(d) and J gives v + 1/phi in A_n(d), and the other five likewise, at every n, by THE HAND CLOSURE above (a theorem), which this run checks and does not prove. Z0 lies in J, so the SHIFT holds on A_inf and B_inf at every d in [1/phi, 1), and with goldcopy's reduction the climb's copies of G_y's fixed sets close on themselves in G_(R y) at every y there. RUN RECORD. 14 of 14, 28.3 s, 93.9 MB (the two record pins added at the move to this folder; 12 of 12, 28.7 s, 94.0 MB before). The first run printed the controls (a) to (c), the KILL, Q2 and Q4 as above, then spent 600 s in Q3 on goldroot's quadratic inside and was stopped; the bisecting inside and control (d), which checks it against goldroot's, are additions after that run; no estimate was named before the first run, which ran past ten minutes unstopped. After a review: the plants (c) are caught by construction (L's top plus 1/phi passes U's; t + phi^-12 moves points off finite sets) and read only that the checker can refuse, (a) and (b) carrying the controls; THE HAND CLOSURE's (-1, L_hi) c' = 0 never plays (image [-1 - d, -d], below V's foot), its clause vacuous. Run: python goldshift.py """ import bisect from collections import Counter import os import sys import time os.environ.setdefault("OPENBLAS_NUM_THREADS", "1") HERE = os.path.dirname(os.path.abspath(__file__)) sys.path.insert(0, HERE) from goldsurv import (Cell, Pt, Split, zmul, zsub, zfloat, # noqa V0, U0, step) import goldren # noqa import goldroot as gr # noqa CHECKS = [] def check(name, ok, detail=""): CHECKS.append(bool(ok)) print(f" [{'PASS' if ok else 'FAIL'}] {name}" + (f" -- {detail}" if detail else "")) PHI = (0, 1) IPHI = (-1, 1) # 1/phi ZERO = (0, 0) V = V0[0] # [1/phi - d, (1 + d)/phi] U = U0[0] # [-2, phi d - 1] # intervals: ((alpha, beta), (alpha, beta)), each end alpha + beta d J = (((-1, 1), (-1, 0)), ((-1, 0), (0, 1))) # [1/phi - d, phi d - 1] KP = (((0, 1), (-1, 0)), ((-1, 1), (-1, 1))) # [phi - d, (1 + d)/phi] L = (((0, 1), (-1, -1)), ((-1, 0), (0, 1))) # [phi - phi^2 d, phi d - 1] LLO = (((0, 1), (-1, -1)), ((0, -1), (0, 1))) # [phi - phi^2 d, phi d - phi] LHI = (((0, -1), (0, 1)), ((-1, 0), (0, 1))) # [phi d - phi, phi d - 1] MP = (((-1, 0), (-1, 0)), ((-1, -1), (0, 1))) # [-1 - d, phi d - phi^2] Z0 = (((-1, 1), (-1, 0)), ((-2, 1), (-1, 1))) # [1/phi - d, d/phi - phi^-2] Z1 = (((-2, 0), (0, 0)), ((-3, 0), (0, 1))) # [-2, phi d - 3] SIX = {"A": [("(1/phi, J)", IPHI, J), ("(-1, K')", (-1, 0), KP)], "B": [("(1/phi, Z1)", IPHI, Z1), ("(1/phi, L_lo)", IPHI, LLO), ("(-1, L_hi)", (-1, 0), LHI), ("(phi, M')", PHI, MP)]} SEEDS = {"A": [("(1/phi, Z0)", IPHI, Z0)], "B": [("(1/phi, Z1)", IPHI, Z1)]} def family(base=SIX, drop=None, swap=None): fam = {} for side in "AB": ps = [(n, t, I) for n, t, I in base[side] if n != drop] if swap: ps = [(n, t, swap[1]) if n == swap[0] else (n, t, I) for n, t, I in ps] fam[side] = ps return fam def fmul(k, f): return (zmul(k, f[0]), zmul(k, f[1])) def fadd(f, g): return (tuple(a + b for a, b in zip(f[0], g[0])), tuple(a + b for a, b in zip(f[1], g[1]))) def const(t): return (t, ZERO) def phi_minus(c, I): """phi(c - I), c a linear function, I = (lo, hi).""" lo, hi = I return (fadd(fmul(PHI, c), fmul((0, -1), hi)), fadd(fmul(PHI, c), fmul((0, -1), lo))) def shift(I, t): return (fadd(I[0], const(t)), fadd(I[1], const(t))) DIGITS = {"c": (0, 1), "e": (0, 1), "c'": (-1, 0, 1)} def reply_ts(kind, t, d): """t' = phi(D - d - t) over the replying digits D.""" return [zmul(PHI, zsub((D - d, 0), t)) for D in DIGITS[kind]] def subset(cell, X, Y): return goldren.subset(cell, X, Y) def check_cell(cell, fam): """Failing (what, pair, digit) on this cell, and the plays read.""" win = {"A": V, "B": U} pairs = {s: [(n, t, cell.inter([win[s]], cell.norm([I]))) for n, t, I in fam[s]] for s in "AB"} pairs = {s: [(n, t, I) for n, t, I in pairs[s] if I] for s in "AB"} ident = {"A": ("id", ZERO, [V]), "B": ("id", ZERO, [U])} fails, plays = [], 0 for s in "AB": for n, t, I in pairs[s]: if not subset(cell, cell.norm([shift(iv, t) for iv in I]), [win[s]]): fails.append(("window", n, None)) moves = [(n, t, I, "c", c, "A") for n, t, I in pairs["A"] for c in (0, 1)] moves += [(n, t, I, "e", e, "B") for n, t, I in pairs["A"] for e in (0, 1)] moves += [(n, t, I, "c'", c, "A") for n, t, I in pairs["B"] for c in (-1, 0, 1)] for n, t, I, kind, d, tgt in moves: cfun = ((d, -1), (1, 0)) if kind == "c'" else const((d, 0)) img = cell.norm([phi_minus(cfun, iv) for iv in I]) img = cell.inter([win[tgt]], img) if not img: continue plays += 1 rs = reply_ts(kind, t, d) cover = [iv for _, x, Is in pairs[tgt] + [ident[tgt]] if x in rs for iv in Is] cover = cell.norm(cover) if not cover or not subset(cell, img, cover): fails.append((f"{kind} = {d}", n, None)) return fails, plays def survey(cuts, fam): stack = [(cuts[0], None)] + list(zip(cuts, cuts[1:])) leaves, roots = [], [] while stack: a, b = stack.pop() try: f, p = check_cell(Cell(a, b), fam) leaves.append((a, b, f, p)) except Split as sp: r = sp.r roots.append(r.exact()) stack += [(a, r), (r, None), (r, b)] return leaves, roots # ------------------------------------------------------------ Q3: levels def history(pt, lmax=40): """G_d's A_n, B_n at the point d = pt, n = 0 .. until empty, fixed or lmax, as exact interval lists of Q(phi).""" cell = Cell(pt, None) A, B = [V], [U] HA, HB = [A], [B] end = "alive" while len(HA) < lmax + 1: if not A: end = "empty" break A2, B2 = step(cell, A, B) if cell.same(A2, A) and cell.same(B2, B): end = "fixed" break A, B = A2, B2 HA.append(A) HB.append(B) d = gr.pt_q(pt) return [gr.ivs(S, d) for S in HA], [gr.ivs(S, d) for S in HB], end def inside(X, Y): """gr.inside on sorted disjoint Y: bisect on floats, decide exactly.""" lows = [gr.fl(c) for c, _ in Y] for a, b in X: i = bisect.bisect_right(lows, gr.fl(a) + 1e-9) if not any(gr.cmp(Y[k][0], a) <= 0 and gr.cmp(b, Y[k][1]) <= 0 for k in range(max(0, i - 3), min(len(Y), i + 1))): return False return True def level_fails(pt, HA, HB, fam, tweak=None): """(checks, failures) of (S_n and I) + t inside S_n over every level.""" d = gr.pt_q(pt) n_ck = n_bad = 0 first = None for side, H in (("A", HA), ("B", HB)): for name, t, I in fam[side]: tq = gr.q(*t) if tweak is not None: tq = gr.add(tq, tweak) Iq = gr.ivs([I], d) for n, S in enumerate(H): X = gr.inter(S, Iq) if not X: continue n_ck += 1 if not inside(gr.affine(X, gr.q(1), tq), S): n_bad += 1 if first is None: first = (side, name, n) return n_ck, n_bad, first OFF = [Pt((a, 0), (b, 0)) for a, b in ((5, 8), (7, 11), (13, 20), (2, 3), (9, 13), (16, 23), (3, 4), (11, 14), (5, 6), (13, 15), (9, 10), (19, 20))] def main(): t0 = time.time() INV, ONE = Pt(IPHI), Pt((1, 0)) print("== controls") lv, sp = survey([INV, ONE], family(SEEDS)) kinds = Counter((k, n) for x in lv for k, n, _ in x[2]) nfail = sum(bool(x[2]) for x in lv) print(f" (a) the seeds alone: {len(lv)} leaves, failing at {nfail}; " f"by digit and pair: {sorted(kinds.items())}") want = {("c = 0", "(1/phi, Z0)"), ("e = 0", "(1/phi, Z0)"), ("c' = -1", "(1/phi, Z1)")} check("(a) the seeds alone fail at every leaf, at c = 0 and e = 0 from " "Z0 and c' = -1 from Z1", nfail == len(lv) and set(kinds) == want) lv, sp = survey([INV, ONE], family(drop="(-1, L_hi)", swap=("(1/phi, L_lo)", L))) wins = sum(any(k == "window" for k, _, _ in x[2]) for x in lv) print(f" (c) plant, L_lo widened to L, (-1, L_hi) dropped: a window " f"fails at {wins} of {len(lv)} leaves") check("(c) the widened L_lo fails a B window", wins > 0) surv = [x for x in gr.SURV if gr.cmp(gr.pt_q(gr.spt(*x)), gr.IPHI) >= 0] print(f" Q3's points: {len(surv)} survivors >= 1/phi, {len(OFF)} off") runs = {} for x in surv: runs[x] = history(gr.spt(*x)) nz = okz = nzb = okzb = 0 for x in surv: HA, HB, end = runs[x] d = gr.pt_q(gr.spt(*x)) assert end == "fixed", (x, end) Aq, Bq = HA[-1], HB[-1] z0 = gr.ivs([Z0], d) z1 = gr.ivs([Z1], d) for v in gr.pts(gr.inter(Aq, z0)): nz += 1 okz += inside([(gr.add(v, gr.IPHI),) * 2], Aq) for u in gr.pts(gr.inter(Bq, z1)): nzb += 1 okzb += inside([(gr.add(u, gr.IPHI),) * 2], Bq) assert all(gr.points(runs[x][0][-1]) for x in surv) print(f" (b) A_inf and Z0 shifted into A_inf at {okz} of {nz}; B_inf " f"and Z1 into B_inf at {okzb} of {nzb}") check("(b) goldcopy's known answer: 4086 of 4086, 6275 of 6275", (okz, nz, okzb, nzb) == (4086, 4086, 6275, 6275)) pl_bad = pl_ck = 0 tw = gr.phipow(-12) for x in surv: HA, HB, _ = runs[x] c, b, _ = level_fails(gr.spt(*x), HA, HB, family(), tweak=tw) pl_ck, pl_bad = pl_ck + c, pl_bad + b print(f" (c) plant, t + phi^-12: {pl_bad} failures of {pl_ck} checks") check("(c) the tweaked translations fail somewhere", pl_bad > 0) agree = n_ag = 0 for x in sorted(surv, key=lambda z: len(runs[z][1][-1]))[:4]: HA, HB, _ = runs[x] d = gr.pt_q(gr.spt(*x)) for tw2 in (None, tw): for side, H in (("A", HA), ("B", HB)): for _, t, I in family()[side]: tq = gr.q(*t) if tw2 is None else gr.add(gr.q(*t), tw2) for S in H: X = gr.affine(gr.inter(S, gr.ivs([I], d)), gr.q(1), tq) n_ag += 1 agree += inside(X, S) == gr.inside(X, S) print(f" (d) the bisecting inside against goldroot's: {agree} of " f"{n_ag} agree, at the four smallest survivors, both arms") check("(d) the fast inside is goldroot's", agree == n_ag) ctrl = all(CHECKS) print(f" ({time.time() - t0:.1f} s)") print("== Q1, the KILL: the six on [1/phi, 1)") lv, sp = survey([INV, ONE], family()) bad = [x for x in lv if x[2]] plays = Counter(x[3] for x in lv) nopen = sum(x[1] is not None for x in lv) print(f" {len(lv)} leaves ({nopen} open), {len(sp)} splits at " f"{sorted(sp)} ((a, b, den): (a + b phi)/den); plays per leaf " f"{sorted(plays.items())}") for a, b, f, p in bad[:8]: print(f" {a!r}" + ("" if b is None else f" .. {b!r}") + f" ({float(a):.5f}): {f[:4]}") print(f"KILL: closure fails at {len(bad)} leaves of [1/phi, 1)") check("Q1 the six close on every leaf of [1/phi, 1)", not bad) check("the record: 8 leaves, 4 open, split at 2/phi^2, phi/2, 3phi - 4", len(lv) == 8 and nopen == 4 and set(sp) == {(0, 1, 2), (-4, 3, 1), (4, -2, 1)}) hand = {(0, 1, 2), (-4, 3, 1), (-2, 4, 5), (4, -2, 1)} print(f" Q4: splits {sorted(set(sp))} against 2/phi^2, phi/2, 3phi - 4," f" 2/sqrt5 = {sorted(hand)}; inside: {set(sp) <= hand}") print("== Q2, each pair but (1/phi, Z1) removed") for side in "AB": for name, _, _ in SIX[side]: if name == "(1/phi, Z1)": continue lv2, _ = survey([INV, ONE], family(drop=name)) nb = sum(bool(x[2]) for x in lv2) print(f" without {name}: closure fails at {nb} of {len(lv2)} " f"leaves") check(f"Q2 {name} is needed", nb > 0) print("== Q3, the levels") tot_ck = tot_bad = 0 firsts = [] for x in surv: HA, HB, _ = runs[x] c, b, f = level_fails(gr.spt(*x), HA, HB, family()) tot_ck, tot_bad = tot_ck + c, tot_bad + b if f: firsts.append((x, f)) ends = Counter() off_ck = off_bad = 0 for pt in OFF: HA, HB, end = history(pt) ends[(end, len(HA) - 1)] += 1 c, b, f = level_fails(pt, HA, HB, family()) off_ck, off_bad = off_ck + c, off_bad + b if f: firsts.append((pt, f)) print(f" survivors: {tot_bad} failures of {tot_ck} checks; off " f"points: {off_bad} of {off_ck}, their runs (end, last n) " f"{sorted(ends.items())}") for f in firsts[:6]: print(f" first failure {f}") check("Q3 every pair holds at every level, survivors and off points", tot_bad == 0 and off_bad == 0) check("the record: 1315 level checks at the survivors, 378 off", (tot_ck, off_ck) == (1315, 378)) if not ctrl: print("CONTROL FAILED: no verdict") print(f"\n{sum(CHECKS)} of {len(CHECKS)} checks, " f"{time.time() - t0:.1f} s") return 0 if all(CHECKS) else 1 if __name__ == "__main__": sys.exit(main())