Assume we have matrix $M$ and
$$ M = A B + C $$
while $M, A, C$ are given. I want to compute $\frac{\partial B}{\partial A}$ and $\frac{\partial B}{\partial C}$. A clear way is to make
$$ B = MA^{-1}-CA^{-1}$$
then differentiate. I am wondering whether there is a more efficient way to do it without computing $A^{-1}$?
$\def\E{\cal E} \def\c{\cdot} \def\l{\left} \def\r{\right} \def\p{\partial} \def\g#1#2{\frac{\p #1}{\p #2}} $Given $$\eqalign{ B &= (M-C)A^{-1} \\ }$$ its differential with respect to $A$ is the matrix quantity $$\eqalign{ dB &= (M-C)\;dA^{-1} \\ &= (M-C)\;\l(-A^{-1}dA\,A^{-1}\r) \\ &= -B\;dA\;A^{-1} \\ }$$ The gradient wrt $A$ is a fourth-order tensor, but its matrix-valued components are $$\eqalign{ \g{B}{A_{ij}} &= -B E_{ij}A^{-1} \\ }$$ where $E_{ij}$ is a matrix with element $(i,j)$ equal to one and all others equal to zero.
The gradient wrt $C$ can be calculated in a similar fashion. $$\eqalign{ dB &= -dC\,A^{-1} \\ \g{B}{C_{ij}} &= -E_{ij}\,A^{-1} \\ }$$ And both results can be reformulated to avoid $A^{-1}$ $$\eqalign{ &\l(\g{B}{C_{ij}}\r)A &= -E_{ij} \\ B&\l(\g{B}{C_{ij}}\r) &= \l(\g{B}{A_{ij}}\r) \\ }$$