Representations of Cyclic Groups in Neural Networks
Abstract
We take addition modulo \( p \) as a starting point for analysing how neural networks encode the structure of a group symmetry. Following the work of Chughtai et al. [1], we derive the form of the irreducible representations of the cyclic group \( \mathbb{Z}_p \) in two independent ways: through character theory and through diagonalization of the cyclic shift operator. Using the group \( \operatorname{SO}(2) \) as an example, we show that resorting to complex numbers is an algebraic necessity here, not a matter of notational convenience. On this basis we reconstruct Gromov's constructive proof [3], relating its Fourier weights to the previously derived invariant subspace \( V_m \), and we show that a single-hidden-layer perceptron architecture implements addition as a phase shift in this subspace. We then confront the analytical results with the weights of an actual trained network.
Introduction
Addition modulo \( p \) is a fundamental analytical problem in the study of the geometry of the internal representations of neural networks. Although the problem itself may seem elementary, it hides a non-trivial algebraic structure.
The argument is divided into two main parts. In the first, we analyse what representation structure is forced by the symmetry of modular addition. In the second, we check whether, and how, a neural network converges to it during optimization.
Why Complex Numbers
Before moving on to the formal proof, it is worth asking: are real numbers sufficient to describe this behaviour at all? Let us start by considering the group \( \operatorname{SO}(2) \), represented by the matrix:
Geometrically, this matrix rotates a vector by the angle \( \theta \). Let us now find its eigenvalues. From the characteristic equation \( \det(R(\theta) - \lambda I) = 0 \):
Computing the discriminant:
This means the equation has real solutions for \( \lambda \) only when \( \cos^2\theta = 1 \), that is, for \( \theta = 0 \) (the identity transformation) and \( \theta = \pi \) (a rotation by \( 180^\circ \), i.e. a point reflection through the origin). Geometrically, these are exactly the cases in which the rotated vector is collinear with the original one. For any other rotation angle, the rotated vector is never parallel to the original vector, so no real eigenvalue exists. The matrix \( R(\theta) \) is diagonalizable only over \( \mathbb{C} \):
This shows that introducing complex numbers into this problem is not a matter of notational convenience, but a necessity following from the algebraic closure of \( \mathbb{C} \). This field guarantees the existence of a full set of eigenvalues for orthogonal matrices.
Set θ to 0° or 180° to see a real eigenvector.
This phenomenon is not specific to \( SO(2) \). Every operator implementing a cyclic shift (including the action of the group \( \mathbb{Z}_p \) on a space of functions, which we will get to later) runs into the same obstacle and requires an analogous extension to \( \mathbb{C} \).
Characters of the Cyclic Group
Consider the cyclic group \( (\mathbb{Z}_p, +) \), i.e. the set of residues modulo \( p \) with the operation of addition modulo \( p \), where \( p \) is a prime.
In general representation theory we look for homomorphisms \( \rho : G \rightarrow \operatorname{GL}(V) \) that assign invertible matrices to the elements of the group \( G \). The character of such a representation is formally defined as the trace of the assigned matrix, i.e. \( \chi_\rho(g) = \operatorname{Tr}(\rho(g)) \). For the group \( \mathbb{Z}_p \), however, a key simplification occurs. Since addition modulo \( p \) is commutative, \( \mathbb{Z}_p \) is an abelian group. By Schur's lemma, over the field of complex numbers all irreducible representations of abelian groups are one-dimensional [2].
This means that our vector space \( V \) reduces to \( \mathbb{C}^1 \), and the matrices of the group \( \operatorname{GL}(V) \) reduce to single non-zero scalars. Since the trace of a \( 1 \times 1 \) matrix equals its only entry, the representation and its character become the same mathematical object (\( \rho \equiv \chi_\rho \)). This lets us drop the matrix machinery entirely and define the character directly as a map into the set of complex numbers \( \mathbb{C}^* \).
To understand what form these representations can take in a neural network, let us start by deriving their analytical form. Since \( \rho \) is a homomorphism, \( \chi \) inherits this property directly:
To determine the form of such a function for \( G = \mathbb{Z}_p \), let us first note its basic properties. First, every element \( k \in \mathbb{Z}_p \) can be written as the \( k \)-fold sum of the element \( 1 \), so the homomorphism property gives:
Moreover, since the group \( \mathbb{Z}_p \) has order \( p \), we have \( p \cdot 1 \equiv 0 \pmod{p} \). Substituting \( k = p \) into \( (1) \) and using \( \chi(0) = 1 \) (which follows directly from the homomorphism condition for \( g=h=0 \)), we obtain
Denoting \( z := \chi(1) \), we arrive at the condition:
so \( \chi(1) \) must be a \( p \)-th root of unity. The equation \( z^p = 1 \) has exactly \( p \) solutions in the complex numbers. Using Euler's formula, they can be written as:
Each choice of \( m \) gives a different value of \( \chi(1) \), and hence a different character, which motivates the notation \( \chi_m(1) := z_m =e^{2\pi i m/p} \). Substituting this into formula \( (1) \) from the previous paragraph, \( \chi(k) = \chi(1)^k \), we obtain the complete family of characters of the group \( \mathbb{Z}_p \):
Choose m and k to see the value of the character.
The Linear Algebra Approach
The problem can equally be approached from the side of pure linear algebra. Consider the space of functions \( V := \operatorname{Fun}(\mathbb{Z}_p, \mathbb{C}) \) and the action of an element \( h \in \mathbb{Z}_p \) on functions \( f: \mathbb{Z}_p \rightarrow \mathbb{C} \) by shifting the argument, \( f \mapsto f(\cdot - h) \). For any element \( h \in \mathbb{Z}_p \) we define the operator \( S_h \) as \( (S_hf)(k) := f(k - h \pmod p) \).
Our goal is to find a basis of the space \( V \) that is optimal for representing the action of this group. In linear-algebra terms, this means looking for functions that do not change their shape under a shift, but are only scaled by some value. We are therefore looking for common eigenvectors of the whole family of operators \( S_h \).
The structure of the cyclic group means that the action of the whole family of operators \( S_h \) is entirely determined by the action of the generator \( S_1 \).
Proof
This follows from the fact that the action of the group \( \mathbb{Z}_p \) on the space of functions is a map \( \rho : \mathbb{Z}_p \rightarrow \operatorname{GL}(V) \), where \( \rho(h):=S_h \). Just like \( \chi \), the function \( \rho \) has the homomorphism property, which can be written as:
Once a basis of \( V \) is chosen, operator composition \( \circ \) corresponds to ordinary matrix multiplication, so from here on we use the notation \( S_g \cdot S_h \). Following the same steps as for the characters, we derive:
This means it is enough to study the properties of the operator \( S_1 \) alone. If \( f \) is an eigenvector of \( S_1 \) with eigenvalue \( \lambda \), then it is automatically an eigenvector of every \( S_h \), with eigenvalue \( \lambda^h \).
To find the eigenvectors of the operator \( S_1 \), we formally look for an \( f \) such that \( S_1f = \lambda f \), i.e. \( f(k - 1) = \lambda f(k) \) for all \( k \in \mathbb{Z}_p \). The operator \( S_1 \) corresponds to a cyclic permutation matrix of size \( p \times p \). From its characteristic equation \( \det(S_1 - \lambda I) = 0 \) we obtain:
This means, just as with the character condition, that \( \lambda \) must be a \( p \)-th root of unity.
Constructing a Real Representation Basis
With a complete basis at hand, we can begin our discussion in the context of representations in neural networks. First, note that the values neural network models operate on are real. This forces us to convert the complex representation into its real counterpart. Using Euler's formula, the character can be written as:
We can now use the sum of the character \( \chi_m(k) \) and its conjugate \( \overline{\chi_m(k)} \). This operation is admissible within our basis, since the conjugate of a character is simply the character with a negated index: \( \overline{\chi_m(k)} = \overline{e^{2\pi i mk /p}} = e^{-2\pi i mk /p} = \chi_{-m}(k) \). Adding these expressions together, we get:
Dividing this result by \( 2 \), we recover a pure cosine function. We proceed analogously for the sine, subtracting the conjugate:
Dividing the expression \( \chi_m(k) - \overline{\chi_m(k)} \) by the constant \( 2i \), we obtain a real representation:
The pair of functions \( \left\{\cos\left(\frac{2\pi m k}{p}\right), \sin\left(\frac{2\pi m k}{p}\right)\right\} \) therefore forms a real basis spanning a two-dimensional subspace \( V_m \), on which the group \( \mathbb{Z}_p \) acts without any need to resort to complex numbers.
It is worth noting that \( \cos(2\pi m k / p) \) alone is not enough. The operator \( S_h \) does not simply scale this expression, but turns it into a linear combination of cosine and sine. This follows directly from the trigonometric identity \( \cos(\alpha - \beta) = \cos\alpha\cos\beta + \sin\alpha\sin\beta \):
This observation implies that the space spanned by the cosine alone is not invariant under the action of the group \( S_h \), since the shift maps the result into a space that also contains the sine. Only the pair \( \left\{\cos\left(\frac{2\pi m k}{p}\right), \sin\left(\frac{2\pi m k}{p}\right)\right\} \) spans the subspace \( V_m \), which is invariant, because for any element \( h \in \mathbb{Z}_p \) and any element \( v \in V_m \) we have \( S_h(v) \in V_m \).
Set h = 0 to see that only then the result is a pure cosine.
Representation in Networks
Having derived the representation of cyclic groups analytically, we can move on to the main question of our analysis: do neural networks spontaneously discover and encode these structures in a similar way? Important insights here come from Andrey Gromov's paper "Grokking modular arithmetic"[3], in which the author studies this question in the context of the dynamics of delayed generalization. In this article we reconstruct his constructive argument about the structure of the solution, deliberately leaving out the topic of grokking as beyond the scope of this article. We are interested only in the mechanics of how the representation forms, not in how fast it emerges over time.
Consider a two-layer perceptron without biases, defined in the mean-field parametrization as:
where:
- \( N \) is the width of the hidden layer, and \( k \in \{1, \dots, N\} \) indexes its neurons,
- \( D \) is the input dimension,
- \( q \in \{0, \dots, p - 1\} \) indexes the output classes (residues modulo \( p \)),
- \( \phi \) is a non-linear activation function.
The weight matrices are initialized from the standard normal distribution: \( W^{(1)}, W^{(2)} \sim \mathcal{N}(0, 1) \).
The author studies addition modulo \( p \) as a classification task. He fixes a (not necessarily prime) number \( p \) and the set \( \mathbb{Z}_p = \{0, 1, \dots, p - 1\} \). Each input number (\( a \) and \( b \)) is encoded as a one-hot vector of length \( p \). This means the model input has dimension \( 2p \) (the concatenation of two \( p \)-element vectors), and the output has dimension \( p \) with a softmax.
For analytical purposes we use the quadratic non-linearity \( \phi(u) = u^2 \). This choice preserves the non-linear character of the network while allowing an exact, algebraic analysis of the interactions between weights without resorting to a Taylor series approximation (which for ReLU requires an intermediate step through a smooth approximation of it, e.g. the Swish function \( x \cdot \sigma (\beta x) \), which converges to ReLU as \( \beta \rightarrow \infty \)). In this setting the network can be written algebraically in a very simple way:
where \( (\cdot)^{\odot 2} \) denotes squaring each element of the vector (the Hadamard square).
Analysis of the \( W^{(1)} \) Layer
The network receives two numbers, \( a \) and \( b \), each represented as a one-hot vector. This means the weight matrix of the first layer, \( W^{(1)} \), can naturally be split into two vertical blocks: \( W_A^{(1)} \), which processes the input \( a \), and \( W_B^{(1)} \) for the input \( b \).
With this split we can easily identify individual weights: the variable \( W_{A, k, a}^{(1)} \) is the weight connecting the active element of the \( a \)-th input to the \( k \)-th neuron of the hidden layer (and analogously for block \( B \)).
Since a one-hot vector acts as a selector (it picks one value and zeroes out the rest), we can skip the full matrix multiplication. The pre-activation state of the \( k \)-th neuron reduces to a scaled sum of the two selected weights:
Proof
The input vector \( x \in \mathbb{R}^{2p} \) is the concatenation of two one-hot vectors for the numbers \( a, b \in \{0, \dots, p - 1 \} \):
where \( e_a \in \mathbb{R}^p \) has the value \( 1 \) at position \( a \) and \( 0 \) at all other positions (and analogously for \( e_b \)).
The weight matrix of the first layer \( W^{(1)} \in \mathbb{R}^{N \times 2p} \) consists of 2 independent blocks of size \( N \times p \):
Substituting this split into the formula for the linear activation of the hidden layer, we get:
Multiplying a matrix by a unit vector, \( W_A^{(1)} e_a \), selects the \( a \)-th column of the matrix \( W_A^{(1)} \). Going from vector notation to the level of a single, \( k \)-th neuron, we obtain directly:
Applying the chosen activation function \( \phi(u) = u^2 \), the output of the \( k \)-th neuron takes the form:
Expanding the square:
The next step is to substitute the Fourier frequency assumption (\( W_{A,k,a} \propto \cos(\omega_m a + \phi_k) \) and \( W_{B,k,b} \propto \cos(\omega_m b + \psi_k) \)):
where \( \omega_k = \frac{2\pi m_k}{p} \) and \( c_k \) is the amplitude of the component.
Expanding the square of the sum:
We apply the trigonometric identities:
- \( \cos^2(\alpha) = \dfrac{1 + \cos(2\alpha)}{2} \)
- \( 2\cos(\alpha)\cos(\beta) = \cos(\alpha + \beta) + \cos(\alpha - \beta) \)
Substituting them into the formula:
The key point here is what this non-linearity implies. Squaring the sum of the signals produced, in the cross term, the expression \( \cos\big(\omega_k(a+b) + \phi_k + \psi_k\big) \), whose argument literally implements the addition of the input numbers \( a \) and \( b \).
Analysis of the \( W^{(2)} \) Layer
The full output activation of the \( q \)-th logit (for the predicted class \( q \in \mathbb{Z}_p \)) is:
For the output corresponding to class \( q \in \{0, 1, \dots, p-1\} \), the weight connecting the \( k \)-th neuron to the \( q \)-th logit has an independent, learnable phase, which we denote by \( \xi_k \):
Substituting \( W_{q, k}^{(2)} \) and \( z_k^{(1)}(a, b) \), we get:
To expand this product into the individual components averaged by the network, we multiply the term \( \cos(\omega_k q + \xi_k) \) by each element in the square brackets, using the trigonometric identity:
Full expansion
In the expanded equation we are mainly interested in the term
To eliminate the phase, we set \( \xi_k = \psi_k + \phi_k \), which gives
Full expansion
The next question is what happens to the remaining terms. All of them contain a phase shift \( \phi_k, \psi_k \) inside the \( \cos \). These phases are initialized randomly and behave like independent random variables.
As a consequence, when summing over a large hidden-layer width \( N \), these terms interfere destructively. By the Central Limit Theorem (CLT) and the mechanics of a random walk, the sum of such terms grows at the rate \( \mathcal{O}(\sqrt{N}) \). Since the whole bracket is preceded by a normalizing factor containing \( 1/N \), the final contribution of these eight terms to the logit scales as \( \mathcal{O}(1/\sqrt{N}) \) and statistically tends to zero for large networks.
The only component that is not cancelled out is the term entirely free of random variables:
For every neuron \( k \) tuned to a given frequency \( \omega_k \), this signal is deterministic and adds up constructively. Its sum grows at the rate \( \mathcal{O}(N) \), which, combined with the \( 1/N \) normalization in front of the bracket, gives a stable value of order \( \mathcal{O}(1) \).
After discarding the vanishing noise terms, the averaging reduces the entire multi-line expression to a single sum. Absorbing the factor \( \frac{1}{2} \) into the constant in front of the sum (\( \frac{1}{2pN}\cdot\frac{1}{2} = \frac{1}{4pN} \)), we obtain the final form of the output activation of the logit:
Assuming that neurons group into clusters tuned to shared frequencies, with \( \frac{c_k^2 d_k}{4p} \approx \gamma \):
Going from a sum over neurons to a sum over frequencies assumes that many neurons \( k \) are tuned to the same frequency \( \omega_k \). Their contributions have been aggregated here into a common amplitude \( \gamma \), assigned to the given frequency \( m \) rather than to an individual neuron. This leads to a set \( S_{\text{active}} \subset \{0, 1, \dots, p-1\} \) of Fourier frequencies to which the network's neurons are tuned. The construction does not determine how many or which frequencies will be selected during training. That depends on the architecture, the activation function and the course of optimization (mechanistic analyses in [4] point to cases of convergence to just a few components).
The component \( \cos\left( \frac{2\pi m}{p} (a + b - q) \right) \), viewed as a function of \( q \), belongs to the real subspace \( V_m \) spanned by the pair \( \{\cos, \sin\} \), which, as we showed in the first part of the analysis, is for \( m \neq 0 \) a subspace invariant under the cyclic shift operators and irreducible over \( \mathbb{R} \). Addition \( a+b \) is implemented in it as a phase shift. The construction therefore shows that the perceptron architecture is capable of implementing addition modulo \( p \) in the basis of irreducible representations of the group \( \mathbb{Z}_p \), up to terms vanishing like \( \mathcal{O}(1/\sqrt{N}) \). It does not, however, settle whether optimization leads to such a solution. That is an empirical question, addressed in part 2 (work in progress).
The Trained Network
Below is a visualization of an actual trained MLP (\( \operatorname{FN}_0 : \mathbb{R}^{2p} \to \mathbb{R}^{142} \), \( x^2 \), \( \operatorname{FN}_2 : \mathbb{R}^{142} \to \mathbb{R}^{p} \), no biases) solving addition modulo \( p = 71 \). The network shown was trained with AdamW, a learning rate of \( 10^{-3} \), without L2 regularization, on \( 100\% \) of all pairs \( (a, b) \), for \( 4\,000 \) epochs. We use the full dataset, deliberately without a train/test split, because we are interested only in the structure of the solution, not in the dynamics of reaching it (as mentioned above, we deliberately leave out grokking here).
Loading model weights…
References
- Chughtai, B., Chan, L., & Nanda, N. (2023). A Toy Model of Universality: Reverse Engineering how Networks Learn Group Operations. ICML.
- Serre, J-P. (1977). Linear Representations of Finite Groups. Graduate Texts in Mathematics, vol. 42. Springer.
- Gromov, A. (2023). Grokking modular arithmetic. arXiv:2301.02679.
- Nanda, N., Chan, L., Lieberum, T., Smith, J., & Steinhardt, J. (2023). Progress measures for grokking via mechanistic interpretability. ICLR.