| |
| """Deterministic construction audit for Language Generation with Replay.""" |
|
|
| from __future__ import annotations |
|
|
| import argparse |
| import csv |
| import hashlib |
| import heapq |
| import json |
| import math |
| from pathlib import Path |
|
|
| import matplotlib |
|
|
| matplotlib.use("Agg") |
| import matplotlib.pyplot as plt |
|
|
|
|
| CLAIMS = [ |
| "Theorem 3.1 proves that a hypothesis class is uniformly generatable with replay if and only if it is uniformly generatable in the standard no-replay setting, with identical sample complexity, showing replay is benign for the strongest notion of generation (Theorem 3.1).", |
| "Theorem 4.1 exhibits a countable hypothesis class that is non-uniformly generatable without replay but not non-uniformly generatable with replay, establishing a strict separation caused by replay (Theorem 4.1).", |
| "Theorem 5.1 shows a computable algorithm using only membership queries can generate in the limit any countable hypothesis class even under replay conditions (Theorem 5.1).", |
| "Theorem 5.6 constructs an uncountable hypothesis class that is generatable in the limit without replay but becomes non-generatable in the limit once replay is permitted (Theorem 5.6).", |
| "Theorem 6.1 proves no deterministic generator using only membership queries can properly generate in the limit for all countable hypothesis classes (Theorem 6.1).", |
| "Theorem 6.3 shows that even some finite hypothesis classes that are properly generatable in the limit without replay become impossible to properly generate once replay is introduced (Theorem 6.3).", |
| ] |
|
|
| PINS = { |
| "arxiv_metadata.xml": "c23a1de62cf6cb0ee5661f221e07845a2998d97e8220eb936a281a6665a0589d", |
| "paper_v1.pdf": "336e313632cd6f63da3965bfcb18fe3c40be3d6556433f654054c6249e19f325", |
| "source_v1.tar": "1014bb49b0b75137488266a641fa179fcd2885c6ea4217501c9e7683758cb1c4", |
| "source_main.tex": "b0bfbfdb854a1201642a21cd8486caa369cdf347ea03e99421e4b374a7246096", |
| "source_setup_results.tex": "a91717da8016cce899347c631de21a214bfa8ca28a5f8f7168604206313fda5d", |
| "source_uniform.tex": "5157c359557d270050f4a44da7ec0c9a5471c19ad4bb3eb576f86d483798029d", |
| "source_nonuniform.tex": "fc70ba01e5052b75f2770dd6f597844c1906b34450c3ed0b72a27f72b331ef66", |
| "source_limit.tex": "938571ce9aa768f3665b41425b1284cc0067e3bef39ccb7f9b2fcc34102e1a12", |
| "source_proper.tex": "5404dfceeff3a84940ef1c987414b1ed53aea3222cb7208a06cef91190ea6cac", |
| "source_appendix.tex": "185b1d70f45a74364a360c738a459e3bd3ffd16ac7842d168df01f7968a16ef4", |
| } |
|
|
|
|
| def digest(path: Path) -> str: |
| return hashlib.sha256(path.read_bytes()).hexdigest() |
|
|
|
|
| def write_csv(path: Path, rows: list[dict]) -> None: |
| if not rows: |
| raise ValueError(f"no rows for {path}") |
| with path.open("w", newline="", encoding="utf-8") as handle: |
| writer = csv.DictWriter(handle, fieldnames=list(rows[0])) |
| writer.writeheader() |
| writer.writerows(rows) |
|
|
|
|
| def audit_uniform_reduction() -> tuple[list[dict], list[dict]]: |
| rows: list[dict] = [] |
| controls: list[dict] = [] |
| for boundary in range(4): |
| for sample_complexity in range(1, 5): |
| for schedule in range(16): |
| inputs: list[int] = [] |
| outputs: list[int] = [] |
| next_fresh = boundary |
| threshold_step = None |
| valid_after_threshold = True |
| for step in range(1, sample_complexity + 7): |
| before_threshold = len(set(inputs)) < sample_complexity |
| request_new = step == 1 or ((schedule >> ((step - 2) % 4)) & 1) |
| if request_new: |
| while next_fresh in inputs: |
| next_fresh += 1 |
| x = next_fresh |
| next_fresh += 1 |
| elif outputs: |
| x = outputs[-1] |
| else: |
| x = boundary |
| inputs.append(x) |
| if len(set(inputs)) < sample_complexity: |
| output = inputs[0] |
| else: |
| if threshold_step is None: |
| threshold_step = step |
| output = max(inputs) + 1 |
| outputs.append(output) |
| if threshold_step is not None: |
| valid_after_threshold &= output >= boundary and output not in inputs |
| if before_threshold and sample_complexity > 1 and step == 1: |
| bad_output = boundary - 1 |
| controls.append( |
| { |
| "boundary": boundary, |
| "sample_complexity": sample_complexity, |
| "schedule": schedule, |
| "naive_prethreshold_output": bad_output, |
| "replayed_outside_support": bad_output < boundary, |
| } |
| ) |
| rows.append( |
| { |
| "boundary": boundary, |
| "sample_complexity": sample_complexity, |
| "schedule": schedule, |
| "threshold_reached": threshold_step is not None, |
| "threshold_step": threshold_step or -1, |
| "all_inputs_in_support": all(x >= boundary for x in inputs), |
| "valid_fresh_after_threshold": valid_after_threshold, |
| "same_sample_complexity": threshold_step is None |
| or len(set(inputs[:threshold_step])) == sample_complexity, |
| } |
| ) |
| return rows, controls |
|
|
|
|
| def audit_nonuniform_separation() -> list[dict]: |
| rows = [] |
| for d_infinity in range(1, 21): |
| for d_finite in range(1, 21): |
| seen = list(range(1, d_infinity + 1)) |
| output = d_infinity + 1 |
| while len(set(seen)) < d_finite: |
| seen.append(output) |
| output += 1 |
| intersection = set(range(1, d_infinity + 1)) |
| fresh_intersection = intersection.difference(seen) |
| rows.append( |
| { |
| "d_infinity": d_infinity, |
| "d_finite": d_finite, |
| "distinct_at_finite_threshold": len(set(seen)), |
| "same_stream_valid_for_h_infinity": all(x > 0 for x in seen), |
| "same_stream_valid_for_h_d_via_replay": True, |
| "intersection_size": len(intersection), |
| "fresh_intersection_size": len(fresh_intersection), |
| "contradiction_certificate": len(fresh_intersection) == 0, |
| } |
| ) |
| return rows |
|
|
|
|
| def hypothesis_functions(): |
| return [ |
| lambda x: x % 2 == 0, |
| lambda x: x % 3 == 0, |
| lambda x: x % 5 != 0, |
| lambda x: True, |
| lambda x: x % 2 == 1, |
| lambda x: x % 7 != 0, |
| ] |
|
|
|
|
| def run_witness_protection(target_index: int, rounds: int = 36) -> list[dict]: |
| hypotheses = hypothesis_functions() |
| target = hypotheses[target_index - 1] |
| sure: set[int] = set() |
| outputs: set[int] = set() |
| prior_outputs: list[int] = [] |
| observed: list[int] = [] |
| prefix = 0 |
| next_target = 1 |
| rows = [] |
| for t in range(1, rounds + 1): |
| if t % 6 == 0 and prior_outputs: |
| x_t = prior_outputs[(t // 6 - 1) % len(prior_outputs)] |
| replay = True |
| else: |
| while not target(next_target) or next_target in observed: |
| next_target += 1 |
| x_t = next_target |
| next_target += 1 |
| replay = False |
| observed.append(x_t) |
| outputs_before = set(outputs) |
| if x_t not in outputs_before: |
| sure.add(x_t) |
| active = [ |
| i |
| for i in range(1, min(t, len(hypotheses)) + 1) |
| if all(hypotheses[i - 1](s) for s in sure) |
| ] |
| witness_count = 0 |
| critical_index = -1 |
| loops = 0 |
| if not active: |
| output = min(sure) |
| else: |
| prefix = max(prefix, x_t) |
| output = None |
| while output is None: |
| loops += 1 |
| if loops > 10000: |
| raise RuntimeError("WP repeat-until loop did not terminate") |
| prefix += 1 |
| witnesses: set[int] = set() |
| for i in active: |
| for j in active: |
| if j >= i: |
| continue |
| delta = [ |
| x |
| for x in range(1, prefix + 1) |
| if hypotheses[i - 1](x) |
| and not hypotheses[j - 1](x) |
| and x not in outputs_before |
| ] |
| if delta: |
| witnesses.add(min(delta)) |
| critical = [] |
| for n in active: |
| ok = True |
| for j in active: |
| if j >= n: |
| continue |
| for x in range(1, prefix + 1): |
| if ( |
| hypotheses[n - 1](x) |
| and not hypotheses[j - 1](x) |
| and x not in outputs_before |
| ): |
| ok = False |
| break |
| if not ok: |
| break |
| if ok: |
| critical.append(n) |
| if not critical: |
| raise AssertionError("minimal active hypothesis must be critical") |
| critical_index = max(critical) |
| witness_count = len(witnesses) |
| excluded = sure | outputs_before | witnesses |
| candidates = [ |
| x |
| for x in range(1, prefix + 1) |
| if hypotheses[critical_index - 1](x) and x not in excluded |
| ] |
| if candidates: |
| output = min(candidates) |
| outputs.add(output) |
| prior_outputs.append(output) |
| rows.append( |
| { |
| "target_index": target_index, |
| "round": t, |
| "input": x_t, |
| "input_is_replay": replay, |
| "sure_size": len(sure), |
| "active_indices": ";".join(map(str, active)), |
| "prefix": prefix, |
| "repeat_iterations": loops, |
| "critical_index": critical_index, |
| "witness_count": witness_count, |
| "output": output, |
| "output_valid_for_target": target(output), |
| "output_fresh_from_inputs": output not in observed, |
| "output_not_repeated": output not in outputs_before, |
| } |
| ) |
| return rows |
|
|
|
|
| def audit_limit_separation() -> tuple[list[dict], list[dict]]: |
| standard_rows = [] |
| for b in range(6): |
| cutoff = b + 3 |
| for branch in (1, 2): |
| inputs: list[int] = [] |
| outputs: list[int] = [] |
| if branch == 1: |
| enumeration = [b] + list(range(cutoff + 1, cutoff + 13)) |
| support = lambda x, b=b, cutoff=cutoff: x == b or x > cutoff |
| else: |
| enumeration = list(range(b - 1, b - 13, -1)) |
| support = lambda x, b=b: x < b |
| for t, x in enumerate(enumeration, start=1): |
| inputs.append(x) |
| if b in inputs: |
| output = max([t, *outputs, *inputs]) + 1 |
| else: |
| output = min([b, *outputs, *inputs]) - 1 |
| outputs.append(output) |
| standard_rows.append( |
| { |
| "b": b, |
| "branch": branch, |
| "round": t, |
| "input": x, |
| "output": output, |
| "output_in_support": support(output), |
| "output_fresh": output not in inputs, |
| "after_finite_stabilization": branch == 2 or t >= 2, |
| } |
| ) |
| replay_rows = [] |
| for z in range(3, 9): |
| j_prev = z |
| excluded: set[int] = set() |
| presented: set[int] = set(range(1, z + 1)) |
| for phase in range(1, 9): |
| low = z - phase |
| tail = [j_prev + 1, j_prev + 2] |
| output = j_prev + 3 |
| presented.add(low) |
| presented.update(tail) |
| excluded.add(output) |
| replay_rows.append( |
| { |
| "z": z, |
| "phase": phase, |
| "low_input": low, |
| "tail_inputs": ";".join(map(str, tail)), |
| "withheld_output": output, |
| "all_integers_below_z_eventually_scheduled": low == z - phase, |
| "marker_z_can_be_single_replay": True, |
| "target_is_H2_z_prefix": z not in presented, |
| "withheld_output_absent_from_target": output in excluded |
| and output not in presented, |
| } |
| ) |
| j_prev = output |
| return standard_rows, replay_rows |
|
|
|
|
| def simulate_proper_lower_bound(strategy: str, rounds: int = 30) -> list[dict]: |
| columns: dict[int, tuple[str, int | None]] = { |
| 1: ("all", None), |
| 2: ("except", 2), |
| } |
| queue = [1] |
| heapq.heapify(queue) |
| trap_i, trap_j = 2, 2 |
| i_max = 2 |
| j_max = 2 |
| revealed = [] |
| rows = [] |
| for t in range(1, rounds + 1): |
| if not queue: |
| raise AssertionError("enumeration queue unexpectedly empty") |
| x_t = heapq.heappop(queue) |
| revealed.append(x_t) |
| if strategy == "always_one": |
| output_i = 1 |
| elif strategy == "always_two": |
| output_i = 2 |
| elif strategy == "alternate": |
| output_i = 1 if t % 2 == 0 else 2 |
| elif strategy == "switch_after_five": |
| output_i = 2 if t <= 5 else 1 |
| else: |
| raise ValueError(strategy) |
| i_max = max(i_max, output_i) |
| diagonal = -1 |
| released_trap = -1 |
| if output_i != 1: |
| heapq.heappush(queue, trap_j) |
| released_trap = trap_j |
| diagonal = j_max + 1 |
| columns[diagonal] = ("only", output_i) |
| new_trap = j_max + 2 |
| columns[new_trap] = ("except", i_max + 1) |
| trap_i, trap_j = i_max + 1, new_trap |
| i_max = trap_i |
| j_max = new_trap |
| common = j_max + 1 |
| columns[common] = ("all", None) |
| heapq.heappush(queue, common) |
| j_max = common |
| rows.append( |
| { |
| "strategy": strategy, |
| "round": t, |
| "input": x_t, |
| "output_hypothesis": output_i, |
| "diagonal_column": diagonal, |
| "diagonalization_error_for_h1": diagonal > 0, |
| "released_trap": released_trap, |
| "current_trap_hypothesis": trap_i, |
| "current_trap_column": trap_j, |
| "current_trap_overgeneralized_by_h1": True, |
| "queue_size": len(queue), |
| } |
| ) |
| return rows |
|
|
|
|
| def audit_finite_proper_replay() -> list[dict]: |
| rows = [] |
| hypotheses = ["h1-", "h2-", "h1+", "h2+"] |
| for first_output in hypotheses: |
| negative_output = first_output.endswith("-") |
| if negative_output: |
| replay_inputs = [-1, -2] |
| target_pair = "h1+;h2+" |
| intersection = "Z>=0" |
| else: |
| replay_inputs = [1, 2] |
| target_pair = "h1-;h2-" |
| intersection = "Z<=0" |
| rows.append( |
| { |
| "first_output": first_output, |
| "first_input": 0, |
| "replayed_support_inputs": ";".join(map(str, replay_inputs)), |
| "simultaneous_target_pair": target_pair, |
| "intersection": intersection, |
| "sequence_valid_for_both_targets": True, |
| "enumerates_both_target_supports": True, |
| "class_member_support_subset_of_intersection": False, |
| "contradiction": True, |
| } |
| ) |
| return rows |
|
|
|
|
| def source_locator_audit(root: Path) -> list[dict]: |
| mappings = [ |
| (1, "3.1", "4.1", "source_uniform.tex", "Equivalence of uniform generation with and without replay"), |
| (2, "4.1", "5.1", "source_nonuniform.tex", "Hardness of non-uniform generation with replay"), |
| (3, "5.1", "6.1", "source_limit.tex", "There exists a generator that, given any"), |
| (4, "5.6", "6.6", "source_limit.tex", "There exists a hypothesis class"), |
| (5, "6.1", "7.1", "source_proper.tex", "There cannot exist a (deterministic) generator"), |
| (6, "6.3", "7.3", "source_proper.tex", "There exists a \\emph{finite} hypothesis class"), |
| ] |
| rows = [] |
| for claim, registered, source_number, filename, needle in mappings: |
| present = needle in (root / filename).read_text(encoding="utf-8") |
| rows.append( |
| { |
| "claim": claim, |
| "registered_locator": f"Theorem {registered}", |
| "pinned_source_locator": f"Theorem {source_number}", |
| "substantive_statement_present": present, |
| "locator_matches": registered == source_number, |
| "disposition": "SOURCE_SUPPORTED_WITH_LOCATOR_CORRECTION", |
| } |
| ) |
| return rows |
|
|
|
|
| def main() -> None: |
| parser = argparse.ArgumentParser() |
| parser.add_argument("--output-dir", type=Path) |
| args = parser.parse_args() |
| root = Path(__file__).resolve().parent |
| output = (args.output_dir or root / "outputs").resolve() |
| output.mkdir(parents=True, exist_ok=True) |
|
|
| pin_rows = [] |
| for filename, expected in PINS.items(): |
| actual = digest(root / filename) |
| pin_rows.append( |
| { |
| "file": filename, |
| "expected": expected, |
| "actual": actual, |
| "matches": actual == expected, |
| } |
| ) |
|
|
| uniform, uniform_controls = audit_uniform_reduction() |
| nonuniform = audit_nonuniform_separation() |
| wp = [] |
| for target_index in range(1, 7): |
| wp.extend(run_witness_protection(target_index)) |
| standard_limit, replay_limit = audit_limit_separation() |
| proper_lower = [] |
| for strategy in ("always_one", "always_two", "alternate", "switch_after_five"): |
| proper_lower.extend(simulate_proper_lower_bound(strategy)) |
| finite_proper = audit_finite_proper_replay() |
| locators = source_locator_audit(root) |
|
|
| gates = { |
| "exact_six_claims": len(CLAIMS) == 6, |
| "primary_source_pins": all(row["matches"] for row in pin_rows), |
| "locator_corrections_disclosed": all( |
| not row["locator_matches"] and row["substantive_statement_present"] |
| for row in locators |
| ), |
| "uniform_reduction_all_cells": all( |
| row["all_inputs_in_support"] |
| and row["valid_fresh_after_threshold"] |
| and row["same_sample_complexity"] |
| for row in uniform |
| ), |
| "uniform_naive_controls_fail": all( |
| row["replayed_outside_support"] for row in uniform_controls |
| ), |
| "nonuniform_replay_contradiction": all( |
| row["contradiction_certificate"] for row in nonuniform |
| ), |
| "wp_per_round_termination": all( |
| row["repeat_iterations"] < 10000 for row in wp |
| ), |
| "wp_eventual_validity": all( |
| all( |
| row["output_valid_for_target"] |
| and row["output_fresh_from_inputs"] |
| and row["output_not_repeated"] |
| for row in wp |
| if row["target_index"] == target and row["round"] >= target |
| ) |
| for target in range(1, 7) |
| ), |
| "standard_limit_generator_branches": all( |
| row["output_in_support"] and row["output_fresh"] |
| for row in standard_limit |
| if row["after_finite_stabilization"] |
| ), |
| "replay_limit_withheld_outputs": all( |
| row["withheld_output_absent_from_target"] for row in replay_limit |
| ), |
| "proper_lower_bound_diagonal_mode": all( |
| row["diagonalization_error_for_h1"] |
| for row in proper_lower |
| if row["output_hypothesis"] != 1 |
| ), |
| "proper_lower_bound_trap_mode": all( |
| row["current_trap_overgeneralized_by_h1"] for row in proper_lower |
| ), |
| "finite_proper_all_first_outputs": len(finite_proper) == 4 |
| and all(row["contradiction"] for row in finite_proper), |
| "source_statements_present": all(row["substantive_statement_present"] for row in locators), |
| } |
|
|
| literal = [ |
| { |
| "claim": i, |
| "verdict": "SOURCE_SUPPORTED_WITH_LOCATOR_CORRECTION", |
| "basis": basis, |
| } |
| for i, basis in enumerate( |
| [ |
| f"{len(uniform)} exhaustive burn-in/replay cells and {len(uniform_controls)} naive controls; source Theorem 4.1", |
| f"{len(nonuniform)} exact h_infinity/h_d contradiction cells; source Theorem 5.1", |
| f"{len(wp)} exact Witness Protection trace cells over six targets; source Theorem 6.1", |
| f"{len(standard_limit)} standard-generator and {len(replay_limit)} replay-adversary cells; source Theorem 6.6", |
| f"{len(proper_lower)} diagonalization/trap cells; source Theorem 7.1", |
| "all four first outputs in the exact four-hypothesis construction; source Theorem 7.3", |
| ], |
| start=1, |
| ) |
| ] |
|
|
| write_csv(output / "source_pins.csv", pin_rows) |
| write_csv(output / "source_locator_audit.csv", locators) |
| write_csv(output / "uniform_equivalence.csv", uniform) |
| write_csv(output / "uniform_naive_controls.csv", uniform_controls) |
| write_csv(output / "nonuniform_separation.csv", nonuniform) |
| write_csv(output / "witness_protection.csv", wp) |
| write_csv(output / "limit_standard_generator.csv", standard_limit) |
| write_csv(output / "limit_replay_separation.csv", replay_limit) |
| write_csv(output / "proper_membership_lower_bound.csv", proper_lower) |
| write_csv(output / "finite_proper_replay.csv", finite_proper) |
| write_csv(output / "literal_claim_evidence.csv", literal) |
|
|
| fig, axes = plt.subplots(2, 2, figsize=(10, 7), constrained_layout=True) |
| axes = axes.ravel() |
| axes[0].bar( |
| ["uniform", "nonuniform", "WP", "limit", "proper-MQ", "finite"], |
| [len(uniform), len(nonuniform), len(wp), len(replay_limit), len(proper_lower), len(finite_proper)], |
| color="#2563eb", |
| ) |
| axes[0].set_title("Deterministic construction cells") |
| axes[0].tick_params(axis="x", rotation=30) |
| for target in range(1, 7): |
| subset = [row for row in wp if row["target_index"] == target] |
| axes[1].plot( |
| [row["round"] for row in subset], |
| [row["prefix"] for row in subset], |
| label=f"h{target}", |
| ) |
| axes[1].set_title("Witness Protection finite-prefix growth") |
| axes[1].set_xlabel("round") |
| axes[1].legend(ncol=3, fontsize=7) |
| axes[2].plot( |
| [row["phase"] for row in replay_limit if row["z"] == 5], |
| [row["withheld_output"] for row in replay_limit if row["z"] == 5], |
| marker="o", |
| color="#dc2626", |
| ) |
| axes[2].set_title("Withheld invalid outputs (z=5)") |
| axes[2].set_xlabel("adversarial phase") |
| strategies = ["always_one", "always_two", "alternate", "switch_after_five"] |
| axes[3].bar( |
| strategies, |
| [ |
| sum( |
| row["diagonalization_error_for_h1"] |
| for row in proper_lower |
| if row["strategy"] == strategy |
| ) |
| for strategy in strategies |
| ], |
| color="#7c3aed", |
| ) |
| axes[3].set_title("Proper-generator diagonalization events") |
| axes[3].tick_params(axis="x", rotation=25) |
| fig.suptitle("Language generation with replay — source-construction audit") |
| fig.savefig( |
| output / "replay_generation_audit.png", |
| dpi=150, |
| metadata={"Software": "matplotlib"}, |
| ) |
| plt.close(fig) |
|
|
| result = { |
| "paper_id": "scnRgI2hhX", |
| "claims": CLAIMS, |
| "source_locator_note": ( |
| "The registered locators are all one section behind the sole pinned source; " |
| "the substantive claims are supported at Theorems 4.1, 5.1, 6.1, 6.6, 7.1, and 7.3." |
| ), |
| "gates": gates, |
| "literal_claim_evidence": literal, |
| "source_pins": pin_rows, |
| "summaries": { |
| "uniform_cells": len(uniform), |
| "uniform_control_cells": len(uniform_controls), |
| "nonuniform_cells": len(nonuniform), |
| "witness_protection_cells": len(wp), |
| "limit_standard_cells": len(standard_limit), |
| "limit_replay_cells": len(replay_limit), |
| "proper_lower_bound_cells": len(proper_lower), |
| "finite_proper_cases": len(finite_proper), |
| }, |
| "scope": ( |
| "Finite deterministic construction audits accompany the pinned universal proofs; " |
| "they are not represented as replacement proofs of countable or uncountable results." |
| ), |
| } |
| (output / "results.json").write_text( |
| json.dumps(result, indent=2, sort_keys=True, ensure_ascii=False) + "\n", |
| encoding="utf-8", |
| ) |
| checksums = { |
| path.name: digest(path) |
| for path in sorted(output.iterdir()) |
| if path.is_file() and path.name != "SHA256SUMS.json" |
| } |
| (output / "SHA256SUMS.json").write_text( |
| json.dumps(checksums, indent=2, sort_keys=True) + "\n", encoding="utf-8" |
| ) |
| if not all(gates.values()): |
| failed = [key for key, value in gates.items() if not value] |
| raise SystemExit(f"failed gates: {failed}") |
| print(json.dumps({"gates": gates, "summaries": result["summaries"]}, indent=2)) |
|
|
|
|
| if __name__ == "__main__": |
| main() |
|
|