Smoothed Shifted Convolutions of Generalised Divisor Functions
Extracted source text ยท arXiv 2509.07556
\documentclass[12pt]{amsart}
\usepackage{amsmath, amsthm, amsfonts, amssymb, graphicx, hyperref, bm,verbatim,mathrsfs,siunitx,natbib,tikz-cd,mathabx,mathtools,dsfont}
\usepackage{stmaryrd,enumerate}
\theoremstyle{plain}
\usepackage{geometry}
\geometry{left=1in,right=1in}
%\pagestyle{plain}
\newtheorem{thm}{Theorem}[section]
\newtheorem{lem}[thm]{Lemma}
\newtheorem{prop}[thm]{Proposition}
\newtheorem{cor}[thm]{Corollary}
\newtheorem{ass}{Assumption}
\newtheorem{defn}[thm]{Definition}
\newtheorem*{rem}{Remark}
\newtheorem*{nprop}{Proposition}
\newtheorem*{nthm}{Theorem}
\newtheorem*{conj}{Conjecture}
\newtheorem*{que}{Question}
\newtheorem{hyp}{Hypothesis}
\newtheorem{sublem}{Sublemma}
\numberwithin{sublem}{thm}
\numberwithin{equation}{section}
\parskip 7.2pt
\newcommand*{\li}{\operatorname{li}}
\renewcommand{\S}{S(\mathcal{A}, \mathcal{P})}
\renewcommand{\mod}[1]{\ (\text{mod }{#1})}
\renewcommand*{\d}{\, \textup{d}}
\renewcommand{\gcd}{\operatorname{gcd}}
\newcommand{\rad}{\operatorname{rad}}
\newcommand{\e}{\varepsilon}
\newcommand{\Mod}[1]{\ (\mathrm{mod}\ #1)}
\renewcommand{\mod}[1]{\ \mathrm{mod}\ #1}
\numberwithin{equation}{section}
\makeatletter
\@namedef{subjclassname@2020}{%
\textup{2020} Mathematics Subject Classification}
\makeatother
\usepackage[T1]{fontenc}
\numberwithin{equation}{section}
\frenchspacing
%\textwidth=15cm
\textheight=23cm
\parindent=16pt
%\oddsidemargin=-0.5cm
%\evensidemargin=-0.5cm
\topmargin=-0.5cm
\baselineskip=17pt
\subjclass[2020]{Primary 11N37; Secondary 11N75}
\keywords{additive divisor problems, shifted convolution sums, divisor functions, generalised divisor functions}
\let\underbrace\LaTeXunderbrace
\let\overbrace\LaTeXoverbrace
\begin{document}
\title{Smoothed Shifted Convolutions of Generalised Divisor Functions}
\author{Cheuk Fung (Joshua) Lau}
\address{Mathematical Institute, University of Oxford, Radcliffe Observatory Quarter, Woodstock Rd, Oxford OX2 6GG, UK}
\email{joshua.cf.lau@gmail.com}
\begin{abstract}
We prove an asymptotic formula for the smoothed shifted convolution of the generalised divisor function $d_k(n)$ and the divisor function $d(n)$, with a power-saving error term independent of $k$. In particular, when $k$ is large, this is an improvement on Topacogullari (2018).
\end{abstract}
\maketitle
\tableofcontents
\section{Introduction}
Prime numbers are of great interest in number theory, and we may use the von Mangoldt function $\Lambda$ to study patterns of prime numbers. For example, to study the number of twin primes less than or equal to $x$, it suffices to estimate $\sum_{n \leq x} \Lambda(n)\Lambda(n+2)$. One idea for estimating this quantity is to use the following decomposition of \citet{linnik1963dispersion}
\[
\Lambda(n)=\log n \sum_{k=1}^\infty \frac{(-1)^{k-1}}{k} \widetilde{d}_k(n),
\]
where $\widetilde{d}_k(n)=\#\{n=n_1 \cdots n_k:n_1,\ldots,n_k>1\}$. Therefore, if one could handle all sums of the form $\sum_{n \leq x} d_k(n) d_j(n+h)$, then we could estimate the number of twin primes. Heuristically, since
we expect $\sum_{n \leq x} d_k(n)$ to grow like $x(\log x)^{k-1}$, one might expect $\sum_{n \leq x} d_k(n) d_j(n+h)$ to behave like $x(\log x)^{k+j-2}$ when $h \neq 0$. The case $j=k=2$ is known as the binary additive divisor problem, which has been studied by many authors. It is known that for $h \in \mathbb{Z}$ non-zero and $|h| \ll x^{\frac23}$,
\[
\sum_{n \leq x} d(n)d(n+h)=xP_{2,h}(\log x)+O(x^{\frac23+\e}),
\]
where $P_{2,h}(t)$ is a quadratic polynomial depending on $h$. This can be found in \citet{motohashi1994binary}, where a more detailed review of this problem can be found as well. For $k=3$, \citet{topacogullari2016shifted} proved for $h \in \mathbb{Z}$ non-zero and $|h| \ll x^{\frac23}$,
\[
\sum_{n \leq x} d_3(n)d(n+h)=xP_{3,h}(\log x)+O(x^{\frac89+\e}),
\]
where $P_{3,h}(t)$ is a cubic polynomial depending on $h$. In the general case $k \geq 4$, the first result with a main term of this kind was obtained by \citet{motohashi1980asymptotic} using the dispersion method, namely
\[
\sum_{n \leq x} d_k(n)d(n+1)=xP_{k}(\log x)+O_{k}(x(\log \log x)^{c_k} (\log x)^{-1}),
\]
where $c_k$ is a constant depending only on $k$ and $P_{k}(t)$ is a polynomial of degree $k$. Using spectral methods, \citet{drappeau2017sums} obtained a power-saving error term and proved that there exists $\delta>0$ such that for $h \in \mathbb{N}$ and $h \ll x^\delta$, we have
\[
\sum_{n \leq x} d_k(n)d(n+h)=xP_{k,h}(\log x)+O_{k}(x^{1-\frac{\delta}{k}}),
\]
where $P_{k,h}(t)$ is a polynomial of degree $k$ depending on $h$. This result was improved by \citet{topacogullari2018shifted}, who proved that for $h$ non-zero and $|h| \ll x^{\frac{15}{19}}$,
\[
\sum_{n \leq x} d_k(n)d(n+h)=xP_{k,h}(\log x)+O_{k,\e}(x^{1-\frac{4}{15k-9}+\e}+x^{\frac{56}{57}+\e}),
\]
where $P_{k,h}(t)$ is a polynomial of degree $k$ depending on $h$. If we consider a smoothed version of this problem, \citet{topacogullari2018shifted} proved that for $w:[1/2,1] \to [0,\infty)$ a smooth and compactly supported function, if $h \in \mathbb{Z}$ is non-zero and $|h| \ll x^{\frac{15}{19}}$, we have
\begin{equation*}
\sum_{n} w \left( \frac{n}{x} \right) d_k(n)d(n+h)=xP_{k,h,w}(\log x)+O_{k,w,\e}(x^{1-\frac{1}{3k-2}+\e}+x^{\frac{37}{38}+\frac{\theta}{19}+\e}),
\end{equation*}
where $P_{k,h,w}(t)$ is a polynomial of degree $k$ depending on $h$ and $w$. The above power saving depends on $k$, and the exponent worsens as $k$ increases. In this paper, we obtain an asymptotic where the power saving is uniform in $k$.
\begin{thm} \label{thm:intromainthm}
Let $w:[1/2,1] \to [0,\infty)$ be smooth and compactly supported. Let $h$ be a non-zero integer such that $|h| \ll x^{\frac{25}{28}-\eta}$ for some $\eta>0$. Then,
\[
\sum_n w\left( \frac{n}{x} \right) d_k(n) d(n + h)=xP_{x,h,w}(\log x)+O_{k,w,\e}(x^{1-\frac{7}{128} \eta+\e}),
\]
where $P_{k,h,w}(t)$ is a polynomial of degree $k$ depending on $h$ and $w$.
\end{thm}
For $k$ large, this improves on \citet{topacogullari2018shifted}. Theorem \ref{thm:intromainthm} is a corollary of the following result.
\begin{thm}
Let $w:[1/2,1] \to [0,\infty)$ be smooth and compactly supported, $h \in \mathbb{Z}$, $\e>0$, and $x \in \mathbb{R}^+$ sufficiently large in terms of $\e$. Then for $0 \leq \delta \leq \frac{1}{16}$ and $|h| \ll x^{1-\e}$, we have
\begin{align*}
\sum_n w \left( \frac{n}{x} \right) &d_k(n) d(n + h)= \ xP_{k,h,w}(\log x)\\
&+O_{k,w,\e,\delta}\left(x^{1-\delta+2 \delta \theta+\e}\left( 1+\frac{|h|^{\frac{1}{4}}}{x^{\frac14-\frac12 \delta}} \right)+x^{1-\delta+\frac{\theta}{3}+\frac{2\delta}{3}\theta+\e} \left(1+\frac{|h|^{\frac{\theta}{2}}}{x^{\frac{\theta}{6}+\frac{4 \delta}{3} \theta}}\right) \right),
\end{align*}
where $P_{k,h,w}$ is a polynomial of degree $k$ depending only on $h$ and $w$, and the implied constant depends on $k,w,\e,\delta$.
\end{thm}
We remark that a fixed power saving for the sharp cutoff problem is currently out of reach, since it remains unknown whether an asymptotic formula with a fixed power saving holds for $\sum_{n \le x} d_k(n)$.
\section{Outline}
In this section, we outline the main ideas and set $h=1$ for simplicity. The first few steps are similar to the treatment in \citet{topacogullari2018shifted}. We first write
\[
\sum_n w \left( \frac{n}{x} \right) d_k(n)d(n+1)=\sum_{a_1,\ldots,a_k} w \left( \frac{a_1 \cdots a_k}{x} \right) d(a_1 \cdots a_k+1),
\]
and so it suffices to estimate
\begin{equation} \label{eqn:outlinedyadic}
\sum_{\substack{a_1,\ldots,a_k\\a_i \asymp A_i}} w \left( \frac{a_1 \cdots a_k}{x} \right) d(a_1 \cdots a_k+1),
\end{equation}
where $a_1,\ldots,a_k$ are supported dyadically on $a_i \asymp A_i$. If there is one large variable, or a product of two variables is large, then (\ref{eqn:outlinedyadic}) can be estimated using the Voronoi formula by splitting the summation into $\mod \prod_i a_i$. Otherwise, some product of the variables $a_i$ must be of 'medium' size, say $a_1 \cdots a_r$. In this case, let $$\Phi_r(b) := \sum_{a_i \asymp A_i \forall i \leq r} d(a_1 \cdots a_rb+1),$$ and write $\widetilde{\Phi}_r(b)$ as the expected main term (using the Voronoi formula). Therefore, (\ref{eqn:outlinedyadic}) becomes
\begin{equation*}
\sum_{a_i \asymp A_i \forall i >r} \widetilde{\Phi}_r(a_{r+1} \cdots a_k)-\sum_{a_i \asymp A_i \forall i>r} (\widetilde{\Phi}(a_{r+1} \cdots a_k)-\Phi(a_{r+1} \cdots a_k)).
\end{equation*}
The first term is the main term and can be computed easily, and to upper bound the second term we use Cauchy-Schwarz and it suffices to bound
\[
\sum_{b \asymp B} (\widetilde{\Phi}_r(b)-\Phi_r(b))^2=\sum_{b \asymp B} \widetilde{\Phi}_r(b)^2-2\sum_{b \asymp B} \widetilde{\Phi}_r(b)\Phi_r(b)+\sum_{b \asymp B} \Phi_r(b)^2,
\]
where $B=A_{r+1} \cdots A_k$. It is straightforward to estimate the first two sums, while if we open the square in the last sum it suffices to estimate sums of the form
\begin{equation} \label{eqn:outlinecertaindivisor}
\sum_n w_1 \left( \frac{r_1n}{x} \right) w_2 \left( \frac{r_2n}{x} \right)d(r_1n+1)d(r_2n+1),
\end{equation}
where $r_1,r_2$ suitably sized with $r_1 \neq r_2$. In fact, before applying Cauchy-Schwarz we can group square factors together, so it suffices to estimate (\ref{eqn:outlinecertaindivisor}) for squarefree $r_1,r_2$.
\\
To do this, we use Theorem \ref{thm:grimmelt10.1}, which is Theorem 10.1 of \citet{grimmelt2024twisted}. This result was proven by spectral methods, and it counts the solutions to determinant equations $ad-bc=h$ twisted by periodic weights. The resulting error term consists of data concerning the ranges of the variables $a,c,d$, as well as a quantity $\mathcal{K}$ that depends on the periodic weight and its underlying geometry.\\
To outline our strategy, we focus on the particular case $r_1,r_2$ coprime, and assume the Ramanujan-Petersson conjecture. We can rewrite (\ref{eqn:outlinecertaindivisor}) as
\begin{equation} \label{eqn:outlinetransformedcertaindivisor}
\sum_n \sum_{\substack{ad=r_1n+1\\bc=r_2n+1}} w_1 \left( \frac{ad-1}{x} \right) w_2 \left( \frac{bc-1}{x} \right).
\end{equation}
Rewriting the constraints as determinant equations, note $ad=r_1n+1$ and $bc=r_2n+1$ together imply $r_2ad-r_1bc=r_2-r_1$. Also, since $(r_1,r_2)=1$, $r_2ad-r_1bc=r_2-r_1$ implies both $ad=r_1n+1$ and $bc=r_2n+1$. Therefore (\ref{eqn:outlinetransformedcertaindivisor}) becomes
\begin{align*}
\sum_{r_2ad-r_1bc=r_2-r_1} w_1 \left( \frac{ad-1}{x} \right) w_2 \left( \frac{bc-1}{x} \right)
= &\sum_{ad-bc=r_2-r_1} w_1 \left( \frac{ad-r_2}{r_2x} \right) w_2 \left( \frac{bc-r_1}{r_1x} \right) \mathds{1}_{r_2 \mid a} \mathds{1}_{r_1 \mid c}
\end{align*}
and let $\alpha(\begin{psmallmatrix}
a & b\\c &d
\end{psmallmatrix})=\mathds{1}_{r_2 \mid a} \mathds{1}_{r_1 \mid c}$. Then, we dyadically split the variables into $a \asymp A$, $c \asymp C$, $d \asymp D$ and without loss of generality assume $r_1^{-1}C \ll D \ll r_2^{-1}A \ll B$. To treat the very skewed ranges $A>r_2C$ or $D>C$, we apply Poisson summation.\\
In other ranges, we may apply Theorem \ref{thm:grimmelt10.1} with $\Gamma=\Gamma_2(r_2,r_1)$. Then, it is straightforward to compute the main term, so we focus on the error term, in particular $\mathcal{K}$. To bound
\[
\sum_{0 \leq |c| \leq \frac{6C}{D}} \left| \sum_{\tau \in \Gamma \backslash \operatorname{SL}_2(\mathbb{Z})} \alpha(\tau) \overline{\alpha(\tau \begin{psmallmatrix}
1 & 0 \\ c & 1
\end{psmallmatrix})} \right|,
\]
we use a description of $\Gamma_2(r_2,r_1) \backslash \operatorname{SL}_2(\mathbb{Z})$ with projective lines to get
\[
\sum_{0 \leq |c| \leq \frac{6C}{D}} \left| \sum_{\tau \in \Gamma \backslash \operatorname{SL}_2(\mathbb{Z})} \alpha(\tau) \overline{\alpha(\tau \begin{psmallmatrix}
1 & 0 \\ c & 1
\end{psmallmatrix})} \right| \ll \frac{C}{r_1r_2D}+1 \ll 1,
\]
and similarly for the corresponding sum over $b$. Combining these bounds, we get $\mathcal{K} \ll 1$. Putting these together, one gets an asymptotic for (\ref{eqn:outlinecertaindivisor}) with error term $\ll \sqrt{r_2x}$. Combining the above and assuming the Ramanujan-Petersson conjecture, a sketch of what we get is
\[
\sum_{\substack{a_1,\ldots,a_k\\ a_i \asymp A_i}} w \left( \frac{a_1 \cdots a_k}{x} \right) d(a_1 \cdots a_k+1)=\mathrm{MT}+R,
\]
where MT is the main term which may be handled straightforwardly, and $R$ is the error term with the upper bounds
\begin{align}
R &\ll \frac{x^{\frac32+\e}}{A_1^{\frac32}}, \label{eqn:outlineremainderbound1}\\
R &\ll \frac{x^{\frac32+\e}}{A_1A_2} \left( 1+\frac{A_2^{\frac12}}{A_1^{\frac12}} \right) \left( 1+ \frac{A_1^\frac12 A_2^{\frac12}}{x^{\frac12}} \right), \label{eqn:outlineremainderbound2}\\
R &\ll \frac{x^{1+\e}}{A^{\frac12}}+A^{\frac34}x^{\frac34+\e}, \label{eqn:outlineremainderbound3}
\end{align}
where $A$ is an arbitrary product of factors $A_1,\ldots,A_k$. As mentioned above, we use the three bounds depending on the sizes of the factors $A_1,\ldots,A_k$. Without loss of generality, assume $A_1 \geq \cdots \geq A_k$, and for $\delta>0$ we let the boundary values to be
\[
X_1=x^{\frac13+\frac23\delta}, \quad X_2=x^{\frac12+\delta}, \quad X_3=x^{\frac13-\frac43\delta}, \quad X_4=x^{2 \delta}.
\]
If $A_1 \gg X_1$, we use (\ref{eqn:outlineremainderbound1}) to get $R \ll x^{1-\delta+\e}$. If $A_1A_2 \gg X_2$, then for $\delta\le 1/2$ we use (\ref{eqn:outlineremainderbound2}) to get
\[
R \ll x^{1-\delta+\e} \left( 1+{x^{-\frac14+\frac12\delta}} \right) \ll x^{1-\delta+\e}.
\]
At last, it can be shown that the only remaining case is $X_4 \ll \prod_{i \in I}A_i \ll X_3$ for some non-empty index set $I \subseteq \{1,2,\ldots,k\}$. Letting $A=\prod_{i \in I}A_i$, using (\ref{eqn:outlineremainderbound3}) we get
\[
R \ll \frac{x^{1+\e}}{X_4^{\frac12}}+X_3^{\frac34}x^{\frac34+\e} \ll x^{1-\delta+\e}.
\]
Compared to \citet{topacogullari2018shifted} our approach differs in two aspects: First, the above application of Theorem \ref{thm:grimmelt10.1} replaces his more classical use of sums of Kloosterman sums. Second, we used a more efficient glueing of variables with Cauchy-Schwarz, as described. The second change alone would allow us to obtain a variant of Theorem \ref{thm:intromainthm} with fixed, albeit worse, power saving.
\section{Acknowledgements}
We would like to thank Jori Merikoski and Lasse Grimmelt for suggesting this question, and for numerous helpful comments throughout the writing of this paper.
\section{Notation}
Throughout this paper, we
%use $\lfloor x \rfloor$ to denote the largest integer not greater than $x$, and $\lceil x \rceil$ to denote the least integer not less than $x$. We
say $f \ll g$ and $f=O(g)$ when there exists a constant $C>0$ such that $|f(x)| \leq Cg(x)$ for $x$ sufficiently large. If this depends on parameter $\e$ say, then we write $f \ll_\e g $ or $f=O_\e(g)$. We use $f=o(g)$ to mean $\lim_{x \to \infty} f(x)/g(x)=0$.\\
%Sums of the form $\sum_p$ is a sum over primes, and $\mathbb{P}$ denotes the set of primes. We use $\mathds{1}_{\mathbb{P}}(n)$ to denote the indicator function of whether $n \in \mathbb{P}$.
Given integers $d_1,d_2$ we use $\gcd(d_1,d_2)$ or $(d_1,d_2)$ to denote the greatest common divisor of $d_1$ and $d_2$, and $\operatorname{lcm}(d_1,d_2)$ or $[d_1,d_2]$ to denote the least common multiple of $d_1$ and $d_2$. We define $(d_1,d_2^\infty) := \prod_{p \mid d_1} p^{\nu_p(d_2)}$.\\
%For a positive integer $q>1$, denote $P^+(q)$ to be the largest prime factor of $q$. We use $\varphi(q)$ to denote the Euler totient function of $q$. Given integers $k$ and $n$, $\log_kn$ denotes the $k$-time iterated logarithm of $n$ in base $e$, for example $\log_1 n=\log n$ and $\log_2n=\log \log n$.
We use $\mathrm{M}_2(\mathbb{Z})$ to denote the set of 2 by 2 matrices with entries in $\mathbb{Z}$, and $\mathrm{M}_{2,h}(\mathbb{Z})$ denotes the subset of $\mathrm{M}_2(\mathbb{Z})$ with determinant $h$. Given $q_1,q_2 \in \mathbb{N}$, we define groups
\begin{align*}
\Gamma_0(q_1) &:= \left\{\begin{pmatrix}
a & b\\ c & d
\end{pmatrix} \in \operatorname{SL}_2(\mathbb{Z}):q_1 \mid c\right\},\\
\Gamma_2(q_1,q_2) &:= \left\{ \begin{pmatrix}
a & b\\ c & d
\end{pmatrix} \in \operatorname{SL}_2(\mathbb{Z}):q_1 \mid b, \ q_2 \mid c \right\}.
\end{align*}
Given a subgroup $\Gamma \leq \operatorname{SL}_2(\mathbb{Z})$, we say $\alpha:\operatorname{SL}_2(\mathbb{Z}) \to \mathbb{C}$ is $\Gamma$-automorphic if $\alpha(\gamma g)=\alpha(g)$ for all $\gamma \in \Gamma$, $g \in \operatorname{SL}_2(\mathbb{Z})$. We write $\mathcal{A}(q_1,q_2)$ to be the set of $\Gamma_2(q_1,q_2)$-automorphic functions.\\
For $n,J \in \mathbb{N}$, $\delta>0$ and $X_1,\ldots,X_n$ positive reals, we define the space
\begin{align*}
C_\delta^J(X_1,\ldots,X_n)=\{&f \in C^J(\mathbb{R}^n):\ \operatorname{supp} f \subseteq [X_1,2X_1] \times \cdots \times [X_n,2X_n],\\&
\lVert \partial_{x_1}^{J_1} \cdots \partial_{x_n}^{J_n}f \rVert_\infty \leq \prod_{i \leq n} (\delta X_i)^{-J_i} \enspace \forall \, 0 \leq J_1+\cdots+J_n \leq J\}.
\end{align*}
%
%For a sequence $\beta_h$, $1 \leq h \leq H$ and $r \in \mathbb{N}$, we write $\lVert \beta \rVert_r := (\beta_1^r+\cdots+\beta_H^r)^{\frac1r}$.
Given $p$ prime and $k \in \mathbb{Z}_{>0}$, we define the projective line over
$\mathbb{Z}/p^k \mathbb{Z}$ by
$$\mathbb{P}_{p^k}^1 := \{(x,y) \in (\mathbb{Z}/p^k \mathbb{Z})^2:x\text{ or }y \in (\mathbb{Z}/p^k \mathbb{Z})^\times\}/\sim,$$
where we define the equivalence relation by $(x_1,y_1)\sim (x_2,y_2)$ if there is $\lambda \in (\mathbb{Z}/p^k \mathbb{Z})^\times$ such that $(x_2,y_2)=(\lambda x_1,y_1)$. For $q \in \mathbb{Z}_{>0}$, we define
\[
\mathbb{P}_q^1:= \prod_{p^k \parallel q} \mathbb{P}_{p^k}^1,
\]
and by the Chinese Remainder Theorem we can identify $\mathbb{P}_q^1$ with
\[
\{(x,y) \in (\mathbb{Z}/q\mathbb{Z})^2:\gcd(x,y,q)=1\}/\sim,
\]
where $\sim$ is the equivalence relation defined above with $\lambda \in (\mathbb{Z}/q\mathbb{Z})^\times$.
\section{A Certain Divisor Problem}
\noindent
We first prove the following result on a certain divisor sum.
\begin{thm} \label{thm:certaindivisorcoprime}
Let $r_1,r_2 \in \mathbb{Z}^+$ be squarefree, and $h \in \mathbb{Z} \setminus \{0\}$ be such that $(h,r_1r_2)=1$. Let $r_0=(r_1,r_2)$, $x,\eta,\e \in \mathbb{R}^+$, and define $w_1,w_2:\mathbb{R} \to \mathbb{R}$ smooth compactly supported functions on $[1/2,1]$, satisfying $w_1^{(j)},w_2^{(j)} \ll_j x^{j \eta}$ for all $j \geq 0$. Then for $h \ll x^{1-\e}$, we have
\begin{align*}
\sum_n w_1 \left( \frac{r_1n}{x} \right) &w_2\left( \frac{r_2n}{x} \right) d(r_1n+h) d(r_2n+h)=\textrm{Main Term}\\
&+O_{\e}\left( x^{\frac12+O(\eta)} r_0 r_2^{\frac12}\gcd(\widetilde{r}_2-\widetilde{r}_1,r_0^\infty)^{\frac12} \left( \left(\frac{|h(r_2-r_1)|}{r_0} \right)^\theta+\frac{x^\theta}{r_1^\theta} \right) \right),
\end{align*}
where the main term is given by
\[
\int w_1 \left( \frac{r_1 \xi}{x} \right) w_2 \left( \frac{r_2 \xi}{x} \right) P(\log(r_1 \xi+h),\log(r_2 \xi+h)) \d \xi,
\]
and $P(X,Y)$ is a quadratic polynomial depending only on $r_1,r_2,h$.
\end{thm}
\noindent The main idea is to use the following special case of \citet[Theorem 10.1]{grimmelt2024twisted}.
\begin{thm} \label{thm:grimmelt10.1}
Let $q_1,q_2 \in \mathbb{Z}_{>0}$. For non-zero integers $h,k$ denote
\[
\mathrm{M}_{2,h,k}(\mathbb{Z}) := \left\{ \begin{pmatrix}
a & b\\ c & d
\end{pmatrix} \in \mathrm{M}_{2,hk}(\mathbb{Z}):\gcd(a,c,k)=\gcd(b,d,k)=1 \right\}.
\]
Denote
$$q=q_1q_2, \quad \Gamma=\Gamma_2(q_1,q_2), \quad T=\Gamma \setminus \operatorname{SL}_2(\mathbb{Z}), \quad T_{1,k} := \operatorname{SL}_2(\mathbb{Z}) \backslash \mathrm{M}_{2,1,k}(\mathbb{Z})$$
and let $\alpha \in \mathcal{A}(q_1,q_2)$. Let $A,C,D,\delta,\eta>0$ with $AD >\delta$ and denote $Z=\max\{A^{\pm 1},C^{ \pm 1},D^{\pm 1},\delta^{-1}\}$. Assume $|hk| \leq (AD)^{1+\eta}$ and $\gcd(h,kq_1q_2)=1$. Let
$$f \in C_\delta^7 \left( \frac{A}{\sqrt{|hk|}},\frac{C}{\sqrt{|hk|}},\frac{D}{\sqrt{|hk|}} \right).$$
Assume that for some $\mathcal{K_+}>0$ we have
$$\frac1k \sum_{\substack{g=\begin{psmallmatrix}
a&b\\c&d
\end{psmallmatrix} \in \operatorname{SL}_2(\mathbb{R})\\
|a|+|b|C/D+|c|D/C+|d| \leq 10}}\left| \sum_{\substack{\sigma_1,\sigma_2 \in T_{1,k}\\ \sigma_1^{-1} g \sigma_2 =: \sigma \in \operatorname{SL}_2(\mathbb{Z})}}\sum_{\substack{\tau \in T}} \alpha(\tau \sigma) \overline{\alpha(\tau \sigma g)} \right| \ll Z^{O(\eta)} \mathcal{K}_+.$$
Then
\begin{align*}
&\sum_{g=\begin{psmallmatrix}
a&b\\c&d
\end{psmallmatrix} \in \operatorname{M}_{2,h,k}(\mathbb{Z})} \alpha(g) f\left( \frac{a}{\sqrt{|hk|}},\frac{c}{\sqrt{|hk|}},\frac{d}{\sqrt{|hk|}} \right) \\
=&\frac{1}{\zeta(2) q \prod_{p \mid q} (1+p^{-1})} \sigma_1(|h|) \sum_{\tau \in \Gamma \backslash M_{2,1,k}(\mathbb{Z})} \alpha(\tau) \int_{\mathbb{R}^3} f(a,c,d) \frac{\d a \d c \d d}{c}\\
&+O \left( Z^{O(\eta)} \delta^{-O(1)} (AD)^{1/2} \mathcal{K}_+^{1/2} \left( \mathcal{R}_0+\min_{j \in \{1,2\}} \mathcal{R}_j \right) \right),
\end{align*}
where
\begin{align*}
\mathcal{R}_0 &= \frac{ A^{1/2}}{q_1^{1/2} C^{1/2}},\\
\mathcal{R}_1 &= |h|^{\theta} \left( 1+ \left( \frac{CD}{|hk|q_2} \right)^\theta \right) \left( 1+\left(\frac{C}{Aq_2} \right)^{\frac{1}{2}-\theta} \right),\\
\mathcal{R}_2 &= \left( 1+ \left( \frac{CD}{|k|q_2} \right)^\theta \right) \left( 1+\left(\frac{|h|C}{Aq_2} \right)^{\frac{1}{2}-\theta} \right).
\end{align*}
\end{thm}
The following description of quotient by subgroups of $\operatorname{SL}_2(\mathbb{Z})$ will be useful later.
\begin{lem} \label{lem:quotientdescription}
For positive integers $q_1,q_2$ and $q_0=\gcd(q_1,q_2)$, the maps
\begin{align*}
\varpi_{q_1,q_2}:\Gamma_2(q_1,q_2) \backslash \operatorname{SL}_2(\mathbb{Z}) &\to \{((a,b),(c,d)) \in \mathbb{P}_{q_1}^1 \times \mathbb{P}_{q_2}^1:(ad-bc,q_0)=1\}\\
\left[ \begin{pmatrix}
a & b\\ c & d
\end{pmatrix} \right] &\mapsto ([(a,b)],[(c,d)])
\end{align*}
and
\begin{align*}
\varpi_{q_1}:\Gamma_0(q_1) \backslash \operatorname{SL}_2(\mathbb{Z}) \to \mathbb{P}_{q_1}^1, \quad \left[ \begin{pmatrix}
a & b\\ c & d
\end{pmatrix} \right] \mapsto [(c,d)]\\
\varpi_{q_2}':\Gamma_0(q_2)^T \backslash \operatorname{SL}_2(\mathbb{Z}) \to \mathbb{P}_{q_2}^1, \quad \left[ \begin{pmatrix}
a & b\\ c & d
\end{pmatrix} \right] \mapsto [(a,b)]
\end{align*}
are bijections.
\end{lem}
\begin{proof}
See the discussions before Lemma 10.2 of \citet{grimmelt2024twisted}.
\end{proof}
We isolate a lemma from the proof of Theorem \ref{thm:certaindivisorcoprime}.
\begin{lem}\label{lem:boundingKeasy}
Let $r_1,r_2 \in \mathbb{Z}^+$, $h \in \mathbb{Z}$, and $B,C \in \mathbb{R}^+$. Define $r_0=\gcd(r_1,r_2)$ and $\widetilde{r}_i=r_i/r_0$ for $i=1,2$. Suppose $r_1,r_2$ are squarefree. Let $\alpha_0:\operatorname{M}_2(\mathbb{Z}) \to \mathbb{C}$ be given by
\[
\alpha_0(\begin{psmallmatrix}
a &b \\ c & d
\end{psmallmatrix})=\mathds{1}_{\widetilde{r}_2 \mid a} \mathds{1}_{\widetilde{r}_1 \mid c}.
\]
Then, for $\Gamma=\Gamma_2(r_2,r_1)$, $\alpha_0$ is left $\Gamma$-automorphic, and that
\begin{align*}
\sum_{0 \leq |b| \leq B} \left| \sum_{\tau \in \Gamma \backslash \operatorname{SL}_2(\mathbb{Z})} \alpha_0 \left(\tau \right) \overline{\alpha_0 \left(\tau \begin{psmallmatrix}
1 & b\\ 0 & 1
\end{psmallmatrix} \right)} \right| &\ll r_0^2B,\\
\sum_{0 < |c| \leq C} \left| \sum_{\tau \in \Gamma \backslash \operatorname{SL}_2(\mathbb{Z})} \alpha_0 \left(\tau \right) \overline{\alpha_0 \left(\tau \begin{psmallmatrix}
1 & 0\\ c & 1
\end{psmallmatrix} \right)} \right| &\ll \frac{r_0^2}{\widetilde{r}_1 \widetilde{r}_2}C,
\end{align*}
and for all $\sigma \in \mathrm{M}_2(\mathbb{Z})$ we have
\begin{align*}
\left| \sum_{\tau \in \Gamma \backslash \operatorname{SL}_2(\mathbb{Z})} \alpha_0(\tau) \overline{\alpha_0(\tau \sigma)} \right| \ll r_0^2.
\end{align*}
\end{lem}
\begin{proof}
To prove $\alpha$ is left $\Gamma$-automorphic, let $g=\begin{psmallmatrix}
a' & r_2b'\\ r_1c' & d'
\end{psmallmatrix} \in \Gamma$, then $(a',r_1r_2)=(d',r_1r_2)=1$, so
\begin{align*}
\alpha_0(\begin{psmallmatrix}
a & b\\ c & d
\end{psmallmatrix})=1 &\iff \widetilde{r}_2 \mid a, \ \widetilde{r}_1 \mid c\\
&\iff \widetilde{r}_2 \mid a'a+r_0\widetilde{r}_2b'c, \ \widetilde{r}_1 \mid r_0\widetilde{r}_1ac'+cd'\\
&\iff \alpha_0(g \begin{psmallmatrix}
a & b\\c & d
\end{psmallmatrix})=1.
\end{align*}We consider the sum over $c$ first. By the Chinese Remainder Theorem,
\begin{align*}
\sum_{0 < |c| \leq C} \Bigg| &\sum_{\tau \in \Gamma \backslash \operatorname{SL}_2(\mathbb{Z})} \alpha_0 \left(\tau \right) \overline{\alpha_0 \left(\tau \begin{psmallmatrix}
1 & 0\\ c & 1
\end{psmallmatrix} \right)} \Bigg|\\
= \sum_{0 < |c| \leq C} &\prod_{\substack{p \nmid r_0,p \mid \widetilde{r}_1}} \Bigg( \sum_{\left[\begin{psmallmatrix}
a' & b'\\ c' & d'
\end{psmallmatrix} \right] \in \Gamma_0(p) \backslash \operatorname{SL}_2(\mathbb{Z})} \mathds{1}_{p \mid c'} \mathds{1}_{p \mid cd'} \Bigg)
\prod_{\substack{p \nmid r_0,
p \mid \widetilde{r}_2}} \Bigg( \sum_{\left[\begin{psmallmatrix}
a' & b'\\ c' & d'
\end{psmallmatrix} \right] \in \Gamma_0(p)^T \backslash \operatorname{SL}_2(\mathbb{Z})} \mathds{1}_{p \mid a'} \mathds{1}_{p \mid cb'} \Bigg)\\
&\hspace{0.65em}\prod_{\substack{p \mid r_0}} \Bigg( \sum_{\left[\begin{psmallmatrix}
a' & b'\\ c' & d'
\end{psmallmatrix} \right] \in \Gamma_2(p,p) \backslash \operatorname{SL}_2(\mathbb{Z})} 1 \Bigg) \\
=: \sum_{0 < |c| \leq C} & \Pi_1 \Pi_2 \Pi_3.
\end{align*}
To bound $\Pi_1$ note $p \nmid d'$, so $p \mid c$ and $\Pi_1 \leq \prod_{p \mid \widetilde{r}_1}\mathds{1}_{p \mid c}=\mathds{1}_{\widetilde{r}_1 \mid c}$. Similarly, $\Pi_2 \leq \mathds{1}_{\widetilde{r}_2 \mid c}$. Also, we have $\Pi_3 \leq r_0^2$. Putting these together, we get the required bound.\\
The sum over $b$ is similar but simpler, so we omit it. For the last bound, we again split into three products
\begin{align*}
\sum_{\tau \in \Gamma \backslash \operatorname{SL}_2(\mathbb{Z})} \alpha_0(\tau) \alpha_0(\tau \sigma) &\leq \sum_{\tau \in \Gamma \backslash \operatorname{SL}_2(\mathbb{Z})} \alpha_0(\tau)\\
&\leq \prod_{\substack{p \mid \widetilde{r}_1}} \Bigg( \sum_{\left[\begin{psmallmatrix}
a' & b'\\ c' & d'
\end{psmallmatrix} \right] \in \Gamma_0(p) \backslash \operatorname{SL}_2(\mathbb{Z})} \mathds{1}_{p \mid c'} \Bigg) \prod_{\substack{
p \mid \widetilde{r}_2}} \Bigg( \sum_{\left[\begin{psmallmatrix}
a' & b'\\ c' & d'
\end{psmallmatrix} \right] \in \Gamma_0(p)^T \backslash \operatorname{SL}_2(\mathbb{Z})} \mathds{1}_{p \mid a'}\Bigg)\\
&\hspace{1.15em} \prod_{\substack{p \mid r_0}} \Bigg( \sum_{\left[\begin{psmallmatrix}
a' & b'\\ c' & d'
\end{psmallmatrix} \right] \in \Gamma_2(p,p) \backslash \operatorname{SL}_2(\mathbb{Z})} 1 \Bigg)\\
&=: \Pi_1' \Pi_2' \Pi_3'.
\end{align*}
Clearly, $\Pi_1',\Pi_2'\leq 1$ while $\Pi_3' \ll r_0^2$, which is the required bound.
\end{proof}
We use Lemma \ref{lem:boundingKeasy} to prove the following.
\begin{lem}\label{lem:boundingK}
Let $r_1,r_2 \in \mathbb{Z}^+$, $h \in \mathbb{Z}$, and $L \in \mathbb{R}^+$. Define $r_0=\gcd(r_1,r_2)$ and $\widetilde{r}_i=r_i/r_0$ for $i=1,2$. Suppose $r_1,r_2$ are squarefree and $\gcd(h,r_1r_2)=1$. Define $k=\gcd(\widetilde{r}_2-\widetilde{r}_1,r_1r_2^\infty)$ and $r=r_0/\gcd(r_0,k)$. Let $\alpha:\operatorname{M}_2(\mathbb{Z}) \to \mathbb{C}$ be given by
\[
\alpha(\begin{psmallmatrix}
a &b \\ c & d
\end{psmallmatrix})=\mathds{1}_{\widetilde{r}_2 \mid a} \mathds{1}_{\widetilde{r}_1 \mid c} \mathds{1}_{r_2 \mid ad-h\widetilde{r}_2},
\]
and define
\[
\mathrm{M}_{2,h,k}(\mathbb{Z}) := \left\{ \begin{pmatrix}
a & b\\ c & d
\end{pmatrix} \in \mathrm{M}_{2,hk}(\mathbb{Z}):\gcd(a,c,k)=\gcd(b,d,k)=1 \right\}.
\]
Then, for $\Gamma=\Gamma_2(r_2,r_1)$, $T_{1,k} = \operatorname{SL}_2(\mathbb{Z}) \backslash \mathrm{M}_{2,1,k}(\mathbb{Z})$, and $T = \Gamma \backslash \operatorname{SL}_2(\mathbb{Z})$, we have
\[
\sum_{\substack{g=\begin{psmallmatrix}
a&b\\c&d
\end{psmallmatrix} \in \operatorname{SL}_2(\mathbb{R})\\
|a|+|b|L+|c|/L+|d| \leq 10}}\left| \sum_{\substack{\sigma_1,\sigma_2 \in T_{1,k}\\ \sigma_1^{-1} g \sigma_2 =: \sigma \in \operatorname{SL}_2(\mathbb{Z})}}\sum_{\substack{\tau \in T}} \alpha(\tau \sigma) \overline{\alpha(\tau \sigma g)} \right| \ll \frac{kr_0^2}{L}+\frac{k^2r_0^2L}{\widetilde{r}_1\widetilde{r}_2}+ k^2r_0^{2+\e}.
\]
\end{lem}
\begin{proof}
The proof is similar to the argument in p.64-66 of \citet{grimmelt2024twisted}. Note that
\[
\begin{pmatrix}
a & b \\ c & d
\end{pmatrix}
\begin{pmatrix}
1 & fr\\ 0 & k
\end{pmatrix}
=
\begin{pmatrix}
a & afr+bk\\ c & cfr+dk
\end{pmatrix},
\]
so for any $\tau = \begin{psmallmatrix} a & b\\ c& d\end{psmallmatrix} \in M_2(\mathbb{Z})$ and $\sigma = \begin{psmallmatrix} 1 & fr \\ 0 & k \end{psmallmatrix}$, we have
\[
\alpha(\tau \sigma) \leq \mathds{1}_{\widetilde{r}_2 \mid a} \mathds{1}_{\widetilde{r}_1 \mid c} =: \alpha_0(\tau).
\]
Therefore,
\begin{align*}
&\sum_{\substack{g=\begin{psmallmatrix}
a&b\\c&d
\end{psmallmatrix} \in \operatorname{SL}_2(\mathbb{R})\\
|a|+|b|L+|c|/L+|d| \leq 10}}\left| \sum_{\substack{\sigma_1,\sigma_2 \in T_{1,k}\\ \sigma_1^{-1} g \sigma_2 =: \sigma \in \operatorname{SL}_2(\mathbb{Z})}}\sum_{\substack{\tau \in T}} \alpha(\tau \sigma) \overline{\alpha(\tau \sigma g)} \right|\\
&\leq \sum_{\sigma=\begin{psmallmatrix} a & b \\ c & d \end{psmallmatrix}\in \operatorname{SL}(\mathbb{Z})} \sum_{\tau \in T} \alpha_0(\tau \sigma) \alpha_0(\tau) \sum_{\substack{\sigma_j = \begin{psmallmatrix} 1 & f_j r\\ 0 & k \end{psmallmatrix}\\ \sigma_2^{-1} \sigma \sigma_1 = \begin{psmallmatrix} a_0 & b_0\\ c_0 & d_0 \end{psmallmatrix}\\ |a_0|+|b_0|L+|c_0|/L+|d_0| \leq 10}} 1.
\end{align*}To bound this quantity, we split into three cases. First, if $c=0$ then $ad=1$ implies $a=d=\pm 1$. Therefore,
\begin{align*}
&\sum_{\substack{\sigma=\begin{psmallmatrix} a & b \\ c & d \end{psmallmatrix}\in \operatorname{SL}(\mathbb{Z})\\ c=0}} \sum_{\tau \in T} \alpha_0(\tau \sigma) \alpha_0(\tau) \sum_{\substack{\sigma_j = \begin{psmallmatrix} 1 & f_j r\\ 0 & k \end{psmallmatrix}\\ \sigma_2^{-1} \sigma \sigma_1 = \begin{psmallmatrix} a_0 & b_0\\ c_0 & d_0 \end{psmallmatrix}\\ |a_0|+|b_0|L+|c_0|/L+|d_0| \leq 10}} 1\\
&\leq \sum_b \sum_{\tau \in T} \alpha_0(\tau \begin{psmallmatrix} \pm 1 & b\\ 0 & \pm 1 \end{psmallmatrix}) \alpha_0(\tau) \sum_{\substack{f_1,f_2 \leq k\\ |f_1r-f_2r \pm kb| \leq 10/L}} 1\\
&\ll k\sum_b \sum_{\tau \in T} \alpha_0(\tau \begin{psmallmatrix} \pm 1 & b\\ 0 & \pm 1 \end{psmallmatrix}) \alpha_0(\tau) \sum_{\substack{f \leq k\\|fr \pm kb| \leq 10/L}} 1\\
&\ll k \sum_{|b_0| \leq 10/L} \sum_{\tau \in T} \alpha_0(\tau \begin{psmallmatrix} \pm 1 & b_0\\ 0 & \pm 1 \end{psmallmatrix}) \alpha_0(\tau)\\
&\ll \frac{kr_0^2}{L},
\end{align*}
where we substituted $b_0=fr\pm kb$ since $\gcd(k,r)=1$, and we used Lemma \ref{lem:boundingKeasy} in the last step. The second case is $c \neq 0$ and $b_0=0$. Note
\[
\sigma_2^{-1} \sigma \sigma_1= \frac{1}{k}
\begin{pmatrix}
* & f_1r a-f_2rd+kb-cf_1f_2r^2/k\\
* & *
\end{pmatrix},
\]
so $b_0=0$ implies $r \mid b$ and $k \mid c$. Therefore,
\begin{align*}
&\sum_{\substack{\sigma=\begin{psmallmatrix} a & b \\ c & d \end{psmallmatrix}\in \operatorname{SL}(\mathbb{Z})\\c \neq 0}} \sum_{\tau \in T} \alpha_0(\tau \sigma) \alpha_0(\tau) \sum_{\substack{\sigma_j = \begin{psmallmatrix} 1 & f_j r\\ 0 & k \end{psmallmatrix}\\ \sigma_2^{-1} \sigma \sigma_1 = \begin{psmallmatrix} a_0 & b_0\\ c_0 & d_0 \end{psmallmatrix}\\ |a_0|+|b_0|L+|c_0|/L+|d_0| \leq 10\\b_0=0}} 1\\
&\leq \sum_{\substack{\sigma=\begin{psmallmatrix} a & b \\ c & d \end{psmallmatrix}\in \operatorname{SL}(\mathbb{Z})\\ 0<|c| \leq 10kL\\ r \mid b,\ k \mid c}} \sum_{\tau \in T} \alpha_0(\tau \sigma) \alpha_0(\tau) \sum_{\substack{f_1,f_2 \leq k\\|a-cf_2r/k|\leq 10\\|d+cf_1/k|\leq 10\\b_0=0}} 1.
\end{align*}
Since $k \mid c$, we have $\alpha_0(\begin{psmallmatrix} 1 & 0\\c & 1 \end{psmallmatrix})=\alpha_0(\begin{psmallmatrix} 1 & 0\\c/k & 0 \end{psmallmatrix})$ and $\alpha_0(\tau \begin{psmallmatrix} a & b\\c & d \end{psmallmatrix})=\alpha_0(\tau \begin{psmallmatrix} 1 & 0\\c & 1 \end{psmallmatrix})$, so the sum is
\begin{align*}
&\ll \sum_{\substack{0<|c| \leq 10kL\\k \mid c}}\sum_{\tau \in T} \alpha_0(\tau \begin{psmallmatrix} 1 & 0\\ c & 1 \end{psmallmatrix}) \alpha_0(\tau)
\sum_{\substack{a,b,d\\ad-bc=1}} \sum_{\substack{f_1,f_2 \leq k\\|a-cf_2r/k|\leq 10\\|d+cf_1/k|\leq 10\\b_0=0}} 1\\
&\ll \sum_{0<|c|\leq 10L} \sum_{\tau \in T} \alpha_0(\tau \begin{psmallmatrix} 1 & 0\\ c & 1 \end{psmallmatrix}) \alpha_0(\tau)
\sum_{\substack{a,b,d\\ad-bck=1}} \sum_{\substack{f_1,f_2 \leq k\\|a-cf_2r|\leq 10\\|d+cf_1|\leq 10\\f_2r d-f_1r a+cf_1f_2r^2=kb}} 1\\
&\ll \sum_{0<|c|\leq 10L} \sum_{\tau \in T} \alpha_0(\tau \begin{psmallmatrix} 1 & 0\\ c & 1 \end{psmallmatrix}) \alpha_0(\tau)
\sum_{f_1,f_2 \leq k} \sum_{\substack{a,d\\|a-cf_2r|\leq 10\\|d+cf_1|\leq 10}} 1\\
&\ll k^2 \sum_{0<|c|\leq 10L} \sum_{\tau \in T} \alpha_0(\tau \begin{psmallmatrix} 1 & 0\\ c & 1 \end{psmallmatrix}) \alpha_0(\tau)\\
&\ll \frac{k^2r_0^2L}{\widetilde{r}_1 \widetilde{r}_2},
\end{align*}
where we used Lemma \ref{lem:boundingKeasy} in the last step. Finally, for the last case we use the trivial bound. For any $\sigma \in M_2(\mathbb{Z})$,
\[
\left| \sum_{\tau \in T} \alpha_0(\tau \sigma) \alpha_0(\tau) \right| \ll r_0^2
\]
by Lemma \ref{lem:boundingKeasy}, and so
\begin{align*}
&\sum_{\substack{\sigma=\begin{psmallmatrix} a & b \\ c & d \end{psmallmatrix}\in \operatorname{SL}(\mathbb{Z})\\c \neq 0}} \sum_{\tau \in T} \alpha_0(\tau \sigma) \alpha_0(\tau) \sum_{\substack{\sigma_j = \begin{psmallmatrix} 1 & f_j r\\ 0 & k \end{psmallmatrix}\\ \sigma_2^{-1} \sigma \sigma_1 = \begin{psmallmatrix} a_0 & b_0\\ c_0 & d_0 \end{psmallmatrix}\\ |a_0|+|b_0|L+|c_0|/L+|d_0| \leq 10\\b_0 \neq 0}} 1\\
&\ll r_0^2 \sum_{\substack{\begin{psmallmatrix} a_1 & b_1\\ c_1&d_1 \end{psmallmatrix} \in \mathrm{M}_{2,k}(\mathbb{Z})\\ c \neq 0}} \sum_{\substack{\sigma_2 \in T_{1,k}\\ \sigma_2^{-1}\begin{psmallmatrix} a_1 & b_1\\ c_1&d_1 \end{psmallmatrix}=\begin{psmallmatrix} a_0 & b_0\\ c_0 & d_0 \end{psmallmatrix}\\|a_0|+|b_0|L+|c_0|/L+|d_0| \leq 10\\ b_0\neq 0}} 1.
\end{align*}Note
\[
\begin{pmatrix}
a_0&b_0\\c_0&d_0
\end{pmatrix}
= \frac1k
\begin{pmatrix}
k & -f_2r\\0&1
\end{pmatrix}
\begin{pmatrix}
a_1&b_1\\c_1&d_1
\end{pmatrix}
= \frac1k
\begin{pmatrix}
ka_1-f_2rc_1 & kb_1-f_2rd_1\\
c_1&d_1
\end{pmatrix},
\]
and let the last matrix be $\frac1k \begin{psmallmatrix} a_2&b_2\\c_2&d_2 \end{psmallmatrix}$. Then, summing over $f_2$ and grouping together variables, the above sum is
\begin{align*}
&\ll r_0^2 \sum_{\substack{a_2d_2-b_2c_2=k^2\\|a_2|/k+|b_2|L/k+|c_2|/(kL)+|d_2|/k \leq 10\\ b_2c_2 \neq 0}} 1
\ll r_0^2 \sum_{\substack{a_2,d_2 \ll k\\a_2d_2 \neq k^2}} \tau(a_2d_2-k^2) \ll k^2 r_0^{2+\e}.
\end{align*}
Grouping these estimates together, we are done.
\end{proof}
\begin{proof}[Proof of Theorem \ref{thm:certaindivisorcoprime}]
Splitting the divisor function, we get
\[
\sum_n w_1 \left( \frac{r_1n}{x} \right) w_2 \left( \frac{r_2n}{x} \right) d(r_1n+h) d(r_2n+h)=\sum_n \sum_{\substack{ad=r_1n+h\\ bc=r_2n+h}} w_1 \left( \frac{ad-h}{x} \right) w_2 \left( \frac{bc-h}{x} \right).
\]
For convenience, let $r_0=(r_1,r_2)$ and $\widetilde{r}_i=r_i/r_0$ for $i=1,2$. Note
\[
\begin{cases}
ad &= r_1n+h\\
bc &= r_2n+h
\end{cases} \implies \widetilde{r}_2ad-\widetilde{r}_1bc=h(\widetilde{r}_2-\widetilde{r}_1).
\]
We wish to recover $n$ from the right hand side along with another condition. Since $(\widetilde{r}_1,\widetilde{r}_2)=1$, $\widetilde{r}_1 \mid \widetilde{r}_2(ad-f_1)$ implies $\widetilde{r}_1 \mid (ad-f_1)$. If we have $r_0 \mid ad-f_1$, then we can choose
\[
n=\frac{ad-f_1}{r_0 \cdot \widetilde{r}_1}=\frac{ad-f_1}{r_1},
\]
since $(r_0,\widetilde{r}_1)=1$. Therefore,
\begin{align*}
&\sum_n \sum_{\substack{ad=r_1n+h\\ bc=r_2n+h}} w_1 \left( \frac{ad-h}{x} \right) w_2 \left( \frac{bc-h}{x} \right)\\ &=\sum_{\substack{\widetilde{r}_2ad-\widetilde{r}_1bc=h(\widetilde{r}_2-\widetilde{r}_1)\\r_0 \mid ad-h}} w_1 \left( \frac{ad-h}{x} \right) w_2 \left( \frac{bc-h}{x} \right)\\
&=\sum_{ad-bc=h(\widetilde{r}_2-\widetilde{r}_1)} w_1 \left( \frac{ad-h\widetilde{r}_2}{\widetilde{r}_2x} \right) w_2 \left( \frac{bc-h\widetilde{r}_1}{\widetilde{r}_1x} \right) \mathds{1}_{\widetilde{r}_2 \mid a}\mathds{1}_{\widetilde{r}_1 \mid c} \mathds{1}_{r_2 \mid a d-h\widetilde{r}_2}\\
&=: \sum_{ad-bc=h(\widetilde{r}_2-\widetilde{r}_1)} w_1 \left( \frac{ad-h\widetilde{r}_2}{\widetilde{r}_2x} \right) w_2 \left( \frac{bc-h\widetilde{r}_1}{\widetilde{r}_1x} \right) \alpha(\begin{psmallmatrix}
a&b\\ c&d
\end{psmallmatrix}).
\end{align*}
Let $\psi:\mathbb{R} \to [0,1]$ be a fixed smooth function supported on $[1,2]$ which satisfies
$$\int_\mathbb{R} \psi \left( \frac{1}{x} \right) \frac{\d x}{x}=1.$$
Inserting this into our sum, we get
\begin{align*}
&\sum_{ad-bc=h(\widetilde{r}_2-\widetilde{r}_1)} w_1 \left( \frac{ad-h\widetilde{r}_2}{\widetilde{r}_2x} \right) w_2 \left( \frac{bc-h\widetilde{r}_1}{\widetilde{r}_1x} \right) \alpha(\begin{psmallmatrix}
a&b\\ c&d
\end{psmallmatrix})\\
&= \int_{\mathbb{R}^3} \sum_{ad-bc=h(\widetilde{r}_2-\widetilde{r}_1)} w_1 \left( \frac{ad-h\widetilde{r}_2}{\widetilde{r}_2x} \right) w_2 \left( \frac{bc-h\widetilde{r}_1}{\widetilde{r}_1x} \right)
%\\ &\hspace{8.9em}
\psi \left( \frac{a}{A} \right) \psi \left( \frac{c}{C} \right) \psi \left( \frac{d}{D} \right) \alpha(\begin{psmallmatrix} a&b\\ c&d\end{psmallmatrix}) \frac{\mathrm{d}A \mathrm{d} C \mathrm{d} D}{ACD},
\end{align*}
and let $S(A,C,D)$ be the inner sum, and denote $B:=(\widetilde{r}_1x+h\widetilde{r}_1)/C$. Since the weight functions $w_1,w_2$ imply $r_1 \asymp r_2$ and we assumed $h \ll x^{1-\e}$, by swapping the variables we may assume
\[
\widetilde{r}_1^{-1}C \ll D \ll \widetilde{r}_2^{-1}A \ll B.
\]
If $A>r_2Cx^\eta$ or $D>r_0Cx^\eta$, we can use Poisson summation to get the correct main term with a negligible error term. Indeed, we have the following congruence requirements on $a$: $$ad \equiv h(\widetilde{r}_2-\widetilde{r}_1 )\Mod{c},\quad a \equiv \widetilde{r}_2 \bar{d}h \Mod{\frac{r_2}{(r_0,d)}},$$ where $\bar{d}$ is the multiplicative inverse of $d$ mod $\frac{r_0}{(r_0,d)}$, and while for $d$ we have
\[
\frac{a}{\widetilde{r}_2} d \equiv h \pmod{r_0}, \quad ad \equiv h(\widetilde{r}_2-\widetilde{r}_1)\pmod{c}
\]
Therefore, it remains to consider the complementary range
\[
1 \ll \frac{A}{C} \ll r_2 x^\eta, \quad \widetilde{r}_1^{-1} \ll \frac{D}{C} \ll r_0x^\eta.
\]
Our goal is to apply Theorem \ref{thm:grimmelt10.1}. However, in the theorem statement the conditions $\gcd(a,c,k)=\gcd(b,d,k)=1$ are assumed, where $k=\gcd(\widetilde{r}_2-\widetilde{r}_1,r_1r_2^\infty)$. Observe that $\gcd(k,\widetilde{r}_1\widetilde{r}_2)=1$, and let $k_{ac}=\gcd(a,c,k)$ and $k_{bd}=\gcd(b,d,k)$. Then we can rewrite our original sum as
\begin{align*}
&\sum_{\gamma_1,\gamma_2 \mid k} \sum_{ad-bc=h(\widetilde{r}_2-\widetilde{r}_1)} w_1 \left( \frac{ad-h\widetilde{r}_2}{\widetilde{r}_2x} \right) w_2 \left( \frac{bc-h\widetilde{r}_1}{\widetilde{r}_1x} \right) \mathds{1}_{\widetilde{r}_2 \mid a}\mathds{1}_{\widetilde{r}_1 \mid c} \mathds{1}_{r_2 \mid a d-h\widetilde{r}_2} \mathds{1}_{k_{ac}=\gamma_1,k_{bd}=\gamma_2}\\
&= \sum_{\gamma_1,\gamma_2 \mid k} \sum_{\substack{ad-bc=\frac{h(\widetilde{r}_2-\widetilde{r}_1)}{\gamma_1\gamma_2}\\ (a,c,k)=(b,d,k)=1}} w_1 \left( \frac{\gamma_1\gamma_2 ad-h\widetilde{r}_2}{\widetilde{r}_2x} \right) w_2 \left( \frac{\gamma_1 \gamma_2 bc-h\widetilde{r}_1}{\widetilde{r}_1x} \right) \mathds{1}_{\widetilde{r}_2 \mid a}\mathds{1}_{\widetilde{r}_1 \mid c} \mathds{1}_{ad \equiv \gamma_3 h\widetilde{r}_2 \mod{\frac{r_0}{(r_0,\gamma_1\gamma_2)} \cdot \widetilde{r}_2}},
\end{align*}
where $\gamma_3$ is the multiplicative inverse of $\gamma_1\gamma_2/(r_0,\gamma_1\gamma_2)$ modulo $r_0/(r_0,\gamma_1\gamma_2)$. This form satisfies the conditions of Theorem \ref{thm:grimmelt10.1} and we may apply the theorem to the inner sum. Since the outer sum has only $\ll r_0^\e$ many terms, for simplicity we focus on estimating
\[
\sum_{\substack{ad-bc=h(\widetilde{r}_2-\widetilde{r}_1)\\ (a,c,k)=(b,d,k)=1}} w_1 \left( \frac{ad-h\widetilde{r}_2}{\widetilde{r}_2x} \right) w_2 \left( \frac{bc-h\widetilde{r}_1}{\widetilde{r}_1x} \right) \mathds{1}_{\widetilde{r}_2 \mid a}\mathds{1}_{\widetilde{r}_1 \mid c} \mathds{1}_{r_2 \mid a d-h\widetilde{r}_2},
\]
and the treatment for the general case is entirely analogous. Now apply Theorem \ref{thm:grimmelt10.1} with the determinant as $h(\widetilde{r}_2-\widetilde{r}_1)/(\widetilde{r}_2-\widetilde{r}_1,r_1r_2^\infty)$ and
\[q_1=r_2, \quad q_2=r_1, \quad k=(\widetilde{r}_2-\widetilde{r}_1,r_1r_2^\infty), \quad \Gamma=\Gamma_2(r_2,r_1).
\]
Observe that $\alpha$ is left $\Gamma$-automorphic. Applying Theorem \ref{thm:grimmelt10.1} and integrating, we obtain the correct main term. Using Lemma \ref{lem:boundingK}, we have
\[
\mathcal{K}_+ \ll r_0^3 x^\eta+\frac{kr_0^2}{\widetilde{r}_2}+ kr_0^{2+\e} \ll k r_0^3 x^\eta.
\]
We bound $\mathcal{R}_0,\mathcal{R}_1,\mathcal{R}_2$ by
\begin{align*}
\mathcal{R}_0 &\ll \frac{A^{1/2}}{q_1^{1/2} C^{1/2}} \ll x^\frac{\eta}{2},\\
\mathcal{R}_1 &\ll |h(\widetilde{r}_2-\widetilde{r}_1)|^\theta \left( 1+ \left( \frac{CD}{r_1|h(\widetilde{r}_2-\widetilde{r}_1)|} \right)^\theta \right)\left( 1+\left( \frac{1}{r_1} \right)^{\frac12-\theta} \right),\\
\mathcal{R}_2 &\ll \left( 1+\left( \frac{CD}{r_1} \right)^\theta \right) \left( 1+ \left( \frac{|h(\widetilde{r}_2-\widetilde{r}_1)|}{r_1} \right)^{\frac{1}{2}-\theta} \right).
\end{align*}
Since $(AD)^{1/2} \ll \widetilde{r}_2^{1/2} x^{1/2+O(\eta)}$, the error term we get from Theorem \ref{thm:grimmelt10.1} is
\[
O_{\e} \left( x^{\frac12+O(\eta)} r_0 r_2^{\frac12}\gcd(\widetilde{r}_2-\widetilde{r}_1,r_0^\infty)^{\frac12} \left( \left(\frac{|h(r_2-r_1)|}{r_0} \right)^\theta+\frac{x^\theta}{r_1^\theta} \right) \right).
\]
\end{proof}
\noindent The following theorem relaxes the condition $(h,r_1r_2)=1$ from Theorem \ref{thm:certaindivisorcoprime}.
\begin{thm} \label{thm:certaindivisor}
Let $r_1,r_2 \in \mathbb{Z}^+$ be squarefree and $h \in \mathbb{Z} \setminus \{0\}$. Let $r_0=(r_1,r_2)$, $x,\eta,\e \in \mathbb{R}^+$, and define $w_1,w_2:\mathbb{R} \to \mathbb{R}$ smooth compactly supported functions on $[1/2,1]$, satisfying $w_1^{(j)},w_2^{(j)} \ll_j x^{j \eta}$ for all $j \geq 0$. Then for $h \ll x^{1-\e}$, we have
\begin{align*}
\sum_n w_1 \left( \frac{r_1n}{x} \right) &w_2\left( \frac{r_2n}{x} \right) d(r_1n+h) d(r_2n+h)=\textrm{Main Term}\\
&+O_{\e} \left( x^{\frac12+O(\eta)} r_0 r_2^{\frac12+\e}\gcd(\widetilde{r}_2-\widetilde{r}_1,r_0^\infty)^{\frac12} \left( \left(\frac{|h(r_2-r_1)|}{r_0} \right)^\theta+\frac{x^\theta}{r_1^\theta} \right) \right),
\end{align*}
where the main term is given by
\[
\int w_1 \left( \frac{r_1 \xi}{x} \right) w_2 \left( \frac{r_2 \xi}{x} \right) P(\log(r_1 \xi+h),\log(r_2 \xi+h)) \d \xi,
\]
and $P(X,Y)$ is a quadratic polynomial depending only on $r_1,r_2,h$.
\end{thm}
\begin{proof}
As in the proof of Theroem \ref{thm:certaindivisorcoprime}, we may arrange the sum to be of the form
\[
\sum_{ad-bc=h(\widetilde{r}_2-\widetilde{r}_1)}w_1 \left( \frac{ad-h\widetilde{r}_2}{\widetilde{r}_2x} \right) w_2 \left( \frac{bc-h\widetilde{r}_1}{\widetilde{r}_1x} \right) \mathds{1}_{\widetilde{r}_2 \mid a}\mathds{1}_{\widetilde{r}_1 \mid c} \mathds{1}_{r_2 \mid a d-h\widetilde{r}_2}.
\]
Let $s_0=\gcd(h,r_0)$ and $s_i=\gcd(h,\widetilde{r}_i)$ for $i=1,2$. From the indicator functions, note that $s_1 \mid c$ and $s_2 \mid a$. Also, from $s_0 \mid h$ and $r_0 \mid ad-h\widetilde{r}_2$ we have $s_0 \mid ad$. Thus, $s_0 \mid bc$ as well. Therefore, the sum can be written as
\begin{align*}
&\sum_{\frac{(a/s_2)d}{s_0s_1}-\frac{b(c/s_1)}{s_0s_2}=\frac{h}{s_0s_1s_2}(\widetilde{r}_2-\widetilde{r}_1)} w_1 \left( \frac{ad-h\widetilde{r}_2}{\widetilde{r}_2x} \right) w_2 \left( \frac{bc-h\widetilde{r}_1}{\widetilde{r}_1x} \right) \mathds{1}_{\widetilde{r}_2 \mid a}\mathds{1}_{\widetilde{r}_1 \mid c} \mathds{1}_{r_0 \widetilde{r}_2 \mid a d-h\widetilde{r}_2}\\
&=\sum_{\substack{u_1v_1=s_1\\u_2v_2=s_2}} \sum_{u_0v_0=u_0'v_0'=s_0} \sum_{ad-bc=h'(\widetilde{r}_2-\widetilde{r}_1)} w_1 \left( \frac{ad-h'\widetilde{r}_2}{\widetilde{r}_2'x} \right) w_2 \left( \frac{bc-h'\widetilde{r}_1}{\widetilde{r}_1'x} \right) \mathds{1}_{\widetilde{r}_2' \mid a}\mathds{1}_{\widetilde{r}_1' \mid c} \mathds{1}_{r_0' \widetilde{r}_2' \mid a d-h'\widetilde{r}_2},
\end{align*}
where $h'=h/s_0s_1s_2$, $r_0'=r_0/s_0$, and $\widetilde{r}_i'=\widetilde{r}_i/s_i$ for $i=1,2$. If we let
\[
q_1=r_0'\widetilde{r}_2', \quad q_2= r_0' \widetilde{r}_1', \quad h''=\frac{h'(\widetilde{r}_2-\widetilde{r}_1)}{(\widetilde{r}_2-\widetilde{r}_1,r_1r_2^\infty)}, \quad k=(\widetilde{r}_2-\widetilde{r}_1,r_1r_2^\infty),
\]
then $\gcd(h'',kq_1q_2)=1$ and we may apply Theorem \ref{thm:certaindivisorcoprime}. By summing over the asymptotic in Theorem \ref{thm:certaindivisorcoprime} and noticing the outer sums only contribute $\ll r_2^\e$ terms, we get the required error term.
\end{proof}
\section{Shifted Convolution of Generalised Divisor Functions}
\noindent In this section, we prove Theorem \ref{thm:generaliseddivisor}.
\setcounter{section}{1}
\setcounter{thm}{1}
\begin{thm}\label{thm:generaliseddivisor}
Let $w:[1/2,1] \to [0,\infty)$ be smooth and compactly supported, $\e>0$, and $x \in \mathbb{R}^+$ sufficiently large in terms of $\e$. Let $h \in \mathbb{N}$. Then for $0 \leq \delta \leq \frac{1}{16}$ and $h \ll x^{1-\e}$, we have
\begin{align*}
\sum_n w \left( \frac{n}{x} \right) &d_k(n) d(n \pm h)= \ xP_{k,h,w}(\log x)\\
&+O_{k,w,\e,\delta}\left(x^{1-\delta+2 \delta \theta+\e}\left( 1+\frac{|h|^{\frac{1}{4}}}{x^{\frac14-\frac12 \delta}} \right)+x^{1-\delta+\frac{\theta}{3}+\frac{2\delta}{3}\theta+\e} \left(1+\frac{|h|^{\frac{\theta}{2}}}{x^{\frac{\theta}{6}+\frac{4 \delta}{3} \theta}}\right) \right),
\end{align*}
where $P_{k,h,w}$ is a polynomial of degree $k$ depending only on $h$ and $w$, and the implied constant depends on $k,w,\e,\delta$.
\end{thm}
\noindent The proof of Theorem \ref{thm:generaliseddivisor} relies on the following lemma.
\setcounter{section}{6}
\setcounter{thm}{0}
\begin{lem} \label{lem:remainderbound}
Let $w:[1/2,1] \to [0,\infty)$ be a smooth and compactly supported function and $x \in \mathbb{R}^+$. Let $h \in \mathbb{N}$, and let $v_1,\ldots,v_k$ be smooth and compactly supported functions with $\operatorname{supp} v_i \asymp A_i$ and $v_i^{(\nu)} \ll A_i^{-\nu}$ for $\nu \geq 0$. Then,
\[
\sum_{a_1,\ldots,a_k} w \left( \frac{a_1 \cdots a_k}{x} \right) v_1(a_1) \cdots v_k(a_k) d(a_1 \cdots a_k+h)=M_{v_1}+R_{v_1},
\]
where $M_{v_1}$ is the main term
$$M_{v_1} := \int w \left( \frac{\xi}{x} \right) \sum_{\substack{a_2,\ldots,a_k\\ d \mid a_2 \cdots a_k}} \frac{v_2(a_2) \cdots v_k(a_k)}{a_2 \cdots a_k} v_1 \left( \frac{\xi}{a_2 \cdots a_k} \right) \lambda_{h,d}(\xi+h) \d \xi,$$
with
\[
\lambda_{h,d}(\xi)=\frac{c_d(h)}{d}(\log \xi+2 \gamma-2\log d), \quad c_d(h) := \sum_{\substack{a \Mod{d}\\ (a,d)=1}} e\left( \frac{an}{d} \right),
\]
and the following bounds for the error term $R_{v_1}$ for $h \ll x^{1-\e}$,
\begin{align}
R_{v_1} &\ll \frac{x^{\frac{3}{2}+\e}}{A_1^{\frac{3}{2}}}, \label{rem1}\\
R_{v_1} &\ll \frac{x^{\frac{3}{2}+\e}}{A_1A_2} \left( 1+\frac{(A_1A_2)^{2 \theta}}{x^\theta} \right) \left( 1+\frac{A_2^{\frac{1}{2}}}{A_1^{\frac{1}{2}}} \right) \left( 1+|h|^{\frac{1}{4}} \frac{A_1^{\frac{1}{2}}A_2^{\frac{1}{2}}}{x^{\frac{1}{2}}} \right), \label{rem2}\\
R_{v_1} &\ll \frac{x^{1+\e}}{A^{\frac12}}+A^{\frac34}x^{\frac34+\e} \left( |h|^{\frac{\theta}{2}} A^{\frac{\theta}{2}}+\frac{x^{\frac{\theta}{2}}}{A^{\frac{\theta}{2}}} \right), \label{rem3}
\end{align}
where $A=\prod_{i \in I}A_i$ for any non-empty index set $I \subseteq\{1,\ldots,k\}$. The implied constants depend only on $k$, and $w,v_1,\ldots,v_k,\e$.
\end{lem}
\begin{proof}
The first two bounds are from \citet[Lemma 2.1]{topacogullari2018shifted}. Let
\[
\Psi_{v_1,\ldots,v_k}=\sum_{a_1,\ldots,a_k} w \left( \frac{a_1 \cdots a_k}{x} \right) v_1(a_1) \cdots v_k(a_k) d(a_1 \cdots a_k+h).
\]
Our treatment of the third bound is a modification of \citet{topacogullari2018shifted}. First we rename variables such that $I=\{1,2,\ldots,|I|\}$. Write
\[
\Psi_{v_1,\ldots,v_k}=\sum_b \delta_I(b) \Phi_I(b),
\]
where
\begin{align*}
\Phi_I(b)&=\sum_{a_i, \, i \in I} d\left( b \prod_{i \in I} a_i+h \right) w \left( \frac{b}{x} \prod_{i \in I}a_i \right) \prod_{i \in I} v_i (a_i),\\
\delta_I(b)&=\sum_{\substack{a_{|I|+1},\ldots,a_k\\ b=a_{|I|+1} \cdots a_k}} v_{|I|+1}(a_{|I|+1}) \cdots v_k(a_k).
\end{align*}
Let $v^{sq}:(0,\infty) \to [0,\infty)$ be a smooth function compactly supported on $[1,2]$, such that
\[
\sum_{j \in \mathbb{Z}} v^{sq} \left( \frac{u}{2^j} \right)=1
\]
for any $u \in \mathbb{R}^+$, and let $v_j^{sq}(u)=v^{sq}(u/2^j)$. Inserting this into $\Psi_{v_1,\ldots,v_k}$, we have
\begin{align*}
\Psi_{v_1,\ldots,v_k}=\sum_j \sum_b \delta_I(b) \sum_{\substack{c\\ a_i', \ i \in I\\ \prod_{i \in I}a_i' \text{ squarefree}}} d \left( bc^2 \prod_{i \in I} a_i'+h \right) w \left( \frac{bc^2}{x} \prod_{i \in I}a_i' \right) v_j'(a_1',\ldots,a_{|I|}') v_j^{sq}(c^2),
\end{align*}
for some function $v_j'(a_1',\ldots,a_{|I|}')$ depending only on $j$ and $v_1,\ldots,v_k$, with support contained in $\prod_{i \in I}[\widetilde{A}_{j,i},2\widetilde{A}_{j,i}]$, say. Rearranging, we have
\begin{align*}
\Psi_{v_1,\ldots,v_k} &= \sum_j \sum_{b,c} \delta_I(b)v_j^{sq}(c^2)\sum_{\substack{a_i', \ i \in I\\\prod_{i \in I}a_i' \text{ squarefree}}}d \left( bc^2 \prod_{i \in I} a_i'+h \right) w \left( \frac{bc^2}{x} \prod_{i \in I} a_i' \right) v_j'(a_1',\ldots,a_{|I|}')\\
&= \sum_j \sum_f \underbrace{\sum_{\substack{b,c\\bc^2=f}}\delta_I(b) v_j^{sq}(c^2)}_{=: \delta_j'(f)} \underbrace{\sum_{\substack{a_i', \ i \in I\\\prod_{i \in I}a_i' \text{ squarefree}}}d \left( f\prod_{i \in I} a_i'+h \right) w \left( \frac{f}{x} \prod_{i \in I}a _i' \right) v_j'(a_1',\ldots,a_{|I|}')}_{=: \Phi_j'(f)}\\
&= \sum_j \sum_f \delta_j'(f) \Phi_j'(f),
\end{align*}
and let $\Psi_{j}' := \sum_f \delta_j'(f) \Phi_j'(f)$. Set $A'=\prod_{i \notin I}A_i\asymp x/\prod_{i \in I} A_i=x/A$. Let $C_j=2^j$ and $\widetilde{A}_j=\prod_{i \in I}\widetilde{A}_{j,i}$. Observe $C_j^2\widetilde{A}_j \asymp A$ and $\widetilde{A}_j \ll A$. The main term of $\Phi_j'(f)$ is $\Phi_{j0}'(f)$, where
\[
\Phi_{j0}'(f)=\frac{1}{f} \sum_{\substack{a_2,\ldots,a_{|I|}\\ \prod_{i=2}^{|I|} a_i \text{ squarefree}}} \int \Delta_\delta(\xi+h) w \left( \frac{\xi-h}{x} \right) v_1 \left( \frac{\xi-h}{f} \right) \prod_{i=2}^{|I|} v_i(a_i) \sum_{d \mid a_2 \cdots a_{|I|}f} \frac{\mu(d)^2c_d(h)}{d^{1+\delta}} \d \xi,
\]
and
$\Delta_\delta(\xi)$ is the operator defined by
\[
\Delta_\delta(\xi)=\left( \log \xi + 2 \gamma + 2 \frac{\partial}{\partial \delta} \right) \Bigr|_{\delta=0}.
\]
We insert $\Phi_{j}'(f)$ manually by
\[
\Psi_{j}'=\sum_f \delta_j'(f) \Phi_{j0}'(f)-\sum_f \delta_j'(f)(\Phi_{j0}'(f)-\Phi_j'(f)),
\]
and the first term on the right hand side equals the main term $M_{v_1}$, and let the rest be $R_{j}'$. We use Cauchy-Schwarz to get
\[
R_{j}' \leq \left( \sum_{f \asymp A'C_j^2} |\delta_j'(f)|^2 \right)^{1/2} \left( \sum_f |\Phi_{j0}'(f)-\Phi_j'(f)|^2 \right)^{1/2}.
\]
The first term can be estimated trivially by
\[
\sum_{f \asymp A'C_j^2} |\delta_j'(f)|^2 \ll x^\e A'C_j^2 \ll \frac{x^{1+\e}}{\widetilde{A}_j},
\]
and for the other factor we expand the square and write
\[
\sum_f |\Phi_{j0}'(f)-\Phi_j'(f)|^2=\Sigma_1'-2\Sigma_2'+\Sigma_3',
\]
where
\[
\Sigma_1'=\sum_f \Phi_{j0}'(f)^2, \quad \Sigma_2'=\sum_f \Phi_{j0}'(f) \Phi_j'(f), \quad \Sigma_3'=\sum_f \Phi_j'(f)^2.
\]
We will show
\begin{align}
\Sigma_1'&=M_0'+O(x^\e \widetilde{A}_j^2) \label{sum1},\\
\Sigma_2'&=M_0'+O \left( x^{1+\e}+x^{\frac{1}{3}+\e}\widetilde{A}_j^2 \right) \label{sum2},\\
\Sigma_3' &= M_0'+ O \left( x^{1+\e}+\widetilde{A}_j^{\frac{5}{2}} x^{\frac{1}{2}+\e} \left( |h|^\theta \widetilde{A}_j^\theta+\frac{x^\theta}{\widetilde{A}_j^\theta} \right) \right), \label{sum3}
\end{align}
where $M_0'$ is the squarefree analog of the quantity $M_0$ defined in \citet[(5.6)]{topacogullari2018shifted}, from which (\ref{rem3}) follows. To prove (\ref{sum1}) and (\ref{sum2}), recall the quantity $\Phi_0$ in \citet{topacogullari2018shifted}, and note the quantities $\Phi_{j0}'$ and $\Phi_0$ are analogous. Therefore,
the same argument that handles $\Sigma_1$ and $\Sigma_2$ in \citet{topacogullari2018shifted} also proves (\ref{sum1}) and (\ref{sum2}). To prove (\ref{sum3}), we write
\[
\Sigma_3'= \sum_{\substack{a_i,a_i', \, i \in I\\ \prod_{i \in I} a_i \text{ squarefree}\\\prod_{i \in I}a_i' \text{ squarefree}}} \prod_{i \in I} v_i(a_i) v_i(a_i') \Sigma_{3a}(a_1 \cdots a_{|I|},a_1' \cdots a_{|I|}'),
\]
where
\[
\Sigma_{3a}(r_1,r_2)=\sum_b w \left( \frac{r_1b}{x} \right) w \left( \frac{r_2b}{x} \right) d(r_1b+h)d(r_2b+h).
\]
For $a_1 \cdots a_{|I|} \neq a_1' \cdots a_{|I|}'$, this corresponds to the sum considered in Theorem \ref{thm:certaindivisor}. In \citet{topacogullari2018shifted}, the proof instead relied on Theorem 1.1 of \citet{topacogullari2015certain}. Since the main term in Theorem \ref{thm:certaindivisor} is also quadratic in $\log x$, our main term coincides with theirs. Consequently, the proof of the main term in (\ref{sum3}) is already established in \citet{topacogullari2018shifted}, and we only need to handle the error term, which we denote by $R_3$. First, we split
\[
R_3 \ll \sum_{r \asymp A} d_{|I|}(r)^2 |\Sigma_{3a} (r,r)|+\sum_{\substack{a_i,a_i' \asymp A_i \, \forall i \in I,\\ \prod a_i \neq \prod a_i',\\
\prod a_i,\prod a_i' \text{ squarefree}}} |R_{3a}(a_1 \cdots a_{|I|},a_1 \cdots a_{|I|}')|,
\]
where $R_{3a}$ is the error term estimating $\Sigma_{3a}$ using Theorem \ref{thm:certaindivisor}. Trivially, the first sum is $\ll x^{1+\e}$. For the second sum, since everything in the summand is non-negative, first write
\[
\sum_{\substack{a_i,a_i' \asymp A_i, \, i \in I\\ a_1 \cdots a_{|I|} \neq a_1' \cdots a_{|I|}'\\ \prod a_i,\prod a_i' \text{ squarefree}}} (\cdots) \ll \sum_{\substack{r_1,r_2 \asymp A\\r_1,r_2 \text{ squarefree}}} d_{|I|}(r_1)d_{|I|}(r_2) (\cdots).
\]
Since the divisor functions contribute at most $A^\e \ll x^\e$, we ignore them. We write $r_1=r_0c_1$ and $r_2=r_0c_2$. Therefore,
\begin{align*}
&\sum_{\substack{r_1,r_2 \asymp A\\ r_1,r_2 \text{ squarefree}}} x^{\frac12+O(\eta)} r_0 r_2^{\frac12+\e}\gcd \left( \widetilde{r}_2-\widetilde{r}_1,r_0^\infty \right)^{\frac12}\left( \frac{|h|^\theta |r_2-r_1|^\theta}{r_0^\theta}+\frac{x^\theta}{r_1^\theta} \right)\\
&\ll \sum_{r_0 \ll A} \sum_{c_1,c_2 \asymp A/r_0} x^{\frac12+O(\eta)}r_0^{\frac32+\e}c_2^{\frac12+\e} \gcd(c_2-c_1,r_0^\infty)^{\frac12} \left( \frac{|h|^\theta A^\theta}{r_0^\theta}+\frac{x^\theta}{r_0^\theta c_1^\theta} \right)\\
&\ll \sum_{r_0 \ll A} \sum_{\substack{d \mid r_0^\infty\\ d \leq A}} \sum_{\substack{c_1,c_2 \asymp A/r_0\\ c_1 \equiv c_2 \Mod{d}}} x^{\frac12+O(\eta)}r_0^{\frac32+\e}c_2^{\frac12+\e}d^{\frac12} \left( \frac{|h|^\theta A^\theta}{r_0^\theta}+\frac{x^\theta}{r_0^\theta c_1^\theta} \right)\\
&\ll \sum_{r_0 \ll A} \sum_{\substack{d \mid r_0^\infty\\ d \leq A}} \sum_{c_2 \asymp A/r_0} x^{\frac12+O(\eta)} r_0^{\frac12+\e}c_2^{\frac12+\e}Ad^{-\frac12} \left( \frac{|h|^\theta A^\theta}{r_0^\theta}+\frac{x^\theta}{A^\theta} \right)\\
&\ll \sum_{r_0 \ll A} \sum_{\substack{d \mid r_0^\infty\\ d \leq A}} x^{\frac12+O(\eta)}r_0^{-1+2\e}A^{\frac52+\e} d^{-\frac12} \left( \frac{|h|^\theta A^\theta}{r_0^\theta}+\frac{x^\theta}{A^\theta} \right).
\end{align*}
Using $d(r_0)=2^{\omega(r_0)}$, the inner sum is bounded by
\begin{align*}
\sum_{\substack{d \mid r_0^\infty\\ d \leq A}} d^{-\frac12}
&\leq \prod_{p \mid r_0} \left( 1+p^{-\frac12}+p^{-1}+\cdots \right)
\leq \prod_{p \mid r_0} \left(1-p^{-\frac12}\right)^{-1}
\leq d(r_0)^{-\log_2 (1-2^{-1/2})},
\end{align*}
which is $\ll x^\e$ by the divisor bound. Therefore, the sum we are interested in is bounded by
\begin{align*}
&\ll A^{\frac52+\e} x^{\frac12+O(\eta)} \left(|h|^\theta A^\theta+\frac{x^\theta}{A^\theta} \right) \sum_{r_0 \ll A} r_0^{-1+2\e}\\
&\ll A^{\frac52+3\e} x^{\frac12+O(\eta)} \left(|h|^\theta A^\theta+\frac{x^\theta}{A^\theta} \right)
\end{align*}
This gives the required error term since $A \ll x$, and thus proving (\ref{rem3}).
\end{proof}
To use Lemma \ref{lem:remainderbound}, we prove that any factorisation into $A_1,\ldots,A_k$ can be partitioned into three admissible cases.
\begin{lem} \label{lem:partition}
Suppose $\alpha_1,\ldots,\alpha_k \in [0,1]$ satisfies $\alpha_1+\cdots+\alpha_k=1$ and $\alpha_1 \geq \alpha_2 \geq \cdots \geq \alpha_k$. Then, for any $\delta \leq \frac{1}{16}$, at least one of the following holds:
\begin{enumerate}[(A).]
\item $\alpha_1 \geq \frac13+\frac23 \delta$.
\item $\alpha_1+\alpha_2 \geq \frac12+\delta$.
\item There exists an non-empty index set $I \subseteq \{1,2,\ldots,k\}$ such that $2 \delta \leq \sum_{i \in I} \alpha_i \leq \frac13-\frac43 \delta$.
\end{enumerate}
\end{lem}
\begin{proof}
Suppose (A) and (C) do not hold. Then, $\alpha_1<\frac13+\frac23 \delta$ and
\[
\alpha_1+\alpha_2>\frac13-\frac43 \delta \quad \text{ or } \quad \alpha_1+\alpha_2<2 \delta.
\]
If $\alpha_1+\alpha_2<2\delta$, then $\alpha_1<2\delta$, and so $\alpha_i<2 \delta$ for all $i=1,2,\ldots,k$. Since $\delta<\frac{1}{16}$, we have $\left( \frac13-\frac43 \delta \right)-2\delta>2\delta.$ Since $\alpha_1+\cdots+\alpha_k=1>\frac13-\frac43 \delta$, we get a contradiction since there exists $1 \leq J \leq k$ such that $$2 \delta \leq \sum_{1 \leq j \leq J} \alpha_j \leq \frac13-\frac43 \delta.$$
Therefore $\alpha_1+\alpha_2>\frac13-\frac43 \delta$. Note also $\alpha_2$ does not satisfy (C). If $\alpha_2<2 \delta$, then $\alpha_3,\ldots,\alpha_k<2 \delta$. Since
$
\alpha_2+\cdots+\alpha_k=1-\alpha_1>\frac23-\frac23 \delta>\frac13-\frac43 \delta
$
and $(\frac13-\frac43 \delta)-2 \delta>2 \delta$, again we have a contradiction since there exists $2 \leq J \leq k$ such that
\[
2 \delta \leq \sum_{2 \leq j \leq J} \alpha_j \leq \frac13-\frac43 \delta.
\]
Thus we must have $\alpha_2>\frac13-\frac43 \delta$, so $\alpha_1,\alpha_2>\frac13-\frac43 \delta$, so $\alpha_3+\cdots+\alpha_k<\frac13+\frac83 \delta$. If $\alpha_1 \leq \frac13-\frac13 \delta$ and $\alpha_2 \leq \frac13-\frac56 \delta$, then $\alpha_3 \leq \alpha_2$ implies $\alpha_1+\alpha_2+\alpha_3 \leq 1-2 \delta$, so $\alpha_4+\cdots+\alpha_k \geq 2\delta$. By failure of (C), we must have $\alpha_4+\cdots+\alpha_k>\frac13-\frac43 \delta$. But then this implies $\alpha_3<(\frac13+\frac83 \delta)-(\frac13-\frac43 \delta)=4\delta$, so $\alpha_3<2 \delta$ by failure of (C). Therefore, $\alpha_4,\ldots,\alpha_k<2 \delta$ but we get a contradiction as before since $\alpha_4+\cdots+\alpha_k>\frac13-\frac43 \delta.$ Thus we must have $\alpha_1>\frac13-\frac13 \delta$ or $\alpha_2>\frac13-\frac56 \delta$. We have two cases.
\begin{itemize}
\item Case 1: $\alpha_1>\frac13-\frac13 \delta$. Then, we are done since
\[
\alpha_1+\alpha_2>\left( \frac13-\frac13 \delta \right)+ \left(\frac13-\frac43 \delta \right)=\frac23-\frac53 \delta \geq \frac12+\delta
\]
for $\delta \geq \frac{1}{16}$.
\item Case 2: $\alpha_2>\frac13-\frac56 \delta$. Then, $\alpha_1 \geq \alpha_2$, so we are done since
\[
\alpha_1+\alpha_2>2 \left( \frac13-\frac56 \delta \right)=\frac23-\frac53 \delta \geq \frac12+\delta
\]
for $\delta \geq \frac{1}{16}$.
\end{itemize}
Therefore, at least one of (A), (B) or (C) must hold, and we are done.
\end{proof}
\begin{proof}[Proof of Theorem \ref{thm:generaliseddivisor}]
We first treat the main term. Here, our method diverges from \citet{topacogullari2018shifted} since their argument is not sufficient for large $k$. Let $v:(0,\infty) \to [0,\infty)$ be a smooth function compactly supported on $[1,2]$, such that
\[
\sum_{j \in \mathbb{Z}} v \left( \frac{2^ju}{x^{\frac1k}} \right)=1
\]
for any $x \in \mathbb{R}^+$, and let $v_j(u) := v(2^ju/x^\frac1k)$. Since there must exist at least one $a_i$ with $a_i \leq x^{\frac1k}$, using Lemma \ref{lem:remainderbound} without loss of generality it suffices to compute
\begin{align*}
\sum_{j \in \mathbb{N}} \int &w \left( \frac{u}{x} \right) \sum_{\substack{a_2,\ldots,a_k\\ d \mid a_2 \cdots a_k}} \frac{1}{a_2 \cdots a_k} v_j \left( \frac{u}{a_2 \cdots a_k} \right) \lambda_{h,d}(u+h) \d u,
\end{align*}
Let $g,g':\mathbb{N}^2 \to \mathbb{R}$ be the functions
\[
g(m,h) := \sum_{d \mid m} \frac{c_d(h)}{d}, \quad g'(m,h) := \sum_{d \mid m} \frac{c_d(h)\log d}{d},
\]
and it suffices to estimate $\sum_j (Q_{1,j}-2\gamma Q_{2,j}-2Q_{3,j})$, where
\begin{align*}
Q_{1,j} &:=\int v_j(u) \sum_m d_{k-1}(m) g(m,h) w \left( \frac{um}{x} \right) \log(um+h) \d u,\\
Q_{2,j} &:= \int v_j(u) \sum_m d_{k-1}(m)g(m,h)w \left( \frac{um}{x} \right) \d u,\\
Q_{3,j} &:= \int v_j(u) \sum_m d_{k-1}(m)g'(m,h) w \left( \frac{um}{x} \right) \d u.
\end{align*}
We treat $Q_{1,j}$ first. Let $W:(0,\infty) \to \mathbb{R}$ be given by
\[
W(\xi) := w \left( \frac{\xi}{x} \right) \log(\xi+h),
\]
and note $W$ is a smooth and compactly supported function, with Mellin transform
\[
\widetilde{W}(s)=\int_{\mathbb{R}}w \left( \frac{\xi}{x} \right) \log(\xi+h) \xi^{s-1} \d \xi.
\]
We mention that it is important for the weight function $w$ to be smooth, since we require the Mellin transform to decay rapidly. By Mellin inversion, for any $\sigma>1$ we have
\begin{align*}
Q_{1,j} &=\frac{1}{2 \pi i}\int v_j(u) \int_{\sigma-i\infty}^{\sigma+i\infty} \widetilde{W}(s)\sum_m \frac{d_{k-1}(m) g(m,h)}{u^sm^s} \d s \d u\\
&=: \frac{1}{2 \pi i}\int v_j(u) \int_{\sigma-i\infty}^{\sigma+i\infty} u^{-s} \widetilde{W}(s) D_h(s) \d s \d u.
\end{align*}
Now, the main term of $Q_{1,j}$ will be the residue of $D_h(s)$ at $s=1$, so we wish to use the residue theorem to move the line of integration. We investigate the poles of $D_h(s)$ by expanding into Euler products. First, from \citet{schwarz1994arithmetical}, $g$ is multiplicative and for all $\alpha \geq 1$ we have
\[
g(p^\alpha,h)=\sum_{0 \leq k \leq \alpha} \frac{c_{p^k}(h)}{p^k}.
\]
If $(p,h)=1$, then
\[
c_{p^k}(h) = \begin{cases}
1, &\quad \text{ for }k=0,\\
-1, &\quad \text{ for }k=1,\\
0, &\quad \text{ for }k \geq 2,
\end{cases}
\]
therefore in this case $g(p^\alpha,h)=1-\frac1p$, and $g(1,h)=1$. If $p \mid h$, then
\[
c_{p^k}(h)=\mu \left( \frac{p^k}{(p^k,h)} \right) \frac{\varphi(p^k)}{\varphi \left( \frac{p^k}{(p^k,h)} \right)}.
\]
Therefore, for $\operatorname{Re}(s)>1$ we have
\begin{align*}
D_h(s) &= \sum_m \frac{d_{k-1}(m) g(m,h)}{m^s}\\
&= \prod_p \sum_{\alpha \geq0} \frac{d_{k-1}(p^\alpha)g(p^\alpha,h)}{p^{\alpha s}}\\
&= \prod_{p \nmid h} \left( 1+\left( 1-\frac1p \right)\sum_{\alpha \geq 1} \frac{d_{k-1}(p^\alpha)}{p^{\alpha s}} \right) \underbrace{\prod_{p \mid h} \sum_{\alpha \geq0} \frac{d_{k-1}(p^\alpha)g(p^\alpha,h)}{p^{\alpha s}}}_{=: E_h(s)}\\
&= E_h(s) \prod_{p \nmid h} \left( \frac1p+\left( 1-\frac{1}{p^s} \right)^{-(k-1)} \left( 1-\frac1p \right) \right).
\end{align*}
Here $E_h(s)$ is a finite product of non-vanishing holomorphic functions, so we focus mainly on the infinite product. Now observe
\begin{align*}
P_h(s) := \zeta(s)^{-(k-1)}D_h(s) &= E_h(s) \prod_{p \mid h} \left( 1-\frac{1}{p^s} \right)^{k-1}\prod_{p \nmid h} \left( \frac1p\left(1-\frac{1}{p^s} \right)^{k-1}+1-\frac1p \right)\\
&= E_h(s) \prod_{p \mid h} \left( 1-\frac{1}{p^s} \right)^{k-1} \prod_{p \nmid h} \left( 1-\frac{k-1}{p^{s+1}}+O(p^{-2s-1}) \right).
\end{align*}
Note $P_h(s)$ is holomorphic for $\operatorname{Re}(s)>1/2$, and so $D_h(s)$ has a pole of order $k-1$ at $s=1$. Using the residue theorem, for $\sigma'=\frac12+\e$ we have
\[
Q_{1,j}=\int v_j(u) \operatorname{Res}_{s=1} u^{-s}\widetilde{W}(s)D_h(s) \d u+\frac{1}{2 \pi i} \int v_j(u) \int_{\sigma'-i\infty}^{\sigma'+i\infty} u^{-s} \widetilde{W}(s) D_h(s) \d s \d u.
\]
Note
\[
u^{-s} \widetilde{W}(s)D_h(s)=\int_\mathbb{R} \frac1\xi w\left( \frac{\xi}{x} \right) \log(\xi+h) \left[ \left( \frac{\xi}{u} \right)^sD_h(s) \right] \d u,
\]
and observe
\[
\operatorname{Res}_{s=1} \left( \frac{\xi}{u} \right)^sD_h(s)=\frac{\xi}{u} P_{k-2}(\log \xi,\log u),
\]
where $P_{k-1}(X,Y)$ is a polynomial of degree $k-1$. Thus the main term of $Q_{1,j}$ is
\[
\int_\mathbb{R} w \left( \frac{\xi}{x} \right) \log(\xi+h) \int \frac{v_j(u)}{u}P_{k-2}(\log \xi,\log u) \d u \d \xi.
\]
If we sum over $j$ and bring the summation inside, we get the desired main term
\[
\int_\mathbb{R} w \left( \frac{\xi}{x} \right) P_k(\log x,\log \xi,\log(\xi+h)) \d \xi.
\]
It remains to bound the error term. Using decay estimates for $\widetilde{W}(s)$ and $|\zeta(\sigma'+it)| \ll |t|^{\frac12+\e}$ for $t \ge 1$, we have
\[
\left|\sum_j Q_{1,j}-\int_\mathbb{R} w \left( \frac{\xi}{x} \right) P_k(\log x,\log \xi,\log(\xi+h)) \d \xi\right| \ll x^{\frac12+\frac{1}{2k}+\e}.
\]
A very similar argument applies to $Q_{2,j}$ and $Q_{3,j}$. We omit the argument for $Q_{2,j}$, but we mention key modifications in the argument for $Q_{3,j}$ since $g'(\cdot,h)$ is not multiplicative. For $\beta \in \mathbb{R}$, let
\[
g_\beta(m,h) := \sum_{d \mid m} \frac{c_d(h)}{d^\beta},
\]
Then,
\[
g'(m,h)=-\frac{\partial}{\partial \beta} g_\beta(m,h) \Biggr|_{\beta=1},
\]
and so for $\operatorname{Re}(s)>1$, we have
\[
\widetilde{D}_h(s) := \sum_m \frac{d_{k-1}(m)g'(m,h)}{m^s} = -\frac{\partial}{\partial \beta} \left( \sum_m \frac{d_{k-1}(m)g_\beta(m,h)}{m^s} \right) \Biggr|_{\beta=1},
\]
and let $D_{h,\beta}(s)$ be the inner sum. As before, we analyse the poles of $D_{h,\beta}(s)$. Analogous to $g$, it can be shown that $g_\beta(\cdot,h)$ is multiplicative with analogous properties as $g$, in particular
\[
g_\beta(1,h)=1, \quad g_\beta(p^\alpha,h)=1-\frac{1}{p^\beta}
\]
for $\alpha \geq 1$ and $p \nmid h$. Therefore, as before we have
\[
D_{h,\beta}(s)=E_{h,\beta}(s) \prod_{p \nmid h} \left( \frac1{p^\beta}+\left( 1-\frac{1}{p^s} \right)^{-(k-1)} \left( 1-\frac{1}{p^\beta} \right) \right),
\]
where $E_{h,\beta}(s)$ is a finite product of non-vanishing holomorphic functions. Taking the logarithmic derivative, we have
\[
\frac{1}{D_{h,\beta}(s)}\frac{\partial}{\partial \beta} D_{h,\beta}(s) \Biggr|_{\beta=1}=\frac{1}{E_{h,\beta}(s)}\frac{\partial}{\partial \beta} E_{h,\beta}(s)\Biggr|_{\beta=1}-\sum_{p \nmid h}\frac{\log p}{p} \cdot \frac{1-\left( 1-\frac{1}{p^s} \right)^{-(k-1)}}{\frac1p+\left( 1-\frac{1}{p^s} \right)^{-(k-1)} \left(1-\frac1p \right)}
\]
The right hand side is analytic for $\operatorname{Re}(s)>\frac12$, so $\widetilde{D}_h(s)$ has an order $k-1$ pole at $s=1$. The rest of the argument follows analogously to above, contributing a degree $k-1$ polynomial. Combining all contributions from $Q_{1,j},Q_{2,j},Q_{3,j}$, we proved the main term is
\[
xP_{k,h,w}(\log x)+O_{w,\e,k}(x^{\frac12+\frac{1}{2k}+\e}).
\]
To treat the required error term from Lemma \ref{lem:remainderbound}, the idea is to dyadically split the sum over $a_1 \cdots a_k \asymp x$ to a sum over $a_i \asymp A_i$ with $A_1 \cdots A_k \asymp X$, and we use the partition in Lemma \ref{lem:partition} along with (\ref{rem1}), (\ref{rem2}), and (\ref{rem3}). We set $A_1 \geq A_2 \geq \cdots \geq A_k$, and let
\[
X_1=x^{\frac13+\frac23 \delta}, \quad X_2=x^{\frac12+\delta}, \quad X_3=x^{\frac13-\frac43 \delta}, \quad X_4=x^{2 \delta}.
\]
If $A_1 \gg X_1$, then use (\ref{rem1}) to get
\[
R_{v_1} \ll x^{1-\delta+\e}.
\]
If $A_1A_2 \gg X_2$, then use (\ref{rem2}) to get
\[
R_{v_1} \ll x^{1-\delta+\e}\left( 1+x^{2 \theta \delta} \right)\left(1+1 \right) \left( 1+\frac{|h|^{\frac{1}{4}}}{x^{\frac14-\frac12 \delta}} \right) \ll x^{1-\delta+2 \delta \theta+\e}\left( 1+\frac{|h|^{\frac{1}{4}}}{x^{\frac14-\frac12 \delta}} \right).
\]
Otherwise, there is an non-empty index set $I \subseteq \{1,2,\ldots,k\}$ such that $X_4 \ll \prod_{i \in I} A_i \ll X_3$. For convenience let $A=\prod_{i \in I} A_i$, so using (\ref{rem3}), we get
\begin{align*}
R_{v_1} &\ll \frac{x^{1+\e}}{X_4^{\frac12}}+X_3^{\frac34} x^{\frac34+\e}\left( |h|^{\frac{\theta}{2}}X_3^{\frac{\theta}{2}}+\frac{x^{\frac{\theta}{2}}}{X_3^{\frac{\theta}{2}}} \right)\\
&=x^{1-\delta+\e}+x^{1-\delta+\e}(|h|^{\frac{\theta}{2}} x^{\frac{\theta}{6}-\frac{2\delta}{3} \theta}+x^{\frac{\theta}{3}+\frac{2\delta}{3} \theta})\\
&\ll x^{1-\delta+\frac{\theta}{3}+\frac{2\delta}{3}\theta+\e} \left(1+\frac{|h|^{\frac{\theta}{2}}}{x^{\frac{\theta}{6}+\frac{4 \delta}{3} \theta}}\right).
\end{align*}
Combining the above bounds, we are done.
\end{proof}
\begin{cor} \label{cor:generaliseddivisor}
Let $w:[1/2,1] \to [0,\infty)$ be a smooth and compactly supported function and $x \in \mathbb{R}^+$. Then for $0 \leq \delta \leq \frac{1}{16}$ we have the following estimates for different ranges of $h \in \mathbb{N}$.
\begin{enumerate}[(a)]
\item For $|h| \leq x^{\frac13+\frac{8 \delta}{3} \theta}$, we have
\[
\sum_n w \left( \frac{n}{x} \right) d_k(n) d(n \pm h)=xP_{k,h,w}(\log x)+O_{k,w,\delta,\e}(x^{1-\delta+\frac{1+2\delta}{3} \theta+\e}).
\]
\item For $x^{\frac13+\frac{8 \delta}{3} \theta} \leq |h| \leq x^{\frac{1-2\delta+\frac{2(1-16\delta)}{3} \theta}{1-2\theta}}$, we have
\[
\sum_n w \left( \frac{n}{x} \right) d_k(n) d(n \pm h)=xP_{k,h,w}(\log x)+O_{k,w,\delta,\e}(|h|^{\frac{\theta}{2}}x^{1-\delta+\frac{1-4\delta}{6} \theta+\e}).
\]
\item For $x^{\frac{1-2\delta+\frac{2(1-16\delta)}{3} \theta}{1-2\theta}} \leq |h| \ll x^{1-\e}$, we have
\[
\sum_n w \left( \frac{n}{x} \right) d_k(n) d(n \pm h)=xP_{k,h,w}(\log x)+O_{k,w,\delta,\e}(|h|^{\frac14}x^{\frac34-\frac{\delta}{2}+2\delta \theta+\e}).
\]
\end{enumerate}
\end{cor}
We can choose $\delta=1/16$ and $\theta \leq 7/64$ from \citet{kim2003functoriality}. If we have $\theta=0$ from the Ramanujan-Petersson conjecture, then all three ranges above can be used and are all non-trivial.
\begin{cor} \label{cor:generaliseddivisorsmall}
Let $w:[1/2,1] \to [0,\infty)$ be a smooth and compactly supported function and $x \in \mathbb{R}^+$. Then we have the following estimates for different ranges of $h \in \mathbb{N}$.
\begin{enumerate}[(a)]
\item For $|h| \leq x^{\frac{45}{128}}$, we have
\[
\sum_n w \left( \frac{n}{x} \right) d_k(n) d(n \pm h)=xP_{k,h,w}(\log x)+O_{k,w,\e}(x^{\frac{15}{16}+\frac{3}{8} \theta+\e}).
\]
\item For $x^{\frac{45}{128}} \leq |h| \leq x^{1-\e}$, we have
\[
\sum_n w \left( \frac{n}{x} \right) d_k(n) d(n + h)=xP_{k,h,w}(\log x)+O_{k,w,\e}(|h|^{\frac{\theta}{2}}x^{\frac{15}{16}+\frac{1}{8} \theta+\e}).
\]
\end{enumerate}
\end{cor}
Using $\theta \leq 7/64$ from \citet{kim2003functoriality}, the bound from (b) is only nontrivial when $|h| \leq x^{\frac{25}{28}-\e}$. Since $\frac{15}{19}<\frac{25}{28}$, Theorem \ref{thm:intromainthm} is an improvement to \citet[Theorem 1.2]{topacogullari2018shifted} when $k$ is large.
\setcounter{section}{1}
\setcounter{thm}{0}
\begin{thm}
Let $w:[1/2,1] \to [0,\infty)$ be smooth and compactly supported. Let $h$ be a non-zero integer such that $|h| \ll x^{\frac{25}{28}-\eta}$ for some $\eta>0$. Then,
\[
\sum_n w\left( \frac{n}{x} \right) d_k(n) d(n \pm h)=xP_{x,h,w}(\log x)+O_{k,w,\e}(x^{1-\frac{7}{128} \eta+\e}).
\]
\end{thm}
\setcounter{section}{6}
\vfill
\setcitestyle{numbers}
\bibliographystyle{apalike}
\bibliography{bibliography.bib}
\end{document}
\begin{thebibliography}{}
\bibitem[Drappeau, 2017]{drappeau2017sums}
Drappeau, S. (2017).
\newblock Sums of kloosterman sums in arithmetic progressions, and the error term in the dispersion method.
\newblock {\em Proceedings of the London Mathematical Society}, 114(4):684--732.
\bibitem[Grimmelt and Merikoski, 2024]{grimmelt2024twisted}
Grimmelt, L. and Merikoski, J. (2024).
\newblock Twisted correlations of the divisor function via discrete averages of $\operatorname{SL}_2 (\mathbb{R})$ poincar\'{e} series.
\newblock {\em arXiv preprint arXiv:2404.08502}.
\bibitem[Kim and Sarnak, 2003]{kim2003functoriality}
Kim, H. and Sarnak, P. (2003).
\newblock Functoriality for the exterior square of $gl_4$ and the symmetric fourth of $gl_2$.
\newblock {\em Journal of the American Mathematical Society}, 16(1):139--183.
\bibitem[Linnik and Schuur, 1963]{linnik1963dispersion}
Linnik, I. and Schuur, S. (1963).
\newblock The dispersion method in binary additive problems.
\newblock {\em American Mathematical Society, Providence, R.I., 1963}.
\bibitem[Motohashi, 1980]{motohashi1980asymptotic}
Motohashi, Y. (1980).
\newblock An asymptotic series for an additive divisor problem.
\newblock {\em Mathematische Zeitschrift}, 170(1):43--63.
\bibitem[Motohashi, 1994]{motohashi1994binary}
Motohashi, Y. (1994).
\newblock The binary additive divisor problem.
\newblock In {\em Annales scientifiques de l'Ecole normale sup{\'e}rieure}, volume~27, pages 529--572.
\bibitem[Schwarz and Spilker, 1994]{schwarz1994arithmetical}
Schwarz, W. and Spilker, J. (1994).
\newblock {\em Arithmetical functions}, volume 184.
\newblock Cambridge University Press.
\bibitem[Topacogullari, 2015]{topacogullari2015certain}
Topacogullari, B. (2015).
\newblock On a certain additive divisor problem.
\newblock {\em Acta Arithmetica}, 181(2).
\bibitem[Topacogullari, 2016]{topacogullari2016shifted}
Topacogullari, B. (2016).
\newblock The shifted convolution of divisor functions.
\newblock {\em The Quarterly Journal of Mathematics}, 67(2):331--363.
\bibitem[Topacogullari, 2018]{topacogullari2018shifted}
Topacogullari, B. (2018).
\newblock The shifted convolution of generalized divisor functions.
\newblock {\em International Mathematics Research Notices}, 2018(24):7681--7724.
\end{thebibliography}