# Exact GAP 4 verification of condition (ii), including repeated points. # Prepared with ChatGPT, 2026-11-03. No additional packages required. # Run: gap -q -b -A -T -m 512m -o 3g verify_condition_ii_gap.g # Read("verify_condition_ii_gap.g"); also works in an interactive session. # Override PaleyIICases before Read to select cases, e.g. [[3,5]]. # # n=p^d-1; Phi= p*x mod n>; Lambda=units mod n; mu=0. # P(a,b) = { (v-u)^Phi : u in a^Phi, v in b^Phi }. # A witness l for (1,b,c) satisfies, for its three pairs (s,t), # P(s,t) intersection P(s-l,t-l) = {(t-s)^Phi}. # The parity label is the same in both products and can be suppressed. # Existence of this witness implies the required m-extension with m=r(0,l). # All canonical triples are counted and verified, not a sample. # This program does NOT verify condition (i); see verify_bn_gap.g. PaleyIIData := function(p,d) local n,ids,orbits,a,x,o,powers; n:=p^d-1; ids:=List([1..n],x->0); orbits:=[]; for a in [0..n-1] do if ids[a+1]=0 then o:=[]; x:=a; repeat ids[x+1]:=Length(orbits)+1; Add(o,x); x:=(p*x) mod n; until x=a; Add(orbits,o); fi; od; powers:=List([0..d-1],i->p^i); return rec(p:=p,d:=d,n:=n,ids:=ids,orbits:=orbits,powers:=powers, collisions:=[]); end;; PaleyIIProduct := function(data,a,b) local ans,k; ans:=[]; # Simultaneous Frobenius on u,v reduces d^2 differences to d labels. for k in data.powers do Add(ans,data.ids[((k*b-a) mod data.n)+1]); od; return Set(ans); end;; PaleyIICollisions := function(data,t) local ans,k,A,z,g,m,first,j; if IsBound(data.collisions[t+1]) then return data.collisions[t+1]; fi; ans:=[]; if t=0 then ans:=[0..data.n-1]; else for k in data.powers do if k<>1 then A:=k-1; z:=Gcdex(A,data.n); g:=z.gcd; if t mod g=0 then m:=QuoInt(data.n,g); first:=(-z.coeff1*QuoInt(t,g)) mod m; for j in [0..g-1] do Add(ans,first+j*m); od; fi; fi; od; fi; ans:=Set(ans); data.collisions[t+1]:=ans; return ans; end;; PaleyIIRow := function(data,b) local n,target,mask,o,delta,t,l; n:=data.n; target:=data.ids[((b-1) mod n)+1]; mask:=BlistList([1..n],[]); for o in PaleyIIProduct(data,1,b) do if o<>target then for delta in data.orbits[o] do t:=(b-1-delta) mod n; # A translated product contains delta^Phi iff # (p^i-1)*(lambda-1) = -t mod n for some i. for l in PaleyIICollisions(data,t) do mask[((1+l) mod n)+1]:=true; od; od; fi; od; return mask; end;; PaleyIIBadDirect := function(data,wrong,b,c,l) local k,o; for k in data.powers do o:=data.ids[((k*(c-l)-(b-l)) mod data.n)+1]; if o in wrong then return true; fi; od; return false; end;; PaleyIISelfCheck := function() local data,n,a,b,l,raw,u,v,prod,wrong,row; data:=PaleyIIData(3,3); n:=data.n; for a in [0..n-1] do for b in [0..n-1] do raw:=[]; for u in data.orbits[data.ids[a+1]] do for v in data.orbits[data.ids[b+1]] do Add(raw,data.ids[((v-u) mod n)+1]); od; od; if Set(raw)<>PaleyIIProduct(data,a,b) then Error("product formula self-check failed"); fi; od; od; for b in [0..n-1] do prod:=PaleyIIProduct(data,1,b); wrong:=Difference(prod,[data.ids[((b-1) mod n)+1]]); row:=PaleyIIRow(data,b); for l in [0..n-1] do if row[l+1]<>PaleyIIBadDirect(data,wrong,1,b,l) then Error("forbidden-witness mask self-check failed"); fi; od; od; Print("PRODUCT_AND_MASK_SELF_CHECK_PASS q=27\n"); end;; PaleyIICheckCase := function(p,d) local data,n,units,inverses,a,z,rows,b,c,ib,ic,x,y,canon, total,vertices,extra,maxL,worst,wrong,l,found,start,target; start:=Runtime(); data:=PaleyIIData(p,d); n:=data.n; units:=0; inverses:=List([1..n],x->0); for a in [1..n-1] do z:=Gcdex(a,n); if z.gcd=1 then inverses[a+1]:=z.coeff1 mod n; units:=units+1; fi; od; Print("CASE p=",p," d=",d," n=",n," units=",units,"\n"); rows:=[]; for b in [0..n-1] do Add(rows,PaleyIIRow(data,b)); od; Print("ROWS_READY elapsed_ms=",Runtime()-start,"\n"); total:=0; vertices:=0; extra:=0; maxL:=0; worst:=fail; for b in [0..n-1] do ib:=inverses[b+1]; for c in [b..n-1] do canon:=true; if ib<>0 then x:=ib; y:=(ib*c) mod n; if x>y then z:=x; x:=y; y:=z; fi; if x0 then x:=ic; y:=(ic*b) mod n; if x>y then z:=x; x:=y; y:=z; fi; if xmaxL then maxL:=l; worst:=[1,b,c]; fi; else l:=l+1; fi; od; if not found then Error("no witness for ",[1,b,c]); fi; fi; fi; fi; od; if b mod 2000=0 then Print("PROGRESS b=",b," T=",total," elapsed_ms=",Runtime()-start,"\n"); fi; od; if total<>vertices+extra then Error("counter mismatch"); fi; Print("RESULT q=",p^d," n=",n," units=",units," T=",total," L=",maxL, " vertex=",vertices," extra=",extra," worst=",worst,"\n"); Print("CONDITION_II_PASS elapsed_ms=",Runtime()-start,"\n\n"); return rec(q:=p^d,n:=n,units:=units,T:=total,L:=maxL, vertices:=vertices,extra:=extra,worst:=worst); end;; PaleyIIRun := function(cases) local results,c; Print("GAP ",GAPInfo.Version,"; complete condition (ii) verification\n"); PaleyIISelfCheck(); results:=[]; for c in cases do Add(results,PaleyIICheckCase(c[1],c[2])); od; Print("ALL_REQUESTED_CASES_PASS\n"); return results; end;; if not IsBound(PaleyIICases) then PaleyIICases:=[[3,5],[3,6],[3,8],[3,10],[5,4],[5,6]]; fi; PaleyIIResults:=PaleyIIRun(PaleyIICases);;