# Exact verification of the table (n, |Lambda|, b_n), GAP 4. # Prepared with ChatGPT, 2026-11-03. No external packages required. # # Run: gap -q -b -A -T verify_bn_gap.g # Or: Read("verify_bn_gap.g"); # # n = p^d-1; Phi acts by a -> p*a modulo n; # Lambda = the units modulo n. All residues are represented by 0..n-1. # a <- lambda iff exactly one b in a^Phi satisfies # (lambda-b)^Phi = (lambda-a)^Phi. # b_n = max_a |{lambda in Lambda : not(a <- lambda)}|. # # Multiplication by a unit preserves this condition and Lambda. # Its orbits on C_n are indexed by gcd(a,n). Thus the maximum is # computed on a=g mod n for ALL positive divisors g of n (g=n means 0). # Two independent methods compute and compare the COMPLETE bad sets: # 1. direct comparison of Phi-orbit labels; # 2. union of solutions of linear congruences, without orbit labels. # For n<=1000, every a in C_n is additionally checked directly, to # verify the divisor reduction on the whole point set. # This file verifies condition (i) only; it does not enumerate triples # or verify condition (ii). PaleyBnOrbitData := function(p, d) local n, ids, orbits, a, x, orb, k; if not IsPrimeInt(p) or p = 2 or d < 1 then Error("expected an odd prime p and a positive exponent d"); fi; n := p^d - 1; ids := List([1..n], x -> 0); orbits := []; for a in [0..n-1] do if ids[a+1] = 0 then k := Length(orbits) + 1; orb := []; x := a; repeat ids[x+1] := k; Add(orb, x); x := (p*x) mod n; until x = a; Add(orbits, orb); fi; od; return rec(n := n, ids := ids, orbits := orbits); end;; PaleyBnBadDirect := function(data, units, a) local bad, orb, lambda, target, b; bad := []; orb := data.orbits[data.ids[a+1]]; for lambda in units do target := data.ids[((lambda-a) mod data.n)+1]; # b=a is always a solution, so nonuniqueness is equivalent # to the existence of another b in the same Phi-orbit. for b in orb do if b <> a and data.ids[((lambda-b) mod data.n)+1] = target then Add(bad, lambda); break; fi; od; od; return bad; end;; PaleyBnBadCongruences := function(p, d, n, units, a) local orb, marked, b, i, power, A, B, bezout, g, modulus, first, j, lambda; # Build a^Phi independently from explicit powers, not orbit labels. orb := Set(List([0..d-1], i -> (a*p^i) mod n)); marked := BlistList([0..n-1], []); for b in orb do if b <> a then # lambda-b = p^i*(lambda-a) mod n is equivalent to # (p^i-1)*lambda = p^i*a-b mod n. # i=0 has no solution because b<>a; skip it. power := p; i := 1; while i < d do A := power - 1; B := (power*a-b) mod n; bezout := Gcdex(A, n); g := bezout.gcd; if B mod g = 0 then modulus := QuoInt(n, g); first := (bezout.coeff1*QuoInt(B,g)) mod modulus; for j in [0..g-1] do lambda := first + j*modulus; marked[lambda+1] := true; od; fi; power := power*p; i := i+1; od; fi; od; return Filtered(units, lambda -> marked[lambda+1]); end;; PaleyBnCheckCase := function(p, d) local data, n, units, divs, counts, rows, g, a, direct, other, maxBad, fullMax, pairs, start; start := Runtime(); data := PaleyBnOrbitData(p,d); n := data.n; units := Filtered([0..n-1], a -> GcdInt(a,n) = 1); if Length(units) <> Phi(n) then Error("unit count disagrees with Euler's phi function"); fi; divs := DivisorsInt(n); counts := List([1..n], a -> -1); rows := []; pairs := 0; maxBad := 0; Print("CASE p=",p," d=",d," q=",p^d," n=",n,"\n"); for g in divs do a := g mod n; direct := PaleyBnBadDirect(data,units,a); other := PaleyBnBadCongruences(p,d,n,units,a); if direct <> other then Error("direct and congruence methods disagree at divisor ",g); fi; counts[g] := Length(direct); Add(rows, [g, Length(direct)]); pairs := pairs+Length(units); maxBad := Maximum(maxBad, Length(direct)); od; Print("divisor_bad_counts=",rows,"\n"); if n <= 1000 then fullMax := 0; for a in [0..n-1] do direct := PaleyBnBadDirect(data,units,a); if Length(direct) <> counts[GcdInt(a,n)] then Error("gcd-orbit reduction failed at a=",a); fi; fullMax := Maximum(fullMax, Length(direct)); od; if fullMax <> maxBad then Error("full point maximum disagrees with divisor maximum"); fi; Print("FULL_POINT_CHECK_PASS points=",n,"\n"); fi; if 4*maxBad >= Length(units) then Error("condition (i) certificate failed: 4*b_n >= |Lambda|"); fi; Print("TWO_METHODS_PASS divisor_unit_pairs=",pairs,"\n"); Print("RESULT q=",p^d," n=",n," units=",Length(units), " b_n=",maxBad," four_b_n=",4*maxBad,"\n"); Print("elapsed_ms=",Runtime()-start,"\n\n"); return rec(p:=p,d:=d,n:=n,units:=Length(units),b_n:=maxBad, divisorCounts:=rows); end;; PaleyBnRunAll := function() local cases, results, c; cases := [[3,5],[3,6],[3,8],[3,10],[5,4],[5,6]]; results := []; Print("GAP ",GAPInfo.Version,"; exact b_n verification\n"); for c in cases do Add(results,PaleyBnCheckCase(c[1],c[2])); od; Print("TABLE q n |Lambda| b_n\n"); for c in results do Print(c.p^c.d," ",c.n," ",c.units," ",c.b_n,"\n"); od; Print("ALL_SIX_CASES_PASS\n"); return results; end;; PaleyBnResults := PaleyBnRunAll();;