#!/usr/bin/env python3 """0029 probe — is `CapEngine.survival` the density grid `d_j`, or the (2.2) cell mass? The inherited finding (cell-mass-discrepancy.md) asserts that `CapEngine.survival` returns `outward_dickman_grid`'s density enclosure `d_j` and that `weighted` consumes it directly. But `survival` is rows = [nonnegative((a / self.h).union(b / self.h), arb(1)) for a, b in grid.conditional_cell_masses()] and `conditional_cell_masses` yields (h, h) for j < cap_index and (h/2*(lo_j+lo_{j+1}) - h^3/(12c^2), h/2*(hi_j+hi_{j+1})) beyond — i.e. the *trapezoid*, which is the paper's (2.2) `A_j(c)`. This probe compares the three candidate objects directly: `grid.lower[j]`, `(grid.lower[j]+grid.lower[j+1])/2`, and the engine's own `survival(cap)`. """ from __future__ import annotations import importlib.util from fractions import Fraction as F from pathlib import Path HERE = Path(__file__).resolve().parent CERTIFICATE = HERE / "repo" / "prime_gap_186_certificate.py" def load(): spec = importlib.util.spec_from_file_location("pg186_certificate", CERTIFICATE) module = importlib.util.module_from_spec(spec) spec.loader.exec_module(module) module.check_flint_signed_fft = lambda: None module._cap_check_environment = lambda: None return module def main() -> int: module = load() engine = module.CapEngine() print("n = %d k = %d fixed_bits = %d" % (engine.n, engine.k, engine.fixed_bits)) for i, shell in enumerate(engine.outer_shells): cap = shell.ceiling aligned = engine.aligned_cap(cap) grid = module.outward_dickman_grid(cap=aligned, step=engine.hq, count=engine.n) M = grid.cap_index surv = engine.survival(cap) print() print("shell %d cap = %s aligned = %s M = %d" % (i, cap, aligned, M)) print(" %8s %16s %16s %16s %16s" % ("j", "grid.lower[j]", "trapz(d_j,d_j+1)", "survival_j", "surv-trapz")) for j in (M - 2, M - 1, M, M + 1, M + 2, M + 100, 98262): if j < 0 or j + 1 >= engine.n: continue d0 = float(grid.lower[j].lower()) d1 = float(grid.lower[j + 1].lower()) trapz = 0.5 * (d0 + d1) sv = float(surv[j].lower()) print(" %8d %16.12g %16.12g %16.12g %16.3g" % (j, d0, trapz, sv, sv - trapz)) return 0 if __name__ == "__main__": raise SystemExit(main())