# Find a matrix for a unitary transform between matrices or prove that there is none

I have hermitian matrices $$A,\,B$$ and would like to find a unitary matrix $$U$$ such that $$UAU^\dagger=B$$ or show that there is no such matrix.

Example:
For $$A=\begin{pmatrix} 0 & 1 & 0 & 0\\ 1 & 0 & 0 & 0\\ 0 & 0 & 0 & -1\\ 0 & 0 & -1 & 0 \end{pmatrix},\, B=\begin{pmatrix} 0 & 0 & -1 & 0\\ 0 & 0 & 0 & 1\\ -1 & 0 & 0 & 0\\ 0 & 1 & 0 & 0 \end{pmatrix}$$ we find $$U=\begin{pmatrix} 1 & 0 & 0 & 0\\ 0 & 0 & -1 & 0 \\ 0 & -1 & 0 & 0\\ 0 & 0 & 0 & 1 \end{pmatrix}$$ by guesswork. A constructive method would be useful.

Next example, where I assume that no such $$U$$ exists, but do not know how to show it: $$A=\begin{pmatrix} b & d & c & a\\ d & - b & a & - c\\ c & a & - b & - d\\ a & - c & - d & b \end{pmatrix} =a\cdot\sigma_x\otimes\tau_x + b\cdot\sigma_z\otimes\tau_z + c\cdot\sigma_x\otimes\tau_z + d\cdot\sigma_z\otimes\tau_x\\ B=\begin{pmatrix} - b & d & - c & - a\\ d & b & - a & c\\ - c & - a & b & - d \\- a & c & - d & - b\end{pmatrix} =-a\cdot\sigma_x\otimes\tau_x - b\cdot\sigma_z\otimes\tau_z - c\cdot\sigma_x\otimes\tau_z + d\cdot\sigma_z\otimes\tau_x$$ where $$\sigma_x,\,\sigma_z,\,\tau_x,\,\tau_z$$ denote the Pauli matrices $$\sigma_0 = \tau_0 = \begin{pmatrix} 1 & 0\\ 0 & 1 \end{pmatrix},\, \sigma_x = \tau_x = \begin{pmatrix} 0 & 1\\ 1 & 0 \end{pmatrix},\, \sigma_y = \tau_y = \begin{pmatrix} 0 & -i\\ i & 0 \end{pmatrix},\, \sigma_z = \tau_z = \begin{pmatrix} 1 & 0\\ 0 & -1 \end{pmatrix}$$ Note: I am mostly interested in $$4\times4$$ matrices, but $$8\times8$$ would be nice, too.
EDIT: Thanks to the answer of Kurt G.. Assume $$a,\,b,\,c,\,d\in\mathbb{R}\backslash\{0\}$$. I was aware that a solution for $$d=0$$ exists. I specifically included $$d$$ to avoid a simple solution of the form $$\sigma_a\otimes\tau_b$$. When $$d=0$$, then a solution exists independently of the other values, for example $$U=\sigma_0\otimes\tau_y$$

• Have you tried the QR algorithm? Jul 16, 2021 at 8:53
• I will have a look at the QR algorithm. So far I have seen it applied for real matrices, so I would have to think about how it can work with hermitian matrices. Jul 16, 2021 at 14:37
• @laolux, if you accept my answer as the correct one can you please mark it accordingly? Jul 17, 2021 at 4:42
• @KurtG. sure, I just wanted to make sure I understand it fully and was not confident to think clearly in the middle of the night. Jul 18, 2021 at 11:34

I think for the existence of a unitary $$U$$ s.t. $$UAU^\dagger=B$$ it is necessary and sufficient that $$A$$ and $$B$$ have the same eigenvalues. Let $$\lambda$$ be an eigenvalue of $$B$$ with eigenvector $$v\,.$$ Then $$Bv=\lambda v$$ and so $$UAU^\dagger v=\lambda v\,.$$ Setting $$w=U^\dagger v$$ gives $$UAw=\lambda Uw\,.$$ Therefore $$Aw=\lambda w\,.$$ This shows that every eigenvalue of $$B$$ is an eigenvalue of $$A\,.$$ Conversely, being square and hermitian, both, $$A$$ and $$B$$ are diagonalizable by unitary matrices $$U_1,U_2\,:$$ $$D_1=U_1AU_1^\dagger\,,~~D_2=U_2BU_2^\dagger\,.$$ If $$A$$ and $$B$$ have the same eigenvalues then the diagonal elements of $$D_1$$ and $$D_2$$ agree. Doing a permutation (which is an unitary operation) we can assume that $$D_1=D_2\,.$$ Then, $$A=U_1^\dagger D_1U_1=U_1^\dagger D_2U_1=U_1^\dagger U_2BU_2^\dagger U_1$$ and we can take $$U=U_1^\dagger U_2\,.$$
In your example where you believe that there is no solution I think you must require that $$a,b,c,d$$ are not zero. Checking in python shows that for $$a=6,b=4,c=3,d=0$$ the eigenvalues of $$A$$ and $$B$$ are the same. So there should exist a $$U$$.
To expand on the great and easy to understand answer of Kurt G. His proposed method of finding the unitary transform between $$A$$ and $$B$$ works because they are hermitian matrices and hence diagonalizable. For other matrices it is not sufficient for unitary equivalence that they have the same eigenvalues; having the same eigenvalues only shows that the two matrices are similar.
Furthermore, calculating the eigenvalues of a matrix is generally only possible up to size $$4\times4$$, even though you can sometimes find eigenvalues for larger matrices by using special properties of the matrices or by simply guessing one or more eigenvalues. However, it seems like it is not necessary to diagonalize matrices in order to show that they are unitarily equivalent. Instead, one can use Specht's theorem which only requires calculating traces of products of matrices in is hence applicable in any dimension.
In the second problem, the two matrices are unitarily similar when $$abcd=0$$. When $$abcd\ne0$$, one can verify that \begin{aligned} \operatorname{tr}(A^4)&=4\left[(a^2+b^2+c^2+d^2)^2+4(ab-cd)^2\right],\\ \operatorname{tr}(B^4)&=4\left[(a^2+b^2+c^2+d^2)^2+4(ab+cd)^2\right]. \end{aligned} Hence $$\operatorname{tr}(A^4)\ne\operatorname{tr}(B^4)$$ in this case and $$A,B$$ are not similar.