If we have square matrices $A$ and $B$ that commute (i.e. $AB=BA$), then we have $e^{A+B} = e^Ae^B$. In general this isn't true without the condition that $A$ and $B$ commute. I would like to know if this is "if and only if", or whether $A$ commuting with $B$ is just a necessary condition.
In other words, do there exist square matrices $A$ and $B$ such that $AB\ne BA$ but $e^{A+B} = e^A e^B$?
Not that it really matters because this question already got a very good answer, but I don't think this should be considered a duplicate of Does $e^{a+b}=e^{a}e^{b}$ implies that $ab=ba$ for banach algebras?, because that question is about Banach algebras whereas mine is only about ordinary finite-dimensional matrices.
Neither is it a duplicate of If $e^A$ and $e^B$ commute, do $A$ and $B$ commute for finite dimensional matrices? (of which Does $e^{a+b}=e^{a}e^{b}$ implies that $ab=ba$ for banach algebras? itself is closed as a duplicate), because that is clearly just a different question.
It is possible to represent quaternions by $2\times2$ complex matrices or $4\times4$ real matrices (Wikipedia).
For $A=2\pi(3\mathbf{i})$ and $B=2\pi(4\mathbf{j})$ we have $e^A=e^B=e^{A+B}=1$ because $(3,4,5)$ is a Pythagorean triple, even though $A$ and $B$ do not commute (indeed, they anticommute: $BA=-AB$).
This gives the explicit counterexample $$ A = 2\pi\begin{pmatrix} 0 & 3 & 0 & 0 \\ -3 & 0 & 0 & 0 \\ 0 & 0 & 0 & -3 \\ 0 & 0 & 3 & 0 \\ \end{pmatrix},\qquad B = 2\pi\begin{pmatrix} 0 & 0 & 4 & 0 \\ 0 & 0 & 0 & 4 \\ -4 & 0 & 0 & 0 \\ 0 & -4 & 0 & 0 \\ \end{pmatrix}. $$