In [72]:
import matplotlib.pyplot as plt
from numpy import sqrt,pi,cos,sin,arange,random,exp
from qutip import *
In [2]:
H = Qobj([[1],[0]])
V = Qobj([[0],[1]])
P45 = Qobj([[1/sqrt(2)],[1/sqrt(2)]])
M45 = Qobj([[1/sqrt(2)],[-1/sqrt(2)]])
R = Qobj([[1/sqrt(2)],[-1j/sqrt(2)]])
L = Qobj([[1/sqrt(2)],[1j/sqrt(2)]])
In [3]:
def sim_transform(o_basis1, o_basis2, n_basis1, n_basis2):
a = n_basis1.dag()*o_basis1
b = n_basis1.dag()*o_basis2
c = n_basis2.dag()*o_basis1
d = n_basis2.dag()*o_basis2
return Qobj([[a.data[0,0],b.data[0,0]],[c.data[0,0],d.data[0,0]]])
In [4]:
def Delta(state, op):
"""Calculate std. dev. of an observable in a given state"""
eO2 = state.dag()*op*op*state
eO = state.dag()*op*state
return sqrt(eO2.data[0,0] - (eO.data[0,0])**2)
In [5]:
Phv = H*H.dag() - V*V.dag()
Phv
Out[5]:
In [6]:
psi = 1/sqrt(5)*H + 2/sqrt(5)*V
In [7]:
psi.dag()*Phv*psi
Out[7]:
In [8]:
psi.dag()*Phv*Phv*psi
Out[8]:
In [9]:
1.0 - (-0.6)**2
Out[9]:
In [43]:
data = random.choice([1, -1],size=20,p=[0.2,0.8])
In [44]:
data.mean()
Out[44]:
In [45]:
data.var()
Out[45]:
In [62]:
data = random.choice([1, -1],size=10000,p=[0.2,0.8])
In [63]:
data.mean()
Out[63]:
In [64]:
data.var()
Out[64]:
10,000 does pretty well for getting to the predictions. "There is no substitute for an adequate sample size."
In [65]:
# 5.11
P_45 = P45*P45.dag() - M45*M45.dag()
In [66]:
#5.12
P_c = L*L.dag() - R*R.dag()
In [67]:
#5.13
(Phv*P_45 - P_45*Phv) == 2j * P_c
Out[67]:
In [68]:
#5.14
(Phv*P_c - P_c*Phv) == -2j * P_45
Out[68]:
In [69]:
#5.15
P_p45 = P45*P45.dag()
P_v = V*V.dag()
In [70]:
P_p45*P_v - P_v*P_p45
Out[70]:
In [73]:
psi = 1/sqrt(3)*H + sqrt(2/3.0)*exp(1j*pi/3.0)*V
psi.norm()
Out[73]:
In [74]:
Delta(psi,P_45)*Delta(psi,Phv)
Out[74]:
In [75]:
1/2j*(psi.dag()*(Phv*P_45 - P_45*Phv)*psi).data[0,0]
Out[75]:
In [ ]: