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
Quick Quantum Computing with Q3
Quantum States in Q3
Measurements in Q3
Operators on Qubits in Q3
Quantum Circuit Model
Q3 provides many utilities and mechanism to facilitate the study of quantum computation and information. In this document, we explain some basic usages of
Q3: Symbolic Quantum Simulation
in the context of quantum computation and quantum information are explained.
For more advanced applications of
Q3: Symbolic Quantum Simulation
, see the Quantum Workbook (2022).
Qubit
A
species
representing a quantum bit or qubit for short.
Ket
Represents a quantum state of a system of
species
.
Basis
Generates the basis of the Hilbert space associated with a system of
species
.
Matrix
Gives the matrix representation of operators on the Hilbert space associated with a system of
species
.
ExpressionFor
Recovers an operator expression from a matrix representation.
Elaborate
Transforms an expression to a more explicit form.
Measurement
Represents a measurement of Pauli operators (including tensor products of single-qubit Pauli operators)
MeasurementOdds
Analyses the probabilities and post-measurement states of a Pauli measurement on a quantum state.
Q3 functions useful in quantum computation and quantum information.
Make sure that the
Q3 package
is loaded to use the demonstrations in this document.
In[1]:=
Needs["QuantumMob`Q3`"]
Quantum States in Q3
A quantum bit, or qubit for short, is a quantum two-level system. It is the elementary unit of quantum computers. Each qubit is associated with a two-dimensional Hilbert space (≃
2

). The computational basis of the Hilbert space is denoted by
{|0〉,|1〉}
.
The Hilbert space associated with a system of
n
qubits is constructed with the tensor product of the Hilbert spaces of individual qubits and is isomorphic to
2

⊗
2

⊗⋯⊗
2

=
⊗n
(
2

)
. The standard tensor-product basis of the Hilbert space is given by
{|
s
1
〉⊗|
s
2
〉⊗⋯⊗|
s
n
〉:
s
k
=0,1}
.
Any quantum state
|ψ〉
in the Hilbert space can be expanded in this basis as
|ψ〉=
1
∑
s
1
=0
1
∑
s
2
=0
⋯
1
∑
s
n
=0
|
s
1
〉⊗|
s
2
〉⊗⋯⊗|
s
n
〉
c
s
1
s
2
⋯s
n
for some complex coefficients
c
s
1
s
2
⋯s
n
.
Q3: Symbolic Quantum Simulation
provides two different ways to represent the computational basis states of an
n
-qubit system.
◼
  • Using
    Ket
    [
    s
    1
    ,
    s
    2
    ,…,
    s
    n
    ]
    to represent tensor-product state
    |
    s
    1
    〉⊗|
    s
    2
    〉⊗⋯⊗|
    s
    n
    〉
    . Although it looks simple, this method becomes quickly tedious as the number of qubits increases. This method is suitable for a small system of qubits.
  • ◼
  • Using
    Ket
    [<|
    S
    [1]
    s
    1
    ,S[2]
    s
    2
    ,…,S[n]
    s
    n
    |>]
    represent tensor-product state
    |
    s
    1
    〉⊗|
    s
    2
    〉⊗⋯⊗|
    s
    n
    〉
    . It may look complicated at the first glance but is more efficient for a larger system of qubits.
  • Method Using
    Ket[…]

    In this method, a computational basis state is represented by
    Ket
    [
    s
    1
    ,
    s
    2
    ,…]
    .
    For example, consider a three-qubit system. Here is the standard tensor-product basis of the system.
    In[2]:=
    bs=Basis[3]
    Out[2]=
    {|0,0,0〉,|0,0,1〉,|0,1,0〉,|0,1,1〉,|1,0,0〉,|1,0,1〉,|1,1,0〉,|1,1,1〉}
    Each state in the above basis is displayed in the bra-ket notation. Internally,
    Ket
    […]
    is used.
    In[3]:=
    InputForm[bs]
    Out[3]//InputForm=
    {Ket[{0, 0, 0}], Ket[{0, 0, 1}], Ket[{0, 1, 0}], Ket[{0, 1, 1}], Ket[{1, 0, 0}],
    Ket[{1, 0, 1}], Ket[{1, 1, 0}], Ket[{1, 1, 1}]}
    A state vector is a linear superposition of the standard basis states.
    In[4]:=
    ket=Ket[{0,1,0}]-I*Ket[{1,0,0}]
    Out[4]=
    |0,1,0〉-|1,0,0〉
    A state vector can be represented by a column vector in the standard tensor-product basis.
    In[5]:=
    vec=Matrix[ket];​​vec//MatrixForm
    Out[6]//MatrixForm=
    0
    0
    1
    0
    -
    0
    0
    0
    The original expression in terms of
    Ket
    […]
    may be recovered with ExpressionFor.
    In[7]:=
    new=ExpressionFor[vec]
    Out[7]=
    |0,1,0〉-|1,0,0〉
    In[8]:=
    new-ket
    Out[8]=
    0

    Method Using
    Ket
    [<|⋯|>]

    In this method, you need to first choose a symbol, say, S, to refer to a set of qubits.
    In[9]:=
    Let[Qubit,S]
    Symbol S declared as qubit can take flavor indices in the form
    S[
    j
    1
    ,
    j
    2
    ,…,μ]
    . The preceding flavor indices
    j
    1
    ,
    j
    2
    ,…
    specifies a particular qubit in the class denoted by the symbol S. The last flavor index
    μ=0,1,2,3,…
    refers to the Pauli operator (
    I,X,Y,Z,…
    , respectively, to be discussed below) on the qubit specified by the preceding indices
    j
    1
    ,
    j
    2
    ,…
    . An exceptional case is
    μ=
    $
    , and
    S[
    j
    1
    ,
    j
    2
    ,…,
    $
    ]
    refers to the qubit itself (rather than an operator) specified by the indices
    j
    1
    ,
    j
    2
    ,…
    .
    Now, a computational basis state is specified by
    Ket
    [<|
    S
    [1,$]
    s
    1
    ,S[2,$]
    s
    2
    ,…,S[n,$]
    s
    n
    |>]
    .
    For example, the logical basis for qubit S[1,$] is comprised of these two states:
    In[10]:=
    v0=Ket[S[1,$]->0]
    v1=Ket[S[1,$]->1]
    Out[10]=
    
    0
    S
    1
    
    Out[11]=
    
    1
    S
    1
    
    They are displayed in the bra-ket notation. Internally,
    Ket
    [<|⋯|>]
    is used:
    In[12]:=
    {v0,v1}//InputForm
    Out[12]//InputForm=
    {Ket[<|S[1, $] -> 0|>], Ket[<|S[1, $] -> 1|>]}
    For a two-qubit system, here is the standard tensor-product basis. Recall that different qubits (within the same class referred to by symbol S) are distinguished by the flavor indices:
    In[15]:=
    bs=Basis[S[1],S[2]]​​bs//InputForm
    Out[15]=
    
    0
    S
    1
    0
    S
    2
    ,
    0
    S
    1
    1
    S
    2
    ,
    1
    S
    1
    0
    S
    2
    ,
    1
    S
    1
    1
    S
    2
    
    Out[16]//InputForm=
    {Ket[<|S[1, $] -> 0, S[2, $] -> 0|>], Ket[<|S[1, $] -> 0, S[2, $] -> 1|>],
    Ket[<|S[1, $] -> 1, S[2, $] -> 0|>], Ket[<|S[1, $] -> 1, S[2, $] -> 1|>]}
    Typing in the special flavor index $ every time you specify a state vector would be cumbersome, and within
    Ket
    […]
    , it can be dropped. (Many other functions in Q3 also allow it.)
    In[17]:=
    v0=Ket[S[1]->0]
    v1=Ket[S[1]->1]
    Out[17]=
    
    0
    S
    1
    
    Out[18]=
    
    1
    S
    1
    
    Note that any unspecified qubit is supposed to be initialized in state
    Ket
    [0]
    .
    In[19]:=
    ket=v0-Iv1​​KetRegulate[ket,{S[1,$],S[2,$]}]​​KetRegulate[ket,{S[1],S[2]}]
    Out[19]=
    
    0
    S
    1
    -
    1
    S
    1
    
    Out[20]=
    
    0
    S
    1
    0
    S
    2
    -
    1
    S
    1
    0
    S
    2
    
    Out[21]=
    
    0
    S
    1
    0
    S
    2
    -
    1
    S
    1
    0
    S
    2
    
    A state vector can be represented by a column vector in the standard tensor-product basis (computational basis). This can be achieved by
    Matrix
    . For example, consider the following state.
    In[22]:=
    ket=S[1,6]**S[2,6]**Ket[]
    Out[22]=
    1
    2
    
    0
    S
    1
    0
    S
    2
    +
    1
    2
    
    0
    S
    1
    1
    S
    2
    +
    1
    2
    
    1
    S
    1
    0
    S
    2
    +
    1
    2
    
    1
    S
    1
    1
    S
    2
    
    Get the column-vector representation of it. Here note that
    S[{1,2}]={S[1],S[2]}
    is equivalent to
    S[{1,2},
    $
    ]={S[1,
    $
    ],S[2,
    $
    ]}
    inside
    Matrix
    .
    In[23]:=
    vec=Matrix[ket,S@{1,2}];​​vec//MatrixForm
    Out[24]//MatrixForm=
    1
    2
    1
    2
    1
    2
    1
    2
    Operators on Qubits in Q3
    Like state vectors, Q3 provides two different ways to represent the Pauli operators.
    Consider a tensor product of single-qubit Pauli operators.
    Consider a state vector.
    You can act operator op on the above state vector using Multiply or, equivalently, **.
    The operator expression may be recovered with ExpressionFor.
    Consider a state vector.
    You can act operator op on the above state vector using Multiply (**).
    It is a good habit to check the standard basis implied in the matrix representation.
    Use the above sets to construct some composite expressions. For example, you can construct
    the Heisenberg Hamiltonian for two spins (qubits).
    Measurements in Q3
    Q3 supports measurement of any Pauli operators (including tensor products of single-qubit Pauli operators).
    As a simple example, consider a three-qubit system in the following state.
    Performing the measurement, you can get random outcomes according to the probabilities shown above.
    Collecting the random outcomes, you can infer the probability distribution.
    As in the above example, one can infer the probability distribution by sampling the outcomes.
    Quantum Circuit Model
    Some frequently used quantum circuit elements in the quantum circuit model of quantum computation.
    Here is an simple example of quantum circuit.
    One can convert a quantum circuit to an analytic expression.
    One can also directly apply a quantum circuit to an input state.
    The above output state should be the same as the result from acting operator expression op.
    It is possible to multiply the quantum circuit with an operator as well.

    © 2025 Wolfram. All rights reserved.

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