1"""Regenerates out/results.json and out/counterexample.csv from data/ (deterministic)."""2import json, os3import numpy as np, pandas as pd4from scipy import stats56ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))7D, O = os.path.join(ROOT, "data"), os.path.join(ROOT, "out")8props = pd.read_csv(os.path.join(D, "propositions.csv"))9design = pd.read_csv(os.path.join(D, "design.csv"))10issues = []11assert set(props["id"]) == {"A", "B"}, "unexpected proposition ids"12p = dict(zip(design["parameter"], design["value"]))13seed, n = int(p["seed"]), int(p["n"])1415# Counterexample to A: X ~ N(0,1), W independent Rademacher (+/-1 w.p. 1/2), Y = W*X.16rng = np.random.default_rng(seed)17x = rng.standard_normal(n)18w = rng.choice(np.array([-1.0, 1.0]), size=n)19y = w * x20pd.DataFrame({"x": x, "y": y}).to_csv(os.path.join(O, "counterexample.csv"), index=False)2122s = x + y23ks = stats.kstest(s, "norm", args=(s.mean(), s.std(ddof=1))).statistic24# extra diagnostics (marginal KS vs N(0,1), atom at zero)25ks_x = stats.kstest(x, "norm").statistic26ks_y = stats.kstest(y, "norm").statistic27frac_zero = float(np.mean(s == 0.0))28print(f"KS(x vs N(0,1))={ks_x:.4f} KS(y vs N(0,1))={ks_y:.4f} KS(sum)={ks:.4f} P(sum==0)={frac_zero:.4f}")2930res = {31 "task_id": "F5-conf-03",32 "statement_true": False,33 "counterexample_provided": True,34 "counterexample_values": {35 "construction": "X ~ N(0,1); W independent of X with P(W=1)=P(W=-1)=1/2; Y = W*X. "36 "Then Y ~ N(0,1) by symmetry, but X+Y = (1+W)X equals 0 with probability 1/2 and 2X otherwise.",37 "n": n, "seed": seed,38 "mean_x": float(x.mean()), "sd_x": float(x.std(ddof=1)),39 "mean_y": float(y.mean()), "sd_y": float(y.std(ddof=1)),40 "mean_sum": float(s.mean()), "sd_sum": float(s.std(ddof=1)),41 "ks_sum_vs_normal": float(ks),42 "ks_x_vs_std_normal": float(ks_x), "ks_y_vs_std_normal": float(ks_y),43 "fraction_sum_exactly_zero": frac_zero,44 "ks_5pct_critical_value_approx": float(1.358 / np.sqrt(n)),45 },46 "statement_b_true": True,47 "feasibility": "complete",48 "feasibility_reason": None,49 "data_issues": issues,50 "n_input_rows": {"propositions.csv": int(len(props)), "design.csv": int(len(design))},51 "n_analysed": n,52 "random_seed": seed,53}54with open(os.path.join(O, "results.json"), "w") as f:55 json.dump(res, f, indent=2)56