TITLE: Interchanging summation involving divisors in index
QUESTION [6 upvotes]: I was reading Apostle's Analytic Number Theory book and I saw this formula being used in many cases. Why is this true?    
$$ \sum_{n=1}^{\infty} \sum_{d|n} f(d,n) = \sum_{d=1}^{\infty} \sum_{n=1}^{\infty} f(d,nd) $$ 
I don't see the intuition behind it.  
Also, will this hold for finite sums, i.e,   
$$ \sum_{n=1}^{m} \sum_{d|n} f(d,n) =^{?} \sum_{d=1}^{m} \sum_{n=1}^{m} f(d,nd) $$

REPLY [6 votes]: We obtain
  \begin{align*}
\color{blue}{\sum_{n=1}^\infty \sum_{d|n}f(d,n)}&=\sum_{n=1}^{\infty} \sum_{{d=1}\atop{d|n}}^n f(d,n)\tag{1}\\
&=\sum_{{1\leq d\leq n\leq \infty}\atop{d|n}}f(d,n)\tag{2}\\
&=\sum_{d=1}^\infty\sum_{{n=d}\atop{d|n}}^\infty f(d,n)\tag{3}\\
&=\sum_{d=1}^\infty \sum_{{n=d}\atop{dd^{\prime}=n}}^\infty f(d,dd^{\prime})\tag{4}\\
&=\sum_{d=1}^\infty\sum_{d^{\prime}=1}^\infty f(d,dd^{\prime})\tag{5}\\
&\,\,\color{blue}{=\sum_{d=1}^\infty\sum_{n=1}^\infty f(d,nd)}
\end{align*}
  and the claim follows.

Comment:

In (1) we write the index range of $d$ more explicitly.
In (2) we write the index range somewhat more conveniently.
In (3) we change the order of summation.
In (4) we introduce $d^\prime$ using the definition of the divisor $d$.
In (5) we sum over $d^\prime$ instead of $n$. We observe $d^\prime=1$ if $n=d$, $d^\prime=2$ if $n=2d$, etc.


Similarly we obtain
  \begin{align*}
\color{blue}{\sum_{n=1}^m \sum_{d|n}f(d,n)}&=\sum_{n=1}^{m} \sum_{{d=1}\atop{d|n}}^n f(d,n)\\
&=\sum_{{1\leq d\leq n\leq m}\atop{d|n}}f(d,n)\\
&=\sum_{d=1}^m\sum_{{n=d}\atop{d|n}}^m f(d,n)\\
&=\sum_{d=1}^m \sum_{{n=d}\atop{dd^{\prime}=n}}^m f(d,dd^{\prime})\\
&=\sum_{d=1}^m\sum_{d^{\prime}=1}^{\left\lfloor m/d\right\rfloor} f(d,dd^{\prime})\\
&\,\,\color{blue}{=\sum_{d=1}^m\sum_{n=1}^{\left\lfloor m/d\right\rfloor}  f(d,nd)}
\end{align*}