\section{Summation over the graphs and proof of the main theorem} \label{sec:sum} Proposition~\ref{prop:fixed} bounds the pairs on a single graph with no uniformity in $G$, while the reduction \eqref{eq:initialgraphs} leaves up to $(\log L)^{O(1)}$ graphs. We now sort the graphs by their index into dyadic bands and show that each band contributes a summable amount. \subsection{Candidates in a band} For $j\ge1$ put $Q_j:=2^j$ and let $\mathcal G_j$ be the set of $G\in\GL_2(\bQ)\setminus\cK$ with \[ Q_j2^{j_0}$ lies in a band $\mathcal G_j$ with $j_0\le j\le j_{\max}$. For every $j$ with $j_0\le j\le j_{\max}$ we perform the $(M(j),K_{\mathrm c}(j))$-excision of Definition~\ref{def:excision} and we excise the rays of the fan $\mathcal F_{K_{\mathrm f}(j)}$; the condition $K_{\mathrm c}(j)\ge C_{\mathrm{exc}}\log(2+M(j))$ follows from $j^3\ge C_{\mathrm{exc}}(6j\log2+C)$ and holds when $j_0$ is large. From now on a vector is called \emph{retained} if it is retained in the sense of \S\ref{sec:graphs} and is not excised by any of these band excisions, and \emph{deleted} otherwise. For each $j$, the levels $K_{\mathrm c}(j),K_{\mathrm f}(j)$ and the $j$-th excision do not depend on $L$; the range $j_0\le j\le j_{\max}$ does. \begin{lemma}\label{lem:band-deletion} The following statements hold. \begin{enumerate} \item The band excisions delete at most $CL^2/j_0+C\,L(\log\log L)^3+C(\log\log L)^7$ primitive vectors of $\sect$ with $N\le L$, with $C$ independent of $j_0$. \item If $v$ is retained, $\gamma$ is a supporting functional at $v$, $j_0\le j\le j_{\max}$, and $\beta$ is an integral form with $0<|\beta|\le M(j)$, then $\angle(\gamma,\{\beta,-\beta\})\ge ce^{-C_{\mathrm{sep}}j^3}$. \item Lemma~\ref{lem:ranktwo}(b) and the dichotomy of \S\ref{sec:pieces} remain valid for the retained collision pairs in the new sense: in every sector pair of the original fine fan $\mathcal F_{H_{\mathrm f}}$ they form a subset of a degenerate piece or of a graph piece, with the same matrix $G$. \end{enumerate} \end{lemma} \begin{proof} (a) By Lemma~\ref{lem:excision}(b) with $\log(2+M(j))\le Cj$ and $K_{\mathrm c}(j)=j^3$, the $j$-th excision deletes at most $C(j^{-2}L^2+Lj^2+j^6)$ vectors, and the rays of $\mathcal F_{K_{\mathrm f}(j)}$ carry at most $CK_{\mathrm f}(j)^2\le Cj^6$ primitive vectors. Summing over $j_0\le j\le j_{\max}$ gives the bound, since $\sum_{j\ge j_0}j^{-2}\le2/j_0$. (b) is Lemma~\ref{lem:excision}(c) for the $(M(j),K_{\mathrm c}(j))$-excision. (c) Removing vectors can only shrink the set of collision pairs in a sector pair, hence the span of their collision vectors. \end{proof} \subsection{A population estimate} \begin{lemma}\label{lem:population} Let $V$ be a finite set of integral vectors in the disc $|x|\le R$, and let $D_V:=\max_{v,v'\in V}|\det(v,v')|$. If $D_V>0$ then \begin{equation}\label{eq:population} |V|\le4D_V+CR+C . \end{equation} If $D_V=0$ and all vectors of $V$ are primitive, then $|V|\le2$. \end{lemma} \begin{proof} Let $v_1,v_2\in V$ attain the maximum $D_V>0$. For $v\in V$ write $v=xv_1+yv_2$; then $|x|D_V=|\det(v,v_2)|\le D_V$ and $|y|D_V=|\det(v_1,v)|\le D_V$, so $|x|,|y|\le1$. Thus $V$ lies in the parallelogram $\{xv_1+yv_2:|x|,|y|\le1\}$, of area $4D_V$ and perimeter $O(R)$, and the unit squares centred at the points of $V$ are disjoint and lie within distance $1$ of it; this gives \eqref{eq:population}. If $D_V=0$, all vectors of $V$ lie on one line through the origin, which contains at most two primitive vectors. \end{proof} \subsection{At most one large band piece in a sector pair} Fix a band $j$ with $j_0\le j\le j_{\max}$ and an ordered pair $(\Sigma,\Sigma')$ of Farey sectors of level $K_{\mathrm f}(j)$. For $G\in\mathcal G_j$ let \[ \mathcal P_G(\Sigma,\Sigma'):=\{v\in\Sigma:\ v\text{ and }Gv\text{ are retained},\ Gv\in\Sigma',\ N(v)=N(Gv)\le L\} \] and $P_G(\Sigma,\Sigma'):=|\mathcal P_G(\Sigma,\Sigma')|$. We call the set of pairs $(v,Gv)$ with $v\in\mathcal P_G(\Sigma,\Sigma')$ the \emph{band piece} $(G,\Sigma,\Sigma')$, and $P_G(\Sigma,\Sigma')$ its \emph{population}; we write $P_G$ when the sector pair is fixed. (Here retained vectors are primitive vectors of $\sect$ by definition.) The band piece is \emph{large} if $P_G\ge L^2/Q_j^{20}$ and \emph{small} otherwise. Since $Q_j\le2^{j_{\max}}\le2(\log L)^5$, the threshold satisfies \begin{equation}\label{eq:threshold} \frac{L^2}{Q_j^{20}}\ge\frac{L^2}{2^{20}(\log L)^{100}} , \end{equation} so that $L=o(L^2/Q_j^{20})$ as $L\to\infty$, uniformly in $j$. \begin{lemma}\label{lem:onegraph} If $j_0$ is sufficiently large (depending only on $N$) and $L$ is sufficiently large, then for every $j$ with $j_0\le j\le j_{\max}$ and every ordered sector pair $(\Sigma,\Sigma')$ of level $K_{\mathrm f}(j)$, at most one $G\in\mathcal G_j$ has a large band piece $(G,\Sigma,\Sigma')$. \end{lemma} \begin{proof} As in the proof of Lemma~\ref{lem:ranktwo}, let $\lambda_\Sigma$ and $\lambda_{\Sigma'}$ be inward supporting functionals at boundary vectors of $\Sigma$ and $\Sigma'$, $\ell:=(\lambda_\Sigma,-\lambda_{\Sigma'})$, and $\eta_j:=CLe^{-\kappa K_{\mathrm f}(j)}$; then \eqref{eq:eta} holds at level $K_{\mathrm f}(j)$, that is, $|N(v)-\lambda_\Sigma(v)|\le\eta_j$ for $v\in\Sigma$ with $N(v)\le L$, and similarly in $\Sigma'$. \emph{A large band piece pins down $\ell$ on its graph plane.} Let $(G,\Sigma,\Sigma')$ be large and $V:=\mathcal P_G(\Sigma,\Sigma')$, a set of $P_G\ge L^2/Q_j^{20}$ primitive vectors in the disc $|x|\le CL$. By Lemma~\ref{lem:population} and \eqref{eq:threshold}, $D_V\ge P_G/8$ for large $L$, so there are $v_1,v_2\in V$ with $|\det(v_1,v_2)|\ge L^2/(8Q_j^{20})$. Consider the linear form $\theta_G:=\lambda_\Sigma-\lambda_{\Sigma'}\circ G$ on $\bR^2$, so that $\ell(x,Gx)=\theta_G(x)$. For $v\in V$, $N(v)=N(Gv)$ gives $|\theta_G(v)|\le2\eta_j$. Expressing $\theta_G$ in the basis dual to $(v_1,v_2)$, whose elements have norm at most $CL/|\det(v_1,v_2)|\le CQ_j^{20}/L$, we get $|\theta_G|\le CQ_j^{20}e^{-\kappa K_{\mathrm f}(j)}$, and therefore, since $|x|\le|(x,Gx)|$, \begin{equation}\label{eq:planeerror} |\ell(z)|\le\varepsilon_j|z|\quad(z\in W_G),\qquad \varepsilon_j:=CQ_j^{20}e^{-\kappa K_{\mathrm f}(j)} . \end{equation} \emph{Two large band pieces are impossible.} Suppose $G\ne G'$ in $\mathcal G_j$ both have large band pieces in $(\Sigma,\Sigma')$, and let $W:=W_G+W_{G'}$, of dimension $d\in\{3,4\}$. Choose $d$ linearly independent vectors $y_1,\dots,y_d$ among the basis vectors \eqref{eq:graphbasis} of $W_G$ and $W_{G'}$; each has norm at most $R_j=CQ_j^2$ and lies in $W_G$ or in $W_{G'}$. Their $d$-dimensional volume is at least $1$, being the square root of a positive integer (the Gram determinant). For $z\in W$ write $z=\sum c_iy_i$; Cramer's rule gives $|c_i|\le|z|R_j^{d-1}$, and \eqref{eq:planeerror} gives $|\ell(y_i)|\le\varepsilon_jR_j$. Hence \begin{equation}\label{eq:spanerror} |\ell(z)|\le d\,\varepsilon_jR_j^d\,|z|\le\varepsilon_j'|z|\quad(z\in W),\qquad \varepsilon_j':=CQ_j^{28}e^{-\kappa K_{\mathrm f}(j)}=C\,2^{28j}e^{-\kappa\lceil B_1j^3\rceil}. \end{equation} The quantity $\varepsilon_j'$ does not depend on $L$, and it tends to $0$ as $j\to\infty$. If $d=4$, then $W=\bR^4$ and \eqref{eq:spanerror} gives $|\ell|\le\varepsilon_j'$, which contradicts $|\ell|\ge c$ once $j_0$ is large. If $d=3$, let $\nu=(\alpha,\beta)$ be the primitive integral normal of $W$; by \eqref{eq:normal-band}, $|\nu|\le M(j)$. Exactly as in the proof of Lemma~\ref{lem:ranktwo}, \eqref{eq:spanerror} shows that the angle between $\ell$ and the line $\bR\nu$ is $O(\varepsilon_j')$, hence that $\beta\ne0$ and $\angle(\lambda_{\Sigma'},\{\beta,-\beta\})\le C\varepsilon_j'$ for $j_0$ large. Let $w:=Gv_1\in\Sigma'$, which is retained since $v_1\in\mathcal P_G(\Sigma,\Sigma')$, and let $\gamma$ be a supporting functional at $w$. By Proposition~\ref{prop:turn}(b), $|\gamma-\lambda_{\Sigma'}|\le Ce^{-\kappa K_{\mathrm f}(j)}\le C\varepsilon_j'$, so $\angle(\gamma,\{\beta,-\beta\})\le C\varepsilon_j'$. But $\beta$ is a nonzero integral form of size at most $M(j)$ and $w$ is retained, so Lemma~\ref{lem:band-deletion}(b) gives $\angle(\gamma,\{\beta,-\beta\})\ge ce^{-C_{\mathrm{sep}}j^3}$. Therefore \[ ce^{-C_{\mathrm{sep}}j^3}\le C\,2^{28j}e^{-\kappa B_1j^3},\qquad\text{that is,}\qquad e^{(\kappa B_1-C_{\mathrm{sep}})j^3}\le C\,2^{28j}, \] which is false for $j\ge j_0$ when $j_0$ is large, by the choice \eqref{eq:B1} of $B_1$. \end{proof} \subsection{The tails} Fix $j$ with $j_0\le j\le j_{\max}$. The fan of level $K_{\mathrm f}(j)$ has at most $CK_{\mathrm f}(j)^2\le Cj^6$ sectors, hence at most $Cj^{12}$ ordered sector pairs. By Lemma~\ref{lem:band-deletion}(c) and the reduction \eqref{eq:initialgraphs}, every retained collision pair lying on a graph piece with matrix $G\in\mathcal G_j$ lies in the band piece $(G,\Sigma,\Sigma')$ for the sector pair $(\Sigma,\Sigma')$ of level $K_{\mathrm f}(j)$ containing it (its members are retained, hence not on the rays of $\mathcal F_{K_{\mathrm f}(j)}$). We bound the sum of all populations of band $j$. The small band pieces contribute, by the bound \eqref{eq:candidates} on $|\mathcal G_j|$, at most \[ |\mathcal G_j|\cdot Cj^{12}\cdot\frac{L^2}{Q_j^{20}}\le CL^2j^{12}2^{-11j}. \] By Lemma~\ref{lem:onegraph} there is at most one large band piece in each sector pair. A large band piece $(G,\Sigma,\Sigma')$ contains two pairs with independent first members (Lemma~\ref{lem:population}, as in the proof of Lemma~\ref{lem:onegraph}), and all its pairs $(v,Gv)$ satisfy $|v|,|Gv|\le CL$; so by Lemma~\ref{lem:indices}(a) its population is at most $CL^2/I(G)\le CL^2/Q_j$. The large band pieces therefore contribute at most $Cj^{12}L^2/Q_j=CL^2j^{12}2^{-j}$. Summing over the bands gives \begin{equation}\label{eq:tail} \sum_{j_0\le j\le j_{\max}}\ \sum_{G\in\mathcal G_j}\ \sum_{(\Sigma,\Sigma')}P_G(\Sigma,\Sigma') \le CL^2\,\tau(j_0),\qquad \tau(j_0):=\sum_{j\ge j_0}j^{12}\bigl(2^{-11j}+2^{-j}\bigr), \end{equation} and $\tau(j_0)\to0$ as $j_0\to\infty$. Finally, the matrices allowed by the reduction \eqref{eq:initialgraphs} with $I(G)\le2^{j_0}$ have $q(G)\le2^{j_0}$ and $h(G)\le10(1+2^{j_0})$, so they form a finite set $\mathcal G_{\le j_0}$ of matrices in $\GL_2(\bQ)\setminus\cK$, independent of $L$. For each $G\in\mathcal G_{\le j_0}$ the retained collision pairs on graph pieces with matrix $G$ are among the pairs $(v,Gv)$ with $v,Gv$ primitive and $N(v)=N(Gv)\le L$, whose number is $o_G(L^2)$ by Proposition~\ref{prop:fixed}. Hence \begin{equation}\label{eq:reserved} \#\{\text{retained collision pairs on graph pieces with }G\in\mathcal G_{\le j_0}\} =o_{j_0}(L^2). \end{equation} \subsection{Proof of Theorem~\ref{thm:main}}\label{sec:proof-main} The proof bounds $T(X)-D(X)$ by the number of deleted vectors plus the number of retained collision pairs, and bounds both by the results of \S\ref{sec:graphs} and~\ref{sec:sum}. Let $L=2\arcosh(3X/2)$ and \[ \mathcal V_L:=\bZ^2_\prim\cap\sect\cap L\ball,\qquad r_m:=\#\{v\in\mathcal V_L:\ m(v)=m\}\quad(m\ge1). \] By Lemma~\ref{lem:dictionary}(c), the sorted Markoff triples with maximum at most $X$ correspond bijectively to the vectors of $\mathcal V_L$, the maximum of the triple being the label of the vector; so $T(X)=|\mathcal V_L|$, $D(X)=|m(\mathcal V_L)|$, and \[ E_L:=T(X)-D(X)=\sum_{m\in m(\mathcal V_L)}(r_m-1). \] For $\mathcal V\subset\mathcal V_L$ put $E(\mathcal V):=|\mathcal V|-|m(\mathcal V)|$, so that $E_L=E(\mathcal V_L)$. Removing one vector from $\mathcal V$ lowers $|\mathcal V|$ by one and $|m(\mathcal V)|$ by at most one, hence lowers $E(\mathcal V)$ by at most one. For the set $\mathcal V_{\rm ret}$ of retained vectors, a label of multiplicity $r\ge2$ in $\mathcal V_{\rm ret}$ contributes $r-1\le r(r-1)$ to $E(\mathcal V_{\rm ret})$, and $r(r-1)$ is the number of retained collision pairs with that label. Therefore \[ E_L\le E(\mathcal V_{\rm ret})+\#\{\text{deleted vectors}\} \le\#\{\text{deleted vectors}\}+\#\{\text{retained collision pairs}\}. \] Fix $A_0$ large and $j_0$ large; $B_0$ is then determined by \eqref{eq:B0}. By Lemma~\ref{lem:ranktwo}(a) and Lemma~\ref{lem:band-deletion}(a), the number of deleted vectors is at most \[ \frac{C}{A_0}L^2+\frac{C}{j_0}L^2+o_{A_0}(L^2), \] with $C$ independent of $A_0$ and $j_0$. The retained collision pairs are counted by the reduction \eqref{eq:initialgraphs} (the exceptional $o_{A_0}(L^2)$ pairs), \eqref{eq:tail} and \eqref{eq:reserved}. Altogether, \[ \limsup_{L\to\infty}\frac{E_L}{L^2}\le\frac C{A_0}+\frac C{j_0}+C\tau(j_0). \] The left-hand side does not depend on $A_0$ or $j_0$; letting $j_0\to\infty$ and then $A_0\to\infty$ gives $E_L=o(L^2)$. Since $L=2\arcosh(3X/2)\sim2\log X$, this says $T(X)-D(X)=o(\log^2X)$. By the count \eqref{eq:Tlength} of Lemma~\ref{lem:dictionary}(d), $T(X)=|\mathcal V_L|\sim c_NL^2$, so $D(X)\sim T(X)$. A non-unique Markoff number $m\le X$ has $r_m\ge2$ and contributes at least $1$ to $E_L$, so $D_2(X)\le E_L=o(L^2)$, and $D_2(X)/D(X)\to0$. \qed