Does light charge the quons? › Files cited on the page › check_trial24_fable/
r33_xuma_ext.py
#!/usr/bin/env python3
"""r33 Xu-Ma extension: (1) count with the published-line tolerance; (2) a null test of the pattern AS CLAIMED:
all 13 points covered by three PARALLEL lines (one slope, three free intercepts) within a tolerance.
Own code. Same Table 1 as r33_xuma.py."""
import math, sys, os, numpy as np
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
from r33_xuma import T
y = np.array([t[5] for t in T]); K = np.array([t[6] for t in T])
pub_b, pub_a = 2.78, -10.7
res = y - (pub_a + pub_b * K)
main8 = sorted(np.argsort(np.abs(res))[:8])
def max_on_line(xv, yv, tol):
n = len(xv); best = 0
for i in range(n):
for j in range(i + 1, n):
if xv[j] == xv[i]: continue
s = (yv[j] - yv[i]) / (xv[j] - xv[i])
if s <= 0: continue
c = yv[i] - s * xv[i]
best = max(best, int((np.abs(yv - (c + s * xv)) <= tol).sum()))
return best
tol_pub = float(np.abs(res[main8]).max())
print(f"Published-line tolerance {tol_pub:.3f} s: real data max on a positive line = {max_on_line(K, y, tol_pub)}")
for tol in (1.0, 1.5, 2.0):
print(f" tolerance {tol} s: real data max on a positive line = {max_on_line(K, y, tol)}")
# Residuals of the five off-mainline points from Xu-Ma's two parallel lines
up, low = -0.47, -20.77
print("Off-mainline residuals from the published parallel lines (upper -0.47, lower -20.77):")
for i in range(13):
if i in main8: continue
r_up = y[i] - (up + pub_b * K[i]); r_low = y[i] - (low + pub_b * K[i])
print(f" {T[i][0]:12s} upper {r_up:+.2f} lower {r_low:+.2f}")
def cover_parallel(xv, yv, tol, nlines=3, slopes=None):
"""Largest number of points covered by nlines parallel lines of common positive slope within tol.
Candidate slopes: through every pair. For each slope, intercepts c_i = y_i - s x_i; cover greedily by
windows of width 2 tol (optimal for 1-D interval covering by sorting)."""
n = len(xv); best = 0
cands = []
for i in range(n):
for j in range(i + 1, n):
if xv[j] != xv[i]:
s = (yv[j] - yv[i]) / (xv[j] - xv[i])
if s > 0: cands.append(s)
for s in cands:
c = np.sort(yv - s * xv)
# dynamic: max points covered by nlines windows of width 2*tol
m = len(c)
# precompute for each start index the end index covered
ends = np.searchsorted(c, c + 2 * tol, side='right')
# dp over lines
# best[k][i] = max covered using k windows among points i..end
dp = np.zeros((nlines + 1, m + 1), dtype=int)
for k in range(1, nlines + 1):
for i in range(m - 1, -1, -1):
dp[k][i] = max(dp[k][i + 1], (ends[i] - i) + dp[k - 1][ends[i]])
best = max(best, int(dp[nlines][0]))
return best
tol3 = 1.25
real3 = cover_parallel(K, y, tol3)
print(f"\nThree parallel lines, tolerance {tol3} s: real data cover {real3} of 13 (the paper's own arrangement covers all 13 within +-1.22 s)")
rng = np.random.default_rng(33)
N = 4000
for nl in (1, 2, 3):
cnt = np.array([cover_parallel(K, rng.permutation(y), tol3, nlines=nl) for _ in range(N)])
realn = cover_parallel(K, y, tol3, nlines=nl)
print(f" {nl} parallel line(s), tol {tol3}: real = {realn}; permutation null P(>= real) = {(cnt >= realn).mean():.4f}; "
f"mean {cnt.mean():.2f}; P(>=13) = {(cnt>=13).mean():.4f}, P(>=12) = {(cnt>=12).mean():.4f}, P(>=11) = {(cnt>=11).mean():.4f}")