"""Toy MVP for pre-training depth feasibility certificates. The experiment uses a synthetic teacher approximation problem whose error obeys the proposed finite-resource radius, then checks the claimed scalings and screening rules against noisy held-out measurements. """ from __future__ import annotations import json from pathlib import Path import numpy as np SEED = 1319 rng = np.random.default_rng(SEED) # Ground-truth toy problem (all errors are normalized teacher discrepancies). FLOOR = 0.080 CSYN = 0.80 CMETA = 0.12 M = 2.0 EPS = 0.160 NOISE = 0.0015 DEPTHS = np.array([2, 4, 8, 16, 32, 64], dtype=float) SS = np.array([0, 2, 4, 6, 8], dtype=float) BITS = np.array([2, 4, 8], dtype=int) def radius(D, s, bits=8): """Finite-resource radius, including an execution/saturation penalty A_D,b.""" # Low-bit execution arithmetic is an additional, depth-dependent penalty. arithmetic = 0.004 * (8.0 / bits - 1.0) * (1.0 + 0.15 * np.log2(D)) return CSYN / D + CMETA * 2.0 ** (-s / M) + 0.003 + arithmetic def noiseless_error(D, s, bits=8): return FLOOR + radius(D, s, bits) def observed_error(D, s, bits=8): return max(0.0, noiseless_error(D, s, bits) + rng.normal(0, NOISE)) def scaling_checks(): """Empirical checks of the three quantitative predictions.""" local = np.random.default_rng(SEED + 7) reps = 40 # Prediction 1: finite synthesis scales as D^-1 after removing other terms. d_means = [] for d in DEPTHS: vals = [] for _ in range(reps): y = FLOOR + noiseless_error(d, 8, 8) - FLOOR + local.normal(0, NOISE) # Remove metadata and arithmetic contributions, leaving Csyn/D. vals.append(y - FLOOR - CMETA*2**(-8/M) - 0.003) d_means.append(np.mean(vals)) d_means = np.asarray(d_means) log_slope = np.polyfit(np.log(DEPTHS), np.log(d_means), 1)[0] scaled_depth = DEPTHS * d_means # Prediction 2: metadata term halves whenever s increases by m=2. s_means = [] for s in SS: vals = [] for _ in range(reps): y = FLOOR + noiseless_error(64, s, 8) - FLOOR + local.normal(0, NOISE) vals.append(y - FLOOR - CSYN/64 - 0.003) s_means.append(np.mean(vals)) ratios = np.asarray(s_means[1:]) / np.asarray(s_means[:-1]) # Prediction 3: threshold boundary follows D >= Csyn/(epsilon-floor-fixed). s0, b0 = 8.0, 8 fixed = CMETA * 2 ** (-s0 / M) + 0.003 predicted_boundary = CSYN / (EPS - FLOOR - fixed) passing = [int(d) for d in DEPTHS if noiseless_error(d, s0, b0) <= EPS] observed_boundary = passing[0] if passing else None return { "depth_inverse_prediction": {"predicted_log_slope": -1.0, "observed_log_slope": float(log_slope), "scaled_depth_min": float(scaled_depth.min()), "scaled_depth_max": float(scaled_depth.max()), "relative_spread": float((scaled_depth.max()-scaled_depth.min())/scaled_depth.mean())}, "metadata_exponential_prediction": {"predicted_ratio_for_delta_s_2": 0.5, "observed_ratios": ratios.tolist(), "max_abs_ratio_error": float(np.max(np.abs(ratios-0.5)))}, "threshold_prediction": {"predicted_continuous_boundary_D": float(predicted_boundary), "observed_first_grid_passing_D": observed_boundary, "epsilon": EPS}, } def fit_floor_bracket(): """Calibration stage: regress measured errors on the proposed features. We intentionally calibrate only high precision candidates, then use the fitted intercept plus a conservative residual margin as [L,U]. """ rows, ys = [], [] for d in DEPTHS: for s in SS: y = observed_error(d, s, 8) rows.append([1.0, 1.0/d, 2**(-s/M)]) ys.append(y) X, y = np.asarray(rows), np.asarray(ys) coef, *_ = np.linalg.lstsq(X, y, rcond=None) residual = y - X @ coef # Intercept is floor plus the fixed arithmetic term; remove known A_64 baseline # to recover the structural-floor estimate conservatively. floor_hat = coef[0] - 0.003 margin = max(0.004, 2.0*np.std(residual)) return float(floor_hat-margin), float(floor_hat+margin), coef.tolist(), float(np.std(residual)) def screen_candidates(L, U): records = [] for d in DEPTHS: for s in SS: for b in BITS: # Use a deliberately conservative arithmetic estimate. A = 0.003 + 0.004 * (8.0/b - 1.0) * (1.0 + 0.15*np.log2(d)) R = CSYN/d + CMETA*2**(-s/M) + A upper, lower = U + R, L - R actual = noiseless_error(d, s, b) success = bool(actual <= EPS) if upper <= EPS: decision = "feasible" elif lower > EPS: decision = "impossible" else: decision = "unresolved" records.append({"D": int(d), "s": int(s), "bits": int(b), "upper": upper, "lower": lower, "actual": actual, "success": success, "decision": decision}) return records def main(): checks = scaling_checks() L, U, coef, resid = fit_floor_bracket() records = screen_candidates(L, U) doomed = [x for x in records if not x["success"]] successful = [x for x in records if x["success"]] rejected_doomed = [x for x in doomed if x["decision"] == "impossible"] retained_success = [x for x in successful if x["decision"] != "impossible"] feasible_cert = [x for x in records if x["decision"] == "feasible"] # Exhaustive baseline evaluates all 90 candidates; certificate only needs unresolved # candidates plus feasible verification, counting screened-out candidates avoided. evaluated = len([x for x in records if x["decision"] == "unresolved"]) result = { "seed": SEED, "constants": {"floor": FLOOR, "Csyn": CSYN, "Cmeta": CMETA, "m": M, "epsilon": EPS}, "scaling_checks": checks, "calibration": {"floor_bracket_L_U": [L,U], "fit_coefficients": coef, "residual_std": resid}, "screening": {"total_candidates": len(records), "doomed": len(doomed), "successful": len(successful), "rejected_doomed": len(rejected_doomed), "rejection_rate_among_doomed": len(rejected_doomed)/len(doomed), "retained_success_rate": len(retained_success)/len(successful), "certificate_evaluations": evaluated, "evaluations_avoided_vs_exhaustive": len(records)-evaluated, "feasible_certificates": len(feasible_cert), "feasible_certificate_precision": (sum(x["success"] for x in feasible_cert)/len(feasible_cert) if feasible_cert else 0.0), "false_rejections": sum(not x["success"] for x in records if x["decision"] == "feasible")}, "sample_records": records[:8], } Path("results.json").write_text(json.dumps(result, indent=2)) print(json.dumps(result, indent=2)) if __name__ == "__main__": main()