<SYSTEM_TASK:>
Given the following text description, write Python code to implement the functionality described below step by step
<END_TASK>
<USER_TASK:>
Description:
 Lab 4 - Measurements
First our standard definitions
Step1:  Q
Step2:  Q
Step3:  Q
Step4:  Example
Step5:  Q
<ASSISTANT_TASK:>
Python Code:
import matplotlib.pyplot as plt
from numpy import sqrt,pi,cos,sin,arange,random
from qutip import *
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)]])
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]]])
Explanation: Lab 4 - Measurements
First our standard definitions:
End of explanation
Phv = H*H.dag() - V*V.dag()
Phv
Explanation: Q: Define the $\hat{\mathscr{P}}_{HV}$ operator
End of explanation
psi = 1/sqrt(5)*H + 2/sqrt(5)*V
psi.dag()*Phv*psi
Explanation: Q: What is the expectation value $\langle \hat{\mathscr{P}}_{HV}\rangle$ for state $|\psi\rangle = \frac{1}{\sqrt{5}}|H\rangle + \frac{2}{\sqrt{5}}|V\rangle$? Interpret this result given the amplitudes in the state.
End of explanation
psi.dag()*Phv*Phv*psi
1- (-0.6)**2
Explanation: Q: What is the variance of $\mathscr{P}_{HV}$?
End of explanation
data = random.choice([1, -1],size=1000000,p=[0.2,0.8])
Explanation: Example: Use the random function to generate a mock data set for the state $|\psi\rangle$.
random.choice([1,-1],size=10,p=[0.2,0.8])
gives a list of 10 numbers, either 1 or -1 with the associated probability p:
End of explanation
data.mean()
data.var()
Explanation: Q: Verify the mean and variance of the mock data set match your QM predictions. How big does the set need to be for you to get ±5% agreement?
End of explanation
<END_TASK>