"""Job #4587 (first look, route 7 rev 5): the step's census on a PRE-REGISTERED SAMPLE of #1840's supports, with #1844's anchor975.py functions imported unchanged (lp, strict_cert, branch; slots from return #370's route4-weighted.py via anchor975's own import). QUESTION (step): where does the one-anchor (depth-1) frontier n1 fall below the weighted frontier n* of #1840's census959w.out? DEFINITION. At support a and prefix n (the first n slots s >= a with gcd(s(s+2), 97#) = 1), an anchor q0 in Q = 101..193 CLOSES if every one of its q0 phase branches is STRICT (exact LP value v_b < 1 AND anchor975's integer recheck strict_cert succeeds; an UNCHECKED branch counts as not strict). n1 = the least n at which some anchor closes. v_b is non-increasing in n (more slots, smaller max fractional coverage), so closing at n implies closing at n+1, and n1 is found by scanning n downward from n* - 1 until no anchor closes; n1 = n* if none closes at n* - 1. PRE-REGISTERED. G1: at a = 9409, n* = 53 and n1 = 51 with anchor 109 the first closing anchor at 51, and none at 50 (#1844 frontier975.out). SAMPLE: supports k = 0..39 of a = 9409 + 6007k (the first forty rows of census959w.out, in file order); n* read from that file. DECISION (the step's own clauses): success-direction if n1 < n* on more than half of the sample; failure-direction if n1 = n* on more than half. The sample is 40 of 200 supports (default run). `python census4587.py all` runs the full census (added after the sample, when the sample's cost showed the whole census fits the budget); its first forty rows must equal the sample's. Stdout: one row per support and a summary; timing on stderr; deterministic.""" import os, sys, re, time, json from multiprocessing import Pool from collections import Counter HERE = os.path.dirname(os.path.abspath(__file__)) sys.path.insert(0, HERE) import anchor975 as A9 # imports r370-route4-weighted.py as rw; main() is guarded rw = A9.rw QS0 = A9.QS0; OLD = A9.OLD def closing_anchor(D): """first q0 (ascending) all of whose phases are STRICT with an integer certificate; also count LPs""" nlp = 0 for q0 in QS0: ok = True for b in range(q0): R, v, (verdict, c) = A9.branch(D, q0, b); nlp += 1 if verdict != 'STRICT': ok = False; break if ok: return q0, nlp return None, nlp def support(args): a, nstar = args; t0 = time.time(); rows = []; nlp = 0; n = nstar - 1; n1 = nstar; anch = None while n >= 1: D = rw.slots_from(a, n, OLD) q0, k = closing_anchor(D); nlp += k rows.append((n, q0)) if q0 is None: break n1, anch = n, q0; n -= 1 return {'a': a, 'nstar': nstar, 'n1': n1, 'gain': nstar - n1, 'anchor_at_n1': anch, 'scan': rows, 'lps': nlp, 'secs': round(time.time() - t0, 1)} if __name__ == '__main__': sys.stdout.reconfigure(newline='\n') txt = open(os.path.join(HERE, 'r1840-census959w.out'), encoding='utf-8').read().splitlines() sup = [(int(m.group(1)), int(m.group(2))) for m in (re.match(r'^(\d+)\s+(\d+)\s', l) for l in txt) if m] assert len(sup) == 200 and sup[0] == (9409, 53) sample = sup[:40] if (len(sys.argv) < 2 or sys.argv[1] != 'all') else sup t0 = time.time() with Pool(8) as pool: res = pool.map(support, sample, chunksize=1) led = [] g = res[0] ok_g1 = g['a'] == 9409 and g['nstar'] == 53 and g['n1'] == 51 and g['anchor_at_n1'] == 109 and g['scan'][-1] == (50, None) led.append(f"{'PASS' if ok_g1 else 'FAIL'} G1_reproduces_1844_frontier_at_9409 :: n* = {g['nstar']}, n1 = {g['n1']}, closing anchor at n1 = {g['anchor_at_n1']}, scan {g['scan']} (#1844: 109 at 51, none at 50)") print('a\tn*\tn1\tn*-n1\tanchor@n1\tLPs') for r in res: print(f"{r['a']}\t{r['nstar']}\t{r['n1']}\t{r['gain']}\t{r['anchor_at_n1']}\t{r['lps']}") gains = Counter(r['gain'] for r in res); anchors = Counter(r['anchor_at_n1'] for r in res if r['anchor_at_n1']) pos = sum(1 for r in res if r['gain'] > 0); zero = sum(1 for r in res if r['gain'] == 0) led.append(f"INFO gain n*-n1 distribution over {len(res)} supports: {dict(sorted(gains.items()))}; n1 < n* on {pos}, n1 = n* on {zero}; closing anchors at n1: {dict(anchors.most_common())}; total LPs {sum(r['lps'] for r in res)}") verdict = 'success-direction (one-anchor gain on most sampled supports)' if pos > len(res) / 2 else ('failure-direction (no gain on most sampled supports)' if zero > len(res) / 2 else 'split') led.append(f"INFO DECISION on the pre-registered sample: {verdict}") print('\n'.join(led)) json.dump(res, open(os.path.join(HERE, 'census4587' + ('-all' if len(res) == 200 else '') + '.json'), 'w'), indent=1) print(f'elapsed {time.time() - t0:.0f} s; per-support secs {[r["secs"] for r in res]}', file=sys.stderr)