# Recompute H0 from a frozen TDCOSMO slice

This folder recomputes the Hubble constant lens by lens from the seven
TDCOSMO lenses in Table 2 of TDCOSMO IV (Birrer et al. 2020,
arXiv:2007.02941v3, A&A 643, A165). It shows how far H0 moves when you
change the external convergence, an internal mass sheet, the mass slope or
the matter density. It does **not** repeat the paper's hierarchical
inference.

## Files

| File | What it is |
| --- | --- |
| `tdcosmo-iv-table2.json` | Input. Table 2 transcribed by hand: redshifts, Einstein radius, slope, external convergence and the power-law time-delay distance, each as `[median, minus, plus]`. Also the published H0 values used for comparison. |
| `reproduce.py` | The script. Python 3 standard library only. |
| `expected-outputs.json` | The outputs we got, rounded to three decimals. |
| `provenance.json` | SHA-256 checksums, Python version and units. |

## Run

```bash
python3 reproduce.py           # prints tables, writes outputs.json in the current folder
python3 reproduce.py --check   # also fails if outputs differ from expected-outputs.json
```

Tested with Python 3.9.6. No packages are needed.

## Units

Angles in arcseconds, distances in Mpc, H0 in km s^-1 Mpc^-1. Cosmology is
flat Lambda-CDM with Omega_m = 0.3 unless a sensitivity case changes it.

## Steps

1. For each lens, the flat Lambda-CDM time-delay distance at H0 = 70 is
   integrated numerically. Because D_dt is proportional to 1/H0, the H0 that
   matches Table 2 is `70 * D_dt(70) / D_dt^pl`.
2. The line of sight is applied as `H0 -> (1 - kappa_ext) H0`
   (TDCOSMO IV Eqs. 29 and 32).
3. The lenses are combined with inverse-variance weights.
4. An internal mass sheet multiplies the result by `lambda_int`
   (TDCOSMO IV Eq. 34), using the population means of Table 6:
   1.02 for TDCOSMO alone and 0.91 for TDCOSMO + SLACS.

## Results (from `expected-outputs.json`)

| Case | H0 |
| --- | --- |
| Power law times (1 - kappa_ext), no internal sheet | 74.2 ± 1.6 |
| times lambda_int = 1.02 | 75.7 ± 6.5 |
| times lambda_int = 0.91 | 67.5 ± 3.3 |

Published, for comparison: H0LiCOW 73.3 (+1.7/-1.8) from six lenses;
TDCOSMO only 74.5 (+5.6/-6.1); TDCOSMO + SLACS 67.4 (+4.1/-3.2).

A slope shift of ±0.05 for every lens moves H0 by ±5.3 percent. Changing
Omega_m from 0.3 to 0.25 or 0.35 moves it by less than 0.3 percent.

## Known errors and limits

- Asymmetric intervals are replaced by their mean half-width and treated as
  Gaussian. The paper uses full posteriors.
- Lenses are treated as independent. Shared systematics are ignored.
- The slope scaling `H0 ∝ gamma - 1` is the near-ring approximation of
  Kochanek (2002), Eq. 8. It holds at fixed image positions and is a rough
  guide, not a model refit.
- Stellar kinematics, anisotropy and the lens-distance constraint are not
  used. They are what fixes lambda_int in the paper; here lambda_int is
  copied in.
- Table 2 was transcribed by hand from the ar5iv HTML rendering. Check it
  against the PDF before you rely on a digit.

## Failure cases to try

- **Ignore the line of sight.** Setting kappa_ext to zero gives 76.8, about
  2.7 units higher. The sample's mean kappa_ext is positive (0.035 in
  TDCOSMO IV, Section 5.1), so ignoring it biases H0 up.
- **Use one lens.** RXJ1131-1231 alone gives 78.1. One lens carries its own
  mass-model and environment errors.
- **Drop the lens H0LiCOW did not use.** Leaving out DES0408-5354 gives
  73.9 with the other six lenses, close to the H0LiCOW XIII value.
- **Edit an input.** Change a distance or kappa_ext digit in
  `tdcosmo-iv-table2.json` and `--check` fails. Any edit at all breaks the
  checksums in `provenance.json`.
