"""Question: does frozen-D51 co-kill alignment fall below its fixed-block null? The preregistration fixes the domain, statistic, R, seed and decision rules. This computes a new statistic, not the old census, LP or permutation nulls. """ import hashlib import json import sys from collections import Counter from decimal import Decimal, localcontext from fractions import Fraction from itertools import combinations from pathlib import Path INPUT_SHA = "b173e69b99916a9562cfab59223359984c629f5845a68a265d4ef3dbc3f162c1" PREREG_SHA = "28c1e0fa4ff3b33246c9a949f41fbbd7d6531bc90e8b259e7375224e5df930e0" SEED, REPLICATES = 1109, 9999 def permutation(n, draw, prime): """Portable deterministic stream; rejection avoids modulo reduction bias. The ideal null uses uniform independent permutations. This finite stream is a seeded pseudorandom approximation, not a theorem of arithmetic randomness. """ domain = b"sah1109/v1/" + SEED.to_bytes(8, "big") domain += draw.to_bytes(4, "big") + prime.to_bytes(4, "big") block, cursor, buffer = 0, 32, b"" result = list(range(n)) for i in range(n - 1, 0, -1): bound = i + 1 ceiling = 256 - 256 % bound while True: if cursor == 32: buffer = hashlib.sha256(domain + block.to_bytes(8, "big")).digest() block += 1 cursor = 0 value = buffer[cursor] cursor += 1 if value < ceiling: break j = value % bound result[i], result[j] = result[j], result[i] return result def graph(slots, prime): edges = [] for i, j in combinations(range(len(slots)), 2): difference = (slots[j] - slots[i]) % prime weight = 2 if difference == 0 else int(difference in (2, prime - 2)) if weight: edges.append((i, j, weight)) return edges def invariants(n, edges): degrees = [0] * n total = squares = 0 for i, j, weight in edges: total += 2 * weight squares += 2 * weight * weight degrees[i] += weight degrees[j] += weight wedges = sum(d * d for d in degrees) - squares disjoint = total * total - 4 * wedges - 2 * squares assert wedges >= 0 and disjoint >= 0 return total, squares, wedges, disjoint def pair_moments(n, left, right): s, t, u, v = left ss, tt, uu, vv = right mean = Fraction(s * ss, n * (n - 1)) second = Fraction(2 * t * tt, n * (n - 1)) second += Fraction(4 * u * uu, n * (n - 1) * (n - 2)) second += Fraction(v * vv, n * (n - 1) * (n - 2) * (n - 3)) variance = second - mean * mean assert variance >= 0 return mean, variance def statistic(n, graphs, permutations=None): sums = [0] * (n * n) result = 0 for block, edges in enumerate(graphs): perm = permutations[block] if permutations else list(range(n)) for i, j, weight in edges: a, b = perm[i], perm[j] if a > b: a, b = b, a index = a * n + b # Each earlier/later prime pair contributes twice for ordered slots. result += 2 * sums[index] * weight sums[index] += weight return result def decimal_text(value): with localcontext() as context: context.prec = 30 return str(Decimal(value.numerator) / Decimal(value.denominator)) def main(): raw = Path(sys.argv[1]).read_bytes() assert hashlib.sha256(raw).hexdigest() == INPUT_SHA data = json.loads(raw) slots, primes = data["slots"], data["Q"] n = len(slots) assert n == data["N"] == 51 and data["p"] == 97 and data["a"] == 9409 assert slots == sorted(set(slots)) and len(primes) == 19 graphs = [graph(slots, q) for q in primes] summaries = [invariants(n, edges) for edges in graphs] reference = statistic(n, graphs) mean = variance = Fraction(0) for left, right in combinations(summaries, 2): pair_mean, pair_variance = pair_moments(n, left, right) mean += pair_mean # Shared-block pair terms are uncorrelated under independent relabeling: # each centered conditional mean is zero when that block is fixed. variance += pair_variance controls = Counter() for draw in range(REPLICATES): perms = [list(range(n))] perms += [permutation(n, draw, q) for q in primes[1:]] controls[statistic(n, graphs, perms)] += 1 total = sum(value * count for value, count in controls.items()) squares = sum(value * value * count for value, count in controls.items()) sample_mean = Fraction(total, REPLICATES) sample_variance = Fraction(squares, REPLICATES) - sample_mean * sample_mean rank = Fraction(1 + sum(c for v, c in controls.items() if v <= reference), REPLICATES + 1) effect_condition = variance > 0 and reference < mean and (mean - reference) ** 2 >= 4 * variance if variance == 0 or reference >= mean: outcome = "falsified_at_frozen_input" elif effect_condition and rank <= Fraction(1, 100): outcome = "finite_probe_success" else: outcome = "inconclusive" with localcontext() as context: context.prec = 30 delta = Decimal((reference - mean).numerator) / Decimal((reference - mean).denominator) var = Decimal(variance.numerator) / Decimal(variance.denominator) standardized = str(delta / var.sqrt()) if variance else None output = { "job": 1109, "input_sha256": INPUT_SHA, "prereg_sha256": PREREG_SHA, "scope": "Frozen N51 raw-phase co-kill alignment; synthetic whole-prime row permutations only", "null_is_arithmetic_exchangeability": False, "rng": "SHA256 sah1109/v1 seed8 draw4 prime4 counter8 big-endian; byte rejection; descending Fisher-Yates", "seed": SEED, "replicates": REPLICATES, "N": n, "prime_pairs": len(primes) * (len(primes) - 1) // 2, "reference_X": reference, "ideal_mean": str(mean), "ideal_variance": str(variance), "ideal_mean_decimal": decimal_text(mean), "ideal_variance_decimal": decimal_text(variance), "standardized_discrepancy_decimal": standardized, "control_frequency": [[value, count] for value, count in sorted(controls.items())], "control_mean": str(sample_mean), "control_variance": str(sample_variance), "conservative_lower_rank": str(rank), "two_sd_deficit": effect_condition, "outcome": outcome, "per_prime_graph_invariants": [ {"q": q, "ordered_weight": row[0], "ordered_squares": row[1], "wedges": row[2], "disjoint_products": row[3]} for q, row in zip(primes, summaries, strict=True) ], } print(json.dumps(output, sort_keys=True, indent=2)) if __name__ == "__main__": main()