In [1]:
import sympy

In [2]:
from sympy.physics.quantum import TensorProduct as Kron
sympy.init_printing(fontsize='6pt')

In [3]:
#here we define sympy symbols to be used in the analytic calculations
g,mu,b,D,k=sympy.symbols('gamma mu B Delta k',real=True)
t,d,eps=sympy.symbols('t delta epsilon',real=True)
mz=sympy.symbols('m_z',real=True)
phi=sympy.symbols('phi',real=True)

In [4]:
#Pauli matrices to be used in symbolic calculations
S1=sympy.physics.matrices.msigma(1)
S2=sympy.physics.matrices.msigma(2)
S3=sympy.physics.matrices.msigma(3)
S0=S1*S1
T1=sympy.physics.matrices.msigma(1)
T2=sympy.physics.matrices.msigma(2)
T3=sympy.physics.matrices.msigma(3)
T0=T1*T1
i=sympy.I

wp=sympy.exp(i*phi)
wm=sympy.exp(-i*phi)

In [5]:
H=sympy.Matrix([[0,0,wp,0],
                [0,0,0,wm],
                [wm,0,0,0],
                [0,wp,0,0]])

In [6]:
P,D=H.diagonalize(normalize=True)

In [7]:
P


Out[7]:
$$\left[\begin{matrix}- \frac{\sqrt{2}}{2} e^{i \phi} & 0 & \frac{\sqrt{2}}{2} e^{i \phi} & 0\\0 & - \frac{\sqrt{2}}{2} e^{- i \phi} & 0 & \frac{\sqrt{2}}{2} e^{- i \phi}\\\frac{\sqrt{2}}{2} & 0 & \frac{\sqrt{2}}{2} & 0\\0 & \frac{\sqrt{2}}{2} & 0 & \frac{\sqrt{2}}{2}\end{matrix}\right]$$

In [8]:
P.inv()*H*P


Out[8]:
$$\left[\begin{matrix}-1 & 0 & 0 & 0\\0 & -1 & 0 & 0\\0 & 0 & 1 & 0\\0 & 0 & 0 & 1\end{matrix}\right]$$