According to Magnus and Neudecker, we can build a matrix calculus without running into higher order tensors by vectorizing the matrices before taking partial derivatives. This leads to the matrix Jacobian defined as $$ \mathrm{DZ}(X)=\frac{\partial \operatorname{vec} Z(X)}{\partial(\operatorname{vec} X)^{\mathsf{T}}} \,. $$
Now let's say we have some function that takes in 2 matrices and gives out another matrix $F:\mathbb{R}^{k \times l} \times \mathbb{R}^{m \times n} \to \mathbb{R}^{p \times q}$. Let's call our input matrices $A^{k \times l}$ and $B^{m \times n}$, and the output matrix $Y^{p \times q}$. So $Y = F(A,B)$.
My question: how can I interchange the order of partial derivatives? For example, given $ \frac{\partial \frac{\partial Y}{\partial A}}{\partial B} ,$ how do I get $ \frac{\partial \frac{\partial Y}{\partial B}}{\partial A} ?$ (where I ommited $\operatorname{vec}$ and transpose for brevity)
By trial and error with a symbolic toolbox I have arrived at this useless expression, since I cannot solve one in terms of the other: $$ \operatorname{vec} \frac{\partial \operatorname{vec} \left( \frac{\partial \operatorname{vec} Y}{\partial (\operatorname{vec} A)^\mathsf{T}}\right)^\mathsf{T}}{\partial(\operatorname{vec}B)^\mathsf{T} } = \operatorname{vec} \left( \frac{\partial\operatorname{vec}\frac{\partial \operatorname{vec} Y}{\partial (\operatorname{vec} B)^\mathsf{T}} }{\partial (\operatorname{vec} A)^\mathsf{T}}\right)^\mathsf{T} $$ I tried using the commutation matrix to eliminate the transpose on the RHS but with no success. Any ideas?
Reference: J. Magnus and H. Neudecker, Matrix Differential Calculus with Applications in Statistics and Econometrics, 3rd edition, 2019, Wiley.