Let $f:\mathfrak{gl}(n;\mathbb{R})\to \mathbb{R}$ be a polynomial (here, $\mathfrak{gl}(n;\mathbb{R})$ is the lie algebra of $GL(n;\mathbb{R})$ and hence is simply the set of $n\times n$ real matrices). $f$ is said to be invariant if $f(X)=f(A^{-1}XA)$ for all $A\in GL(n;\mathbb{R})$ and $X\in \mathfrak{gl}(n;\mathbb{R})$. My question is:
If $f$ is an invariant polynomial, does it imply $f(ZY)=f(YZ)$ for any two matrices $Z,Y$?
The converse is clearly true if you take $Z=A^{-1}X$ and $Y=A$. The above question is trivial if at least one of $Y$ or $Z$ is invertible. Can anyone give a hint about how to prove this in the general case? Thanks in advance!