"""Independent exact checks of E(rho_1(T)^k), for k=1,2,3. T_j has law Bin(2s,1/2)-s. The computation conditions on the normalized column types of a k by a sign matrix. No quadrature is used. Only the standard library is required. These finite checks supplement, and do not prove, the uniform moment estimate in the paper. """ from fractions import Fraction from math import comb, factorial, log, exp from itertools import permutations from pathlib import Path import json def moment(k, a, s): if k == 1: return Fraction(comb(2*a*s, a*s), 4**(a*s)) if k == 2: numerator = sum(comb(a,j)*comb(2*s*j,s*j) *comb(2*s*(a-j),s*(a-j)) for j in range(a+1)) return Fraction(numerator, 2**a*4**(a*s)) assert k == 3 numerator = 0 for b in range(a+1): for c in range(b,a-b+1): for d in range(c,a-b-c+1): e = a-b-c-d ns=(b,c,d,e) if e