\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 $X0$ & 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_{j0$ put \[ R_\varepsilon(T,X)=\frac TX\log^3(2X/T) +X^{-1/3+\varepsilon}\max(T,\sqrt X)^{1/4}. \] \begin{theorem}\label{thm:elliptic} For integers $1\le T\le p$ and every $\varepsilon>0$, \[ \KL(P_T\Vert Q_T)\le\chi^2(P_T\Vert Q_T) \ll_\varepsilon R_\varepsilon(T,p). \] As $p\to\infty$, the KL divergence tends to zero if and only if $T=o(p)$. For $T\ge p$ it is $\frac12\log(T/p)+O(1)$, uniformly. \end{theorem} The short-interval estimate of \cite[Theorem~1.3]{DavidKoukoulopoulosSmith} gives vanishing loss for $T\le p^{1-\eta}$ with fixed $\eta>0$, by Section~\ref{sec:kl-short} and monotonicity. For a quadratic field $K$ with character $\chi_K$, the factorization $\zeta_K(s)=\zeta(s)L(s,\chi_K)$ transfers Alp\"oge's critical-line theorem~\cite{AlpogeAnnouncement,SutherlandVerification} to $\zeta_K$. Thus Ma~\cite[Theorem~1.5]{Ma} gives histogram convergence for trace lengths $f(p)=o(\sqrt p)$ with $f(p)\ge\exp(C(\log\log p)^2)$ eventually for every fixed $C>0$. To reach all $T=o(p)$ we estimate the Fourier modes of the trace weights after binomial sampling. \subsection{Class numbers on the trace lattice} Let $D_t=4p-t^2>0$ and $\Delta_p=(4\sqrt p)^{-1}$. We use the Hurwitz class number $H(D)$ with the normalization $H(3)=1/3$, $H(4)=1/2$. By Deuring's theorem, the $\F_p$-isomorphism classes with trace $t$, each weighted by $2/\#\operatorname{Aut}_{\F_p}(E)$, have total weight $H(D_t)$~\cite[Theorem~14.18]{Cox}\cite[(1.5)--(1.6)]{Lenstra}. A class contains $(p-1)/\#\operatorname{Aut}_{\F_p}(E)$ equations, so $(p-1)H(D_t)/2$ equations have trace $t$. Dividing by $p(p-1)$ gives the bias mass $\Delta_p\sigma(f_t)F(t)$, where $\sigma(f)=(8/\pi)\sqrt{f(1-f)}$ and $F(t)=\pi H(D_t)/\sqrt{D_t}$ is the correction to the sampled Sato--Tate mass. Write $-D_t=d_0r^2$ with $d_0$ fundamental and $\chi=\chi_{d_0}$. Let $\rho_t(n)$ count roots of $x^2-tx+p$ modulo $n$ and set $b_t=\lambda_{\rm L}*\rho_t$, with $\lambda_{\rm L}$ the Liouville function. The change $x\mapsto t-2x$ identifies the roots modulo $n$ with the classes $b\bmod 2n$ satisfying $b^2\equiv-D_t\pmod{4n}$, including at $2$. Zagier's formula~\cite[Proposition~3]{Zagier} gives \[ b_t=c_t*\chi,\qquad c_t(n)=\sum_{\substack{ge^2=n\\ge\mid r}}\mu(g)\chi(g)e,\qquad F(t)=\sum_{n\ge1} b_t(n)/n . \] The last series converges in ordinary order because $c_t$ has finite support and $\chi$ is nonprincipal. Its value at $s=1$ is the class-number formula for the orders of discriminant dividing $-D_t$ by a square~\cite[Theorem~7.24]{Cox}. We use $\sum|c_t(n)|/n\le \sum_{m\mid r}\tau(m)/m\le\sigma_{-1}(r)^2$ and write $F_N(t)=\sum_{n\le N} b_t(n)/n$. \begin{lemma}[Truncating the class-number weights]\label{lem:elliptic-tail} For $1\le N\le p^{13/30}$ and every $\varepsilon>0$, \[ \sum_{|t|<2\sqrt p}|F(t)-F_N(t)|^2 \ll_\varepsilon \sqrt p \left(\frac{\log^4(2N)}{N}+p^{-1/15+\varepsilon}\right). \] \end{lemma} \begin{proof} \emph{Fourier coefficients of the truncated series.} For $0\le AA}\frac{|h_d(n)|}n \ll\frac{\varphi(d)}{d^2}\min(1,\sqrt{d/A}), \] with the minimum interpreted as $1$ at $A=0$. For the tail, sum $s^{-2}m^{-2}j^{-2}$ over $s^2mj>A/d$, first in $s$. In particular the constant coefficient of $F_N$ is $1+O(N^{-1/2})$. Writing $\tau(d)$ for the divisor function, the Weil bound~\cite[Corollary~11.12]{IK} shows that the coefficient of $e(at/d)$ is $O(\tau(d)d^{-3/2}\min(1,\sqrt{d/A}))$. \emph{The terms with $Ny}\chi(n)/n\ll_\varepsilon p^{1/9+\varepsilon}y^{-1/3}$. This also holds for $0p$. \emph{Long observations.} Since $F_1=1$, Lemma~\ref{lem:elliptic-tail} gives $\Delta_p\sum_t F(t)^2\ll1$. Applying \eqref{eq:grid-norm} to $F$ yields $\sum_k P_T(k)^2/Q_T(k)\ll1+\sqrt{T/p}$. Jensen's inequality gives the logarithmic upper bound for $T\ge p$. Its matching lower bound is Lemma~\ref{lem:atomic}, since there are at most $4\sqrt p+1$ biases. \emph{The threshold.} The short-length bound tends to zero for $T=o(p)$. For $T\ge cp$ with fixed $c>0$, detect the lattice by testing the count $N_T$ with $\cos(\xi(N_T/T-1/2))$, where $\xi=2\pi/\Delta_p$. The binomial characteristic function, expanded at $\xi/T$, gives the complex expectation \[ e^{i\xi(f-1/2)} \exp\!\left(-\frac{\xi^2}{2T}f(1-f)\right)+O_c(p^{-1/2}) \] uniformly in $f$. Indeed $T(\xi/T)^3=O_c(p^{-1/2})$. The first factor is $1$ on the trace lattice, so the actual expectation of the cosine is at least $e^{-8\pi^2/c}+o(1)$. Against the reference, integrate the oscillation by parts. The product of $\sigma(f)$ and the damping factor has variation $O(1)$, so the reference expectation is $O(p^{-1/2})$. Pinsker's inequality for the bounded test gives a positive lower limit for the KL divergence for every $T\ge cp$. \end{proof} To apply the bound to restricted families, we allow omission of a fixed finite set $J$ of primes. Write $F^{(J)}$ for the series for $F$ with terms divisible by any prime in $J$ omitted, and $F^{(\ell)}$ for $J=\{\ell\}$. \begin{lemma}[Restricted trace weights]\label{est:restricted-smoothing} Let $A$ be a trace congruence class modulo a fixed integer $M$, and put $u=F^{(J)}1_A$. For $1\le T\le p$, \begin{equation}\label{eq:restricted-smoothing} \|P^u-\gamma_B Q_T\|_Q^2\ll_{M,J,\varepsilon}R_\varepsilon(T,p). \end{equation} Here $\gamma_B$ is the constant Fourier coefficient of the restricted weight after applying the smooth cutoff at $B=p^{2/3}\max(T,T_0)^{-1/4}$. \end{lemma} \begin{proof} Write $U=1_A F^{(J)}_{B,\psi}$ for the restricted cutoff weight. In the Mellin integral, restrict $C_t$ to integers prime to $J$ and multiply $L(s,\chi)$ by $\prod_{\ell\in J}(1-\chi(\ell)\ell^{-s})$. The extra factors are bounded on $\Re s=1/2$, so $\|P^{u-U}\|_Q^2\ll_{J,\varepsilon}p^{1/3+\varepsilon}/B$ as before. The same bounds for the cutoff on the trace lattice hold because $\sum_{n\le2B}|b_t(n)|/n$ also bounds the restricted sum. In the Fourier coefficients, the omission restricts the $h_d$ sum to integers prime to $J$. Multiplication by $1_A$ shifts the frequencies by $j/M$. If a reduced denominator $d$ becomes $d'$, then $d\mid Md'$ and $d'\mid Md$, so $\tau(d)d^{-3/2}\ll_M\tau(d')d'^{-3/2}$. The constant coefficient $\gamma_B$ is bounded because it only uses denominators dividing $M$. Decompose the centered measure as \[ P^u-\gamma_BQ_T=P^{u-U}+P^{U-\gamma_B} +\gamma_B(P^1-Q_T). \] Lemma~\ref{lem:smoothing} applies to the second term with denominator bound $2MB$. The last term has squared norm $O_M(T/p)$. With the chosen $B$ these estimates give \eqref{eq:restricted-smoothing} for $T\ge T_0$, and for $Tv=v_\ell(M)$, each unit root modulo $\ell^v$ has $\ell^{j-v}$ lifts $x$, each requiring the single trace $x+p/x\bmod\ell^j$. The conditional mean is therefore $\rho_{t_0}(\ell^v)$. The $j=0$ term gives $C\ge(2/3)^{\omega(M)}$, and the limited moduli give the claimed dependence on $p$. The mass $Z$ is independent of $T$, so taking $T=\lceil p^{9/10}\rceil$ gives $Z=C/M+o(1)$. For the chi-square bound, center \eqref{eq:restricted-smoothing} at $ZQ_T$ and divide by $Z^2$. Applying \eqref{eq:grid-norm} to $F1_{\mathcal A}$ gives $\sum_k P_T^M(k)^2/Q_T(k)\ll_M1+\sqrt{T/p}$, hence the upper bound for $T\ge p$ by Jensen's inequality. With at most $4\sqrt p/M+1$ biases, Lemma~\ref{lem:atomic} gives $\frac12\log(TM^2/p)-O(1)$ for $p\ge M^2$. Finally, for $T\ge cp$ test the count with $\cos(\xi(N_T/T-1/2)-2\pi t_0/M)$ and $\xi=2\pi/(M\Delta_p)$. On the class $\xi(f_t-1/2)=2\pi t/M$ is constant modulo $2\pi$. The cosine test in Theorem~\ref{thm:elliptic} then gives a positive lower limit for the loss. \end{proof} \subsection{The modular family and Hecke traces} Fix an odd prime $\ell\ne p$. For $\ell\ge5$, let $P_T^{Y_1}$ be the count law obtained by sampling uniformly in $Y_1(\ell)(\F_p)$ and using the trace of the corresponding elliptic curve for the bias. Write $N_\ell(p)=\#Y_1(\ell)(\F_p)$. For $\ell=3$ give each isomorphism class of pairs $(E,P)$ weight $1/|\operatorname{Aut}(E,P)|$ and let $N_3(p)$ be their total weight. We use $P_T^{Y_1}$ only when this family is nonempty. \begin{proposition}[Prediction on $Y_1(\ell)$]\label{prop:y-one} For every fixed odd prime $\ell$ and all sufficiently large $p\ne\ell$, \[ \chi^2(P_T^{Y_1}\Vert Q_T)\ll_{\ell,\varepsilon} R_\varepsilon(T,p) \qquad(1\le T\le p). \] As $p\to\infty$, the loss on $Y_1(\ell)$ tends to zero exactly when $T=o(p)$, and for $T\ge p$ it is $\frac12\log(T/p)+O_\ell(1)$. \end{proposition} \begin{proof} Let $C_\ell$ be the event $\ell\mid\#E(\F_p)$ and $D_\ell$ the event that all $\ell$-torsion is rational. The number of points of order $\ell$ is $(\ell-1)(1_{C_\ell}+\ell1_{D_\ell})$. A nontrivial automorphism $\alpha$ of $E$ fixes only $\ker(1-\alpha)$, of order at most four, so for $\ell\ge5$ the automorphisms act freely on the points of order $\ell$ and every pair $(E,P)$ has trivial automorphism group. For $\ell=3$ the law $P_T^{Y_1}$ is by definition the normalized law with the weights $1/|\operatorname{Aut}(E,P)|$. By orbit-stabilizer, the normalized $Y_1(\ell)$ trace law is the Weierstrass law reweighted by $1_{C_\ell}+\ell1_{D_\ell}$. Indeed the weight of a Weierstrass class is $1/(p|\operatorname{Aut}(E)|)$. If $Z=\Pr(C_\ell)+\ell\Pr(D_\ell)$, then $N_\ell(p)=p(\ell-1)Z$. Proposition~\ref{prop:classes} gives $Z\gg_\ell1$, and $Z\le1+\ell$. When $p\not\equiv1\pmod\ell$, the event $D_\ell$ is empty and the congruence-class estimate applies directly. \emph{When all $\ell$-torsion is rational.} For $p\equiv1\pmod\ell$, the group order is divisible by $\ell$ on $A=\{t:t\equiv p+1\bmod\ell\}$. Rationality of all the $\ell$-torsion can occur only on $B=\{t:t\equiv p+1\bmod\ell^2\}$. The mass of curves with all $\ell$-torsion rational at trace $t$ is $H(D_t/\ell^2)/(2p)$ on $B$ by \cite[Lemma~4]{KaplanPetrow}. These traces are ordinary since $t\equiv2\pmod\ell$ and the only supersingular trace over $\F_p$ is zero. For $t\in B$ compare the root counts of $x^2-tx+p$ with those of $y^2-((t-2)/\ell)y+(p+1-t)/\ell^2$, whose discriminant is $-D_t/\ell^2$. The substitution $x=1+\ell y$ identifies the root counts at moduli prime to $\ell$. At $\ell$ the old count is one, and at $\ell^{j+2}$ it is $\ell$ times the new count at $\ell^j$. The Liouville convolution multiplies each local root series at $s=1$ by $(1+1/\ell)^{-1}$. Hence the old and new local factors satisfy $L_\ell=1+L'_\ell/\ell$. Zagier's identity holds for every nonzero discriminant, so $F'(t)=\pi H(D_t/\ell^2)/\sqrt{D_t/\ell^2}$ is the value at $s=1$ of the series for the new quadratic. Since $b_t=c_t*\chi$ with $c_t$ multiplicative, $F=L_\ell F^{(\ell)}$ and $F'=L'_\ell F^{(\ell)}$ with the same $F^{(\ell)}$. Therefore $F-F^{(\ell)}=F'/\ell=\pi H(D_t/\ell^2)/\sqrt{D_t}$ on $B$. The resulting unnormalized $Y_1$ weight is \begin{equation}\label{eq:torsion-weight} U(t)=F(t)1_A(t)+\ell\bigl(F(t)-F^{(\ell)}(t)\bigr)1_B(t). \end{equation} For each of the three terms in \eqref{eq:torsion-weight}, \eqref{eq:restricted-smoothing} bounds the squared norm of the associated count measure after subtracting its mass times $Q_T$. Combine the three bounds by the triangle inequality and normalize by $Z$. The local factors are positive and $0\le F^{(\ell)}\le F$ on $B$, so $0\le U\le(1+\ell)F$. Equation~\eqref{eq:grid-norm} gives the upper bound for long observations. The finite-support bound and the lattice cosine test give the lower estimates just as for $P_T$. \end{proof} For $k\ge2$ set \[ \tau_k=p^{-(k-1)/2}\tr(T_p\mid S_k(SL_2(\mathbf Z))),\qquad \tau_k^{(\ell)}=p^{-(k-1)/2}\tr(T_p\mid S_k(\Gamma_1(\ell))). \] \begin{corollary}\label{cor:hecke-traces} For $1\le T\le p$, \[ \sum_{\substack{4\le k\le T+2\\k\ \mathrm{even}}} \kappa_{k-2}(T)\bigl(\tau_k+p^{-(k-1)/2}\bigr)^2 =p\,\chi^2(P_T\Vert Q_T)\ll_\varepsilon p R_\varepsilon(T,p). \] For every $p$ with $N_\ell(p)>0$ and all $T\ge1$, the prime-level identity is \[ \sum_{k=3}^{T+2}\kappa_{k-2}(T) \bigl(\tau_k^{(\ell)}+(\ell-1)c_kp^{-(k-1)/2}\bigr)^2 =\frac{N_\ell(p)^2}{p}\,\chi^2(P_T^{Y_1}\Vert Q_T), \] where $c_k=(1+1_{p\equiv1\,(\ell)}+(-1)^k1_{p\equiv-1\,(\ell)})/2$. In particular, for $2\le K\le\sqrt p$, \begin{equation}\label{eq:hecke-square} \sum_{\substack{4\le k\le K\\k\ \mathrm{even}}}|\tau_k|^2,\ \sum_{3\le k\le K}|\tau_k^{(\ell)}|^2 \ll_{\ell,\varepsilon} K^2\log^3(2p/K^2) +p^{2/3+\varepsilon}\max(K,p^{1/4})^{1/2}. \end{equation} The constant for the level-one sum is independent of $\ell$. \end{corollary} \begin{proof} \emph{Level one.} The Birch--Ihara formula \cite[Theorems~2 and~3]{KaplanPetrow} gives the degree-$(k-2)$ Chebyshev moment $-p^{-1/2}(\tau_k+p^{-(k-1)/2})$ for even $k\ge4$. The odd moments vanish by quadratic twisting, so Proposition~\ref{prop:angles} gives the first identity. \emph{The prime-level trace identity.} Let $C_\ell$ and $D_\ell$ be the divisibility and full-torsion events in the proof of Proposition~\ref{prop:y-one}. Use \cite[Theorem~3]{KaplanPetrow}. In its notation, when $p\equiv1\pmod\ell$, multiplying the unnormalized $C_\ell$ and $D_\ell$ moments by $p$ gives $T_{\ell,1}/(\ell-1)-\ell T_{\ell,\ell}$ and $T_{\ell,\ell}$, respectively, with $T_{a,b}=T_{a,b}(p,1)$. Thus the full-level trace cancels in the moment with weight $1_{C_\ell}+\ell1_{D_\ell}$. For $p\not\equiv1\pmod\ell$ the $C_\ell$ moment alone gives $T_{\ell,1}/(\ell-1)$. In both cases, for $k\ge3$, the prime-index formula for $T_{\ell,1}$ is $-\tr(T_p\mid S_k(\Gamma_1(\ell)))-(\ell-1)c_k$. Dividing by the mass and replacing $U_{k-2}(t,p)$ by $p^{(k-2)/2}U_{k-2}(t/(2\sqrt p))$ gives the normalized Chebyshev moment $-\sqrt p\,(\tau_k^{(\ell)}+(\ell-1)c_kp^{-(k-1)/2})/N_\ell(p)$. Apply Proposition~\ref{prop:angles}. \emph{Bounding the sum up to weight $K$.} Take $T=\lfloor K^2\rfloor$ in the two trace identities. For the weights retained in \eqref{eq:hecke-square}, $\kappa_{k-2}(T)\gg1$. Apply Theorem~\ref{thm:elliptic} and Proposition~\ref{prop:y-one} on the right sides of the identities. Removing the explicit corrections by the triangle inequality costs $O_\ell(1)$ in the squared bound. \end{proof} \begin{corollary}[Hecke trace bounds]\label{comp:hecke-traces} For $K=p^a$ with $4/150$, Petrow~\cite[Theorems~1.1--1.2]{Petrow} gives $|\tau_k|,|\tau_k^{(\ell)}|\ll_{\ell,\eta}p^{1/44+\eta}k^{61/66}$ for $k\ge p^{3/10+\eta}$. Sum its square and use Deligne below that cutoff to obtain $O_{\ell,\varepsilon}(p^{1/22+\varepsilon}K^{94/33})$ in the range of Petrow's estimate. The trace angles have spacing $\gg p^{-1/2}$ and $\sum_t F(t)^2\ll\sqrt p$, so the angular large sieve gives $O_\ell(p)$ for $K\le\sqrt p$. At prime level, use $U$ from \eqref{eq:torsion-weight}, or $F1_A$ if there is no full rational torsion. Comparing exponents in \eqref{eq:hecke-square} gives the claimed range. The $K^2$ term with its logarithm dominates for $K\ge p^{4/9+\eta}$ with any fixed $\eta>0$ and sufficiently small $\varepsilon$. At $K\asymp\sqrt p$ both \eqref{eq:hecke-square} and the large sieve are $O_\ell(p)$. \end{proof} A $2$-isogeny identifies the Legendre trace law with that of curves equipped with a rational point of order four, so the same smoothing bound applies. \begin{corollary}[Legendre family]\label{cor:legendre} For $p\ge5$ sample $\lambda$ uniformly in $\F_p\setminus\{0,1\}$ and use the trace of $y^2=x(x-1)(x-\lambda)$ for the bias. Its count law $P_T^{\mathrm{Leg}}$ satisfies $\chi^2(P_T^{\mathrm{Leg}}\Vert Q_T)\ll_\varepsilon R_\varepsilon(T,p)$ for $1\le T\le p$. The logarithmic loss tends to zero exactly when $T=o(p)$, and equals $\frac12\log(T/p)+O(1)$ for $T\ge p$. \end{corollary} \begin{proof} The universal $Y_1(4)$ curve $y^2=(x+s)(x^2+x+s)$ has a point $(0,s)$ of order four. Quotienting by the subgroup generated by its double gives the Legendre curve with $\lambda=1-4s$~\cite[Section~2]{KatzRatios}. The isogeny preserves the trace, and the parameters are in bijection. By the Tate normal form, $s\mapsto(E_s,(0,s))$ is a bijection onto the $\F_p$-isomorphism classes of pairs of a curve and a point of order four, and automorphisms act freely on such points. Thus the Legendre law is obtained by weighting each Weierstrass curve by its number of rational points of order four and dividing by the mean $(p-2)/p$. Writing $n=\#E(\F_p)$ and $A_j=\{E[j]\subset E(\F_p)\}$, this number is \begin{equation}\label{eq:legendre-order-four} 2(1_{4\mid n}-1_{A_2})+4\,1_{A_2}1_{8\mid n}+8\,1_{A_4}. \end{equation} When the $2$-torsion is rational, the $2$-part of the group is $\mathbf Z/2^a\times\mathbf Z/2^b$ with $a\ge b\ge1$, and $8\mid n$ exactly when $a\ge2$. Indeed, the rational $4$-torsion is either cyclic, $(\mathbf Z/2)^2$, $\mathbf Z/4\times\mathbf Z/2$, or $(\mathbf Z/4)^2$. At trace $t$, the mass of $A_2$ is $H(D_t/4)/(2p)$ when $4\mid p+1-t$, and that of $A_4$ is $H(D_t/16)/(2p)$ when $p\equiv1\pmod4$ and $16\mid p+1-t$, with zero otherwise \cite[Lemmas~3--4]{KaplanPetrow}. This includes $t=0$ for $A_2$. It occurs only for $p\equiv3\pmod4$, when $H(p)=h_w(-p)$ in their notation. On the first progression the substitution $x=1+2y$ used in \eqref{eq:torsion-weight} gives the local relation $L_0=1+L_1/2$. On the second, the new quadratic is $y^2$ modulo $2$ and one can divide again with $y=2z$, giving $L_1=1+L_2/2$. Hence the two masses on their respective progressions are $\Delta_p\sigma(f_t)(F-F^{(2)})(t)$ and $\Delta_p\sigma(f_t)(F-\frac32F^{(2)})(t)$. The bounds for the restricted weights $F$ and $F^{(2)}$ follow from Lemma~\ref{est:restricted-smoothing}, with $J=\varnothing$ or $J=\{2\}$. Subtract the mass times $Q_T$ from each of these measures and combine their bounds to obtain the short-length estimate. The order-four weight is at most twelve, so \eqref{eq:grid-norm} gives the upper bound for long observations. The finite-support bound and the lattice test give the lower estimates. \end{proof} \section{The critical profile}\label{sec:critical} We derive the limiting likelihood ratio at $T/p\to c>0$ and use it to compute both divergences. We then let $c\downarrow0$ and extend the fixed-$c$ formulas to the restricted families. \subsection{The profile at the trace-lattice scale} At $T\sim cp$ the sampling error is on the scale of the bias spacing, so neighboring traces contribute to the same count. Take a subsequence of primes on which $p\bmod d$ eventually stabilizes for each fixed $d$, with unit residue system $A$. For a reduced fraction $a/d\pmod 1$ put \[ \gamma_A(a/d)=\frac{S(a,aA;d)}{d^2} \prod_{\ell\mid d}(1-\ell^{-2})^{-1},\qquad \gamma_A(0)=1, \] where $aA$ uses the residue of $A$ modulo $d$. Extend $\gamma_A$ to $\mathbf Q$ by periodicity, and let $\mu_A$ put mass $|\gamma_A(\beta)|^2$ at $|\beta|$ for each nonzero rational $\beta$. Let $R$ record the residues of the integer trace nearest the observed proportion of ones on the bias scale. In the limit, $R$ is uniform on $\widehat{\mathbf Z}=\prod_\ell\mathbf Z_\ell$. For each prime $\ell$ let $\rho_{A,R}(\ell^j)$ count the roots of $x^2-Rx+A$ modulo $\ell^j$, with $\rho_{A,R}(1)=1$. Set \[ L_{\ell,A}(R)=\frac{1}{1+\ell^{-1}} \sum_{j\ge0}\frac{\rho_{A,R}(\ell^j)}{\ell^j}, \qquad F_A(R)=\prod_\ell L_{\ell,A}(R). \] The product converges in $L^2$. Take $Y$ with density $\sigma$ and $U$ uniform on $[-1/2,1/2)$, independently of each other and $R$. The binomial variance of the proportion of ones in squared lattice steps tends to $v=16Y(1-Y)/c$. Let $\phi_v$ be the centered normal density of variance $v$ and set \[ B_{A,c}(Y,R,U)=\sum_{j\in\mathbf Z} F_A(R+j)\phi_v(U-j), \qquad v=16Y(1-Y)/c. \] \begin{theorem}\label{thm:critical-profile} Suppose $T/p\to c>0$ along a sequence of primes whose residues stabilize modulo every fixed integer, and let $A$ be the resulting system of unit residues. Then the expected excess log loss satisfies \begin{equation}\label{eq:critical-kl} \KL(P_T\Vert Q_T)\longrightarrow \mathcal K_A(c)=\E\big[B_{A,c}\log B_{A,c}\big]. \end{equation} The corresponding chi-square limit is \begin{equation}\label{eq:critical-profile} \chi^2(P_T\Vert Q_T)\longrightarrow \mathcal C_A(c)= \int_0^1 \sigma(y) \sum_{\substack{\beta\in\mathbf Q\\\beta\ne0}} |\gamma_A(\beta)|^2 e^{-64\pi^2 y(1-y)\beta^2/c}\,dy. \end{equation} Both limits are finite and positive. As $c\to\infty$ the limiting logarithmic loss satisfies \begin{equation}\label{eq:critical-kl-large} \mathcal K_A(c)=\tfrac12\log c-1-\tfrac12\log(2\pi) +\E[F_A\log F_A]+o(1). \end{equation} If $A\equiv1\pmod3$ and $A'\equiv2\pmod3$, then $\mathcal C_A$ and $\mathcal C_{A'}$ are distinct. If their components away from $3$ coincide, then $\mathcal K_{A'}(c)>\mathcal K_A(c)$ for all sufficiently large $c$. \end{theorem} Gekeler~\cite{Gekeler} derived the local trace weights, also described in \cite[Theorem~1.1]{DavidKoukoulopoulosSmith}. Ma~\cite[Theorem~1.3, Corollary~1.4 and Lemma~7.1]{Ma} gives subsequence laws for the isogeny-class size at a uniformly sampled trace. Its local factors depend on $(p/\ell)$ at odd $\ell$ and on $p\bmod8$ at $2$. Here binomial sampling combines the joint weights of neighboring traces. Related smoothing appears in channel capacity for equally spaced priors~\cite[Sections~3.1 and~4]{AbbottMachta} and in Lee's preprint for one curve across primes under symmetric-power GRH~\cite[Theorem~1.4]{LeeSatoTate}. \begin{proof} \emph{The limiting weights.} Each local series converges uniformly by the quadratic root bound $\rho_{A,R}(\ell^j)\ll_\ell\ell^{j/2}$. For $j\ge1$ the mean of $\rho_{A,R}(\ell^j)$ is $\varphi(\ell^j)/\ell^j$: each unit $x$ determines the single trace $x+A/x$. Thus $\E L_{\ell,A}=1$. For a primitive frequency $a/\ell^k$, the Fourier coefficient of $\rho_{A,R}(\ell^j)$ is zero when $j0$ for every $c>0$. If $G_v$ is a centered normal variable of variance $v$, then its reduction to $[-1/2,1/2)$ has density $Z_v$ and its nearest integer has entropy $o(1)$ as $v\to0$, by Gaussian tails. The entropy chain rule therefore gives $\int Z_v\log Z_v=-\frac12\log(2\pi e v)+o(1)$. By Jensen and translation invariance, \[ \int_{-1/2}^{1/2}\! Z_v(u)\, \E_R|\overline F_v(R,u)-F_A(R)|^2\,du \le 4\|F_A\|_2^2\Pr(|G_v|\ge1/2). \] By Jensen, $\E_R\overline F_v^2\le\|F_A\|_2^2$ for every $u$, so the variables $\overline F_v\log \overline F_v$ are uniformly integrable. With the $L^2$ bound just displayed, the second term tends to $\E[F_A\log F_A]$. Both errors vanish uniformly for $v\le4/c$ as $c\to\infty$. The beta law gives $\E\log(Y(1-Y))=1-4\log2$. Averaging proves \eqref{eq:critical-kl-large}. \emph{Dependence on the prime residues.} For $1/20. \] 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 $0a/x\\(a,d)=1}} \frac{Y_{a,d}}{d^3}. \] When $d$ is of order $1/x$, only a bounded number of numerators contribute. We use the mean over denominators for each such numerator. Let $\E_L$ denote conditional expectation with the coordinates at primes $\ell\le L$ held fixed, and put $P=\prod_{\ell\le L}\ell$. Write $d=rm$, with $r$ composed of primes dividing $P$ and $(m,P)=1$. For fixed $a$ and $r$ with $(r,a)=1$, the conditional mean of $Y_{a,rm}$ is $g(m)$ times $Y_{a\bar m,r}$, where $\bar m$ is taken modulo $r$. The function $g(m)1_{(m,aP)=1}$ has mean \[ M(aP)=\prod_{\ell\mid aP}(1-\ell^{-1}) \prod_{\ell\nmid aP} \left((1-\ell^{-1})\sum_{k\ge0}\frac{g(\ell^k)}{\ell^k}\right). \] In each unit class modulo $r$, its sum up to $D$ is $DM(aP)/\varphi(r)+O(\tau(aP))$. For this estimate expand $g=1*(g*\mu)$, then use inclusion--exclusion at the primes dividing $aP$ that do not divide $r$. Absolute summability of $g*\mu$ controls the sum of the errors. Partial summation above $m=a/(xr)$ and averaging $Y_{a\bar m,r}$ over the unit classes gives the main term $M(aP)w_A(r)/(a^2\varphi(r))$ in $\E_L Z_x$. For $r\le x^{-1/8}$ the sum of the errors is \[ \ll x\,\tau(P)\sum_{r\le x^{-1/8}} r\tau(r)^2 \sum_{a\ge1}\frac{\tau(a)}{a^3}. \] Here the coefficient bound for a unit numerator is $Y_{a,r}\ll\tau(r)^2$. For larger $r$, both the sum and its main term are bounded by a constant times $\sum_{r>x^{-1/8},\,r\mid P^\infty}\tau(r)^2/r$. This is at most $x^{1/16}\exp(O(\sqrt L))$, by inserting $r^{1/2}$ and summing the product over $\ell\mid P$. Taking $L=\tfrac1{10}\log(1/x)$, both errors are $O(x^{1/32})$. The main terms over $a$ and $r$ form an Euler product. Whether $\ell\le L$ or $\ell>L$, its factor is \[ (1-\ell^{-1})\left(1+\frac1{\ell^2-1}\right) +\frac{\ell}{\ell^2-1} =(1-\ell^{-2})^{-1}. \] At a prime held fixed this uses \eqref{eq:local-short-mean}. At the other primes one uses its expectation. Consequently $\E_L Z_x=\zeta(2)+O(x^{1/32})$ uniformly in the fixed coordinates. \emph{Fluctuations from the remaining primes.} In the fourth moment of $Z_x-\E_L Z_x$, consider four denominators $d_1,\ldots,d_4$. If one denominator shares no prime $\ell>L$ with the other three, its centered factor is independent of theirs once the small-prime residues are fixed. Its conditional mean is zero, so the term vanishes. The full Haar expectation of the absolute value of the product of the four centered weights is bounded by \[ \ll \prod_{iL$ and sets $I_s\subset\{1,2,3,4\}$ such that $|I_s|\ge2$, their union is all four indices, and $\ell_s\mid d_i$ for $i\in I_s$. Expand $\tau(n)^2=\sum_{h\mid n}(\tau^2*\mu)(h)$, whose coefficients at $\ell^k$ are $2k+1$ for $k\ge1$. If $D_i$ is the least common multiple of the divisibility conditions imposed on $d_i$, then \[ \sum_{\substack{d_i>a_i/x\\D_i\mid d_i}}d_i^{-3} \ll \frac{x^2}{D_i a_i^2}. \] After dividing by $x^8$ and summing the $a_i$, the remaining divisor sums are an Euler product. At a prime let $k$ be the largest exponent in the six divisors for the pairs $iL}\ell^{-2}$. Thus \[ \E\bigl|Z_x-\E_L Z_x\bigr|^4\ll L^{-2}. \] At $x_n=\exp(-n^{3/4})$ the fourth-moment bounds are summable, so Markov's inequality and Borel--Cantelli give $Z_{x_n}\to\zeta(2)$ almost surely. Since $x_{n+1}/x_n\to1$ and $\mu_A((0,x))$ is increasing in $x$, the same limit holds as $x\downarrow0$. \emph{From the frequency mass to the profile.} Put $b(y)=64\pi^2y(1-y)$. Integration by parts in \eqref{eq:critical-profile}, followed by $z=b(y)x^2/c$, gives \[ \frac{\mathcal C_A(c)}c =\int_0^1\frac{\sigma(y)}{b(y)} \int_0^\infty z e^{-z}Z_{\sqrt{cz/b(y)}}\,dz\,dy. \] For a residue system satisfying the first limit, $Z_x$ is bounded for all $x>0$. For large $x$ this follows from the periodicity of $\gamma_A$ and its square-summable coefficients modulo one. Dominated convergence gives $\zeta(2)/(8\pi^2)=1/48$, since $\int_0^1\sigma(y)/(y(1-y))\,dy=8$. \end{proof} The preprint of Jiang and Lau~\cite[Corollary~4.1]{JiangLau} gives the upper bound $\mathcal C_A(c)\ll c$ for every residue system. With $z=1$ and $\nu=2$, their corollary bounds $\sum_{d\le D}|S(1,b;d)|^2/d\ll D$ uniformly over all nonzero integers $b$. For each $D$, choose a nonzero representative of $a^2A$ modulo $\operatorname{lcm}(1,\ldots,D)$. Partial summation then bounds the contribution from a fixed numerator $a$ by $O(x^2/a^2)$. Summing over $a$ gives $\mu_A((0,x))\ll x^2$, and the preceding integral gives $\mathcal C_A(c)\ll c$. The theorems below do not use this bound. \subsection{Profiles for restricted families}\label{sec:profile-families} For a trace class $t\equiv t_0\pmod M$, replace each factor $L_{\ell,A}$ for $\ell\mid M$ in $F_A$ by its restriction to $R\equiv t_0\pmod{\ell^{v_\ell(M)}}$, divided by its mass. For $Y_1(\ell)$, replace just $L_{\ell,A}$ by the normalization of \begin{equation}\label{eq:profile-level-factor} V_A(R)=L_{\ell,A}(R)1_{R\equiv A+1\,(\ell)} +1_{A\equiv1\,(\ell)}\,\ell\bigl(L_{\ell,A}(R)-1\bigr) 1_{R\equiv A+1\,(\ell^2)}. \end{equation} Write $F_A^\flat$ for the resulting weight, $\gamma_A^\flat$ for its Fourier coefficients, and $B^\flat_{A,c}$ for the Gaussian sum $B_{A,c}$ with $F_A^\flat$ in place of $F_A$. In either case write $P_T^\flat$ for the corresponding count law. \begin{proposition}\label{prop:profile-families} Suppose $T/p\to c>0$ along a sequence of primes whose residues stabilize modulo every fixed integer, with limiting system $A$. Then \[ \KL(P_T^\flat\Vert Q_T)\longrightarrow \E\bigl[B^\flat_{A,c}\log B^\flat_{A,c}\bigr], \qquad \chi^2(P_T^\flat\Vert Q_T)\longrightarrow \int_0^1\sigma(y)\sum_{\beta\ne0}|\gamma_A^\flat(\beta)|^2 e^{-64\pi^2y(1-y)\beta^2/c}\,dy . \] Both limits are finite and positive, and as $c\to\infty$ the first is $\frac12\log c-1-\frac12\log(2\pi)+\E[F_A^\flat\log F_A^\flat]+o(1)$. \end{proposition} \begin{proof} For $P_T^M$ the weight is $F1_{\mathcal A}/Z$, and for $P_T^{Y_1}$ it is $U/Z$ with $U$ as in \eqref{eq:torsion-weight}. Truncating $F$ and $F^{(\ell)}$ at $N$ gives periodic weights that stabilize for fixed $N$. Their squared tail bound from Lemma~\ref{lem:elliptic-tail} persists under fixed congruence restrictions and omission of $\ell$. The masses converge to the local means by Propositions~\ref{prop:classes} and~\ref{prop:y-one} and the cutoff estimate \eqref{eq:restricted-smoothing}. In the modular case \eqref{eq:torsion-weight} gives exactly \eqref{eq:profile-level-factor}. Thus the normalized cutoffs converge to $F_A^\flat$ in $L^2$. The likelihood-ratio and Parseval arguments of Theorem~\ref{thm:critical-profile} apply to these cutoffs, with their endpoint contributions bounded by \eqref{eq:grid-norm} and the beta-binomial estimate used there. The full ratio is nonnegative and its bounded second moment yields uniform integrability of $x\log x$. Normalization gives mean one for $F_A^\flat$, so the same wrapped Gaussian proves positivity and the large-$c$ expansion. \end{proof} \section{Short observations and Hecke trace asymptotics}\label{sec:short} A trace weight $g$ is a fixed finite real linear combination of $F^{(J)}1_{\mathcal A}$ as in Lemma~\ref{est:restricted-smoothing}. The coefficients may depend on a fixed residue class of $p$. Choose $M$ divisible by the selector periods, the moduli specifying the coefficients, and all primes in the omitted sets $J$. Write $P^g$ for the corresponding unnormalized count measure. The pairing $\mathcal B_r(g,h)$ is defined in Section~\ref{sec:trace-pairing}. \begin{theorem}[Short-length limits for trace weights]\label{thm:prime-density} Fix $0<\delta\le2/3$, a unit class $r\bmod M$, and a finite list of trace weights. Write $Z_g$ for the mass of $P^g$ and $m_{g,p}(j)$ for the degree-$j$ Chebyshev moment of the unnormalized bias measure with weight $g$. There is a set of relative density one among primes in the class on which, for every pair $g,h$ from the list and every fixed $\lambda>0$, with $T=\lfloor\lambda p^{1-\delta}\rfloor$ and $K=p^{(1-\delta)/2}$, \begin{align} \frac pT\langle P^g-Z_gQ_T,P^h-Z_hQ_T\rangle_Q &\longrightarrow\mathcal B_r(g,h)/48,\label{eq:mixed-short}\\ \frac p{K^2}\sum_{1\le j\le K-2}m_{g,p}(j)m_{h,p}(j) &\longrightarrow\mathcal B_r(g,h)/48.\label{eq:mixed-sharp} \end{align} Here $\langle P,R\rangle_Q=\sum_k P(k)R(k)/Q_T(k)$. For fixed $\lambda>0$ and $0<\eta\le1$, count the primes $p\ge5$ in $(X,2X]$ in the designated class with $T\ge1$ on which the first expression differs from its limit by more than $\eta$. Their number is \[ O_{g,h,M,\delta,\lambda}\bigl(\pi(X)/(\eta^2\log X)\bigr). \] \end{theorem} Write $\mathcal P_\delta$ for the set with $g=h=F$ and $M=1$. The two limits are then the normalized chi-square divergence and, by Corollary~\ref{cor:hecke-traces}, the level-one trace sum. The common set can depend on $\delta$, the weights and $r\bmod M$. The dyadic bound is for each fixed $\lambda$ and pair. \paragraph{Proof of Theorem~\ref{thm:prime-density}.} We truncate the class-number weights and control the products at distinct frequencies. Section~\ref{sec:trace-pairing} averages the Fourier diagonal over primes and recovers the sharp cutoff. \paragraph{Truncating the class-number weights.} Let $g_B$ be the smooth cutoff at $B$. Average its error by grouping the Mellin integrals by fundamental discriminant. Each $d$ with $|d|\asymp D$ occurs for at most $O(X/\sqrt D)$ pairs $(p,t)$ in $(X,2X]$, since $4p=t^2+|d|r_t^2$. Heath--Brown's fourth moment \cite[Theorem~2]{HeathBrownReal} and Cauchy--Schwarz bound the sum of $|L(1/2+iv,\chi_d)|^2$ over these discriminants by $O_\varepsilon(D^{1+\varepsilon}(1+|v|)^2)$. Multiplying by the multiplicity and the grid step $\Delta_p\asymp X^{-1/2}$, summing in $D$ and integrating with weight $(1+|v|)^{-10}$ gives a total $O_\varepsilon(X^{1+\varepsilon})$. On shifting the Mellin integral to $\Re s=1/2$, Cauchy--Schwarz supplies $B^{-1}$ in the squared error. The divisor factors cost $p^\varepsilon$ and the omitted Euler factors are bounded. Markov's inequality and \eqref{eq:grid-norm} give \begin{equation}\label{eq:averaged-class-tail} \Delta_p\sum_{t^2<4p}|g(t)-g_B(t)|^2 +\|P^g-P^{g_B}\|_Q^2\ll_{g,\varepsilon}p^\varepsilon/B \end{equation} for all $B\ge1$ and $1\le T\le p$ on the same set of primes, outside $O_{g,\varepsilon}(X^{1-\varepsilon/4})$ exceptions for $0<\varepsilon<1$. See \hyperref[lem:averaged-tail]{Lemma~S5.1} for the integral used in this bound. \begin{lemma}[Uniform approximation at short lengths]\label{lem:short-profile} Let $A_p$ have the residue of $p$ at each prime other than $p$, and $p$-adic coordinate $1$. For a weight $g$ as above, let $Z_p$ be the mass of $P^g$. Write $\mathcal C_{A_p}^g(c)$ for the nonzero-frequency integral of Theorem~\ref{thm:critical-profile} with the Fourier coefficients of the corresponding weight on $\widehat{\mathbf Z}$. Fix $0<\delta_0<1/2$. Outside $O_{g,\delta_0}(X^{1-\xi})$ primes in each $(X,2X]$, uniformly for $p^{-\delta_0}\le c=T/p\le1/2$, \begin{equation}\label{eq:shrinking-profile} \|P^g-Z_pQ_T\|_Q^2 =\mathcal C_{A_p}^g(c)+O_{g,\delta_0}(c^{3/2}+cp^{-\nu}) \end{equation} for some $\xi,\nu>0$. For fixed $\lambda>0$, $1/6\le a\le1/4$, and every $J>0$, at $T=\lfloor\lambda p^{2a}\rfloor$ the same formula holds with $c=\lambda p^{2a-1}$ and $p^{-\nu}$ replaced by $(\log X)^{-J}$, outside $O_{g,a,\lambda,J}(X(\log X)^{-J})$ primes. In both cases the mass $Z_p$ differs from the complete constant Fourier coefficient by a power-saving error. \end{lemma} \begin{proof} \emph{From moments to an angular integral.} Write $U=T$ in the first range and $U=\lambda p^{2a}$ at a fixed weight exponent, and put $c=U/p$. Set $w=2\sqrt p\sin\phi$, $s=2\sqrt p\cos\phi$, $\theta_t=\arccos(t/(2\sqrt p))$ and $G(z)=\sum_{j\in\mathbf Z}e^{-j^2/(2U)}e^{ijz}$. After expanding the trace selectors, the cutoff Fourier coefficients are sums of $C_dS(m,mp;d)$ at $\beta=m/d+\alpha$, where $(m,d)=1$, $\alpha$ is a fixed rational shift and $|C_d|\ll_g d^{-2}$ by Lemma~\ref{lem:elliptic-tail}. With $B$ fixed on $(X,2X]$, each $C_d$ is constant in the given prime class. Write $\gamma_B(\beta)$ for the combined coefficient and $Z_B$ for the mass of $P^{g_B}$. The odd kernel gives the angular sum \[ \mathcal D(\phi)=\sum_t g_B(t)\bigl(G(\phi-\theta_t)-G(\phi+\theta_t)\bigr) -2\pi\gamma_B(0)w e^{-1/(2U)}. \] Its coefficient of $\sin((m+1)\phi)$ is $4\pi\sqrt p\,e^{-(m+1)^2/(2U)} (m_{g_B,p}(m)-1_{\{m=0\}}\gamma_B(0))$. Sine Parseval gives \hyperref[eq:odd-heat]{\textup{(S2)}}, with first-sine term $e^{-1/U}|Z_B-\gamma_B(0)|^2$. In the interior, linearizing the trace-to-angle map and using Poisson summation give the mode $2\pi w e(\beta s)e^{-2\pi^2w^2\beta^2/U}$. The equal-frequency terms give the truncated profile, since $w^2=16py(1-y)$ for $y=(1+\cos\phi)/2$ and $w^2|d\phi|/(2\pi p)=\sigma(y)|dy|$. \emph{Longer observations.} Take $\rho=(1/2-\delta_0)/2$, $B=X^{1/2-\rho}$ and split the Fourier sum at denominator $X^{1/4}$. Integration by parts bounds the low mixed terms, and the additive large sieve bounds the high squared norm on average. Their relative cost is $O(X^\varepsilon X^{1/4}/\sqrt T)$, while the class-number tail costs $O(X^\varepsilon/(Bc))$. Both are $O(X^{-\rho+\varepsilon})$. The normalized squared Taylor and mass errors are $O(X^\varepsilon((Tc)^{-1}+B/(pc)))$. The edge contributes $O(c^{3/2}+cX^{-\nu})$ in squared norm. The uniform version and its dyadic summation are in \hyperref[lem:profile-above-endpoint]{Lemma~S5.2}. \emph{Shorter observations.} For $1/60$ small. For $\mu=(3a-1/2)/2$ we have $Bc\asymp X^\mu$ and $B/X^{1/2+a}=X^{-\mu}$. The odd kernel gives the edge bound. On rescaling the trace by $L=X^{1/2-2a}$ its Fourier transform decays with exponent $3/2$. The large sieve on moving intervals of length $\asymp\sqrt X L$ gives the relative squared error $X^{O(\nu+\varepsilon)}(X^{-a}+D/X^{1/2+a})$ at denominator scale $D$. In the interior the Taylor parameter is $\sqrt p/(w\sqrt U)\ll X^{-\nu}$ for $w\ge X^{1/2-a+\nu}$. The continuous integral $2\pi w e^{-1/(2U)}$ cancels the zero mode. These estimates give the approximation in \hyperref[lem:endpoint-heat]{Lemma~S5.3}, \[ \chi_X(\phi)\,2\pi w \sum_{\beta\ne0}\gamma_B^+(\beta)e(\beta s)e^{-2\pi^2w^2\beta^2/U}, \qquad \chi_X(\phi)=\chi(X^\omega w/\sqrt X). \] Here $\chi$ is a smooth cutoff from zero to one on $[1,2]$ and $\gamma_B^+$ restricts the original denominators to $d\le D_+$. For the first sine projection use $\sqrt X|\beta|\gg X^{a-\omega}$. Both squared errors are $O(c(\log X)^{-J})$ off $O(X(\log X)^{-J})$ primes. \emph{Nearby frequencies.} Oscillation in the trace removes well-separated pairs. For the rest, open the Kloosterman sums and average over integers. Put $b_0=1/2-a$, $v=p/X$ and $u=s/\sqrt X$. Each pair has amplitude proportional to $\chi_X^2\sqrt{4v-u^2}/v$ times a Gaussian with exponent $-C_\lambda X^{2b_0}(4v-u^2) (\beta^2+\beta'^2)/v^{2a}$. Each derivative costs $O(X^{2\omega})$ times a weaker Gaussian. Gaussian decay and integration by parts in $u$ allow us to impose \[ |\beta|,|\beta'|\le X^{-b_0+\omega+\varepsilon},\qquad 0<|\beta-\beta'|\le X^{-1/2+2\omega+\varepsilon}, \] with arbitrary power savings, also for one $v$ derivative. Write $\beta=A/(Md)$, $\beta'=A'/(Me)$ with $M$ containing the fixed shifts. Then $0<|A|,|A'|\ll_g J=X^{2\omega+\varepsilon}$, $de\gg_g P=X^{2b_0-2\omega-2\varepsilon}$ and $0<|h|=|Ae-A'd|\ll_g H=X^{2b_0-1/2+4\omega+\varepsilon}$. For $g_1=(d,e)\asymp G$ there are $O_g(J^2D_+H/G)$ pairs: $g_1\mid h$, and $A,A',d/g_1,h/g_1$ determine $e/g_1$. If $(d,e)=1$, the unshifted numerators give $h_0=me-m'd$ and \[ S(m,mn;d)\overline{S(m',m'n;e)}=S(h_0^2,n;de). \] Indeed $r=xe-x'd\bmod de$ runs through the units, and its inverse phase has numerator $(m^2e^2+m'^2d^2)\bar r\equiv h_0^2\bar r\bmod de$. In general, frequencies lie on the grid of period $l=[d,e]$ with at most $g_1$ preimages, so the coefficients are $O_g(g_1(de)^{-2})$. Call the sum $F(n,v)$, with phases at $n$ and amplitudes at $v$. For fixed $v$, use a smooth nonnegative majorant of $1_{[1,2]}(n/X)$. Poisson summation bounds the kernel by $O_A((1+X\|\xi-\xi'\|)^{-A})$. Differences between grids of periods $l,l'$ run through the grid of period $[l,l']$ with multiplicity $(l,l')$. Off zero the integral test gives $O(ll'/X)$. Since $g_1l=de$, the bound per two pairs is $O_g(1/(Xde\,d'e'))$, giving $O_g((J^2D_+H)^2/(XP^2))$. At a coincident frequency of reduced denominator $q$ we have $l/q\mid g_1$: the numerator is a unit where the exponents of $d,e$ differ. For $g_1\asymp G$, choosing $l/q,d,e,A,A'$ gives at most $O_{g,\varepsilon}(J^2GX^\varepsilon)$ pairs per frequency. Each has squared coefficient sum $O_g(GP^{-3})$. Cauchy--Schwarz and $G\ll H$ give $O_{g,\varepsilon}(X^\varepsilon J^4D_+ H^2P^{-3})$ after the logarithmic cost of summing the blocks. One $v$ derivative costs $X^{4\omega}$ in these bounds. The inequality $\sup |f|^2\ll\|f\|_2^2+\|f\|_2\|f'\|_2$ in $v$ and Cauchy--Schwarz in $n$ cost $X^{2\omega}$ in the mean square and let us set $v=p/X$. The resulting bound is $O_{g,\lambda}(X^{-1-2a+O(\omega+\varepsilon)} +X^{a-3/2+O(\omega+\varepsilon)})$. Relative to $c^2$ the exponents are $-4\mu$ and $-2\mu$ before losses. Choose $\omega,\varepsilon$ small in terms of $\mu$ to get $O(X^{-\mu})$. Markov bounds the primes with a cross term above $c(\log X)^{-J}$ by $O(X^{1-\mu}(\log X)^{2J})$. At equal \emph{trace} frequencies we add the coefficients before squaring in the profile. \emph{The endpoint $a=1/6$.} Now $c\asymp X^{-2/3}$ and the preceding mean-square bounds reach the scale $c^2$. In \hyperref[lem:sixth-endpoint]{Lemma~S5.4} the quadratic functional equation converts the class-number remainder at $B=X^{2/3-\rho}$ into a dual sum of length $O(X^{1/3+\rho+\varepsilon})$. Removing square factors supported on the omitted primes reduces the conductor. The cutoff condition $\widehat\psi(-1/2)=0$ cancels the pole in the zero mode. In squared angular norm the edge costs $O(X^{-7/6+7\nu+3\rho+\varepsilon})$ and the nonzero dual modes cost $O(X^{-1+\rho+\varepsilon})$ on average by the large sieve. Both are smaller than $c$ by a power. The averaged tail estimate controls $g-g_{B_1}$ for $B_1=X^{2/3+\rho}$. The angular estimates in the proof of S5.3 control the difference of the two cutoffs for $d\le2B$. Subtracting this part bounds the block $d>2B$ with its original phases. Nearby frequencies have denominators of size $X^{1/3+O(\omega+\varepsilon)}$ and determinants $|h|,|h'|\ll X^{1/6+O(\omega+\varepsilon)}$. At coincident integer frequencies Parseval gives $O(X^{-3/2+O(\omega+\varepsilon)})$. For nonzero Poisson modes, $O(1/(Xd_1d_2d_3d_4))$ per quadruple gives a power saving on exceptional shared factors and discarded numerators. After separating shared primes, reciprocity gives a phase proportional to $h^2P_2/P_1+h'^2P_1/P_2$, where $P_1=d_1d_2$ and $P_2=d_3d_4$. The modulus is a squarefree factor $j_0$ of the Poisson numerator, of size $X^{1/3}$ up to small powers. With $h,h',d_3,d_4$ fixed, the phase has two simple poles in $d_1$. Weil's bound and completion cost $O_\varepsilon(X^\varepsilon(1+D_+/j_0)\sqrt{j_0})$. The determinants, second pair and numerator cost $X$, and the four coefficients supply $X^{-8/3}$, up to small powers. Thus $X^{1+1/6-8/3}$ saves a power over $c^2\asymp X^{-4/3}$. The same bound for one $v$ derivative lets us set $v=p/X$. Markov gives $O(cX^{-\xi})$ outside $O(X^{1-\xi})$ primes for some $\xi>0$. \emph{Recovering the profile.} The truncated diagonal is $O_g(c\log^3 X)$. In the short range the omitted angular region costs $O_g(cX^{-\omega}\log^3 X+c^{3/2})$ and the diagonal above $D_+$ costs $O_{g,\varepsilon}(X^\varepsilon\sqrt c/D_+)$. Above the endpoint, the coefficient error in Lemma~S5.2 is $O_g(B^{-1}\log^4 B)$ in squared diagonal norm, so $Bc$ gives a power margin. Use Cauchy--Schwarz for overlaps and approximation errors, then remove the first sine using its mass estimate. At $a=1/6$, S5.4 restores the full heat norm using the dual remainder and the coefficient comparison below $D_+$. For $m+1\le\sqrt U\log X$, the moment multiplier $\kappa_m(T)$ differs relatively from $e^{-(m+1)^2/U}$ by $O(U^{-1/2}\log^3 X)$, including the effect of $T=\lfloor U\rfloor$. The remaining degrees are negligible by Gaussian decay and $|m_{g_B,p}(m)|+|m_{g,p}(m)|\ll_{g,\varepsilon}X^\varepsilon(m+1)$. Thus Proposition~\ref{prop:angles} gives the centered count norm. Above the endpoint, projection and \eqref{eq:averaged-class-tail} replace $g_B$ by $g$ with a power saving. The same tail bound controls the change in mass at all lengths, including the endpoint, and the constant coefficient changes by $O_g(B^{-1/2})$. \end{proof} \subsection{From the Fourier profile to sharp trace sums}\label{sec:trace-pairing} By the Chinese remainder theorem a trace weight is a finite sum of products with local factors $w_{\ell,A}=a_\ell L_{\ell,A}+b_\ell$ at finitely many primes and $L_{\ell,A}$ elsewhere. Here $a_\ell,b_\ell$ are real and periodic modulo $\ell^{v_\ell}$ with $v_\ell\ge1$ at every modified prime. Conversely, expanding a product gives a combination of $F^{(J)}1_{\mathcal A}$: a term without $L_{\ell,A}$ omits that prime from the class-number series. Define the local pairing by \begin{equation}\label{eq:local-pairing} \mathcal B_{\ell,A}(w,z)=(1-\ell^{-2})\left( \frac{\ell}{\ell+1}\widehat w(0)\overline{\widehat z(0)} +\sum_{j\ge1}\ell^j\sum_{b\bmod\ell^j}^{*} \widehat w(b/\ell^j)\overline{\widehat z(b/\ell^j)} \right). \end{equation} It is real for real weights. Equation~\eqref{eq:local-short-mean} gives $\mathcal B_{\ell,A}(L_{\ell,A},L_{\ell,A})=1$. For products take the product of the local pairings over $\ell\mid M$, and extend bilinearly to sums. This defines $\mathcal B_r(g,h)$ for $A\equiv r\bmod M$, since the local computation below uses only the residue of $A$ modulo the common period. \paragraph{Computing the local pairing.} Fix $\ell$ and write $q=\ell^v$, $v\ge1$, for the common period. For $j\le v$ the coefficients are obtained from the class means of $L_{\ell,A}$. The mean on $R\bmod q$ is \[ \frac1{1+\ell^{-1}}\left(\sum_{i=0}^{v-1} \frac{\rho_i(R)}{\ell^i}+\frac{\rho_v(R)}{q(1-\ell^{-1})}\right), \] where $\rho_i(R)$ counts roots modulo $\ell^i$. Each lift of a root above level $v$ determines one lift of the trace, giving this mean. For $j>v$, put $f(u)=u+A/u$. The root series gives \[ \widehat w(b/\ell^j)=\frac{\ell^{-2j}}{1-\ell^{-2}} \sum_{u\bmod\ell^j}^{*}a_\ell(f(u))e(-bf(u)/\ell^j) \qquad(\ell\nmid b). \] Indeed only the terms of the root series at levels $j$ and above contribute. For $j\ge2v$, split $u$ modulo $\ell^{\lceil j/2\rceil}$ and sum the lifts. The multiplier is constant on the lifts and the phase forces $u^2\equiv A\bmod\ell^{\lfloor j/2\rfloor}$. There are at most four unit roots at this modulus, including at $2$. Thus the coefficient is $O_{w,\ell}(\ell^{-3j/2})$. For $z=a'_\ell L_{\ell,A}+b'_\ell$, let $N_j$ be the collision sum over unit pairs with $f(u)\equiv f(u')\pmod{\ell^j}$, with weight $a_\ell(f(u))a'_\ell(f(u'))$. Additive orthogonality on primitive numerators gives the part above level $v$ of the frequency sum inside \eqref{eq:local-pairing} as \begin{equation}\label{eq:local-pair-tail} \frac{(1-\ell^{-1})\displaystyle\sum_{j>v}N_j/\ell^{2j} -N_v/(\ell q^2)}{(1-\ell^{-2})^2}. \end{equation} The sum over $j$ integrates $v_\ell(f(u)-f(u'))-v$ over the matching classes modulo $q$, with their weights and Haar measure on $\mathbf Z_\ell^2$. Since $f(u)-f(u')=(u-u')(uu'-A)/(uu')$, the involution $u'\mapsto A/u'$ makes the two valuations have the same integral, preserving the classes of the traces and their weights. The sum is thus $q^{-2}$ times the finite sum over matching unit pairs modulo $q$ of their weight times \begin{equation}\label{eq:local-pair-count} 2\min\{v,v_\ell(u-u')\}-v+\frac{2\,1_{u=u'\,(\bmod q)}}{\ell-1}. \end{equation} On a diagonal pair of residue classes the extra valuation has mean $1/(\ell-1)$. All these calculations use only $A\bmod q$. \begin{proof}[Proof of Theorem~\ref{thm:prime-density}] \emph{Averaging over residue systems.} The short-length constant comes from the Fourier mass near zero. For two product weights, replace the squared coefficient in the proof of Theorem~\ref{thm:short-constant} by the product of the two coefficients, conjugating the second. The positive and negative frequencies combine to give a real profile. Include all modified primes among the primes $\ell\le L$ held fixed. At a modified prime the term with denominator exponent zero is $(\ell/(\ell+1))\widehat w(0)\overline{\widehat z(0)}$, by summing the powers of $\ell$ in the numerator. At exponent $j\ge1$ the average over unit numerators gives the corresponding summand of \eqref{eq:local-pairing}. The Euler product becomes $\zeta(2)\mathcal B_r(g,h)$ on the class $A\equiv r\bmod M$. The uniform bounds of the local coefficients preserve the conditional mean error $O_{g,h,M}(x^{1/32})$. In the fourth moment the finitely many modified factors are uniformly bounded in their exponents, so the vanishing condition and divisor counts at the other primes give the same $O_{g,h,M}(L^{-2})$ estimate, also conditional on the designated class. The resulting $Z_x$ differs from $\zeta(2)\mathcal B_r(g,h)$ in conditional $L^2$ by $O_{g,h,M}((\log(1/x))^{-1/2})$ for $0Q$ for sufficiently large $X$, each character in the expansion can be replaced on primes by the primitive character inducing it. For primitive characters of conductor $f$, the norm of the combined coefficient vector is at most \[ \ll_{g,h,M}\sum_{\substack{b\le Q\\f\mid b}}\frac{\tau(b)^6}{b} \ll_{g,h,M}\frac{\tau(f)^6}{f}(\log X)^C \] for an absolute $C$. The same estimate holds after $c\partial_c$. The principal character gives the exact Haar mean of the class-weighted square. For conductors $f$ in a dyadic block $R\le f<2R$, the squared coefficient norm is $O_{g,h,M}(R^{-1}(\log X)^{C'})$ by the usual mean bound for divisor powers. The multiplicative large sieve \cite[\S7.5]{IK} applied to the prime indicator on any subinterval of $(X,2X]$, followed by Cauchy--Schwarz, bounds the contribution by $O_{g,h,M}((\log X)^{C''}(X/\sqrt R+\sqrt{XR}))$. For $f\le(\log X)^{A}$, Siegel--Walfisz \cite[Corollary~5.29]{IK} gives arbitrary logarithmic savings for the nonprincipal characters. Take $A$ sufficiently large and sum the dyadic blocks. With $Q\ll_M X^{5/6}$, the total is $O_{g,h,M,J}(X/(\log X)^J)$ for any $J$. This estimate also allows the variation of $c(p)$. Apply the fixed-parameter bound first at $c(X)$ and then, for each $X\le y\le2X$, to the derivative on $(y,2X]$, and integrate with $|c'(y)|/c(y)$. Its integral is bounded. Dividing by the prime count in the specified class, \eqref{eq:short-haar-mean-square} gives a mean squared error $O_{g,h,M,\delta,\lambda}(1/\log X)$. Apply Lemma~\ref{lem:short-profile} to $g,h,g+h$ and polarize, choosing $\delta<\delta_0<1/2$ in its first range. On the retained primes the left side of \eqref{eq:mixed-short} differs from the normalized profile at $c(p)$ by $O((\log X)^{-2})$, including the floor in $T$ by \eqref{eq:denominator-bound}. Chebyshev's inequality and the exceptional sets of the lemma give the count for $\eta>(\log X)^{-1/2}$. For smaller $\eta$ the count is trivial. \emph{A common prime set.} It suffices to control diagonal norms for the given weights and all their pairwise sums. Enumerate the positive rational multipliers and let $B_j$ be the bad set for the first $j$ multipliers at tolerance $1/j$. These sets increase and have relative density zero. Choose increasing $X_j$ so that $B_j$ has proportion at most $1/j$ up to every $X\ge X_j$ in the class, and remove $B_j\cap[X_j,X_{j+1})$. All removals up to $X$ in the $j$th interval lie in $B_j$. The remaining set has relative density one. The diagonal squared norm increases with $T$ by contraction under thinning, including for signed weights. Bracketing by rational multipliers and then polarizing gives \eqref{eq:mixed-short} for every $\lambda>0$ on this set. \emph{The sharp cutoff.} For a weight $g$, consider the positive measure \[ \nu_p=\frac p{K^2}\sum_{j\ge1}m_{g,p}(j)^2\delta_{j^2/K^2}. \] Here $\delta_x$ is unit mass at $x$. By Proposition~\ref{prop:angles}, the sum against $\kappa_j(T)$ is $(p/K^2)\|P^g-Z_gQ_T\|_Q^2$, which tends to $\lambda\mathcal B_r(g,g)/48$. For the Sato--Tate parameters the product gives, for $j=O(K)$, $\log\kappa_j(T)=-j(j+2)/T+O((j+1)^3/T^2)$. Thus at $u=j^2/K^2$ the weights converge uniformly on compact intervals to $e^{-u/\lambda}$. There they are bounded below, so the masses are bounded. For $j\le T$ and $T\le s\le2T$ each term of the logarithmic derivative of $\kappa_j(s)$ is $(2r+3)/((s-r)(s+r+3))\ge(2r+3)/(12T^2)$, where $0\le rT$, and $2T\le\lfloor2\lambda K^2\rfloor$. Hence the sum at $2\lambda$ bounds the weighted tail $u>R$ by $O(e^{-R/(12\lambda)})$. Test along a vaguely convergent subsequence with continuous cutoffs on compact intervals, then let $R$ tend to infinity using the tail bound. Each limit measure has Laplace transform $\lambda\mathcal B_r(g,g)/48$. Multiplying by $e^{-u}$ and mapping $u$ to $z=e^{-u}$, the choices $\lambda=1/(n+1)$ give the moments of $(\mathcal B_r(g,g)/48)\,dz$ on $[0,1]$. Polynomials determine this measure. Hence $\nu_p$ converges on compact intervals to $(\mathcal B_r(g,g)/48)\,du$. This measure has no atom at $1$, so the cutoff $(K-2)^2/K^2\to1$ gives the diagonal limit. Polarization proves \eqref{eq:mixed-sharp}. \end{proof} \subsection{The log loss at short lengths}\label{sec:kl-short} To recover the log loss from the chi-square divergence, we use a quadratic expansion on counts where the likelihood ratio is close to one and bound the remaining counts separately. \begin{proposition}\label{prop:kl-half} Fix $0<\eta<1/2$ and $L>0$. Uniformly for $Lp^{1/3}\le T\le p^{1-\eta}$, as $p\to\infty$, \[ \KL(P_T\Vert Q_T)=\bigl(\tfrac12+o(1)\bigr)\chi^2(P_T\Vert Q_T) +o(T/p). \] \end{proposition} \begin{corollary}\label{cor:kl-density} On the set $\mathcal P_\delta$ of Theorem~\ref{thm:prime-density}, for every fixed $\lambda>0$ and $T=\lfloor\lambda p^{1-\delta}\rfloor$, \[ \frac pT\KL(P_T\Vert Q_T)\longrightarrow\frac1{96}. \] \end{corollary} \begin{proof}[Proof of Proposition~\ref{prop:kl-half}] Put $u_k=P_T(k)/Q_T(k)$ and $\Psi(u)=u\log u-u+1$, so that $\KL(P_T\Vert Q_T)=\sum_kQ_T(k)\Psi(u_k)$. One has $0\le\Psi(u)\le(u-1)^2$, and $\Psi(u)=\frac12(u-1)^2(1+O(|u-1|))$ for $|u-1|\le1/2$. For $T\le p^{9/20}$ every count admits a one-sided interval of length $\ell=p^{-1/2+\varepsilon}$ from $x=k/T$ toward the farther endpoint $y$. On that interval $f=(1-u)x+uy$ with $u\le2\ell$, so $D(x\Vert f)\le-\log(1-u)\ll\ell$ for Bernoulli laws. The binomial likelihood is at least $m\exp(-CT\ell)$ there, where $m$ is its maximum. Integrate the masses of its superlevel intervals as below. For heights above $m\exp(-CT\ell)$ use the mass at that height as an upper bound. The short-interval theorem then gives $u_k=1+O_J((\log p)^{-J}+T\ell)$ uniformly in $k$. Take $\varepsilon<1/20$ and use the expansion of $\Psi$ to finish this case. For $T>p^{9/20}$ put $c=T/p$, choose $\varepsilon>0$ small in terms of $\eta$, and put $\vartheta=p^{3\varepsilon}c+p^{-1/2+2\varepsilon}$. Call $k$ a bulk count when $\hat k(1-\hat k)\ge\vartheta$ for $\hat k=k/T$, and an edge count otherwise. For a bulk count the function $f\mapsto b_{T,f}(k)$ is unimodal with maximum $m$ at $\hat k$. Its superlevel sets $I_s$ are intervals, and $P_T(k)$ and $Q_T(k)$ are the integrals over $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 $X0$, 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$. Because $W$ has mass one on a single class, every coefficient of denominator at most $q$ has modulus one. Those terms, including the constant term, contribute $q\varphi(q)$ after multiplication by $1-\ell^{-2}$. For the higher terms the unit pairs in \eqref{eq:local-pair-count} range over $\mathcal R_\ell^2$. Their sum is $2S_\ell-vh^2+2h/(\ell-1)$, and $N_v=h^2/B_\ell^2$. Formula~\eqref{eq:local-pair-tail} gives the correction in \eqref{eq:class-local-constant}. The product of the local pairings gives the normalized chi-square limit by Theorem~\ref{thm:prime-density}, and Proposition~\ref{prop:kl-level} gives the KL limit. \end{proof} \subsection{Traces on \texorpdfstring{$\Gamma_0(N)$}{Gamma0(N)}}\label{sec:gamma0} The local pairing also gives the full and new trace moments at arbitrary fixed levels. For $p\nmid N$ and even $k\ge4$, let $\tau^0_{N,k}(p)$ and $\tau^{\rm new}_{N,k}(p)$ be the full and new $T_p$ traces at level $N$, multiplied by $p^{-(k-1)/2}$. For a prime $\ell$, write $F_e(\ell,r)$ and $B_{ef}(\ell,r)$ for the full diagonal and new mixed factors computed in \hyperref[sec:prime-square]{S6}. Let $G_N$ be the full trace weight defined there and $P_T^N=P^{G_N}/Z_{G_N}$. \begin{theorem}[Mixed Hecke traces at fixed levels]\label{thm:gamma0} Fix $1/6\le a<1/2$ and a finite list of levels with least common multiple $M$. In every unit class $r\bmod M$ there is a common relative-density-one prime set on which, with $K=p^a$, \begin{align*} \frac{48}{K^2}\sum_{\substack{4\le k\le K\\ k\ {\rm even}}} |\tau^0_{N,k}(p)|^2 &\longrightarrow \prod_{\ell\mid M}F_{v_\ell(N)}(\ell,r),\\ \frac{48}{K^2}\sum_{\substack{4\le k\le K\\ k\ {\rm even}}} \tau^{\rm new}_{D,k}(p)\overline{\tau^{\rm new}_{E,k}(p)} &\longrightarrow \prod_{\ell\mid M} B_{v_\ell(D),v_\ell(E)}(\ell,r) \end{align*} for levels $N,D,E$ in the list. At odd primes only the Legendre symbols matter. At $2$ at most the residue of $p\bmod8$ is needed. For each fixed $\lambda>0$ and $T=\lfloor\lambda K^2\rfloor$, $p\,\KL(P_T^N\Vert Q_T)/T$ tends to the full product divided by $96$. \end{theorem} \begin{proof} Section~\hyperref[sec:prime-square]{S6} uses the lifted-root trace formula to express $G_N$ and the new weight as products of local factors $aL_{\ell,p}+b$ with fixed periods dividing $M$. The errors in the normalized traces have total square $O_M(p^{-3})$ and can be removed by Cauchy--Schwarz. Equation~\eqref{eq:mixed-sharp} with $\delta=1-2a$ gives both products, throughout $1/6\le a<1/2$. The full weight is nonnegative with limiting mass one, so Proposition~\ref{prop:kl-level} gives the log loss. \end{proof} Section~\hyperref[sec:prime-square]{S6} classifies the vanishing local factors in the mixed product. For squarefree levels the products are $1_{D=E}\varphi(D)$ for the newspaces and $\prod_{\ell\mid N}(\ell+3)$ for the full space in every class. The new diagonal then agrees with the leading total dimension over even weights~\cite[Theorem~1]{MartinDimensions}. \begin{corollary}\label{cor:exceptional-level} For each fixed $\lambda>0$, Corollary~\ref{cor:exceptional} applies to the laws and limits in Corollary~\ref{thm:level-density-one} and Theorem~\ref{thm:classes-short} within each fixed prime class. The implied constant may also depend on $\ell$ or $M$. \end{corollary} \begin{proof} Apply Theorem~\ref{thm:prime-density} and normalize using the mass bound of Lemma~\ref{lem:short-profile}. The lemma gives $p\chi^2/T\ll\log^3 p$, so Proposition~\ref{prop:kl-level} with $J=4$ gives the KL rate, including the removed primes as in Corollary~\ref{cor:exceptional}. \end{proof} \begin{corollary}[Prime-square level]\label{thm:gamma-square} In the units of Theorem~\ref{thm:gamma0}, the full and new second moments at level $\ell^2$ have constants \[ \ell+3+s(\ell+1)^2,\qquad \ell+s(\ell^2-2\ell-1), \qquad s=\#\{u\bmod\ell:u^2\equiv p\bmod\ell\}. \] For odd $\ell$, $s=2$ in the square class and $s=0$ in the nonsquare class. At level $4$ the constants are $14$ and $1$ for all odd primes in the set of the theorem. \end{corollary} \section{Estimates from the Dirichlet critical-line theorem} \label{sec:grh} The trace asymptotics and leading variance use unconditional estimates. The quadratic case of Alp\"oge's Dirichlet critical-line theorem \cite{AlpogeAnnouncement,SutherlandVerification} improves the Mellin truncation bound for quadratic characters of conductor at most $4p$. For $1\le T\le X$ put \[ R^{*}_\varepsilon(T,X)=\frac TX\log^3(2X/T) +X^{-1/2+\varepsilon}\max(T,\sqrt X)^{1/4}. \] \begin{proposition}\label{prop:grh} Let $p\ge5$ be prime. \begin{enumerate} \item Theorem~\ref{thm:elliptic}, Propositions~\ref{prop:classes} and~\ref{prop:y-one}, and Corollaries~\ref{cor:hecke-traces} and~\ref{cor:legendre} hold with $R^{*}_\varepsilon$ in place of $R_\varepsilon$. \item For $2\le K\le\sqrt p$ the two sums in \eqref{eq:hecke-square} are $O_{\ell,\varepsilon}(K^2\log^3(2p/K^2) +p^{1/2+\varepsilon}\max(K,p^{1/4})^{1/2})$. For $K=p^a$ this saves a power of $p$ over Deligne's bound, Petrow's bound and the angular large sieve when $5/241/3$. \end{enumerate} \end{proposition} \begin{proof} Alp\"oge's theorem and \cite[Corollary~5.20]{IK} give $L(1/2+iv,\chi)\ll_\varepsilon(p(1+|v|))^\varepsilon$. The Mellin shift of Theorem~\ref{thm:elliptic} gives squared error $p^\varepsilon/B$, also with bounded omitted factors. Balance it with $p^\varepsilon B\sqrt T/p$ from Lemma~\ref{lem:smoothing} at $B=p^{1/2}T^{-1/4}$ and thin from $T_0$. Corollary~\ref{cor:hecke-traces} gives the trace remainder. It saves a power over $K^3$ for $a>5/24$, over Petrow's bound in its range, and over $K^2$ for $a>1/3$. \end{proof} Corollary~\hyperref[prop:prime-mean-second]{S9.2} uses the full Dirichlet theorem to average the nonprincipal character terms over primes. It gives second terms for the sharp trace mean at $0<\delta<1/6$ and the count mean at $0<\delta<1/5$. \section{Open questions} Do the short-length limits hold for every prime sequence, and does $\mathcal C_A(c)/c\to1/48$ as $c\downarrow0$ for every fixed $A$? How far can the trace asymptotic, variance and mean formulas extend? \paragraph{AI Declaration.}\hypertarget{ai-declaration}{} OpenAI Codex and Anthropic Claude assisted with parts of the mathematical argument, including the derivation and checking of estimates in S5.4 and S8--S9. They also assisted with numerical checks and with drafting and revising the text. The author is responsible for the proofs and results. \input{supplement} \input{references} \end{document}