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

Q3mini

Guides

  • Fermionic Quantum Computation
  • Q3: Symbolic Quantum Simulation
  • Quantum Information Systems
  • Quantum Many-Body Systems
  • Quantum Spin Systems

Tech Notes

  • About Q3
  • Q3: Quick Start
  • Quantum Fourier Transform
  • Quantum Information Systems with Q3
  • Quantum Many-Body Systems with Q3
  • Quantum Operations
  • Quantum Spin Systems with Q3
  • Quantum States
  • Quantum Teleportation
  • Quick Quantum Computing with Q3

Symbols

  • Basis
  • Boson
  • Bra
  • CNOT
  • ControlledGate
  • ExpressionFor
  • Fermion
  • Heisenberg
  • Ket
  • Let
  • Majorana
  • Matrix
  • Multiply
  • NambuGreen
  • NambuHermitian
  • NambuMatrix
  • NambuUnitary
  • Pauli
  • Phase
  • QuantumCircuit
  • Qubit
  • Qudit
  • RandomWickCircuitSimulate
  • Rotation
  • Species
  • Spin
  • SWAP
  • WickCircuit
  • WickEntanglementEntropy
  • WickEntropy
  • WickGreenFunction
  • WickJump
  • WickLindbladSolve
  • WickLogarithmicNegativity
  • WickMeasurement
  • WickMonitor
  • WickMutualInformation
  • WickNonunitary
  • WickSimulate
  • WickState
  • WickUnitary

Overviews

  • The Postulates of Quantum Mechanics
  • Quantum Algorithms
  • Quantum Computation: Models
  • Quantum Computation: Overview
  • Quantum Error-Correction Codes
  • Quantum Information Theory
  • Quantum Noise and Decoherence
QuantumMob`Q3mini`
CNOT
​
CNOT
[c,t]
represents the
CNOT
gate on the two qubits
c
and
t
, which are the control and target qubits, respectively.
​
​
CNOT
[{
c
1
,
c
2
,…},{
t
1
,
t
2
,…}]
represents the multi-control and multi-target NOT gate flipping the bits of the target qubits
{
t
1
,
t
2
,…}
condition on the values of the control qubits
{
c
1
,
c
2
,…}
.
​
​
CNOT
[{
c
1

v
1
,
c
2

v
2
,…},{
t
1
,
t
2
,…}]
represents a variation of the CNOT gate, which flips the target qubits
t
1
,
t
2
,…
when the control qubits
c
1
,
c
2
,…
take the values
v
1
,
v
2
,…
, respectively.
​
​
CNOT
[cv,…]
is converted to
CNOT
[{cv},…]
.
​
​
CNOT
[{
c
1
,
c
2
,…}v,…]
is converted to
CNOT
[{
c
1
v,
c
2
v,…},…]
.
​
Details and Options

Examples  
(8)
Basic Examples  
(6)
Let us choose symbol S to refer to a quantum register of two (or more) qubits.
In[1]:=
Let[Qubit,S]
The first qubit is the control qubit and the second is the target qubit.
In[2]:=
cn=CNOT[S[1,$],S[2,$]]
Out[2]=
CNOT[{
S
1
1},{
S
2
}]
The last flavor index
$
may be dropped since it is clear from the context.
In[3]:=
cn=CNOT[S[1],S[2]]
Out[3]=
CNOT[{
S
1
1},{
S
2
}]
In the quantum circuit model, the CNOT gate is displayed as follows.
In[4]:=
qc=QuantumCircuit[cn]
Out[4]=
​
In[1]:=
Let[Qubit,S]
Take the computational basis states as input.
In[2]:=
in=Basis[S@{1,2}](*Thisisashort-handformofBasis[S[{1,2,},$]].*)
Out[2]=

0
S
1
0
S
2
,
0
S
1
1
S
2
,
1
S
1
0
S
2
,
1
S
1
1
S
2

Here are the results of applying the CNOT gate on the computational basis states.
In[3]:=
out=qc**in(*Thisisequivalenttocn**in*)
Out[3]=

0
S
1
0
S
2
,
0
S
1
1
S
2
,
1
S
1
1
S
2
,
1
S
1
0
S
2

Compare the input and output states.
In[4]:=
Thread[inout]//TableForm
Out[4]//TableForm=
​
In[1]:=
Let[Qubit,S]
Consider a multi-control NOT gate.
In[2]:=
qc=QuantumCircuit[CNOT[S@{1,2},S[3]]]
Out[2]=
In[3]:=
op=ExpressionFor[qc]
Out[3]=
3
4
-
1
4
Z
S
1
Z
S
2
-
1
4
Z
S
1
X
S
3
-
1
4
Z
S
2
X
S
3
+
1
4
Z
S
1
Z
S
2
X
S
3
+
1
4
Z
S
1
+
1
4
Z
S
2
+
1
4
X
S
3
In[4]:=
mat=Matrix[qc];​​mat//MatrixForm
Out[4]//MatrixForm=
1
0
0
0
0
0
0
0
0
1
0
0
0
0
0
0
0
0
1
0
0
0
0
0
0
0
0
1
0
0
0
0
0
0
0
0
1
0
0
0
0
0
0
0
0
1
0
0
0
0
0
0
0
0
0
1
0
0
0
0
0
0
1
0
​
In[1]:=
Let[Qubit,S]
In[2]:=
qc=QuantumCircuit[CNOT[S@{1,2}{1,0},S[3]]]​​op=ExpressionFor[qc]
Out[2]=
Out[2]=
3
4
+
1
4
Z
S
1
Z
S
2
-
1
4
Z
S
1
X
S
3
+
1
4
Z
S
2
X
S
3
-
1
4
Z
S
1
Z
S
2
X
S
3
+
1
4
Z
S
1
-
1
4
Z
S
2
+
1
4
X
S
3
In[3]:=
new=QuantumCircuit[S[2,1],CNOT[S@{1,2},S[3]],S[2,1]]
Out[3]=
In[4]:=
qc-new//Elaborate
Out[4]=
0
​
In[1]:=
Let[Qubit,S]
The CNOT gate is closely related to the CZ (controlled-Z) and SWAP gates.
In[2]:=
cz=CZ[S[1],S[2]]​​swap=SWAP[S[1],S[2]]
Out[2]=
CZ[{
S
1
,
S
2
}]
Out[2]=
SWAP[
S
1
,
S
2
]
In[3]:=
Elaborate[cz]​​Elaborate[swap]
Out[3]=
1
2
-
1
2
Z
S
1
Z
S
2
+
1
2
Z
S
1
+
1
2
Z
S
2
Out[3]=
1
2
+
1
2
X
S
1
X
S
2
+
1
2
Y
S
1
Y
S
2
+
1
2
Z
S
1
Z
S
2
In[4]:=
Matrix[cz]//MatrixForm​​Matrix[swap]//MatrixForm
Out[4]//MatrixForm=
1
0
0
0
0
1
0
0
0
0
1
0
0
0
0
-1
Out[4]//MatrixForm=
1
0
0
0
0
0
1
0
0
1
0
0
0
0
0
1
Compare the quantum circuit representations of the gates.
​
The CNOT, CZ, and SWAP gates are expanded automatically when necessary.

© 2025 Wolfram. All rights reserved.

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