"""Replication entry point for F5-conf-03. Run from workspace root: ~/wp29/venv/bin/python out/analysis.py Reads only data/, writes out/results.json and out/counterexample.csv deterministically. Counterexample to A: X ~ N(0,1); W independent of X with P(W=1)=P(W=-1)=1/2; Y = W*X. Y ~ N(0,1) by symmetry of N(0,1); X+Y = (1+W)X equals 0 w.p. 1/2 and 2X otherwise, so it has an atom of mass 1/2 at 0 and is not a constant -> not normal (not even degenerate). """ import json, os import numpy as np import pandas as pd from scipy import stats ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) DATA = os.path.join(ROOT, "data") OUT = os.path.join(ROOT, "out") props = pd.read_csv(os.path.join(DATA, "propositions.csv")) design = pd.read_csv(os.path.join(DATA, "design.csv")) data_issues = [] assert set(props["id"]) == {"A", "B"}, "unexpected proposition ids" d = dict(zip(design["parameter"], design["value"])) seed, n = int(d["seed"]), int(d["n"]) # Verdicts: from the mathematical argument in out/argument.md (not from the simulation). statement_true = False # A is false (counterexample below) statement_b_true = True # B is true (characteristic-function / convolution proof) # ---- Counterexample sample (order of draws fixed: x first, then w) ---- rng = np.random.default_rng(seed) x = rng.standard_normal(n) w = rng.choice(np.array([-1.0, 1.0]), size=n) y = w * x s = x + y def ks_vs_fitted_normal(v): m, sd = v.mean(), v.std(ddof=1) return float(stats.kstest(v, "norm", args=(m, sd)).statistic) pd.DataFrame({"x": x, "y": y}).to_csv(os.path.join(OUT, "counterexample.csv"), index=False) cv = { "construction": ("X ~ N(0,1); W independent of X with P(W=1)=P(W=-1)=1/2; Y = W*X. " "Then Y ~ N(0,1), and X+Y = (1+W)X is 0 with probability 1/2 and 2X otherwise " "(atom of mass 1/2 at 0, non-constant), hence not normal."), "n": int(len(x)), "seed": seed, "mean_x": float(x.mean()), "sd_x": float(x.std(ddof=1)), "mean_y": float(y.mean()), "sd_y": float(y.std(ddof=1)), "mean_sum": float(s.mean()), "sd_sum": float(s.std(ddof=1)), "ks_sum_vs_normal": ks_vs_fitted_normal(s), } # ---- Supplementary diagnostics (same KS rule) ---- # Baseline for B: independent normal partner Z drawn AFTER the counterexample draws from the same rng z = rng.standard_normal(n) supp = { "ks_x_vs_normal": ks_vs_fitted_normal(x), "ks_y_vs_normal": ks_vs_fitted_normal(y), "share_sum_exactly_zero": float(np.mean(s == 0.0)), "baseline_ks_independent_sum_vs_normal": ks_vs_fitted_normal(x + z), "corr_x_y": float(np.corrcoef(x, y)[0, 1]), "note": ("baseline_* uses Z ~ N(0,1) independent of X (proposition B setting), drawn after x and w " "from the same generator; KS statistics use parameters estimated from the sample."), } results = { "task_id": "F5-conf-03", "statement_true": statement_true, "counterexample_provided": True, "counterexample_values": cv, "statement_b_true": statement_b_true, "feasibility": "complete", "feasibility_reason": None, "data_issues": data_issues, "n_input_rows": {"propositions.csv": int(len(props)), "design.csv": int(len(design))}, "n_analysed": int(len(x)), "random_seed": seed, "supplementary": supp, } with open(os.path.join(OUT, "results.json"), "w") as f: json.dump(results, f, indent=2) print(json.dumps(results, indent=2))