Solution (source code)

= Solution

Write the <curl> and <cross product> with the <Levi-Civita symbol>, then use its contraction identity:
$$
\begin{aligned}
[\nabla\times(A\times B)]_i
&=\epsilon_{ijk}\partial_j(\epsilon_{k\ell m}A_\ell B_m)\\
&=(\delta_{i\ell}\delta_{jm}-\delta_{im}\delta_{j\ell})\partial_j(A_\ell B_m)\\
&=\partial_j(A_iB_j-A_jB_i).
\end{aligned}
$$
Expanding with the <product rule> gives
$$
A_i\partial_jB_j+B_j\partial_jA_i-B_i\partial_jA_j-A_j\partial_jB_i.
$$
Recognize the <divergence> in the first and third terms, and the <directional derivatives> in the other two. The <curl of a cross product> identity is therefore
$$
\boxed{\nabla\times(A\times B)=A(\nabla\cdot B)+(B\cdot\nabla)A-B(\nabla\cdot A)-(A\cdot\nabla)B.}
$$
The derivatives act on both vector fields. No assumption of vanishing divergence or spatially constant fields has been made.