#!/usr/bin/env python3 """ CP2: Delta-Squared Probe — t/T = 3/8 from Singh's Jordan Algebra ================================================================== Date: 2026-03-21 Status: UNAUDITED (pending internal audit) Test description: TLT_4D_CP2_DELTA_SQUARED_test_description.txt PURPOSE: Probe whether t/T = 3/8 = 0.375 (Singh's universal Jordan eigenvalue spread) shows any special feature in the TLT-019 framework. Method: IDENTICAL to TLT-019 (N=3 pulsed interference, Variant C). No engine modifications. Only the sweep range is narrowed. """ import numpy as np import json import time as timer from pathlib import Path from datetime import datetime, timezone from scipy import ndimage # ====================================================================== # CONSTANTS (identical to TLT-019) # ====================================================================== PHI = (1 + np.sqrt(5)) / 2 # Key values to mark in output KEY_VALUES = { "our_optimal": 0.300, "delta_squared": 0.375, # Singh's 3/8 "phi_squared_inv": round(1.0 / PHI**2, 4), # 0.3820 (already falsified) "control_0.400": 0.400, } OUTPUT_DIR = Path(__file__).parent.parent.parent / "results" / "unaudited" / "CP2_delta_squared" OUTPUT_DIR.mkdir(parents=True, exist_ok=True) # ====================================================================== # CORE: N=3 INTERFERENCE WITH PHASE OFFSETS # (Identical to TLT-003 audited code / TLT-019) # ====================================================================== def generate_n3_with_phases(wavelength, grid_extent, resolution, phase_offsets=(0.0, 0.0, 0.0)): """N=3 interference pattern with per-wave phase offsets. Identical to TLT-003 audited implementation.""" x = np.linspace(-grid_extent, grid_extent, resolution) y = np.linspace(-grid_extent, grid_extent, resolution) X, Y = np.meshgrid(x, y) k = 2.0 * np.pi / wavelength psi = np.zeros_like(X, dtype=complex) for n in range(3): theta = 2.0 * np.pi * n / 3.0 kx = k * np.cos(theta) ky = k * np.sin(theta) psi += np.exp(1j * (kx * X + ky * Y + phase_offsets[n])) intensity = np.abs(psi) ** 2 return X, Y, intensity # ====================================================================== # MEASUREMENT: SITE CLASSIFICATION # (Identical to TLT-003 audited code / TLT-019) # ====================================================================== def find_maxima_intensities(intensity, threshold_fraction=0.5): """Find local maxima and return their intensity values. Identical to TLT-003 audited implementation.""" I_max = np.max(intensity) I_min = np.min(intensity) threshold = I_min + threshold_fraction * (I_max - I_min) binary = intensity > threshold labeled, n_features = ndimage.label(binary) maxima_values = [] for i in range(1, n_features + 1): region = (labeled == i) peak_val = np.max(intensity[region]) maxima_values.append(peak_val) return np.array(maxima_values) def classify_sites(maxima_values): """Classify maxima into intensity clusters via gap splitting. Identical to TLT-003 audited implementation.""" if len(maxima_values) < 2: return 1, 0.0, 0.0 cv = np.std(maxima_values) / np.mean(maxima_values) if np.mean(maxima_values) > 0 else 0.0 sorted_vals = np.sort(maxima_values) diffs = np.diff(sorted_vals) if len(diffs) == 0: return 1, cv, 0.0 median_gap = np.median(diffs) if median_gap == 0: gap_threshold = 0.01 * np.mean(maxima_values) else: gap_threshold = 3.0 * median_gap gap_indices = np.where(diffs > gap_threshold)[0] if len(gap_indices) == 0: return 1, cv, 0.0 boundaries = [0] + list(gap_indices + 1) + [len(sorted_vals)] n_classes = len(boundaries) - 1 # Silhouette sort_order = np.argsort(maxima_values) class_labels = np.zeros(len(maxima_values), dtype=int) class_means = [] for c in range(n_classes): start, end = boundaries[c], boundaries[c + 1] original_indices = sort_order[start:end] class_labels[original_indices] = c class_means.append(np.mean(sorted_vals[start:end])) if n_classes >= 2: inter = np.max(class_means) - np.min(class_means) intra_stds = [] for c in range(n_classes): vals = maxima_values[class_labels == c] if len(vals) > 1: intra_stds.append(np.std(vals)) else: intra_stds.append(0.0) intra = np.mean(intra_stds) if intra_stds else 0.0 silhouette = inter / (inter + intra) if (inter + intra) > 0 else 0.0 else: silhouette = 0.0 return n_classes, cv, silhouette # ====================================================================== # CP2 SWEEP # ====================================================================== def run_cp2_sweep(): """Run the delta-squared probe sweep.""" # Parameters (same as TLT-019 production settings) wavelength = 1.0 grid_extent = 5.0 resolution = 256 M_values = [100] # Scale-independent verified; M=100 sufficient # Dense sweep bracketing the region of interest tT_values = [round(0.30 + i * 0.005, 4) for i in range(31)] # 0.300 to 0.450 # Ensure key values are included for kv in KEY_VALUES.values(): if not any(abs(t - kv) < 0.001 for t in tT_values): tT_values.append(round(kv, 4)) tT_values = sorted(set(tT_values)) print("=" * 70) print("CP2: DELTA-SQUARED PROBE") print("=" * 70) print(f" Sweep: t/T = {tT_values[0]} to {tT_values[-1]}, {len(tT_values)} values") print(f" M = {M_values}") print(f" Key: optimal={KEY_VALUES['our_optimal']}, " f"delta^2={KEY_VALUES['delta_squared']}, " f"1/phi^2={KEY_VALUES['phi_squared_inv']}") print(f" Resolution: {resolution}, Grid: +/-{grid_extent}") print("=" * 70) t_start = timer.monotonic() results = [] total = len(M_values) * len(tT_values) count = 0 for M in M_values: print(f"\n M = {M}:", flush=True) for tT in tT_values: count += 1 # Accumulate M bursts with progressive phase drift intensity_acc = None for cycle in range(M): phase0 = 2.0 * np.pi * 1 * tT * cycle / M phase1 = 2.0 * np.pi * 2 * tT * cycle / M phase2 = 2.0 * np.pi * 3 * tT * cycle / M _, _, intensity_c = generate_n3_with_phases( wavelength, grid_extent, resolution, phase_offsets=(phase0, phase1, phase2) ) if intensity_acc is None: intensity_acc = intensity_c.copy() else: intensity_acc += intensity_c intensity_acc /= M maxima_vals = find_maxima_intensities(intensity_acc) n_classes, cv, silhouette = classify_sites(maxima_vals) result = { "M": M, "tT": round(float(tT), 4), "cv": round(float(cv), 8), "n_classes": n_classes, "silhouette": round(float(silhouette), 6), "n_maxima": len(maxima_vals), } results.append(result) # Mark key values marker = "" for name, val in KEY_VALUES.items(): if abs(tT - val) < 0.001: marker = f" ← {name}" print(f" t/T={tT:.4f}: classes={n_classes}, " f"CV={cv:.6f}, maxima={len(maxima_vals)}, " f"sil={silhouette:.4f}{marker}", flush=True) elapsed = timer.monotonic() - t_start # Save results output = { "test": "CP2_delta_squared_probe", "date": datetime.now(timezone.utc).isoformat(), "parameters": { "wavelength": wavelength, "grid_extent": grid_extent, "resolution": resolution, "M_values": M_values, "tT_range": [tT_values[0], tT_values[-1]], "tT_step": 0.005, "n_values": len(tT_values), }, "key_values": KEY_VALUES, "elapsed_seconds": round(elapsed, 1), "results": results, } with open(OUTPUT_DIR / "cp2_results.json", "w") as f: json.dump(output, f, indent=2) # Print summary table print("\n" + "=" * 70) print("CP2 RESULTS") print("=" * 70) print(f"{'t/T':>8s} {'Classes':>7s} {'CV':>10s} {'Maxima':>6s} {'Sil':>8s} {'Note':>15s}") print("-" * 60) for r in results: note = "" for name, val in KEY_VALUES.items(): if abs(r["tT"] - val) < 0.001: note = name print(f"{r['tT']:8.4f} {r['n_classes']:7d} {r['cv']:10.6f} " f"{r['n_maxima']:6d} {r['silhouette']:8.4f} {note:>15s}") print(f"\nRuntime: {elapsed:.1f}s") print(f"Results: {OUTPUT_DIR / 'cp2_results.json'}") return results if __name__ == "__main__": run_cp2_sweep()