# Independent Blind Recomputation & Producer Code Audit (`D-050`): Days 4–5 (`#71` / `#77`)

## 1. Protocol & Provenance Attestation

1. **Strict blindness maintained:** `day45/independent/recompute.py` was written from scratch using only the Python standard library (`json`, `math`, `statistics`, `pathlib`) after reading only `PLAN.md`, `day45/PLAN.md`, `day45/DRYRUN.md`, `day23/RESULT.md`, and the raw output JSONs in `day45/out/` and `day23/out/`.
2. **Pre-audit output freeze:** `day45/independent/RECOMPUTED.json` was generated and saved on disk prior to opening `day45/analyse_day45.py`, `day45/mhis_fast.py`, `day45/run_day4_mech.py`, `day45/run_day5_mhis.py`, or the staged `summary_day45.json`, and was not edited afterward.
3. **Overall audit conclusion:** **PASS (exact numerical and verdict agreement).** Across all **95** shared scalar, list, count, and verdict fields between `day45/independent/RECOMPUTED.json` and `summary_day45.json`, the maximum relative floating-point discrepancy is **$2.75 \times 10^{-16}$** (1 IEEE-754 `float64` ULP from `sum/n` vs `numpy.mean`), and all zero counts, gate statuses, and frozen decision-rule verdicts match identically:
   - **Day 4 (`R-M1`):** `M1_INCONCLUSIVE`
   - **Day 4 (`R-M2` / `R-M3`):** `MIXED_DEPENDENCE` (strictly under the frozen conjunction; see Section 4.3 on the `0.08` split-half gate)
   - **Day 5 (`R-H2`):** `H2_WRONG_AT_2P18` (`3` of `3` distributions `flat_and_above`)

---

## 2. Day 4 Independent Verification (`R-M1`, `R-M2`, `R-M3`)

### 2.1 Gates (`G0` and `LN`)

| Distribution | `Gate G0` max rel diff (`S0` vs `day23` $2^{20}$) | `Gate G0` (`<= 1e-5`) | `Gate LN` $\max|\|z\|_2^2 - 512|$ (`<= 0.05`) | `Gate LN` $\max|\sum_k z_k|$ (`<= 1e-3`) | `Gate LN` |
|---|---:|:---:|---:|---:|:---:|
| `hex` | `0.0` | PASS | `4.118430e-3` | `1.048637e-5` | PASS |
| `camel` | `0.0` | PASS | `8.758697e-3` | `1.370917e-5` | PASS |
| `english` | `0.0` | PASS | `1.268332e-2` | `1.244156e-5` | PASS |

### 2.2 `M32` (`median |log10(est / p_true)|`, `0 -> inf`), Split-Half, and Direction Diagnostics

| Metric | `hex` | `camel` | `english` | Producer diff |
|---|---:|---:|---:|---:|
| `M32(S0)` (in-sample $2^{20}$, zeros) | `1.026549` (`1`) | `1.116942` (`0`) | `0.553403` (`0`) | `0.0` |
| `M32(S1)` (held-out A $2^{20}$, zeros) | `1.176129` (`0`) | `1.191450` (`0`) | `0.576968` (`0`) | `0.0` |
| `M32(S2)` (held-out B $2^{20}$, zeros) | `1.161146` (`3`) | `1.222454` (`0`) | `0.505660` (`0`) | `0.0` |
| `split_half_med_abslog10` (`S1>0 & S2>0`, $n_{\text{fin}}$) | `0.153243` (`29`) | `0.036159` (`32`) | `0.096352` (`32`) | `0.0` |
| `S1` median `est / p_true` | `10.046462` | `15.560514` | `3.495369` | `0.0` |
| `|M32(S1) - M32(S0)| / M32(S0)` | `0.145712` | `0.066707` | `0.042582` | `0.0` |
| `5` fresh dir seeds `M32` median | `0.968709` | `1.149341` | `0.559994` | `0.0` |
| `5` fresh dir seeds `M32` `[min, max]` | `[0.943197, 0.993198]` | `[1.131549, 1.157378]` | `[0.540817, 0.594153]` | `0.0` |
| `|M32_5seed_med - M32(S0)|` | `0.057840` | `0.032399` | `0.006590` | `0.0` |
| Deterministic direction `M32` (zeros) | `1.394689` (`0`) | `1.333298` (`0`) | `0.707634` (`0`) | `0.0` |
| `M32(NS16_S0)` (`16`-bin norm-stratified, zeros) | `0.764325` (`1`) | `0.594439` (`0`) | `0.440324` (`0`) | `0.0` |
| `M32(NS16_S1)` (`16`-bin held-out A, zeros) | `0.840881` (`2`) | `0.604900` (`0`) | `0.444856` (`0`) | `0.0` |
| `NS16_over_std_ratio` (`M32(NS16_S0) / M32(S0)`) | `0.744558` | `0.532202` | `0.795666` | `0.0` |
| `median_spearman_a_lower` | `0.036812` | `0.104789` | `0.075125` | `0.0` |
| `median_delta_hurdle_sd` | `+0.735033` | `+2.726090` | `+0.807289` | `0.0` |
| `pos_delta_hurdle_count` (`/ 32`) | `26 / 32` | `31 / 32` | `29 / 32` | `0` |
| Exact binomial $p$ (one-sided $\ge k$ / two-sided) | `2.68e-4` / `5.35e-4` | `7.68e-9` / `1.54e-8` | `1.28e-6` / `2.56e-6` | — |

### 2.3 Day 4 Frozen Verdicts

- **`R-M1` (`M1_INCONCLUSIVE`):**
  - `M1_SUPPORTED` (`S1` or `5`-seed median cuts `M32` by $\ge 30\%$ on $\ge 2/3$): **0 of 3** (`S1` increases `M32` by `+14.6%`, `+6.7%`, `+4.3%`; `5`-seed median changes `M32` by `-5.6%`, `+2.9%`, `+1.2%`).
  - `M1_REFUTED` clauses `(ii)` (`S1` median `est/p >= 3.0` and within $20\%$ of `M32(S0)`) and `(iii)` (`5`-seed median within `0.15` of `M32(S0)`): **3 of 3** (`hex`, `camel`, `english`).
  - `M1_REFUTED` clause `(i)` (`split_half_med_abslog10 <= 0.08`): **1 of 3** (`camel = 0.0362 <= 0.08`; `english = 0.0964 > 0.08`; `hex = 0.1532 > 0.08`).
  - Conjunction `(i) & (ii) & (iii)` holds on **1 of 3** `< 2`, yielding **`M1_INCONCLUSIVE`**.
- **`R-M2` / `R-M3` (`MIXED_DEPENDENCE`):**
  - `R-M2` (`NS16_over_std_ratio <= 0.70` on $\ge 2/3$): **1 of 3** (`camel` only, `0.5322 <= 0.70`).
  - `R-M3` coupling clauses: `NS16_over_std_ratio > 0.70` holds on **2 of 3** (`hex = 0.7446`, `english = 0.7957`), and `median_delta_hurdle_sd > 0` with `pos_delta_hurdle_count >= 22` holds on **3 of 3** (`26/32`, `31/32`, `29/32`). However, because frozen `R-M3` includes `M1_REFUTED` as a prerequisite gate, the strict frozen verdict is **`MIXED_DEPENDENCE`** (whereas without the `0.08` split-half gate it would evaluate to `DIRECTIONAL_HURDLE_COUPLING_DOMINANT`).

---

## 3. Day 5 Independent Verification (`R-H2`)

### 3.1 `Gate M0`

- `short_token_67` (`hex`, $n=256$, `burn_in=4`, `B=32`, `seed=4242`): `orig = 5.2576695452444255e-05`, `fast = 5.2576659072656184e-05`, `rel_diff = 6.919375e-07 <= 1e-5` (**PASS**).
- `full_hex_420` (`hex`, $n=2^{16}$, `burn_in=1024`, `B=32`, `seed=5420`): `ref_day23 = 1.541763516854644e-08` (verified directly against `day23/out/hex/mhis.json["420"]["est"]`), `fast = 1.541763694490328e-08`, `rel_diff = 1.152159e-07 <= 1e-4` (**PASS**).

### 3.2 `M12` (`12` Yardstick Tokens), Zero Counts, Pooled Estimates, and `D-043` Smoothed IS Loss

| Distribution (`day23` state) | Estimator | `M12` | Zeros (`/ 12`) | `D-043` `c=1` IS (`max(est, 2^-18)`) | `D-043` `c=1` two-sided IS (`+ 2^-18`) | `flat_and_above` |
|---|---|---:|---:|---:|---:|:---:|
| `hex` (`flat`, $R=1.012$) | `QLD(2^20)` | `1.109097` | `1` | `2.360947` | `0.265617` | — |
| `hex` (`flat`, retained) | `MHIS(2^16)` (`temp=0.67`) | `0.480251` | `0` | `1.976119` | `0.018179` | **`True`** (`1.109 > 0.480`) |
| `camel` (`flat`, $R=1.070$) | `QLD(2^20)` | `1.094520` | `0` | `3.234298` | `1.068883` | — |
| `camel` (`flat`, Day 2–3) | `MHIS(2^16)` (`temp=2.24`) | `inf` | `7` | `1.797257` | `0.117586` | `False` |
| `camel` (`flat`, **Day 5**) | **`MHIS(2^18)` (`temp=2.24`)** | **`0.239570`** | **`4`** | **`1.787587`** | **`0.012992`** | **`True`** (`1.095 > 0.240`) |
| `camel` (`flat`, pooled `327,680`) | `0.2*est_16 + 0.8*est_18` | `0.215466` | `4` | `1.780385` | `0.019330` | `True` (`1.095 > 0.215`) |
| `camel` (`temp=1.0` diagnostic) | `MHIS(2^16)` (`temp=1.0`) | `1.405146` | `1` | `1.758518` | `0.070022` | — |
| `english` (`flat`, $R=1.002$) | `QLD(2^20)` | `0.443507` | `0` | `1.819222` | `0.152917` | — |
| `english` (`flat`, Day 2–3) | `MHIS(2^16)` (`temp=1.5`) | `0.600429` | `4` | `1.608568` | `0.037323` | `False` |
| `english` (`flat`, **Day 5**) | **`MHIS(2^18)` (`temp=1.5`)** | **`0.225220`** | **`2`** | **`1.591145`** | **`0.010128`** | **`True`** (`0.444 > 0.225`) |
| `english` (`flat`, pooled `327,680`) | `0.2*est_16 + 0.8*est_18` | `0.224470` | `2` | `1.596676` | `0.006775` | `True` (`0.444 > 0.224`) |

- **Self-normalized IS internal check:** Across all 36 Day 5 `tok_*.json` files (`camel` $2^{18}$, `english` $2^{18}$, `camel_temp1`), `num_mean / den_mean` matches `est` within `<= 2.1e-16` relative difference.
- **Frozen `R-H2` Verdict:** `flat_and_above_count = 3` (`hex`, `camel`, `english`) `>= 2` $\implies$ **`H2_WRONG_AT_2P18`**. (Even excluding `hex`'s retained $2^{16}$ baseline, the two newly run $2^{18}$ distributions `camel` and `english` alone reach `2 >= 2`.)

---

## 4. Producer Math & Code Audit Findings

### 4.1 `NS-QLD` Normalization (`day45/run_day4_mech.py:109-121, 147-168`) — **VERIFIED EXACT**
- For $n = 2^{20}$ partitioned via stable `mergesort` into $Q = 16$ disjoint equal-count bins $I_0, \dots, I_{15}$ of exact size $B = n / Q = 65{,}536$, the bin-$q$ product-measure estimate is $\hat{p}_q = C_q / B^2$, where $C_q = \sum_{i \in I_q}\sum_{j \in I_q} \mathbf{1}[a_j \in (\text{lower}_i, \text{upper}_i)]$.
- Uniformly averaging the $Q$ equal-mass strata yields:
  $$\hat{p}_{\text{NS}} = \frac{1}{Q}\sum_{q=0}^{Q-1} \frac{C_q}{B^2} = \frac{\sum_{q=0}^{Q-1} C_q}{Q \cdot B^2} = \frac{\text{counts\_ns}}{\text{n\_bins} \cdot \text{bin\_size}^2}.$$
  `denom_ns = float(n_bins) * float(bin_size) * float(bin_size)` ($= n^2 / Q = 68{,}719{,}476{,}736$) is algebraically exact.
- Minor boundary note: line 157 uses `searchsorted(arr_q, uk, "left") - searchsorted(arr_q, lk, "left")`, which counts the half-open interval $[l_i, u_i)$ rather than strictly open $(l_i, u_i)$. Because $a_j$ and $l_i$ are non-degenerate continuous `float32` projections (and for $j = i$, $l_i < a_i < u_i$ strictly iff $t$ is the argmax), measure-zero endpoint ties have no practical effect.

### 4.2 `mhis_fast.py` Equivalence (`W_E[samples]` & Lazy `argmax`) — **VERIFIED EXACT**
- **Embedding-indexed gradient identity (`mhis_fast.py:48-56, 63, 71-80`):** Because $\text{emb}_{b,p} = \sum_v \mathbf{1}[s_{b,p} = v] W_E[v]$, the chain rule gives $\partial \text{score}_b / \partial \text{onehot}_{b,p,v} = (\nabla_{\text{emb}_{b,p}} \text{score}_b) W_E^\top|_v$. Indexing `W_E[samples]` directly and projecting only the mutated position `emb.grad[b_idx, pos] @ W_E.T` is mathematically identical to ARC's dense one-hot forward/backward pass, and `gelu-1l` has no unembed bias `b_U` (`Gate G0` `0.0` diff confirms `Lu = x @ W_U`).
- **Lazy `argmax` & RNG stream (`mhis_fast.py:58-60, 99-110`):** Each MCMC step draws RNG exclusively in `randint` (line 62), `multinomial` (line 66), and `rand` (line 92). Skipping `(x_last @ W_U).argmax(-1)` for `step < burn_in - 1`, computing all `batch_size` rows once after the accept/reject update at `step == burn_in - 1` (and at `step == 0` if `burn_in == 0`), and recomputing only `accept_mask` rows for `step >= burn_in` preserves both the exact PyTorch RNG state sequence and every post-burn-in indicator (`1.15e-7` relative diff across 3,072 steps / 98,304 proposals in `Gate M0`).

### 4.3 `R-M1` Split-Half `0.08` Threshold Behavior & Scientific Interpretation
- **Why `0.08` failed on `english` (`0.0964`) and `hex` (`0.1532`):** At fixed `(mean20, A20, D20)`, $\hat{p}_{S_r}(t)$ on a $2^{20}$ slice depends on the empirical right-tail count of $a_j$ exceeding typical lower hurdles. For rare targets ($p_t \sim 3\times 10^{-8}\text{–}10^{-7}$), only a handful of extreme $a_j$ draws per $2^{20}$ slice populate that tail, creating `1.25x` (`0.096` log10) to `1.42x` (`0.153` log10) Monte Carlo variation between independent $2^{20}$ slices `S1` and `S2` even when both share the **exact same population product-measure bias** (`M32(S0) = 1.027, 1.117, 0.553` vs `M32(S1) = 1.176, 1.191, 0.577` vs `M32(S2) = 1.161, 1.222, 0.506`).
- **Distinguishing frozen rule vs mechanism:** Under the frozen rules, `R-M1 = M1_INCONCLUSIVE` and `R-M2/M3 = MIXED_DEPENDENCE` must be reported unchanged. Scientifically, however, Rival M1 (in-sample/direction-search winner's curse) is clearly ruled out as the source of the upward bias because held-out `S1` error is *slightly higher* than in-sample `S0` on all 3 distributions and 5 fresh direction seeds leave `M32` unchanged within `<= 0.058`. Across distributions, `gelu-1l`'s plateau genuinely reflects **mixed non-linear dependence dominated by directional competitor-hurdle co-movement**: LayerNorm radial coupling accounts for `46.8%` of `M32` on `camel` (`1.117 -> 0.594`) vs `25.5%` on `hex` (`1.027 -> 0.764`) and `20.4%` on `english` (`0.553 -> 0.440`), while substantial residual upward bias (`0.44–0.84` log10) and strong positive tail hurdle co-movement (`26/32`, `31/32`, `29/32` tokens, all $p \le 5.35\times 10^{-4}$) persist everywhere.

### 4.4 Non-Blocking Code & Diagnostic Observations
1. **Latent per-distribution conjunction bug in `analyse_day45.py:78`:** Line 78 computes `m3_dom = m1_ref and (not m2_dom) and (med_delta_hurdle > 0) and (pos_hurdle_tokens >= 22)` per distribution before summing `m3_count`, whereas `day45/PLAN.md` L47 specifies distribution-level `M1_REFUTED` (`>= 2/3`), `NS-QLD` reduction `< 30%` on `>= 2/3`, and positive hurdle shift on `>= 2/3`. Had `english` passed `split_gap <= 0.08`, `M1_REFUTED` (`camel` + `english`) and `NS-QLD < 30%` (`hex` + `english`) would both have held on `2/3` distributions, yet `analyse_day45.py:78` would have yielded `m3_count = 1` (`english` only). On the realized data, `m1_verdict = M1_INCONCLUSIVE`, so this bug is **latent** and does not alter any output verdict.
2. **Floor scale of secondary `c1_loss` (`analyse_day45.py:20-28`):** `day45/PLAN.md` L59 cited `D-043` ($c=1$) without inlining the formula `es = max(est, 2^-18); p/es - ln(p/es) - 1`. Because $2^{-18} = 3.815\times 10^{-6}$ exceeds 9–10 of the 12 ground-truth target probabilities ($p_t \in [3\times 10^{-8}, 10^{-5}]$) while MHIS importance weights resolve $10^{-8}$ probabilities well below $1/n$, clamping $\hat{p}$ at $2^{-18}$ masks `camel_temp1`'s $10^4\times$ downward weight-collapse underestimates (`M12 = 1.405`, yet `c1_loss = 1.759` vs `MHIS(2^18)`'s `1.788` at `M12 = 0.240`). Writeups should treat `M12` and zero counts as the informative metrics on `[1e-9, 1e-5]` and note why `eps = 2^-18` saturates `c1_loss`.
3. **Diagnostic `spearman_rho` strided subsampling (`run_day4_mech.py:181`):** `spearman_rho` is evaluated on `ak_f[::16], lk_f[::16]` (`65,536` strided rows, $\text{SE} \approx 0.0039$) rather than all `1,048,576` rows, whereas the gated `R-M3` statistic `delta_hurdle_sd` (`lines 182-185`) uses all `1,048,576` rows. Also `mean_a_all` on line 189 is unused (`mean(a) == 0` on in-sample `S0` by construction). Neither affects any gated metric or verdict.
4. **Optional `hex` $2^{16}$ `seed = 6000 + t` stability run (`day45/PLAN.md` L53):** Supported in `run_day5_mhis.py:80-84` and `analyse_day45.py:155-161` (`mhis_hex_recheck`) but omitted during container execution beyond the `token = 420` `Gate M0` run. Zero impact on `R-H2`, which froze `hex` at `day23`'s $2^{16}$ yardstick (`0.480`) and already reaches `2/3 >= 2` from `camel` and `english` alone.
