Simple Algorithm
Quantum Computing · Rydberg State · 24 min

Kronecker Products & Ordering Conventions

Endianness, qubit ordering and getting the matrices right.

The tensor product is canonical; its matrices are not. Turning HA⊗HB\Hil_A\otimes\Hil_B into arrays of numbers requires an ordered basis, and two incompatible orderings are in daily use. This lesson makes every choice explicit and gives the exact permutations that translate between them.

What you’ll learn

  • State and prove the main Kronecker-product identities: mixed product, trace, rank, spectrum, determinant and norms.
  • Translate states and operators between big-endian and little-endian conventions with permutation matrices.
  • Use the reshaping identity (A⊗B)∣ψ⟩↔ACBT(A\otimes B)\ket\psi\leftrightarrow ACB^{T} to compute local actions, overlaps and partial traces.
  • Explain why "control" and "target" are basis-dependent notions.

From abstract tensors to Kronecker matrices

No basis appears in this definition. Matrices appear only once you choose orthonormal bases {∣i⟩}i<m\{\ket{i}\}_{i<m} of Cm\C^m and {∣j⟩}j<p\{\ket{j}\}_{j<p} of Cp\C^p and order the product basis. Lexicographic order, ∣i⟩⊗∣j⟩↦epi+j\ket{i}\otimes\ket{j}\mapsto e_{pi+j}, identifies Cm⊗Cp\C^m\otimes\C^p with Cmp\C^{mp}, and then operators become Kronecker products:

(A⊗B)pi+j,  pk+l=Aik Bjl.(A\otimes B)_{pi+j,\;pk+l} = A_{ik}\,B_{jl}.

For nn subsystems of dimensions d0,…,dn−1d_0,\dots,d_{n-1}, the basis state ∣x0x1⋯xn−1⟩\ket{x_0x_1\cdots x_{n-1}} gets the mixed-radix index ∑kxk∏j>kdj\sum_kx_k\prod_{j>k}d_j, with x0x_0 most significant. This is big-endian, or row-major, order.

Endianness and permutations

Two conventions dominate for qubits:

  • Big-endian: qubit 0 is the leftmost tensor factor and the most significant bit, so ∣q0q1⋯qn−1⟩\ket{q_0q_1\cdots q_{n-1}} has index ∑kqk2n−1−k\sum_kq_k2^{n-1-k}. This course, Nielsen & Chuang and most physics texts use it, and so does np.kron if you list qubit 0 first.
  • Little-endian: qubit 0 is the least significant bit, with index ∑kqk2k\sum_kq_k2^k. Qiskit uses this, and prints bit strings with qubit 0 on the right.

The two are related by a permutation of tensor factors.

DerivationProof
  1. Pσ†(w0⊗⋯⊗wn−1)=wσ(0)⊗⋯⊗wσ(n−1)P_\sigma^\dagger(w_0\otimes\cdots\otimes w_{n-1}) = w_{\sigma(0)}\otimes\cdots\otimes w_{\sigma(n-1)}

    PσP_\sigma permutes the orthonormal product basis, so it is unitary with Pσ†=Pσ−1=Pσ−1P_\sigma^\dagger = P_\sigma^{-1} = P_{\sigma^{-1}}:

  2. Pσ(⨂iAi)Pσ†⨂jwj=Pσ⨂iAiwσ(i)P_\sigma\Big(\bigotimes_iA_i\Big)P_\sigma^\dagger\bigotimes_jw_j = P_\sigma\bigotimes_iA_iw_{\sigma(i)}

    Apply the left-hand side to a product vector. After Pσ†P_\sigma^\dagger, slot ii holds wσ(i)w_{\sigma(i)}, which AiA_i then acts on:

  3. =⨂jAσ−1(j) wσ(σ−1(j))=(⨂jAσ−1(j))⨂jwj= \bigotimes_jA_{\sigma^{-1}(j)}\,w_{\sigma(\sigma^{-1}(j))} = \Big(\bigotimes_jA_{\sigma^{-1}(j)}\Big)\bigotimes_jw_j

    PσP_\sigma moves the factor in slot i=σ−1(j)i = \sigma^{-1}(j) into slot jj:

  4. Product vectors span the space, so the two operators agree. Since every operator is a sum of tensor products, PσMPσ†P_\sigma MP_\sigma^\dagger is "MM with its tensor slots relabelled" for every MM.

For endianness the relevant permutation is bit reversal, σ(k)=n−1−k\sigma(k) = n-1-k. It is an involution, so its matrix RR satisfies R=R†=R−1R = R^\dagger = R^{-1}, and every state and operator translates as

∣ψ⟩little=R∣ψ⟩big,Mlittle=R Mbig R.\ket\psi_{\text{little}} = R\ket\psi_{\text{big}},\qquad M_{\text{little}} = R\,M_{\text{big}}\,R.

For two qubits RR is the SWAP matrix. The same physical gate, a CNOT with control q0q_0 and target q1q_1, therefore has two different matrices:

ConventionBasis orderCNOT, control q0q_0, target q1q_1
Big-endian (this course)∣q0q1⟩\ket{q_0q_1}: 00,01,10,1100, 01, 10, 11(1000010000010010)\begin{pmatrix}1&0&0&0\\0&1&0&0\\0&0&0&1\\0&0&1&0\end{pmatrix}
Little-endian (Qiskit)∣q1q0⟩\ket{q_1q_0}: 00,01,10,1100, 01, 10, 11(1000000100100100)\begin{pmatrix}1&0&0&0\\0&0&0&1\\0&0&1&0\\0&1&0&0\end{pmatrix}
Same gate, different coordinates: the second matrix is RR times the first times RR, with R=SWAPR = \mathrm{SWAP}.
Check your understanding

In Qiskit, a 3-qubit circuit applies XX to qubit 0 only and is then measured. Which bit string labels the outcome?

  1. 100
  2. 010
  3. 001
  4. 110
Show the answer

C. 001

Little-endian strings put qubit 0 on the right: 001 means q0=1q_0 = 1 and q1=q2=0q_1 = q_2 = 0. In this course's big-endian notation the same state is ∣100⟩\ket{100}.

Reshaping: states as matrices

A vector ∣ψ⟩∈Cm⊗Cp\ket\psi\in\C^m\otimes\C^p is the same data as an m×pm\times p coefficient matrix CC, with ∣ψ⟩=∑ijCij∣i⟩∣j⟩\ket\psi = \sum_{ij}C_{ij}\ket{i}\ket{j}. In big-endian order, CC is the row-major reshape of the amplitude vector, psi.reshape(m, p) in NumPy. Bipartite computations then become ordinary matrix algebra:

DerivationThe reshaping identities
  1. (A⊗B)∣ψ⟩=∑ijCij A∣i⟩⊗B∣j⟩=∑kl(∑ijAki Cij Blj)∣k⟩∣l⟩(A\otimes B)\ket\psi = \sum_{ij}C_{ij}\,A\ket i\otimes B\ket j = \sum_{kl}\Big(\sum_{ij}A_{ki}\,C_{ij}\,B_{lj}\Big)\ket k\ket l

    Expand the action of a local operator:

  2. (A⊗B)∣ψ⟩  ⟷  A C BT\boxed{(A\otimes B)\ket\psi\;\longleftrightarrow\;A\,C\,B^{T}}

    The bracket is (ACBT)kl(ACB^T)_{kl}. Note the transpose, not the adjoint: local operators act linearly.

  3. ⟨ϕ∣ψ⟩=∑ijDij‾ Cij=Tr⁡(D†C)\braket{\phi|\psi} = \sum_{ij}\overline{D_{ij}}\,C_{ij} = \Tr\big(D^\dagger C\big)

    Overlaps are Hilbert–Schmidt inner products of coefficient matrices (DD is the matrix of ∣ϕ⟩\ket\phi):

  4. ρA=Tr⁡B∣ψ⟩ ⁣⟨ψ∣=C C†,ρB=Tr⁡A∣ψ⟩ ⁣⟨ψ∣=CT C‾\rho_A = \Tr_B\dyad\psi = C\,C^\dagger,\qquad \rho_B = \Tr_A\dyad\psi = C^{T}\,\overline{C}

    Partial traces are matrix products. Their common nonzero spectrum is the set of squared singular values of CC: the Schmidt decomposition in disguise.

  5. veccol(AXB)=(BT⊗A) veccol(X)\mathrm{vec}_{\text{col}}(AXB) = (B^{T}\otimes A)\,\mathrm{vec}_{\text{col}}(X)

    With column-major storage (Fortran, MATLAB, Julia) the reshape of ∣ψ⟩\ket\psi is CTC^T, and the identity takes its textbook form with the Kronecker factors in the opposite order. Same mathematics, one more place where conventions bite.

python
import numpy as np

def apply_1q(psi, U, k, n):
    """Apply the 2x2 matrix U to qubit k of an n-qubit state (big-endian: qubit 0 leftmost)."""
    t = psi.reshape([2] * n)                    # one axis per qubit; axis k is qubit k
    t = np.tensordot(U, t, axes=([1], [k]))     # contract U's column index with axis k
    t = np.moveaxis(t, 0, k)                    # move the new index back into slot k
    return t.reshape(-1)

def reverse_qubits(psi, n):
    """Big-endian <-> little-endian: apply the bit-reversal permutation R."""
    return psi.reshape([2] * n).transpose(list(reversed(range(n)))).reshape(-1)

A state-vector simulator never builds U⊗I⊗⋯⊗IU\otimes I\otimes\cdots\otimes I. It reshapes and contracts one axis, which costs O(2n)\order{2^n} operations per single-qubit gate instead of the O(4n)\order{4^n} of a dense matrix–vector product.

Control and target are basis-dependent

Even "which qubit is the control" is a statement about the computational basis. The controlled-ZZ, CZ=∣0⟩ ⁣⟨0∣⊗I+∣1⟩ ⁣⟨1∣⊗Z=diag⁡(1,1,1,−1)CZ = \dyad0\otimes I+\dyad1\otimes Z = \diag(1,1,1,-1), is symmetric under exchanging the qubits, and conjugating its target by HH gives a CNOT: CNOT0→1=(I⊗H) CZ (I⊗H)\mathrm{CNOT}_{0\to1} = (I\otimes H)\,CZ\,(I\otimes H). Hence:

(H⊗H) CNOT0→1 (H⊗H)=(H⊗I) CZ (H⊗I)=CNOT1→0(H\otimes H)\,\mathrm{CNOT}_{0\to1}\,(H\otimes H) = (H\otimes I)\,CZ\,(H\otimes I) = \mathrm{CNOT}_{1\to0}
In the XX basis, control and target trade places.
Think first Is there any basis-independent sense in which CNOT acts "from" one qubit "onto" the other?

No direction is invariant, but the nonlocal content is. CNOT0→1\mathrm{CNOT}_{0\to1}, CNOT1→0\mathrm{CNOT}_{1\to0} and CZCZ are all equal up to local unitaries, have operator Schmidt rank 2, and turn a product input into at most one ebit. Two-qubit gates up to local unitaries are classified by the Cartan (KAK) decomposition U=(A0⊗A1) ei(cxXX+cyYY+czZZ) (B0⊗B1)U = (A_0\otimes A_1)\,e^{i(c_xXX+c_yYY+c_zZZ)}\,(B_0\otimes B_1); CNOT corresponds to (cx,cy,cz)=(π/4,0,0)(c_x,c_y,c_z) = (\pi/4,0,0).

Key takeaways

  • The tensor product is basis-free; a Kronecker matrix requires an ordered product basis. Lexicographic order gives the mixed-radix index ∑kxk∏j>kdj\sum_kx_k\prod_{j>k}d_j.
  • Kronecker identities: mixed products, traces, ranks and spectra multiply, and det⁡(A⊗B)=(det⁡A)p(det⁡B)m\det(A\otimes B) = (\det A)^p(\det B)^m.
  • Reordering qubits is conjugation by a permutation unitary; big- and little-endian are related by bit reversal, Mlittle=RMbigRM_{\text{little}} = RM_{\text{big}}R.
  • Reshaping a bipartite state into its coefficient matrix turns A⊗BA\otimes B into C↦ACBTC\mapsto ACB^T and partial traces into CC†CC^\dagger and CTC‾C^T\overline C.
  • Control and target are basis-dependent: conjugation by H⊗HH\otimes H reverses a CNOT.

Check yourself

In the interactive lesson these are scored with your confidence, and what you miss comes back for review.

Question 1

Qubits (q0,q1,q2)=(1,1,0)(q_0,q_1,q_2) = (1,1,0). What is the basis index in big-endian and in little-endian order, respectively?

  1. 33 and 66
  2. 66 and 66
  3. 66 and 33
  4. 33 and 33
Show the answer

C. 66 and 33

Big-endian: 1⋅4+1⋅2+0⋅1=61\cdot4+1\cdot2+0\cdot1 = 6. Little-endian: 1⋅1+1⋅2+0⋅4=31\cdot1+1\cdot2+0\cdot4 = 3. Bit reversal maps 110↦011110\mapsto011.

Question 2

AA is 2×22\times2 with det⁡A=2\det A = 2, and BB is 3×33\times3 with det⁡B=5\det B = 5. What is det⁡(A⊗B)\det(A\otimes B)?

  1. 1010
  2. 200200
  3. 500500
  4. 100100
Show the answer

B. 200200

det⁡(A⊗B)=(det⁡A)3(det⁡B)2=8⋅25=200\det(A\otimes B) = (\det A)^3(\det B)^2 = 8\cdot25 = 200: each determinant is raised to the dimension of the other factor.

Question 3

With ∣ψ⟩↔C\ket\psi\leftrightarrow C (row-major coefficient matrix), which matrix represents (A⊗B)∣ψ⟩(A\otimes B)\ket\psi?

  1. ACBACB
  2. ACB†ACB^\dagger
  3. BCATBCA^{T}
  4. ACBTACB^{T}
Show the answer

D. ACBTACB^{T}

((A⊗B)ψ)kl=∑ijAkiCijBlj=(ACBT)kl\big((A\otimes B)\psi\big)_{kl} = \sum_{ij}A_{ki}C_{ij}B_{lj} = (ACB^T)_{kl}.

Question 4

Which gate equals (H⊗H) CNOT0→1 (H⊗H)(H\otimes H)\,\mathrm{CNOT}_{0\to1}\,(H\otimes H)?

  1. CNOT1→0\mathrm{CNOT}_{1\to0}
  2. CNOT0→1\mathrm{CNOT}_{0\to1}
  3. CZCZ
  4. SWAP
Show the answer

A. CNOT1→0\mathrm{CNOT}_{1\to0}

With CNOT0→1=(I⊗H) CZ (I⊗H)\mathrm{CNOT}_{0\to1} = (I\otimes H)\,CZ\,(I\otimes H) and H2=IH^2 = I, the product is (H⊗I) CZ (H⊗I)(H\otimes I)\,CZ\,(H\otimes I): a CNOT with control qubit 1 and target qubit 0.

Further reading

  • R. A. Horn & C. R. Johnson, Topics in Matrix Analysis, ch. 4 (Cambridge, 1991).
  • C. F. Van Loan, "The ubiquitous Kronecker product", J. Comput. Appl. Math. 123, 85 (2000).
  • J. R. Magnus & H. Neudecker, "The commutation matrix: some properties and applications", Ann. Statist. 7, 381 (1979).
  • B. Coecke & A. Kissinger, Picturing Quantum Processes (Cambridge, 2017).
  • S. B. Bravyi & A. Yu. Kitaev, "Fermionic quantum computation", Ann. Phys. 298, 210 (2002).