# trunc.py - JOB #642. # Re-implement the served producer's PART 4 rule (prod159.js, tctRHS) on MY OWN build of # the T_23 gap word, and report the certificate as a function of the truncation Lmax. # The producer's rule, verbatim from its source: # rhs[b] = (q-2)*#gaps with gap = 6b + 2 * sum_{L>=1} #{i : sum of g_i..g_{i+L} = 6b, # interiors g_{i+1}..g_{i+L-1} qualify} # certificate = largest theta=6b with rhs(theta) >= 1 ("G2(new) < min{theta: rhs < 1}") # qualifies(g,q): g%q in {0,2,q-2}. L=1 has NO interior condition in the source. import numpy as np from math import gcd Q = 29 g = np.load('t23-gaps.npy').astype(np.int64) D = g.size W23 = 223092870 print('my T_23 gap word: D = %d (record W(23) = %d)' % (D, W23)) print('max gap = %d ; all multiples of 6: %s' % (g.max(), bool(np.all(g % 6 == 0)))) qc = ((g % Q) == 0) | ((g % Q) == 2) | ((g % Q) == Q - 2) print('qualifying gaps: %d of %d = %.6f' % (qc.sum(), D, qc.sum() / D)) NB = 4200 mine = np.zeros((9, NB), dtype=np.int64) roll = [np.roll(g, -k) for k in range(9)] qcr = [np.roll(qc, -k) for k in range(9)] for L in range(1, 9): s = roll[0].copy() ok = np.ones(D, dtype=bool) for j in range(1, L + 1): if j >= 2: # the source's "L >= 2" test: interior g_{i+j-1} ok &= qcr[j - 1] s = s + roll[j] b = s // 6 m = ok & (b < NB) mine[L] += 2 * np.bincount(b[m], minlength=NB)[:NB] mine[0] = (Q - 2) * np.bincount((g // 6)[(g // 6) < NB], minlength=NB)[:NB] # suffix sums: rhs(theta) = sum over windows with sum >= theta cum = np.cumsum(mine[:, ::-1], axis=1)[:, ::-1] def cert(Lmax): rhs = cum[0] + cum[1:Lmax + 1].sum(axis=0) idx = np.nonzero(rhs >= 1)[0] return int(idx[-1] * 6) if idx.size else 0 print() print(' truncation Lmax certificate (producer prints 270 for Lmax = 8)') for Lmax in [8, 6, 4, 3, 2, 1, 0]: print(' %2d %4d' % (Lmax, cert(Lmax))) print() print(' L loose windows theta-mass sum_theta Q_L max window sum') thetamass = {} for L in range(1, 9): s = roll[0].copy() ok = np.ones(D, dtype=bool) for j in range(1, L + 1): if j >= 2: ok &= qcr[j - 1] s = s + roll[j] thetamass[L] = int((s[ok] // 6).sum()) b = int(mine[L].nonzero()[0].max()) if mine[L].any() else 0 print(' %2d %12d %15d %12d' % (L, int(mine[L].sum() / 2), thetamass[L], b * 6)) print(' sum_theta over L <= 8 (the producer\'s LMAX): %d' % sum(thetamass.values())) # legality census of the Q_3 windows (2 interior gaps) under the producer's own # Alternation rule: qclass(g) in {0,+1,-1}, legal pair = not (+1,+1) and not (-1,-1). cls = np.where(g % Q == 0, 0, np.where(g % Q == 2, 1, np.where(g % Q == Q - 2, -1, 2))) L = 3 s = roll[0].copy() ok = np.ones(D, dtype=bool) for j in range(1, L + 1): if j >= 2: ok &= qcr[j - 1] s = s + roll[j] b = s // 6 sel = ok & (b < NB) & (s >= 6) idx = np.nonzero(sel)[0] c1 = cls[(idx + 1) % D] c2 = cls[(idx + 2) % D] legal = ~(((c1 == 1) & (c2 == 1)) | ((c1 == -1) & (c2 == -1))) print() print('Q_3 windows at T_23: %d ; class pairs (c1,c2):' % idx.size) from collections import Counter print(' ', Counter(zip(c1.tolist(), c2.tolist()))) print(' run-legal by the producer\'s Alternation rule: %d of %d (its part 0.3 prints 0 of 288)' % (int(legal.sum()), idx.size)) if legal.any(): print(' max window sum among the legal ones: %d' % int((s[idx][legal]).max())) g29 = np.load('t29-gaps.npy', mmap_mode='r') print() print('my T_29 gap word: D = %d , max gap = %d (producer PART 4 "true G2(new)" = 258)' % (g29.size, int(np.max(g29))))