"""Independent finite checks for the 2 December 2026 factorial divisor sums PDF.""" from fractions import Fraction from functools import cache from itertools import combinations, product from math import factorial, gcd, isqrt, prod @cache def factors(n): result = {} p = 2 while p * p <= n: while n % p == 0: result[p] = result.get(p, 0) + 1 n //= p p = 3 if p == 2 else p + 2 if n > 1: result[n] = 1 return result @cache def sigma(n, h): return prod(sum(p ** (j*h) for j in range(e+1)) for p, e in factors(n).items()) def crt(congruences): modulus = prod(m for _, m in congruences) solution = 0 for a, m in congruences: if m > 1: quotient = modulus // m solution += a * quotient * pow(quotient, -1, m) return solution % modulus, modulus def check_expansions(): # Finite differences of x^i at zero give j! S(i,j). Multiply the proposed # Taylor polynomial by its denominator and check coefficients through its order. from math import comb count = 0 for h in range(9): for j in range(h+1): degree = h-j numerator = [ sum((-1)**(j-t) * comb(j,t) * t**i for t in range(j+1)) // factorial(j) for i in range(j, h+1) ] for v in range(1, j+1): numerator = [numerator[0]] + [ numerator[i] - v*numerator[i-1] for i in range(1, degree+1) ] assert numerator == [1] + [0]*degree count += 1 print(f"Tail expansion: {count} truncated polynomial identities through h=8.") def mean_over_zeta(prime_powers, a, k): # Finite Fourier expansion sum_{d|q} c_d(a)/d^(k+1), in prime-power factors. # c_(p^j)(a) is the sum over all p^j additive characters minus the sum # over characters already present at level j-1. value = Fraction(1) for p, exponent in prime_powers.items(): local = Fraction(1) prev = 1 for _ in range(exponent): cur = prev*p ramanujan = cur * (a % cur == 0) - prev * (a % prev == 0) local += Fraction(ramanujan, cur**(k+1)) prev = cur value *= local return value def check_densities(): # Directly count a full period of the divisibility indicator. tested = 0 for q in range(1, 14): for d in range(1, 48): g = gcd(q, d) for a in range(1, 2*q+1): period = d//g hits = sum((a+q*v) % d == 0 for v in range(period)) assert hits == int(a % g == 0) tested += 1 print(f"Divisor densities: {tested:,} exact period counts.") def degree_one(slopes, offsets, m, prime): first = [p-b for p,b in zip(slopes, offsets)] assert len(set(first)) == 1 shifts = [2*p-b for p,b in zip(slopes, offsets)] assert len(set(shifts)) == 3 and prime > max(shifts) row0, row1 = [[Fraction(p, sigma(p,h)) for p in slopes] for h in (0,1)] # Fix u_2 = 1 and solve the two linear equations for u_0 and u_1. minor = row0[0]*row1[1] - row0[1]*row1[0] u = [(row0[1]*row1[2]-row0[2]*row1[1])/minor, (row0[2]*row1[0]-row0[0]*row1[2])/minor, Fraction(1)] assert all(sum(a*b for a,b in zip(u,row)) == 0 for row in (row0,row1)) top = [ui*Fraction(p*p, sigma(p,1)) for ui,p in zip(u,slopes)] q_factors = factors(m).copy() for p in slopes: assert q_factors.keys().isdisjoint(factors(p)) q_factors.update({t:2*e for t,e in factors(p).items()}) assert factors(prime) == {prime:1} and prime not in q_factors finer = dict(q_factors) finer[prime] = 1 for r in range(m): start, q = crt([(r,m)] + [(b,p*p) for b,p in zip(offsets,slopes)]) start += q for p,b in zip(slopes,offsets): n, rem = divmod(start-b,p) assert rem == 0 and n > 0 and n % m == r and n % p == 0 assert gcd(p,n+1) == gcd(p,n+2) == 1 base, _ = crt([(start,q),(0,prime)]) base_means = [mean_over_zeta(finer,base+s,1) for s in shifts] for i,s in enumerate(shifts): new, _ = crt([(start,q),(-s,prime)]) differences = [mean_over_zeta(finer,new+t,1)-b for t,b in zip(shifts,base_means)] predicted = mean_over_zeta(q_factors,start+s,1)/prime assert predicted > 0 assert differences == [predicted if n == i else 0 for n in range(3)] assert sum(c*d for c,d in zip(top,differences)) == top[i]*predicted yield r, i, top, differences[i] def check_degree_one(): for r,i,top,difference in degree_one([3,5,7],[0,2,4],2,11): coefficients = [30*x for x in top] assert coefficients == [Fraction(315,4), Fraction(-525,2), Fraction(735,4)] if i == 0: gap = (-1)**r * coefficients[0] * difference assert gap == (Fraction(768,77), Fraction(-2304,385))[r] print(f"Worked example: parity {r}, signed mean gap/zeta(2) = {gap}.") count = 0 zero_weights = 0 for m in range(1,31): offsets = [0,24*m,48*m] slopes = [1+48*m+b for b in offsets] last = max(2*p-b for p,b in zip(slopes,offsets)) ell = last+1 while factors(ell) != {ell:1} or gcd(ell,m*prod(slopes)) != 1: ell += 1 for _,i,top,_ in degree_one(slopes,offsets,m,ell): zero_weights += top[i] == 0 count += 1 assert count == 1395 print(f"Degree-one family: {count:,} exact isolated mean differences; " f"{zero_weights} corresponding zero kernel coefficients.") def rank_mod_prime(rows,p): echelon = [[int(x.numerator * pow(x.denominator,-1,p) % p) for x in row] for row in rows] rank = 0 for col in range(len(echelon[0])): pivot = next((j for j in range(rank,len(echelon)) if echelon[j][col]),None) if pivot is None: continue echelon[rank], echelon[pivot] = echelon[pivot], echelon[rank] pivot_row = echelon[rank] inverse = pow(pivot_row[col],-1,p) for j in range(rank+1,len(echelon)): multiplier = echelon[j][col]*inverse % p if multiplier: echelon[j] = [(x-multiplier*y) % p for x,y in zip(echelon[j],pivot_row)] rank += 1 return rank def check_degree_two(): side, radix = 8, 15 base, step = 49972807679, 223092870 points = list(product(range(side),repeat=2)) slopes = [base + step*(a+radix*b) for a,b in points] offsets = [step*(a+2*radix*b) for a,b in points] assert all(gcd(p,q) == 1 for p,q in combinations(slopes,2)) shifts = [[(j+1)*p-off for p,off in zip(slopes, offsets)] for j in range(3)] assert len(set(shifts[2])) == 64 and min(map(min,shifts)) > 0 assert set(shifts[2]).isdisjoint(shifts[0]+shifts[1]) for i,(x,y) in enumerate(points): assert (shifts[0][i],shifts[1][i],shifts[2][i]) == ( base-step*radix*y, 2*base+step*x, 3*base+step*(2*x+radix*y)) # Group by actual arithmetic shifts, without assuming which vertices share a line. rows = {} for h in range(3): for i in range(min(1,h)+1): weights = [Fraction(p**(i+1),sigma(p,h)) for p in slopes] for j in range(i+1): rows[h,i,j] = [ [v if s == t else 0 for s,v in zip(shifts[j],weights)] for t in sorted(set(shifts[j])) ] all_rows = [row for group in rows.values() for row in group] assert (len(all_rows),len(all_rows[0])) == (56,64) # Two exact row relations on disjoint sets: the fiber sums at j=0,1 agree # for each common weight p^2/sigma_h(p), for h=1 and h=2. for h in (1,2): assert list(map(sum,zip(*rows[h,1,0]))) == list(map(sum,zip(*rows[h,1,1]))) prime = 1_000_003 assert all(prime % k for k in range(2,isqrt(prime)+1)) rank = rank_mod_prime(all_rows,prime) assert rank == 54 print(f"56 x 64 matrix: rank {rank} modulo {prime:,}; two independent exact row relations " "give rational rank 54 and nullity 10.") print("Degree-two example: 64 positive isolated terminal shifts and pairwise coprime dilations.") if __name__ == "__main__": check_expansions() check_densities() check_degree_one() check_degree_two()