I am familiar with the derivation of $D_A(\det(A)) := \dfrac{\partial \det(A)}{\partial A}$ as a Fréchet derivative by considering $$D_A[H] = \det(A+H) - \det(A) \; as \; \|H \| \rightarrow 0 = \det(A) \mathrm{tr} (A^{-1}H) = \det(A) A^{-T} \cdot H$$ for a general square matrix $A$. I have used the Frobenius inner product for writing the trace as an inner product. This leads to the same answer as that given in The Matrix Cookbook.
But if $A$ is symmetric , how do I compute the Fréchet derivative to be $$ \det(A) (2A^{-1} - \operatorname{diag}(A^{-1}) )$$ I am curious to know if we can derive this formula that is quoted from The Matrix Cookbook in various posts, see for example --
What is the derivative of the determinant of a symmetric positive definite matrix?
This doesn't look right to me.
Let $J = \begin{bmatrix} 0 & 1 \\ 1 & 0 \end{bmatrix}$, $A=A^{-1} = J$, $H=J$.
Then $D \det (A)(H) = -2$, whereas the other formula would give $-4$ (since $A$ is zero on the diagonal).
Commentary:
Let me abuse notation and use $S^n$ to denote the set of symmetric $n \times n$ matrices.
The Fréchet derivative is the best linear approximation to a function at a given point, it is unique and does not depend on any basis. In particular, the if the given point lies in some subspace (for example, $S^n \subset \mathbb{R}^{n \times n}$), the derivative is the same. There may be some simplifications in the formula that depend on characteristics of the subspace, but the resulting derivative will be the same.
Since the Cookbook formula gives a value that differs from the derivative, it cannot be the Fréchet derivative of the map $\det : S^n \to S^n$.
My understanding of what the Cookbook means by structured matrices is that there is some map $p$ from $\mathbb{R}^{n \times n}$ into the collection of structured matrices, and the (Fréchet) derivative of the composition $\det \circ p$, evaluated at a point of $ S^n$, is what the Cookbook gives.
For symmetric matrices, a parameterisation that is consistent with the Cookbook is $p:\mathbb{R}^{n \times n} \to S^n$, $p(X) = X+X^T - \operatorname{diag} X$, which would give rise to the formula (using the chain rule, linearity & symmetry of $p$ and properties of $\operatorname{tr}$): \begin{eqnarray} D (\det \circ p) (X)(H) &=& D \det(p(X)) ( D p(X)(H)) \\ &=& D \det(p(X))( p(H)) \\ &=& \det(p(X)) \operatorname{tr} ( p(X)^{-1} p(H)) \\ &=& \det(p(X)) \operatorname{tr} ( p(X)^{-1} (H+H^T - \operatorname{diag} H)) \\ &=& \det(p(X)) \operatorname{tr} ( 2p(X)^{-1} H - p(X)^{-1} \operatorname{diag} H)) \\ &=& \det(p(X)) \operatorname{tr} ( 2p(X)^{-1} H - \operatorname{diag} (p(X)^{-1})H) \\ &=& \det(p(X)) \operatorname{tr} ( (2p(X)^{-1} -\operatorname{diag} (p(X)^{-1}) H) \\ \end{eqnarray} Note, however, this is the Fréchet derivative of the composition $\det \circ p$, not the Fréchet derivative evaluated at a point of $S^n$ in the direction $H$. The parameterisation is very relevant.
In terms of the example above, we have $D \det (J)(J) = -2$, but $D (\det \circ p) (J) (J) = -4$.
The reason for the extra factor of $2$ is that $p(J) = 2J$ since the parameterisation $p$ doubles the non diagonal elements of the perturbation $p$.
That is, $\det(J+H) \approx -1 -2 \langle J, H \rangle$ but $(\det \circ p)(J+H) \approx -2 -4 \langle J, H \rangle$, so while both are Fréchet derivatives, they are derivatives of different functions evaluated at different points.