Solution (source code)

= Solution

Let $D(d)=\begin{pmatrix}1&d\\0&1\end{pmatrix}$ be the drift <beam transfer matrix>. Start immediately before the first lens and end immediately before its counterpart in the next <FODO cell>. Matrices act on column vectors from right to left. With $A=1/f_1$ and $B=1/f_2$, where both focal lengths are signed in the chosen plane,
$$
\boxed{M=DQ(f_2)DQ(f_1)=
\begin{pmatrix}
1-2dA-dB+d^2AB&2d-d^2B\\
-A-B+dAB&1-dB
\end{pmatrix}.}
$$
The two drifts account for both gaps. Direct multiplication gives $\det M=1$ and
$$
\frac12\operatorname{tr}M=1-d(A+B)+\frac{d^2AB}{2}.
$$
For the equal-strength focusing-defocusing case, $f_1=f>0$ and $f_2=-f$:
$$
M=\begin{pmatrix}1-d/f-d^2/f^2&2d+d^2/f\\-d/f^2&1+d/f\end{pmatrix},
\qquad \operatorname{tr}M=2-\frac{d^2}{f^2}.
$$
Choosing a different start within the cell gives a conjugate matrix, with the same trace and eigenvalues. If $f_2$ is specified as a positive magnitude of a defocusing lens, its signed value in these formulas is $-f_2$.