from numpy import sin,cos,pi,sqrt
from qutip import *

pz = Qobj([[1],[0]])  # +z
mz = Qobj([[0],[1]])  # -z
px = Qobj([[1/sqrt(2)],[1/sqrt(2)]])  # +x
mx = Qobj([[1/sqrt(2)],[-1/sqrt(2)]])  # -x
py = Qobj([[1/sqrt(2)],[1j/sqrt(2)]])  # +y
my = Qobj([[1/sqrt(2)],[-1j/sqrt(2)]])  # -y
Sx = 1/2.0*sigmax()
Sy = 1/2.0*sigmay()
Sz = 1/2.0*sigmaz()

"""
Explanation: Lab 6 - Spin
A few new operators (or new names for the same ones!)
The three axes, x, y, z spin components can be measured with $SA_x$, $SA_y$, and $SA_z$ devices.
We'll use $\hbar=1$ for numerical results, this is fairly standard practice, but can be tricky to remember.
End of explanation
"""


((px.dag()*my).norm())**2

"""
Explanation: Example: determine $P(S_x = \frac{\hbar}{2} ||-y\rangle)$
End of explanation
"""


Sx*Sz - Sz*Sx == -1j*Sy  # remember, h = 1

"""
Explanation: Example: verify the commutation relation: $\left[\hat{S}_x,\hat{S}_z\right] = -i\hbar\hat{S}_y$
End of explanation
"""


pz.dag()*Sx*pz

"""
Explanation: Ex: find $\langle \hat{S}_x\rangle$ for the state $|\psi\rangle=|+Z\rangle$.
End of explanation
"""


px.dag()*Sx*px

"""
Explanation: This makes sense given that $S_x$ can be either $\frac{+\hbar}{2}$ or $\frac{-\hbar}{2}$ with equal probability. Similarly, if the state is $|\psi\rangle=|+x\rangle$.
End of explanation
"""


