#!/usr/bin/env python3 """Independent re-check of the suspected C1 counterexample (P=30, p=13, R={7,11,19}). Pure Python, no numpy, explicit witness extraction, sympy for primality only. """ from math import gcd from sympy import isprime def slots_mod(P): return [r for r in range(P) if gcd(r, P) == 1 and gcd(r + 2, P) == 1] def kstar_pure(P, R): """Return (K*, witness_run) where witness_run is a list of absolute slot positions forming a maximal cyclic run, and also the full killed bitstring for inspection.""" R = list(R) slots = slots_mod(P) D = len(slots) prodR = 1 for q in R: prodR *= q N = D * prodR # build consecutive-slot sequence positions seq = [] for k in range(prodR): base = k * P for r in slots: seq.append(base + r) assert len(seq) == N killed = [False] * N for i, x in enumerate(seq): for q in R: if x % q == 0 or (x + 2) % q == 0: killed[i] = True break # longest cyclic run: double the sequence, cap at N best = 0 best_start = -1 cur = 0 cur_start = 0 for i in range(2 * N): if killed[i % N]: if cur == 0: cur_start = i cur += 1 if cur > best: best = cur best_start = cur_start if best >= N: return N, None else: cur = 0 # extract witness (positions in seq) for the best run, mod N if best_start >= 0: idxs = [j % N for j in range(best_start, best_start + best)] witness = [seq[j] for j in idxs] else: witness = [] return best, witness def main(): cases = [ (30, [7, 11, 19]), (390, [7, 11, 19]), (30, [7, 11, 13, 19]), ] for P, R in cases: K, witness = kstar_pure(P, R) print(f"K*({P}, {R}) = {K}") if witness: print(" witness run positions:", witness) # sanity: consecutive in slot order, each killed by R for x in witness: assert any(x % q == 0 or (x + 2) % q == 0 for q in R), f"not killed: {x}" # sanity: twin-admissible mod P for x in witness: assert gcd(x, P) == 1 and gcd(x + 2, P) == 1, f"not admissible: {x}" print(" (each witness slot verified killed + admissible)") print() # Summarize the sandwich inequalities for the suspected case L1, _ = kstar_pure(30, [7, 11, 19]) L2, _ = kstar_pure(390, [7, 11, 19]) L3, _ = kstar_pure(30, [7, 11, 13, 19]) print(f"sandwich: K*(30,R)={L1}, K*(390,R)={L2}, K*(30,R u {{13}})={L3}") print(f" C1 (lower bound L2>=L1): {L2 >= L1}") print(f" sharpened transfer (L2<=L3): {L2 <= L3}") print(f" C2 (-1: L2<=L3-1): {L2 <= L3 - 1}") print(f" sandwich (L1<=L2<=L3-1): {L1 <= L2 <= L3 - 1}") print(f" p=13 vs 2*L1={2*L1}: {'hard regime (p<=2L)' if 13 <= 2*L1 else 'conditional regime'}") if __name__ == "__main__": main()