Proof for the funky trace derivative : $d (\operatorname{trace} (ABA'C))$? Given three matrices $A$, $B$ and $C$ such that $ABA^T C$ is a square matrix, the derivative of the trace with respect to $A$ is:
$$
\nabla_A \operatorname{trace}( ABA^{T}C )  = CAB + C^T AB^T
$$
There is a proof here, page 4 (PDF file). However, I was not able to understand the second line of the proof. it says something like this:
$$
\nabla_A \operatorname{trace}( ABA^T C )=
\nabla_\bullet \operatorname{trace}(f(\bullet)A^{T}C) + \nabla_\bullet \operatorname{trace}(f(A) \bullet^T C)
$$
Where  $f(A) = AB$
I tried searching the proof or any hint using google, but I couldn't fine anything. Could anyone please help me with this second line. I cannot sleep. I am obsessed with this proof.
 A: $\nabla$ is not the derivative but the gradient of a function $f$, that is
$(\nabla f)(x) \cdot v=Df_x(v)$ where $\cdot$ is a dot product and $Df_x(v)$ is the derivative in $x$ in the direction of the vector $v$.
For the real matrices, we consider the following scalar product:
$$(U,V)\rightarrow U \cdot V=\text{Tr}(U^TV).$$
Here the derivative is 
\begin{align*} 
Df_A:H &\rightarrow \text{Tr}(HBA^TC)+\text{Tr}(ABH^TC) \\
&= \text{Tr}(BA^TCH)+Trace(B^TA^TC^TH) \\
&= \text{Tr}((C^TAB^T+CAB)^TH) \\
&= (C^TAB^T+CAB) \cdot H.
\end{align*}
Finally $(\nabla f)(A)=C^TAB^T+CAB$ as required.
A: Since those "dots" appear nowhere else in the document, and the calculation is labeled "funky," I wonder if the author himself even understands what is going on there.  (If I came across this while grading, I'd assume the writer had asked a friend for an explanation and copied down only half of what they said.  It's a level of detail associated more with personal notes than communicating with others.)
I don't mean to criticize: the spirit of that document is to collect a number of matrix calculations and that is fine.  But when the author uses the word "prove" (in "we prove that...") he is using it in a very loose sense.  Enough detail is given in the calculation so that if you understand it, you could go and construct a proof.  But a chain of unjustified, unexplained equations is not a "proof" in the strict sense.  (The appearance of "$f'$" in that context cannot actually be explained in a way consistent with his definitions of $f$ and $'$, and so maybe counts as a mistake--- although it is immediately replaced with the right thing.)
Anyway, it is implicit use of the chain rule.  ("Implicit" in the English language sense of "there but not mentioned", not in any sense like implicit differentiation.)  Here is a scalar-calculus analogy.  One way to compute the derivative of 
$$
g(a) = a^a
$$
is to regard $g(a)$ as the result of plugging the pair of functions $x = a$ and $y = a$ into the multivariable function $H(x,y) = x^y$.  Whenever $H(x,y)$ is a function of two variables $x$ and $y$, each of which is a function of $a$, the multivariable chain rule tells you that
$$
\frac{d}{da} H(x,y) = \frac{\partial H(x, y)}{\partial x} \cdot \frac{dx}{da} + \frac{\partial H(x,y)}{\partial y} \cdot \frac{dy}{da}
$$
and the the partials of $H(x,y) = x^y$ are easy to calculate since in computing the $x$-partial derivative you hold $y$ fixed, and vice versa: $\frac{\partial H}{\partial x} = y x^{y-1}$ (from the power rule) and $\frac{\partial H}{\partial y} = x^y \ln(x)$ (from the rule for differentiating exponential functions).  So with $H(x,y) = x^y$ and $x=a$ and $y=a$ in the above, we see
\begin{align*}
\frac{d}{da} (a^a) & = \frac{\partial H(a, a)}{\partial x} \cdot 1 + \frac{\partial H(a,a)}{\partial y} \cdot 1 \\
& = a a^{a - 1} + a^a \ln(a) = a^a + a^a \ln(a).
\end{align*}
It is not too much trouble to follow this calculation because I introduced new variables $x$ and $y$ and explicitly defined the function $H$ I was using.  If instead of writing the new variables I wrote dots, and instead of defining my new function $H$ I just wrote out formulas with $a$s and dots, it might get confusing.
That's basically what's going on in that document.  Fix matrices $B$ and $C$.  The function
$$
g(A) = \operatorname{trace} (ABA^TC)
$$
of the matrix $A$ has the form
$$
g(A) = H(f(A),A)
$$
for the scalar valued function $H(X,Y) = \operatorname{trace} X Y^T C$ of two matrix variables and the matrix valued function $f(A) = AB$ of one variable.  The chain rule implies that in this case we have
$$
\nabla_A H(f(A),A) = (\nabla_X H(X,Y)) B^T + \nabla_Y H(X,Y)
$$
where you evaluate the right hand side at $X = f(A)$ and $Y = A$ after computing the matrix derivatives.  Elsewhere in that document he sketches how to compute $\nabla_X H(X,Y) = (Y^T C)^T$ and $\nabla_Y H(X,Y) = CX$.  So that is how the result $(A^T C)^T B^T + CAB$ comes out.  Just like the scalar case, introducing new variables so that you can treat some as constant when differentiating with respect to others, simplifies the calculation.
To return to my initial remark about $f'$: many of that document's formal particulars are sketchy.  For example, the nonrigorous treatment of the Jacobian in section 4 is just to motivate calculation, and the appearance of $f'$ in the calculation you ask about is not consistent with this use.  My guess is that the author wanted to remind himself that something coming from the chain rule and related to $f$ went there, and so he wrote $f'$ as a mental reminder.  Since he replaced it with the right thing, $B^T$, no harm was done.
... And one is right to be cautious about what exactly goes there, since for arbitrary matrix valued functions $X = f(A)$ and $Y = k(A)$, the expression for $\nabla_A H(f(A),k(A))$ is a complicated function of the entries of $\nabla_X H(X,Y)$ and $\nabla_Y H(X,Y)$ and the partial derivatives of the entries of $f(A)$ and $g(A)$.  It is not easily written as a matrix product of $\nabla_X H(X,Y)$ with a matrix depending only on $f$, plus a matrix product of $\nabla_Y H(X,Y)$ with a matrix depending only on $g$.  We got a simple formula above because our $f(A) = AB$ and $k(A) = A$ were simple functions of $A$ (e.g. any one entry of $f(A)$ depends only on one row of entries of $A$, and not all of the entries of $A$, as might happen in general).  If you were wondering why the author did not include a general matrix derivative chain rule, this is why.  It doesn't look very nice in general; it only looks nice in various special cases.
A: I like your presentation and explanation very much. I am finding it difficult to follow how derivative of $AB$ with respect to $A$ turned out to be $B^T$.
I am under the assumption that $f(A)$ is a function $f:R^{m X n} \rightarrow R$. Then $\nabla_A f(A)$ is defined and is an $m X n$  matrix with $(i,j)th$ entry being equal to $\frac{\partial }{\partial a_{i,j}}f(A) $. 
$trace(ABA^TC)$ is a real valued function where as $AB$ is a matrix. 
A: I recently came across the same problem from CS229 lecture notes on page 9. After learning from the other answers, I formulated my own derivation, which I think is straightforward.
I assume you've already proved the following, which are in the lecture notes, too.
\begin{align*} 
\mathrm{tr}(AB) &= \mathrm{tr}(BA) \\
\mathrm{tr}(A) &= \mathrm{tr}(A^T) \\
\nabla_A \mathrm{tr}(AB) &= B^T \\
\end{align*}
Then, using the multivariate derivative rule, I label the variate being looked at with $X$,
\begin{align*}
\nabla_A \mathrm{tr}( ABA^T C ) &= \nabla_X \mathrm{tr}( XBA^T C ) + \nabla_X \mathrm{tr}( ABX^T C) \\
&= (BA^TC)^T + \nabla_X \mathrm{tr}(CABX^T) \\
&= C^TAB^T + \nabla_X \mathrm{tr}(X(CAB)^T) \\
&= C^TAB^T + ((CAB)^T)^T \\
&= C^TAB^T + CAB \\
\end{align*}
A: We need to prove:  $$\nabla_{A} \operatorname{tr} A B A^{T} C =C A B+C^{T} A B^{T} $$
First, we define a scalar valued function $f=\operatorname{tr} A B A^{T} C$
Then we compute the differential:
$$\begin{align}  
 df &= d\ \operatorname{tr} (A B A^{T} C)  \\
    &= \operatorname{tr}(d(A B A^{T} C)) \\
    &= \operatorname{tr}(dA (B A^{T} C)+A dB (A^{T} C)+(A B) dA^{T} (C)+(A B A^{T}) dC) \\
    &= \operatorname{tr}(dA (B A^{T} C)+(A B) dA^{T} (C)) \\
    &= \operatorname{tr}((B A^{T} C)dA)+\operatorname{tr}( (CA B) dA^{T})) \\
 &= \operatorname{tr}((B A^{T} C)dA)+\operatorname{tr}( (CAB)^T (dA^{T})^T)) \\
 &= \operatorname{tr}((B A^{T} C)dA)+\operatorname{tr}( (CAB)^T dA) \\
 &= \operatorname{tr}\left(\left(BA^{T}C+ (CAB)^T\right) dA\right)
    \end{align}$$
Because:
$$d f=\operatorname{tr}\left(\left(\frac{\partial f}{\partial X}\right)^{T} d X\right)$$

(If you are not familiar about this, the first link down below is a good tutorial about matrix derivative)

Hence:
$$\frac{\partial f}{\partial A}=\left(BA^{T}C+ (CAB)^T\right)^T=C A B+C^{T} A B^{T}$$
End of proof.
I came across this problem from CS229 lecture.Andrew Ng. said that the proof is reasonably simple, while I spent a whole day learning about matrix derivative before finally understood it.
Here are some helpful sites:

*

*Pili HU, Matrix Calculus, https://github.com/hupili/tutorial/tree/master/matrix-calculus

*Wikipedia: Gradient:
The "实值函数相对于向量和矩阵的梯度"(The gradient of scalar valued functions with respect to vectors and matrices) part is quite helpful, it's in Chinese, I didn't find this part in the English version.
https://zh.wikipedia.org/zh-sg/%E6%A2%AF%E5%BA%A6

*

*Anyway, the key idea is that



$$
\nabla_{A} f(\boldsymbol{A})\stackrel{\text { def }}{=}\left[\begin{array}{cccc}
\frac{\partial f(A)}{\partial a_{11}} & \frac{\partial f(A)}{\partial a_{12}} & \cdots & \frac{\partial f(A)}{\partial a_{1 n}} \\
\frac{\partial f(A)}{\partial a_{21}} & \frac{\partial f(A)}{\partial a_{22}} & \cdots & \frac{\partial f(A)}{\partial a_{2 n}} \\
\vdots & \vdots & \ddots & \vdots \\
\frac{\partial f(A)}{\partial a_{m 1}} & \frac{\partial f(A)}{\partial a_{m 2}} & \cdots & \frac{\partial f(A)}{\partial a_{m n}}
\end{array}\right]=\frac{\partial f(\boldsymbol{A})}{\partial \boldsymbol{A}}
$$
