Let us first recall [Specht's Theorem](https://en.wikipedia.org/wiki/Specht%27s_theorem). Denote by $\text{Mat}\_{\mathbb{C}}(n)$ the set of all $n\times n$ matrices over the complex field $\mathbb{C}$. Let $A$ be a matrix in $\text{Mat}\_{\mathbb{C}}(n)$ and denote by $A^\*$ its conjugate transpose. A word $w(A,A^\*)$ of $A$ and $A^\*$ is an expression of the form 
$$
A^{n\_1}\cdot (A^\*)^{m\_1}\cdot\cdots\cdot A^{n\_k}\cdot (A^\*)^{m\_k}
$$ 
where ``$\cdot$'' represent matrix multiplication, $A^i$ is the $i$th power of $A$ (similarly for $(A^\*)^i$) and $n\_1,m\_1,\ldots,n\_k,m\_k$ are non-negative integers.
The length of a word is given by $n\_1+n\_2+\cdots+n\_k+m\_1+\cdots+m\_k$.


**Spechts's Theorem:** Given two matrices $A$ and $B$ in $\text{Mat}\_{\mathbb{C}}(n)$. Then, $A=U\cdot B\cdot U^\*$ for some unitary matrix $U$ *if and only if* 
$$
\text{tr}(w(A,A^\*))=\text{tr}(w(B,B^\*))
$$
for all words $w$. Here, $\text{tr}(\cdot)$ is the standard trace function on matrices.


Let us now replace the trace function by the ``sum of all entries'' function $\sigma$ defined as
$$
\sigma:\text{Mat}\_{\mathbb{C}}(n) \to \mathbb{C}: A=(a\_{ij})\mapsto \sigma(A)=\sum\_{i=1}^n\sum\_{j=1}^n a\_{ij}.$$ 
It is known that the functions $s(\cdot)$ and $\text{tr}(\cdot)$ share certain properties, see e.g., [Merikoski: On the trace and the sum of elements of a matrix](http://dx.doi.org/10.1016/0024-3795%2884%2990078-8), Linear Algebra and its applications, Volume 60, August 1984, pp. 177-185.


But what is known for two matrices $A$ and $B$ such that 
$$
\sigma(w(A,A^\*))=\sigma(w(B,B^\*))\tag{1}
$$
for all words $w$?


**Question:** Is a Specht-like characterisation of matrices satisfying the conditions (1) known? Moreover, 


* Is the equivalence relation $A\equiv\_s B$ iff $\sigma(w(A,A^\*))=\sigma(w(B,B^\*))
$
for all words $w$ studied before?
* What about $A\equiv\_s^K B$ iff $\sigma(w(A,A^\*))=\sigma(w(B,B^\*))
$
for all words *of length less than $K$*?
* Can it be that $A\equiv\_s^K B$ but $A\not\equiv\_s^{K+1} B$?
* What if we restrict $A$ and $B$ to (non-negative) real matrices?


Any pointers to related work or insights are welcome.


**UPDATE:** A *sufficient* condition seems to be that $P\cdot B=A\cdot P$ and $P\cdot B^\*=A^\*\cdot P$ for a matrix $P\in\text{Mat}\_{\mathbb{C}}(n)$ such that $P\cdot \mathbf{e}=\mathbf{e}$ and $\mathbf{e}^t\cdot P=\mathbf{e}^t$, where $\mathbf{e}$ is the $n\times 1$ vector consisting entirely out of $1$'s (so $P$ is doubly stochastic). Indeed,


* first note that $s(w(A,A^\*))=\mathbf{e}^t\cdot w(A,A^\*)\cdot \mathbf{e}$;
* then, assume that $w(A,A^\*)=w'(A,A^\*)\cdot A$ for some smaller word $w'$. (The case that $w(A,A^\*)=w'(A,A^\*)\cdot A^\*$ is analogous). Note that $$w(A,A^\*)\cdot\mathbf{e}=w'(A,A^\*)\cdot A\cdot\mathbf{e}=w'(A,A^\*)\cdot A
\cdot P\cdot \mathbf{e}=w'(A,A^\*)\cdot P\cdot B\cdot\mathbf{e}.$$ An inductive argument shows that $w(A,A^\*)\cdot\mathbf{e}=P\cdot w(B,B^\*)\cdot\mathbf{e}$. Then, it suffices to note that $$\mathbf{e}^t\cdot w(A,A^\*)\cdot\mathbf{e}=\mathbf{e}^t\cdot P\cdot w(B,B^\*)\cdot\mathbf{e}=\mathbf{e}^t\cdot w(B,B^\*)\cdot\mathbf{e},$$ or that $s(w(A,A^\*))=s(w(B,B^\*))$.


This hold for any word $w$.


The question is now whether equation (1) also implies the existence of a matrix $P\in\text{Mat}\_{\mathbb{C}}(n)$ such that $P\cdot \mathbf{e}=\mathbf{e}$ and $\mathbf{e}^t\cdot P=\mathbf{e}^t$, and such that $P\cdot B=A\cdot P$ and $P\cdot B^\*=A^\*\cdot P$ for the given matrices $A$ and $B$.



A variant of Specht's Theorem using sum of elements (rather than trace) of complex matrices?
A sum-of-entries version of Specht's theorem was proven in [Theorem 20 of Grohe et al. (2022): Homomorphism Tensors and Linear Equations](https://drops.dagstuhl.de/opus/volltexte/2022/16411). The condition you're describing is also sufficient. More precisely, for matrices $A$ and $B$ it holds that $\sigma(w(A,A^\*)) = \sigma(w(B,B^\*))$ if and only if there exists a pseudo-stochastic matrix $X$ such that $XA = BX$ and $XA^\* = B^\*X$. A matrix is called *pseudo-stochastic* if $X \boldsymbol{1} = \boldsymbol{1} = X^T \boldsymbol{1}$ for $\boldsymbol{1}$ the all-ones vector.


