# Independent re-derivation: r3-b1-17 and r3-b1-37, Delhi (holdout state)

Date: 2026-08-05. Purpose: independent re-derivation of two rung-3 Popper Engine validation
values for Delhi, per the registration's near-threshold protocol. This computation was performed
**without opening** `docs/generated/popper_v2_rung3_validation_delhi_*` (the machine's own
values/report files for Delhi) at any point. The only inputs read were the two frozen pinned
instruments:

- `docs/generated/popper_v2_rung3_pinned_instruments_b.json`, conjecture `r3-b1-17` (note: the
  task that requested this re-derivation named `_a.json` as r3-b1-17's location; `_a.json` only
  contains conjectures 01–14, so the instrument was located in `_b.json`, which covers 15–28 —
  the correct frozen instrument for r3-b1-17. This is a pinned-instrument file of the same kind
  as `_a.json`/`_c.json`, containing only the 11 training states' values, no Delhi/holdout data,
  so independence with respect to Delhi is preserved.)
- `docs/generated/popper_v2_rung3_pinned_instruments_c.json`, conjecture `r3-b1-37`.

Neither instrument carries an `amended_at_registration` enrichment-exclusion tag (unlike e.g.
r3-b1-01/08/35/40 in the same files), so both frozen queries below are run as pinned, with
`<STATE_ID>` substituted for Delhi (`raw->>'holding_state_id'='10'`).

DB accessed: `docker exec inferopedia-db-1 psql -U inferopedia -d inferopedia`, prod, read-only
(SELECT/SET only, no writes). `SET enable_indexscan=off` issued before all JSONB-scan queries per
the instruments' own methodology note. Delhi total row count under `source_id=51 AND
raw->>'holding_state_id'='10'`: **51,704**.

---

## r3-b1-17 — full-distribution log(rank)-log(count) OLS slope

Statement: "[CONDITIONAL] Full-distribution log(rank)-log(count) OLS slope is in [-3.0,-0.3] in
every complete state (heavy-tailed shape, independent of concentration LEVEL)." Band: **[-3.0,
-0.3]**.

### Exact SQL run

```sql
SET enable_indexscan=off;

WITH ranked AS (
  SELECT raw->>'institute_raw' inst, count(*) n,
         ROW_NUMBER() OVER (ORDER BY count(*) DESC) rk
  FROM scriptome_manuscriptrecord
  WHERE source_id=51 AND raw->>'holding_state_id'='10'
    AND raw->>'institute_raw' IS NOT NULL AND raw->>'institute_raw' != ''
  GROUP BY 1
),
capped AS (
  SELECT *, count(*) OVER () AS n_institutions FROM ranked
),
stats AS (
  SELECT regr_count(ln(n::float8), ln(rk::float8)) AS npoints,
         regr_slope(ln(n::float8), ln(rk::float8)) AS slope,
         regr_r2(ln(n::float8), ln(rk::float8)) AS r2,
         regr_sxx(ln(n::float8), ln(rk::float8)) AS sxx,
         regr_syy(ln(n::float8), ln(rk::float8)) AS syy,
         regr_sxy(ln(n::float8), ln(rk::float8)) AS sxy
  FROM capped WHERE rk <= LEAST(500, n_institutions)
)
SELECT npoints, slope, r2, sxx, syy, sxy,
       sqrt( (syy - slope*sxy) / (npoints-2) / sxx ) AS se
FROM stats;
```

(SE computed via the instrument's own documented client-side identity:
`SE(slope) = sqrt( (syy - slope*sxy)/(npoints-2) / sxx )`, evaluated here inside the same query.)

Context query (distinct `institute_raw` count in Delhi, before the `LEAST(500, n_institutions)`
cap): **n_institutions = 76** — below 500, so the cap did not truncate; all 76 Delhi institutions
were used.

### Raw output

| npoints | slope | SE | R² | sxx | syy | sxy |
|---|---|---|---|---|---|---|
| 76 | -2.7131773589619166 | 0.09966640958915268 | 0.909210158607444 | 62.70220656278677 | 507.66230059180623 | -170.12220720310637 |

### Independent cross-check (separate implementation)

The Postgres `regr_*` aggregates above are one implementation of the frozen query. As a second,
fully independent implementation, the raw capped `(rk, n)` pairs (76 rows, `rk` 1..76) were
exported directly from the same `ranked`/`capped` CTEs (no `regr_*` functions) and OLS was
recomputed from scratch in Python (manual `Sxx`/`Syy`/`Sxy`, `slope = Sxy/Sxx`, `R² =
Sxy²/(Sxx·Syy)`, same SE identity):

```
npoints = 76
slope   = -2.7131773589619157
se      = 0.09966640958915317
r2      = 0.9092101586074431
sxx     = 62.702206562786785
syy     = 507.66230059180646
sxy     = -170.12220720310634
```

Agrees with the Postgres `regr_*` output to ~12 significant figures (differences confined to
floating-point noise in the 15th digit). Both computations used the identical 76-row Delhi
`(rank, count)` distribution.

### Result and band position

- **slope = -2.71318** (rounded from -2.7131773589619166)
- **SE = 0.09967**
- **R² = 0.90921**
- **n_points = 76**
- Band: [-3.0, -0.3], width 2.7.
- Numeric position: slope is **0.28682 above the lower edge (-3.0)** and **2.41318 below the
  upper edge (-0.3)** — i.e. located 10.62% of the band width up from the -3.0 edge (89.38% of
  the way toward the -0.3 edge, measuring from -3.0).

Runtime: n_institutions context query 32.60s; regression query 33.66s (both against the live
51,704-row Delhi slice under `SET enable_indexscan=off`, no temp table).

---

## r3-b1-37 — distinct count of `raw->>'language_raw'` in Delhi

Statement: "Every complete state's records span between 30 and 160 distinct raw.language_raw
values." Band: **[30, 160]**.

### Exact SQL run (frozen query, literal form)

```sql
SET enable_indexscan=off;

SELECT count(DISTINCT raw->>'language_raw') AS distinct_language_count
FROM scriptome_manuscriptrecord
WHERE source_id=51 AND raw->>'holding_state_id'='10';
```

Result: **33**. Runtime: 8.62s.

### Verification query (explicit non-null/non-empty filter + composition check)

The frozen query's `count(DISTINCT ...)` already excludes SQL `NULL` by standard semantics, but
does **not** exclude an empty string `''` (a non-NULL value distinct from any language name). The
task's framing ("count of distinct non-null/non-empty ... values") is stricter than the literal
frozen SQL text on this point, so both were computed:

```sql
SELECT
  count(DISTINCT raw->>'language_raw') FILTER (WHERE raw->>'language_raw' IS NOT NULL AND raw->>'language_raw' != '') AS strict_nonnull_nonempty_count,
  count(*) FILTER (WHERE raw->>'language_raw' = '') AS empty_string_rows,
  count(*) FILTER (WHERE raw->>'language_raw' IS NULL) AS null_rows
FROM scriptome_manuscriptrecord
WHERE source_id=51 AND raw->>'holding_state_id'='10';
```

Result: **strict_nonnull_nonempty_count = 32**, empty_string_rows = 1162, null_rows = 0. Runtime:
15.01s.

So Delhi has 0 NULL `language_raw` rows and 1162 rows where `language_raw` is present but equals
`''`; that empty string is itself one of the 33 values the literal frozen query counts as
"distinct." Excluding it (per the task's explicit non-null/non-empty framing) gives 32.

### Result and band position

- **Frozen-query literal value = 33.** Band [30, 160], width 130. Numeric position: 3 above the
  lower edge (30), 127 below the upper edge (160) — 2.31% of the band width up from the floor.
- **Strict non-null/non-empty value = 32.** Numeric position: 2 above the lower edge (30), 128
  below the upper edge (160) — 1.54% of the band width up from the floor.

Both candidate values sit within 2-3 units of the 30-floor — the closest-to-floor margin of the
two figures re-derived in this pass.
