Solution (source code)

= Solution

An ideal $\pi$ pulse is $-i\sigma_\phi$. Since $\sigma_\phi\sigma_{2\phi}\sigma_\phi=\sigma_x$, the chronological three-pulse sequence has propagator
$$
\boxed{R_\phi(\pi)R_{2\phi}(\pi)R_\phi(\pi)=i\sigma_x.}
$$
It implements the <Pauli X gate> up to <global phase>, for every $\phi$.

For this <three-pulse amplitude-error compensation>, the leading error in the supplied fidelity expansion vanishes when $1+2\cos\phi=0$, giving
$$
\boxed{\phi=\frac{2\pi}{3}\quad\text{or}\quad\frac{4\pi}{3}\pmod{2\pi}.}
$$
These choices minimize the leading small-angle-error infidelity. Substituting $\cos\phi=\cos2\phi=-1/2$ into the fourth-order term gives
$$
\boxed{\mathcal F_3=1-\frac{3\pi^4}{128}\epsilon^4+O(\epsilon^6).}
$$
The fourth-order coefficient is nonzero, so this three-pulse sequence improves the single pulse's quadratic infidelity to quartic infidelity, rather than sixth-order infidelity.

An exact check is available. With $x=\pi\epsilon/2$, multiplication of the three imperfect <rotation gates> at either optimum gives
$$
\boxed{\mathcal F_3=\left|\cos x\left(1+\frac12\sin^2x\right)\right|.}
$$
Its <Taylor expansion> has precisely the fourth-order coefficient above. The improvement concerns the same systematic fractional angle error on all three pulses; other errors need not cancel.