Matrices over $\mathbb{F}_p$ satisfying a Determinant and Trace Condition Fix an odd prime $p$, and integer $n \geq 1$, an $\alpha \in \mathbb{F}_p^{\times}$, and $\delta, \tau \in \mathbb{F}_p$. Let $T = (t_{ij})$ denote an arbitrary symmetric $n \times n$ matrix mod $p$. I wish to show the sets below have the same cardinality:

*

*The symmetric matrices mod $p$ with fixed determinant $\delta$ and trace $\tau$,


*The symmetric matrices mod $p$ with fixed determinant $\delta$ and satisfying the trace condition
\begin{align*}
\alpha t_{11} + \alpha^{-1} t_{22} + t_{33} + \cdots + t_{nn} = \tau.
\end{align*}
This statement is true if we instead count all such matrices over the (at most degree $2$) extension $\mathbb{F}_p(\sqrt{\alpha})$. That is, in this setting we have the explicit bijection
\begin{align*}
T \mapsto UTU^t
\end{align*}
where
\begin{align*}
U = \textrm{diag}(\sqrt{\alpha}^{-1},\sqrt{\alpha},1,\ldots,1).
\end{align*}
 A: I'll rename your matrix to $M$ (because I don't like the conflict with $T$ meaning transpose). We'll try to construct a bijection of the form $M \mapsto AMA^T$ where $A$ is a block diagonal matrix with a top-left $2 \times 2$ block $\left[ \begin{array}{cc} a & b \\ c & d \end{array} \right]$ and $1$s on the diagonal otherwise, and whose determinant squares to $1$. A computation gives
$$\text{tr}(AMA^T) = (a^2 + c^2) m_{11} + (ab + cd) m_{21} + (ab + cd) m_{12} + (b^2 + d^2) m_{22} + \sum_{i=3}^n m_{ii}$$
so we're done if we can find $a, b, c, d$ such that
$$a^2 + c^2 = \alpha$$
$$b^2 + d^2 = \alpha^{-1}$$
$$ab + cd = 0$$
$$(ad - bc)^2 = 1.$$
As you remark, if $\alpha$ has a square root this is easy since we can take $b = c = 0, a = \sqrt{\alpha}, d = \sqrt{\alpha}^{-1}$. In fact it is always possible: the equation $a^2 + c^2 = \alpha$ has a solution in $\mathbb{F}_p$ for every $\alpha \in \mathbb{F}_p^{\times}$. This says equivalently that the norm map $\mathbb{F}_p[i]^{\times} \to \mathbb{F}_p^{\times}$ is surjective, which is true whether or not $\mathbb{F}_p[i]$ is a field. Then we can take $b, d$ such that
$$d + bi = \frac{1}{a + ci} = \frac{a - ci}{a^2 + c^2} = \frac{a - ci}{\alpha}$$
so $N(a + ci) = \alpha$ gives $N(d + bi) = \alpha^{-1}$, and $(a + ci)(d + bi) = (ad - bc) + (ab + cd) i = 1$, so $ab + cd = 0$ and $ad - bc = 1$ automatically, which is all the conditions we needed. Probably a more conceptual argument is possible; I guess this is some standard fact about quadratic forms.

Some more details about the claimed surjectivity of the norm map. We can split into two cases: if $p \equiv 1 \bmod 4$ then $\mathbb{F}_p[x]/(x^2+1) \cong \mathbb{F}_p \times \mathbb{F}_p$ with the isomorphism sending $a + bx$ to $(a + bi, a - bi)$ where $i^2 = -1$ in $\mathbb{F}_p$. In this case the norm map is just multiplication $(x, y) \mapsto xy$ and surjectivity is clear.
If $p \equiv 3 \bmod 4$ then $\mathbb{F}_p[i] \cong \mathbb{F}_{p^2}$ whose multiplicative group has a generator $g$ whose norm is $N(g) = g \overline{g} = g^{p+1}$. Since $g$ has order $p^2 - 1$ it follows that $N(g)$ has order $p - 1$.
(If $p = 2$ then $\mathbb{F}_p[i] \cong \mathbb{F}_p[\epsilon]/\epsilon^2$ and the surjectivity of the norm map still holds in this case but is trivial.)

A somewhat more conceptual version of the computation above is to write $\text{tr}(AMA^T) = \text{tr}(A^T A M)$ where $A^T A$ has top-left $2 \times 2$ block
$$\left[ \begin{array}{cc} a & c \\ b & d \end{array} \right] \left[ \begin{array}{cc} a & b \\ c & d \end{array} \right] = \left[ \begin{array}{cc} a^2 + c^2 & ab+cd \\ ab + cd & b^2 + d^2 \end{array} \right].$$
I suppose this makes the effect of this transformation on the diagonal entries and hence on the trace a little clearer. We want $\text{tr}(A^T A M)$ to have the effect of multiplying the first diagonal entry by $\alpha$ and the second by $\alpha^{-1}$, and $\text{tr}(A' M)$ accomplishes this where $A' = \text{diag}(\alpha, \alpha^{-1}, \dots)$, so by the nondegeneracy of the trace form we require $A^T A$ to have top-left block $\left[ \begin{array}{cc} \alpha & 0 \\ 0 & \alpha^{-1} \end{array} \right]$. The rest of the argument still isn't quite as slick as I'd like it to be though. What we've shown is that the quadratic form $\alpha x^2 + \alpha^{-1} y^2$ is equivalent to the quadratic form $x^2 + y^2$. But I'm missing a general sense of when quadratic forms over finite fields are equivalent.
