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 = []11if set(props["id"]) != {"A", "B"} or len(props) != 2:12 issues.append({"issue": "propositions.csv does not contain exactly ids A and B", "handling": "used ids present"})13dv = dict(zip(design["parameter"], design["value"]))14seed, n = int(dv["seed"]), int(dv["n"])1516# Counterexample to A: X ~ N(0,1), S independent Rademacher (+/-1 w.p. 1/2), Y = S*X.17# Y ~ N(0,1) by symmetry of N(0,1); X+Y = (1+S)X equals 0 w.p. 1/2 and 2X otherwise.18rng = np.random.default_rng(seed)19x = rng.standard_normal(n)20s = rng.choice(np.array([-1.0, 1.0]), size=n)21y = s * x22pd.DataFrame({"x": x, "y": y}).to_csv(os.path.join(O, "counterexample.csv"), index=False)2324z = x + y25ks = float(stats.kstest(z, "norm", args=(z.mean(), z.std(ddof=1))).statistic)26# auxiliary checks (reported in report, not required keys)27aux = {28 "ks_x_vs_N01": float(stats.kstest(x, "norm").statistic),29 "ks_y_vs_N01": float(stats.kstest(y, "norm").statistic),30 "frac_sum_exactly_zero": float(np.mean(z == 0.0)),31 "corr_xy": float(np.corrcoef(x, y)[0, 1]),32}33res = {34 "task_id": "F5-conf-03",35 "statement_true": False,36 "counterexample_provided": True,37 "counterexample_values": {38 "construction": "X ~ N(0,1); S independent of X with P(S=1)=P(S=-1)=1/2; Y = S*X. "39 "Then Y ~ N(0,1) and X+Y = (1+S)X has an atom of mass 1/2 at 0 (and equals 2X otherwise), so it is not normal.",40 "n": n, "seed": seed,41 "mean_x": float(x.mean()), "sd_x": float(x.std(ddof=1)),42 "mean_y": float(y.mean()), "sd_y": float(y.std(ddof=1)),43 "mean_sum": float(z.mean()), "sd_sum": float(z.std(ddof=1)),44 "ks_sum_vs_normal": ks,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 "auxiliary_checks": aux,54}55with open(os.path.join(O, "results.json"), "w") as f:56 json.dump(res, f, indent=2)57print(json.dumps(res, indent=2))58