Skip to content

Computational Notebooks

This page is the notebook index and reproducibility contract for composite systems and entanglement. It specifies what each notebook should compute, which conventions it must state, and which checks must pass before the notebook should be treated as a reliable teaching or reference artifact.

At this draft stage, the entries below are specifications rather than downloadable notebook links. When notebook files are added, they should live under a stable path such as notebooks/composite-systems/, preserve these validation checks, and link back to the canonical explanatory pages.

This page owns the computational contract for small, transparent notebooks in this volume. It does not own the derivations of tensor products, partial traces, Schmidt decomposition, entanglement entropy, or second quantization. Those stay in their canonical pages and are linked below.

The notebook suite should emphasize reproducible understanding:

  • state the basis ordering before constructing arrays;
  • print dimensions of vectors, matrices, and reshaped tensors;
  • check normalization, Hermiticity, trace preservation, and eigenvalue sanity;
  • compare numerical outputs to analytic formulas from the text;
  • avoid hidden high-level library calls for the core operation being taught;
  • expose small parameters that readers can change without rewriting the notebook.

Unless a notebook explicitly states otherwise, two-qubit vectors use the product basis

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

with subsystem AA written first and subsystem BB second. If a,b∈{0,1}a,b\in\{0,1\}, the array index is

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

For nn qubits in this convention,

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

This is a big-endian convention for displayed bit strings. Other conventions are legitimate, but a notebook must state the convention before using compact labels.

Density matrices are represented as square arrays in the same product-basis order. A two-qubit density matrix can be reshaped as

ρab,a′b′⟷ρ[a,b,a′,b′].\rho_{a b,a' b'} \quad \longleftrightarrow \quad \rho[a,b,a',b'].

The partial trace over BB is then the index contraction

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

Every notebook that constructs a state or density operator should include the relevant subset of these checks:

⟨ψ∣ψ⟩=1,Tr⁡ρ=1,ρ†=ρ.\langle\psi\vert\psi\rangle = 1, \qquad \operatorname{Tr}\rho = 1, \qquad \rho^\dagger = \rho.

Density-operator eigenvalues should be nonnegative up to numerical tolerance:

λmin⁡(ρ)≥−ϵ,\lambda_{\min}(\rho) \ge -\epsilon,

where ϵ\epsilon is a stated roundoff tolerance, not an unexamined escape hatch.

Reduced states should preserve trace:

Tr⁡ρA=Tr⁡ρAB.\operatorname{Tr}\rho_A = \operatorname{Tr}\rho_{AB}.

Pure-state Schmidt coefficients should satisfy

∑rsr2=1,sr≥0.\sum_r s_r^2 = 1, \qquad s_r\ge0.

For fermionic notebooks, the creation and annihilation matrices should satisfy

{ci,cj†}=δijI,{ci,cj}=0,{ci†,cj†}=0.\{c_i,c_j^\dagger\} = \delta_{ij}I, \qquad \{c_i,c_j\} = 0, \qquad \{c_i^\dagger,c_j^\dagger\} = 0.

The notebook should print the maximum residual norm for these identities. A result that is “visually close” in a matrix display is not enough.

Notebook specificationCanonical filenameMain computationRequired checksCanonical pages
Tensor-product basis orderingtensor-product-basis-ordering.ipynbBuild two- and three-qubit bases; construct local Pauli operatorsDimensions, index map, local-operator commutatorsProduct Bases
Partial trace for two qubitspartial-trace-two-qubits.ipynbReduce product, Bell, and classically correlated statesTrace preservation, Hermiticity, local expectation valuesPartial Trace
Schmidt decomposition by SVDschmidt-decomposition-svd.ipynbReshape a pure-state vector into a coefficient matrix and compute singular valuesReconstruction error, normalized singular values, entropy comparisonSchmidt Decomposition
Bell-state correlationsbell-states-correlations.ipynbCompute Pauli correlation matrices and reduced states for Bell statesOrthonormality, one-qubit reductions, correlation signsBell States
Small-system entanglement entropyentanglement-entropy-spin-chain-small.ipynbDiagonalize small spin chains and compute subsystem entropiesNormalization, trace preservation, entropy benchmarksEntanglement in Many-Body Physics
Fermionic signs and Jordan-Wigner previewfermionic-signs-jordan-wigner-preview.ipynbBuild occupation basis and fermionic ladder operatorsAnticommutators, sign conventions, number eigenvaluesFermionic Anticommutation Relations
Small second-quantized Hamiltoniansecond-quantized-hamiltonian-small-basis.ipynbBuild a two-site Hubbard-style Hamiltonian in fixed particle sectorsHermiticity, particle-number conservation, sector dimensionsMany-Particle Hamiltonians

This notebook should begin with arrays, not abstractions. For two qubits, list the basis states, array indices, and subsystem labels in a table:

indexstate(a,b)0∣00⟩(0,0)1∣01⟩(0,1)2∣10⟩(1,0)3∣11⟩(1,1)\begin{array}{c|c|c} \text{index} & \text{state} & (a,b)\\ \hline 0 & \lvert00\rangle & (0,0)\\ 1 & \lvert01\rangle & (0,1)\\ 2 & \lvert10\rangle & (1,0)\\ 3 & \lvert11\rangle & (1,1) \end{array}

Then construct local Pauli operators as

XA=X⊗I,XB=I⊗X,ZA=Z⊗I,ZB=I⊗Z.X_A=X\otimes I, \qquad X_B=I\otimes X, \qquad Z_A=Z\otimes I, \qquad Z_B=I\otimes Z.

The notebook should verify that operators on different subsystems commute:

[XA,ZB]=0,[ZA,XB]=0.[X_A,Z_B] = 0, \qquad [Z_A,X_B] = 0.

It should also show one failure mode: if the basis ordering is silently changed, an array with the same numerical entries can represent a different physical operator.

The partial-trace notebook should compute reduced states in three examples:

  1. a product pure state;
  2. a Bell state;
  3. a classically correlated separable mixed state.

For the plus Bell state,

∣Φ+⟩=∣00⟩+∣11⟩2,\lvert\Phi^+\rangle = \frac{ \lvert00\rangle+\lvert11\rangle }{\sqrt2},

the notebook should obtain

ρA=ρB=12I.\rho_A = \rho_B = \frac12 I.

For the classically correlated state

ρcc=12∣00⟩⟨00∣+12∣11⟩⟨11∣,\rho_{\mathrm{cc}} = \frac12\lvert00\rangle\langle00\rvert + \frac12\lvert11\rangle\langle11\rvert,

the same local reductions occur, but the joint state is separable. This is a mandatory comparison: it prevents the common mistake of using mixed marginals as a mixed-state entanglement test.

The notebook should verify local statistics by comparing

Tr⁡AB[ρAB(OA⊗IB)]\operatorname{Tr}_{AB} \bigl[ \rho_{AB}(O_A\otimes I_B) \bigr]

with

Tr⁡A(ρAOA)\operatorname{Tr}_A(\rho_A O_A)

for several one-qubit observables OAO_A.

For a pure vector

∣ψ⟩=∑ijCij ∣i⟩A∣j⟩B,\lvert\psi\rangle = \sum_{ij} C_{ij}\, \lvert i\rangle_A\lvert j\rangle_B,

the notebook should reshape the state into the coefficient matrix CC and compute its singular-value decomposition:

C=UΣV†.C = U\Sigma V^\dagger.

The diagonal entries of Σ\Sigma are the Schmidt coefficients. The notebook should reconstruct the state and report the residual

∥C−UΣV†∥.\left\| C-U\Sigma V^\dagger \right\|.

It should compare the entropy computed from singular values,

S=−∑rsr2log⁡sr2,S = - \sum_r s_r^2\log s_r^2,

with the entropy computed from eigenvalues of the reduced density operator ρA=CC†\rho_A=CC^\dagger.

Useful test cases:

  • a product state, with one singular value equal to one;
  • a Bell state, with two singular values equal to 1/21/\sqrt2;
  • a random normalized two-qubit state, with results checked by reconstruction.

The Bell-correlation notebook should compute the matrix

Tij=⟨σi⊗σj⟩,i,j∈{x,y,z},T_{ij} = \langle \sigma_i\otimes\sigma_j \rangle, \qquad i,j\in\{x,y,z\},

for each Bell state. It should also compute the one-qubit Bloch vectors and show that they vanish for all Bell states:

⟨σi⊗I⟩=0,⟨I⊗σi⟩=0.\langle \sigma_i\otimes I\rangle = 0, \qquad \langle I\otimes\sigma_i\rangle = 0.

This makes the distinction between local randomness and joint correlation explicit. It also gives a numerical bridge to Bell measurements, correlation tensors, witnesses, and foundations examples.

Small-System Entanglement-Entropy Notebook

Section titled “Small-System Entanglement-Entropy Notebook”

The spin-chain entropy notebook should stay small enough that a reader can inspect the arrays. A good first target is a few qubits with a Hamiltonian such as

H=−J∑i=1L−1ZiZi+1−h∑i=1LXi,H = -J\sum_{i=1}^{L-1} Z_iZ_{i+1} -h\sum_{i=1}^{L} X_i,

with open boundary conditions and LL small. The notebook should diagonalize HH, choose a low-energy state, trace out part of the chain, and compute

SA=−Tr⁡(ρAlog⁡ρA).S_A = - \operatorname{Tr}(\rho_A\log\rho_A).

Validation should include benchmark states whose entropy is known before diagonalization:

  • a product state, with SA=0S_A=0 for every cut;
  • a Bell pair crossing the cut, with SA=log⁡2S_A=\log2;
  • a GHZ state, with one bit or one nat depending on logarithm base;
  • a classically correlated mixed state, used only to show why mixed-state entropy is not automatically entanglement entropy.

The notebook should state the logarithm base and label entropy units.

The fermionic-sign notebook should build an occupation basis for MM modes, such as

∣n1n2⋯nM⟩,ni∈{0,1}.\lvert n_1n_2\cdots n_M\rangle, \qquad n_i\in\{0,1\}.

With canonical mode order 1,2,…,M1,2,\ldots,M, the annihilation operator acts as

ci∣n1⋯ni⋯nM⟩=(−1)Sini∣n1⋯0i⋯nM⟩,c_i \lvert n_1\cdots n_i\cdots n_M\rangle = (-1)^{S_i} n_i \lvert n_1\cdots 0_i\cdots n_M\rangle,

where

Si=∑k<ink.S_i = \sum_{k<i} n_k.

The creation operator is similar, with nin_i replaced by 1−ni1-n_i. The notebook should verify anticommutation relations as matrix identities and show how Jordan-Wigner strings implement the same signs in a qubit representation.

This notebook should not present the Jordan-Wigner transformation as a full many-body algorithm. It is a sign-convention preview that prepares readers for later computational and many-body treatments.

The small-Hamiltonian notebook should construct a finite basis and a Hamiltonian such as a two-site spinful Hubbard model:

H=−t∑σ(c1σ†c2σ+c2σ†c1σ)+U∑i=12ni↑ni↓.H = -t \sum_{\sigma} \left( c_{1\sigma}^\dagger c_{2\sigma} + c_{2\sigma}^\dagger c_{1\sigma} \right) + U \sum_{i=1}^{2} n_{i\uparrow}n_{i\downarrow}.

It should build the Hamiltonian from creation and annihilation matrices, verify Hermiticity, and check particle-number conservation:

[H,N]=0.[H,N] = 0.

For small sectors, the notebook should print the basis states explicitly and diagonalize each sector separately. This keeps the connection between first-quantized intuition, occupation notation, and matrix mechanics visible.

Optional notebooks should be added only after the core suite is stable:

  • negativity-ppt-two-qubits.ipynb: partial transpose, eigenvalues, and negativity for simple two-qubit mixed states.
  • ghz-w-entanglement.ipynb: reduced states of GHZ and W states for different traced-out subsystems.
  • occupation-number-bosons-two-modes.ipynb: bosonic occupation basis, ladder-operator square roots, and two-mode examples.
  • two-mode-squeezed-state-truncation.ipynb: truncated continuous-variable calculations and normalization errors.
  • jordan-wigner-preview.ipynb: a slightly deeper spin-chain mapping after the sign notebook is mature.

Each optional notebook should have a small analytic benchmark. A notebook that only produces plausible plots is not ready.

  • Silent basis-ordering changes. The same array can mean different states under different bit conventions.
  • Using rounded matrices as exact evidence. Always report norms or tolerances.
  • Forgetting to renormalize after truncation. This is especially dangerous for continuous-variable and Fock-space examples.
  • Treating a negative eigenvalue from roundoff as physical. Compare it with the stated tolerance and with Hermiticity error.
  • Using local entropy as mixed-state entanglement. Entropy is an entanglement measure only in the pure bipartite setting.
  • Guessing fermionic signs. Derive them from the mode order or verify the anticommutators.
  • Hiding the central operation in a library call. A notebook teaching the partial trace should show the contraction at least once.
  • M. A. Nielsen and I. L. Chuang, Quantum Computation and Quantum Information, Cambridge University Press, 2010.
  • G. H. Golub and C. F. Van Loan, Matrix Computations, 4th ed., Johns Hopkins University Press, 2013.
  • L. N. Trefethen and D. Bau III, Numerical Linear Algebra, SIAM, 1997.
  • A. L. Fetter and J. D. Walecka, Quantum Theory of Many-Particle Systems, McGraw-Hill, 1971.
  • E. Lieb, T. Schultz, and D. Mattis, “Two soluble models of an antiferromagnetic chain”, Annals of Physics 16, 407-466, 1961, doi:10.1016/0003-4916(61)90115-4.
  • P. Jordan and E. Wigner, “Uber das Paulische Aquivalenzverbot”, Zeitschrift fur Physik 47, 631-651, 1928.
  • J. Hubbard, “Electron correlations in narrow energy bands”, Proceedings of the Royal Society of London A 276, 238-257, 1963, doi:10.1098/rspa.1963.0204.
  • U. Schollwoeck, “The density-matrix renormalization group in the age of matrix product states”, Annals of Physics 326, 96-192, 2011, doi:10.1016/j.aop.2010.09.012.
  1. Basis index check. In the stated two-qubit convention, what are the array indices of ∣01⟩\lvert01\rangle and ∣10⟩\lvert10\rangle? Why does this matter for local operators?
Solution

The convention is

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

Thus ∣01⟩\lvert01\rangle has index 11 and ∣10⟩\lvert10\rangle has index 22. This matters because an operator such as X⊗IX\otimes I flips the first bit, while I⊗XI\otimes X flips the second bit. If the basis order is changed silently, the same numerical matrix can act on the wrong subsystem.

  1. Trace preservation. A notebook computes ρA=Tr⁡BρAB\rho_A=\operatorname{Tr}_B\rho_{AB} for a normalized two-qubit density operator. What scalar check should be printed immediately?
Solution

It should print

Tr⁡ρA−Tr⁡ρAB.\operatorname{Tr}\rho_A - \operatorname{Tr}\rho_{AB}.

For a normalized density operator this should be zero up to numerical tolerance. Since Tr⁡ρAB=1\operatorname{Tr}\rho_{AB}=1, the reduced state should also have trace one.

  1. SVD entropy check. A normalized two-qubit pure state has Schmidt coefficients s1=s2=1/2s_1=s_2=1/\sqrt2. What entropy should both the SVD route and the reduced-density-matrix route produce?
Solution

The probabilities are p1=p2=1/2p_1=p_2=1/2. Therefore

S=−∑r=12prlog⁡pr=−2(12log⁡12)=log⁡2.S = - \sum_{r=1}^{2} p_r\log p_r = - 2 \left( \frac12\log\frac12 \right) = \log2.

Both computational routes should give the same value, apart from the chosen logarithm base.

  1. Fermionic sign. In a three-mode occupation basis with order 1,2,31,2,3, compute the sign factor for c3c_3 acting on ∣110⟩\lvert110\rangle and on ∣101⟩\lvert101\rangle.
Solution

For c3c_3, the sign exponent is

S3=n1+n2.S_3 = n_1+n_2.

For ∣110⟩\lvert110\rangle, n3=0n_3=0, so the annihilation operator gives zero regardless of the sign. The formal sign factor would be (−1)2=+1(-1)^{2}=+1.

For ∣101⟩\lvert101\rangle, n3=1n_3=1 and S3=1+0=1S_3=1+0=1, so the sign factor is −1-1:

c3∣101⟩=−∣100⟩.c_3\lvert101\rangle = -\lvert100\rangle.