#!/usr/bin/env python """Look-elsewhere arithmetic and the paper's own side-peak mismatches. No event list is used. Run: python -I 04_lookelsewhere.py Writes ../out/lookelsewhere.json """ import json import math import os import re import sys import numpy as np sys.path.insert(0, os.path.dirname(os.path.abspath(__file__))) import rr_core as rr # noqa: E402 # ------------------------------------------------------------------------------------------------- # 1. The planetary arithmetic # ------------------------------------------------------------------------------------------------- V, E, J = 224.701, 365.256, 4332.589 # sidereal periods, NASA NSSDC fact sheets, days def syn(a, b): return 1.0 / abs(1.0 / a - 1.0 / b) P_VE, P_EJ, P_VJ = syn(V, E), syn(E, J), syn(V, J) f_VE, f_EJ, f_VJ = 1 / P_VE, 1 / P_EJ, 1 / P_VJ arith = dict( P_VE=P_VE, P_EJ=P_EJ, P_VJ=P_VJ, quarter_VE=P_VE / 4, quarter_EJ=P_EJ / 4, quarter_VJ=P_VJ / 4, half_VE=P_VE / 2, half_EJ=P_EJ / 2, half_VJ=P_VJ / 2, P84=0.5 / (f_VE + f_VJ), P74=0.5 / (f_EJ + f_VJ), P629=0.5 / (f_EJ - f_VE), sum_rule_fVJ_minus_fVE_minus_fEJ=f_VJ - f_VE - f_EJ, schwabe_from_lattice_3f3_minus_2f2=1 / abs(3 * 2 * f_VE - 2 * 2 * f_EJ), ) # f2 = 2 f_EJ, f3 = 2 f_VE: every one of the nine is a f2 + b f3 with small integers f2, f3 = 2 * f_EJ, 2 * f_VE lattice = {n: 1 / (rr.COEF[n][0] * f2 + rr.COEF[n][1] * f3) for n in rr.NAMES} # ------------------------------------------------------------------------------------------------- # 2. Independent frequencies # ------------------------------------------------------------------------------------------------- nind = {} for span in (25000.0, 17000.0): nind[str(int(span))] = { "20_to_9000": (1 / 20.0 - 1 / 9000.0) * span, "20_to_850": (1 / 20.0 - 1 / 850.0) * span, "50_to_850": (1 / 50.0 - 1 / 850.0) * span, "50_to_350": (1 / 50.0 - 1 / 350.0) * span, } a = nind[str(int(span))] a["expected_z_over_4.61_20_to_9000"] = a["20_to_9000"] * math.exp(-4.61) a["expected_z_over_6.91_20_to_9000"] = a["20_to_9000"] * math.exp(-6.91) # ------------------------------------------------------------------------------------------------- # 3. How much of the axis counts as near a predicted period # ------------------------------------------------------------------------------------------------- lines = 1 / np.array([rr.PERIODS[n] for n in rr.NAMES]) core = rr.CORE_OFF full = rr.FULL_OFF def coverage(offsets, tol, tmin, tmax, extra_lines=None): fg = np.linspace(1 / tmax, 1 / tmin, 2_000_001) cov = np.zeros(fg.size, dtype=bool) for f in lines: for d in offsets: lo, hi = f + d - tol, f + d + tol i0, i1 = np.searchsorted(fg, [lo, hi]) cov[i0:i1] = True freq_share = cov.mean() # linear in period, as the paper's panels are drawn: weight each frequency step by dT = df / f^2 w = 1 / fg ** 2 period_share = (cov * w).sum() / w.sum() return float(freq_share), float(period_share) cov = {} for rule, off in (("central_only", np.array([0.0])), ("core", core), ("full", full)): for tname, tol in (("1/25000", 1 / 25000.0), ("1/17000", 1 / 17000.0), ("3.4/25000", 3.4 / 25000.0)): for tmin, tmax in ((50, 350), (50, 850), (20, 350), (20, 850)): fs, ps = coverage(off, tol, tmin, tmax) cov[f"{rule}|tol={tname}|T={tmin}-{tmax}"] = dict(frequency_share=fs, linear_period_share=ps) # windows per predicted period, in independent frequencies, and the chance of a hit under independence hit = {} for rule, off in (("central_only", np.array([0.0])), ("core", core), ("full", full)): for tname, tol in (("1/25000", 1 / 25000.0), ("1/17000", 1 / 17000.0)): M = len(off) * 2 * tol * 25000.0 # independent frequencies, ignoring overlap # union width allowing for overlaps, at one line ivs = sorted((d - tol, d + tol) for d in off) width = 0.0 cur_lo, cur_hi = ivs[0] for lo, hi in ivs[1:]: if lo <= cur_hi: cur_hi = max(cur_hi, hi) else: width += cur_hi - cur_lo cur_lo, cur_hi = lo, hi width += cur_hi - cur_lo M_union = width * 25000.0 row = dict(M_no_overlap=M, M_union=M_union) for theta in (4.61, 6.91): for kappa in (1.0, 2.0, 3.0, 5.0): p1 = 1 - (1 - math.exp(-theta / kappa)) ** M_union row[f"p_one_period_theta{theta}_kappa{kappa:g}"] = p1 row[f"p_all_nine_theta{theta}_kappa{kappa:g}"] = p1 ** 9 hit[f"{rule}|tol={tname}"] = row # ------------------------------------------------------------------------------------------------- # 4. The paper's own side peaks against its stated theoretical values # ------------------------------------------------------------------------------------------------- tex = open(os.path.join(rr.DL, "arxiv-2610.16428", "src-extracted", "stefani.tex"), encoding="utf-8").read() rows = [] pat = re.compile(r"\$P\^\*_\{([^}]*)\}=([\d.]+)\$&&\$P_\{[^}]*\}=(.*?)=([\d.]+)\$\s*\\\\") for m in pat.finditer(tex): label, obs, expr, theo = m.groups() rows.append(dict(label=label, observed=float(obs), theory=float(theo), expr=expr)) tables = re.split(r"\\begin\{table\}", tex)[1:] per_table = [] for t in tables: cap = re.search(r"\\caption\{(.*?)\}", t, flags=re.S).group(1) name = re.search(r"P_\{?(\d+)\}?\s*=\s*([\d.]+)", cap) r = [dict(label=a, observed=float(b), theory=float(d)) for a, b, c, d in pat.findall(t)] for x in r: x["mismatch_in_1_over_25000"] = abs(1 / x["observed"] - 1 / x["theory"]) * 25000 x["mismatch_days"] = abs(x["observed"] - x["theory"]) x["tolerance_days_T2_over_25000"] = x["theory"] ** 2 / 25000 per_table.append(dict(period=name.group(0) if name else cap[:40], rows=r)) allr = [x for t in per_table for x in t["rows"]] mm = np.array([x["mismatch_in_1_over_25000"] for x in allr]) summary = dict( n_side_peaks=len(allr), n_within_1=int((mm <= 1).sum()), n_within_2=int((mm <= 2).sum()), max=float(mm.max()), median=float(np.median(mm)), ) # the paper's "inferred" central period: check that its formula is an average of the pair's frequencies pair_check = [] # (upper, lower, stated centre, stated modulator, harmonic factor k, label) for up, low, stated, smod, k, label in [ (508, 848, 635.4, 2534, 1, "Table 1, P629, T pair"), (262, 330, 292.1, 2543, 1, "Table 2, P292, T pair"), (275, 309, 291.1, 4998, 1, "Table 2, P292, S pair"), (285, 300, 292.3, 11400, 1, "Table 2, P292, H pair"), (182.5, 218, 198.7, 2241, 1, "Table 3, P199, T pair"), (191.5, 207.5, 199.2, 4967, 1, "Table 3, P199, S pair"), (134, 159, 146.0, 2108, 1, "Table 4, P146, Q pair"), (136.7, 156, 145.7, 2210, 1, "Table 4, P146, T pair"), (141.5, 152.7, 146.9, 3858, 1, "Table 4, P146, S pair"), (144.3, 149.8, 147.0, 7860, 1, "Table 4, P146, H pair"), (113.6, 125.4, 119.2, 2414, 1, "Table 5, P118, T pair"), (116.0, 122.8, 119.3, 3858, 1, "Table 5, P118, S pair"), (82.1, 85.8, 83.9, 3807, 1, "Table 7, P84, S pair"), (73.4, 75.7, 74.5, 4831, 1, "Table 8, P74, S pair"), (57.0, 61.1, 59.0, 1699, 1, "Table 9, P59, T pair"), (55.7, 62.0, 58.7, 2192, 2, "Table 9, P59, 2T pair"), (54.5, 63.1, 58.5, 2399, 3, "Table 9, P59, 3T pair"), ]: cen = 2 / (1 / up + 1 / low) mod = 2 * k / (1 / up - 1 / low) pair_check.append( dict( label=label, upper=up, lower=low, stated_centre=stated, computed_centre=round(cen, 2), stated_modulator=smod, computed_modulator=round(mod, 1), centre_differs=abs(cen - stated) > 0.11, modulator_differs=abs(mod - smod) > 0.01 * smod, ) ) # what the Table 4 Q row returns if the theoretical pair is put into the formula instead q_theory = dict( centre=2 / (1 / 136.5 + 1 / 156.8), modulator=2 / (1 / 136.5 - 1 / 156.8), ) rr.save_json( os.path.join(rr.OUT, "lookelsewhere.json"), dict( planetary_arithmetic=arith, lattice_periods=lattice, independent_frequencies=nind, coverage=cov, chance_of_a_hit=hit, mismatch_summary=summary, mismatch_by_table=per_table, inferred_centre_check=pair_check, table4_q_row_from_theoretical_pair=q_theory, ), ) print(summary) for t in per_table: print(t["period"], [(x["observed"], x["theory"], round(x["mismatch_in_1_over_25000"], 2)) for x in t["rows"]]) for p in pair_check: print(p) print(q_theory)