Let’s say I have a matrix $ H$ represented in some basis, $ a$ , and I’d like to transform this to be represented in a different basis, $ b$ . The only difference between the bases is that $ b$ is a basis of eigenvectors of a reflection operator, $ \hat{\sigma}$ . So in theory, what I want to do is find the eigenvectors of $ \hat{\sigma}$ , but them into a matrix that I’ll call $ U$ , and then compute $ H_b = U^\dagger H U$ . My problem is that the basis $ a$ is ordered according to an order I want to preserve, but Mathematica by default sorts the eigenvectors of $ \hat{\sigma}$ by the eigenvalues (which are all either +1 or -1 since this is a reflection operator). How can I keep the ordering of the eigenvectors locked to the original basis so I can indeed use this as a basis transformation without mixing up the subblocks of my existing matrix?

Here’s a code example of what I want:

`Ha = {{298.1, -0.7, 0., 0., 0., 0., 0., 0.}, {-0.7, 296.8, 0., 0., 0., 0., 0., 0.}, {0., 0., 298.1, -0.7, 0., 0., 0., 0.}, {0., 0., -0.7, 296.8, 0., 0., 0., 0.}, {0., 0., 0., 0., 298.1, -0.7, 0., 0.}, {0., 0., 0., 0., -0.7, 296.8, 0., 0.}, {0., 0., 0., 0., 0., 0., 298.1, -0.7}, {0., 0., 0., 0., 0., 0., -0.7, 296.8}}; `

Note that Ha is blocked in 4 2×2 blocks. When I change bases, I expect this to become blocked in 2 4×4 blocks.

Now, my operator $ \hat{\sigma}$ can be represented as:

`sigma={{0, 0, 0, 1., 0, 0, 0, 0}, {0, 0, 1., 0, 0, 0, 0, 0}, {0, 1., 0, 0, 0, 0, 0, 0}, {1., 0, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 0, 1.}, {0, 0, 0, 0, 0, 0, 1., 0}, {0, 0, 0, 0, 0, 1., 0, 0}, {0, 0, 0, 0, 1., 0, 0, 0}}; `

But then when I call `Transpose[Eigenvectors[sigma]].Ha.Eigenvectors[sigma]`

, I get a matrix that is horribly off-diagonal, which is just showing that the eigenvectors of `sigma`

are not sorted properly. So, how do I keep everything sorted correctly?