A Notebook for Subsystems and Entanglement
Small numerical examples make tensor-product conventions tangible. The downloadable Python notebook computes a complex qubit–qutrit reduction, compares three kinds of correlation, tests a noisy singlet, and truncates a two-mode squeezed state. Each result can also be checked by hand.
Helpful background. Product-basis ordering explains array indices; partial trace and Schmidt decomposition explain the calculations. Basic Python arrays are enough to follow the code.
Composite states as arrays
Section titled “Composite states as arrays”The file uses # %% cell markers, so a compatible notebook editor can run one cell at a time. It also runs as an ordinary script with Python 3 and NumPy:
python composite-state-calculations.pyThe examples were executed with NumPy 2.1.2. They use dense arrays for small systems; a joint density matrix requires entries, so the method is not a scalable many-body simulation.
The basis index is , with subsystem first. For two qubits this means . Reshaping a density matrix exposes four indices in the order :
r = rho.reshape(dA, dB, dA, dB)rho_A = np.trace(r, axis1=1, axis2=3)rho_B = np.trace(r, axis1=0, axis2=2)Tracing over means setting its ket and bra indices equal and summing them. It does not mean keeping one block of the matrix. NumPy’s trace documentation explains the axis convention.
The downloadable functions check matrix shape, finite entries, Hermiticity, trace one, and positivity before computing entropies. A tolerance of accommodates roundoff in these small examples; it is not an experimental uncertainty. Values outside that tolerance cause an error. Only accepted roundoff asymmetry or tiny negative eigenvalues are removed, rather than silently turning an invalid matrix into a state.
A complex state tests conjugation
Section titled “A complex state tests conjugation”Consider
With defined as the amplitude of , the two contractions are
rho_A = C @ C.conj().Trho_B = C.T @ C.conj()The second formula is easy to mistype. The correct result is
Its nonzero eigenvalues are , so either subsystem has entropy bits. But eigenvalues alone cannot detect every conjugation error: has the same eigenvalues and opposite imaginary entries. A local observable distinguishes them:
The notebook also reconstructs the state from the singular-value decomposition:
U, s, Vh = np.linalg.svd(C, full_matrices=False)restored = sum(s[k] * np.kron(U[:, k], Vh[k, :]) for k in range(len(s)))Here the components of the Schmidt ket are a row of Vh, used without further conjugation. Check the reconstructed vector itself, not just the singular values.
Three states with the same local statistics
Section titled “Three states with the same local statistics”The next cell compares
All three reduce to on either qubit. Their joint entropies are respectively bits, while their mutual informations are bits. These outputs distinguish entanglement, classical correlation, and independence despite identical single-qubit measurements.
For these finite matrices the entropy routine uses the Hermitian eigenvalues and computes . The zero eigenvalues contribute zero. The local entropy of a mixed joint state is not, by itself, its entanglement.
Partial transpose of a noisy singlet
Section titled “Partial transpose of a noisy singlet”For , define
The notebook transposes only the two indices:
rho_PT = r.transpose(0, 3, 2, 1).reshape(dA*dB, dA*dB)At , the eigenvalues of are . The negative eigenvalue proves entanglement, and its absolute value gives negativity . Try : all eigenvalues become nonnegative. For this two-qubit system PPT is also sufficient for separability; that last conclusion is dimension dependent. See negativity and PPT before applying it to other systems.
Partial transpose need not produce a positive matrix. Consequently the notebook uses a Hermitian eigensolver directly on that result, rather than passing it to the entropy function that expects a physical density matrix.
Occupation cutoffs and discarded probability
Section titled “Occupation cutoffs and discarded probability”A two-mode squeezed state has Schmidt probabilities , where . Keeping discards exactly
For and , the discarded probability is . The normalized truncated pure state has squared overlap with the exact state. This is a controlled approximation to the state vector; an unbounded observable can require additional tail estimates.
A finite occupation basis also changes operator identities. If is the annihilation operator projected onto , then
The top-state correction is a truncation effect, not a floating-point mistake. Increase the cutoff and check the quantity you actually want, rather than treating a small normalization error as proof of convergence. Two-mode entanglement explains the exact squeezed-state distribution.
Exercises
Section titled “Exercises”- Replace by in the complex example. What changes, and what stays fixed?
Solution
The off-diagonal entries of are complex conjugated and becomes . The reduced eigenvalues , purity , and entropy stay fixed. This pair of states illustrates why matching entropies does not establish matching measurement statistics.
- Derive the partial-transpose eigenvalues of , and compare the output at with the separability threshold.
Solution
The singlet’s partial transpose has eigenvalues . Adding the identity contribution gives once and three times. At these are . The state is PPT, hence separable for two qubits. The exact threshold is ; negativity above it is .
- For , choose the smallest cutoff with discarded probability below .
Solution
We need . Since and , the smallest cutoff is . There are then twenty retained number states per mode.
- Construct for and verify the boundary correction in its commutator.
Solution
In the basis ,
The products are and . Their difference is . Every finite-dimensional commutator has trace zero, so it cannot equal the identity.
References
Section titled “References”- G. H. Golub and C. F. Van Loan, Matrix Computations, 4th ed., Johns Hopkins University Press, 2013.
- M. A. Nielsen and I. L. Chuang, Quantum Computation and Quantum Information, 10th anniversary ed., Cambridge University Press, 2010.
- NumPy Developers, NumPy reference: trace, singular-value decomposition, and Hermitian eigenvalues, accessed 13 October 2026.
- J. Watrous, The Theory of Quantum Information, Cambridge University Press, 2018; author’s text.