My question is as follows:
Let $p$ be a given prime number (i.e. a natural number greater than $1$ whose only positive divisors are $1$ and itself).
Let $G$ be the group of all the $2 \times 2$ matrices $\left[ \begin{matrix} a & b \\ c & d \end{matrix} \right]$, where $a, b, c, d \in \{ 0, \ldots, p-1 \}$ and $ad - bc \not\equiv 0 \mod p$, under multiplication modulo $p$.
What is the order of $G$?
My Attempt:
Let us first put $p \colon= 2$.
In this case, $G$ consists of all the matrices $\left[ \begin{matrix} a & b \\ c & d \end{matrix} \right]$, where $a, b, c, d \in \{ 0, 1 \}$ and $ad - bc \not\equiv 0 \mod 2$.
Case 1. First, we consider the case where at least one of the entries of the general element $\left[ \begin{matrix} a & b \\ c & d \end{matrix} \right]$ of $G$ is $0$, more precisely is congruent to $0$ modulo $2$.
In this case, neither of the rows and neither of the columns of $\left[ \begin{matrix} a & b \\ c & d \end{matrix} \right]$ can be zero modulo $2$.
Accordingly, we have the following four sub-cases:
Sub-Case 1.1. If $a = 0$, then $b$ and $c$ cannot be $0$, although $d$ can; this gives us two possibilities, namely $\left[ \begin{matrix} 0 & 1 \\ 1 & 0 \end{matrix} \right]$ and $\left[ \begin{matrix} 0 & 1 \\ 1 & 1 \end{matrix} \right]$.
Sub-Case 1.2. If $b = 0$, then $a$ and $d$ cannot be $0$, although $c$ can; this gives us two possibilities, namely $\left[ \begin{matrix} 1 & 0 \\ 0 & 1 \end{matrix} \right]$ and $\left[ \begin{matrix} 1 & 0 \\ 1 & 1 \end{matrix} \right]$.
Sub-Case 1.3. If $c = 0$, then $a$ and $d$ cannot be $0$, although $b$ can; this gives us two possibilities, namely $\left[ \begin{matrix} 1 & 0 \\ 0 & 1 \end{matrix} \right]$ and $\left[ \begin{matrix} 1 & 1 \\ 0 & 1 \end{matrix} \right]$, but only one of these two is a new possibility, for the other one (i.e. the first) has already occured in Sub-Case 1.2. So we have only one more possibility, namely $\left[ \begin{matrix} 1 & 1 \\ 0 & 1 \end{matrix} \right]$.
Sub-Case 1.4. Finally, if $d = 0$, then $b$ and $c$ cannot be $0$, although $a$ can; this gives us two possibilities, namely $\left[ \begin{matrix} 0 & 1 \\ 1 & 0 \end{matrix} \right]$ and $\left[ \begin{matrix} 1 & 1 \\ 1 & 0 \end{matrix} \right]$, but only one of these two is a new possibility, for the first matrix has already occured in Sub-Case 1.1 above. So we have one more possibility, namely $\left[ \begin{matrix} 1 & 1 \\ 1 & 0 \end{matrix} \right]$.
Thus in the case where at least one of the entries of $\left[ \begin{matrix} a & b \\ c & d \end{matrix} \right]$ is $0$, we have the following six elements of $G$: $\left[ \begin{matrix} 0 & 1 \\ 1 & 0 \end{matrix} \right]$, $\left[ \begin{matrix} 0 & 1 \\ 1 & 1 \end{matrix} \right]$, $\left[ \begin{matrix} 1 & 0 \\ 0 & 1 \end{matrix} \right]$, $\left[ \begin{matrix} 1 & 0 \\ 1 & 1 \end{matrix} \right]$, $\left[ \begin{matrix} 1 & 1 \\ 0 & 1 \end{matrix} \right]$, and $\left[ \begin{matrix} 1 & 1 \\ 1 & 0 \end{matrix} \right]$.
Case 2. Next, we consider the case when none of the entries of $\left[ \begin{matrix} a & b \\ c & d \end{matrix} \right]$ is $0$. In this case, we are only left with the matrix $\left[ \begin{matrix} 1 & 1 \\ 1 & 1 \end{matrix} \right]$. However, for this matrix we have $1 \cdot 1 - 1 \cdot 1 = 0$. So we obtain no new elements of $G$ in this case.
Therefore for $p = 2$, the order of $G$ is $6$.
Am I right?
Next, we put $p \colon= 3$.
In this case, $G$ consists of all the matrices $\left[ \begin{matrix} a & b \\ c & d \end{matrix} \right]$, where $a, b, c, d \in \{ 0, 1, 2 \}$ and $ad - bc \not\equiv 0 \mod 3$.
Case 1. First, we consider the case where at least one of the entries of the general element $\left[ \begin{matrix} a & b \\ c & d \end{matrix} \right]$ of $G$ is $0$, more precisely is congruent to $0$ modulo $3$.
In this case, neither of the rows and neither of the columns of $\left[ \begin{matrix} a & b \\ c & d \end{matrix} \right]$ can be zero modulo $3$.
Accordingly, we have the following four sub-cases:
Sub-Case 1.1. If $a = 0$, then $b$ and $c$ cannot be $0$, although $d$ can; this gives us $2 \times 2 \times 3 = 12$ possibilities.
Sub-Case 1.2. If $d = 0$, then $b$ and $c$ cannot be $0$, although $a$ can; however for $a=0$ four possibilities from Sub-Case 1.1 will occur again. Thus we have $2 \times 2 \times 2 = 8$ new possibilities.
Sub-Case 1.3. If $b = 0$, then $a$ and $d$ cannot be $0$, although $c$ can; this gives us $2 \times 2 \times 3 = 12$ possibilities.
Sub-Case 1.4. Finally, if $c = 0$, then $a$ and $d$ cannot be $0$, although $b$ can; this gives us $2 \times 2 \times 3 = 12$ possibilities in all, but for $b = 0$ the four possibilities of Sub-Case 1.3 will occur again. Thus we get only $2 \times 2 \times 2 = 8$ new possibilities.
Thus in the case where at least one of the entries of $\left[ \begin{matrix} a & b \\ c & d \end{matrix} \right]$ is $0$, we have $12 + 8 + 12 + 8 = 40$ possibilities.
Case 2. Next, we consider the case when none of the entries of $\left[ \begin{matrix} a & b \\ c & d \end{matrix} \right]$ is $0$ modulo $3$. In this case we have $2 \times 2 \times 2 \times 2 = 16$ possibilities at most.
However, in this case, neither of the two columns of $\left[ \begin{matrix} a & b \\ c & d \end{matrix} \right]$ can be a multiple modulo $3$ of the other column, and neither of the two rows of this matrix can be a multiple modulo $3$ of the other row.
Thus the following eight matrices cannot occur in $G$: $$ \left[ \begin{matrix} 1 & 1 \\ 1 & 1 \end{matrix} \right], \left[ \begin{matrix} 1 & 1 \\ 2 & 2 \end{matrix} \right], \left[ \begin{matrix} 1 & 2 \\ 1 & 2 \end{matrix} \right], \left[ \begin{matrix} 1 & 2 \\ 2 & 1 \end{matrix} \right], \left[ \begin{matrix} 2 & 1 \\ 2 & 1 \end{matrix} \right], \left[ \begin{matrix} 2 & 1 \\ 1 & 2 \end{matrix} \right], \left[ \begin{matrix} 2 & 2 \\ 1 & 1 \end{matrix} \right], \left[ \begin{matrix} 2 & 2 \\ 2 & 2 \end{matrix} \right]. $$
We are thus left with only $16 - 8 = 8$ possibilities in the case where none of the entries of $\left[ \begin{matrix} a & b \\ c & d \end{matrix} \right]$ is $0$ modulo $3$.
Therefore for $p=3$, the order of $G$ is $40 + 8 = 48$.
Am I right?
Now we consider a general $p$.
In this case, $G$ consists of all the matrices $\left[ \begin{matrix} a & b \\ c & d \end{matrix} \right]$, where $a, b, c, d \in \{ 0, 1, \ldots, p-1 \}$ and $ad - bc \not\equiv 0 \mod p$.
Case 1. First, we consider the case where at least one of the entries of the general element $\left[ \begin{matrix} a & b \\ c & d \end{matrix} \right]$ of $G$ is $0$, more precisely is congruent to $0$ modulo $p$.
In this case, neither of the rows and neither of the columns of $\left[ \begin{matrix} a & b \\ c & d \end{matrix} \right]$ can be zero modulo $p$.
Accordingly, we have the following four sub-cases:
Sub-Case 1.1. If $a = 0$, then $b$ and $c$ cannot be $0$, although $d$ can; this gives us $$ (p-1) (p-1)p = p(p-1)^2 $$ possibilities.
Sub-Case 1.2. If $d = 0$, then $b$ and $c$ cannot be $0$, although $a$ can, giving us $(p-1)(p-1)p = p(p-1)^2$ possibilities; however for $a=0$ the $(p-1)(p-1) = (p-1)^2$ possibilities from Sub-Case 1.1 will occur again. Thus we only have $$ p(p-1)^2 - (p-1)^2 = (p-1)^3 $$ new possibilities.
Sub-Case 1.3. If $b = 0$, then $a$ and $d$ cannot be $0$, although $c$ can; this gives us $$ (p-1)(p-1)p = p(p-1)^2 $$ possibilities.
Sub-Case 1.4. Finally, if $c = 0$, then $a$ and $d$ cannot be $0$, although $b$ can; this gives us $(p-1)(p-1)p = p(p-1)^2$ possibilities in all, but for $b = 0$ the $(p-1)(p-1) = (p-1)^2$ possibilities of Sub-Case 1.3 will occur again. Thus we get only $p(p-1)^2-(p-1)^2 = (p-1)^3$ new possibilities.
Thus in the case where at least one of the entries of $\left[ \begin{matrix} a & b \\ c & d \end{matrix} \right]$ is $0$ modulo $p$, we have $$ p(p-1)^2+(p-1)^3+p(p-1)^2+(p-1)^3 = 2(2p-1)(p-1)^2 $$ possibilities.
Case 2. Next, we consider the case when none of the entries of $\left[ \begin{matrix} a & b \\ c & d \end{matrix} \right]$ is $0$ modulo $p$.
Now if $x \in \{ 1, \ldots, p-1 \}$, then $\mbox{gcd}(x, p) = 1$ and so there are integers $x^\prime$ and $p^\prime$ such that $xx^\prime + pp^\prime = 1$, by Lemma 1.3.1 in Herstein, and hence $xx^\prime -1 = pp^\prime$, which implies that $p$ divides $xx^\prime - 1$, or in other words, we have $$ xx^\prime \equiv 1 \mod p. \tag{A} $$ Now if we divide $x^\prime$ by $p$, we get integers $q^\prime$ and $r^\prime$ such that $$x^\prime = pq^\prime + r^\prime, $$ where $r^\prime \in \{ 0, 1, \ldots, p-1 \}$, from which it follows that $$ x^\prime \equiv r^\prime \mod p, $$ and therefore we obtain $$ xx^\prime \equiv xr^\prime \mod p, \tag{B} $$ by Lemma 1.3.3 in Herstein.
Thus from (A) and (B) and by Result 1. in Lemma 1.3.3 in Herstein, we have shown that, for each element $x \in \{ 1, \ldots, p-1 \}$, there exists an element $y \colon= r^\prime$ in $\{ 1, \ldots, p-1 \}$ such that $$ xy \equiv 1 \mod p, $$ or in other words, $$ xy = 1 \ \mbox{ modulo } p. \tag{1} $$ Let us denote this element $y$ by $x^{-1}$.
Alternatively, since $p$ is a prime, the set $\{ 0, 1, \ldots, p-1 \}$ is a field under the operations of addition and multiplication modulo $p$, which implies that, for each element $x$ of this set, there exists a unique element $x^{-1}$ in the set, such that $$ xx^{-1} = x^{-1}x = 1 \ \mbox{ modulo $p$}. \tag{1} $$
Now since each of the entries of the general element $\left[ \begin{matrix} a & b \\ c & d \end{matrix} \right]$ of $G$ is to be from the set $\{ 1, \ldots, p-1 \}$, therefore we have $(p-1)(p-1)(p-1)(p-1) = (p-1)^4$ possibilities at most.
However, once we have chosen $a$, $b$, and $c$ arbitrarily from the set $\{ 1, \ldots, p-1 \}$, for which there are $(p-1)^3$ possibilities, we cannot choose $d$ from this set in such a way that $ad = bc$ modulo $p$.
Thus, corresponding to each one of the $(p-1)^3$ possible choices for the ordered triple $(a, b, c)$, the entry $d$ can only be chosen from the set $$ \{ 1, \ldots, p-1 \} - \{ \ a^{-1}bc \}. \qquad \mbox{ [ Refer to (1) above. ] } $$ Thus there are only $p-2$ choices for $d$ corresponding to each one of the $(p-1)^3$ choices for the ordered triple $(a, b, c)$.
Therefore in the case when none of the entries of $\left[ \begin{matrix} a & b \\ c & d \end{matrix} \right]$ is $0$ modulo $p$ we have $(p-2)(p-1)^3$ possibilities.
Hence the order of $G$ is $$ \begin{align} 2(2p-1)(p-1)^2 + (p-2)(p-1)^3 &= \big[ 2(2p-1) + (p-2)(p-1) \big] (p-1)^2 \\ &= \big[ (4p-2) + (p^2 - 3p + 2) \big] (p-1)^2 \\ &= (p^2 + p)(p-1)^2 \\ &= p(p+1)(p-1)^2. \end{align} $$
For $p = 2$, we note that $$ p(p+1)(p-1)^2 = 2(2+1)(2-1)^2= 2(3)(1)^2 = 6,$$ whereas for $p=3$, we have $$ p(p+1)(p-1)^2 = 3(3+1)(3-1)^2= 3(4)(2)^2 = 48.$$ Both these calculations agree with our earlier results.
Is my answer correct for a general prime $p$? If so, then is each and every detail of my solution accurate enough too? Is my approach the same as that required by Herstein?
Or, are there problems of accuracy, clarity, or rigor with my attempt?
Adding to the comment by @SarthakRout.
Suppose we assign values to $a, b, c$. Then $d$ should not be $a^{-1}*b*c$ since that will give $a*d-b*c = 0$.
Here, we will consider $a = 0$ separately since $a^{-1}$ is not defined.
For $a \in \{1, 2, ..., p-1\}$, we have $b,c \in \{0, 1, 2, ..., p-1\}$ and $d \in \{0, 1, 2, ..., p-1\}\backslash\{{a^{-1}}*b*c\},$ which gives ${(p-1)}^{2}p^{2}$ combinations.
For $a = 0$, we should have both $b$ and $c$ non-zero and $d \in \{0, 1, 2, ..., p-1\}$, which gives ${(p-1)}^{2}p$ combinations.
Finally, the total combinations are ${(p-1)}^{2}p^{2}\ +\ {(p-1)}^{2}p \,=\, ({p^{2}}-1)(p-1)p$.