Differentiating summations Consider the following equation 
$$
\sum_{m=0}^{M}b_m r^m \left(\frac {d^2}{dr^2}+\frac{2}{r}\frac d {dr}+2E\right)\Psi-2\sum_{k=0}^{K}a_k r^k \Psi=0 \tag{1}
$$
Now suppose 
$$
\Psi(r)=A \exp{[-S(r)]} \tag{2}
$$
where
$$
S(r)=\sum_{n=1}^N \lambda_n r^n \tag{3}
$$
and
$$
A=exp[-\lambda_0]
$$
If we substitute equation (2) in equation (1), How can we obtain the following equation?
$$
\sum_{m=0}^M b_m r^m \left[\sum_{i,j}i j\lambda_i \lambda_j r^{i+j-2}-\sum_j j(j+1) \lambda_j r^{j-2}+2E\right]-2\sum_{k=0}^K a_k r^k=0 \tag{4}
$$
and specially I can't understand how $i$ emerges?
 A: 
Comparison  of (1)  and  (4)  shows  it is sufficient to focus on the  calculation of
  \begin{align*}
\left(\frac {d^2}{dr^2}+\frac{2}{r}\frac d {dr}+2E\right)\Psi\tag{1a}
\end{align*}

From  (2) we  obtain
\begin{align*}
\frac{d}{dr}\Psi(r)&=\frac{d}{dr}\left(Ae^{-S(r)}\right)\\
&=Ae^{-S(r)}\left(-S^{\prime}(r)\right)\\
&=-S^{\prime}(r)\Psi(r)\\
\frac{d^2}{dr^2}\Psi(r)&=\frac{d}{dr}\left(-S^{\prime}(r)\Psi(r)\right)\\
&=-S^{\prime}(r)\Psi^{\prime}(r)-S^{\prime\prime}(r)\Psi(r)\\
&=\left(\left(S^{\prime}(r)\right)^2-S^{\prime\prime}(r)\right)\Psi(r)\tag{2a}
\end{align*}
From (3) we obtain
\begin{align*}
S(r)&=\sum_{j=1}^N\lambda_jr^j
\qquad S^{\prime}(r)=\sum_{j=1}^Nj\lambda_jr^{j-1}
\qquad S^{\prime\prime}(r)=\sum_{j=1}^Nj(j-1)\lambda_jr^{j-2}\tag{3a}\\
\left(S^{\prime}(r)\right)^2&=\left(\sum_{i=1}^Ni\lambda_i r^{i-1}\right)\left(\sum_{j=1}^Nj\lambda_j  r^{j-1}\right)
=\sum_{n=2}^{2N}\sum_{{i+j=n}\atop{i,j\geq   1}}ij\lambda_i   \lambda_jr^{i+j-2}\tag{4a}
\end{align*}

Putting (1a) - (4a) together we obtain
  \begin{align*}
&\color{blue}{\left(\frac {d^2}{dr^2}+\frac{2}{r}\frac d {dr}+2E\right)\Psi}\\
&\qquad=\left(\left(S^{\prime}(r)\right)^2-S^{\prime\prime}(r)-\frac{2}{r}S^{\prime}(r)+2E\right)\psi\\
&\qquad=\left(\sum_{n=2}^{2N}\sum_{{i+j=n}\atop{i,j\geq   1}}ij\lambda_i   \lambda_jr^{i+j-2}
-\sum_{j=1}^Nj(j-1)\lambda_jr^{j-2}
-2\sum_{j=1}^Nj\lambda_jr^{j-2}+2E\right)\Psi\\
&\qquad\,\,\color{blue}{=\left(\sum_{n=2}^{2N}\sum_{{i+j=n}\atop{i,j\geq   1}}ij\lambda_i   \lambda_jr^{i+j-2}-\sum_{j=1}^Nj(j+1)\lambda_jr^{j-2}+2E\right)\Psi}\tag{5a}\\
\end{align*}

We see the  index $i$  emerges from  the  square of the series in (4a).
