Wolfram Language
Paclet Repository
Community-contributed installable additions to the Wolfram Language
Primary Navigation
Categories
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
Create a Paclet
Get Started
Download Definition Notebook
Learn More about
Wolfram Language
QuantumPlaybook
Guides
QuantumPlaybook
Tech Notes
Addition of Numbers
Baker-Hausdorff Lemma
Chiral Fermion Random Circuit
Clifford Operators: How to Test
Commutation Relations for Qubits
Entanglement Distillation
Generalized Pauli Operators: Implementation
Hatano-Nelson-Kitaev Model: Monte Carlo Simulation
Hatano-Nelson Model: Monte Carlo Simulation
Kitaev Chain
Kitaev Random Circuit
Λ-Matter in a Cavity
Measurement of Total Pauli Z
Non-Unitary Dynamics of Quantum States
Partial Trace: Physical Meaning
Quantum Dot Systems
A Quantum Playbook
Magnetic Exchange Coupling
Solovay-Kitaev Algorithm
Spin Code
Symmetry Effects On Quantum Master Equations
Transmon: Quantum Phase Model
Transposition as a Supermap
Variational Quantum Classifier: Iris
Variational Quantum Classifier: Parity
Variational Quantum Eigensolver: Transverse-Field Ising Model
Symbols
BlochEnergy
BlochFunction
QuantumPlaybookCheckUpdate
QuantumPlaybookEdition
QuantumPlaybookUpdate
TransmonEnergy
TransmonExponent
TransmonFunction
TransmonHamiltonian
Addition of Numbers
Here, we introduce a quantum circuit implementation of addition.
Make sure that Q3 is loaded.
I
n
[
3
2
]
:
=
N
e
e
d
s
[
"
Q
u
a
n
t
u
m
M
o
b
`
Q
3
`
"
]
The two numbers to add are initially stored in quantum registers
A
and
B
, respectively. Temporary register
T
is to store the carrier bits.
I
n
[
3
3
]
:
=
L
e
t
[
Q
u
b
i
t
,
A
,
B
,
T
]
Suppose that we added two numbers each represented by
n
binary digits. Note that we need one more bit in the temporary register
T
.
I
n
[
3
4
]
:
=
$
n
=
3
;
k
k
=
R
a
n
g
e
[
$
n
]
;
A
A
=
A
[
k
k
,
$
]
;
B
B
=
B
[
k
k
,
$
]
;
T
T
=
T
[
R
a
n
g
e
[
$
n
+
1
]
,
$
]
;
The result is stored in the register
B
. Note, however, that the last carrier bit is still stored in
T
only.
I
n
[
3
9
]
:
=
e
l
m
=
F
l
a
t
t
e
n
@
T
a
b
l
e
[
{
C
N
O
T
[
{
A
[
k
]
,
B
[
k
]
}
,
T
[
k
+
1
]
]
,
C
N
O
T
[
A
[
k
]
,
B
[
k
]
]
,
C
N
O
T
[
{
B
[
k
]
,
T
[
k
]
}
,
T
[
k
+
1
]
]
,
C
N
O
T
[
T
[
k
]
,
B
[
k
]
]
}
,
{
k
,
$
n
}
]
;
I
n
[
4
0
]
:
=
q
c
=
Q
u
a
n
t
u
m
C
i
r
c
u
i
t
[
S
e
q
u
e
n
c
e
@
@
e
l
m
,
"
I
n
v
i
s
i
b
l
e
"
{
A
[
$
n
+
1
/
2
]
,
B
[
$
n
+
1
/
2
]
}
]
O
u
t
[
4
0
]
=
I
n
[
4
1
]
:
=
b
s
=
B
a
s
i
s
[
A
A
,
B
B
]
;
I
n
[
4
2
]
:
=
E
c
h
o
T
i
m
i
n
g
[
o
u
t
=
q
c
*
*
b
s
;
]
⌚
2
.
3
4
4
2
8
I
n
[
4
3
]
:
=
a
b
=
{
F
r
o
m
D
i
g
i
t
s
[
R
e
v
e
r
s
e
[
#
@
A
A
]
,
2
]
,
F
r
o
m
D
i
g
i
t
s
[
R
e
v
e
r
s
e
[
#
@
B
B
]
,
2
]
}
&
/
@
b
s
;
c
c
=
F
r
o
m
D
i
g
i
t
s
[
R
e
v
e
r
s
e
@
J
o
i
n
[
#
@
B
B
,
#
@
T
@
{
$
n
+
1
}
]
,
2
]
&
/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
1
]
]
,
C
N
O
T
[
A
[
k
]
,
B
[
k
]
]
,
C
N
O
T
[
{
B
[
k
]
,
T
[
k
]
}
,
T
[
k
+
1
]
]
}
,
{
k
,
$
n
}
]
;
I
n
[
4
7
]
:
=
q
c
=
Q
u
a
n
t
u
m
C
i
r
c
u
i
t
[
S
e
q
u
e
n
c
e
@
@
e
l
m
,
"
I
n
v
i
s
i
b
l
e
"
{
A
[
$
n
+
1
/
2
]
,
B
[
$
n
+
1
/
2
]
}
]
O
u
t
[
4
7
]
=
To extract the sum, you need to consider both registers
B
and
T
.