#!/usr/bin/env python3 """Job 2085 (route 91): exact N_k curves at the two priced chain cells, 19#->43# and 23#->43#. Runs #1799's kdfs.c (sha256 7a16820b...0bc9d, /files/) in count mode for every k from 1 to K*+1 at both cells, then checks: (a) the F1 closed form N_1 = D*(NCOPY - prod_q (q-2)) at each cell (route 91's anchor); (b) N_k non-increasing in k (the first k-1 slots of a killed k-window form a killed (k-1)-window); (c) the certificate cells against the record (#1144: N_20=4, N_21=0 at 19#->43#; #1799: N_16=12, N_17=0 at 23#->43#); (d) #1113's sampled census at 23#->43# (sample-2065.out.json, sha 6c85923f...) against the exact N_k: z = (N_hat - N_k) / SE, with SE the binomial standard error at the exact p = N_k / W. Rows are appended to curve2085.rows.jsonl as each cell finishes; stdout is canonical JSON (no timings), stderr carries timings. Stdlib only. Usage: cc -O2 -o kdfs kdfs.c && python3 curve2085.py [threads] """ import json, math, subprocess, sys from concurrent.futures import ThreadPoolExecutor CELLS = {"19#->43#": (19, 43, 21), "23#->43#": (23, 43, 17)} RECORD = {("19#->43#", 20): 4, ("19#->43#", 21): 0, ("23#->43#", 16): 12, ("23#->43#", 17): 0} def primorial(n): r = 1 for p in range(2, n + 1): if all(p % d for d in range(2, p)): r *= p return r def primes_between(a, b): return [p for p in range(a + 1, b + 1) if all(p % d for d in range(2, p))] def run(job): step, k = job P, PP, _ = CELLS[step] out = subprocess.run(["./kdfs", str(P), str(PP), "count", str(k)], capture_output=True, text=True, check=True).stdout d = json.loads(out.strip().splitlines()[0]) print(f"{step} k={k} N_k={d['N_k']} ({d['seconds']} s)", file=sys.stderr, flush=True) row = {"step": step, "k": k, "N_k": d["N_k"], "D": d["D"], "Q": d["Q"]} with open("curve2085.rows.jsonl", "a") as f: f.write(json.dumps(row, sort_keys=True) + "\n") return row threads = int(sys.argv[1]) if len(sys.argv) > 1 else 4 jobs = [(s, k) for s, (_, _, kmax) in CELLS.items() for k in range(kmax, 0, -1)] with ThreadPoolExecutor(threads) as ex: rows = list(ex.map(run, jobs)) res, ok = {}, True for step, (P, PP, kmax) in CELLS.items(): curve = {r["k"]: r["N_k"] for r in rows if r["step"] == step} D = next(r["D"] for r in rows if r["step"] == step) Q = primes_between(P, PP) ncopy = primorial(PP) // primorial(P) anchor = D * (ncopy - math.prod(q - 2 for q in Q)) mono = all(curve[k] >= curve[k + 1] for k in range(1, kmax)) kstar = max(k for k in curve if curve[k] >= 1) rec = {str(k): curve[k] == v for (s, k), v in RECORD.items() if s == step} windows = D * ncopy res[step] = {"D": D, "Q": Q, "NCOPY": ncopy, "windows_per_period": windows, "curve": [curve[k] for k in range(1, kmax + 1)], "anchor_closed_form": anchor, "anchor_match": curve[1] == anchor, "non_increasing": mono, "kstar": kstar, "record_cells_match": rec} ok &= curve[1] == anchor and mono and all(rec.values()) samp = json.load(open("sample-2065.out.json")) W, U = samp["windows_per_period"], samp["U"] exact = res["23#->43#"]["curve"] cmp_rows = [] for r in samp["rows"]: k, Nh = r["k"], r["sample_N_hat"] N = exact[k - 1] p = N / W se = W * math.sqrt(p * (1 - p) / U) cmp_rows.append({"k": k, "hits": r["hits"], "expected_hits": round(p * U, 3), "N_hat": Nh, "N_exact": N, "rel_error": round((Nh - N) / N, 5), "z_exact_se": round((Nh - N) / se, 3)}) res["sample_1113_vs_exact"] = {"source": "sample-2065.out.json 6c85923f0f49fde4f1bae38318151fb5fa7116f5581eb3c4dff96f7eb854463c", "U": U, "seed": samp["seed"], "rows": cmp_rows, "max_abs_z": max(abs(c["z_exact_se"]) for c in cmp_rows)} print(json.dumps({"engine": "kdfs.c 7a16820b4587d79efdba841c0b7227f227109def867080223729d597f9e0bc9d", "cells": res, "all_checks_pass": ok}, indent=1, sort_keys=True)) sys.exit(0 if ok else 1)