\pdfoutput=1 \documentclass[12pt]{amsart} \usepackage{amsmath,amssymb,amsthm} \usepackage[a4paper,margin=1.15in]{geometry} \usepackage{xcolor} \usepackage{enumitem} \usepackage{booktabs} \usepackage{tikz} \usetikzlibrary{arrows.meta,positioning} \usepackage[T1]{fontenc} \usepackage{lmodern} \usepackage{microtype} \usepackage[colorlinks=true,linkcolor=blue!50!black,citecolor=green!35!black,urlcolor=blue!50!black]{hyperref} \numberwithin{equation}{section} \newtheorem{theorem}{Theorem}[section] \newtheorem{proposition}[theorem]{Proposition} \newtheorem{lemma}[theorem]{Lemma} \newtheorem{corollary}[theorem]{Corollary} \newtheorem{heuristic}{Heuristic} \newtheorem*{hypothesis}{Hypothesis} \theoremstyle{definition} \newtheorem{definition}[theorem]{Definition} \newtheorem{comparison}{Comparison} \theoremstyle{remark} \newtheorem{remark}[theorem]{Remark} \newcommand{\ZZ}{\mathbb{Z}} \newcommand{\QQ}{\mathbb{Q}} \newcommand{\RR}{\mathbb{R}} \newcommand{\NN}{\mathbb{N}} \newcommand{\FF}{\mathbb{F}} \newcommand{\CC}{\mathbb{C}} \newcommand{\PP}{\mathbb{P}} % vectors of length 3 \newcommand{\va}{{\vec a}} \newcommand{\vb}{{\vec b}} \newcommand{\vc}{{\vec c}} \newcommand{\vn}{{\vec n}} \newcommand{\vr}{{\vec r}} \newcommand{\vs}{{\vec s}} \newcommand{\vt}{{\vec t}} \newcommand{\vG}{{\vec G}} \newcommand{\vw}{{\vec w}} \newcommand{\vx}{{\vec x}} \newcommand{\vy}{{\vec y}} \newcommand{\vv}{{\vec v}} \newcommand{\vz}{{\vec z}} \newcommand{\vk}{{\vec k}} \newcommand{\vF}{{\vec F}} \newcommand{\vnu}{{\vec\nu}} \newcommand{\vrho}{{\vec\rho}} \newcommand{\vxi}{{\vec\xi}} \newcommand{\veta}{{\vec\eta}} \newcommand{\vtheta}{{\vec\theta}} \newcommand{\vbeta}{{\vec\beta}} \newcommand{\vgamma}{{\vec\gamma}} \newcommand{\vzero}{{\vec 0}} % vectors of length s \newcommand{\bx}{\mathbf{x}} \newcommand{\by}{\mathbf{y}} \newcommand{\bz}{\mathbf{z}} \newcommand{\bu}{\mathbf{u}} \newcommand{\bv}{\mathbf{v}} \newcommand{\bh}{\mathbf{h}} \newcommand{\bb}{\mathbf{b}} \newcommand{\bw}{\mathbf{w}} \newcommand{\bzero}{\mathbf{0}} \newcommand{\ee}{\mathrm{e}} \newcommand{\one}{\mathbf{1}} \newcommand{\Lp}{\Lambda^{\!\perp}} \newcommand{\cM}{\mathcal{M}} \newcommand{\cA}{\mathcal{A}} \newcommand{\cK}{\mathcal{K}} \newcommand{\cN}{\mathcal{N}} \newcommand{\cO}{\mathcal{O}} \newcommand{\be}{\mathbf{e}} \newcommand{\vlambda}{{\vec\lambda}} \newcommand{\cC}{\mathcal{C}} \newcommand{\cZ}{\mathcal{Z}} \newcommand{\cU}{\mathcal{U}} \newcommand{\fS}{\mathfrak{S}} \newcommand{\fJ}{\mathfrak{J}} \newcommand{\fM}{\mathfrak{M}} \newcommand{\sumstar}{\sideset{}{^*}\sum} \newcommand{\corank}{\operatorname{corank}} % --- revision marking: \redversiontrue shows changes in red, \redversionfalse gives the clean version \newif\ifredversion \redversionfalse \newcommand{\rev}[1]{\ifredversion{\color{red}#1}\else#1\fi} \newenvironment{revblock}{\ifredversion\color{red}\fi}{} \newcommand{\orev}[1]{#1} \newenvironment{orevblock}{}{} \setlength{\emergencystretch}{2em} \begin{document} \title[Three-dimensional delta symbol method]{A three-dimensional delta symbol method and its application to intersections of three quadratic forms} \author{Esrafil Ali Molla} \address{Department of Mathematics, Indian Institute of Technology Bombay, Mumbai 400076, India} \email{esrafil.math@gmail.com} \date{} \subjclass[2020]{11D45 (11D72, 11P55, 11G35, 14G05)} \keywords{circle method, delta symbol, Kloosterman refinement, systems of quadratic forms, intersections of quadrics, Hasse principle} \begin{abstract} \orev{Using a new three-dimensional delta symbol with a Kloosterman refinement, we prove the asymptotic formula for the number of integral points of bounded height on a non-singular intersection of three quadrics in at least $22$ variables, improving on the $27$ variables required by Birch and by Rydin Myerson.} \end{abstract} \maketitle \setcounter{tocdepth}{1} {\hypersetup{linkcolor=teal}\color{teal}\tableofcontents} %====================================================================== \section{Introduction}\label{sec:overview} %====================================================================== In 1962 Birch~\cite{Bir}, following Davenport, used the Hardy--Littlewood circle method to obtain an asymptotic formula for the number of integral points of bounded height on a variety defined by a system of forms of the same degree, provided that the number of variables is large in terms of the degree and the number of forms. For a single form this result has been improved in a number of important cases. For quadratic forms the decisive idea goes back to Kloosterman~\cite{Klo}, who showed how to average the complete exponential sums over the numerators $a$ of the fractions $a/q$ around which the arcs are placed. For cubic forms Heath-Brown~\cite{HB07} reduced the number of variables required from $16$ to $14$. The delta symbol method of Duke, Friedlander and Iwaniec~\cite{DFI}, in the form developed by Heath-Brown~\cite{HB}, gives a convenient way of carrying out such averages over $a$, the Kloosterman refinement, and also over $q$, the double Kloosterman refinement. For systems of forms the situation is much less satisfactory. A Kloosterman refinement needs a dissection of the unit square, or of the unit cube, with the arithmetic features of the Farey dissection of the unit interval, and for a long time nothing of the kind was available. For pairs of quadratic forms, Browning and Munshi~\cite{BM} \orev{studied intersections of two quadrics in $9$ or more variables whose singular locus is a pair of conjugate points defined over $\QQ(i)$, such as those given by $Q_1(\bx)-x_{n+1}^2-x_{n+2}^2$ and $Q_2(\bx)$}, by trading the first equation for a family of congruences. Munshi~\cite{Mun} then applied the one-dimensional delta symbol twice, in a nested manner, and obtained the asymptotic formula for an arbitrary non-singular pair in $11$ or more variables. More recently Li, Rydin Myerson and Vishe~\cite{LRV} constructed a genuinely two-dimensional delta symbol. Its moduli are as small as Dirichlet's theorem in $\RR^2$ allows, and its weights depend on the numerator only through a lattice. This gives the asymptotic formula for non-singular pairs \orev{for even $s\geqslant10$ and odd $s\geqslant11$, and for $s=9$ under the generalised Lindel\"of hypothesis, by a double Kloosterman refinement~\cite[Theorem~1.1]{LRV}}. For systems of $R$ quadratic forms the best general result is due to Rydin Myerson~\cite{RM}, who obtained the asymptotic formula for non-singular systems in at least $9R$ variables. On the qualitative side, the Hasse principle for smooth intersections of two quadrics is known in $9$ variables by the work of Colliot-Th\'el\`ene, Sansuc and Swinnerton-Dyer~\cite{CSS}, and Heath-Brown~\cite{HB18} has reduced this to $8$ variables. In this paper we are concerned with intersections of three quadrics. Let $F_1,F_2,F_3\in\ZZ[x_1,\dots,x_s]$ be quadratic forms, write $\vF=(F_1,F_2,F_3)$, and for $\vbeta\in\CC^3$ let $F_\vbeta=\vbeta\cdot\vF$, let $M_\vbeta$ be the symmetric matrix of $F_\vbeta$, and let $\Delta(\vbeta)=\det M_\vbeta$. We shall always suppose that the variety $V\subset\PP^{s-1}$ defined by $F_1=F_2=F_3=0$ is a non-singular complete intersection of codimension $3$. This has a simple consequence for the net of quadrics $\{F_\vbeta\}$. Suppose that $M_\vbeta$ had corank at least $3$ for some $\vbeta\neq\vzero$. Choose $\vbeta',\vbeta''$ completing $\vbeta$ to a basis of $\CC^3$. Then $F_{\vbeta'}$ and $F_{\vbeta''}$ would have a common non-trivial zero $\bx$ on $\ker M_\vbeta$, and since also $F_\vbeta(\bx)=0$, the point $[\bx]$ would lie on $V$. But the rows $M_1\bx,M_2\bx,M_3\bx$ of the Jacobian matrix at $\bx$ satisfy $\sum_i\beta_iM_i\bx=\bzero$, contradicting the non-singularity of $V$. Thus every member of the net has corank at most $2$. The singular locus in the sense of Birch, namely the set of $\bx\in\CC^s$ with $\operatorname{rank}(M_1\bx,M_2\bx,M_3\bx)\leqslant2$, is the union of the kernels $\ker M_\vbeta$. The members of corank $1$ form a curve, and those of corank $2$ are finite in number (Lemma~\ref{lem:geometry}). So the Birch singular locus has dimension $B\leqslant2$, and Birch's theorem, in the form~\cite[(1.2)]{BHB}, gives the asymptotic formula when $s>B+(d-1)2^{d-1}R(R+1)=B+24$, that is, for $s\geqslant27$. Rydin Myerson's theorem gives the same range. Our main result goes beyond this. \begin{theorem}\label{thm:mainA} Let $F_1,F_2,F_3$ be quadratic forms with integral coefficients in $s$ variables, such that the projective variety $F_1=F_2=F_3=0$ is non-singular of codimension $3$. Let $\bz_0\in\RR^s\setminus\{\bzero\}$ be a real zero of $F_1,F_2,F_3$, and let $w\in C_c^\infty(\RR^s)$ be supported in a sufficiently small neighbourhood of $\bz_0$. If $s\geqslant22$, then there is $\Delta=\Delta(s)>0$ such that \begin{equation}\label{eq:mainasymp} \sum_{\substack{\bx\in\ZZ^s\\ F_1(\bx)=F_2(\bx)=F_3(\bx)=0}}w\Bigl(\frac{\bx}{P}\Bigr)=\fS\,\fJ\,P^{s-6}+O(P^{s-6-\Delta}). \end{equation} Here the singular series $\fS$, defined in~\eqref{eq:singseries}, depends on $F_1,F_2,F_3$, and the singular integral $\fJ$, defined in~\eqref{eq:singint}, depends on $F_1,F_2,F_3$ and $w$. The implied constant depends on $F_1,F_2,F_3$ and $w$. \end{theorem} The proof for $s\geqslant23$ is given in Section~\ref{sec:kloosterman} (Theorem~\ref{thm:23}), and the case $s=22$, which needs one more ingredient, in Section~\ref{sec:s22} (Theorem~\ref{thm:22}). The theorem uses no unproved hypothesis. \orev{The proof gives every $\Delta<\frac1{88}$ for $s=22$, every $\Delta<\frac14$ for $s=23$ and every $\Delta<\frac12$ for $s=24$, and Theorem~\ref{thm:main} gives every $\Delta<(s-24)/4$ for $s\geqslant25$.} The product $\fS\fJ$ is positive when $V$ has points over every completion of $\QQ$ and $w(\bz_0)>0$ (Lemma~\ref{lem:SJ}), so Theorem~\ref{thm:mainA} gives an analytic proof of the Hasse principle for these varieties in the same range. \orev{In fact the conditions at the primes are automatic here: by the work of Birch and Lewis~\cite{BL} and Schuur~\cite{Schu}, three quadratic forms over $\QQ_p$ in at least $13$ variables have a non-trivial common zero (see also~\cite{HB10} for systems of $r$ quadratic forms over $p$-adic fields). Since $V$ is non-singular, such a zero is a point of $V(\QQ_p)$, and Lemma~\ref{lem:SJ} gives $\fS>0$ for every $s\geqslant22$. So the main term in~\eqref{eq:mainasymp} is positive as soon as $w\geqslant0$ and $w(\bz_0)>0$, and in particular $V(\QQ)\neq\varnothing$ whenever $V(\RR)\neq\varnothing$.} (Weak approximation would follow from a version of Theorem~\ref{thm:mainA} with congruence conditions on $\bx$; this requires only routine changes to the local computations, but we have not carried them out.) We do not claim novelty for this consequence. Heath-Brown~\cite{HB3} has proved the Hasse principle and weak approximation for non-singular intersections of three quadrics in at least $19$ variables, over any number field. He finds a suitable linear space on one of the quadrics and applies his result for pairs of quadrics; his method gives no asymptotic formula. The asymptotic formula~\eqref{eq:mainasymp} is new for $22\leqslant s\leqslant26$. The closest work to ours is that of Pierce, Schindler and Wood~\cite{PSW}, who studied the representations of a triple $\vn=(n_1,n_2,n_3)\in\ZZ^3$ by a system of three quadratic forms, that is, the inhomogeneous equations $\vF(\bx)=\vn$. They developed a three-dimensional form of Kloosterman's method, based on overlapping Dirichlet boxes in $\RR^3$, and proved that the expected asymptotic formula holds for almost every triple $\vn$ in at least $10$ variables, provided the discriminant curve $\det(xM_1+yM_2+zM_3)=0$ is smooth. Their argument averages over $\vn$: a mean square over $\vn$ turns the underlying exponential sum into an absolute square, as explained in~\cite[\S1.2]{LRV}, and this is what allows so few variables. For an individual triple, and in particular for the homogeneous problem $\vn=\vzero$ considered in Theorem~\ref{thm:mainA}, no such average is available, and the benchmark remains Birch's theorem with $27$ variables. Our unrefined method needs no average over $\vn$, because all its bounds for the error terms use only the absolute values of the exponential sums and integrals, and these do not change when $\vF(\bx)$ is replaced by $\vF(\bx)-\vn$. \begin{orevblock}Consequently the proof of Theorem~\ref{thm:main} gives, for $s\geqslant25$, $C\geqslant1$ and every $\Delta<(s-24)/4$, \[ \sum_{\substack{\bx\in\ZZ^s\\ \vF(\bx)=\vn}}w\Bigl(\frac{\bx}P\Bigr)=\fS(\vn)\,\sigma_w\Bigl(\frac{\vn}{P^2}\Bigr)P^{s-6}+O\bigl(P^{s-6-\Delta}\bigr), \] uniformly for all $\vn\in\ZZ^3$ with $|\vn|\leqslant CP^2$. Here \[ \fS(\vn)=\sum_qq^{-s}\sumstar_{\va\bmod q}\ee_q(-\va\cdot\vn)S_q(\va,\bzero) \] is the singular series of the inhomogeneous problem, with $S_q$ as in~\eqref{eq:Sdef}, which converges absolutely and uniformly in $\vn$, and $\sigma_w$ is the density of the push-forward of $w(\bx)\,d\bx$ under $\vF$ (\S\ref{sec:integrals}). The only changes in the proof are the choice of $Q$ in~\S\ref{sec:reduction}, with $M_UP^2$ replaced by $M_UP^2+|\vn|$, so that still $Q^{4/3}\asymp P^2$ and $|\vF(\bx)-\vn|\leqslant\frac14Q^{4/3}$ on the support of $w(\bx/P)$; the factor $\ee_q(-\va\cdot\vn)\ee(-\vw\cdot\vn)$, of modulus one, in the Poisson summation formula; and the main term, which is obtained from Proposition~\ref{prop:mainprop} applied to the shifted test functions $\vx\mapsto\sigma_w(\vn/P^2+Q^{4/3}P^{-2}\vx)$, whose Schwartz seminorms are bounded uniformly in $\vn$. We leave the details to the reader. This result for \emph{every} triple $\vn$ needs more variables than~\cite{PSW}, but it has no exceptional set and needs no condition on the discriminant curve.\end{orevblock} \begin{orevblock} We mention some other related work. For pairs of quadratic forms the representation problem was studied by Heath-Brown and Pierce~\cite{HBP}, who showed that a pair of integral quadratic forms in $5$ or more variables simultaneously represents almost all pairs of integers that are not excluded by local conditions, under suitable non-singularity assumptions; there too the average over the pair of integers is essential, and their proof introduced a two-dimensional version of the Kloosterman refinement for this averaged problem. The work of Pierce, Schindler and Wood~\cite{PSW} extends this approach to three forms. For the homogeneous problem, the general theory of systems of quadratic forms goes back to Schmidt~\cite{Sch82}, who found non-trivial integral zeros of systems of rational quadratic forms under conditions on the ranks of the members of the pencil; Dietmann~\cite{Die04} improved these conditions and obtained the asymptotic formula, and Rydin Myerson~\cite{RM} obtained it for all non-singular systems of $R$ quadratic forms in at least $9R$ variables. For an individual target vector, Kloosterman refinements for systems of forms became available only recently. Vishe~\cite{Vis} developed a version of the Farey dissection for systems of forms over $\FF_q(t)$, and building on these ideas Northey and Vishe~\cite{NV} proved the Hasse principle for smooth intersections of two cubic forms over $\QQ$ in at least $39$ variables. The two-dimensional delta symbol of Li, Rydin Myerson and Vishe~\cite{LRV}, and the three-dimensional symbol of the present paper, give such a dissection over $\QQ$ in a smooth form, with weights that depend on the numerators only through a lattice. \end{orevblock} Let us now explain the idea behind these results. Write $\vn=\vF(\bx)$ with $|\bx|\leqslant P$, so that $|\vn|\ll P^2$. If one detected each of the three equations $F_i(\bx)=0$ separately by the one-dimensional delta symbol of~\cite{HB}, the moduli would be of size $P$ for each equation, and the combined modulus would be of size $P^3$. Munshi's nesting idea~\cite{Mun} reduces this. One detects the first equation with a modulus $q_1$, writes the remaining equations as the congruences $F_i(\bx)\equiv0\pmod{q_1}$ together with the equations $F_i(\bx)/q_1=0$ for smaller integers, and detects these. Nesting the one-dimensional symbol three times gives combined moduli of size $P^{7/4}$, and nesting it with the two-dimensional symbol of~\cite{LRV} gives $P^{5/3}$. On the other hand, Dirichlet's theorem in $\RR^3$ approximates every point of $[0,1]^3$ by a fraction $\va/q$ with $q\leqslant Q$ to within $(qQ^{1/3})^{-1}$, and for vectors $\vn$ of size $P^2$ this suggests moduli of size $Q\asymp P^{3/2}$. The main technical result of this paper, Theorem~\ref{thm:symbol} below, is a three-dimensional delta symbol which reaches this size. Since $Q\asymp P^{3/2}$ is much smaller than the square of the length $P$ of each variable, Poisson summation in each variable saves a factor $P/Q^{1/2}=P^{1/4}$ in the critical range $q\asymp Q$. As the main term has size $P^{s-6}$, we need a total saving of $P^{6}$. Without any further averaging this leads to the condition $s>24$, that is, to the asymptotic formula for $s\geqslant25$ (Theorem~\ref{thm:main} in Section~\ref{sec:preparing}); the computation is made precise in~\S\ref{sec:savings}. This unrefined form of the method is the first step of the proof of Theorem~\ref{thm:mainA}. As in~\cite{LRV}, the weight attached to a fraction $\va/q$ depends only on the lattice $\ZZ\va+q\ZZ^3$, and so it is the same for all the numerators $\lambda\va$ with $\gcd(\lambda,q)=1$. This makes a Kloosterman refinement possible. For the terms attached to lines the average over $\lambda$ produces Gauss sums or Ramanujan sums and saves $q^{1/2}$; for the terms attached to planes and points the numerators run over a plane or over all residues, and the complete sums save $q^{1/2}$ as well. For small moduli this is too weak, and the saving comes instead from the exponential integrals, which decay faster than in the unrefined method away from the finitely many real members of corank $2$; near these members we use the theorems of Roth and Schmidt on rational approximation to algebraic points. Together the two savings give $Q^{1/2}=P^{3/4}$ on the whole critical curve, against the $P^{(24-s)/4}$ that we need. For $s=23$ this leaves a margin of $P^{1/2}$, and for $s=22$ a margin of $P^{1/4}$. The margin at $s=23$ is large enough to allow a simple treatment of everything that is not generic. At the primes dividing $\gcd(q,\gcd(\vrho))$, where $\vrho$ is the long vector of the flag, and at the primes dividing the discriminant of the member $\vrho/\gcd(\vrho)$, we use no cancellation at all, only the size of the Gauss sums and the fact that the dual vectors on which they do not vanish lie in a coset. The moduli on which this loses much are rare: a large value of $\gcd(q,\gcd(\vrho))$ forces the direction of the flag to be short, and the flags with short directions carry little of the mass. For the flags whose direction is a singular member of the net the kernel of the singular member takes the place of the sum over $\lambda$\orev{; what remains is handled by an average over the numerators on a plane, based on the factorisation of a binary form over $p$-adic fields.} At $s=22$ the same argument leaves a single loss, at the end of the critical curve where $q$ is close to $Q$. It comes from members $\vc$ of the net which have corank two modulo many primes. We show that such members are sparse, by a transversality argument which says that, modulo a prime power, the reductions of corank two lie on finitely many lines (Section~\ref{sec:s22}). The construction of the delta symbol itself follows the lead of~\cite{LRV}. In two dimensions the key observation there is a duality between the divisors of a vector $\vn\in\ZZ^2$ and the vectors orthogonal to it, which reduces the vanishing of $\vn$ to the vanishing of a single linear form. In three dimensions we apply this duality twice, first to reduce the vanishing of $\vn$ to its lying on a line, and then to reduce this to the vanishing of a linear form. The geometry of numbers in $\RR^3$ then forces two further kinds of terms: terms attached to rational planes and terms attached to rational lines. One might at first expect that the property needed to extract the main term would require a long pointwise analysis of the weights, as in~\cite[\S4]{LRV}. \orev{In fact it follows from the exactness of the identity alone} (Remark~\ref{rem:pointwise}), and this argument works in any dimension. We hope that the method will also be of interest for other problems involving three equations. Systems of $R\geqslant4$ quadrics, however, are better treated by the methods of Rydin Myerson~\cite{RM}. An $R$-dimensional version of our symbol exists, but its savings fall behind $9R$ as soon as $R\geqslant4$; see Section~\ref{sec:heuristic}. \subsection{A three-dimensional delta symbol} We write \begin{equation}\label{eq:deltadef} \delta_\vn=\begin{cases}1&\text{if }\vn=\vzero,\\ 0&\text{if }\vn\in\ZZ^R\setminus\{\vzero\}.\end{cases} \end{equation} Throughout, $|\cdot|$ is the Euclidean norm. We write $\ee(x)=\exp(2\pi ix)$ and $\ee_q(x)=\exp(2\pi ix/q)$, and an asterisk on a sum over $\va\bmod q$ indicates that $\gcd(\va,q)=1$. For $q\in\NN$ and $\va\in\ZZ^3$ with $\gcd(\va,q)=1$ let \begin{equation}\label{eq:Lambda} \Lambda(\va,q)=\{k\va+q\vy:\ k\in\ZZ,\ \vy\in\ZZ^3\}. \end{equation} We fix smooth non-negative functions $\omega$ and $\omega_0$ on $\RR$ as in~\cite[\S1.3]{LRV}: $\omega$ is supported on $(\frac12,1)$ with $\int\omega=1$, and $\omega_0$ is even, supported on $(-\frac12,\frac12)$, and satisfies $\omega_0(0)=1$. For a unit vector $\hat\vnu$ and $\vw\in\RR^3$ we note that $|\vw\times\hat\vnu|$ is the length of the component of $\vw$ orthogonal to $\hat\vnu$. \begin{theorem}\label{thm:symbol} Let $\vn\in\ZZ^3$ and let $Q\geqslant1$ be a large parameter. For each $q\in\NN$ and $\va\in\ZZ^3$ with $\gcd(\va,q)=1$ there exists a function $p_{\Lambda(\va,q)}$ on $\RR^3$, defined in~\eqref{eq:pLambda} below, which depends only on the lattice $\Lambda(\va,q)$ and the choice of the functions $\omega$ and $\omega_0$, such that \begin{equation}\label{eq:symbol} \delta_\vn=\sum_{1\leqslant q\leqslant Q}\ \sumstar_{\va\bmod q}\int_{\RR^3}p_{\Lambda(\va,q)}(\vw)\,\ee\bigl((\va/q+\vw)\cdot\vn\bigr)\,d\vw+O_N(Q^{-N}) \end{equation} for any $N>0$, with an implicit constant independent of $\vn$. The functions $p_{\Lambda(\va,q)}$ satisfy \begin{equation}\label{eq:mainprop} \int_{\RR^3}p_{\Lambda(\va,q)}(\vw)\,Q^4\hat g(-Q^{4/3}\vw)\,d\vw=g(\vzero)+O_{N,\delta,g}(Q^{-N})\qquad\text{if }q0$, where $\hat g(\vxi)=\int g(\vx)\ee(-\vxi\cdot\vx)\,d\vx$. More explicitly, we have the decomposition \begin{multline}\label{eq:decomp} p_{\Lambda(\va,q)}(\vw)=p_{1,q}(\vw)+\sum_{\substack{\vnu\in\Lp(\va,q)\\ k=\gcd(\vnu)/\gcd(\vnu,q)}}\omega\Bigl(\frac{|\vnu|}{Q^{1/3}}\Bigr)p_{2,\vnu,k,q}(\vw)\\ +\sum_{\substack{(\vnu,\vrho)\ \text{flag},\ \vnu\in\Lp(\va,q),\ \vrho\in\Lambda(\va,q)\\ k=\gcd(\vrho)/\gcd(\vrho,q)}}\omega\Bigl(\frac{|\vnu|}{Q^{1/3}}\Bigr)\omega\Bigl(\frac{|\vrho|}{Q^{2/3}}\Bigr)p_{3,\vnu,\vrho,k,q}(\vw), \end{multline} where $\Lp(\va,q)=\{\vnu\in\ZZ^3:\ q\mid\vnu\cdot\va\}$, a flag is a pair of non-zero vectors $\vnu,\vrho\in\ZZ^3$ with $\vnu\cdot\vrho=0$ and $\gcd(\vnu)\mid\vrho$, and the functions $p_{1,q}$, $p_{2,\vnu,k,q}$ and $p_{3,\vnu,\vrho,k,q}$, defined in~\eqref{eq:p1}--\eqref{eq:p3}, satisfy \begin{align} p_{1,q}(\vw)&\ll_N\frac{Q}{q(1+|\vw|Q^{4/3})}\bigl(1+|\vw|qQ^{1/3}\bigr)^{-N},\label{eq:p1bound}\\ p_{2,\vnu,k,q}(\vw)&\ll_N\frac{Q}{kq(1+|\vw\times\hat\vnu|Q^{4/3})}\bigl(1+|\vw\times\hat\vnu|kqQ^{1/3}+|\vw\cdot\hat\vnu|Q^{4/3}\bigr)^{-N},\label{eq:p2bound}\\ p_{3,\vnu,\vrho,k,q}(\vw)&\ll_{\varepsilon,N}Q^{\varepsilon}\bigl(1+|\vw\cdot\hat\vrho|kqQ^{1/3}+|\vw\times\hat\vrho|Q^{4/3}\bigr)^{-N},\label{eq:p3bound} \end{align} for $\frac12Q^{1/3}<|\vnu|0$ and $r_q=(qQ^{1/3})^{-1}$. Then \begin{multline*} \sumstar_{\va\bmod q}\int_{|\vw|\leqslant W}|p_{\Lambda(\va,q)}(\vw)|\,d\vw\\ \ll_\varepsilon Q^{\varepsilon}\Bigl(q^2Q\min(W,r_q)^2\min(W,Q^{-4/3})+qQ^2\min(W,r_q)\min(W,Q^{-4/3})^2\Bigr). \end{multline*} In particular \[ \sum_{q\leqslant Q}\sumstar_{\va}\int_{\RR^3}|p_{\Lambda(\va,q)}(\vw)|\,d\vw\ll_\varepsilon Q^{\varepsilon}. \] \end{proposition} \orev{We make some comments on} Theorem~\ref{thm:symbol}. Since $\delta_\vn=\int_{[0,1]^3}\ee(\vw\cdot\vn)\,d\vw$, the identity~\eqref{eq:symbol} may be viewed as a smooth partition of unity on $[0,1]^3$, with weights placed around the reduced fractions $\va/q$ with $q\leqslant Q$. By~\eqref{eq:p1bound}--\eqref{eq:p3bound}, the weight $p_{\Lambda(\va,q)}(\vw-\va/q)$ is essentially supported on the ball $|\vw-\va/q|\ll q^{-1}Q^{-1/3+\varepsilon}$, and by Dirichlet's theorem in $\RR^3$ these balls could not be made smaller and still cover $[0,1]^3$. For $|\vn|\leqslant\frac12Q^{4/3}$ the function $\ee(\vw\cdot\vn)$ hardly oscillates on the ball when $q\asymp Q$, and so we take $Q\asymp|\vn|^{3/4}$ in applications. The weight attached to $\va/q$ depends only on the lattice $\Lambda(\va,q)$, and $\Lambda(\va,q)=\Lambda(\lambda\va,q)$ whenever $\gcd(\lambda,q)=1$, see Lemma~\ref{lem:lattice}. As in~\cite{LRV}, this is what makes a Kloosterman refinement possible. We do not use it in the unrefined argument of Sections~\ref{sec:preparing}--\ref{sec:exceptional}; it is the basis of the Kloosterman refinement in Sections~\ref{sec:kloosterman} and~\ref{sec:s22}. \begin{remark}\label{rem:pointwise} The property~\eqref{eq:mainprop} says that $p_{\Lambda(\va,q)}$ is equal to $1$ when tested against functions concentrated at scale $Q^{-4/3}$, which is the scale on which the singular integral is extracted. The two-dimensional symbol satisfies the stronger pointwise statement~\cite[(1.6)]{LRV}, whose proof occupies~\cite[\S4]{LRV}. We do not prove a pointwise analogue of~\cite[(1.6)]{LRV} here. Our proof of~\eqref{eq:mainprop} in Section~\ref{sec:mainprop} is different: we apply the identity~\eqref{eq:symbol} itself to the function $\vn\mapsto g(\vn/Q^{4/3})\ee(-\va\cdot\vn/q)$, and use only~\eqref{eq:p1bound}--\eqref{eq:p3bound} and Poisson summation. The argument works for delta symbols of this shape in any dimension. For the one-dimensional symbol it gives the property of Heath-Brown's function $h$ in~\cite[Lemma~9]{HB}. \end{remark} \begin{remark}\label{rem:accumulation} As in~\cite[Remark~1.4]{LRV}, one might expect the weights to be independent of $\va$, as $p_{1,q}$ is. Because of the geometry of numbers in $\RR^3$, the arcs of $p_{1,q}$ alone accumulate around fractions which lie on rational planes and rational lines of small height. The terms $p_2$ and $p_3$ correct this; they are supported on discs around fractions on rational planes and on rods around fractions on rational lines. \end{remark} \subsection{Description of the method}\label{sec:description} We now describe how Theorem~\ref{thm:symbol} is proved, and how it is used for Theorem~\ref{thm:mainA}. The two-dimensional symbol of~\cite{LRV} rests on a duality between the divisors of a non-zero vector $\vn\in\ZZ^2$ and the vectors $\vr$ with $\vn\in\ZZ\vr^\perp$. It reduces the vanishing of $\vn$ to the vanishing of the single linear form $\vr\cdot\vn$, which is detected by the one-dimensional symbol. In three dimensions we use this duality twice. A non-zero vector $\vn\in\ZZ^3$ lies on a unique line $\ZZ\vnu_0$ with $\vnu_0$ primitive, and the divisors of $\vn$ are dual to the vectors $\vnu$ with $\vn/\gcd(\vnu)\in\ZZ\vnu_0$ (Lemma~\ref{lem:dual}(i)). This reduces the vanishing of $\vn$ to its lying on a line. The condition that $\vn$ lies on the line through $\vnu$ is a pair of linear equations, that is, the vanishing of a vector in the two-dimensional lattice $\ZZ^3/\ZZ\vnu_0$, and to it we apply the same duality in the plane $\vnu^\perp$ (Lemma~\ref{lem:dual}(ii)). This reduces the problem to the vanishing of a single linear form $\vc\cdot\vn$ with $\vc\perp\vnu$, which we detect with the one-dimensional symbol. At each step there is a divisor term, which accounts for the vectors $\vn$ that have already been detected. So a vector $\vn$ is detected by a \emph{flag} $(\vnu,\vrho)$: a vector $\vnu$ of height about $Q^{1/3}$, a vector $\vrho\perp\vnu$ of height about $Q^{2/3}$, and a one-dimensional symbol with moduli up to $Q/\gcd(\vrho)$. The heights are chosen so that every modulus that occurs is at most $Q$, for vectors $\vn$ of size up to $Q^{4/3}$ (Proposition~\ref{prop:flag}). The result is an exact identity with three kinds of terms: flag terms, plane terms (the divisor terms of the inner step) and point terms (the divisor terms of the outer step). Writing the periodic part of each term in lowest terms (Lemmas~\ref{lem:flagfreq} and~\ref{lem:planefreq}) and applying Fourier inversion gives~\eqref{eq:symbol} and~\eqref{eq:decomp}. The point terms give $p_{1,q}$, supported on balls of radius $r_q=(qQ^{1/3})^{-1}$ around every fraction $\va/q$; the plane terms give $p_{2,\vnu,k,q}$, supported on discs of radius $r_q/k$ and thickness $Q^{-4/3}$ around the fractions on the plane $q\mid\vnu\cdot\va$; and the flag terms give $p_{3,\vnu,\vrho,k,q}$, supported on rods of length $r_q/k$ and thickness $Q^{-4/3}$ around the fractions on the line $q\mid\vrho\times\va$ inside that plane. For the application we take $\vn=\vF(\bx)$, where $\vF=(F_1,F_2,F_3)$ and $|\bx|\leqslant P$, so that $Q\asymp P^{3/2}$. We apply Poisson summation to the sum over $\bx$ modulo $q$. The dual vector $\bu=\bzero$ and the moduli $q24$ comes from. Trivially, the left side of~\eqref{eq:mainasymp} is $O(P^s)$, and the main term has size $P^{s-6}$, so we must save $P^6$ on all error terms. Apply Theorem~\ref{thm:symbol} with $Q\asymp P^{3/2}$, so that $Q^{4/3}\asymp P^2$, and consider the moduli $q\asymp Y$ and the range $|\vw|\asymp W$. Put $X=1+P^2W$. By Proposition~\ref{prop:mass}, the delta symbol costs nothing in $L^1$: the total mass of the weights is $Q^{\varepsilon}$. For fixed $q$, $\va$ and $\vw$, Poisson summation modulo $q$ gives \[ \sum_{\bx}w(\bx/P)\,\ee\bigl((\va/q+\vw)\cdot\vF(\bx)\bigr)=q^{-s}\sum_{\bu\in\ZZ^s}S_q(\va,\bu)\,I_q(\vw,\bu), \] where $S_q$ is a complete exponential sum modulo $q$ and $I_q$ an oscillatory integral. \orev{The factors have the following sizes:} \begin{itemize}[leftmargin=*] \item the integral restricts the dual vectors to $|\bu|\ll P^{\varepsilon}qX/P$, so there are about $(qX/P)^s$ of them, and none except $\bu=\bzero$ if $qX24$. \orev{Consider the extreme case $q\asymp Q$, $|\vw|\leqslant P^{-2}$.} There the modulus $q\asymp P^{3/2}$ is larger than the length $P$ of the sum over each variable. Poisson summation replaces $P^s$ terms by about $(q/P)^s=P^{s/2}$ dual terms, each of size $q^{-s}\cdot q^{s/2}\cdot P^s=P^{s/4}$, so the saving is $P^{s/4}$, or $P/Q^{1/2}=P^{1/4}$ for each variable. The mass of the weights in this range is $\asymp1$. With the two-dimensional symbol for pairs of quadrics one has $Q\asymp P^{4/3}$, and the same computation saves $P/Q^{1/2}=P^{1/3}$ for each variable against the required $P^4$, that is, $s>12$; with the one-dimensional symbol for one quadric one has $Q\asymp P$, a saving of $P^{1/2}$ for each variable, and $s>4$. \begin{center}\small \renewcommand{\arraystretch}{1.25} \begin{tabular}{lccccc} \toprule & $Q$ & saving per variable & needed & pointwise & $\lambda$-average\\ \midrule one quadric~\cite{HB} & $P$ & $P^{1/2}$ & $P^2$ & $s\geqslant5$ & $s\geqslant4$\\ two quadrics~\cite{LRV} & $P^{4/3}$ & $P^{1/3}$ & $P^4$ & $s\geqslant13$ & $s\geqslant11$\\ three quadrics & $P^{3/2}$ & $P^{1/4}$ & $P^6$ & $s\geqslant25$ & $s\geqslant22$\\ \bottomrule \end{tabular} \end{center} The last column refers to the Kloosterman refinement. The flag terms allow an average over the numerators $\lambda\va$ with $\gcd(\lambda,q)=1$, a set of size about $q$, and square-root cancellation in this average saves a further $Q^{1/2}=P^{3/4}$ in the extreme case $q\asymp Q$. The error becomes $P^{3s/4-3/4}$, which is smaller than $P^{s-6}$ for $s>21$. We carry out the average over $\lambda$ in Section~\ref{sec:kloosterman}. Square-root cancellation is available in it at the primes not dividing $2D_F\Delta(\va)$, but it saves only $q^{1/2}$, which is too little when $q$ is small. In that range the missing factor comes from the exponential integral, whose decay is better than in Lemma~\ref{lem:integrals} away from the finitely many directions of corank $2$. The two savings together give $Q^{1/2}$ at every point of the critical curve $q(1+P^2|\vw|)\asymp Q$, and after the losses described above they lead to Theorem~\ref{thm:mainA}. For comparison, the two-dimensional symbol with these refinements gives $s\geqslant11$ for odd $s$ and $s\geqslant10$ for even $s$, which is the unconditional theorem of~\cite{LRV}. There the difference between even and odd $s$ comes from the Ramanujan sums, which for even $s$ save $q$ rather than $q^{1/2}$. In our setting this extra saving does not help at $s=22$, because the remaining loss comes from moduli which share most of their prime factors with fixed integers, and for these there is no sum over $\lambda$ to exploit. \subsection{\texorpdfstring{\orev{Plan of the paper}}{Plan of the paper}} Section~\ref{sec:expo} is an informal account of the method, which explains how the delta symbol is built up from the one-dimensional case and why it saves what it saves; it also contains a table of notation. In Section~\ref{sec:notation} we set notation and collect the properties of Heath-Brown's function $h$ that we need. Section~\ref{sec:duality} contains the duality Lemma~\ref{lem:dual}, the exact flag identity, and the definition and analytic properties of the $p$-functions. In Section~\ref{sec:thmsymbol} we prove Theorem~\ref{thm:symbol} using properties of the lattice $\Lambda(\va,q)$, we prove the main-term property~\eqref{eq:mainprop}, and we prove Proposition~\ref{prop:mass}. The rest of the paper is devoted to the application. In Section~\ref{sec:preparing} we apply Theorem~\ref{thm:symbol}, reduce Theorem~\ref{thm:main} to Lemma~\ref{lem:reduction}, and collect the geometry of nets of quadrics. Sections~\ref{sec:integrals} and~\ref{sec:sums} treat the exponential integrals and the exponential sums, including the local averages of $K(\va,q)$. The main term is obtained in Section~\ref{sec:major}. In Section~\ref{sec:averages} we average the exponential sums over the arcs, and in Sections~\ref{sec:generic} and~\ref{sec:exceptional} we bound the remaining contributions; this proves the unrefined Theorem~\ref{thm:main}. Section~\ref{sec:heuristic} compares delta symbol methods for three quadrics. Section~\ref{sec:kloosterman} contains the Kloosterman refinement and the proof for $s\geqslant23$, and Section~\ref{sec:s22} the additional argument for $s=22$. \begin{revblock} \emph{How to read the paper.} The paper can be read at three levels. A reader who wants only the ideas can read the introduction and Section~\ref{sec:expo}. A reader who wants to understand the method in full, but not the refinements, can read Sections~\ref{sec:notation}--\ref{sec:exceptional}, which give a complete proof of the asymptotic formula for $s\geqslant25$; this part is largely self-contained and uses only standard tools. Sections~\ref{sec:kloosterman} and~\ref{sec:s22} are more technical, and a guide to Section~\ref{sec:kloosterman} is given at its beginning. Throughout the paper, most proofs begin with a few sentences explaining the idea, and the longer arguments are preceded by a heuristic account of what has to be shown and why it should be true; the reader may find it useful to read these passages first, and to return to the details later. \end{revblock} \subsection*{\texorpdfstring{\orev{Declaration on the use of AI}}{Declaration on the use of AI}} \begin{orevblock} During the preparation of this work the author used Claude, an AI assistant developed by Anthropic, to help draft and revise parts of the text and of the arguments, to check proofs, computations and references, and to prepare the \LaTeX{} manuscript. The author has reviewed and edited all the material, and takes full responsibility for the content of the paper. \end{orevblock} %====================================================================== \section{\texorpdfstring{\orev{Overview of the method}}{Overview of the method}}\label{sec:expo} %====================================================================== \orev{This section explains, with as little notation as possible, how a delta symbol is built and where its saving comes from.} It may be skipped by readers familiar with~\cite{HB} and~\cite{LRV}. Nothing in the later sections depends on it, except the notation collected in~\S\ref{sec:notationtable}. \subsection{Detecting zero with divisors} Let $n$ be an integer with $|n|\leqslant N$, and let $\omega$ be a smooth function supported in $(\frac12,1)$ with $\int\omega=1$. The starting point of Duke, Friedlander and Iwaniec~\cite{DFI} is the observation that, for $n\neq0$, the map $d\mapsto|n|/d$ permutes the positive divisors of $n$, so that \begin{equation}\label{eq:DFIidea} \sum_{d\mid n}\Bigl(\omega\Bigl(\frac dQ\Bigr)-\omega\Bigl(\frac{|n|}{dQ}\Bigr)\Bigr)=0\qquad(n\neq0). \end{equation} For $n=0$ every $d$ divides $n$, the second term is $\omega(0)=0$, and the sum is $\sum_d\omega(d/Q)\approx Q$. Thus the left side of~\eqref{eq:DFIidea}, divided by $\sum_d\omega(d/Q)$, is exactly $\delta_n$. If we take $Q=(2N)^{1/2}$, then in both terms only divisors $d\leqslant Q$ occur: in the first term because of the support of $\omega$, and in the second because $|n|/(dQ)>\frac12$ forces $d<2N/Q=Q$. Finally we write the condition $d\mid n$ with additive characters, \[ \one_{d\mid n}=\frac1d\sum_{a\bmod d}\ee\Bigl(\frac{an}d\Bigr)=\frac1d\sum_{q\mid d}\ \sumstar_{a\bmod q}\ee\Bigl(\frac{an}{q}\Bigr), \] and collect the terms with the same reduced fraction $a/q$. The result is Heath-Brown's identity~\eqref{eq:HBdelta}: \[ \delta_n=\frac{c_Q}{Q^2}\sum_{q\leqslant Q}\ \sumstar_{a\bmod q}\ee\Bigl(\frac{an}q\Bigr)h\Bigl(\frac qQ,\frac n{Q^2}\Bigr). \] \orev{Two features of this identity are important.} First, only moduli $q\leqslant Q\asymp N^{1/2}$ occur. This is the same size as in Dirichlet's approximation theorem: every real number lies within $1/(qQ)$ of a fraction $a/q$ with $q\leqslant Q$. Secondly, the weight $h(q/Q,n/Q^2)$ attached to $a/q$ does not depend on $a$. So after the sum over $n$ has been evaluated, one can sum the resulting complete exponential sums over $a$, which is Kloosterman's refinement, and even over $q$. \subsection{Why a delta symbol saves} Let $F$ be a non-singular quadratic form in $s$ variables, and suppose we want to count $\bx\in\ZZ^s$ with $|\bx|\leqslant P$ and $F(\bx)=0$. Then $n=F(\bx)$ has size $N\asymp P^2$, so $Q\asymp P$. For fixed $q$ and $a$ we apply Poisson summation to the sum over $\bx$ modulo $q$: \[ \sum_{|\bx|\leqslant P}\ee\Bigl(\frac{aF(\bx)}q\Bigr)\cdots=q^{-s}\sum_{\bu\in\ZZ^s}S_q(a,\bu)I_q(\bu), \] where $S_q$ is a complete exponential sum modulo $q$ and $I_q$ is an oscillatory integral. When $q\asymp Q\asymp P$, the dual vectors $\bu$ effectively run over $|\bu|\ll q/P\asymp1$, the Gauss sum $S_q$ has size $q^{s/2}$, and $I_q$ has size $P^s$. So the sum over $\bx$, which has $P^s$ terms, is replaced by $O(1)$ terms of size $q^{-s}q^{s/2}P^s=P^{s/2}$. The saving is $P^{1/2}$ for each variable. Since we need to save $P^2$ to beat the trivial bound against the main term $P^{s-2}$, the method works when $s/2>2$, that is, $s\geqslant5$. \orev{For one quadric this rough calculation already contains the main idea:} \emph{the smaller the moduli compared with $P^2$, the more Poisson summation saves.} \subsection{Two equations} For two quadratic forms the vector $\vn=(F_1(\bx),F_2(\bx))\in\ZZ^2$ has size $N\asymp P^2$. Applying the one-dimensional symbol to each coordinate separately gives moduli $q_1,q_2\leqslant P$, so the combined modulus $q_1q_2$ can be as large as $P^2$. Poisson summation then saves only $P/(q_1q_2)^{1/2}$ per variable, that is, nothing at all in the worst case. Munshi's nested method~\cite{Mun} does better. Detect $F_1(\bx)=0$ with a modulus $q_1\leqslant P$. Split $F_2(\bx)=0$ into the congruence $F_2(\bx)\equiv0\pmod{q_1}$ and the equation $F_2(\bx)/q_1=0$, and detect the latter, whose size is now $P^2/q_1$, with a modulus $q_2\leqslant P/q_1^{1/2}$. The combined modulus is at most $P^{3/2}$. Dirichlet's theorem in $\RR^2$ suggests that one can go further. Every point of $[0,1]^2$ lies within $(qQ^{1/2})^{-1}$ of a fraction $\va/q$ with $\va\in\ZZ^2$ and $q\leqslant Q$. For vectors $\vn$ of size $N$ the natural choice is then $Q\asymp N^{2/3}=P^{4/3}$, and the saving per variable becomes $P/Q^{1/2}=P^{1/3}$, which gives $s>12$ without any refinement. Li, Rydin Myerson and Vishe~\cite{LRV} found a delta symbol with exactly these moduli. Two new features appear, and both persist in three dimensions. \emph{The weights must depend on $\va$.} In two dimensions the arcs of radius $(qQ^{1/2})^{-1}$ around all fractions $\va/q$ do not cover the square evenly. Fractions on a rational line of small height are much denser than elsewhere, because on such a line the problem is one-dimensional, and there the arcs overlap heavily. A smooth partition of unity must therefore give less weight to these fractions. In~\cite{LRV} the weight attached to $\va/q$ depends only on the lattice $\ZZ\va+q\ZZ^2$, which records how $\va/q$ sits with respect to the rational lines. Since $\ZZ\lambda\va+q\ZZ^2=\ZZ\va+q\ZZ^2$ when $\gcd(\lambda,q)=1$, a Kloosterman refinement over the numerators $\lambda\va$ is still possible. \emph{A duality replaces~\eqref{eq:DFIidea}.} For $\vn\in\ZZ^2\setminus\{\vzero\}$ there are exactly two primitive vectors $\pm\vc$ orthogonal to $\vn$, and the divisors $e$ of $\gcd(\vn)$ are in bijection, up to this sign, with the vectors $\vr=e\vc$. Comparing a weighted sum over these $\vr$ with a weighted sum over the divisors of $\gcd(\vn)$, as in~\eqref{eq:DFIidea}, gives an identity which vanishes for $\vn\neq\vzero$. Its terms involve only the single linear form $\vr\cdot\vn$, whose vanishing is detected by the one-dimensional symbol. \subsection{Three equations} For three quadratic forms, $\vn=\vF(\bx)\in\ZZ^3$ has size $P^2$, and Dirichlet's theorem in $\RR^3$ suggests moduli $Q\asymp N^{3/4}=P^{3/2}$. We apply the duality twice. First, a non-zero $\vn\in\ZZ^3$ lies on a unique rational line, and the divisors of $\gcd(\vn)$ are dual to the vectors $\vnu$ with $\vn/\gcd(\vnu)$ on the line $\ZZ\vnu/\gcd(\vnu)$ (Lemma~\ref{lem:dual}(i)). This reduces the vanishing of $\vn$ to the statement that $\vn$ lies on a given line, which is a pair of linear conditions. Secondly, these two conditions describe the vanishing of a vector in a two-dimensional lattice, and the two-dimensional duality (Lemma~\ref{lem:dual}(ii)) reduces it to the vanishing of a single linear form $\vc\cdot\vn$ with $\vc\perp\vnu$. Finally the one-dimensional symbol detects $\vc\cdot\vn=0$. So each vector is detected by a \emph{flag}: a vector $\vnu$ of height about $Q^{1/3}$, a vector $\vrho=G\vc\perp\vnu$ of height about $Q^{2/3}$, and a one-dimensional symbol with moduli up to $Q/G$. Each step of the duality also produces a ``divisor term'', which accounts for the vectors that have already been detected. In the end there are three kinds of terms, corresponding to the three kinds of special positions a fraction $\va/q$ can have: \begin{center}\small \renewcommand{\arraystretch}{1.25} \begin{tabular}{llll} \toprule term & fractions $\va/q$ involved & support of the weight & weight\\ \midrule point & all fractions & ball of radius $r_q=(qQ^{1/3})^{-1}$ & $p_{1,q}$\\ plane & fractions on a plane $q\mid\vnu\cdot\va$ & disc of radius $r_q/k$, thickness $Q^{-4/3}$ & $p_{2,\vnu,k,q}$\\ flag & fractions on a line $q\mid\vrho\times\va$ & rod of length $r_q/k$, thickness $Q^{-4/3}$ & $p_{3,\vnu,\vrho,k,q}$\\ \bottomrule \end{tabular} \end{center} Here $r_q$ is the radius suggested by Dirichlet's theorem. To get a feeling for the sizes, take $P=10^4$. Then $Q=P^{3/2}=10^6$, the vectors $\vnu$ have length about $10^2$, the vectors $\vrho$ about $10^4$, the arcs have radius $r_q\approx10^{-2}/q$, and Poisson summation saves a factor $P^{1/4}=10$ for each variable in the critical range $q\asymp Q$. With $s=25$ variables this is a total saving of $10^{25}$, against the $P^6=10^{24}$ that is required: a margin of $10=P^{1/4}$. \subsection{Extracting the main term} The main term comes from the dual vector $\bu=\bzero$ and from small moduli $q$. To extract it one needs to know that the weight $p_{\Lambda(\va,q)}$ behaves like the indicator function of its arc when tested against slowly varying functions. In two dimensions this is proved in~\cite[\S4]{LRV} by a careful pointwise analysis of the weights. We use a shortcut (Proposition~\ref{prop:mainprop}). We apply the exact identity~\eqref{eq:symbol} itself to the test function $\vn\mapsto g(\vn/Q^{4/3})\ee(-\va\cdot\vn/q)$, and use Poisson summation on the sum over $\vn$. The term we want appears as the zero frequency, and all other frequencies are negligible by the decay of the weights. The argument uses only the exactness of the identity and the bounds~\eqref{eq:p1bound}--\eqref{eq:p3bound}, and it works for symbols of this shape in any dimension. \subsection{The structure of the proof of Theorem~\ref{thm:mainA}} The proof proceeds in seven steps, which correspond to the sections of the paper. Steps~1--6 give the unrefined Theorem~\ref{thm:main}, and step~7 completes the proof of Theorem~\ref{thm:mainA}. \begin{enumerate}[label=\arabic*.,leftmargin=*] \item \emph{The identity} (Sections~\ref{sec:duality} and~\ref{sec:thmsymbol}). We construct the delta symbol, prove the bounds for the weights and their total mass, and prove the main-term property. \item \emph{Poisson summation} (Section~\ref{sec:preparing}). We insert the identity with $\vn=\vF(\bx)$, apply Poisson summation, and split the result into the main term $N_0$, the generic terms $N_1$ and the exceptional terms $N_2$. We also collect the geometry of the net of quadrics. \item \emph{Integrals and sums} (Sections~\ref{sec:integrals} and~\ref{sec:sums}). The integrals $I_q$ restrict the dual vectors to $|\bu|\ll qX/P$ and have size $P^sX^{-(s-2)/2}$. The sums $S_q(\va,\bu)$ are Gauss sums for the single quadratic form $\va\cdot\vF$, and their absolute value is given exactly by the number $K(\va,q)$ of solutions of a linear congruence. \item \emph{The main term} (Section~\ref{sec:major}). It gives the singular series and the singular integral. \item \emph{Averages of $K(\va,q)$} (Sections~\ref{sec:sums} and~\ref{sec:averages}). The quantity $K(\va,q)$ is large when the form $\va\cdot\vF$ is close to a singular member of the net, and we show that this is rare on average over the fractions that occur in each kind of term. \item \emph{The error terms} (Sections~\ref{sec:generic} and~\ref{sec:exceptional}). We add up the bounds over dyadic ranges of $q$ and $|\vw|$. All ranges on the curve $q(1+P^2|\vw|)\asymp Q$ contribute the same amount $Q^{s/2}=P^{3s/4}$, and this gives the condition $s>24$. \item \emph{The Kloosterman refinement} (Sections~\ref{sec:kloosterman} and~\ref{sec:s22}). We use that the weights are the same for all numerators $\lambda\va$, and sum the exponential sums over $\lambda$ before taking absolute values. Together with a sharper treatment of the integrals for small moduli, this saves a further factor $Q^{1/2}$ on the critical curve. At the primes shared by $q$ and the flag, and at the primes dividing the discriminant of its direction, we use only the size of the Gauss sums; this costs a factor which is large only for rare moduli, and gives $s\geqslant23$. For $s=22$ we show in addition that the members of the net which have corank two modulo many primes are sparse. \end{enumerate} \subsection{Notation}\label{sec:notationtable} For the convenience of the reader we list the main notation. \begin{center}\small \renewcommand{\arraystretch}{1.2} \begin{tabular}{p{0.24\textwidth}p{0.66\textwidth}} \toprule $P$, $s$ & size of the variables, number of variables\\ $\vF=(F_1,F_2,F_3)$ & the quadratic forms; $F_\vbeta=\vbeta\cdot\vF$, with matrix $M_\vbeta$\\ $\Delta(\vbeta)$ & $\det M_\vbeta$, the discriminant of the net, a ternary form of degree $s$\\ $Q$ & the parameter of the delta symbol, $Q\asymp P^{3/2}$, so that $Q^{4/3}\asymp P^2$\\ $q$, $\va$ & modulus and numerator of a fraction $\va/q$, $\va\in\ZZ^3$, $\gcd(\va,q)=1$\\ $\Lambda(\va,q)$, $\Lp(\va,q)$ & the lattice $\ZZ\va+q\ZZ^3$, and $\{\vnu:\ q\mid\vnu\cdot\va\}$\\ flag $(\vnu,\vrho)$ & $\vnu\perp\vrho$, $\gcd(\vnu)\mid\vrho$; $\vrho=G\vc$ with $\vc$ primitive\\ $p_{1},p_{2},p_{3}$ & the weights of the point, plane and flag terms\\ $\vw$, $X$ & distance from $\va/q$, and $X=1+P^2|\vw|$\\ $\bu$, $L$ & dual vector after Poisson summation, and its effective range $L\asymp qX/P$\\ $S_q(\va,\bu)$, $I_q(\vw,\bu)$ & complete exponential sum and oscillatory integral, \eqref{eq:Sdef} and~\eqref{eq:Idef}\\ $K(\va,q)$ & number of $\bh\bmod q$ with $M_\va\bh\equiv\bzero$; $|S_q|=q^{s/2}K^{1/2}$ or $0$\\ $\cZ_2$, $\cC_F$, $\cN_F$ & points of corank $2$; singular primitive vectors; exceptional plane directions\\ $D_F$, $b(q)$ & product of bad primes, and the part of $q$ composed of them\\ $\fM(Y,W)$ & normalised mass of the weights with $q\asymp Y$, $|\vw|\leqslant W$, \eqref{eq:fM}\\ \bottomrule \end{tabular} \end{center} %====================================================================== \section{\texorpdfstring{\orev{Notation and preliminaries}}{Notation and preliminaries}}\label{sec:notation} %====================================================================== We first set some notation which will be used throughout. The notation $|\cdot|$, $\delta_\vn$, $\ee(x)$, $\ee_q(x)$, $\sumstar_{\va\bmod q}$ and $\Lambda(\va,q)$ will always be as defined before Theorem~\ref{thm:symbol}. We use $\va,\vb,\vc,\vn,\vr,\vnu,\vrho$ to denote vectors in $\ZZ^3$, $\vw,\vx,\vy,\vxi$ to denote vectors in $\RR^3$, and $\bx,\bu,\bh,\dots$ to denote vectors in $\ZZ^s$ or $\RR^s$, where $s$ is the number of variables in Theorem~\ref{thm:main}. For a non-zero integer vector $\vx$ we write $\gcd(\vx)$ for the greatest common divisor of its coordinates and $\gcd(\vx,q)=\gcd(\gcd(\vx),q)$; for $g\in\NN$, $g\mid\vx$ means that $g$ divides every coordinate of $\vx$. We set $\one_S=1$ if $S$ is true and $0$ otherwise. We write $A\ll B$ or $A=O(B)$ if $|A|\leqslant C|B|$ for an implicit constant $C$, and $A\asymp B$ if $A\ll B\ll A$. From Section~\ref{sec:preparing} onward we fix the forms $F_1,F_2,F_3$ and the weight $w$, we use $\varepsilon$ for an arbitrarily small positive constant whose value may change from line to line, and all implicit constants may depend on $s$, $w$, $F_1,F_2,F_3$ and $\varepsilon$. \begin{revblock} This section collects the one-dimensional tools that the rest of the paper is built on: the function $h$ from Heath-Brown's delta symbol, with the bounds we need for it, and a form of Poisson summation over lattices. The reader who knows~\cite{HB} can skim the statements and move on; the proofs are short and are included to keep the paper self-contained. \end{revblock} For $m\in\NN$ we define \begin{equation}\label{eq:cm} c_m=\Bigl(\int_{\RR^m}\omega(|\vx|)\,d\vx\Bigr)^{-1}. \end{equation} Since $\omega_0$ is even and smooth, $\vx\mapsto\omega_0(|\vx|)$ is a smooth function on $\RR^m$. As in~\cite{HB} and~\cite[(2.2)]{LRV}, we define for $y>0$ and $z\in\RR$ \begin{equation}\label{eq:hdef} h(y,z)=\sum_{j\in\NN}\frac1{yj}\Bigl(\omega(yj)-\omega\Bigl(\frac{|z|}{yj}\Bigr)\Bigr). \end{equation} This function appears in the one-dimensional delta symbol: by~\cite[Theorem~1]{HB}, for $Q_1\geqslant1$ and $t\in\ZZ$, \begin{equation}\label{eq:HBdelta} \delta_t=\frac{c_{Q_1}}{Q_1^2}\sum_{q\in\NN}\ \sumstar_{a\bmod q}\ee_q(at)\,h\Bigl(\frac q{Q_1},\frac t{Q_1^2}\Bigr),\qquad c_{Q_1}=Q_1\Bigl(\sum_{m\in\NN}\omega(m/Q_1)\Bigr)^{-1}, \end{equation} and $c_{Q_1}=1+O_N(Q_1^{-N})$ by Poisson summation. The identity~\eqref{eq:HBdelta} is exact. \begin{revblock}It is worth keeping a picture of $h$ in mind. For a fixed small $y=q/Q_1$, the function $z\mapsto h(y,z)$ is essentially constant, of size at most $1/y$, on the interval $|z|0$ and $z\in\RR$. Part~(1) holds for all $y>0$; in parts~(2)--(4) we assume $00$ and $i\geqslant0$, we have $\partial_z^ih(y,z)\ll_{\varepsilon,N,i}y^N$ for $y^{1-\varepsilon}\leqslant|z|\leqslant1$. \item For any $\varepsilon>0$, $\int_{-1}^1|h(y,z)|\,dz\ll_\varepsilon y^{-\varepsilon}$, and $\int_{-1}^1|\partial_z^ih(y,z)|\,dz\ll_{\varepsilon,i}y^{-i-\varepsilon}$ for $i\geqslant1$. \end{enumerate} \end{lemma} \begin{proof} \rev{Everything follows from the definition~\eqref{eq:hdef}, in which $h$ is the difference of two sums over $j$. The first sum does not depend on $z$, and the second one is only present when $|z|$ is comparable to $yj$. Parts~(1) and~(2) count the terms which can be non-zero, and part~(3) uses Poisson summation in $j$ to see a cancellation between the two sums.} (1) If $y\geqslant1$ then $\omega(yj)=0$ for all $j\in\NN$, and if moreover $y\geqslant2|z|$ then $|z|/(yj)\leqslant\frac12$, so $\omega(|z|/(yj))=0$. The first sum in~\eqref{eq:hdef} has at most $1/(2y)+1$ non-zero terms, each $\ll1$. A term of the second sum is non-zero only if $|z|0$ and $f(t)=0$ for $t\leqslant0$. Then $f$ is smooth, since $\omega(|z|/t)$ vanishes for $t\leqslant|z|$, and it is supported in $[\min(|z|,\frac12),2]$; moreover $|f^{(M)}(t)|\ll_M|z|^{-M-1}$ on $[|z|,2|z|]$ and $|f^{(M)}(t)|\ll_M1$ elsewhere, and $h(y,z)=\sum_{j\in\ZZ}f(yj)=y^{-1}\sum_{k\in\ZZ}\hat f(k/y)$ by Poisson summation. The substitution $t\mapsto|z|/t$ shows that $\hat f(0)=\int f=0$. For $k\neq0$, integration by parts gives $\hat f(k/y)\ll_M(y/|k|)^M\int|f^{(M)}|\ll_M(y/|k|)^M|z|^{-M}$, since $|z|\leqslant1$. Hence $h(y,z)\ll_My^{-1}(y/|z|)^M\leqslant y^{\varepsilon M-1}$. \rev{Choosing $M$ large in terms of $\varepsilon$ and $N$ gives the bound $y^N$.} The same argument applies to $\partial_z^ih$, since $\partial_z^if$ also has integral zero and the same support. (4) This follows from (1)--(3): \rev{split the interval $[-1,1]$ into the range $|z|0$. Then for $T\geqslant1$ with $\lambda T\geqslant1$ and any $N>0$ \[ \sum_{\vr\in L}\omega\Bigl(\frac{|\vr|}{T}\Bigr)=\frac{T^m}{c_m\operatorname{covol}(L)}\Bigl(1+O_N\bigl((\lambda T)^{-N}\bigr)\Bigr). \] \end{lemma} \begin{proof} \rev{The idea is that Poisson summation turns the sum over $L$ into a sum over the dual lattice $L^*$, in which the zero vector gives the volume term and every other vector is far out in the tail of a Schwartz function.} By Poisson summation the sum is $\operatorname{covol}(L)^{-1}T^m\sum_{\vxi\in L^*}\hat f(T\vxi)$ with $f(\vy)=\omega(|\vy|)$. The term $\vxi=\vzero$ gives the main term. The balls of radius $\lambda/2$ around the points of $L^*$ are disjoint, so the number of $\vxi\in L^*$ with $|\vxi|\leqslant u$ is $\leqslant(1+2u/\lambda)^m\ll(u/\lambda)^m$ for $u\geqslant\lambda$. Since $\hat f$ is a Schwartz function, $|\hat f(T\vxi)|\ll_{N'}(T|\vxi|)^{-N'}$, and splitting the $\vxi\neq\vzero$ into the shells $2^i\lambda\leqslant|\vxi|<2^{i+1}\lambda$ we obtain \[ \sum_{\vxi\neq\vzero}|\hat f(T\vxi)|\ll_{N'}\sum_{i\geqslant0}2^{(i+1)m}(2^i\lambda T)^{-N'}\ll(\lambda T)^{-N'} \] for $N'>m$. So the other terms contribute $\ll_N(\lambda T)^{-N}T^m/\operatorname{covol}(L)$. \end{proof} For a non-zero $\vnu\in\ZZ^3$ we write $g=\gcd(\vnu)$, $\vnu_0=\vnu/g$, and \[ L_\vnu=\{\vr\in\ZZ^3:\ \vr\cdot\vnu=0\}. \] This is a primitive lattice of rank $2$ and covolume $|\vnu_0|$. We fix a $3\times2$ integer matrix $B_\vnu$ whose columns form a basis of $L_\vnu$; then $\vx\mapsto B_\vnu^T\vx$ maps $\ZZ^3$ onto $\ZZ^2$ with kernel $\ZZ\vnu_0$. The dual lattice of $L_\vnu$ in the plane $\vnu^\perp$ is the orthogonal projection of $\ZZ^3$ to that plane, and its non-zero vectors have length at least $1/|\vnu_0|$, since the projection of $\vx$ has length $|\vx\times\vnu_0|/|\vnu_0|$. \rev{In the language of Lemma~\ref{lem:poissonlattice}, the lattice $L_\vnu$ may therefore be counted in balls of radius $T$ with a negligible error as soon as $T$ is a little larger than $|\vnu_0|$. This is how Lemma~\ref{lem:poissonlattice} will be used in the construction of the delta symbol.} %====================================================================== \section{\texorpdfstring{\orev{Duality of divisors}}{Duality of divisors}}\label{sec:duality} %====================================================================== In this section we make the preparations for the proof of Theorem~\ref{thm:symbol}. We begin with the duality of divisors on which the construction rests. It is the three-dimensional counterpart of~\cite[Lemma~3.1]{LRV}, which is itself a higher-dimensional analogue of the identity used by Duke, Friedlander and Iwaniec~\cite[(2.3)]{DFI}. \begin{revblock} Before stating the lemma we explain the idea in its simplest form. In one dimension, a non-zero integer $n$ has the divisors $d$ and $|n|/d$ in pairs, and the identity~\eqref{eq:DFIidea} compares a sum over $d$ with the same sum over $|n|/d$; the two agree when $n\neq0$, and the difference only survives at $n=0$. In three dimensions a non-zero vector $\vn$ determines a rational line, namely the line through $\vn$, and on this line $\vn$ is $\lambda$ times a primitive vector, with $\lambda=\gcd(\vn)$. Part~(i) of the lemma is the one-dimensional identity applied to $\lambda$, written in terms of the vectors $\vnu=g\vnu_0$ on this line. Part~(ii) is the same statement one dimension lower: inside a plane $L_{\vnu_0}$, a non-zero vector $\vec m$ determines a unique line, now described by the primitive vectors $\pm\vc$ orthogonal to it. In both parts the right-hand side involves only the size of $\vn$ (or of $\vx\times\vnu_0$), and this is what will allow us to subtract it off. \end{revblock} \subsection{\texorpdfstring{\orev{A duality between divisors and flags}}{A duality between divisors and flags}} \begin{lemma}\label{lem:dual} Let $W:[0,\infty)\to\RR$ be any function. \begin{enumerate}[label=(\roman*)] \item For $\vn\in\ZZ^3\setminus\{\vzero\}$ we have \[ \sum_{\vnu\in\ZZ^3\setminus\{\vzero\}}\one_{g\mid\vn}\,\one_{\vn/g\in\ZZ\vnu_0}\,W(|\vnu|)=2\sum_{g'\mid\vn}W\bigl(|\vn|/g'\bigr), \] where $g=\gcd(\vnu)$ and $\vnu_0=\vnu/g$. \item Let $\vnu_0$ be primitive and let $\vx\in\ZZ^3$ with $\vec m=B_{\vnu_0}^T\vx\neq\vzero$. Then \[ \sum_{\substack{\vr\in L_{\vnu_0}\setminus\{\vzero\}\\ \vr=e\vc,\ \vc\text{ primitive}}}\one_{e\mid\vec m}\,\one_{\vc\cdot\vx=0}\,W(|\vr|)=2\sum_{e'\mid\vec m}W\bigl(|\vx\times\vnu_0|/e'\bigr). \] \end{enumerate} \end{lemma} \begin{proof} (i) There are exactly two primitive vectors parallel to $\vn$. \rev{The conditions on the left force $\vnu$ to be parallel to $\vn$, so the only question is which multiples of these two primitive vectors occur, and with what weight.} If $\vn=\lambda\vnu_0$ with $\lambda\in\NN$, the conditions say that $g\mid\lambda$, and $g\mapsto g'=\lambda/g$ permutes the divisors of $\lambda$, with $|\vnu|=g|\vnu_0|=|\vn|/g'$. The same holds for $-\vnu_0$. \rev{So each divisor $g'$ of $\lambda$ is counted twice on the left, once for $\vnu_0$ and once for $-\vnu_0$, and with the weight $W(|\vn|/g')$; this is the factor~$2$ on the right.} (ii) Write $B=B_{\vnu_0}$ and $\vc=B\vs$ with $\vs\in\ZZ^2$ primitive. Then $\vc\cdot\vx=\vs\cdot\vec m$, so $\vc\cdot\vx=0$ if and only if $\vec m=\pm\lambda\vs^\perp$, where $\lambda=\gcd(\vec m)$ and $\vs^\perp=(-s_2,s_1)$. This determines $\vs$ up to sign, and the condition $e\mid\vec m$ says that $e\mid\lambda$. \rev{So, exactly as in part~(i), the vectors $\vr$ which occur are $e\vc$ for the two choices $\pm\vc$ and for the divisors $e$ of $\lambda$; it only remains to express $|\vr|$ in terms of the divisor $e'=\lambda/e$. This is a computation with the Gram matrix of the basis $B$.} Let $G=B^TB$, so that $\det G=|\vnu_0|^2$, and let $\pi(\vx)=BG^{-1}\vec m$ be the orthogonal projection of $\vx$ to $\vnu_0^\perp$. For a symmetric $2\times2$ matrix we have $(\vs^\perp)^T\operatorname{adj}(G)\vs^\perp=\vs^TG\vs$, hence \[ |\pi(\vx)|^2=\vec m^TG^{-1}\vec m=\frac{\lambda^2\,\vs^TG\vs}{|\vnu_0|^2}=\frac{\lambda^2|B\vs|^2}{|\vnu_0|^2}. \] Therefore $|\vr|=e|\vc|=e|\vnu_0||\pi(\vx)|/\lambda=|\vx\times\vnu_0|/e'$ with $e'=\lambda/e$. \rev{Here we used $|B\vs|=|\vc|$ and $|\vnu_0||\pi(\vx)|=|\vx\times\vnu_0|$, the latter because the projection of $\vx$ to $\vnu_0^\perp$ has length $|\vx\times\vnu_0|/|\vnu_0|$. As in~(i), the map $e\mapsto e'$ is a bijection of the divisors of $\lambda$, and the factor $2$ comes from the two signs of $\vc$.} \end{proof} We now combine the two parts of the lemma with the one-dimensional delta symbol. Put $R_1=Q^{1/3}$, and for a non-zero $\vnu\in\ZZ^3$ with $g=\gcd(\vnu)$ put $\varrho_\vnu=Q^{2/3}/g$. \begin{revblock} The proposition below is the delta symbol before Fourier analysis. It expresses $\delta_\vn$ as a sum of three kinds of terms. The \emph{flag terms}~\eqref{eq:flagterm} come from detecting $\vn=\vzero$ in three steps: $\vn$ lies on the line $\RR\vnu$, then inside the plane $L_\vnu$ the projected vector vanishes along the direction $\vc$, and finally the single integer $\vc\cdot\vn/(ge)$ vanishes, which is detected by Heath-Brown's one-dimensional symbol. The \emph{plane terms}~\eqref{eq:planeterm} and the \emph{point terms}~\eqref{eq:pointterm} are the ``divisor sums'' on the right of Lemma~\ref{lem:dual}(ii) and~(i), which have to be subtracted at each step. The parameters are chosen so that every vector $\vnu$ has length about $R_1=Q^{1/3}$ and every vector $\vr$ has length about $Q^{2/3}/g$; with these sizes the moduli $ge\,q_1$ of the final step never exceed $Q$, and the lattice counts in the normalisation are as accurate as Lemma~\ref{lem:poissonlattice} allows. \end{revblock} \begin{proposition}\label{prop:flag} Let $Q\geqslant1$ and let $\vn\in\ZZ^3$ with $|\vn|<\frac12Q^{4/3}$. In the sums below, $g=\gcd(\vnu)$, and $\vr=e\vc$ with $e=\gcd(\vr)$. For any $N>0$ we have \begin{align} \delta_\vn={}&\frac{c_2c_3}{Q^{13/3}}\sum_{\vnu\neq\vzero}\omega\Bigl(\frac{|\vnu|}{R_1}\Bigr)|\vnu|\sum_{\vr\in L_\vnu\setminus\{\vzero\}}\omega\Bigl(\frac{|\vr|}{\varrho_\vnu}\Bigr)\,g^3e^2\,\one_{g\mid\vn}\,\one_{e\mid B_\vnu^T\vn/g}\notag\\ &\hspace{3.2cm}\times\sum_{q_1\leqslant Q/(ge)}\ \sumstar_{a\bmod q_1}\ee_{q_1}\Bigl(\frac{a\,\vc\cdot\vn}{ge}\Bigr)h\Bigl(\frac{geq_1}{Q},\frac{ge\,\vc\cdot\vn}{Q^2}\Bigr)\label{eq:flagterm}\\ &-\frac{2c_2c_3}{Q^{7/3}}\sum_{\vnu\neq\vzero}\omega\Bigl(\frac{|\vnu|}{R_1}\Bigr)|\vnu|\,g\,\one_{g\mid\vn}\sum_{e'\mid B_\vnu^T\vn/g}\omega\Bigl(\frac{|\vn\times\vnu_0|}{e'Q^{2/3}}\Bigr)\label{eq:planeterm}\\ &-\frac{2c_3}{Q}\sum_{g'\mid\vn}\omega\Bigl(\frac{|\vn|}{g'R_1}\Bigr)+O_N(Q^{-N}),\label{eq:pointterm} \end{align} where the implicit constant does not depend on $\vn$. \end{proposition} \begin{proof} \rev{The proof follows the three steps just described. At each of the first two steps we apply Lemma~\ref{lem:dual}, which says that a weighted count of the vectors detecting $\vn$ equals a divisor sum when $\vn\neq\vzero$; the difference of the two is therefore a multiple of $\delta_\vn$, and we only have to compute the multiple, which is a lattice point count. At the last step we insert~\eqref{eq:HBdelta}.} \emph{The outer step.} Since $\one_{\vx\in\ZZ\vnu_0}=\delta_{B_\vnu^T\vx}$, Lemma~\ref{lem:dual}(i) with $W(t)=\omega(t/R_1)$ gives, for $\vn\neq\vzero$, \begin{equation}\label{eq:outer} \sum_{\vnu}\omega(|\vnu|/R_1)\,\one_{g\mid\vn}\,\delta_{B_\vnu^T\vn/g}-2\sum_{g'\mid\vn}\omega\bigl(|\vn|/(g'R_1)\bigr)=0 . \end{equation} For $\vn=\vzero$ the second sum is empty, and the first sum equals \[ S_3=\sum_{\vnu\in\ZZ^3}\omega(|\vnu|/R_1)=c_3^{-1}Q(1+O_N(Q^{-N})) \] by Lemma~\ref{lem:poissonlattice}. Thus $\delta_\vn$ equals $S_3^{-1}$ times the left side of~\eqref{eq:outer}. \rev{In words: $\vn$ vanishes if and only if every $\vnu$ ``sees'' it, and the count of all $\vnu$ is the normalising factor $S_3$.} \emph{The inner step.} Fix $\vnu$ with $g\mid\vn$, and put $\vx=\vn/g$ and $\vec m=B_\vnu^T\vx$. Lemma~\ref{lem:dual}(ii) with $W(t)=\omega(t/\varrho_\vnu)$ gives, for $\vec m\neq\vzero$, \begin{equation}\label{eq:inner} \sum_{\vr=e\vc\in L_\vnu\setminus\{\vzero\}}\omega(|\vr|/\varrho_\vnu)\,\one_{e\mid\vec m}\,\delta_{\vc\cdot\vx/e}-2\sum_{e'\mid\vec m}\omega\Bigl(\frac{|\vx\times\vnu_0|}{e'\varrho_\vnu}\Bigr)=0 . \end{equation} Note that $e\mid\vec m$ implies $e\mid\vc\cdot\vx$. For $\vec m=\vzero$ the second sum is empty and the first equals $S_2(\vnu)=\sum_{\vr\in L_\vnu}\omega(|\vr|/\varrho_\vnu)$. By Lemma~\ref{lem:poissonlattice} in the plane $\vnu^\perp$, with $\lambda=1/|\vnu_0|$ and $\lambda\varrho_\vnu=Q^{2/3}/|\vnu|\geqslant Q^{1/3}$ when $|\vnu|\leqslant R_1$, we have $S_2(\vnu)=\varrho_\vnu^2c_2^{-1}|\vnu_0|^{-1}(1+O_N(Q^{-N}))$. Thus $\delta_{\vec m}$ equals $S_2(\vnu)^{-1}$ times the left side of~\eqref{eq:inner}. \rev{Since $\vec m=B_\vnu^T\vn/g$ vanishes exactly when $\vn/g\in\ZZ\vnu_0$, this replaces the factor $\delta_{B_\vnu^T\vn/g}$ in~\eqref{eq:outer} by a sum over the vectors $\vr$ in the plane $L_\vnu$, each of which only asks for the vanishing of the single integer $\vc\cdot\vx/e$.} \emph{The last step.} We detect $t=\vc\cdot\vx/e=0$ by~\eqref{eq:HBdelta} with $Q_1=Q/(ge)$. If $\omega(|\vr|/\varrho_\vnu)\neq0$ then $e|\vc|<\varrho_\vnu$, so $|t|\leqslant|\vc||\vn|/(ge)<\frac12Q_1^2$, and only $q_1\leqslant Q_1$ occur by Lemma~\ref{lem:h}(1). Moreover $ge\leqslant g|\vr|Q^{1/3}$ and $c_{Q_1}=1+O_N(Q^{-N})$. Collecting the factors \[ \frac{c_3}{Q}\cdot\frac{c_2|\vnu_0|}{\varrho_\vnu^2}\cdot\frac{1}{Q_1^2}=\frac{c_2c_3|\vnu|g^3e^2}{Q^{13/3}},\qquad\frac{c_3}{Q}\cdot\frac{c_2|\vnu_0|}{\varrho_\vnu^2}=\frac{c_2c_3|\vnu|g}{Q^{7/3}}, \] we obtain~\eqref{eq:flagterm} and~\eqref{eq:planeterm}, where we used $|\vx\times\vnu_0|/\varrho_\vnu=|\vn\times\vnu_0|/Q^{2/3}$. There are $O(Q^{7/3})$ pairs $(\vnu,\vr)$ with non-zero weight and every term is $O(Q^{C})$ for some absolute $C$, so the relative errors add up to $O_N(Q^{-N})$. \end{proof} \begin{revblock} It is useful to keep in mind the sizes of the three kinds of terms. A point term carries the factor $Q^{-1}$ and there is one for each divisor of $\vn$; a plane term carries $Q^{-7/3}|\vnu|$, and there are about $Q$ vectors $\vnu$; a flag term carries $Q^{-13/3}|\vnu|$ times a one-dimensional symbol, and there are about $Q^{2}$ pairs $(\vnu,\vr)$ (up to logarithms, for each $\vnu$ with $\gcd(\vnu)=1$ the plane $L_\vnu$ contains about $Q^{4/3}/|\vnu|\asymp Q$ vectors $\vr$ of length at most $Q^{2/3}$). As a check, at $\vn=\vzero$ the one-dimensional symbol contributes about $Q_1^2$, and $Q^{-13/3}\cdot Q^{1/3}\cdot Q^2\cdot Q^2=1$, as it should be. After Fourier inversion, which we carry out next, these three families become the point, plane and flag weights of Theorem~\ref{thm:symbol}. \end{revblock} \begin{remark}\label{rem:exact} If $c_3^{-1}Q$, $\varrho_\vnu^2/(c_2|\vnu_0|)$ and $c_{Q_1}$ are replaced by the exact quantities $S_3$, $S_2(\vnu)$ and $Q_1(\sum_m\omega(m/Q_1))^{-1}$, the proof gives an identity without error term for every $\vn$ with $|\vn|<\frac12Q^{4/3}$. Everything below holds for either version. \end{remark} \subsection{\texorpdfstring{\orev{The weight functions}}{The weight functions}} Next, we use Fourier inversion to pass from Proposition~\ref{prop:flag} to the form~\eqref{eq:symbol}. \rev{The idea is simple. Each term of Proposition~\ref{prop:flag} is a congruence condition on $\vn$ times a smooth function of $\vn$. The congruence condition is written with additive characters $\ee(\va\cdot\vn/q)$, and the smooth function is written as a Fourier integral $\int p(\vw)\ee(\vw\cdot\vn)\,d\vw$. The functions $p$ obtained in this way are the weights.} For $q,k\in\NN$, a non-zero $\vnu\in\ZZ^3$, a flag $(\vnu,\vrho)$ and $\vw\in\RR^3$ we define \begin{align} p_{1,q}(\vw)&=-\frac{2c_3}{Q}\int_{\RR^3}\omega_0\Bigl(\frac{|\vx|}{Q^{4/3}}\Bigr)\sum_{j\in\NN}\frac1{(qj)^3}\,\omega\Bigl(\frac{|\vx|}{jqQ^{1/3}}\Bigr)\ee(-\vw\cdot\vx)\,d\vx,\label{eq:p1}\\ p_{2,\vnu,k,q}(\vw)&=-\frac{2c_2c_3|\vnu|}{Q^{7/3}}\int_{\RR^3}\omega_0\Bigl(\frac{|\vx|}{Q^{4/3}}\Bigr)\sum_{j\in\NN}\frac1{(qkj)^2}\,\omega\Bigl(\frac{|\vx\times\vnu|}{qkjQ^{2/3}}\Bigr)\ee(-\vw\cdot\vx)\,d\vx,\label{eq:p2}\\ p_{3,\vnu,\vrho,k,q}(\vw)&=\frac{c_2c_3|\vnu|}{Q^{13/3}}\int_{\RR^3}\omega_0\Bigl(\frac{|\vx|}{Q^{4/3}}\Bigr)h\Bigl(\frac{kq}{Q},\frac{\vrho\cdot\vx}{Q^2}\Bigr)\ee(-\vw\cdot\vx)\,d\vx.\label{eq:p3} \end{align} Each integrand is a smooth function of $\vx$ with support in $|\vx|<\frac12Q^{4/3}$: the function $\omega(|\vx\times\vnu|/(\cdots))$ vanishes near the line $\RR\vnu$, and $h(y,z)$ does not depend on $z$ for $|z|\frac12$ on the support of $\omega$, only $jkqQ^{1/3}$. Taking $i,i'\in\{0,N\}$ gives~\eqref{eq:p3bound}. \end{proof} %====================================================================== \section{\texorpdfstring{\orev{Proof of the identity}}{Proof of the identity}}\label{sec:thmsymbol} %====================================================================== In this section we prove Theorem~\ref{thm:symbol}. The identity of Proposition~\ref{prop:flag} is exact but its terms are written with periodic functions of $\vn$; to obtain~\eqref{eq:symbol} we must write each periodic function as a sum over fractions $\va/q$ in lowest terms and check that the resulting weight depends only on the lattice $\Lambda(\va,q)$. This is done in the first two subsections, with elementary lattice arguments. In~\S\ref{sec:mainprop} we prove the main-term property, and at the end of the section the mass bound. \subsection{\texorpdfstring{\orev{Lattices attached to a fraction}}{Lattices attached to a fraction}} To prove Theorem~\ref{thm:symbol} we need some properties of the lattices $\Lambda(\va,q)$ and $\Lp(\va,q)=\{\vnu\in\ZZ^3:\ q\mid\vnu\cdot\va\}$. \rev{Geometrically, $\Lambda(\va,q)$ consists of the integer vectors $\vrho$ which are congruent modulo $q$ to a multiple of $\va$; when the multiple is coprime to $q$, the rational line $\RR\vrho$ passes through the point $\va/q$ of the torus $\RR^3/\ZZ^3$. Similarly $\Lp(\va,q)$ consists of the normal vectors $\vnu$ for which $\va/q$ lies on one of the parallel planes $\vnu\cdot\vx\in\ZZ$. Part~(iii) is the reason why the weights are invariant under $\va\mapsto\lambda\va$, which is the basis of the Kloosterman refinement.} \begin{lemma}\label{lem:lattice} Let $q\in\NN$ and $\va\in\ZZ^3$ with $\gcd(\va,q)=1$. \begin{enumerate}[label=(\roman*)] \item $\Lambda(\va,q)=\{\vrho\in\ZZ^3:\ q\mid\vrho\times\va\}$, and $\Lambda(\va,q)$ has covolume $q^2$. \item $\Lp(\va,q)=q\,\Lambda(\va,q)^*$, and $\Lp(\va,q)$ has covolume $q$. \item $\Lambda(\va,q)=\Lambda(\vb,q)$ if and only if $\vb\equiv\lambda\va\pmod q$ for some $\lambda$ with $\gcd(\lambda,q)=1$. \end{enumerate} \end{lemma} \begin{proof} Write $\va=t\va_0$ with $\va_0$ primitive. \rev{Everything is reduced to the case where $\va$ is a basis vector, by a unimodular change of coordinates.} Then $\gcd(t,q)=1$, $\Lambda(\va,q)=\Lambda(\va_0,q)$, and the conditions in (i) and (ii) do not change if $\va$ is replaced by $\va_0$. Complete $\va_0$ to a basis $\va_0,\va',\va''$ of $\ZZ^3$. Then $\Lambda(\va_0,q)=\ZZ\va_0+q\ZZ\va'+q\ZZ\va''$, which has covolume $q^2$. Since $\va_0\times\va'$ and $\va_0\times\va''$ form a basis of the primitive lattice $\va_0^\perp\cap\ZZ^3$, the cross product of $x\va_0+y\va'+z\va''$ with $\va_0$ is divisible by $q$ if and only if $q\mid y$ and $q\mid z$. This proves (i). Part~(ii) is the definition of the dual lattice. \orev{For (iii), suppose first that $\vb\equiv\lambda\va\pmod q$ with $\gcd(\lambda,q)=1$. Then $\vb\in\Lambda(\va,q)$, so $\Lambda(\vb,q)\subseteq\Lambda(\va,q)$; choosing $\lambda'$ with $\lambda\lambda'\equiv1\pmod q$ we have $\va\equiv\lambda'\vb$, and the reverse inclusion follows in the same way. Conversely, if $\Lambda(\vb,q)=\Lambda(\va,q)$, then $\vb\in\Lambda(\va,q)$, so $\vb=k\va+q\vy$ for some $k\in\ZZ$ and $\vy\in\ZZ^3$. If a prime $p$ divided both $k$ and $q$, then $p\mid\vb$, contradicting $\gcd(\vb,q)=1$. So $\gcd(k,q)=1$, and $\vb\equiv k\va\pmod q$. (This is~\cite[Lemma~4.1]{LRV} in three dimensions.)} \end{proof} The periodic parts of the terms in Proposition~\ref{prop:flag} are characters of finite abelian groups. We now write them in lowest terms. \rev{The next two lemmas are pure bookkeeping, but they are the heart of the matter: they show that, after expanding the congruence conditions of a flag term and of a plane term into additive characters and reducing each fraction to lowest terms, the flag $(\vnu,\vrho)$ is attached to the fraction $\va/q$ exactly when $\vnu\in\Lp(\va,q)$ and $\vrho\in\Lambda(\va,q)$. In other words, a flag ``belongs'' to the fractions lying on the line $\RR\vrho$ and on the plane $\vnu^\perp$, modulo $\ZZ^3$.} \begin{lemma}\label{lem:flagfreq} Let $\vnu=g\vnu_0$ with $\vnu_0$ primitive, let $\vr=e\vc\in L_\vnu$ with $\vc$ primitive, and put $G=ge$ and $\vrho=g\vr=G\vc$. Then for $q_1\in\NN$ and $\vn\in\ZZ^3$ \[ g^3e^2\,\one_{g\mid\vn}\,\one_{e\mid B_\vnu^T\vn/g}\sumstar_{a\bmod q_1}\ee_{q_1}\Bigl(\frac{a\,\vc\cdot\vn}{G}\Bigr)=\sum_{\substack{q\in\NN\\ q/\gcd(q,G)=q_1}}\ \sumstar_{\substack{\va\bmod q\\ \vrho\in\Lambda(\va,q),\ \vnu\in\Lp(\va,q)}}\ee_q(\va\cdot\vn). \] \end{lemma} \begin{proof} \rev{The left side is a sum of characters over a finite group, namely the indicator function of a lattice of $\vn$'s times a Ramanujan-type sum. We write it as one sum of characters $\ee(\vec A\cdot\vn/(Gq_1))$, identify the set of frequencies $\vec A$ by counting, and then reduce each frequency to lowest terms.} The set $\{\vn:\ g\mid\vn,\ e\mid B_\vnu^T\vn/g\}=g(\ZZ\vnu_0+e\ZZ^3)$ is a lattice of index $g^3e^2$, and its dual lattice is $G^{-1}\{\vy\in\ZZ^3:\ e\mid\vnu_0\cdot\vy\}$. Hence the left side equals $\sum_{\vec A}\ee_{Gq_1}(\vec A\cdot\vn)$, where $\vec A=a\vc+q_1\vy$ with $\gcd(a,q_1)=1$ and $\vy$ running modulo $G$ over the solutions of $e\mid\vnu_0\cdot\vy$. These $\varphi(q_1)g^3e^2$ vectors are distinct modulo $Gq_1$, and they satisfy \[ \vec A\equiv a\vc\ (\mathrm{mod}\ q_1)\text{ for some }a\text{ with }\gcd(a,q_1)=1,\qquad\vnu_0\cdot\vec A\equiv0\ (\mathrm{mod}\ q_1e). \] The number of classes modulo $Gq_1$ with these two properties is also $\varphi(q_1)g^3e^2$, so the $\vec A$ are exactly those classes. Write $\vec A/(Gq_1)=\va/q$ in lowest terms, so that $\vec A=j\va$ with $jq=Gq_1$. The first property and the primitivity of $\vc$ give $\gcd(\vec A,q_1)=1$, hence $\gcd(j,q_1)=1$, $j\mid G$, and $q=dq_1$ with $d=G/j=\gcd(q,G)$. The first property becomes $q_1\mid\vc\times\va$, which is equivalent to $q\mid\vrho\times\va$ because $\vrho=dj\vc$ and $\gcd(j,q_1)=1$; by Lemma~\ref{lem:lattice}(i) this says $\vrho\in\Lambda(\va,q)$. Multiplying the second property by $g$ gives $q_1dj\mid j\,\vnu\cdot\va$, that is, $q\mid\vnu\cdot\va$. The converse is proved by reversing these steps. \end{proof} \begin{lemma}\label{lem:planefreq} Let $\vnu=g\vnu_0$ with $\vnu_0$ primitive. For $e'\in\NN$ and $\vn\in\ZZ^3$ \[ g^3e'^2\,\one_{g\mid\vn}\,\one_{e'\mid B_\vnu^T\vn/g}=\sum_{q\mid ge'}\ \sumstar_{\substack{\va\bmod q\\ \vnu\in\Lp(\va,q)}}\ee_q(\va\cdot\vn). \] For a given $q$, the $e'$ with $q\mid ge'$ are those with $ge'=qkj$ for some $j\in\NN$, where $k=g/\gcd(g,q)$. \end{lemma} \begin{proof} As in the previous proof, the left side equals $\sum_\vy\ee_{ge'}(\vy\cdot\vn)$ over $\vy$ modulo $ge'$ with $e'\mid\vnu_0\cdot\vy$. Writing $\vy=j\va$ in lowest terms with $jq=ge'$, the condition $e'\mid j\vnu_0\cdot\va$ is equivalent to $ge'\mid j\,\vnu\cdot\va$, that is, to $q\mid\vnu\cdot\va$. \end{proof} \subsection{\texorpdfstring{\orev{The weight attached to a fraction}}{The weight attached to a fraction}} We are now ready to state the formula for $p_{\Lambda(\va,q)}$. \rev{It is obtained by collecting, for each reduced fraction $\va/q$, all the contributions which Lemmas~\ref{lem:flagfreq} and~\ref{lem:planefreq} attach to it.} For $q\in\NN$ and $\va\in\ZZ^3$ with $\gcd(\va,q)=1$ we define \begin{multline}\label{eq:pLambda} p_{\Lambda(\va,q)}(\vw)=p_{1,q}(\vw)+\sum_{\substack{\vnu\in\Lp(\va,q)\\ k=\gcd(\vnu)/\gcd(\vnu,q)}}\omega\Bigl(\frac{|\vnu|}{Q^{1/3}}\Bigr)p_{2,\vnu,k,q}(\vw)\\ +\sum_{\substack{(\vnu,\vrho)\ \text{flag},\ \vnu\in\Lp(\va,q),\ \vrho\in\Lambda(\va,q)\\ k=\gcd(\vrho)/\gcd(\vrho,q)}}\omega\Bigl(\frac{|\vnu|}{Q^{1/3}}\Bigr)\omega\Bigl(\frac{|\vrho|}{Q^{2/3}}\Bigr)p_{3,\vnu,\vrho,k,q}(\vw), \end{multline} with the $p$-functions of~\eqref{eq:p1}--\eqref{eq:p3}. By Lemma~\ref{lem:lattice}, the conditions $\vnu\in\Lp(\va,q)$ and $\vrho\in\Lambda(\va,q)$ depend only on the lattice $\Lambda(\va,q)$, and so does $p_{\Lambda(\va,q)}$. The sums are finite. \rev{The next lemma shows that the weight attached to $\va/q$ is concentrated on the ball of radius $r_q=(qQ^{1/3})^{-1}$ around $\va/q$, up to the harmless factor $Q^\varepsilon$. This is the three-dimensional analogue of the arcs of the classical circle method, and $r_q$ is exactly the radius suggested by Dirichlet's theorem in $\RR^3$.} \begin{lemma}\label{lem:concentration} Let $1\leqslant q\leqslant Q$ and $\gcd(\va,q)=1$, and put $r_q=(qQ^{1/3})^{-1}$. Then $p_{\Lambda(\va,q)}(\vw)\ll Q^{4}$, and for any $\varepsilon,N>0$ \[ p_{\Lambda(\va,q)}(\vw)\ll_{\varepsilon,N}Q^{-N}(1+|\vw|)^{-N}\qquad\text{if }|\vw|\geqslant Q^{\varepsilon}r_q . \] \end{lemma} \begin{proof} \rev{Each of the three kinds of weight decays rapidly once $\vw$ leaves a box around $\va/q$ whose longest side is at most $r_q$. So we only have to check, for each kind, that a vector $\vw$ of length at least $Q^{3\varepsilon}r_q$ is far outside the box in at least one direction.} The sums in~\eqref{eq:pLambda} have $O(Q^{7/3})$ terms, and each is $\ll Q^{1+\varepsilon}$ by Lemmas~\ref{lem:p1}--\ref{lem:p3}. Let $|\vw|\geqslant Q^{3\varepsilon}r_q$. For $p_{1,q}$ the factor $(1+|\vw|qQ^{1/3})^{-2N}$ is at most $Q^{-3\varepsilon N}(1+|\vw|)^{-N}$, as $qQ^{1/3}\geqslant1$. For $p_{2,\vnu,k,q}$, either $|\vw\times\hat\vnu|\geqslant|\vw|/2$, and then $|\vw\times\hat\vnu|kqQ^{1/3}\geqslant Q^{3\varepsilon}/2$, or \[ |\vw\cdot\hat\vnu|\geqslant|\vw|/2\geqslant Q^{3\varepsilon}Q^{-4/3}. \] The same alternative holds for $p_{3,\vnu,\vrho,k,q}$ with $\hat\vrho$ in place of $\hat\vnu$, and the factor $Q^{\varepsilon}$ in~\eqref{eq:p3bound} is absorbed. Replacing $3\varepsilon$ by $\varepsilon$ gives the lemma. \end{proof} \subsection{\texorpdfstring{\orev{Assembling the identity}}{Assembling the identity}} Since $\omega_0(0)=1$ we have $\delta_\vn=\omega_0(|\vn|/Q^{4/3})\delta_\vn$, and $\omega_0(|\vn|/Q^{4/3})=0$ when $|\vn|\geqslant\frac12Q^{4/3}$. We multiply Proposition~\ref{prop:flag} by $\omega_0(|\vn|/Q^{4/3})$; for $|\vn|\geqslant\frac12Q^{4/3}$ both sides of the resulting identity vanish. We treat the three terms in turn. \rev{In each case the plan is the same: Lemma~\ref{lem:flagfreq} or~\ref{lem:planefreq} rewrites the congruence conditions as a sum over reduced fractions $\va/q$, the smooth factor which remains is a function of $\vn$ supported in $|\vn|<\frac12Q^{4/3}$, and Fourier inversion turns it into the corresponding $p$-function. The only thing to check is that no modulus larger than $Q$ appears.} \emph{The term~\eqref{eq:flagterm}.} Replace $\vr$ by $\vrho=g\vr$. Then $(\vnu,\vrho)$ runs over the flags, $\omega(|\vr|/\varrho_\vnu)=\omega(|\vrho|/Q^{2/3})$, and $\gcd(\vrho)=ge=G$. By Lemma~\ref{lem:flagfreq}, and since $Gq_1=kq$ with $k=G/\gcd(q,G)$ when $q=\gcd(q,G)q_1$, the term equals \[ \sum_{q\in\NN}\ \sumstar_{\va\bmod q}\ee_q(\va\cdot\vn)\!\!\sum_{\substack{(\vnu,\vrho)\ \text{flag}\\ \vnu\in\Lp(\va,q),\ \vrho\in\Lambda(\va,q)}}\!\!\omega\Bigl(\frac{|\vnu|}{Q^{1/3}}\Bigr)\omega\Bigl(\frac{|\vrho|}{Q^{2/3}}\Bigr)\frac{c_2c_3|\vnu|}{Q^{13/3}}\,\omega_0\Bigl(\frac{|\vn|}{Q^{4/3}}\Bigr)h\Bigl(\frac{kq}{Q},\frac{\vrho\cdot\vn}{Q^2}\Bigr). \] The function $\vx\mapsto\omega_0(|\vx|/Q^{4/3})h(kq/Q,\vrho\cdot\vx/Q^2)$ vanishes identically when $kq\geqslant Q$, since $|\vrho\cdot\vx|/Q^2<\frac12$ on the support of $\omega_0$. So only $q\leqslant Q$ occur, and Fourier inversion in $\vn$ gives the flag part of~\eqref{eq:pLambda}. \emph{The term~\eqref{eq:planeterm}.} By Lemma~\ref{lem:planefreq}, writing $ge'=qkj$, the coefficient of $\ee_q(\va\cdot\vn)$ for $\vnu\in\Lp(\va,q)$ is \[ -\frac{2c_2c_3|\vnu|g}{Q^{7/3}}\sum_{j\in\NN}\frac1{g^3e'^2}\,\omega\Bigl(\frac{|\vn\times\vnu_0|}{e'Q^{2/3}}\Bigr)=-\frac{2c_2c_3|\vnu|}{Q^{7/3}}\sum_{j\in\NN}\frac{1}{(qkj)^2}\,\omega\Bigl(\frac{|\vn\times\vnu|}{qkjQ^{2/3}}\Bigr). \] On the supports of $\omega_0(|\vn|/Q^{4/3})$ and $\omega$ we have $qkj<2|\vn||\vnu|/Q^{2/3}Q^{\delta}r_q\geqslant\rho_0$, so every term of $\Sigma(\va,q)$ is covered by the claim, and $\Sigma(\va,q)\ll_NQ^{-N}$. If $\va/q\equiv\va^*/q^*$, then $q=q^*$ and $\va\equiv\va^*\pmod{q^*}$, so this pair occurs exactly once; then $\vtheta\in\ZZ^3$, and the terms with $\vk\neq\vtheta$ satisfy $|\vk-\vtheta|\geqslant1\geqslant\rho_0$ and are negligible by the claim. Since there are at most $Q^4$ pairs $(\va,q)$, we conclude that \[ g(\vzero)=\hat\Psi_{\va^*,q^*}(\vzero)+O_N(Q^{-N}). \] Finally \[ \hat\Psi_{\va^*,q^*}(\vzero)=\int\Phi_{\va^*,q^*}(\vy)g(\vy/T)\,d\vy=\int p_{\Lambda(\va^*,q^*)}(\vw)\,T^3\hat g(-T\vw)\,d\vw. \] \end{proof} \begin{remark}\label{rem:otherdims} The proof uses only that the identity holds for all $\vn$ with an error independent of $\vn$, that the weight of $\va/q$ is concentrated within $Q^{\varepsilon}(qQ^{1/R})^{-1}$ of $\va/q$, where $R$ is the dimension, and that it is polynomially bounded. Two distinct fractions with denominators $q\leqslant Q$ and $q^*$ are at distance at least $1/(qq^*)$, so the argument gives the main-term property for $q^*s$ (and over $\overline\QQ$), a root of $G$ has multiplicity at least $3$ if and only if $G$ and its three second partial derivatives $G_{xx},G_{xy},G_{yy}$ all vanish there. Since $\vnu_0\notin\cN_F$, at each of the at most $s$ roots of $G$ in $\PP^1(\overline\QQ)$ the vector $(G_{xx},G_{xy},G_{yy})$ is non-zero. The integer pairs $(t_1,t_2)$ for which $G_{xx}+t_1G_{xy}+t_2G_{yy}$ vanishes at one of these roots lie on at most $s$ lines in $\RR^2$. Each line contains at most $s+1$ points of $\{0,\dots,s\}^2$, so we may choose $t_1,t_2\in\{0,\dots,s\}$ off all of them. Put $A=G_{xx}+t_1G_{xy}+t_2G_{yy}$ and let $R_{\vnu_0}=\operatorname{Res}(A,G)$ be the resultant of the binary forms $A$ and $G$. It is non-zero because $A$ and $G$ have no common root in $\PP^1(\overline\QQ)$. It is a polynomial of bounded degree in the coefficients, so $|R_{\vnu_0}|\ll|\vnu_0|^{C}$. If $p\nmid R_{\vnu_0}$, then the reductions of $A$ and $G$ have no common root in $\PP^1(\overline\FF_p)$; in particular $G$ is non-zero modulo $p$, since otherwise the resultant would vanish modulo $p$. If moreover $p>s$, a root of $G$ modulo $p$ of multiplicity at least $3$ would be a common root of $G$ and $A$ modulo $p$. This proves (ii), since $D_F$ is divisible by all primes $p\leqslant s$. \end{proof} The discriminant curve may contain lines, including lines defined over $\QQ$. The following lemma describes exactly when this happens; we use it in~\S\ref{sec:smallq}. \begin{lemma}\label{lem:lineinDelta} Let $k$ be an algebraically closed field of characteristic $0$, and let $\ell\subset\PP^2$ be a line with $\Delta|_\ell\equiv0$, spanned by $[\vbeta_1],[\vbeta_2]$. Then the members of the pencil $\ell$ have a common kernel vector: there is $\bx_0\in k^s\setminus\{\bzero\}$, unique up to scaling, with $M_{\vbeta_1}\bx_0=M_{\vbeta_2}\bx_0=\bzero$; moreover $F_\vgamma(\bx_0)\neq0$ for every $\vgamma\notin\ell$. If $\ell$ is defined over $\QQ$, then $\bx_0$ may be taken primitive in $\ZZ^s$, and after a unimodular change of variables with $\bx_0=\be_1$ the system takes the form \[ F_{\vbeta_1}=G_1(\bx'),\qquad F_{\vbeta_2}=G_2(\bx'),\qquad F_{\vgamma}=cx_1^2+2x_1L(\bx')+G_3(\bx'), \] with $\bx'=(x_2,\dots,x_s)$, quadratic forms $G_i$, a linear form $L$ and $c=F_\vgamma(\bx_0)\neq0$. Conversely, every system of this shape has $\ell$ in its discriminant curve. \end{lemma} \begin{proof} \rev{A pencil of symmetric matrices whose determinant vanishes identically has a kernel vector depending polynomially on the parameter. The proof shows, using the non-singularity of the variety, that this kernel vector must in fact be constant. This is a special case of the Kronecker canonical form for pencils~\cite{Tho}, and we give a direct argument.} Write $A=M_{\vbeta_1}$ and $B=M_{\vbeta_2}$. Since $\det(sA+tB)\equiv0$, the matrix $sA+tB$ has a non-zero kernel over $k(s,t)$; clearing denominators, there is a non-zero vector $\bx(s,t)=\sum_{i=0}^{\varepsilon}s^{\varepsilon-i}t^i\bx_i$ of forms of degree $\varepsilon\geqslant0$ with $(sA+tB)\bx(s,t)\equiv\bzero$, and we take $\varepsilon$ minimal. Then $\bx(s_0,t_0)\neq\bzero$ for every $(s_0,t_0)\neq(0,0)$, for otherwise $\bx(s,t)$ would be divisible by $t_0s-s_0t$, contradicting minimality. Comparing coefficients gives \[ A\bx_0=\bzero,\qquad A\bx_i+B\bx_{i-1}=\bzero\quad(1\leqslant i\leqslant\varepsilon),\qquad B\bx_\varepsilon=\bzero. \] Suppose that $\varepsilon\geqslant1$. For $0\leqslant i\leqslant\varepsilon-1$ and $1\leqslant j\leqslant\varepsilon$ these relations give \[ \bx_i^TA\bx_j=-\bx_i^TB\bx_{j-1}=-(B\bx_i)^T\bx_{j-1}=\bx_{i+1}^TA\bx_{j-1}. \] Iterating, every $\bx_i^TA\bx_j$ equals either some $\bx_m^TA\bx_0=0$ or some $\bx_\varepsilon^TA\bx_m$, and the latter is $0$ for $m=0$ and equals $-(B\bx_\varepsilon)^T\bx_{m-1}=0$ for $m\geqslant1$. So the span $W$ of $\bx_0,\dots,\bx_\varepsilon$ is totally isotropic for $A$, and in the same way for $B$. Let $\vgamma$ complete $\vbeta_1,\vbeta_2$ to a basis. The binary form $F_\vgamma(\bx(s,t))$ has degree $2\varepsilon\geqslant2$, so it has a zero $(s_0,t_0)$ in $\PP^1(k)$ (or vanishes identically). The vector $\bw=\bx(s_0,t_0)\neq\bzero$ satisfies $F_{\vbeta_1}(\bw)=F_{\vbeta_2}(\bw)=F_\vgamma(\bw)=0$, so $[\bw]\in V$, and $(s_0A+t_0B)\bw=\bzero$, so the rows $A\bw,B\bw$ of the Jacobian matrix at $\bw$ are linearly dependent. This contradicts the non-singularity of $V$. Hence $\varepsilon=0$, and $\bx_0=\bx(s,t)$ is a common kernel vector. If $F_\vgamma(\bx_0)=0$, then $[\bx_0]\in V$ and the Jacobian matrix at $\bx_0$ has rank at most $1$, a contradiction; since $F_{\vbeta_1}(\bx_0)=F_{\vbeta_2}(\bx_0)=0$, this gives $F_\vgamma(\bx_0)\neq0$ for all $\vgamma\notin\ell$. If the common kernel had dimension at least $2$, the form $F_\vgamma$ would have a zero $\bw\neq\bzero$ on it, and the same argument would give a singular point of $V$. If $\ell$ is defined over $\QQ$ we may take $\vbeta_1,\vbeta_2\in\ZZ^3$; the common kernel of $A$ and $B$ is then a line defined over $\QQ$, spanned by a primitive $\bx_0\in\ZZ^s$, and completing $\bx_0$ to a basis of $\ZZ^s$ gives a unimodular change of variables with $\bx_0=\be_1$. In the new variables the first row and column of $A$ and $B$ vanish, which is the stated shape, with $c=F_\vgamma(\be_1)=F_\vgamma(\bx_0)$. The converse is clear, since every member of the pencil then has $\be_1$ in its kernel. \end{proof} For example, if $F_i=a_ix_1^2+G_i(\bx')$ with $\va=(a_1,a_2,a_3)\neq\vzero$, then $\Delta(\vbeta)=(\va\cdot\vbeta)\det M'_\vbeta$, where $M'_\vbeta$ is the matrix of $\vbeta\cdot\mathbf G$, so the line $\va\cdot\vbeta=0$ lies in the discriminant curve; and $V$ is non-singular for a generic choice of the $G_i$. (A singular point with $x_1\neq0$ would require $\bx'$ to lie in the kernel of a member $G_\vlambda$ with $\vlambda\perp\va$, together with the three equations $a_ix_1^2+G_i(\bx')=0$; for generic $G_i$ the pencil $\{G_\vlambda:\vlambda\perp\va\}$ has finitely many singular members, each with a one-dimensional kernel, and these equations have no common solution. A singular point with $x_1=0$ would be a singular point of $G_1=G_2=G_3=0$.) So rational lines in the discriminant curve do occur. \rev{We can now say which parts of the delta symbol need special attention. A flag term with direction $\vc$ collects fractions $\va/q$ close to the line through $\vc$, so the exponential sums it produces behave like Gauss sums for the form $F_\vc$; if $F_\vc$ is singular, these sums are larger than usual. Similarly a plane term with normal $\vnu_0$ collects fractions near the line $\ell_{\vnu_0}$ of~$\PP^2$, and it is harmless unless this line meets the discriminant curve in a degenerate way. We therefore separate these two kinds of terms.} We split \[ p_{\Lambda(\va,q)}=p^{\rm gen}_{\Lambda(\va,q)}+p^{\rm exc}_{\Lambda(\va,q)}, \] where $p^{\rm exc}_{\Lambda(\va,q)}$ consists of the terms of~\eqref{eq:pLambda} of the following two kinds: the terms $p_{2,\vnu,k,q}$ with $\vnu/\gcd(\vnu)\in\cN_F$ (Definition~\ref{def:NF}), and the terms $p_{3,\vnu,\vrho,k,q}$ with $\vrho/\gcd(\vrho)\in\cC_F$. \subsection{The unrefined method and the sums $N_i$}\label{sec:reduction} The first step towards Theorem~\ref{thm:mainA} is the following result, which uses the delta symbol of Theorem~\ref{thm:symbol} with absolute values throughout, and no average over the numerators. Its proof occupies Sections~\ref{sec:preparing}--\ref{sec:exceptional}, and it provides the framework, the notation and most of the estimates for the Kloosterman refinement in Sections~\ref{sec:kloosterman} and~\ref{sec:s22}. \begin{theorem}[the unrefined method]\label{thm:main} Under the hypotheses of Theorem~\ref{thm:mainA}, the asymptotic formula~\eqref{eq:mainasymp} holds for $s\geqslant25$, with any $\Delta<(s-24)/4$. \end{theorem} For the rest of the paper we adopt the following conventions. We let $P\geqslant1$ be a large parameter. Let $\bz_0$ be a non-zero real zero of $\vF$. Since the variety is non-singular, the Jacobian matrix of $\vF$ at $\bz_0$ has rank $3$. We fix a closed ball $U$ around $\bz_0$, not containing $\bzero$, on which the Jacobian matrix has rank $3$, and we take $w\in C_c^\infty(\RR^s)$ supported in $U$. We work with the counting function \[ N(P)=\sum_{\substack{\bx\in\ZZ^s\\ \vF(\bx)=\vzero}}w(\bx/P)=\sum_{\bx\in\ZZ^s}w(\bx/P)\,\delta_{\vF(\bx)}. \] Let $M_U=\max(1,\max_{\bx\in U}|\vF(\bx)|)$. We choose \[ Q=(4M_UP^2)^{3/4},\qquad\text{so that}\qquad Q^{4/3}=4M_UP^2, \] and $|\vF(\bx)|\leqslant\frac14Q^{4/3}$ whenever $w(\bx/P)\neq0$. We fix $\delta>0$ small and put $q_0=Q^{1/3-\delta}$. The exponential sums and integrals are \begin{align} S_q(\va,\bu)&=\sum_{\bb\bmod q}\ee_q\bigl(\va\cdot\vF(\bb)+\bb\cdot\bu\bigr),\label{eq:Sdef}\\ I_q(\vw,\bu)&=\int_{\RR^s}w\Bigl(\frac{\bx}{P}\Bigr)\ee\bigl(\vw\cdot\vF(\bx)\bigr)\ee_q(-\bx\cdot\bu)\,d\bx.\label{eq:Idef} \end{align} \begin{lemma}\label{lem:Ni} For any $N>0$ we have \[ N(P)=N_0(P)+N_1(P)+N_2(P)+O_N(P^{-N}), \] where \begin{align*} N_0(P)&=\sum_{1\leqslant q24$.} \begin{lemma}\label{lem:reduction} Let $\varepsilon>0$. With the notation above, for all sufficiently small $\delta$ we have \begin{enumerate}[label=(\alph*)] \item $N_0(P)=\fS\fJ P^{s-6}+O\bigl(P^{s-6-(s-8)/4+\varepsilon}\bigr)$ for $s\geqslant11$; \item $N_1(P)\ll P^{s-6-(s-24)/4+\varepsilon}$; \item $N_2(P)\ll P^{s-6-(s-24)/4+\varepsilon}$. \end{enumerate} \end{lemma} Part~(a) is proved in Section~\ref{sec:major}, part~(b) in Section~\ref{sec:generic}, and part~(c) in Section~\ref{sec:exceptional}. Note that $s-6-(s-24)/4=3s/4$: the bounds in (b) and (c) are the quantity $Q^{s/2}$ of Section~\ref{sec:savings}. \begin{proof}[Proof of Theorem~\ref{thm:main}] Combining Lemma~\ref{lem:Ni} with Lemma~\ref{lem:reduction}, we obtain~\eqref{eq:mainasymp} with any $\Delta<(s-24)/4$, since $(s-8)/4>(s-24)/4$. \end{proof} %====================================================================== \section{\texorpdfstring{\orev{Exponential integrals}}{Exponential integrals}}\label{sec:integrals} %====================================================================== \orev{We need two facts about the integrals:} that the integral is negligible unless the dual vector $\bu$ is small (by repeated integration by parts), and that it decays like $X^{-(s-2)/2}$ when $\vw$ is large (by stationary phase, using that every member of the net has rank at least $s-2$). \orev{Both are standard.} Recall the exponential integral $I_q(\vw,\bu)$ defined in~\eqref{eq:Idef}. After the change of variables $\bx\mapsto P\bx$ we have \begin{equation}\label{eq:Ichange} I_q(\vw,\bu)=P^s\int_{\RR^s}w(\bx)\,\ee\Bigl(P^2\vw\cdot\vF(\bx)-\frac{P}{q}\,\bx\cdot\bu\Bigr)d\bx . \end{equation} Throughout this section and later we write $X_\vw=1+P^2|\vw|$. \rev{The quantity $X_\vw$ measures how much the phase $P^2\vw\cdot\vF(\bx)$ oscillates on the support of $w$: for $|\vw|\leqslant P^{-2}$ it hardly oscillates and the integral is essentially $P^s$, while for larger $\vw$ the phase makes about $X_\vw$ turns. Lemma~\ref{lem:integrals} says that two things then happen. The dual vectors $\bu$ with $|\bu|$ much larger than $qX_\vw/P$ contribute nothing, because the linear phase $\bx\cdot\bu/q$ oscillates faster than the quadratic phase can compensate; and the integral itself shrinks by the factor $X_\vw^{-1/2}$ for each direction in which the quadratic form $\vw\cdot\vF$ is non-degenerate.} \begin{lemma}\label{lem:integrals} There is a constant $C_1$, depending on $\vF$ and $U$, such that the following holds. \begin{enumerate}[label=(\roman*)] \item If $|\bu|\geqslant C_1qX_\vw/P$, then $I_q(\vw,\bu)\ll_NP^s(P|\bu|/q)^{-N}$. \item For all $\vw$ and $\bu$ we have $I_q(\vw,\bu)\ll P^sX_\vw^{-(s-2)/2}$. \end{enumerate} \end{lemma} \begin{proof} (i) \rev{This is the principle of non-stationary phase: if the gradient of the phase never vanishes on the support of the amplitude, and is large compared with the second derivatives, then repeated integration by parts makes the integral as small as we like.} Write $\bv=\bu/q$. The phase $\phi(\bx)=P^2\vw\cdot\vF(\bx)-P\bv\cdot\bx$ has gradient $P^2M_\vw\bx-P\bv$, and $|P^2M_\vw\bx|\leqslant\frac12C_1P^2|\vw|$ on $U$ for a suitable $C_1$. If $P|\bv|\geqslant C_1X_\vw$, then $|\nabla\phi|\geqslant\frac12P|\bv|$ on $U$, while all second derivatives of $\phi$ are $\ll P^2|\vw|\leqslant P|\bv|$ and the higher derivatives vanish. Integrating by parts $N$ times with the operator $(2\pi i)^{-1}|\nabla\phi|^{-2}\nabla\phi\cdot\nabla$, each step gains a factor $\ll(P|\bv|)^{-1}$. (ii) \rev{After diagonalising the quadratic form $\vw\cdot\vF$ by an orthogonal change of variables, the integral becomes a product-like integral of one-dimensional Fresnel integrals $\int\ee(\beta y^2+by)\,\psi(y)\,dy$, each of which is $\ll|\beta|^{-1/2}$. Since every member of the net has rank at least $s-2$, at least $s-2$ of the coefficients $\beta_i$ have size $\asymp P^2|\vw|$, and this gives the factor $X_\vw^{-(s-2)/2}$. The only technical point is that the amplitude is not a product, which we handle with Parseval's identity.} Let $\vw\neq\vzero$ and let $\beta_1,\dots,\beta_s$ be the eigenvalues of the real symmetric matrix $\frac12P^2M_\vw$. By Lemma~\ref{lem:geometry}(i), $\operatorname{rank}M_{\hat\vw}\geqslant s-2$ for every unit vector $\hat\vw$. By continuity and compactness, at least $s-2$ eigenvalues of $M_{\hat\vw}$ have absolute value at least $c_F>0$ \orev{(the $(s-2)$-th largest absolute value of an eigenvalue of $M_{\hat\vw}$ is a continuous function of $\hat\vw$, positive on the unit sphere, hence bounded below there)}, and so at least $s-2$ of the $|\beta_i|$ are $\geqslant\frac12c_FP^2|\vw|$. It therefore suffices to show that \[ \Bigl|\int_{\RR^s}\psi(\by)\,\ee\Bigl(\sum_i\beta_iy_i^2+\bb\cdot\by\Bigr)d\by\Bigr|\ll_\psi\prod_{|\beta_i|\geqslant1}|\beta_i|^{-1/2} \] for every smooth compactly supported $\psi$, uniformly in $\bb\in\RR^s$; we apply this with $\psi(\by)=w(O\by)$ for an orthogonal matrix $O$ which diagonalises $M_\vw$, and the bounds for the derivatives of $\psi$ are uniform in $O$. Split $\by=(\by',\by'')$, where $\by''$ consists of the coordinates with $|\beta_i|\geqslant1$. For fixed $\by'$, Parseval's identity and the formula for the Fourier transform of $\ee(\beta t^2)$ give \[ \Bigl|\int\psi(\by',\by'')\,\ee\Bigl(\sum\nolimits''\beta_iy_i^2+\bb''\cdot\by''\Bigr)d\by''\Bigr|\leqslant\bigl\|\widehat{\psi(\by',\cdot)}\bigr\|_{L^1}\prod\nolimits''|2\beta_i|^{-1/2}, \] and $\|\widehat{\psi(\by',\cdot)}\|_{L^1}$ is bounded uniformly in $\by'$. Integrating over $\by'$ in a bounded set gives the claim. \end{proof} The bound~(ii) loses the factor $X_\vw$ for the two eigenvalues which may be small. For a pair of quadrics the corresponding loss concerns one eigenvalue, and in~\cite[(5.10) and \S6]{LRV} it is controlled through the distance of $\vw$ from the directions of the singular members of the pencil; we do not need such a refinement here. \subsection{The zero frequency} \rev{For the main term we need the integral $I_q(\vw,\bzero)$ integrated against the weight $p_{\Lambda(\va,q)}$. The point of the next lemma is that this integral can be evaluated exactly, in terms of the density $\sigma$ of the values of $\vF$, and that the main-term property of the delta symbol turns it into the singular integral.} Let \[ \sigma(\vt)=\int_{\vF(\bx)=\vt}w(\bx)\,\frac{d\mathcal H^{s-3}(\bx)}{\sqrt{\det\bigl(J(\bx)J(\bx)^T\bigr)}}\qquad(\vt\in\RR^3) \] be the density of the push-forward of the measure $w(\bx)\,d\bx$ under $\vF$, where $J$ is the Jacobian matrix of $\vF$ and $\mathcal H^{s-3}$ is the Hausdorff measure. Since $\vF$ is a submersion on $U$, the function $\sigma$ is smooth with compact support, and $\int w(\bx)f(\vF(\bx))\,d\bx=\int_{\RR^3}f(\vt)\sigma(\vt)\,d\vt$ for continuous $f$. The singular integral is \begin{equation}\label{eq:singint} \fJ=\sigma(\vzero)=\lim_{\eta\to0}(2\eta)^{-3}\int_{\max_i|F_i(\bx)|\leqslant\eta}w(\bx)\,d\bx . \end{equation} \begin{lemma}\label{lem:zeroterm} For $\gcd(\va,q)=1$ we have \[ \int_{\RR^3}p_{\Lambda(\va,q)}(\vw)\,I_q(\vw,\bzero)\,d\vw=P^{s-6}\int_{\RR^3}\Phi_{\va,q}(\vy)\,\sigma(\vy/P^2)\,d\vy, \] with $\Phi_{\va,q}$ as in Section~\ref{sec:mainprop}. If $qm$, so the set in question lies in a ball of measure at most $p^{-m}$. In the remaining case $v(\alpha)<\min(0,v(\beta))$, and then $v(h(t))=v(\alpha)<0$ for all $t\in\ZZ_p$, so the set is empty. \end{proof} The following lemma describes how often $\Delta$ is highly divisible by $p$ near a given point. It is the only place where the geometry of the net enters the local analysis. \begin{lemma}\label{lem:localval} Let $p$ be good, $k\geqslant1$, let $\vx_0\in\ZZ_p^3$ be primitive, and let $B=\vx_0+p^k\ZZ_p^3$. Let $r$ be the corank of $M_{\vx_0}$ modulo $p$. Then for every integer $j\geqslant0$, \[ \frac{\mu(B\cap\{v(\Delta)\geqslant j\})}{\mu(B)}\leqslant\begin{cases}\one_{j=0}&\text{if }r=0,\\ \min(1,p^{k-j})&\text{if }r=1,\\ \min(1,2p^{k-j/2})&\text{if }r=2.\end{cases} \] \end{lemma} \begin{proof} \rev{We expand $\Delta$ around $\vx_0$ in a Taylor series. If $r=1$ the linear term has a unit coefficient (the point is a smooth point of the curve modulo $p$), and Hensel's lemma shows that $\Delta$ is equidistributed $p$-adically. If $r=2$ the linear term vanishes modulo $p$ but the quadratic term does not, by Lemma~\ref{lem:geometry}(v), and we restrict to lines on which the quadratic term is non-zero and apply Lemma~\ref{lem:padicquad}.} Write $\vx=\vx_0+p^k\vy$ with $\vy\in\ZZ_p^3$, so that $\mu(B\cap E)/\mu(B)$ is the $\vy$-measure of the corresponding set. If $r=0$, then $\Delta(\vx)\equiv\Delta(\vx_0)\not\equiv0\pmod p$ on $B$. Let $r=1$. By Lemma~\ref{lem:geometry}(ii) over $\overline\FF_p$, the gradient $\nabla\Delta(\vx_0)$ is not divisible by $p$. Since $\Delta$ has integer coefficients, \[ \Delta(\vx_0+p^k\vy)=\Delta(\vx_0)+p^k\nabla\Delta(\vx_0)\cdot\vy+p^{2k}E(\vy) \] with $E\in\ZZ_p[\vy]$. If $v(\Delta(\vx_0))2k$. Integrating over $\vy_0$ gives the claim. \end{proof} We can now average $K(\va,q)^{1/2}$. \rev{Part~(i) of the next proposition is the average over all residues, which is what the point terms need, and part~(ii) is the average over the residues on a plane $q\mid\vnu\cdot\va$, which is what the plane terms need. In part~(ii) the discriminant restricted to the plane is a binary form, and the role of the condition $\vnu_0\notin\cN_F$ is to guarantee that its roots modulo $p$ have multiplicity at most $2$, so that the heuristic above still applies. Part~(iii) collects the elementary facts we use to sum the factors $b(q)$ and $m_{\vnu_0}(q)$ over $q$.} Recall the set $\cN_F$ of exceptional directions and the integers $R_{\vnu_0}$ from~\S\ref{sec:geometry}. For a primitive $\vnu_0\notin\cN_F$ we put \[ m_{\vnu_0}(q)=\prod_{p\mid D_FR_{\vnu_0}}p^{v_p(q)} . \] \begin{proposition}\label{prop:Kloc} \begin{enumerate}[label=(\roman*)] \item For every $q\in\NN$ we have \[ \sumstar_{\va\bmod q}K(\va,q)^{1/2}\ll_\varepsilon q^{3+\varepsilon}b(q). \] \item Let $\vnu=g\vnu_0$ with $g\in\NN$ and $\vnu_0\notin\cN_F$ primitive. Then \[ \sumstar_{\substack{\va\bmod q\\ q\mid\vnu\cdot\va}}K(\va,q)^{1/2}\ll_\varepsilon q^{2+\varepsilon}\gcd(q,g)\,m_{\vnu_0}(q). \] \item For $Y\geqslant1$, every non-zero integer $N$ and every integer $R\neq0$ we have \[ \sum_{q\leqslant Y}\gcd(N,q)\leqslant Y\tau(N),\qquad\#\{m\leqslant Y:\ m\mid R^\infty\}\ll_\varepsilon(Y|R|)^{\varepsilon}, \] and consequently $\sum_{q\leqslant Y}b(q)\ll_\varepsilon Y^{1+\varepsilon}$ and \[ \sum_{q\leqslant Y}m_{\vnu_0}(q)\ll_\varepsilon Y^{1+\varepsilon}|\vnu_0|^{\varepsilon}. \] \end{enumerate} \end{proposition} \begin{proof} (iii) The first bound follows from \[ \sum_{q\leqslant Y}\gcd(N,q)\leqslant\sum_{d\mid N}d\cdot\#\{q\leqslant Y:\ d\mid q\}\leqslant Y\tau(N). \] For the second, Rankin's trick gives, for $0<\eta\leqslant1/2$, \[ \#\{m\leqslant Y:\ m\mid R^\infty\}\leqslant Y^{\eta}\sum_{m\mid R^\infty}m^{-\eta}=Y^{\eta}\prod_{p\mid R}(1-p^{-\eta})^{-1}\leqslant Y^\eta C_\eta^{\omega(R)}, \] and $C_\eta^{\omega(R)}\ll_{\eta,\varepsilon}|R|^{\varepsilon}$ because $\omega(R)\ll\log|R|/\log\log|R|$. Finally, if $m(q)$ denotes the part of $q$ composed of the primes dividing $R$, then \[ \sum_{q\leqslant Y}m(q)=\sum_{\substack{m\leqslant Y\\ m\mid R^\infty}}m\cdot\#\{q\leqslant Y:\ m(q)=m\}\leqslant Y\cdot\#\{m\leqslant Y:\ m\mid R^\infty\}, \] which gives the last two bounds, since $|R_{\vnu_0}|\ll|\vnu_0|^C$. (i) By Lemma~\ref{lem:Kbasic}(i) and the Chinese remainder theorem, both sides are multiplicative in $q$, so it suffices to consider $q=p^n$. \rev{The plan is to cover the primitive vectors by the $p^3-1$ balls of radius $p^{-1}$, sort the balls according to the corank $r\in\{0,1,2\}$ of their centre modulo $p$, and apply Lemma~\ref{lem:localval} on each ball. The balls with $r=0$ contribute the main term $1$; there are $O(p^2)$ balls with $r=1$, each contributing $O(p^{-5/2})$; and $O(p)$ balls with $r=2$, each contributing $O(np^{-2})$.} If $p$ is bad, Lemma~\ref{lem:Kpointwise}(ii) gives the bound $p^{\mu_p/2}p^{4n}$. Let $p$ be good. Since $K(\va,p^n)$ depends only on $\va$ modulo $p^n$, \[ \sumstar_{\va\bmod p^n}K(\va,p^n)^{1/2}=p^{3n}\int_{\vx\ \text{primitive}}K(\vx,p^n)^{1/2}\,d\mu(\vx). \] We split the set of primitive $\vx$ into the $p^3-1$ balls $B=\vx_0+p\ZZ_p^3$, each of measure $p^{-3}$. On each ball we use Lemma~\ref{lem:Kpointwise}(i) in the form \[ \int_BK^{1/2}\,d\mu\leqslant\int_Bp^{\min(v(\Delta),2n)/2}\,d\mu\leqslant\sum_{j=0}^{2n}p^{j/2}\mu\bigl(B\cap\{v(\Delta)\geqslant j\}\bigr), \] and Lemma~\ref{lem:localval} with $k=1$. The balls with $r=0$ contribute at most $1$ in total. On a ball with $r=1$ the right side is at most $p^{-3}(1+p^{1/2}+\sum_{j\geqslant2}p^{1-j/2})\leqslant6p^{-5/2}$. The number of such balls is at most the number of non-zero zeros of $\bar\Delta$ in $\FF_p^3$, which is at most $sp^2$, since $\bar\Delta$ is a non-zero form of degree $s$ (recall that $p\nmid D_F$, so $p$ does not divide the content of $\Delta$). On a ball with $r=2$ the right side is at most \[ p^{-3}\Bigl(1+p^{1/2}+p+\sum_{j=3}^{2n}2p\Bigr)\leqslant7(n+1)p^{-2}. \] The vectors $\bar\vx_0$ of corank $2$ lie on the lines through the points of $\cZ_2$ over $\FF_p$. These points are the common zeros in $\PP^2(\overline\FF_p)$ of the $(s-1)\times(s-1)$ minors of $M_\vbeta$, which are forms of degree $s-1$. The set is finite by Lemma~\ref{lem:geometry}(iii), so two generic linear combinations of the minors have no common component, and B\'ezout's theorem bounds the number of points by $(s-1)^2$. So there are at most $(s-1)^2(p-1)$ such balls. Altogether \[ \sumstar_{\va\bmod p^n}K(\va,p^n)^{1/2}\leqslant p^{3n}\bigl(1+6sp^{-1/2}+7s^2(n+1)p^{-1}\bigr)\leqslant p^{3n}(n+1)(1+13s^2p^{-1/2}). \] The product of $(n_p+1)(1+13s^2p^{-1/2})$ over $p^{n_p}\parallel q$ is at most \[ \tau(q)\prod_{p\mid q}(1+13s^2p^{-1/2})\ll_\varepsilon q^{\varepsilon}, \] which proves (i). (ii) Again both sides are multiplicative, and we take $q=p^n$. \rev{The structure is the same as in~(i), but now the residues lie on the plane $\vnu_0\cdot\vx\equiv0\pmod{p^{n-f}}$, so we must understand $\Delta$ on a thin neighbourhood of a plane rather than on balls. After reducing modulo $p$, everything is governed by the binary form $\bar\Delta|_{\bar\vnu_0^\perp}$, and the cases below correspond to the multiplicity $m$ of its root at the centre $\bar\vx_0$ and the corank $r$ of $M_{\vx_0}$.} Let $p^f=\gcd(p^n,g)$, so that $p^n\mid\vnu\cdot\va$ if and only if $p^{n-f}\mid\vnu_0\cdot\va$. The number of residues in question is at most $p^{3n}\cdot p^{-(n-f)}=p^{2n+f}$. If $p\mid D_FR_{\vnu_0}$, we use $K^{1/2}\leqslant c_F^{1/2}p^n$ from Lemma~\ref{lem:Kpointwise}. If $f=n$ the condition is empty and (i) applies. So let $p\nmid D_FR_{\vnu_0}$ and $n-f\geqslant1$, and put $\tau_0=n-f-1\geqslant0$. As in (i) the sum equals $p^{3n}\int_AK^{1/2}d\mu$, where $A=\{\vx\ \text{primitive}:\ v(\vnu_0\cdot\vx)\geqslant n-f\}$ has measure at most $p^{-(n-f)}$. Every $\vx\in A$ reduces to a non-zero vector of the plane $\bar\vnu_0^\perp\subset\FF_p^3$. Fix such a vector, and choose a lift $\vx_0$ of it in the lattice $\vnu_0^\perp\cap\ZZ_p^3$; this is possible because $\vnu_0$ is primitive, so that this lattice reduces onto $\bar\vnu_0^\perp$. Since $\vx_0$ is primitive, we can choose $\vw$ such that $\vx_0,\vw$ is a basis of $\vnu_0^\perp\cap\ZZ_p^3$, and $\vw_3$ with $\vnu_0\cdot\vw_3=1$; then $\vx_0,\vw,\vw_3$ is a basis of $\ZZ_p^3$. The part of $A$ in the ball $\vx_0+p\ZZ_p^3$ is \[ A_{\vx_0}=\{\vx_0+p(y_2\vx_0+y_1\vw+t\vw_3):\ y_1,y_2\in\ZZ_p,\ v(t)\geqslant\tau_0\}, \] of measure $p^{-3}p^{-\tau_0}=p^{-2}p^{-(n-f)}$. Since $\Delta$ is homogeneous of degree $s$, \[ \Delta\bigl(\vx_0+p(y_2\vx_0+y_1\vw+t\vw_3)\bigr)=(1+py_2)^s\,\Delta\bigl(\vx_0+p(y_1'\vw+t'\vw_3)\bigr) \] with $y_1'=y_1/(1+py_2)$ and $t'=t/(1+py_2)$. For fixed $y_2$, the map $(y_1,t)\mapsto(y_1',t')$ preserves measure and the condition $v(t)\geqslant\tau_0$, so it suffices to study \[ G(y_1,t)=\Delta(\vx_0+py_1\vw+pt\vw_3)=\sum_{i,l\geqslant0}p^{i+l}c_{il}\,y_1^it^l,\qquad c_{il}\in\ZZ_p, \] on $\ZZ_p\times p^{\tau_0}\ZZ_p$. The binary form $\Delta|_{\ell_{\vnu_0}}$ in the basis $\vx_0,\vw$ is congruent modulo $p$ to the restriction of $\bar\Delta$ to $\bar\vnu_0^\perp$. By the choice of $R_{\vnu_0}$ (see~\S\ref{sec:geometry}) the latter is non-zero and all its roots have multiplicity at most $2$. Let $m\in\{0,1,2\}$ be the multiplicity at $\bar\vx_0$. Then $c_{i0}\equiv0\pmod p$ for $i1+\tau_0$ it requires $v(G_0)\geqslant1+\tau_0$, and then, for fixed $y_1$, the condition on $\tau$ is that $G_0/p^{1+\tau_0}+\tau U$ has valuation at least $j-1-\tau_0$; by Hensel's lemma this has $\tau$-measure $p^{-(j-1-\tau_0)}$. Hence the relative measure of $\{v(\Delta)\geqslant j\}$ in $A_{\vx_0}$ is at most $\min(1,2p^{1-j/2})$ for $j\leqslant1+\tau_0$, and at most $2p^{1-(1+\tau_0)/2}p^{-(j-1-\tau_0)}$ for $j>1+\tau_0$. \emph{Case $m=2$ and $r=2$.} Now $\nabla\Delta(\vx_0)\equiv\vzero$, so $c_{01}\equiv c_{10}\equiv0\pmod p$, while $c_{20}$ is a unit. For fixed $t\in p^{\tau_0}\ZZ_p$, the coefficient of $y_1^2$ in $G$ is $p^2(c_{20}+O(p))$, of valuation exactly $2$, and the coefficient of $y_1^i$ for $i\geqslant3$ is divisible by $p^i$. Lemma~\ref{lem:padicquad} shows that the $y_1$-measure of $\{v(G)\geqslant j\}$ is at most $\min(1,2p^{1-j/2})$, uniformly in $t$. In every case \[ \frac{1}{\mu(A_{\vx_0})}\int_{A_{\vx_0}}K^{1/2}\,d\mu\leqslant\sum_{j=0}^{2n}p^{j/2}\,\frac{\mu(A_{\vx_0}\cap\{v(\Delta)\geqslant j\})}{\mu(A_{\vx_0})}\leqslant C(n+1)p, \] and it is $1$ when $m=0$. In the third case this uses \[ \sum_{j>1+\tau_0}p^{j/2}\cdot2p^{1-(1+\tau_0)/2}p^{-(j-1-\tau_0)}=2p\sum_{i\geqslant1}p^{-i/2}\leqslant6p . \] There are at most $p^2$ vectors $\bar\vx_0$, and at most $s(p-1)$ of them have $m\geqslant1$, because $\bar\Delta|_{\bar\vnu_0^\perp}$ is a non-zero binary form of degree $s$. Since $\mu(A_{\vx_0})=p^{-2}\mu(A)$ up to a bounded factor, we obtain \[ \int_AK^{1/2}\,d\mu\leqslant\mu(A)\bigl(1+Cs(n+1)\bigr), \] and hence the sum is at most $p^{2n+f}(1+Cs(n+1))$. Taking the product over the primes dividing $q$ proves (ii). \end{proof} The proof shows where the exceptional directions come from. If the plane $\bar\vnu_0^\perp$ meets the discriminant curve with multiplicity $m\geqslant3$ at some point, then the residues near that point give a contribution of size about $p^{n(1-2/m)}$ relative to the expected one. This is why such planes, which are finite in number over $\overline\QQ$, are treated separately in Section~\ref{sec:exceptional}, and why the finitely many primes dividing $R_{\vnu_0}$ are handled crudely. %====================================================================== \section{\texorpdfstring{\orev{The main term}}{The main term}}\label{sec:major} %====================================================================== In this section we prove Lemma~\ref{lem:reduction}(a). \rev{This is the easy part of the paper. Once the main-term property of the delta symbol is available, the contribution of the small moduli and the zero dual vector factorises as a sum over $q$, which is the singular series, times an integral, which is the singular integral. The work in this section is to show that the series converges fast enough, and to interpret both factors as local densities.} We define the singular series by \begin{equation}\label{eq:singseries} \fS=\sum_{q=1}^\infty q^{-s}\sumstar_{\va\bmod q}S_q(\va,\bzero). \end{equation} By Lemma~\ref{lem:gauss} and Proposition~\ref{prop:Kloc}(i), \begin{equation}\label{eq:Aq} q^{-s}\sumstar_{\va\bmod q}|S_q(\va,\bzero)|\leqslant q^{-s/2}\sumstar_{\va\bmod q}K(\va,q)^{1/2}\ll q^{3-s/2+\varepsilon}b(q). \end{equation} Since $b(q)\leqslant q$, the series converges absolutely for $s\geqslant11$. Moreover, by Proposition~\ref{prop:Kloc}(iii) and partial summation over dyadic ranges, \begin{equation}\label{eq:Atail} \sum_{q\geqslant Y}q^{3-s/2+\varepsilon}b(q)\ll_\varepsilon Y^{4-s/2+2\varepsilon}\qquad(s\geqslant11). \end{equation} \begin{lemma}\label{lem:SJ} Let $s\geqslant11$. \begin{enumerate}[label=(\roman*)] \item We have $\fS=\prod_p\sigma_p$, where \[ \sigma_p=\lim_{e\to\infty}p^{-e(s-3)}\#\{\bx\bmod p^e:\ \vF(\bx)\equiv\vzero\pmod{p^e}\}. \] The product converges absolutely, and $\sigma_p=1+O(p^{3-s/2+\varepsilon})$. \item If the variety $F_1=F_2=F_3=0$ has a point over $\QQ_p$, then $\sigma_p>0$. Hence $\fS>0$ if it has points over every $\QQ_p$. \item If $w\geqslant0$ and $w(\bz_0)>0$, then $\fJ>0$. \end{enumerate} \end{lemma} \begin{proof} \rev{Part~(i) is the usual argument: the terms of the series are multiplicative in $q$, and the sum over the powers of a fixed prime counts solutions modulo prime powers. Part~(ii) lifts a non-singular $p$-adic point to many solutions modulo $p^e$ by Hensel's lemma, and part~(iii) is the analogous real statement.} (i) Let $A(q)=q^{-s}\sumstar_{\va\bmod q}S_q(\va,\bzero)$. By the Chinese remainder theorem $A$ is multiplicative, and by orthogonality of characters \[ \sum_{e\leqslant E}A(p^e)=p^{-E(s-3)}\#\{\bx\bmod p^E:\ \vF(\bx)\equiv\vzero\}. \] For a good prime $p$ we have $b(p^e)=1$, so~\eqref{eq:Aq} gives \[ \sum_{e\geqslant1}|A(p^e)|\ll\sum_{e\geqslant1}p^{e(3-s/2+\varepsilon)}\ll p^{3-s/2+\varepsilon}. \] For each of the finitely many bad primes, $\sum_e|A(p^e)|\ll\sum_ep^{e(4-s/2+\varepsilon)}$ converges. This gives the claims. (ii) Since the variety is non-singular, a $\QQ_p$-point can be scaled to a primitive $\bx_0\in\ZZ_p^s$ with $\vF(\bx_0)=\vzero$ at which the Jacobian matrix $J(\bx_0)$ has rank $3$. Let $\mu$ be the smallest valuation of a $3\times3$ minor of $J(\bx_0)$, put $k=2\mu+1$, and renumber the variables so that the minor formed by the first three columns has valuation $\mu$. Write $\bx=(\by,\bz)$ with $\by\in\ZZ_p^3$, $\bz\in\ZZ_p^{s-3}$, and $\bx_0=(\by_0,\bz_0)$. For $\bz\equiv\bz_0\pmod{p^k}$ the map $\by\mapsto\vF(\by,\bz)$ takes at $\by_0$ a value of valuation at least $k>2\mu$, and its Jacobian determinant at $\by_0$ is congruent modulo $p^k$ to the chosen minor, so it has valuation exactly $\mu$. By the multivariable Hensel lemma there is $\by\in\ZZ_p^3$ with $\vF(\by,\bz)=\vzero$. Hence for $e\geqslant k$ each of the $p^{(s-3)(e-k)}$ classes $\bz\bmod p^e$ with $\bz\equiv\bz_0\pmod{p^k}$ is the $\bz$-part of a solution of $\vF(\bx)\equiv\vzero\pmod{p^e}$, so \[ p^{-e(s-3)}\#\{\bx\bmod p^e:\ \vF(\bx)\equiv\vzero\}\geqslant p^{-(s-3)k} \] and $\sigma_p\geqslant p^{-(s-3)(2\mu+1)}>0$. The product $\prod_p\sigma_p$ is then positive, since by~(i) it converges absolutely and none of its factors vanishes. (iii) The singular integral $\fJ=\sigma(\vzero)$ is the integral of $w/\sqrt{\det(JJ^T)}$ over the manifold $\{\vF=\vzero\}\cap U$, which passes through $\bz_0$. \orev{This manifold is smooth of dimension $s-3$, because $J$ has rank $3$ on $U$; the integrand is continuous and non-negative, and positive at $\bz_0$, hence positive on a neighbourhood of $\bz_0$ in the manifold, which has positive $\mathcal H^{s-3}$-measure. So $\fJ>0$.} \end{proof} \begin{proof}[Proof of Lemma~\ref{lem:reduction}(a)] \rev{We use the main-term property to evaluate each integral in $N_0$, which leaves a truncated singular series; the truncation error is controlled by the tail bound~\eqref{eq:Atail}.} By Lemma~\ref{lem:zeroterm}, for $q0$ we put $r_Y=(YQ^{1/3})^{-1}$ and \begin{equation}\label{eq:fM} \fM(Y,W)=Y^2Q\min(W,r_Y)^2\min(W,Q^{-4/3})+YQ^2\min(W,r_Y)\min(W,Q^{-4/3})^2 . \end{equation} By Proposition~\ref{prop:mass}, the mass of the weights with $Y0$, and put \[ \mathcal S(Y,W)=\sum_{Y0$, \[ \mathcal S(Y,W)\ll_\varepsilon Q^{\varepsilon}\,Y\,\fM(Y,W). \] \end{proposition} \begin{proof} \begin{revblock} We follow the proof of Proposition~\ref{prop:mass}, keeping the factor $K(\va,q)^{1/2}$, and we sum over $q\in(Y,2Y]$ before summing over the vectors $\vnu$ and $\vrho$. Throughout we write $T=Q^{4/3}$ and \[ \varpi_1=\min(W,r_Y)^2\min(W,T^{-1}),\qquad \varpi_2=\min(W,r_Y)\min(W,T^{-1})^2, \] so that $Y\fM(Y,W)=Y^3Q\,\varpi_1+Y^2Q^2\,\varpi_2$. Since $r_Y/2\leqslant r_q\leqslant r_Y$ for $q\in(Y,2Y]$, we have $\min(W,r_q)\asymp\min(W,r_Y)$, and we use this without further comment. Note also that $Y\leqslant Q$, so that $Y^{\varepsilon}\leqslant Q^{\varepsilon}$. \emph{Step 1: splitting the weight.} By~\eqref{eq:pLambda} and the definition of $p^{\rm gen}_{\Lambda(\va,q)}$, and since $\omega$ is bounded, \[ \bigl|p^{\rm gen}_{\Lambda(\va,q)}\bigr|\ll|p_{1,q}|+\sum_{\substack{\vnu\in\Lp(\va,q),\ |\vnu|\leqslant Q^{1/3}\\ \vnu/\gcd(\vnu)\notin\cN_F}}|p_{2,\vnu,k,q}|+\sum_{\substack{(\vnu,\vrho)\ \text{flag},\ \vnu\in\Lp(\va,q),\ \vrho\in\Lambda(\va,q)\\ |\vnu|\leqslant Q^{1/3},\ |\vrho|\leqslant Q^{2/3},\ \vrho/\gcd(\vrho)\notin\cC_F}}|p_{3,\vnu,\vrho,k,q}|, \] with $k$ as in~\eqref{eq:pLambda}. Accordingly $\mathcal S(Y,W)\ll\mathcal S_1+\mathcal S_2+\mathcal S_3$, where $\mathcal S_1$, $\mathcal S_2$ and $\mathcal S_3$ are the contributions of the point, plane and flag weights. In $\mathcal S_2$ and $\mathcal S_3$ we interchange the order of summation, so that the sums over $\vnu$, or over the flags $(\vnu,\vrho)$, are on the outside. We recall from the proof of Proposition~\ref{prop:mass} the bounds \begin{equation}\label{eq:Kavgint} \int_{|\vw|\leqslant W}|p_{1,q}|\ll\frac Qq\,\varpi_1,\qquad\int_{|\vw|\leqslant W}|p_{2,\vnu,k,q}|\ll\frac Q{kq}\,\varpi_2,\qquad\int_{|\vw|\leqslant W}|p_{3,\vnu,\vrho,k,q}|\ll Q^{2\varepsilon}\varpi_2, \end{equation} none of which depends on $\va$. We also use repeatedly that the functions $b$ and $m_{\vnu_0}$ of Proposition~\ref{prop:Kloc} are completely multiplicative, in the sense that $b(xy)=b(x)b(y)$ and $m_{\vnu_0}(xy)=m_{\vnu_0}(x)m_{\vnu_0}(y)$ for all $x,y\in\NN$, since $v_p(xy)=v_p(x)+v_p(y)$; moreover $b(x)\leqslant x$ and $m_{\vnu_0}(x)\leqslant x$. \emph{Step 2: the point terms.} By~\eqref{eq:Kavgint} and Proposition~\ref{prop:Kloc}(i), \[ \mathcal S_1\ll\sum_{Y0$ is arbitrary, this proves the proposition. \end{revblock} \end{proof} For the flag terms the numerators $\va$ lie on the line through $\vc$ modulo $q/d$, so the average over $\va$ does not remove large values of $K(\va,q)$. They are removed instead by the average over the moduli $q$. This is a simple form of the double Kloosterman refinement of~\cite{HB}, and it is the reason why it matters that $\Delta(\vc)\neq0$: for a singular $\vc$ the factor $\gcd(\Delta(\vc),q)$ becomes $q$, and these flags are treated separately in Section~\ref{sec:exceptional}. %====================================================================== \section{\texorpdfstring{\orev{The generic terms}}{The generic terms}}\label{sec:generic} %====================================================================== \orev{For each dyadic range of $q$ and of $|\vw|$ the bound is a product of four quantities:} the number of dual vectors, the size of the exponential sum, the size of the integral, and the mass of the weights. The outcome, Lemma~\ref{lem:bookkeeping}, is that all ranges on the curve $q(1+P^2|\vw|)\asymp Q$ contribute the same amount $Q^{s/2}$, which is the computation sketched in~\S\ref{sec:savings}. In this section we prove Lemma~\ref{lem:reduction}(b). We decompose the ranges of $q$ and $\vw$ dyadically: $Y21$. With the average over $q$ as well, the error would be $P^{3s/4-3/2}$, smaller than $P^{s-6}$ for $s>18$. To carry out the average over $\lambda$, one needs the sums $\sumstar_{\lambda\bmod q}S_q(\lambda\va,\bu)$. For an odd prime $q=p$ with $p\nmid\Delta(\va)$, completing the square shows that $S_p(\lambda\va,\bu)$ is $p^{s/2}$ times a factor of modulus one which depends on $\lambda$ through the quadratic character of $\lambda^s$ and through $\ee_p(-\overline{2\lambda}\,\bu^TM_\va^{-1}\bu)$. So the average over $\lambda$ is a Gauss sum when $s$ is odd and a Ramanujan sum when $s$ is even; it saves $p^{1/2}$ when $s$ is odd, and $p$ when $s$ is even unless $p$ divides the dual form $\bu^T\operatorname{adj}(M_\va)\bu$. This is the source of the difference between even and odd $s$ in~\cite[Theorem~1.1]{LRV}, see the comments on Ramanujan sums in~\cite[\S14]{LRV}, and one may hope for $s\geqslant20$ for even $s$ here. In Sections~\ref{sec:kloosterman} and~\ref{sec:s22} we carry out the average over $\lambda$ and obtain $s\geqslant22$ for all $s$. We do not use the extra saving for even $s$; the reason is explained in~\S\ref{sec:savings}. \begin{comparison} One can also detect three equations by nesting. Applying the one-dimensional symbol to $F_1$ with modulus $q_1\leqslant P$, imposing $q_1\mid F_2$ and $q_1\mid F_3$ by additive characters as in~\cite{Mun}, and applying the two-dimensional symbol of~\cite{LRV} to $(F_2,F_3)/q_1$ with modulus $q_2\leqslant(P^2/q_1)^{2/3}$, gives total moduli $q_1q_2\leqslant P^{5/3}$ and classes of size about $q_1\cdot q_1^2\cdot q_2\leqslant P^{11/3}$. The heuristic error is $P^{(5s-11)/6}$, which is smaller than $P^{s-6}$ for $s>25$. Nesting in the other order (the two-dimensional symbol for $(F_1,F_2)$, then the one-dimensional symbol for $F_3$) gives $s>27$, and nesting the one-dimensional symbol three times gives total moduli $P^{7/4}$, classes of size $P^{17/4}$, and $s>31$. Without any average over $\va$ the nested methods give $s>36$, against $s>24$ for Theorem~\ref{thm:symbol}. \end{comparison} \begin{comparison} Iterating the duality of Lemma~\ref{lem:dual} gives an $R$-dimensional symbol for every $R$, with flags of sublattices of heights $Q^{1/R},Q^{2/R},\dots,Q^{(R-1)/R}$ and moduli $q\leqslant Q$ for vectors of size $Q^{1+1/R}$; the argument of Section~\ref{sec:mainprop} gives its main-term property (Remark~\ref{rem:otherdims}). For $R$ quadratic forms $Q=P^{2R/(R+1)}$, and the error terms are $Q^{s/2}=P^{sR/(R+1)}$ without an average over $\va$ and $P^{(s-1)R/(R+1)}$ with it. These are smaller than $P^{s-2R}$ for $s>2R(R+1)$ and $s>2R^2+R$ respectively. Since Rydin Myerson's theorem~\cite{RM} needs only $s\geqslant9R$, the delta symbol approach can improve on it only for $R\leqslant3$: \begin{center}\small \renewcommand{\arraystretch}{1.2} \begin{tabular}{cccccc} \toprule $R$ & $Q$ & no average over $\va$ & average over $\lambda\va$ & Birch & Rydin Myerson\\ \midrule $1$ & $P$ & $5$ & $4$ & $5$ & $9$\\ $2$ & $P^{4/3}$ & $13$ & $11$ & $14$ & $18$\\ $3$ & $P^{3/2}$ & $25$ & $22$ & $27$ & $27$\\ $4$ & $P^{8/5}$ & $41$ & $37$ & $44$ & $36$\\ \bottomrule \end{tabular} \end{center} The entries in the third and fourth columns are the smallest $s$ allowed by the heuristic; for $R=1,2$ and the fourth column they are the theorems of~\cite{HB} and~\cite{LRV} (with $s=10$ for even $s$ when $R=2$), and for $R=3$ they are Theorems~\ref{thm:main} and~\ref{thm:mainA}. \end{comparison} %====================================================================== \section{\texorpdfstring{\orev{The Kloosterman refinement and the case $s\geqslant23$}}{The Kloosterman refinement and the case s>=23}}\label{sec:kloosterman} %====================================================================== So far we have estimated every exponential sum by its absolute value. In this section and the next we use the fact that the weight $p_{\Lambda(\va,q)}$ is the same for all the numerators $\lambda\va$ with $\gcd(\lambda,q)=1$, so that we may sum the exponential sums over these numerators before taking absolute values. In this section we prove the following theorem. \begin{theorem}\label{thm:23} Under the hypotheses of Theorem~\ref{thm:main}, the asymptotic formula~\eqref{eq:mainasymp} holds for $s\geqslant23$, for some $\Delta=\Delta(s)>0$. \end{theorem} For $s\geqslant25$ this is Theorem~\ref{thm:main}, so only $s=23$ and $s=24$ have to be treated. The plan is that of Sections~\ref{sec:generic} and~\ref{sec:exceptional}. In each dyadic range of $q$ and of $|\vw|$ we compare each family of terms with the bound $B(Y,W)$ of the unrefined method, and we show that it is smaller than $B(Y,W)$ by a fixed power of $P$ more than is needed. For $s=23$ we need to save $P^{1/4}=Q^{1/6}$ against $B(Y,W)$ (\S\ref{sec:margin}). Two savings are available. The first comes from the sums over the numerators. For a flag term the numerators are, at most primes, a single class $\{\lambda\vc\}$, and the sum over $\lambda$ is a Gauss sum or a Ramanujan sum, which saves $q^{1/2}$ (\S\ref{sec:lambdasums}). For the point and plane terms the numerators run over all residues, or over the residues on a plane, and the complete sums over them save $q^{1/2}$ as well (\S\S\ref{sec:goodsqfree}--\ref{sec:planeprimepowers}). The second saving comes from the exponential integrals. Away from the finitely many real members of corank two the integrals decay faster than Lemma~\ref{lem:integrals} says, and on average over the directions of $\vw$ they save $X^{1/2}$, where $X=1+P^2|\vw|$ (\S\ref{sec:smallq}). On the critical curve $q(1+P^2|\vw|)\asymp Q$ the two savings together give $Q^{1/2}=P^{3/4}$. For $s=23$ this is $P^{1/2}=Q^{1/3}$ more than we need. This margin allows a simple treatment of everything that is not generic. For a flag term we keep the cancellation in the sum over $\lambda$ only at the primes which divide neither $\gcd(q,\gcd(\vrho))$ nor the discriminant of the member $\vc=\vrho/\gcd(\vrho)$. At all other primes we use nothing but the size of the Gauss sums and the fact that the dual vectors for which they do not vanish lie in a coset (Lemma~\ref{lem:gauss}). This costs at most a factor $1+K^{1/2}/L$, where $K$ is the index of the coset and $L\asymp P^{1/2}$ is the length of the range of dual vectors on the critical curve. \orev{However, the moduli on which this loss is large are rare.} A large value of $\gcd(q,\gcd(\vrho))$ forces the direction $\vc$ to be short, and the flags with short directions carry little of the mass (Lemma~\ref{lem:dmass}); and among all moduli $q$, those composed of the primes dividing a fixed integer are rare. In this way the generic flag terms are smaller than $B(Y,W)$ by $Q^{1/2}$ up to a loss of at most $Q^{1/6}$ (Proposition~\ref{prop:flagterms}). The flags whose direction is a singular member of the net are treated \orev{in the same way} in~\S\ref{sec:singflags}, with the kernel of the singular member in place of the sum over $\lambda$. In Section~\ref{sec:s22} we show that the loss $Q^{1/6}$ for the generic flag terms can be removed at the end of the critical curve where it occurs, and this gives $s=22$. \begin{revblock} \emph{A guide to this section.} The section is long, and it may help to know in advance how it is organised. \begin{itemize} \item \S\ref{sec:lambdasums} evaluates the sums over $\lambda$ at good primes (Lemma~\ref{lem:Tprime}); they are Gauss sums or Ramanujan sums times a fixed phase. \item \S\ref{sec:margin} sets up the bookkeeping: it defines the ``relative size'' of a family of terms, and says how much each family has to save (Lemma~\ref{lem:margin}). \item \S\ref{sec:refinedavg} contains the averaging lemmas, in particular Lemma~\ref{lem:Tfixedc}, which carries out the whole refinement for a single non-singular direction $\vc$. \item \S\S\ref{sec:goodsqfree}--\ref{sec:planeprimepowers} treat the point and plane terms. The cancellation is used only at primes which divide $q$ exactly once; the other primes are rare. \item \S\S\ref{sec:localfactors}--\ref{sec:flagterms} treat the generic flag terms, which carry most of the mass and are the heart of the matter. \item \S\S\ref{sec:E0count}--\ref{sec:dualquadric} count the dual vectors for which no cancellation is available. \item \S\ref{sec:smallq} improves the bound for the integrals on average over the direction of $\vw$. \item \S\S\ref{sec:exc22}--\ref{sec:singflags} return to the exceptional terms of Section~\ref{sec:exceptional}. \item \S\ref{sec:proof23} adds everything up. \end{itemize} A reader who wants the main line of the argument can read \S\S\ref{sec:lambdasums}, \ref{sec:margin}, \ref{sec:refinedavg}, \ref{sec:flagterms}, \ref{sec:smallq} and~\ref{sec:proof23} first, taking the other results on trust. \end{revblock} \subsection{Sums over \texorpdfstring{$\lambda$}{lambda}}\label{sec:lambdasums} For $q\in\NN$, $\va\in\ZZ^3$ and $\bu\in\ZZ^s$ we put \[ T_q(\va,\bu)=\sumstar_{\lambda\bmod q}S_q(\lambda\va,\bu). \] For $\va$ with $\Delta(\va)\neq0$ we write $F^*_\va(\bu)=\bu^T\operatorname{adj}(M_\va)\bu$ for the dual form of $F_\va$; it is a quadratic form in $\bu$ with integer coefficients, and $F^*_{\lambda\va}=\lambda^{s-1}F^*_\va$. \begin{lemma}\label{lem:Tmult} Let $q=q_1q_2$ with $\gcd(q_1,q_2)=1$. Then \[ S_q(\va,\bu)=S_{q_1}(q_2\va,\bu)S_{q_2}(q_1\va,\bu),\qquad T_q(\va,\bu)=T_{q_1}(q_2\va,\bu)T_{q_2}(q_1\va,\bu). \] Moreover $T_q(\mu\va,\bu)=T_q(\va,\bu)$ whenever $\gcd(\mu,q)=1$. \end{lemma} \begin{proof} \rev{This is the usual multiplicativity of complete exponential sums, from the Chinese remainder theorem.} Write $\bb=q_2\bb_1+q_1\bb_2$ with $\bb_i$ modulo $q_i$. Since $\va\cdot\vF(\bb)\equiv q_2^2\,\va\cdot\vF(\bb_1)+q_1^2\,\va\cdot\vF(\bb_2)\pmod{q}$, we get \[ \ee_q(\va\cdot\vF(\bb)+\bu\cdot\bb)=\ee_{q_1}(q_2\va\cdot\vF(\bb_1)+\bu\cdot\bb_1)\,\ee_{q_2}(q_1\va\cdot\vF(\bb_2)+\bu\cdot\bb_2), \] which gives the first identity. The second follows by writing $\lambda$ modulo $q$ as a pair of residues modulo $q_1$ and $q_2$, and the last is clear. \end{proof} For a prime power $p^e$ and an integer $t$ let $c_{p^e}(t)=\sumstar_{\mu\bmod p^e}\ee_{p^e}(\mu t)$ be the Ramanujan sum, and for odd $p$ let $g_{p^e}(t)=\sumstar_{\mu\bmod p^e}\bigl(\frac{\mu}{p}\bigr)\ee_{p^e}(\mu t)$. \rev{The next lemma is the basic computation of the Kloosterman refinement. At an odd prime $p$ which does not divide $\Delta(\va)$, completing the square shows that $S_{p^e}(\lambda\va,\bu)$ depends on $\lambda$ only through a quadratic character and a phase $\ee_{p^e}(c/\lambda)$, where $c$ is essentially the value of the dual form $F^*_\va$ at $\bu$. Summing over $\lambda$ therefore produces a Ramanujan sum or a Gauss sum in $c$, and these are small unless $c$ is divisible by a large power of $p$.} \begin{lemma}\label{lem:Tprime} Let $p$ be an odd prime, $e\geqslant1$, and $\va\in\ZZ^3$ with $p\nmid\Delta(\va)$. There is a complex number $\gamma=\gamma_{p^e}(\va)$ with $|\gamma|=p^{es/2}$ such that, for $\gcd(\lambda,p)=1$ and $\bu\in\ZZ^s$, \[ S_{p^e}(\lambda\va,\bu)=\gamma\Bigl(\frac\lambda p\Bigr)^{es}\ee_{p^e}\bigl(-\overline{2\lambda\Delta(\va)}\,F^*_\va(\bu)\bigr). \] Consequently, with $t=-\overline{2\Delta(\va)}F^*_\va(\bu)$, \[ T_{p^e}(\va,\bu)=\begin{cases}\gamma\,c_{p^e}(t)&\text{if $es$ is even},\\ \gamma\,g_{p^e}(t)&\text{if $es$ is odd},\end{cases} \] and in particular: \begin{enumerate}[label=(\roman*)] \item $|T_{p^e}(\va,\bu)|\leqslant p^{e(s+1)/2}\gcd\bigl(p^e,F^*_\va(\bu)\bigr)^{1/2}$; \item if $s$ is even, $|T_{p^e}(\va,\bu)|\leqslant p^{es/2}\gcd\bigl(p^e,F^*_\va(\bu)\bigr)$, and $T_{p^e}(\va,\bu)=0$ unless $p^{e-1}\mid F^*_\va(\bu)$; \item if $s$ and $e$ are odd, $T_{p^e}(\va,\bu)=0$ unless $p^{e-1}$ exactly divides $F^*_\va(\bu)$; in particular $T_p(\va,\bu)=0$ when $p\mid F^*_\va(\bu)$. \end{enumerate} \end{lemma} \begin{proof} \rev{We complete the square to remove the linear term $\bu\cdot\bb$, which produces the phase depending on $F^*_\va(\bu)$, and then evaluate the remaining pure Gauss sum by diagonalising $M_\va$ over $\ZZ_p$.} Write $M=M_\va$ and let $\overline M$ be the symmetric integer matrix with $M\overline M\equiv I\pmod{p^e}$; then $\overline M\equiv\overline{\Delta(\va)}\operatorname{adj}(M)\pmod{p^e}$. Since $p$ is odd and $p\nmid\lambda\Delta(\va)$, we may complete the square: replacing $\bb$ by $\bb-\overline\lambda\,\overline M\bu$, \[ \tfrac12\lambda\bb^TM\bb+\bu\cdot\bb\mapsto\tfrac12\lambda\bb^TM\bb-\overline{2\lambda}\,\bu^T\overline M\bu\pmod{p^e}. \] Hence \[ S_{p^e}(\lambda\va,\bu)=\ee_{p^e}(-\overline{2\lambda\Delta(\va)}F^*_\va(\bu))\,S_{p^e}(\lambda\va,\bzero). \] Diagonalising $M$ over $\ZZ_p$ as $\operatorname{diag}(d_1,\dots,d_s)$ with units $d_i$, $S_{p^e}(\lambda\va,\bzero)$ is the product of the one-dimensional Gauss sums \[ \sum_{x\bmod p^e}\ee_{p^e}(\frac12\lambda d_ix^2)=(\frac{\lambda d_i\overline2}{p})^eG_{p^e} \] with $|G_{p^e}|=p^{e/2}$. This gives the formula with $\gamma=(\frac{\overline{2}^s d_1\cdots d_s}{p})^eG_{p^e}^s$. Summing over $\lambda$ and substituting $\mu=\overline\lambda$, so that $(\frac\lambda p)=(\frac\mu p)$, we obtain $T_{p^e}=\gamma c_{p^e}(t)$ or $\gamma g_{p^e}(t)$. For the bounds, recall that $c_{p^e}(t)$ vanishes unless $p^{e-1}\mid t$, and $|c_{p^e}(t)|\leqslant\gcd(p^e,t)$. If $e$ is odd, the sum $g_{p^e}(t)$ vanishes unless $p^{e-1}$ exactly divides $t$, in which case $|g_{p^e}(t)|=p^{e-1/2}$; if $e$ is even, $g_{p^e}=c_{p^e}$, since then $es$ is even. In each case $|c_{p^e}(t)|$ or $|g_{p^e}(t)|$ is at most $p^{e/2}\gcd(p^e,t)^{1/2}$. Finally $\gcd(p^e,t)=\gcd(p^e,F^*_\va(\bu))$. \end{proof} For the primes dividing $2D_F\Delta(\va)$ we use the bound \[ |T_{p^e}(\va,\bu)|\leqslant\varphi(p^e)p^{es/2}K(\va,p^e)^{1/2} \] from Lemma~\ref{lem:gauss}. Combining this with Lemmas~\ref{lem:Tmult} and~\ref{lem:Tprime} we obtain the following. \begin{proposition}\label{prop:Tbound} Let $\va\in\ZZ^3$ with $\Delta(\va)\neq0$, and $q\in\NN$. Write $q=q_1q_2$, where $q_2$ is composed of the primes dividing $2D_F\Delta(\va)$ and $\gcd(q_1,2D_F\Delta(\va))=1$. Then \[ |T_q(\va,\bu)|\leqslant q^{(s+1)/2}\,\gcd\bigl(q_1,F^*_\va(\bu)\bigr)^{1/2}\,E(\va,q_2),\qquad E(\va,q_2)=\prod_{p^e\parallel q_2}p^{e/2}K(\va,p^e)^{1/2}. \] If $s$ is even, the factor $q_1^{1/2}\gcd(q_1,F^*_\va(\bu))^{1/2}$ may be replaced by $\gcd(q_1,F^*_\va(\bu))$. \end{proposition} Compared with the trivial bound $\varphi(q)q^{s/2}K(\va,q)^{1/2}$, the proposition saves the factor $(q_1/g_1)^{1/2}$, where $g_1=\gcd(q_1,F^*_\va(\bu))$, and the factor $q_1/g_1$ when $s$ is even. There is no saving when $F^*_\va(\bu)=0$, and none at the primes dividing $2D_F\Delta(\va)$. \rev{The rest of the section is about showing that these exceptional situations are rare enough: the dual vectors with $F^*_\va(\bu)=0$ lie on a quadric and are few, and the moduli with a large factor in common with $2D_F\Delta(\va)$ are rare on average over $q$.} \subsection{The savings required}\label{sec:margin} We keep the notation of Sections~\ref{sec:generic} and~\ref{sec:exceptional}. For a dyadic range $(Y,W)$ we put $X=1+P^2W$, \[ t=\frac{YX}Q\ll Q^{\varepsilon},\qquad L=2C_1P^{\varepsilon}\frac{YX}P\asymp P^{1/2+\varepsilon}t, \] and we write $B(Y,W)=P^{C\varepsilon}Y^{s/2+1}X^{s/2+1}\fM(Y,2W)$ for the bound obtained for the generic terms in the proof of Proposition~\ref{prop:N1}; by Lemma~\ref{lem:bookkeeping}, $B(Y,W)\ll P^{3s/4+C\varepsilon}t^{s/2+2}$. We say that a family of terms of $N_1(P)+N_2(P)$ has \emph{relative size at most $R=R(Y,W)$} if, for every dyadic range, its contribution from that range is $\ll P^{C\varepsilon}R\,B(Y,W)$, with $C$ depending only on $s$. If $L<1$ there are no terms with $\bu\neq\bzero$, up to $O(P^{-N})$, so we always assume $L\geqslant1$ when we discuss these terms. \begin{orevblock} We now make precise how the relative size of a family is checked. By a \emph{term} with modulus $q$ we mean one of the summands $\tau$ of~\eqref{eq:pLambda}: the point term $p_{1,q}$, a plane term $p_{2,\vnu,k,q}$ or a flag term $p_{3,\vnu,\vrho,k,q}$; we write $p_\tau$ for its weight and $\cA_\tau$ for its set of numerators, that is, the primitive $\va\bmod q$ whose $p_{\Lambda(\va,q)}$ contains $p_\tau$. Since $p_\tau$ does not depend on $\va\in\cA_\tau$, the contribution of $\tau$ to $N_1(P)+N_2(P)$ from the range $(Y,W)$ is \[ q^{-s}\sum_{\bu}\ \int_{\vw\in\mathcal W}p_\tau(\vw)\Bigl(\sum_{\va\in\cA_\tau}S_q(\va,\bu)\Bigr)I_q(\vw,\bu)\,d\vw, \] where $\mathcal W$ is the ball or shell of the range. For a weight function $0\leqslant\phi\leqslant1$ on $\RR^3$ put $m^\phi_\tau=\int_{|\vw|\leqslant2W}|p_\tau(\vw)|\phi(\vw)\,d\vw$, and $m_\tau=m^1_\tau$. \rev{In words: to show that a family has relative size $R$, it suffices to show that its sums over the numerators, summed over the dual vectors and weighted by the masses of the terms, are $R$ times their trivial bound. The integrals enter only through their size, possibly improved by the weight $\phi$ of~\S\ref{sec:smallq}.} \begin{lemma}\label{lem:relsize} Let $(Y,W)$ be a dyadic range with $L\geqslant1$, and let $\mathcal F$ be a set of terms with moduli $q\in(Y,2Y]$. Let $\phi=1$, or $\phi(\vw)=\min(1,(X\eta(\hat\vw))^{-1/2})$. If \[ \sum_{\tau\in\mathcal F}\ \sum_{0<|\bu|\leqslant L}\Bigl|\sum_{\va\in\cA_\tau}S_q(\va,\bu)\Bigr|\,m^\phi_\tau\leqslant R\,Q^{C\varepsilon}\,Y^{s/2}L^s\cdot Y\fM(Y,2W), \] then the terms of $\mathcal F$ with $\bu\neq\bzero$ contribute $\ll P^{C'\varepsilon}R\,B(Y,W)+O(P^{-N})$ from this range. Moreover $\sum_\tau\#\cA_\tau m_\tau\ll Q^{\varepsilon}Y\fM(Y,2W)$, the sum being over all terms with $q\in(Y,2Y]$, so that the right side is $R$ times the trivial bound $Y^{s/2}L^s\sum_\tau\#\cA_\tau m_\tau$ summed over all terms, up to $Q^{C\varepsilon}$. \end{lemma} \begin{proof} \rev{We bound the integrand of each term in absolute value, using the bound for the integral and the hypothesis for the sums, and then repeat the computation of Proposition~\ref{prop:N1}.} By Lemma~\ref{lem:integrals}(i) the dual vectors with $|\bu|>L$ contribute $O(P^{-N})$. For $|\bu|\leqslant L$ we bound the integrand in absolute value and use Lemma~\ref{lem:integrals}(ii), or Lemma~\ref{lem:integrals2}(ii) when $\phi\neq1$, in the form $|I_q(\vw,\bu)|\ll P^sX^{-(s-2)/2}\phi(\vw)$ on the range. So the contribution is \begin{align*} &\ll Y^{-s}P^sX^{-(s-2)/2}\sum_{\tau\in\mathcal F}\ \sum_{0<|\bu|\leqslant L}\Bigl|\sum_{\va\in\cA_\tau}S_q(\va,\bu)\Bigr|m^\phi_\tau\\ &\ll R\,Q^{C\varepsilon}Y^{-s/2}L^sP^sX^{-(s-2)/2}\,Y\fM(Y,2W). \end{align*} Since $L\ll P^{\varepsilon}YX/P$, we have $Y^{-s/2}L^sP^sX^{-(s-2)/2}\ll P^{s\varepsilon}Y^{s/2}X^{s/2+1}$, and the bound is $\ll P^{C'\varepsilon}R\,Y^{s/2+1}X^{s/2+1}\fM(Y,2W)$, which is $P^{C'\varepsilon}R\,B(Y,W)$ up to the value of $C$. The last statement is the proof of Proposition~\ref{prop:mass}, in which the masses of the point, plane and flag terms were bounded term by term. \end{proof} For the flag terms we use the lemma in the following form. Each flag term has the mass $m_\tau\ll Q^{2\varepsilon}\min(W,r_Y)\min(W,Q^{-4/3})^2$, independently of the numerator, and $Y^2Q^2\min(W,r_Y)\min(W,Q^{-4/3})^2\leqslant Y\fM(Y,2W)$ by~\eqref{eq:fM}. For the weight $\phi(\vw)=\min(1,(X\eta(\hat\vw))^{-1/2})$ we use~\eqref{eq:etashift} below: on the support of $p_{3,\vnu,\vrho,k,q}$, up to a part of mass $O(Q^{-N})$, $\phi(\vw)\ll Q^{\varepsilon}\phi(\vrho)$ with $\phi(\vrho)=\min(1,(X\eta(\hat\vc))^{-1/2})$ and $\vc=\vrho/\gcd(\vrho)$. The number of numerators of a flag term is $\#\cA^\flat$ (Lemma~\ref{lem:flagfactor} below). \end{orevblock} Put $U=Q^{1/3}$ and, for primitive $\vc$ with $|\vc|\leqslant Q^{2/3}$, \begin{equation}\label{eq:Omegaplus} Z_\vc=\frac{Q^{2/3}}{|\vc|},\qquad\Omega^+_\vc=Y^2Z_\vc\Bigl(\frac U{\lambda_1(\vc)}+\frac{U^2}{|\vc|}\Bigr), \end{equation} where $\lambda_1(\vc)$ is the length of the shortest non-zero vector of $\vc^\perp\cap\ZZ^3$. Then $\sum_\vc\Omega^+_\vc\ll Y^2Q^2\log Q$ (Lemma~\ref{lem:flagweights}). \orev{By Lemma~\ref{lem:relsize},} a family $\mathcal F$ of flag terms in the range $(Y,W)$ has relative size at most $R$ provided that \begin{equation}\label{eq:normalisation} \sum_{(\vnu,\vrho,q)\in\mathcal F}\ \sum_{0<|\bu|\leqslant L}\Bigl|\sum_{\va\in\cA^\flat}S_q(\va,\bu)\Bigr|\,\phi(\vrho)\ll Q^{C\varepsilon}R\,Y^{s/2}L^s\,Y^2Q^2, \end{equation} where $\phi(\vrho)=1$, or, if we also use the improved bound for the integrals in~\S\ref{sec:smallq}, $\phi(\vrho)=\min(1,(X\eta(\hat\vc))^{-1/2})$ with $\vc=\vrho/\gcd(\vrho)$. \orev{For the point and plane terms we use Lemma~\ref{lem:relsize} directly, with their own masses and numerators.} \rev{The next lemma translates relative sizes into the final result. A family of relative size $R$ contributes at most $R$ times the bound $P^{3s/4}t^{s/2+2}$ of the unrefined method, and the main term is $P^{s-6}$; so the saving needed is $P^{3s/4-(s-6)}=P^{(24-s)/4}$, up to the factor $t^{s/2+2}$, which is harmless off the critical curve. This is the exponent $\theta_s$.} \begin{lemma}\label{lem:margin} Let $22\leqslant s\leqslant24$ and put $\theta_s=(24-s)/4$. Suppose that the terms of $N_1(P)+N_2(P)$ are divided into $O(1)$ families, each of relative size at most $P^{-\theta_s-\kappa}t^{-s/2-2}$ for some $\kappa>0$ independent of the range. Then~\eqref{eq:mainasymp} holds with some $\Delta>0$. \end{lemma} \begin{proof} Each family contributes \[ \ll P^{C\varepsilon-\theta_s-\kappa}P^{3s/4}=P^{s-6-\kappa+C\varepsilon} \] from each of the $O((\log P)^2)$ ranges, since $3s/4-\theta_s=s-6$. Taking $\varepsilon$ small and using Lemma~\ref{lem:reduction}(a) for the main term gives the result. \end{proof} So the relative saving needed on the critical curve is as follows: \begin{center}\small \renewcommand{\arraystretch}{1.2} \begin{tabular}{cccc} \toprule $s$ & needed & from $\lambda$ and the integral & margin\\ \midrule $22$ & $P^{1/2}=Q^{1/3}$ & $Y^{1/2}X^{1/2}=Q^{1/2}$ & $P^{1/4}$\\ $23$ & $P^{1/4}=Q^{1/6}$ & $Q^{1/2}$ & $P^{1/2}$\\ $24$ & $P^{\varepsilon}$ & $Q^{1/2}$ & $P^{3/4}$\\ \bottomrule \end{tabular} \end{center} Off the curve $t$ is small, and the factor $t^{s/2+2}$ in $B(Y,W)$ absorbs the factors $t^{-1}$, $t^{-2}$ which appear below through $L$. Since $L\asymp P^{1/2+\varepsilon}t$, a loss of the shape $1+Y^{1/2}/L$ is at most $Q^{1/6+\varepsilon}t^{-1}$, which is affordable for $s\geqslant23$. The losses we meet are of three kinds: a gcd with a fixed non-zero integer, which we remove by summing over the modulus first; a power of the part of the modulus composed of the primes dividing a fixed integer, which is rare; and a power of $\gcd(q,\gcd(\vrho))$, which is controlled by Lemma~\ref{lem:dmass}. The first two are covered by the following elementary lemma, which we use repeatedly. For an integer $N\neq0$ and $x\in\NN$ write $x_N$ for the largest divisor of $x$ composed of primes dividing $N$. \begin{lemma}\label{lem:freeloss} Let $N\neq0$ be an integer and $W\geqslant1$. \begin{enumerate}[label=(\roman*)] \item $\sum_{x\leqslant W}\gcd(x,N)\leqslant W\tau(N)$, and \[ \sum_{x\leqslant W}C^{\omega(x)}\gcd(x,N)^{1/2}\ll_{C,\varepsilon}W^{1+\varepsilon}\tau(N). \] \item \[ \#\{m\leqslant W:\ m\mid N^\infty\}\ll_\varepsilon(W|N|)^{\varepsilon}. \] \item If $f\geqslant0$ is a function on the integers composed of primes dividing $N$ with $f(m)\leqslant m$, then $\sum_{x\leqslant W}f(x_N)\ll_\varepsilon W(W|N|)^{\varepsilon}$. \end{enumerate} \end{lemma} \begin{proof} \rev{These are the elementary facts behind the phrase ``removed by summing over $q$ first'': a gcd with a fixed integer is bounded on average, and so is any factor that depends only on the part of $q$ made of primes from a fixed integer.} (i) \[ \sum_{x\leqslant W}\gcd(x,N)\leqslant\sum_{d\mid N}d\,\#\{x\leqslant W:\ d\mid x\}\leqslant W\tau(N); \] the second bound follows in the same way, with $C^{\omega(x)}\ll x^{\varepsilon}$. (ii) This is Proposition~\ref{prop:Kloc}(iii) for the primes dividing $N$: the number of such $m$ is at most $\prod_{p\mid N}(1+\log W/\log p)\ll(W|N|)^{\varepsilon}$. (iii) The sum is at most $\sum_{m\mid N^\infty,\,m\leqslant W}m\cdot W/m$, and (ii) applies. \end{proof} \subsection{Sums over the numerators in each term} \rev{We now explain how the sums over $\lambda$ enter. In the unrefined method we took absolute values term by term, for each numerator $\va$. Here we use instead that each term of the delta symbol has a set of numerators which is a union of full classes $\{\lambda\va\}$, so that its sum over numerators is a sum of the complete sums $T_q$ studied above.} Every set of numerators that occurs in~\eqref{eq:pLambda} is a union of classes $\{\lambda\va\}$: the point terms use all $\va\bmod q$, the plane terms use the $\va$ with $q\mid\vnu\cdot\va$, and the flag terms use the $\va$ with $\vrho\in\Lambda(\va,q)$ and $\vnu\in\Lp(\va,q)$. Since each $p$-function is attached to the term and not to $\va$, we may sum over $\va$ inside each term, before integrating over $\vw$: \[ \sumstar_{\va\in\mathcal A}S_q(\va,\bu)=\sum_{[\va]\subseteq\mathcal A}T_q(\va,\bu)\cdot\frac{\#[\va]}{\varphi(q)}, \] where $[\va]=\{\lambda\va\bmod q\}$ runs over the classes contained in the set $\mathcal A$. For a flag $(\vnu,\vrho)$ with $\vrho=G\vc$ and $\gcd(q,G)=1$, Lemma~\ref{lem:counta}(ii) shows that $\mathcal A$ is the single class of $\vc$; when $d=\gcd(q,G)>1$ it is the union of the classes of $\lambda\vc+(q/d)\vb$ with $\vb$ modulo $d$. The exact set, which also involves the condition $\vnu\in\Lp(\va,q)$, is described in Lemma~\ref{lem:flagfactor}. \subsection{Averaging the gcd factors}\label{sec:refinedavg} The factors $\gcd(q_1,F^*_\va(\bu))^{1/2}$ and $E(\va,q_2)$ are removed on average by the following elementary lemma, applied with the sum over $q$ taken first, as in the proof of Proposition~\ref{prop:Kavg}. \begin{lemma}\label{lem:gcdavg} Let $N$ be a non-zero integer, $Y\geqslant1$, and let $f$ be a multiplicative function supported on the integers composed of primes dividing $N$, with $f(p^e)\leqslant p^{e/2}\gcd(p^e,N)^{1/2}$. Then \[ \sum_{q\leqslant Y}\gcd(q,N)^{1/2}\leqslant Y\tau(N),\qquad\sum_{q\leqslant Y}f(q)\ll_\varepsilon Y|N|^{\varepsilon}. \] \end{lemma} \begin{proof} \rev{Both bounds express the fact that a factor depending only on the part of $q$ composed of primes dividing $N$ is harmless on average, because such parts are rare.} The first bound is Proposition~\ref{prop:Kloc}(iii). For the second, write $q=q'm$ with $m$ composed of primes dividing $N$ and $\gcd(q',N)=1$. Then \[ \sum_{q\leqslant Y}f(q)\leqslant Y\sum_mf(m)/m\leqslant Y\prod_{p\mid N}\sum_{e\geqslant0}f(p^e)p^{-e}. \] If $p^v\parallel N$, then $f(p^e)p^{-e}\leqslant p^{(\min(e,v)-e)/2}$, so the inner sum is at most $v+1+\sum_{j\geqslant1}p^{-j/2}\leqslant v+4$. The product is $\leqslant4^{\omega(N)}\tau(N)\ll|N|^{\varepsilon}$. \end{proof} For a fixed member $\vc$ of the net, which is the situation of the flag terms with $\gcd(q,G)=1$, the following lemma carries out this averaging completely. Its point is that the large values of $K(\vc,q)$ are compensated by the fact that the dual vectors $\bu$ with $T_q(\vc,\bu)\neq0$ lie in a coset of index $K(\vc,q)$, exactly as in Lemma~\ref{lem:usum}. The only loss that survives is the factor $D_{s-1}(\vc)^{1/2}$ in~\eqref{eq:Tfixedc}, where $D_{s-1}(\vc)$ is the greatest common divisor of the $(s-1)\times(s-1)$ minors of $M_\vc$. \begin{lemma}\label{lem:Tfixedc} Let $\vc\in\ZZ^3$ be primitive with $\Delta(\vc)\neq0$, and put $N=2D_F\Delta(\vc)$. \begin{enumerate}[label=(\roman*)] \item For each $q$ there is a set $\cM(\vc,q)\subseteq(\ZZ/q\ZZ)^s$, either empty or a coset of a subgroup of index $K(\vc,q)$, such that $S_q(\lambda\vc,\bu)=0$ for every $\lambda$ coprime to $q$ unless $\bu\bmod q\in\cM(\vc,q)$. Moreover $\cM(\vc,q)$ depends only on $\bu$ modulo the part $q_2$ of $q$ composed of primes dividing $N$. \item For $Y,L\geqslant1$, \begin{equation}\label{eq:Tfixedc} \sum_{q\leqslant Y}\ \sum_{\substack{0<|\bu|\leqslant L\\ F^*_\vc(\bu)\neq0}}\frac{|T_q(\vc,\bu)|}{\varphi(q)q^{(s-1)/2}}\ll_\varepsilon Y^{1+\varepsilon}(|\vc|L)^{\varepsilon}\bigl(L^s+L^{s-1}D_{s-1}(\vc)^{1/2}\bigr). \end{equation} \item For $Y,L\geqslant1$, \[ \sum_{q\leqslant Y}\ \sum_{\substack{0<|\bu|\leqslant L\\ F^*_\vc(\bu)=0}}\frac{|T_q(\vc,\bu)|}{\varphi(q)q^{(s-1)/2}}\ll_\varepsilon Y^{3/2+\varepsilon}(|\vc|L)^{\varepsilon}L^{s-2}. \] \end{enumerate} \end{lemma} \begin{proof} \rev{Part~(i) observes that the coset of Lemma~\ref{lem:gauss} is the same for all the numerators $\lambda\vc$, so it restricts $\bu$ independently of $\lambda$. In part~(ii) we split $q=q_1q_2$, where $q_1$ is coprime to $N$. At the primes of $q_1$ Lemma~\ref{lem:Tprime} gives square-root cancellation up to a gcd with $F^*_\vc(\bu)$, which is $1$ on average over $q_1$; at the primes of $q_2$ we use only the size of the Gauss sums together with the coset condition from~(i), which compensates for the large values of $K(\vc,q_2)$ as in Lemma~\ref{lem:usum}. The only loss which survives is the boundary term of the coset count, which produces $D_{s-1}(\vc)^{1/2}$. Part~(iii) is the trivial bound on the quadric $F^*_\vc(\bu)=0$.} (i) By Lemma~\ref{lem:gauss}, $S_q(\lambda\vc,\bu)\neq0$ only if $\bu\bmod q\in\cM(\lambda\vc,q)$, and $\cK(\lambda\vc,q)=\cK(\vc,q)$. For $\bh\in\cK(\vc,q)$ we have $M_\vc\bh\equiv\bzero\pmod q$, hence $2F_\vc(\bh)=\bh^TM_\vc\bh\equiv0\pmod q$. If $p^e\parallel q$ with $p$ odd this gives $F_\vc(\bh)\equiv0\pmod{p^e}$, and if $p=2$ it gives $F_\vc(\bh)\equiv0\pmod{2^{e-1}}$, so that $\lambda F_\vc(\bh)\equiv F_\vc(\bh)\pmod{2^e}$ for odd $\lambda$. In both cases $F_{\lambda\vc}(\bh)\equiv F_\vc(\bh)\pmod{p^e}$, so $\cM(\lambda\vc,q)=\cM(\vc,q)$, which is empty or a coset of index $K(\vc,q)$ by Lemma~\ref{lem:gauss}. If $p\nmid N$, then $M_\vc$ is invertible modulo $p$, so $\cK(\vc,p^e)=\{\bzero\}$ and the condition at $p$ is empty. This proves (i). (ii) Write $q=q_1q_2$ with $\gcd(q_1,N)=1$ and $q_2\mid N^\infty$. By Lemma~\ref{lem:Tmult} and Lemma~\ref{lem:Tprime}(i) at the primes dividing $q_1$, and the trivial bound $|T_{p^e}|\leqslant\varphi(p^e)p^{es/2}K(\vc,p^e)^{1/2}$ at the primes dividing $q_2$ (note that $\Delta(m\vc)=m^s\Delta(\vc)$ and $F^*_{m\vc}=m^{s-1}F^*_\vc$, so the twists in Lemma~\ref{lem:Tmult} do not change the relevant gcds), we get \[ \frac{|T_q(\vc,\bu)|}{\varphi(q)q^{(s-1)/2}}\leqslant\frac{q_1}{\varphi(q_1)}\gcd\bigl(q_1,F^*_\vc(\bu)\bigr)^{1/2}\cdot q_2^{1/2}K(\vc,q_2)^{1/2}\cdot\one_{\bu\bmod q_2\in\cM(\vc,q_2)}. \] We sum first over $q_1\leqslant Y/q_2$. Since $q_1/\varphi(q_1)\ll\log\log(3q_1)$ and $\sum_{m\leqslant Z}\gcd(m,n)^{1/2}\leqslant Z\tau(n)$ for $n\neq0$, and $|F^*_\vc(\bu)|\ll|\vc|^{s-1}L^2$, the sum over $q_1$ is $\ll(Y/q_2)^{1+\varepsilon}(|\vc|L)^{\varepsilon}$. Next we sum over $\bu$: by (i) and Lemma~\ref{lem:cosets}, the number of $\bu$ with $|\bu|\leqslant L$ and $\bu\bmod q_2\in\cM(\vc,q_2)$ is $\ll L^s/K(\vc,q_2)+L^{s-1}$. Hence the left side of~\eqref{eq:Tfixedc} is \[ \ll Y^{1+\varepsilon}(|\vc|L)^{\varepsilon}\sum_{q_2\mid N^\infty}q_2^{-1/2}\Bigl(L^sK(\vc,q_2)^{-1/2}+L^{s-1}K(\vc,q_2)^{1/2}\Bigr). \] The first part is \[ \leqslant L^s\prod_{p\mid N}(1-p^{-1/2})^{-1}\ll L^s|N|^{\varepsilon}. \] For the second, Lemma~\ref{lem:Kbasic}(iv) gives $K(\vc,p^e)\leqslant p^{v_p(D_{s-1}(\vc))}p^{\min(v,e)}$ with $v=v_p(\Delta(\vc))$, so \[ \sum_{e\geqslant0}p^{-e/2}K(\vc,p^e)^{1/2}\leqslant p^{v_p(D_{s-1}(\vc))/2}\sum_{e\geqslant0}p^{(\min(v,e)-e)/2}\leqslant(v+4)\,p^{v_p(D_{s-1}(\vc))/2}, \] and the second part is \[ \leqslant L^{s-1}D_{s-1}(\vc)^{1/2}\prod_{p\mid N}(v_p(N)+4)\ll L^{s-1}D_{s-1}(\vc)^{1/2}|N|^{\varepsilon}. \] Since $|N|\ll|\vc|^s$, this proves (ii). (iii) Here $\gcd(q_1,F^*_\vc(\bu))=q_1$, and we use only $q_1^{1/2}q_2^{1/2}\leqslant Y^{1/2}$ and the count~\eqref{eq:dualcount} below for the $\bu$. It remains to bound \[ \sum_{q\leqslant Y}(q_1/\varphi(q_1))K(\vc,q_2)^{1/2}\ll Y^{1+\varepsilon}\sum_{q_2\mid N^\infty}K(\vc,q_2)^{1/2}/q_2. \] For good $p$ we have $K(\vc,p^e)\leqslant p^{\min(v,2e)}$ by Lemma~\ref{lem:Kpointwise}(i), and for bad $p$ we have $K(\vc,p^e)\leqslant p^{\mu_p+\min(v,2e)}$ by the same argument with Lemma~\ref{lem:Kpointwise}(ii). In both cases \[ \sum_ep^{-e}K(\vc,p^e)^{1/2}\ll p^{\mu_p/2}\sum_ep^{\min(v/2,e)-e}\leqslant p^{\mu_p/2}(v+2), \] and the product over $p\mid N$ is $\ll|N|^{\varepsilon}$. \end{proof} Thus for a fixed non-singular member $\vc$, and for moduli $q$ coprime to $\gcd(\vrho)$, the sum over $\lambda$ saves the full factor $q^{1/2}$ up to $Q^{\varepsilon}$, apart from the loss $D_{s-1}(\vc)^{1/2}/L$, and the dual vectors on the dual quadric cost a factor $Y^{1/2}/L^2$. In this section we do not need the bound in terms of $D_{s-1}(\vc)$: we shall only use that $K(\vc,q)\leqslant c_Fq^2$, which gives the loss $\min(Y,D_{s-1}(\vc))^{1/2}/L\leqslant Y^{1/2}/L$. The finer bound is used in Section~\ref{sec:s22}. The moduli which share a factor with $\gcd(\vrho)$ are treated in~\S\ref{sec:flagterms}. \subsection{Point and plane terms: reduction to good squarefree moduli}\label{sec:goodsqfree} For the point terms the weight is the same for all primitive $\va$ modulo $q$, and for a plane term it is the same for all primitive $\va$ with $q\mid\vnu\cdot\va$. So in these terms we may sum $S_q(\va,\bu)$ over a complete set $\cA$ of numerators before taking absolute values. The guiding principle of this subsection is to use the cancellation in this sum only at the primes $p$ with $p\parallel q$ and $p\nmid2D_F$, where it is elementary, and to use the bounds of Theorem~\ref{thm:main} at all other primes. The moduli with a large part of the second kind are rare (Lemma~\ref{lem:sqfullsum}), and at the primes of the first kind the averages over $\va$ are densities modulo $p$, so no equidistribution of $\bu$ in boxes is needed. For $\bu\in\ZZ^s$ let $f_\bu(\va)=F^*_\va(\bu)$, a ternary form of degree $s-1$ in $\va$ with integer coefficients, and let $C(\bu)$ be its content, the greatest common divisor of its coefficients. Thus $C(\bu)=0$ exactly when $\bu\in E_0$, the set defined in~\S\ref{sec:E0count}, which has dimension at most $s-3$. For primitive $\vnu_0$ choose a basis $\bw_1,\bw_2$ of $\vnu_0^\perp\cap\ZZ^3$ and let $C_{\vnu_0}(\bu)$ be the content of the binary form $(x,y)\mapsto f_\bu(x\bw_1+y\bw_2)$; it does not depend on the choice of basis. \begin{lemma}\label{lem:factorA} Let $q=\prod_pp^{n_p}$ and let $\cA\subseteq(\ZZ/q\ZZ)^3$ be a set of primitive residues of the form $\cA=\prod_p\cA_p$ under the Chinese remainder theorem, where each $\cA_p\subseteq(\ZZ/p^{n_p}\ZZ)^3$ is stable under multiplication by units. Then \[ \sum_{\va\in\cA}S_q(\va,\bu)=\prod_{p\mid q}\ \sum_{\va\in\cA_p}S_{p^{n_p}}(\va,\bu). \] The sets of numerators of the point terms and of the plane terms are of this form: for the point terms $\cA_p$ consists of all primitive residues modulo $p^{n_p}$, and for a plane term with $\vnu=g\vnu_0$ it consists of the primitive $\va$ with $p^{n_p-f}\mid\vnu_0\cdot\va$, where $p^f=\gcd(p^{n_p},g)$. \end{lemma} \begin{proof} \rev{The point is that the sets of numerators are themselves products over primes, so the sum over numerators factorises like the exponential sums.} If $q=q_1q_2$ with $\gcd(q_1,q_2)=1$, writing $\bb=q_2\bb_1+q_1\bb_2$ in the definition of $S_q$ as in the proof of Lemma~\ref{lem:Tmult} gives $S_q(\va,\bu)=S_{q_1}(q_2\va,\bu)S_{q_2}(q_1\va,\bu)$. By induction, $S_q(\va,\bu)=\prod_pS_{p^{n_p}}(m_p\va,\bu)$ with $m_p=q/p^{n_p}$. Summing over $\va\in\cA$ and substituting $\va\mapsto\overline{m_p}\va$ in the $p$-th factor, which permutes $\cA_p$, gives the formula. The descriptions of $\cA_p$ are immediate from $q\mid\vnu\cdot\va\iff p^{n_p}\mid g\vnu_0\cdot\va$ for all $p$. \end{proof} \rev{The next lemma is the local estimate at a prime $p\parallel q$. The sum over all numerators in a subspace $W$ of $\FF_p^3$ is grouped into the classes $\{\lambda\va\}$, that is, into the points of the projective space $\PP(W)$. For almost every point Lemma~\ref{lem:Tprime} gives the saving $p^{1/2}$; the exceptional points are those where $\Delta$ or the dual form $F^*_\va(\bu)$ vanishes modulo $p$, and there are few of them unless one of these forms vanishes identically on $W$.} \begin{lemma}\label{lem:onegoodprime} Let $p\nmid2D_F$ be a prime, let $W\subseteq\FF_p^3$ be a subspace of dimension $r\in\{2,3\}$, and let $\bu\in\ZZ^s$. Let $\PP(W)$ be the set of lines in $W$, of cardinality $N=(p^r-1)/(p-1)$. Then \[ \Bigl|\sum_{\va\in W\setminus\{\bzero\}}S_p(\va,\bu)\Bigr|\leqslant(p^r-1)\,p^{(s-1)/2}\cdot\frac p{p-1}\cdot\beta, \] where \[ \beta\leqslant1+2(s-1)p^{-1/2}+2s+p^{1/2}\one_{f_\bu|_W\equiv0}+p\,\one_{\Delta|_W\equiv0}+\frac{p^{3/2}}N\,n_2(W), \] and $n_2(W)\leqslant(s-1)^2$ is the number of points of $\PP(W)$ at which $M_\va$ has corank $2$ modulo $p$. \end{lemma} \begin{proof} \rev{We bound each class sum $T_p(\va,\bu)$ according to the behaviour of $F_\va$ modulo $p$, and then count the classes of each kind with the elementary bound for the number of zeros of a form over $\FF_p$.} Group the $\va\in W\setminus\{\bzero\}$ into the classes $\{\lambda\va:\lambda\in\FF_p^*\}$, so that the sum equals $\sum_{[\va]\in\PP(W)}T_p(\va,\bu)$. If $p\nmid\Delta(\va)$, Lemma~\ref{lem:Tprime} with $e=1$ gives $|T_p(\va,\bu)|\leqslant p^{s/2}\max(|c_p(t)|,|g_p(t)|)$, which is at most $p^{(s+1)/2}$ if $p\nmid F^*_\va(\bu)$ and at most $p^{(s+1)/2}p^{1/2}$ otherwise. If $p\mid\Delta(\va)$, Lemma~\ref{lem:gauss} gives \[ |T_p(\va,\bu)|\leqslant(p-1)p^{s/2}K(\va,p)^{1/2}\leqslant p^{(s+1)/2}p^{(1+k)/2}, \] where $k\in\{1,2\}$ is the corank of $M_\va$ modulo $p$ (at most $2$ by Lemma~\ref{lem:geometry}(i) over $\overline{\FF}_p$), since $K(\va,p)=p^k$ by Lemma~\ref{lem:Kbasic}(i). Hence the sum is at most $p^{(s+1)/2}N\beta$ with \[ \beta=1+\frac{p^{1/2}}N\#\{[\va]:\ p\nmid\Delta(\va),\ p\mid F^*_\va(\bu)\}+\frac1N\sum_{[\va]:\ p\mid\Delta(\va)}p^{(1+k(\va))/2}, \] and $p^{(s+1)/2}N=(p^r-1)p^{(s-1)/2}\cdot p/(p-1)$. A non-zero form of degree $d$ in $r$ variables over $\FF_p$ has at most $dp^{r-1}$ zeros in $\FF_p^r$, hence at most $2dp^{r-2}$ zeros in $\PP(W)$ when $r\geqslant2$, while $N\geqslant p^{r-1}$. If $f_\bu|_W\not\equiv0$, the first count is therefore at most $2(s-1)p^{r-2}\leqslant2(s-1)N/p$, which gives the term $2(s-1)p^{-1/2}$; otherwise we bound it by $N$, which gives $p^{1/2}$. The classes of corank $1$ contribute at most $p\cdot2sp^{r-2}/N\leqslant2s$ if $\Delta|_W\not\equiv0$, and at most $p$ otherwise. The classes of corank $2$ contribute $p^{3/2}n_2(W)/N$, and they correspond to points of $\cZ_2(\FF_p)$, of which there are at most $(s-1)^2$, as in the proof of Proposition~\ref{prop:Kloc}(i). \end{proof} For $r=3$ we have $\Delta|_W\not\equiv0$ by Lemma~\ref{lem:geometry}(iv) over $\overline{\FF}_p$, and $p^{3/2}n_2/N\leqslant(s-1)^2p^{-1/2}$, so $\beta\leqslant C_s\gcd(p,C(\bu))^{1/2}$ with $C_s=4s+(s-1)^2$. For $r=2$ and $W=\bar\vnu_0^{\,\perp}$ the three exceptional terms occur only when $p\mid C_{\vnu_0}(\bu)$, when $p$ divides the content of $G_{\vnu_0}$ (and hence $R_{\vnu_0}$), and when the line $\PP(W)$ contains a point of corank $2$. \rev{At the bad primes we cannot use the geometry of the net modulo $p$, but we can use it over $\QQ_p$. The next lemma is the analogue at bad primes of the local estimates of Section~\ref{sec:sums}, with a loss of a constant depending on $p$; since there are only finitely many bad primes, this loss is harmless.} \begin{lemma}\label{lem:Kbadprime} For every prime $p$ there is $C_p$ such that \[ \mu\{\va\in\ZZ_p^3\ \text{primitive}:\ v_p(\Delta(\va))\geqslant j\}\leqslant C_p\orev{p^{-j/2}} \] for all $j\geqslant0$. Consequently $\sumstar_{\va\bmod p^n}K(\va,p^n)^{1/2}\ll_pp^{3n}\orev{(n+1)}$ for all $n\geqslant1$. \end{lemma} \begin{proof} \begin{orevblock} For good $p$ this is contained in Lemma~\ref{lem:localval} and the proof of Proposition~\ref{prop:Kloc}(i); the argument below works for every $p$, and it is a $p$-adic version of the proof of Lemma~\ref{lem:localval} with a bounded loss. Let $\mathcal P$ be the compact set of primitive vectors in $\ZZ_p^3$. For $\vx\in\mathcal P$ and $\vb\in\ZZ_p^3$ let $Q_\vx(\vb)$ be the coefficient of $t^2$ in $\Delta(\vx+t\vb)$, a quadratic form in $\vb$ whose coefficients are polynomials in $\vx$. Let $\mathcal V=\{\be_i,\ \be_i+\be_j\}$; a quadratic form in three variables which vanishes on $\mathcal V$ vanishes identically. We first show that for every $\vx\in\mathcal P$ \[ \Delta(\vx)\neq0,\qquad\text{or}\qquad\nabla\Delta(\vx)\neq\vzero,\qquad\text{or}\qquad Q_\vx(\vv)\neq0\text{ for some }\vv\in\mathcal V. \] Indeed, $M_\vx$ has corank at most $2$ by Lemma~\ref{lem:geometry}(i) over $\overline{\QQ}_p$. If the corank is $1$, then $\nabla\Delta(\vx)\neq\vzero$ by Lemma~\ref{lem:geometry}(ii). If it is $2$, write $W=\ker M_\vx$ and use a basis of $\overline{\QQ}_p^s$ adapted to $W\oplus W'$, in which $M_\vx=\operatorname{diag}(0,N)$ with $N$ invertible; expanding the determinant gives $\Delta(\vx+t\vb)=c\,t^2\det N\det(M_\vb|_W)+O(t^3)$ with $c\neq0$ (the square of the determinant of the change of basis), so $Q_\vx(\vb)=c\det N\det(M_\vb|_W)$, which is not identically zero by Lemma~\ref{lem:geometry}(v). The function $\vx\mapsto\max\bigl(|\Delta(\vx)|_p,|\nabla\Delta(\vx)|_p,\max_{\vv\in\mathcal V}|Q_\vx(\vv)|_p\bigr)$ is continuous and positive on $\mathcal P$, so it is $\geqslant p^{-c_0}$ for some integer $c_0\geqslant0$. Put $t=c_0+1$ and cover $\mathcal P$ by the $\leqslant p^{3t}$ balls $B=\vx_0+p^t\ZZ_p^3$ with $\vx_0\in\mathcal P$. For each ball one of the three quantities at $\vx_0$ has valuation at most $c_0$, and we write $\vx=\vx_0+p^t\vy$. \emph{Case (a): $v_p(\Delta(\vx_0))\leqslant c_0$.} Then $\Delta(\vx)\equiv\Delta(\vx_0)\pmod{p^t}$, so $v_p(\Delta)=v_p(\Delta(\vx_0))\leqslant c_0$ on $B$, and $B\cap\{v_p(\Delta)\geqslant j\}=\varnothing$ for $j>c_0$. \emph{Case (b): some coordinate of $\nabla\Delta(\vx_0)$, say the first, has valuation $a\leqslant c_0$.} For fixed $y_2,y_3$ put $g(y_1)=\Delta(\vx_0+p^t\vy)$. Since $\Delta$ has integral coefficients, $g(y_1)-g(y_1')=(y_1-y_1')\,h$ with $h=p^t\partial_1\Delta(\vx_0)+p^{2t}h_1$, $h_1\in\ZZ_p$, so $v_p(h)=t+a$ because $t>a$. Hence two values $y_1,y_1'$ with $v_p(g)\geqslant j$ satisfy $v_p(y_1-y_1')\geqslant j-t-a$, and the $y_1$-measure of $\{v_p(g)\geqslant j\}$ is at most $p^{-(j-t-c_0)}$. \emph{Case (c): $v_p(Q_{\vx_0}(\vv))=e\leqslant c_0$ for some $\vv\in\mathcal V$.} The vector $\vv$ is primitive; complete it to a basis $\vv,\vw_1,\vw_2$ of $\ZZ_p^3$ and write $\vy=\tau\vv+\vy_0$ with $\vy_0\in\ZZ_p\vw_1+\ZZ_p\vw_2$. For fixed $\vy_0$ put $\vz=\vx_0+p^t\vy_0$ and $g(\tau)=\Delta(\vz+p^t\tau\vv)=\sum_iA_i\tau^i$. Then $A_i=p^{ti}c_i$ with $c_i\in\ZZ_p$ the coefficient of $u^i$ in $\Delta(\vz+u\vv)$, and $c_2=Q_\vz(\vv)\equiv Q_{\vx_0}(\vv)\pmod{p^t}$, so $v_p(c_2)=e$ and $v_p(A_2)=2t+e$. Lemma~\ref{lem:padicquad} applies to $g/A_2$, whose coefficients of $\tau^i$, $i\geqslant3$, have valuation $\geqslant t(i-2)-e\geqslant1$; so the $\tau$-measure of $\{v_p(g)\geqslant j\}$ is at most $2p^{-(j-2t-e)/2}$. In all three cases \[ \mu(B\cap\{v_p(\Delta)\geqslant j\})\leqslant2p^{t+c_0}p^{-j/2}\mu(B), \] and summing over the balls gives the first statement with $C_p=2p^{t+c_0}$. For the second, Lemma~\ref{lem:Kpointwise}(ii) and its proof give $K(\va,p^n)\leqslant p^{\mu_p}p^{\min(v_p(\Delta(\va)),2n)}$, so \[ K(\va,p^n)^{1/2}\leqslant p^{\mu_p/2}\sum_{0\leqslant j\leqslant\min(v_p(\Delta(\va)),2n)}p^{j/2}, \] and \[ \sumstar_{\va\bmod p^n}K(\va,p^n)^{1/2}\leqslant p^{3n}p^{\mu_p/2}\sum_{j\leqslant2n}p^{j/2}\mu\{v_p(\Delta)\geqslant j\}\leqslant p^{3n}p^{\mu_p/2}C_p(2n+1). \] This argument uses only Lemma~\ref{lem:geometry} over $\overline{\QQ}_p$, Hensel-type estimates and Lemma~\ref{lem:padicquad}; in particular no resolution of singularities is needed. \end{orevblock} \end{proof} \begin{lemma}\label{lem:sqfullsum} For $q\in\NN$ let $q^\flat$ be the product of the primes $p$ with $p\parallel q$ and $p\nmid2D_F$, and $q^\sharp=q/q^\flat$. Let $\kappa$ be a multiplicative function with $\kappa(p^n)\leqslant2(n+1)(1+13s^2p^{-1/2})$ for $p\nmid2D_F$ and $\kappa(p^n)\leqslant C_p(n+1)^3$ for $p\mid2D_F$. Then for any non-zero integer $N$, \[ \sum_{q\leqslant Y}(q^\sharp)^{1/2}\kappa(q^\sharp)\,C_s^{\omega(q^\flat)}\gcd(q^\flat,N)^{1/2}\ll_\varepsilon Y^{1+\varepsilon}|N|^{\varepsilon}. \] \end{lemma} \begin{proof} \rev{The square-full numbers up to $Y$ are only about $Y^{1/2}$ in number, which is exactly what is needed to compensate the factor $(q^\sharp)^{1/2}$.} Every prime factor of $q^\sharp$ divides $2D_F$ or occurs in $q^\sharp$ with exponent at least $2$. Summing first over $q^\flat\leqslant Y/q^\sharp$, using $C_s^{\omega(m)}\ll m^{\varepsilon}$ and $\sum_{m\leqslant Z}\gcd(m,N)^{1/2}\leqslant Z\tau(N)$, the sum is \[ \ll Y^{1+\varepsilon}\tau(N)\sum_{q^\sharp}\kappa(q^\sharp)(q^\sharp)^{-1/2}. \] The last sum is at most \begin{align*} &\prod_{p\mid2D_F}\sum_{n\geqslant0}C_p(n+1)^3p^{-n/2}\cdot\prod_{p\leqslant Y}\Bigl(1+\sum_{n\geqslant2}2(n+1)(1+13s^2p^{-1/2})p^{-n/2}\Bigr)\\ &\qquad\ll\prod_{p\leqslant Y}\Bigl(1+\frac{C}p\Bigr)\ll(\log Y)^C. \end{align*} \end{proof} \begin{proposition}\label{prop:pointterms} Let $\bu\in\ZZ^s$ with $C(\bu)\neq0$, and let $J(q)$ be the number of primitive residues modulo $q$. Then $|\sumstar_{\va\bmod q}S_q(\va,\bu)|\leqslant J(q)q^{(s-1)/2}A(q,\bu)$ with \[ \sum_{q\leqslant Y}A(q,\bu)\ll_\varepsilon Y^{1+\varepsilon}(1+|\bu|)^{\varepsilon}. \] \end{proposition} \begin{proof} \rev{At the primes dividing $q$ exactly once we use the cancellation of Lemma~\ref{lem:onegoodprime}, and at all other prime powers only the size of the Gauss sums, averaged over $\va$ by Proposition~\ref{prop:Kloc}(i). The resulting losses are of the two kinds that Lemma~\ref{lem:sqfullsum} controls.} By Lemma~\ref{lem:factorA} the sum is the product of its local factors. For $p\parallel q$ with $p\nmid2D_F$, Lemma~\ref{lem:onegoodprime} with $W=\FF_p^3$ and the remark after it bound the local factor by $J(p)p^{(s-1)/2}\cdot2C_s\gcd(p,C(\bu))^{1/2}$. For the other prime powers $p^n\parallel q$, Lemma~\ref{lem:gauss} gives the bound \[ p^{ns/2}\sumstar_{\va\bmod p^n}K(\va,p^n)^{1/2}=J(p^n)p^{n(s-1)/2}\cdot p^{n/2}\kappa(p^n), \] where $\kappa(p^n)=J(p^n)^{-1}\sumstar K(\va,p^n)^{1/2}$ satisfies the hypothesis of Lemma~\ref{lem:sqfullsum} by the proof of Proposition~\ref{prop:Kloc}(i) for $p\nmid2D_F$ (note $J(p^n)\geqslant p^{3n}/2$) and by Lemma~\ref{lem:Kbadprime} for $p\mid2D_F$. Hence \[ A(q,\bu)\leqslant(2C_s)^{\omega(q^\flat)}\gcd(q^\flat,C(\bu))^{1/2}(q^\sharp)^{1/2}\kappa(q^\sharp), \] and Lemma~\ref{lem:sqfullsum} with $N=C(\bu)$, which is $\ll|\bu|^{2}$, completes the proof. \end{proof} Thus for the point terms the sum over the numerators saves the full factor $q^{1/2}$ on average over $q$, for all $\bu\notin E_0$, with no condition on the size of $\bu$ relative to $q$. The vectors $\bu\in E_0$ number $\ll L^{s-3}$ in a box of side $L$. For a plane term with $\vnu=g\vnu_0$ and $p\parallel q$, $p\nmid2D_F$, the local set is $\FF_p^3\setminus\{\bzero\}$ if $p\mid g$ and $\bar\vnu_0^{\,\perp}\setminus\{\bzero\}$ otherwise, and Lemma~\ref{lem:onegoodprime} applies with $r=3$ or $r=2$. With $r=2$ its exceptional terms cost at most a factor $p$ at the primes dividing $C_{\vnu_0}(\bu)$, the content of $G_{\vnu_0}$, or the resultant $R'_{\vnu_0}$ that detects points of $\cZ_2(\FF_p)$ on the line $\bar\vnu_0^{\,\perp}$ which are not reductions of points of $\cZ_2(\overline\QQ)$ on that line; such losses are removed by summing over $q$ first (Lemma~\ref{lem:freeloss}). The part $q^\sharp$ of the modulus is treated in~\S\ref{sec:planeprimepowers} below, and the lines through rational members of corank $2$ in Proposition~\ref{prop:planeZ2}. \subsection{Plane terms at prime powers}\label{sec:planeprimepowers} At a prime power $p^n\parallel q$ with $n\geqslant2$ we give up the cancellation in the sum over the numerators, as for the point terms, and bound the local factor by $p^{ns/2}\sum_{\va\in\cA_p}K(\va,p^n)^{1/2}$. For the point terms the average of $K^{1/2}$ was bounded in Proposition~\ref{prop:Kloc}(i). For a plane term the numerators lie on the line $\vnu_0^\perp$, along which $\Delta$ is the binary form $G_{\vnu_0}$, and the average of $K^{1/2}$ along the line depends on how the roots of $G_{\vnu_0}$ cluster $p$-adically. \orev{We show that} the loss is controlled by a single non-zero integer attached to $\vnu_0$, so that it can be removed by summing over $q$ first, as in Lemma~\ref{lem:gcdavg}. We use the following notation. Let $\cO$ be the ring of integers of a finite extension of $\QQ_p$, with valuation $v$ extending $v_p$. For primitive vectors $\bz,\bz'\in\cO^2$ put $d(\bz,\bz')=v(\bz\times\bz')$, where $\bz\times\bz'=z_1z_2'-z_2z_1'$; this is the chordal distance on $\PP^1$, and it satisfies the ultrametric inequality $d(\bz,\bz'')\geqslant\min(d(\bz,\bz'),d(\bz',\bz''))$. For a non-zero binary form $G\in\ZZ[x,y]$ of degree $d$, Gauss's lemma gives a factorisation $G=p^{\kappa}u\prod_{i=1}^d(\beta_ix-\alpha_iy)$ over a suitable $\cO$, with $\kappa=v_p(\operatorname{cont}G)$, $u\in\cO^*$ and $(\alpha_i,\beta_i)$ primitive, so that \begin{equation}\label{eq:vGdist} v_p(G(\bz))=\kappa+\sum_{i=1}^dd(\bz,\boldsymbol\alpha_i)\qquad(\bz\in\ZZ_p^2\ \text{primitive}), \end{equation} with $\boldsymbol\alpha_i=(\alpha_i,\beta_i)$. Let $\delta_3(G)$ be the largest $\delta$ such that some three distinct indices $i,j,k$ have pairwise distances at least $\delta$ (so $\delta_3=\infty$ exactly when $G$ has a root of multiplicity at least $3$), and put $e_p(G)=\kappa+d\,\delta_3(G)$. \rev{The intuition is that $v_p(G(\bz))$ is the sum of the $p$-adic distances from $\bz$ to the roots of $G$, by~\eqref{eq:vGdist}. If no three roots are $p$-adically close together, then $\bz$ can be close to at most two roots at the same time, and the binary form behaves locally like a quadratic; Lemma~\ref{lem:binaryform} then gives the same square-root bound as Lemma~\ref{lem:padicquad}, with a loss $e_p(G)$ which measures how close together the roots are, and which is bounded in terms of a single non-zero integer $E_G$.} \begin{lemma}\label{lem:binaryform} Let $G\in\ZZ[x,y]$ be a non-zero binary form of degree $d$ without roots of multiplicity at least $3$, and let $\mu$ be the Haar measure on $\ZZ_p^2$. \begin{enumerate}[label=(\roman*)] \item $\delta_3(G)\leqslant v_p(\operatorname{Disc}(G^{\rm red}))$, where $G^{\rm red}$ is the primitive integral form whose roots are those of $G$, each with multiplicity one; hence $e_p(G)\leqslant v_p(E_G)$ with $E_G=\operatorname{cont}(G)\operatorname{Disc}(G^{\rm red})^d\neq0$. \item For every $j\geqslant0$, \[ \mu\{\bz\ \text{primitive}:\ v_p(G(\bz))\geqslant j\}\leqslant d\,p^{-\lceil(j-e_p(G))/2\rceil}. \] \end{enumerate} \end{lemma} \begin{proof} \rev{Part~(i) bounds the closeness of the roots by the discriminant. For part~(ii), a point $\bz$ with $v_p(G(\bz))\geqslant j$ must, by~\eqref{eq:vGdist} and the ultrametric inequality, be within distance about $(j-e_p)/2$ of one of the roots, and the set of such points has small measure.} (i) Three distinct indices involve at least two distinct roots $\boldsymbol\alpha\neq\boldsymbol\alpha'$ of $G^{\rm red}$, and the discriminant of $G^{\rm red}$ is a unit times the product of the squares of the $\boldsymbol\alpha_i\times\boldsymbol\alpha_j$ over its pairs of roots, each of which has non-negative valuation. Hence $d(\boldsymbol\alpha,\boldsymbol\alpha')\leqslant v_p(\operatorname{Disc}(G^{\rm red}))$. (ii) We may assume $j>e_p(G)$. Let $\bz$ be primitive with $v_p(G(\bz))\geqslant j$, and let $t=\max_id(\bz,\boldsymbol\alpha_i)$, attained at $i_0$. If $t\leqslant\delta_3$, then~\eqref{eq:vGdist} gives $v_p(G(\bz))\leqslant\kappa+d\delta_3\delta_3$. If two indices $k_1,k_2$ other than $i_0$ had $d(\bz,\boldsymbol\alpha_{k})>\delta_3$, then by the ultrametric inequality the three indices $i_0,k_1,k_2$ would have pairwise distances $>\delta_3$, which is impossible. So at most one index other than $i_0$ has $d(\bz,\boldsymbol\alpha_k)>\delta_3$, and for it $d(\bz,\boldsymbol\alpha_k)\leqslant t$. Thus $j\leqslant\kappa+2t+(d-2)\delta_3\leqslant e_p(G)+2t$, so \[ d(\bz,\boldsymbol\alpha_{i_0})\geqslant m:=\lceil(j-e_p(G))/2\rceil. \] If the set of primitive $\bz\in\ZZ_p^2$ with $d(\bz,\boldsymbol\alpha_i)\geqslant m$ is non-empty, it contains some $\bz_0$, and by the ultrametric inequality it equals $\{\bz:\ v_p(\bz\times\bz_0)\geqslant m\}$. Moving $\bz_0$ to $(1,0)$ by an element of $\mathrm{GL}_2(\ZZ_p)$, which preserves $\mu$, this set becomes $\{(x,y):\ p\nmid x,\ p^m\mid y\}$, of measure $(1-p^{-1})p^{-m}\leqslant p^{-m}$. Summing over the $d$ indices gives (ii). \end{proof} \rev{We now apply this to the restriction of $\Delta$ to a line. The new feature, compared with the average over all residues in Proposition~\ref{prop:Kloc}(i), is that $K(\va,p^n)$ depends on the two non-unit invariant factors of $M_\va$ separately, and not only on their product $\Delta(\va)$; the smaller of the two is controlled by the corank-two points through Lemma~\ref{lem:corank2lines}.} \begin{lemma}\label{lem:Kline} Let $p$ be a prime, let $\vnu_0\notin\cN_F$ be primitive, let $\bw_1,\bw_2$ be a basis of $\vnu_0^\perp\cap\ZZ^3$, and put $e=e_p(G_{\vnu_0})$. For $n\geqslant1$ and $0\leqslant f\leqslant n$ let $\cA_p$ be the set of primitive $\va\bmod p^n$ with $p^{n-f}\mid\vnu_0\cdot\va$. Then \[ \frac1{\#\cA_p}\sum_{\va\in\cA_p}K(\va,p^n)^{1/2}\leqslant C_s\,p^f(n+1)^2p^{\min(e,n)/2}, \] with $C_s$ depending only on $s$ if $p\nmid D_F$, and on $\vF$ and $p$ if $p\mid D_F$. \end{lemma} \begin{proof} \rev{We parametrise the line, so that $\Delta$ becomes the binary form $G_{\vnu_0}$, and split the residues according to the valuation $k$ of $D_{s-1}(\va)$. The residues with $k\geqslant1$ lie in a few small $p$-adic discs, by Lemma~\ref{lem:corank2lines}, and on each set with fixed $k$ Lemma~\ref{lem:binaryform} bounds how often $G_{\vnu_0}$ is highly divisible.} First let $f=0$. Since $\vnu_0^\perp\cap\ZZ^3$ is saturated, the map $\bz=(x,y)\mapsto\va(\bz)=x\bw_1+y\bw_2$ identifies the primitive $\bz\bmod p^n$ with $\cA_p$, and $\Delta(\va(\bz))=G_{\vnu_0}(\bz)$; so we have to bound $\frac1{\mu(\mathrm{prim})}\int K(\va(\bz),p^n)^{1/2}\,d\mu(\bz)$ over the primitive $\bz\in\ZZ_p^2$, where $\mu(\mathrm{prim})=1-p^{-2}$. As $p$ is good, $M_{\va}$ has corank at most $2$ modulo $p$, so its first $s-2$ invariant factors are units; let $v_1\leqslant v_2$ be the valuations of the last two. By Lemma~\ref{lem:Kbasic}(i), $K(\va,p^n)=p^{\min(v_1,n)+\min(v_2,n)}$, and $v_1+v_2=v_p(G_{\vnu_0}(\bz))$, $v_1=v_p(D_{s-1}(\va))$. By Lemma~\ref{lem:corank2lines}, the primitive $\va$ with $p^k\mid D_{s-1}(\va)$ lie in at most $(s-1)^2$ classes $\{\lambda\vbeta\bmod p^k\}$, and each class meets the line in at most one class $\{\lambda\bz_0\bmod p^k\}$ of primitive $\bz$, of measure at most $p^{-k}$. So the set $U_k=\{\bz:\ v_1\geqslant k\}$ is a union of at most $(s-1)^2$ sets $D$ of measure at most $p^{-k}$ (with $U_0$ the whole set). On $U_k\setminus U_{k+1}$ we have $v_1=k$ and $v_2=v_p(G_{\vnu_0}(\bz))-k$, so \[ K^{1/2}\leqslant p^{\min(k,n)/2}\Bigl(1+\sum_{j=1}^np^{j/2}\one_{v_p(G_{\vnu_0}(\bz))\geqslant k+j}\Bigr). \] By Lemma~\ref{lem:binaryform}(ii), each $D$ satisfies \[ \mu\{\bz\in D:\ v_p(G_{\vnu_0}(\bz))\geqslant k+j\}\leqslant\min(p^{-k},s\,p^{-(k+j-e)/2})\leqslant s\,p^{-k}\min(1,p^{(k+e-j)/2}), \] and \[ \sum_{j\leqslant n}p^{j/2}\min(1,p^{(k+e-j)/2})\leqslant(n+3)p^{\min(n,k+e)/2}. \] Hence \[ \int_{U_k\setminus U_{k+1}}K^{1/2}\,d\mu\leqslant(s-1)^2s(n+4)\,p^{\min(k,n)/2-k+\min(n,k+e)/2}. \] For $k\leqslant n$ the exponent is at most $\min(n-k,e)/2\leqslant\min(n,e)/2$, and for $k>n$ it is at most $n-k$. Summing over $k\geqslant0$ gives the lemma for $f=0$, with $C_s=8s(s-1)^2$, since $\mu(\mathrm{prim})\geqslant3/4$ and $(n+3)(n+4)\leqslant6(n+1)^2$. If $p\mid D_F$ the same argument applies with three changes: the first $s-2$ invariant factors of $M_\va$ have total valuation at most $\mu_p$ (Lemma~\ref{lem:Kpointwise}(ii)), so $K(\va,p^n)\leqslant p^{\mu_p}p^{\min(v_1,n)+\min(v_2,n)}$, where now $v_1\leqslant v_2$ are the valuations of the last two invariant factors, with $v_1\leqslant v_p(D_{s-1}(\va))$ and $v_1+v_2\leqslant v_p(G_{\vnu_0}(\bz))$; the sets $U_k=\{v_1\geqslant k\}$ have measure at most $(s-1)^2p^{C_p-k}$ by Lemma~\ref{lem:corank2linesbad}; and $K(\va,p^f)\leqslant p^{\mu_p+2f}$ below. \orev{Indeed, on $U_k\setminus U_{k+1}$ we have $v_1=k$ and $v_2\leqslant v_p(G_{\vnu_0}(\bz))-k$, so the displayed bound for $K^{1/2}$ holds with the extra factor $p^{\mu_p/2}$; each of the at most $(s-1)^2$ sets $D$ making up $U_k$ (now of measure at most $p^{C_p-k}$) satisfies the bound obtained from Lemma~\ref{lem:binaryform}(ii) with $p^{-k}$ replaced by $p^{C_p-k}$; and the sum over $k$ is the same.} This multiplies the bound by $p^{\mu_p+C_p}$. If $f\geqslant1$, Lemma~\ref{lem:Kbasic}(ii) and Lemma~\ref{lem:Kpointwise}(i) give \[ K(\va,p^n)\leqslant K(\va,p^{n-f})K(\va,p^f)\leqslant p^{2f}K(\va,p^{n-f}). \] The set $\cA_p$ is the full preimage of the corresponding set modulo $p^{n-f}$, and $K(\va,p^{n-f})$ depends only on $\va\bmod p^{n-f}$, so the average is at most $p^f$ times the average for $n-f$ in place of $n$ and $f=0$ (and at most $p^f$ if $f=n$). \end{proof} \begin{proposition}\label{prop:planeterms} Let $\vnu=g\vnu_0$ with $\vnu_0\notin\cN_F$ primitive, such that the line $\vnu_0^\perp$ contains no point of $\cZ_2(\overline\QQ)$, let $\bu\in\ZZ^s$ with $C_{\vnu_0}(\bu)\neq0$, and let $\cA_q(\vnu)$ be the set of primitive $\va\bmod q$ with $q\mid\vnu\cdot\va$. Then for all $q$ \[ \Bigl|\sum_{\va\in\cA_q(\vnu)}S_q(\va,\bu)\Bigr|\leqslant\#\cA_q(\vnu)\,q^{(s-1)/2}\gcd(q^\sharp,g)\,B(q),\qquad\sum_{q\leqslant Y}B(q)\ll_\varepsilon(Y|\vnu||\bu|)^{\varepsilon}Y. \] \end{proposition} \begin{proof} \rev{This is the plane-term version of Proposition~\ref{prop:pointterms}. At the primes $p\parallel q$ we use Lemma~\ref{lem:onegoodprime}, now on the plane $W=\bar\vnu_0^\perp$, where the exceptional classes are controlled by three non-zero integers attached to $\vnu_0$ and $\bu$; at the other prime powers we use Lemma~\ref{lem:Kline}. All losses are then gcd's with a fixed non-zero integer $N$, or factors supported on square-full moduli, and both are harmless after summing over $q$.} Let $E=E_{G_{\vnu_0}}$, as in Lemma~\ref{lem:binaryform}(i). Since the restrictions to the line of the $(s-1)\times(s-1)$ minors of $M_\vbeta$ have no common root over $\overline\QQ$, two suitable integral linear combinations of them are binary forms without a common root, and their resultant $R'_{\vnu_0}$ is a non-zero integer; for primitive $\va$ on the line, every prime dividing $D_{s-1}(\va)$ divides $R'_{\vnu_0}$. All of $E$, $R'_{\vnu_0}$ and $C_{\vnu_0}(\bu)$ are $\ll(|\vnu||\bu|)^{C}$ in absolute value, with $C$ depending only on $s$. Put $N=C_{\vnu_0}(\bu)\,E\,R'_{\vnu_0}\neq0$. By Lemma~\ref{lem:factorA} the sum factorises. Write $q=q^\flat q^\sharp$ as in Lemma~\ref{lem:sqfullsum}; the primes dividing $2D_F$ belong to $q^\sharp$. Let $p\parallel q$ with $p\nmid2D_F$. If $p\mid g$, Lemma~\ref{lem:onegoodprime} with $W=\FF_p^3$ bounds the local factor by $\#\cA_p\,p^{(s-1)/2}\cdot2C_s\gcd(p,C(\bu))^{1/2}$, and $C(\bu)\mid C_{\vnu_0}(\bu)$ since the content of a form divides the content of its restriction. If $p\nmid g$, we use Lemma~\ref{lem:onegoodprime} with $W=\bar\vnu_0^{\,\perp}$ and $N(W)=p+1$. Its exceptional terms are $p^{1/2}$ if $p\mid C_{\vnu_0}(\bu)$, $p$ if $p\mid\operatorname{cont}(G_{\vnu_0})$ (which divides $E$), and at most $(s-1)^2p^{1/2}$ if the reduction of the line contains a point of corank $2$, in which case $p\mid R'_{\vnu_0}$. In all cases the local factor at $p$ is at most $\#\cA_p\,p^{(s-1)/2}\,C'_s\gcd(p,N)$, with $C'_s$ depending only on $s$. Let $p^n\parallel q^\sharp$, that is, $n\geqslant2$ or $p\mid2D_F$, and put $p^f=\gcd(p^n,g)$. By Lemma~\ref{lem:gauss} and Lemma~\ref{lem:Kline}, the local factor is at most \[ p^{ns/2}\sum_{\va\in\cA_p}K(\va,p^n)^{1/2}\leqslant\#\cA_p\,p^{n(s-1)/2}\cdot p^f\cdot C_s(n+1)^2p^{n/2}p^{\min(e_p,n)/2}, \] and $e_p\leqslant v_p(E)$ by Lemma~\ref{lem:binaryform}(i). Hence the stated bound holds with \[ B(q)=\prod_{p\mid q^\flat}C'_s\gcd(p,N)\cdot\prod_{p^n\parallel q^\sharp}C_p(n+1)^2p^{n/2}\gcd(p^n,E)^{1/2}, \] with $C_p=C_s$ for $p\nmid D_F$. Summing first over $q^\flat\leqslant Y/q^\sharp$, using $C_s'^{\omega(m)}\ll m^{\varepsilon}$ and $\sum_{m\leqslant Z}\prod_{p\mid m}\gcd(p,N)\leqslant Z\tau(N)$, we get $\sum_qB(q)\ll Y^{1+\varepsilon}\tau(N)\prod_{p\leqslant Y}\sigma_p$ with \[ \sigma_p=1+\sum_{n\geqslant2}C_s(n+1)^2p^{-n/2}\gcd(p^n,E)^{1/2}. \] (with the term $n=1$ included when $p\mid2D_F$). If $p\nmid2D_FE$, then $\sigma_p\leqslant1+C/p$; the finitely many $p\mid2D_F$ with $p\nmid E$ contribute a bounded factor. If $p^v\parallel E$, then $p^{-n/2}\gcd(p^n,E)^{1/2}=p^{(\min(n,v)-n)/2}$, so \[ \sigma_p\ll\sum_{n\leqslant v}(n+1)^2+\sum_{n>v}(n+1)^2p^{-(n-v)/2}\ll(v+1)^3. \] Therefore \[ \prod_{p\leqslant Y}\sigma_p\ll(\log Y)^C\prod_{p\mid E}(v_p(E)+1)^{C}\ll(Y|E|)^{\varepsilon}, \] which completes the proof. \end{proof} If the line $\vnu_0^\perp$ contains a non-rational point $z$ of $\cZ_2(\overline\QQ)$, it also contains a conjugate $z'\neq z$, so it is the line through $z$ and $z'$; there are only finitely many such lines, and we add their normals $\vnu_0$ to the finite set $\cN_F$. It remains to allow rational members of corank $2$ on the line. For such a member $\vc_0$ we use Lemma~\ref{lem:kernelsplit}, with a fixed choice of $U$, and we write $t'_{\vc_0}(\bu)=\bv'^T\operatorname{adj}(N_{\vc_0})\bv'$, a non-singular quadratic form in $\bv'$, where $(\bv'',\bv')=U^T\bu$. \begin{proposition}\label{prop:planeZ2} Let $\vnu=g\vnu_0$ with $\vnu_0\notin\cN_F$ primitive, and let $\vc_0^{(1)},\dots,\vc_0^{(k)}$ be the points of $\cZ_2(\overline\QQ)$ on the line $\vnu_0^\perp$, all rational. Then the conclusion of Proposition~\ref{prop:planeterms} holds for every $\bu$ with $C_{\vnu_0}(\bu)\neq0$ and $t'_{\vc_0^{(j)}}(\bu)\neq0$ for $1\leqslant j\leqslant k$. \end{proposition} \begin{proof} \rev{A rational corank-two point on the line would make the integer $R'_{\vnu_0}$ of the previous proof vanish. We remove these points from the resultant, and at the classes they define we use the kernel splitting of Lemma~\ref{lem:kernelsplit} instead of the trivial bound.} The proof of Proposition~\ref{prop:planeterms} applies with two changes at the primes $p\parallel q$ with $p\nmid2D_Fg$. First, the integer $R'_{\vnu_0}$ is replaced as follows. The restrictions to the line of the $(s-1)\times(s-1)$ minors of $M_\vbeta$ have exactly the common roots $\vc_0^{(j)}$; choose two integral linear combinations $A,B$ of them with no other common root, let $a_j,b_j$ be their orders of vanishing at $\vc_0^{(j)}$, and let $\ell_j$ be a primitive integral linear form on the line vanishing at $\vc_0^{(j)}$. Then $A'=A/\prod_j\ell_j^{a_j}$ and $B'=B/\prod_j\ell_j^{b_j}$ have no common root, and we let $R''_{\vnu_0}$ be the product of their resultant, of their leading coefficients and of the resultants $\operatorname{Res}(\ell_i,\ell_j)$, $i\neq j$; it is a non-zero integer, and $|R''_{\vnu_0}|\ll|\vnu_0|^C$. If $p\nmid R''_{\vnu_0}$ and a primitive residue on the line modulo $p$ has corank $2$, then it is the reduction of some $\vc_0^{(j)}$: otherwise $\ell_j$ would not vanish at it, and it would be a common root of $A'$ and $B'$ modulo $p$. Secondly, in Lemma~\ref{lem:onegoodprime} with $W=\bar\vnu_0^{\,\perp}$ the classes of corank $2$ are therefore, for $p\nmid R''_{\vnu_0}$, the reductions of the $\vc_0^{(j)}$, and for $p\nmid\prod_j\det N_{\vc_0^{(j)}}$ we use Lemma~\ref{lem:kernelsplit} for them instead of Lemma~\ref{lem:gauss}: $T_p(\vc_0^{(j)},\bu)=p^2\one_{p\mid\bv''}T^{N}_p(\bv')$ with $N=N_{\vc_0^{(j)}}$ invertible modulo $p$, and Lemma~\ref{lem:Tprime}(i) for $N$ gives \[ |T_p(\vc_0^{(j)},\bu)|\leqslant p^2\cdot p^{(s-1)/2}\gcd\bigl(p,t'_{\vc_0^{(j)}}(\bu)\bigr)^{1/2}. \] In the notation of the proof of Lemma~\ref{lem:onegoodprime}, where the sum is normalised by $p^{(s+1)/2}N(W)$ with $N(W)=p+1$, this class contributes at most $\gcd(p,t'_{\vc_0^{(j)}}(\bu))^{1/2}$ to $\beta$, instead of $p^{1/2}$. Hence the local factor at $p$ is at most $\#\cA_p\,p^{(s-1)/2}C'_s\gcd(p,N)$ with \[ N=C_{\vnu_0}(\bu)\,E\,R''_{\vnu_0}\prod_j\det N_{\vc_0^{(j)}}\,t'_{\vc_0^{(j)}}(\bu)\neq0, \] which is $\ll(|\vnu||\bu|)^C$. The primes $p\mid g$ are treated with $W=\FF_p^3$ as before, and Lemma~\ref{lem:Kline}, used at the prime powers, does not depend on the points of corank $2$ on the line. The rest of the proof is unchanged. \end{proof} The vectors $\bu$ with $t'_{\vc_0}(\bu)=0$ satisfy a non-singular quadratic equation in the $s-2\geqslant5$ coordinates $\bv'$, so by~\cite[Theorem~2]{HB02} there are $\ll L^{2}\cdot L^{s-4+\varepsilon}=L^{s-2+\varepsilon}$ of them with $|\bu|\leqslant L$, a proportion $L^{-2+\varepsilon}$, as for the dual quadric in~\S\ref{sec:dualquadric}. The factor $\gcd(q^\sharp,g)$ in Propositions~\ref{prop:planeterms} and~\ref{prop:planeZ2} \orev{costs only $Q^{\varepsilon}$} in the sum over the plane terms. In the proof of Proposition~\ref{prop:Kavg} the plane terms carry the weight $\gcd(q,g)^2/g$, and their total weight is $\asymp Q$ for each $q$. \begin{orevblock}Since $B(q)$ depends on $\vnu_0$, we do not separate the sums over $q$ and $\vnu$, but use $\gcd(q,g)^2\gcd(q^\sharp,g)/g\leqslant g^2$: for each $\vnu=g\vnu_0$ the sum over $q\leqslant2Y$ of $B(q)$ is $\ll(Y|\vnu||\bu|)^{\varepsilon}Y$, and \[ \sum_{|\vnu|\leqslant Q^{1/3}}g^2\leqslant\sum_{g\leqslant Q^{1/3}}g^2\,\#\{\vnu_0:\ |\vnu_0|\leqslant Q^{1/3}/g\}\ll\sum_{g\leqslant Q^{1/3}}g^2\Bigl(\frac{Q^{1/3}}g\Bigr)^3\ll Q\log Q . \] So the weighted sum over $q$ and $\vnu$ is $\ll Q^{1+\varepsilon}Y^{1+\varepsilon}$, which is the same bound as for the weights $\gcd(q,g)^2/g$ alone, up to $Q^{\varepsilon}$.\end{orevblock} \subsection{Kernel splitting and the numerators of the flag terms}\label{sec:localfactors} \rev{This subsection prepares the treatment of the flag terms. It contains three tools: the kernel splitting, which reduces Gauss sums for a singular member to Gauss sums for a non-singular form in fewer variables; an exact description of the numerators of a flag term; and a precise account of how the mass of the flag terms is distributed over the directions $\vc$.} The proof of Lemma~\ref{lem:Tprime} uses only that $M_\va$ is a symmetric integral matrix invertible modulo $p$; so Lemma~\ref{lem:Tprime}, and with it Lemma~\ref{lem:Tfixedc}, hold for every such matrix $N$ in place of $M_\va$, with the dual form $\bv^T\operatorname{adj}(N)\bv$ in place of $F^*_\va$ and the invariant factors of $N$ in place of those of $M_\va$. We use this without comment. For a symmetric integral matrix $N$ we write \[ S^N_q(\lambda,\bv)=\sum_{\by\bmod q}\ee_q(\frac12\lambda\by^TN\by+\bv\cdot\by), \] so that $S_q(\lambda\va,\bu)=S^{M_\va}_q(\lambda,\bu)$, and $T^N_q(\bv)=\sumstar_{\lambda\bmod q}S^N_q(\lambda,\bv)$. \begin{lemma}[kernel splitting]\label{lem:kernelsplit} Let $\vc\in\ZZ^3$ be such that $M_\vc$ has corank $r\geqslant1$, let $\bh_1,\dots,\bh_r$ be a basis of the saturated lattice $\ker M_\vc\cap\ZZ^s$, and let $U\in\mathrm{GL}_s(\ZZ)$ have first columns $\bh_1,\dots,\bh_r$. Then $U^TM_\vc U=\operatorname{diag}(0_r,N_\vc)$ with $N_\vc$ symmetric and $\det N_\vc\neq0$, and for all $q$, $\lambda$ and $\bu$, writing $U^T\bu=(\bv'',\bv')$ with $\bv''=(\bh_1\cdot\bu,\dots,\bh_r\cdot\bu)$, \[ S_q(\lambda\vc,\bu)=q^r\,\one_{q\mid\bv''}\,S^{N_\vc}_q(\lambda,\bv'),\qquad T_q(\vc,\bu)=q^r\,\one_{q\mid\bv''}\,T^{N_\vc}_q(\bv'). \] The same holds over $\FF_p$ for a residue $\va$ whose matrix has corank $r$ modulo $p$, with $U\in\mathrm{GL}_s(\FF_p)$. \end{lemma} \begin{proof} \rev{In coordinates adapted to the kernel, the quadratic form does not involve the first $r$ variables at all, so the sum over them is a pure linear exponential sum, which detects the congruence $q\mid\bv''$.} The first columns of $U$ span $\ker M_\vc$, so $U^TM_\vc U$ has vanishing first $r$ rows and columns, and its lower block is non-singular since $\operatorname{rank}M_\vc=s-r$. Substituting $\bb=U\bx$ in the definition of $S_q$, the sum over the first $r$ coordinates of $\bx$ is \[ \prod_{i\leqslant r}\sum_{x_i\bmod q}\ee_q(x_i\bh_i\cdot\bu)=q^r\one_{q\mid\bv''}, \] and the sum over the others is $S^{N_\vc}_q(\lambda,\bv')$. \end{proof} We next describe exactly the numerators of a flag term; the description of Lemma~\ref{lem:flaglocal}, which ignored the condition $\vnu\in\Lp(\va,q)$, was enough for upper bounds but not for the sums over the numerators. Let $(\vnu,\vrho)$ be a flag with $\vnu=g\vnu_0$, $\vrho=G\vc$, $\vnu_0,\vc$ primitive, and let $q\in\NN$ and $d=\gcd(q,G)$. Write $q=q_cq_d$ with $q_d=\prod_{p\mid d}p^{v_p(q)}$, so that $\gcd(q_c,G)=1$ and $q_d\mid G^\infty$. For $p\mid d$ put $n_p=v_p(q)$, $\delta_p=v_p(d)=\min(n_p,v_p(G))$ and $f_p=\min(\delta_p,v_p(g))$. \begin{lemma}\label{lem:flagfactor} The set \[ \cA^\flat=\{\va\bmod q:\ \gcd(\va,q)=1,\ \vrho\in\Lambda(\va,q),\ \vnu\in\Lp(\va,q)\} \] of numerators of the flag term is the product, under the Chinese remainder theorem, of the class $\cA_c=\{\lambda\vc\bmod q_c\}$ and of the sets \[ \cA_p=\{\lambda\vc+p^{n_p-\delta_p}\vb:\ p\nmid\lambda,\ \vb\bmod p^{\delta_p},\ p^{\delta_p-f_p}\mid\vnu_0\cdot\vb\}\qquad(p\mid d), \] each stable under multiplication by units. If $\delta_p=n_p$, then $\cA_p$ is the set of primitive residues modulo $p^{n_p}$ on the plane $p^{n_p-f_p}\mid\vnu_0\cdot\va$; this is the set of all primitive residues if moreover $f_p=n_p$. Consequently \begin{equation}\label{eq:flagfactor} \sum_{\va\in\cA^\flat}S_q(\va,\bu)=T_{q_c}(\vc,\bu)\prod_{p\mid d}\ \sum_{\va\in\cA_p}S_{p^{n_p}}(\va,\bu), \end{equation} and $\#\cA^\flat\leqslant q\,d\gcd(d,g)$. \end{lemma} \begin{proof} \rev{We combine the description of Lemma~\ref{lem:counta}(ii) with the second condition $\vnu\in\Lp(\va,q)$, and read off the local structure prime by prime.} By Lemma~\ref{lem:counta}(ii), the condition $\vrho\in\Lambda(\va,q)$ means $\va=\lambda\vc+q_1\vb$ with $q_1=q/d$, $\lambda$ a unit modulo $q_1$ and $\vb\bmod d$. Since $\vnu\cdot\vc=0$, we have $\vnu\cdot\va=q_1\vnu\cdot\vb$, so $\vnu\in\Lp(\va,q)$ means $d\mid g\vnu_0\cdot\vb$, that is, $p^{\delta_p-f_p}\mid\vnu_0\cdot\vb$ for every $p\mid d$. For $p\nmid d$ we have $p^{n_p}\mid q_1$, so the residue modulo $p^{n_p}$ is $\lambda\vc$; for $p\mid d$ we have $v_p(q_1)=n_p-\delta_p$, and the residue modulo $p^{n_p}$ runs over $\cA_p$. The residues of $\lambda$ and $\vb$ at the different primes are independent, which gives the product structure; the case $\delta_p=n_p$ follows from $\vnu_0\cdot\vc=0$. Formula~\eqref{eq:flagfactor} follows from Lemma~\ref{lem:factorA} and Lemma~\ref{lem:Tmult}. Finally, the pairs $(\lambda,\vb)$ number at most $q_1\cdot d^3\gcd(d,g)/d=qd\gcd(d,g)$. \end{proof} The bound $\#\cA^\flat\leqslant qd\gcd(d,g)$ is smaller than the bound $qd^2$ used in Proposition~\ref{prop:Kavg} by the factor $d/\gcd(d,g)$. This changes the distribution of the mass of the flag terms among the directions $\vc$, though not its total. For primitive $\vc$, $1\leqslant Y\leqslant Q$ and $U=Q^{1/3}$ put \[ \Omega_\vc(Y)=\sum_{\substack{\vnu\perp\vc\\ 0<|\vnu|\leqslant U}}\ \sum_{G\leqslant Z_\vc}\ \sum_{Y1$ are not rare, but the weight of a given $d$ decreases like $\gcd(d,g)/d$. The next lemma makes precise the remark that short directions carry little of the mass. \orev{It explains why large values of $\gcd(q,G)$ cause no difficulty:} such values occur only when $G\geqslant\gcd(q,G)$, hence only for directions with $|\vc|\leqslant Q^{2/3}/\gcd(q,G)$. For a primitive $\vc$ and $1\leqslant Y\leqslant Q$ we put \[ Z'_\vc=\min(2Y,Z_\vc)=\min\Bigl(2Y,\frac{Q^{2/3}}{|\vc|}\Bigr), \] so that $\gcd(q,G)\leqslant Z'_\vc$ for every flag term with $\vrho=G\vc$ and $Y0$, uniformly in $\vb$; let $\be_\vb\in W$ be a unit eigenvector. Also $|B_\vb|,|D_\vb|\leqslant C$. Since $M$ is symmetric, its singular values are the absolute values of its eigenvalues, and by the min-max principle $\sigma_2(M)\geqslant\min\{|M\bv|:\ \bv\in V,\ |\bv|=1\}$ for every subspace $V$ of dimension $s-1$. We take $V=\RR\be_\vb\oplus W'$ and write $\bv=\alpha\be_\vb+\bw$ with $\bw\in W'$ and $\alpha^2+|\bw|^2=1$. Then \[ M\bv=\bigl(t'\alpha\lambda_\vb\be_\vb+t'B_\vb\bw\bigr)+\bigl(t'\alpha B_\vb^T\be_\vb+(N+t'D_\vb)\bw\bigr), \] with the first bracket in $W$ and the second in $W'$. Let $K=4C/c$. If $|\bw|\geqslant Kt'$, the second bracket has length $\geqslant(c-Ct')|\bw|-Ct'\geqslant\frac c2Kt'-Ct'=Ct'$ for $t'\leqslant c/(2C)$. If $|\bw|0$ there is $c_{z,\varepsilon}>0$ such that every primitive $\vc\in\ZZ^3$ with $[\vc]\neq z$ has angular distance at least $c_{z,\varepsilon}|\vc|^{-2-\varepsilon}$ from $z$. \item Let $0<\eta_0\leqslant1$ and $1\leqslant H\leqslant Q^{2/3}$. Then \[ \sum_{\substack{\vc\ \text{primitive},\ |\vc|\asymp H\\ [\vc]\notin\cZ_2,\ \eta(\hat\vc)\leqslant\eta_0}}\Bigl(\frac U{\lambda_1(\vc)}+\frac{U^2}{|\vc|}\Bigr)\ll_\varepsilon\eta_0^{1-\varepsilon}\log(2H)\,\bigl(UH^{5/2}+U^2H^2\bigr). \] \item For a fixed primitive $\vnu_0$, the number of primitive $\vc\perp\vnu_0$ with $|\vc|\asymp H$, $[\vc]\notin\cZ_2$ and $\eta(\hat\vc)\leqslant\eta_0$ is $\ll_{\vnu_0,\varepsilon}\eta_0^{1-\varepsilon}H^2$. \end{enumerate} \end{lemma} \begin{proof} \rev{Part~(i) is a Diophantine approximation statement for the algebraic point $z$, and it depends on whether $z$ is rational, lies on a rational line, or neither. Parts~(ii) and~(iii) count lattice points in a thin cone around $z$; the volume of the cone gives the factor $\eta_0^2$ or $\eta_0$, and part~(i) shows that a cone containing a lattice point must be long enough for the volume bound to be accurate.} (i) If $z$ is rational, the angle between $\vc$ and $z$ is $\gg|\vc\times\vz|/|\vc|\gg|\vc|^{-1}$, where $\vz$ is a primitive integral representative. If $z$ lies on a rational line $\vnu_0^\perp$ but is not rational, then for $\vc\notin\vnu_0^\perp$ we have $|\vnu_0\cdot\vc|\geqslant1$, so the angle is $\gg|\vc|^{-1}$; and for $\vc=x\bw_1+y\bw_2$ on the line, with $\bw_1,\bw_2$ a basis of $\vnu_0^\perp\cap\ZZ^3$, the angle is $\gg|x/y-\alpha|$, where $z$ corresponds to the real algebraic irrational $\alpha$, and Roth's theorem~\cite{Rot} gives $|x/y-\alpha|\gg_\varepsilon|y|^{-2-\varepsilon}$ (and the case $|x|\gg|y|$ is treated in the same way with $y/x$). If $z$ lies on no rational line, normalise $z=(1,\alpha_1,\alpha_2)$ (after permuting coordinates); then $1,\alpha_1,\alpha_2$ are linearly independent over $\QQ$, and Schmidt's theorem on simultaneous approximation to algebraic numbers~\cite[Chapter~VI]{Sch}\orev{, which says that $\|c_1\alpha_1\|\,\|c_1\alpha_2\|\gg_\varepsilon|c_1|^{-1-\varepsilon}$ for $c_1\neq0$, gives} $\max_i\|c_1\alpha_i\|\gg_\varepsilon|c_1|^{-1/2-\varepsilon}$, so the angle is $\gg|\vc|^{-3/2-\varepsilon}$. \orev{(Here $\|x\|$ is the distance to the nearest integer; if $|c_1|<\frac12\max_i|c_{i+1}|$ the angle between $\vc$ and $z$ is $\gg1$, and otherwise it is \[ \gg\max_i|c_{i+1}/c_1-\alpha_i|\geqslant\max_i\|c_1\alpha_i\|/|c_1|. \] )} (ii) It suffices to consider one real point $z$, and to count the primitive $\vc$ in the cone $\cK=\{\vx:\ |\vx|\leqslant2H,\ \angle(\vx,z)\leqslant\eta_0\}$, which is convex. If $\cK$ contains a non-zero lattice point, it contains a primitive one, and by~(i) this forces $H\geqslant H_*:=c'\eta_0^{-1/(2+\varepsilon)}$. The volume of $\cK$ is $\ll H^3\eta_0^2$, its projections to the coordinate planes have area $\ll H^2\eta_0$, and those to the axes have length $\ll H$; so by Davenport's lemma~\cite{Dav} the number of lattice points in $\cK$ is $\ll(H^3\eta_0^2+H^2\eta_0+H)\one_{H\geqslant H_*}$. Multiplying by $U^2/H$, this part is \[ \ll U^2H^2(\eta_0^2+\eta_0+H_*^{-2})\ll U^2H^2\eta_0^{2/(2+\varepsilon)}. \] For the part with $U/\lambda_1(\vc)$, choose for each $\vc$ a primitive $\vy\perp\vc$ with $|\vy|=\lambda_1(\vc)\ll H^{1/2}$. The plane $\vy^\perp$ meets $\cK$ only if it passes within angle $\eta_0$ of $z$, that is, $|\hat\vy\cdot\vz|\ll\eta_0$, and then in a sector of angle $\ll\eta_0$. Two primitive vectors $\bv\neq\pm\bv'$ of the lattice $\vy^\perp\cap\ZZ^3$ have $\bv\times\bv'\in\ZZ\vy\setminus\{\vzero\}$, so $|\bv\times\bv'|\geqslant|\vy|$, and consecutive primitive vectors of length $\leqslant2H$ in the sector are at angle $\geqslant|\vy|/(4H^2)$; hence the sector contains $\ll1+H^2\eta_0/|\vy|$ of them, and none unless $H\geqslant H_*$. The number of $\vy$ with $|\vy|\asymp Y'$ and $|\hat\vy\cdot\vz|\ll\eta_0$ is $\ll Y'^3\eta_0+Y'^2$, by Davenport's lemma for the corresponding slab. Hence \begin{align*} \sum\frac1{\lambda_1(\vc)}&\ll\one_{H\geqslant H_*}\sum_{Y'\ll H^{1/2}}\frac{Y'^3\eta_0+Y'^2}{Y'}\Bigl(1+\frac{H^2\eta_0}{Y'}\Bigr)\\ &\ll\one_{H\geqslant H_*}\bigl(H\eta_0+H^{1/2}+H^{5/2}\eta_0^2+H^2\eta_0\log2H\bigr), \end{align*} the sums being over dyadic $Y'$. This is $\ll H^{5/2}\log(2H)(\eta_0+H_*^{-2})$, which is $\ll H^{5/2}\log(2H)\,\eta_0^{2/(2+\varepsilon)}$. (iii) The sector argument with $\vy=\vnu_0$ gives \[ \ll(1+H^2\eta_0/|\vnu_0|)\one_{H\geqslant H_*}\ll H^2(\eta_0+H_*^{-2}). \] \end{proof} \begin{lemma}\label{lem:etaavg} In each dyadic range $(Y,W)$, the following hold for $X=1+P^2W$. \begin{enumerate}[label=(\roman*)] \item The average of $\min(1,(X\eta(\hat\vw))^{-1/2})$ against the mass $\int|p_{1,q}|\,d\vw$ of the point terms, and against the mass of the plane terms with $\vnu/\gcd(\vnu)\notin\cN_F$, is $\ll Q^{\varepsilon}X^{-1/2}$. \item For every $\eta_0\in(0,1]$ and every dyadic $H$, the weights $\Omega^+_\vc=Y^2Z_\vc(U/\lambda_1(\vc)+U^2/|\vc|)$ of Proposition~\ref{prop:flagterms} satisfy \[ \sum_{|\vc|\asymp H,\ \eta(\hat\vc)\leqslant\eta_0}\Omega^+_\vc\ll_\varepsilon Q^{\varepsilon}\eta_0^{1-\varepsilon}\sum_{|\vc|\asymp H}\Omega^+_\vc, \] the sums being over the primitive $\vc\notin\cZ_2$ with $|\vc|\leqslant Q^{2/3}$. Consequently \[ \sum_{\vc}\Omega^+_\vc\min\bigl(1,(X\eta(\hat\vc))^{-1/2}\bigr)\ll_\varepsilon Q^{\varepsilon}X^{-1/2}\sum_\vc\Omega^+_\vc, \] and the same holds for the singular $\vc$ on a fixed rational line contained in $\Delta=0$, with their own weights. \end{enumerate} \end{lemma} \begin{proof} \rev{In each case we show that the weights put a proportion $\ll\eta_0$ (up to $Q^\varepsilon$) of their mass on the directions within $\eta_0$ of a real corank-two point; a dyadic decomposition in $\eta_0$ then shows that the factor $\min(1,(X\eta)^{-1/2})$ is $X^{-1/2}$ on average.} (i) The weight $p_{1,q}$ is radial, so the directions $\hat\vw$ are distributed according to surface measure, and the measure of the $\eta_0$-neighbourhood of the finitely many real points of $\cZ_2$ is $\ll\eta_0^2$. By the proof of Proposition~\ref{prop:mass}, the mass of a plane term $p_{2,\vnu,k,q}$ at $|\vw|\asymp W\geqslant Q^{-4/3}$ lies within $O(Q^{-4/3})$ of the plane $\vnu^\perp$ and is distributed uniformly in angle there, and a great circle meets the $\eta_0$-neighbourhood of a finite set in a set of length $\ll\eta_0$; for $W\delta$, the ultrametric inequality gives $d(\bz,\boldsymbol\alpha')\leqslant\delta$ for every root $\boldsymbol\alpha'\neq\boldsymbol\alpha$, so by~\eqref{eq:vGdist} $v_p(G(\bz))\leqslant\kappa+mt+(d-m)\delta\leqslant e+mt$; if $t\leqslant\delta$, then $v_p(G(\bz))\leqslant\kappa+d\delta\leqslant e$. So $v_p(G(\bz))\geqslant j>e$ forces $d(\bz,\boldsymbol\alpha_i)\geqslant(j-e)/m$ for some $i$, and the measure of this set is at most $p^{-\lceil(j-e)/m\rceil}$ for each $i$, as in the proof of Lemma~\ref{lem:binaryform}(ii). (ii) Let $p$ be good. As in the proof of Lemma~\ref{lem:Kline}, \[ K(\va,p^n)=p^{\min(v_1,n)+\min(v_2,n)},\qquad v_1=v_p(D_{s-1}(\va))\leqslant v_2,\qquad v_1+v_2=v_p(G_{\vnu_0}(\bz)), \] so that \[ K^{1/2}\leqslant p^{\min(v_1,n)/2}p^{\min(v_p(G_{\vnu_0}(\bz)),n)/2}. \] By Cauchy's inequality the average of $K^{1/2}$ is at most the geometric mean of the averages of $p^{\min(v_1,n)}$ and of $p^{\min(v_p(G_{\vnu_0}),n)}$. The first is \[ \leqslant1+\sum_{k\leqslant n}p^k\cdot2(s-1)^2p^{-k}\leqslant4(s-1)^2(n+1), \] by Lemma~\ref{lem:corank2lines}. The second is \[ \leqslant1+\sum_{j\leqslant n}p^j\,s\,p^{-(j-e)/s}\leqslant2s\,p^{e/s}(n+1)p^{n(1-1/s)}, \] by~(i) with $m\leqslant d=s$. This gives the general bound. For $n=1$ \orev{and $p\nmid\operatorname{cont}(G_{\vnu_0})$, the reduction of $G_{\vnu_0}$ is non-zero, so} at most $s$ classes on the line have corank $1$ and at most $(s-1)^2$ have corank $2$, with $K=p$ and $K=p^2$ respectively, so the average is $\leqslant1+(sp^{1/2}+(s-1)^2p)/(p+1)\leqslant C_s$. For $p\mid D_F$ the same argument applies with the changes in the proof of Lemma~\ref{lem:Kline}. (iii) The vector $\bx_0$ lies in $\ker M_\va$ for every $\va\in\ell$, which gives the block form and, by Lemma~\ref{lem:kernelsplit}, the formula for $S_q$. The members of $\ell$ have corank $1$ except for at most $(s-1)^2$ of corank $2$, so $G'_\ell\not\equiv0$. At a good prime the corank of $M_\va$ modulo $p$ is at most $2$, so that of $N_\va$ is at most $1$, and $K_{N_\va}(p^n)=p^{\min(v_p(G'_\ell(\va)),n)}$. The average is then bounded by~(i) as in~(ii), \orev{now with $m\leqslant\deg G'_\ell=s-1$,} without the factor coming from $v_1$. \orev{For $n=1$ and $p\nmid2D_F\operatorname{cont}(G'_\ell)$, the classes on the line with $p\mid G'_\ell(\va)$ have corank $2$ modulo $p$, so there are at most $(s-1)^2$ of them, each with $K_{N_\va}(p)=p$, and the average is at most $1+(s-1)^2p^{1/2}/(p+1)\leqslant C_s$.} \end{proof} For a fixed line the bounds of Lemma~\ref{lem:lineavg} \orev{cost only $Y^{\varepsilon}$} on average over $q$: if $f$ is the multiplicative function with $f(p^n)$ equal to the bound in~(ii) \orev{(or in~(iii), with $s-1$ in place of $s$)}, then \begin{equation}\label{eq:lineavgsum} \sum_{q\leqslant Y}f(q)\ll_{\ell,\varepsilon}Y^{1+\varepsilon}, \end{equation} since $f(p)\leqslant C_s$ for good $p$ \orev{not dividing the content of the relevant binary form}, and $\sum_{n\geqslant2}p^{-n}f(p^n)\ll p^{-1-1/s}$ \orev{(respectively $p^{-1-1/(s-1)}$)} for $p\nmid E_\ell D_F$, while the finitely many other primes contribute a bounded factor. \begin{orevblock} The numerators of a plane term $\vnu=g\vnu_0$ lie on the line $\ell=\vnu_0^\perp$ only modulo $q/\gcd(q,g)$: at a prime $p$ with $p^{n}\parallel q$ and $f=\min(n,v_p(g))$ they form the set $\cA_p(n,v_p(g))$ of primitive $\va\bmod p^n$ with $p^{n-f}\mid\vnu_0\cdot\va$ (Lemma~\ref{lem:factorA}). For $f=n$ this is the set of all primitive residues, and for $0\delta_p$. Note that these primes divide $k''$. For $\vnu_0\notin\cN_F$ let $E_{\vnu_0}$ be the integer of Lemma~\ref{lem:binaryform}(i) for $G_{\vnu_0}$. \begin{lemma}\label{lem:singavg} In the situation of Lemma~\ref{lem:singlocal}, put $\alpha=\#\cA_k^{-1}\sum_{\va\in\cA_k}K(\va,d)^{1/2}$. Then $\alpha\leqslant c_Fd$. If moreover $\vnu_0\notin\cN_F$, then \[ \alpha\leqslant C^{\omega(d)}\tau(d)^2\,\gcd(d_0,g)\gcd(d_0,E_{\vnu_0})^{1/2}\,d_1, \] with $C$ depending only on $\vF$. \end{lemma} \begin{proof} \rev{At the primes $p\mid d$ where $q$ and $G$ share their full power, the numerators run over a plane, and Lemma~\ref{lem:Kline} applies; at the other primes of $d$ we use the trivial bound.} The set $\cA_k$ is the product of the class of $\vc$ modulo $k''$ and of the sets $\cA_p$ for $p\mid d$, and $K(\va,d)=\prod_{p\mid d}K(\va,p^{\delta_p})$. The first bound is Lemma~\ref{lem:Kpointwise}. For the second we treat the primes separately. If $p\mid d_1$ we use $K(\va,p^{\delta_p})\leqslant p^{\mu_p+2\delta_p}$. If $p\mid d_0$, then $n_p=\delta_p$, and by Lemma~\ref{lem:flagfactor} the set $\cA_p$ consists of the primitive $\va\bmod p^{n_p}$ with $p^{n_p-f_p}\mid\vnu_0\cdot\va$; Lemma~\ref{lem:Kline} bounds the average of $K(\va,p^{n_p})^{1/2}$ over it by $C_pp^{f_p}(n_p+1)^2p^{\min(e,n_p)/2}$, and $e\leqslant v_p(E_{\vnu_0})$ by Lemma~\ref{lem:binaryform}(i). Taking the product over $p\mid d$ gives the bound, since $\prod_{p\mid d_0}p^{f_p}\leqslant\gcd(d_0,g)$. \end{proof} \rev{Before the main estimate we sort the singular flags into families of different mass. The idea is that the bound for the ratio $\mathcal R$ obtained in each family can be poor, but only in families which carry a correspondingly small proportion of the total mass.} We divide the flags with a singular direction into three families. For $\vc\in\cC_F$ let $\vy_\vc$ be a primitive vector of $\vc^\perp\cap\ZZ^3$ of length $\lambda_1(\vc)$. A flag $(g\vnu_0,G\vc)$ is called \emph{ordinary} if $\vnu_0\neq\pm\vy_\vc$ and $\vnu_0\notin\cN_F$; it is \emph{of the first kind} if $\vnu_0=\pm\vy_\vc$; and it is \emph{exceptional} if $\vnu_0\neq\pm\vy_\vc$ and $\vnu_0\in\cN_F$. A primitive $\vnu_0\perp\vc$ with $\vnu_0\neq\pm\vy_\vc$ is linearly independent of $\vy_\vc$, so its length is at least the second minimum $\lambda_2(\vc)\asymp|\vc|/\lambda_1(\vc)$ of $\vc^\perp\cap\ZZ^3$, and the number of such $\vnu_0$ with $|\vnu_0|\leqslant R$ is $\ll R^2/|\vc|$. Repeating the proof of Lemma~\ref{lem:flagweights}, we see that the mass of the ordinary flags with direction $\vc$ is $\ll(\log Q)^3\Omega^{\rm ord}_\vc$ and that of the flags of the first kind is $\ll(\log Q)^3\Omega^{(1)}_\vc$, where \[ \Omega^{\rm ord}_\vc=Y^2Z_\vc\frac{U^2}{|\vc|},\qquad\Omega^{(1)}_\vc=Y^2Z_\vc\frac U{\lambda_1(\vc)} . \] The weight of a given $g$ is $\ll\tau(g)g^{-2}$ in the first case and $\ll\tau(g)g^{-1}$ in the second. We also divide the singular directions. By Lemma~\ref{lem:geometry}(iii), the set $\cC_F^{(2)}$ of $\vc\in\cC_F$ of corank $2$ is finite. Let $\ell_1,\dots,\ell_J$ be the rational lines contained in the curve $\Delta=0$ (there are finitely many, since $\Delta$ is reduced), and let $\cC_F^{\rm lin}$ be the set of $\vc\in\cC_F$ of corank $1$ lying on one of them. Let $\cC_F^{\rm curve}$ be the set of the remaining $\vc\in\cC_F$ of corank $1$. Every $\vc\in\cC_F^{\rm curve}$ lies on a component of $\Delta=0$ of degree at least $2$, or on a component not defined over $\QQ$; the latter contain only finitely many rational points, and the former contain $\ll H^{1+\varepsilon}$ primitive $\vc$ with $|\vc|\leqslant H$, by~\cite[Theorem~3]{HB02}. Hence \begin{equation}\label{eq:curvecount} \#\{\vc\in\cC_F^{\rm curve}:\ |\vc|\leqslant H\}\ll_\varepsilon H^{1+\varepsilon},\qquad\#\{\vc\in\cC_F^{\rm lin}:\ |\vc|\leqslant H\}\ll H^2 . \end{equation} For $\vc\in\cC_F^{\rm lin}$ on the line $\ell_i=\vnu_i^\perp$ we have $\vnu_i\perp\vc$, so $\lambda_1(\vc)\leqslant|\vnu_i|\ll1$; and for $|\vc|\gg1$ the vector $\vy_\vc$ is $\pm\vnu_i$. So the flags of the first kind with $\vc\in\cC_F^{\rm lin}$ are, apart from finitely many $\vc$, exactly the flags along the line $\ell_i$: all their numerators lie, modulo $q/\gcd(q,g)$, on the line $\ell_i$. The masses of the families are as follows. By~\eqref{eq:curvecount}, and since $Z_\vc\asymp Q^{2/3}/H$ for $|\vc|\asymp H$, \begin{equation}\label{eq:singmass} \sum_{\substack{\vc\in\cC_F^{\rm curve}\\ |\vc|\asymp H}}\bigl(\Omega^{\rm ord}_\vc+\Omega^{(1)}_\vc\bigr)\ll Y^2Q^{2/3+\varepsilon}\Bigl(\frac{U^2}H+U\Bigr),\qquad\sum_{\substack{\vc\in\cC_F^{\rm lin}\\ |\vc|\asymp H}}\Omega^{\rm ord}_\vc\ll Y^2Q^{2/3}U^2, \end{equation} and \[ \sum_{\vc\in\cC_F^{\rm lin},|\vc|\asymp H}\Omega^{(1)}_\vc\ll Y^2Q^{2/3}UH. \] Relative to the total mass $Y^2Q^2$ these are proportions $Q^{-2/3+\varepsilon}H^{-1}+Q^{-1+\varepsilon}$, $Q^{-2/3}$ and $Q^{-1}H$ respectively. The directions in $\cC_F^{(2)}$ have bounded height, so their ordinary flags have mass $\ll Y^2Q^{4/3}$, a proportion $Q^{-2/3}$, and their flags of the first kind a proportion $Q^{-1}$. The exceptional flags have $\vc\perp\vnu_0$ for one of the finitely many $\vnu_0\in\cN_F$ with $\vnu_0\neq\pm\vy_\vc$. For $\vc\in\cC_F^{\rm curve}\cup\cC_F^{(2)}$ this leaves finitely many $\vc$, since a line meets a component of degree at least $2$ in finitely many points; for $\vc\in\cC_F^{\rm lin}$ on $\ell_i$ it leaves $\vc$ on the intersection of $\ell_i$ with $\vnu_0^\perp$, where $\vnu_0\neq\vnu_i$, so again finitely many $\vc$, together with the finitely many $\vc$ of bounded height for which $\vnu_i\neq\pm\vy_\vc$. So the exceptional flags have bounded directions and fixed $\vnu_0$, and their mass is $\ll Y^2Q^{2/3}(\log Q)^3$, a proportion $Q^{-4/3+\varepsilon}$. \orev{We shall need the following bound for averages of multiplicative functions several times.} \begin{lemma}\label{lem:multavg} Let $C\geqslant1$, $D\geqslant2$, let $E$ be a non-zero integer, and let $f\geqslant0$ be a multiplicative function with \[ f(p^\delta)\leqslant C(\delta+1)^C\bigl(\gcd(p^\delta,E)^{1/2}+p^{\delta-1}\bigr) \] for all prime powers $p^\delta$. Then $\sum_{d\leqslant D}f(d)/d\ll_{C,\varepsilon}(D|E|)^{\varepsilon}$. \end{lemma} \begin{proof} \rev{The hypothesis says that $f(p^\delta)/p^\delta$ is about $p^{-1}$ or smaller for $p\nmid E$, so the Euler product converges after a slight shift; the primes dividing $E$ contribute a divisor-type factor.} By Rankin's trick with $\sigma=\varepsilon$, the sum is at most $D^{\sigma}\prod_p\bigl(1+\sum_{\delta\geqslant1}f(p^\delta)p^{-\delta(1+\sigma)}\bigr)$. If $p\nmid E$, then \[ \sum_{\delta\geqslant1}\frac{f(p^\delta)}{p^{\delta(1+\sigma)}}\leqslant C\sum_{\delta\geqslant1}(\delta+1)^C\Bigl(\frac1{p^{\delta(1+\sigma)}}+\frac1{p^{1+\delta\sigma}}\Bigr)\leqslant\frac{C_\sigma}{p^{1+\sigma}}, \] and if $p\mid E$, the same computation with $\gcd(p^\delta,E)^{1/2}\leqslant p^{\delta/2}$ gives the bound $C_\sigma p^{-1/2}$. Hence the product is \[ \ll_\sigma C_\sigma^{\omega(E)}\ll_\varepsilon|E|^{\varepsilon}. \] \end{proof} \begin{proposition}\label{prop:singflags} The flag terms with $\vrho/\gcd(\vrho)\in\cC_F$ and $\bu\neq\bzero$ have relative size $\ll Q^{-1/2+\varepsilon}t^{-4}$. \end{proposition} \begin{proof} \rev{For each family we bound the ratio $\mathcal R$ of the sum over $q'$ and $\bu$ to the trivial quantity, and multiply by the proportion of the mass carried by the family. Corank one and corank two are treated separately, and within corank one the flags along a rational line in the discriminant curve need an extra argument, because they carry the largest proportion of mass, $Q^{-1/3}$. The final table collects the results.} Fix a range $(Y,W)$ and a flag with direction $\vc\in\cC_F$ of corank $r$. We fix also $d\mid G$ and $k=dk''$, and sum over the $q'\leqslant2Y/k$ coprime to $dN'_\vc$ and over $\bu$. As in the proof of Proposition~\ref{prop:flagterms}, it suffices to bound the ratio $\mathcal R$ of this sum to the trivial quantity $\sum_{q'}\#\cA^\flat q^{s/2}L^s$, and then to average $\mathcal R$ with the weight $\gcd(d,g)/d$ for $d$, which comes from the sum over $G$, and the weight $1/k''$ for $k''$, which comes from the number of $q$ with a given $k$. By Lemma~\ref{lem:singlocal}, $|S_k(\va,\bu)|=k^{s/2}K(\va,k)^{1/2}\one_{\bu\in\cM(\va,k)}$, and \begin{equation}\label{eq:singK} \frac1{\#\cA_k}\sum_{\va\in\cA_k}K(\va,k)^{1/2}\leqslant K(\vc,k'')^{1/2}\alpha\leqslant c_Fk''\alpha . \end{equation} \emph{Corank one.} Let $r=1$. We use the first bound of Lemma~\ref{lem:singlocal}(ii), which loses $q'^{1/2}$ against the trivial bound $\varphi(q')q'^{s/2}$. For fixed $q'$ and $\va\in\cA_k$, the vectors $\bu$ with $q'\mid\bv''$ and $\bu\bmod k\in\cM(\va,k)$ form a coset of a lattice of index $q'K(\va,k)$, since $\bh_1$ is primitive and $q'$ is coprime to $k$. By Lemma~\ref{lem:cosets} it has $\ll L^s/(q'K(\va,k))+L^{s-1}$ points with $|\bu|\leqslant L$. Averaging $q'^{\pm1/2}$ over $q'\leqslant2Y/k$ with the weight $\varphi(q')q'^{s/2}$ of the trivial quantity, we get \[ \mathcal R\ll\Bigl(\frac kY\Bigr)^{1/2}+\Bigl(\frac Yk\Bigr)^{1/2}\frac{K(\vc,k'')^{1/2}\alpha}L\ll\Bigl(\frac{dk''}Y\Bigr)^{1/2}+\Bigl(\frac Yd\Bigr)^{1/2}\frac{k''^{1/2}\alpha}L . \] \begin{orevblock} The quantity $\alpha$ depends on $k''$ only through the set of primes $p\mid d$ which divide $k''$; these are the primes dividing $d_1$. More precisely, the proof of Lemma~\ref{lem:singavg} gives $\alpha\leqslant\prod_{p\mid d}\alpha_p$, where $\alpha_p\leqslant p^{\mu_p/2}p^{\delta_p}$ if $p\mid k''$, while, for the ordinary flags, \[ \alpha_p\leqslant\beta_p:=C_p(\delta_p+1)^2\gcd(p^{\delta_p},g)\gcd(p^{\delta_p},E_{\vnu_0})^{1/2} \] if $p\nmid k''$. A prime $p\mid d$ which divides $k''$ contributes a factor at least $p$ to $k''$, and there are $\ll Q^{\varepsilon}$ values of $k''$ altogether (Lemma~\ref{lem:freeloss}(ii)). Grouping the $k''$ according to the set of primes $p\mid d$ which divide them, we obtain, for the ordinary flags, \begin{equation}\label{eq:k2avg} \sum_{k''}\frac{\alpha}{k''^{1/2}}\ll Q^{\varepsilon}\prod_{p\mid d}\bigl(\beta_p+p^{\mu_p/2}p^{\delta_p-1/2}\bigr),\qquad\sum_{k''}\frac{\alpha}{k''}\ll Q^{\varepsilon}\prod_{p\mid d}\bigl(\beta_p+p^{\mu_p/2}p^{\delta_p-1}\bigr). \end{equation} For the ordinary flags, by~\eqref{eq:k2avg} the average of $\mathcal R$ over $k''$ with the weight $1/k''$ is \[ \ll Q^{\varepsilon}\Bigl(\frac dY\Bigr)^{1/2}+Q^{\varepsilon}\frac{Y^{1/2}}L\,d^{-1/2}\prod_{p\mid d}\bigl(\beta_p+p^{\mu_p/2}p^{\delta_p-1/2}\bigr). \] Since $\gcd(p^{\delta_p},g)\geqslant1$, the product is at most $\gcd(d,g)\prod_{p\mid d}\gamma_p$ with \[ \gamma_p=C_p(\delta_p+1)^2\gcd(p^{\delta_p},E_{\vnu_0})^{1/2}+p^{\mu_p/2}p^{\delta_p-1/2}. \] We average over $d\leqslant Z'_\vc$ with the weight $\gcd(d,g)/d$, which comes from the sum over $G$, and then over $g$ with the weight $\tau(g)g^{-2}$ of the ordinary flags. The first term gives $\ll Q^{\varepsilon}(Z'_\vc/Y)^{1/2}\ll Q^{\varepsilon}$. In the second, the factor $\gcd(d,g)^2$ \orev{is absorbed by the sum over $g$}, because \[ \sum_g\tau(g)g^{-2}\gcd(d,g)^2\leqslant\sum_{e\mid d}e^2\sum_{e\mid g}\tau(g)g^{-2}\ll\tau(d)^2. \] The remaining sum is $\sum_{d\leqslant Z'_\vc}f(d)/d$ with the multiplicative function \[ f(d)=\tau(d)^2d^{-1/2}\prod_{p\mid d}\gamma_p, \] and \[ f(p^\delta)\leqslant C(\delta+1)^C\bigl(\gcd(p^\delta,E_{\vnu_0})^{1/2}+p^{\delta-1}\bigr), \] because $p^{-\delta/2}p^{\delta-1/2}\leqslant p^{\delta-1}$ for $\delta\geqslant1$ and $p^{\mu_p}$ is bounded. So Lemma~\ref{lem:multavg} applies with $E=E_{\vnu_0}$, and $|E_{\vnu_0}|\ll Q^{C}$. Hence, for the ordinary flags, \end{orevblock} \begin{equation}\label{eq:R1ord} \mathcal R\ll Q^{\varepsilon}\Bigl(1+\frac{Y^{1/2}}L\Bigr)\ll Q^{1/6+\varepsilon}t^{-1} \end{equation} on average. For the flags of the first kind and the exceptional flags we use the bound $\alpha\leqslant c_Fd$ of Lemma~\ref{lem:singavg}; the same computation, now with \[ \sum_{d\leqslant Z'_\vc}\gcd(d,g)d^{-1}(Y/d)^{1/2}d\ll\tau(g)Y^{1/2}Z'^{1/2}_\vc, \] gives on average \begin{equation}\label{eq:R1crude} \mathcal R\ll Q^{\varepsilon}\Bigl(1+\frac{Y^{1/2}Z'^{1/2}_\vc}L\Bigr). \end{equation} \emph{The flags along a line.} The bound~\eqref{eq:R1crude} is not good enough for the flags of the first kind with $\vc\in\cC_F^{\rm lin}$, which carry a proportion $Q^{-1/3}$ of the mass. For them we use that all members of the line $\ell_i$ have the common kernel vector $\bx_0=\bh_1$ (Lemma~\ref{lem:lineavg}(iii)). Let $p\mid d$. By Lemma~\ref{lem:flagfactor}, with $\vnu_0=\vnu_i$, the numerators in $\cA_p$ are congruent modulo $p^{n_p-f_p}$ to vectors of $\ell_i\cap\ZZ^3$. The proof of Lemma~\ref{lem:mrestrict} applies with $\lambda\vc$ replaced by any vector of $\ell_i\cap\ZZ^3$, because every such vector $\vb$ satisfies $M_\vb\bx_0=\bzero$ and $F_\vb(\bx_0)=0$. Hence $S_{p^{n_p}}(\va,\bu)=0$ unless $\bx_0\cdot\bu\equiv0\pmod{p^{n_p-f_p}}$. Together with Lemma~\ref{lem:singlocal}(i), $S_q(\va,\bu)\neq0$ implies $\bx_0\cdot\bu\equiv0\pmod{q/e}$, where $e=\prod_{p\mid d}p^{f_p}=\gcd(d,g)$. Suppose first that $q/e>C_2L$. Then $\bx_0\cdot\bu=0$, so $\bu$ lies in a fixed lattice of rank $s-1$ and there are $\ll L^{s-1}$ of them; for them the condition $q'\mid\bv''$ holds trivially. We use the second bound of Lemma~\ref{lem:singlocal}(ii) and sum over $q'$ first, as in the proof of Proposition~\ref{prop:flagterms}, and at the primes dividing $k$ we use only $K(\va,k)\leqslant c_Fk^2$. The vectors with $t_\vc(\bv')=0$, of which there are $\ll L^{s-3+\varepsilon}$, lose $q'^{1/2}$ in the sum over $q'$. This gives \[ \mathcal R\ll Q^{\varepsilon}\Bigl(\frac kL+\Bigl(\frac Yk\Bigr)^{1/2}\frac k{L^2}\Bigr)\ll Q^{\varepsilon}\frac{dk''}L\Bigl(1+\frac{Y^{1/2}}L\Bigr). \] The factor $k''$ is cancelled by the weight $1/k''$. The flags with $d\asymp D$ have $|\vc|\leqslant Q^{2/3}/D$, and by~\eqref{eq:singmass} they carry a proportion $\ll Q^{-1/3}D^{-1}$ of the total mass. Summing over dyadic $D$, these terms have relative size \[ \ll Q^{-1/3+\varepsilon}L^{-1}(1+Y^{1/2}L^{-1})\ll Q^{-1/2+\varepsilon}t^{-2}. \] Suppose next that $q/e\leqslant C_2L$. Then $YC_2L$. Then Lemma~\ref{lem:singlocal}(i) gives $\bv''=\bzero$, so there are $\ll L^{s-2}$ vectors $\bu$, and we use the second bound of Lemma~\ref{lem:singlocal}(ii), summing over $q'$ first. This loses $q'^{1/2}$ against the trivial bound, and the $\bu$ with $t_\vc(\bv')=0$, of which there are $\ll L^{s-4+\varepsilon}$ by~\cite[Theorem~2]{HB02}, lose $q'$. With~\eqref{eq:singK} we get \[ \mathcal R\ll Q^{\varepsilon}\Bigl(\Bigl(\frac Yk\Bigr)^{1/2}\frac{k''\alpha}{L^2}+\frac Yk\cdot\frac{k''\alpha}{L^{4}}\Bigr)=Q^{\varepsilon}\Bigl(\Bigl(\frac Yd\Bigr)^{1/2}\frac{k''^{1/2}\alpha}{L^2}+\frac Yd\cdot\frac{\alpha}{L^{4}}\Bigr). \] Suppose next that $q_1\leqslant C_2L$. We use the first bound of Lemma~\ref{lem:singlocal}(ii), which loses $q'$, and we count the $\bu$ in two ways: for each $\va\in\cA_k$ they lie in a coset of index $q'^2K(\va,k)$, and they satisfy $q_1\mid\bv''$, which leaves $\ll L^s/q_1^2$ of them. Hence \[ \mathcal R\ll q'\Bigl(\frac1{q'^2}+k''\alpha\min\Bigl(\frac1L,\frac1{q_1^2}\Bigr)\Bigr)\ll\frac1{q'}+\frac{q'k''\alpha}{q_1L^{1/2}}=\frac1{q'}+\frac{\alpha}{L^{1/2}}, \] since $q_1=q'k''$. For the ordinary flags we use the second bound of Lemma~\ref{lem:singavg}, and~\eqref{eq:k2avg}\orev{ (the first bound for the terms with $k''^{1/2}\alpha$, the second for the term with $\alpha$, after the weight $1/k''$)}; the averages over $d$ and $g$ are bounded by Lemma~\ref{lem:multavg} as before, and we find \[ \mathcal R\ll Q^{\varepsilon}\Bigl(1+\frac{Y^{1/2}}{L^2}+\frac Y{L^4}+\frac1{L^{1/2}}\Bigr)\ll Q^{\varepsilon}\bigl(1+Q^{-1/6}t^{-4}\bigr) \] on average. For the flags of the first kind and the exceptional flags we use $\alpha\leqslant c_Fd$, and find \[ \mathcal R\ll Q^{\varepsilon}(1+Y^{1/2}Z'^{1/2}_\vc L^{-2}+YL^{-4}+Z'_\vc L^{-1/2})\ll Q^{1/2+\varepsilon}t^{-4}, \] since $Z'_\vc\leqslant Q^{2/3}$ and $L\gg P^{1/2}t$. \begin{revblock} \emph{Conclusion.} By Lemma~\ref{lem:relsize}, the relative size of a family is at most the proportion of the total mass $Y^2Q^2$ of the flag terms that it carries, multiplied by the average $\mathcal R$ of the ratio over the family. We combine the proportions computed before Lemma~\ref{lem:multavg} with the bounds for $\mathcal R$ obtained above. Throughout we use $Y\leqslant Q$, $Z'_\vc\leqslant Q^{2/3}$, $L\gg Q^{1/3}t$ and $t\ll Q^{\varepsilon}$; in particular \begin{equation}\label{eq:YLbounds} \frac{Y^{1/2}}L\ll Q^{1/6}t^{-1},\qquad\frac{Y^{1/2}Z'^{1/2}_\vc}L\ll Q^{1/2}t^{-1},\qquad1\ll Q^{\varepsilon}t^{-1}. \end{equation} There are $O(\log Q)$ dyadic ranges of $|\vc|$, and the factors $\log Q$ are absorbed into $Q^{\varepsilon}$. \emph{(a) Ordinary flags of corank one.} By~\eqref{eq:singmass}, the ordinary flags with $\vc\in\cC_F^{\rm curve}$ and $|\vc|\asymp H$ carry a proportion $\ll Q^{-2/3+\varepsilon}H^{-1}$ of the mass, and those with $\vc\in\cC_F^{\rm lin}$ a proportion $\ll Q^{-2/3}$. By~\eqref{eq:R1ord} and~\eqref{eq:YLbounds}, $\mathcal R\ll Q^{\varepsilon}(1+Y^{1/2}L^{-1})\ll Q^{1/6+\varepsilon}t^{-1}$ on average. So these flags have relative size \[ \ll Q^{-2/3+\varepsilon}\cdot Q^{1/6+\varepsilon}t^{-1}=Q^{-1/2+2\varepsilon}t^{-1}. \] \emph{(b) Flags of the first kind of corank one, not along a line.} These are the flags of the first kind with $\vc\in\cC_F^{\rm curve}$, and those with one of the finitely many $\vc\in\cC_F^{\rm lin}$ for which $\vy_\vc\neq\pm\vnu_i$. For the first ones, $\lambda_1(\vc)\geqslant1$ and~\eqref{eq:curvecount} give \[ \sum_{\substack{\vc\in\cC_F^{\rm curve}\\ |\vc|\asymp H}}\Omega^{(1)}_\vc\ll Y^2\frac{Q^{2/3}}H\,U\cdot H^{1+\varepsilon}=Y^2Q^{1+\varepsilon}, \] a proportion $\ll Q^{-1+\varepsilon}$ of the mass. The second ones have bounded $|\vc|$, so $\Omega^{(1)}_\vc\ll Y^2Q^{2/3}U=Y^2Q$, again a proportion $\ll Q^{-1}$. For all of them we use~\eqref{eq:R1crude}, which by~\eqref{eq:YLbounds} gives $\mathcal R\ll Q^{\varepsilon}(1+Y^{1/2}Z'^{1/2}_\vc L^{-1})\ll Q^{1/2+2\varepsilon}t^{-1}$ on average. So these flags have relative size \[ \ll Q^{-1+\varepsilon}\bigl(1+Y^{1/2}Q^{1/3}L^{-1}\bigr)\ll Q^{-1+\varepsilon}\cdot Q^{1/2+\varepsilon}t^{-1}=Q^{-1/2+2\varepsilon}t^{-1}. \] \emph{(c) Flags along a line.} The remaining flags of the first kind of corank one are those with $\vc\in\cC_F^{\rm lin}$ and $\vy_\vc=\pm\vnu_i$, that is, the flags along the lines $\ell_i$. They were treated above: the case $q/e>C_2L$ gives relative size $\ll Q^{-1/2+\varepsilon}t^{-2}$, and the case $q/e\leqslant C_2L$ gives $\ll Q^{-1/2+\varepsilon}$. \emph{(d) Directions of corank two.} The set $\cC_F^{(2)}$ is finite. Its ordinary flags carry a proportion $\ll Q^{-2/3}$ of the mass and have $\mathcal R\ll Q^{\varepsilon}(1+Q^{-1/6}t^{-4})$; its flags of the first kind carry a proportion $\ll Q^{-1}$ and have $\mathcal R\ll Q^{1/2+\varepsilon}t^{-4}$. So they have relative size \[ \ll Q^{-2/3+\varepsilon}\bigl(1+Q^{-1/6}t^{-4}\bigr)+Q^{-1}\cdot Q^{1/2+\varepsilon}t^{-4}\ll Q^{-1/2+\varepsilon}t^{-4}. \] \emph{(e) Exceptional flags.} They carry a proportion $\ll Q^{-4/3+\varepsilon}$ of the mass. For them $\mathcal R$ is bounded by~\eqref{eq:R1crude} if $\vc$ has corank one, and by the bound for the flags of the first kind of corank two otherwise; in both cases $\mathcal R\ll Q^{1/2+5\varepsilon}t^{-4}$ by~\eqref{eq:YLbounds}, since $t^{-1}\ll Q^{3\varepsilon}t^{-4}$. So they have relative size $\ll Q^{-5/6+6\varepsilon}t^{-4}$. Since $t\ll Q^{\varepsilon}$, each of the bounds in~(a)--(e) is $\ll Q^{-1/2+C\varepsilon}t^{-4}$ for a constant $C$, and this proves the proposition. \end{revblock} \begin{orevblock} The table below summarises the cases. In the table, ``mass'' is the proportion of the total mass $Y^2Q^2$ of the flag terms carried by the family (for the flags along a line, by those with $d\asymp D$, respectively $e\asymp E$), $\mathcal R$ is the ratio to the trivial bound on average over the family (including the factor from the integrals where it is used), and the last column is their product, summed over the dyadic parameters. Throughout, $L\asymp Q^{1/3+\varepsilon}t$, $Y\leqslant Q$ and $Z'_\vc\leqslant Q^{2/3}$. \begin{center}\small \renewcommand{\arraystretch}{1.3} \begin{tabular}{llll} \toprule family & mass & $\mathcal R$ & relative size\\ \midrule corank $1$, ordinary & $Q^{-2/3+\varepsilon}$ & $Q^{\varepsilon}(1+Y^{1/2}/L)$ & $Q^{-1/2+\varepsilon}t^{-1}$\\ corank $1$, first kind, $\vc\in\cC_F^{\rm curve}$ & $Q^{-1+\varepsilon}$ & $Q^{\varepsilon}(1+Y^{1/2}Z'^{1/2}_\vc/L)$ & $Q^{-1/2+\varepsilon}t^{-1}$\\ along a line, $q/e>C_2L$ & $Q^{-1/3}D^{-1}$ & $Q^{\varepsilon}DL^{-1}(1+Y^{1/2}/L)$ & $Q^{-1/2+\varepsilon}t^{-2}$\\ along a line, $q/e\leqslant C_2L$ & $Q^{-1/3}E^{-1}$ & $Q^{-1/3+\varepsilon}E^{3/2}$ & $Q^{-1/2+\varepsilon}$\\ corank $2$, ordinary & $Q^{-2/3}$ & $Q^{\varepsilon}(1+Q^{-1/6}t^{-4})$ & $Q^{-2/3+\varepsilon}t^{-4}$\\ corank $2$, first kind & $Q^{-1}$ & $Q^{1/2+\varepsilon}t^{-4}$ & $Q^{-1/2+\varepsilon}t^{-4}$\\ exceptional & $Q^{-4/3+\varepsilon}$ & $Q^{1/2+\varepsilon}t^{-4}$ & $Q^{-5/6+\varepsilon}t^{-4}$\\ \bottomrule \end{tabular} \end{center} \end{orevblock} \end{proof} \orev{Thus the singular directions cause no loss even for $s=22$:} they carry a proportion at most $Q^{-1/3}$ of the mass, and on them the kernel of $M_\vc$, combined with the averages over the numerators of Lemma~\ref{lem:Kline}, recovers almost all of the saving of the sum over $\lambda$. \subsection{The bookkeeping}\label{sec:proof23} \rev{We can now collect the estimates. For each family of terms we recall the saving obtained, as a relative size compared with the bound $B(Y,W)$ of the unrefined method, and check that it is at least the saving $P^{\theta_s}$ required by Lemma~\ref{lem:margin}, with a little to spare. The point and plane terms save the square root $Y^{1/2}$ from the sums over the numerators and $X^{1/2}$ from the integrals, which on the critical curve is $(YX)^{1/2}\asymp Q^{1/2}\asymp P^{3/4}$; the same is true of the generic flag terms, apart from one term discussed at the end.} We now prove Theorem~\ref{thm:23} by checking the hypothesis of Lemma~\ref{lem:margin} for each family of terms. Fix a dyadic range $(Y,W)$, with $X$, $t$ and $L$ as in~\S\ref{sec:margin}; recall that $L\asymp P^{1/2+\varepsilon}t$ and $Q^{1/3}\asymp P^{1/2}$. For $s=23$ the target is relative size $P^{-1/4-\kappa}t^{-s/2-2}$, and for $s=24$ it is $P^{-\kappa}t^{-s/2-2}$. \emph{The vector $\bu=\bzero$.} As in the proofs of Propositions~\ref{prop:N1} and~\ref{prop:exc}, these terms contribute $O(P^{3s/4-3/2+\varepsilon})$, which is $o(P^{s-6})$ for $s\geqslant22$. \emph{Point terms.} For $C(\bu)\neq0$, Proposition~\ref{prop:pointterms} saves $Y^{1/2}$ on average over $q$, uniformly in $\vw$, and Lemma~\ref{lem:integrals2} with Lemma~\ref{lem:etaavg}(i) saves $X^{1/2}$ on average over $\vw$. So these terms have relative size \[ \ll Q^{\varepsilon}(YX)^{-1/2}=Q^{\varepsilon}(tQ)^{-1/2}\ll P^{-3/4+\varepsilon}t^{-1/2}. \] The $\bu$ with $C(\bu)=0$ number $\ll L^{s-3}$ (Lemma~\ref{lem:E0count}), and contribute relative size $\ll L^{-3}$. \emph{Plane terms with $\vnu_0\notin\cN_F$.} For $C_{\vnu_0}(\bu)\neq0$ and $t'_{\vc_0}(\bu)\neq0$, Propositions~\ref{prop:planeterms} and~\ref{prop:planeZ2} save $Y^{1/2}$, and the factor $\gcd(q^\sharp,g)$ \orev{costs only $Q^{\varepsilon}$}, as explained after Proposition~\ref{prop:planeZ2}; with Lemma~\ref{lem:etaavg}(i) the relative size is $\ll P^{-3/4+\varepsilon}t^{-1/2}$. The remaining $\bu$ form a proportion $\ll L^{-2+\varepsilon}$, by Lemma~\ref{lem:E0count}(ii) and the remark after Proposition~\ref{prop:planeZ2}, and the trivial bound gives relative size $\ll L^{-2+\varepsilon}$. \emph{Plane terms with $\vnu_0\in\cN_F$.} By Proposition~\ref{prop:excplanes22}, relative size $\ll Q^{-1/2+\varepsilon}t^{-1}\ll P^{-3/4+\varepsilon}t^{-1}$. \emph{Generic flag terms.} Let $\vc$ be non-singular. By~\eqref{eq:etashift} and Lemma~\ref{lem:integrals2}, the integrals on the support of a flag term with direction $\vc$ are \[ \ll Q^{\varepsilon}P^sX^{-(s-2)/2}\min\bigl(1,(X\eta(\hat\vc))^{-1/2}\bigr). \] By~\eqref{eq:normalisation} and Proposition~\ref{prop:flagterms}, the relative size of the terms with $F^*_\vc(\bu)\neq0$ is therefore \[ \ll\frac{Q^{\varepsilon}}{Y^2Q^2}\sum_\vc\Omega^+_\vc\Bigl(\Bigl(\frac{Z'_\vc}Y\Bigr)^{1/2}+\frac{Z'_\vc}L\Bigr)\min\bigl(1,(X\eta(\hat\vc))^{-1/2}\bigr). \] In each dyadic range $|\vc|\asymp H$ the factor in the large brackets is constant up to a factor $2$, so Lemma~\ref{lem:etaavg}(ii), applied in each such range, replaces the minimum by $Q^{\varepsilon}X^{-1/2}$. Lemma~\ref{lem:dmass}(ii) with $a=\frac12$ and $a=1$ then gives relative size \begin{align*} &\ll Q^{\varepsilon}X^{-1/2}\Bigl(\frac1{Y^{1/2}}+\frac1L\Bigr)\ll Q^{\varepsilon}\bigl((tQ)^{-1/2}+X^{-1/2}L^{-1}\bigr)\\ &\ll P^{-3/4+\varepsilon}t^{-1/2}+P^{-1/2+\varepsilon}X^{-1/2}t^{-1}. \end{align*} The terms with $F^*_\vc(\bu)=0$ have relative size $\ll Q^{\varepsilon}L^{-2}$, by~\eqref{eq:flag0} and Lemma~\ref{lem:dmass}(ii) with $a=1$. \emph{Flag terms with singular direction.} By Proposition~\ref{prop:singflags}, relative size $\ll Q^{-1/2+\varepsilon}t^{-4}\ll P^{-3/4+\varepsilon}t^{-4}$. All these relative sizes are $\ll P^{-1/2+\varepsilon}t^{-4}$. This is $\ll P^{-\theta_s-\kappa}t^{-s/2-2}$ with $\kappa=\frac14-\varepsilon$ for $s=23$ and $\kappa=\frac12-\varepsilon$ for $s=24$. By Lemma~\ref{lem:margin} this proves Theorem~\ref{thm:23}. We note for later use that every family except one has relative size $\ll P^{-3/4+\varepsilon}t^{-4}$. The exception is the part \begin{equation}\label{eq:badterm} P^{-1/2+\varepsilon}X^{-1/2}t^{-1} \end{equation} of the generic flag terms, which comes from the term $Z'_\vc/L$ in~\eqref{eq:flag1}. It is smaller than $P^{-1/2-\kappa}$ unless $X\leqslant P^{2\kappa}$, that is, unless $Y$ is close to $Q$. This is the only obstacle to $s=22$, and it is removed in the next section. \begin{remark}[parity] For even $s$ the sums over $\lambda$ are Ramanujan sums (Lemma~\ref{lem:Tprime}(ii)), and for the flag terms they save $q$ rather than $q^{1/2}$, apart from the dual vectors on the dual quadrics. This does not help with~\eqref{eq:badterm}, which comes from moduli whose part prime to $\gcd(q,G)N_\vc$ is small, so we do not use it. \end{remark} %====================================================================== \section{\texorpdfstring{\orev{The case $s=22$}}{The case s=22}}\label{sec:s22} %====================================================================== In this section we prove the remaining case of Theorem~\ref{thm:mainA}. \begin{theorem}\label{thm:22} Under the hypotheses of Theorem~\ref{thm:main}, the asymptotic formula~\eqref{eq:mainasymp} holds for $s=22$, for some $\Delta>0$. \end{theorem} For $s=22$ the target in Lemma~\ref{lem:margin} is relative size $P^{-1/2-\kappa}t^{-13}$. By the bookkeeping in~\S\ref{sec:proof23}, every family of terms meets this target, with $\kappa=\frac14-\varepsilon$, except the part~\eqref{eq:badterm} of the generic flag terms. This part comes from the second term $Z'_\vc/L$ in~\eqref{eq:flag1}, which in turn comes from the moduli $q$ whose part $q'$ prime to $dN_\vc$ is small, and for which $K(\va,k)$ is close to its largest possible value $c_Fk^2$. In~\eqref{eq:flag2} the factor $K(\vc,k'')^{1/2}$ was bounded instead by $D_{s-1}(\vc)^{1/2}$, where $D_{s-1}(\vc)$ is the greatest common divisor of the $(s-1)\times(s-1)$ minors of $M_\vc$. A prime $p$ divides $D_{s-1}(\vc)$ exactly when $M_\vc$ has corank at least $2$ modulo $p$. So what we need is that the members $\vc$ which have corank two modulo many primes are rare. This is a transversality statement\orev{: modulo $p^k$ the reductions of corank two lie on finitely many lines.} \begin{revblock} Let us explain the shape of the argument. A member $F_\vc$ has corank two modulo $p$ only if $[\vc]$ reduces to one of the at most $(s-1)^2$ points of $\cZ_2(\FF_p)$, so the proportion of such $\vc$ is about $p^{-2}$. If $p^k$ divides $D_{s-1}(\vc)$, Lemma~\ref{lem:corank2lines} below shows that $\vc$ is congruent modulo $p^k$ to a multiple of one of these points, a condition of probability about $p^{-2k}$. Combining the primes, a divisor $m>T$ of $D_{s-1}(\vc)$ forces $\vc$ into one of a few lattices of index $m^2$. Since we do not know $m$ exactly, we have to sum the resulting proportions $m^{-2}$ over $m>T$, and the proportion of $\vc$ with $D_{s-1}(\vc)>T$ comes out as about $T^{-1}$ (Lemma~\ref{lem:Dlargecount}); after the separate treatment of the bad primes we use the weaker bound $T^{-1/2}$ (Lemma~\ref{lem:Dsparse}). This sparsity is then weighed against the loss $D_{s-1}(\vc)^{1/2}$ in~\eqref{eq:flag2}. In~\S\ref{sec:Dlarge} we prove the sparsity statements, and in~\S\ref{sec:proof22} we balance the two bounds~\eqref{eq:flag1} and~\eqref{eq:flag2} with a threshold $T$. \end{revblock} \subsection{Members with many reductions of corank two}\label{sec:Dlarge} For $\vc$ with $\Delta(\vc)\neq0$ write $D^{\rm good}(\vc)$ for the largest divisor of $D_{s-1}(\vc)$ coprime to $D_F$. \begin{lemma}\label{lem:corank2lines} Let $p$ be a good prime and $k\geqslant1$. If $\vc,\vc'\in\ZZ^3$ are primitive, $p^k$ divides both $D_{s-1}(\vc)$ and $D_{s-1}(\vc')$, and $\vc\equiv\mu\vc'\pmod p$ for some integer $\mu$, then $\vc\equiv\lambda\vc'\pmod{p^k}$ for some integer $\lambda$ coprime to $p$. Consequently, for every integer $m\geqslant1$ coprime to $D_F$ there are at most $(s-1)^{2\omega(m)}$ vectors $\vbeta\in\ZZ^3$, primitive modulo every prime dividing $m$, such that every primitive $\vc$ with $m\mid D_{s-1}(\vc)$ lies in one of the lattices $\Lambda_{m,\vbeta}=\ZZ\vbeta+m\ZZ^3$, each of index $m^2$ in $\ZZ^3$. \end{lemma} \begin{proof} \rev{After a change of basis adapted to the two-dimensional kernel modulo $p$, the divisibility of $D_{s-1}$ by powers of $p$ is measured by a $2\times2$ Schur complement. If $\vc$ and $\vc'$ agree modulo $p^j$ but not modulo $p^{j+1}$ (up to scalars), the Schur complement of $\vc$ differs from that of $\vc'$ by $p^j$ times the restriction of $M_\vb$ to the kernel, which is non-zero by Lemma~\ref{lem:geometry}(v). So $D_{s-1}(\vc)$ cannot be divisible by more than $p^j$.} Since $p\mid D_{s-1}(\vc')$, all $(s-1)\times(s-1)$ minors of $M_{\vc'}$ vanish modulo $p$, so $M_{\vc'}$ has corank at least $2$ modulo $p$, and exactly $2$ by Lemma~\ref{lem:geometry}(i) applied over $\overline{\FF}_p$. Let $\overline W\subset\FF_p^s$ be its kernel modulo $p$, of dimension $2$. Choose $U\in\mathrm{GL}_s(\ZZ_p)$ whose first two columns reduce to a basis of $\overline W$. For $\vb\in\ZZ_p^3$ write \[ U^TM_\vb U=\begin{pmatrix}A_\vb&B_\vb\\ B_\vb^T&N_\vb\end{pmatrix}, \] with $A_\vb$ of size $2\times2$; these blocks are linear in $\vb$. Then $A_{\vc'}\equiv0$ and $B_{\vc'}\equiv0\pmod p$, and $N_{\vc'}$ is invertible modulo $p$ because $M_{\vc'}$ has rank $s-2$ modulo $p$. Whenever $N_\vb$ is invertible over $\ZZ_p$, the matrix $U^TM_\vb U$ is equivalent over $\ZZ_p$ to $\operatorname{diag}(N_\vb,S_\vb)$ with the Schur complement $S_\vb=A_\vb-B_\vb N_\vb^{-1}B_\vb^T$, so its invariant factors are $s-2$ units and the two invariant factors of $S_\vb$. Hence $v_p(D_{s-1}(\vb))$ is the smallest valuation of an entry of $S_\vb$. Replacing $\vc'$ by $\mu\vc'$ (note $p\nmid\mu$, as $\vc$ is primitive), we may assume $\vc\equiv\vc'\pmod p$. Let $j\geqslant1$ be the largest integer such that $\vc\equiv\lambda\vc'\pmod{p^j}$ for some $\lambda$ coprime to $p$, and suppose that $jC_p$ the primitive $\vc\in\ZZ^3$ with $D_{s-1}(\vc)\neq0$ and $p^k\mid D_{s-1}(\vc)$ lie in at most $(s-1)^2$ sets $\{\vc\equiv\lambda\vbeta\pmod{p^{k-C_p}}\}$, with $\vbeta\in\ZZ_p^3$ primitive. \end{lemma} \begin{proof} \rev{The argument is the same, carried out around the $p$-adic points of $\cZ_2$ instead of their reductions; the constant $C_p$ measures how degenerate the situation is modulo $p$, and is obtained by compactness.} For primitive $\vc\in\ZZ_p^3$ we have $D_{s-1}(\vc)=0$ exactly when $[\vc]\in\cZ_2(\QQ_p)$, and $\cZ_2(\QQ_p)$ has at most $(s-1)^2$ points by Lemma~\ref{lem:geometry} over $\overline\QQ_p$; choose a primitive $\vbeta\in\ZZ_p^3$ for each of them. Fix one. By Lemma~\ref{lem:geometry}(i) over $\overline\QQ_p$, $M_\vbeta$ has corank exactly $2$, so $\ker M_\vbeta\cap\ZZ_p^s$ is a saturated submodule of rank $2$, and there is $U\in\mathrm{GL}_s(\ZZ_p)$ whose first two columns span it. For $\vb\in\ZZ_p^3$ write $U^TM_\vb U=\left(\begin{smallmatrix}A_\vb&B_\vb\\ B_\vb^T&N_\vb\end{smallmatrix}\right)$ as in the proof of Lemma~\ref{lem:corank2lines}. Then $A_\vbeta=0$, $B_\vbeta=0$, and $N_\vbeta$ is non-singular; put $n_\vbeta=v_p(\det N_\vbeta)$. By Lemma~\ref{lem:geometry}(v) over $\overline\QQ_p$, $A_\vb\neq0$ for every $\vb\notin\QQ_p\vbeta$. \begin{orevblock}To make this quantitative, complete $\vbeta$ to a basis $\vbeta,\be_2,\be_3$ of $\ZZ_p^3$. For $\vb=b_1\vbeta+b_2\be_2+b_3\be_3$ we have $A_\vb=b_2A_{\be_2}+b_3A_{\be_3}$, since $A_\vbeta=0$, and $A_{\be_2},A_{\be_3}$ are linearly independent over $\QQ_p$. So the $3\times2$ matrix whose columns list the three entries of $A_{\be_2}$ and of $A_{\be_3}$ has a non-zero $2\times2$ minor; let $m_\vbeta$ be its valuation. By Cramer's rule $b_2$ and $b_3$ are combinations of two entries of $A_\vb$ with coefficients of valuation $\geqslant-m_\vbeta$, so $\min v_p(\text{entries of }A_\vb)\leqslant m_\vbeta+\min(v_p(b_2),v_p(b_3))$. If the reduction of $\vb$ modulo $p$ is not a multiple of $\bar\vbeta$, then $\min(v_p(b_2),v_p(b_3))=0$, and so $\min v_p(\text{entries of }A_\vb)\leqslant m_\vbeta$.\end{orevblock} Put $t_0=1+\max_\vbeta(n_\vbeta+m_\vbeta)$. The set $\mathcal K$ of primitive $\vc\in\ZZ_p^3$ with $\vc\not\equiv\lambda\vbeta\pmod{p^{t_0}}$ for all $\vbeta$ and $\lambda$ is compact, and $D_{s-1}$ does not vanish on it, so $v_p(D_{s-1}(\vc))\leqslant C_1$ on $\mathcal K$ for some $C_1$. \orev{(Here $v_p(D_{s-1}(\vc))$ is the smallest valuation of an $(s-1)\times(s-1)$ minor of $M_\vc$; the function $\vc\mapsto\max_m|m(\vc)|_p$ over these minors $m$ is continuous and positive on $\mathcal K$, hence bounded below by $p^{-C_1}$.)} Let $\vc$ be primitive with $D_{s-1}(\vc)\neq0$ and $v_p(D_{s-1}(\vc))\geqslant k>C_1$. Then $\vc\equiv\lambda\vbeta\pmod{p^{t_0}}$ for some $\vbeta$; let $j\geqslant t_0$ be maximal such that $\vc\equiv\lambda\vbeta\pmod{p^j}$ for some unit $\lambda$ ($j$ is finite as $D_{s-1}(\vc)\neq0$). Replacing $\vc$ by $\lambda^{-1}\vc$, which changes $D_{s-1}$ by a unit, we have $\vc=\vbeta+p^j\vb$ with $\bar\vb\notin\FF_p\bar\vbeta$. Since $j>n_\vbeta$, the matrix $N_\vc=N_\vbeta(I+p^jN_\vbeta^{-1}N_\vb)$ is non-singular, with $v_p(\det N_\vc)=n_\vbeta$ and $p^{n_\vbeta}N_\vc^{-1}$ integral. The Schur complement is \[ S_\vc=A_\vc-B_\vc N_\vc^{-1}B_\vc^T=p^jA_\vb-p^{2j}B_\vb N_\vc^{-1}B_\vb^T, \] and as $j>m_\vbeta+n_\vbeta$ the second term has all entries of valuation $\geqslant2j-n_\vbeta>j+m_\vbeta$, so some entry of $S_\vc$ has valuation at most $j+m_\vbeta$. For $k',l'\in\{1,2\}$, the $(s-1)\times(s-1)$ minor of $U^TM_\vc U$ obtained by deleting its $k'$-th row and $l'$-th column equals $\pm\det N_\vc$ times the entry of $S_\vc$ in the complementary position, by the Schur determinant formula applied to the remaining matrix, whose upper left block is $1\times1$; and $D_{s-1}(U^TM_\vc U)=D_{s-1}(\vc)$ up to a unit. Hence $k\leqslant v_p(D_{s-1}(\vc))\leqslant n_\vbeta+j+m_\vbeta$, so $\vc\equiv\lambda\vbeta\pmod{p^{k-n_\vbeta-m_\vbeta}}$. The lemma follows with $C_p=\max(C_1,\max_\vbeta(n_\vbeta+m_\vbeta))$. \end{proof} \begin{lemma}\label{lem:latticeprim} Let $\Lambda\subseteq\ZZ^3$ be a lattice with $m\ZZ^3\subseteq\Lambda$ and $[\ZZ^3:\Lambda]=m^2$. For $H\geqslant1$ the number of primitive vectors of $\ZZ^3$ in $\Lambda$ of length at most $H$ is $\ll1+H^2/m+H^3/m^2$. \end{lemma} \begin{proof} \rev{The three terms correspond to vectors on the shortest line of $\Lambda$, on its shortest plane, and in general position.} Let $\mu_1\leqslant\mu_2\leqslant\mu_3$ be the successive minima of $\Lambda$ and $\bv_1,\bv_2,\bv_3$ a reduced basis, so that $\mu_1\mu_2\mu_3\asymp m^2$, and $\mu_3\leqslant m$ because $m\ZZ^3\subseteq\Lambda$; hence $\mu_1\mu_2\gg m$. A vector $\bx=a_1\bv_1+a_2\bv_2+a_3\bv_3$ with $|\bx|\leqslant H$ has $|a_i|\ll H/\mu_i$. On the line $\RR\bv_1$ there are at most two primitive vectors of $\ZZ^3$. The vectors with $(a_2,a_3)\neq(0,0)$ exist only if $H\gg\mu_2$, and then their number is \[ \ll(1+H/\mu_1)(H/\mu_2)(1+H/\mu_3)\ll H^2/(\mu_1\mu_2)+H^3/(\mu_1\mu_2\mu_3)\ll H^2/m+H^3/m^2. \] \end{proof} \begin{lemma}\label{lem:ekedahl} For $H,M\geqslant1$, the number of primitive $\vc\in\ZZ^3$ with $|\vc|\leqslant H$ and $\Delta(\vc)\neq0$ such that some prime $p>M$ with $p\nmid D_F$ divides $D_{s-1}(\vc)$ is $\ll_\varepsilon H^3/M+H^{2+\varepsilon}$. \end{lemma} \begin{proof} \rev{This is an Ekedahl-type sieve statement: a fixed variety of codimension two (here the finite set $\cZ_2$ in $\PP^2$) has few points modulo large primes. For primes up to a constant times $H$ we count with Lemmas~\ref{lem:corank2lines} and~\ref{lem:latticeprim}; for larger primes a resultant shows that each $\vc$ has only $O(1)$ such prime divisors, and that each pair $(c_2,c_3)$ admits only $O(1)$ values of $c_1$.} For the primes $MC_0H$ we use a resultant. The common zeros in $\PP^2$ of all the $(s-1)\times(s-1)$ minors of $M_\vbeta$ form the finite set $\cZ_2$, so two suitable integral linear combinations $A(\vbeta),B(\vbeta)$ of these minors, homogeneous of degree $s-1$, have no common component. \begin{orevblock}(Take for $A$ any minor which is not identically zero. The curve $A=0$ has finitely many components, and on none of them do all the minors vanish, since $\cZ_2$ is finite; so for each component the combinations which vanish on it form a proper subspace, and we choose for $B$ an integral combination outside these finitely many subspaces.) Choose a primitive $\vv\in\ZZ^3$ with $A(\vv)\neq0$, and make a fixed unimodular change of the coordinates $\vbeta$ taking $\vv$ to $(1,0,0)$; this preserves primitivity and changes $H$ only by a constant factor. Then $A$ has the non-zero coefficient $a_0=A(\vv)$ of $\beta_1^{s-1}$, and since $A$ and $B$ are coprime in $\QQ[\vbeta]$, the resultant $R(\beta_2,\beta_3)=\operatorname{Res}_{\beta_1}(A,B)$ is a non-zero binary form.\end{orevblock} Since $R=UA+VB$ with $U,V\in\ZZ[\vbeta]$, every prime dividing $D_{s-1}(\vc)$ divides $R(c_2,c_3)$. If $R(c_2,c_3)\neq0$, then $|R(c_2,c_3)|\ll H^{\deg R}$, so at most $O(1)$ primes $p>C_0H$ divide it. For each such $p$ the polynomial $A(x,c_2,c_3)$ has degree $s-1$ modulo $p$ when $C_0>|a_0|$, so it has at most $s-1$ roots modulo $p$, and since $p>2H$ at most $s-1$ integers $c_1$ with $|c_1|\leqslant H$ satisfy $p\mid A(\vc)$. So each pair $(c_2,c_3)$ with $R(c_2,c_3)\neq0$ gives $O(1)$ vectors. The pairs with $R(c_2,c_3)=0$ lie on $O(1)$ lines through the origin, so there are $O(H)$ of them, each with at most $2H+1$ values of $c_1$. In total the primes $p>C_0H$ give $O(H^2)$ vectors. \end{proof} \begin{lemma}\label{lem:Dlargecount} Let $H,T\geqslant1$ and $0<\theta<1$. The number of primitive $\vc\in\ZZ^3$ with $|\vc|\leqslant H$, $\Delta(\vc)\neq0$ and $D^{\rm good}(\vc)>T$ is \[ \ll_{\theta,\varepsilon}\frac{H^{3+\varepsilon}}{T}+H^{3-\theta}+H^{2+\theta+\varepsilon}. \] \end{lemma} \begin{proof} \rev{If $D^{\rm good}(\vc)$ has a large prime factor, Lemma~\ref{lem:ekedahl} applies. Otherwise $D^{\rm good}(\vc)$ is built from small primes, and we can extract a divisor $m$ of a convenient size between $T$ and $TM$; then $\vc$ lies in one of the lattices of Lemma~\ref{lem:corank2lines} of index $m^2$, and Lemma~\ref{lem:latticeprim} counts its points.} Put $M=H^\theta$. The $\vc$ for which $D^{\rm good}(\vc)$ has a prime factor $p>M$ are counted by Lemma~\ref{lem:ekedahl}, which gives $\ll H^{3-\theta}+H^{2+\varepsilon}$. For the others, all prime factors of $D^{\rm good}(\vc)$ are at most $M$, and $D^{\rm good}(\vc)>T_1=\min(T,H^2)$. Building up a divisor of $D^{\rm good}(\vc)$ one prime factor at a time, we find a divisor $m$ of $D^{\rm good}(\vc)$ with $T_1T}}\Omega^+_\vc\ll_\varepsilon Q^{\varepsilon}T^{-c_1}\,Y^2Q^{2/3}\bigl(U^2H+UH^{3/2}\bigr). \] \end{lemma} \begin{proof} \rev{Step~1 converts the counting lemmas into a bound for the proportion $\pi(H,T)$ of directions with $D_{s-1}(\vc)>T$; Step~2 observes that $D_{s-1}(\vc)>T$ is impossible for very short $\vc$, which turns the term $H^{-1/2}$ into a power of $T$; and Step~3 inserts the weights $\Omega^+_\vc$, whose non-uniform part $U/\lambda_1(\vc)$ is handled by Cauchy's inequality.} \begin{orevblock} \emph{Step 1: the proportion.} Let $\pi(H,T)$ be the number of primitive $\vc$ with $|\vc|\asymp H$, $\Delta(\vc)\neq0$ and $D_{s-1}(\vc)>T$, divided by $H^3$. We claim that \[ \pi(H,T)\ll_\varepsilon H^{\varepsilon}\bigl(T^{-1/2}+H^{-1/2}\bigr). \] Write $D_{s-1}(\vc)=D^{\rm good}(\vc)D^{\rm bad}(\vc)$, where $D^{\rm bad}$ is composed of primes dividing $D_F$. If $D_{s-1}(\vc)>T$, then $D^{\rm good}(\vc)>T^{1/2}$ or $D^{\rm bad}(\vc)>T^{1/2}$. By Lemma~\ref{lem:Dlargecount} with $\theta=\frac12$ and $T^{1/2}$ in place of $T$, the number of $\vc$ of the first kind is $\ll H^{3+\varepsilon}T^{-1/2}+H^{5/2+\varepsilon}$. For the second kind write $D^{\rm bad}(\vc)=\prod_{p\mid D_F}p^{k_p}$. For each prime with $k_p>C_p$, Lemma~\ref{lem:corank2linesbad} gives a primitive $\vbeta_p$, from a set of at most $(s-1)^2$ vectors, with $\vc\equiv\lambda_p\vbeta_p\pmod{p^{k_p-C_p}}$. By the Chinese remainder theorem, $\vc\equiv\lambda\vbeta\pmod m$ with $m=\prod_{k_p>C_p}p^{k_p-C_p}$ and a vector $\vbeta$ which is primitive modulo every prime dividing $m$, chosen from a set of at most $(s-1)^{2\omega(D_F)}\ll1$ vectors; so $\vc$ lies in the lattice $\ZZ\vbeta+m\ZZ^3$, of index $m^2$. Moreover \[ m\geqslant D^{\rm bad}(\vc)/\prod_{p\mid D_F}p^{C_p}\gg T^{1/2}. \] By Lemma~\ref{lem:latticeprim} the number of these $\vc$, for a given tuple $(k_p)$, is $\ll1+H^2/m+H^3/m^2\ll H^2+H^3/T$. Since $v_p(D_{s-1}(\vc))\leqslant v_p(\Delta(\vc))\ll\log H$, there are $\ll(\log H)^{\omega(D_F)}\ll H^{\varepsilon}$ tuples. Adding up gives the claim. \emph{Step 2: only large $\vc$ occur.} If $\Delta(\vc)\neq0$, some $(s-1)\times(s-1)$ minor of $M_\vc$ is non-zero; it is $\ll|\vc|^{s-1}$, and $D_{s-1}(\vc)$ divides it. So $\pi(H,T)=0$ unless $H\gg T^{1/(s-1)}$, and in that case $H^{-1/2}\ll T^{-1/(2(s-1))}$. Since $T^{-1/2}\leqslant T^{-c_1}$, Step 1 gives \[ \pi(H,T)\ll_\varepsilon H^{\varepsilon}T^{-c_1}\qquad\text{and also}\qquad\pi(H,T)\ll_\varepsilon H^{\varepsilon}\bigl(T^{-1/2}+H^{-1/2}\bigr). \] \emph{Step 3: the weights.} For $|\vc|\asymp H$ we have $\Omega^+_\vc\asymp Y^2Q^{2/3}H^{-1}(U/\lambda_1(\vc)+U^2/H)$. The part with $U^2/H$ contributes \[ \ll Y^2Q^{2/3}U^2H\,\pi(H,T)\ll Q^{\varepsilon}T^{-c_1}Y^2Q^{2/3}U^2H. \] For the other part, Cauchy's inequality gives \[ \sum_{\substack{|\vc|\asymp H\\ D_{s-1}(\vc)>T}}\frac1{\lambda_1(\vc)}\leqslant\Bigl(\sum_{|\vc|\leqslant2H}\frac1{\lambda_1(\vc)^2}\Bigr)^{1/2}\bigl(H^3\pi(H,T)\bigr)^{1/2}\ll H^{5/2}\bigl(\pi(H,T)\log2H\bigr)^{1/2}, \] where we used $\sum_{|\vc|\leqslant2H}\lambda_1(\vc)^{-2}\ll H^2\log2H$. (Group the $\vc$ according to a primitive $\vy\perp\vc$ with $|\vy|=\lambda_1(\vc)\ll H^{1/2}$; the lattice $\vy^\perp\cap\ZZ^3$ has determinant $|\vy|$ and contains $\ll H^2/|\vy|+H$ vectors of length $\leqslant2H$, and $\sum_{|\vy|\ll H^{1/2}}|\vy|^{-2}(H^2/|\vy|+H)\ll H^2\log2H$.) By the second bound of Step 2, $\pi^{1/2}\ll H^{\varepsilon}(T^{-1/4}+H^{-1/4})$, so this part is \[ \ll Q^{\varepsilon}Y^2Q^{2/3}\bigl(T^{-1/4}UH^{3/2}+UH^{5/4}\bigr). \] Here $T^{-1/4}\leqslant T^{-c_1}$, as $c_1\leqslant\frac14$; and \[ UH^{5/4}=U^2H\cdot H^{1/4}/U\leqslant U^2H\,Q^{-1/6}\leqslant U^2H\,T^{-1/2}, \] because $H\leqslant Q^{2/3}$, $U=Q^{1/3}$ and $T\leqslant Q^{1/3}$. This proves the lemma. \end{orevblock} \end{proof} \subsection{Proof of Theorem~\ref{thm:22}}\label{sec:proof22} \rev{The plan is simple. We split the generic flag terms according to whether $D_{s-1}(\vc)$ is at most $T$ or larger than $T$. For the first kind we use the bound~\eqref{eq:flag2}, whose loss is at most $T^{1/2}$; for the second kind we use~\eqref{eq:flag1}, together with the sparsity of Lemma~\ref{lem:Dsparse}, which gains $T^{-c_1}$. Choosing $T$ to balance the two gives a saving of a small power of $P$ beyond the target $P^{-1/2}$.} Fix a dyadic range $(Y,W)$ and let $T\geqslant1$ be a parameter. We divide the generic flag terms with $F^*_\vc(\bu)\neq0$ according to the size of $D_{s-1}(\vc)$, and we use~\eqref{eq:flag1} for the first term $(Z'_\vc/Y)^{1/2}$ as before; it gives relative size $\ll P^{-3/4+\varepsilon}t^{-1/2}$. For the second term we argue as follows. If $D_{s-1}(\vc)\leqslant T$ we use~\eqref{eq:flag2}. With the integrals, exactly as in~\S\ref{sec:proof23}, and with the second bound of Lemma~\ref{lem:dmass}(ii), these terms have relative size \[ \ll Q^{\varepsilon}X^{-1/2}\frac{T^{1/2}\min(Y,Q^{2/3})^{1/2}}{Y^{1/2}L}. \] If $Y\geqslant Q^{2/3}$ this is \[ Q^{\varepsilon}T^{1/2}Q^{1/3}(YX)^{-1/2}L^{-1}=Q^{\varepsilon}T^{1/2}Q^{1/3}(tQ)^{-1/2}L^{-1}, \] and if $YtQ^{1/3}$. In both cases it is \[ \ll Q^{-1/2+\varepsilon}T^{1/2}t^{-3/2}. \] If $D_{s-1}(\vc)>T$ we use~\eqref{eq:flag1} without the integrals. By Lemma~\ref{lem:Dsparse}, and the computation in the proof of Lemma~\ref{lem:dmass}(ii) with $a=1$, these terms have relative size \[ \ll\frac{Q^{\varepsilon}}{Y^2Q^2}\sum_H\ \sum_{\substack{|\vc|\asymp H\\ D_{s-1}(\vc)>T}}\Omega^+_\vc\,\frac{Z'_\vc}L\ll Q^{\varepsilon}T^{-c_1}L^{-1}\ll Q^{-1/3+\varepsilon}T^{-c_1}t^{-1}. \] \begin{orevblock}We balance the two bounds by choosing $T=Q^{1/(3+6c_1)}$, which is at most $Q^{1/3}$ as Lemma~\ref{lem:Dsparse} requires. Then $Q^{-1/2}T^{1/2}=Q^{-1/3}T^{-c_1}=Q^{-1/3-c_1/(3+6c_1)}$, so both parts are $\ll Q^{-1/3-c_1/(3+6c_1)+\varepsilon}t^{-3/2}$. As $Q^{1/3}\asymp P^{1/2}$, this is $P^{-1/2-\kappa+\varepsilon}t^{-3/2}$ with \[ \kappa=\frac32\cdot\frac{c_1}{3+6c_1}=\frac{c_1}{2+4c_1}=\frac1{4s}, \] since $c_1=1/(2(s-1))$; for $s=22$, $c_1=\frac1{42}$, $T=Q^{7/22}$ and $\kappa=\frac1{88}$. All the other families have relative size $\ll P^{-3/4+\varepsilon}t^{-4}$ by~\S\ref{sec:proof23}, which is $\ll P^{-1/2-1/4+\varepsilon}t^{-13}$. So Lemma~\ref{lem:margin} applies with any $\kappa<\frac1{88}$, and gives Theorem~\ref{thm:22}.\end{orevblock} \rev{Together with Theorem~\ref{thm:23}, which covers $s\geqslant23$, this completes the proof of Theorem~\ref{thm:mainA}.} \begin{remark}[the size of $\Delta$] \begin{orevblock}The proof gives~\eqref{eq:mainasymp} for $s=22$ with every $\Delta<\frac1{88}$. All the families except the generic flag terms with $Y$ close to $Q$ are smaller than needed by $P^{1/4}$; the exponent $\frac1{88}=\frac1{4s}$ comes from the balance between the sparsity exponent $c_1=\frac1{42}$ of Lemma~\ref{lem:Dsparse} and the loss $D_{s-1}(\vc)^{1/2}$ in~\eqref{eq:flag2}. Any improvement of the exponent in Lemma~\ref{lem:Dsparse} improves $\Delta(22)$; we have not tried to optimise it.\end{orevblock} \end{remark} \begin{thebibliography}{Schu80} \bibitem[Bir62]{Bir} B.\,J. Birch, Forms in many variables, \emph{Proc. Roy. Soc. Ser. A} \textbf{265} (1961/62), 245--263. \bibitem[BL64]{BL} \orev{B.\,J. Birch and D.\,J. Lewis, Systems of three quadratic forms, \emph{Acta Arith.} \textbf{10} (1964/65), 423--442.} \bibitem[BHB17]{BHB} T.\,D. Browning and D.\,R. Heath-Brown, Forms in many variables and differing degrees, \emph{J. Eur. Math. Soc.} \textbf{19} (2017), 357--394. \bibitem[BM13]{BM} T.\,D. Browning and R. Munshi, Rational points on singular intersections of quadrics, \emph{Compos. Math.} \textbf{149} (2013), 1457--1494. \bibitem[CSS87]{CSS} J.-L. Colliot-Th\'el\`ene, J.-J. Sansuc and P. Swinnerton-Dyer, Intersections of two quadrics and Ch\^atelet surfaces. I, \emph{J. reine angew. Math.} \textbf{373} (1987), 37--107. \bibitem[Dav51]{Dav} H. Davenport, On a principle of Lipschitz, \emph{J. Lond. Math. Soc.} \textbf{26} (1951), 179--183. \bibitem[Die04]{Die04} \orev{R. Dietmann, Systems of rational quadratic forms, \emph{Arch. Math. (Basel)} \textbf{82} (2004), 507--516.} \bibitem[DFI93]{DFI} W. Duke, J. Friedlander and H. Iwaniec, Bounds for automorphic $L$-functions, \emph{Invent. Math.} \textbf{112} (1993), 1--8. \bibitem[HB96]{HB} D.\,R. Heath-Brown, A new form of the circle method, and its application to quadratic forms, \emph{J. reine angew. Math.} \textbf{481} (1996), 149--206. \bibitem[HB02]{HB02} D.\,R. Heath-Brown, The density of rational points on curves and surfaces, \emph{Ann. of Math.} \textbf{155} (2002), 553--595. \bibitem[HB07]{HB07} D.\,R. Heath-Brown, Cubic forms in 14 variables, \emph{Invent. Math.} \textbf{170} (2007), 199--230. \bibitem[HB10]{HB10} \orev{D.\,R. Heath-Brown, Zeros of systems of $\mathfrak p$-adic quadratic forms, \emph{Compos. Math.} \textbf{146} (2010), 271--287.} \bibitem[HB17]{HB3} D.\,R. Heath-Brown, Rational points on the intersection of three quadrics, \orev{\emph{Int. J. Number Theory} \textbf{13} (2017), 273--289.} \bibitem[HB18]{HB18} D.\,R. Heath-Brown, Zeros of pairs of quadratic forms, \emph{J. reine angew. Math.} \textbf{739} (2018), 41--80. \bibitem[HBP17]{HBP} D.\,R. Heath-Brown and L.\,B. Pierce, Simultaneous integer values of pairs of quadratic forms, \emph{J. reine angew. Math.} \textbf{727} (2017), 85--143. \bibitem[Klo26]{Klo} H.\,D. Kloosterman, On the representation of numbers in the form $ax^2+by^2+cz^2+dt^2$, \emph{Acta Math.} \textbf{49} (1926), 407--464. \bibitem[LRV24]{LRV} J. Li, S.\,L. Rydin Myerson and P. Vishe, A two-dimensional delta symbol method and its application to pairs of quadratic forms, preprint \orev{(2024)}, arXiv:2411.11355. \bibitem[Mun15]{Mun} R. Munshi, Pairs of quadrics in $11$ variables, \emph{Compos. Math.} \textbf{151} (2015), 1189--1214. \bibitem[NV24]{NV} \orev{M.\,J. Northey and P. Vishe, On the Hasse principle for complete intersections, \emph{Compos. Math.} \textbf{160} (2024), 771--835.} \bibitem[PSW16]{PSW} L.\,B. Pierce, D. Schindler and M.\,M. Wood, Representations of integers by systems of three quadratic forms, \emph{Proc. Lond. Math. Soc.} (3) \textbf{113} (2016), 289--344. \bibitem[Rot55]{Rot} K.\,F. Roth, Rational approximations to algebraic numbers, \emph{Mathematika} \textbf{2} (1955), 1--20. \bibitem[RM18]{RM} S.\,L. Rydin Myerson, Quadratic forms and systems of forms in many variables, \emph{Invent. Math.} \textbf{213} (2018), 205--235. \bibitem[Sch80]{Sch} W.\,M. Schmidt, \emph{Diophantine approximation}, Lecture Notes in Math. \textbf{785}, Springer, Berlin, 1980. \bibitem[Sch82]{Sch82} \orev{W.\,M. Schmidt, Simultaneous rational zeros of quadratic forms, in \emph{Seminar on Number Theory, Paris 1980--81}, Progr. Math. \textbf{22}, Birkh\"auser, Boston, 1982, 281--307.} \bibitem[Schu80]{Schu} \orev{S.\,E. Schuur, On systems of three quadratic forms, \emph{Acta Arith.} \textbf{36} (1980), 315--322.} \bibitem[Tho91]{Tho} \orev{R.\,C. Thompson, Pencils of complex and real symmetric and skew matrices, \emph{Linear Algebra Appl.} \textbf{147} (1991), 323--371.} \bibitem[Vis23]{Vis} P. Vishe, Rational points on complete intersections over $\FF_q(t)$, \emph{Proc. Lond. Math. Soc.} (3) \textbf{126} (2023), 556--619. \end{thebibliography} \end{document}