cross-prime-v1 β Modular Arithmetic Challenge
A compliant submission to the SAIR Modular Arithmetic Challenge:
a neural network that learns to compute (a Β· b) mod p for a prime p and
integers a, b that may be far larger than p.
Team MCSC (MAC01-T00008).
What it is
A prime-conditioned joint Transformer encoder (~3.2M parameters). The digits
of a mod p, b mod p, and p are tokenized (base-10, fixed width 5, with
learned token / position / segment embeddings) and a 6-layer encoder attends
over all three operands jointly, reading out the answer as 5 base-10 digits via
per-position linear heads.
It deliberately does not use the discrete-log / additive bottleneck of the
reference dlp_grokking model β whose own ablation showed that bias is not the
limiting factor; the wall is generalizing across primes. This model instead
lets attention learn the field operation directly, conditioned on p.
Results (official pipeline, public benchmark, 100 problems/tier)
| Tier | p bits | this model | dlp_grokking (best reference) |
|---|---|---|---|
| 1 | 1β3 | 1.00 | 1.00 |
| 2 | 4β8 | 0.35 | 0.12 |
| 3β10 | 9β2048 | ~0.02 | ~0.02 |
| overall_accuracy | 0.150 | 0.127 | |
| highest_tier_above_90 | 1 | 1 |
Beats the strongest shipped baseline on overall_accuracy; tier 2 ~3Γ. Scores identically on CPU and MPS (deterministic), and runs the full 1100-problem set in ~35s (budget: 5 min).
How it stays compliant
The answer comes from trained parameters, not a hand-coded algorithm
(SAIR rules/evaluation.md, Principle 2 β perturbing the weights collapses
accuracy):
preprocess_{a,b,p}are pure per-argument identities (no cross-argument leakage).predict_digitsreducesa % pandb % p(two operands at a time β the same legal normalization the reference baselines use) and never formsa Β· b, never computes(aΒ·b) % p, and uses no lookup table. The network argmax is the answer.- No
sympy/gmpy2/ Barrett / CRT in the forward path. Forp β₯ 10β΅(outside the trained width) it emits a constant0β an honest out-of-regime fallback, not an answer shortcut.
Files
model.pyβ architecture + theModularMultiplicationModelentry class.manifest.jsonβ entry class,output_base = 10, required descriptions.weights.ptβ{state_dict, config}.
Limitations
Tiers 3+ (thousands of distinct primes) sit near the floor: the model memorizes the per-prime multiplication tables it was trained on but does not yet generalize the operation to unseen primes β the open problem at the heart of the challenge. A reciprocal/learned-Barrett variant is under development to attack exactly that.