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

QuantumFramework

Tutorials

  • Getting Started
  • Quantum Object Composition

Guides

  • Wolfram Quantum Computation Framework

Tech Notes

  • Bell's Theorem: CHSH inequality
  • Circuit Diagram
  • Exploring Fundamentals of Quantum Theory
  • QPU Service Connection
  • Quantum object abstraction
  • Quantum Optimization
  • Second Quantization Functions
  • Tensor Network
  • Quantum Computation

Symbols

  • CliffordChannel
  • EinsteinSummation
  • GraphState
  • LocalComplement
  • PauliStabilizer
  • QiskitTarget
  • QuantumBasis
  • QuantumChannel
  • QuantumCircuitMultiwayGraph [EXPERIMENTAL]
  • QuantumCircuitOperator
  • QuantumDistance
  • QuantumEntangledQ
  • QuantumEntanglementMonotone
  • QuantumEvolve
  • QuantumMeasurement
  • QuantumMeasurementOperator
  • QuantumMeasurementSimulation
  • QuantumMPS [EXPERIMENTAL]
  • QuantumOperator
  • QuantumPartialTrace
  • QuantumPhaseSpaceTransform
  • QuantumQASM
  • QuantumShortcut [EXPERIMENTAL]
  • QuantumSimilarity
  • QuantumStateEstimate [EXPERIMENTAL]
  • QuantumState
  • QuantumTensorProduct
  • QuantumWignerMICTransform [EXPERIMENTAL]
  • QuantumWignerTransform [EXPERIMENTAL]
  • QuditBasis
  • QuditName
  • StabilizerFrame
  • StabilizerStateQ
Second Quantization Functions
Bosonic states and operators
Quasi-probability Representations
Details and options
Quasi-probability representations: Applications and options
Basic usage
Advanced examples
This tech note introduces the QuantumFramework implementation of bosonic second quantization on a truncated Fock space. The truncation provides a finite-dimensional representation that is convenient for computation while retaining the structure of common states and operators. The examples below focus on practical workflows for building states, applying operators, and visualizing results in quantum mechanics and quantum optics.
Install and load the QuantumFramework paclet and the second-quantization subpackage (skip the install step if it is already available):
In[4]:=
PacletInstall["https://www.wolfr.am/DevWQCF",ForceVersionInstallTrue]
In[1]:=
<<Wolfram`QuantumFramework`​​<<Wolfram`QuantumFramework`SecondQuantization`
Bosonic states and operators

Fock space size and utilities

SetFockSpaceSize
[size]
Sets size as the default truncation dimension , all the other definitions can use this default size
OperatorVariance
[ψ,op]
Variance of the operator op for a state ψ

States

FockState
[
n
,size]
n-th Fock state in a basis of dimension size
FockState
[{
n
1
,
n
2
,..},size]
Multimode Fock state with occupation numbers
n
i
, with each mode in a basis of dimension size
CoherentState
[size]​​
CoherentState
[size][α]
Parametric state representing a normalized coherent state in a basis of dimension size , the complex amplitude is a parameter
ThermalState
[nbar,size]
Thermal mixed state with the average number of photons nbar in a basis of dimension size
CatState
[size]​​
CatState
[size][α,ϕ]
Parametric general cat state representing a superposition of coherent states in a basis of dimension size, the complex amplitude and the phase are parameters

Operators

AnnihilationOperator
[size, order]
Bosonic annihilation operator in a truncated Fock spacewith basis dimension size and qudit order order
DisplacementOperator
[α,size, order]
Phase space displacement operator of a single mode with complex amplitude alpha , basis dimension size and qudit order order
SqueezeOperator
[ξ,size,order]
Squeeze operator of a single mode with complex parameter xi , basis dimension size and qudit order order
QuadratureOperators
[size,order]
X
1
and
X
2
position and momentum quadrature operators with basis dimension size and qudit order order
PhaseShiftOperator
[θ,size,order]
Phase space rotation operator with rotation angle θ, basis dimension size and qudit order order
BeamSplitterOperator
[{θ,ϕ},size,order]
Two mode beam-splitter operator, θ indicates the reflectivity, ϕ the relative phase in a basis of dimension size and qudit order order
In the sections below, we demonstrate how to use these functions in the QuantumFramework.
Details and options

Operators Mathematical Definitions

DisplacementOperator
Exp[α
†
a
-
*
α
a]
SqueezeOperator
Exp
1
2
ξ
2
a
- ξ
†2
a

PhaseShiftOperator
Exp[ θ
†
a
a]
BeamSplitterOperator
Expθ
 ϕ

a
1
†
a
2
-
- ϕ

†
a
1
a
2

QuadratureOperators
X
1
:
1
2
(a+
†
a
)​​
X
2
:
1
2 
(a-
†
a
)

Displacement operator ordering

By default, when "Ordering" is not specified, normal ordering is used. The formulas for the three orderings are shown below:
DisplacementOperator
[..,"Ordering"st]
st can be "Normal", "Weak" or "Antinormal".​​​​For "Normal", one gets:​​
Exp[-|α
2
|
/2]Exp[α
†
a
]Exp[-αa]
​​​​For "Weak", one gets:​​
Exp[α
†
a
-αa]
​​​​For "Antinormal", one gets:​​
Exp[|α
2
|
/2]Exp[-αa]Exp[α
†
a
]

Squeeze operator ordering

By default, when "Ordering" is not specified, normal ordering is used. The formulas for the three orderings are shown below:
SqueezeOperator
[…,"Ordering"st]
st
can be "Normal", "Antinormal" or "Weak". Given
ξ=
θ
r
​for "Normal", one gets:​
Exp[-
1
2
θ

Tanh[r]
†2
a
]Exp[-Log[Cosh[r]](
†
a
a+
1
2
)]Exp[
1
2
-θ

Tanh[r]
2
a
]
​​For "Weak", one gets:​
Exp[
1
2
(ξ
2
a
-ξ
†2
a
)]
​​For "Antinormal", one gets:​
Exp[
1
2
-θ

Tanh[r]
2
a
]Exp[Log[Cosh[r]](
†
a
a+
1
2
)]Exp[-
1
2
θ

Tanh[r]
†2
a
]

Coherence and correlation functions

G2Coherence
[ψ]
Second-order coherence
(2)
g
(0) for state ψ
G1Correlation
[ψ,{{
r
1
,
t
1
},{
r
2
,
t
2
}}]
First-order correlation function
(1)
G
(
x
1
,
x
2
)
for state ψ at the space and time coordinates
r
1
,
t
1
,
r
2
,
t
2
Basic usage

Setting the space size

The global variable
$FockSize
stores the default truncation size (dimension) of the Fock space. It is used by all second-quantization functions when the size parameter is not explicitly specified.
• Default value: 16
• Use
SetFockSpaceSize[n]
to change the default.
• Use
SetFockSpaceSize[]
to reset to 16.
Note: Larger truncation sizes improve accuracy for high photon-number states, but increase computational cost.
Show the default truncation size:
In[3]:=
$FockSize
Out[3]=
16
Set the truncation size to 20:
In[4]:=
SetFockSpaceSize[20];
Show new truncation size:
In[5]:=
$FockSize
Out[5]=
20
Set the default size again:
In[6]:=
SetFockSpaceSize[];
Show the current truncation size:
In[7]:=
$FockSize
Out[7]=
16

Fock States

Create a single-mode Fock state with occupation number 5 using the default truncation size:
In[10]:=
FockState[5]
Out[10]=
QuantumState
Pure state
Qudits: 1
Type: Vector
Dimension: 16

Create a single-mode Fock state with occupation number 5 using truncation size 10:
In[9]:=
FockState[5,10]
Out[9]=
QuantumState
Pure state
Qudits: 1
Type: Vector
Dimension: 10

Create a two-mode Fock state with occupation numbers 2 and 12:
Verify the shorthand string representation matches the two-mode state:
This shorthand does not work for numbers ≥ 10 because the digits are interpreted as separate qudits:

Annihilation and creation operators

Create a single-mode annihilation operator with the default truncation size:
Create an annihilation operator with truncation size 8 (an 8×8 matrix) using the default mode order {1}:
Create an annihilation operator acting on mode 2 using the default truncation size:
Create an annihilation operator with size 5 acting on mode 3:
Apply the annihilation operator to a Fock state:
Define the creation operator by taking the adjoint (SuperDagger) of the annihilation operator, then apply it to a Fock state:
Or use the "Dagger" property directly:

Coherent state

Create a symbolic coherent state with the default truncation size:

Cat State

Photon distribution of the same state:

Thermal state

Define a parametric thermal state in terms of the mean photon number:
Plot the entropy as a function of the mean photon number:

Displacement operator

Create a displacement operator with truncation size 40 and amplitude 3+:
Verify that displacing the vacuum produces a coherent state:
Specify the mode (order) of the operator with the default size, mode 2 in this case:

Phase shift operator

Matrix form of the phase-shift operator for truncation size 10:
Effect of phase shift on a single-mode symbolic state:
Effect of phase shift on a two-mode superposition state:
Phase shift operator coincides with the "Z" gate for qudits when the angle is 2π/n (up to conjugation):

Squeeze operator

Create a squeeze operator with complex parameter 1+ using the default size:
Plot the non-zero amplitudes of the state:

Beam-Splitter Operator

Transform the state |1,1〉 with the symmetric beam splitter:
Specify the mode order (where the operator acts) and the truncation size:

BeamSplitter operator: Method option

BeamSplitterOperator supports two computation methods via the Method option. The default is MatrixExp which uses direct matrix exponentiation; Recurrence uses an efficient recurrence relation for the beam splitter matrix elements. Performance can vary depending on whether the angle arguments are numeric or exact/symbolic.
Use the "Recurrence" method with exact parameters:

OperatorVariance

Calculate the variance of the quadrature operators for the ground state:
A Fock state has a definite number of photons, so the variance of the number operator is zero:

G2Coherence (Second-Order Coherence)

Improve the result increasing the truncation size:
It is not exactly 2 because of truncation: the thermal distribution has some weight at photon numbers beyond the cutoff.
Consider the mixed state (1-ϵ) |0〉 〈0| + ϵ |2〉 〈2|:
Extreme bunching when ϵ  0:

G1Correlation (first - order correlation)

The first-order correlation is defined for some state |ψ〉 as

Quadrature Operators

Or alternatively because the operator is Hermitian:

Mode Order (Multimode Systems)

Single-mode operator with explicit order:
Verify the property:
Two-mode beam splitter acting on modes 1 and 3:
Displacement operator on mode 3:
Note: When using mode order, all operators in a calculation should use consistent mode assignments. The order parameter does NOT change the Fock space dimension—it only labels which mode the operator acts on.

Error Messages

The following error messages may be generated by second-quantization functions:
Example: FockState index clipping

Ordering option

Displacement and squeeze operators can be defined with different orderings. Use the "Ordering" option to choose "Weak", "Normal", or "Antinormal". In the infinite-dimensional limit these are equivalent, but in a truncated space the numerical error depends on the ordering, so one choice may be more accurate for a given calculation.
Repeat the check using weak ordering:
Amplitudes obtained from a known analytic formula:
Compute absolute errors:
Show the results:

Applications: States and operators

Mean number of photons

Define the annihilation operator and create a random pure state:
Compute the mean number of photons using QuantumMeasurementOperator:
Number operator is Hermitian:
Using the probabilities of the diagonal of the density matrix:

Heisenberg evolution of annihilation operator

Define the Hamiltonian:
Construct the evolution super-operator:
Evolve the operator:
Compare the result to the known result of quantum mechanics:
Quasi-probability Representations
Two phase-space quasi-probability representations are included: Wigner and HusimiQ. They are used extensively in quantum mechanics and quantum optics. Each is computed numerically on a grid of phase-space points and returns an interpolating function. Glauber representation is not included because, for a general state, a stable numerical algorithm is not feasible due to highly singular behavior.
In the sections below, we demonstrate how to use these functions in the QuantumFramework.

Examples

Ground state Wigner Representation:

Compute the Wigner representation on the square region [-4, 4] × [-4, 4]:
Visualize the function in 3D:

HusimiQ Representation of a Fock state

Visualize the density plot of the representation:
Quasi-probability representations: Applications and options

Applications

Expectation values

Compute the Wigner function for the Fock state |2〉:
Phase space integral (normalization):

Marginal distributions

Visualize momentum distribution:
Visualize position distribution:

Squeezed vacuum Wigner Representation

Plot the function, the nonclassical quadrature behavior of squeezed states is visible:

Options

Scaling of the representation for ground state

Set the Gaussian scaling parameter to 0.5:
Visualize the result:

Using GridSize

Compute the Wigner function value at the origin for the Fock state |2〉 using a grid size of 140:
A grid size of 20 is insufficient for this region and yields noticeable numerical error:
The exact value from the analytic expression is:
Compare absolute errors:
Advanced examples

Decay of a coherent state

Set the decay rate γ:
Define the Hamiltonian including photon loss:
State evolution, we can do it symbolically:
Plot the mean photon number as a function of time:
Plot the fidelity with respect to the analytic expression:
Show the results:

Optical balance

Consider the following master equation, which balances a driving field Hamiltonian and single-photon loss:
Set the drive strength g:
Random initial state:
Set up the master equation:
Initial state:
Evolved state:
Photon number expectations and fidelity:
Plot both quantities versus time:

Jaynes-Cummings Model: Calculating the unitary

Define the basis and the relevant operators:
Define the atomic operators and the annihilation operator in second mode:
Going to the interaction picture at resonance, we get a time-independent Hamiltonian and from it we get the unitary operator to evolve states:

Jaynes-Cummings Model: Evolving states

Field in a Fock State

Rabi oscillations when the field is initially in a Fock state
Find the probability of the atom being in the excited state, using the projector as a measurement operator:
Plot the result:
Calculate the evolution for the states |g〉 ⊗ |n〉, varying the number state n:

Coherent state: Collapse and revivals

Atom "thermalization" (atom interacting with a thermal state field)

Reduced density matrix of the atom:
Plot two components of the matrix:
Atom gets "thermalized"; the time-average of the coherences → 0:

Jaynes-Cummings with dissipation

Definition of the basis and the necessary operators:
Parameter setting:
Hamiltonian definition:
Jump operators:
Helper definition to get the probability of finding the atom in the excited state in a time window:
Damped Rabi oscillations:
Define the states:
Define the master equation super-operator:
Calculate the probabilities of the evolved states:
Plot the results:

Driven-Dissipative Kerr Nonlinear Oscillator

The Hamiltonian is:
Define the Hamiltonian:
We take the vacuum as the initial state:
Wigner function snapshots:
We see the steady state resembles a coherent state up to distortion that depends of the parameters, it is known that evolution in Kerr nonlinear oscillators can produce coherent state manifold convergence
Taking the root with less energy:

© 2026 Wolfram. All rights reserved.

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