Unitary matrix commute with function I'm wondering in which cases the following identity is satisfied :
$$
f\left(UXU^T\right) = Uf\left(X\right)U^T
$$
where $X \in \mathbb{R}^{n\times n}$ is a square matrix, $U$ is any permutation matrix and $ f:\mathbb{R}^{n\times n} \rightarrow \mathbb{R}^{n\times n}$
I already know of two cases :

*

*$f$ can be expressed as a matrix Taylor series (in this case $U$ could be any unitary matrix)

*$f$ is an element-wise function

Are these the general cases?
Bonus :
Is there an extension of the preceding identity to tensors $T \in \mathbb{R}^{n^m}$ and $f:\mathbb{R}^{n^m} \rightarrow \mathbb{R}^{n^m}$. I am not sure what form the product and the operator $U$ would take in that case.
 A: Here's a bit of relevant literature:

*

*Deep Sets (NIPS 2017) classifies all linear functions $\mathbb R^{n\times k} \to \mathbb R^{n\times l}$ that are permutation invariant / equivariant across the first axis.


*On Universal Equivariant Set Networks  (ICLR 2020) deals with the case of finding all homogeneous polynomial functions $\mathbb R^{n\times k} \to \mathbb R^{n\times l}$ that are permutation equivariant across the first axis.


*Invariant and Equivariant Graph Networks (ICLR 2019) deals with the case of finding linear functions $\mathbb R^{n^k} \to \mathbb R^{n^k}$ that are permutation invariant / equivariant across all $k$ axes
Especially, the 3rd paper gives as an example the case of linear function $\mathbb R^{n^2}\to\mathbb R^{n^2}$ that are permutation equivariant across each axis, i.e. $f(P^T X P)=P^T f(X) P$, which is precisely your problem. They show that the space of such linear functions is $15$-dimensional, independent of $n$ (!).
One can combine papers 2 and 3 to find all homogeneous polynomial functions $\mathbb R^{n^k}\to\mathbb R^{n^k}$ that are permutation equivariant across all $k$ axes.
