"""Certified log-derivative rows for the nested Li–Liu strip grids.""" import argparse import math import os from concurrent.futures import ProcessPoolExecutor from pathlib import Path import numpy as np from flint import acb, acb_poly, acb_series, arb, ctx from experiment_dyadic import powers_of_five BITS = 112 CACHE = Path(__file__).resolve().parent / ".lake" / "kernel-rows-112-v1" DEGREE = 21 def grid(k): alpha, beta = 1 / arb(1 << k).log(), arb(1) / 8 width = beta - alpha count = 4 * math.ceil(5 / (4 * float(width))) step = arb(5) / count if not (width/2 < step < width): raise ArithmeticError("Unexpected grid spacing") return alpha, width, count, step def node(k, layer, j): alpha, width, _, step = grid(k) return acb(alpha + width * layer / 4, j * step) def row_path(k, layer, j): return CACHE / f"n{k}-layer{layer}-height{j}.npz" def residue_data(k): n = 1 << k result = [] for a0 in powers_of_five(k): for a in (int(a0), n - int(a0)): v = arb(a) / n bin_id = 16 * a // n center = arb(2*bin_id + 1) / 32 result.append((bin_id, v - center, v.log())) return result def polynomials(u): # Expand zeta(u,1+a) around the midpoint of each of 16 bins in a. # For |v-u|<=1/8, Re(v)>0 and |v|<6. For n>=DEGREE the magnitude # of coefficient n is <= 2*binomial(n+5,5). |a-center| <= 1/32. # Successive majorants have ratio <1/2. Cauchy adds 8 for d/du. if not (u.real > arb(1)/8 and abs(u) + arb(1)/8 < 6): raise ArithmeticError("Taylor enclosure outside its proved domain") shift = acb_series([u, 1], prec=2) out = [] for idx in range(16): center = 1 + arb(2*idx + 1)/32 factor = acb_series([1], prec=2) co, dc = [], [] for n in range(DEGREE): val = factor * (shift + n).zeta(center) co.append(val[0]) dc.append(val[1]) factor = -factor * (shift + n) / (n+1) out.append((acb_poly(co), acb_poly(dc))) return out def certified_transform(data, n, s): u = s + arb(1)/2 polys = polynomials(u) er = 4*math.comb(DEGREE+5, 5) / arb(32)**DEGREE value_error = acb(arb(0, er), arb(0, er)) deriv_error = acb(arb(0, 8*er), arb(0, 8*er)) values, derivatives = [], [] for j in range(0, len(data), 2): pair = [] for bin_id, offset, log_a in (data[j], data[j+1]): poly, dpoly = polys[bin_id] lead = (-u * log_a).exp() pair.append((lead + poly(offset), dpoly(offset) - log_a * lead)) values.append(pair[0][0] - pair[1][0] + 2*value_error) derivatives.append(pair[0][1] - pair[1][1] + 2*deriv_error) log_n = arb(n).log() den, num = acb.dft(values), acb.dft(derivatives) if any(z.contains(0) for z in den): raise ArithmeticError("Nonvanishing check failed") return [d/z - log_n for d,z in zip(num, den)] _worker_data = {} def write_row(job): k, layer, j = job ctx.prec = BITS path = row_path(k, layer, j) if path.exists(): return if k not in _worker_data: _worker_data.clear() _worker_data[k] = residue_data(k) s = node(k, layer, j) raw = certified_transform(_worker_data[k], 1 << k, s) # Cache midpoints plus a rigorously outward-rounded common error bound # for the entire weighted row. A negative height permutes and conjugates. balls = [z/(1+s) for z in raw] centers = np.array([complex(z) for z in balls]) radii = [abs(z-acb(m)).upper() for z,m in zip(balls, centers)] radius = math.nextafter(float(max(radii)), math.inf) if not math.isfinite(radius): raise ArithmeticError("Nonfinite row radius") tmp = path.with_suffix(f".{os.getpid()}.npz") np.savez(tmp, centers=centers, radius=radius) tmp.replace(path) def prepare(levels, workers): CACHE.mkdir(parents=True, exist_ok=True) with ProcessPoolExecutor(workers) as pool: for k in levels: count = grid(k)[2] jobs = [(k, layer, j) for layer in (1, 3) for j in range(count+1)] for _ in pool.map(write_row, jobs, chunksize=2): pass print(f"Certified all {len(jobs)} nonnegative-height rows for k={k}", flush=True) if __name__ == "__main__": parser = argparse.ArgumentParser() parser.add_argument("--levels", type=int, nargs="+", default=[15,16,17,18]) parser.add_argument("--workers", type=int, default=6) args = parser.parse_args() ctx.prec = BITS prepare(args.levels,args.workers)