< Back

Generating finite rings

Note: To be clear, the definition of ring I'm using includes the multiplicative identity 1.

A while back I wrote a program to exhaustively generate all finite rings of some given order $n$. This post shares the ideas that went into that.

In a computer, a ring of order $n$ can be represented as a pair consisting of an addition table and a multiplication table, each of the tables being $n\times n$. One could then generate the rings by brute force: iterate through all possible pairs of tables and check which ones satisfy the ring axioms. However, the number of pairs of tables, as a function of $n$, is

$$\left(n^{n^2}\right)^2 = n^{2n^2}.$$

For $n=3$ the computation is already infeasible. Luckily there are optimizations that can be made.

One easy observation is that by the classification of finite abelian groups (FAGs), all the valid addition tables are already known. If $G$ is the additive group of an order $n$ ring, then

$$\begin{equation} \label{eq:decompose} G \cong \bigoplus_i\Z_{d_i}\ ,\quad\text{where $d_{i+1}\mid d_i$ and $\prod_i d_i=n$}. \end{equation}$$

The $d_i$'s are called invariant factors. So the problem reduces to generating valid multiplication tables for a given addition able.

Another observation is that the multiplication table is fully determined by its restriction to a set of generators for $G$. The rest of the table can be determined using the distributive law and the addition table. For instance, if $g_1$ and $g_2$ are two generators for $G$, then we can determine the product of $2g_1+g_2$ and $g_1+2g_2$ as follows:

$$(2g_1+g_2)(g_1+2g_2) = ({g_1}^2+{g_1}^2)+(g_1g_2+g_1g_2+g_1g_2+g_1g_2)+g_2g_1+({g_2}^2+{g_2}^2).$$

Thus it suffices to specify the products ${g_1}^2$, $g_1g_2$, $g_2g_1$ and ${g_2}^2$. This reduces the number of multiplication tables that need to be checked to

$$n^{g^2},\ \text{where $g$ is the number of generators.}$$

Clearly it is desirable to minimise $g$. For example, looking at the additive group

$$\Z_4\oplus\Z_3\oplus\Z_2,$$

one's first instinct might be to consider the generators $(1,0,0)$, $(0,1,0)$ and $(0,0,1)$, in which case $g=3$. But this is not the minimum, for we have

$$\Z_4\oplus\Z_3\oplus\Z_2 \cong \Z_{12}\oplus\Z_2,$$

and the RHS can obviously be generated by 2 elements. We can't reduce $g$ to 1 since $\Z_{12}\oplus\Z_2$ is not cyclic, and so $g=2$ is the minimum. Note that when the minimum was attained, $\Z_{12}\oplus\Z_2$ was is in the form of \eqref{eq:decompose}; in general, the minimal number of generators is the number of (non-unit) invariant factors. This can actually be proved quite generally for finitely generated modules over a PID, of which FAGs are a specific example.

Proposition. Let $M$ be a fg module over a PID $D$. The minimum number of generators $g$ for $M$ is equal to the number of (non-unit) invariant factors, $k$.

Proof. Note that $g$ exists and is finite since $M$ is fg. On one hand we have $g\le k$ because given the decomposition $M\cong \bigoplus_{i=1}^k D/(d_i)$ where none of the $d_i$'s are units, there is an obvious generating set of size $k$. On the other hand, $M$ can be realised as a quotient $D^g/K$, and $K$ can be associated with an $n\times g$ matrix $A$, where $n\le g$ and the rows of $A$ generate $K$. The diagonal entries of the Smith normal form of $A$ consist of the invariant factors of $D^g/K$, of which there are $\le g$ of them. $\qed$

From now on I'll use $g$ to denote the minimum number of generators for a given FAG $G$. Furthermore, I will think of elements of $G$ as tuples in the direct sum decomposition $\bigoplus_i\Z_{d_i}$, and I will fix the generators $e_1,\ldots,e_g$, where $e_i$ refers to the tuple with $1$ at the $i$th component and 0 everywhere else. Let's take a moment to examine how the maximum of $g$ across all order $n$ FAGs changes with $n$. This is quite important, since the FAG with the largest $g$ will take up the vast majority of computing time in finding rings.

Consider a FAG with a large number of invariant factors. If $p$ is a prime dividing the smallest invariant factors, then it divides all of them, thus the multiplicity of $p$ in $n$ is very large. On the flip side, if the multiplicity of $p$ in $n$ is large, say $n=p^ka$ for large $k$ and $p\nmid a$, then we can exhibit an order $n$ FAG with many invariant factors, namely

$$\Z_{ap}\oplus\Z_p^{k-1}.$$

Thus, we see that the total number of multiplication tables depends greatly on the sizes of the multiplicies in the prime factorisation of $n$. This also supports the observation that rings with 'small' factorisations are easier to classify.

So far we've only talked about the additive structure, but further optimisations can be made if we consider the multiplicative structure too. First, note that the multiplicative identity 1 must have additive order $d_1$ (the largest invariant factor). For if the order is say $n$ and it is $< d_1$, then for each $r$ in the ring we have

$$\underbrace{r+\ldots+r}_\text{$n$ times} = \underbrace{(1+\ldots+1)}_\text{$n$ times}\cdot r = 0r = 0,$$

so every element has additive order $< d_1$. But this cannot be true because the element $e_1$ has additive order $d_1$!

The question is, which order $d_1$ element can 1 be? The answer is, we can set it to be the tuple $e_1$ without any loss of generality! (I prove this below). Therefore, the products $e_1e_k$ and $e_ke_1$ are known a priori for all $k$, and only $(g-1)^2$ products of the generators remain to be specified. Hence the number of multiplication tables reduces to

$$n^{(g-1)^2}.$$

I will now justify why $e_1$ can be used as 1. A priori, we only know that 1 has order $d_1$ in $G$. Thus, it has the form $(x_1,\ldots,x_g)$ where $x_1$ is a generator of $\Z_{d_1}$ and the rest are arbitrary. But then $G$ can be written as an internal direct sum

$$\angles{(x_1,\ldots,x_g)}\oplus \angles{e_2}\oplus \cdots\oplus \angles{e_g},$$

where the $i$th summand is isomorphic to $\Z_{d_i}$. We can thus represent elements of $G$ as tuples with respect to this internal direct sum, in which $e_1$ now corresponds to 1.

There is one last optimisation that I thought of but haven't implemented yet. Given $j,k$ satisfying $1<i\le j\le g$, we have that $e_i$ and $e_j$ have additive orders $d_i$ and $d_j$ respectively. Thus the additive order of the products $e_ie_j$ and $e_je_i$ must divide $(d_i,d_j)=d_j$. This implies that the products must belong in the subgroup

$$\underbrace{\Z_{d_j}\oplus\cdots\oplus\Z_{d_j}}_\text{$j$ times}\oplus \Z_{d_{j+1}}\oplus\cdots\Z_{d_g} \le \bigoplus_i\Z_{d_i},$$

which is precisely the subgroup of elements with order dividing $d_j$. In practise I don't think this is a significant optimization.

Addendum: classifying order $p$ and $p^2$ rings

Lemma. The only ring with cyclic additive group $\Z_n$ is $\ZZ n$.

Proof. Such a ring's multiplicative structure is completely determined by the product of the generator $1\in\Z_n$ with itself. By the remarks above we can assume WLOG that 1 is also the multiplicative identity, in which case we are forced to have $1\cdot1=1$, giving rise to the ring $\ZZ n$. $\qed$

Corollary. The only order $p$ ring is $\F_p$.

Proposition. The only order $p^2$ rings are $\ZZ{p^2}$, $\F_p\times\F_p$, $\F_{p^2}$ and $\F_p[x]/(x^2)$.

Proof. Either the additive group is cyclic in which case the ring is $\ZZ{p^2}$, or the additive group is $\Z_p\oplus\Z_p$. We can assume that $(0,1)$ is the multiplicative identity, in which case the multiplicative structure is completely determined by the product $(1,0)(1,0)$. If $(1,0)^2=(a,b)$, then the ring can be modelled as a quotient

$$\F_p[x]/(x^2-ax-b),$$

where $(0,1)$ and $(1,0)$ correspond to 1 and $x$ respectively. There are 3 possibilities depending on the behaviour of $p(x)=x^2-ax-b$:

  1. $p(x)$ splits into 2 distinct linear factors $(x-\alpha)$ and $(x-\beta)$, in which case

    $$\F_p[x]/(x^2-ax-b) \cong \F_p[x]/(x-\alpha) \times \F_p[x]/(x-\beta) \cong \F_p\times\F_p.$$

  2. $p(x)=(x-\alpha)^2$, in which csae there is an isomorphism

    $$\begin{matrix} \F_p[x]/(x^2) & \to & \F_p[x]/(x-\alpha)^2 \\ \overline x & \mapsto & \overline{x-\alpha} \end{matrix}$$

  3. $p(x)$ is irreducible, in which case the ring is $\F_{p^2}$. $\qed$