How many entries of a group’s multiplication table does a transformer need to see?

Summary

  • A simple rule-based algorithm fills in the multiplication table of a group of order $n$ from around $0.71\,n^{3/2}$ random entries. It only ever combines 2 known entries that share a row or a column. A random graph heuristic predicts the constant 0.71, and simulations on all 6 groups agree. Steinberg’s results for $\mathbf Z/p\mathbf Z$ are also broadly in line with an exponent of $3/2$, though I do not know whether there is any deep reason for this.
  • A 1-layer transformer typically needs between $2.7\,n^{3/2}$ and $3.2\,n^{3/2}$ entries for the cyclic groups of order 60, 120 and 168, so roughly 4 times more than the rule-based algorithm. For the 3 corresponding non-abelian groups this increases by a further factor of 1.7-2.2; no such increase for the rule-based algorithm.
  • Fitting a power law gives an exponent of 1.67 over the 3 cyclic groups and 1.91 over the 3 non-abelian ones. Obviously this is far too few points to be confident about any exponent, but the non-abelian thresholds look nearer to $n^2$, which the rule-based algorithm does not account for. Of course, all models were run with equal widths, so at least some of this difference could be due to lack of capacity.

Question

Given $m$ entries chosen uniformly at random from the group multiplication table (with group elements relabelled arbitrarily), complete the remaining entries. How many entries will be needed? I give 2 answers: one from a simple algorithm, which makes no distinction between abelian and non-abelian groups, and one measured empirically for a fairly small neural network, where the question is whether the answer depends on the group being non-abelian.

Much work has been done for this task on $\mathbf Z/p\mathbf Z$. A small network trained on $a+b \bmod p$ will first memorize its training entries and only much later generalize to the rest. This “grokking” (Power et al. 2022) was analysed by Nanda et al. (2023), who showed that a one-layer network learns to compute $a+b \bmod p$ by representing some small set of values of $e^{2\pi i ka/p}$ as rotations of $\mathbf R^2$ and multiplying to obtain values of $e^{2\pi i k(a+b)/p}$, then returning the unique element with the corresponding set of rotations. Steinberg (2026) varies the prime from 31 to 113 and asks how many entries must be given to elicit generalization. This threshold grows roughly like $2.7\,p^{3/2}$, while directly fitting a power law gives exponent 1.42, and Steinberg rightly calls this suggestive rather than settled, given less than a 4-fold range in size of prime.

There is no obvious benchmark for how well this is done, and I know of no such measurement for non-abelian groups. I describe a basic algorithm, which explains at least one way of getting an exponent of $3/2$. I also run the same 1-layer network for 3 orders, each time with an abelian and a non-abelian group.

At each of orders 60, 120 and 168 I compare the cyclic group with a non-abelian group, namely $A_5$, $S_5$ and $\mathrm{PSL}_2(\mathbf F_7)$ respectively. Networks trained on groups seem to build their solutions out of representations, so the final column gives the dimensions of the irreducible complex representations. In the abelian case these correspond simply to the various $a\mapsto e^{2\pi i ka/n}$, that is, rotations of the plane as used by the network discussed above, whereas the others range up to dimension 8.

GroupOrderAbelianIrreducible representations
$\mathbf Z/60\mathbf Z$60yes60 of dimension 1
$A_5$60nodimensions 1, 3, 3, 4, 5
$\mathbf Z/120\mathbf Z$120yes120 of dimension 1
$S_5$120nodimensions 1, 1, 4, 4, 5, 5, 6
$\mathbf Z/168\mathbf Z$168yes168 of dimension 1
$\mathrm{PSL}_2(\mathbf F_7)$168nodimensions 1, 3, 3, 6, 7, 8

The algorithm (or network) is given $m$ entries $(a,b,ab)$ uniformly at random without replacement, and must predict the remaining $n^2-m$. Since the labels are shuffled there is no arithmetic to exploit, and the only way to distinguish $\mathbf Z/60\mathbf Z$ from $A_5$ is via the given entries.

Rule-based algorithm

The algorithm uses only the following identity, valid in any group: if $ab=c$ and $ab'=c'$ are given entries in the same row, then \[ b^{-1}b' \;=\; (ab)^{-1}(ab') \;=\; c^{-1}c'. \] Likewise $ab=c$ and $a'b=c'$ in the same column give $a\,a'^{-1}=c\,c'^{-1}$. Commutativity is never used. Note this does not tell us $b^{-1}b'$ itself, only that the pairs $(b,b')$ and $(c,c')$ have equal quotients.

To keep track of this, take the graph whose vertices are the $n^2$ ordered pairs $(u,v)$ of symbols, with $u^{-1}v$ the left quotient of $(u,v)$. Every instance of the row identity adds edges $(b,b')$–$(c,c')$ and $(b',b)$–$(c',c)$, hence left quotients are constant on connected components. The column identity similarly gives a graph for right quotients $uv^{-1}$, and the algorithm simply maintains the components of both graphs as edges are added.

Prediction of an unknown entry $xy$ then works as follows. Pick a given entry $xy'=z$ in the same row and look in the component of $(y',y)$ for some pair $(z,w)$; if there is one then $z^{-1}w=y'^{-1}y$, so $w=z\,y'^{-1}y=xy$. The column is handled the same way using right quotients. So the algorithm never actually guesses, and any answer it gives is correct; the only question is how often it can give one.

The threshold can be estimated heuristically. There are roughly $m/n$ given entries per row, every ordered pair of which gives an edge, so about $n(m/n)^2=m^2/n$ edges in total. Edges only ever join pairs with the same quotient, so the graph is really $n$ separate graphs on $n$ vertices each (one per value of the quotient), with around $m^2/n^2$ edges each, i.e. mean degree $2m^2/n^3$. A query succeeds when 2 particular vertices of one of these are connected, which is likely once there is a giant component, and for a random graph this appears at mean degree 1 (Erdős–Rényi). Hence \[ \frac{2m^2}{n^3}=1 \quad\Longleftrightarrow\quad m^\ast=\frac{n^{3/2}}{\sqrt2}\approx 0.71\,n^{3/2}. \] Below $m^\ast$ the components are small and few queries succeed. Above $m^\ast$ each of the 2 vertices lies in the giant component with positive probability, and since each query gets around $\sqrt n$ attempts from its row and the same again from its column, almost all queries succeed. Of course the edges are not independent, as all edges coming from the same given entry are correlated, so this is only a heuristic. I will call this mechanism pairing, since it only ever combines 2 given entries at a time.

  • abelian: $\mathbf Z/60\mathbf Z$, $\mathbf Z/120\mathbf Z$, $\mathbf Z/168\mathbf Z$
  • non-abelian: $A_5$, $S_5$, $\mathrm{PSL}_2(\mathbf F_7)$
  • heuristic estimate
Figure 1. Fraction of unknown entries the rule-based algorithm answers in a single pass, against $m/n^{3/2}$ (5 random training sets per point, 600 unknown entries each). All 6 groups reach one half at roughly $0.70\,n^{3/2}$, compared with the estimate $n^{3/2}/\sqrt2\approx0.71\,n^{3/2}$.

In all 6 groups half the unknown entries are answered at $m\approx0.70\,n^{3/2}$ (Figure 1), so the heuristic is off by only $0.01\,n^{3/2}$ and gets the constant as well as the exponent. Abelian and non-abelian groups of equal order give the same curve, which is to be expected given that the argument only uses the order. An algorithm which knew the group to be abelian could of course do better, since then $ab=c$ also gives $ba=c$, but this one is not told.

Repeated passes and a lower bound

A single pass uses each pair of given entries once. Adding every derived entry back in and repeating until nothing new follows brings the threshold down to $1.4n$ at order 60 and $2.1n$ to $2.3n$ at order 168 (see Figure 5 for all groups). Divided by $n^{3/2}$ this is 0.16-0.19 for all 6 groups, and a least-squares fit gives $m^\ast\propto n^{1.41}$; so at least over this range, repeated passes improve the constant by a factor of around 4 rather than the exponent. In simulations at orders 60 and 120, a run with repeated passes either stalls having answered less than a tenth of the unknown entries, or answers more than four fifths, rather like bootstrap percolation. I have no derivation of this threshold, and at these orders it cannot be distinguished from $n^{3/2}$ over some power of $\log n$.

For a lower bound, note that since the labels are shuffled, even an algorithm that knows the group has $n!/|\mathrm{Aut}(G)|$ possible tables to choose between, and an entry carries at most $\log_2 n$ bits. Recovering the table therefore needs at least about $\log_2(n!)/\log_2 n$ entries, which is roughly $0.8n$ here. Somewhere between this and the rule-based algorithm is the algebraic algorithm for cyclic groups of prime order $p$: give each symbol an unknown $x_s\in\mathbf F_p$, read each given entry $(a,b,c)$ as $x_c=x_a+x_b$, and solve by Gaussian elimination. It depends on commutativity, so I include it only for reference.

  • measured for this post
  • Steinberg (2026)
Figure 2. Entries of the $\mathbf Z/113\mathbf Z$ table (12,769 total) needed by each algorithm, log scale. For the rule-based algorithm this is the point at which half the unknown entries are answered, and for the transformer the point at which the median seed reaches 95% test accuracy, within 40,000 epochs (Steinberg) or 30,000 steps (mine). The rule-based curves are steep enough that the ordering does not depend on these choices. The dotted lines mark the lower bound $\log_2(113!)/\log_2 113\approx90$ and the whole table.

So on $\mathbf Z/113\mathbf Z$ (Figure 2) the transformer is a long way above the lower bound, needing around 4 times what a single pass of the rule-based algorithm needs, and 16-17 times what repeated passes need.

Transformer

The rule-based threshold only depends on the order of the group. For the network I expected non-abelian groups to be harder: networks trained on groups apparently build their solutions out of representations (Chughtai et al. 2023) or cosets (Stander et al. 2024), and in the first case $A_5$ requires $3\times3$ up to $5\times5$ matrices where $\mathbf Z/60\mathbf Z$ makes do with rotations of the plane. I fixed in advance what would count as a difference, namely that the 90% bootstrap intervals of the 2 thresholds in a pair are disjoint.

I use the 1-layer transformer of Nanda et al. (2023), which Steinberg also uses, at varying width. Here the width is 128, with 4 attention heads, a ReLU MLP of width 512, no LayerNorm, and the answer read from the logits at an “=” token after $a$ and $b$. Training is full-batch AdamW (learning rate $10^{-3}$, betas $(0.9, 0.98)$, weight decay 1.0, 10 warm-up steps) on a fraction $f$ of the entries for up to 30,000 steps, and a run counts as a success if test accuracy reaches 95% within that. The relabelling, train/test split and initialization are all redrawn for each seed.

For each group the threshold $f^\ast_{50}$ is the fraction where the success rate first hits one half, interpolating in $\log f$ (so $m^\ast=f^\ast_{50}n^2$), and the 90% interval is from 1,000 bootstrap resamples of the runs. I started with a coarse grid of 6 fractions and then added 4 more near each crossing, 5 seeds per fraction, with the same settings throughout. I also ran $\mathbf Z/113\mathbf Z$, to compare against Steinberg.

Figure 3 has the pair of order 60. All runs fit the training entries within 200 steps, and test accuracy only goes up thousands of steps after that. At the same fraction of the table this happens later for $A_5$ than for $\mathbf Z/60\mathbf Z$, if at all within the budget.

  • $\mathbf Z/60\mathbf Z$, test accuracy
  • $A_5$, test accuracy
  • training accuracy, every run
Figure 3. Training curves for the 2 groups of order 60 on 40% and 60% of the table, 5 runs each; a run stops when test accuracy reaches 95% (marker). At 40% all the $\mathbf Z/60\mathbf Z$ runs get there between steps 8,000 and 16,000, while no $A_5$ run gets above 1%. At 60% the $\mathbf Z/60\mathbf Z$ runs take at most 1,200 steps, and 3 of the 5 $A_5$ runs succeed, at steps 16,000-25,000.

Doing this for a range of fractions gives Figure 4. For the cyclic groups of order 60, 120, 168 the thresholds $f^\ast_{50}$ come out at 0.34, 0.27, 0.24, whereas $A_5$, $S_5$ and $\mathrm{PSL}_2(\mathbf F_7)$ give 0.59, 0.54, 0.54. Within each pair the 90% intervals are disjoint (see Figure 5), so by the criterion fixed beforehand all 3 pairs differ, in the direction I expected. On $\mathbf Z/113\mathbf Z$ I get 0.27, against 0.25 for Steinberg.

  • cyclic
  • non-abelian
  • half the runs
Figure 4. Runs (out of 5) reaching 95% test accuracy within 30,000 steps, against training fraction $f$; $f^\ast_{50}$ is where a curve first meets the dotted line. The cyclic curves move left as the order grows. The non-abelian ones stay between 0.5 and 0.6 and are also less steep, with $A_5$ and $\mathrm{PSL}_2(\mathbf F_7)$ still having a failing run at $f=0.8$.

Comparing fractions is fine within a pair, as the orders agree, but not across orders. As Steinberg notes, a threshold growing like $n^{3/2}$ is a fraction shrinking like $n^{-1/2}$, which is why everything in Figure 5 is divided by $n^{3/2}$. Measured this way the rule-based algorithm needs 0.70 for all groups in a single pass and 0.16-0.19 with repeated passes. For the cyclic groups the transformer needs 2.7-3.2, which is close to Steinberg’s $2.7\,p^{3/2}$ and around 3.8-4.5 times the rule-based algorithm; the non-abelian groups need 4.6, 5.9 and 7.0.

Least-squares fits over the 3 orders give $m^\ast\propto n^{1.67}$ (cyclic) and $n^{1.91}$ (non-abelian), versus 1.42 for Steinberg’s primes 31-113. With 3 orders spanning a factor of only 2.8 I would not trust either exponent much, but they do suggest the non-abelian thresholds grow almost like the whole table. Equivalently, the ratio within a pair goes from 1.7 at order 60 up to 2.2 at order 168.

  • rule-based, one pass
  • rule-based, repeated passes
  • transformer, abelian
  • transformer, non-abelian
  • Steinberg (2026)
Figure 5. Entries needed by each algorithm divided by $n^{3/2}$, log scale, so that thresholds growing like $n^{3/2}$ line up. Grey ticks are the rule-based algorithm in a single pass (dark) and with repeated passes (light); markers are the transformer’s $f^\ast_{50}\sqrt n$ with 90% bootstrap intervals, circles cyclic and squares non-abelian, and the dotted line is Steinberg’s fit $2.7\,n^{3/2}$. The rule-based algorithm needs the same for both groups of a given order, whereas the transformer needs 1.7-2.2 times more for the non-abelian one, increasingly so with the order.

All of this depends on the budget, as a run that is still improving at step 30,000 might succeed later. I meant to check this only for order 60, but the non-abelian runs that succeeded often did so late, so I reran all 3 pairs for 60,000 steps at 6 fractions around each crossing (Figure 6). Every threshold drops by 4-9%, and the non-abelian group in each pair still needs more entries, with intervals still disjoint. Between a fifth and a half of the successful runs in each group only reached 95% after step 30,000, so the budget does partly set the thresholds, for abelian and non-abelian groups alike.

  • 30,000 steps
  • 60,000 steps
Figure 6. $f^\ast_{50}$ for each group with 30,000 steps (hollow) and 60,000 steps (filled). Doubling the budget lowers every threshold by 4-9%, and the gap within each pair stays.

Discussion

In every pair the transformer needs 1.7-2.2 times as many entries for the non-abelian group, while the rule-based algorithm needs the same for both, so the network is picking up on something the algorithm ignores. Possibly it builds its solution from irreducible representations, which are bigger for these groups; possibly it uses $ab=ba$ (which would also help a rule-based algorithm allowed to use it); or the non-abelian solutions might just need more width than I gave them. Telling these apart would need varying the width and looking inside the trained networks, and I have done neither.

What the rule-based algorithm does give is one concrete way for an exponent of $3/2$ to come about, namely that a query gets answered once 2 pairs are connected via other given entries, which happens once $m^2/n^3$ is of order 1. A transformer doing this would have a threshold scaling the same way. For the cyclic groups it needs 3.8-4.5 times the rule-based algorithm between orders 60 and 168, consistent with the same exponent and a worse constant, but equally consistent with the 1.67 from the power-law fit; 3 orders cannot settle this. I doubt it says much about what the network is really doing in any case, and it says nothing about the non-abelian groups, where the pairing argument is unchanged yet the transformer’s thresholds grow nearly like $n^2$.

Caveats

The experiment is fairly small: 3 pairs of groups of orders 60-168, 1 architecture, 1 optimizer setting, 5 seeds per fraction, hence wide intervals.

Every group was run at the same width (128, MLP width 512). At the critical fraction for $\mathbf Z/p\mathbf Z$ Steinberg finds only a minority of seeds grok at widths 16-64, but all of them at 128 and 256. A solution built from representations of dimension up to 8 may well need more width than one built from rotations of the plane, so at least part of the gap within each pair could be capacity.

The exponents in Figure 5 are from 3 orders spanning a factor of 2.8, and the cyclic orders are not prime, unlike Steinberg’s. Thresholds also depend on the training budget; doubling it lowered them 4-9% without changing any comparison (Figure 6), but I did not try beyond 60,000 steps.

The estimate $n^{3/2}/\sqrt2$ treats correlated edges as independent and is not a theorem, and the repeated-pass threshold is purely empirical. Finally, the rule-based algorithm is meant as a benchmark, not as a model of what networks compute.

A few pointers, not a survey. Grokking was first observed by Power et al. (2022), and the algorithm described above for $\mathbf Z/p\mathbf Z$ is from Nanda et al. (2023). For other groups there is work on networks using representations (Chughtai et al. 2023) and cosets (Stander et al. 2024). The sample complexity of modular addition has also been studied theoretically, e.g. by Mohamadi et al. (2024) and Huang and Li (2025), and Gu et al. (2026) look at grokking on Latin squares more generally. The $n^{3/2}$ scale for random sparse equations comes from the literature on refuting random constraint satisfaction problems and on tensor completion (Allen, O’Donnell and Witmer 2015; Barak and Moitra 2016; Kothari et al. 2017). The $p^{3/2}$ measurement used throughout is Steinberg’s (2026).

Code

Code: github.com/ayan7744/learning-group-laws. python fig1.py gives Figure 1, python thresholds.py the rule-based numbers in Figures 2 and 5, and python analyze.py results.jsonl the transformer thresholds in Figures 4-6 (run once on the 30,000-step runs and once on the 60,000-step ones). Every line of results.jsonl also contains its run’s training curve, which is what Figure 3 plots. The rule-based numbers took under a minute on 32 CPU cores of MIT’s Engaging cluster, the transformer runs around 21 GPU-hours on NVIDIA L40S GPUs.

References

  1. A. Power, Y. Burda, H. Edwards, I. Babuschkin, V. Misra. Grokking: generalization beyond overfitting on small algorithmic datasets (2022). arXiv:2201.02177
  2. N. Nanda, L. Chan, T. Lieberum, J. Smith, J. Steinhardt. Progress measures for grokking via mechanistic interpretability. ICLR (2023). arXiv:2301.05217
  3. B. Chughtai, L. Chan, N. Nanda. A toy model of universality: reverse engineering how networks learn group operations. ICML (2023). arXiv:2302.03025
  4. D. Stander, Q. Yu, H. Fan, S. Biderman. Grokking group multiplication with cosets. ICML (2024). arXiv:2312.06581
  5. M. A. Mohamadi, Z. Li, L. Wu, D. J. Sutherland. Why do you grok? A theoretical analysis of grokking modular addition. ICML (2024). arXiv:2407.12332
  6. T. Huang, Z. Li. Provable benefits of sinusoidal activation for modular addition (2025). arXiv:2511.23443
  7. J. Steinberg. The grokking phase diagram from a single layer transformer learning modular addition. Blog post, June 13th, 2026. jasteinberg.github.io
  8. Z. Gu, L. Zhao, T. Ma, H. Zhang, W. Su, Y. Cao, Y. Hu. Mapping the solution-set structure of grokking on Latin squares (2026). arXiv:2610.35036
  9. S. R. Allen, R. O’Donnell, D. Witmer. How to refute a random CSP. FOCS (2015). arXiv:1505.04383
  10. B. Barak, A. Moitra. Noisy tensor completion via the sum-of-squares hierarchy. COLT (2016). arXiv:1501.06521
  11. P. K. Kothari, R. Mori, R. O’Donnell, D. Witmer. Sum of squares lower bounds for refuting any CSP. STOC (2017). arXiv:1701.04521

Claude was used to draft a first version of this essay and to help write the code for the experiments.