"""Independent finite sanity check; not a universal proof. Standard library only.""" from collections import Counter from math import gcd import json rows = [] for q in range(1, 33): n = 4*q units = [u for u in range(n) if gcd(u,n)==1] for x in range(n): if x in (0,q,2*q,3*q): continue p = {0,q,x,(x+2*q)%n} target = {0,q,(x+q)%n,(x+3*q)%n} profile = lambda s: Counter((a+b)%n for a in s for b in s) assert len(p)==len(target)==4 assert profile(p)==profile(target), (q,x,'profile') # Exhaust all unit multipliers. Since 0 is in p, any admissible offset # must lie in target. No use of the four-system classification here. witness = next(((u,v) for u in units for v in target if {(u*a+v)%n for a in p}==target), None) predicted_nonaffine = (q//gcd(q,x))%4==2 assert (witness is None)==predicted_nonaffine, (q,x,witness) rows.append({'q':q,'x':x,'nonaffine':predicted_nonaffine}) result = {'q_max':32,'admissible_parameters':len(rows), 'nonaffine_parameters':sum(r['nonaffine'] for r in rows), 'profile_mismatches':0,'criterion_mismatches':0, 'method':'all units and all possible offsets; exact integer counts'} print(json.dumps(result,indent=2))