"""shifted.py -- the shifted subtree bar: a lower bound on c_comp read L levels into the zero cylinder, with the reader's shift relaxed. QUESTION. At alpha = [0; 1 x (N + 1), 10^8, ...], s0 = 1, s the family's, c_lo = 1 and c_def = 2 at the gap m (defer.py). Is c_comp 2? DESIGN. At a pin level t (|T_(t+1)| < 1, read from above), lookahead c, j = t + c + 1, over the zero prefix d_0 .. d_(t+c) = 0 a completion reader's output star mx + M is P + tau, P = sum_(k<=t) e_k theta_k, tau in T_(t+1); y = M - P puts y + m I_j inside T_(t+1), and L - 1 levels down the subtree (the opponent's d_(j+i-1), greedy, then the reader's e_(t+i)) y + m X_i inside the committed window. The winning set W of y is a finite union of closed intervals, translation-covariant, so one set per level and flag: W_L = R; W_i(z) = cap_d cup_e [(G(t+i, r_d) cap W_(i+1)(d = 0)) - m d theta_K + e theta_(t+i)], K = j + i - 1; W = G(t, I_j) cap W_1(true), G(lv, r) = {g : g + m r in T_(lv+1)}. Three arms, each 1 + the largest c at which it fails at a pin level: PINNED y = 0 (valid at (0, 1) only), FREE y real, LATTICE y = M - P with the e_k in their caps (the windows below t dropped). Every T window is widened at both ends by Metric's above surplus, so a tie passes and a failure is a real one. PREDICTIONS (frozen before the engine). F1 FREE (L = 2) reads 1 at least at the three Q cells with m | Q. F2 FREE up to L = 12 still 1 there. F3 LATTICE up to L = 12 reads 2 at all four Q cells. F4 FREE <= LATTICE <= c_saf at the grid's 120 E > 0 cells and the Q cells; c_lo <= FREE. Controls: C1 PINNED = c_lo2 (L = 2), c_level (L = 3 .. 6) at the 24 (0, 1) cells; C2 LATTICE = PINNED there; C3 FREE (L = 2) = c_lo at golden; C4 a plant, LATTICE with e_t forced 0. KILL: at H = 10^8, N = 2 .. 7, the gap m, the best arm passing the Q control prints 1. No arm passing: no 10^8 read. Section S, frozen after T with the proof below: R1 W_1(true) at L = 3 empty at every cell with m >= s + 2; R2 nonempty at m <= s + 1 (the converse, read only to s = 6 before); R3 defer.py's c_def = 2 at every family m = 2^e >= s + 2. KILL: R1 or R3 off at any cell. THE TAIL LAW (proved). At a pin level t with every quotient from a_(t+3) on equal to Q, c = 1, s + 2 <= m <= Q, W_1(true) at L = 3 is empty, at every s0. Write u_i = |theta_(t+1+i)|: u_0 = Q u_1 + u_2, u_1 = Q u_2 + u_3, u_2 = Q u_3 + u_4, u_3 > Q u_4; b = 1 + s/Q; up to sign T_(t+3) = [-b u_2, b u_1]. A surviving y has, for each d <= Q, a digit e_d, and for each d' <= Q - 1 (d' = Q too at d = 0) some e' <= Q + s with P = y - e_d u_0 - m d u_1 + m d' u_2 + e' u_1 in S_1 = [(m - b)u_2 - m u_3, b u_1 - m u_3] (above (m - b)u_2 at d' = 0). Z_d = y - e_d u_0 - m d u_1 then lies in an interval of length b(u_1 + u_2) + (Q + s - m)u_1, so e_d - e_(d+1) <= 1, and e_0 - e_Q >= m; so mod u_1 the points y + n u_2 lie in S_1 for mQ + 1 consecutive n. Their largest gap is u_2 - (m - 1)u_3 (laps of Q steps, each u_3 lower), below the arc outside S_1, lam = (m - 1)u_2 - s(u_1 + u_2)/Q, by at least u_3 - s(u_3 + u_4)/Q > 0: a contradiction. The family's quotients are 10^8 from a_(N+2), so c_comp >= 2 there at every m from s + 2 to 10^8. FINDINGS (copied from the print). Controls held: C1 and C2 0 of 120 off, C3 0 of 20 (its answer by hand: at golden mI_j splits in two pieces and T_(t+1)'s first and last members reach its two ends, so the two-level free bar is c_lo). C4 is missed by construction: PINNED reads 2 at L = 3 and 12 at the four Q cells (c up to 4 read), so y = 0, every e_k 0 and e_t among them, passes at c = 2 .. 4, and forcing e_t = 0 removes no point the bar needs; it reads nothing. F1/F2 failed: FREE reads 1 at L <= 2 and 2 from L = 3 at all four Q cells, m | Q or not; the free shift is not too lax three levels down, and the seam transplant (m | Q lines cuts up with seams) plays no part. At c = 1 FREE is empty at all 12 pin levels read (L = 3 and 4) at each. F3 held: LATTICE reads 2 at all four (from L = 2 at Q 4 x3, L = 3 elsewhere), at every L to 12. F4 held at the grid's 120 E > 0 cells: c_lo <= FREE <= LATTICE <= c_saf. LATTICE is above c_lo at 63 and above FREE at 5 (golden x3, sqrt(3) - 1 x4, [2, 1, 3, 1] x3 at (0, 1); sqrt(3) - 1 x5, [1, 1, 1, 2] x5 at (3, 3)). T (added after the Q read): at the constant quotient [0; Q, Q, ...], Q in 4 .. 9, 11, 16, 17, 24, s in 0 .. 4, 6, m from 2 to min(Q - 1, 2s + 4) with c_lo = 1, two pin levels t >= 4: FREE fails at c = 1 (L = 3 or 4) iff m >= s + 2, at all 336 cells (386 with Q = 32 under --wide), whether or not m divides Q. At all 194 failing cells (228) W_1(true) at L = 3 is empty with no root: levels t + 1 and t + 2 alone leave no shift. At all 142 passing cells (158) W_1(true) equals W: the root never binds. The family's (N, s, gap m) are (2, 1, 4), (3, 3, 16), (4, 6, 64), (5, 11, 256), (6, 19, 512), (7, 32, 2048), m >= s + 2 at each. S: the control read section T's Q 16 s 3 row (empty iff m >= 5). At s = 11, Q = 27 and s = 19, Q = 43 (and s = 32, Q = 69 under --wide), m = s - 1, s, s + 1, s + 2, s + 3, Q - 1, Q: R1 and R2 held, W_1 empty iff m >= s + 2; at m <= s + 1 lam <= 0, the proof silent; the largest gap over lam is 0.963, 0.977 (and 0.986) at m = s + 2, 0.329 to 0.332 at s + 3, at most 0.006 at Q - 1 and Q. R3 held: c_def = 2 at every family m = 2^e >= s + 2, N = 2 .. 7. So c_comp = 2 at the 10^8 family at each such m, the gap m among them; the KILL's direct read at 10^8 is not made, the proof standing for it. RUN RECORD. The bare run: 16 of 16, 103.2 s, peak 262.0 MB under a 512 MB watch, F1/F2 checked as the failed prediction it is; --wide reads section T with Q = 32 and section S with s = 32: 8 of 8, 114.2 s, peak 687.4 MB under a 2048 MB watch. Changes to what was frozen: the first run read C1 and C2 on Metric's truncated windows, and PINNED stood one above c_level at 5 of 120 (golden x2 L5, L6, sqrt(3) - 1 x3 L5, [1, 1, 1, 2] x2 L5, L6), the truncated T lying inside the exact hull so that an exact tie failed; they now read the windows from above, as every arm does. Section T and the family's print were added after the first run; the PINNED and per-pin prints at the Q cells and the W_1 count after a second reading. The root flag first shadowed its own name (W returned the rooted set whatever the flag); the control at L = 1 fails at 386 of 386 on that code, and a first control (W_1 wider than W at some passing cell) could not fire, the root never binding. Section S froze m <= Q - 1; m = Q was added once the proof was re-derived there (m u_3 < u_2 and Q - s - b > 0 hold at s <= Q - 2), and its Metric reads to 40 levels, not the frozen 30. Run: python shifted.py [--wide] """ import os import sys import time os.environ.setdefault("OPENBLAS_NUM_THREADS", "1") from flush import (Game, Metric, PERIODIC, SLACKS, Source, # noqa: E402 c_floor, c_level, c_lo2, c_overlap, numeration, pin_levels) from defer import c_def, family # noqa: E402 CHECKS = [] def check(name, ok, detail=""): CHECKS.append(bool(ok)) print(f" [{'ok ' if ok else 'FAIL'}] {name}" + (f" -- {detail}" if detail else "")) # ------------------------------------------------------------ intervals def _norm(xs): xs = sorted(xs) out = [] for a, b in xs: if a > b: continue if out and a <= out[-1][1]: if b > out[-1][1]: out[-1] = (out[-1][0], b) else: out.append((a, b)) return out def _inter(U, V): """U cap V; None is the whole line.""" if U is None: return V if V is None: return U out, i, k = [], 0, 0 while i < len(U) and k < len(V): a, b = max(U[i][0], V[k][0]), min(U[i][1], V[k][1]) if a <= b: out.append((a, b)) if U[i][1] < V[k][1]: i += 1 else: k += 1 return out def _shift(U, v): return [(a + v, b + v) for a, b in U] def _hull(x, y): return (min(x, y), max(x, y)) # ------------------------------------------------------------ the bar class Bar: """The subtree's winning sets at one cell (met, m) and lookahead c.""" def __init__(self, met, m, above=True): self.met, self.m, self.above = met, m, above self.slack = {} def window(self, lv): """T_(lv+1), widened by the above surplus unless above is off.""" lo, hi = self.met.T(lv + 1) if not self.above: return lo, hi if lv not in self.slack: self.slack[lv] = (self.met.Tlen(lv + 1, True) - self.met.Tlen(lv + 1)) d = self.slack[lv] return lo - d, hi + d def G(self, lv, r): lo, hi = self.window(lv) a, b = lo - self.m * r[0], hi - self.m * r[1] return [(a, b)] if a <= b else [] def W(self, t, c, L, root=True): """The winning set of y at pin level t, read L levels; without root, W_1(true) alone (levels t + 1 .. t + L - 1).""" th, m = self.met.theta, self.m j = t + c + 1 memo = {} def win(i, pz): if i == L: return None if (i, pz) in memo: return memo[(i, pz)] K, lv = j + i - 1, t + i top = self.met.a[K + 1] if pz else self.met.a[K + 1] - 1 acc = None for d in range(top + 1): r = _hull(-th(K + 1), -th(K)) if d == 0 else \ _hull(-th(K + 1), -th(K) - th(K + 1)) core = _inter(self.G(lv, r), win(i + 1, d == 0)) core = _shift(core, -m * d * th(K)) ways = _norm([iv for e in range(self.met.cap(lv) + 1) for iv in _shift(core, e * th(lv))]) acc = ways if acc is None else _inter(acc, ways) if not acc: break memo[(i, pz)] = acc return acc if not root: return win(1, True) top = self.G(t, _hull(-th(j), -th(j - 1))) return top if L == 1 else _inter(top, win(1, True)) def lattice_hit(met, t, W, plant=False): """Some y = M - sum_(k<=t) e_k theta_k in W, the e_k within their caps (with plant, e_t forced 0)? Breadth-first over k, pruned.""" if not W: return False Q, th = met.Q, met.theta lo, hi = W[0][0], W[-1][1] caps = [met.cap(k) for k in range(t + 1)] if plant: caps[t] = 0 # rest[k] = the range of sum_(k'>=k, <= t) e theta rest = [(0, 0)] * (t + 2) for k in range(t, -1, -1): v = caps[k] * th(k) rl, rh = rest[k + 1] rest[k] = (rl + min(0, v), rh + max(0, v)) # M Q - P - rest in [lo, hi]: P = 0 at the start rl, rh = rest[0] Ms = range(-((-(lo + rl)) // Q), (hi + rh) // Q + 1) for M in Ms: S = {0} for k in range(t + 1): rl, rh = rest[k + 1] nxt = set() for P in S: # e th(k) in [M Q - P - rh - hi, M Q - P - rl - lo] a, b = M * Q - P - rh - hi, M * Q - P - rl - lo x = th(k) if x > 0: e0, e1 = -((-a) // x), b // x else: e0, e1 = -((-b) // x), a // x for e in range(max(e0, 0), min(e1, caps[k]) + 1): nxt.add(P + e * x) S = nxt if not S: break for P in S: y = M * Q - P if any(a <= y <= b for a, b in W): return True return False def arm_bar(met, m, ts, L, arm, cmax, above=True, plant=False): """1 + the largest c <= cmax at which the arm fails at some t in ts, 0 if none fails; and whether it passes at cmax.""" bar = Bar(met, m, above) fails = [] for c in range(cmax + 1): bad = False for t in ts: W = bar.W(t, c, L) if arm == "free": ok = bool(W) elif arm == "pinned": ok = any(a <= 0 <= b for a, b in W) else: ok = lattice_hit(met, t, W, plant) if not ok: bad = True break fails.append(bad) return 1 + max([c for c in range(cmax + 1) if fails[c]], default=-1), \ not fails[-1] def pin_ts(met, depth): return [t for t in range(depth) if met.Tlen(t + 1, True) < met.Q] # ------------------------------------------------------------ sections def section_controls(): print("== C1 C2 C3 the controls") c1 = c2 = c3 = 0 n1 = n3 = 0 rows = [] for name, per in PERIODIC: w = numeration(name, per) met = Metric(w, 0, 1, 120) ts = pin_levels(met, 40) for m in range(2, 6): lo2 = c_lo2(met, m, depth=40) for L in range(2, 7): want = lo2 if L == 2 else c_level(met, m, L, ts, 12)[0] pin, _ = arm_bar(met, m, ts, L, "pinned", 11) lat, _ = arm_bar(met, m, ts, L, "lattice", 11) n1 += 1 c1 += pin != want c2 += lat != pin if L in (2, 6): rows.append(f"{name.split()[0]} x{m} L{L} " f"{want}/{pin}/{lat}") print(" c_lo2 or c_level / PINNED / LATTICE: " + "; ".join(rows)) check("C1 PINNED = c_lo2 (L = 2) and c_level (L = 3 .. 6) at the 24 " "(0, 1) cells", c1 == 0, f"{c1} of {n1} off") check("C2 LATTICE = PINNED there", c2 == 0, f"{c2} of {n1} off") w = numeration("golden [1]", (1,)) for m in range(2, 6): for s, s0 in SLACKS[1:]: met = Metric(w, s, s0, 120) ts = pin_ts(met, 40) lo = c_floor(met, m, 40) fr, _ = arm_bar(met, m, ts, 2, "free", 12) n3 += 1 c3 += fr != lo check("C3 FREE (L = 2) = c_lo at golden, m = 2 .. 5, every E > 0 " "slack", c3 == 0, f"{c3} of {n3} off") def c_saf_ge(src, m, s, s0, b): """c_saf >= b: the game loses at b - 1 (b = 0 is vacuous).""" return b == 0 or not Game(src, m, s, s0, b - 1).solve(False) def section_grid(Ls=(2, 4, 8)): print("== F4 the grid's 120 E > 0 cells: c_lo <= FREE <= LATTICE <= " "c_saf") t0 = time.time() bad_lo = bad_order = bad_saf = cells = 0 lifted = [] for name, per in PERIODIC: w = numeration(name, per) src = Source(period=per) for m in (2, 3, 4, 5): for s, s0 in SLACKS[1:]: met = Metric(w, s, s0, 120) ts = pin_ts(met, 30) lo = c_floor(met, m, 60) cells += 1 fr = max(arm_bar(met, m, ts, L, "free", 8)[0] for L in Ls) la = max(arm_bar(met, m, ts, L, "lattice", 8)[0] for L in Ls) bad_lo += fr < lo bad_order += fr > la bad_saf += not c_saf_ge(src, m, s, s0, la) if la > lo: lifted.append(f"{name.split()[0]} x{m} ({s}, {s0}) " f"{lo}/{fr}/{la}") print(f" {cells} cells, {time.time() - t0:.0f} s; LATTICE above c_lo " f"at {len(lifted)} (c_lo/FREE/LATTICE): " + "; ".join(lifted)) check("F4 c_lo <= FREE", bad_lo == 0, f"{bad_lo} below") check("F4 FREE <= LATTICE", bad_order == 0, f"{bad_order} above") check("F4 LATTICE <= c_saf (the game loses one below it)", bad_saf == 0, f"{bad_saf} above") QCELLS = [(2, 4, 3), (2, 8, 4), (3, 8, 8), (2, 16, 4)] def section_q(Ls=(1, 2, 3, 4, 6, 8, 12)): print("== F1 F2 F3 the Q cells, c_saf = 2 (defer.py)") best = {"free": [], "lattice": []} for N, Q, m in QCELLS: w, s = family(N, Q) met = Metric(w, s, 1, N + 60) ts = pin_ts(met, N + 12) lo = c_floor(met, m, N + 50) row = [] for arm in ("free", "lattice"): bars = [arm_bar(met, m, ts, L, arm, 4)[0] for L in Ls] best[arm].append(max(bars)) row.append(f"{arm} " + " ".join(f"L{L}:{b}" for L, b in zip(Ls, bars))) plant = arm_bar(met, m, ts, max(Ls), "lattice", 4, plant=True)[0] pinned = [arm_bar(met, m, ts, L, "pinned", 4)[0] for L in (3, max(Ls))] bar = Bar(met, m) dead = {L: sum(not bar.W(t, 1, L) for t in ts) for L in (3, 4)} print(f" N {N} Q {Q} x{m} s {s} c_lo {lo}, pins t = {ts[0]}.." f"{ts[-1]}: " + "; ".join(row) + f"; plant {plant}; PINNED " f"L3, L{max(Ls)} {pinned}; FREE at c = 1 empty at {dead[3]} " f"(L3) and {dead[4]} (L4) of {len(ts)} pins") check("F1/F2 failed: FREE reads 2, not 1, at all four Q cells, m | Q " "or not", best["free"] == [2] * 4, f"{best['free']}") check("F3 LATTICE reads 2 at all four Q cells", best["lattice"] == [2] * 4, f"{best['lattice']}") return best TAIL_QS = (4, 5, 6, 7, 8, 9, 11, 16, 17, 24) def section_tail(Qs=TAIL_QS): print("== T the constant quotient [0; Q, Q, ...], c_lo = 1: FREE fails " "at c = 1 (L = 3 or 4) beside m >= s + 2") t0 = time.time() off = n = nf = w1 = wider = flag_off = 0 for Q in Qs: w = numeration(f"[{Q}]", (Q,)) for s in (0, 1, 2, 3, 4, 6): met = Metric(w, s, 1, 60) ts = [t for t in pin_ts(met, 12) if t >= 4][:2] bar = Bar(met, 2) row = [] for m in range(2, min(Q - 1, 2 * s + 4) + 1): if c_floor(met, m, 30) != 1: continue bar.m = m f = any(not bar.W(t, 1, L) for L in (3, 4) for t in ts) n += 1 off += f != (m >= s + 2) if f: nf += 1 w1 += all(not bar.W(t, 1, 3, root=False) for t in ts) else: wider += any(bar.W(t, 1, 3, root=False) != bar.W(t, 1, 3) for t in ts) # the flag's control: at L = 1 no root is the whole line flag_off += any(bar.W(t, 1, 1, root=False) is not None for t in ts) row.append(f"{m}{'x' if f else '.'}") print(f" Q {Q:2d} s {s}: " + " ".join(row)) print(f" {n} cells, {time.time() - t0:.0f} s (x: FREE fails at c = " f"1); W_1(true) at L = 3, no root, empty at both pins at {w1} " f"of the {nf} failing; it differs from W at {wider} of the " f"{n - nf} passing") check("control: the root flag, W at L = 1 with no root the whole line", flag_off == 0, f"{flag_off} of {n} off") check("the tail: FREE fails at c = 1 iff m >= s + 2 at every cell read", off == 0, f"{off} of {n} off") rows = [] for N in range(2, 8): w, s = family(N) met = Metric(w, s, 1, N + 50) gaps = [(c_overlap(met, 2 ** e, N + 40, 40) - c_floor(met, 2 ** e, N + 40), 2 ** e) for e in range(1, 13)] g = max(gaps)[0] m = next(mm for gg, mm in gaps if gg == g) rows.append((N, s, m)) print(" the 10^8 family (N, s, the gap m): " + "; ".join( f"({N}, {s}, {m})" for N, s, m in rows)) check("the 10^8 family's gap m is >= s + 2 at N = 2 .. 7", all(m >= s + 2 for _, s, m in rows)) def _gap_lam(met, Q, s, m, t): """(the largest gap of the mQ + 1 points n u_(t+3) mod u_(t+2), and lam, the arc outside S_1), both times Q, exact.""" u1, u2 = abs(met.theta(t + 2)), abs(met.theta(t + 3)) pts = sorted((n * u2) % u1 for n in range(m * Q + 1)) gap = max([b - a for a, b in zip(pts, pts[1:])] + [pts[0] + u1 - pts[-1]]) return gap * Q, Q * u1 - (Q + s) * (u1 + u2) + m * Q * u2 S_CELLS = ((11, 27), (19, 43)) def section_s(cells=S_CELLS): print("== S the family's own s at [0; Q, Q, ...]: W_1(true) at c = 1, " "L = 3, no root, empty iff m >= s + 2?") t0 = time.time() def one(Q, s): met = Metric(numeration(f"[{Q}]", (Q,)), s, 1, 40) return met, [t for t in pin_ts(met, 12) if t >= 4][0] met, t = one(16, 3) got = [not Bar(met, m).W(t, 1, 3, root=False) for m in range(2, 11)] print(" control Q 16 s 3 (section T's print: empty iff m >= 5): " + " ".join(f"{m}{'x' if g else '.'}" for m, g in zip(range(2, 11), got))) check("control: the filter reads section T's Q 16 s 3 row", got == [m >= 5 for m in range(2, 11)]) r1 = r2 = inst = n = 0 for s, Q in cells: met, t = one(Q, s) row = [] for m in (s - 1, s, s + 1, s + 2, s + 3, Q - 1, Q): if c_floor(met, m, 30) != 1: row.append(f"{m}(c_lo {c_floor(met, m, 30)}, skipped)") continue t1 = time.time() empty = not Bar(met, m).W(t, 1, 3, root=False) gQ, lQ = _gap_lam(met, Q, s, m, t) n += 1 r1 += m >= s + 2 and not empty r2 += m <= s + 1 and empty inst += m >= s + 2 and not gQ < lQ row.append(f"{m}{'x' if empty else '.'}" f"[gap/lam {gQ / lQ:.3f}]" if lQ > 0 else f"{m}{'x' if empty else '.'}[lam <= 0]") row[-1] += f" {time.time() - t1:.0f}s" print(f" Q {Q} s {s} t {t}: " + "; ".join(row)) print(f" {n} cells, {time.time() - t0:.0f} s (x: W_1 empty)") check("R1 W_1 empty at every cell with m >= s + 2", r1 == 0, f"{r1} off") check("R2 W_1 nonempty at every cell with m <= s + 1 (the converse)", r2 == 0, f"{r2} off") check("instrument: the largest gap below lam at every m >= s + 2", inst == 0, f"{inst} off") r3, rows = 0, [] for N in range(2, 8): w, s = family(N) met = Metric(w, s, 1, N + 50) cds = [(2 ** e, c_def(met, 2 ** e, N + 40)[0]) for e in range(1, 13) if 2 ** e >= s + 2] r3 += sum(cd != 2 for _, cd in cds) rows.append(f"N {N} s {s}: " + " ".join(str(cd) for _, cd in cds) + f" (m = {cds[0][0]} .. 4096)") print(" c_def at the family's m = 2^e >= s + 2: " + "; ".join(rows)) check("R3 c_def = 2 at every family m >= s + 2", r3 == 0, f"{r3} off") def main(): t0 = time.time() if "--wide" in sys.argv: section_tail(TAIL_QS + (32,)) section_s(S_CELLS + ((32, 69),)) else: section_controls() section_q() section_tail() section_s() section_grid() print(f"\n{sum(CHECKS)} of {len(CHECKS)} checks passed " f"({time.time() - t0:.1f} s)") sys.exit(0 if all(CHECKS) else 1) if __name__ == "__main__": main()