Tensor Product Ordering
Tensor-product ordering is the convention that says which subsystem is first, which basis vectors appear first in a coordinate column, how local operators are embedded into the full space, and which array axes are contracted in a partial trace.
The abstract Hilbert spaces and are naturally isomorphic when the factors have been identified. Their coordinate representations are not the same object until an ordering convention has been chosen. Most sign errors, swapped qubits, and wrong reduced states in finite-dimensional examples are bookkeeping errors of this kind.
This page is the convention anchor for tensor-product ordering in this volume. The product-basis construction belongs to Product Bases, embedded operators belong to Operators on Composite Systems, and reduced states belong to Partial Trace. Here the focus is how to keep those constructions unambiguous.
Declare the Ordered Factors
Section titled “Declare the Ordered Factors”Always declare the ordered tensor product before using compact labels. For a bipartite system the default convention is
For three factors the default convention is
Then the compact ket
means
The subscript is not decoration. It records the order in which the slots are being read. If one writes and later writes , the labels are being read in different ordered tensor products.
Parentheses do not usually carry physical information in finite tensor products:
Ordering does carry information for coordinates, matrices, and software arrays.
Basis Ordering for Qubits
Section titled “Basis Ordering for Qubits”For two qubits ordered as , the default computational basis order is
This is the order used for coordinate columns and matrix rows unless a page states otherwise. In this convention,
| Array index | Basis state | Bit values |
|---|---|---|
| 0 | ||
| 1 | ||
| 2 | ||
| 3 |
Thus a state
has coordinate column
Equivalently, for ,
For qubits ordered as , the displayed bit string is read left to right:
This is a big-endian convention for displayed bit strings. Other conventions are common in quantum information software and circuit diagrams, so the convention must be stated whenever a calculation depends on array indices.
Coordinate Columns Are Convention Dependent
Section titled “Coordinate Columns Are Convention Dependent”The same abstract vector can have different coordinate columns under different orderings. Conversely, the same column vector can represent different physical states if the ordering convention changes.
For example, in the default order,
represents , meaning
If a calculation silently changes to the order, the same displayed column would be read as , meaning
Those are not the same statement about the subsystems.
The swap map makes the distinction explicit. Define
by
For two qubits, if both spaces use the displayed computational order, the corresponding permutation matrix is
so that
The swap is a real operator or a relabeling map depending on context. A physical swap gate exchanges the states of two subsystems. A bookkeeping permutation only rewrites coordinates in a different ordered basis. State which one is being used.
Operator Ordering
Section titled “Operator Ordering”Operator order follows subsystem order. If
then an operator acting only on is embedded as
An operator acting on and but not is embedded as
only after one has explained how it is placed inside the ordering. In explicit tensor notation, a product operator on and has the form
A genuinely joint operator on and with as spectator is best described by its matrix elements or by a permutation into adjacent factors, application of the joint operator, and permutation back. The identity on the spectator factor cannot simply be omitted from a matrix implementation.
For two factors,
This equation fixes the matrix convention. The row and column labels are ordered pairs. In the default basis, the row label is flattened using the same rule as the state-vector index.
Matrix Example: Acting on the Second Qubit
Section titled “Matrix Example: Acting on the Second Qubit”Let
In the default two-qubit order, the operator that flips the second qubit is
Its matrix in the basis is
The operator that flips the first qubit is
The two matrices are different because they act on different tensor factors. A reliable calculation names the factor, writes the identity factors, and checks the basis order used to flatten the product basis.
Partial-Trace Ordering
Section titled “Partial-Trace Ordering”Partial trace is basis independent as an operator operation, but array formulas require a basis order. For
write a matrix element of as
The reduced state on is obtained by setting the bra and ket labels equal and summing:
The reduced state on is
For three factors ordered as , a density matrix has labels
Tracing out gives an operator on :
In code this is an axis contraction. The axis labels should be named before the contraction is performed. For a density matrix reshaped as
tracing out contracts the second and fifth axes. It does not contract the first and fourth axes, and it does not depend merely on which subsystem has dimension two.
Code Ordering Versus Notation Ordering
Section titled “Code Ordering Versus Notation Ordering”Code has its own ordering rules: row-major and column-major memory layouts, little-endian and big-endian bit strings, and library-specific qubit-numbering conventions. These rules are not wrong, but they are conventions and must be reconciled with the written notation.
Every multi-qubit or multi-subsystem notebook should state:
- the ordered Hilbert space, such as ;
- the basis order used to flatten product states into vectors;
- the index formula used for bit strings or multi-indices;
- the order in which matrix rows and columns are labeled;
- the tensor axes used before reshaping or tracing;
- whether any library uses the opposite bit-endian convention.
The Computational Notebooks page uses this as a reproducibility rule. A notebook should be readable without guessing whether the leftmost displayed bit is the most significant or least significant array index.
How to Document Ordering in Examples
Section titled “How to Document Ordering in Examples”When an example uses two or more tensor factors, include a short convention block before the first vector or matrix. A compact version is:
- Subsystem order. State the ordered Hilbert space.
- Product basis. List the finite basis order or define the multi-index order.
- Vector coordinates. Say how a ket becomes a column vector.
- Operator support. Write identity factors for local operators.
- Reduced states. Say which subsystem is traced out and which remains.
- Code convention. If code is used, state whether its bit order matches the displayed ket order.
For example:
We use and the basis . Array indices are . The operator acts on subsystem . The reduced state is computed as .
This small declaration prevents most ordering ambiguities.
Common Mistakes
Section titled “Common Mistakes”- Treating and as the same coordinate convention.
- Using compact kets such as before declaring the subsystem order.
- Building in code while reading the result as .
- Taking a partial trace over axes chosen by dimension rather than by subsystem label.
- Mixing a displayed big-endian ket convention with a little-endian software convention.
- Calling a bookkeeping permutation a physical swap gate without saying which interpretation is intended.
- Omitting spectator identity factors when constructing many-body or multi-qubit matrices.
Cross-Links
Section titled “Cross-Links”- Notation and Subsystem Labels
- Circuit Model
- Multi-Qubit Gates
- Tensor Products of Hilbert Spaces
- Product Bases
- Operators on Composite Systems
- Local and Global Observables
- Direct Sums versus Tensor Products
- Partial Trace
- Computational Notebooks
- Tensor Product Exercises
- Mathematical Toolkit: Tensor Products
References
Section titled “References”- P. A. M. Dirac, The Principles of Quantum Mechanics, 4th ed., Oxford University Press, 1958.
- R. Shankar, Principles of Quantum Mechanics, 2nd ed., Springer, 1994.
- J. J. Sakurai and J. Napolitano, Modern Quantum Mechanics, 3rd ed., Cambridge University Press, 2020.
- M. A. Nielsen and I. L. Chuang, Quantum Computation and Quantum Information, Cambridge University Press, 2010.
- J. Preskill, Lecture Notes for Physics 219: Quantum Computation, California Institute of Technology, 1998.
Exercises
Section titled “Exercises”- In the default two-qubit basis order, what coordinate column represents ?
Solution
The default order is
Therefore is the third basis vector:
- For a three-qubit register ordered as , write the operator that applies to only.
Solution
The operator is
The identity factors specify that and are spectators.
- Let have components in the order. Write the component formula for tracing out .
Solution
Tracing out sets the row and column labels equal and sums over them:
The remaining operator acts on in the induced order.
- A library labels the rightmost displayed bit as qubit . A page writes with as the first tensor factor. What must an accompanying notebook state before comparing matrices?
Solution
It must state how the library qubit labels map to the written tensor factors. For example, it might say that library qubit corresponds to the written subsystem , qubit to , and qubit to . It should also state the basis-order index rule used to flatten bit strings. Without that map, a matrix comparison can confuse an ordering permutation with a physical difference.