Derivative of trace squared and trace of a matrix squared? Going through the matrix cookbook and other resources I can't find an algebraic proof of the following, if $f:\mathbb{R}^{n\times n} \to \mathbb{R}$ and $F:\mathbb{R}^{n\times n} \to \mathbb{R}$ and $H\in\mathbb{R}^{n\times n}$such that
$$
f(A) :=\left( \text{tr}[A]^2 \right) \text{ and } F(A):= \left( \text{tr}[A^2]\right).
$$
It then asks to calculate $\partial_H f(A)$ and $\partial_H F(A)$ but I can't figure the algebra out and I'm stuck on both.
 A: Most of the calculation relies on linearity of trace.
For the first one,
\begin{align*}
(D_Hf)(A) &= \lim_{t \to 0} \frac{\operatorname{tr}[A + tH]^2 - \operatorname{tr}[A]^2}{t}\\
&= \lim_{t \to 0} \frac{\left(\operatorname{tr}[A] + \operatorname{tr}[tH]\right)^2 - \operatorname{tr}[A^2]}{t}\\
&= \lim_{t \to 0} \frac{\operatorname{tr}[A]^2 + 2 \operatorname{tr}[A]\operatorname{tr}[tH] + \operatorname{tr}[tH]^2 - \operatorname{tr}[A^2]}{t}\\
&= \lim_{t \to 0} \frac{2 t \operatorname{tr}[A]\operatorname{tr}[H] + t^2\operatorname{tr}[H]^2 }{t}\\
&= 2\operatorname{tr}[A]\operatorname{tr}[H].
\end{align*}
For the second one,
\begin{align*}
(D_H F)(A) &= \lim_{t \to 0} \frac{\operatorname{tr}[(A + tH)^2] - \operatorname{tr}[A^2]}{t}\\
&= \lim_{t \to 0} \frac{\operatorname{tr}[A^2 + t(AH + HA) + t^2H^2] - \operatorname{tr}[A^2]}{t}\\
&= \lim_{t \to 0} \frac{\operatorname{tr}[A^2] + t\operatorname{tr}[(AH + HA)] + t^2\operatorname{tr}[H^2] - \operatorname{tr}[A^2]}{t}\\
&= \lim_{t \to 0} \frac{t\operatorname{tr}[(AH + HA)] + t^2\operatorname{tr}[H^2]}{t}\\
&=\operatorname{tr}[AH + HA]\\
&=2\operatorname{tr}[AH].
\end{align*}
