# How can I simulate EPR and Bell’s inequalities in qiskit?

According to Bernard Zygelman "A First Introduction to Quantum Computing and Information", I can compute the $$QS|f\rangle$$ with $$|f\rangle = \frac{1}{\sqrt{2}} (|00\rangle -|11\rangle)$$, with $$Q=Z$$, $$S = \frac{1}{\sqrt{2}}(X+Z) = H$$, but

Q: How can you compute $$\langle f|QS|f\rangle$$?

Here my code up to now

import qiskit as q
circuit = q.QuantumCircuit(2,2)
circuit.x(0)
circuit.h(0)
circuit.cx(0,1)
backend = q.Aer.get_backend('statevector_simulator')
result = q.execute(circuit, backend=backend).result()
print(circuit)
print(result.get_statevector()) # 1/sqrt(2) (|00> -|11>)
# CSHS <QS> = 1/sqrt(2)
circuit = q.QuantumCircuit(2,2)
circuit.x(0)
circuit.h(0)
circuit.cx(0,1)

circuit.z(0)   #  Q = Z
circuit.h(1)   #  S = 1/sqrt(2)*(X+Z) = H

print(circuit)
#circuit.measure([0,1],[0,1])
backend = q.Aer.get_backend('statevector_simulator')
result = q.execute(circuit, backend=backend).result()
print(result.get_statevector())


I got the correct output state: Statevector([ 0.5+0.j, 0.5+0.j, 0.5+0.j, -0.5+0.j], dims=(2, 2))

• To evaluate $\langle f | O | f \rangle$ for some state $| f \rangle = U | 0 \rangle$, you need to evaluate $\langle 0 | U^\dagger O U | 0 \rangle$. To evaluate $\langle 0 | \psi \rangle$, you need just to measure $| \psi \rangle$. So, apply $U^\dagger O U$ and measure. Sep 18, 2023 at 10:06