Wolfram Language Paclet Repository

Community-contributed installable additions to the Wolfram Language

Primary Navigation

    • Cloud & Deployment
    • Core Language & Structure
    • Data Manipulation & Analysis
    • Engineering Data & Computation
    • External Interfaces & Connections
    • Financial Data & Computation
    • Geographic Data & Computation
    • Geometry
    • Graphs & Networks
    • Higher Mathematical Computation
    • Images
    • Knowledge Representation & Natural Language
    • Machine Learning
    • Notebook Documents & Presentation
    • Scientific and Medical Data & Computation
    • Social, Cultural & Linguistic Data
    • Strings & Text
    • Symbolic & Numeric Computation
    • System Operation & Setup
    • Time-Related Computation
    • User Interface Construction
    • Visualization & Graphics
    • Random Paclet
    • Alphabetical List
  • Using Paclets
    • Get Started
    • Download Definition Notebook
  • Learn More about Wolfram Language

QuantumFramework

Tutorials

  • Bell's Theorem: CHSH inequality
  • Circuit Diagram
  • Exploring Fundamentals of Quantum Theory
  • Getting Started
  • An IBM Quantum Error Map
  • Connecting to QPU Services
  • Quantum Machine Learning in Phase Space
  • Quantum object abstraction
  • Quantum Object Composition
  • Quantum Optimization
  • Second Quantization Functions
  • Sending Queries to IBM QPUs
  • Tensor Network
  • Time Evolution
  • Fast Gates on a Transmon
  • Quantum Computation

Guides

  • Wolfram Quantum Computation Framework

Symbols

  • CliffordChannel
  • EinsteinSummation
  • GraphState
  • IBMJob
  • IBMJobSubmit
  • LocalComplement
  • PauliStabilizer
  • QiskitCircuit
  • QiskitTarget
  • QuantumBasis
  • QuantumChannel
  • QuantumCircuitMultiwayGraph [EXPERIMENTAL]
  • QuantumCircuitOperator
  • QuantumDistance
  • QuantumEntangledQ
  • QuantumEntanglementMonotone
  • QuantumEvolve
  • QuantumMeasurement
  • QuantumMeasurementOperator
  • QuantumMeasurementSimulation
  • QuantumMPS [EXPERIMENTAL]
  • QuantumOperator
  • QuantumPartialTrace
  • QuantumPhaseSpaceTransform
  • QuantumQASM
  • QuantumShortcut [EXPERIMENTAL]
  • QuantumSimilarity
  • QuantumStateEstimate [EXPERIMENTAL]
  • QuantumState
  • QuantumTensorProduct
  • QuantumWignerMICTransform [EXPERIMENTAL]
  • QuantumWignerTransform [EXPERIMENTAL]
  • QuditBasis
  • QuditName
  • StabilizerFrame
  • StabilizerStateQ

Bell's Theorem: CHSH inequality

Entangled states, correlations, and measurement
Explore Bell’s inequality in a quantum circuit
Bell’s inequality
Reference
In[1]:=
Column@EntityValue[​​Entity["Person","JohnStewartBell::364v4"],{"Image","BirthDate",​​"DeathDate","NotableFacts"}]
Bell's inequalities are examined within the Wolfram quantum framework, using the standard language of quantum computation. A straightforward computational approach is employed to comprehend the underlying derivations of those equations, fully derived from standard quantum computation.

Entangled states, correlations, and measurement

Consider a 2-qubit quantum system that is prepared in the following quantum state
In[2]:=
ψm=
QuantumState
["PsiMinus"]
Check if it is an entangled state:
In[3]:=
QuantumEntangledQ
[ψm]
which is, of course, maximally entangled:
In[4]:=
QuantumEntanglementMonotone
[ψm]
An entangled state is a state that cannot be written as product of two states
ρ
1
⊗
ρ
2
. This possibility can be tested using
QuantumEntangledQ
which returns as True or False.
Let’s define a unit vector in 3D (which is parametrized by two angles):
In[5]:=
a[θ_,ϕ_]:={Sin[θ]Cos[ϕ],​​Sin[θ]Sin[ϕ],Cos[θ]}
Given two unit vectors, let’s find the angle between:
In[6]:=
vecAngle=​​FullSimplify[VectorAngle[a[θ1,ϕ1],a[θ2,ϕ2]],​​Assumptions{θ1∈Reals,θ2∈​​Reals,ϕ1∈Reals,ϕ2∈Reals}]
Now let us calculate the quantum expectation (i.e. the mean value) of a composite operator as follows:
〈
-
ψ
|

a
1
.
σ
⊗

a
2
.
σ
|
-
ψ
〉
with
|
-
ψ
〉=
1
2
(|01〉-|10〉)
and
σ
the Pauli vector.
Define a Pauli vector:
In[7]:=
σ[θ_,ϕ_]:=​​
QuantumOperator
[a[θ,ϕ].Table[PauliMatrix[i],{i,3}]]
Calculate
〈
-
ψ
|

a
1
.
σ
⊗

a
2
.
σ
|
-
ψ
〉
:
In[8]:=
†
ψm
​​
QuantumTensorProduct
[σ[θ1,ϕ1],\​σ[θ2,ϕ2]][ψm]
Note that the result is a scalar, but as an object, we treat it as a quantum state object, with 0 number of qudits (look at the summary box of above result). The actual scalar number can be extracted like this:
In[9]:=
Φ12=FullSimplify[%["Number"]]
The expectation value is related to the vector angle as follows:
In[10]:=
-Cos[vecAngle]Φ12
In other words:
〈
-
ψ
|

a
1
.
σ
⊗

a
2
.
σ
|
-
ψ
〉=-cos(
Φ
12
)
Remember this result. We will use it later within Bell’s inequality. But before jumping to Bell’s inequality, let’s explore how above expectation value can be calculated or obtained experimentally using quantum circuits.
For simplicity, let’s consider the case where qubit-1 is measured in Pauli-X basis, and qubit-2 in another basis which obtained by rotating Pauli-X basis by π/8 around z-axis
Define new basis (Pauli-X which is rotated by π/8 around z-axis) and label it:
In[11]:=
newBasis=​​
QuantumBasis
N@
QuantumOperator
["RZ"[π/8]]
QuantumBasis
["X"],​​"Label"​​"
π
8
xz
";
Note I added N, just to enforce numeric calculations, which are faster.
Measure in Pauli-X basis on qubit-1, in new basis on qubit-2, when the system is prepared in
-
ψ
:
In[12]:=
meas=
QuantumMeasurementOperator
["X"]@​​
QuantumMeasurementOperator
[newBasis,{2}]@
QuantumState
["PsiMinus"];
Find the measurement probabilities:
In[13]:=
prob=meas["Probabilities"]
Note the first and last results correspond to + eigenvalue (their multiplication) and middle ones -. So for the mean value, we do as follows:
In[14]:=
prob〚1〛+prob〚4〛-(prob〚2〛+prob〚3〛)
Taking
co
-1
s
of above result (note
〈
-
ψ
|

a
1
.
σ
⊗

a
2
.
σ
|
-
ψ
〉=-cos(
Φ
12
)
) one can confirm:
In[15]:=
ArcCos[-%]π/8
which is what we expected. Now let’s focus on the circuit version.
The following quantum circuit prepare a 2-qubit quantum system in
-
ψ
first, and then two measurements are performed on 2-qubits (as described previously).
In[16]:=
qc1=
QuantumCircuitOperator

QuantumCircuitOperator
[{"X"{1,2},​​"H","CNOT"},​​"Circuit to create
-
ψ
"],\​"RZ"[π/8]2,"H"{1,2},{1},{2};​​qc1["Diagram"]
The above circuit is the one you see in many literature, mostly because that is how you send it to a Quantum Processing Unit (QPU, ie a quantum hardware). However, in our framework, you can define the measurement in any basis, for example:
In[17]:=
qc2=
QuantumCircuitOperator

QuantumCircuitOperator
[{"X"{1,2},​​"H","CNOT"},​​"Circuit to create
-
ψ
"],​​
QuantumMeasurementOperator
["X"],​​
QuantumMeasurementOperator
[newBasis,{2}];​​qc2["Diagram"]
Note that those light purple boxes representing measurement are fundamentally different from other boxes representing usual gates. But that is a different story (
refer to this for more details
).
The above circuits are equivalent. However, for the sake of communicating with a QPU, some transpilers may have some issues with defining measurements for a customized basis. So let’s focus on first circuit:
In[18]:=
qc1["Diagram"]
In above circuit,

a
1
{θ=π/2,ϕ=0}
(measurement on qubit-1) and

a
2
{θ=π/2,ϕ=π/8}
(measurement on qubit-2). Note the Hadamard (H) boxes before measurements are transforming the measurement to Pauli-X, and
R
z
rotation rotates it by an angle in xy-plane. So the correlation function should be
-cos(π/8)
Find the probabilities from above circuit:
In[19]:=
prob1=FullSimplify/@qc1[]["Probabilities"]
Calculate the correlation function:
In[20]:=
prob1​​
QuditName
[{0,0},"Dual"False]+prob1​​
QuditName
[{1,1},​​"Dual"False]-prob1​​
QuditName
[{0,1},"Dual"False]+prob1​​
QuditName
[{1,0},​​"Dual"False]//FullSimplify
which is, of course, what we expected.
Note that the experimental results that one gets out of a QPU is counters per measurement results; something like this:
In[21]:=
exp=qc1[]
Simulate measurement results for 1024 shots:
In[22]:=
counts=Counts[exp["SimulatedMeasurement",1024]]
Calculate the corresponding correlation (using frequency of occurrence for each result):
In[23]:=
counts​​
QuditName
[{0,0},"Dual"False]+​​counts​​
QuditName
[{1,1},"Dual"False]-counts​​
QuditName
[{0,1},"Dual"False]+​​counts​​
QuditName
[{1,0},"Dual"False]1024//​​N
which is what we expected (close enough, given number of shots)
In[24]:=
-Cos[π/8]//N
Now let’s see how those correlations are used in Bell inequality

Bell’s inequality

There are many good literature on the Bell’s inequality and what it implies. If you are looking for a short paper, with some nice [personal] history, we highly recommend this preprint by GianCarlo Ghirardi: John Stuart Bell: recollections of a great scientist and a great man.
Let us rephrase the reasoning behind the derivation of Bell’s inequality (following Ghirardi):
“Experimental Perfect Correlations” ∧ “Bell’s Locality”
⇒
“Determinism” “Determinism” ∧ “Bell’s Locality”
⇒
“Bell’s Inequality” “General Quantum Correlations”
⇒
¬ “Bell’s Inequality” ¬“Bell’s Inequality”
⇒
¬ “Determinism” ∨ ¬“Bell’s Locality” Summarizing: “Natural Processes”
⇒
¬“Bell’s Locality”, i.e.: Nature is non-locally causal.
From locality to determinism. If distant measurements on the singlet state always give opposite results (perfect correlations), and if we insist that what happens at one site cannot depend on what happens at the other (Bell's Locality), then the outcomes must have been fixed in advance, determinism follows as a consequence. If outcomes are predetermined and Bell's Locality holds, then the correlations between measurement results are constrained, they must satisfy Bell's inequality. Quantum mechanics violates the inequality. The correlations predicted by quantum theory (and confirmed by experiment) exceed the bound imposed by Bell's inequality. Something must give. Since the inequality is violated, at least one of its premises fails: either determinism is wrong, or Bell's Locality is wrong (or both). Locality fails regardless. Suppose we try to save things by abandoning determinism. But then we lose the only local explanation for why perfect correlations occur. Without locality, we can't derive determinism, and without determinism, we can't locally account for the perfect correlations we actually observe. So dropping determinism alone doesn't help; locality must fail too.
Well, if anything, let's comment on Bell’s Locality, which implies that measurement probabilities (accessible or not, to observer) at two space-like regions are independent.
Bell’s inequality in the
CHSH form
can be written as follows:
E
μ
(

a
1
,

a
2
)-
E
μ
(

a
1
,

a
4
)+
E
μ
(

a
3
,

a
2
)+
E
μ
(

a
3
,

a
4
)
≤
E
μ
(

a
1
,

a
2
)-
E
μ
(

a
1
,

a
4
)
+
E
μ
(

a
3
,

a
2
)+
E
μ
(

a
3
,

a
4
)
≤2
with μ the accessible variable of the system that specifies the quantum state (eg the preparation step). Note there is another variable in the derivation of Bell’s inequality, usually denoted b λ, which is inaccessible variable specifying the quantum state (the quantum world/level is obtained by averaging over λ).
Also,
E
μ
(

a
i
,

a
j
)
is identified as the quantum expectation value. Assuming that the state is
-
ψ
and using the result for the correlation function (
〈
-
ψ
|

a
1
.
σ
⊗

a
2
.
σ
|
-
ψ
〉=-cos(
Φ
12
)
with
Φ
12
the vector angle between

a
1
and

a
2
), the left-side of above inequality can be written as:
One can obtain those regions (where the Bell’s inequality is violated) explicitly:
One can also find the maximum violation, which happens at π/4:

Explore Bell’s inequality in a quantum circuit

Now let’s calculate the corresponding correlations, using above circuits. We will find those correlations analytically, using our quantum framework. Of course, one can find the numerical value of those correlations (theoretically, by some simulation as shown in the previous section, or experimentally using some QPUs).
Plug them into Bell’s inequality:
Plot the region that Bell’s inequality (above) is violated:
Certainly, the aforementioned circuits may be executed using existing QPUs to obtain empirical correlations. However, such findings hold little value unless we know the details of experimental setting employed, to address problems commonly known as “loopholes” (such as the locality loophole).

Reference

GianCarlo Ghirardi: John Stuart Bell: recollections of a great scientist and a great man, arXiv:1411.1425v1 (2014).
John S. Bell: The Trieste lecture of John Stewart Bell, Journal of Physics A: Mathematical and Theoretical 40, 2919-2933 (2007).

© 2026 Wolfram. All rights reserved.

  • Legal & Privacy Policy
  • Contact Us
  • WolframAlpha.com
  • WolframCloud.com