"""Finite cross-checks for the 21 November auxiliary-primes manuscript. Run with standard Python 3.10 or later, with assertions enabled. The tests use toy finite parameters to exercise the arguments' discrete steps. """ from fractions import Fraction as F from itertools import combinations, combinations_with_replacement, product from math import factorial, gcd, isqrt, prod def site_mask(sites): return sum(1 << i for i in set(sites)) def check_runs(): runs = wrapped = odd_wraps = 0 for cell_size, tiles, run_size in product((2, 3, 4), (3, 5), (2, 3)): tile_size = 7 * cell_size for remainder in (0, 1, tile_size - 1): order = tiles * tile_size + remainder for direction in (1, order - 1): for origin in range(order): orbit = [(origin + direction * i) % order for i in range(order)] for first in range(tiles): tile_numbers = [(first + j) % tiles for j in range(run_size)] wrapped_here = first + run_size > tiles and remainder > 0 span = run_size * tile_size + (remainder if wrapped_here else 0) window = { orbit[(first * tile_size + i) % order] for i in range(span) } positions = [ range(t * tile_size, (t + 1) * tile_size) for t in tile_numbers ] sites = [orbit[i] for tile in positions for i in tile] assert len(set(sites)) == run_size * tile_size assert set(sites) <= window and span < (run_size + 1) * tile_size for tile in positions: # Parity is evaluated before sending indices to the group. for cell_index in (1, 3, 5): cell = tile[cell_index * cell_size:(cell_index + 1) * cell_size] assert sum(i % 2 == 0 for i in cell) >= cell_size // 2 runs += 1 wrapped += int(wrapped_here) odd_wraps += int(wrapped_here and order % 2 == 1) assert 0 < odd_wraps < wrapped < runs print(f"Tile runs checked: {runs}, including {wrapped} crossing a nonempty remainder" f" ({odd_wraps} on odd cycles).") def check_alteration(): n = 8 directions = (1, 3) windows = [site_mask((a + j * v) % n for j in range(4)) for a, v in product(range(n), directions)] edges = sorted({site_mask((a, (a + v) % n)) for a, v in product(range(n), directions)}) families = local_tests = triple_cases = 0 for eligible in range(1 << n): realized = [e for e in edges if e & eligible == e] matchings = [(0, ())] for edge in realized: more = [(union | edge, chosen + (edge,)) for union, chosen in matchings if not union & edge] matchings.extend(more) # Classify the windows directly using ALL realized obstructions. bad_windows = set() for a, b, c in combinations(realized, 3): if a & b or a & c or b & c: continue bad_windows.update(w for w in windows if w & a and w & b and w & c) triple_cases += len(bad_windows) for deleted, chosen in matchings: if any(not deleted & e for e in realized): continue families += 1 survivors = eligible & ~deleted assert all((e & survivors).bit_count() <= 1 for e in edges) for w in windows: if w not in bad_windows: assert sum(bool(w & e) for e in chosen) <= 2 assert (w & deleted).bit_count() <= 4 local_tests += 1 assert families > 256 and local_tests and triple_cases print(f"Alteration on Z/8, K=1, two short-window directions: all 256 eligible sets," f" {families} maximal disjoint families, {local_tests} local bounds checked;" f" {triple_cases} eligible-set/distinct-window cases contained a disjoint triple" " meeting the window.") def check_completion(): # g=2 with target counts 4 and 3, in cosets of size five. even_sets = [site_mask(c) for c in combinations(range(0, 10, 2), 4)] odd_sets = [site_mask(c) for c in combinations(range(1, 10, 2), 3)] completions = [a | b for a, b in product(even_sets, odd_sets)] even, odd = site_mask(range(0, 10, 2)), site_mask(range(1, 10, 2)) feasible = 0 for states in product(range(3), repeat=10): compulsory = site_mask(i for i in range(10) if states[i] == 2) eligible = site_mask(i for i in range(10) if states[i] != 0) bracket = all((compulsory & c).bit_count() <= goal <= (eligible & c).bit_count() for c, goal in ((even, 4), (odd, 3))) exists = any(t & compulsory == compulsory and t & eligible == t for t in completions) assert exists == bracket feasible += int(exists) print(f"Exact coset completion: {3**10} nested pairs, {feasible} feasible for counts 4 and 3.") def check_protected_marks(): # Three marked r=1, u=3 tiles and a remainder of five optional sites. tile_size, cell_size = 21, 3 size = 3*tile_size + 5 cells = [[range(i, i+cell_size) for i in range(a, a+tile_size, cell_size)] for a in range(0, 3*tile_size, tile_size)] compulsory_sites = [next(i for i in cell if i % 2 == 0) for tile in cells for cell in tile[1::2]] compulsory = site_mask(compulsory_sites) tested = 0 for optional in range(1 << 5): completed = compulsory | (optional << (3*tile_size)) occupied = [i for i in range(size) if completed & (1 << i)] for count in (0, 1, 2): for deleted_sites in combinations(occupied, count): survivors = completed & ~site_mask(deleted_sites) marks = 0 for tile in cells: occupancy = [[i for i in cell if survivors & (1 << i)] for cell in tile] if (all(not c for c in occupancy[::2]) and all(len(c) == 1 and c[0] % 2 == 0 for c in occupancy[1::2])): marks += 1 assert marks >= 3-count tested += 1 print(f"Protected marks: {tested} completions and deletions across three tiles and a remainder.") def symbol_table(p): residues = {i * i % p for i in range(1, p)} return [0 if i == 0 else (1 if i in residues else -1) for i in range(p)] def check_moments(): primes = (3, 5, 7, 11) tables = {p: symbol_table(p) for p in primes} patterns = remainders = moments = 0 for k in range(1, 5): for factors in combinations_with_replacement(primes, 2 * k): exponents = {p: factors.count(p) for p in set(factors)} period = prod(exponents) values = [prod(tables[p][t % p] ** e for p, e in exponents.items()) for t in range(1, period + 1)] diagonal = all(e % 2 == 0 for e in exponents.values()) assert sum(values) == (prod(p - 1 for p in exponents) if diagonal else 0) if not diagonal: partial = 0 for v in values: partial += v assert abs(partial) < period remainders += 1 patterns += 1 # Compare actual full-period moments of complex sums with the diagonal bound. period = prod(primes) vectors = (((1, 0), (0, 1), (-1, 1), (2, -1)), ((-1, 2), (2, 0), (1, -3), (0, 0)), ((1, 1), (1, 1), (1, 1), (1, 1))) for coeffs in vectors: b2 = sum(a*a + b*b for a, b in coeffs) norms = [] for t in range(1, period + 1): re = sum(z[0] * tables[p][t % p] for p, z in zip(primes, coeffs)) im = sum(z[1] * tables[p][t % p] for p, z in zip(primes, coeffs)) norms.append(re*re + im*im) for k in range(1, 5): pairings = factorial(2*k) // (2**k * factorial(k)) assert sum(b**k for b in norms) <= period * pairings * b2**k moments += 1 print(f"CRT: {patterns} exponent patterns of degrees 2, 4, 6 and 8," f" {remainders} incomplete-period checks, {moments} complex full-period moments.") def check_transfer(): # Real and imaginary parts separately, with exact rational affine weights. Z = 24 data = [[F((j*n + n*n) % 11 - 5, 7) for n in range(1, Z+1)] for j in (1, 4)] tests = 0 for a, ld in zip(data, [F(-3, 7), F(4, 11)]): tail = -ld - sum(w / n for n, w in enumerate(a, 1)) def weighted(y): return sum(w * min(1, y/n) for n, w in enumerate(a, 1)) for n in range(1, Z): for theta in (F(0), F(1, 3), F(1, 2), F(3, 4), F(1)): y = n + theta assert weighted(y) == (1-theta)*weighted(F(n)) + theta*weighted(F(n+1)) centered = sum(w*(y/i-1) for i, w in enumerate(a, 1) if i <= y) + y*ld assert centered == -weighted(y) - y*tail tests += 1 # CRT examples with q = 3 (mod 8), odd primes <= 7, and d searched directly. examples = 0 for q in (11, 19, 43): modulus = 16*q*3*5*7 residues = [a for a in range(7, modulus, 16) if (a+1) % (modulus//16) == 0] assert len(residues) == 1 and gcd(residues[0], modulus) == 1 d = residues[0] while d == 1 or any(d % j == 0 for j in range(2, 1+isqrt(d))): d += modulus assert (-d) % 8 == 1 and all(symbol_table(p)[(-d) % p] == 1 for p in (3,5,7,q)) examples += 1 print(f"Finite-sum affine interpolation and signed tail identity: {tests} exact" f" rational component checks; {examples} CRT and splitting examples.") if __name__ == "__main__": if not __debug__: raise RuntimeError("Run without -O so the assertions are active") check_runs() check_alteration() check_completion() check_protected_marks() check_moments() check_transfer() print("All independent finite checks passed.")