Prove2Me
Navigate
DiscoverCollectionsFormalpediaGalaxyBlogsUsersMomentumMy Missions+
Prove2Me
Log in
← Formalpedia

Finite-dimensional quantum states, partial traces, entropies and erasure codes (Harlow TASI §4)

Definition
HarlowTASI_QuantumBasics

by Lucas · Oct 9, 2026 · Mathlib 0df444a (Lean v4.33.1)

holographyoperator-algebrasquantum-error-correctionquantum-information

Basic finite-dimensional quantum-information vocabulary used throughout Harlow's lectures, §4 and §5.

All Hilbert spaces are finite-dimensional and are modelled by coordinates: a space with orthonormal basis indexed by a finite set ι\iotaι is Cι\mathbb C^{\iota}Cι, and operators are complex ι×ι\iota\times\iotaι×ι matrices. A bipartite space HR⊗HR‾\mathcal H_R\otimes\mathcal H_{\overline R}HR​⊗HR​ is CR×R‾\mathbb C^{R\times\overline R}CR×R, and X⊗YX\otimes YX⊗Y is the Kronecker product.

  1. An isometry is a matrix VVV with V†V=IV^\dagger V=IV†V=I. A code subspace Hcode⊆HR⊗HR‾\mathcal H_{code}\subseteq\mathcal H_R\otimes\mathcal H_{\overline R}Hcode​⊆HR​⊗HR​ is represented by an isometry V:CC→HR⊗HR‾V:\mathbb C^{C}\to\mathcal H_R\otimes\mathcal H_{\overline R}V:CC→HR​⊗HR​ whose columns ∣i~⟩=V∣i⟩|\tilde i\rangle=V|i\rangle∣i~⟩=V∣i⟩ form an orthonormal basis of Hcode\mathcal H_{code}Hcode​; an operator O~\tilde OO~ on Hcode\mathcal H_{code}Hcode​ is a C×CC\times CC×C matrix, and the code state ∣ψ~⟩|\tilde\psi\rangle∣ψ~​⟩ is V∣ψ⟩V|\psi\rangleV∣ψ⟩.
  2. A unitary between two index sets is a matrix UUU with U†U=IU^\dagger U=IU†U=I and UU†=IUU^\dagger=IUU†=I.
  3. A density matrix is a positive semidefinite matrix of trace one.
  4. Partial traces TrR‾\mathrm{Tr}_{\overline R}TrR​ and TrR\mathrm{Tr}_RTrR​ of an operator on HR⊗HR‾\mathcal H_R\otimes\mathcal H_{\overline R}HR​⊗HR​.
  5. The von Neumann entropy S(ρ)=−Tr ρlog⁡ρ=−∑λλlog⁡λS(\rho)=-\mathrm{Tr}\,\rho\log\rho=-\sum_\lambda \lambda\log\lambdaS(ρ)=−Trρlogρ=−∑λ​λlogλ over the eigenvalues of a Hermitian ρ\rhoρ (with 0log⁡0=00\log0=00log0=0), eq. (5.14).
  6. The relative entropy S(ρ∣σ)=Tr ρlog⁡ρ−Tr ρlog⁡σ∈(−∞,+∞]S(\rho|\sigma)=\mathrm{Tr}\,\rho\log\rho-\mathrm{Tr}\,\rho\log\sigma\in(-\infty,+\infty]S(ρ∣σ)=Trρlogρ−Trρlogσ∈(−∞,+∞], eq. (5.17), computed from spectral decompositions ρ=∑ipi∣ui⟩⟨ui∣\rho=\sum_i p_i|u_i\rangle\langle u_i|ρ=∑i​pi​∣ui​⟩⟨ui​∣, σ=∑jqj∣vj⟩⟨vj∣\sigma=\sum_j q_j|v_j\rangle\langle v_j|σ=∑j​qj​∣vj​⟩⟨vj​∣ as
S(ρ∣σ)=∑i,j∣⟨ui∣vj⟩∣2 pi (log⁡pi−log⁡qj),S(\rho|\sigma)=\sum_{i,j}|\langle u_i|v_j\rangle|^2\,p_i\,(\log p_i-\log q_j),S(ρ∣σ)=i,j∑​∣⟨ui​∣vj​⟩∣2pi​(logpi​−logqj​),

with terms having pi=0p_i=0pi​=0 or ⟨ui∣vj⟩=0\langle u_i|v_j\rangle=0⟨ui​∣vj​⟩=0 equal to 000, and terms having pi≠0p_i\neq0pi​=0, ⟨ui∣vj⟩≠0\langle u_i|v_j\rangle\neq0⟨ui​∣vj​⟩=0, qj=0q_j=0qj​=0 equal to +∞+\infty+∞. 7. Reduced density matrices ρSB,ρS,ρB\rho_{SB},\rho_S,\rho_BρSB​,ρS​,ρB​ of a pure state ∣ψ⟩∈S⊗A⊗B|\psi\rangle\in S\otimes A\otimes B∣ψ⟩∈S⊗A⊗B. 8. The reference state of eq. (4.18), ∣ϕ⟩=∣S∣−1/2∑i∣i⟩S∣i~⟩RR‾|\phi\rangle=|S|^{-1/2}\sum_i|i\rangle_S|\tilde i\rangle_{R\overline R}∣ϕ⟩=∣S∣−1/2∑i​∣i⟩S​∣i~⟩RR​, with the reference system SSS indexed by the code basis. 9. For nnn qudits of dimension ddd and a set AAA of sites, the splitting (Cd)⊗n≅(Cd)⊗A⊗(Cd)⊗Ac(\mathbb C^d)^{\otimes n}\cong(\mathbb C^d)^{\otimes A}\otimes(\mathbb C^d)^{\otimes A^c}(Cd)⊗n≅(Cd)⊗A⊗(Cd)⊗Ac, and the predicate "the encoded information is accessible from AAA": every logical operator O~\tilde OO~ has an OAO_AOA​ acting on AAA alone with OA∣ψ~⟩=O~∣ψ~⟩O_A|\tilde\psi\rangle=\tilde O|\tilde\psi\rangleOA​∣ψ~​⟩=O~∣ψ~​⟩ and OA†∣ψ~⟩=O~†∣ψ~⟩O_A^\dagger|\tilde\psi\rangle=\tilde O^\dagger|\tilde\psi\rangleOA†​∣ψ~​⟩=O~†∣ψ~​⟩ for all code states (condition (1) of Theorem 4.1, as used in the derivation of the quantum Singleton bound).

These notions are shared by every statement of the mission.

Formalization Note Entropies are defined through the eigen-decomposition of a Hermitian matrix and take the junk value 000 on non-Hermitian input; they are only ever applied to density matrices. The relative entropy is valued in EReal so that the value +∞+\infty+∞ (support of ρ\rhoρ not contained in that of σ\sigmaσ) is representable.

Definition code
import Mathlib

/-!
# Harlow, TASI Lectures on the Emergence of Bulk Physics in AdS/CFT — basic quantum notions

Finite-dimensional Hilbert spaces are modelled as `ℂ^ι` for a finite index type `ι`, and
operators as complex matrices indexed by `ι`. A bipartite space `H_R ⊗ H_R̄` is indexed by the
product type `R × Rb`, and `X ⊗ₖ Y` is the Kronecker (tensor) product of matrices.
A code subspace `H_code ⊆ H_R ⊗ H_R̄` is described by an isometry `V : ℂ^C → H_R ⊗ H_R̄`
whose columns form an orthonormal basis `|ĩ⟩` of `H_code`.
-/

namespace HarlowTASI

open Matrix
open scoped Kronecker ComplexOrder

noncomputable section

/-- `V` is an isometry: `V† V = 1`. Its columns are then an orthonormal basis of its range. -/
def IsIsometry {m n : Type} [Fintype m] [DecidableEq n] (V : Matrix m n ℂ) : Prop :=
  Vᴴ * V = 1

/-- `U` is unitary (possibly between two differently indexed spaces of equal dimension):
`U† U = 1` and `U U† = 1`. -/
def IsUnitaryMatrix {m n : Type} [Fintype m] [Fintype n] [DecidableEq m] [DecidableEq n]
    (U : Matrix m n ℂ) : Prop :=
  Uᴴ * U = 1 ∧ U * Uᴴ = 1

/-- A density matrix (mixed state): positive semidefinite with unit trace. -/
def IsDensityMatrix {n : Type} [Fintype n] (ρ : Matrix n n ℂ) : Prop :=
  ρ.PosSemidef ∧ ρ.trace = 1

/-- Partial trace over the second tensor factor: `(Tr_B X)_{ij} = ∑_k X_{(i,k),(j,k)}`. -/
def traceRight {A B : Type} [Fintype B] (X : Matrix (A × B) (A × B) ℂ) : Matrix A A ℂ :=
  fun i j => ∑ k, X (i, k) (j, k)

/-- Partial trace over the first tensor factor: `(Tr_A X)_{ij} = ∑_k X_{(k,i),(k,j)}`. -/
def traceLeft {A B : Type} [Fintype A] (X : Matrix (A × B) (A × B) ℂ) : Matrix B B ℂ :=
  fun i j => ∑ k, X (k, i) (k, j)

/-- Von Neumann entropy `S(ρ) = -Tr(ρ log ρ) = -∑ λ log λ` over the eigenvalues `λ` of a
Hermitian matrix `ρ` (with `0 log 0 = 0`). Junk value `0` on non-Hermitian input. -/
noncomputable def vonNeumannEntropy {n : Type} [Fintype n] [DecidableEq n]
    (ρ : Matrix n n ℂ) : ℝ :=
  if h : ρ.IsHermitian then ∑ i, Real.negMulLog (h.eigenvalues i) else 0

/-- Quantum relative entropy `S(ρ|σ) = Tr(ρ log ρ) - Tr(ρ log σ)`, valued in the extended reals.
Writing `ρ = ∑ pᵢ |uᵢ⟩⟨uᵢ|`, `σ = ∑ qⱼ |vⱼ⟩⟨vⱼ|` (spectral decompositions) and
`wᵢⱼ = |⟨uᵢ, vⱼ⟩|²`, it is `∑ᵢⱼ wᵢⱼ pᵢ (log pᵢ - log qⱼ)`, where a term with `pᵢ = 0` or
`wᵢⱼ = 0` is `0`, and a term with `pᵢ ≠ 0`, `wᵢⱼ ≠ 0`, `qⱼ = 0` is `+∞` (so `S(ρ|σ) = +∞`
exactly when the support of `ρ` is not contained in that of `σ`, for density matrices).
Junk value `0` on non-Hermitian input. -/
noncomputable def relativeEntropy {n : Type} [Fintype n] [DecidableEq n]
    (ρ σ : Matrix n n ℂ) : EReal :=
  if h : ρ.IsHermitian ∧ σ.IsHermitian then
    ∑ i, ∑ j,
      (if h.1.eigenvalues i = 0 ∨
          ‖inner ℂ (h.1.eigenvectorBasis i) (h.2.eigenvectorBasis j)‖ = 0 then (0 : EReal)
       else if h.2.eigenvalues j = 0 then ⊤
       else (((‖inner ℂ (h.1.eigenvectorBasis i) (h.2.eigenvectorBasis j)‖ ^ 2 *
          h.1.eigenvalues i * (Real.log (h.1.eigenvalues i) - Real.log (h.2.eigenvalues j)) : ℝ))
          : EReal))
  else 0

/-- Reduced density matrix on `S ⊗ B` of the pure state `|ψ⟩ ∈ S ⊗ A ⊗ B` (trace over `A`):
`ρ_{SB}((s,b),(s',b')) = ∑_a ψ(s,a,b) · conj ψ(s',a,b')`. -/
def reducedSB {S A B : Type} [Fintype A] (ψ : S × A × B → ℂ) : Matrix (S × B) (S × B) ℂ :=
  fun x y => ∑ a, ψ (x.1, a, x.2) * star (ψ (y.1, a, y.2))

/-- Reduced density matrix on `S` of the pure state `|ψ⟩ ∈ S ⊗ A ⊗ B`. -/
def reducedS {S A B : Type} [Fintype A] [Fintype B] (ψ : S × A × B → ℂ) : Matrix S S ℂ :=
  fun s s' => ∑ a, ∑ b, ψ (s, a, b) * star (ψ (s', a, b))

/-- Reduced density matrix on `B` of the pure state `|ψ⟩ ∈ S ⊗ A ⊗ B`. -/
def reducedB {S A B : Type} [Fintype S] [Fintype A] (ψ : S × A × B → ℂ) : Matrix B B ℂ :=
  fun b b' => ∑ s, ∑ a, ψ (s, a, b) * star (ψ (s, a, b'))

/-- The state `|φ⟩ = |S|^{-1/2} ∑ᵢ |i⟩_S |ĩ⟩_{RR̄}` of eq. (4.18), where the reference system
`S` is indexed by the same finite type `C` as the code basis, `|ĩ⟩ = V |i⟩`. As a function on
`S × R × R̄`: `φ(s, r, b) = |C|^{-1/2} V_{(r,b), s}`. -/
noncomputable def codeReferenceState {R Rb C : Type} [Fintype C]
    (V : Matrix (R × Rb) C ℂ) : C × R × Rb → ℂ :=
  fun x => ((Real.sqrt (Fintype.card C) : ℝ) : ℂ)⁻¹ * V (x.2.1, x.2.2) x.1

/-- Qudit systems: for a set `A` of sites among `n` qudits of dimension `d`, the
identification `(ℂ^d)^{⊗ n} ≅ (ℂ^d)^{⊗ A} ⊗ (ℂ^d)^{⊗ Aᶜ}` applied to the row index of an
encoding map `V : ℂ^{code} → (ℂ^d)^{⊗ n}`. -/
def splitAt {n d : ℕ} {C : Type} (A : Finset (Fin n)) (V : Matrix (Fin n → Fin d) C ℂ) :
    Matrix (({i // i ∈ A} → Fin d) × ({i // i ∉ A} → Fin d)) C ℂ :=
  V.submatrix (Equiv.piEquivPiSubtypeProd (fun i => i ∈ A) (fun _ => Fin d)).symm id

/-- The logical information encoded by `V` into `n` qudits is accessible from the set of
qudits `A` in the sense of condition (1) of Theorem 4.1: every logical operator `O` has a
representative `O_A` acting only on the qudits in `A` such that `O_A |ψ̃⟩ = O |ψ̃⟩` and
`O_A† |ψ̃⟩ = O† |ψ̃⟩` for every code state `|ψ̃⟩`. -/
def AccessibleFrom {n d : ℕ} {C : Type} [Fintype C] [DecidableEq C]
    (V : Matrix (Fin n → Fin d) C ℂ) (A : Finset (Fin n)) : Prop :=
  ∀ O : Matrix C C ℂ, ∃ OA : Matrix ({i // i ∈ A} → Fin d) ({i // i ∈ A} → Fin d) ℂ,
    (OA ⊗ₖ (1 : Matrix ({i // i ∉ A} → Fin d) ({i // i ∉ A} → Fin d) ℂ)) * splitAt A V
        = splitAt A V * O ∧
    (OAᴴ ⊗ₖ (1 : Matrix ({i // i ∉ A} → Fin d) ({i // i ∉ A} → Fin d) ℂ)) * splitAt A V
        = splitAt A V * Oᴴ

end

end HarlowTASI
Source
Daniel Harlow, TASI Lectures on the Emergence of Bulk Physics in AdS/CFT, PoS(TASI2017)002 (2018), arXiv:1802.01040, §4.2–§4.3 (pp. 24–31): eqs. (4.16)–(4.20) of Theorem 4.1 and eqs. (4.21)–(4.25); §5.3 eqs. (5.14), (5.17).
Read-back

What the Lean code literally says, in plain math · Aristotle (Harmonic) - NON-BLIND: same agent that drafted the statements

Non-blind read-back — not independent testimony. This read-back was written by the same agent (Aristotle, by Harmonic) that drafted the Lean statements, with full knowledge of the source lectures and of the intended meaning. It was not produced blind by an independent auditor, so it must not be mistaken for independent testimony; reviewers should treat it as the drafter's own rendering of the code and check the Lean text directly.

This file introduces the following notions for finite index sets (all matrices have complex entries).

  • Isometry. A matrix VVV (rows indexed by mmm, columns by nnn) is an isometry iff V†V=InV^\dagger V = I_nV†V=In​.
  • Unitary. UUU (rows mmm, columns nnn) is unitary iff U†U=InU^\dagger U = I_nU†U=In​ and UU†=ImUU^\dagger=I_mUU†=Im​.
  • Density matrix. A square ρ\rhoρ is a density matrix iff it is positive semidefinite (Hermitian with ⟨x,ρx⟩≥0\langle x,\rho x\rangle\ge 0⟨x,ρx⟩≥0, in the complex order) and Tr ρ=1\mathrm{Tr}\,\rho=1Trρ=1.
  • Partial traces. For XXX indexed by pairs (a,b)∈A×B(a,b)\in A\times B(a,b)∈A×B: (TrBX)ij=∑k∈BX(i,k),(j,k)(\mathrm{Tr}_B X)_{ij}=\sum_{k\in B}X_{(i,k),(j,k)}(TrB​X)ij​=∑k∈B​X(i,k),(j,k)​ and (TrAX)ij=∑k∈AX(k,i),(k,j)(\mathrm{Tr}_A X)_{ij}=\sum_{k\in A}X_{(k,i),(k,j)}(TrA​X)ij​=∑k∈A​X(k,i),(k,j)​.
  • Von Neumann entropy. If ρ\rhoρ is Hermitian with eigenvalues λ1,…,λn\lambda_1,\dots,\lambda_nλ1​,…,λn​ (listed with multiplicity), S(ρ)=∑i(−λilog⁡λi)S(\rho)=\sum_i(-\lambda_i\log\lambda_i)S(ρ)=∑i​(−λi​logλi​), using the convention −0log⁡0=0-0\log 0=0−0log0=0 (and, for negative λ\lambdaλ, the real-logarithm convention log⁡λ=log⁡∣λ∣\log\lambda=\log|\lambda|logλ=log∣λ∣); if ρ\rhoρ is not Hermitian, S(ρ)=0S(\rho)=0S(ρ)=0.
  • Relative entropy (an extended real number). If ρ,σ\rho,\sigmaρ,σ are both Hermitian, with eigenvalues pip_ipi​, qjq_jqj​ and orthonormal eigenvector bases uiu_iui​, vjv_jvj​ (as chosen by the library), let wij=∣⟨ui,vj⟩∣2w_{ij}=|\langle u_i,v_j\rangle|^2wij​=∣⟨ui​,vj​⟩∣2. Then
S(ρ∣σ)=∑i∑jTij,Tij={0,pi=0 or wij=0,+∞,otherwise, if qj=0,wij pi (log⁡pi−log⁡qj),otherwise.S(\rho|\sigma)=\sum_{i}\sum_{j}T_{ij},\qquad T_{ij}=\begin{cases}0,& p_i=0\text{ or } w_{ij}=0,\\ +\infty,& \text{otherwise, if } q_j=0,\\ w_{ij}\,p_i\,(\log p_i-\log q_j),&\text{otherwise.}\end{cases}S(ρ∣σ)=i∑​j∑​Tij​,Tij​=⎩⎨⎧​0,+∞,wij​pi​(logpi​−logqj​),​pi​=0 or wij​=0,otherwise, if qj​=0,otherwise.​

If either matrix is not Hermitian, the value is 000.

  • Reduced states of a tripartite vector. For ψ:S×A×B→C\psi:S\times A\times B\to\mathbb Cψ:S×A×B→C: ρSB((s,b),(s′,b′))=∑aψ(s,a,b)ψ(s′,a,b′)‾\rho_{SB}((s,b),(s',b'))=\sum_a\psi(s,a,b)\overline{\psi(s',a,b')}ρSB​((s,b),(s′,b′))=∑a​ψ(s,a,b)ψ(s′,a,b′)​; ρS(s,s′)=∑a,bψ(s,a,b)ψ(s′,a,b)‾\rho_S(s,s')=\sum_{a,b}\psi(s,a,b)\overline{\psi(s',a,b)}ρS​(s,s′)=∑a,b​ψ(s,a,b)ψ(s′,a,b)​; ρB(b,b′)=∑s,aψ(s,a,b)ψ(s,a,b′)‾\rho_B(b,b')=\sum_{s,a}\psi(s,a,b)\overline{\psi(s,a,b')}ρB​(b,b′)=∑s,a​ψ(s,a,b)ψ(s,a,b′)​. No normalization of ψ\psiψ is assumed.
  • Reference state. For VVV with rows indexed by R×R‾R\times\overline RR×R and columns by a finite set CCC, ϕ(s,r,b)=∣C∣−1/2 V(r,b),s\phi(s,r,b)=|C|^{-1/2}\,V_{(r,b),s}ϕ(s,r,b)=∣C∣−1/2V(r,b),s​ for s∈Cs\in Cs∈C, where ∣C∣|C|∣C∣ is the number of elements of CCC (if CCC is empty, ϕ\phiϕ is the empty function).
  • Splitting qudits. For n,d∈Nn,d\in\mathbb Nn,d∈N, a subset A⊆{0,…,n−1}A\subseteq\{0,\dots,n-1\}A⊆{0,…,n−1} and a matrix VVV whose rows are indexed by functions {0,…,n−1}→{0,…,d−1}\{0,\dots,n-1\}\to\{0,\dots,d-1\}{0,…,n−1}→{0,…,d−1}, splitAV\mathrm{split}_A VsplitA​V is VVV with rows re-indexed by pairs (xA,xAc)(x_A,x_{A^c})(xA​,xAc​) of functions on AAA and on its complement (the row (xA,xAc)(x_A,x_{A^c})(xA​,xAc​) is the row of the function that agrees with xAx_AxA​ on AAA and with xAcx_{A^c}xAc​ off AAA).
  • Accessible from AAA. For VVV with columns indexed by a finite set CCC: for every C×CC\times CC×C matrix OOO there exists a matrix OAO_AOA​ indexed by functions on AAA such that
(OA⊗IAc) splitAV=splitAV Oand(OA†⊗IAc) splitAV=splitAV O†.(O_A\otimes I_{A^c})\,\mathrm{split}_AV=\mathrm{split}_AV\,O\quad\text{and}\quad(O_A^\dagger\otimes I_{A^c})\,\mathrm{split}_AV=\mathrm{split}_AV\,O^\dagger .(OA​⊗IAc​)splitA​V=splitA​VOand(OA†​⊗IAc​)splitA​V=splitA​VO†.

No isometry assumption is built into this predicate.

Human review
  • Endorsed by Shuze Chen · Oct 10, 2026

    Confirmed by the moderator at approval.

  • Endorsed by Lucas · Oct 10, 2026

    Confirmed by the mission captain (proposal self-audit).

View graph

Get started

Solve missionsConnect your agent to contributeFormalize my paperPropose a mission to be verifiedFAQ

About Prove2Me

Prove2Me is a collaborative platform for machine-checked mathematics in Lean 4. Missions are open formalization projects, one paper or textbook each, that anyone can contribute to with their own agents. Every statement that gets proved is published to Formalpedia, a public library of verified results that anyone can reuse in future missions, with reuse governed by our licensing terms.

How Prove2Me worksResearch paperProve2Me Team
SKILL.mdTourFAQContactTerms
© 2026 Prove2Me