Where does the last term come from in the two-lens formula: $\frac{1}{f}=\frac{1}{f_1} +\frac{1}{f_2} -\frac{d}{f_1f_2}$? I can derive the formula for lenses in contact: i.e, $$\frac{1}{f}=\frac{1}{f_1} +\frac{1}{f_2}.\tag{1}$$
But for two lenses separated by a distance $d$ I can't seem to get:
$$\frac{1}{f}=\frac{1}{f_1} +\frac{1}{f_2} -\frac{d}{f_1f_2}.\tag{2}$$
For the first derivation I let the image distance for the first lens $v_1$ equal the negative object distance for the second lens. ie. $v_1=-u_2$
When trying to derive the second formula I let: $u_2=d-v_1$ , and then followed the same procedure. I ended up with a very tedious algebraic expression. Did I go wrong with $u_2=d-v_1$? How do you derive the second formula?
 A: I can't resist to show how this is done using ray transfer matrices. There are two key parameter at any point along a light ray: the distance $x$ of the point from the optical axis, and the angle $\theta$ of the ray with the horizontal. Then any optical component of the system can be represented as a $2\times 2$ matrix which transform the pair $(x,\theta)$ for the incoming ray into the pair $(x',\theta')$ for the outgoing ray:
$$\begin{pmatrix}x'\\\theta'\end{pmatrix}=\begin{pmatrix}\times&\times\\\times&\times\end{pmatrix}\begin{pmatrix}x\\\theta\end{pmatrix}.$$
By using what you know, you can easily write down that 


*

*a thin lens has a matrix
$$L=\begin{pmatrix}1&0\\-\dfrac{1}{f}&1\end{pmatrix}$$ 
where $f$ is the focal distance;

*a thickness $d$ of empty space has a matrix
$$S=\begin{pmatrix}1 & d\\0&1\end{pmatrix}.$$


Onto your problem: we have a lens of focal $f_1$ (matrix $L_1$), empty space and another lens of focal $f_2$ (matrix $L_2$), so the matrix for the whole system is simply the product of the matrices, in reverse order
$$M=L_2\ S\ L_1
=\begin{pmatrix}1&0\\-\dfrac{1}{f_2}&1\end{pmatrix}
\begin{pmatrix}1 & d\\0&1\end{pmatrix}
\begin{pmatrix}1&0\\-\dfrac{1}{f_1}&1\end{pmatrix}
=\begin{pmatrix}1-\dfrac{d}{f_1}&d\\-\left(\dfrac{1}{f_1}+\dfrac{1}{f_2}-\dfrac{d}{f_1f_2}\right)&1-\dfrac{d}{f_2}\end{pmatrix}$$
and you can read the focal distance in the bottom left corner! As you see, 99% of my exposition is just explaining the method. The actual computation is that trivial, systematic, triple matrix product. No monkeying about with geometry all the time: you just need to do it once to deduce the matrices for common components. 
A: There is a way to derive that formula without using ray-transfer matrices, but instead using the lens equation. There is nothing wrong in the way you write $u_2$.
For the first ($f_1$) and second lens ($f_2$), separated by a distance $d$, it holds
$\Large \frac{1}{f_1}=\frac{1}{s_1}+\frac{1}{s_m} \tag{1}$
and
$\Large \frac{1}{f_2}=\frac{1}{d-s_m}+\frac{1}{s_2} \tag{2}$,
where $s_m$ is the position of the image from $s_1$ formed with respect to lens 1. The final image is formed at distance $s_2$ after the second lens.
The piece of information missing in this analysis is that you must leave some distance $d_f$ in front and $d_b$ behind the equivalent lens in order to make things work. The equation for the effective focal length is therefore
$\Large \frac{1}{d_f+s_1}+\frac{1}{d_b+s_2}=\frac{1}{f_e}$
or, rewriting:
$\Large \frac{1}{d_f+s_1}-\frac{1}{f_e}+\frac{1}{d_b+s_2} = 0 \tag{3}$
The calculation proceeds as follows:

*

*Write $s_2(s_m)$ as a function of $s_m$ using equation (2) and substitute it in equation (3)

*Write $s_m(s_1)$ as a function of $s_1$ using equation (1) and substitute it in equation (3). Now eq. (3) features only $s_1,d_b,d_f,f_e$.

*Write the resulting equation (3) as a fraction. Assuming the denominator is not $0$, we can solve for the numerator $= 0$. This numerator happens to be a quadratic equation in $s_1$ that is $ a_2 s_1^2 + a_1 s_1 + a_0 = 0$ for any value of $s_1$. A quadratic polynomial is always $0$ iff its three coefficients are $ a_2 = a_1 = a_0 = 0$.

*You need to solve for $f_e, d_f, d_b$ using the three equations given by $ a_2 = a_1 = a_0 = 0$. Now you realize why solving for only one parameter does not work, because the system would be over-constrained.

You will get the two-lens formula for $f=f_e$, the effective focal length, given in the OP.
