Solution (source code)

= Solution

Use the <Levi-Civita symbol> contraction $\epsilon_{ijk}\epsilon_{i\ell m}=\delta_{j\ell}\delta_{km}-\delta_{jm}\delta_{k\ell}$ in <suffix notation>:
$$
\begin{aligned}
(a\times b)\cdot(c\times d)
&=\epsilon_{ijk}a_jb_k\epsilon_{i\ell m}c_\ell d_m\\
&=(\delta_{j\ell}\delta_{km}-\delta_{jm}\delta_{k\ell})a_jb_kc_\ell d_m.
\end{aligned}
$$
Thus the <cross product> contraction expands as
$$
\boxed{(a\times b)\cdot(c\times d)=(a\cdot c)(b\cdot d)-(a\cdot d)(b\cdot c).}
$$