Skip to content

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 HA⊗HB\mathcal H_A\otimes\mathcal H_B and HB⊗HA\mathcal H_B\otimes\mathcal H_A 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.

Always declare the ordered tensor product before using compact labels. For a bipartite system the default convention is

HAB=HA⊗HB.\mathcal H_{AB} = \mathcal H_A\otimes\mathcal H_B.

For three factors the default convention is

HABC=HA⊗HB⊗HC.\mathcal H_{ABC} = \mathcal H_A\otimes\mathcal H_B\otimes\mathcal H_C.

Then the compact ket

∣ijk⟩ABC\lvert i j k\rangle_{ABC}

means

∣i⟩A⊗∣j⟩B⊗∣k⟩C.\lvert i\rangle_A \otimes \lvert j\rangle_B \otimes \lvert k\rangle_C.

The subscript is not decoration. It records the order in which the slots are being read. If one writes ∣ij⟩AB\lvert ij\rangle_{AB} and later writes ∣ji⟩BA\lvert ji\rangle_{BA}, the labels are being read in different ordered tensor products.

Parentheses do not usually carry physical information in finite tensor products:

(HA⊗HB)⊗HC≃HA⊗(HB⊗HC).(\mathcal H_A\otimes\mathcal H_B)\otimes\mathcal H_C \simeq \mathcal H_A\otimes(\mathcal H_B\otimes\mathcal H_C).

Ordering does carry information for coordinates, matrices, and software arrays.

For two qubits ordered as A,BA,B, the default computational basis order is

∣00⟩,∣01⟩,∣10⟩,∣11⟩.\lvert00\rangle,\quad \lvert01\rangle,\quad \lvert10\rangle,\quad \lvert11\rangle.

This is the order used for coordinate columns and matrix rows unless a page states otherwise. In this convention,

Array indexBasis stateBit values
0∣00⟩\lvert00\ranglea=0, b=0a=0,\ b=0
1∣01⟩\lvert01\ranglea=0, b=1a=0,\ b=1
2∣10⟩\lvert10\ranglea=1, b=0a=1,\ b=0
3∣11⟩\lvert11\ranglea=1, b=1a=1,\ b=1

Thus a state

∣Ψ⟩=c00∣00⟩+c01∣01⟩+c10∣10⟩+c11∣11⟩\lvert\Psi\rangle = c_{00}\lvert00\rangle +c_{01}\lvert01\rangle +c_{10}\lvert10\rangle +c_{11}\lvert11\rangle

has coordinate column

(c00c01c10c11).\begin{pmatrix} c_{00}\\ c_{01}\\ c_{10}\\ c_{11} \end{pmatrix}.

Equivalently, for a,b∈{0,1}a,b\in\{0,1\},

index⁡(ab)=2a+b.\operatorname{index}(ab) = 2a+b.

For nn qubits ordered as 1,2,…,n1,2,\ldots,n, the displayed bit string is read left to right:

index⁡(a1a2⋯an)=∑r=1nar 2n−r.\operatorname{index}(a_1a_2\cdots a_n) = \sum_{r=1}^{n} a_r\,2^{n-r}.

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 ABAB order,

(0100)AB\begin{pmatrix} 0\\ 1\\ 0\\ 0 \end{pmatrix}_{AB}

represents ∣01⟩AB\lvert01\rangle_{AB}, meaning

∣0⟩A⊗∣1⟩B.\lvert0\rangle_A\otimes\lvert1\rangle_B.

If a calculation silently changes to the BABA order, the same displayed column would be read as ∣01⟩BA\lvert01\rangle_{BA}, meaning

∣0⟩B⊗∣1⟩A.\lvert0\rangle_B\otimes\lvert1\rangle_A.

Those are not the same statement about the subsystems.

The swap map makes the distinction explicit. Define

SAB:HA⊗HB⟶HB⊗HAS_{AB} : \mathcal H_A\otimes\mathcal H_B \longrightarrow \mathcal H_B\otimes\mathcal H_A

by

SAB(∣i⟩A⊗∣j⟩B)=∣j⟩B⊗∣i⟩A.S_{AB} \bigl( \lvert i\rangle_A\otimes\lvert j\rangle_B \bigr) = \lvert j\rangle_B\otimes\lvert i\rangle_A.

For two qubits, if both spaces use the displayed computational order, the corresponding permutation matrix is

S=(1000001001000001),S = \begin{pmatrix} 1&0&0&0\\ 0&0&1&0\\ 0&1&0&0\\ 0&0&0&1 \end{pmatrix},

so that

S∣00⟩=∣00⟩,S∣01⟩=∣10⟩,S∣10⟩=∣01⟩,S∣11⟩=∣11⟩.S\lvert00\rangle=\lvert00\rangle,\quad S\lvert01\rangle=\lvert10\rangle,\quad S\lvert10\rangle=\lvert01\rangle,\quad S\lvert11\rangle=\lvert11\rangle.

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 order follows subsystem order. If

HABC=HA⊗HB⊗HC,\mathcal H_{ABC} = \mathcal H_A\otimes\mathcal H_B\otimes\mathcal H_C,

then an operator acting only on BB is embedded as

IA⊗OB⊗IC.I_A\otimes O_B\otimes I_C.

An operator acting on AA and CC but not BB is embedded as

OACO_{AC}

only after one has explained how it is placed inside the ABCABC ordering. In explicit tensor notation, a product operator on AA and CC has the form

OA⊗IB⊗OC.O_A\otimes I_B\otimes O_C.

A genuinely joint operator on AA and CC with BB 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,

AB⟨ij∣(A⊗B)∣kl⟩AB=AikBjl.{}_{AB}\langle ij\vert (A\otimes B) \vert kl\rangle_{AB} = A_{ik}B_{jl}.

This equation fixes the matrix convention. The row and column labels are ordered pairs. In the default ABAB basis, the row label ijij 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

X=(0110).X = \begin{pmatrix} 0&1\\ 1&0 \end{pmatrix}.

In the default two-qubit ABAB order, the operator that flips the second qubit is

IA⊗XB.I_A\otimes X_B.

Its matrix in the basis ∣00⟩,∣01⟩,∣10⟩,∣11⟩\lvert00\rangle,\lvert01\rangle,\lvert10\rangle,\lvert11\rangle is

I⊗X=(0100100000010010).I\otimes X = \begin{pmatrix} 0&1&0&0\\ 1&0&0&0\\ 0&0&0&1\\ 0&0&1&0 \end{pmatrix}.

The operator that flips the first qubit is

XA⊗IB=(0010000110000100).X_A\otimes I_B = \begin{pmatrix} 0&0&1&0\\ 0&0&0&1\\ 1&0&0&0\\ 0&1&0&0 \end{pmatrix}.

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 is basis independent as an operator operation, but array formulas require a basis order. For

HAB=HA⊗HB,\mathcal H_{AB} = \mathcal H_A\otimes\mathcal H_B,

write a matrix element of ρAB\rho_{AB} as

ρab,a′b′.\rho_{a b,a' b'}.

The reduced state on AA is obtained by setting the BB bra and ket labels equal and summing:

(ρA)aa′=∑bρab,a′b.(\rho_A)_{a a'} = \sum_b \rho_{a b,a' b}.

The reduced state on BB is

(ρB)bb′=∑aρab,ab′.(\rho_B)_{b b'} = \sum_a \rho_{a b,a b'}.

For three factors ordered as A,B,CA,B,C, a density matrix has labels

ρabc,a′b′c′.\rho_{a b c,a' b' c'}.

Tracing out BB gives an operator on HA⊗HC\mathcal H_A\otimes\mathcal H_C:

(ρAC)ac,a′c′=∑bρabc,a′bc′.(\rho_{AC})_{a c,a' c'} = \sum_b \rho_{a b c,a' b c'}.

In code this is an axis contraction. The axis labels should be named before the contraction is performed. For a density matrix reshaped as

ρ[a,b,c,a′,b′,c′],\rho[a,b,c,a',b',c'],

tracing out BB 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 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 HA⊗HB⊗HC\mathcal H_A\otimes\mathcal H_B\otimes\mathcal H_C;
  • 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.

When an example uses two or more tensor factors, include a short convention block before the first vector or matrix. A compact version is:

  1. Subsystem order. State the ordered Hilbert space.
  2. Product basis. List the finite basis order or define the multi-index order.
  3. Vector coordinates. Say how a ket becomes a column vector.
  4. Operator support. Write identity factors for local operators.
  5. Reduced states. Say which subsystem is traced out and which remains.
  6. Code convention. If code is used, state whether its bit order matches the displayed ket order.

For example:

We use HAB=HA⊗HB\mathcal H_{AB}=\mathcal H_A\otimes\mathcal H_B and the basis ∣00⟩,∣01⟩,∣10⟩,∣11⟩\lvert00\rangle,\lvert01\rangle,\lvert10\rangle,\lvert11\rangle. Array indices are index⁡(ab)=2a+b\operatorname{index}(ab)=2a+b. The operator I⊗XI\otimes X acts on subsystem BB. The reduced state ρA\rho_A is computed as (ρA)aa′=∑bρab,a′b(\rho_A)_{a a'}=\sum_b\rho_{a b,a' b}.

This small declaration prevents most ordering ambiguities.

  • Treating HA⊗HB\mathcal H_A\otimes\mathcal H_B and HB⊗HA\mathcal H_B\otimes\mathcal H_A as the same coordinate convention.
  • Using compact kets such as ∣ij⟩\lvert ij\rangle before declaring the subsystem order.
  • Building OA⊗IBO_A\otimes I_B in code while reading the result as IA⊗OBI_A\otimes O_B.
  • 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.
  • 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.
  1. In the default two-qubit basis order, what coordinate column represents ∣10⟩AB\lvert10\rangle_{AB}?
Solution

The default order is

∣00⟩,∣01⟩,∣10⟩,∣11⟩.\lvert00\rangle,\quad \lvert01\rangle,\quad \lvert10\rangle,\quad \lvert11\rangle.

Therefore ∣10⟩AB\lvert10\rangle_{AB} is the third basis vector:

(0010).\begin{pmatrix} 0\\ 0\\ 1\\ 0 \end{pmatrix}.
  1. For a three-qubit register ordered as A,B,CA,B,C, write the operator that applies ZZ to BB only.
Solution

The operator is

IA⊗ZB⊗IC.I_A\otimes Z_B\otimes I_C.

The identity factors specify that AA and CC are spectators.

  1. Let ρABC\rho_{ABC} have components ρabc,a′b′c′\rho_{a b c,a' b' c'} in the A,B,CA,B,C order. Write the component formula for tracing out BB.
Solution

Tracing out BB sets the BB row and column labels equal and sums over them:

(ρAC)ac,a′c′=∑bρabc,a′bc′.(\rho_{AC})_{a c,a' c'} = \sum_b \rho_{a b c,a' b c'}.

The remaining operator acts on HA⊗HC\mathcal H_A\otimes\mathcal H_C in the induced A,CA,C order.

  1. A library labels the rightmost displayed bit as qubit 00. A page writes ∣q1q2q3⟩\lvert q_1 q_2 q_3\rangle with q1q_1 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 00 corresponds to the written subsystem CC, qubit 11 to BB, and qubit 22 to AA. 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.