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`
ExpressionFor
​
ExpressionFor
[mat]
returns the operator expression corresponding to the matrix representation
mat
.
​
​
ExpressionFor
[vec]
returns the state vector corresponding to the column vector representation
vec
.
​
​
ExpressionFor
[mat,{
s
1
,
s
2
,…}]
returns the operator expression corresponding to the matrix representation
mat
and acting on the system consisting of the species
{
s
1
,
s
2
,…}
.
​
​
ExpressionFor
[vec,{
s
1
,
s
2
,…}]
returns the state vector corresponding to the column vector representation
vec
and acting on the system consisting of the species
{
s
1
,
s
2
,…}
.
​
​
ExpressionFor
[mat,s]
is equivalent to
ExpressionFor
[mat,{s}]
.
​
​
ExpressionFor
[vec,s]
is equivalent to
ExpressionFor
[vec,{s}]
.
​
Details and Options

Examples  
(11)
Basic Examples  
(10)
Consider an operator expression in terms of
Pauli
[…]
for unlabeled qubits.
In[1]:=
expr=Pauli[{1,1}]+Pauli[{2,2}]+JPauli[{3,3}]
Out[1]=
X⊗X+Y⊗Y+JZ⊗Z
This is the matrix representation in the standard basis.
In[2]:=
mat=Matrix[expr];​​mat//MatrixForm
Out[2]//MatrixForm=
J
0
0
0
0
-J
2
0
0
2
-J
0
0
0
0
J
This converts the matrix representation back to the operator expression.
In[3]:=
new=ExpressionFor[mat]​​Elaborate[new]
Out[3]=
JZ⊗Z+2
+
X
⊗
-
X
+2
-
X
⊗
+
X
Out[3]=
X⊗X+Y⊗Y+JZ⊗Z
​
Next, consider a state vector in terms of
Ket
[…]
for unlabeled qubits.
In[1]:=
ket=Ket[{0,0}]+I*Ket[{0,1}]-I*Ket[{1,0}]
Out[1]=
|0,0〉+|0,1〉-|1,0〉
This is the column vector representation of the state vector in the standard basis.
In[2]:=
vec=Matrix[ket];​​vec//Normal
Out[2]=
{1,,-,0}
This converts the column vector back to the state-vector expression.
In[3]:=
new=ExpressionFor[vec]​​new-ket
Out[3]=
|0,0〉+|0,1〉-|1,0〉
Out[3]=
0
​
In[1]:=
Let[Qubit,S]
Consider an operator expression for labeled qubits.
In[2]:=
op=1+S[1,2]+S[1,3]**S[2,1]
Out[2]=
1+
Z
S
1
X
S
2
+
Y
S
1
This is the matrix representation of the above operator in the standard basis for qubits S[1,$] and S[2,$] involved in the expression. In many cases,
Matrix
automatically extract the relevant qubits.
In[3]:=
mat=Matrix[op];​​mat//MatrixForm
Out[3]//MatrixForm=
1
1
-
0
1
1
0
-

0
1
-1
0

-1
1
This converts the matrix representation back to an operator expression.
In[4]:=
new=ExpressionFor[mat,S@{1,2}]​​Elaborate[new]
Out[4]=
1+
Z
S
1
+
S
2
+
Z
S
1
-
S
2
-
+
S
1
+
-
S
1
Out[4]=
1+
Z
S
1
X
S
2
+
Y
S
1
As you note above,
ExpressionFor
returns the expression in terms of the raising and lowering operators. If you want it in terms of the Pauli X and Y operators, use
Elaborate
.
In[5]:=
expr=Elaborate[new]
Out[5]=
1+
Z
S
1
X
S
2
+
Y
S
1
In[6]:=
RaisingLoweringForm[expr]
Out[6]=
1+
Z
S
1
+
S
2
+
Z
S
1
-
S
2
-
+
S
1
+
-
S
1
In[7]:=
op-new//Elaborate
Out[7]=
0
​
Consider a state vector expressed in terms of
Ket
[<|…|>]
for labeled qubits.
In[1]:=
ket=(3Ket[]+4IKet[S[1]1,S[2]1])/5//KetRegulate
Out[1]=
1
5
3
0
S
1
0
S
2
+4
1
S
1
1
S
2

In the standard basis for qubits, S[1,$] and S[2,$], it has the following column vector representation.
In[2]:=
vec=Matrix[ket];​​vec//MatrixForm
Out[2]//MatrixForm=
3
5
0
0
4
5
This converts the column vector back to the state-vector expression.
In[3]:=
new=ExpressionFor[vec,S@{1,2}]​​ket-new//Simplify
Out[3]=
3
5

0
S
1
0
S
2
+
4
5

1
S
1
1
S
2

Out[3]=
0
​
Matrix
also converts state expression in terms of
Bra
[<|…|>]
into a row vector representation. However, Mathematica does not distinguish row and column vectors.
In[1]:=
bra=Dagger[ket]​​vec=Matrix[bra];​​vec//MatrixForm
Out[1]=
1
5
3
0
S
1
0
S
2
-4
1
S
1
1
S
2

Out[1]//MatrixForm=
3
5
0
0
-
4
5
​
Let us now consider a system of qudits.
Here is a state vector.
The column vector representation of the state vector in the standard basis is given as follows.
​
Consider an operator on a system of qudits.
This is its matrix representation in the standard basis.
This converts the matrix representation back to an operator expression.
It looks different from the original operator. However, if you take into account the closure relation, then the two expressions are the same.
​
Spin objects with spin=1/2 are essentially the same as qubits.
Here is an operator we want to examine.
This is its matrix representation in the standard basis.
This converts the matrix representation back to the operator expression.
Here is a state vector.
The column vector representation is as follows.
This converts the column vector representation back to the state vector.
​
Let us now consider a bigger spin.
​
As the Hilbert space associated with fermions is finite dimensional, one can find an operator expression for fermions from a matrix representation in a systematic way.
For example, consider a tight-biding Hamiltonian.
As the conversion of the matrix representation into the operator expression involves the Jordan-Wigner transformation, it is a bit slower for fermions.
Compare the above evaluation with the one for the Pauli operators (for labeled qubits).
As it does not involve the Jordan-Wigner transformation, the evaluation is faster than for Fermions.

© 2025 Wolfram. All rights reserved.

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