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

  • Getting Started

Guides

  • Wolfram Quantum Computation Framework

Tech Notes

  • Bell's Theorem
  • Circuit Diagram
  • Exploring Fundamentals of Quantum Theory
  • QPU Service Connection
  • Quantum object abstraction
  • Quantum Optimization
  • Second Quantization Functions
  • Tensor Network
  • Quantum Computation

Symbols

  • QuantumBasis
  • QuantumChannel
  • QuantumCircuitMultiwayGraph [EXPERIMENTAL]
  • QuantumCircuitOperator
  • QuantumDistance
  • QuantumEntangledQ
  • QuantumEntanglementMonotone
  • QuantumEvolve
  • QuantumMeasurement
  • QuantumMeasurementOperator
  • QuantumMeasurementSimulation
  • QuantumMPS [EXPERIMENTAL]
  • QuantumOperator
  • QuantumPartialTrace
  • QuantumPhaseSpaceTransform
  • QuantumShortcut [EXPERIMENTAL]
  • QuantumStateEstimate [EXPERIMENTAL]
  • QuantumState
  • QuantumTensorProduct
  • QuantumWignerMICTransform [EXPERIMENTAL]
  • QuantumWignerTransform [EXPERIMENTAL]
  • QuditBasis
  • QuditName
Bell's Theorem
Entangled states, correlations, and measurement
Explore Bell’s inequality in a quantum circuit
Bell’s inequality
Reference
In[51]:=
Column@EntityValue
John Stewart Bell
PERSON
,{"Image","BirthDate","DeathDate","NotableFacts"}
Out[51]=
Thu 28 Jun 1928
Mon 1 Oct 1990
{Originated Bell's theorem in 1964, relating to hidden variable theories in quantum physics,Known for work in superdeterminism and formulation of the paradox known as Bell's spaceship paradox,Worked for most of his career at the European Organization for Nuclear Research (CERN),Nominated for the Nobel Prize in Physics in 1990, but died before the selection was made}
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
ψm=
QuantumState
["PsiMinus"]
1
2
|01〉-
1
2
|10〉
Check if it is an entangled state:
QuantumEntangledQ
[ψm]
True
which is, of course, maximally entangled:
QuantumEntanglementMonotone
[ψm]
1
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):
a[θ_,ϕ_]:={Sin[θ]Cos[ϕ],Sin[θ]Sin[ϕ],Cos[θ]}
Given two unit vectors, let’s find the angle between:
vecAngle=FullSimplify[VectorAngle[a[θ1,ϕ1],a[θ2,ϕ2]],Assumptions{θ1∈Reals,θ2∈Reals,ϕ1∈Reals,ϕ2∈Reals}]
ArcCos[Cos[θ1]Cos[θ2]+Cos[ϕ1-ϕ2]Sin[θ1]Sin[θ2]]
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:
σ[θ_,ϕ_]:=
QuantumOperator
[a[θ,ϕ].Table[PauliMatrix[i],{i,3}]]
Calculate
〈
-
ψ
|
a
1
.
σ
⊗
a
2
.
σ
|
-
ψ
〉
:
ψm["Dagger"]
QuantumTensorProduct
[σ[θ1,ϕ1],σ[θ2,ϕ2]][ψm]
QuantumState
Pure scalar
Qudits: 0
Type: Vector
Dimension: 1
Picture: Schrödinger
​

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:
Φ12=FullSimplify[%["Number"]]
-Cos[θ1]Cos[θ2]-Cos[ϕ1-ϕ2]Sin[θ1]Sin[θ2]
The expectation value is related to the vector angle as follows:
-Cos[vecAngle]Φ12
True
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:
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
-
ψ
:
meas=
QuantumMeasurementOperator
["X"]@
QuantumMeasurementOperator
[newBasis,{2}]@
QuantumState
["PsiMinus"];
Find the measurement probabilities:
prob=meas["Probabilities"]
|

+
0〉0.0190301,|

+
1〉0.48097,|

−
0〉0.48097,|

−
1〉0.0190301
Note the first and last results correspond to + eigenvalue (their multiplication) and middle ones -. So for the mean value, we do as follows:
prob〚1〛+prob〚4〛-(prob〚2〛+prob〚3〛)
-0.92388
Taking
-1
cos
of above result (note
〈
-
ψ
|
a
1
.
σ
⊗
a
2
.
σ
|
-
ψ
〉=-cos(
Φ
12
)
) one can confirm:
ArcCos[-%]π/8
True
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).
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:
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:
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:
prob1=FullSimplify/@qc1[]["Probabilities"]
00
1
2
2
Sin
π
16

,01
1
4
1+Cos
π
8
,10
1
4
1+Cos
π
8
,11
1
2
2
Sin
π
16


Calculate the correlation function:
prob1[
|
00
〉
]+prob1[
|
11
〉
]-(prob1[
|
01
〉
]+prob1[
|
10
〉
])//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:
Simulate measurement results for 1024 shots:
Calculate the corresponding correlation (using frequency of occurrence for each result):
which is what we expected (close enough, given number of shots)
Now let’s see how those correlations are used in Bell inequality
Bell’s inequality
Let us rephrase the reasoning behind the derivation of Bell’s inequality (following Ghirardi):
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).

© 2025 Wolfram. All rights reserved.

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