"""Certify a diagonal ternary Foulkes block by projecting split-point evaluations.""" import argparse from functools import lru_cache from itertools import groupby from time import perf_counter import numpy as np P = 239 class WeightSpaces: def __init__(self, degree): self.degree = degree self.terms = [ (degree - y - t, y, t) for y in range(degree + 1) for t in range(degree - y + 1) ] self.ids = {alpha: i for i, alpha in enumerate(self.terms)} @lru_cache(None) def basis(self, weight): a = self.degree _, y, t = weight terms = [(i, j, k) for i, (_, j, k) in enumerate(self.terms) if j <= y and k <= t] result = [] def visit(low, n, b, c, monomial): if n == 1: if b + c <= a: i = self.ids[a - b - c, b, c] if i >= low: result.append(tuple(monomial + [i])) return for i, j, k in terms: if i >= low and j <= b and k <= c: if b + c - j - k <= (n - 1) * a: visit(i, n - 1, b - j, c - k, monomial + [i]) visit(0, a, y, t, []) return result @lru_cache(None) def ladder(self, weight, i, j): """E_ij on coefficient monomials in the raw split-coefficient normalization.""" from scipy.sparse import csr_matrix dest = list(weight) dest[i] += 1 dest[j] -= 1 dest = tuple(dest) old = self.basis(weight) positions = {mon: u for u, mon in enumerate(self.basis(dest))} changes = {} for q, alpha in enumerate(self.terms): if alpha[j]: beta = list(alpha) beta[i] += 1 beta[j] -= 1 changes[q] = (self.ids[tuple(beta)], beta[i]) rows, cols, vals = [], [], [] for col, mon in enumerate(old): for q, group in groupby(mon): if q not in changes: continue dest_id, factor = changes[q] new = list(mon) new.remove(q) new.append(dest_id) rows.append(positions[tuple(sorted(new))]) cols.append(col) vals.append(factor * sum(1 for _ in group)) return csr_matrix( (np.asarray(vals, dtype=np.int32), (rows, cols)), shape=(len(positions), len(old)) ) def root_transpose(self, batch, weight, i, j, shift): """Apply the transpose of one root factor with a forward and backward sweep.""" upper = [batch] levels = [weight] coeff = [] for r in range(1, weight[j] + 1): old = levels[-1] dest = list(old) dest[i] += 1 dest[j] -= 1 dest = tuple(dest) if not self.basis(dest): break down = self.ladder(dest, j, i) upper.append((down.T @ upper[-1]) % P) levels.append(dest) coeff.append(-pow(r * (weight[i] - weight[j] + shift + r), -1, P) % P) out = upper.pop() for r in reversed(range(len(coeff))): up = self.ladder(levels[r], i, j) out = (upper.pop() + coeff[r] * ((up.T @ out) % P)) % P return out def project_rows(self, batch, weight): for i, j, shift in ((1, 2, 1), (0, 2, 2), (0, 1, 1)): batch = self.root_transpose(batch, weight, i, j, shift) return batch def multiplicity(a, lam): _, y, t = lam weights = np.zeros((a + 1, y + 2, t + 1), dtype=object) weights[0, 0, 0] = 1 for b in range(min(a, y + 1) + 1): for c in range(min(a - b, t) + 1): for n in range(1, a + 1): weights[n, b:, c:] += weights[n - 1, : y + 2 - b, : t + 1 - c] def w(b, c): return int(weights[a, b, c]) if min(b, c) >= 0 else 0 return w(y, t) - w(y - 1, t) - w(y + 1, t - 1) + w(y - 1, t - 1) + w(y + 1, t - 2) - w(y, t - 2) def split_values(a, terms, count, rng, fix_first=False, repeat_first=False): coeff = np.zeros((count, a + 1, a + 1), dtype=np.int32) coeff[:, 0, 0] = 1 for slot in range(a): u, v = rng.integers(P, size=(2, count, 1, 1), dtype=np.int32) if slot == 0: du, dv = u, v if slot == 1 and repeat_first: u, v = du, dv if fix_first: if slot == 0 or (slot == 1 and repeat_first): continue u, v = u - du, v - dv old = coeff.copy() coeff[:, 1:, :] += u * old[:, :-1, :] coeff[:, :, 1:] += v * old[:, :, :-1] coeff %= P return np.stack([coeff[:, y, t] for _, y, t in terms]) def repeat_rows(pivots, rows, batch, allowance): """Keep full batches inside a slab on the double-factor locus.""" if allowance >= pivots: return rows return max(0, allowance) // batch * batch def certify(a, lam, batch_size): from flint import nmod_mat start = perf_counter() spaces = WeightSpaces(a) monomials = np.asarray(spaces.basis(lam), dtype=np.int32) m = multiplicity(a, lam) rng = np.random.Generator(np.random.PCG64(50158)) if not m: print(f"a={a} shape={lam} multiplicity=0") return # Shuffle raw coordinates into m buckets and use one coefficient per coordinate. # A full-rank result is a certificate for the original projected rows. order = rng.permutation(len(monomials)) factors = rng.integers(1, P, size=(len(order), 1), dtype=np.int32) starts = np.arange(m) * len(order) // m projected = [] for base in range(0, m + 4, batch_size): count = min(batch_size, m + 4 - base) coeff = split_values(a, spaces.terms, count, rng) values = np.ones((len(monomials), count), dtype=np.int32) for ids in monomials.T: values = values * coeff[ids] % P values = spaces.project_rows(values, lam) weighted = values[order] * factors projected.append((np.add.reduceat(weighted, starts, axis=0, dtype=np.int64) % P).T) rank = nmod_mat(np.vstack(projected).tolist(), P).rank() print( f"a={a} shape={lam} raw={len(monomials)} multiplicity={m} rank={rank} " f"seconds={perf_counter() - start:.3f}", flush=True, ) if rank != m: raise ArithmeticError("the projected minor did not reach the character multiplicity") if __name__ == "__main__": p = argparse.ArgumentParser(description=__doc__) p.add_argument("a", type=int) p.add_argument("shape", nargs=3, type=int) p.add_argument("--batch", type=int, default=16) args = p.parse_args() l, m, k = args.shape if not ( l >= m >= k >= 0 and min(args.a, args.batch) > 0 and sum(args.shape) == args.a**2 < P - 2 ): p.error("expected a dominant diagonal shape of positive degree below the rank prime") certify(args.a, tuple(args.shape), args.batch)