"""Independent float model of the pinned-small-prime construction (fitting only; not rigorous). Representation: a function on [0,1] by its cell values on N cells (cell i = (i/N,(i+1)/N)). conv(a,b) of two step functions is piecewise linear; we return vertex values V[0..N] (V[n] = (1/N) sum_{i+j=n-1} a_i b_j) and use cell value (V[n]+V[n+1])/2. Notation for the independent calculation: bins b=0..k-1, bin 0 = small (eta, alpha'), others rough partition of (alpha',1/2). K_v = conv_i (k_i^{*v_i}/v_i!), k_i = 1/t on bin i. L_d = sum_{v<=d} (-1)^{|v|} K_v * (chi K_{d-v}), chi = 1_{(1/2,inf)}. T_d = (-1)^{|d|} K_d + sum_{v<=d} (-2)^{|v|} K_v * (chi K_{d-v}). giant value at observer z (counts), giant y: f_z(y) = -y [sum_{r>=z} c_r L_{r-z}(y) + h-part]. """ import numpy as np from itertools import product from fractions import Fraction as Fr from scipy.signal import fftconvolve def sub(a, b): return tuple(x - y for x, y in zip(a, b)) def add(a, b): return tuple(x + y for x, y in zip(a, b)) def leq(a, b): return all(x <= y for x, y in zip(a, b)) def subvecs(r): return product(*(range(a + 1) for a in r)) class Model: def __init__(self, edges, N, prof={2: 1, 3: -1}): self.edges = [Fr(e) for e in edges] self.N = N self.k = len(edges) - 1 self.prof = prof for e in self.edges: assert (e * N).denominator == 1, 'edges must be mesh points' self.cut = [int(e * N) for e in self.edges] self.half = N // 2 assert self.cut[-1] == self.half lo = self.edges[:-1]; hi = self.edges[1:] self.lo, self.hi = lo, hi # free vectors (all parts in bins, total one feasible) def rec(i, rem): if i == self.k: yield (); return for n in range(int(rem / lo[i]) + 1): for t in rec(i + 1, rem - n * lo[i]): yield (n,) + t self.free = [r for r in rec(0, Fr(1)) if sum(a * b for a, b in zip(r, lo)) < 1 < sum(a * b for a, b in zip(r, hi))] self.zero = (0,) * self.k self.e0 = (1,) + (0,) * (self.k - 1) self.obs = [z for z in rec(0, Fr(1, 2)) if any(z) and sum(a * b for a, b in zip(z, lo)) < Fr(1, 2)] self.base = {} idx = np.arange(N) for b in range(self.k): a = np.zeros(N) ix = idx[self.cut[b]:self.cut[b + 1]] a[ix] = N * np.log((ix + 1) / ix) self.base[b] = a self.Kc = {} # cell values self.Kv = {} # vertex values (point values), for evaluation at 1 self._build() def conv(self, a, b): N = self.N full = fftconvolve(a, b)[:N] / N # full[m] = (1/N) sum_{i+j=m} a_i b_j V = np.zeros(N + 1) V[1:] = full return V @staticmethod def cellof(V): return 0.5 * (V[:-1] + V[1:]) def chi(self, a): b = a.copy(); b[:self.half] = 0; return b def _build(self): N = self.N allv = set() for r in self.free: for v in subvecs(r): allv.add(v) self.allv = sorted(allv, key=lambda v: (sum(v), v)) Kc = self.Kc; Kv = self.Kv Kc[self.zero] = None for v in self.allv: if v == self.zero: continue i = next(i for i in range(self.k) if v[i]) u = list(v); u[i] -= 1; u = tuple(u) if u == self.zero: Kc[v] = self.base[i].copy() V = np.zeros(N + 1) # point values of 1/t on bin Kv[v] = None else: V = self.conv(Kc[u], self.base[i]) / v[i] Kv[v] = V Kc[v] = self.cellof(V) # L_d and T_d as vertex arrays (on y>1/2 only meaningful) and point value at 1 self.L = {}; self.T = {} for d in self.allv: L = np.zeros(N + 1); T = np.zeros(N + 1) if d != self.zero and sum(d) >= 2: # v = 0 term: chi K_d (vertex values; use Kv if available) Kd = Kv[d] if Kd is not None: ch = Kd.copy(); ch[:self.half] = 0 # keep right limit at 1/2 # careful: vertex at exactly 1/2 belongs to boundary; set 0 L += ch; T += ch + (-1) ** sum(d) * Kd * (np.arange(N + 1) >= self.half) for v in subvecs(d): if v == self.zero or v == d: continue w = sub(d, v) if sum(w) < 2: continue # chi K_w = 0 for single part (<1/2) cv = self.conv(Kc[v], self.chi(Kc[w])) L += (-1) ** sum(v) * cv T += (-2) ** sum(v) * cv self.L[d] = L; self.T[d] = T # ---------- single rough bin kernels for the profile ---------- def rough_kernels(self, jmax=3): N = self.N r = np.zeros(N); idx = np.arange(N) ix = idx[self.cut[1]:self.half] r[ix] = N * np.log((ix + 1) / ix) Rc = {0: None, 1: r}; Rv = {1: None} for j in range(2, jmax + 1): V = self.conv(Rc[j - 1], r) / j Rv[j] = V; Rc[j] = self.cellof(V) self.Rc, self.Rv = Rc, Rv # T^R_j on y>1/2: (-1)^j R_j + chi R_j + sum_{v=1}^{j-1} (-2)^v R_v * chi R_{j-v} TR = {} for j in range(2, jmax + 1): T = (1 + (-1) ** j) * Rv[j] * (np.arange(N + 1) >= self.half) for v in range(1, j): if j - v < 2: continue T = T + (-2) ** v * self.conv(Rc[v], self.chi(Rc[j - v])) TR[j] = T self.TR = TR # L^R_m: m=2: chi R_2 ; m=3: chi R_3 - R_1*chi R_2 LR = {0: np.zeros(N + 1), 1: np.zeros(N + 1)} gt = (np.arange(N + 1) >= self.half) LR[2] = Rv[2] * gt LR[3] = Rv[3] * gt - self.conv(Rc[1], self.chi(Rc[2])) self.LR = LR # diagonal B(s) on small-bin cells: s cell i -> t = 1-s in cell N-1-i ; use cell value B = np.zeros(N) for j, w in self.prof.items(): B += w * self.cellof(TR[j])[::-1] # B[i] = value at cell N-1-i self.B = B return B