TITLE: Counterexample to the chain-rule
QUESTION [12 upvotes]: I made the following observation
Let $f(t):=\left(\begin{matrix} 0 &e^{it} \\ e^{-it} & 0 \end{matrix}\right),$ then $f(t)^2= \operatorname{id}$.
Thus, we have $\frac{d}{dt}f(t)^2= \frac{d}{dt}\operatorname{id}=0.$
On the other hand yields the chain-rule
$$\frac{d}{dt}f(t)^2= 2 f(t)f'(t)=0.$$
However, $f(t)$ and $f'(t)$ are both matrices with full-rank. So something is very wrong here, no? Can anybody explain to me what just happened?

REPLY [19 votes]: The chain rule obviously applies, and since answers/comments seem to imply that it is ill-defined, I think this answer may be useful.
The problem with your application of the chain rule is that the derivative of $X \mapsto X^2$ at a matrix $X_0$ is not $H \mapsto 2X_0H$, but instead $H \mapsto X_0H+HX_0$.*
This yields the derivative of your $g(t)=f(t)^2$ (identifying the linear map $g':\mathbb{R} \to M_n(2,2)$ with its value at $1$, as is usually done) as
$$f(t)\cdot f'(t)+f'(t) \cdot f(t)$$
by the chain rule, which you can see that makes the computation check out.
*This is a simple computation, given by 
$$(X_0+H)^2=X_0^2+X_0H+HX_0+H^ 2=X_0^2+(X_0H+HX_0)+o(H),$$ and noting that the term in parenthesis is linear on $H$.