"""Independent exact spot checks for the December 1 prime-product Lambert manuscript.""" from collections import Counter, defaultdict from fractions import Fraction from itertools import combinations from math import comb, gcd, isqrt, prod def check_coefficients(limit=40_000, max_degree=6): omega = [0] * (limit + 1) squarefree = bytearray([1]) * (limit + 1) for p in range(2, limit + 1): if omega[p]: continue for multiple in range(p, limit + 1, p): omega[multiple] += 1 for multiple in range(p * p, limit + 1, p * p): squarefree[multiple] = 0 # Expand each actual Lambert denominator into its multiples. layers = [[0] * (limit + 1) for _ in range(max_degree + 1)] for exponent in range(2, limit + 1): if squarefree[exponent] and omega[exponent] <= max_degree: layer = layers[omega[exponent]] for n in range(exponent, limit + 1, exponent): layer[n] += 1 for n in range(1, limit + 1): assert omega[n] <= max_degree for j in range(1, max_degree + 1): assert layers[j][n] == comb(omega[n], j) alternating = sum((-1) ** (j - 1) * layers[j][n] for j in range(1, max_degree + 1)) assert alternating == int(n > 1) assert layers[6][30_030] == 1 print(f"Divisor coefficients: {limit * max_degree:,} for n <= {limit:,}, j = 1..{max_degree}.") print(f"Alternating identity: {limit:,} coefficients; the six-prime layer occurs at n = 30,030.") def check_array(blocks): k_max = 4 * blocks j_max = k_max + k_max**2 radix = 10 * (j_max + 1) vectors = [] for block in range(blocks): place = radix ** (2 * block) for i, digit in enumerate((2, 3, radix, 1), start=1): width = place * digit vectors.append((width, (4 * block + i) * width)) # Enumerate the original subsets before combining coincident points. weights = Counter() for size in range(k_max + 1): for subset in combinations(vectors, size): point = (sum(u for u, v in subset), sum(v for u, v in subset)) weights[point] += (-1) ** size rows = [(u, v, sign) for (u, v), sign in weights.items() if sign] assert weights[0, 0] == 1 and len(rows) == 12**blocks assert len({u for u, v, sign in rows}) == len(rows) assert all(abs(sign) == 1 and 0 <= v <= k_max * u for u, v, sign in rows) for k in range(1, k_max + 1): totals = Counter() for u, v, sign in rows: totals[k * u - v] += sign assert all(weight == 0 for weight in totals.values()) for k in range(k_max + 1, j_max + 1): assert len({k * u - v for u, v, sign in rows}) == len(rows) projections = (j_max - k_max) * len(rows) print(f"g = {blocks}: {len(rows):,} tails, {k_max} early depths, {projections:,} retained projections.") return k_max, projections def distinct_primes(integer): n = integer factors = [] d = 2 while d * d <= n: if n % d == 0: factors.append(d) while n % d == 0: n //= d d = 3 if d == 2 else d + 2 if n != 1: factors.append(n) return factors def next_prime(n): candidate = n + 1 while any(candidate % d == 0 for d in range(2, isqrt(candidate) + 1)): candidate += 1 return candidate def chinese_remainder(congruences): modulus = prod(m for r, m in congruences) residue = 0 for target, factor in congruences: other = modulus // factor assert gcd(other, factor) == 1 residue += target * other * pow(other, -1, factor) return residue % modulus, modulus def check_balanced_dilations(): # Two early depths, three retained depths, and genuine collisions at both # early depths. The affine parameters give 2 or 3 factors per dilation. rows = ((0, 0, 1), (1, 2, -1), (2, 2, -1), (3, 4, 1)) a, scale, common_loss = 31_291, 210, 2 dilations = [a + scale * u for u, v, sign in rows] offsets = [scale * v for u, v, sign in rows] factors = [distinct_primes(q) for q in dilations] assert [len(ps) for ps in factors] == [3, 2, 2, 2] assert dilations[1] == 17**2 * 109 shifts = {(row, k): k * q - offsets[row] for row, q in enumerate(dilations) for k in range(1, 6)} assert len({shifts[row, k] for row in range(len(rows)) for k in (3, 4, 5)}) == 12 smallest_prime = min(p for ps in factors for p in ps) for k in (3, 4, 5): for (u, v, _), (w, t, _) in combinations(rows, 2): assert 0 < abs(k * (u - w) - v + t) < smallest_prime marker = (0, 3) cutoff = 2 + 2 * max(map(abs, shifts.values())) + max(dilations) first = next_prime(cutoff) marks = {first, next_prime(first)} prescriptions = [] for q, offset, primes in zip(dilations, offsets, factors): excess = len(primes) - common_loss targets = [-1] * excess + [-2] * excess + [0] * (len(primes) - 2 * excess) lift, radical = chinese_remainder(list(zip(targets, primes))) prescriptions.append((offset + q * lift, q * radical)) prescriptions.extend((-shifts[marker], p) for p in sorted(marks)) residue, modulus = chinese_remainder(prescriptions) prescribed = set().union(marks, *factors) early = retained = 0 for h in range(1, 22): n = residue + h * modulus for k in range(1, 6): fibers = defaultdict(list) for row, (u, v, sign) in enumerate(rows): q = dilations[row] shift = shifts[row, k] quotient, remainder = divmod(n + shift, q) assert remainder == 0 known = {p for p in prescribed if quotient % p == 0} if k <= 2: lost = {p for p in factors[row] if quotient % p != 0} assert len(lost) == common_loss fibers[shift].append((sign, len(known))) early += 1 else: assert known == (marks if (row, k) == marker else set()) retained += 1 for members in fibers.values(): assert len(members) == 2 assert sum(sign for sign, count in members) == 0 assert len({count for sign, count in members}) == 1 print(f"CRT example: q = {dilations}, M = {common_loss}, marked primes {sorted(marks)}.") print(f"Verified {early} equal-loss arguments and {retained} marked/unmarked arguments, including repeated 17 in q.") def check_count_law(primes): period = prod(primes) # Translate on a nontrivial progression with invertible step. counts = Counter(sum((17 * j + 19) % p == 0 for p in primes) for j in range(period)) # Coefficients of the integer polynomial product of (p-1 + z). poly = [1] for p in primes: poly = [a * (p - 1) + b for a, b in zip(poly + [0], [0] + poly)] assert [counts[k] for k in range(len(poly))] == poly for power in range(1, 5): empirical = sum(mass * k**power for k, mass in counts.items()) assert empirical == sum(mass * k**power for k, mass in enumerate(poly)) pair_moments = [] for power in (2, 4): numerator = sum(na * nb * (a - b)**power for a, na in counts.items() for b, nb in counts.items()) pair_moments.append(Fraction(numerator, period**2)) variances = [Fraction(2 * (p - 1), p * p) for p in primes] total_variance = sum(variances) assert pair_moments[0] == total_variance assert pair_moments[1] == 3 * total_variance**2 + sum(v - 3 * v**2 for v in variances) print(f"Period {period:,}: full count law, raw moments 1..4, independent-difference moments 2 and 4 agree.") if __name__ == "__main__": check_coefficients() checked = [check_array(g) for g in range(1, 5)] print(f"Projection totals: {sum(e for e, r in checked)} early depths, {sum(r for e, r in checked):,} retained.") check_balanced_dilations() check_count_law((2, 3, 5, 7, 11)) check_count_law((2, 3, 5, 7, 11, 13)) scale = Fraction(1, 4) second, fourth = 2 * scale**2, 12 * scale**4 print(f"Limiting second and fourth moments: {second}, {fourth}.") print(f"Limiting moment difference: {second - fourth}; distance lower bound: {(second - fourth) / 2}.")