Abstract
"Grokking" is a phenomenon where neural networks suddenly achieve perfect generalization long after memorizing training data. This paper investigates why certain modular polynomials are "grok-able" while others remain memorized. By deriving analytical weight solutions for 2-layer Multi-Layer Perceptrons (MLPs), the authors propose that learnability is constrained by a specific additive functional form: $h(g_1(n_1) + g_2(n_2)) \pmod p$. We demonstrate that trained networks converge to these theoretical periodic solutions, and we provide a compositional framework to solve complex polynomials that standard training fails to generalize.
Introduction
Deep learning models often exhibit a "generalization gap" in algorithmic tasks. In modular arithmetic, a model might achieve 100% training accuracy quickly but require thousands of additional epochs to "grok" the underlying mathematical rule. While well-documented for simple addition, the boundary between learnable and un-learnable modular functions has remained opaque. This study bridges the gap between empirical observation and mathematical theory by identifying the structural requirements for generalization in 2-layer MLPs.
Methods
The authors extend previous work on modular addition through three primary technical contributions:
- Analytical Weight Construction: They derive explicit formulas for MLP weights using periodic cosine-based functions. These weights exploit the inherent symmetries of finite fields $GF(p)$.
- Logarithmic Mapping: Modular multiplication is solved by transforming it into an addition problem in "log-space" using primitive roots. This allows an addition-optimized network architecture to be repurposed for multiplication.
- Compositional Expert Networks: For complex polynomials, the authors propose a modular architecture where "multiplication experts" feed into an "addition expert." A low-temperature Softmax function is used to maintain clean internal representations, enabling the network to solve polynomials that are otherwise "un-learnable" via standard SGD.
Results and Discussion
The Learnability Boundary
The central finding is Hypothesis 5.1: a standard 2-layer MLP can only grok a polynomial if it can be decomposed into the form $h(g_1(n_1) + g_2(n_2)) \pmod p$. If variables are entangled in a way that violates this additive structure—such as adding a raw cross-term $n_1n_2$ to an existing sum—the network fails to generalize. For example, while $(4n_1 + n_2^2)^3 \pmod{97}$ is easily grokked, adding $n_1n_2$ causes test accuracy to drop to 2.27%, despite perfect training accuracy.
Structural Convergence
The authors show that the optimization process naturally favors the periodic solutions they derived analytically. By measuring the Inverse Participation Ratio (IPR), they quantify the "periodicity" of neurons. As shown in Figure 1, the average IPR increases monotonically as the network groks, confirming the transition from random memorization to structured periodic representation.
The Cost of Complexity
While analytical solutions exist for many-term addition, the required network width ($N$) grows exponentially with the number of terms ($S$). This explains the empirical difficulty of grokking longer mathematical expressions; as the number of terms increases, the "cross-talk" between periodic components requires a significantly larger hidden layer to suppress.
Conclusion
This work provides a theoretical foundation for understanding generalization in modular arithmetic. By identifying the $h(g_1 + g_2)$ learnability form and validating it through IPR analysis, the authors clarify why neural networks "get" some math and fail at others. Future work will explore whether these findings extend to deeper architectures like Transformers and if optimization biases can be steered toward more complex functional forms.
Summary updated