\documentclass[11pt]{article} \usepackage[T1]{fontenc} \usepackage[margin=1in]{geometry} \usepackage{amsmath,amssymb,amsthm,mathtools,microtype} \usepackage[hidelinks,pdfusetitle]{hyperref} \newtheorem{theorem}{Theorem}[section] \newtheorem{proposition}[theorem]{Proposition} \newtheorem{lemma}[theorem]{Lemma} \newtheorem{corollary}[theorem]{Corollary} \newcommand{\F}{\mathbf F} \newcommand{\KL}{D_{\mathrm{KL}}} \newcommand{\E}{\mathbb E} \DeclareMathOperator{\tr}{tr} \setlength{\emergencystretch}{1em} \title{Second Moments of Hecke Traces and Vertical Sato--Tate} \author{Zhongpai Gao} \date{21 November 2026} \begin{document} \maketitle \begin{abstract} We relate sums of squared Hecke traces to the distribution of Frobenius traces of elliptic curves over $\F_p$. For every fixed $1/6\le a<1/2$, the sum of squared normalized traces at level one up to weight $K=p^a$ is asymptotic to $K^2/48$ on a density-one set of primes. In the same range, fixed-level limits hold on sets of relative density one in the relevant prime classes, with constants that factor over prime powers. We compute the mixed moments between newform spaces at different levels and between character spaces at odd prime level. The connection comes from tossing a coin whose bias is determined by the trace of a uniformly chosen nonsingular Weierstrass equation. The Sato--Tate predictor's excess log loss tends to zero exactly when $T=o(p)$. For $T=\lfloor\lambda K^2\rfloor$ with fixed $\lambda>0$ it is asymptotic to $T/(96p)$ on the level-one prime set. When $T/p\to c>0$, we compute the limiting losses along prime subsequences whose residues stabilize modulo each fixed integer. The two nonzero classes modulo~$3$ can give different limits. At level one we compute the leading variances across prime intervals for the normalized trace sum and the normalized chi-square divergence. \end{abstract} \section{Introduction} For a prime $p$, let $\tau_k(p)$ be the trace of $T_p$ on $S_k(\mathrm{SL}_2(\mathbf Z))$ divided by $p^{(k-1)/2}$. We prove that for each fixed $1/6\le a<1/2$ there is a density-one set of primes on which, with $K=p^a$, \[ \sum_{\substack{4\le k\le K\\k\ {\rm even}}}|\tau_k(p)|^2 \sim \frac{K^2}{48}. \] The sum has the same leading term as the total dimension, since $\dim S_k(\mathrm{SL}_2(\mathbf Z))=k/12+O(1)$ at even weights. At fixed level the full and newform moments are products of local factors that can depend on the residue of $p$. Distinct squarefree newform levels have zero limiting mixed moment. At odd prime level we also separate the character components. Jung and Sardari~\cite[Theorem~1.3]{JungSardari} bound the trace square sum on newspaces of fixed squarefree level $N>1$ at $k\asymp\sqrt p$. At that scale Bober et al.~\cite[Theorem~1.1]{BoberEtAl} and Kuan and Lesesvre~\cite[Theorem~1]{KuanLesesvre} study signed first moments under GRH, the latter with Petersson weights. Petrow~\cite[Theorem~1.1]{Petrow} bounds individual traces for $k\ge p^{3/10+\eta}$ at fixed level. At fixed weight, averaging over primes gives the diagonal dimension by Rankin--Selberg orthogonality~\cite[Theorems~2.5--2.6]{KanekoThorner}. In a residue class the prime average can pair forms related by a Dirichlet twist. Our asymptotic concerns a sharp cutoff $K=p^a=o(\sqrt p)$ at individual primes in sets of relative density one, with explicit mixed constants at every fixed level. Binomial smoothing supplies the weight cutoff. For a uniform nonsingular short Weierstrass equation $E$ over $\F_p$, toss a coin $T$ times with bias $f_t=1/2+t/(4\sqrt p)$, where $t=p+1-\#E(\F_p)$. Write $P_T$ for the count law and $Q_T$ for its analogue under the Sato--Tate prior $\mathrm{Beta}(3/2,3/2)$. The expected extra log loss is $\KL(P_T\Vert Q_T)$. The chi-square divergence sums squared Chebyshev moments with weights that decay past $\sqrt T$. Kaplan and Petrow's formula~\cite{KaplanPetrow} identifies these moments with normalized Hecke traces. Varying $T$ recovers the sharp sum. We call $1/2+(4\sqrt p)^{-1}\mathbf Z$ the \emph{trace lattice}. In the interior the sampling error $T^{-1/2}$ reaches its spacing at $T\asymp p$, where the limiting losses reflect the residues of $p$. At shorter lengths the main term comes from squared Fourier coefficients. Averaging over primes controls the products at distinct frequencies. At $a=1/6$ the proof also uses the quadratic functional equation and additive reciprocity. The short-interval estimates of David, Koukoulopoulos and Smith~\cite[Theorem~1.3]{DavidKoukoulopoulosSmith} control the likelihood ratios. For the short-length results, put $K=p^a$ and $T=\lfloor\lambda K^2\rfloor$ with fixed $1/6\le a<1/2$ and $\lambda>0$. \begin{center} \small \begin{tabular}{@{}p{.27\linewidth}p{.44\linewidth}p{.21\linewidth}@{}} \textbf{Result} & \textbf{Conclusion} & \textbf{Prime coverage}\\[2pt] \hyperref[thm:prime-density]{Level-one traces} & $\sum_{4\le k\le K,\ k\ {\rm even}}|\tau_k|^2\sim K^2/48$ & Density one\\ \hyperref[thm:gamma0]{Fixed-level traces} & Local products in units of $K^2/48$ & Relative density one\\ \hyperref[sec:exceptional]{Level-one variance} & Explicit multiples of $X^{a-1/2}\log X$ for $a\ge3/8$ & Average over $X
0$
& Fixed limiting residues\\
\end{tabular}
\end{center}
Section~\ref{sec:critical} derives the Fourier profile at the threshold.
Section~\ref{sec:short} uses it to prove the trace asymptotics. The \hyperref[sec:supplement]{supplement} lists the
\hyperref[sec:dependencies]{proof dependencies}.
The trace asymptotics and leading variance are unconditional. The
second terms for the prime means use Alp\"oge's Dirichlet theorem,
released in Lean on 20 November 2026 and accepted by independent
kernels. A full written proof by Alp\"oge has yet to
appear~\cite{AlpogeAnnouncement,SutherlandVerification}. Its quadratic
case also gives the sharper bounds in Section~\ref{sec:grh} and S1.
\section{Prediction loss for binary mixtures}\label{sec:coefficients}
For word laws $A$ and $B$, the chain rule gives the expected excess
log loss of using $B$ as $\KL(A\Vert B)=\E_A\log(A/B)$, with natural
logarithms. We also use $\chi^2(A\Vert B)=\E_B[(A/B-1)^2]$.
Draw $\theta\in[0,\pi]$ once, then draw bits independently with bias
$f=(1+\cos\theta)/2$. Write $A_\nu^{(T)}$ for the word law with
$f\sim\nu$. The likelihood ratio depends only on the count of ones,
so either divergence can be computed from the count laws.
The reference $B_{a,b}^{(T)}$ uses a Beta$(a,b)$ prior ($a,b>0$)
and predicts a one with probability $(k+a)/(j+a+b)$ after $k$ ones
in $j$ bits. The choices $a=b=1/2$ and $a=b=3/2$ give the uniform
and Sato--Tate angle laws, respectively. The first is the
Krichevsky--Trofimov predictor~\cite{KT}.
\subsection{A coefficient formula for prediction}
\begin{proposition}\label{prop:angles}
Let $P_m$ be the orthonormal polynomials for the Beta$(a,b)$ law of
$f$, with $P_0=1$. With
\[
\kappa_m(T)=\prod_{j=0}^{m-1}\frac{T-j}{T+a+b+j},
\]
one has
\[
\chi^2(A_\nu^{(T)}\Vert B_{a,b}^{(T)})
=\sum_{m=1}^{T}\kappa_m(T)\left(\int P_m\,d\nu\right)^2.
\]
For $a=b=1/2$, $P_m=\sqrt2\cos(m\theta)$ for $m\ge1$.
For $a=b=3/2$, $P_m=U_m(\cos\theta)$, where $U_m$ is the
Chebyshev polynomial of the second kind.
In both cases $\kappa_m(T)\le e^{-m(m+a+b-1)/(2T+2)}$.
\end{proposition}
\begin{proof}
Under the beta-binomial reference, the conditional expectations
from count to bias and from bias to count are adjoints. Binomial
factorial moments and the Beta$(a+k,b+T-k)$ posterior moments show
that both maps preserve polynomial degree.
By orthogonality, each map therefore sends a degree-$m$ orthonormal
polynomial to a scalar multiple of its counterpart. From the leading
coefficients, the composition multiplies by
$T(T-1)\cdots(T-m+1)/\prod_{j 0$, and let
$T=\lfloor\lambda p^{1-\delta}\rfloor$. Uniformly for $X\ge2$ and
$0<\eta\le1$, counting only primes $p\ge5$ for which $T\ge1$,
\[
\#\Bigl\{X \eta\Bigr\}
\ll_{\delta,\lambda}\frac{\pi(X)}{\eta^2\log X}.
\]
The same bound holds for $p\,\KL(P_T\Vert Q_T)/T$ and $1/96$.
\end{corollary}
\begin{proof}
Apply Theorem~\ref{thm:prime-density} with $g=h=F$.
On the retained primes $p\chi^2/T\ll\log^3(2p)$ by the profile
estimates in its proof. In Proposition~\ref{prop:kl-half}
the bulk Taylor error can be taken as $O((\log p)^{-4})$ relative
to $\chi^2$, and the edge error is $O((T/p)p^{-\kappa})$ for some
$\kappa>0$, by its proof. Thus $p\,\KL/T=\frac12p\chi^2/T+
O(1/\log p)$ there. The profile estimates remove at most
$O(X(\log X)^{-3})$ primes, giving the same bound for log loss.
\end{proof}
\subsection{Short intervals and log loss for restricted families}
\label{sec:kl-level}
\begin{lemma}[Sato--Tate on short intervals]\label{lem:short-class}
Let $g$ be a weight from Theorem~\ref{thm:prime-density}, with
$g(t)\ge0$ on the trace grid for the primes in the designated class.
Assume its complete constant coefficient $Z_r$ is positive.
The normalized bias measure $\mu_p^g$ satisfies
\[
\mu_p^g(I)=\bigl(1+O_{g,M,\varepsilon,J}((\log p)^{-J})\bigr)
\int_I\sigma(f)\,df
\]
for every $\varepsilon>0$, $J\ge1$, and $I\subset[0,1]$ of length
at least $p^{-1/2+\varepsilon}$.
\end{lemma}
\begin{proof}
Expand the weight into terms $F^{(J_0)}1_{\mathcal A}$ and treat
each trace progression $t=t_0+Na$ as a separate Euler product
average. In the local formula of
\cite[Theorem~3.2 and Corollary~3.3]{DavidKoukoulopoulosSmith} use
trace $t$ and determinant $p$. The mass is
$\Delta_p\sigma(f_t)\prod_s f_s(t,p,1)$ with the primes in $J_0$
omitted. The factor at $p$ is $1+O(p^{-1})$ uniformly and may be
dropped at that relative cost.
Apply \cite[Theorem~4.2]{DavidKoukoulopoulosSmith} to
the single integer variable $a$, with $d=k=1$,
analytic scale $\asymp\sqrt p$, and polynomial
$(t_0+Na)^2-4p$. Its content is bounded by $N^2$.
Its discriminant is nonzero and its values are negative
and congruent to $0$ or $1$ modulo $4$.
At retained primes $s\ne p$ take the normalized matrix counts
of trace $t$ and determinant $p$ as periodic approximants.
At omitted primes both the factor and its approximants are one.
Theorem~3.2 of that paper supplies the local bounds. The retained
local means are at least $(1+s^{-1})^{-1}$ by the root series,
and outside $N$ the means are one, since $t$ runs through all
residue classes. The primes dividing $2pN\prod_{s\in J_0}s$ may be
included in its exceptional integer. The product of the means
together with the progression factor $1/N$ is the complete
constant coefficient of the term.
For $s_I=|I|$ and $H=\sup_I\sigma$, concavity gives
$\int_I\sigma\ge s_I H/2$. On every class of $a\bmod b$ the
Riemann sum of the weights differs from
$(Nb)^{-1}\int_I\sigma$ by $O_N(H/\sqrt p)$, by bounded
variation. Thus the total weight is $\asymp_N s_IH$, and
condition (4.6) of that theorem holds with this weight as
$\widetilde W$. The sum of discrepancies is
$O_N(QH/\sqrt p)$ for $Q=\exp((\log\log(2p))^2)$.
The square-class error is $O_N(H/\sqrt p)$: a fixed square
class gives a fixed imaginary quadratic field containing
$(t+\sqrt{t^2-4p})/2$, an algebraic integer of norm $p$.
There are at most two ideals of norm $p$, each with at most
six generators. Dividing these errors by the total weight
saves a power and gives an error $O((\log p)^{-J})\int_I\sigma$
for the term. Summing the finitely many terms gives main mass
$Z_r\int_I\sigma$. Evaluating at $I=[0,1]$ and dividing by the
actual mass gives the result.
\end{proof}
\begin{proposition}\label{prop:kl-level}
For $g$ as in Lemma~\ref{lem:short-class} let $P_T^g=P^g/Z_g$.
Fix $0<\eta<1/2$, $L>0$ and $J\ge1$. For some
$\kappa=\kappa(\eta)>0$, uniformly for $Lp^{1/3}\le T\le p^{1-\eta}$,
\[
\KL(P_T^g\Vert Q_T)=\tfrac12\chi^2(P_T^g\Vert Q_T)
+O_{g,M,\eta,J,L}\left((\log p)^{-J}\chi^2(P_T^g\Vert Q_T)
+\frac Tp\,p^{-\kappa}\right).
\]
In particular, on the sets in Theorem~\ref{thm:prime-density},
the limit of $p\,\KL(P_T^g\Vert Q_T)/T$ is
$\mathcal B_r(g,g)/(96 Z_r^2)$.
\end{proposition}
\begin{proof}
Lemma~\ref{lem:short-class} and the same superlevel argument give
likelihood ratios $1+O_J((\log p)^{-J})$ on every count for
$T\le p^{9/20}$, and on the bulk for larger $T$. For larger $T$
the edge estimate follows from $P_T^g\ll_{g,M}P_T$. Indeed
$L_{\ell,p}\ge(1+\ell^{-1})^{-1}$ by its root series, so
$|F^{(J_0)}|\ll_{J_0}F$. The same $\vartheta$ therefore gives
a power saving after division by $c=T/p$.
The bulk Taylor expansion of $u\log u-u+1$ gives the
factor $1/2$ with relative error $O_J((\log p)^{-J})$.
For the limit, take $\eta=\delta/2$ and $L=\lambda/2$ and use
\eqref{eq:mixed-short} on the diagonal divided by $Z_g^2$,
where $Z_g\to Z_r$ by Lemma~\ref{lem:short-profile}.
\end{proof}
\begin{corollary}\label{cor:kl-level}
On the sets of primes in Corollary~\ref{thm:level-density-one},
for every fixed $\lambda>0$ and
$T=\lfloor\lambda p^{1-\delta}\rfloor$,
\[
\frac pT\KL(P_T^{Y_1}\Vert Q_T)\longrightarrow
\begin{cases}
\ell(\ell-1)/96,& p\not\equiv0,1\pmod\ell,\\
(2\ell+1)(\ell-1)/96,&p\equiv1\pmod\ell.
\end{cases}
\]
\end{corollary}
\begin{proof}
The length $T$ lies in the range of Proposition~\ref{prop:kl-level}
with $\eta=\delta/2$ and $L=\lambda/2$ for large $p$. Combine it with the chi-square
limits of Corollary~\ref{thm:level-density-one}.
\end{proof}
\subsection{The constants for arbitrary trace classes}\label{sec:classes-short}
For a fixed modulus $M\ge2$, take $p\equiv r\pmod M$ with $r$ a
unit and restrict the trace to $t\equiv t_0\pmod M$. The pairing
reduces to counting pairs of roots at each $q=\ell^v\Vert M$.
Let $\mathcal R_\ell$ be the roots of $u^2-t_0u+r$ modulo $q$,
let $h=|\mathcal R_\ell|$, and let $\rho_i$ count the roots modulo
$\ell^i$, with $\rho_0=1$. Set
\[
B_\ell=\frac{1}{q(1+\ell^{-1})}
\left(\sum_{i=0}^{v-1}\frac{\rho_i}{\ell^i}
+\frac{h}{q(1-\ell^{-1})}\right),\qquad
S_\ell=\sum_{u,w\in\mathcal R_\ell}\min\{v,v_\ell(u-w)\}.
\]
Here the summand for $u=w$ is $v$. The local factor is
\begin{equation}\label{eq:class-local-constant}
A_\ell=q\varphi(q)+
\frac{(1-\ell^{-1})(2S_\ell-vh^2)+(2h-h^2)/\ell}
{(1-\ell^{-2})q^2 B_\ell^2}.
\end{equation}
\begin{theorem}\label{thm:classes-short}
Fix $M,r,t_0$ as above and $0<\delta\le2/3$. There is a
relative-density-one set of primes in the class $r$ on which
every fixed $\lambda>0$ and $T=\lfloor\lambda p^{1-\delta}\rfloor$ give
\[
\frac pT\chi^2(P_T^M\Vert Q_T)\longrightarrow
\frac1{48}\prod_{\ell\mid M}A_\ell,\qquad
\frac pT\KL(P_T^M\Vert Q_T)\longrightarrow
\frac1{96}\prod_{\ell\mid M}A_\ell.
\]
\end{theorem}
If each local weight is constant on its trace class, the product is
$M\varphi(M)$. This includes odd $\ell$ with
$v_\ell(t_0^2-4r)0.
\]
Dirichlet's theorem realizes both compatible residue systems by
successively choosing primes in their residue classes modulo $j!$.
\end{proof}
\subsection{The short-length limit of the Fourier profile}
For each fixed $0s_*$ each is at
most its value at $s_*$, and $Q_T(k)$ is at least $s_*$ times the
Sato--Tate mass of $I_{s_*}$. Hence
$|u_k-1|\ll_J(\log p)^{-J}+p^{-\varepsilon}$ on the bulk.
For the edge, $\Psi(u)\le(u-1)^2\le2u^2+2$. So the edge counts
contribute to either divergence at most twice the sum of
$P_T(k)^2/Q_T(k)$ plus twice the sum of $Q_T(k)$ over the edge. The
second sum is $O(\vartheta^{3/2}+T^{-3/2})$, the last term accounting
for the counts $0$ and $T$. By Cauchy--Schwarz at each count,
\[
P_T(k)^2\le P^{F^2}(k)P^1(k),\qquad
P^1(k)\ll Q_T(k)\bigl(1+\Delta_pm_{T,k}\bigr).
\]
One has $F(t)\ll\log p\,(\log\log p)^2$, by $L(1,\chi)\ll\log p$ and
the bound $\sigma_{-1}(r)^2$ for the finite factor. This gives
\[
\sum_{\mathrm{edge}}\frac{P_T(k)^2}{Q_T(k)}
\ll(\log p)^3\sum_{\mathrm{edge}}Q_T(k)\bigl(1+\Delta_p^2m_{T,k}^2\bigr)
\ll(\log p)^3\bigl(\vartheta^{3/2}+T^{-3/2}+c\sqrt\vartheta
+T^{1/2}p^{-1}\bigr),
\]
by the bounds for $Q_T(k)$ and $m_{T,k}$. After division by $c$ the terms save powers:
$\vartheta^{3/2}/c\ll_L p^{9\varepsilon/2-\eta/2}
+p^{-1/5+3\varepsilon}$ and $pT^{-5/2}\ll_L p^{-1/8}$. On the bulk,
$\Psi(u_k)=\frac12(u_k-1)^2(1+o(1))$ uniformly. Summing proves the
proposition.
\end{proof}
For the corollary, fix $\delta,\lambda$ as in
Theorem~\ref{thm:prime-density}. The length
$\lfloor\lambda p^{1-\delta}\rfloor$ belongs to the range of the
proposition with $\eta=\delta/2$ and $L=\lambda/2$ for large $p$.
Combining the proposition with $p\chi^2/T\to1/48$ on
$\mathcal P_\delta$ gives the stated limit.
\subsection{Prime level by character}\label{sec:level}
The trace-weight pairing gives both the second moment in each
nebentypus and the mixed moments between characters. For a
Dirichlet character $\chi\bmod\ell$, write $\tau_{\chi,k}(p)$
for the trace of $T_p$ on $S_k(\Gamma_0(\ell),\chi)$ multiplied by
$p^{-(k-1)/2}$. Set it to zero if $\chi(-1)\ne(-1)^k$.
These are the character components of the trace on $\Gamma_1(\ell)$.
\begin{theorem}[Prime-level character traces]\label{thm:level-density}
Fix an odd prime $\ell$, a unit class $r\bmod\ell$ and
$0<\delta\le2/3$. There is a relative-density-one set of primes
$p\equiv r\bmod\ell$ on which, for $K=p^{(1-\delta)/2}$ and
all characters $\chi,\psi\bmod\ell$,
\begin{equation}\label{eq:prime-level-character-matrix}
\frac{48}{K^2}\sum_{3\le k\le K}\tau_{\chi,k}(p)\overline{\tau_{\psi,k}(p)}
\longrightarrow
(\ell+1)\bigl(1_{\chi=\psi}+\chi(r)1_{\psi=\bar\chi}\bigr)
-(\ell-1)1_{\chi=\psi=1}.
\end{equation}
\end{theorem}
The diagonal is $\ell+3$ for the trivial character, $(\ell+1)(1+\chi(r))$
for the quadratic character, and $\ell+1$ for a nonreal character.
\begin{corollary}\label{thm:level-density-one}
On the set of Theorem~\ref{thm:level-density}, for every fixed
$\lambda>0$ and $T=\lfloor\lambda p^{1-\delta}\rfloor$,
\[
\frac{48}{K^2}\sum_{3\le k\le K}|\tau_k^{(\ell)}|^2,\qquad
\frac{48p}{T}\chi^2(P_T^{Y_1}\Vert Q_T)
\quad\longrightarrow\quad
(\ell-1)\bigl(\ell+(\ell+1)1_{r=1}\bigr).
\]
\end{corollary}
\begin{proof}[Proof of Theorem~\ref{thm:level-density} and Corollary~\ref{thm:level-density-one}]
We compute the pairing for fixed Frobenius eigenvalues modulo
$\ell$, then take character sums. Put $L=L_{\ell,A}$ and $n=\ell-1$
at determinant $A$.
For $a\in\mathbf F_\ell^\times$ choose a unit lift and put
\[
W_a(R)=n\left(
L(R)1_{R\equiv a+A/a\,(\ell)}+
\ell(L(R)-1)1_{A\equiv a^2\,(\ell)}1_{a^2-aR+A\equiv0\,(\ell^2)}
\right).
\]
The last condition, on the repeated-root class, is independent
of the lift. Let $g_\chi$ have local factor
$n^{-1}\sum_a\chi(a)W_a$ at $\ell$ and the usual factors elsewhere.
By \cite[Theorem~10, (43)--(44)]{KaplanPetrow}, an elliptic order
with index prime to $\ell$ contributes the sum of $\chi(a)$ over
roots modulo $\ell$. When $\ell$ divides the index, the repeated
root lifts modulo $\ell^2$ and receives the additional factor
$\ell$. Restricting to these orders removes the first term of the
local class-number sum, giving $L-1$ as in Supplement S6.
The hyperbolic term gives, in matching parity,
\[
\tau_{\chi,k}(p)=-\sqrt p\,m_{g_\chi,p}(k-2)
-(1+\chi(p))p^{-(k-1)/2}.
\]
In the other parity both the trace and the moment vanish, since
$W_a(-R)=W_{-a}(R)$. The squared corrections sum to $O_\ell(p^{-2})$.
Scaling the root variable by $a$ reduces the mean and diagonal
pairing of $W_a$ to those of $W_1$ at determinant $A/a^2$.
If $a^2\not\equiv r\bmod\ell$, the roots are simple and $W_a$
is $\ell$ times its trace-class indicator. Otherwise, on classes
modulo $\ell^2$, the mean of $W_a$ is $n$ times the indicator
modulo $\ell$ plus $\ell$ times the indicator modulo $\ell^2$.
The root-series means of Section~\ref{sec:trace-pairing} give
mean one in both cases and, for a repeated root, coefficient
magnitudes $1$ and $1/\ell$ at denominators $\ell$ and $\ell^2$.
In \eqref{eq:local-pair-tail} the $\ell$ lifts all give the same
trace modulo $\ell^2$, with coefficient $\ell^2-1$ for $L$.
Using $\sum_{u,u'}\min(2,v_\ell(u-u'))=\ell^2+\ell$ in
\eqref{eq:local-pair-count} gives higher-denominator energy $\ell$.
Thus
$\mathcal B_{\ell,A}(W_a,W_a)$ is $n\ell$ in the simple case
and $n(2\ell+1)$ in the repeated case.
The weights satisfy $W_{r/a}=W_a$. Reindexing gives
$g_\chi=\chi(r)g_{\bar\chi}$, and the trace corrections satisfy
the same relation. Thus $\tau_{\chi,k}\overline{\tau_{\bar\chi,k}}
=\chi(p)|\tau_{\chi,k}|^2$ exactly.
If $b$ is neither $a$ nor $r/a$, the weights have disjoint trace
classes modulo $\ell$. In that case
the cross Fourier sum is $-1$ at denominator $\ell$ and zero at
$\ell^j$ for $j\ge2$, by the Ramanujan sum on the difference of
the trace classes. Inserting these values into
\eqref{eq:local-pairing} gives the single formula
\begin{equation}\label{eq:prime-level-local-sum}
\mathcal B_{\ell,A}(W_a,W_b)
=n\bigl((\ell+1)(1_{b=a}+1_{b=r/a})-1\bigr).
\end{equation}
The involution term in the character sum is
$\sum_a\chi(a)\overline{\psi(r/a)}=n\chi(r)1_{\psi=\bar\chi}$,
which gives the phase in \eqref{eq:prime-level-character-matrix}.
Apply Theorem~\ref{thm:prime-density} to the real and imaginary parts of all
the weights, with $M=\ell^2$, and extend the pairing by sesquilinearity.
The constants depend only on $r\bmod\ell$, so the finitely many
prime classes modulo $\ell^2$ give the asserted set.
Summing over both characters gives the trace limit in the
corollary. For the prediction limit, $\sum_\chi g_\chi$ has local
factor $W_1$ by character orthogonality, so the global weight is
$(\ell-1)U$ from \eqref{eq:torsion-weight}. Its mass tends to one.
The smoothed limit in Theorem~\ref{thm:prime-density} then gives
the chi-square limit.
\end{proof}
In these units the dimension is $\ell^2-1$~\cite[Section~2]{RossDimensions}.
The two level-one copies count twice in the trivial-sector dimension
and four times in the second moment, adding two to the difference.
The remaining correction is $(\ell+1)\sum_{\chi\ne1}\chi(r)$.
For nonsquare $r$ the quadratic trace vanishes and the mixed terms
sum to zero. For square $r\ne1$ the mixed sum is $-2(\ell+1)$.
At fixed weight a Rankin--Selberg prime average counts common
automorphic constituents after twisting. Of the twists by characters
modulo $\ell$, the only
nontrivial level-preserving one is the contragredient twist by
$\bar\chi$ for $\chi\ne1$~\cite[Sections~1 and~3]{AtkinLi}.
\subsection{Variance and exceptional primes}\label{sec:exceptional}
At level one, the variances of both statistics in
Theorem~\ref{thm:prime-density}, over all primes $X