Matrix Rings {#sec:redRings}
========================================

In some contexts, the “natural” underlying alphabet in the reduction $\phi_p$ is, rather than the field $\mathbb{F}_p$, the ring $\mathcal{M}_n(\mathbb{F}_p)$ of $n \times n$ matrices with entries in $\mathbb{F}_p$. Although we can identify $\mathcal{M}_n(\mathbb{F}_p)$ with $\mathbb{F}_p^{n^2}$, the identification does not carry enough algebraic structure for our purposes. For instance, we cannot guarantee that the constructed lattices are closed under multiplication by units, which is crucial in order to obtain the full density improvements of these lattices, as in [@Vance]. For this reason, we study in this section a version of Theorem \[thm:AverageEnsembleGeneral\] for codes over matrix rings.

An Averaging Bound for Codes over Rings
---------------------------------------

Let $\mathcal{R}$ be a finite ring and $\mathcal{R}^{*}$ its units. Denote by $(\mathcal{R}^n)^{*}$ the set of vectors in $\mathcal{R}^n$ such that at least one coordinate is a unit. A linear code in $\mathcal{C} \subset \mathbb{R}^n$ is a *free*[^2] $\mathcal{R}$-submodule of $\mathcal{R}^n$ (with the natural scalar multiplication). Following [@Loeliger], we define balanced sets of codes as follows.

Consider a non-empty set of codes $\mathcal{C}_b$ of same cardinality. We say that $\mathcal{C}_b$ is *balanced* if any ${\mathbf{x}}\in (\mathcal{R}^n)^{*}$ is contained in the same number of codes (say, $L$) of $\mathcal{C}_b$.

Let $M$ be 