# How many orthogonal matrices are there over a given finite ring or field?

I want to know how many $2\times 2$ orthogonal matrices exist over the ring $\mathbb{Z}_n$ or the field $\mathbf{F}_p$. And how many $2\times 1$ orthogonal vectors exist over the ring $\mathbb{Z}_n$ or the field $\mathbf{F}_p$.

-
It makes no sense to ask "how many $2\times 1$ orthogonal vectors exist", because a vector is not "orthogonal" or "not orthogonal". For vectors, orthogonality is a relation between vectors, not a property of vectors. – Arturo Magidin Aug 3 '11 at 7:41
The order of the orthogonal group over the field of $q$ elements can be found in Wikipedia. – Arturo Magidin Aug 3 '11 at 7:52
@Arturo, does the answer for ${\bf Z}_n$ follow from the answer for ${\bf F}_p$ by the Chinese Remainder Theorem, at least for squarefree $n$? – Gerry Myerson Aug 4 '11 at 1:32
@Gerry: It should for squarefree $n$. Don't know off-hand for arbitrary $n$. – Arturo Magidin Aug 4 '11 at 6:31
An anonymous user suggested an edit to this question that I rejected because it didn't make any sense to me (and was misspelled). Karan, in case this was you, please edit the question under the account that you used in creating it; then it won't require peer review. – joriki Aug 6 '11 at 9:11

If by orthogonal vectors you mean a collection $S$ of non-zero vectors such that all pairs of distinct vectors $(a,b)$ and $(c,d)$ from the set $S$ satisfy the relation $ac+bd=0$, then the question is a bit subtle, because it is possible for a vector to be `perpendicular to itself'. In $F_p^2$ this happens, iff $p\equiv 1\pmod{4}$, because the equation $$a^2+b^2=0\Leftrightarrow (a/b)^2=-1$$ has non-trivial ($ab\neq0$) solutions, iff $-1$ has a square root in $F_p$. In those cases we can include all (non-zero) multiples of such a vector to get a total of $p-1$ non-zero vectors with pairwise vanishing inner products. This is also the maximum. A way to see this is as follows: if an orthogonal set contains a (non-zero) vector $\vec{v}$ perpendicular to itself, then all the vectors $\perp\vec{v}$ must be scalar multiples of $\vec{v}$. This is because $\vec{v}$ cannot be orthogonal to the entire space, so the subspace $\langle\vec{v}\rangle^\perp$ has dimension one, and must be spanned by $\vec{v}$. If the orthogonal set has no such vectors as elements, then it is linearly *IN*dependent by the usual proof for "orthogonality $\Rightarrow$ linear independence", and has size at most 2.
If $p\equiv3 \pmod 4$, then all the non-zero vectors of $F_p^2$ have non-zero inner products with themselves, and again, the set is linearly independent.
If you mean something else, please edit your question accordingly. I don't know what happens with the ring $\mathbf{Z}_n$. In line with the comments by Arturo and Gerry, I think that CRT will help in the case of a square-free $n$.
@user2154420: The congruence $x^2\equiv-1\pmod p$ has a solution if and only if $p\not\equiv3\pmod4$. This is a fact from elementary number theory. – Jyrki Lahtonen Feb 10 '15 at 4:18