"""DEFINITIVE line census: all cyclic order-q subgroups <= Z_q^3, v having >=1 unit coordinate (necessary for order q); normalize by FIRST UNIT coordinate (any position). Exact MIS per quotient. Usage: python census.py --q 9""" import sys, time, itertools, json, argparse from math import gcd import numpy as np from ortools.sat.python import cp_model def run(q, tl=25): Dset=set() for d in itertools.product((-1,0,1),repeat=3): if any(x!=0 for x in d): Dset.add(tuple(x%q for x in d)) Darr=np.array(sorted(Dset),dtype=np.int64) pw=(q**np.arange(3)).astype(np.int64) allv=np.array(list(itertools.product(range(q),repeat=3)),dtype=np.int64) Nall=len(allv) units=[u for u in range(1,q) if gcd(u,q)==1] seen=set(); dirs=[] for vt in itertools.product(range(q),repeat=3): v=np.array(vt,dtype=np.int64)%q if not v.any(): continue upos=[i for i,c in enumerate(v) if gcd(int(c),q)==1] if not upos: continue # order drops below q i=upos[0]; key=tuple((v*pow(int(v[i]),-1,q))%q) if key in seen: continue seen.add(key); dirs.append(key) print(f"q={q}: {len(dirs)} distinct cyclic order-{q} lines", flush=True) out=[]; witnesses={} t0=time.time() for i,key in enumerate(dirs): v=np.array(key,dtype=np.int64) lam=np.array([(t*v)%q for t in range(q)],dtype=np.int64) if not all(tuple(l) not in Dset for l in lam if tuple(l)!=(0,0,0)): out.append({"v":[int(x) for x in v],"valid":False,"union":None,"status":"INVALID","classes":None}) continue cand=(allv[:,None,:]+lam[None,:,:])%q rep=(cand@pw).min(axis=1) uniq,inv=np.unique(rep,return_inverse=True) n=len(uniq); assert n*q==Nall forb=set(); cls_of=inv for dvec in Darr: t=((allv+dvec[None,:])%q) candt=(t[:,None,:]+lam[None,:,:])%q mint=(candt@pw).min(axis=1) tgt=np.searchsorted(uniq,mint) m=cls_of!=tgt for x,y in zip(cls_of[m].tolist(),tgt[m].tolist()): forb.add((x,y)) nbrs=[[j for j in range(n) if (j,ii) in forb or (ii,j) in forb] for ii in range(n)] mdl=cp_model.CpModel() xs=[mdl.NewBoolVar(str(z)) for z in range(n)] for uu in range(n): for vv in nbrs[uu]: if uu=q-1)).all(axis=1).sum()) print(f"witness for v={r['v']}: {len(A)} pts adjacent-pairs={bad}") assert bad==0 and len(A)==mx fn=rf"C:\Users\jack\recens-run\sc7\coset_c{q}3_{mx}.txt" with open(fn,"w") as f: for p in pts: f.write(" ".join(map(str,p))+"\n") print("saved",fn)