"""Reproduce the two algebraic examples and the simultaneous auxiliary-prime table.""" import math def prime(n): return n >= 2 and all(n % d for d in range(2, math.isqrt(n) + 1)) def first_menu(P, degree): count = 0 while degree ** (2 * count) < P: count += 1 primes = [] candidate = 1 while len(primes) < count: candidate += 12 * degree if prime(candidate): primes.append(candidate) return primes def evaluate(P, bound): menus = {r: first_menu(P, r) for r in range(2, bound + 1) if prime(r)} table = {} for p in range(P // 2 + 1, P + 1): if not prime(p): continue row = {} for r, menu in menus.items(): row[r] = None for ell in menu: # Check the character test against the actual power subgroup. residue = pow(p, (ell - 1) // r, ell) passes = p != ell and residue != 1 powers = {pow(x, r, ell) for x in range(1, ell)} assert passes == (p % ell != 0 and p % ell not in powers) if passes and row[r] is None: row[r] = (ell, residue) table[p] = row return table, menus def tex_table(table, menus): lines = [r"\begin{table}[htbp]\centering\small", r"\begin{tabular}{rccc}\toprule", r"Characteristic \(p\) & Degree 2 & Degree 3 & Degree 5\\\midrule"] for p, row in table.items(): cells = [str(p)] for r, result in row.items(): if result is None: cells.append(r"\cellcolor{misscell}---") else: cells.append(r"\cellcolor{passcell}\(%d,\ %d\)" % result) lines.append(" & ".join(cells) + r"\\") lines.extend([r"\bottomrule\end{tabular}", r"\caption{Simultaneous witnesses at \(P=64,\ D=5\). " r"The lists for degrees \(2,3,5\) are respectively " + ", ".join(r"\(\{" + ",".join(map(str, menu)) + r"\}\)" for menu in menus.values()) + r". Each cell gives the first successful \(\ell\) and its residue " r"\(p^{(\ell-1)/r}\bmod\ell\). A dash means that the entire list fails. " r"Five of these seven characteristics pass in every degree.}", r"\end{table}"]) return "\n".join(lines) def verify(): roots = [x for x in range(19) if (x*x+x+1) % 19 == 0] units = [(7+5*x) % 19 for x in roots] assert roots == [7, 11] and units == [4, 5] assert [pow(x, 3, 19) for x in units] == roots assert all(pow(x, 9, 19) == 1 for x in units) assert units[0]*units[1] % 19 == 1 assert all(pow(x, 3, 19) != 4 for x in range(19)) p = 33666821 assert prime(p) and (p+1) == 2 * 3**2 * 7**4 * 779 assert (p+1)//18 == 1870379 and math.gcd(779, 2*3*5*7) == 1 table, menus = evaluate(64, 5) assert [p for p, row in table.items() if not all(row.values())] == [43, 61] assert menus == {2: [73, 97, 193], 3: [37, 73], 5: [61, 181]} return table, menus if __name__ == "__main__": print(tex_table(*verify()))