#!/usr/bin/env python3 """The check: certificates about Hodge classes on Fermat varieties, in exact integer arithmetic. Standard library only. Usage: verify.py FOLDER FOLDER is a route's folder. Two kinds of file directly in it are judged; any other file is left alone. xi.json, a length certificate for Aoki's exceptional tuple xi_q (piece C-3), q one of scienceslack.json's instances: {"q": 44, "d": 132, "remainder": [a, ...], "terms": [[coef, e, [tuple of degree e]], ...]} It claims, in Aoki's free module R_d on (Z/d) minus 0, where a tuple of degree e | d counts its entries multiplied by d/e: lift_d(xi_q) = remainder + sum of coef * lift_d(term). Every term must be algebraic for a reason this check verifies itself (Miranda, Movasati, Rufino, Villaflor 2026, MMRV): linear (a, e - a), or (e/2) for e even (Shioda, Ran; MMRV Prop. 3.6, Remark 4.6); short Hodge a Hodge character of length at most 6 (Lefschetz (1,1) and Kang 2016; MMRV Prop. 4.3); standard (i, k + i, ..., (p - 1)k + i, e - p i) with p >= 5 prime, e = p k, k >= 3, p not dividing i (Aoki; MMRV Def. 3.7, Prop. 3.7). A character of degree e is Hodge when its length is even, its entries sum to 0 mod e, and for every unit t mod e the residues t*a mod e sum to (length/2) * e (Shioda's criterion). The remainder must be Hodge, with the linear (d/2) added when its length is odd (d even). Its length is the value: at most 6 makes xi_q algebraic (MMRV Prop. 4.3), if MMRV holds. xi_q itself comes from checks/exceptional.json, never from the route. LATTICE.json, the linear cycles of a Fermat surface x_0^d + x_1^d + x_2^d + x_3^d = 0 and their intersection matrix: {"target": "C-1", "n": 2, "d": 3, "cycles": [[[u, v, a], [u', v', a']], ...], "gram": [[...]], "rank": 7, "divisors": [1, 1, 1, 1, 1, 1, 1]} A cycle is a matching of the coordinates 0..3 into two pairs, each pair (u, v) with u < v carrying the equation x_u = z^(1 + 2a) x_v, z = exp(pi i/d), 0 <= a < d (Aljovin, Movasati, Villaflor 2019, eq. (2)). The certificate must list every such cycle once (3 d^2 of them: the 27 lines for d = 3), their intersection numbers in the listed order, and the rank and elementary divisors (the nonzero ones, ascending) of that matrix; the check recomputes all of it. Targets: E-1 (d = 2, the example), C-1 (d = 3) and C-2 (d = 4); another target named in docs/submission.md exits 0 saying that a maintainer reads it. The last line is what the site shows on the commit: exit 0 "q = 44: 7; C-1: 27 lines, rank 7, elementary divisors 1^7", the parts in that order, or that there is nothing to check yet; exit 1 the first thing wrong, with the file. """ import json import math import re import sys from pathlib import Path HERE = Path(__file__).resolve().parent MAX_BYTES = 4_000_000 # the largest certificate found so far (xi_52 at d = 156) is 0.1 MB MAX_D = 4096 # degrees up to here run in seconds; MMRV's lifts stop at 204 MAX_TERMS = 20_000 MAX_ENTRIES = 128 # a standard character of prime p has p + 1 entries SURFACES = {"E-1": 2, "C-1": 3, "C-2": 4} # target: degree d of the Fermat surface (n = 2) OTHERS = {"C-4", "C-5", "C-6"} # pieces with a certificate a maintainer reads (docs/submission.md) class Wrong(Exception): """A certificate the check refuses; its text is what the author reads.""" def instances(): """The q this project's board tracks, from scienceslack.json's instances ("q = 44").""" spec = json.loads((HERE.parent / "scienceslack.json").read_text(encoding="utf-8")) return [int(m.group(1)) for name in spec.get("instances", []) if (m := re.fullmatch(r"q\s*=\s*(\d+)", name.strip()))] def read(path): if path.stat().st_size > MAX_BYTES: raise Wrong(f"{path.name}: over {MAX_BYTES // 1_000_000} MB") try: return json.loads(path.read_text(encoding="utf-8")) except (UnicodeDecodeError, json.JSONDecodeError) as e: raise Wrong(f"{path.name}: not JSON ({e})") from None def integer(x, what): if type(x) is not int: raise Wrong(f"{what} is not an integer") return x def entries(t, what, cap=MAX_ENTRIES): if not isinstance(t, list) or len(t) > cap: raise Wrong(f"{what} is not a list of at most {cap} integers") return [integer(a, what) for a in t] # ---- characters of Fermat varieties ---------------------------------------------------------------------------- def is_prime(n): return n > 1 and all(n % p for p in range(2, math.isqrt(n) + 1)) HODGE = {} def hodge(t, e): """Shioda's criterion for the character t of degree e.""" key = (tuple(sorted(t)), e) if key not in HODGE: half = len(t) // 2 HODGE[key] = (len(t) % 2 == 0 and all(0 < a < e for a in t) and sum(t) % e == 0 and all(sum(u * a % e for a in t) == half * e for u in range(1, e) if math.gcd(u, e) == 1)) return HODGE[key] def kind(t, e): """Why the term is algebraic, or Wrong.""" if len(t) == 2 and (t[0] + t[1]) % e == 0 or len(t) == 1 and 2 * t[0] == e: return "linear" if len(t) <= 6 and hodge(t, e): return "short Hodge" p = len(t) - 1 if p >= 5 and is_prime(p) and e % p == 0 and e // p >= 3: k = e // p for i in set(t): # the entries may come in any order if i % p and sorted(t) == sorted([(i + j * k) % e for j in range(p)] + [(-p * i) % e]): return "standard" raise Wrong(f"the term {t} of degree {e} is not linear, a Hodge character of length at most 6, or a standard character") def lifted(t, e, d, into, coef=1): """Add coef times the tuple t of degree e, lifted to degree d, to the counts `into`.""" if e < 2 or d % e: raise Wrong(f"degree {e} does not divide {d}") for a in t: if not 0 < a < e: raise Wrong(f"the entry {a} of {t} is not in 1..{e - 1}") into[a * (d // e)] += coef def length(name, c, xi): """A length certificate: the remainder's length, if every claim in it holds.""" if not isinstance(c, dict) or not {"q", "d", "remainder", "terms"} <= c.keys(): raise Wrong(f"{name}: needs q, d, remainder and terms") q, d = integer(c["q"], f"{name}: q"), integer(c["d"], f"{name}: d") if f"xi{q}.json" != name: raise Wrong(f"{name}: says q = {q}; name the file xi{q}.json") if not 2 <= d <= MAX_D or d % q: raise Wrong(f"{name}: d = {d} must be a multiple of q = {q}, at most {MAX_D}") rem = entries(c["remainder"], f"{name}: remainder") terms = c["terms"] if not isinstance(terms, list) or len(terms) > MAX_TERMS: raise Wrong(f"{name}: terms must be a list of at most {MAX_TERMS}") lhs, rhs = [0] * d, [0] * d lifted(xi, q, d, lhs) lifted(rem, d, d, rhs) used = {} for i, term in enumerate(terms): if not isinstance(term, list) or len(term) != 3: raise Wrong(f"{name}: term {i} is not [coef, e, tuple]") coef, e, t = integer(term[0], f"{name}: term {i}'s coefficient"), integer(term[1], f"{name}: term {i}'s degree"), entries(term[2], f"{name}: term {i}'s tuple") if not coef: continue lifted(t, e, d, rhs, coef) k = kind(t, e) used[k] = used.get(k, 0) + 1 if lhs != rhs: bad = [a for a in range(d) if lhs[a] != rhs[a]][:5] raise Wrong(f"{name}: the identity fails at the entries {bad} of degree {d}") if len(rem) % 2 and d % 2: raise Wrong(f"{name}: a remainder of odd length needs an even degree, so that (d/2) completes it") if not hodge(rem + [d // 2] if len(rem) % 2 else rem, d): raise Wrong(f"{name}: the remainder {rem} is not a Hodge character of degree {d}") return len(rem), used # ---- linear cycles on Fermat surfaces (Aljovin, Movasati, Villaflor 2019) -------------------------------------- def every_cycle(d): """Each matching of 0..3 into two pairs, with an exponent per pair: 3 d^2 cycles, as sorted triples.""" pairs = [((0, 1), (2, 3)), ((0, 2), (1, 3)), ((0, 3), (1, 2))] return {((p[0], p[1], a), (r[0], r[1], b)) for p, r in pairs for a in range(d) for b in range(d)} def cycle(x, d, what): if not isinstance(x, list) or len(x) != 2: raise Wrong(f"{what} is not two triples [u, v, a]") out = [] for triple in x: u, v, a = entries(triple, what, 3) if isinstance(triple, list) and len(triple) == 3 else (None, None, None) if u is None or not 0 <= u < v <= 3 or not 0 <= a < d: raise Wrong(f"{what}: each triple is [u, v, a] with 0 <= u < v <= 3 and 0 <= a < {d}") out.append((u, v, a)) out.sort() if {out[0][0], out[0][1], out[1][0], out[1][1]} != {0, 1, 2, 3}: raise Wrong(f"{what}: the two pairs do not cover the coordinates 0..3") return tuple(out) def meet(P, Q, d): """The intersection number of two linear cycles of a Fermat surface: 1 when the lines meet in a point, 0 when they are disjoint, 2 - d for a line with itself. Their common points are read off the union of the two matchings, a union of even cycles, each giving one dimension when the roots of unity around it multiply to 1 (AMV 2019); the number is (1 - (1 - d)^(k + 1)) / d for an intersection of projective dimension k.""" step = lambda C: {u: (v, 1 + 2 * a) for u, v, a in C} | {v: (u, -(1 + 2 * a)) for u, v, a in C} sp, sq, seen, k = step(P), step(Q), set(), -1 for s in range(4): if s in seen: continue cur, e, use = s, 0, 0 while True: seen.add(cur) nxt, by = (sp if use == 0 else sq)[cur] e -= by cur, use = nxt, 1 - use if cur == s and use == 0: break k += e % (2 * d) == 0 return (1 - (1 - d) ** (k + 1)) // d def divisors(M): """The nonzero elementary divisors of an integer matrix, ascending, each dividing the next (Smith form).""" A = [row[:] for row in M] rows, cols, out, r = len(A), len(A[0]) if A else 0, [], 0 for c in range(cols): while True: piv = [(abs(A[i][j]), i, j) for i in range(r, rows) for j in range(c, cols) if A[i][j]] if not piv: return smith(out) _, i, j = min(piv) A[r], A[i] = A[i], A[r] for row in A: row[c], row[j] = row[j], row[c] p = A[r][c] done = True for i in range(r + 1, rows): if A[i][c] // p: f = A[i][c] // p A[i] = [x - f * y for x, y in zip(A[i], A[r])] done &= A[i][c] == 0 for j in range(c + 1, cols): if A[r][j] // p: f = A[r][j] // p for row in A: row[j] -= f * row[c] done &= A[r][j] == 0 if done and all(A[i][j] % p == 0 for i in range(r + 1, rows) for j in range(c + 1, cols)): out.append(abs(p)) r += 1 break if done: # p does not divide the rest: fold a row in and go again i = next(i for i in range(r + 1, rows) if any(A[i][j] % p for j in range(c + 1, cols))) A[r] = [x + y for x, y in zip(A[r], A[i])] return smith(out) def smith(ds): ds = sorted(ds) for i in range(len(ds)): for j in range(i + 1, len(ds)): g = math.gcd(ds[i], ds[j]) ds[i], ds[j] = g, ds[i] * ds[j] // g return sorted(ds) def word(ds): return " ".join(f"{v}^{ds.count(v)}" for v in sorted(set(ds))) def lattice(c): """A LATTICE.json certificate: what it shows, if every number in it is right.""" if not isinstance(c, dict) or "target" not in c: raise Wrong("LATTICE.json: needs a target") target = c["target"] if target in OTHERS: raise NotChecked(target) if target not in SURFACES: raise Wrong(f"LATTICE.json: unknown target {target!r}; the check knows {', '.join(SURFACES)}") d = SURFACES[target] if c.get("n") != 2 or c.get("d") != d: raise Wrong(f"LATTICE.json: {target} is the Fermat surface of degree {d}: n = 2, d = {d}") raw = c.get("cycles") if not isinstance(raw, list): raise Wrong("LATTICE.json: cycles is not a list") cycles = [cycle(x, d, f"LATTICE.json: cycle {i}") for i, x in enumerate(raw)] if len(set(cycles)) != len(cycles): raise Wrong("LATTICE.json: a cycle is listed twice") if set(cycles) != every_cycle(d): raise Wrong(f"LATTICE.json: the cycles are not all {3 * d * d} linear cycles of the surface") G = [[meet(P, Q, d) for Q in cycles] for P in cycles] gram = c.get("gram") if not isinstance(gram, list) or len(gram) != len(G) or any(not isinstance(row, list) or len(row) != len(G) for row in gram): raise Wrong(f"LATTICE.json: gram is not a {len(G)} x {len(G)} matrix") for i, row in enumerate(gram): for j, x in enumerate(row): if x != G[i][j] or type(x) is not int: raise Wrong(f"LATTICE.json: gram[{i}][{j}] is {x!r}; cycles {i} and {j} meet with intersection number {G[i][j]}") ds = divisors(G) if c.get("rank") != len(ds): raise Wrong(f"LATTICE.json: rank is {c.get('rank')!r}; it is {len(ds)}") if c.get("divisors") != ds: raise Wrong(f"LATTICE.json: the elementary divisors are {word(ds)}, not {c.get('divisors')!r}") return f"{target}: {len(G)} lines, rank {len(ds)}, elementary divisors {word(ds)}" class NotChecked(Exception): """A target this check does not verify yet; a maintainer reads the certificate instead.""" def main(argv): if len(argv) != 2: print("usage: verify.py FOLDER", file=sys.stderr) return 2 folder = Path(argv[1]) if not folder.is_dir(): # the default branch, or a route that has not made its folder yet print("Nothing to check here: this commit has no route folder.") return 0 table = json.loads((HERE / "exceptional.json").read_text(encoding="utf-8")) said = [] try: for q in instances(): path = folder / f"xi{q}.json" if path.is_file(): n, used = length(path.name, read(path), table[str(q)]) said.append((f"q = {q}: {n}", f"{path.name}: length {n} modulo {sum(used.values())} algebraic terms ({', '.join(f'{v} {k}' for k, v in sorted(used.items()))}); {'at most 6: xi_' + str(q) + ' is algebraic, if MMRV holds' if n <= 6 else 'above 6: not settled'}")) if (folder / "LATTICE.json").is_file(): try: said.append((lattice(read(folder / "LATTICE.json")), "")) except NotChecked as e: said.append((f"no automatic verifier for {e} yet: a maintainer reads it, as docs/submission.md says", "")) except Wrong as e: print(f"FAILED {e}") return 1 for _, detail in said: if detail: print(detail) print("; ".join(line for line, _ in said) if said else "Nothing to check yet: the route's folder holds no xi.json and no LATTICE.json.") return 0 if __name__ == "__main__": sys.exit(main(sys.argv))