Wolfram.com
WolframAlpha.com
WolframCloud.com
Wolfram Language
Example Repository
Ready-to-use examples for the Wolfram Language
Primary Navigation
Categories
Astronomy
Audio Processing
Calculus
Cellular Automata
Chemistry
Complex Systems
Computer Science
Computer Vision
Control Systems
Creative Arts
Data Science
Engineering
Finance & Economics
Finite Element Method
Food & Nutrition
Geography
Geometry
Graphs & Networks
Image Processing
Life Sciences
Machine Learning
Mathematics
Optimization
Physics
Puzzles and Recreation
Quantum Computation
Signal Processing
Social Sciences
System Modeling
Text & Language Processing
Time-Related Computation
Video Processing
Visualization & Graphics
Alphabetical List
Submit a New Resource
Learn More about
Wolfram Language
Related Pages
Related Categories
Computer Science
Mathematics
Physics
Quantum Computation
Compute the Expectation Value of a Quantum Operator
Example Notebook
Open in Cloud
Download Notebook
The expectation value of an operator with respect to a quantum state can be computed in different ways.
Install the QuantumFramework paclet:
I
n
[
1
]
:
=
P
a
c
l
e
t
I
n
s
t
a
l
l
[
"
W
o
l
f
r
a
m
/
Q
u
a
n
t
u
m
F
r
a
m
e
w
o
r
k
"
]
;
Load the paclet:
I
n
[
2
]
:
=
N
e
e
d
s
[
"
W
o
l
f
r
a
m
`
Q
u
a
n
t
u
m
F
r
a
m
e
w
o
r
k
`
"
]
;
Create a many-body random mixed state:
I
n
[
3
]
:
=
q
s
=
Q
u
a
n
t
u
m
S
t
a
t
e
[
"
R
a
n
d
o
m
M
i
x
e
d
"
[
3
]
,
"
L
a
b
e
l
"
"
ρ
"
]
O
u
t
[
3
]
=
Q
u
a
n
t
u
m
S
t
a
t
e
M
i
x
e
d
s
t
a
t
e
Q
u
d
i
t
s
:
3
T
y
p
e
:
M
a
t
r
i
x
D
i
m
e
n
s
i
o
n
:
8
Create a random many-body Hermitian operator:
I
n
[
4
]
:
=
o
p
=
Q
u
a
n
t
u
m
O
p
e
r
a
t
o
r
[
"
R
a
n
d
o
m
H
e
r
m
i
t
i
a
n
"
,
R
a
n
g
e
[
3
]
,
"
L
a
b
e
l
"
"
R
a
n
d
o
m
H
e
r
m
i
t
i
a
n
"
]
O
u
t
[
4
]
=
Q
u
a
n
t
u
m
O
p
e
r
a
t
o
r
P
i
c
t
u
r
e
:
S
c
h
r
o
d
i
n
g
e
r
A
r
i
t
y
:
3
D
i
m
e
n
s
i
o
n
:
8
→
8
Q
u
d
i
t
s
:
3
→
3
Calculate
〈
A
〉
=
T
r
[
A
.
ρ
]
, which is the expectation value of the operator
A
, given the density matrix
ρ
:
I
n
[
5
]
:
=
T
r
[
o
p
[
"
M
a
t
r
i
x
"
]
.
q
s
[
"
D
e
n
s
i
t
y
M
a
t
r
i
x
"
]
]
/
/
C
h
o
p
O
u
t
[
5
]
=
0
.
1
0
6
4
1
7
One can feed the density matrix into a circuit to find the expectation value:
I
n
[
6
]
:
=
q
c
=
Q
u
a
n
t
u
m
C
i
r
c
u
i
t
O
p
e
r
a
t
o
r
[
{
q
s
[
"
B
e
n
d
"
]
,
o
p
,
S
e
q
u
e
n
c
e
@
@
T
a
b
l
e
[
"
C
a
p
"
{
i
,
i
+
3
}
,
{
i
,
3
}
]
}
]
;
q
c
[
"
D
i
a
g
r
a
m
"
]
O
u
t
[
6
]
=
Evaluate the circuit and get the scalar result:
I
n
[
7
]
:
=
q
c
[
]
[
"
S
c
a
l
a
r
"
]
/
/
C
h
o
p
O
u
t
[
7
]
=
0
.
1
0
6
4
1
7
Transform the density matrix into an operator, then do partial tracing:
I
n
[
8
]
:
=
Q
u
a
n
t
u
m
P
a
r
t
i
a
l
T
r
a
c
e
[
o
p
[
q
s
[
"
O
p
e
r
a
t
o
r
"
]
]
]
[
"
S
c
a
l
a
r
"
]
/
/
C
h
o
p
O
u
t
[
8
]
=
0
.
1
0
6
4
1
7
Measure the operator, given the state, and find the mean value:
I
n
[
9
]
:
=
Q
u
a
n
t
u
m
M
e
a
s
u
r
e
m
e
n
t
O
p
e
r
a
t
o
r
[
o
p
]
[
q
s
]
[
"
M
e
a
n
"
]
/
/
C
h
o
p
O
u
t
[
9
]
=
0
.
1
0
6
4
1
7
See Also
Wolfram/QuantumFramework
Publisher Information
Contributed by:
Wolfram Research, Quantum Computation Framework Team