# Number of units in the ring of matrices

I want to know about the number of units in the ring of all matrices of order $n\times n$ over the field of order $p$, where $p$ is a prime.

I read in one my book that the order of $\mathit{GL}(n,\mathbb Z_p)$ is $(p^n-1)(p^n-p)(p^n-p^2)\dots (p^n-p^{n-1})$. I think this is the required number of units in the group $M_n(\mathbb Z_p)$. But I can't deduce it.

Also I have a question what will be the result if p is not prime i.e composite.? Hope to get help. Thanks.

Edit: My question for prime modulus $p$ is already been discussed here.

So I would like to know about the case when the modulus is composite.

• The key is having rows (or columns, if you prefer) that are linearly independent. Every choice of a row narrows the possibilities for the subsequent choices. For the first row you can pick anything except the zero row, hence the factor $p^n - 1$. See if you can do something with this argument; the result is actually quite elegant. Then we can talk about composite moduli. – hardmath Jun 9 '17 at 2:17
• Oh ! Then the 2nd row will have $pⁿ-p$ choices as it will not be a multiple of the 1st row,similarly the 3rd row will be have $pⁿ-p²$ choices as it will not be a multiple of the 1st and 2nd row and so on...Is it right? – hiren_garai Jun 9 '17 at 2:41
• Yes the 'span' is more general than the multiple thing.(multiple is a special case of span here).I got it . For composite will it be same ? – hiren_garai Jun 9 '17 at 2:50
• No, the composite situation is more complicated. The ring of coefficients not being a field, we are no longer working with a vector space of choices for the rows. However we can say that a matrix over $\mathbb{Z}/m\mathbb{Z}$ is invertible if and only if the determinant is coprime to $m$. – hardmath Jun 9 '17 at 4:01
• The first part of your Question is solved by a somewhat more general question, math.stackexchange.com/questions/1399406/…, which deals with any "finite field". That is, a finite field has order $q$ which is a power of a prime $p$ (the characteristic of the field). Perhaps you would like to reword your Question to focus instead on the issue of a composite modulus $\mathbb{Z}/m\mathbb{Z}$ for matrix entries. – hardmath Jun 10 '17 at 2:40

Invertibility of $n\times n$ matrices over $\mathbb{Z}/m\mathbb{Z}$ is equivalent to checking the determinant of the matrix is coprime to $m$. Note that the determinant can be computed as if the entries are integers, and then reduced mod $m$, since the determinant is a polynomial in the matrix entries.

This leads to a fairly simple analysis via Chinese remainder theorem when $m$ is a product of distinct primes. See for example the previous Question about counting where $m=26$. As Jyrki Lahtonen outlines in the Comments on that Question, any pairing of invertible matrix $A$ mod $2$ and invertible matrix $B$ mod $13$ can be combined per CRT to give invertible matrix $C$ mod $26$. Thus the count of invertible matrices mod $m=pq$ where $p,q$ are distinct primes is the product of the counts for invertible matrices mod $p$ and mod $q$.

Indeed this reduction works for any factorization of $m$ into factors that are coprime (not necessarily prime factors), provided we know how to count the invertible matrices mod those coprime factors separately. Chinese remainder theorem again allows us to piece together invertible pairs of matrices in the coprime factor moduli.

So the hard part of the counting for general moduli concerns the case of repeated prime factors, i.e. for $m = p^k$. A short classroom note (on Linear Ciphers) that gives upper and lower bounds on the count is K. Pommerening's The Number of Invertible Matrices over a Residue Class Ring.

Formulas for the exact count of invertible matrices (with composite moduli) are developed in On the Keyspace of the Hill Cipher by Overbey, Traves, and Wojdylo (2005).

By the observations above it suffices to give their formula (Thm. 2.2.2) for a prime power modulus, with minor changes in notation for consistency:

$$\text{When } m=p^k,\;\; |\mathit{GL}(n,\mathbb{Z}/m\mathbb{Z})| = p^{(k-1)n^2} \prod_{i=0}^{n-1} (p^n - p^i) .$$

Here $\mathit{GL}(n,\mathbb{Z}/m\mathbb{Z})$ is the "general linear" group of $n\times n$ invertible matrices with entries in $\mathbb{Z}/m\mathbb{Z}$. So the order of that (multiplicative) group of matrices is precisely the count of invertible matrices under discussion.

Note that when $k=1$ the above formula simplifies immediately to the case already established for a prime modulus $\mathbb{Z}/p\mathbb{Z}$.

• I think it is a little bit high standard for me. I have tried to understand,but I am not aware of some of the concepts,hope to make it clear in future.by the way thanks for the answer. – hiren_garai Jun 10 '17 at 23:05
• Perhaps a worked example will make things clearer. – hardmath Jun 10 '17 at 23:07